@pairdraw/design-jsx 0.0.0-stage → 0.16.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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/chunks/attributes.js +32 -0
  4. package/dist/chunks/attributes.js.map +1 -0
  5. package/dist/chunks/behaviours/elements.js +321 -0
  6. package/dist/chunks/behaviours/elements.js.map +1 -0
  7. package/dist/chunks/behaviours/render.js +368 -0
  8. package/dist/chunks/behaviours/render.js.map +1 -0
  9. package/dist/chunks/component-properties.js +809 -0
  10. package/dist/chunks/component-properties.js.map +1 -0
  11. package/dist/chunks/components.js +78 -0
  12. package/dist/chunks/components.js.map +1 -0
  13. package/dist/chunks/connectors.js +290 -0
  14. package/dist/chunks/connectors.js.map +1 -0
  15. package/dist/chunks/effects.js +57 -0
  16. package/dist/chunks/effects.js.map +1 -0
  17. package/dist/chunks/elements.js +618 -0
  18. package/dist/chunks/elements.js.map +1 -0
  19. package/dist/chunks/export/behaviours.js +113 -0
  20. package/dist/chunks/export/behaviours.js.map +1 -0
  21. package/dist/chunks/export/bindings.js +273 -0
  22. package/dist/chunks/export/bindings.js.map +1 -0
  23. package/dist/chunks/export/decoration.js +96 -0
  24. package/dist/chunks/export/decoration.js.map +1 -0
  25. package/dist/chunks/export/font.js +17 -0
  26. package/dist/chunks/export/font.js.map +1 -0
  27. package/dist/chunks/export/icons.js +34 -0
  28. package/dist/chunks/export/icons.js.map +1 -0
  29. package/dist/chunks/export/index.js +1390 -0
  30. package/dist/chunks/export/index.js.map +1 -0
  31. package/dist/chunks/fields.js +1065 -0
  32. package/dist/chunks/fields.js.map +1 -0
  33. package/dist/chunks/index.js +438 -0
  34. package/dist/chunks/index.js.map +1 -0
  35. package/dist/chunks/jsx-dev-runtime.js +16 -0
  36. package/dist/chunks/jsx-dev-runtime.js.map +1 -0
  37. package/dist/index.d.ts +543 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +11 -0
  40. package/dist/jsx-dev-runtime.d.ts +2 -0
  41. package/dist/jsx-dev-runtime.js +2 -0
  42. package/dist/jsx-runtime.d.ts +44 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/tree.d.ts +261 -0
  46. package/dist/tree.d.ts.map +1 -0
  47. package/package.json +66 -4
  48. package/src/attributes.ts +30 -0
  49. package/src/behaviours/elements.ts +47 -0
  50. package/src/behaviours/index.ts +253 -0
  51. package/src/behaviours/render.ts +144 -0
  52. package/src/component-properties.ts +428 -0
  53. package/src/components.ts +109 -0
  54. package/src/connectors.ts +316 -0
  55. package/src/definitions.ts +277 -0
  56. package/src/effects.ts +80 -0
  57. package/src/elements.ts +321 -0
  58. package/src/enums.ts +182 -0
  59. package/src/export/behaviours.ts +143 -0
  60. package/src/export/bindings.ts +155 -0
  61. package/src/export/decoration.ts +39 -0
  62. package/src/export/font.ts +25 -0
  63. package/src/export/helpers.ts +75 -0
  64. package/src/export/icons.ts +42 -0
  65. package/src/export/index.ts +297 -0
  66. package/src/export/paint.ts +276 -0
  67. package/src/export/props.ts +369 -0
  68. package/src/export/state.ts +52 -0
  69. package/src/export/text.ts +155 -0
  70. package/src/export/value.ts +99 -0
  71. package/src/export/variables.ts +393 -0
  72. package/src/fields.ts +39 -0
  73. package/src/figjam-text.ts +37 -0
  74. package/src/global.d.ts +4 -0
  75. package/src/helpers.ts +135 -0
  76. package/src/index.ts +155 -0
  77. package/src/jsx-dev-runtime.ts +1 -0
  78. package/src/jsx-runtime.ts +51 -0
  79. package/src/mini-react.ts +23 -0
  80. package/src/overrides/effects.ts +39 -0
  81. package/src/overrides/fills.ts +56 -0
  82. package/src/overrides/state.ts +55 -0
  83. package/src/overrides/strokes.ts +109 -0
  84. package/src/overrides/text.ts +116 -0
  85. package/src/overrides/vector.ts +122 -0
  86. package/src/paints.ts +230 -0
  87. package/src/props-overrides.ts +481 -0
  88. package/src/reconcile.ts +134 -0
  89. package/src/reference/authoring.md +76 -0
  90. package/src/reference/examples.ts +49 -0
  91. package/src/reference.ts +19 -0
  92. package/src/refs.ts +48 -0
  93. package/src/render.ts +147 -0
  94. package/src/renderer.ts +598 -0
  95. package/src/scalar-bindings.ts +36 -0
  96. package/src/schema.ts +213 -0
  97. package/src/services.ts +36 -0
  98. package/src/shapes-with-text.ts +73 -0
  99. package/src/stickies.ts +72 -0
  100. package/src/streaming/index.ts +47 -0
  101. package/src/streaming/literals.ts +82 -0
  102. package/src/streaming/projection.ts +189 -0
  103. package/src/text-content.ts +233 -0
  104. package/src/transform.ts +78 -0
  105. package/src/tree.ts +285 -0
  106. package/src/types.ts +13 -0
  107. package/src/variables/graph.ts +265 -0
  108. package/src/variables/index.ts +124 -0
  109. package/src/variables/props.ts +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.js","names":[],"sources":["../../src/effects.ts"],"sourcesContent":["import type { BlendMode, Effect } from '@pairdraw/scene-graph'\nimport { parseColor } from '@pairdraw/scene-graph/color'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport type { Color, Vector } from '@pairdraw/scene-graph/primitives'\n\nexport type EffectColor = string | Color\n\nexport interface ShadowEffectOptions {\n color?: EffectColor\n x?: number\n y?: number\n offset?: Vector\n radius?: number\n spread?: number\n visible?: boolean\n blendMode?: BlendMode\n showShadowBehindNode?: boolean\n}\n\nexport interface BlurEffectOptions {\n radius?: number\n visible?: boolean\n}\n\n/** Radius of a shadow or blur that does not set one. */\nconst DEFAULT_EFFECT_RADIUS = 8\n\nfunction toColor(color: EffectColor | undefined): Color {\n if (color === undefined) return { ...TRANSPARENT }\n return typeof color === 'string' ? parseColor(color) : color\n}\n\nfunction shadowEffect(type: 'DROP_SHADOW' | 'INNER_SHADOW', options: ShadowEffectOptions): Effect {\n return {\n type,\n color: toColor(options.color ?? 'rgba(0, 0, 0, 0.25)'),\n offset: options.offset ?? { x: options.x ?? 0, y: options.y ?? 4 },\n radius: options.radius ?? DEFAULT_EFFECT_RADIUS,\n spread: options.spread ?? 0,\n visible: options.visible ?? true,\n blendMode: options.blendMode,\n showShadowBehindNode: options.showShadowBehindNode\n }\n}\n\nfunction blurEffect(\n type: 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR',\n radiusOrOptions: number | BlurEffectOptions = {}\n): Effect {\n const options =\n typeof radiusOrOptions === 'number' ? { radius: radiusOrOptions } : radiusOrOptions\n return {\n type,\n color: { ...TRANSPARENT },\n offset: { x: 0, y: 0 },\n radius: options.radius ?? DEFAULT_EFFECT_RADIUS,\n spread: 0,\n visible: options.visible ?? true\n }\n}\n\nexport function dropShadow(options: ShadowEffectOptions = {}): Effect {\n return shadowEffect('DROP_SHADOW', options)\n}\n\nexport function innerShadow(options: ShadowEffectOptions = {}): Effect {\n return shadowEffect('INNER_SHADOW', options)\n}\n\nexport function layerBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('LAYER_BLUR', radiusOrOptions)\n}\n\nexport function backgroundBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('BACKGROUND_BLUR', radiusOrOptions)\n}\n\nexport function foregroundBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('FOREGROUND_BLUR', radiusOrOptions)\n}\n"],"mappings":";;;;AAyBA,MAAM,wBAAwB;AAE9B,SAAS,QAAQ,OAAuC;CACtD,IAAI,UAAU,KAAA,GAAW,OAAO,EAAE,GAAG,YAAY;CACjD,OAAO,OAAO,UAAU,WAAW,WAAW,KAAK,IAAI;AACzD;AAEA,SAAS,aAAa,MAAsC,SAAsC;CAChG,OAAO;EACL;EACA,OAAO,QAAQ,QAAQ,SAAS,qBAAqB;EACrD,QAAQ,QAAQ,UAAU;GAAE,GAAG,QAAQ,KAAK;GAAG,GAAG,QAAQ,KAAK;EAAE;EACjE,QAAQ,QAAQ,UAAU;EAC1B,QAAQ,QAAQ,UAAU;EAC1B,SAAS,QAAQ,WAAW;EAC5B,WAAW,QAAQ;EACnB,sBAAsB,QAAQ;CAChC;AACF;AAEA,SAAS,WACP,MACA,kBAA8C,CAAC,GACvC;CACR,MAAM,UACJ,OAAO,oBAAoB,WAAW,EAAE,QAAQ,gBAAgB,IAAI;CACtE,OAAO;EACL;EACA,OAAO,EAAE,GAAG,YAAY;EACxB,QAAQ;GAAE,GAAG;GAAG,GAAG;EAAE;EACrB,QAAQ,QAAQ,UAAU;EAC1B,QAAQ;EACR,SAAS,QAAQ,WAAW;CAC9B;AACF;AAEA,SAAgB,WAAW,UAA+B,CAAC,GAAW;CACpE,OAAO,aAAa,eAAe,OAAO;AAC5C;AAEA,SAAgB,YAAY,UAA+B,CAAC,GAAW;CACrE,OAAO,aAAa,gBAAgB,OAAO;AAC7C;AAEA,SAAgB,UAAU,iBAAsD;CAC9E,OAAO,WAAW,cAAc,eAAe;AACjD;AAEA,SAAgB,eAAe,iBAAsD;CACnF,OAAO,WAAW,mBAAmB,eAAe;AACtD;AAEA,SAAgB,eAAe,iBAAsD;CACnF,OAAO,WAAW,mBAAmB,eAAe;AACtD"}
@@ -0,0 +1,618 @@
1
+ import { REKA_ELEMENTS, plainTextOf, rekaRole } from "./behaviours/elements.js";
2
+ import { FIGJAM_TEXT_SIZE, FIGJAM_TYPEFACE, SHAPE_KIND, STROKE_ALIGN, STROKE_CAP, STROKE_JOIN, connectorPropsSchema, ownLayerPropsSchema, placedOwnLayerPropsSchema, readElementProps, shapeLayerPropsSchema, shapePropsSchema, stickyPropsSchema } from "./component-properties.js";
3
+ import { DESIGN_JSX_PARAGRAPH_PROPERTY_NAMES, DESIGN_JSX_SPAN_PROPERTY_NAMES, DESIGN_JSX_SUPPORTED_PROPERTY_NAMES, DESIGN_JSX_TEXT_PARAGRAPH_PROPERTY_NAMES } from "./behaviours/render.js";
4
+ import { connectorBindingTarget, helperCall, plainValue, renderConnectorNode } from "./connectors.js";
5
+ import { colorToHex, colorToHex8 } from "@pairdraw/scene-graph/color";
6
+ import { gradientTransformRows, isIdentityGradientTransform } from "@pairdraw/scene-graph/gradient";
7
+ import { isShaderPresetPaint, shaderOfPaint } from "@pairdraw/scene-graph/shaders";
8
+ import { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_SIZE, STICKY_COLORS, createShapeWithText, createSticky, isWideSticky, shapeWithTextLabel, stickyScale, stickySublayers } from "@pairdraw/scene-graph/generated";
9
+ import { difference } from "es-toolkit/array";
10
+ import { figJamTextSize, figJamTextSizeFields, figJamTypeface, figJamTypefaceFields } from "@pairdraw/scene-graph/figjam";
11
+ //#region src/export/helpers.ts
12
+ function formatColor(color, opacity = 1) {
13
+ return colorToHex8(color, opacity);
14
+ }
15
+ function formatShadow(e) {
16
+ if (e.type !== "DROP_SHADOW" && e.type !== "INNER_SHADOW") return null;
17
+ return `${e.offset.x} ${e.offset.y} ${e.radius} ${formatColor(e.color, e.color.a)}`;
18
+ }
19
+ function getNodeContext(node, graph) {
20
+ const parent = node.parentId ? graph.getNode(node.parentId) : null;
21
+ return {
22
+ isAutoLayout: node.layoutMode !== "NONE",
23
+ isGrid: node.layoutMode === "GRID",
24
+ isFlex: node.layoutMode === "HORIZONTAL" || node.layoutMode === "VERTICAL",
25
+ parentIsAutoLayout: parent ? parent.layoutMode !== "NONE" : false,
26
+ parentIsGrid: parent ? parent.layoutMode === "GRID" : false
27
+ };
28
+ }
29
+ function collectPadding(node) {
30
+ const { paddingTop: pt, paddingRight: pr, paddingBottom: pb, paddingLeft: pl } = node;
31
+ if (pt === 0 && pr === 0 && pb === 0 && pl === 0) return null;
32
+ return {
33
+ pt,
34
+ pr,
35
+ pb,
36
+ pl
37
+ };
38
+ }
39
+ function emitPadding(edges, uniform, symmetric, individual) {
40
+ const { pt, pr, pb, pl } = edges;
41
+ if (pt === pr && pr === pb && pb === pl) return [uniform(pt)];
42
+ if (pt === pb && pl === pr) return symmetric(pt, pl);
43
+ return individual(edges);
44
+ }
45
+ function collectCornerRadii(node) {
46
+ if (node.independentCorners) {
47
+ const corners = {
48
+ tl: node.topLeftRadius,
49
+ tr: node.topRightRadius,
50
+ br: node.bottomRightRadius,
51
+ bl: node.bottomLeftRadius
52
+ };
53
+ return Object.values(corners).some((radius) => radius > 0) ? corners : null;
54
+ }
55
+ if (node.cornerRadius <= 0) return null;
56
+ const r = node.cornerRadius;
57
+ return {
58
+ tl: r,
59
+ tr: r,
60
+ br: r,
61
+ bl: r
62
+ };
63
+ }
64
+ function formatTrack(t) {
65
+ if (t.sizing === "FR") return `${t.value}fr`;
66
+ if (t.sizing === "FIXED") return `${t.value}px`;
67
+ return "auto";
68
+ }
69
+ function formatTracks(tracks) {
70
+ return tracks.map(formatTrack).join(" ");
71
+ }
72
+ //#endregion
73
+ //#region src/export/paint.ts
74
+ const GRADIENT_HELPERS = {
75
+ GRADIENT_LINEAR: "linearGradient",
76
+ GRADIENT_RADIAL: "radialGradient",
77
+ GRADIENT_ANGULAR: "angularGradient",
78
+ GRADIENT_DIAMOND: "diamondGradient"
79
+ };
80
+ function isIdentity(transform) {
81
+ return !transform || isIdentityGradientTransform(transform);
82
+ }
83
+ /** A paint transform as authors write it, in Figma's rows. */
84
+ function rows(transform) {
85
+ return transform && gradientTransformRows(transform);
86
+ }
87
+ /** Paints and effects imported from Figma often spell out the default blend mode. */
88
+ function blendMode(mode) {
89
+ return mode === "NORMAL" || mode === "PASS_THROUGH" ? void 0 : mode;
90
+ }
91
+ /** Helper options with defaults left out, or `undefined` when none differ. */
92
+ function options(entries) {
93
+ return Object.values(entries).some((value) => value !== void 0) ? entries : void 0;
94
+ }
95
+ function fillValue(fill, node) {
96
+ const visible = fill.visible ? void 0 : false;
97
+ const shader = shaderOfPaint(node, fill);
98
+ if (shader && isShaderPresetPaint(shader)) {
99
+ const { components, ...rest } = shader.preset;
100
+ return helperCall("shader", plainValue(Object.keys(rest).length === 0 ? components : shader.preset), options({
101
+ opacity: fill.opacity === 1 ? void 0 : fill.opacity,
102
+ visible,
103
+ blendMode: blendMode(fill.blendMode)
104
+ }));
105
+ }
106
+ if (shader) {
107
+ const uniforms = shader.uniforms ?? {};
108
+ return helperCall("shaderSource", shader.source, options({
109
+ uniforms: Object.keys(uniforms).length === 0 ? void 0 : plainValue(uniforms),
110
+ opacity: fill.opacity === 1 ? void 0 : fill.opacity,
111
+ visible,
112
+ blendMode: blendMode(fill.blendMode)
113
+ }));
114
+ }
115
+ if (fill.type === "SOLID") {
116
+ const color = formatColor(fill.color, fill.color.a);
117
+ const opacity = fill.opacity === fill.color.a ? void 0 : fill.opacity;
118
+ return helperCall("solid", color, options({
119
+ opacity,
120
+ visible,
121
+ blendMode: blendMode(fill.blendMode)
122
+ }));
123
+ }
124
+ const helper = GRADIENT_HELPERS[fill.type];
125
+ if (helper && fill.gradientStops) {
126
+ const stops = fill.gradientStops.map((stop) => [formatColor(stop.color, stop.color.a), stop.position]);
127
+ return helperCall(helper, stops, options({
128
+ opacity: fill.opacity === 1 ? void 0 : fill.opacity,
129
+ visible,
130
+ blendMode: blendMode(fill.blendMode),
131
+ transform: isIdentity(fill.gradientTransform) ? void 0 : plainValue(rows(fill.gradientTransform))
132
+ }));
133
+ }
134
+ return plainValue({
135
+ ...fill,
136
+ gradientTransform: rows(fill.gradientTransform),
137
+ imageTransform: rows(fill.imageTransform)
138
+ });
139
+ }
140
+ /** A single visible solid paint fits the `bg` or text `color` shorthand. */
141
+ function solidShorthand(fills) {
142
+ if (fills.length !== 1) return null;
143
+ const [fill] = fills;
144
+ if (fill.type !== "SOLID" || !fill.visible || blendMode(fill.blendMode)) return null;
145
+ if (fill.opacity !== fill.color.a) return null;
146
+ return formatColor(fill.color, fill.color.a);
147
+ }
148
+ /** One paint as a colour prop takes it: a colour string when it is plain, its helper otherwise. */
149
+ function paintPropValue(fill, node) {
150
+ return solidShorthand([fill]) ?? fillValue(fill, node);
151
+ }
152
+ function collectFillProps(node, props) {
153
+ if (node.fills.length === 0) {
154
+ if (node.type === "TEXT") props.push(["fills", []]);
155
+ return;
156
+ }
157
+ const shorthand = solidShorthand(node.fills);
158
+ if (shorthand) props.push([node.type === "TEXT" ? "color" : "bg", shorthand]);
159
+ else props.push(["fills", node.fills.map((fill) => fillValue(fill, node))]);
160
+ }
161
+ function strokeValue(stroke) {
162
+ return {
163
+ color: formatColor(stroke.color, stroke.color.a),
164
+ opacity: stroke.opacity === stroke.color.a ? void 0 : stroke.opacity,
165
+ weight: stroke.weight === 1 ? void 0 : stroke.weight,
166
+ align: stroke.align === "INSIDE" ? void 0 : STROKE_ALIGN.print(stroke.align),
167
+ dash: stroke.dashPattern && stroke.dashPattern.length > 0 ? [...stroke.dashPattern] : void 0,
168
+ cap: stroke.cap && STROKE_CAP.print(stroke.cap),
169
+ join: stroke.join && STROKE_JOIN.print(stroke.join),
170
+ visible: stroke.visible ? void 0 : false
171
+ };
172
+ }
173
+ const STROKE_SHORTHAND = {
174
+ color: "stroke",
175
+ weight: "strokeWidth",
176
+ align: "strokeAlign",
177
+ dash: "strokeDash"
178
+ };
179
+ /** Node-level cap and join apply to strokes that do not set their own. */
180
+ const DEFAULT_STROKE_CAP = "NONE";
181
+ const DEFAULT_STROKE_JOIN = "MITER";
182
+ /**
183
+ * The shorthand props describe one stroke, and `strokeCap`/`strokeJoin` also set the node's
184
+ * cap and join; they fit only when the stroke agrees with the node on both.
185
+ */
186
+ function fitsStrokeShorthand(node, stroke) {
187
+ if (stroke.visible !== void 0 || stroke.opacity !== void 0) return false;
188
+ const nodeCap = STROKE_CAP.print(node.strokeCap);
189
+ const nodeJoin = STROKE_JOIN.print(node.strokeJoin);
190
+ return (stroke.cap ?? nodeCap) === nodeCap && (stroke.join ?? nodeJoin) === nodeJoin;
191
+ }
192
+ function collectStrokeProps(node, props) {
193
+ const strokes = node.strokes.map(strokeValue);
194
+ const [only] = strokes;
195
+ if (strokes.length === 1 && fitsStrokeShorthand(node, only)) {
196
+ for (const [key, value] of Object.entries(only)) if (value !== void 0 && key !== "cap" && key !== "join") props.push([STROKE_SHORTHAND[key], value]);
197
+ } else if (strokes.length > 0) props.push(["strokes", strokes]);
198
+ if (node.strokeCap !== DEFAULT_STROKE_CAP) props.push(["strokeCap", STROKE_CAP.print(node.strokeCap)]);
199
+ if (node.strokeJoin !== DEFAULT_STROKE_JOIN) props.push(["strokeJoin", STROKE_JOIN.print(node.strokeJoin)]);
200
+ if (node.dashPattern.length > 0) props.push(["dashPattern", [...node.dashPattern]]);
201
+ if (node.independentStrokeWeights) props.push(["strokeWeights", {
202
+ top: node.borderTopWeight,
203
+ right: node.borderRightWeight,
204
+ bottom: node.borderBottomWeight,
205
+ left: node.borderLeftWeight
206
+ }]);
207
+ }
208
+ const EFFECT_HELPERS = {
209
+ DROP_SHADOW: "dropShadow",
210
+ INNER_SHADOW: "innerShadow",
211
+ LAYER_BLUR: "layerBlur",
212
+ BACKGROUND_BLUR: "backgroundBlur",
213
+ FOREGROUND_BLUR: "foregroundBlur"
214
+ };
215
+ function effectValue(effect) {
216
+ const visible = effect.visible ? void 0 : false;
217
+ if (effect.type === "DROP_SHADOW" || effect.type === "INNER_SHADOW") return helperCall(EFFECT_HELPERS[effect.type], options({
218
+ x: effect.offset.x,
219
+ y: effect.offset.y,
220
+ radius: effect.radius,
221
+ spread: effect.spread === 0 ? void 0 : effect.spread,
222
+ color: formatColor(effect.color, effect.color.a),
223
+ visible,
224
+ blendMode: blendMode(effect.blendMode),
225
+ showShadowBehindNode: effect.showShadowBehindNode
226
+ }));
227
+ return helperCall(EFFECT_HELPERS[effect.type], visible === void 0 ? effect.radius : {
228
+ radius: effect.radius,
229
+ visible
230
+ });
231
+ }
232
+ function plainDropShadow(effect) {
233
+ return effect.type === "DROP_SHADOW" && effect.spread === 0 && !blendMode(effect.blendMode) && effect.showShadowBehindNode === void 0 ? formatShadow(effect) : null;
234
+ }
235
+ /**
236
+ * `shadow` and `blur` describe a plain drop shadow followed by a layer blur, each optional,
237
+ * in the order the renderer appends them; anything else needs `effects`.
238
+ */
239
+ function effectShorthand(effects) {
240
+ if (effects.some((effect) => !effect.visible)) return null;
241
+ const shadow = effects.length > 0 ? plainDropShadow(effects[0]) : null;
242
+ const rest = shadow ? effects.slice(1) : effects;
243
+ if (rest.length > 1 || rest.some((effect) => effect.type !== "LAYER_BLUR")) return null;
244
+ const props = [];
245
+ if (shadow) props.push(["shadow", shadow]);
246
+ for (const blur of rest) props.push(["blur", blur.radius]);
247
+ return props;
248
+ }
249
+ function collectEffectProps(node, props) {
250
+ const effects = node.effects.filter((effect) => effect.type !== "SHADER");
251
+ if (effects.length === 0) return;
252
+ props.push(...effectShorthand(effects) ?? [["effects", effects.map(effectValue)]]);
253
+ }
254
+ //#endregion
255
+ //#region src/figjam-text.ts
256
+ /**
257
+ * The fields a sticky note's body or a shape's label takes from `textSize` and `typeface`, as
258
+ * FigJam's text menus set them; the typeface keeps the size the text ends up at.
259
+ */
260
+ function figJamTextFields(text, textSize, typeface) {
261
+ const sized = textSize ? figJamTextSizeFields(textSize, typeface) : {};
262
+ if (!typeface) return sized;
263
+ return figJamTypefaceFields(typeface, { fontSize: sized.fontSize ?? text.fontSize });
264
+ }
265
+ /** `textSize` and `typeface` as an element writes them, each left out at FigJam's default. */
266
+ function figJamTextProps(text) {
267
+ const props = [];
268
+ const size = figJamTextSize(text);
269
+ if (size !== "small") props.push(["textSize", FIGJAM_TEXT_SIZE.print(size)]);
270
+ const typeface = figJamTypeface(text);
271
+ if (typeface && typeface !== "simple") props.push(["typeface", FIGJAM_TYPEFACE.print(typeface)]);
272
+ return props;
273
+ }
274
+ //#endregion
275
+ //#region src/shapes-with-text.ts
276
+ /**
277
+ * The shape an element describes, with `layer`'s fields; it is named by its label, as FigJam
278
+ * names a shape, until given a name.
279
+ */
280
+ function renderShapeNode(graph, tree, parentId, layer) {
281
+ const props = readElementProps(shapePropsSchema, tree.props);
282
+ const text = plainTextOf(tree);
283
+ const shape = createShapeWithText(graph, parentId, {
284
+ ...layer,
285
+ name: layer.name ?? (text.trim() || "Shape with text"),
286
+ autoRename: !layer.name,
287
+ shapeWithTextType: props.kind ?? "SQUARE",
288
+ shapeTruncates: props.truncate ?? false
289
+ }, { text });
290
+ const label = shapeWithTextLabel(graph, shape);
291
+ if (label) graph.updateNode(label.id, figJamTextFields(label, props.textSize, props.typeface));
292
+ return shape;
293
+ }
294
+ /**
295
+ * A shape's own props as `<Shape>` writes them, after its name and position: the height it was
296
+ * given rather than the height its label grew it to, so it grows the same way when read back.
297
+ */
298
+ function shapeWithTextProps(graph, node) {
299
+ const props = [];
300
+ if (node.shapeWithTextType !== "SQUARE") props.push(["kind", SHAPE_KIND.print(node.shapeWithTextType)]);
301
+ const label = shapeWithTextLabel(graph, node);
302
+ if (label) props.push(...figJamTextProps(label));
303
+ const height = !node.shapeTruncates && node.shapeUserHeight > 0 ? node.shapeUserHeight : node.height;
304
+ if (node.width !== SHAPE_WITH_TEXT_SIZE) props.push(["w", node.width]);
305
+ if (height !== SHAPE_WITH_TEXT_SIZE) props.push(["h", height]);
306
+ if (node.shapeTruncates) props.push(["truncate", true]);
307
+ if (node.rotation !== 0) props.push(["rotate", Math.round(node.rotation * 100) / 100]);
308
+ collectFillProps(node, props);
309
+ collectStrokeProps(node, props);
310
+ if (node.cornerRadius !== SHAPE_WITH_TEXT_CORNER_RADIUS) props.push(["rounded", node.cornerRadius]);
311
+ return props;
312
+ }
313
+ /** The label a shape writes as its children. */
314
+ function shapeWithTextLabelText(graph, node) {
315
+ return shapeWithTextLabel(graph, node)?.text ?? "";
316
+ }
317
+ //#endregion
318
+ //#region src/stickies.ts
319
+ /**
320
+ * The note an element describes, with `layer`'s fields; it is named by its body, as FigJam names
321
+ * a note, until given a name.
322
+ */
323
+ function renderStickyNode(graph, tree, parentId, layer) {
324
+ const props = readElementProps(stickyPropsSchema, tree.props);
325
+ const text = plainTextOf(tree);
326
+ const author = props.author ?? "";
327
+ const sticky = createSticky(graph, parentId, {
328
+ text,
329
+ author,
330
+ authorVisible: props.authorVisible !== false && author !== "",
331
+ color: props.color,
332
+ wide: props.wide === true,
333
+ scale: props.scale ?? 1
334
+ }, {
335
+ ...layer,
336
+ name: layer.name ?? (text.trim() || "Sticky"),
337
+ autoRename: !layer.name
338
+ });
339
+ const body = stickySublayers(graph, sticky)?.body;
340
+ if (body) graph.updateNode(body.id, figJamTextFields(body, props.textSize, props.typeface));
341
+ return sticky;
342
+ }
343
+ /** The colour as `<Sticky>` writes it: its palette name, or a hex colour off the palette. */
344
+ function colorName(color) {
345
+ const hex = colorToHex(color);
346
+ const named = Object.entries(STICKY_COLORS).find(([, value]) => colorToHex(value) === hex);
347
+ return named ? named[0] : hex;
348
+ }
349
+ /** A note's own props as `<Sticky>` writes them, after its name and position. */
350
+ function stickyProps(graph, node) {
351
+ const layers = stickySublayers(graph, node);
352
+ const color = node.fills.at(0)?.color;
353
+ const props = [];
354
+ if (color) props.push(["color", colorName(color)]);
355
+ if (layers?.author.text) props.push(["author", layers.author.text]);
356
+ if (layers?.author.text && !layers.author.visible) props.push(["authorVisible", false]);
357
+ if (isWideSticky(graph, node)) props.push(["wide", true]);
358
+ if (layers) props.push(...figJamTextProps(layers.body));
359
+ const scale = layers ? stickyScale(layers.author) : 1;
360
+ if (scale !== 1) props.push(["scale", scale]);
361
+ return props;
362
+ }
363
+ /** The body a note writes as its children. */
364
+ function stickyBody(graph, node) {
365
+ return stickySublayers(graph, node)?.body.text ?? "";
366
+ }
367
+ //#endregion
368
+ //#region src/elements.ts
369
+ function rekaDescription(namespace, part) {
370
+ const role = rekaRole(`${namespace}.${part}`);
371
+ if (role?.role === "root") return `A main component that behaves as Reka UI's ${namespace} ${part}.`;
372
+ if (role?.role === "input") return `The text layer of a ${namespace}'s text property.`;
373
+ return `The ${namespace} ${part}, drawn by a slot of its component.`;
374
+ }
375
+ /** A Reka UI element as the element list describes it. */
376
+ function rekaElementDefinitions() {
377
+ return Object.entries(REKA_ELEMENTS).flatMap(([namespace, parts]) => Object.keys(parts).map((part) => {
378
+ const type = `${namespace}.${part}`;
379
+ return {
380
+ name: type,
381
+ runtimeType: type,
382
+ description: rekaDescription(namespace, part)
383
+ };
384
+ }));
385
+ }
386
+ const DESIGN_JSX_ELEMENTS = [
387
+ {
388
+ name: "Frame",
389
+ runtimeType: "frame",
390
+ description: "A frame or auto-layout container.",
391
+ nodeType: "FRAME",
392
+ writes: [
393
+ "FRAME",
394
+ "COMPONENT_SET",
395
+ "INSTANCE"
396
+ ]
397
+ },
398
+ {
399
+ name: "Text",
400
+ runtimeType: "text",
401
+ description: "A text layer.",
402
+ nodeType: "TEXT",
403
+ writes: ["TEXT"]
404
+ },
405
+ {
406
+ name: "Span",
407
+ runtimeType: "text-span",
408
+ description: "Characters inside a Text, styled apart from the rest.",
409
+ props: ["key", ...DESIGN_JSX_SPAN_PROPERTY_NAMES]
410
+ },
411
+ {
412
+ name: "Paragraph",
413
+ runtimeType: "text-paragraph",
414
+ description: "One paragraph of a Text, plain or a list item.",
415
+ props: ["key", ...DESIGN_JSX_PARAGRAPH_PROPERTY_NAMES]
416
+ },
417
+ {
418
+ name: "Rectangle",
419
+ runtimeType: "rectangle",
420
+ description: "A rectangle layer.",
421
+ nodeType: "RECTANGLE",
422
+ writes: ["RECTANGLE", "ROUNDED_RECTANGLE"]
423
+ },
424
+ {
425
+ name: "Ellipse",
426
+ runtimeType: "ellipse",
427
+ description: "An ellipse layer.",
428
+ nodeType: "ELLIPSE",
429
+ writes: ["ELLIPSE"]
430
+ },
431
+ {
432
+ name: "Line",
433
+ runtimeType: "line",
434
+ description: "A line layer.",
435
+ nodeType: "LINE",
436
+ writes: ["LINE"]
437
+ },
438
+ {
439
+ name: "Star",
440
+ runtimeType: "star",
441
+ description: "A star layer.",
442
+ nodeType: "STAR",
443
+ writes: ["STAR"]
444
+ },
445
+ {
446
+ name: "Polygon",
447
+ runtimeType: "polygon",
448
+ description: "A polygon layer.",
449
+ nodeType: "POLYGON",
450
+ writes: ["POLYGON"]
451
+ },
452
+ {
453
+ name: "Vector",
454
+ runtimeType: "vector",
455
+ description: "A vector layer.",
456
+ nodeType: "VECTOR",
457
+ writes: ["VECTOR"]
458
+ },
459
+ {
460
+ name: "Group",
461
+ runtimeType: "group",
462
+ description: "A group of layers.",
463
+ nodeType: "GROUP",
464
+ writes: ["GROUP"]
465
+ },
466
+ {
467
+ name: "Section",
468
+ runtimeType: "section",
469
+ description: "A canvas section.",
470
+ nodeType: "SECTION",
471
+ writes: ["SECTION"]
472
+ },
473
+ {
474
+ name: "Component",
475
+ runtimeType: "component",
476
+ description: "A reusable component.",
477
+ nodeType: "COMPONENT",
478
+ writes: ["COMPONENT"]
479
+ },
480
+ {
481
+ name: "ComponentSet",
482
+ runtimeType: "component-set",
483
+ description: "A component variant set.",
484
+ nodeType: "COMPONENT_SET"
485
+ },
486
+ {
487
+ name: "Instance",
488
+ runtimeType: "instance",
489
+ description: "An instance of a component."
490
+ },
491
+ {
492
+ name: "View",
493
+ runtimeType: "frame",
494
+ description: "An alias for Frame.",
495
+ nodeType: "FRAME"
496
+ },
497
+ {
498
+ name: "Rect",
499
+ runtimeType: "rectangle",
500
+ description: "An alias for Rectangle.",
501
+ nodeType: "RECTANGLE"
502
+ },
503
+ {
504
+ name: "Icon",
505
+ runtimeType: "icon",
506
+ description: "An Iconify icon."
507
+ },
508
+ {
509
+ name: "Sticky",
510
+ runtimeType: "sticky",
511
+ description: "A FigJam sticky note; its text is the body.",
512
+ schema: stickyPropsSchema,
513
+ ownLayer: {
514
+ layer: placedOwnLayerPropsSchema,
515
+ render: renderStickyNode
516
+ },
517
+ writes: ["STICKY"]
518
+ },
519
+ {
520
+ name: "Shape",
521
+ runtimeType: "shape",
522
+ description: "A FigJam shape with text; its text is the label.",
523
+ schema: shapePropsSchema,
524
+ ownLayer: {
525
+ layer: shapeLayerPropsSchema,
526
+ render: renderShapeNode
527
+ },
528
+ writes: ["SHAPE_WITH_TEXT"]
529
+ },
530
+ {
531
+ name: "Connector",
532
+ runtimeType: "connector",
533
+ description: "A FigJam connector between two layers of the same JSX, named by `from` and `to`, or points.",
534
+ schema: connectorPropsSchema,
535
+ ownLayer: {
536
+ layer: ownLayerPropsSchema,
537
+ render: renderConnectorNode,
538
+ bindingTarget: connectorBindingTarget
539
+ },
540
+ writes: ["CONNECTOR"]
541
+ },
542
+ ...rekaElementDefinitions()
543
+ ];
544
+ /** Props an inline `<svg>` takes besides a layer's: its markup's view box and body. */
545
+ const SVG_PROPERTY_NAMES = ["viewBox", "body"];
546
+ /**
547
+ * Lowercase tags JSX also accepts, as HTML names them, with the layer each makes; they are
548
+ * not written back.
549
+ */
550
+ const INTRINSIC_ELEMENTS = {
551
+ componentset: "COMPONENT_SET",
552
+ div: "FRAME",
553
+ main: "FRAME",
554
+ header: "FRAME",
555
+ footer: "FRAME",
556
+ nav: "FRAME",
557
+ article: "FRAME",
558
+ aside: "FRAME",
559
+ span: "TEXT",
560
+ p: "TEXT",
561
+ h1: "TEXT",
562
+ h2: "TEXT",
563
+ h3: "TEXT",
564
+ h4: "TEXT",
565
+ h5: "TEXT",
566
+ h6: "TEXT",
567
+ svg: null
568
+ };
569
+ /** Paragraph props describe a paragraph of a text, never a layer, unless a text sets them too. */
570
+ const LAYER_PROPS = new Set(difference(DESIGN_JSX_SUPPORTED_PROPERTY_NAMES, difference(DESIGN_JSX_PARAGRAPH_PROPERTY_NAMES, DESIGN_JSX_TEXT_PARAGRAPH_PROPERTY_NAMES)));
571
+ const BY_RUNTIME_TYPE = new Map(DESIGN_JSX_ELEMENTS.map((element) => [element.runtimeType, element]).reverse());
572
+ const PROPS_BY_RUNTIME_TYPE = new Map([["svg", /* @__PURE__ */ new Set([...LAYER_PROPS, ...SVG_PROPERTY_NAMES])], ...DESIGN_JSX_ELEMENTS.flatMap((element) => {
573
+ const props = element.schema ? Object.keys(element.schema.entries) : element.props;
574
+ return props ? [[element.runtimeType, new Set(props)]] : [];
575
+ })]);
576
+ const TAG_BY_NODE_TYPE = new Map(DESIGN_JSX_ELEMENTS.flatMap((element) => (element.writes ?? []).map((type) => [type, element.name])));
577
+ /** The layer an element of `runtimeType` makes, for an element without its own renderer. */
578
+ function elementNodeType(runtimeType) {
579
+ return BY_RUNTIME_TYPE.get(runtimeType)?.nodeType ?? INTRINSIC_ELEMENTS[runtimeType] ?? void 0;
580
+ }
581
+ /** The props an element of `runtimeType` takes. */
582
+ function elementProps(runtimeType) {
583
+ return PROPS_BY_RUNTIME_TYPE.get(runtimeType) ?? LAYER_PROPS;
584
+ }
585
+ const BY_NAME = new Map(DESIGN_JSX_ELEMENTS.map((element) => [element.name, element]));
586
+ /**
587
+ * The props an element written `<name>` takes, as the renderer checks them, for an editor that
588
+ * checks them as they are typed; null for a name that is no element, and for an instance, which
589
+ * also takes its component's properties by name.
590
+ */
591
+ function elementPropsByName(name) {
592
+ const element = BY_NAME.get(name);
593
+ if (!element) return Object.hasOwn(INTRINSIC_ELEMENTS, name) ? elementProps(name) : null;
594
+ return element.runtimeType === "instance" ? null : elementProps(element.runtimeType);
595
+ }
596
+ /** The schema an element of `runtimeType` reads its props by, if it has one. */
597
+ function elementSchema(runtimeType) {
598
+ return BY_RUNTIME_TYPE.get(runtimeType)?.schema;
599
+ }
600
+ /** How an element of `runtimeType` draws its own layer, if it does. */
601
+ function elementOwnLayer(runtimeType) {
602
+ return BY_RUNTIME_TYPE.get(runtimeType)?.ownLayer;
603
+ }
604
+ /** The element export writes a layer of `type` as, if any. */
605
+ function elementTag(type) {
606
+ return TAG_BY_NODE_TYPE.get(type);
607
+ }
608
+ /**
609
+ * `const Frame = 'frame', …`: the element names a JSX string's code can use, bound to their
610
+ * runtime types. Reka UI elements, named `Switch.Root`, are bound by their namespaces.
611
+ */
612
+ function elementBindings() {
613
+ return DESIGN_JSX_ELEMENTS.filter((element) => !element.name.includes(".")).map((element) => `const ${element.name} = '${element.runtimeType}'`).join("\n");
614
+ }
615
+ //#endregion
616
+ export { DESIGN_JSX_ELEMENTS, collectCornerRadii, collectEffectProps, collectFillProps, collectPadding, collectStrokeProps, elementBindings, elementNodeType, elementOwnLayer, elementProps, elementPropsByName, elementSchema, elementTag, emitPadding, formatColor, formatTracks, getNodeContext, paintPropValue, shapeWithTextLabelText, shapeWithTextProps, stickyBody, stickyProps };
617
+
618
+ //# sourceMappingURL=elements.js.map