@zag-js/slider 0.2.13 → 0.2.15
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.
- package/dist/chunk-5CWNUPC7.mjs +50 -0
- package/dist/chunk-VTUEW45P.mjs +212 -0
- package/dist/{chunk-X363CZYV.mjs → chunk-XHNKYJMN.mjs} +36 -63
- package/dist/index.js +125 -486
- package/dist/index.mjs +3 -4
- package/dist/slider.connect.d.ts +30 -0
- package/dist/slider.connect.js +66 -180
- package/dist/slider.connect.mjs +2 -3
- package/dist/slider.dom.d.ts +9 -6
- package/dist/slider.dom.js +6 -86
- package/dist/slider.dom.mjs +1 -1
- package/dist/slider.machine.js +14 -354
- package/dist/slider.machine.mjs +2 -3
- package/package.json +7 -6
- package/dist/chunk-3UP6QL6A.mjs +0 -42
- package/dist/chunk-55KEN77D.mjs +0 -128
- package/dist/chunk-5XVLG734.mjs +0 -460
package/dist/slider.machine.js
CHANGED
|
@@ -24,357 +24,17 @@ __export(slider_machine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(slider_machine_exports);
|
|
26
26
|
var import_core = require("@zag-js/core");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var runIfFn = (v, ...a) => {
|
|
30
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
31
|
-
return res ?? void 0;
|
|
32
|
-
};
|
|
33
|
-
var callAll = (...fns) => (...a) => {
|
|
34
|
-
fns.forEach(function(fn) {
|
|
35
|
-
fn?.(...a);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// ../../utilities/core/src/guard.ts
|
|
40
|
-
var isArray = (v) => Array.isArray(v);
|
|
41
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
42
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
43
|
-
|
|
44
|
-
// ../../utilities/core/src/object.ts
|
|
45
|
-
function compact(obj) {
|
|
46
|
-
if (obj === void 0)
|
|
47
|
-
return obj;
|
|
48
|
-
return Object.fromEntries(
|
|
49
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ../../utilities/dom/src/platform.ts
|
|
54
|
-
var isDom = () => typeof window !== "undefined";
|
|
55
|
-
function getPlatform() {
|
|
56
|
-
const agent = navigator.userAgentData;
|
|
57
|
-
return agent?.platform ?? navigator.platform;
|
|
58
|
-
}
|
|
59
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
60
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
61
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
62
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
63
|
-
var isIos = () => isApple() && !isMac();
|
|
64
|
-
|
|
65
|
-
// ../../utilities/dom/src/query.ts
|
|
66
|
-
function isDocument(el) {
|
|
67
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
68
|
-
}
|
|
69
|
-
function isWindow(value) {
|
|
70
|
-
return value?.toString() === "[object Window]";
|
|
71
|
-
}
|
|
72
|
-
function getDocument(el) {
|
|
73
|
-
if (isWindow(el))
|
|
74
|
-
return el.document;
|
|
75
|
-
if (isDocument(el))
|
|
76
|
-
return el;
|
|
77
|
-
return el?.ownerDocument ?? document;
|
|
78
|
-
}
|
|
79
|
-
function getWindow(el) {
|
|
80
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
81
|
-
}
|
|
82
|
-
function defineDomHelpers(helpers) {
|
|
83
|
-
const dom2 = {
|
|
84
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
85
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
86
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
87
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
88
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
89
|
-
};
|
|
90
|
-
return {
|
|
91
|
-
...dom2,
|
|
92
|
-
...helpers
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ../../utilities/dom/src/event.ts
|
|
97
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
98
|
-
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
99
|
-
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
100
|
-
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
101
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
102
|
-
var isLeftClick = (v) => v.button === 0;
|
|
103
|
-
|
|
104
|
-
// ../../utilities/dom/src/get-element-offset.ts
|
|
105
|
-
function getElementOffset(element) {
|
|
106
|
-
let left = 0;
|
|
107
|
-
let top = 0;
|
|
108
|
-
let el = element;
|
|
109
|
-
if (el.parentNode) {
|
|
110
|
-
do {
|
|
111
|
-
left += el.offsetLeft;
|
|
112
|
-
top += el.offsetTop;
|
|
113
|
-
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
114
|
-
el = element;
|
|
115
|
-
do {
|
|
116
|
-
left -= el.scrollLeft;
|
|
117
|
-
top -= el.scrollTop;
|
|
118
|
-
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
top,
|
|
122
|
-
right: innerWidth - left - element.offsetWidth,
|
|
123
|
-
bottom: innerHeight - top - element.offsetHeight,
|
|
124
|
-
left
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
129
|
-
function getPointRelativeToNode(point, element) {
|
|
130
|
-
const offset = getElementOffset(element);
|
|
131
|
-
const x = point.x - offset.left;
|
|
132
|
-
const y = point.y - offset.top;
|
|
133
|
-
return { x, y };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// ../../utilities/dom/src/listener.ts
|
|
137
|
-
var isRef = (v) => hasProp(v, "current");
|
|
138
|
-
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
139
|
-
function extractInfo(event, type = "page") {
|
|
140
|
-
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
|
|
141
|
-
return {
|
|
142
|
-
point: {
|
|
143
|
-
x: point[`${type}X`],
|
|
144
|
-
y: point[`${type}Y`]
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
149
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
150
|
-
node?.addEventListener(eventName, handler, options);
|
|
151
|
-
return () => {
|
|
152
|
-
node?.removeEventListener(eventName, handler, options);
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function addPointerEvent(target, event, listener, options) {
|
|
156
|
-
const type = getEventName(event) ?? event;
|
|
157
|
-
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
158
|
-
}
|
|
159
|
-
function wrapHandler(fn, filter = false) {
|
|
160
|
-
const listener = (event) => {
|
|
161
|
-
fn(event, extractInfo(event));
|
|
162
|
-
};
|
|
163
|
-
return filter ? filterPrimaryPointer(listener) : listener;
|
|
164
|
-
}
|
|
165
|
-
function filterPrimaryPointer(fn) {
|
|
166
|
-
return (event) => {
|
|
167
|
-
const win = event.view ?? window;
|
|
168
|
-
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
169
|
-
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
170
|
-
if (isPrimary)
|
|
171
|
-
fn(event);
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
var mouseEventNames = {
|
|
175
|
-
pointerdown: "mousedown",
|
|
176
|
-
pointermove: "mousemove",
|
|
177
|
-
pointerup: "mouseup",
|
|
178
|
-
pointercancel: "mousecancel",
|
|
179
|
-
pointerover: "mouseover",
|
|
180
|
-
pointerout: "mouseout",
|
|
181
|
-
pointerenter: "mouseenter",
|
|
182
|
-
pointerleave: "mouseleave"
|
|
183
|
-
};
|
|
184
|
-
var touchEventNames = {
|
|
185
|
-
pointerdown: "touchstart",
|
|
186
|
-
pointermove: "touchmove",
|
|
187
|
-
pointerup: "touchend",
|
|
188
|
-
pointercancel: "touchcancel"
|
|
189
|
-
};
|
|
190
|
-
function getEventName(evt) {
|
|
191
|
-
if (supportsPointerEvent())
|
|
192
|
-
return evt;
|
|
193
|
-
if (supportsTouchEvent())
|
|
194
|
-
return touchEventNames[evt];
|
|
195
|
-
if (supportsMouseEvent())
|
|
196
|
-
return mouseEventNames[evt];
|
|
197
|
-
return evt;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// ../../utilities/dom/src/mutation-observer.ts
|
|
201
|
-
function observeAttributes(node, attributes, fn) {
|
|
202
|
-
if (!node)
|
|
203
|
-
return;
|
|
204
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
205
|
-
const win = node.ownerDocument.defaultView || window;
|
|
206
|
-
const obs = new win.MutationObserver((changes) => {
|
|
207
|
-
for (const change of changes) {
|
|
208
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
209
|
-
fn(change);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
214
|
-
return () => obs.disconnect();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
218
|
-
function nextTick(fn) {
|
|
219
|
-
const set = /* @__PURE__ */ new Set();
|
|
220
|
-
function raf2(fn2) {
|
|
221
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
222
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
223
|
-
}
|
|
224
|
-
raf2(() => raf2(fn));
|
|
225
|
-
return function cleanup() {
|
|
226
|
-
set.forEach(function(fn2) {
|
|
227
|
-
fn2();
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function raf(fn) {
|
|
232
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
233
|
-
return function cleanup() {
|
|
234
|
-
globalThis.cancelAnimationFrame(id);
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// ../../utilities/dom/src/text-selection.ts
|
|
239
|
-
var state = "default";
|
|
240
|
-
var savedUserSelect = "";
|
|
241
|
-
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
242
|
-
function disableTextSelection({ target, doc } = {}) {
|
|
243
|
-
const _document = doc ?? document;
|
|
244
|
-
if (isIos()) {
|
|
245
|
-
if (state === "default") {
|
|
246
|
-
savedUserSelect = _document.documentElement.style.webkitUserSelect;
|
|
247
|
-
_document.documentElement.style.webkitUserSelect = "none";
|
|
248
|
-
}
|
|
249
|
-
state = "disabled";
|
|
250
|
-
} else if (target) {
|
|
251
|
-
modifiedElementMap.set(target, target.style.userSelect);
|
|
252
|
-
target.style.userSelect = "none";
|
|
253
|
-
}
|
|
254
|
-
return () => restoreTextSelection({ target, doc: _document });
|
|
255
|
-
}
|
|
256
|
-
function restoreTextSelection({ target, doc } = {}) {
|
|
257
|
-
const _document = doc ?? document;
|
|
258
|
-
if (isIos()) {
|
|
259
|
-
if (state !== "disabled")
|
|
260
|
-
return;
|
|
261
|
-
state = "restoring";
|
|
262
|
-
setTimeout(() => {
|
|
263
|
-
nextTick(() => {
|
|
264
|
-
if (state === "restoring") {
|
|
265
|
-
if (_document.documentElement.style.webkitUserSelect === "none") {
|
|
266
|
-
_document.documentElement.style.webkitUserSelect = savedUserSelect || "";
|
|
267
|
-
}
|
|
268
|
-
savedUserSelect = "";
|
|
269
|
-
state = "default";
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}, 300);
|
|
273
|
-
} else {
|
|
274
|
-
if (target && modifiedElementMap.has(target)) {
|
|
275
|
-
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
276
|
-
if (target.style.userSelect === "none") {
|
|
277
|
-
target.style.userSelect = targetOldUserSelect ?? "";
|
|
278
|
-
}
|
|
279
|
-
if (target.getAttribute("style") === "") {
|
|
280
|
-
target.removeAttribute("style");
|
|
281
|
-
}
|
|
282
|
-
modifiedElementMap.delete(target);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// ../../utilities/dom/src/pointer-event.ts
|
|
288
|
-
var THRESHOLD = 5;
|
|
289
|
-
function trackPointerMove(doc, opts) {
|
|
290
|
-
const { onPointerMove, onPointerUp } = opts;
|
|
291
|
-
const handlePointerMove = (event, info) => {
|
|
292
|
-
const { point: p } = info;
|
|
293
|
-
const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
|
|
294
|
-
if (distance < THRESHOLD)
|
|
295
|
-
return;
|
|
296
|
-
if (isMouseEvent(event) && isLeftClick(event)) {
|
|
297
|
-
onPointerUp();
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
onPointerMove(info, event);
|
|
301
|
-
};
|
|
302
|
-
return callAll(
|
|
303
|
-
addPointerEvent(doc, "pointermove", handlePointerMove, false),
|
|
304
|
-
addPointerEvent(doc, "pointerup", onPointerUp, false),
|
|
305
|
-
addPointerEvent(doc, "pointercancel", onPointerUp, false),
|
|
306
|
-
addPointerEvent(doc, "contextmenu", onPointerUp, false),
|
|
307
|
-
disableTextSelection({ doc })
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// src/slider.machine.ts
|
|
27
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
28
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
312
29
|
var import_element_size = require("@zag-js/element-size");
|
|
313
|
-
|
|
314
|
-
// ../../utilities/form-utils/src/input-event.ts
|
|
315
|
-
function getDescriptor(el, options) {
|
|
316
|
-
const { type, property = "value" } = options;
|
|
317
|
-
const proto = getWindow(el)[type].prototype;
|
|
318
|
-
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
319
|
-
}
|
|
320
|
-
function dispatchInputValueEvent(el, value) {
|
|
321
|
-
if (!el)
|
|
322
|
-
return;
|
|
323
|
-
const win = getWindow(el);
|
|
324
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
325
|
-
return;
|
|
326
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
327
|
-
desc.set?.call(el, value);
|
|
328
|
-
const event = new win.Event("input", { bubbles: true });
|
|
329
|
-
el.dispatchEvent(event);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// ../../utilities/form-utils/src/form.ts
|
|
333
|
-
function getClosestForm(el) {
|
|
334
|
-
if (isFormElement(el))
|
|
335
|
-
return el.form;
|
|
336
|
-
else
|
|
337
|
-
return el.closest("form");
|
|
338
|
-
}
|
|
339
|
-
function isFormElement(el) {
|
|
340
|
-
return el.matches("textarea, input, select, button");
|
|
341
|
-
}
|
|
342
|
-
function trackFormReset(el, callback) {
|
|
343
|
-
if (!el)
|
|
344
|
-
return;
|
|
345
|
-
const form = getClosestForm(el);
|
|
346
|
-
form?.addEventListener("reset", callback, { passive: true });
|
|
347
|
-
return () => {
|
|
348
|
-
form?.removeEventListener("reset", callback);
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
function trackFieldsetDisabled(el, callback) {
|
|
352
|
-
const fieldset = el?.closest("fieldset");
|
|
353
|
-
if (!fieldset)
|
|
354
|
-
return;
|
|
355
|
-
callback(fieldset.disabled);
|
|
356
|
-
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
357
|
-
}
|
|
358
|
-
function trackFormControl(el, options) {
|
|
359
|
-
if (!el)
|
|
360
|
-
return;
|
|
361
|
-
const { onFieldsetDisabled, onFormReset } = options;
|
|
362
|
-
const cleanups = [
|
|
363
|
-
trackFormReset(el, onFormReset),
|
|
364
|
-
trackFieldsetDisabled(el, (disabled) => {
|
|
365
|
-
if (disabled)
|
|
366
|
-
onFieldsetDisabled();
|
|
367
|
-
})
|
|
368
|
-
];
|
|
369
|
-
return () => {
|
|
370
|
-
cleanups.forEach((cleanup) => cleanup?.());
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// src/slider.machine.ts
|
|
30
|
+
var import_form_utils2 = require("@zag-js/form-utils");
|
|
375
31
|
var import_numeric_range4 = require("@zag-js/numeric-range");
|
|
32
|
+
var import_utils = require("@zag-js/utils");
|
|
376
33
|
|
|
377
34
|
// src/slider.dom.ts
|
|
35
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
36
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
37
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
378
38
|
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
379
39
|
|
|
380
40
|
// src/slider.style.ts
|
|
@@ -490,7 +150,7 @@ var styles = {
|
|
|
490
150
|
};
|
|
491
151
|
|
|
492
152
|
// src/slider.dom.ts
|
|
493
|
-
var dom =
|
|
153
|
+
var dom = (0, import_dom_query.createScope)({
|
|
494
154
|
...styles,
|
|
495
155
|
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
496
156
|
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
@@ -509,7 +169,7 @@ var dom = defineDomHelpers({
|
|
|
509
169
|
const el = dom.getControlEl(ctx);
|
|
510
170
|
if (!el)
|
|
511
171
|
return;
|
|
512
|
-
const relativePoint =
|
|
172
|
+
const relativePoint = (0, import_dom_event.getRelativePointValue)(point, el);
|
|
513
173
|
const percentX = relativePoint.x / el.offsetWidth;
|
|
514
174
|
const percentY = relativePoint.y / el.offsetHeight;
|
|
515
175
|
let percent;
|
|
@@ -524,7 +184,7 @@ var dom = defineDomHelpers({
|
|
|
524
184
|
const input = dom.getHiddenInputEl(ctx);
|
|
525
185
|
if (!input)
|
|
526
186
|
return;
|
|
527
|
-
dispatchInputValueEvent(input, ctx.value);
|
|
187
|
+
(0, import_form_utils.dispatchInputValueEvent)(input, ctx.value);
|
|
528
188
|
}
|
|
529
189
|
});
|
|
530
190
|
|
|
@@ -555,7 +215,7 @@ function increment(ctx, step) {
|
|
|
555
215
|
|
|
556
216
|
// src/slider.machine.ts
|
|
557
217
|
function machine(userContext) {
|
|
558
|
-
const ctx = compact(userContext);
|
|
218
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
559
219
|
return (0, import_core.createMachine)(
|
|
560
220
|
{
|
|
561
221
|
id: "slider",
|
|
@@ -669,7 +329,7 @@ function machine(userContext) {
|
|
|
669
329
|
},
|
|
670
330
|
activities: {
|
|
671
331
|
trackFormControlState(ctx2) {
|
|
672
|
-
return trackFormControl(dom.getHiddenInputEl(ctx2), {
|
|
332
|
+
return (0, import_form_utils2.trackFormControl)(dom.getHiddenInputEl(ctx2), {
|
|
673
333
|
onFieldsetDisabled() {
|
|
674
334
|
ctx2.disabled = true;
|
|
675
335
|
},
|
|
@@ -681,7 +341,7 @@ function machine(userContext) {
|
|
|
681
341
|
});
|
|
682
342
|
},
|
|
683
343
|
trackPointerMove(ctx2, _evt, { send }) {
|
|
684
|
-
return trackPointerMove(dom.getDoc(ctx2), {
|
|
344
|
+
return (0, import_dom_event2.trackPointerMove)(dom.getDoc(ctx2), {
|
|
685
345
|
onPointerMove(info) {
|
|
686
346
|
send({ type: "POINTER_MOVE", point: info.point });
|
|
687
347
|
},
|
|
@@ -724,7 +384,7 @@ function machine(userContext) {
|
|
|
724
384
|
ctx2.value = (0, import_numeric_range4.clampValue)(value, ctx2.min, ctx2.max);
|
|
725
385
|
},
|
|
726
386
|
focusThumb(ctx2) {
|
|
727
|
-
raf(() => dom.getThumbEl(ctx2)?.focus());
|
|
387
|
+
(0, import_dom_query2.raf)(() => dom.getThumbEl(ctx2)?.focus());
|
|
728
388
|
},
|
|
729
389
|
decrement(ctx2, evt) {
|
|
730
390
|
ctx2.value = decrement(ctx2, evt.step);
|
package/dist/slider.machine.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/slider",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,16 +27,17 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@zag-js/anatomy": "0.1.4",
|
|
30
|
-
"@zag-js/core": "0.2.
|
|
30
|
+
"@zag-js/core": "0.2.10",
|
|
31
|
+
"@zag-js/dom-query": "0.1.4",
|
|
32
|
+
"@zag-js/dom-event": "0.0.1",
|
|
33
|
+
"@zag-js/form-utils": "0.2.5",
|
|
34
|
+
"@zag-js/utils": "0.3.3",
|
|
31
35
|
"@zag-js/element-size": "0.3.2",
|
|
32
36
|
"@zag-js/numeric-range": "0.1.1",
|
|
33
37
|
"@zag-js/types": "0.3.4"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
36
|
-
"clean-package": "2.2.0"
|
|
37
|
-
"@zag-js/dom-utils": "0.2.4",
|
|
38
|
-
"@zag-js/form-utils": "0.2.4",
|
|
39
|
-
"@zag-js/utils": "0.3.3"
|
|
40
|
+
"clean-package": "2.2.0"
|
|
40
41
|
},
|
|
41
42
|
"clean-package": "../../../clean-package.config.json",
|
|
42
43
|
"main": "dist/index.js",
|
package/dist/chunk-3UP6QL6A.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// ../../utilities/core/src/guard.ts
|
|
2
|
-
var isArray = (v) => Array.isArray(v);
|
|
3
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
4
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
5
|
-
|
|
6
|
-
// ../../utilities/dom/src/platform.ts
|
|
7
|
-
var isDom = () => typeof window !== "undefined";
|
|
8
|
-
function getPlatform() {
|
|
9
|
-
const agent = navigator.userAgentData;
|
|
10
|
-
return agent?.platform ?? navigator.platform;
|
|
11
|
-
}
|
|
12
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
13
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
14
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
15
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
16
|
-
var isIos = () => isApple() && !isMac();
|
|
17
|
-
|
|
18
|
-
// ../../utilities/dom/src/event.ts
|
|
19
|
-
function getNativeEvent(e) {
|
|
20
|
-
return e.nativeEvent ?? e;
|
|
21
|
-
}
|
|
22
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
23
|
-
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
24
|
-
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
25
|
-
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
26
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
27
|
-
var isLeftClick = (v) => v.button === 0;
|
|
28
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
isObject,
|
|
32
|
-
hasProp,
|
|
33
|
-
isIos,
|
|
34
|
-
getNativeEvent,
|
|
35
|
-
supportsPointerEvent,
|
|
36
|
-
supportsTouchEvent,
|
|
37
|
-
supportsMouseEvent,
|
|
38
|
-
isMouseEvent,
|
|
39
|
-
isTouchEvent,
|
|
40
|
-
isLeftClick,
|
|
41
|
-
isModifiedEvent
|
|
42
|
-
};
|
package/dist/chunk-55KEN77D.mjs
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
styles
|
|
3
|
-
} from "./chunk-IJAAAKZQ.mjs";
|
|
4
|
-
|
|
5
|
-
// ../../utilities/dom/src/query.ts
|
|
6
|
-
function isDocument(el) {
|
|
7
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
8
|
-
}
|
|
9
|
-
function isWindow(value) {
|
|
10
|
-
return value?.toString() === "[object Window]";
|
|
11
|
-
}
|
|
12
|
-
function getDocument(el) {
|
|
13
|
-
if (isWindow(el))
|
|
14
|
-
return el.document;
|
|
15
|
-
if (isDocument(el))
|
|
16
|
-
return el;
|
|
17
|
-
return el?.ownerDocument ?? document;
|
|
18
|
-
}
|
|
19
|
-
function getWindow(el) {
|
|
20
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
21
|
-
}
|
|
22
|
-
function defineDomHelpers(helpers) {
|
|
23
|
-
const dom2 = {
|
|
24
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
25
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
26
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
27
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
28
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
29
|
-
};
|
|
30
|
-
return {
|
|
31
|
-
...dom2,
|
|
32
|
-
...helpers
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ../../utilities/dom/src/get-element-offset.ts
|
|
37
|
-
function getElementOffset(element) {
|
|
38
|
-
let left = 0;
|
|
39
|
-
let top = 0;
|
|
40
|
-
let el = element;
|
|
41
|
-
if (el.parentNode) {
|
|
42
|
-
do {
|
|
43
|
-
left += el.offsetLeft;
|
|
44
|
-
top += el.offsetTop;
|
|
45
|
-
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
46
|
-
el = element;
|
|
47
|
-
do {
|
|
48
|
-
left -= el.scrollLeft;
|
|
49
|
-
top -= el.scrollTop;
|
|
50
|
-
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
top,
|
|
54
|
-
right: innerWidth - left - element.offsetWidth,
|
|
55
|
-
bottom: innerHeight - top - element.offsetHeight,
|
|
56
|
-
left
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
61
|
-
function getPointRelativeToNode(point, element) {
|
|
62
|
-
const offset = getElementOffset(element);
|
|
63
|
-
const x = point.x - offset.left;
|
|
64
|
-
const y = point.y - offset.top;
|
|
65
|
-
return { x, y };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ../../utilities/form-utils/src/input-event.ts
|
|
69
|
-
function getDescriptor(el, options) {
|
|
70
|
-
const { type, property = "value" } = options;
|
|
71
|
-
const proto = getWindow(el)[type].prototype;
|
|
72
|
-
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
73
|
-
}
|
|
74
|
-
function dispatchInputValueEvent(el, value) {
|
|
75
|
-
if (!el)
|
|
76
|
-
return;
|
|
77
|
-
const win = getWindow(el);
|
|
78
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
79
|
-
return;
|
|
80
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
81
|
-
desc.set?.call(el, value);
|
|
82
|
-
const event = new win.Event("input", { bubbles: true });
|
|
83
|
-
el.dispatchEvent(event);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/slider.dom.ts
|
|
87
|
-
import { getPercentValue } from "@zag-js/numeric-range";
|
|
88
|
-
var dom = defineDomHelpers({
|
|
89
|
-
...styles,
|
|
90
|
-
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
91
|
-
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
92
|
-
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
93
|
-
getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
|
|
94
|
-
getOutputId: (ctx) => ctx.ids?.output ?? `slider:${ctx.id}:output`,
|
|
95
|
-
getTrackId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}track`,
|
|
96
|
-
getRangeId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:range`,
|
|
97
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`,
|
|
98
|
-
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
99
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
100
|
-
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
101
|
-
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
102
|
-
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
103
|
-
getValueFromPoint(ctx, point) {
|
|
104
|
-
const el = dom.getControlEl(ctx);
|
|
105
|
-
if (!el)
|
|
106
|
-
return;
|
|
107
|
-
const relativePoint = getPointRelativeToNode(point, el);
|
|
108
|
-
const percentX = relativePoint.x / el.offsetWidth;
|
|
109
|
-
const percentY = relativePoint.y / el.offsetHeight;
|
|
110
|
-
let percent;
|
|
111
|
-
if (ctx.isHorizontal) {
|
|
112
|
-
percent = ctx.isRtl ? 1 - percentX : percentX;
|
|
113
|
-
} else {
|
|
114
|
-
percent = 1 - percentY;
|
|
115
|
-
}
|
|
116
|
-
return getPercentValue(percent, ctx.min, ctx.max, ctx.step);
|
|
117
|
-
},
|
|
118
|
-
dispatchChangeEvent(ctx) {
|
|
119
|
-
const input = dom.getHiddenInputEl(ctx);
|
|
120
|
-
if (!input)
|
|
121
|
-
return;
|
|
122
|
-
dispatchInputValueEvent(input, ctx.value);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
export {
|
|
127
|
-
dom
|
|
128
|
-
};
|