@zag-js/utils 1.34.1 → 1.35.0

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.mjs CHANGED
@@ -1,545 +1,10 @@
1
- var __defProp = Object.defineProperty;
2
- var __typeError = (msg) => {
3
- throw TypeError(msg);
4
- };
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
9
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
-
11
- // src/array.ts
12
- function toArray(v) {
13
- if (v == null) return [];
14
- return Array.isArray(v) ? v : [v];
15
- }
16
- var fromLength = (length) => Array.from(Array(length).keys());
17
- var first = (v) => v[0];
18
- var last = (v) => v[v.length - 1];
19
- var isEmpty = (v) => v.length === 0;
20
- var has = (v, t) => v.indexOf(t) !== -1;
21
- var add = (v, ...items) => v.concat(items);
22
- var remove = (v, ...items) => v.filter((t) => !items.includes(t));
23
- var removeAt = (v, i) => v.filter((_, idx) => idx !== i);
24
- var insertAt = (v, i, ...items) => [...v.slice(0, i), ...items, ...v.slice(i)];
25
- var uniq = (v) => Array.from(new Set(v));
26
- var diff = (a, b) => {
27
- const set = new Set(b);
28
- return a.filter((t) => !set.has(t));
29
- };
30
- var addOrRemove = (v, item) => has(v, item) ? remove(v, item) : add(v, item);
31
- function clear(v) {
32
- while (v.length > 0) v.pop();
33
- return v;
34
- }
35
- function nextIndex(v, idx, opts = {}) {
36
- const { step = 1, loop = true } = opts;
37
- const next2 = idx + step;
38
- const len = v.length;
39
- const last2 = len - 1;
40
- if (idx === -1) return step > 0 ? 0 : last2;
41
- if (next2 < 0) return loop ? last2 : 0;
42
- if (next2 >= len) return loop ? 0 : idx > len ? len : idx;
43
- return next2;
44
- }
45
- function next(v, idx, opts = {}) {
46
- return v[nextIndex(v, idx, opts)];
47
- }
48
- function prevIndex(v, idx, opts = {}) {
49
- const { step = 1, loop = true } = opts;
50
- return nextIndex(v, idx, { step: -step, loop });
51
- }
52
- function prev(v, index, opts = {}) {
53
- return v[prevIndex(v, index, opts)];
54
- }
55
- function chunk(v, size) {
56
- return v.reduce((rows, value, index) => {
57
- if (index % size === 0) rows.push([value]);
58
- else last(rows)?.push(value);
59
- return rows;
60
- }, []);
61
- }
62
- function flatArray(arr) {
63
- return arr.reduce((flat, item) => {
64
- if (Array.isArray(item)) {
65
- return flat.concat(flatArray(item));
66
- }
67
- return flat.concat(item);
68
- }, []);
69
- }
70
- function partition(arr, fn) {
71
- return arr.reduce(
72
- ([pass, fail], value) => {
73
- if (fn(value)) pass.push(value);
74
- else fail.push(value);
75
- return [pass, fail];
76
- },
77
- [[], []]
78
- );
79
- }
80
-
81
- // src/equal.ts
82
- var isArrayLike = (value) => value?.constructor.name === "Array";
83
- var isArrayEqual = (a, b) => {
84
- if (a.length !== b.length) return false;
85
- for (let i = 0; i < a.length; i++) {
86
- if (!isEqual(a[i], b[i])) return false;
87
- }
88
- return true;
89
- };
90
- var isEqual = (a, b) => {
91
- if (Object.is(a, b)) return true;
92
- if (a == null && b != null || a != null && b == null) return false;
93
- if (typeof a?.isEqual === "function" && typeof b?.isEqual === "function") {
94
- return a.isEqual(b);
95
- }
96
- if (typeof a === "function" && typeof b === "function") {
97
- return a.toString() === b.toString();
98
- }
99
- if (isArrayLike(a) && isArrayLike(b)) {
100
- return isArrayEqual(Array.from(a), Array.from(b));
101
- }
102
- if (!(typeof a === "object") || !(typeof b === "object")) return false;
103
- const keys = Object.keys(b ?? /* @__PURE__ */ Object.create(null));
104
- const length = keys.length;
105
- for (let i = 0; i < length; i++) {
106
- const hasKey = Reflect.has(a, keys[i]);
107
- if (!hasKey) return false;
108
- }
109
- for (let i = 0; i < length; i++) {
110
- const key = keys[i];
111
- if (!isEqual(a[key], b[key])) return false;
112
- }
113
- return true;
114
- };
115
-
116
- // src/guard.ts
117
- var isDev = () => process.env.NODE_ENV !== "production";
118
- var isArray = (v) => Array.isArray(v);
119
- var isBoolean = (v) => v === true || v === false;
120
- var isObjectLike = (v) => v != null && typeof v === "object";
121
- var isObject = (v) => isObjectLike(v) && !isArray(v);
122
- var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
123
- var isString = (v) => typeof v === "string";
124
- var isFunction = (v) => typeof v === "function";
125
- var isNull = (v) => v == null;
126
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
127
- var baseGetTag = (v) => Object.prototype.toString.call(v);
128
- var fnToString = Function.prototype.toString;
129
- var objectCtorString = fnToString.call(Object);
130
- var isPlainObject = (v) => {
131
- if (!isObjectLike(v) || baseGetTag(v) != "[object Object]" || isFrameworkElement(v)) return false;
132
- const proto = Object.getPrototypeOf(v);
133
- if (proto === null) return true;
134
- const Ctor = hasProp(proto, "constructor") && proto.constructor;
135
- return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
136
- };
137
- var isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
138
- var isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
139
- var isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
140
-
141
- // src/functions.ts
142
- var runIfFn = (v, ...a) => {
143
- const res = typeof v === "function" ? v(...a) : v;
144
- return res ?? void 0;
145
- };
146
- var cast = (v) => v;
147
- var identity = (v) => v();
148
- var noop = () => {
149
- };
150
- var callAll = (...fns) => (...a) => {
151
- fns.forEach(function(fn) {
152
- fn?.(...a);
153
- });
154
- };
155
- var uuid = /* @__PURE__ */ (() => {
156
- let id = 0;
157
- return () => {
158
- id++;
159
- return id.toString(36);
160
- };
161
- })();
162
- function match(key, record, ...args) {
163
- if (key in record) {
164
- const fn = record[key];
165
- return isFunction(fn) ? fn(...args) : fn;
166
- }
167
- const error = new Error(`No matching key: ${JSON.stringify(key)} in ${JSON.stringify(Object.keys(record))}`);
168
- Error.captureStackTrace?.(error, match);
169
- throw error;
170
- }
171
- var tryCatch = (fn, fallback) => {
172
- try {
173
- return fn();
174
- } catch (error) {
175
- if (error instanceof Error) {
176
- Error.captureStackTrace?.(error, tryCatch);
177
- }
178
- return fallback?.();
179
- }
180
- };
181
- function throttle(fn, wait = 0) {
182
- let lastCall = 0;
183
- let timeout = null;
184
- return ((...args) => {
185
- const now = Date.now();
186
- const timeSinceLastCall = now - lastCall;
187
- if (timeSinceLastCall >= wait) {
188
- if (timeout) {
189
- clearTimeout(timeout);
190
- timeout = null;
191
- }
192
- fn(...args);
193
- lastCall = now;
194
- } else if (!timeout) {
195
- timeout = setTimeout(() => {
196
- fn(...args);
197
- lastCall = Date.now();
198
- timeout = null;
199
- }, wait - timeSinceLastCall);
200
- }
201
- });
202
- }
203
- function debounce(fn, wait = 0) {
204
- let timeout = null;
205
- return ((...args) => {
206
- if (timeout) {
207
- clearTimeout(timeout);
208
- timeout = null;
209
- }
210
- timeout = setTimeout(() => {
211
- fn(...args);
212
- }, wait);
213
- });
214
- }
215
- var toChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
216
- function toName(code) {
217
- let name = "";
218
- let x;
219
- for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
220
- return toChar(x % 52) + name;
221
- }
222
- function toPhash(h, x) {
223
- let i = x.length;
224
- while (i) h = h * 33 ^ x.charCodeAt(--i);
225
- return h;
226
- }
227
- var hash = (value) => toName(toPhash(5381, value) >>> 0);
228
-
229
- // src/number.ts
230
- var { floor, abs, round, min, max, pow, sign } = Math;
231
- var isNaN = (v) => Number.isNaN(v);
232
- var nan = (v) => isNaN(v) ? 0 : v;
233
- var mod = (v, m) => (v % m + m) % m;
234
- var wrap = (v, vmax) => (v % vmax + vmax) % vmax;
235
- var getMinValueAtIndex = (i, v, vmin) => i === 0 ? vmin : v[i - 1];
236
- var getMaxValueAtIndex = (i, v, vmax) => i === v.length - 1 ? vmax : v[i + 1];
237
- var isValueAtMax = (v, vmax) => nan(v) >= vmax;
238
- var isValueAtMin = (v, vmin) => nan(v) <= vmin;
239
- var isValueWithinRange = (v, vmin, vmax) => {
240
- const value = nan(v);
241
- const minCheck = vmin == null || value >= vmin;
242
- const maxCheck = vmax == null || value <= vmax;
243
- return minCheck && maxCheck;
244
- };
245
- var roundValue = (v, vmin, step) => round((nan(v) - vmin) / step) * step + vmin;
246
- var clampValue = (v, vmin, vmax) => min(max(nan(v), vmin), vmax);
247
- var clampPercent = (v) => clampValue(v, 0, 1);
248
- var getValuePercent = (v, vmin, vmax) => (nan(v) - vmin) / (vmax - vmin);
249
- var getPercentValue = (p, vmin, vmax, step) => clampValue(roundValue(p * (vmax - vmin) + vmin, vmin, step), vmin, vmax);
250
- var roundToStepPrecision = (v, step) => {
251
- let rv = v;
252
- let ss = step.toString();
253
- let pi = ss.indexOf(".");
254
- let p = pi >= 0 ? ss.length - pi : 0;
255
- if (p > 0) {
256
- let pw = pow(10, p);
257
- rv = round(rv * pw) / pw;
258
- }
259
- return rv;
260
- };
261
- var roundToDpr = (v, dpr) => typeof dpr === "number" ? floor(v * dpr + 0.5) / dpr : round(v);
262
- var snapValueToStep = (v, vmin, vmax, step) => {
263
- const min2 = vmin != null ? Number(vmin) : 0;
264
- const max2 = Number(vmax);
265
- const remainder = (v - min2) % step;
266
- let snapped = abs(remainder) * 2 >= step ? v + sign(remainder) * (step - abs(remainder)) : v - remainder;
267
- snapped = roundToStepPrecision(snapped, step);
268
- if (!isNaN(min2) && snapped < min2) {
269
- snapped = min2;
270
- } else if (!isNaN(max2) && snapped > max2) {
271
- const stepsInRange = floor((max2 - min2) / step);
272
- const largestValidStep = min2 + stepsInRange * step;
273
- snapped = stepsInRange <= 0 || largestValidStep < min2 ? max2 : largestValidStep;
274
- }
275
- return roundToStepPrecision(snapped, step);
276
- };
277
- var setValueAtIndex = (vs, i, v) => {
278
- if (vs[i] === v) return vs;
279
- return [...vs.slice(0, i), v, ...vs.slice(i + 1)];
280
- };
281
- function getValueSetterAtIndex(index, ctx) {
282
- const minValueAtIndex = getMinValueAtIndex(index, ctx.values, ctx.min);
283
- const maxValueAtIndex = getMaxValueAtIndex(index, ctx.values, ctx.max);
284
- let nextValues = ctx.values.slice();
285
- return function setValue(value) {
286
- let nextValue = snapValueToStep(value, minValueAtIndex, maxValueAtIndex, ctx.step);
287
- nextValues = setValueAtIndex(nextValues, index, value);
288
- nextValues[index] = nextValue;
289
- return nextValues;
290
- };
291
- }
292
- function getNextStepValue(index, ctx) {
293
- const nextValue = ctx.values[index] + ctx.step;
294
- return getValueSetterAtIndex(index, ctx)(nextValue);
295
- }
296
- function getPreviousStepValue(index, ctx) {
297
- const nextValue = ctx.values[index] - ctx.step;
298
- return getValueSetterAtIndex(index, ctx)(nextValue);
299
- }
300
- var getClosestValueIndex = (vs, t) => {
301
- let i = vs.findIndex((v) => t - v < 0);
302
- if (i === 0) return i;
303
- if (i === -1) return vs.length - 1;
304
- let vLeft = vs[i - 1];
305
- let vRight = vs[i];
306
- if (abs(vLeft - t) < abs(vRight - t)) return i - 1;
307
- return i;
308
- };
309
- var getClosestValue = (vs, t) => vs[getClosestValueIndex(vs, t)];
310
- var getValueRanges = (vs, vmin, vmax, gap) => vs.map((v, i) => ({
311
- min: i === 0 ? vmin : vs[i - 1] + gap,
312
- max: i === vs.length - 1 ? vmax : vs[i + 1] - gap,
313
- value: v
314
- }));
315
- var getValueTransformer = (va, vb) => {
316
- const [a, b] = va;
317
- const [c, d] = vb;
318
- return (v) => a === b || c === d ? c : c + (d - c) / (b - a) * (v - a);
319
- };
320
- var toFixedNumber = (v, d = 0, b = 10) => {
321
- const pow2 = Math.pow(b, d);
322
- return round(v * pow2) / pow2;
323
- };
324
- var countDecimals = (value) => {
325
- if (!Number.isFinite(value)) return 0;
326
- let e = 1, p = 0;
327
- while (Math.round(value * e) / e !== value) {
328
- e *= 10;
329
- p += 1;
330
- }
331
- return p;
332
- };
333
- var decimalOp = (a, op, b) => {
334
- let result = op === "+" ? a + b : a - b;
335
- if (a % 1 !== 0 || b % 1 !== 0) {
336
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
337
- a = Math.round(a * multiplier);
338
- b = Math.round(b * multiplier);
339
- result = op === "+" ? a + b : a - b;
340
- result /= multiplier;
341
- }
342
- return result;
343
- };
344
- var incrementValue = (v, s) => decimalOp(nan(v), "+", s);
345
- var decrementValue = (v, s) => decimalOp(nan(v), "-", s);
346
- var toPx = (v) => typeof v === "number" ? `${v}px` : v;
347
-
348
- // src/object.ts
349
- function compact(obj) {
350
- if (!isPlainObject(obj) || obj === void 0) return obj;
351
- const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
352
- const filtered = {};
353
- for (const key of keys) {
354
- const value = obj[key];
355
- if (value !== void 0) {
356
- filtered[key] = compact(value);
357
- }
358
- }
359
- return filtered;
360
- }
361
- var json = (v) => JSON.parse(JSON.stringify(v));
362
- function pick(obj, keys) {
363
- const filtered = {};
364
- for (const key of keys) {
365
- const value = obj[key];
366
- if (value !== void 0) {
367
- filtered[key] = value;
368
- }
369
- }
370
- return filtered;
371
- }
372
- function splitProps(props, keys) {
373
- const rest = {};
374
- const result = {};
375
- const keySet = new Set(keys);
376
- const ownKeys = Reflect.ownKeys(props);
377
- for (const key of ownKeys) {
378
- if (keySet.has(key)) {
379
- result[key] = props[key];
380
- } else {
381
- rest[key] = props[key];
382
- }
383
- }
384
- return [result, rest];
385
- }
386
- var createSplitProps = (keys) => {
387
- return function split(props) {
388
- return splitProps(props, keys);
389
- };
390
- };
391
- function omit(obj, keys) {
392
- return createSplitProps(keys)(obj)[1];
393
- }
394
-
395
- // src/store.ts
396
- function createStore(initialState, compare = Object.is) {
397
- let state = { ...initialState };
398
- const listeners = /* @__PURE__ */ new Set();
399
- const subscribe = (listener) => {
400
- listeners.add(listener);
401
- return () => listeners.delete(listener);
402
- };
403
- const publish = () => {
404
- listeners.forEach((listener) => listener());
405
- };
406
- const get = (key) => {
407
- return state[key];
408
- };
409
- const set = (key, value) => {
410
- if (!compare(state[key], value)) {
411
- state[key] = value;
412
- publish();
413
- }
414
- };
415
- const update = (updates) => {
416
- let hasChanges = false;
417
- for (const key in updates) {
418
- const value = updates[key];
419
- if (value !== void 0 && !compare(state[key], value)) {
420
- state[key] = value;
421
- hasChanges = true;
422
- }
423
- }
424
- if (hasChanges) {
425
- publish();
426
- }
427
- };
428
- const snapshot = () => ({ ...state });
429
- return {
430
- subscribe,
431
- get,
432
- set,
433
- update,
434
- snapshot
435
- };
436
- }
437
-
438
- // src/timers.ts
439
- var currentTime = () => performance.now();
440
- var _tick;
441
- var Timer = class {
442
- constructor(onTick) {
443
- this.onTick = onTick;
444
- __publicField(this, "frameId", null);
445
- __publicField(this, "pausedAtMs", null);
446
- __publicField(this, "context");
447
- __publicField(this, "cancelFrame", () => {
448
- if (this.frameId === null) return;
449
- cancelAnimationFrame(this.frameId);
450
- this.frameId = null;
451
- });
452
- __publicField(this, "setStartMs", (startMs) => {
453
- this.context.startMs = startMs;
454
- });
455
- __publicField(this, "start", () => {
456
- if (this.frameId !== null) return;
457
- const now = currentTime();
458
- if (this.pausedAtMs !== null) {
459
- this.context.startMs += now - this.pausedAtMs;
460
- this.pausedAtMs = null;
461
- } else {
462
- this.context.startMs = now;
463
- }
464
- this.frameId = requestAnimationFrame(__privateGet(this, _tick));
465
- });
466
- __publicField(this, "pause", () => {
467
- if (this.frameId === null) return;
468
- this.cancelFrame();
469
- this.pausedAtMs = currentTime();
470
- });
471
- __publicField(this, "stop", () => {
472
- if (this.frameId === null) return;
473
- this.cancelFrame();
474
- this.pausedAtMs = null;
475
- });
476
- __privateAdd(this, _tick, (now) => {
477
- this.context.now = now;
478
- this.context.deltaMs = now - this.context.startMs;
479
- const shouldContinue = this.onTick(this.context);
480
- if (shouldContinue === false) {
481
- this.stop();
482
- return;
483
- }
484
- this.frameId = requestAnimationFrame(__privateGet(this, _tick));
485
- });
486
- this.context = { now: 0, startMs: currentTime(), deltaMs: 0 };
487
- }
488
- get elapsedMs() {
489
- if (this.pausedAtMs !== null) {
490
- return this.pausedAtMs - this.context.startMs;
491
- }
492
- return currentTime() - this.context.startMs;
493
- }
494
- };
495
- _tick = new WeakMap();
496
- function setRafInterval(fn, intervalMs) {
497
- const timer = new Timer(({ now, deltaMs }) => {
498
- if (deltaMs >= intervalMs) {
499
- const startMs = intervalMs > 0 ? now - deltaMs % intervalMs : now;
500
- timer.setStartMs(startMs);
501
- fn({ startMs, deltaMs });
502
- }
503
- });
504
- timer.start();
505
- return () => timer.stop();
506
- }
507
- function setRafTimeout(fn, delayMs) {
508
- const timer = new Timer(({ deltaMs }) => {
509
- if (deltaMs >= delayMs) {
510
- fn();
511
- return false;
512
- }
513
- });
514
- timer.start();
515
- return () => timer.stop();
516
- }
517
-
518
- // src/warning.ts
519
- function warn(...a) {
520
- const m = a.length === 1 ? a[0] : a[1];
521
- const c = a.length === 2 ? a[0] : true;
522
- if (c && process.env.NODE_ENV !== "production") {
523
- console.warn(m);
524
- }
525
- }
526
- function invariant(...a) {
527
- const m = a.length === 1 ? a[0] : a[1];
528
- const c = a.length === 2 ? a[0] : true;
529
- if (c && process.env.NODE_ENV !== "production") {
530
- throw new Error(m);
531
- }
532
- }
533
- function ensure(c, m) {
534
- if (c == null) throw new Error(m());
535
- }
536
- function ensureProps(props, keys, scope) {
537
- let missingKeys = [];
538
- for (const key of keys) {
539
- if (props[key] == null) missingKeys.push(key);
540
- }
541
- if (missingKeys.length > 0)
542
- throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
543
- }
544
-
545
- export { Timer, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, createStore, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, hash, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
1
+ // src/index.ts
2
+ export * from "./array.mjs";
3
+ export * from "./equal.mjs";
4
+ export * from "./functions.mjs";
5
+ export * from "./guard.mjs";
6
+ export * from "./number.mjs";
7
+ export * from "./object.mjs";
8
+ export * from "./store.mjs";
9
+ export * from "./timers.mjs";
10
+ export * from "./warning.mjs";
@@ -0,0 +1,41 @@
1
+ declare const isNaN: (v: number) => boolean;
2
+ declare const nan: (v: number) => number;
3
+ declare const mod: (v: number, m: number) => number;
4
+ declare const wrap: (v: number, vmax: number) => number;
5
+ declare const getMinValueAtIndex: (i: number, v: number[], vmin: number) => number;
6
+ declare const getMaxValueAtIndex: (i: number, v: number[], vmax: number) => number;
7
+ declare const isValueAtMax: (v: number, vmax: number) => boolean;
8
+ declare const isValueAtMin: (v: number, vmin: number) => boolean;
9
+ declare const isValueWithinRange: (v: number, vmin: number | null | undefined, vmax: number | null | undefined) => boolean;
10
+ declare const roundValue: (v: number, vmin: number, step: number) => number;
11
+ declare const clampValue: (v: number, vmin: number, vmax: number) => number;
12
+ declare const clampPercent: (v: number) => number;
13
+ declare const getValuePercent: (v: number, vmin: number, vmax: number) => number;
14
+ declare const getPercentValue: (p: number, vmin: number, vmax: number, step: number) => number;
15
+ declare const roundToStepPrecision: (v: number, step: number) => number;
16
+ declare const roundToDpr: (v: number, dpr: unknown) => number;
17
+ declare const snapValueToStep: (v: number, vmin: number | undefined, vmax: number | undefined, step: number) => number;
18
+ declare const setValueAtIndex: <T>(vs: T[], i: number, v: T) => T[];
19
+ interface RangeContext {
20
+ min: number;
21
+ max: number;
22
+ step: number;
23
+ values: number[];
24
+ }
25
+ declare function getValueSetterAtIndex(index: number, ctx: RangeContext): (value: number) => number[];
26
+ declare function getNextStepValue(index: number, ctx: RangeContext): number[];
27
+ declare function getPreviousStepValue(index: number, ctx: RangeContext): number[];
28
+ declare const getClosestValueIndex: (vs: number[], t: number) => number;
29
+ declare const getClosestValue: (vs: number[], t: number) => number;
30
+ declare const getValueRanges: (vs: number[], vmin: number, vmax: number, gap: number) => {
31
+ min: number;
32
+ max: number;
33
+ value: number;
34
+ }[];
35
+ declare const getValueTransformer: (va: number[], vb: number[]) => (v: number) => number;
36
+ declare const toFixedNumber: (v: number, d?: number, b?: number) => number;
37
+ declare const incrementValue: (v: number, s: number) => number;
38
+ declare const decrementValue: (v: number, s: number) => number;
39
+ declare const toPx: (v: number | string | undefined) => string | undefined;
40
+
41
+ export { clampPercent, clampValue, decrementValue, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, incrementValue, isNaN, isValueAtMax, isValueAtMin, isValueWithinRange, mod, nan, roundToDpr, roundToStepPrecision, roundValue, setValueAtIndex, snapValueToStep, toFixedNumber, toPx, wrap };
@@ -0,0 +1,41 @@
1
+ declare const isNaN: (v: number) => boolean;
2
+ declare const nan: (v: number) => number;
3
+ declare const mod: (v: number, m: number) => number;
4
+ declare const wrap: (v: number, vmax: number) => number;
5
+ declare const getMinValueAtIndex: (i: number, v: number[], vmin: number) => number;
6
+ declare const getMaxValueAtIndex: (i: number, v: number[], vmax: number) => number;
7
+ declare const isValueAtMax: (v: number, vmax: number) => boolean;
8
+ declare const isValueAtMin: (v: number, vmin: number) => boolean;
9
+ declare const isValueWithinRange: (v: number, vmin: number | null | undefined, vmax: number | null | undefined) => boolean;
10
+ declare const roundValue: (v: number, vmin: number, step: number) => number;
11
+ declare const clampValue: (v: number, vmin: number, vmax: number) => number;
12
+ declare const clampPercent: (v: number) => number;
13
+ declare const getValuePercent: (v: number, vmin: number, vmax: number) => number;
14
+ declare const getPercentValue: (p: number, vmin: number, vmax: number, step: number) => number;
15
+ declare const roundToStepPrecision: (v: number, step: number) => number;
16
+ declare const roundToDpr: (v: number, dpr: unknown) => number;
17
+ declare const snapValueToStep: (v: number, vmin: number | undefined, vmax: number | undefined, step: number) => number;
18
+ declare const setValueAtIndex: <T>(vs: T[], i: number, v: T) => T[];
19
+ interface RangeContext {
20
+ min: number;
21
+ max: number;
22
+ step: number;
23
+ values: number[];
24
+ }
25
+ declare function getValueSetterAtIndex(index: number, ctx: RangeContext): (value: number) => number[];
26
+ declare function getNextStepValue(index: number, ctx: RangeContext): number[];
27
+ declare function getPreviousStepValue(index: number, ctx: RangeContext): number[];
28
+ declare const getClosestValueIndex: (vs: number[], t: number) => number;
29
+ declare const getClosestValue: (vs: number[], t: number) => number;
30
+ declare const getValueRanges: (vs: number[], vmin: number, vmax: number, gap: number) => {
31
+ min: number;
32
+ max: number;
33
+ value: number;
34
+ }[];
35
+ declare const getValueTransformer: (va: number[], vb: number[]) => (v: number) => number;
36
+ declare const toFixedNumber: (v: number, d?: number, b?: number) => number;
37
+ declare const incrementValue: (v: number, s: number) => number;
38
+ declare const decrementValue: (v: number, s: number) => number;
39
+ declare const toPx: (v: number | string | undefined) => string | undefined;
40
+
41
+ export { clampPercent, clampValue, decrementValue, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, incrementValue, isNaN, isValueAtMax, isValueAtMin, isValueWithinRange, mod, nan, roundToDpr, roundToStepPrecision, roundValue, setValueAtIndex, snapValueToStep, toFixedNumber, toPx, wrap };