@zag-js/core 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.
@@ -0,0 +1,80 @@
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/merge-props.ts
21
+ var merge_props_exports = {};
22
+ __export(merge_props_exports, {
23
+ mergeProps: () => mergeProps
24
+ });
25
+ module.exports = __toCommonJS(merge_props_exports);
26
+ var import_utils = require("@zag-js/utils");
27
+ var clsx = (...args) => args.map((str) => str?.trim?.()).filter(Boolean).join(" ");
28
+ var CSS_REGEX = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
29
+ var serialize = (style) => {
30
+ const res = {};
31
+ let match;
32
+ while (match = CSS_REGEX.exec(style)) {
33
+ res[match[1]] = match[2];
34
+ }
35
+ return res;
36
+ };
37
+ var css = (a, b) => {
38
+ if ((0, import_utils.isString)(a)) {
39
+ if ((0, import_utils.isString)(b)) return `${a};${b}`;
40
+ a = serialize(a);
41
+ } else if ((0, import_utils.isString)(b)) {
42
+ b = serialize(b);
43
+ }
44
+ return Object.assign({}, a ?? {}, b ?? {});
45
+ };
46
+ function mergeProps(...args) {
47
+ let result = {};
48
+ for (let props of args) {
49
+ if (!props) continue;
50
+ for (let key in result) {
51
+ if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
52
+ result[key] = (0, import_utils.callAll)(props[key], result[key]);
53
+ continue;
54
+ }
55
+ if (key === "className" || key === "class") {
56
+ result[key] = clsx(result[key], props[key]);
57
+ continue;
58
+ }
59
+ if (key === "style") {
60
+ result[key] = css(result[key], props[key]);
61
+ continue;
62
+ }
63
+ result[key] = props[key] !== void 0 ? props[key] : result[key];
64
+ }
65
+ for (let key in props) {
66
+ if (result[key] === void 0) {
67
+ result[key] = props[key];
68
+ }
69
+ }
70
+ const symbols = Object.getOwnPropertySymbols(props);
71
+ for (let symbol of symbols) {
72
+ result[symbol] = props[symbol];
73
+ }
74
+ }
75
+ return result;
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ mergeProps
80
+ });
@@ -0,0 +1,55 @@
1
+ // src/merge-props.ts
2
+ import { callAll, isString } from "@zag-js/utils";
3
+ var clsx = (...args) => args.map((str) => str?.trim?.()).filter(Boolean).join(" ");
4
+ var CSS_REGEX = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
5
+ var serialize = (style) => {
6
+ const res = {};
7
+ let match;
8
+ while (match = CSS_REGEX.exec(style)) {
9
+ res[match[1]] = match[2];
10
+ }
11
+ return res;
12
+ };
13
+ var css = (a, b) => {
14
+ if (isString(a)) {
15
+ if (isString(b)) return `${a};${b}`;
16
+ a = serialize(a);
17
+ } else if (isString(b)) {
18
+ b = serialize(b);
19
+ }
20
+ return Object.assign({}, a ?? {}, b ?? {});
21
+ };
22
+ function mergeProps(...args) {
23
+ let result = {};
24
+ for (let props of args) {
25
+ if (!props) continue;
26
+ for (let key in result) {
27
+ if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
28
+ result[key] = callAll(props[key], result[key]);
29
+ continue;
30
+ }
31
+ if (key === "className" || key === "class") {
32
+ result[key] = clsx(result[key], props[key]);
33
+ continue;
34
+ }
35
+ if (key === "style") {
36
+ result[key] = css(result[key], props[key]);
37
+ continue;
38
+ }
39
+ result[key] = props[key] !== void 0 ? props[key] : result[key];
40
+ }
41
+ for (let key in props) {
42
+ if (result[key] === void 0) {
43
+ result[key] = props[key];
44
+ }
45
+ }
46
+ const symbols = Object.getOwnPropertySymbols(props);
47
+ for (let symbol of symbols) {
48
+ result[symbol] = props[symbol];
49
+ }
50
+ }
51
+ return result;
52
+ }
53
+ export {
54
+ mergeProps
55
+ };
@@ -0,0 +1,15 @@
1
+ import { isActiveElement } from '@zag-js/dom-query';
2
+ import { Scope } from './types.mjs';
3
+
4
+ declare function createScope(props: Pick<Scope, "id" | "ids" | "getRootNode">): {
5
+ getRootNode: () => Document | ShadowRoot;
6
+ getDoc: () => Document;
7
+ getWin: () => Window & typeof globalThis;
8
+ getActiveElement: () => HTMLElement | null;
9
+ isActiveElement: typeof isActiveElement;
10
+ getById: <T extends Element = HTMLElement>(id: string) => T | null;
11
+ id?: string | undefined | undefined;
12
+ ids?: Record<string, any> | undefined;
13
+ };
14
+
15
+ export { createScope };
@@ -0,0 +1,15 @@
1
+ import { isActiveElement } from '@zag-js/dom-query';
2
+ import { Scope } from './types.js';
3
+
4
+ declare function createScope(props: Pick<Scope, "id" | "ids" | "getRootNode">): {
5
+ getRootNode: () => Document | ShadowRoot;
6
+ getDoc: () => Document;
7
+ getWin: () => Window & typeof globalThis;
8
+ getActiveElement: () => HTMLElement | null;
9
+ isActiveElement: typeof isActiveElement;
10
+ getById: <T extends Element = HTMLElement>(id: string) => T | null;
11
+ id?: string | undefined | undefined;
12
+ ids?: Record<string, any> | undefined;
13
+ };
14
+
15
+ export { createScope };
package/dist/scope.js ADDED
@@ -0,0 +1,46 @@
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/scope.ts
21
+ var scope_exports = {};
22
+ __export(scope_exports, {
23
+ createScope: () => createScope
24
+ });
25
+ module.exports = __toCommonJS(scope_exports);
26
+ var import_dom_query = require("@zag-js/dom-query");
27
+ function createScope(props) {
28
+ const getRootNode = () => props.getRootNode?.() ?? document;
29
+ const getDoc = () => (0, import_dom_query.getDocument)(getRootNode());
30
+ const getWin = () => getDoc().defaultView ?? window;
31
+ const getActiveElementFn = () => (0, import_dom_query.getActiveElement)(getRootNode());
32
+ const getById = (id) => getRootNode().getElementById(id);
33
+ return {
34
+ ...props,
35
+ getRootNode,
36
+ getDoc,
37
+ getWin,
38
+ getActiveElement: getActiveElementFn,
39
+ isActiveElement: import_dom_query.isActiveElement,
40
+ getById
41
+ };
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ createScope
46
+ });
package/dist/scope.mjs ADDED
@@ -0,0 +1,21 @@
1
+ // src/scope.ts
2
+ import { getActiveElement, getDocument, isActiveElement } from "@zag-js/dom-query";
3
+ function createScope(props) {
4
+ const getRootNode = () => props.getRootNode?.() ?? document;
5
+ const getDoc = () => getDocument(getRootNode());
6
+ const getWin = () => getDoc().defaultView ?? window;
7
+ const getActiveElementFn = () => getActiveElement(getRootNode());
8
+ const getById = (id) => getRootNode().getElementById(id);
9
+ return {
10
+ ...props,
11
+ getRootNode,
12
+ getDoc,
13
+ getWin,
14
+ getActiveElement: getActiveElementFn,
15
+ isActiveElement,
16
+ getById
17
+ };
18
+ }
19
+ export {
20
+ createScope
21
+ };
@@ -0,0 +1,25 @@
1
+ import { MachineSchema, Machine, MachineState, TransitionMatch } from './types.mjs';
2
+
3
+ declare function ensureStateIndex<T extends MachineSchema>(machine: Machine<T>): Map<string, MachineState<T, string>>;
4
+ type StateChain<T extends MachineSchema> = Array<{
5
+ path: string;
6
+ state: MachineState<T>;
7
+ }>;
8
+ declare function getStateChain<T extends MachineSchema>(machine: Machine<T>, state: T["state"] | undefined): StateChain<T>;
9
+ declare function resolveStateValue<T extends MachineSchema>(machine: Machine<T>, value: T["state"] | string, source?: string): T["state"];
10
+ declare function getStateDefinition<T extends MachineSchema>(machine: Machine<T>, state: T["state"]): MachineState<T, string>;
11
+ declare function findTransition<T extends MachineSchema>(machine: Machine<T>, state: T["state"], eventType: string): TransitionMatch<T>;
12
+ declare function getExitEnterStates<T extends MachineSchema>(machine: Machine<T>, prevState: T["state"] | undefined, nextState: T["state"], reenter?: boolean): {
13
+ exiting: {
14
+ path: string;
15
+ state: MachineState<T, string>;
16
+ }[];
17
+ entering: {
18
+ path: string;
19
+ state: MachineState<T, string>;
20
+ }[];
21
+ };
22
+ declare function matchesState(current: string | undefined, value: string): boolean;
23
+ declare function hasTag<T extends MachineSchema>(machine: Machine<T>, state: T["state"], tag: T["tag"]): boolean;
24
+
25
+ export { ensureStateIndex, findTransition, getExitEnterStates, getStateChain, getStateDefinition, hasTag, matchesState, resolveStateValue };
@@ -0,0 +1,25 @@
1
+ import { MachineSchema, Machine, MachineState, TransitionMatch } from './types.js';
2
+
3
+ declare function ensureStateIndex<T extends MachineSchema>(machine: Machine<T>): Map<string, MachineState<T, string>>;
4
+ type StateChain<T extends MachineSchema> = Array<{
5
+ path: string;
6
+ state: MachineState<T>;
7
+ }>;
8
+ declare function getStateChain<T extends MachineSchema>(machine: Machine<T>, state: T["state"] | undefined): StateChain<T>;
9
+ declare function resolveStateValue<T extends MachineSchema>(machine: Machine<T>, value: T["state"] | string, source?: string): T["state"];
10
+ declare function getStateDefinition<T extends MachineSchema>(machine: Machine<T>, state: T["state"]): MachineState<T, string>;
11
+ declare function findTransition<T extends MachineSchema>(machine: Machine<T>, state: T["state"], eventType: string): TransitionMatch<T>;
12
+ declare function getExitEnterStates<T extends MachineSchema>(machine: Machine<T>, prevState: T["state"] | undefined, nextState: T["state"], reenter?: boolean): {
13
+ exiting: {
14
+ path: string;
15
+ state: MachineState<T, string>;
16
+ }[];
17
+ entering: {
18
+ path: string;
19
+ state: MachineState<T, string>;
20
+ }[];
21
+ };
22
+ declare function matchesState(current: string | undefined, value: string): boolean;
23
+ declare function hasTag<T extends MachineSchema>(machine: Machine<T>, state: T["state"], tag: T["tag"]): boolean;
24
+
25
+ export { ensureStateIndex, findTransition, getExitEnterStates, getStateChain, getStateDefinition, hasTag, matchesState, resolveStateValue };
package/dist/state.js ADDED
@@ -0,0 +1,172 @@
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/state.ts
21
+ var state_exports = {};
22
+ __export(state_exports, {
23
+ ensureStateIndex: () => ensureStateIndex,
24
+ findTransition: () => findTransition,
25
+ getExitEnterStates: () => getExitEnterStates,
26
+ getStateChain: () => getStateChain,
27
+ getStateDefinition: () => getStateDefinition,
28
+ hasTag: () => hasTag,
29
+ matchesState: () => matchesState,
30
+ resolveStateValue: () => resolveStateValue
31
+ });
32
+ module.exports = __toCommonJS(state_exports);
33
+ var STATE_DELIMITER = ".";
34
+ var stateIndexCache = /* @__PURE__ */ new WeakMap();
35
+ function joinStatePath(parts) {
36
+ return parts.join(STATE_DELIMITER);
37
+ }
38
+ function isAbsoluteStatePath(value) {
39
+ return value.includes(STATE_DELIMITER);
40
+ }
41
+ function appendStatePath(base, segment) {
42
+ return base ? `${base}${STATE_DELIMITER}${segment}` : segment;
43
+ }
44
+ function buildStateIndex(machine) {
45
+ const index = /* @__PURE__ */ new Map();
46
+ const visit = (basePath, state) => {
47
+ index.set(basePath, state);
48
+ const childStates = state.states;
49
+ if (!childStates) return;
50
+ for (const [childKey, childState] of Object.entries(childStates)) {
51
+ if (!childState) continue;
52
+ const childPath = appendStatePath(basePath, childKey);
53
+ visit(childPath, childState);
54
+ }
55
+ };
56
+ for (const [topKey, topState] of Object.entries(machine.states)) {
57
+ if (!topState) continue;
58
+ visit(topKey, topState);
59
+ }
60
+ return index;
61
+ }
62
+ function ensureStateIndex(machine) {
63
+ const cached = stateIndexCache.get(machine);
64
+ if (cached) return cached;
65
+ const index = buildStateIndex(machine);
66
+ stateIndexCache.set(machine, index);
67
+ return index;
68
+ }
69
+ function toSegments(value) {
70
+ if (!value) return [];
71
+ return String(value).split(STATE_DELIMITER).filter(Boolean);
72
+ }
73
+ function getStateChain(machine, state) {
74
+ if (!state) return [];
75
+ const stateIndex = ensureStateIndex(machine);
76
+ const segments = toSegments(state);
77
+ const chain = [];
78
+ const statePath = [];
79
+ for (const segment of segments) {
80
+ statePath.push(segment);
81
+ const path = joinStatePath(statePath);
82
+ const current = stateIndex.get(path);
83
+ if (!current) break;
84
+ chain.push({ path, state: current });
85
+ }
86
+ return chain;
87
+ }
88
+ function resolveAbsoluteStateValue(machine, value) {
89
+ const stateIndex = ensureStateIndex(machine);
90
+ const segments = toSegments(value);
91
+ if (!segments.length) return value;
92
+ const resolved = [];
93
+ for (const segment of segments) {
94
+ resolved.push(segment);
95
+ const path = joinStatePath(resolved);
96
+ if (!stateIndex.has(path)) return value;
97
+ }
98
+ let resolvedPath = joinStatePath(resolved);
99
+ let current = stateIndex.get(resolvedPath);
100
+ while (current?.initial) {
101
+ const nextPath = `${resolvedPath}${STATE_DELIMITER}${current.initial}`;
102
+ const nextState = stateIndex.get(nextPath);
103
+ if (!nextState) break;
104
+ resolvedPath = nextPath;
105
+ current = nextState;
106
+ }
107
+ return resolvedPath;
108
+ }
109
+ function hasStatePath(machine, value) {
110
+ const stateIndex = ensureStateIndex(machine);
111
+ return stateIndex.has(value);
112
+ }
113
+ function resolveStateValue(machine, value, source) {
114
+ const stateValue = String(value);
115
+ if (!isAbsoluteStatePath(stateValue) && source) {
116
+ const sourceSegments = toSegments(source);
117
+ for (let index = sourceSegments.length; index >= 1; index--) {
118
+ const base = sourceSegments.slice(0, index).join(STATE_DELIMITER);
119
+ const candidate = appendStatePath(base, stateValue);
120
+ if (hasStatePath(machine, candidate)) return resolveAbsoluteStateValue(machine, candidate);
121
+ }
122
+ }
123
+ return resolveAbsoluteStateValue(machine, stateValue);
124
+ }
125
+ function getStateDefinition(machine, state) {
126
+ const chain = getStateChain(machine, state);
127
+ return chain[chain.length - 1]?.state;
128
+ }
129
+ function findTransition(machine, state, eventType) {
130
+ const chain = getStateChain(machine, state);
131
+ for (let index = chain.length - 1; index >= 0; index--) {
132
+ const transitionMap = chain[index]?.state.on;
133
+ const transition = transitionMap?.[eventType];
134
+ if (transition) return { transitions: transition, source: chain[index]?.path };
135
+ }
136
+ const rootTransitionMap = machine.on;
137
+ return { transitions: rootTransitionMap?.[eventType], source: void 0 };
138
+ }
139
+ function getExitEnterStates(machine, prevState, nextState, reenter) {
140
+ const prevChain = prevState ? getStateChain(machine, prevState) : [];
141
+ const nextChain = getStateChain(machine, nextState);
142
+ let commonIndex = 0;
143
+ while (commonIndex < prevChain.length && commonIndex < nextChain.length && prevChain[commonIndex]?.path === nextChain[commonIndex]?.path) {
144
+ commonIndex += 1;
145
+ }
146
+ let exiting = prevChain.slice(commonIndex).reverse();
147
+ let entering = nextChain.slice(commonIndex);
148
+ const sameLeaf = prevChain.at(-1)?.path === nextChain.at(-1)?.path;
149
+ if (reenter && sameLeaf) {
150
+ exiting = prevChain.slice().reverse();
151
+ entering = nextChain;
152
+ }
153
+ return { exiting, entering };
154
+ }
155
+ function matchesState(current, value) {
156
+ if (!current) return false;
157
+ return current === value || current.startsWith(`${value}${STATE_DELIMITER}`);
158
+ }
159
+ function hasTag(machine, state, tag) {
160
+ return getStateChain(machine, state).some((item) => item.state.tags?.includes(tag));
161
+ }
162
+ // Annotate the CommonJS export names for ESM import in node:
163
+ 0 && (module.exports = {
164
+ ensureStateIndex,
165
+ findTransition,
166
+ getExitEnterStates,
167
+ getStateChain,
168
+ getStateDefinition,
169
+ hasTag,
170
+ matchesState,
171
+ resolveStateValue
172
+ });
package/dist/state.mjs ADDED
@@ -0,0 +1,140 @@
1
+ // src/state.ts
2
+ var STATE_DELIMITER = ".";
3
+ var stateIndexCache = /* @__PURE__ */ new WeakMap();
4
+ function joinStatePath(parts) {
5
+ return parts.join(STATE_DELIMITER);
6
+ }
7
+ function isAbsoluteStatePath(value) {
8
+ return value.includes(STATE_DELIMITER);
9
+ }
10
+ function appendStatePath(base, segment) {
11
+ return base ? `${base}${STATE_DELIMITER}${segment}` : segment;
12
+ }
13
+ function buildStateIndex(machine) {
14
+ const index = /* @__PURE__ */ new Map();
15
+ const visit = (basePath, state) => {
16
+ index.set(basePath, state);
17
+ const childStates = state.states;
18
+ if (!childStates) return;
19
+ for (const [childKey, childState] of Object.entries(childStates)) {
20
+ if (!childState) continue;
21
+ const childPath = appendStatePath(basePath, childKey);
22
+ visit(childPath, childState);
23
+ }
24
+ };
25
+ for (const [topKey, topState] of Object.entries(machine.states)) {
26
+ if (!topState) continue;
27
+ visit(topKey, topState);
28
+ }
29
+ return index;
30
+ }
31
+ function ensureStateIndex(machine) {
32
+ const cached = stateIndexCache.get(machine);
33
+ if (cached) return cached;
34
+ const index = buildStateIndex(machine);
35
+ stateIndexCache.set(machine, index);
36
+ return index;
37
+ }
38
+ function toSegments(value) {
39
+ if (!value) return [];
40
+ return String(value).split(STATE_DELIMITER).filter(Boolean);
41
+ }
42
+ function getStateChain(machine, state) {
43
+ if (!state) return [];
44
+ const stateIndex = ensureStateIndex(machine);
45
+ const segments = toSegments(state);
46
+ const chain = [];
47
+ const statePath = [];
48
+ for (const segment of segments) {
49
+ statePath.push(segment);
50
+ const path = joinStatePath(statePath);
51
+ const current = stateIndex.get(path);
52
+ if (!current) break;
53
+ chain.push({ path, state: current });
54
+ }
55
+ return chain;
56
+ }
57
+ function resolveAbsoluteStateValue(machine, value) {
58
+ const stateIndex = ensureStateIndex(machine);
59
+ const segments = toSegments(value);
60
+ if (!segments.length) return value;
61
+ const resolved = [];
62
+ for (const segment of segments) {
63
+ resolved.push(segment);
64
+ const path = joinStatePath(resolved);
65
+ if (!stateIndex.has(path)) return value;
66
+ }
67
+ let resolvedPath = joinStatePath(resolved);
68
+ let current = stateIndex.get(resolvedPath);
69
+ while (current?.initial) {
70
+ const nextPath = `${resolvedPath}${STATE_DELIMITER}${current.initial}`;
71
+ const nextState = stateIndex.get(nextPath);
72
+ if (!nextState) break;
73
+ resolvedPath = nextPath;
74
+ current = nextState;
75
+ }
76
+ return resolvedPath;
77
+ }
78
+ function hasStatePath(machine, value) {
79
+ const stateIndex = ensureStateIndex(machine);
80
+ return stateIndex.has(value);
81
+ }
82
+ function resolveStateValue(machine, value, source) {
83
+ const stateValue = String(value);
84
+ if (!isAbsoluteStatePath(stateValue) && source) {
85
+ const sourceSegments = toSegments(source);
86
+ for (let index = sourceSegments.length; index >= 1; index--) {
87
+ const base = sourceSegments.slice(0, index).join(STATE_DELIMITER);
88
+ const candidate = appendStatePath(base, stateValue);
89
+ if (hasStatePath(machine, candidate)) return resolveAbsoluteStateValue(machine, candidate);
90
+ }
91
+ }
92
+ return resolveAbsoluteStateValue(machine, stateValue);
93
+ }
94
+ function getStateDefinition(machine, state) {
95
+ const chain = getStateChain(machine, state);
96
+ return chain[chain.length - 1]?.state;
97
+ }
98
+ function findTransition(machine, state, eventType) {
99
+ const chain = getStateChain(machine, state);
100
+ for (let index = chain.length - 1; index >= 0; index--) {
101
+ const transitionMap = chain[index]?.state.on;
102
+ const transition = transitionMap?.[eventType];
103
+ if (transition) return { transitions: transition, source: chain[index]?.path };
104
+ }
105
+ const rootTransitionMap = machine.on;
106
+ return { transitions: rootTransitionMap?.[eventType], source: void 0 };
107
+ }
108
+ function getExitEnterStates(machine, prevState, nextState, reenter) {
109
+ const prevChain = prevState ? getStateChain(machine, prevState) : [];
110
+ const nextChain = getStateChain(machine, nextState);
111
+ let commonIndex = 0;
112
+ while (commonIndex < prevChain.length && commonIndex < nextChain.length && prevChain[commonIndex]?.path === nextChain[commonIndex]?.path) {
113
+ commonIndex += 1;
114
+ }
115
+ let exiting = prevChain.slice(commonIndex).reverse();
116
+ let entering = nextChain.slice(commonIndex);
117
+ const sameLeaf = prevChain.at(-1)?.path === nextChain.at(-1)?.path;
118
+ if (reenter && sameLeaf) {
119
+ exiting = prevChain.slice().reverse();
120
+ entering = nextChain;
121
+ }
122
+ return { exiting, entering };
123
+ }
124
+ function matchesState(current, value) {
125
+ if (!current) return false;
126
+ return current === value || current.startsWith(`${value}${STATE_DELIMITER}`);
127
+ }
128
+ function hasTag(machine, state, tag) {
129
+ return getStateChain(machine, state).some((item) => item.state.tags?.includes(tag));
130
+ }
131
+ export {
132
+ ensureStateIndex,
133
+ findTransition,
134
+ getExitEnterStates,
135
+ getStateChain,
136
+ getStateDefinition,
137
+ hasTag,
138
+ matchesState,
139
+ resolveStateValue
140
+ };