@pairdraw/design-jsx 0.17.0 → 0.19.0-beta.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/dist/chunks/component-properties.js +61 -10
- package/dist/chunks/component-properties.js.map +1 -1
- package/dist/chunks/effects.js +6 -1
- package/dist/chunks/effects.js.map +1 -1
- package/dist/chunks/elements.js +6 -2
- package/dist/chunks/elements.js.map +1 -1
- package/dist/chunks/export/index.js +7 -7
- package/dist/chunks/export/index.js.map +1 -1
- package/dist/chunks/fields.js +183 -45
- package/dist/chunks/fields.js.map +1 -1
- package/dist/chunks/index.js +1 -1
- package/dist/chunks/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/tree.d.ts +1 -1
- package/package.json +3 -3
- package/src/effects.ts +10 -2
- package/src/export/paint.ts +10 -3
- package/src/overrides/effects.ts +101 -12
- package/src/overrides/strokes.ts +16 -12
- package/src/props-overrides.ts +50 -38
- package/src/reference/authoring.md +3 -2
- package/src/render.ts +62 -2
- package/src/renderer.ts +66 -24
- package/src/schema.ts +67 -0
package/dist/chunks/fields.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { REKA_ELEMENTS, isTreeNode, resolveToTree } from "./behaviours/elements.js";
|
|
2
|
-
import { BLEND_MODE, CONSTRAINT, ENUM_PROPS, LayerRefs, MASK_TYPE, TEXT_ALIGN, TEXT_ALIGN_VERTICAL, TEXT_AUTO_RESIZE, TEXT_CASE, TEXT_DECORATION, TEXT_DIRECTION, applyStrokeOverrides, assignComponentProperties, assignNamedProperties, bindProperties, componentPropNames as componentPropNames$1, elementPropWarnings, exposeInstance, fillFromValue, inferComponentSetProperties, isColor, isFillValue, isVariable, parseScriptInput, readElementProps } from "./component-properties.js";
|
|
2
|
+
import { BLEND_MODE, CONSTRAINT, ENUM_PROPS, LayerRefs, MASK_TYPE, TEXT_ALIGN, TEXT_ALIGN_VERTICAL, TEXT_AUTO_RESIZE, TEXT_CASE, TEXT_DECORATION, TEXT_DIRECTION, applyStrokeOverrides, assignComponentProperties, assignNamedProperties, bindProperties, componentPropNames as componentPropNames$1, elementPropWarnings, enumProp, exposeInstance, fillFromValue, inferComponentSetProperties, isColor, isFillValue, isVariable, layerPropsSchema, parseScriptInput, readElementProps, readLayerProps, svgLayerPropsSchema } from "./component-properties.js";
|
|
3
3
|
import { DESIGN_JSX_STYLE_KEYS, designJSXProp, renderRekaNode } from "./behaviours/render.js";
|
|
4
4
|
import { DESIGN_JSX_HELPERS, TEXT_CONTENT_NAMES, applyVariableDefinitions, bindVariableProp, designJSXHelpers, isShaderFill, isTextContent, requireVariableId, resolveForLayer, textContentFields, variableModes } from "./export/index.js";
|
|
5
5
|
import { resolveConnectorEnds } from "./connectors.js";
|
|
6
6
|
import { elementBindings, elementNodeType, elementOwnLayer, elementProps, elementSchema } from "./elements.js";
|
|
7
7
|
import { applyTextDetailOverrides, textLengthProp } from "./export/decoration.js";
|
|
8
8
|
import { paintProps, scalarProps } from "./export/bindings.js";
|
|
9
|
-
import { colorToFill, parseColor } from "@pairdraw/scene-graph/color";
|
|
9
|
+
import { colorSchema, colorToFill, parseColor, tryParseColor } from "@pairdraw/scene-graph/color";
|
|
10
10
|
import { TRANSPARENT } from "@pairdraw/scene-graph/constants";
|
|
11
11
|
import * as v from "valibot";
|
|
12
|
-
import { withShaderPaints } from "@pairdraw/scene-graph/shaders";
|
|
12
|
+
import { shaderUniformValueSchema, withShaderPaints } from "@pairdraw/scene-graph/shaders";
|
|
13
13
|
import { omitBy } from "es-toolkit/object";
|
|
14
14
|
import { uniq } from "es-toolkit/array";
|
|
15
|
+
import { omit, pickBy } from "es-toolkit";
|
|
16
|
+
import { parseCSSGridTracks, parseCSSNumber, parseCSSShadows } from "@pairdraw/scene-graph/css";
|
|
17
|
+
import { autoLayoutSizingFields, fillSizingFields, parseAutoLayoutDirection, parseCounterAxisAlign, parsePrimaryAxisAlign } from "@pairdraw/scene-graph/layout";
|
|
18
|
+
import { normalizeEffects } from "@pairdraw/scene-graph/effects";
|
|
19
|
+
import { finiteNumberSchema } from "@pairdraw/scene-graph/primitives";
|
|
15
20
|
import { setInstanceOverride } from "@pairdraw/scene-graph/instances/overrides";
|
|
21
|
+
import { createDefaultNode, textLayerName } from "@pairdraw/scene-graph/node-defaults";
|
|
16
22
|
import { parsePluginVectorPath, parseSVGPathData } from "@pairdraw/scene-graph/parse-path";
|
|
17
23
|
import { mergeVectorNetworks, transformVectorNetwork } from "@pairdraw/scene-graph/vector-network";
|
|
18
|
-
import { parseCSSGridTracks, parseCSSNumber, parseCSSShadows } from "@pairdraw/scene-graph/css";
|
|
19
|
-
import { autoLayoutSizingFields, fillSizingFields, parseAutoLayoutDirection, parseCounterAxisAlign, parsePrimaryAxisAlign } from "@pairdraw/scene-graph/layout";
|
|
20
|
-
import { omit } from "es-toolkit";
|
|
21
|
-
import { createDefaultNode } from "@pairdraw/scene-graph/node-defaults";
|
|
22
24
|
import { parse } from "acorn";
|
|
23
25
|
import { transform } from "sucrase";
|
|
24
26
|
//#region \0rolldown/runtime.js
|
|
@@ -47,14 +49,84 @@ function createElement(type, props, ...children) {
|
|
|
47
49
|
}
|
|
48
50
|
//#endregion
|
|
49
51
|
//#region src/overrides/effects.ts
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
const offsetSchema = v.object({
|
|
53
|
+
x: v.optional(finiteNumberSchema),
|
|
54
|
+
y: v.optional(finiteNumberSchema)
|
|
55
|
+
});
|
|
56
|
+
const effectFields = {
|
|
57
|
+
radius: finiteNumberSchema,
|
|
58
|
+
offset: v.optional(offsetSchema),
|
|
59
|
+
spread: v.optional(finiteNumberSchema, 0),
|
|
60
|
+
visible: v.optional(v.boolean(), true),
|
|
61
|
+
blendMode: v.optional(enumProp(BLEND_MODE)),
|
|
62
|
+
showShadowBehindNode: v.optional(v.boolean())
|
|
63
|
+
};
|
|
64
|
+
function shadowEffectSchema(type) {
|
|
65
|
+
return v.object({
|
|
66
|
+
type: v.literal(type),
|
|
67
|
+
color: colorSchema,
|
|
68
|
+
...effectFields
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function blurEffectSchema(type) {
|
|
72
|
+
return v.object({
|
|
73
|
+
type: v.literal(type),
|
|
74
|
+
color: v.optional(colorSchema),
|
|
75
|
+
...effectFields
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const shaderEffectSchema = v.object({
|
|
79
|
+
type: v.literal("SHADER"),
|
|
80
|
+
source: v.pipe(v.string(), v.minLength(1)),
|
|
81
|
+
uniforms: v.optional(v.record(v.string(), shaderUniformValueSchema)),
|
|
82
|
+
uniformBindings: v.optional(v.record(v.string(), v.string())),
|
|
83
|
+
visible: v.optional(v.boolean(), true),
|
|
84
|
+
blendMode: v.optional(enumProp(BLEND_MODE))
|
|
85
|
+
});
|
|
86
|
+
const effectSchema = v.variant("type", [
|
|
87
|
+
shadowEffectSchema("DROP_SHADOW"),
|
|
88
|
+
shadowEffectSchema("INNER_SHADOW"),
|
|
89
|
+
blurEffectSchema("LAYER_BLUR"),
|
|
90
|
+
blurEffectSchema("BACKGROUND_BLUR"),
|
|
91
|
+
blurEffectSchema("FOREGROUND_BLUR"),
|
|
92
|
+
shaderEffectSchema
|
|
93
|
+
]);
|
|
94
|
+
const effectsSchema = v.array(effectSchema);
|
|
95
|
+
/** Drop an omitted offset so `normalizeEffects` can apply the shadow or blur default. */
|
|
96
|
+
function forNormalize(effect) {
|
|
97
|
+
if (effect.type === "SHADER") {
|
|
98
|
+
const shader = {
|
|
99
|
+
type: "SHADER",
|
|
100
|
+
source: effect.source,
|
|
101
|
+
visible: effect.visible
|
|
102
|
+
};
|
|
103
|
+
if (effect.uniforms !== void 0) shader.uniforms = effect.uniforms;
|
|
104
|
+
if (effect.uniformBindings !== void 0) shader.uniformBindings = effect.uniformBindings;
|
|
105
|
+
if (effect.blendMode !== void 0) shader.blendMode = effect.blendMode;
|
|
106
|
+
return shader;
|
|
107
|
+
}
|
|
108
|
+
const shadow = {
|
|
109
|
+
type: effect.type,
|
|
110
|
+
color: effect.color ?? { ...TRANSPARENT },
|
|
111
|
+
radius: effect.radius,
|
|
112
|
+
spread: effect.spread,
|
|
113
|
+
visible: effect.visible
|
|
114
|
+
};
|
|
115
|
+
if (effect.offset !== void 0) {
|
|
116
|
+
const offset = {};
|
|
117
|
+
if (effect.offset.x !== void 0) offset.x = effect.offset.x;
|
|
118
|
+
if (effect.offset.y !== void 0) offset.y = effect.offset.y;
|
|
119
|
+
shadow.offset = offset;
|
|
120
|
+
}
|
|
121
|
+
if (effect.blendMode !== void 0) shadow.blendMode = effect.blendMode;
|
|
122
|
+
if (effect.showShadowBehindNode !== void 0) shadow.showShadowBehindNode = effect.showShadowBehindNode;
|
|
123
|
+
return shadow;
|
|
52
124
|
}
|
|
53
125
|
/** `effects` takes structured effects; `shadow` appends its shadows and `blur` a layer blur. */
|
|
54
126
|
function applyEffectOverrides(props, o) {
|
|
55
|
-
if (Array.isArray(props.effects)) {
|
|
56
|
-
const effects = props.effects
|
|
57
|
-
|
|
127
|
+
if (Array.isArray(props.effects) && props.effects.length > 0) {
|
|
128
|
+
const effects = parseScriptInput("effects", effectsSchema, props.effects).map(forNormalize);
|
|
129
|
+
o.effects = normalizeEffects(effects);
|
|
58
130
|
}
|
|
59
131
|
const shadows = typeof props.shadow === "string" ? parseCSSShadows(props.shadow) : [];
|
|
60
132
|
if (shadows.length > 0) o.effects = [...o.effects ?? [], ...shadows];
|
|
@@ -162,7 +234,7 @@ function applySizeOverrides(props, o, parentLayout) {
|
|
|
162
234
|
*/
|
|
163
235
|
function setFills(values, o) {
|
|
164
236
|
const shaders = [];
|
|
165
|
-
const fills = values.map((value) => {
|
|
237
|
+
const fills = values.filter((value) => typeof value !== "string" || tryParseColor(value) !== null).map((value) => {
|
|
166
238
|
const fill = fillFromValue(value);
|
|
167
239
|
if (!isShaderFill(fill)) return fill;
|
|
168
240
|
const { shader, ...paint } = fill;
|
|
@@ -186,8 +258,8 @@ function applyFillOverride(props, o) {
|
|
|
186
258
|
if (isFillValue(bg)) setFills([bg], o);
|
|
187
259
|
}
|
|
188
260
|
function applyCornerOverrides(props, o) {
|
|
189
|
-
const rounded =
|
|
190
|
-
if (
|
|
261
|
+
const rounded = props.rounded ?? props.cornerRadius ?? props.borderRadius;
|
|
262
|
+
if (rounded !== void 0) o.cornerRadius = rounded;
|
|
191
263
|
if (props.roundedTL !== void 0 || props.roundedTR !== void 0 || props.roundedBL !== void 0 || props.roundedBR !== void 0) {
|
|
192
264
|
o.independentCorners = true;
|
|
193
265
|
if (props.roundedTL !== void 0) o.topLeftRadius = props.roundedTL;
|
|
@@ -208,7 +280,7 @@ function applyVisualOverrides(props, o) {
|
|
|
208
280
|
if (props.overflow === "hidden") o.clipsContent = true;
|
|
209
281
|
}
|
|
210
282
|
function applyTransformOverrides(props, o) {
|
|
211
|
-
const rotation =
|
|
283
|
+
const rotation = props.rotate ?? props.rotation;
|
|
212
284
|
if (rotation !== void 0) o.rotation = rotation;
|
|
213
285
|
if (props.flipX !== void 0) o.flipX = props.flipX === true;
|
|
214
286
|
if (props.flipY !== void 0) o.flipY = props.flipY === true;
|
|
@@ -281,13 +353,14 @@ function applyGridOverrides(props, o, w, h) {
|
|
|
281
353
|
function applyGridChildOverrides(props, o) {
|
|
282
354
|
const col = designJSXProp(props, "colStart");
|
|
283
355
|
const row = designJSXProp(props, "rowStart");
|
|
284
|
-
const colSpan = props
|
|
285
|
-
const rowSpan = props
|
|
286
|
-
if (col
|
|
356
|
+
const colSpan = designJSXProp(props, "colSpan");
|
|
357
|
+
const rowSpan = designJSXProp(props, "rowSpan");
|
|
358
|
+
if (col === void 0 && row === void 0 && colSpan === void 0 && rowSpan === void 0) return;
|
|
359
|
+
o.gridPosition = {
|
|
287
360
|
column: col ?? 0,
|
|
288
361
|
row: row ?? 0,
|
|
289
|
-
columnSpan: colSpan,
|
|
290
|
-
rowSpan
|
|
362
|
+
columnSpan: colSpan ?? 1,
|
|
363
|
+
rowSpan: rowSpan ?? 1
|
|
291
364
|
};
|
|
292
365
|
}
|
|
293
366
|
function applyAutoLayoutSizing(o, props, w, h) {
|
|
@@ -361,7 +434,8 @@ function applyTextAlignmentOverrides(props, o) {
|
|
|
361
434
|
function applyTextAutoResize(props, o, parentLayout) {
|
|
362
435
|
const w = designJSXProp(props, "w");
|
|
363
436
|
const hasExplicitWidth = w !== void 0;
|
|
364
|
-
const
|
|
437
|
+
const grow = typeof props.grow === "number" ? props.grow : void 0;
|
|
438
|
+
const fillsParent = w === "fill" || grow !== void 0 && grow > 0;
|
|
365
439
|
const isInsideAutoLayout = parentLayout !== "NONE";
|
|
366
440
|
if (props.textAutoResize) o.textAutoResize = TEXT_AUTO_RESIZE.parse(props.textAutoResize) ?? "NONE";
|
|
367
441
|
else if (hasExplicitWidth || isInsideAutoLayout && fillsParent) o.textAutoResize = "HEIGHT";
|
|
@@ -369,7 +443,8 @@ function applyTextAutoResize(props, o, parentLayout) {
|
|
|
369
443
|
}
|
|
370
444
|
function applyTextOverrides(props, o, parentLayout) {
|
|
371
445
|
applyTextStyleOverrides(props, o);
|
|
372
|
-
|
|
446
|
+
const direction = parseDirection(props.dir);
|
|
447
|
+
if (direction) o.textDirection = direction;
|
|
373
448
|
applyTextAutoResize(props, o, parentLayout);
|
|
374
449
|
}
|
|
375
450
|
const FULL_TURN_DEGREES = 360;
|
|
@@ -410,15 +485,15 @@ function shapeOverrides(nodeType, props) {
|
|
|
410
485
|
return o;
|
|
411
486
|
}
|
|
412
487
|
function propsToOverrides(props, isText, parentLayout) {
|
|
413
|
-
|
|
488
|
+
const layer = readLayerProps(normalizeStyleProps(props));
|
|
414
489
|
const o = {};
|
|
415
|
-
if (
|
|
416
|
-
const { w, h } = applySizeOverrides(
|
|
417
|
-
applyVisualOverrides(
|
|
418
|
-
applyLayoutOverrides(
|
|
419
|
-
if (isText) applyTextOverrides(
|
|
420
|
-
applyEffectOverrides(
|
|
421
|
-
applyStateOverrides(
|
|
490
|
+
if (layer.name) o.name = layer.name;
|
|
491
|
+
const { w, h } = applySizeOverrides(layer, o, parentLayout);
|
|
492
|
+
applyVisualOverrides(layer, o);
|
|
493
|
+
applyLayoutOverrides(layer, o, w, h, isText, parentLayout);
|
|
494
|
+
if (isText) applyTextOverrides(layer, o, parentLayout);
|
|
495
|
+
applyEffectOverrides(layer, o);
|
|
496
|
+
applyStateOverrides(layer, o);
|
|
422
497
|
return o;
|
|
423
498
|
}
|
|
424
499
|
//#endregion
|
|
@@ -646,7 +721,7 @@ async function renderIconNode(services, graph, tree, parentId) {
|
|
|
646
721
|
function placeArtwork(services, graph, artwork, props, size, parentId) {
|
|
647
722
|
const parentLayout = graph.getNode(parentId)?.layoutMode ?? "NONE";
|
|
648
723
|
const overrides = {};
|
|
649
|
-
if (props.label) overrides.name = props.label;
|
|
724
|
+
if (typeof props.label === "string" && props.label) overrides.name = props.label;
|
|
650
725
|
applyIconSize(props, overrides, parentLayout, size);
|
|
651
726
|
const modes = variableModes(graph, props.mode);
|
|
652
727
|
if (modes) overrides.variableModes = modes;
|
|
@@ -688,23 +763,50 @@ function renderSVGNode(services, graph, tree, parentId) {
|
|
|
688
763
|
if (!artwork) throw new Error("<svg> requires SVG markup, a body prop, or supported SVG shape children");
|
|
689
764
|
return placeArtwork(services, graph, artwork, props, size, parentId);
|
|
690
765
|
}
|
|
691
|
-
|
|
692
|
-
|
|
766
|
+
/** Every component or set the reference names: one by ID, or each one sharing the name. */
|
|
767
|
+
function componentsNamed(graph, ref) {
|
|
768
|
+
const byId = graph.getNode(ref);
|
|
769
|
+
if (byId?.type === "COMPONENT" || byId?.type === "COMPONENT_SET") return [byId];
|
|
770
|
+
const components = [];
|
|
771
|
+
const sets = [];
|
|
772
|
+
for (const node of graph.getAllNodes()) {
|
|
773
|
+
if (node.name !== ref) continue;
|
|
774
|
+
if (node.type === "COMPONENT") components.push(node);
|
|
775
|
+
else if (node.type === "COMPONENT_SET") sets.push(node);
|
|
776
|
+
}
|
|
777
|
+
return [...components, ...sets];
|
|
693
778
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
return variants.find((variant) => Object.entries(requested).every(([key, value]) => variant.componentPropertyValues[key] === value)) ?? variants[0];
|
|
779
|
+
/** Whether `props` selects a variant of `set`, naming one of its variant properties. */
|
|
780
|
+
function selectsVariant(set, props) {
|
|
781
|
+
return Object.keys(props).some((key) => set.componentPropertyDefinitions.some((definition) => definition.type === "VARIANT" && definition.name === key));
|
|
698
782
|
}
|
|
699
|
-
/**
|
|
783
|
+
/**
|
|
784
|
+
* The component or component set an element names. A name several of them share uses the set when
|
|
785
|
+
* the props select one of its variants, and the first otherwise; the warning from
|
|
786
|
+
* `componentReferenceWarnings` says so and how to pick one by ID.
|
|
787
|
+
*/
|
|
700
788
|
function namedComponent(graph, props) {
|
|
701
789
|
const ref = props.component ?? props.componentId ?? props.of;
|
|
702
790
|
if (typeof ref !== "string") return void 0;
|
|
703
|
-
const
|
|
704
|
-
if (
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
791
|
+
const matches = componentsNamed(graph, ref);
|
|
792
|
+
if (matches.length <= 1) return matches[0];
|
|
793
|
+
return matches.find((node) => node.type === "COMPONENT_SET" && selectsVariant(node, props)) ?? matches[0];
|
|
794
|
+
}
|
|
795
|
+
/** A name several components or sets share, naming each candidate by its ID. */
|
|
796
|
+
function componentReferenceWarnings(graph, props) {
|
|
797
|
+
const ref = props.component ?? props.componentId ?? props.of;
|
|
798
|
+
if (typeof ref !== "string") return [];
|
|
799
|
+
const matches = componentsNamed(graph, ref);
|
|
800
|
+
if (matches.length < 2) return [];
|
|
801
|
+
const chosen = namedComponent(graph, props);
|
|
802
|
+
const choices = matches.map((node) => `${node.id} (${node.type === "COMPONENT_SET" ? "component set" : "component"})`).join(", ");
|
|
803
|
+
const joined = chosen?.type === "COMPONENT_SET" ? "the component set" : "the first";
|
|
804
|
+
return [`<Instance> of "${ref}" names ${matches.length} components and joins ${joined}; name the one you mean by its ID: ${choices}.`];
|
|
805
|
+
}
|
|
806
|
+
function findVariantInSet(graph, componentSet, props) {
|
|
807
|
+
const requested = Object.fromEntries(Object.entries(props).filter(([key]) => componentSet.componentPropertyDefinitions.some((definition) => definition.type === "VARIANT" && definition.name === key)).map(([key, value]) => [key, String(value)]));
|
|
808
|
+
const variants = graph.getChildren(componentSet.id).filter((node) => node.type === "COMPONENT");
|
|
809
|
+
return variants.find((variant) => Object.entries(requested).every(([key, value]) => variant.componentPropertyValues[key] === value)) ?? variants[0];
|
|
708
810
|
}
|
|
709
811
|
function resolveComponent(graph, props) {
|
|
710
812
|
const named = namedComponent(graph, props);
|
|
@@ -834,6 +936,8 @@ function elementOverrides(graph, nodeType, tree, parentId) {
|
|
|
834
936
|
if (isText) {
|
|
835
937
|
const spanOverrides = (spanProps) => propsToOverrides(preparePropsForRender(graph, spanProps, true, layer).props, true, "NONE");
|
|
836
938
|
Object.assign(overrides, textContentFields(tree, props, overrides, spanOverrides));
|
|
939
|
+
if (overrides.name) overrides.autoRename = false;
|
|
940
|
+
else if (overrides.text !== void 0) overrides.name = textLayerName("TEXT", overrides.text);
|
|
837
941
|
}
|
|
838
942
|
return {
|
|
839
943
|
overrides,
|
|
@@ -885,7 +989,9 @@ async function renderNodeContent(services, graph, tree, parentId, onNode, scope)
|
|
|
885
989
|
placeVectorPaths(graph, node, tree.props, (network) => services.vectorBounds(network));
|
|
886
990
|
for (const child of tree.children) {
|
|
887
991
|
if (typeof child === "string" || node.type === "TEXT" && isTextContent(child)) continue;
|
|
888
|
-
if (isTreeNode(child))
|
|
992
|
+
if (!isTreeNode(child)) continue;
|
|
993
|
+
if (node.type === "TEXT") throw new Error(`<${child.type}> cannot be inside <Text>`);
|
|
994
|
+
await renderNode(services, graph, child, node.id, onNode, scope);
|
|
889
995
|
}
|
|
890
996
|
if (node.type === "COMPONENT_SET") inferComponentSetProperties(graph, node.id);
|
|
891
997
|
return node;
|
|
@@ -958,6 +1064,22 @@ function transformDesignJSXProgram(source) {
|
|
|
958
1064
|
}
|
|
959
1065
|
//#endregion
|
|
960
1066
|
//#region src/render.ts
|
|
1067
|
+
const SIZE_PROPS = /* @__PURE__ */ new Set(["w", "h"]);
|
|
1068
|
+
const PAINT_PROPS = /* @__PURE__ */ new Set([
|
|
1069
|
+
"bg",
|
|
1070
|
+
"fill",
|
|
1071
|
+
"stroke"
|
|
1072
|
+
]);
|
|
1073
|
+
/** How a warning names a value it could not read. */
|
|
1074
|
+
function propValueText(value) {
|
|
1075
|
+
return typeof value === "string" ? `"${value}"` : String(value);
|
|
1076
|
+
}
|
|
1077
|
+
function unreadableSize(value) {
|
|
1078
|
+
return !isVariable(value) && typeof value !== "number" && value !== "hug" && value !== "fill";
|
|
1079
|
+
}
|
|
1080
|
+
function unreadablePaint(value) {
|
|
1081
|
+
return typeof value === "string" && tryParseColor(value) === null;
|
|
1082
|
+
}
|
|
961
1083
|
/** `const Switch = { Root: 'Switch.Root', … }`: each Reka namespace as element types. */
|
|
962
1084
|
const REKA_ALIASES = Object.entries(REKA_ELEMENTS).map(([namespace, parts]) => `const ${namespace} = ${JSON.stringify(Object.fromEntries(Object.keys(parts).map((part) => [part, `${namespace}.${part}`])))}`).join("\n");
|
|
963
1085
|
/** `const solid = __helpers.solid`, …: every helper in the scope of the code. */
|
|
@@ -1036,6 +1158,12 @@ function stripHTMLComments(jsxString) {
|
|
|
1036
1158
|
}
|
|
1037
1159
|
return out;
|
|
1038
1160
|
}
|
|
1161
|
+
/** Why `value` cannot go into the layer field `key` names, or nothing when it can. */
|
|
1162
|
+
function valueKindWarning(key, value, element, type) {
|
|
1163
|
+
if (type === "svg") return void 0;
|
|
1164
|
+
if (SIZE_PROPS.has(key) && unreadableSize(value)) return `Invalid ${key} ${propValueText(value)} on <${element}> is ignored; expected a number, "hug", or "fill".`;
|
|
1165
|
+
if (PAINT_PROPS.has(key) && unreadablePaint(value)) return `Invalid ${key} ${propValueText(value)} on <${element}> is ignored; expected a colour or a paint.`;
|
|
1166
|
+
}
|
|
1039
1167
|
function unsupportedPropWarnings(graph, tree) {
|
|
1040
1168
|
const warnings = [];
|
|
1041
1169
|
collectUnsupportedPropWarnings(graph, tree, warnings);
|
|
@@ -1043,15 +1171,25 @@ function unsupportedPropWarnings(graph, tree) {
|
|
|
1043
1171
|
}
|
|
1044
1172
|
function collectUnsupportedPropWarnings(graph, tree, warnings) {
|
|
1045
1173
|
const supported = elementProps(tree.type);
|
|
1174
|
+
if (tree.type === "instance") warnings.push(...componentReferenceWarnings(graph, tree.props));
|
|
1046
1175
|
const properties = componentPropNames(graph, tree.props);
|
|
1047
1176
|
const element = TEXT_CONTENT_NAMES[tree.type] ?? tree.type;
|
|
1048
1177
|
const schema = elementSchema(tree.type);
|
|
1049
1178
|
if (schema) warnings.push(...elementPropWarnings(schema, tree.props, element));
|
|
1179
|
+
const layerSchema = tree.type === "svg" ? svgLayerPropsSchema : layerPropsSchema;
|
|
1180
|
+
const layerProps = pickBy(normalizeStyleProps(tree.props), (_, key) => supported.has(key) && !(schema && Object.hasOwn(schema.entries, key)));
|
|
1181
|
+
warnings.push(...elementPropWarnings(layerSchema, layerProps, element));
|
|
1050
1182
|
for (const [key, value] of Object.entries(tree.props)) {
|
|
1051
1183
|
if (!supported.has(key) && !properties.includes(key)) {
|
|
1052
1184
|
warnings.push(`Unsupported prop "${key}" on <${element}> is ignored.`);
|
|
1053
1185
|
continue;
|
|
1054
1186
|
}
|
|
1187
|
+
if (schema && key in schema.entries) continue;
|
|
1188
|
+
const kindWarning = valueKindWarning(key, value, element, tree.type);
|
|
1189
|
+
if (kindWarning) {
|
|
1190
|
+
warnings.push(kindWarning);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1055
1193
|
const values = ENUM_PROPS[key];
|
|
1056
1194
|
if (values && typeof value === "string" && values.parse(value) === void 0) warnings.push(`Unknown ${key} "${value}" on <${element}> is ignored; expected ${values.names.join(", ")}.`);
|
|
1057
1195
|
}
|