machinalayout 0.1.0 → 0.2.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/README.md +280 -49
- package/dist/chunk-BJOQRPPX.js +382 -0
- package/dist/chunk-HU6XYOH7.js +133 -0
- package/dist/chunk-KYWOCAHK.js +205 -0
- package/dist/chunk-RJYRJ3LD.js +0 -0
- package/dist/chunk-TR24ERZT.js +66 -0
- package/dist/dispatch/index.d.ts +49 -0
- package/dist/dispatch/index.js +217 -0
- package/dist/index.d.ts +15 -238
- package/dist/index.js +596 -591
- package/dist/react/index.d.ts +33 -0
- package/dist/react/index.js +7 -0
- package/dist/react-native/index.d.ts +30 -0
- package/dist/react-native/index.js +83 -0
- package/dist/text/index.d.ts +10 -0
- package/dist/text/index.js +9 -0
- package/dist/text/react/index.d.ts +14 -0
- package/dist/text/react/index.js +7 -0
- package/dist/text/react-native/index.d.ts +16 -0
- package/dist/text/react-native/index.js +155 -0
- package/dist/text/vue/index.d.ts +113 -0
- package/dist/text/vue/index.js +202 -0
- package/dist/types-BudfpzZX.d.ts +184 -0
- package/dist/types-C4poVJpR.d.ts +74 -0
- package/dist/vue/index.d.ts +173 -0
- package/dist/vue/index.js +111 -0
- package/docs/adapter-packaging-a0-plan.md +352 -0
- package/docs/adapters.md +19 -0
- package/docs/api-coherence-m8-audit.md +397 -0
- package/docs/error-codes.md +84 -0
- package/docs/grid-arrange-m5a-contract.md +480 -0
- package/docs/grid-arrange.md +51 -0
- package/docs/layout-interpolation.md +52 -0
- package/docs/machina-dispatch-d0-contract.md +496 -0
- package/docs/machina-dispatch.md +143 -0
- package/docs/named-layers.md +40 -0
- package/docs/react-adapter.md +51 -69
- package/docs/react-native-adapter.md +56 -0
- package/docs/react-native-text-renderer.md +50 -0
- package/docs/reference-alignment-m7a-contract.md +384 -0
- package/docs/reference-alignment.md +44 -0
- package/docs/responsive-variants.md +54 -0
- package/docs/vue-adapter.md +55 -0
- package/docs/vue-text-renderer.md +55 -0
- package/package.json +60 -5
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
// src/text/parseMachinaText.ts
|
|
2
|
+
function makeDiagnostic(code, message, index, length, line, column) {
|
|
3
|
+
return { code, message, index, length, line, column, level: "error" };
|
|
4
|
+
}
|
|
5
|
+
function toLines(source) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
let i = 0;
|
|
8
|
+
let line = 1;
|
|
9
|
+
while (i <= source.length) {
|
|
10
|
+
const start = i;
|
|
11
|
+
while (i < source.length && source[i] !== "\n" && source[i] !== "\r") i += 1;
|
|
12
|
+
const text = source.slice(start, i);
|
|
13
|
+
lines.push({ text, index: start, line });
|
|
14
|
+
if (i >= source.length) break;
|
|
15
|
+
if (source[i] === "\r" && source[i + 1] === "\n") i += 2;
|
|
16
|
+
else i += 1;
|
|
17
|
+
line += 1;
|
|
18
|
+
}
|
|
19
|
+
return lines;
|
|
20
|
+
}
|
|
21
|
+
function parseInline(text, lineIndex, line) {
|
|
22
|
+
const diagnostics = [];
|
|
23
|
+
const inline = [];
|
|
24
|
+
let cursor = 0;
|
|
25
|
+
const pushText = (t) => {
|
|
26
|
+
if (!t) return;
|
|
27
|
+
const prev = inline[inline.length - 1];
|
|
28
|
+
if (prev?.kind === "text") prev.text += t;
|
|
29
|
+
else inline.push({ kind: "text", text: t });
|
|
30
|
+
};
|
|
31
|
+
const allowedEscapes = /* @__PURE__ */ new Set(["\\", "*", "`", "[", "]", "(", ")", "-"]);
|
|
32
|
+
const consumeEscape = () => {
|
|
33
|
+
if (text[cursor] !== "\\") return false;
|
|
34
|
+
if (cursor === text.length - 1) {
|
|
35
|
+
diagnostics.push(
|
|
36
|
+
makeDiagnostic(
|
|
37
|
+
"invalid_escape",
|
|
38
|
+
"Dangling escape sequence.",
|
|
39
|
+
lineIndex + cursor,
|
|
40
|
+
1,
|
|
41
|
+
line,
|
|
42
|
+
cursor + 1
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
pushText("\\");
|
|
46
|
+
cursor += 1;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const escaped = text[cursor + 1];
|
|
50
|
+
if (allowedEscapes.has(escaped)) {
|
|
51
|
+
pushText(escaped);
|
|
52
|
+
cursor += 2;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
diagnostics.push(
|
|
56
|
+
makeDiagnostic(
|
|
57
|
+
"invalid_escape",
|
|
58
|
+
`Unsupported escape sequence: \\${escaped}`,
|
|
59
|
+
lineIndex + cursor,
|
|
60
|
+
2,
|
|
61
|
+
line,
|
|
62
|
+
cursor + 1
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
pushText(escaped);
|
|
66
|
+
cursor += 2;
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
while (cursor < text.length) {
|
|
70
|
+
if (consumeEscape()) continue;
|
|
71
|
+
if (text.startsWith("![", cursor)) {
|
|
72
|
+
diagnostics.push(
|
|
73
|
+
makeDiagnostic(
|
|
74
|
+
"unsupported_syntax",
|
|
75
|
+
"Images are not supported.",
|
|
76
|
+
lineIndex + cursor,
|
|
77
|
+
2,
|
|
78
|
+
line,
|
|
79
|
+
cursor + 1
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
pushText("![");
|
|
83
|
+
cursor += 2;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (text[cursor] === "`") {
|
|
87
|
+
const close = text.indexOf("`", cursor + 1);
|
|
88
|
+
if (close < 0) {
|
|
89
|
+
diagnostics.push(
|
|
90
|
+
makeDiagnostic(
|
|
91
|
+
"unclosed_inline",
|
|
92
|
+
"Unclosed inline code marker.",
|
|
93
|
+
lineIndex + cursor,
|
|
94
|
+
text.length - cursor,
|
|
95
|
+
line,
|
|
96
|
+
cursor + 1
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
pushText(text.slice(cursor));
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
inline.push({ kind: "code", text: text.slice(cursor + 1, close) });
|
|
103
|
+
cursor = close + 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (text.startsWith("**", cursor)) {
|
|
107
|
+
const close = text.indexOf("**", cursor + 2);
|
|
108
|
+
if (close < 0) {
|
|
109
|
+
diagnostics.push(
|
|
110
|
+
makeDiagnostic(
|
|
111
|
+
"unclosed_inline",
|
|
112
|
+
"Unclosed strong marker.",
|
|
113
|
+
lineIndex + cursor,
|
|
114
|
+
text.length - cursor,
|
|
115
|
+
line,
|
|
116
|
+
cursor + 1
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
pushText(text.slice(cursor));
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
const children = parseInline(text.slice(cursor + 2, close), lineIndex + cursor + 2, line);
|
|
123
|
+
diagnostics.push(...children.diagnostics);
|
|
124
|
+
inline.push({ kind: "strong", children: children.inline });
|
|
125
|
+
cursor = close + 2;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (text[cursor] === "*") {
|
|
129
|
+
const close = text.indexOf("*", cursor + 1);
|
|
130
|
+
if (close < 0) {
|
|
131
|
+
diagnostics.push(
|
|
132
|
+
makeDiagnostic(
|
|
133
|
+
"unclosed_inline",
|
|
134
|
+
"Unclosed emphasis marker.",
|
|
135
|
+
lineIndex + cursor,
|
|
136
|
+
text.length - cursor,
|
|
137
|
+
line,
|
|
138
|
+
cursor + 1
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
pushText(text.slice(cursor));
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
const children = parseInline(text.slice(cursor + 1, close), lineIndex + cursor + 1, line);
|
|
145
|
+
diagnostics.push(...children.diagnostics);
|
|
146
|
+
inline.push({ kind: "emphasis", children: children.inline });
|
|
147
|
+
cursor = close + 1;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (text[cursor] === "[") {
|
|
151
|
+
const closeBracket = text.indexOf("]", cursor + 1);
|
|
152
|
+
if (closeBracket < 0 || text[closeBracket + 1] !== "(") {
|
|
153
|
+
diagnostics.push(
|
|
154
|
+
makeDiagnostic(
|
|
155
|
+
"malformed_link",
|
|
156
|
+
"Malformed link syntax.",
|
|
157
|
+
lineIndex + cursor,
|
|
158
|
+
Math.max(1, text.length - cursor),
|
|
159
|
+
line,
|
|
160
|
+
cursor + 1
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
pushText("[");
|
|
164
|
+
cursor += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const closeParen = text.indexOf(")", closeBracket + 2);
|
|
168
|
+
if (closeParen < 0) {
|
|
169
|
+
diagnostics.push(
|
|
170
|
+
makeDiagnostic(
|
|
171
|
+
"malformed_link",
|
|
172
|
+
"Malformed link syntax.",
|
|
173
|
+
lineIndex + cursor,
|
|
174
|
+
text.length - cursor,
|
|
175
|
+
line,
|
|
176
|
+
cursor + 1
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
pushText(text.slice(cursor));
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
const label = text.slice(cursor + 1, closeBracket);
|
|
183
|
+
const href = text.slice(closeBracket + 2, closeParen);
|
|
184
|
+
if (label.length === 0) {
|
|
185
|
+
diagnostics.push(
|
|
186
|
+
makeDiagnostic(
|
|
187
|
+
"malformed_link",
|
|
188
|
+
"Link label cannot be empty.",
|
|
189
|
+
lineIndex + cursor,
|
|
190
|
+
closeParen - cursor + 1,
|
|
191
|
+
line,
|
|
192
|
+
cursor + 1
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
pushText(text.slice(cursor, closeParen + 1));
|
|
196
|
+
cursor = closeParen + 1;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const labelInline = parseInline(label, lineIndex + cursor + 1, line);
|
|
200
|
+
diagnostics.push(...labelInline.diagnostics);
|
|
201
|
+
inline.push({ kind: "link", href, children: labelInline.inline });
|
|
202
|
+
cursor = closeParen + 1;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const specials = ["![", "`", "**", "*", "[", "\\"];
|
|
206
|
+
let next = text.length;
|
|
207
|
+
for (const special of specials) {
|
|
208
|
+
const p = text.indexOf(special, cursor);
|
|
209
|
+
if (p >= 0 && p < next) next = p;
|
|
210
|
+
}
|
|
211
|
+
if (next === cursor) {
|
|
212
|
+
pushText(text[cursor]);
|
|
213
|
+
cursor += 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
pushText(text.slice(cursor, next));
|
|
217
|
+
cursor = next;
|
|
218
|
+
}
|
|
219
|
+
return { inline, diagnostics };
|
|
220
|
+
}
|
|
221
|
+
function classifyForbiddenBlock(line) {
|
|
222
|
+
if (/^#{1,6}\s+/.test(line)) return "heading_forbidden";
|
|
223
|
+
if (/^\d+\.\s+/.test(line)) return "unsupported_syntax";
|
|
224
|
+
if (/^\s*-\s+\[[ xX]\]\s+/.test(line)) return "unsupported_syntax";
|
|
225
|
+
if (/^>\s+/.test(line)) return "unsupported_syntax";
|
|
226
|
+
if (/^```/.test(line)) return "unsupported_syntax";
|
|
227
|
+
if (/^\s*<\/?[a-zA-Z][^>]*>/.test(line)) return "unsupported_syntax";
|
|
228
|
+
if (/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(line)) return "unsupported_syntax";
|
|
229
|
+
return void 0;
|
|
230
|
+
}
|
|
231
|
+
function parseBulletLine(line) {
|
|
232
|
+
if (line.startsWith("\\- ")) return void 0;
|
|
233
|
+
if (line.startsWith("- ")) return { depth: 1, text: line.slice(2) };
|
|
234
|
+
if (line.startsWith(" - ")) return { depth: 2, text: line.slice(4) };
|
|
235
|
+
if (line.startsWith(" - ")) return { depth: 3, text: line.slice(6) };
|
|
236
|
+
return void 0;
|
|
237
|
+
}
|
|
238
|
+
function parseMachinaTextInline(text) {
|
|
239
|
+
return parseInline(text, 0, 1);
|
|
240
|
+
}
|
|
241
|
+
function parseMachinaText(source) {
|
|
242
|
+
const src = typeof source === "string" ? { kind: "machina-text", text: source } : source;
|
|
243
|
+
if (src?.kind !== "plain" && src?.kind !== "machina-text") {
|
|
244
|
+
const diagnostic = makeDiagnostic(
|
|
245
|
+
"unsupported_syntax",
|
|
246
|
+
"Unsupported MachinaText source kind.",
|
|
247
|
+
0,
|
|
248
|
+
0,
|
|
249
|
+
1,
|
|
250
|
+
1
|
|
251
|
+
);
|
|
252
|
+
return { ok: false, document: { blocks: [] }, diagnostics: [diagnostic] };
|
|
253
|
+
}
|
|
254
|
+
if (src.kind === "plain") {
|
|
255
|
+
return {
|
|
256
|
+
ok: true,
|
|
257
|
+
document: { blocks: [{ kind: "paragraph", inline: [{ kind: "text", text: src.text }] }] },
|
|
258
|
+
diagnostics: []
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const blocks = [];
|
|
262
|
+
const diagnostics = [];
|
|
263
|
+
const lines = toLines(src.text);
|
|
264
|
+
let i = 0;
|
|
265
|
+
while (i < lines.length) {
|
|
266
|
+
const lineInfo = lines[i];
|
|
267
|
+
const trimmed = lineInfo.text.trim();
|
|
268
|
+
if (trimmed.length === 0) {
|
|
269
|
+
i += 1;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const forbiddenCode = classifyForbiddenBlock(lineInfo.text);
|
|
273
|
+
if (forbiddenCode) {
|
|
274
|
+
const code = forbiddenCode;
|
|
275
|
+
diagnostics.push(
|
|
276
|
+
makeDiagnostic(
|
|
277
|
+
code,
|
|
278
|
+
"Unsupported block syntax.",
|
|
279
|
+
lineInfo.index,
|
|
280
|
+
lineInfo.text.length || 1,
|
|
281
|
+
lineInfo.line,
|
|
282
|
+
1
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
blocks.push({ kind: "paragraph", inline: [{ kind: "text", text: lineInfo.text }] });
|
|
286
|
+
i += 1;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const bullet = parseBulletLine(lineInfo.text);
|
|
290
|
+
if (bullet) {
|
|
291
|
+
const items = [];
|
|
292
|
+
let lastTop;
|
|
293
|
+
while (i < lines.length) {
|
|
294
|
+
const current = lines[i];
|
|
295
|
+
if (current.text.trim().length === 0) break;
|
|
296
|
+
const currentBullet = parseBulletLine(current.text);
|
|
297
|
+
if (!currentBullet) break;
|
|
298
|
+
if (/^\s*-\s+\[[ xX]\]\s+/.test(current.text)) {
|
|
299
|
+
diagnostics.push(
|
|
300
|
+
makeDiagnostic(
|
|
301
|
+
"unsupported_syntax",
|
|
302
|
+
"Task lists are not supported.",
|
|
303
|
+
current.index,
|
|
304
|
+
current.text.length || 1,
|
|
305
|
+
current.line,
|
|
306
|
+
1
|
|
307
|
+
)
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (currentBullet.depth > 2) {
|
|
311
|
+
diagnostics.push(
|
|
312
|
+
makeDiagnostic(
|
|
313
|
+
"max_list_depth_exceeded",
|
|
314
|
+
"Maximum bullet depth is 2.",
|
|
315
|
+
current.index,
|
|
316
|
+
current.text.length || 1,
|
|
317
|
+
current.line,
|
|
318
|
+
1
|
|
319
|
+
)
|
|
320
|
+
);
|
|
321
|
+
const parsed3 = parseInline(
|
|
322
|
+
current.text.trim(),
|
|
323
|
+
current.index + (current.text.length - current.text.trimStart().length),
|
|
324
|
+
current.line
|
|
325
|
+
);
|
|
326
|
+
diagnostics.push(...parsed3.diagnostics);
|
|
327
|
+
blocks.push({
|
|
328
|
+
kind: "paragraph",
|
|
329
|
+
inline: parsed3.inline.length ? parsed3.inline : [{ kind: "text", text: current.text }]
|
|
330
|
+
});
|
|
331
|
+
i += 1;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const parsed2 = parseInline(
|
|
335
|
+
currentBullet.text,
|
|
336
|
+
current.index + (currentBullet.depth === 1 ? 2 : 4),
|
|
337
|
+
current.line
|
|
338
|
+
);
|
|
339
|
+
diagnostics.push(...parsed2.diagnostics);
|
|
340
|
+
const item = { inline: parsed2.inline };
|
|
341
|
+
if (currentBullet.depth === 1) {
|
|
342
|
+
items.push(item);
|
|
343
|
+
lastTop = item;
|
|
344
|
+
} else if (lastTop) {
|
|
345
|
+
if (!lastTop.children) lastTop.children = [];
|
|
346
|
+
lastTop.children.push(item);
|
|
347
|
+
} else {
|
|
348
|
+
diagnostics.push(
|
|
349
|
+
makeDiagnostic(
|
|
350
|
+
"unsupported_syntax",
|
|
351
|
+
"Nested bullet requires a parent bullet.",
|
|
352
|
+
current.index,
|
|
353
|
+
current.text.length || 1,
|
|
354
|
+
current.line,
|
|
355
|
+
1
|
|
356
|
+
)
|
|
357
|
+
);
|
|
358
|
+
blocks.push({ kind: "paragraph", inline: [{ kind: "text", text: current.text }] });
|
|
359
|
+
}
|
|
360
|
+
i += 1;
|
|
361
|
+
}
|
|
362
|
+
blocks.push({ kind: "bulletList", items });
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const paragraphLines = [];
|
|
366
|
+
while (i < lines.length && lines[i].text.trim().length > 0 && !parseBulletLine(lines[i].text) && !classifyForbiddenBlock(lines[i].text)) {
|
|
367
|
+
paragraphLines.push(lines[i]);
|
|
368
|
+
i += 1;
|
|
369
|
+
}
|
|
370
|
+
const paragraphText = paragraphLines.map((line) => line.text).join("\n");
|
|
371
|
+
const first = paragraphLines[0];
|
|
372
|
+
const parsed = parseInline(paragraphText, first?.index ?? 0, first?.line ?? 1);
|
|
373
|
+
diagnostics.push(...parsed.diagnostics);
|
|
374
|
+
blocks.push({ kind: "paragraph", inline: parsed.inline });
|
|
375
|
+
}
|
|
376
|
+
return { ok: diagnostics.every((d) => d.level !== "error"), document: { blocks }, diagnostics };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export {
|
|
380
|
+
parseMachinaTextInline,
|
|
381
|
+
parseMachinaText
|
|
382
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toResolvedTree
|
|
3
|
+
} from "./chunk-TR24ERZT.js";
|
|
4
|
+
|
|
5
|
+
// src/react/MachinaReactView.tsx
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
function normalizeLayerZ(value) {
|
|
9
|
+
if (value === void 0 || !Number.isFinite(value) || !Number.isInteger(value) || value < -5 || value > 5) {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function getEffectiveLayer(node, defaultLayer) {
|
|
15
|
+
return node.layer ?? defaultLayer;
|
|
16
|
+
}
|
|
17
|
+
function getEffectiveLayerZ(node, layers, defaultLayer) {
|
|
18
|
+
const layerName = getEffectiveLayer(node, defaultLayer);
|
|
19
|
+
return normalizeLayerZ(layers[layerName]?.z);
|
|
20
|
+
}
|
|
21
|
+
function renderNode(node, parentRect, views, viewData, nodeData, nodeClassName, debug, nodeContainment, nodeContentVisibility, nodeContainIntrinsicSize, nodesById, layers, defaultLayer) {
|
|
22
|
+
const viewKey = node.view ?? node.slot;
|
|
23
|
+
const View = viewKey ? views[viewKey] : void 0;
|
|
24
|
+
const selectedViewData = viewKey ? viewData?.[viewKey] : void 0;
|
|
25
|
+
const selectedNodeData = nodeData?.[node.id];
|
|
26
|
+
const left = node.rect.x - parentRect.x;
|
|
27
|
+
const top = node.rect.y - parentRect.y;
|
|
28
|
+
const effectiveLayer = getEffectiveLayer(node, defaultLayer);
|
|
29
|
+
const effectiveLayerZ = getEffectiveLayerZ(node, layers, defaultLayer);
|
|
30
|
+
const style = {
|
|
31
|
+
position: "absolute",
|
|
32
|
+
left,
|
|
33
|
+
top,
|
|
34
|
+
width: node.rect.width,
|
|
35
|
+
height: node.rect.height,
|
|
36
|
+
boxSizing: "border-box",
|
|
37
|
+
zIndex: effectiveLayerZ * 100 + (node.z ?? 0),
|
|
38
|
+
...nodeContainment === "layout-paint" ? { contain: "layout paint" } : null,
|
|
39
|
+
...nodeContainment === "strict" ? { contain: "strict" } : null,
|
|
40
|
+
...nodeContentVisibility === "auto" ? { contentVisibility: "auto" } : null,
|
|
41
|
+
...nodeContainIntrinsicSize !== void 0 ? { containIntrinsicSize: nodeContainIntrinsicSize } : null,
|
|
42
|
+
...debug ? { outline: "1px dashed rgba(59, 130, 246, 0.9)" } : null
|
|
43
|
+
};
|
|
44
|
+
const renderedSlot = View && nodesById[node.id] ? React.createElement(View, {
|
|
45
|
+
id: node.id,
|
|
46
|
+
rect: { ...node.rect },
|
|
47
|
+
debugLabel: node.debugLabel,
|
|
48
|
+
node: { ...nodesById[node.id], rect: { ...nodesById[node.id].rect } },
|
|
49
|
+
viewKey,
|
|
50
|
+
viewData: selectedViewData,
|
|
51
|
+
nodeData: selectedNodeData
|
|
52
|
+
}) : null;
|
|
53
|
+
return /* @__PURE__ */ jsxs(
|
|
54
|
+
"div",
|
|
55
|
+
{
|
|
56
|
+
"data-testid": `machina-node-${node.id}`,
|
|
57
|
+
className: nodeClassName,
|
|
58
|
+
style,
|
|
59
|
+
"data-machina-node-id": node.id,
|
|
60
|
+
"data-machina-slot": node.slot,
|
|
61
|
+
"data-machina-view": viewKey,
|
|
62
|
+
"data-machina-debug-label": node.debugLabel,
|
|
63
|
+
"data-machina-layer": effectiveLayer,
|
|
64
|
+
children: [
|
|
65
|
+
debug ? /* @__PURE__ */ jsx("small", { children: node.debugLabel ?? node.id }) : null,
|
|
66
|
+
renderedSlot,
|
|
67
|
+
[...node.children].map((child, index) => ({ child, index })).sort(
|
|
68
|
+
(a, b) => getEffectiveLayerZ(a.child, layers, defaultLayer) - getEffectiveLayerZ(b.child, layers, defaultLayer) || (a.child.z ?? 0) - (b.child.z ?? 0) || a.index - b.index
|
|
69
|
+
).map(
|
|
70
|
+
({ child }) => renderNode(
|
|
71
|
+
child,
|
|
72
|
+
node.rect,
|
|
73
|
+
views,
|
|
74
|
+
viewData,
|
|
75
|
+
nodeData,
|
|
76
|
+
nodeClassName,
|
|
77
|
+
debug,
|
|
78
|
+
nodeContainment,
|
|
79
|
+
nodeContentVisibility,
|
|
80
|
+
nodeContainIntrinsicSize,
|
|
81
|
+
nodesById,
|
|
82
|
+
layers,
|
|
83
|
+
defaultLayer
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
node.id
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
function MachinaReactView(props) {
|
|
92
|
+
const {
|
|
93
|
+
layout,
|
|
94
|
+
views = {},
|
|
95
|
+
viewData,
|
|
96
|
+
nodeData,
|
|
97
|
+
className,
|
|
98
|
+
style,
|
|
99
|
+
nodeClassName,
|
|
100
|
+
debug,
|
|
101
|
+
nodeContainment = "layout-paint",
|
|
102
|
+
nodeContentVisibility = "none",
|
|
103
|
+
nodeContainIntrinsicSize,
|
|
104
|
+
layers = { base: { z: 0 } },
|
|
105
|
+
defaultLayer = "base"
|
|
106
|
+
} = props;
|
|
107
|
+
const tree = toResolvedTree(layout);
|
|
108
|
+
const wrapperStyle = {
|
|
109
|
+
position: "relative",
|
|
110
|
+
width: tree.rect.width,
|
|
111
|
+
height: tree.rect.height,
|
|
112
|
+
...style
|
|
113
|
+
};
|
|
114
|
+
return /* @__PURE__ */ jsx("div", { className, style: wrapperStyle, "data-machina-root-id": tree.id, children: renderNode(
|
|
115
|
+
tree,
|
|
116
|
+
tree.rect,
|
|
117
|
+
views,
|
|
118
|
+
viewData,
|
|
119
|
+
nodeData,
|
|
120
|
+
nodeClassName,
|
|
121
|
+
debug,
|
|
122
|
+
nodeContainment,
|
|
123
|
+
nodeContentVisibility,
|
|
124
|
+
nodeContainIntrinsicSize,
|
|
125
|
+
layout.nodes,
|
|
126
|
+
layers,
|
|
127
|
+
defaultLayer
|
|
128
|
+
) });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export {
|
|
132
|
+
MachinaReactView
|
|
133
|
+
};
|