@pairdraw/design-jsx 0.0.0-stage → 0.16.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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/chunks/attributes.js +32 -0
- package/dist/chunks/attributes.js.map +1 -0
- package/dist/chunks/behaviours/elements.js +321 -0
- package/dist/chunks/behaviours/elements.js.map +1 -0
- package/dist/chunks/behaviours/render.js +368 -0
- package/dist/chunks/behaviours/render.js.map +1 -0
- package/dist/chunks/component-properties.js +809 -0
- package/dist/chunks/component-properties.js.map +1 -0
- package/dist/chunks/components.js +78 -0
- package/dist/chunks/components.js.map +1 -0
- package/dist/chunks/connectors.js +290 -0
- package/dist/chunks/connectors.js.map +1 -0
- package/dist/chunks/effects.js +57 -0
- package/dist/chunks/effects.js.map +1 -0
- package/dist/chunks/elements.js +618 -0
- package/dist/chunks/elements.js.map +1 -0
- package/dist/chunks/export/behaviours.js +113 -0
- package/dist/chunks/export/behaviours.js.map +1 -0
- package/dist/chunks/export/bindings.js +273 -0
- package/dist/chunks/export/bindings.js.map +1 -0
- package/dist/chunks/export/decoration.js +96 -0
- package/dist/chunks/export/decoration.js.map +1 -0
- package/dist/chunks/export/font.js +17 -0
- package/dist/chunks/export/font.js.map +1 -0
- package/dist/chunks/export/icons.js +34 -0
- package/dist/chunks/export/icons.js.map +1 -0
- package/dist/chunks/export/index.js +1390 -0
- package/dist/chunks/export/index.js.map +1 -0
- package/dist/chunks/fields.js +1065 -0
- package/dist/chunks/fields.js.map +1 -0
- package/dist/chunks/index.js +438 -0
- package/dist/chunks/index.js.map +1 -0
- package/dist/chunks/jsx-dev-runtime.js +16 -0
- package/dist/chunks/jsx-dev-runtime.js.map +1 -0
- package/dist/index.d.ts +543 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-runtime.d.ts +44 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/tree.d.ts +261 -0
- package/dist/tree.d.ts.map +1 -0
- package/package.json +54 -4
- package/src/attributes.ts +30 -0
- package/src/behaviours/elements.ts +47 -0
- package/src/behaviours/index.ts +253 -0
- package/src/behaviours/render.ts +144 -0
- package/src/component-properties.ts +428 -0
- package/src/components.ts +109 -0
- package/src/connectors.ts +316 -0
- package/src/definitions.ts +277 -0
- package/src/effects.ts +80 -0
- package/src/elements.ts +321 -0
- package/src/enums.ts +182 -0
- package/src/export/behaviours.ts +143 -0
- package/src/export/bindings.ts +155 -0
- package/src/export/decoration.ts +39 -0
- package/src/export/font.ts +25 -0
- package/src/export/helpers.ts +75 -0
- package/src/export/icons.ts +42 -0
- package/src/export/index.ts +297 -0
- package/src/export/paint.ts +276 -0
- package/src/export/props.ts +369 -0
- package/src/export/state.ts +52 -0
- package/src/export/text.ts +155 -0
- package/src/export/value.ts +99 -0
- package/src/export/variables.ts +393 -0
- package/src/fields.ts +39 -0
- package/src/figjam-text.ts +37 -0
- package/src/global.d.ts +4 -0
- package/src/helpers.ts +135 -0
- package/src/index.ts +155 -0
- package/src/jsx-dev-runtime.ts +1 -0
- package/src/jsx-runtime.ts +51 -0
- package/src/mini-react.ts +23 -0
- package/src/overrides/effects.ts +39 -0
- package/src/overrides/fills.ts +56 -0
- package/src/overrides/state.ts +55 -0
- package/src/overrides/strokes.ts +109 -0
- package/src/overrides/text.ts +116 -0
- package/src/overrides/vector.ts +122 -0
- package/src/paints.ts +230 -0
- package/src/props-overrides.ts +481 -0
- package/src/reconcile.ts +134 -0
- package/src/reference/authoring.md +76 -0
- package/src/reference/examples.ts +49 -0
- package/src/reference.ts +19 -0
- package/src/refs.ts +48 -0
- package/src/render.ts +147 -0
- package/src/renderer.ts +598 -0
- package/src/scalar-bindings.ts +36 -0
- package/src/schema.ts +213 -0
- package/src/services.ts +36 -0
- package/src/shapes-with-text.ts +73 -0
- package/src/stickies.ts +72 -0
- package/src/streaming/index.ts +47 -0
- package/src/streaming/literals.ts +82 -0
- package/src/streaming/projection.ts +189 -0
- package/src/text-content.ts +233 -0
- package/src/transform.ts +78 -0
- package/src/tree.ts +285 -0
- package/src/types.ts +13 -0
- package/src/variables/graph.ts +265 -0
- package/src/variables/index.ts +124 -0
- package/src/variables/props.ts +77 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { BEHAVIOUR_PROPS, bindInput, bindPart, containerPart, createScope, finishRoot, namesComponent, rekaRole, wrapRepeatedParts } from "./elements.js";
|
|
2
|
+
//#region src/definitions.ts
|
|
3
|
+
/** Props only `<Paragraph>` takes; like every element, it also takes `key`. */
|
|
4
|
+
const DESIGN_JSX_PARAGRAPH_PROPERTY_NAMES = [
|
|
5
|
+
"list",
|
|
6
|
+
"level",
|
|
7
|
+
"spacing",
|
|
8
|
+
"listSpacing",
|
|
9
|
+
"indent"
|
|
10
|
+
];
|
|
11
|
+
/** Props `<Span>` takes: `<Text>`'s character styles, under the same names, and a link. */
|
|
12
|
+
const DESIGN_JSX_SPAN_PROPERTY_NAMES = [
|
|
13
|
+
"style",
|
|
14
|
+
"size",
|
|
15
|
+
"fontSize",
|
|
16
|
+
"font",
|
|
17
|
+
"fontFamily",
|
|
18
|
+
"weight",
|
|
19
|
+
"fontWeight",
|
|
20
|
+
"italic",
|
|
21
|
+
"color",
|
|
22
|
+
"fill",
|
|
23
|
+
"fills",
|
|
24
|
+
"lineHeight",
|
|
25
|
+
"letterSpacing",
|
|
26
|
+
"textDecoration",
|
|
27
|
+
"textDecorationStyle",
|
|
28
|
+
"textDecorationColor",
|
|
29
|
+
"textDecorationThickness",
|
|
30
|
+
"textUnderlineOffset",
|
|
31
|
+
"textDecorationSkipInk",
|
|
32
|
+
"fontFeatures",
|
|
33
|
+
"fontVariations",
|
|
34
|
+
"lang",
|
|
35
|
+
"textCase",
|
|
36
|
+
"href"
|
|
37
|
+
];
|
|
38
|
+
/** Props `<Text>` sets every paragraph's spacing with; a `<Paragraph>` sets its own. */
|
|
39
|
+
const DESIGN_JSX_TEXT_PARAGRAPH_PROPERTY_NAMES = [
|
|
40
|
+
"paragraphSpacing",
|
|
41
|
+
"listSpacing",
|
|
42
|
+
"paragraphIndent",
|
|
43
|
+
"hangingList"
|
|
44
|
+
];
|
|
45
|
+
const DESIGN_JSX_SUPPORTED_PROPERTY_NAMES = [
|
|
46
|
+
"name",
|
|
47
|
+
"key",
|
|
48
|
+
"ref",
|
|
49
|
+
"flex",
|
|
50
|
+
"flow",
|
|
51
|
+
"dir",
|
|
52
|
+
"gap",
|
|
53
|
+
"wrap",
|
|
54
|
+
"rowGap",
|
|
55
|
+
"columnGap",
|
|
56
|
+
"justify",
|
|
57
|
+
"justifyContent",
|
|
58
|
+
"items",
|
|
59
|
+
"align",
|
|
60
|
+
"alignItems",
|
|
61
|
+
"grow",
|
|
62
|
+
"w",
|
|
63
|
+
"h",
|
|
64
|
+
"width",
|
|
65
|
+
"height",
|
|
66
|
+
"minW",
|
|
67
|
+
"maxW",
|
|
68
|
+
"minH",
|
|
69
|
+
"maxH",
|
|
70
|
+
"x",
|
|
71
|
+
"y",
|
|
72
|
+
"top",
|
|
73
|
+
"left",
|
|
74
|
+
"position",
|
|
75
|
+
"constraints",
|
|
76
|
+
"p",
|
|
77
|
+
"padding",
|
|
78
|
+
"px",
|
|
79
|
+
"py",
|
|
80
|
+
"pt",
|
|
81
|
+
"pr",
|
|
82
|
+
"pb",
|
|
83
|
+
"pl",
|
|
84
|
+
"bg",
|
|
85
|
+
"fill",
|
|
86
|
+
"fills",
|
|
87
|
+
"background",
|
|
88
|
+
"backgroundColor",
|
|
89
|
+
"stroke",
|
|
90
|
+
"border",
|
|
91
|
+
"borderColor",
|
|
92
|
+
"strokeWidth",
|
|
93
|
+
"borderWidth",
|
|
94
|
+
"strokeAlign",
|
|
95
|
+
"strokeDash",
|
|
96
|
+
"strokeCap",
|
|
97
|
+
"strokeJoin",
|
|
98
|
+
"dashPattern",
|
|
99
|
+
"strokes",
|
|
100
|
+
"strokeWeights",
|
|
101
|
+
"rounded",
|
|
102
|
+
"borderRadius",
|
|
103
|
+
"roundedTL",
|
|
104
|
+
"roundedTR",
|
|
105
|
+
"roundedBL",
|
|
106
|
+
"roundedBR",
|
|
107
|
+
"cornerRadius",
|
|
108
|
+
"cornerSmoothing",
|
|
109
|
+
"opacity",
|
|
110
|
+
"blendMode",
|
|
111
|
+
"rotate",
|
|
112
|
+
"rotation",
|
|
113
|
+
"flipX",
|
|
114
|
+
"flipY",
|
|
115
|
+
"overflow",
|
|
116
|
+
"mask",
|
|
117
|
+
"visible",
|
|
118
|
+
"locked",
|
|
119
|
+
"shadow",
|
|
120
|
+
"blur",
|
|
121
|
+
"effects",
|
|
122
|
+
"size",
|
|
123
|
+
"fontSize",
|
|
124
|
+
"font",
|
|
125
|
+
"fontFamily",
|
|
126
|
+
"weight",
|
|
127
|
+
"fontWeight",
|
|
128
|
+
"italic",
|
|
129
|
+
"color",
|
|
130
|
+
"text",
|
|
131
|
+
"characters",
|
|
132
|
+
"content",
|
|
133
|
+
"value",
|
|
134
|
+
"title",
|
|
135
|
+
"textAlign",
|
|
136
|
+
"textAlignHorizontal",
|
|
137
|
+
"textHorizontalAlignment",
|
|
138
|
+
"textAlignVertical",
|
|
139
|
+
"textVerticalAlignment",
|
|
140
|
+
"textAutoResize",
|
|
141
|
+
"lineHeight",
|
|
142
|
+
"letterSpacing",
|
|
143
|
+
"textDecoration",
|
|
144
|
+
"textDecorationStyle",
|
|
145
|
+
"textDecorationColor",
|
|
146
|
+
"textDecorationThickness",
|
|
147
|
+
"textUnderlineOffset",
|
|
148
|
+
"textDecorationSkipInk",
|
|
149
|
+
"fontFeatures",
|
|
150
|
+
"fontVariations",
|
|
151
|
+
"lang",
|
|
152
|
+
"fontOpticalSizing",
|
|
153
|
+
"textCase",
|
|
154
|
+
"paragraphSpacing",
|
|
155
|
+
"paragraphIndent",
|
|
156
|
+
"hangingList",
|
|
157
|
+
"list",
|
|
158
|
+
"level",
|
|
159
|
+
"spacing",
|
|
160
|
+
"listSpacing",
|
|
161
|
+
"indent",
|
|
162
|
+
"maxLines",
|
|
163
|
+
"truncate",
|
|
164
|
+
"grid",
|
|
165
|
+
"columns",
|
|
166
|
+
"rows",
|
|
167
|
+
"colStart",
|
|
168
|
+
"rowStart",
|
|
169
|
+
"col",
|
|
170
|
+
"row",
|
|
171
|
+
"colSpan",
|
|
172
|
+
"rowSpan",
|
|
173
|
+
"points",
|
|
174
|
+
"pointCount",
|
|
175
|
+
"innerRadius",
|
|
176
|
+
"startAngle",
|
|
177
|
+
"endAngle",
|
|
178
|
+
"d",
|
|
179
|
+
"fillRule",
|
|
180
|
+
"paths",
|
|
181
|
+
"label",
|
|
182
|
+
"style",
|
|
183
|
+
"bind",
|
|
184
|
+
"component",
|
|
185
|
+
"componentId",
|
|
186
|
+
"properties",
|
|
187
|
+
"of",
|
|
188
|
+
"exposed",
|
|
189
|
+
"mode",
|
|
190
|
+
"modelValue",
|
|
191
|
+
"open",
|
|
192
|
+
"disabled",
|
|
193
|
+
"filled",
|
|
194
|
+
"states",
|
|
195
|
+
"min",
|
|
196
|
+
"max",
|
|
197
|
+
"step",
|
|
198
|
+
"defaultValue"
|
|
199
|
+
];
|
|
200
|
+
const DESIGN_JSX_SUPPORTED_PROPERTIES = new Set(DESIGN_JSX_SUPPORTED_PROPERTY_NAMES);
|
|
201
|
+
/**
|
|
202
|
+
* Properties accepted under more than one name, keyed by the name Design JSX writes. The
|
|
203
|
+
* renderer reads the first one set, in this order; editors use it to find a value written
|
|
204
|
+
* under any of its names.
|
|
205
|
+
*/
|
|
206
|
+
const DESIGN_JSX_PROPERTY_ALIASES = {
|
|
207
|
+
w: ["width"],
|
|
208
|
+
h: ["height"],
|
|
209
|
+
bg: [
|
|
210
|
+
"fill",
|
|
211
|
+
"background",
|
|
212
|
+
"backgroundColor"
|
|
213
|
+
],
|
|
214
|
+
stroke: ["border", "borderColor"],
|
|
215
|
+
rounded: ["cornerRadius", "borderRadius"],
|
|
216
|
+
rotate: ["rotation"],
|
|
217
|
+
p: ["padding"],
|
|
218
|
+
colStart: ["col"],
|
|
219
|
+
rowStart: ["row"],
|
|
220
|
+
justify: ["justifyContent"],
|
|
221
|
+
items: ["align", "alignItems"],
|
|
222
|
+
size: ["fontSize"],
|
|
223
|
+
font: ["fontFamily"],
|
|
224
|
+
weight: ["fontWeight"],
|
|
225
|
+
textAlign: ["textAlignHorizontal", "textHorizontalAlignment"],
|
|
226
|
+
textAlignVertical: ["textVerticalAlignment"]
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Properties also read from `style={{ … }}`, keyed by the name Design JSX writes, in the order
|
|
230
|
+
* the renderer reads them. An attribute under any of the property's names wins over `style`.
|
|
231
|
+
*/
|
|
232
|
+
const DESIGN_JSX_STYLE_KEYS = {
|
|
233
|
+
bg: [{ key: "background" }, { key: "backgroundColor" }],
|
|
234
|
+
color: [{ key: "color" }],
|
|
235
|
+
stroke: [{ key: "borderColor" }],
|
|
236
|
+
strokeWidth: [{
|
|
237
|
+
key: "borderWidth",
|
|
238
|
+
px: true
|
|
239
|
+
}],
|
|
240
|
+
rounded: [{
|
|
241
|
+
key: "borderRadius",
|
|
242
|
+
px: true
|
|
243
|
+
}],
|
|
244
|
+
size: [{
|
|
245
|
+
key: "fontSize",
|
|
246
|
+
px: true
|
|
247
|
+
}],
|
|
248
|
+
weight: [{ key: "fontWeight" }],
|
|
249
|
+
w: [{
|
|
250
|
+
key: "width",
|
|
251
|
+
px: true
|
|
252
|
+
}],
|
|
253
|
+
h: [{
|
|
254
|
+
key: "height",
|
|
255
|
+
px: true
|
|
256
|
+
}],
|
|
257
|
+
opacity: [{ key: "opacity" }]
|
|
258
|
+
};
|
|
259
|
+
/** Every name a property is accepted under, the written name first. */
|
|
260
|
+
function designJSXPropertyNames(name) {
|
|
261
|
+
return [name, ...DESIGN_JSX_PROPERTY_ALIASES[name] ?? []];
|
|
262
|
+
}
|
|
263
|
+
/** The value of a property under the first of its names that is set. */
|
|
264
|
+
function designJSXProp(props, name) {
|
|
265
|
+
for (const key of designJSXPropertyNames(name)) if (props[key] !== void 0 && props[key] !== null) return props[key];
|
|
266
|
+
}
|
|
267
|
+
const DESIGN_JSX_PROPERTIES = DESIGN_JSX_SUPPORTED_PROPERTY_NAMES.map((name) => ({
|
|
268
|
+
name,
|
|
269
|
+
description: `Pairdraw ${name} property.`
|
|
270
|
+
}));
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/behaviours/render.ts
|
|
273
|
+
function withoutBehaviourProps(tree) {
|
|
274
|
+
const props = Object.fromEntries(Object.entries(tree.props).filter(([key]) => !BEHAVIOUR_PROPS.includes(key)));
|
|
275
|
+
return {
|
|
276
|
+
...tree,
|
|
277
|
+
props
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
async function renderChildren(render, children, parentId, scope) {
|
|
281
|
+
for (const child of children) if (typeof child !== "string") await render(child, parentId, scope);
|
|
282
|
+
}
|
|
283
|
+
/** A name for a part that JSX leaves unnamed: the Reka part it is, such as Thumb. */
|
|
284
|
+
function named(tree, fallback) {
|
|
285
|
+
return tree.props.name === void 0 ? {
|
|
286
|
+
...tree,
|
|
287
|
+
props: {
|
|
288
|
+
...tree.props,
|
|
289
|
+
name: fallback
|
|
290
|
+
}
|
|
291
|
+
} : tree;
|
|
292
|
+
}
|
|
293
|
+
/** The props that give a frame a layout or size of its own, under any of their names. */
|
|
294
|
+
const LAYOUT_PROPS = [
|
|
295
|
+
"flex",
|
|
296
|
+
"display",
|
|
297
|
+
"w",
|
|
298
|
+
"h"
|
|
299
|
+
];
|
|
300
|
+
/**
|
|
301
|
+
* A part that holds content, such as a panel or a trigger, with no layout of its own stacks
|
|
302
|
+
* its children in a column that hugs them, rather than pinning them in a fixed box.
|
|
303
|
+
*/
|
|
304
|
+
function laidOut(tree) {
|
|
305
|
+
if (!tree.children.some((child) => typeof child !== "string") || LAYOUT_PROPS.some((prop) => designJSXProp(tree.props, prop) !== void 0)) return tree;
|
|
306
|
+
return {
|
|
307
|
+
...tree,
|
|
308
|
+
props: {
|
|
309
|
+
...tree.props,
|
|
310
|
+
flex: "col"
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Render a Reka UI element: a root as a main component (or a component set, when it has
|
|
316
|
+
* variants) that behaves as its control, a part as the slot that draws it, and an input as the
|
|
317
|
+
* text layer of the field's text property. Returns undefined for other elements.
|
|
318
|
+
*/
|
|
319
|
+
async function renderRekaNode(graph, tree, parentId, scope, hooks) {
|
|
320
|
+
const container = containerPart(tree.type);
|
|
321
|
+
const role = container ? {
|
|
322
|
+
role: "part",
|
|
323
|
+
part: container
|
|
324
|
+
} : rekaRole(tree.type);
|
|
325
|
+
if (!role) return void 0;
|
|
326
|
+
const partName = tree.type.slice(tree.type.indexOf(".") + 1);
|
|
327
|
+
switch (role.role) {
|
|
328
|
+
case "root": {
|
|
329
|
+
if (namesComponent(tree.props)) return hooks.instance(tree, parentId);
|
|
330
|
+
const variants = tree.children.some((child) => typeof child !== "string" && child.type === "component");
|
|
331
|
+
const root = hooks.create(variants ? "COMPONENT_SET" : "COMPONENT", withoutBehaviourProps(tree), parentId);
|
|
332
|
+
const own = createScope(role.kind, root.id);
|
|
333
|
+
await renderChildren(hooks.render, wrapRepeatedParts(tree, role.kind), root.id, own);
|
|
334
|
+
if (variants) hooks.finishSet(root.id);
|
|
335
|
+
finishRoot(graph, own, tree.props);
|
|
336
|
+
return root;
|
|
337
|
+
}
|
|
338
|
+
case "part": {
|
|
339
|
+
if (!scope) throw new Error(`<${tree.type}> must be inside its Root`);
|
|
340
|
+
const frame = hooks.create("FRAME", laidOut(named(tree, partName)), parentId);
|
|
341
|
+
await renderChildren(hooks.render, tree.children, frame.id, scope);
|
|
342
|
+
bindPart(graph, scope, frame, role.part);
|
|
343
|
+
return frame;
|
|
344
|
+
}
|
|
345
|
+
case "repeat": {
|
|
346
|
+
const frame = hooks.create("FRAME", laidOut(named(tree, partName)), parentId);
|
|
347
|
+
await renderChildren(hooks.render, tree.children, frame.id, scope);
|
|
348
|
+
const siblings = graph.getChildren(parentId);
|
|
349
|
+
if (role.container === "panels" && siblings[0]?.id !== frame.id && tree.props.visible === void 0) graph.updateNode(frame.id, { visible: false });
|
|
350
|
+
return frame;
|
|
351
|
+
}
|
|
352
|
+
case "input": {
|
|
353
|
+
if (!scope) throw new Error(`<${tree.type}> must be inside its Root`);
|
|
354
|
+
const text = hooks.create("TEXT", named(tree, "Text"), parentId);
|
|
355
|
+
bindInput(graph, scope, text, role.valueId, typeof tree.props.name === "string" ? tree.props.name : "Text");
|
|
356
|
+
return text;
|
|
357
|
+
}
|
|
358
|
+
case "frame": {
|
|
359
|
+
const frame = hooks.create("FRAME", laidOut(named(tree, partName)), parentId);
|
|
360
|
+
await renderChildren(hooks.render, tree.children, frame.id, scope);
|
|
361
|
+
return frame;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
export { DESIGN_JSX_PARAGRAPH_PROPERTY_NAMES, DESIGN_JSX_PROPERTIES, DESIGN_JSX_PROPERTY_ALIASES, DESIGN_JSX_SPAN_PROPERTY_NAMES, DESIGN_JSX_STYLE_KEYS, DESIGN_JSX_SUPPORTED_PROPERTIES, DESIGN_JSX_SUPPORTED_PROPERTY_NAMES, DESIGN_JSX_TEXT_PARAGRAPH_PROPERTY_NAMES, designJSXProp, designJSXPropertyNames, renderRekaNode };
|
|
367
|
+
|
|
368
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../../src/definitions.ts","../../../src/behaviours/render.ts"],"sourcesContent":["type DesignJSXNamedDefinition = {\n name: string\n description: string\n}\n\nexport type DesignJSXPropertyDefinition = DesignJSXNamedDefinition\nexport type DesignJSXHelperDefinition = DesignJSXNamedDefinition\n\n/** Props only `<Paragraph>` takes; like every element, it also takes `key`. */\nexport const DESIGN_JSX_PARAGRAPH_PROPERTY_NAMES = [\n 'list',\n 'level',\n 'spacing',\n 'listSpacing',\n 'indent'\n] as const\n\n/** Props `<Span>` takes: `<Text>`'s character styles, under the same names, and a link. */\nexport const DESIGN_JSX_SPAN_PROPERTY_NAMES = [\n 'style',\n 'size',\n 'fontSize',\n 'font',\n 'fontFamily',\n 'weight',\n 'fontWeight',\n 'italic',\n 'color',\n 'fill',\n 'fills',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationColor',\n 'textDecorationThickness',\n 'textUnderlineOffset',\n 'textDecorationSkipInk',\n 'fontFeatures',\n 'fontVariations',\n 'lang',\n 'textCase',\n 'href'\n] as const\n\n/** Props `<Text>` sets every paragraph's spacing with; a `<Paragraph>` sets its own. */\nexport const DESIGN_JSX_TEXT_PARAGRAPH_PROPERTY_NAMES = [\n 'paragraphSpacing',\n 'listSpacing',\n 'paragraphIndent',\n 'hangingList'\n] as const\n\nexport const DESIGN_JSX_SUPPORTED_PROPERTY_NAMES = [\n 'name',\n 'key',\n 'ref',\n 'flex',\n 'flow',\n 'dir',\n 'gap',\n 'wrap',\n 'rowGap',\n 'columnGap',\n 'justify',\n 'justifyContent',\n 'items',\n 'align',\n 'alignItems',\n 'grow',\n 'w',\n 'h',\n 'width',\n 'height',\n 'minW',\n 'maxW',\n 'minH',\n 'maxH',\n 'x',\n 'y',\n 'top',\n 'left',\n 'position',\n 'constraints',\n 'p',\n 'padding',\n 'px',\n 'py',\n 'pt',\n 'pr',\n 'pb',\n 'pl',\n 'bg',\n 'fill',\n 'fills',\n 'background',\n 'backgroundColor',\n 'stroke',\n 'border',\n 'borderColor',\n 'strokeWidth',\n 'borderWidth',\n 'strokeAlign',\n 'strokeDash',\n 'strokeCap',\n 'strokeJoin',\n 'dashPattern',\n 'strokes',\n 'strokeWeights',\n 'rounded',\n 'borderRadius',\n 'roundedTL',\n 'roundedTR',\n 'roundedBL',\n 'roundedBR',\n 'cornerRadius',\n 'cornerSmoothing',\n 'opacity',\n 'blendMode',\n 'rotate',\n 'rotation',\n 'flipX',\n 'flipY',\n 'overflow',\n 'mask',\n 'visible',\n 'locked',\n 'shadow',\n 'blur',\n 'effects',\n 'size',\n 'fontSize',\n 'font',\n 'fontFamily',\n 'weight',\n 'fontWeight',\n 'italic',\n 'color',\n 'text',\n 'characters',\n 'content',\n 'value',\n 'title',\n 'textAlign',\n 'textAlignHorizontal',\n 'textHorizontalAlignment',\n 'textAlignVertical',\n 'textVerticalAlignment',\n 'textAutoResize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationColor',\n 'textDecorationThickness',\n 'textUnderlineOffset',\n 'textDecorationSkipInk',\n 'fontFeatures',\n 'fontVariations',\n 'lang',\n 'fontOpticalSizing',\n 'textCase',\n 'paragraphSpacing',\n 'paragraphIndent',\n 'hangingList',\n 'list',\n 'level',\n 'spacing',\n 'listSpacing',\n 'indent',\n 'maxLines',\n 'truncate',\n 'grid',\n 'columns',\n 'rows',\n 'colStart',\n 'rowStart',\n 'col',\n 'row',\n 'colSpan',\n 'rowSpan',\n 'points',\n 'pointCount',\n 'innerRadius',\n 'startAngle',\n 'endAngle',\n 'd',\n 'fillRule',\n 'paths',\n 'label',\n 'style',\n 'bind',\n 'component',\n 'componentId',\n 'properties',\n 'of',\n 'exposed',\n 'mode',\n // A Reka UI root's behaviour, by its own property names\n 'modelValue',\n 'open',\n 'disabled',\n 'filled',\n 'states',\n 'min',\n 'max',\n 'step',\n 'defaultValue'\n] as const\n\nexport const DESIGN_JSX_SUPPORTED_PROPERTIES = new Set<string>(DESIGN_JSX_SUPPORTED_PROPERTY_NAMES)\n\n/**\n * Properties accepted under more than one name, keyed by the name Design JSX writes. The\n * renderer reads the first one set, in this order; editors use it to find a value written\n * under any of its names.\n */\nexport const DESIGN_JSX_PROPERTY_ALIASES: Readonly<Record<string, readonly string[]>> = {\n w: ['width'],\n h: ['height'],\n bg: ['fill', 'background', 'backgroundColor'],\n stroke: ['border', 'borderColor'],\n rounded: ['cornerRadius', 'borderRadius'],\n rotate: ['rotation'],\n p: ['padding'],\n colStart: ['col'],\n rowStart: ['row'],\n justify: ['justifyContent'],\n items: ['align', 'alignItems'],\n size: ['fontSize'],\n font: ['fontFamily'],\n weight: ['fontWeight'],\n textAlign: ['textAlignHorizontal', 'textHorizontalAlignment'],\n textAlignVertical: ['textVerticalAlignment']\n}\n\n/** A CSS-style key read from the `style` prop; `px` values like `'320px'` become numbers. */\nexport interface DesignJSXStyleKey {\n key: string\n px?: boolean\n}\n\n/**\n * Properties also read from `style={{ … }}`, keyed by the name Design JSX writes, in the order\n * the renderer reads them. An attribute under any of the property's names wins over `style`.\n */\nexport const DESIGN_JSX_STYLE_KEYS: Readonly<Record<string, readonly DesignJSXStyleKey[]>> = {\n bg: [{ key: 'background' }, { key: 'backgroundColor' }],\n color: [{ key: 'color' }],\n stroke: [{ key: 'borderColor' }],\n strokeWidth: [{ key: 'borderWidth', px: true }],\n rounded: [{ key: 'borderRadius', px: true }],\n size: [{ key: 'fontSize', px: true }],\n weight: [{ key: 'fontWeight' }],\n w: [{ key: 'width', px: true }],\n h: [{ key: 'height', px: true }],\n opacity: [{ key: 'opacity' }]\n}\n\n/** Every name a property is accepted under, the written name first. */\nexport function designJSXPropertyNames(name: string): readonly string[] {\n return [name, ...(DESIGN_JSX_PROPERTY_ALIASES[name] ?? [])]\n}\n\n/** The value of a property under the first of its names that is set. */\nexport function designJSXProp(props: Readonly<Record<string, unknown>>, name: string): unknown {\n for (const key of designJSXPropertyNames(name)) {\n if (props[key] !== undefined && props[key] !== null) return props[key]\n }\n return undefined\n}\n\nexport const DESIGN_JSX_PROPERTIES: DesignJSXPropertyDefinition[] =\n DESIGN_JSX_SUPPORTED_PROPERTY_NAMES.map((name) => ({\n name,\n description: `Pairdraw ${name} property.`\n }))\n","import type { NodeType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { designJSXProp } from '../definitions'\nimport type { TreeNode } from '../tree'\nimport {\n BEHAVIOUR_PROPS,\n bindInput,\n bindPart,\n containerPart,\n createScope,\n finishRoot,\n namesComponent,\n rekaRole,\n wrapRepeatedParts,\n type RekaScope\n} from './index'\n\nexport type RenderChild = (\n tree: TreeNode,\n parentId: string,\n scope?: RekaScope\n) => Promise<SceneNode>\nexport type CreateElement = (nodeType: NodeType, tree: TreeNode, parentId: string) => SceneNode\nexport type RenderInstance = (tree: TreeNode, parentId: string) => Promise<SceneNode>\n\nfunction withoutBehaviourProps(tree: TreeNode): TreeNode {\n const props = Object.fromEntries(\n Object.entries(tree.props).filter(\n ([key]) => !(BEHAVIOUR_PROPS as readonly string[]).includes(key)\n )\n )\n return { ...tree, props }\n}\n\nasync function renderChildren(\n render: RenderChild,\n children: TreeNode['children'],\n parentId: string,\n scope: RekaScope | undefined\n): Promise<void> {\n for (const child of children) if (typeof child !== 'string') await render(child, parentId, scope)\n}\n\n/** A name for a part that JSX leaves unnamed: the Reka part it is, such as Thumb. */\nfunction named(tree: TreeNode, fallback: string): TreeNode {\n return tree.props.name === undefined\n ? { ...tree, props: { ...tree.props, name: fallback } }\n : tree\n}\n\n/** The props that give a frame a layout or size of its own, under any of their names. */\nconst LAYOUT_PROPS = ['flex', 'display', 'w', 'h']\n\n/**\n * A part that holds content, such as a panel or a trigger, with no layout of its own stacks\n * its children in a column that hugs them, rather than pinning them in a fixed box.\n */\nfunction laidOut(tree: TreeNode): TreeNode {\n const content = tree.children.some((child) => typeof child !== 'string')\n if (!content || LAYOUT_PROPS.some((prop) => designJSXProp(tree.props, prop) !== undefined))\n return tree\n return { ...tree, props: { ...tree.props, flex: 'col' } }\n}\n\n/**\n * Render a Reka UI element: a root as a main component (or a component set, when it has\n * variants) that behaves as its control, a part as the slot that draws it, and an input as the\n * text layer of the field's text property. Returns undefined for other elements.\n */\nexport async function renderRekaNode(\n graph: SceneGraph,\n tree: TreeNode,\n parentId: string,\n scope: RekaScope | undefined,\n hooks: {\n render: RenderChild\n create: CreateElement\n instance: RenderInstance\n /** Derive a component set's variant properties from its variants' names. */\n finishSet: (setId: string) => void\n }\n): Promise<SceneNode | undefined> {\n const container = containerPart(tree.type)\n const role = container ? { role: 'part' as const, part: container } : rekaRole(tree.type)\n if (!role) return undefined\n const partName = tree.type.slice(tree.type.indexOf('.') + 1)\n switch (role.role) {\n case 'root': {\n // A group's item that names a component is an item, drawn as an instance of it.\n if (namesComponent(tree.props)) return hooks.instance(tree, parentId)\n const variants = tree.children.some(\n (child) => typeof child !== 'string' && child.type === 'component'\n )\n const root = hooks.create(\n variants ? 'COMPONENT_SET' : 'COMPONENT',\n withoutBehaviourProps(tree),\n parentId\n )\n const own = createScope(role.kind, root.id)\n await renderChildren(hooks.render, wrapRepeatedParts(tree, role.kind), root.id, own)\n if (variants) hooks.finishSet(root.id)\n finishRoot(graph, own, tree.props)\n return root\n }\n case 'part': {\n if (!scope) throw new Error(`<${tree.type}> must be inside its Root`)\n const frame = hooks.create('FRAME', laidOut(named(tree, partName)), parentId)\n await renderChildren(hooks.render, tree.children, frame.id, scope)\n bindPart(graph, scope, frame, role.part)\n return frame\n }\n case 'repeat': {\n const frame = hooks.create('FRAME', laidOut(named(tree, partName)), parentId)\n await renderChildren(hooks.render, tree.children, frame.id, scope)\n // Only the first tab's panel shows as designed; preview shows the others as chosen.\n const siblings = graph.getChildren(parentId)\n if (\n role.container === 'panels' &&\n siblings[0]?.id !== frame.id &&\n tree.props.visible === undefined\n )\n graph.updateNode(frame.id, { visible: false })\n return frame\n }\n case 'input': {\n if (!scope) throw new Error(`<${tree.type}> must be inside its Root`)\n const text = hooks.create('TEXT', named(tree, 'Text'), parentId)\n bindInput(\n graph,\n scope,\n text,\n role.valueId,\n typeof tree.props.name === 'string' ? tree.props.name : 'Text'\n )\n return text\n }\n case 'frame': {\n const frame = hooks.create('FRAME', laidOut(named(tree, partName)), parentId)\n await renderChildren(hooks.render, tree.children, frame.id, scope)\n return frame\n }\n }\n return undefined\n}\n"],"mappings":";;;AASA,MAAa,sCAAsC;CACjD;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,iCAAiC;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,2CAA2C;CACtD;CACA;CACA;CACA;AACF;AAEA,MAAa,sCAAsC;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,kCAAkC,IAAI,IAAY,mCAAmC;;;;;;AAOlG,MAAa,8BAA2E;CACtF,GAAG,CAAC,OAAO;CACX,GAAG,CAAC,QAAQ;CACZ,IAAI;EAAC;EAAQ;EAAc;CAAiB;CAC5C,QAA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