@zag-js/slider 2.0.0-next.2 → 2.0.0-next.4
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.d.mts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +16 -38
- package/dist/index.mjs +2 -7
- package/dist/slider.anatomy.d.mts +2 -6
- package/dist/slider.anatomy.d.ts +2 -6
- package/dist/slider.anatomy.js +8 -44
- package/dist/slider.anatomy.mjs +4 -18
- package/dist/slider.connect.d.mts +3 -7
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +403 -372
- package/dist/slider.connect.mjs +399 -352
- package/dist/slider.dom.d.mts +15 -30
- package/dist/slider.dom.d.ts +15 -30
- package/dist/slider.dom.js +56 -141
- package/dist/slider.dom.mjs +40 -97
- package/dist/slider.machine.d.mts +2 -7
- package/dist/slider.machine.d.ts +2 -7
- package/dist/slider.machine.js +372 -368
- package/dist/slider.machine.mjs +368 -352
- package/dist/slider.props.d.mts +7 -12
- package/dist/slider.props.d.ts +7 -12
- package/dist/slider.props.js +49 -73
- package/dist/slider.props.mjs +40 -43
- package/dist/slider.style.d.mts +15 -17
- package/dist/slider.style.d.ts +15 -17
- package/dist/slider.style.js +103 -157
- package/dist/slider.style.mjs +91 -124
- package/dist/slider.types.d.mts +402 -377
- package/dist/slider.types.d.ts +402 -377
- package/dist/slider.types.js +4 -18
- package/dist/slider.types.mjs +1 -0
- package/dist/slider.utils.d.mts +23 -27
- package/dist/slider.utils.d.ts +23 -27
- package/dist/slider.utils.js +196 -205
- package/dist/slider.utils.mjs +180 -176
- package/package.json +7 -7
package/dist/slider.types.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/slider.types.ts
|
|
17
|
-
var slider_types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(slider_types_exports);
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
package/dist/slider.types.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/slider.utils.d.mts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { SliderOrigin, SliderSchema, ThumbCollisionBehavior } from "./slider.types.mjs";
|
|
2
|
+
import { Params } from "@zag-js/core";
|
|
3
|
+
import { Size } from "@zag-js/types";
|
|
5
4
|
type Ctx = Params<SliderSchema>;
|
|
6
5
|
interface ThumbCollisionResult {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
values: number[];
|
|
7
|
+
index: number;
|
|
8
|
+
swapped: boolean;
|
|
10
9
|
}
|
|
11
|
-
declare function resolveThumbCollision(behavior: ThumbCollisionBehavior, index: number, value: number, values: number[], min: number, max: number, step: number, minStepsBetweenThumbs: number, startValue?: number): ThumbCollisionResult;
|
|
12
|
-
declare function normalizeValues(params: Ctx, nextValues: number[]): number[];
|
|
13
|
-
declare function getRangeAtIndex(params: Pick<Ctx, "context" | "prop">, index: number): {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export declare function resolveThumbCollision(behavior: ThumbCollisionBehavior, index: number, value: number, values: number[], min: number, max: number, step: number, minStepsBetweenThumbs: number, startValue?: number, disabled?: ReadonlySet<number>): ThumbCollisionResult;
|
|
11
|
+
export declare function normalizeValues(params: Ctx, nextValues: number[]): number[];
|
|
12
|
+
export declare function getRangeAtIndex(params: Pick<Ctx, "context" | "prop">, index: number): {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
value: number;
|
|
17
16
|
};
|
|
18
|
-
declare function constrainValue(params: Pick<Ctx, "context" | "prop">, value: number, index: number): number;
|
|
19
|
-
declare function
|
|
20
|
-
declare function
|
|
21
|
-
|
|
22
|
-
declare function
|
|
23
|
-
declare function
|
|
17
|
+
export declare function constrainValue(params: Pick<Ctx, "context" | "prop">, value: number, index: number): number;
|
|
18
|
+
export declare function stepThumb(params: Pick<Ctx, "context" | "prop">, delta: number, index?: number): number[];
|
|
19
|
+
export declare function getClosestIndex(params: Pick<Ctx, "context" | "prop">, pointValue: number, disabled?: ReadonlySet<number>): number;
|
|
20
|
+
/** Hand a press on stacked thumbs to the one that can move toward the pointer */
|
|
21
|
+
export declare function resolveStackedThumb(values: number[], index: number, pointValue: number, disabled?: ReadonlySet<number>): number;
|
|
22
|
+
export declare function selectMovableThumb(params: Pick<Ctx, "context" | "prop">, index: number, disabled?: ReadonlySet<number>): number;
|
|
24
23
|
/** Resolves the `origin` prop to a percent position (0-100) within `min`-`max`. */
|
|
25
|
-
declare function getOriginPercent(origin: SliderOrigin, min: number, max: number): number;
|
|
26
|
-
|
|
27
|
-
declare function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { assignArray, constrainValue, decrement, getClosestIndex, getFillRange, getOriginPercent, getRangeAtIndex, increment, normalizeValues, resolveThumbCollision, selectMovableThumb };
|
|
24
|
+
export declare function getOriginPercent(origin: SliderOrigin, min: number, max: number): number;
|
|
25
|
+
export declare function getFillSpan(params: Pick<Ctx, "computed" | "prop">): [number, number];
|
|
26
|
+
export declare function getThumbExtent(params: Pick<Ctx, "context" | "prop">): number;
|
|
27
|
+
export declare const toThumbSize: (size: number | Size | undefined) => Size | null;
|
|
28
|
+
export {};
|
package/dist/slider.utils.d.ts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { SliderOrigin, SliderSchema, ThumbCollisionBehavior } from "./slider.types.js";
|
|
2
|
+
import { Size } from "@zag-js/types";
|
|
3
|
+
import { Params } from "@zag-js/core";
|
|
5
4
|
type Ctx = Params<SliderSchema>;
|
|
6
5
|
interface ThumbCollisionResult {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
values: number[];
|
|
7
|
+
index: number;
|
|
8
|
+
swapped: boolean;
|
|
10
9
|
}
|
|
11
|
-
declare function resolveThumbCollision(behavior: ThumbCollisionBehavior, index: number, value: number, values: number[], min: number, max: number, step: number, minStepsBetweenThumbs: number, startValue?: number): ThumbCollisionResult;
|
|
12
|
-
declare function normalizeValues(params: Ctx, nextValues: number[]): number[];
|
|
13
|
-
declare function getRangeAtIndex(params: Pick<Ctx, "context" | "prop">, index: number): {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export declare function resolveThumbCollision(behavior: ThumbCollisionBehavior, index: number, value: number, values: number[], min: number, max: number, step: number, minStepsBetweenThumbs: number, startValue?: number, disabled?: ReadonlySet<number>): ThumbCollisionResult;
|
|
11
|
+
export declare function normalizeValues(params: Ctx, nextValues: number[]): number[];
|
|
12
|
+
export declare function getRangeAtIndex(params: Pick<Ctx, "context" | "prop">, index: number): {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
value: number;
|
|
17
16
|
};
|
|
18
|
-
declare function constrainValue(params: Pick<Ctx, "context" | "prop">, value: number, index: number): number;
|
|
19
|
-
declare function
|
|
20
|
-
declare function
|
|
21
|
-
|
|
22
|
-
declare function
|
|
23
|
-
declare function
|
|
17
|
+
export declare function constrainValue(params: Pick<Ctx, "context" | "prop">, value: number, index: number): number;
|
|
18
|
+
export declare function stepThumb(params: Pick<Ctx, "context" | "prop">, delta: number, index?: number): number[];
|
|
19
|
+
export declare function getClosestIndex(params: Pick<Ctx, "context" | "prop">, pointValue: number, disabled?: ReadonlySet<number>): number;
|
|
20
|
+
/** Hand a press on stacked thumbs to the one that can move toward the pointer */
|
|
21
|
+
export declare function resolveStackedThumb(values: number[], index: number, pointValue: number, disabled?: ReadonlySet<number>): number;
|
|
22
|
+
export declare function selectMovableThumb(params: Pick<Ctx, "context" | "prop">, index: number, disabled?: ReadonlySet<number>): number;
|
|
24
23
|
/** Resolves the `origin` prop to a percent position (0-100) within `min`-`max`. */
|
|
25
|
-
declare function getOriginPercent(origin: SliderOrigin, min: number, max: number): number;
|
|
26
|
-
|
|
27
|
-
declare function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { assignArray, constrainValue, decrement, getClosestIndex, getFillRange, getOriginPercent, getRangeAtIndex, increment, normalizeValues, resolveThumbCollision, selectMovableThumb };
|
|
24
|
+
export declare function getOriginPercent(origin: SliderOrigin, min: number, max: number): number;
|
|
25
|
+
export declare function getFillSpan(params: Pick<Ctx, "computed" | "prop">): [number, number];
|
|
26
|
+
export declare function getThumbExtent(params: Pick<Ctx, "context" | "prop">): number;
|
|
27
|
+
export declare const toThumbSize: (size: number | Size | undefined) => Size | null;
|
|
28
|
+
export {};
|
package/dist/slider.utils.js
CHANGED
|
@@ -1,222 +1,213 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/slider.utils.ts
|
|
21
|
-
var slider_utils_exports = {};
|
|
22
|
-
__export(slider_utils_exports, {
|
|
23
|
-
assignArray: () => assignArray,
|
|
24
|
-
constrainValue: () => constrainValue,
|
|
25
|
-
decrement: () => decrement,
|
|
26
|
-
getClosestIndex: () => getClosestIndex,
|
|
27
|
-
getFillRange: () => getFillRange,
|
|
28
|
-
getOriginPercent: () => getOriginPercent,
|
|
29
|
-
getRangeAtIndex: () => getRangeAtIndex,
|
|
30
|
-
increment: () => increment,
|
|
31
|
-
normalizeValues: () => normalizeValues,
|
|
32
|
-
resolveThumbCollision: () => resolveThumbCollision,
|
|
33
|
-
selectMovableThumb: () => selectMovableThumb
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
4
|
});
|
|
35
|
-
|
|
36
|
-
|
|
5
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
6
|
+
// src/slider.utils.ts
|
|
7
|
+
const NO_DISABLED = /* @__PURE__ */ new Set();
|
|
37
8
|
function getThumbBounds(ctx) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
9
|
+
const { index, values, min, max, gap } = ctx;
|
|
10
|
+
const prevThumb = values[index - 1];
|
|
11
|
+
const nextThumb = values[index + 1];
|
|
12
|
+
return {
|
|
13
|
+
min: prevThumb != null ? prevThumb + gap : min,
|
|
14
|
+
max: nextThumb != null ? nextThumb - gap : max
|
|
15
|
+
};
|
|
45
16
|
}
|
|
46
17
|
function round(value) {
|
|
47
|
-
|
|
18
|
+
return Math.round(value * 1e10) / 1e10;
|
|
48
19
|
}
|
|
49
20
|
function handleNone(ctx) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
const { index, value, values } = ctx;
|
|
22
|
+
const bounds = getThumbBounds(ctx);
|
|
23
|
+
const nextValues = values.slice();
|
|
24
|
+
nextValues[index] = round((0, _zag_js_utils.clampValue)(value, bounds.min, bounds.max));
|
|
25
|
+
return {
|
|
26
|
+
values: nextValues,
|
|
27
|
+
index,
|
|
28
|
+
swapped: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function getDisabledBounds(ctx) {
|
|
32
|
+
const { index, values, gap, disabled } = ctx;
|
|
33
|
+
let lower = -1e400;
|
|
34
|
+
let upper = 1e400;
|
|
35
|
+
for (let i = index - 1; i >= 0; i--) if (disabled.has(i)) {
|
|
36
|
+
lower = values[i] + (index - i) * gap;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
for (let i = index + 1; i < values.length; i++) if (disabled.has(i)) {
|
|
40
|
+
upper = values[i] - (i - index) * gap;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
lower,
|
|
45
|
+
upper
|
|
46
|
+
};
|
|
55
47
|
}
|
|
56
48
|
function handlePush(ctx) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
49
|
+
const { index, value, values, min, max, gap } = ctx;
|
|
50
|
+
const nextValues = values.slice();
|
|
51
|
+
const walls = getDisabledBounds(ctx);
|
|
52
|
+
const absoluteMin = Math.max(min + index * gap, walls.lower);
|
|
53
|
+
const absoluteMax = Math.min(max - (values.length - 1 - index) * gap, walls.upper);
|
|
54
|
+
nextValues[index] = round((0, _zag_js_utils.clampValue)(value, absoluteMin, absoluteMax));
|
|
55
|
+
for (let i = index + 1; i < values.length; i++) {
|
|
56
|
+
const minAllowed = nextValues[i - 1] + gap;
|
|
57
|
+
if (nextValues[i] < minAllowed) nextValues[i] = round(minAllowed);
|
|
58
|
+
}
|
|
59
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
60
|
+
const maxAllowed = nextValues[i + 1] - gap;
|
|
61
|
+
if (nextValues[i] > maxAllowed) nextValues[i] = round(maxAllowed);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
values: nextValues,
|
|
65
|
+
index,
|
|
66
|
+
swapped: false
|
|
67
|
+
};
|
|
75
68
|
}
|
|
76
69
|
function handleSwap(ctx, startValue) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
70
|
+
const { index, value, values, gap } = ctx;
|
|
71
|
+
const prevThumb = values[index - 1];
|
|
72
|
+
const nextThumb = values[index + 1];
|
|
73
|
+
const crossingNext = nextThumb != null && value >= nextThumb && value > startValue;
|
|
74
|
+
const crossingPrev = prevThumb != null && value <= prevThumb && value < startValue;
|
|
75
|
+
if (!crossingNext && !crossingPrev) return handleNone(ctx);
|
|
76
|
+
const swapIndex = crossingNext ? index + 1 : index - 1;
|
|
77
|
+
if (ctx.disabled.has(swapIndex)) return handleNone(ctx);
|
|
78
|
+
const nextValues = values.slice();
|
|
79
|
+
const bounds = getThumbBounds({
|
|
80
|
+
...ctx,
|
|
81
|
+
index: swapIndex
|
|
82
|
+
});
|
|
83
|
+
nextValues[swapIndex] = round((0, _zag_js_utils.clampValue)(value, bounds.min, bounds.max));
|
|
84
|
+
nextValues[index] = values[swapIndex];
|
|
85
|
+
if (crossingNext && nextValues[index] > nextValues[swapIndex] - gap) nextValues[index] = round(nextValues[swapIndex] - gap);
|
|
86
|
+
else if (crossingPrev && nextValues[index] < nextValues[swapIndex] + gap) nextValues[index] = round(nextValues[swapIndex] + gap);
|
|
87
|
+
return {
|
|
88
|
+
values: nextValues,
|
|
89
|
+
index: swapIndex,
|
|
90
|
+
swapped: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function resolveThumbCollision(behavior, index, value, values, min, max, step, minStepsBetweenThumbs, startValue, disabled = NO_DISABLED) {
|
|
94
|
+
if (values.length === 1) return {
|
|
95
|
+
values: [round((0, _zag_js_utils.clampValue)(value, min, max))],
|
|
96
|
+
index: 0,
|
|
97
|
+
swapped: false
|
|
98
|
+
};
|
|
99
|
+
const ctx = {
|
|
100
|
+
behavior,
|
|
101
|
+
index,
|
|
102
|
+
value,
|
|
103
|
+
values,
|
|
104
|
+
min,
|
|
105
|
+
max,
|
|
106
|
+
gap: step * minStepsBetweenThumbs,
|
|
107
|
+
disabled
|
|
108
|
+
};
|
|
109
|
+
switch (behavior) {
|
|
110
|
+
case "push": return handlePush(ctx);
|
|
111
|
+
case "swap": return handleSwap(ctx, startValue ?? values[index]);
|
|
112
|
+
default: return handleNone(ctx);
|
|
113
|
+
}
|
|
113
114
|
}
|
|
114
115
|
function normalizeValues(params, nextValues) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
return nextValues.map((value, index) => {
|
|
117
|
+
return constrainValue(params, value, index);
|
|
118
|
+
});
|
|
118
119
|
}
|
|
119
120
|
function getRangeAtIndex(params, index) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const { context, prop } = params;
|
|
122
|
+
const step = prop("step") * prop("minStepsBetweenThumbs");
|
|
123
|
+
return (0, _zag_js_utils.getValueRanges)(context.get("value"), prop("min"), prop("max"), step)[index];
|
|
123
124
|
}
|
|
124
125
|
function constrainValue(params, value, index) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const thumbValue = values[index];
|
|
173
|
-
if (thumbValue === max) {
|
|
174
|
-
let movableIndex = index;
|
|
175
|
-
while (movableIndex > 0 && values[movableIndex - 1] === max) {
|
|
176
|
-
movableIndex -= 1;
|
|
177
|
-
}
|
|
178
|
-
return movableIndex;
|
|
179
|
-
}
|
|
180
|
-
return index;
|
|
181
|
-
}
|
|
182
|
-
function assignArray(current, next) {
|
|
183
|
-
for (let i = 0; i < next.length; i++) {
|
|
184
|
-
const value = next[i];
|
|
185
|
-
current[i] = value;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
126
|
+
const { prop } = params;
|
|
127
|
+
const range = getRangeAtIndex(params, index);
|
|
128
|
+
const snapValue = (0, _zag_js_utils.snapValueToStep)(value, prop("min"), prop("max"), prop("step"));
|
|
129
|
+
return (0, _zag_js_utils.clampValue)(snapValue, range.min, range.max);
|
|
130
|
+
}
|
|
131
|
+
function stepThumb(params, delta, index) {
|
|
132
|
+
const { context } = params;
|
|
133
|
+
const idx = index ?? context.get("focusedIndex");
|
|
134
|
+
const values = context.get("value");
|
|
135
|
+
return (0, _zag_js_utils.setValueAtIndex)(values, idx, constrainValue(params, values[idx] + delta, idx));
|
|
136
|
+
}
|
|
137
|
+
function getClosestIndex(params, pointValue, disabled = NO_DISABLED) {
|
|
138
|
+
const { context } = params;
|
|
139
|
+
const values = context.get("value");
|
|
140
|
+
let closestIndex = -1;
|
|
141
|
+
let minDistance = 1e400;
|
|
142
|
+
for (let i = 0; i < values.length; i++) {
|
|
143
|
+
if (disabled.has(i)) continue;
|
|
144
|
+
const distance = Math.abs(values[i] - pointValue);
|
|
145
|
+
if (distance <= minDistance) {
|
|
146
|
+
closestIndex = i;
|
|
147
|
+
minDistance = distance;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return closestIndex === -1 ? -1 : selectMovableThumb(params, closestIndex, disabled);
|
|
151
|
+
}
|
|
152
|
+
/** Hand a press on stacked thumbs to the one that can move toward the pointer */
|
|
153
|
+
function resolveStackedThumb(values, index, pointValue, disabled = NO_DISABLED) {
|
|
154
|
+
const value = values[index];
|
|
155
|
+
const dir = pointValue < value ? -1 : pointValue > value ? 1 : 0;
|
|
156
|
+
if (dir === 0) return index;
|
|
157
|
+
let next = index;
|
|
158
|
+
while (values[next + dir] === value && !disabled.has(next + dir)) next += dir;
|
|
159
|
+
return next;
|
|
160
|
+
}
|
|
161
|
+
function selectMovableThumb(params, index, disabled = NO_DISABLED) {
|
|
162
|
+
const { context, prop } = params;
|
|
163
|
+
const values = context.get("value");
|
|
164
|
+
const max = prop("max");
|
|
165
|
+
if (values[index] === max) {
|
|
166
|
+
let movableIndex = index;
|
|
167
|
+
while (movableIndex > 0 && values[movableIndex - 1] === max && !disabled.has(movableIndex - 1)) movableIndex -= 1;
|
|
168
|
+
return movableIndex;
|
|
169
|
+
}
|
|
170
|
+
return index;
|
|
171
|
+
}
|
|
172
|
+
/** Resolves the `origin` prop to a percent position (0-100) within `min`-`max`. */
|
|
188
173
|
function getOriginPercent(origin, min, max) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
174
|
+
if (typeof origin === "number") return (0, _zag_js_utils.clampValue)(100 * (0, _zag_js_utils.getValuePercent)(origin, min, max), 0, 100);
|
|
175
|
+
switch (origin) {
|
|
176
|
+
case "end": return 100;
|
|
177
|
+
case "center": return 50;
|
|
178
|
+
default: return 0;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function getFillSpan(params) {
|
|
182
|
+
const { computed, prop } = params;
|
|
183
|
+
const percents = computed("valuePercent");
|
|
184
|
+
if (percents.length > 1) return [percents[0], percents[percents.length - 1]];
|
|
185
|
+
const origin = getOriginPercent(prop("origin"), prop("min"), prop("max"));
|
|
186
|
+
const value = percents[0];
|
|
187
|
+
return value < origin ? [value, origin] : [origin, value];
|
|
188
|
+
}
|
|
189
|
+
function getThumbExtent(params) {
|
|
190
|
+
const { context, prop } = params;
|
|
191
|
+
if (prop("thumbAlignment") !== "contain") return 0;
|
|
192
|
+
const size = context.get("thumbSize");
|
|
193
|
+
return (prop("orientation") === "vertical" ? size?.height : size?.width) ?? 0;
|
|
194
|
+
}
|
|
195
|
+
const toThumbSize = (size) => {
|
|
196
|
+
if (size == null) return null;
|
|
197
|
+
return typeof size === "number" ? {
|
|
198
|
+
width: size,
|
|
199
|
+
height: size
|
|
200
|
+
} : size;
|
|
201
|
+
};
|
|
202
|
+
exports.constrainValue = constrainValue;
|
|
203
|
+
exports.getClosestIndex = getClosestIndex;
|
|
204
|
+
exports.getFillSpan = getFillSpan;
|
|
205
|
+
exports.getOriginPercent = getOriginPercent;
|
|
206
|
+
exports.getRangeAtIndex = getRangeAtIndex;
|
|
207
|
+
exports.getThumbExtent = getThumbExtent;
|
|
208
|
+
exports.normalizeValues = normalizeValues;
|
|
209
|
+
exports.resolveStackedThumb = resolveStackedThumb;
|
|
210
|
+
exports.resolveThumbCollision = resolveThumbCollision;
|
|
211
|
+
exports.selectMovableThumb = selectMovableThumb;
|
|
212
|
+
exports.stepThumb = stepThumb;
|
|
213
|
+
exports.toThumbSize = toThumbSize;
|