@zag-js/slider 0.0.0-dev-20230220134212 → 0.0.0-dev-20230222120620
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-X363CZYV.mjs → chunk-KUUPJ6WI.mjs} +6 -63
- package/dist/chunk-VTUEW45P.mjs +212 -0
- package/dist/index.js +95 -486
- package/dist/index.mjs +3 -4
- package/dist/slider.connect.js +36 -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/index.js
CHANGED
|
@@ -43,410 +43,15 @@ var anatomy = (0, import_anatomy.createAnatomy)("slider").parts(
|
|
|
43
43
|
);
|
|
44
44
|
var parts = anatomy.build();
|
|
45
45
|
|
|
46
|
-
// ../../utilities/dom/src/attrs.ts
|
|
47
|
-
var dataAttr = (guard) => {
|
|
48
|
-
return guard ? "" : void 0;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// ../../utilities/core/src/functions.ts
|
|
52
|
-
var runIfFn = (v, ...a) => {
|
|
53
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
54
|
-
return res ?? void 0;
|
|
55
|
-
};
|
|
56
|
-
var callAll = (...fns) => (...a) => {
|
|
57
|
-
fns.forEach(function(fn) {
|
|
58
|
-
fn?.(...a);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// ../../utilities/core/src/guard.ts
|
|
63
|
-
var isArray = (v) => Array.isArray(v);
|
|
64
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
65
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
66
|
-
|
|
67
|
-
// ../../utilities/core/src/object.ts
|
|
68
|
-
function compact(obj) {
|
|
69
|
-
if (obj === void 0)
|
|
70
|
-
return obj;
|
|
71
|
-
return Object.fromEntries(
|
|
72
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// ../../utilities/dom/src/platform.ts
|
|
77
|
-
var isDom = () => typeof window !== "undefined";
|
|
78
|
-
function getPlatform() {
|
|
79
|
-
const agent = navigator.userAgentData;
|
|
80
|
-
return agent?.platform ?? navigator.platform;
|
|
81
|
-
}
|
|
82
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
83
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
84
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
85
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
86
|
-
var isIos = () => isApple() && !isMac();
|
|
87
|
-
|
|
88
|
-
// ../../utilities/dom/src/query.ts
|
|
89
|
-
function isDocument(el) {
|
|
90
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
91
|
-
}
|
|
92
|
-
function isWindow(value) {
|
|
93
|
-
return value?.toString() === "[object Window]";
|
|
94
|
-
}
|
|
95
|
-
function getDocument(el) {
|
|
96
|
-
if (isWindow(el))
|
|
97
|
-
return el.document;
|
|
98
|
-
if (isDocument(el))
|
|
99
|
-
return el;
|
|
100
|
-
return el?.ownerDocument ?? document;
|
|
101
|
-
}
|
|
102
|
-
function getWindow(el) {
|
|
103
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
104
|
-
}
|
|
105
|
-
function defineDomHelpers(helpers) {
|
|
106
|
-
const dom2 = {
|
|
107
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
108
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
109
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
110
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
111
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
112
|
-
};
|
|
113
|
-
return {
|
|
114
|
-
...dom2,
|
|
115
|
-
...helpers
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// ../../utilities/dom/src/event.ts
|
|
120
|
-
function getNativeEvent(e) {
|
|
121
|
-
return e.nativeEvent ?? e;
|
|
122
|
-
}
|
|
123
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
124
|
-
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
125
|
-
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
126
|
-
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
127
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
128
|
-
var isLeftClick = (v) => v.button === 0;
|
|
129
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
130
|
-
|
|
131
|
-
// ../../utilities/dom/src/get-element-offset.ts
|
|
132
|
-
function getElementOffset(element) {
|
|
133
|
-
let left = 0;
|
|
134
|
-
let top = 0;
|
|
135
|
-
let el = element;
|
|
136
|
-
if (el.parentNode) {
|
|
137
|
-
do {
|
|
138
|
-
left += el.offsetLeft;
|
|
139
|
-
top += el.offsetTop;
|
|
140
|
-
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
141
|
-
el = element;
|
|
142
|
-
do {
|
|
143
|
-
left -= el.scrollLeft;
|
|
144
|
-
top -= el.scrollTop;
|
|
145
|
-
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
top,
|
|
149
|
-
right: innerWidth - left - element.offsetWidth,
|
|
150
|
-
bottom: innerHeight - top - element.offsetHeight,
|
|
151
|
-
left
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ../../utilities/dom/src/get-event-point.ts
|
|
156
|
-
var fallback = {
|
|
157
|
-
pageX: 0,
|
|
158
|
-
pageY: 0,
|
|
159
|
-
clientX: 0,
|
|
160
|
-
clientY: 0
|
|
161
|
-
};
|
|
162
|
-
function getEventPoint(event, type = "page") {
|
|
163
|
-
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
164
|
-
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
168
|
-
function getPointRelativeToNode(point, element) {
|
|
169
|
-
const offset = getElementOffset(element);
|
|
170
|
-
const x = point.x - offset.left;
|
|
171
|
-
const y = point.y - offset.top;
|
|
172
|
-
return { x, y };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
176
|
-
var rtlKeyMap = {
|
|
177
|
-
ArrowLeft: "ArrowRight",
|
|
178
|
-
ArrowRight: "ArrowLeft"
|
|
179
|
-
};
|
|
180
|
-
var sameKeyMap = {
|
|
181
|
-
Up: "ArrowUp",
|
|
182
|
-
Down: "ArrowDown",
|
|
183
|
-
Esc: "Escape",
|
|
184
|
-
" ": "Space",
|
|
185
|
-
",": "Comma",
|
|
186
|
-
Left: "ArrowLeft",
|
|
187
|
-
Right: "ArrowRight"
|
|
188
|
-
};
|
|
189
|
-
function getEventKey(event, options = {}) {
|
|
190
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
191
|
-
let { key } = event;
|
|
192
|
-
key = sameKeyMap[key] ?? key;
|
|
193
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
194
|
-
if (isRtl && key in rtlKeyMap) {
|
|
195
|
-
key = rtlKeyMap[key];
|
|
196
|
-
}
|
|
197
|
-
return key;
|
|
198
|
-
}
|
|
199
|
-
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
200
|
-
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
201
|
-
function getEventStep(event) {
|
|
202
|
-
if (event.ctrlKey || event.metaKey) {
|
|
203
|
-
return 0.1;
|
|
204
|
-
} else {
|
|
205
|
-
const isPageKey = PAGE_KEYS.has(event.key);
|
|
206
|
-
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
207
|
-
return isSkipKey ? 10 : 1;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// ../../utilities/dom/src/listener.ts
|
|
212
|
-
var isRef = (v) => hasProp(v, "current");
|
|
213
|
-
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
214
|
-
function extractInfo(event, type = "page") {
|
|
215
|
-
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
|
|
216
|
-
return {
|
|
217
|
-
point: {
|
|
218
|
-
x: point[`${type}X`],
|
|
219
|
-
y: point[`${type}Y`]
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
224
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
225
|
-
node?.addEventListener(eventName, handler, options);
|
|
226
|
-
return () => {
|
|
227
|
-
node?.removeEventListener(eventName, handler, options);
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function addPointerEvent(target, event, listener, options) {
|
|
231
|
-
const type = getEventName(event) ?? event;
|
|
232
|
-
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
233
|
-
}
|
|
234
|
-
function wrapHandler(fn, filter = false) {
|
|
235
|
-
const listener = (event) => {
|
|
236
|
-
fn(event, extractInfo(event));
|
|
237
|
-
};
|
|
238
|
-
return filter ? filterPrimaryPointer(listener) : listener;
|
|
239
|
-
}
|
|
240
|
-
function filterPrimaryPointer(fn) {
|
|
241
|
-
return (event) => {
|
|
242
|
-
const win = event.view ?? window;
|
|
243
|
-
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
244
|
-
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
245
|
-
if (isPrimary)
|
|
246
|
-
fn(event);
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
var mouseEventNames = {
|
|
250
|
-
pointerdown: "mousedown",
|
|
251
|
-
pointermove: "mousemove",
|
|
252
|
-
pointerup: "mouseup",
|
|
253
|
-
pointercancel: "mousecancel",
|
|
254
|
-
pointerover: "mouseover",
|
|
255
|
-
pointerout: "mouseout",
|
|
256
|
-
pointerenter: "mouseenter",
|
|
257
|
-
pointerleave: "mouseleave"
|
|
258
|
-
};
|
|
259
|
-
var touchEventNames = {
|
|
260
|
-
pointerdown: "touchstart",
|
|
261
|
-
pointermove: "touchmove",
|
|
262
|
-
pointerup: "touchend",
|
|
263
|
-
pointercancel: "touchcancel"
|
|
264
|
-
};
|
|
265
|
-
function getEventName(evt) {
|
|
266
|
-
if (supportsPointerEvent())
|
|
267
|
-
return evt;
|
|
268
|
-
if (supportsTouchEvent())
|
|
269
|
-
return touchEventNames[evt];
|
|
270
|
-
if (supportsMouseEvent())
|
|
271
|
-
return mouseEventNames[evt];
|
|
272
|
-
return evt;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// ../../utilities/dom/src/mutation-observer.ts
|
|
276
|
-
function observeAttributes(node, attributes, fn) {
|
|
277
|
-
if (!node)
|
|
278
|
-
return;
|
|
279
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
280
|
-
const win = node.ownerDocument.defaultView || window;
|
|
281
|
-
const obs = new win.MutationObserver((changes) => {
|
|
282
|
-
for (const change of changes) {
|
|
283
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
284
|
-
fn(change);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
289
|
-
return () => obs.disconnect();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
293
|
-
function nextTick(fn) {
|
|
294
|
-
const set = /* @__PURE__ */ new Set();
|
|
295
|
-
function raf2(fn2) {
|
|
296
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
297
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
298
|
-
}
|
|
299
|
-
raf2(() => raf2(fn));
|
|
300
|
-
return function cleanup() {
|
|
301
|
-
set.forEach(function(fn2) {
|
|
302
|
-
fn2();
|
|
303
|
-
});
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
function raf(fn) {
|
|
307
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
308
|
-
return function cleanup() {
|
|
309
|
-
globalThis.cancelAnimationFrame(id);
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// ../../utilities/dom/src/text-selection.ts
|
|
314
|
-
var state = "default";
|
|
315
|
-
var savedUserSelect = "";
|
|
316
|
-
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
317
|
-
function disableTextSelection({ target, doc } = {}) {
|
|
318
|
-
const _document = doc ?? document;
|
|
319
|
-
if (isIos()) {
|
|
320
|
-
if (state === "default") {
|
|
321
|
-
savedUserSelect = _document.documentElement.style.webkitUserSelect;
|
|
322
|
-
_document.documentElement.style.webkitUserSelect = "none";
|
|
323
|
-
}
|
|
324
|
-
state = "disabled";
|
|
325
|
-
} else if (target) {
|
|
326
|
-
modifiedElementMap.set(target, target.style.userSelect);
|
|
327
|
-
target.style.userSelect = "none";
|
|
328
|
-
}
|
|
329
|
-
return () => restoreTextSelection({ target, doc: _document });
|
|
330
|
-
}
|
|
331
|
-
function restoreTextSelection({ target, doc } = {}) {
|
|
332
|
-
const _document = doc ?? document;
|
|
333
|
-
if (isIos()) {
|
|
334
|
-
if (state !== "disabled")
|
|
335
|
-
return;
|
|
336
|
-
state = "restoring";
|
|
337
|
-
setTimeout(() => {
|
|
338
|
-
nextTick(() => {
|
|
339
|
-
if (state === "restoring") {
|
|
340
|
-
if (_document.documentElement.style.webkitUserSelect === "none") {
|
|
341
|
-
_document.documentElement.style.webkitUserSelect = savedUserSelect || "";
|
|
342
|
-
}
|
|
343
|
-
savedUserSelect = "";
|
|
344
|
-
state = "default";
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
}, 300);
|
|
348
|
-
} else {
|
|
349
|
-
if (target && modifiedElementMap.has(target)) {
|
|
350
|
-
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
351
|
-
if (target.style.userSelect === "none") {
|
|
352
|
-
target.style.userSelect = targetOldUserSelect ?? "";
|
|
353
|
-
}
|
|
354
|
-
if (target.getAttribute("style") === "") {
|
|
355
|
-
target.removeAttribute("style");
|
|
356
|
-
}
|
|
357
|
-
modifiedElementMap.delete(target);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// ../../utilities/dom/src/pointer-event.ts
|
|
363
|
-
var THRESHOLD = 5;
|
|
364
|
-
function trackPointerMove(doc, opts) {
|
|
365
|
-
const { onPointerMove, onPointerUp } = opts;
|
|
366
|
-
const handlePointerMove = (event, info) => {
|
|
367
|
-
const { point: p } = info;
|
|
368
|
-
const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
|
|
369
|
-
if (distance < THRESHOLD)
|
|
370
|
-
return;
|
|
371
|
-
if (isMouseEvent(event) && isLeftClick(event)) {
|
|
372
|
-
onPointerUp();
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
onPointerMove(info, event);
|
|
376
|
-
};
|
|
377
|
-
return callAll(
|
|
378
|
-
addPointerEvent(doc, "pointermove", handlePointerMove, false),
|
|
379
|
-
addPointerEvent(doc, "pointerup", onPointerUp, false),
|
|
380
|
-
addPointerEvent(doc, "pointercancel", onPointerUp, false),
|
|
381
|
-
addPointerEvent(doc, "contextmenu", onPointerUp, false),
|
|
382
|
-
disableTextSelection({ doc })
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
46
|
// src/slider.connect.ts
|
|
47
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
48
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
387
49
|
var import_numeric_range3 = require("@zag-js/numeric-range");
|
|
388
50
|
|
|
389
|
-
// ../../utilities/form-utils/src/input-event.ts
|
|
390
|
-
function getDescriptor(el, options) {
|
|
391
|
-
const { type, property = "value" } = options;
|
|
392
|
-
const proto = getWindow(el)[type].prototype;
|
|
393
|
-
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
394
|
-
}
|
|
395
|
-
function dispatchInputValueEvent(el, value) {
|
|
396
|
-
if (!el)
|
|
397
|
-
return;
|
|
398
|
-
const win = getWindow(el);
|
|
399
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
400
|
-
return;
|
|
401
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
402
|
-
desc.set?.call(el, value);
|
|
403
|
-
const event = new win.Event("input", { bubbles: true });
|
|
404
|
-
el.dispatchEvent(event);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// ../../utilities/form-utils/src/form.ts
|
|
408
|
-
function getClosestForm(el) {
|
|
409
|
-
if (isFormElement(el))
|
|
410
|
-
return el.form;
|
|
411
|
-
else
|
|
412
|
-
return el.closest("form");
|
|
413
|
-
}
|
|
414
|
-
function isFormElement(el) {
|
|
415
|
-
return el.matches("textarea, input, select, button");
|
|
416
|
-
}
|
|
417
|
-
function trackFormReset(el, callback) {
|
|
418
|
-
if (!el)
|
|
419
|
-
return;
|
|
420
|
-
const form = getClosestForm(el);
|
|
421
|
-
form?.addEventListener("reset", callback, { passive: true });
|
|
422
|
-
return () => {
|
|
423
|
-
form?.removeEventListener("reset", callback);
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
function trackFieldsetDisabled(el, callback) {
|
|
427
|
-
const fieldset = el?.closest("fieldset");
|
|
428
|
-
if (!fieldset)
|
|
429
|
-
return;
|
|
430
|
-
callback(fieldset.disabled);
|
|
431
|
-
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
432
|
-
}
|
|
433
|
-
function trackFormControl(el, options) {
|
|
434
|
-
if (!el)
|
|
435
|
-
return;
|
|
436
|
-
const { onFieldsetDisabled, onFormReset } = options;
|
|
437
|
-
const cleanups = [
|
|
438
|
-
trackFormReset(el, onFormReset),
|
|
439
|
-
trackFieldsetDisabled(el, (disabled) => {
|
|
440
|
-
if (disabled)
|
|
441
|
-
onFieldsetDisabled();
|
|
442
|
-
})
|
|
443
|
-
];
|
|
444
|
-
return () => {
|
|
445
|
-
cleanups.forEach((cleanup) => cleanup?.());
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
51
|
// src/slider.dom.ts
|
|
52
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
53
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
54
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
450
55
|
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
451
56
|
|
|
452
57
|
// src/slider.style.ts
|
|
@@ -562,7 +167,7 @@ var styles = {
|
|
|
562
167
|
};
|
|
563
168
|
|
|
564
169
|
// src/slider.dom.ts
|
|
565
|
-
var dom =
|
|
170
|
+
var dom = (0, import_dom_query.createScope)({
|
|
566
171
|
...styles,
|
|
567
172
|
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
568
173
|
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
@@ -581,7 +186,7 @@ var dom = defineDomHelpers({
|
|
|
581
186
|
const el = dom.getControlEl(ctx);
|
|
582
187
|
if (!el)
|
|
583
188
|
return;
|
|
584
|
-
const relativePoint =
|
|
189
|
+
const relativePoint = (0, import_dom_event.getRelativePointValue)(point, el);
|
|
585
190
|
const percentX = relativePoint.x / el.offsetWidth;
|
|
586
191
|
const percentY = relativePoint.y / el.offsetHeight;
|
|
587
192
|
let percent;
|
|
@@ -596,38 +201,38 @@ var dom = defineDomHelpers({
|
|
|
596
201
|
const input = dom.getHiddenInputEl(ctx);
|
|
597
202
|
if (!input)
|
|
598
203
|
return;
|
|
599
|
-
dispatchInputValueEvent(input, ctx.value);
|
|
204
|
+
(0, import_form_utils.dispatchInputValueEvent)(input, ctx.value);
|
|
600
205
|
}
|
|
601
206
|
});
|
|
602
207
|
|
|
603
208
|
// src/slider.connect.ts
|
|
604
|
-
function connect(
|
|
605
|
-
const ariaLabel =
|
|
606
|
-
const ariaLabelledBy =
|
|
607
|
-
const ariaValueText =
|
|
608
|
-
const isFocused =
|
|
609
|
-
const isDragging =
|
|
610
|
-
const isDisabled =
|
|
611
|
-
const isInteractive =
|
|
612
|
-
const isInvalid =
|
|
209
|
+
function connect(state, send, normalize) {
|
|
210
|
+
const ariaLabel = state.context["aria-label"];
|
|
211
|
+
const ariaLabelledBy = state.context["aria-labelledby"];
|
|
212
|
+
const ariaValueText = state.context.getAriaValueText?.(state.context.value);
|
|
213
|
+
const isFocused = state.matches("focus");
|
|
214
|
+
const isDragging = state.matches("dragging");
|
|
215
|
+
const isDisabled = state.context.disabled;
|
|
216
|
+
const isInteractive = state.context.isInteractive;
|
|
217
|
+
const isInvalid = state.context.invalid;
|
|
613
218
|
function getPercentValueFn(percent) {
|
|
614
|
-
return (0, import_numeric_range3.getPercentValue)(percent,
|
|
219
|
+
return (0, import_numeric_range3.getPercentValue)(percent, state.context.min, state.context.max, state.context.step);
|
|
615
220
|
}
|
|
616
221
|
function getValuePercentFn(value) {
|
|
617
|
-
return (0, import_numeric_range3.getValuePercent)(value,
|
|
222
|
+
return (0, import_numeric_range3.getValuePercent)(value, state.context.min, state.context.max);
|
|
618
223
|
}
|
|
619
224
|
return {
|
|
620
225
|
isFocused,
|
|
621
226
|
isDragging,
|
|
622
|
-
value:
|
|
623
|
-
percent: (0, import_numeric_range3.getValuePercent)(
|
|
227
|
+
value: state.context.value,
|
|
228
|
+
percent: (0, import_numeric_range3.getValuePercent)(state.context.value, state.context.min, state.context.max),
|
|
624
229
|
setValue(value) {
|
|
625
230
|
send({ type: "SET_VALUE", value });
|
|
626
231
|
},
|
|
627
232
|
getPercentValue: getPercentValueFn,
|
|
628
233
|
getValuePercent: getValuePercentFn,
|
|
629
234
|
focus() {
|
|
630
|
-
dom.getThumbEl(
|
|
235
|
+
dom.getThumbEl(state.context)?.focus();
|
|
631
236
|
},
|
|
632
237
|
increment() {
|
|
633
238
|
send("INCREMENT");
|
|
@@ -637,45 +242,45 @@ function connect(state2, send, normalize) {
|
|
|
637
242
|
},
|
|
638
243
|
rootProps: normalize.element({
|
|
639
244
|
...parts.root.attrs,
|
|
640
|
-
"data-disabled": dataAttr(isDisabled),
|
|
641
|
-
"data-focus": dataAttr(isFocused),
|
|
642
|
-
"data-orientation":
|
|
643
|
-
"data-invalid": dataAttr(isInvalid),
|
|
644
|
-
id: dom.getRootId(
|
|
645
|
-
dir:
|
|
646
|
-
style: dom.getRootStyle(
|
|
245
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
246
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
247
|
+
"data-orientation": state.context.orientation,
|
|
248
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
249
|
+
id: dom.getRootId(state.context),
|
|
250
|
+
dir: state.context.dir,
|
|
251
|
+
style: dom.getRootStyle(state.context)
|
|
647
252
|
}),
|
|
648
253
|
labelProps: normalize.label({
|
|
649
254
|
...parts.label.attrs,
|
|
650
|
-
"data-disabled": dataAttr(isDisabled),
|
|
651
|
-
"data-invalid": dataAttr(isInvalid),
|
|
652
|
-
"data-focus": dataAttr(isFocused),
|
|
653
|
-
id: dom.getLabelId(
|
|
654
|
-
htmlFor: dom.getHiddenInputId(
|
|
255
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
256
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
257
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
258
|
+
id: dom.getLabelId(state.context),
|
|
259
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
655
260
|
onClick(event) {
|
|
656
261
|
if (!isInteractive)
|
|
657
262
|
return;
|
|
658
263
|
event.preventDefault();
|
|
659
|
-
dom.getThumbEl(
|
|
264
|
+
dom.getThumbEl(state.context)?.focus();
|
|
660
265
|
},
|
|
661
266
|
style: dom.getLabelStyle()
|
|
662
267
|
}),
|
|
663
268
|
thumbProps: normalize.element({
|
|
664
269
|
...parts.thumb.attrs,
|
|
665
|
-
id: dom.getThumbId(
|
|
666
|
-
"data-disabled": dataAttr(isDisabled),
|
|
667
|
-
"data-orientation":
|
|
668
|
-
"data-focus": dataAttr(isFocused),
|
|
270
|
+
id: dom.getThumbId(state.context),
|
|
271
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
272
|
+
"data-orientation": state.context.orientation,
|
|
273
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
669
274
|
draggable: false,
|
|
670
|
-
"aria-invalid":
|
|
671
|
-
"data-invalid": dataAttr(isInvalid),
|
|
672
|
-
"aria-disabled":
|
|
275
|
+
"aria-invalid": (0, import_dom_query2.ariaAttr)(isInvalid),
|
|
276
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
277
|
+
"aria-disabled": (0, import_dom_query2.ariaAttr)(isDisabled),
|
|
673
278
|
"aria-label": ariaLabel,
|
|
674
|
-
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(
|
|
675
|
-
"aria-orientation":
|
|
676
|
-
"aria-valuemax":
|
|
677
|
-
"aria-valuemin":
|
|
678
|
-
"aria-valuenow":
|
|
279
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state.context),
|
|
280
|
+
"aria-orientation": state.context.orientation,
|
|
281
|
+
"aria-valuemax": state.context.max,
|
|
282
|
+
"aria-valuemin": state.context.min,
|
|
283
|
+
"aria-valuenow": state.context.value,
|
|
679
284
|
"aria-valuetext": ariaValueText,
|
|
680
285
|
role: "slider",
|
|
681
286
|
tabIndex: isDisabled ? void 0 : 0,
|
|
@@ -692,24 +297,24 @@ function connect(state2, send, normalize) {
|
|
|
692
297
|
onKeyDown(event) {
|
|
693
298
|
if (!isInteractive)
|
|
694
299
|
return;
|
|
695
|
-
const step = getEventStep(event) *
|
|
300
|
+
const step = (0, import_dom_event2.getEventStep)(event) * state.context.step;
|
|
696
301
|
let prevent = true;
|
|
697
302
|
const keyMap = {
|
|
698
303
|
ArrowUp() {
|
|
699
304
|
send({ type: "ARROW_UP", step });
|
|
700
|
-
prevent =
|
|
305
|
+
prevent = state.context.isVertical;
|
|
701
306
|
},
|
|
702
307
|
ArrowDown() {
|
|
703
308
|
send({ type: "ARROW_DOWN", step });
|
|
704
|
-
prevent =
|
|
309
|
+
prevent = state.context.isVertical;
|
|
705
310
|
},
|
|
706
311
|
ArrowLeft() {
|
|
707
312
|
send({ type: "ARROW_LEFT", step });
|
|
708
|
-
prevent =
|
|
313
|
+
prevent = state.context.isHorizontal;
|
|
709
314
|
},
|
|
710
315
|
ArrowRight() {
|
|
711
316
|
send({ type: "ARROW_RIGHT", step });
|
|
712
|
-
prevent =
|
|
317
|
+
prevent = state.context.isHorizontal;
|
|
713
318
|
},
|
|
714
319
|
PageUp() {
|
|
715
320
|
send({ type: "PAGE_UP", step });
|
|
@@ -724,7 +329,7 @@ function connect(state2, send, normalize) {
|
|
|
724
329
|
send("END");
|
|
725
330
|
}
|
|
726
331
|
};
|
|
727
|
-
const key = getEventKey(event,
|
|
332
|
+
const key = (0, import_dom_event2.getEventKey)(event, state.context);
|
|
728
333
|
const exec = keyMap[key];
|
|
729
334
|
if (!exec)
|
|
730
335
|
return;
|
|
@@ -733,57 +338,57 @@ function connect(state2, send, normalize) {
|
|
|
733
338
|
event.preventDefault();
|
|
734
339
|
}
|
|
735
340
|
},
|
|
736
|
-
style: dom.getThumbStyle(
|
|
341
|
+
style: dom.getThumbStyle(state.context)
|
|
737
342
|
}),
|
|
738
343
|
hiddenInputProps: normalize.input({
|
|
739
344
|
...parts.hiddenInput.attrs,
|
|
740
345
|
type: "text",
|
|
741
|
-
defaultValue:
|
|
742
|
-
name:
|
|
743
|
-
form:
|
|
744
|
-
id: dom.getHiddenInputId(
|
|
346
|
+
defaultValue: state.context.value,
|
|
347
|
+
name: state.context.name,
|
|
348
|
+
form: state.context.form,
|
|
349
|
+
id: dom.getHiddenInputId(state.context),
|
|
745
350
|
hidden: true
|
|
746
351
|
}),
|
|
747
352
|
outputProps: normalize.output({
|
|
748
353
|
...parts.output.attrs,
|
|
749
|
-
"data-disabled": dataAttr(isDisabled),
|
|
750
|
-
"data-invalid": dataAttr(isInvalid),
|
|
751
|
-
id: dom.getOutputId(
|
|
752
|
-
htmlFor: dom.getHiddenInputId(
|
|
354
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
355
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
356
|
+
id: dom.getOutputId(state.context),
|
|
357
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
753
358
|
"aria-live": "off"
|
|
754
359
|
}),
|
|
755
360
|
trackProps: normalize.element({
|
|
756
361
|
...parts.track.attrs,
|
|
757
|
-
id: dom.getTrackId(
|
|
758
|
-
"data-disabled": dataAttr(isDisabled),
|
|
759
|
-
"data-focus": dataAttr(isFocused),
|
|
760
|
-
"data-invalid": dataAttr(isInvalid),
|
|
761
|
-
"data-orientation":
|
|
362
|
+
id: dom.getTrackId(state.context),
|
|
363
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
364
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
365
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
366
|
+
"data-orientation": state.context.orientation,
|
|
762
367
|
style: dom.getTrackStyle()
|
|
763
368
|
}),
|
|
764
369
|
rangeProps: normalize.element({
|
|
765
370
|
...parts.range.attrs,
|
|
766
|
-
id: dom.getRangeId(
|
|
767
|
-
"data-focus": dataAttr(isFocused),
|
|
768
|
-
"data-invalid": dataAttr(isInvalid),
|
|
769
|
-
"data-disabled": dataAttr(isDisabled),
|
|
770
|
-
"data-orientation":
|
|
771
|
-
style: dom.getRangeStyle(
|
|
371
|
+
id: dom.getRangeId(state.context),
|
|
372
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
373
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
374
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
375
|
+
"data-orientation": state.context.orientation,
|
|
376
|
+
style: dom.getRangeStyle(state.context)
|
|
772
377
|
}),
|
|
773
378
|
controlProps: normalize.element({
|
|
774
379
|
...parts.control.attrs,
|
|
775
|
-
id: dom.getControlId(
|
|
776
|
-
"data-disabled": dataAttr(isDisabled),
|
|
777
|
-
"data-invalid": dataAttr(isInvalid),
|
|
778
|
-
"data-orientation":
|
|
779
|
-
"data-focus": dataAttr(isFocused),
|
|
380
|
+
id: dom.getControlId(state.context),
|
|
381
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
382
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
383
|
+
"data-orientation": state.context.orientation,
|
|
384
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
780
385
|
onPointerDown(event) {
|
|
781
386
|
if (!isInteractive)
|
|
782
387
|
return;
|
|
783
|
-
const evt = getNativeEvent(event);
|
|
784
|
-
if (!isLeftClick(evt) || isModifiedEvent(evt))
|
|
388
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
389
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
785
390
|
return;
|
|
786
|
-
const point =
|
|
391
|
+
const point = { x: evt.clientX, y: evt.clientY };
|
|
787
392
|
send({ type: "POINTER_DOWN", point });
|
|
788
393
|
event.preventDefault();
|
|
789
394
|
event.stopPropagation();
|
|
@@ -794,20 +399,20 @@ function connect(state2, send, normalize) {
|
|
|
794
399
|
...parts.markerGroup.attrs,
|
|
795
400
|
role: "presentation",
|
|
796
401
|
"aria-hidden": true,
|
|
797
|
-
"data-orientation":
|
|
402
|
+
"data-orientation": state.context.orientation,
|
|
798
403
|
style: dom.getMarkerGroupStyle()
|
|
799
404
|
}),
|
|
800
405
|
getMarkerProps({ value }) {
|
|
801
406
|
const percent = getValuePercentFn(value);
|
|
802
|
-
const style = dom.getMarkerStyle(
|
|
803
|
-
const markerState = value >
|
|
407
|
+
const style = dom.getMarkerStyle(state.context, percent);
|
|
408
|
+
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
804
409
|
return normalize.element({
|
|
805
410
|
...parts.marker.attrs,
|
|
806
411
|
role: "presentation",
|
|
807
|
-
"data-orientation":
|
|
808
|
-
id: dom.getMarkerId(
|
|
412
|
+
"data-orientation": state.context.orientation,
|
|
413
|
+
id: dom.getMarkerId(state.context, value),
|
|
809
414
|
"data-value": value,
|
|
810
|
-
"data-disabled": dataAttr(isDisabled),
|
|
415
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
811
416
|
"data-state": markerState,
|
|
812
417
|
style
|
|
813
418
|
});
|
|
@@ -817,8 +422,12 @@ function connect(state2, send, normalize) {
|
|
|
817
422
|
|
|
818
423
|
// src/slider.machine.ts
|
|
819
424
|
var import_core = require("@zag-js/core");
|
|
425
|
+
var import_dom_event3 = require("@zag-js/dom-event");
|
|
426
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
820
427
|
var import_element_size = require("@zag-js/element-size");
|
|
428
|
+
var import_form_utils2 = require("@zag-js/form-utils");
|
|
821
429
|
var import_numeric_range5 = require("@zag-js/numeric-range");
|
|
430
|
+
var import_utils = require("@zag-js/utils");
|
|
822
431
|
|
|
823
432
|
// src/slider.utils.ts
|
|
824
433
|
var import_numeric_range4 = require("@zag-js/numeric-range");
|
|
@@ -847,7 +456,7 @@ function increment(ctx, step) {
|
|
|
847
456
|
|
|
848
457
|
// src/slider.machine.ts
|
|
849
458
|
function machine(userContext) {
|
|
850
|
-
const ctx = compact(userContext);
|
|
459
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
851
460
|
return (0, import_core.createMachine)(
|
|
852
461
|
{
|
|
853
462
|
id: "slider",
|
|
@@ -961,7 +570,7 @@ function machine(userContext) {
|
|
|
961
570
|
},
|
|
962
571
|
activities: {
|
|
963
572
|
trackFormControlState(ctx2) {
|
|
964
|
-
return trackFormControl(dom.getHiddenInputEl(ctx2), {
|
|
573
|
+
return (0, import_form_utils2.trackFormControl)(dom.getHiddenInputEl(ctx2), {
|
|
965
574
|
onFieldsetDisabled() {
|
|
966
575
|
ctx2.disabled = true;
|
|
967
576
|
},
|
|
@@ -973,7 +582,7 @@ function machine(userContext) {
|
|
|
973
582
|
});
|
|
974
583
|
},
|
|
975
584
|
trackPointerMove(ctx2, _evt, { send }) {
|
|
976
|
-
return trackPointerMove(dom.getDoc(ctx2), {
|
|
585
|
+
return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
|
|
977
586
|
onPointerMove(info) {
|
|
978
587
|
send({ type: "POINTER_MOVE", point: info.point });
|
|
979
588
|
},
|
|
@@ -1016,7 +625,7 @@ function machine(userContext) {
|
|
|
1016
625
|
ctx2.value = (0, import_numeric_range5.clampValue)(value, ctx2.min, ctx2.max);
|
|
1017
626
|
},
|
|
1018
627
|
focusThumb(ctx2) {
|
|
1019
|
-
raf(() => dom.getThumbEl(ctx2)?.focus());
|
|
628
|
+
(0, import_dom_query3.raf)(() => dom.getThumbEl(ctx2)?.focus());
|
|
1020
629
|
},
|
|
1021
630
|
decrement(ctx2, evt) {
|
|
1022
631
|
ctx2.value = decrement(ctx2, evt.step);
|