@zag-js/slider 0.0.0-dev-20220627111117 → 0.0.0-dev-20220628115342
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 +48 -38
- package/dist/index.mjs +48 -38
- package/dist/slider.connect.d.ts +2 -2
- package/dist/slider.dom.d.ts +9 -10
- package/dist/slider.types.d.ts +4 -0
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -72,8 +72,6 @@ var runIfFn = (v, ...a) => {
|
|
|
72
72
|
const res = typeof v === "function" ? v(...a) : v;
|
|
73
73
|
return res != null ? res : void 0;
|
|
74
74
|
};
|
|
75
|
-
var noop = () => {
|
|
76
|
-
};
|
|
77
75
|
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
78
76
|
var isRef = (v) => hasProp(v, "current");
|
|
79
77
|
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
@@ -168,7 +166,7 @@ function getNativeEvent(e) {
|
|
|
168
166
|
}
|
|
169
167
|
function observeAttributes(node, attributes, fn) {
|
|
170
168
|
if (!node)
|
|
171
|
-
return
|
|
169
|
+
return;
|
|
172
170
|
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
173
171
|
const win = node.ownerDocument.defaultView || window;
|
|
174
172
|
const obs = new win.MutationObserver((changes) => {
|
|
@@ -206,6 +204,45 @@ function trackFieldsetDisabled(el, callback) {
|
|
|
206
204
|
callback(fieldset.disabled);
|
|
207
205
|
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
208
206
|
}
|
|
207
|
+
function getElementOffset(element) {
|
|
208
|
+
let left = 0;
|
|
209
|
+
let top = 0;
|
|
210
|
+
let el = element;
|
|
211
|
+
if (el.parentNode) {
|
|
212
|
+
do {
|
|
213
|
+
left += el.offsetLeft;
|
|
214
|
+
top += el.offsetTop;
|
|
215
|
+
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
216
|
+
el = element;
|
|
217
|
+
do {
|
|
218
|
+
left -= el.scrollLeft;
|
|
219
|
+
top -= el.scrollTop;
|
|
220
|
+
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
top,
|
|
224
|
+
right: innerWidth - left - element.offsetWidth,
|
|
225
|
+
bottom: innerHeight - top - element.offsetHeight,
|
|
226
|
+
left
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
var fallback2 = {
|
|
230
|
+
pageX: 0,
|
|
231
|
+
pageY: 0,
|
|
232
|
+
clientX: 0,
|
|
233
|
+
clientY: 0
|
|
234
|
+
};
|
|
235
|
+
function getEventPoint(event, type = "page") {
|
|
236
|
+
var _a, _b;
|
|
237
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback2 : event;
|
|
238
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
239
|
+
}
|
|
240
|
+
function getPointRelativeToNode(point, element) {
|
|
241
|
+
const offset = getElementOffset(element);
|
|
242
|
+
const x = point.x - offset.left;
|
|
243
|
+
const y = point.y - offset.top;
|
|
244
|
+
return { x, y };
|
|
245
|
+
}
|
|
209
246
|
function getDescriptor(el, options) {
|
|
210
247
|
var _a;
|
|
211
248
|
const { type, property } = options;
|
|
@@ -323,25 +360,6 @@ function trackPointerMove(opts) {
|
|
|
323
360
|
return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
|
|
324
361
|
}
|
|
325
362
|
|
|
326
|
-
// ../../utilities/rect/dist/index.mjs
|
|
327
|
-
var isArray2 = (v) => Array.isArray(v);
|
|
328
|
-
var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
|
|
329
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
330
|
-
var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
|
|
331
|
-
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
332
|
-
function getEventPoint(e, t = "page") {
|
|
333
|
-
const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
|
|
334
|
-
return { x: p[`${t}X`], y: p[`${t}Y`] };
|
|
335
|
-
}
|
|
336
|
-
function relativeToNode(p, el) {
|
|
337
|
-
const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
|
|
338
|
-
const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
|
|
339
|
-
return {
|
|
340
|
-
point: { x: dx, y: dy },
|
|
341
|
-
progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
|
|
345
363
|
// ../../utilities/number/dist/index.mjs
|
|
346
364
|
var __pow2 = Math.pow;
|
|
347
365
|
function round(v, t) {
|
|
@@ -575,15 +593,17 @@ var dom = __spreadProps(__spreadValues({}, styles), {
|
|
|
575
593
|
getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
|
|
576
594
|
getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
|
|
577
595
|
getValueFromPoint(ctx, point) {
|
|
578
|
-
const
|
|
579
|
-
if (!
|
|
596
|
+
const el = dom.getControlEl(ctx);
|
|
597
|
+
if (!el)
|
|
580
598
|
return;
|
|
581
|
-
const
|
|
599
|
+
const relativePoint = getPointRelativeToNode(point, el);
|
|
600
|
+
const percentX = relativePoint.x / el.offsetWidth;
|
|
601
|
+
const percentY = relativePoint.y / el.offsetHeight;
|
|
582
602
|
let percent;
|
|
583
603
|
if (ctx.isHorizontal) {
|
|
584
|
-
percent = ctx.isRtl ? 1 -
|
|
604
|
+
percent = ctx.isRtl ? 1 - percentX : percentX;
|
|
585
605
|
} else {
|
|
586
|
-
percent = 1 -
|
|
606
|
+
percent = 1 - percentY;
|
|
587
607
|
}
|
|
588
608
|
return utils.fromPercent(ctx, percent);
|
|
589
609
|
},
|
|
@@ -595,22 +615,12 @@ var dom = __spreadProps(__spreadValues({}, styles), {
|
|
|
595
615
|
}
|
|
596
616
|
});
|
|
597
617
|
|
|
598
|
-
// ../../types/dist/index.mjs
|
|
599
|
-
function createNormalizer(fn) {
|
|
600
|
-
return new Proxy({}, {
|
|
601
|
-
get() {
|
|
602
|
-
return fn;
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
var normalizeProp = createNormalizer((v) => v);
|
|
607
|
-
|
|
608
618
|
// ../../utilities/core/dist/index.mjs
|
|
609
619
|
var isLeftClick2 = (v) => v.button === 0;
|
|
610
620
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
611
621
|
|
|
612
622
|
// src/slider.connect.ts
|
|
613
|
-
function connect(state2, send, normalize
|
|
623
|
+
function connect(state2, send, normalize) {
|
|
614
624
|
var _a, _b;
|
|
615
625
|
const ariaLabel = state2.context["aria-label"];
|
|
616
626
|
const ariaLabelledBy = state2.context["aria-labelledby"];
|
package/dist/index.mjs
CHANGED
|
@@ -48,8 +48,6 @@ var runIfFn = (v, ...a) => {
|
|
|
48
48
|
const res = typeof v === "function" ? v(...a) : v;
|
|
49
49
|
return res != null ? res : void 0;
|
|
50
50
|
};
|
|
51
|
-
var noop = () => {
|
|
52
|
-
};
|
|
53
51
|
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
54
52
|
var isRef = (v) => hasProp(v, "current");
|
|
55
53
|
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
@@ -144,7 +142,7 @@ function getNativeEvent(e) {
|
|
|
144
142
|
}
|
|
145
143
|
function observeAttributes(node, attributes, fn) {
|
|
146
144
|
if (!node)
|
|
147
|
-
return
|
|
145
|
+
return;
|
|
148
146
|
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
149
147
|
const win = node.ownerDocument.defaultView || window;
|
|
150
148
|
const obs = new win.MutationObserver((changes) => {
|
|
@@ -182,6 +180,45 @@ function trackFieldsetDisabled(el, callback) {
|
|
|
182
180
|
callback(fieldset.disabled);
|
|
183
181
|
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
184
182
|
}
|
|
183
|
+
function getElementOffset(element) {
|
|
184
|
+
let left = 0;
|
|
185
|
+
let top = 0;
|
|
186
|
+
let el = element;
|
|
187
|
+
if (el.parentNode) {
|
|
188
|
+
do {
|
|
189
|
+
left += el.offsetLeft;
|
|
190
|
+
top += el.offsetTop;
|
|
191
|
+
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
192
|
+
el = element;
|
|
193
|
+
do {
|
|
194
|
+
left -= el.scrollLeft;
|
|
195
|
+
top -= el.scrollTop;
|
|
196
|
+
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
top,
|
|
200
|
+
right: innerWidth - left - element.offsetWidth,
|
|
201
|
+
bottom: innerHeight - top - element.offsetHeight,
|
|
202
|
+
left
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
var fallback2 = {
|
|
206
|
+
pageX: 0,
|
|
207
|
+
pageY: 0,
|
|
208
|
+
clientX: 0,
|
|
209
|
+
clientY: 0
|
|
210
|
+
};
|
|
211
|
+
function getEventPoint(event, type = "page") {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback2 : event;
|
|
214
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
215
|
+
}
|
|
216
|
+
function getPointRelativeToNode(point, element) {
|
|
217
|
+
const offset = getElementOffset(element);
|
|
218
|
+
const x = point.x - offset.left;
|
|
219
|
+
const y = point.y - offset.top;
|
|
220
|
+
return { x, y };
|
|
221
|
+
}
|
|
185
222
|
function getDescriptor(el, options) {
|
|
186
223
|
var _a;
|
|
187
224
|
const { type, property } = options;
|
|
@@ -299,25 +336,6 @@ function trackPointerMove(opts) {
|
|
|
299
336
|
return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
|
|
300
337
|
}
|
|
301
338
|
|
|
302
|
-
// ../../utilities/rect/dist/index.mjs
|
|
303
|
-
var isArray2 = (v) => Array.isArray(v);
|
|
304
|
-
var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
|
|
305
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
306
|
-
var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
|
|
307
|
-
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
308
|
-
function getEventPoint(e, t = "page") {
|
|
309
|
-
const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
|
|
310
|
-
return { x: p[`${t}X`], y: p[`${t}Y`] };
|
|
311
|
-
}
|
|
312
|
-
function relativeToNode(p, el) {
|
|
313
|
-
const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
|
|
314
|
-
const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
|
|
315
|
-
return {
|
|
316
|
-
point: { x: dx, y: dy },
|
|
317
|
-
progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
339
|
// ../../utilities/number/dist/index.mjs
|
|
322
340
|
var __pow2 = Math.pow;
|
|
323
341
|
function round(v, t) {
|
|
@@ -551,15 +569,17 @@ var dom = __spreadProps(__spreadValues({}, styles), {
|
|
|
551
569
|
getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
|
|
552
570
|
getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
|
|
553
571
|
getValueFromPoint(ctx, point) {
|
|
554
|
-
const
|
|
555
|
-
if (!
|
|
572
|
+
const el = dom.getControlEl(ctx);
|
|
573
|
+
if (!el)
|
|
556
574
|
return;
|
|
557
|
-
const
|
|
575
|
+
const relativePoint = getPointRelativeToNode(point, el);
|
|
576
|
+
const percentX = relativePoint.x / el.offsetWidth;
|
|
577
|
+
const percentY = relativePoint.y / el.offsetHeight;
|
|
558
578
|
let percent;
|
|
559
579
|
if (ctx.isHorizontal) {
|
|
560
|
-
percent = ctx.isRtl ? 1 -
|
|
580
|
+
percent = ctx.isRtl ? 1 - percentX : percentX;
|
|
561
581
|
} else {
|
|
562
|
-
percent = 1 -
|
|
582
|
+
percent = 1 - percentY;
|
|
563
583
|
}
|
|
564
584
|
return utils.fromPercent(ctx, percent);
|
|
565
585
|
},
|
|
@@ -571,22 +591,12 @@ var dom = __spreadProps(__spreadValues({}, styles), {
|
|
|
571
591
|
}
|
|
572
592
|
});
|
|
573
593
|
|
|
574
|
-
// ../../types/dist/index.mjs
|
|
575
|
-
function createNormalizer(fn) {
|
|
576
|
-
return new Proxy({}, {
|
|
577
|
-
get() {
|
|
578
|
-
return fn;
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
var normalizeProp = createNormalizer((v) => v);
|
|
583
|
-
|
|
584
594
|
// ../../utilities/core/dist/index.mjs
|
|
585
595
|
var isLeftClick2 = (v) => v.button === 0;
|
|
586
596
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
587
597
|
|
|
588
598
|
// src/slider.connect.ts
|
|
589
|
-
function connect(state2, send, normalize
|
|
599
|
+
function connect(state2, send, normalize) {
|
|
590
600
|
var _a, _b;
|
|
591
601
|
const ariaLabel = state2.context["aria-label"];
|
|
592
602
|
const ariaLabelledBy = state2.context["aria-labelledby"];
|
package/dist/slider.connect.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
2
|
import type { Send, State } from "./slider.types";
|
|
3
|
-
export declare function connect<T extends PropTypes
|
|
3
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
4
|
isFocused: boolean;
|
|
5
5
|
isDragging: boolean;
|
|
6
6
|
value: number;
|
package/dist/slider.dom.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Point } from "
|
|
2
|
-
import type { MachineContext as Ctx } from "./slider.types";
|
|
1
|
+
import type { MachineContext as Ctx, Point } from "./slider.types";
|
|
3
2
|
export declare const dom: {
|
|
4
3
|
getDoc: (ctx: Ctx) => Document;
|
|
5
4
|
getRootNode: (ctx: Ctx) => Document | ShadowRoot;
|
|
@@ -19,12 +18,12 @@ export declare const dom: {
|
|
|
19
18
|
getValueFromPoint(ctx: Ctx, point: Point): number | undefined;
|
|
20
19
|
dispatchChangeEvent(ctx: Ctx): void;
|
|
21
20
|
getThumbOffset: (ctx: import("./slider.types").SharedContext) => string;
|
|
22
|
-
getControlStyle: () =>
|
|
23
|
-
getThumbStyle: (ctx: import("./slider.types").SharedContext) =>
|
|
24
|
-
getRangeStyle: (ctx: Pick<import("./slider.types").SharedContext, "isVertical" | "isRtl">) =>
|
|
25
|
-
getRootStyle: (ctx: Ctx) =>
|
|
26
|
-
getMarkerStyle: (ctx: Pick<import("./slider.types").SharedContext, "isHorizontal" | "isRtl">, percent: number) =>
|
|
27
|
-
getLabelStyle: () =>
|
|
28
|
-
getTrackStyle: () =>
|
|
29
|
-
getMarkerGroupStyle: () =>
|
|
21
|
+
getControlStyle: () => JSX.CSSProperties;
|
|
22
|
+
getThumbStyle: (ctx: import("./slider.types").SharedContext) => JSX.CSSProperties;
|
|
23
|
+
getRangeStyle: (ctx: Pick<import("./slider.types").SharedContext, "isVertical" | "isRtl">) => JSX.CSSProperties;
|
|
24
|
+
getRootStyle: (ctx: Ctx) => JSX.CSSProperties;
|
|
25
|
+
getMarkerStyle: (ctx: Pick<import("./slider.types").SharedContext, "isHorizontal" | "isRtl">, percent: number) => JSX.CSSProperties;
|
|
26
|
+
getLabelStyle: () => JSX.CSSProperties;
|
|
27
|
+
getTrackStyle: () => JSX.CSSProperties;
|
|
28
|
+
getMarkerGroupStyle: () => JSX.CSSProperties;
|
|
30
29
|
};
|
package/dist/slider.types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/slider",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220628115342",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,11 +29,10 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.0.0-dev-
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.0.0-dev-20220628115342",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220628115342",
|
|
34
34
|
"@zag-js/number-utils": "0.1.2",
|
|
35
|
-
"@zag-js/
|
|
36
|
-
"@zag-js/types": "0.2.0",
|
|
35
|
+
"@zag-js/types": "0.0.0-dev-20220628115342",
|
|
37
36
|
"@zag-js/utils": "0.1.2"
|
|
38
37
|
},
|
|
39
38
|
"scripts": {
|