machinalayout 0.2.0 → 0.3.1
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/README.md +15 -0
- package/dist/MachinaReactView-Bau5bErA.d.ts +41 -0
- package/dist/chunk-2ZQ2RFFI.js +400 -0
- package/dist/chunk-33CKBEJH.js +186 -0
- package/dist/{chunk-HU6XYOH7.js → chunk-MSTBFD7H.js} +106 -17
- package/dist/{chunk-TR24ERZT.js → chunk-SVWYWI7I.js} +3 -10
- package/dist/chunk-VREK57S3.js +13 -0
- package/dist/chunk-ZIGW44D5.js +63 -0
- package/dist/debugOverlay-fWLv1cS7.d.ts +36 -0
- package/dist/deus/index.d.ts +15 -0
- package/dist/deus/index.js +26 -0
- package/dist/handoff/index.d.ts +44 -0
- package/dist/handoff/index.js +83 -0
- package/dist/index.d.ts +47 -5
- package/dist/index.js +169 -3
- package/dist/inspect/index.d.ts +8 -0
- package/dist/inspect/index.js +97 -0
- package/dist/react/index.d.ts +6 -33
- package/dist/react/index.js +9 -3
- package/dist/react-native/index.d.ts +3 -1
- package/dist/react-native/index.js +8 -2
- package/dist/screenCatalog-ZjonGiOi.d.ts +46 -0
- package/dist/types-CWaup8Z6.d.ts +92 -0
- package/dist/{types-BudfpzZX.d.ts → types-CYgsjDai.d.ts} +1 -1
- package/dist/types-bJlg6wno.d.ts +32 -0
- package/dist/useDeusMachine-2w2u_dki.d.ts +14 -0
- package/dist/vue/index.d.ts +15 -3
- package/dist/vue/index.js +39 -4
- package/docs/deusmachina.md +191 -0
- package/docs/error-codes.md +11 -0
- package/docs/inspection-and-handoff.md +126 -0
- package/docs/react-adapter.md +27 -0
- package/docs/react-native-adapter.md +4 -0
- package/docs/screen-catalog-and-viewports.md +124 -0
- package/docs/stack-geometry-helpers.md +115 -0
- package/docs/vue-adapter.md +4 -0
- package/package.json +127 -115
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
toResolvedTree
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SVWYWI7I.js";
|
|
4
|
+
import {
|
|
5
|
+
getMachinaDebugOverlayBehavior
|
|
6
|
+
} from "./chunk-2ZQ2RFFI.js";
|
|
4
7
|
|
|
5
8
|
// src/react/MachinaReactView.tsx
|
|
6
9
|
import React from "react";
|
|
@@ -88,6 +91,88 @@ function renderNode(node, parentRect, views, viewData, nodeData, nodeClassName,
|
|
|
88
91
|
node.id
|
|
89
92
|
);
|
|
90
93
|
}
|
|
94
|
+
function collectOverlayNodes(node) {
|
|
95
|
+
return [node, ...node.children.flatMap((child) => collectOverlayNodes(child))];
|
|
96
|
+
}
|
|
97
|
+
function renderDebugOverlay(tree, options) {
|
|
98
|
+
const board = {
|
|
99
|
+
mode: options.mode ?? "collapsed",
|
|
100
|
+
labels: options.labels ?? true,
|
|
101
|
+
borders: options.borders ?? true,
|
|
102
|
+
selectedNodeId: options.selectedNodeId
|
|
103
|
+
};
|
|
104
|
+
const behavior = getMachinaDebugOverlayBehavior(board);
|
|
105
|
+
if (!behavior.visible) return null;
|
|
106
|
+
const nodes = collectOverlayNodes(tree);
|
|
107
|
+
return /* @__PURE__ */ jsxs(
|
|
108
|
+
"div",
|
|
109
|
+
{
|
|
110
|
+
"data-testid": "machina-debug-overlay",
|
|
111
|
+
"data-machina-debug-overlay-mode": board.mode,
|
|
112
|
+
style: {
|
|
113
|
+
position: "absolute",
|
|
114
|
+
inset: 0,
|
|
115
|
+
pointerEvents: behavior.pointerEvents,
|
|
116
|
+
zIndex: 1e4,
|
|
117
|
+
boxSizing: "border-box"
|
|
118
|
+
},
|
|
119
|
+
children: [
|
|
120
|
+
nodes.map((node) => /* @__PURE__ */ jsx(
|
|
121
|
+
"div",
|
|
122
|
+
{
|
|
123
|
+
"data-testid": `machina-debug-overlay-node-${node.id}`,
|
|
124
|
+
"data-machina-debug-overlay-node-id": node.id,
|
|
125
|
+
style: {
|
|
126
|
+
position: "absolute",
|
|
127
|
+
left: node.rect.x - tree.rect.x,
|
|
128
|
+
top: node.rect.y - tree.rect.y,
|
|
129
|
+
width: node.rect.width,
|
|
130
|
+
height: node.rect.height,
|
|
131
|
+
boxSizing: "border-box",
|
|
132
|
+
border: behavior.showBorders ? "1px solid rgba(14, 165, 233, 0.9)" : "0",
|
|
133
|
+
pointerEvents: behavior.pointerEvents
|
|
134
|
+
},
|
|
135
|
+
children: behavior.showLabels ? /* @__PURE__ */ jsx(
|
|
136
|
+
"span",
|
|
137
|
+
{
|
|
138
|
+
style: {
|
|
139
|
+
position: "absolute",
|
|
140
|
+
left: 0,
|
|
141
|
+
top: 0,
|
|
142
|
+
fontSize: 10,
|
|
143
|
+
lineHeight: "12px",
|
|
144
|
+
background: "rgba(14, 165, 233, 0.9)",
|
|
145
|
+
color: "white",
|
|
146
|
+
padding: "0 3px"
|
|
147
|
+
},
|
|
148
|
+
children: node.debugLabel ?? node.id
|
|
149
|
+
}
|
|
150
|
+
) : null
|
|
151
|
+
},
|
|
152
|
+
node.id
|
|
153
|
+
)),
|
|
154
|
+
behavior.showPanel ? /* @__PURE__ */ jsxs(
|
|
155
|
+
"div",
|
|
156
|
+
{
|
|
157
|
+
"data-testid": "machina-debug-overlay-panel",
|
|
158
|
+
style: {
|
|
159
|
+
position: "absolute",
|
|
160
|
+
right: 8,
|
|
161
|
+
top: 8,
|
|
162
|
+
background: "rgba(15, 23, 42, 0.92)",
|
|
163
|
+
color: "white",
|
|
164
|
+
padding: 8
|
|
165
|
+
},
|
|
166
|
+
children: [
|
|
167
|
+
"Debug overlay",
|
|
168
|
+
board.selectedNodeId ? `: ${board.selectedNodeId}` : ""
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
) : null
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
}
|
|
91
176
|
function MachinaReactView(props) {
|
|
92
177
|
const {
|
|
93
178
|
layout,
|
|
@@ -102,7 +187,8 @@ function MachinaReactView(props) {
|
|
|
102
187
|
nodeContentVisibility = "none",
|
|
103
188
|
nodeContainIntrinsicSize,
|
|
104
189
|
layers = { base: { z: 0 } },
|
|
105
|
-
defaultLayer = "base"
|
|
190
|
+
defaultLayer = "base",
|
|
191
|
+
debugOverlay
|
|
106
192
|
} = props;
|
|
107
193
|
const tree = toResolvedTree(layout);
|
|
108
194
|
const wrapperStyle = {
|
|
@@ -111,21 +197,24 @@ function MachinaReactView(props) {
|
|
|
111
197
|
height: tree.rect.height,
|
|
112
198
|
...style
|
|
113
199
|
};
|
|
114
|
-
return /* @__PURE__ */
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
200
|
+
return /* @__PURE__ */ jsxs("div", { className, style: wrapperStyle, "data-machina-root-id": tree.id, children: [
|
|
201
|
+
renderNode(
|
|
202
|
+
tree,
|
|
203
|
+
tree.rect,
|
|
204
|
+
views,
|
|
205
|
+
viewData,
|
|
206
|
+
nodeData,
|
|
207
|
+
nodeClassName,
|
|
208
|
+
debug,
|
|
209
|
+
nodeContainment,
|
|
210
|
+
nodeContentVisibility,
|
|
211
|
+
nodeContainIntrinsicSize,
|
|
212
|
+
layout.nodes,
|
|
213
|
+
layers,
|
|
214
|
+
defaultLayer
|
|
215
|
+
),
|
|
216
|
+
debugOverlay ? renderDebugOverlay(tree, debugOverlay) : null
|
|
217
|
+
] });
|
|
129
218
|
}
|
|
130
219
|
|
|
131
220
|
export {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
constructor(code, message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = "MachinaLayoutError";
|
|
7
|
-
this.code = code;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
MachinaLayoutError
|
|
3
|
+
} from "./chunk-VREK57S3.js";
|
|
10
4
|
|
|
11
5
|
// src/toResolvedTree.ts
|
|
12
6
|
function toResolvedTree(document) {
|
|
@@ -61,6 +55,5 @@ function toResolvedTree(document) {
|
|
|
61
55
|
}
|
|
62
56
|
|
|
63
57
|
export {
|
|
64
|
-
MachinaLayoutError,
|
|
65
58
|
toResolvedTree
|
|
66
59
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDeusSnapshot,
|
|
3
|
+
stepDeusMachine
|
|
4
|
+
} from "./chunk-2ZQ2RFFI.js";
|
|
5
|
+
|
|
6
|
+
// src/react-common/useDeusMachine.ts
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
8
|
+
function resolveInitialBoard(initialBoard) {
|
|
9
|
+
return typeof initialBoard === "function" ? initialBoard() : initialBoard;
|
|
10
|
+
}
|
|
11
|
+
function useDeusMachine(machine, initialBoard) {
|
|
12
|
+
const initialBoardRef = useRef(initialBoard);
|
|
13
|
+
initialBoardRef.current = initialBoard;
|
|
14
|
+
const createSnapshot = useCallback(
|
|
15
|
+
(board) => createDeusSnapshot(machine, resolveInitialBoard(board ?? initialBoardRef.current)),
|
|
16
|
+
[machine]
|
|
17
|
+
);
|
|
18
|
+
const [snapshot, setSnapshot] = useState(() => createSnapshot());
|
|
19
|
+
const snapshotRef = useRef(snapshot);
|
|
20
|
+
const [lastTrace, setLastTrace] = useState(null);
|
|
21
|
+
const didMountRef = useRef(false);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!didMountRef.current) {
|
|
24
|
+
didMountRef.current = true;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const nextSnapshot = createSnapshot();
|
|
28
|
+
snapshotRef.current = nextSnapshot;
|
|
29
|
+
setSnapshot(nextSnapshot);
|
|
30
|
+
setLastTrace(null);
|
|
31
|
+
}, [createSnapshot]);
|
|
32
|
+
const dispatch = useCallback(
|
|
33
|
+
(event) => {
|
|
34
|
+
const result = stepDeusMachine(machine, snapshotRef.current, event);
|
|
35
|
+
snapshotRef.current = result.snapshot;
|
|
36
|
+
setSnapshot(result.snapshot);
|
|
37
|
+
setLastTrace(result.trace);
|
|
38
|
+
return result;
|
|
39
|
+
},
|
|
40
|
+
[machine]
|
|
41
|
+
);
|
|
42
|
+
const reset = useCallback(
|
|
43
|
+
(board) => {
|
|
44
|
+
const nextSnapshot = createSnapshot(board);
|
|
45
|
+
snapshotRef.current = nextSnapshot;
|
|
46
|
+
setSnapshot(nextSnapshot);
|
|
47
|
+
setLastTrace(null);
|
|
48
|
+
},
|
|
49
|
+
[createSnapshot]
|
|
50
|
+
);
|
|
51
|
+
return {
|
|
52
|
+
snapshot,
|
|
53
|
+
board: snapshot.board,
|
|
54
|
+
state: snapshot.state,
|
|
55
|
+
dispatch,
|
|
56
|
+
lastTrace,
|
|
57
|
+
reset
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
useDeusMachine
|
|
63
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { e as DeusMachine } from './types-CWaup8Z6.js';
|
|
2
|
+
|
|
3
|
+
type MachinaDebugOverlayMode = "collapsed" | "nonInteractiveOverlay" | "interactivePanel";
|
|
4
|
+
type MachinaDebugOverlayBoard = {
|
|
5
|
+
mode: MachinaDebugOverlayMode;
|
|
6
|
+
labels: boolean;
|
|
7
|
+
borders: boolean;
|
|
8
|
+
selectedNodeId?: string;
|
|
9
|
+
};
|
|
10
|
+
type MachinaDebugOverlayEvent = {
|
|
11
|
+
type: "showOverlay";
|
|
12
|
+
} | {
|
|
13
|
+
type: "openPanel";
|
|
14
|
+
nodeId?: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "collapse";
|
|
17
|
+
} | {
|
|
18
|
+
type: "toggleLabels";
|
|
19
|
+
} | {
|
|
20
|
+
type: "toggleBorders";
|
|
21
|
+
} | {
|
|
22
|
+
type: "selectNode";
|
|
23
|
+
nodeId: string;
|
|
24
|
+
};
|
|
25
|
+
type MachinaDebugOverlayBehavior = {
|
|
26
|
+
visible: boolean;
|
|
27
|
+
pointerEvents: "none" | "auto";
|
|
28
|
+
consumesLayoutSpace: boolean;
|
|
29
|
+
showPanel: boolean;
|
|
30
|
+
showLabels: boolean;
|
|
31
|
+
showBorders: boolean;
|
|
32
|
+
};
|
|
33
|
+
declare function createMachinaDebugOverlayMachine(): DeusMachine<MachinaDebugOverlayBoard, MachinaDebugOverlayEvent>;
|
|
34
|
+
declare function getMachinaDebugOverlayBehavior(board: MachinaDebugOverlayBoard): MachinaDebugOverlayBehavior;
|
|
35
|
+
|
|
36
|
+
export { type MachinaDebugOverlayMode as M, type MachinaDebugOverlayBehavior as a, type MachinaDebugOverlayBoard as b, type MachinaDebugOverlayEvent as c, createMachinaDebugOverlayMachine as d, getMachinaDebugOverlayBehavior as g };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { U as UtilityCandidate, J as JudgeUtilityOptions, f as UtilityJudgment, D as DeusEvent, e as DeusMachine, a as DeusSnapshot, b as DeusStatePath, d as DeusStepTrace, c as DeusStepResult } from '../types-CWaup8Z6.js';
|
|
2
|
+
export { g as DeusAction, h as DeusMachinaError, i as DeusStateRow, j as DeusTransitionRow, k as DeusTransitionTrace, l as DeusUtilityTransitionCandidate, m as UtilityCandidateResult, n as UtilityScore } from '../types-CWaup8Z6.js';
|
|
3
|
+
export { a as MachinaDebugOverlayBehavior, b as MachinaDebugOverlayBoard, c as MachinaDebugOverlayEvent, M as MachinaDebugOverlayMode, d as createMachinaDebugOverlayMachine, g as getMachinaDebugOverlayBehavior } from '../debugOverlay-fWLv1cS7.js';
|
|
4
|
+
|
|
5
|
+
declare function judgeUtility<TContext, TKey extends string = string>(context: TContext, candidates: readonly UtilityCandidate<TContext, TKey>[], options?: JudgeUtilityOptions<TKey>): UtilityJudgment<TKey>;
|
|
6
|
+
|
|
7
|
+
declare function formatDeusPath(path: DeusStatePath): string;
|
|
8
|
+
declare function sameDeusPath(a: DeusStatePath, b: DeusStatePath): boolean;
|
|
9
|
+
declare function isDeusAncestorPath(ancestor: DeusStatePath, path: DeusStatePath): boolean;
|
|
10
|
+
declare function defineDeusMachine<TBoard, TEvent extends DeusEvent>(machine: DeusMachine<TBoard, TEvent>): DeusMachine<TBoard, TEvent>;
|
|
11
|
+
declare function createDeusSnapshot<TBoard, TEvent extends DeusEvent>(machine: DeusMachine<TBoard, TEvent>, board: TBoard): DeusSnapshot<TBoard>;
|
|
12
|
+
declare function stepDeusMachine<TBoard, TEvent extends DeusEvent>(machine: DeusMachine<TBoard, TEvent>, snapshot: DeusSnapshot<TBoard>, event: NoInfer<TEvent>): DeusStepResult<TBoard>;
|
|
13
|
+
declare function formatDeusStepTrace(trace: DeusStepTrace): string;
|
|
14
|
+
|
|
15
|
+
export { DeusEvent, DeusMachine, DeusSnapshot, DeusStatePath, DeusStepResult, DeusStepTrace, JudgeUtilityOptions, UtilityCandidate, UtilityJudgment, createDeusSnapshot, defineDeusMachine, formatDeusPath, formatDeusStepTrace, isDeusAncestorPath, judgeUtility, sameDeusPath, stepDeusMachine };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DeusMachinaError,
|
|
3
|
+
createDeusSnapshot,
|
|
4
|
+
createMachinaDebugOverlayMachine,
|
|
5
|
+
defineDeusMachine,
|
|
6
|
+
formatDeusPath,
|
|
7
|
+
formatDeusStepTrace,
|
|
8
|
+
getMachinaDebugOverlayBehavior,
|
|
9
|
+
isDeusAncestorPath,
|
|
10
|
+
judgeUtility,
|
|
11
|
+
sameDeusPath,
|
|
12
|
+
stepDeusMachine
|
|
13
|
+
} from "../chunk-2ZQ2RFFI.js";
|
|
14
|
+
export {
|
|
15
|
+
DeusMachinaError,
|
|
16
|
+
createDeusSnapshot,
|
|
17
|
+
createMachinaDebugOverlayMachine,
|
|
18
|
+
defineDeusMachine,
|
|
19
|
+
formatDeusPath,
|
|
20
|
+
formatDeusStepTrace,
|
|
21
|
+
getMachinaDebugOverlayBehavior,
|
|
22
|
+
isDeusAncestorPath,
|
|
23
|
+
judgeUtility,
|
|
24
|
+
sameDeusPath,
|
|
25
|
+
stepDeusMachine
|
|
26
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { M as MachinaDomSummary } from '../types-bJlg6wno.js';
|
|
2
|
+
import { M as MachinaViewport, a as MachinaScreenViewportTask } from '../screenCatalog-ZjonGiOi.js';
|
|
3
|
+
import '../types-CYgsjDai.js';
|
|
4
|
+
|
|
5
|
+
type MachinaHandoffArtifactPaths = {
|
|
6
|
+
screenshot?: string;
|
|
7
|
+
domSummary?: string;
|
|
8
|
+
layoutSnapshot?: string;
|
|
9
|
+
manifest: string;
|
|
10
|
+
};
|
|
11
|
+
type MachinaHandoffBundleManifest = {
|
|
12
|
+
schemaVersion: 1;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
route?: string;
|
|
15
|
+
fixture?: string;
|
|
16
|
+
screenKey?: string;
|
|
17
|
+
viewportKey?: string;
|
|
18
|
+
viewport?: MachinaViewport;
|
|
19
|
+
tags?: readonly string[];
|
|
20
|
+
artifactBaseName?: string;
|
|
21
|
+
artifacts: MachinaHandoffArtifactPaths;
|
|
22
|
+
metadata?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
type WriteMachinaHandoffBundleInput = {
|
|
25
|
+
outputDir: string;
|
|
26
|
+
artifactBaseName?: string;
|
|
27
|
+
screenshotPath?: string;
|
|
28
|
+
domSummary?: MachinaDomSummary;
|
|
29
|
+
layoutSnapshot?: unknown;
|
|
30
|
+
task?: MachinaScreenViewportTask;
|
|
31
|
+
route?: string;
|
|
32
|
+
fixture?: string;
|
|
33
|
+
tags?: readonly string[];
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
createdAt?: string;
|
|
36
|
+
};
|
|
37
|
+
type WriteMachinaHandoffBundleResult = {
|
|
38
|
+
manifest: MachinaHandoffBundleManifest;
|
|
39
|
+
paths: MachinaHandoffArtifactPaths;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
declare function writeMachinaHandoffBundle(input: WriteMachinaHandoffBundleInput): Promise<WriteMachinaHandoffBundleResult>;
|
|
43
|
+
|
|
44
|
+
export { type MachinaHandoffArtifactPaths, type MachinaHandoffBundleManifest, type WriteMachinaHandoffBundleInput, type WriteMachinaHandoffBundleResult, writeMachinaHandoffBundle };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
slugMachinaArtifactName
|
|
3
|
+
} from "../chunk-33CKBEJH.js";
|
|
4
|
+
import "../chunk-VREK57S3.js";
|
|
5
|
+
|
|
6
|
+
// src/handoff/writeMachinaHandoffBundle.ts
|
|
7
|
+
import { copyFile, mkdir, writeFile } from "fs/promises";
|
|
8
|
+
import path from "path";
|
|
9
|
+
function artifactBaseName(input) {
|
|
10
|
+
const candidate = input.artifactBaseName ?? input.task?.artifactBaseName ?? [
|
|
11
|
+
input.route ?? input.task?.route,
|
|
12
|
+
input.fixture ?? input.task?.fixture,
|
|
13
|
+
input.task?.viewportKey
|
|
14
|
+
].filter((part) => typeof part === "string" && part.trim() !== "").join("-") ?? "";
|
|
15
|
+
return slugMachinaArtifactName(candidate === "" ? "machina-handoff" : candidate);
|
|
16
|
+
}
|
|
17
|
+
function orderedUnique(...groups) {
|
|
18
|
+
const result = [];
|
|
19
|
+
for (const group of groups) {
|
|
20
|
+
for (const tag of group ?? []) {
|
|
21
|
+
if (!result.includes(tag)) result.push(tag);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result.length === 0 ? void 0 : result;
|
|
25
|
+
}
|
|
26
|
+
function json(value) {
|
|
27
|
+
return `${JSON.stringify(value, null, 2)}
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
function screenshotExtension(screenshotPath) {
|
|
31
|
+
const extension = path.extname(screenshotPath);
|
|
32
|
+
return extension === "" ? ".png" : extension;
|
|
33
|
+
}
|
|
34
|
+
async function writeMachinaHandoffBundle(input) {
|
|
35
|
+
if (typeof input.outputDir !== "string" || input.outputDir.trim() === "") {
|
|
36
|
+
throw new Error("outputDir must be a non-empty string");
|
|
37
|
+
}
|
|
38
|
+
const outputDir = path.resolve(input.outputDir);
|
|
39
|
+
await mkdir(outputDir, { recursive: true });
|
|
40
|
+
const base = artifactBaseName(input);
|
|
41
|
+
const artifactNames = { manifest: `${base}__handoff.json` };
|
|
42
|
+
const paths = {
|
|
43
|
+
manifest: path.join(outputDir, artifactNames.manifest)
|
|
44
|
+
};
|
|
45
|
+
if (input.screenshotPath !== void 0) {
|
|
46
|
+
artifactNames.screenshot = `${base}__screenshot${screenshotExtension(input.screenshotPath)}`;
|
|
47
|
+
paths.screenshot = path.join(outputDir, artifactNames.screenshot);
|
|
48
|
+
await copyFile(input.screenshotPath, paths.screenshot);
|
|
49
|
+
}
|
|
50
|
+
if (input.domSummary !== void 0) {
|
|
51
|
+
artifactNames.domSummary = `${base}__dom-summary.json`;
|
|
52
|
+
paths.domSummary = path.join(outputDir, artifactNames.domSummary);
|
|
53
|
+
await writeFile(paths.domSummary, json(input.domSummary), "utf8");
|
|
54
|
+
}
|
|
55
|
+
if (input.layoutSnapshot !== void 0) {
|
|
56
|
+
artifactNames.layoutSnapshot = `${base}__machina-snapshot.json`;
|
|
57
|
+
paths.layoutSnapshot = path.join(outputDir, artifactNames.layoutSnapshot);
|
|
58
|
+
await writeFile(paths.layoutSnapshot, json(input.layoutSnapshot), "utf8");
|
|
59
|
+
}
|
|
60
|
+
const tags = orderedUnique(input.task?.tags, input.tags);
|
|
61
|
+
const manifest = {
|
|
62
|
+
schemaVersion: 1,
|
|
63
|
+
createdAt: input.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
64
|
+
artifacts: artifactNames
|
|
65
|
+
};
|
|
66
|
+
const route = input.route ?? input.task?.route;
|
|
67
|
+
const fixture = input.fixture ?? input.task?.fixture;
|
|
68
|
+
if (route !== void 0) manifest.route = route;
|
|
69
|
+
if (fixture !== void 0) manifest.fixture = fixture;
|
|
70
|
+
if (input.task !== void 0) {
|
|
71
|
+
manifest.screenKey = input.task.screenKey;
|
|
72
|
+
manifest.viewportKey = input.task.viewportKey;
|
|
73
|
+
manifest.viewport = input.task.viewport;
|
|
74
|
+
}
|
|
75
|
+
if (tags !== void 0) manifest.tags = tags;
|
|
76
|
+
manifest.artifactBaseName = base;
|
|
77
|
+
if (input.metadata !== void 0) manifest.metadata = input.metadata;
|
|
78
|
+
await writeFile(paths.manifest, json(manifest), "utf8");
|
|
79
|
+
return { manifest, paths };
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
writeMachinaHandoffBundle
|
|
83
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { E as EdgeInsets, U as UiLength,
|
|
2
|
-
export {
|
|
3
|
-
export { MachinaReactView, MachinaReactViewProps, MachinaSlotProps } from './
|
|
1
|
+
import { E as EdgeInsets, U as UiLength, a as Rect, O as OffsetSpec, L as LayoutRow, c as LayoutDocument, F as FrameSpec, R as ResolvedLayoutDocument, d as ResolvedLayoutTree, b as ResolvedLayoutNode, N as NodeId, e as LayerName, S as StackAxis, A as ArrangeSpec } from './types-CYgsjDai.js';
|
|
2
|
+
export { f as AbsoluteFrame, g as AnchorFrame, C as CellFrame, h as EdgeRef, i as FillFrame, j as FixedFrame, G as GridArrange, k as GridTrack, l as GuideFrame, m as GuideLength, n as LayoutNode, o as LayoutRowVariant, p as LayoutVariantCondition, q as RectEdge, r as RootFrame, s as StackAlign, t as StackArrange, u as StackJustify } from './types-CYgsjDai.js';
|
|
3
|
+
export { M as MachinaReactDebugOverlayOptions, a as MachinaReactView, b as MachinaReactViewProps, c as MachinaSlotProps } from './MachinaReactView-Bau5bErA.js';
|
|
4
4
|
export { c as MachinaBulletItem, d as MachinaInline, e as MachinaTextAlign, f as MachinaTextBlock, g as MachinaTextDiagnostic, h as MachinaTextDiagnosticCode, i as MachinaTextDiagnosticLevel, b as MachinaTextDocument, j as MachinaTextLeading, k as MachinaTextOverflow, a as MachinaTextSource, M as MachinaTextSpec, l as MachinaTextVariant, m as MachinaTextVerticalAlign, n as MachinaTextWrap, P as ParseMachinaTextResult } from './types-C4poVJpR.js';
|
|
5
5
|
export { parseMachinaText, parseMachinaTextInline } from './text/index.js';
|
|
6
6
|
export { MachinaTextView, MachinaTextViewProps } from './text/react/index.js';
|
|
7
|
+
export { b as MachinaScreen, c as MachinaScreenCatalog, a as MachinaScreenViewportTask, M as MachinaViewport, d as MachinaViewportMatrix, e as createViewportMatrix, f as defineMachinaScreens, g as defineMachinaViewports, h as expandScreenViewportTasks, i as getMachinaViewport, s as slugMachinaArtifactName } from './screenCatalog-ZjonGiOi.js';
|
|
7
8
|
import 'react';
|
|
9
|
+
import './debugOverlay-fWLv1cS7.js';
|
|
10
|
+
import './types-CWaup8Z6.js';
|
|
8
11
|
|
|
9
|
-
type MachinaLayoutErrorCode = "EmptyRows" | "MissingRoot" | "MultipleRoots" | "DuplicateId" | "InvalidId" | "MissingParent" | "UnknownParent" | "SelfParent" | "Cycle" | "UnreachableNode" | "NonFiniteNumber" | "InvalidLengthUnit" | "InvalidZ" | "InvalidVariantCondition" | "NegativeSize" | "NegativeGap" | "NegativePadding" | "InvalidAnchorHorizontal" | "InvalidAnchorVertical" | "NegativeResolvedSize" | "FixedFrameWithoutArranger" | "FillFrameWithoutArranger" | "InvalidFillWeight" | "StackChildMustBeFixed" | "StackContentNegative" | "StackOverflow" | "CellFrameWithoutGrid" | "GridChildMustBeCell" | "InvalidGridTrack" | "InvalidGridCell" | "GridContentNegative" | "GridOverflow" | "RootFrameNotRoot" | "RootFrameWithoutRoot" | "IncompatibleLayouts" | "GuideTargetNotFound" | "GuideSelfReference" | "GuideReferenceCycle" | "GuideInvalidEdgeForAxis" | "GuideTooManyReferencesPerAxis" | "InvalidGuideFrame" | "GuideTargetUnresolved";
|
|
12
|
+
type MachinaLayoutErrorCode = "EmptyRows" | "MissingRoot" | "MultipleRoots" | "DuplicateId" | "InvalidId" | "MissingParent" | "UnknownParent" | "SelfParent" | "Cycle" | "UnreachableNode" | "NonFiniteNumber" | "InvalidLengthUnit" | "InvalidZ" | "InvalidVariantCondition" | "NegativeSize" | "NegativeGap" | "NegativePadding" | "InvalidAnchorHorizontal" | "InvalidAnchorVertical" | "NegativeResolvedSize" | "FixedFrameWithoutArranger" | "FillFrameWithoutArranger" | "InvalidFillWeight" | "StackChildMustBeFixed" | "StackContentNegative" | "StackOverflow" | "ExpectedStackArrange" | "StackQueryInvalidRange" | "CellFrameWithoutGrid" | "GridChildMustBeCell" | "InvalidGridTrack" | "InvalidGridCell" | "GridContentNegative" | "GridOverflow" | "RootFrameNotRoot" | "RootFrameWithoutRoot" | "IncompatibleLayouts" | "GuideTargetNotFound" | "GuideSelfReference" | "GuideReferenceCycle" | "GuideInvalidEdgeForAxis" | "GuideTooManyReferencesPerAxis" | "InvalidGuideFrame" | "GuideTargetUnresolved" | "InvalidViewport" | "DuplicateViewportKey" | "UnknownViewportKey" | "InvalidScreen" | "DuplicateScreenKey" | "UnknownScreenKey";
|
|
10
13
|
declare class MachinaLayoutError extends Error {
|
|
11
14
|
readonly code: MachinaLayoutErrorCode;
|
|
12
15
|
constructor(code: MachinaLayoutErrorCode, message: string);
|
|
@@ -39,8 +42,47 @@ declare function flattenResolvedTree(tree: ResolvedLayoutTree): ResolvedLayoutNo
|
|
|
39
42
|
|
|
40
43
|
declare function formatRect(rect: Rect): string;
|
|
41
44
|
|
|
45
|
+
type StackChildMetric = {
|
|
46
|
+
id: NodeId;
|
|
47
|
+
rect: Rect;
|
|
48
|
+
mainStart: number;
|
|
49
|
+
mainEnd: number;
|
|
50
|
+
mainSize: number;
|
|
51
|
+
crossStart: number;
|
|
52
|
+
crossEnd: number;
|
|
53
|
+
crossSize: number;
|
|
54
|
+
frameKind: FrameSpec["kind"];
|
|
55
|
+
z?: number;
|
|
56
|
+
layer?: LayerName;
|
|
57
|
+
};
|
|
58
|
+
type StackMainAxisMetrics = {
|
|
59
|
+
parentId: NodeId;
|
|
60
|
+
axis: StackAxis;
|
|
61
|
+
parentRect: Rect;
|
|
62
|
+
contentRect: Rect;
|
|
63
|
+
padding: EdgeInsets;
|
|
64
|
+
gap: number;
|
|
65
|
+
childIds: NodeId[];
|
|
66
|
+
childMetrics: StackChildMetric[];
|
|
67
|
+
contentMainSize: number;
|
|
68
|
+
contentCrossSize: number;
|
|
69
|
+
totalChildMainSize: number;
|
|
70
|
+
totalGapSize: number;
|
|
71
|
+
usedMainSize: number;
|
|
72
|
+
unusedMainSize: number;
|
|
73
|
+
};
|
|
74
|
+
declare function getArrangeContentRect(parentRect: Rect, arrange?: ArrangeSpec): Rect;
|
|
75
|
+
declare function getStackContentRect(layout: ResolvedLayoutDocument, parentId: NodeId): Rect;
|
|
76
|
+
declare function getStackMainAxisMetrics(layout: ResolvedLayoutDocument, parentId: NodeId): StackMainAxisMetrics;
|
|
77
|
+
declare function getStackChildRects(layout: ResolvedLayoutDocument, parentId: NodeId): Record<NodeId, Rect>;
|
|
78
|
+
declare function getRemainingStackRect(layout: ResolvedLayoutDocument, options: {
|
|
79
|
+
parentId: NodeId;
|
|
80
|
+
afterChildren?: NodeId[];
|
|
81
|
+
beforeChildren?: NodeId[];
|
|
82
|
+
}): Rect;
|
|
83
|
+
|
|
42
84
|
declare function lerpNumber(a: number, b: number, t: number): number;
|
|
43
85
|
declare function lerpRect(a: Rect, b: Rect, t: number): Rect;
|
|
44
86
|
declare function lerpResolvedLayouts(a: ResolvedLayoutDocument, b: ResolvedLayoutDocument, t: number): ResolvedLayoutDocument;
|
|
45
87
|
|
|
46
|
-
export { EdgeInsets, FrameSpec, LayoutDocument, LayoutRow, MachinaLayoutError, type MachinaLayoutErrorCode, OffsetSpec, Rect, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutTree, UiLength, applyOffset, assertFiniteNumber, assertNonNegativeGap, assertNonNegativePadding, assertNonNegativeSize, compileLayoutRows, flattenResolvedTree, formatRect, lerpNumber, lerpRect, lerpResolvedLayouts, normalizePadding, resolveFrame, resolveLayoutDocument, resolveLayoutRows, resolveUiLength, selectLayoutRowsForRoot, toResolvedTree };
|
|
88
|
+
export { ArrangeSpec, EdgeInsets, FrameSpec, LayerName, LayoutDocument, LayoutRow, MachinaLayoutError, type MachinaLayoutErrorCode, NodeId, OffsetSpec, Rect, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutTree, StackAxis, type StackChildMetric, type StackMainAxisMetrics, UiLength, applyOffset, assertFiniteNumber, assertNonNegativeGap, assertNonNegativePadding, assertNonNegativeSize, compileLayoutRows, flattenResolvedTree, formatRect, getArrangeContentRect, getRemainingStackRect, getStackChildRects, getStackContentRect, getStackMainAxisMetrics, lerpNumber, lerpRect, lerpResolvedLayouts, normalizePadding, resolveFrame, resolveLayoutDocument, resolveLayoutRows, resolveUiLength, selectLayoutRowsForRoot, toResolvedTree };
|