@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/array.d.mts +27 -0
- package/dist/array.d.ts +27 -0
- package/dist/array.js +137 -0
- package/dist/array.mjs +94 -0
- package/dist/chunk-MXGZDBDQ.mjs +15 -0
- package/dist/equal.d.mts +3 -0
- package/dist/equal.d.ts +3 -0
- package/dist/equal.js +62 -0
- package/dist/equal.mjs +39 -0
- package/dist/functions.d.mts +15 -0
- package/dist/functions.d.ts +15 -0
- package/dist/functions.js +136 -0
- package/dist/functions.mjs +103 -0
- package/dist/guard.d.mts +14 -0
- package/dist/guard.d.ts +14 -0
- package/dist/guard.js +72 -0
- package/dist/guard.mjs +39 -0
- package/dist/index.d.mts +9 -148
- package/dist/index.d.ts +9 -148
- package/dist/index.js +39 -632
- package/dist/index.mjs +10 -545
- package/dist/number.d.mts +41 -0
- package/dist/number.d.ts +41 -0
- package/dist/number.js +202 -0
- package/dist/number.mjs +151 -0
- package/dist/object.d.mts +9 -0
- package/dist/object.d.ts +9 -0
- package/dist/object.js +85 -0
- package/dist/object.mjs +57 -0
- package/dist/store.d.mts +12 -0
- package/dist/store.d.ts +12 -0
- package/dist/store.js +70 -0
- package/dist/store.mjs +47 -0
- package/dist/timers.d.mts +26 -0
- package/dist/timers.d.ts +26 -0
- package/dist/timers.js +119 -0
- package/dist/timers.mjs +90 -0
- package/dist/warning.d.mts +9 -0
- package/dist/warning.d.ts +9 -0
- package/dist/warning.js +60 -0
- package/dist/warning.mjs +34 -0
- package/package.json +1 -1
package/dist/timers.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface TimerBaseContext {
|
|
2
|
+
startMs: number;
|
|
3
|
+
deltaMs: number;
|
|
4
|
+
}
|
|
5
|
+
interface TimerContext extends TimerBaseContext {
|
|
6
|
+
now: number;
|
|
7
|
+
}
|
|
8
|
+
type TimerContextFn = (ctx: TimerContext) => boolean | void;
|
|
9
|
+
declare class Timer {
|
|
10
|
+
#private;
|
|
11
|
+
private readonly onTick;
|
|
12
|
+
private frameId;
|
|
13
|
+
private pausedAtMs;
|
|
14
|
+
private context;
|
|
15
|
+
constructor(onTick: TimerContextFn);
|
|
16
|
+
private cancelFrame;
|
|
17
|
+
setStartMs: (startMs: number) => void;
|
|
18
|
+
get elapsedMs(): number;
|
|
19
|
+
start: () => void;
|
|
20
|
+
pause: () => void;
|
|
21
|
+
stop: () => void;
|
|
22
|
+
}
|
|
23
|
+
declare function setRafInterval(fn: (ctx: TimerBaseContext) => void, intervalMs: number): () => void;
|
|
24
|
+
declare function setRafTimeout(fn: () => void, delayMs: number): () => void;
|
|
25
|
+
|
|
26
|
+
export { Timer, type TimerBaseContext, type TimerContextFn, setRafInterval, setRafTimeout };
|
package/dist/timers.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
25
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
26
|
+
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);
|
|
27
|
+
|
|
28
|
+
// src/timers.ts
|
|
29
|
+
var timers_exports = {};
|
|
30
|
+
__export(timers_exports, {
|
|
31
|
+
Timer: () => Timer,
|
|
32
|
+
setRafInterval: () => setRafInterval,
|
|
33
|
+
setRafTimeout: () => setRafTimeout
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(timers_exports);
|
|
36
|
+
var currentTime = () => performance.now();
|
|
37
|
+
var _tick;
|
|
38
|
+
var Timer = class {
|
|
39
|
+
constructor(onTick) {
|
|
40
|
+
this.onTick = onTick;
|
|
41
|
+
__publicField(this, "frameId", null);
|
|
42
|
+
__publicField(this, "pausedAtMs", null);
|
|
43
|
+
__publicField(this, "context");
|
|
44
|
+
__publicField(this, "cancelFrame", () => {
|
|
45
|
+
if (this.frameId === null) return;
|
|
46
|
+
cancelAnimationFrame(this.frameId);
|
|
47
|
+
this.frameId = null;
|
|
48
|
+
});
|
|
49
|
+
__publicField(this, "setStartMs", (startMs) => {
|
|
50
|
+
this.context.startMs = startMs;
|
|
51
|
+
});
|
|
52
|
+
__publicField(this, "start", () => {
|
|
53
|
+
if (this.frameId !== null) return;
|
|
54
|
+
const now = currentTime();
|
|
55
|
+
if (this.pausedAtMs !== null) {
|
|
56
|
+
this.context.startMs += now - this.pausedAtMs;
|
|
57
|
+
this.pausedAtMs = null;
|
|
58
|
+
} else {
|
|
59
|
+
this.context.startMs = now;
|
|
60
|
+
}
|
|
61
|
+
this.frameId = requestAnimationFrame(__privateGet(this, _tick));
|
|
62
|
+
});
|
|
63
|
+
__publicField(this, "pause", () => {
|
|
64
|
+
if (this.frameId === null) return;
|
|
65
|
+
this.cancelFrame();
|
|
66
|
+
this.pausedAtMs = currentTime();
|
|
67
|
+
});
|
|
68
|
+
__publicField(this, "stop", () => {
|
|
69
|
+
if (this.frameId === null) return;
|
|
70
|
+
this.cancelFrame();
|
|
71
|
+
this.pausedAtMs = null;
|
|
72
|
+
});
|
|
73
|
+
__privateAdd(this, _tick, (now) => {
|
|
74
|
+
this.context.now = now;
|
|
75
|
+
this.context.deltaMs = now - this.context.startMs;
|
|
76
|
+
const shouldContinue = this.onTick(this.context);
|
|
77
|
+
if (shouldContinue === false) {
|
|
78
|
+
this.stop();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
this.frameId = requestAnimationFrame(__privateGet(this, _tick));
|
|
82
|
+
});
|
|
83
|
+
this.context = { now: 0, startMs: currentTime(), deltaMs: 0 };
|
|
84
|
+
}
|
|
85
|
+
get elapsedMs() {
|
|
86
|
+
if (this.pausedAtMs !== null) {
|
|
87
|
+
return this.pausedAtMs - this.context.startMs;
|
|
88
|
+
}
|
|
89
|
+
return currentTime() - this.context.startMs;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
_tick = new WeakMap();
|
|
93
|
+
function setRafInterval(fn, intervalMs) {
|
|
94
|
+
const timer = new Timer(({ now, deltaMs }) => {
|
|
95
|
+
if (deltaMs >= intervalMs) {
|
|
96
|
+
const startMs = intervalMs > 0 ? now - deltaMs % intervalMs : now;
|
|
97
|
+
timer.setStartMs(startMs);
|
|
98
|
+
fn({ startMs, deltaMs });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
timer.start();
|
|
102
|
+
return () => timer.stop();
|
|
103
|
+
}
|
|
104
|
+
function setRafTimeout(fn, delayMs) {
|
|
105
|
+
const timer = new Timer(({ deltaMs }) => {
|
|
106
|
+
if (deltaMs >= delayMs) {
|
|
107
|
+
fn();
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
timer.start();
|
|
112
|
+
return () => timer.stop();
|
|
113
|
+
}
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
Timer,
|
|
117
|
+
setRafInterval,
|
|
118
|
+
setRafTimeout
|
|
119
|
+
});
|
package/dist/timers.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__privateAdd,
|
|
3
|
+
__privateGet,
|
|
4
|
+
__publicField
|
|
5
|
+
} from "./chunk-MXGZDBDQ.mjs";
|
|
6
|
+
|
|
7
|
+
// src/timers.ts
|
|
8
|
+
var currentTime = () => performance.now();
|
|
9
|
+
var _tick;
|
|
10
|
+
var Timer = class {
|
|
11
|
+
constructor(onTick) {
|
|
12
|
+
this.onTick = onTick;
|
|
13
|
+
__publicField(this, "frameId", null);
|
|
14
|
+
__publicField(this, "pausedAtMs", null);
|
|
15
|
+
__publicField(this, "context");
|
|
16
|
+
__publicField(this, "cancelFrame", () => {
|
|
17
|
+
if (this.frameId === null) return;
|
|
18
|
+
cancelAnimationFrame(this.frameId);
|
|
19
|
+
this.frameId = null;
|
|
20
|
+
});
|
|
21
|
+
__publicField(this, "setStartMs", (startMs) => {
|
|
22
|
+
this.context.startMs = startMs;
|
|
23
|
+
});
|
|
24
|
+
__publicField(this, "start", () => {
|
|
25
|
+
if (this.frameId !== null) return;
|
|
26
|
+
const now = currentTime();
|
|
27
|
+
if (this.pausedAtMs !== null) {
|
|
28
|
+
this.context.startMs += now - this.pausedAtMs;
|
|
29
|
+
this.pausedAtMs = null;
|
|
30
|
+
} else {
|
|
31
|
+
this.context.startMs = now;
|
|
32
|
+
}
|
|
33
|
+
this.frameId = requestAnimationFrame(__privateGet(this, _tick));
|
|
34
|
+
});
|
|
35
|
+
__publicField(this, "pause", () => {
|
|
36
|
+
if (this.frameId === null) return;
|
|
37
|
+
this.cancelFrame();
|
|
38
|
+
this.pausedAtMs = currentTime();
|
|
39
|
+
});
|
|
40
|
+
__publicField(this, "stop", () => {
|
|
41
|
+
if (this.frameId === null) return;
|
|
42
|
+
this.cancelFrame();
|
|
43
|
+
this.pausedAtMs = null;
|
|
44
|
+
});
|
|
45
|
+
__privateAdd(this, _tick, (now) => {
|
|
46
|
+
this.context.now = now;
|
|
47
|
+
this.context.deltaMs = now - this.context.startMs;
|
|
48
|
+
const shouldContinue = this.onTick(this.context);
|
|
49
|
+
if (shouldContinue === false) {
|
|
50
|
+
this.stop();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.frameId = requestAnimationFrame(__privateGet(this, _tick));
|
|
54
|
+
});
|
|
55
|
+
this.context = { now: 0, startMs: currentTime(), deltaMs: 0 };
|
|
56
|
+
}
|
|
57
|
+
get elapsedMs() {
|
|
58
|
+
if (this.pausedAtMs !== null) {
|
|
59
|
+
return this.pausedAtMs - this.context.startMs;
|
|
60
|
+
}
|
|
61
|
+
return currentTime() - this.context.startMs;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
_tick = new WeakMap();
|
|
65
|
+
function setRafInterval(fn, intervalMs) {
|
|
66
|
+
const timer = new Timer(({ now, deltaMs }) => {
|
|
67
|
+
if (deltaMs >= intervalMs) {
|
|
68
|
+
const startMs = intervalMs > 0 ? now - deltaMs % intervalMs : now;
|
|
69
|
+
timer.setStartMs(startMs);
|
|
70
|
+
fn({ startMs, deltaMs });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
timer.start();
|
|
74
|
+
return () => timer.stop();
|
|
75
|
+
}
|
|
76
|
+
function setRafTimeout(fn, delayMs) {
|
|
77
|
+
const timer = new Timer(({ deltaMs }) => {
|
|
78
|
+
if (deltaMs >= delayMs) {
|
|
79
|
+
fn();
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
timer.start();
|
|
84
|
+
return () => timer.stop();
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
Timer,
|
|
88
|
+
setRafInterval,
|
|
89
|
+
setRafTimeout
|
|
90
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function warn(m: string): void;
|
|
2
|
+
declare function warn(c: boolean, m: string): void;
|
|
3
|
+
declare function invariant(m: string): void;
|
|
4
|
+
declare function invariant(c: boolean, m: string): void;
|
|
5
|
+
declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c is T;
|
|
6
|
+
type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
7
|
+
declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
|
|
8
|
+
|
|
9
|
+
export { ensure, ensureProps, invariant, warn };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function warn(m: string): void;
|
|
2
|
+
declare function warn(c: boolean, m: string): void;
|
|
3
|
+
declare function invariant(m: string): void;
|
|
4
|
+
declare function invariant(c: boolean, m: string): void;
|
|
5
|
+
declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c is T;
|
|
6
|
+
type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
7
|
+
declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
|
|
8
|
+
|
|
9
|
+
export { ensure, ensureProps, invariant, warn };
|
package/dist/warning.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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/warning.ts
|
|
21
|
+
var warning_exports = {};
|
|
22
|
+
__export(warning_exports, {
|
|
23
|
+
ensure: () => ensure,
|
|
24
|
+
ensureProps: () => ensureProps,
|
|
25
|
+
invariant: () => invariant,
|
|
26
|
+
warn: () => warn
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(warning_exports);
|
|
29
|
+
function warn(...a) {
|
|
30
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
31
|
+
const c = a.length === 2 ? a[0] : true;
|
|
32
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
33
|
+
console.warn(m);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function invariant(...a) {
|
|
37
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
38
|
+
const c = a.length === 2 ? a[0] : true;
|
|
39
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
40
|
+
throw new Error(m);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function ensure(c, m) {
|
|
44
|
+
if (c == null) throw new Error(m());
|
|
45
|
+
}
|
|
46
|
+
function ensureProps(props, keys, scope) {
|
|
47
|
+
let missingKeys = [];
|
|
48
|
+
for (const key of keys) {
|
|
49
|
+
if (props[key] == null) missingKeys.push(key);
|
|
50
|
+
}
|
|
51
|
+
if (missingKeys.length > 0)
|
|
52
|
+
throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
ensure,
|
|
57
|
+
ensureProps,
|
|
58
|
+
invariant,
|
|
59
|
+
warn
|
|
60
|
+
});
|
package/dist/warning.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "./chunk-MXGZDBDQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/warning.ts
|
|
4
|
+
function warn(...a) {
|
|
5
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
6
|
+
const c = a.length === 2 ? a[0] : true;
|
|
7
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
8
|
+
console.warn(m);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function invariant(...a) {
|
|
12
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
13
|
+
const c = a.length === 2 ? a[0] : true;
|
|
14
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
15
|
+
throw new Error(m);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function ensure(c, m) {
|
|
19
|
+
if (c == null) throw new Error(m());
|
|
20
|
+
}
|
|
21
|
+
function ensureProps(props, keys, scope) {
|
|
22
|
+
let missingKeys = [];
|
|
23
|
+
for (const key of keys) {
|
|
24
|
+
if (props[key] == null) missingKeys.push(key);
|
|
25
|
+
}
|
|
26
|
+
if (missingKeys.length > 0)
|
|
27
|
+
throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
ensure,
|
|
31
|
+
ensureProps,
|
|
32
|
+
invariant,
|
|
33
|
+
warn
|
|
34
|
+
};
|