@zag-js/slider 0.0.0-dev-20220626175355 → 0.0.0-dev-20220627213111
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 +47 -27
- package/dist/index.mjs +47 -27
- package/dist/slider.dom.d.ts +1 -2
- package/dist/slider.types.d.ts +4 -0
- package/package.json +3 -4
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
|
},
|
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
|
},
|
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;
|
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-20220627213111",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,10 +29,9 @@
|
|
|
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-20220627213111",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220627213111",
|
|
34
34
|
"@zag-js/number-utils": "0.1.2",
|
|
35
|
-
"@zag-js/rect-utils": "0.1.2",
|
|
36
35
|
"@zag-js/types": "0.2.0",
|
|
37
36
|
"@zag-js/utils": "0.1.2"
|
|
38
37
|
},
|