@zag-js/slider 0.1.4 → 0.1.7
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/index.js +96 -83
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +96 -83
- package/dist/index.mjs.map +3 -3
- package/dist/slider.dom.d.ts +1 -0
- package/dist/slider.dom.d.ts.map +1 -1
- package/dist/slider.machine.d.ts.map +1 -1
- package/dist/slider.types.d.ts +6 -5
- package/dist/slider.types.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -66,19 +66,33 @@ function raf(fn) {
|
|
|
66
66
|
globalThis.cancelAnimationFrame(id);
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
var
|
|
70
|
-
};
|
|
71
|
-
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
72
|
-
var platform = (v) => isDom() && v.test(navigator.platform);
|
|
73
|
-
var isDom = () => !!(typeof window !== "undefined");
|
|
74
|
-
var isMac = () => platform(/^Mac/);
|
|
75
|
-
var isIPhone = () => platform(/^iPhone/);
|
|
76
|
-
var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
|
|
77
|
-
var isIos = () => isIPhone() || isIPad();
|
|
69
|
+
var isDom = () => typeof window !== "undefined";
|
|
78
70
|
var isArray = (v) => Array.isArray(v);
|
|
79
71
|
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
80
|
-
var
|
|
72
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
73
|
+
function getPlatform() {
|
|
74
|
+
var _a;
|
|
75
|
+
const agent = navigator.userAgentData;
|
|
76
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
77
|
+
}
|
|
78
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
79
|
+
var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
|
|
80
|
+
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
81
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
82
|
+
var isIos = () => isApple() && !isMac();
|
|
83
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
84
|
+
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
85
|
+
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
86
|
+
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
87
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
81
88
|
var isLeftClick = (v) => v.button === 0;
|
|
89
|
+
var runIfFn = (v, ...a) => {
|
|
90
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
91
|
+
return res != null ? res : void 0;
|
|
92
|
+
};
|
|
93
|
+
var noop = () => {
|
|
94
|
+
};
|
|
95
|
+
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
82
96
|
function getListenerElements() {
|
|
83
97
|
;
|
|
84
98
|
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
|
|
@@ -89,7 +103,7 @@ function getListenerCache() {
|
|
|
89
103
|
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
90
104
|
return globalThis.__listenerCache__;
|
|
91
105
|
}
|
|
92
|
-
function
|
|
106
|
+
function addGlobalEventListener(node, type, handler, options) {
|
|
93
107
|
var _a;
|
|
94
108
|
if (!node)
|
|
95
109
|
return noop;
|
|
@@ -141,10 +155,7 @@ function globalEventBus(node, type, handler, options) {
|
|
|
141
155
|
}
|
|
142
156
|
};
|
|
143
157
|
}
|
|
144
|
-
var
|
|
145
|
-
var isRef = (v) => t(v) === "Object" && "current" in v;
|
|
146
|
-
var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
|
|
147
|
-
var isTouchEvent = (v) => t(v) === "Object" && !!v.touches;
|
|
158
|
+
var isRef = (v) => hasProp(v, "current");
|
|
148
159
|
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
149
160
|
function extractInfo(event, type = "page") {
|
|
150
161
|
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
|
|
@@ -157,7 +168,7 @@ function extractInfo(event, type = "page") {
|
|
|
157
168
|
}
|
|
158
169
|
function addDomEvent(target, event, listener, options) {
|
|
159
170
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
160
|
-
return
|
|
171
|
+
return addGlobalEventListener(node, event, listener, options);
|
|
161
172
|
}
|
|
162
173
|
function addPointerEvent(target, event, listener, options) {
|
|
163
174
|
var _a;
|
|
@@ -180,9 +191,6 @@ function filterPrimaryPointer(fn) {
|
|
|
180
191
|
fn(event);
|
|
181
192
|
};
|
|
182
193
|
}
|
|
183
|
-
var supportsPointerEvent = () => typeof window !== "undefined" && window.onpointerdown === null;
|
|
184
|
-
var supportsTouchEvent = () => typeof window !== "undefined" && window.ontouchstart === null;
|
|
185
|
-
var supportsMouseEvent = () => typeof window !== "undefined" && window.onmousedown === null;
|
|
186
194
|
var mouseEventNames = {
|
|
187
195
|
pointerdown: "mousedown",
|
|
188
196
|
pointermove: "mousemove",
|
|
@@ -212,66 +220,68 @@ function getOwnerWindow(el) {
|
|
|
212
220
|
var _a;
|
|
213
221
|
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
214
222
|
}
|
|
215
|
-
function getNativeEvent(
|
|
223
|
+
function getNativeEvent(e) {
|
|
216
224
|
var _a;
|
|
217
|
-
return (_a =
|
|
218
|
-
}
|
|
219
|
-
function getDescriptor(el, options) {
|
|
220
|
-
var _a;
|
|
221
|
-
const { type, property } = options;
|
|
222
|
-
const win = getOwnerWindow(el);
|
|
223
|
-
const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
|
|
224
|
-
const proto = win[_type].prototype;
|
|
225
|
-
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
225
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
226
226
|
}
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
function trackInputPropertyMutation(el, options) {
|
|
238
|
-
const { fn, property, type } = options;
|
|
239
|
-
if (!fn || !el)
|
|
240
|
-
return;
|
|
241
|
-
const { get, set } = getDescriptor(el, { property, type });
|
|
242
|
-
let run = true;
|
|
243
|
-
Object.defineProperty(el, property, {
|
|
244
|
-
get() {
|
|
245
|
-
return get == null ? void 0 : get.call(this);
|
|
246
|
-
},
|
|
247
|
-
set(value) {
|
|
248
|
-
if (run)
|
|
249
|
-
fn(value);
|
|
250
|
-
return set == null ? void 0 : set.call(this, value);
|
|
227
|
+
function observeAttributes(node, attributes, fn) {
|
|
228
|
+
if (!node)
|
|
229
|
+
return noop;
|
|
230
|
+
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
231
|
+
const win = node.ownerDocument.defaultView || window;
|
|
232
|
+
const obs = new win.MutationObserver((changes) => {
|
|
233
|
+
for (const change of changes) {
|
|
234
|
+
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
235
|
+
fn(change);
|
|
236
|
+
}
|
|
251
237
|
}
|
|
252
238
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
};
|
|
239
|
+
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
240
|
+
return () => obs.disconnect();
|
|
256
241
|
}
|
|
257
|
-
function
|
|
242
|
+
function getClosestForm(el) {
|
|
258
243
|
if (isFormElement(el))
|
|
259
244
|
return el.form;
|
|
260
245
|
else
|
|
261
246
|
return el.closest("form");
|
|
262
247
|
}
|
|
263
248
|
function isFormElement(el) {
|
|
264
|
-
return
|
|
249
|
+
return el.matches("textarea, input, select, button");
|
|
265
250
|
}
|
|
266
251
|
function trackFormReset(el, callback) {
|
|
267
252
|
if (!el)
|
|
268
253
|
return;
|
|
269
|
-
const form =
|
|
254
|
+
const form = getClosestForm(el);
|
|
270
255
|
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
|
|
271
256
|
return () => {
|
|
272
257
|
form == null ? void 0 : form.removeEventListener("reset", callback);
|
|
273
258
|
};
|
|
274
259
|
}
|
|
260
|
+
function trackFieldsetDisabled(el, callback) {
|
|
261
|
+
const fieldset = el == null ? void 0 : el.closest("fieldset");
|
|
262
|
+
if (!fieldset)
|
|
263
|
+
return;
|
|
264
|
+
callback(fieldset.disabled);
|
|
265
|
+
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
266
|
+
}
|
|
267
|
+
function getDescriptor(el, options) {
|
|
268
|
+
var _a;
|
|
269
|
+
const { type, property } = options;
|
|
270
|
+
const win = getOwnerWindow(el);
|
|
271
|
+
const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
|
|
272
|
+
const proto = win[_type].prototype;
|
|
273
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
274
|
+
}
|
|
275
|
+
function dispatchInputValueEvent(el, value) {
|
|
276
|
+
var _a;
|
|
277
|
+
const win = getOwnerWindow(el);
|
|
278
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
279
|
+
return;
|
|
280
|
+
const desc = getDescriptor(el, { type: "input", property: "value" });
|
|
281
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
282
|
+
const event = new win.Event("input", { bubbles: true });
|
|
283
|
+
el.dispatchEvent(event);
|
|
284
|
+
}
|
|
275
285
|
var rtlKeyMap = {
|
|
276
286
|
ArrowLeft: "ArrowRight",
|
|
277
287
|
ArrowRight: "ArrowLeft",
|
|
@@ -427,11 +437,11 @@ findByTypeahead.defaultOptions = {
|
|
|
427
437
|
|
|
428
438
|
// ../../utilities/number/dist/index.mjs
|
|
429
439
|
var __pow2 = Math.pow;
|
|
430
|
-
function round(v,
|
|
440
|
+
function round(v, t) {
|
|
431
441
|
let num = valueOf(v);
|
|
432
|
-
const p = __pow2(10,
|
|
442
|
+
const p = __pow2(10, t != null ? t : 10);
|
|
433
443
|
num = Math.round(num * p) / p;
|
|
434
|
-
return
|
|
444
|
+
return t ? num.toFixed(t) : v.toString();
|
|
435
445
|
}
|
|
436
446
|
var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
|
|
437
447
|
var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
|
|
@@ -486,13 +496,16 @@ var transform = (a, b) => {
|
|
|
486
496
|
};
|
|
487
497
|
|
|
488
498
|
// ../../utilities/rect/dist/index.mjs
|
|
499
|
+
var isDom2 = () => typeof window !== "undefined";
|
|
489
500
|
var isArray2 = (v) => Array.isArray(v);
|
|
490
501
|
var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
|
|
491
|
-
var
|
|
502
|
+
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
503
|
+
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
504
|
+
var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
|
|
492
505
|
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
493
|
-
function getEventPoint(e,
|
|
506
|
+
function getEventPoint(e, t = "page") {
|
|
494
507
|
const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
|
|
495
|
-
return { x: p[`${
|
|
508
|
+
return { x: p[`${t}X`], y: p[`${t}Y`] };
|
|
496
509
|
}
|
|
497
510
|
function relativeToNode(p, el) {
|
|
498
511
|
const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
|
|
@@ -628,6 +641,7 @@ var dom = {
|
|
|
628
641
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
|
|
629
642
|
},
|
|
630
643
|
getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
|
|
644
|
+
getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
|
|
631
645
|
getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
|
|
632
646
|
getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
|
|
633
647
|
getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
|
|
@@ -670,11 +684,17 @@ var dom = {
|
|
|
670
684
|
|
|
671
685
|
// ../../types/dist/index.mjs
|
|
672
686
|
function createNormalizer(fn) {
|
|
673
|
-
return {
|
|
687
|
+
return new Proxy({}, {
|
|
688
|
+
get() {
|
|
689
|
+
return fn;
|
|
690
|
+
}
|
|
691
|
+
});
|
|
674
692
|
}
|
|
675
693
|
var normalizeProp = createNormalizer((v) => v);
|
|
676
694
|
|
|
677
695
|
// ../../utilities/core/dist/index.mjs
|
|
696
|
+
var isDom3 = () => typeof window !== "undefined";
|
|
697
|
+
var isTouchDevice3 = isDom3() && !!navigator.maxTouchPoints;
|
|
678
698
|
var isLeftClick2 = (v) => v.button === 0;
|
|
679
699
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
680
700
|
|
|
@@ -920,7 +940,7 @@ function machine(ctx = {}) {
|
|
|
920
940
|
watch: {
|
|
921
941
|
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
922
942
|
},
|
|
923
|
-
activities: ["trackFormReset", "
|
|
943
|
+
activities: ["trackFormReset", "trackFieldsetDisabled"],
|
|
924
944
|
on: {
|
|
925
945
|
SET_VALUE: {
|
|
926
946
|
actions: "setValue"
|
|
@@ -1008,17 +1028,12 @@ function machine(ctx = {}) {
|
|
|
1008
1028
|
isVertical: (ctx2) => ctx2.isVertical
|
|
1009
1029
|
},
|
|
1010
1030
|
activities: {
|
|
1011
|
-
|
|
1031
|
+
trackFieldsetDisabled(ctx2) {
|
|
1012
1032
|
let cleanup;
|
|
1013
1033
|
nextTick(() => {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
cleanup = trackInputPropertyMutation(el, {
|
|
1018
|
-
type: "input",
|
|
1019
|
-
property: "value",
|
|
1020
|
-
fn(value) {
|
|
1021
|
-
send({ type: "SET_VALUE", value: parseFloat(value) });
|
|
1034
|
+
cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
|
|
1035
|
+
if (disabled != ctx2.disabled) {
|
|
1036
|
+
ctx2.disabled = disabled;
|
|
1022
1037
|
}
|
|
1023
1038
|
});
|
|
1024
1039
|
});
|
|
@@ -1027,15 +1042,13 @@ function machine(ctx = {}) {
|
|
|
1027
1042
|
trackFormReset(ctx2) {
|
|
1028
1043
|
let cleanup;
|
|
1029
1044
|
nextTick(() => {
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
return;
|
|
1033
|
-
cleanup = trackFormReset(el, () => {
|
|
1034
|
-
if (ctx2.initialValue != null)
|
|
1045
|
+
cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
|
|
1046
|
+
if (ctx2.initialValue != null) {
|
|
1035
1047
|
ctx2.value = ctx2.initialValue;
|
|
1048
|
+
}
|
|
1036
1049
|
});
|
|
1037
1050
|
});
|
|
1038
|
-
return cleanup;
|
|
1051
|
+
return () => cleanup == null ? void 0 : cleanup();
|
|
1039
1052
|
},
|
|
1040
1053
|
trackPointerMove(ctx2, _evt, { send }) {
|
|
1041
1054
|
return trackPointerMove({
|
|
@@ -1091,7 +1104,7 @@ function machine(ctx = {}) {
|
|
|
1091
1104
|
ctx2.value = utils.clamp(ctx2, value);
|
|
1092
1105
|
},
|
|
1093
1106
|
focusThumb(ctx2) {
|
|
1094
|
-
|
|
1107
|
+
raf(() => {
|
|
1095
1108
|
var _a;
|
|
1096
1109
|
return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
|
|
1097
1110
|
});
|