@pairdraw/design-jsx 0.20.0 → 0.21.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/dist/chunks/component-properties.js +6 -6
- package/dist/chunks/component-properties.js.map +1 -1
- package/dist/chunks/elements.js +37 -32
- package/dist/chunks/elements.js.map +1 -1
- package/dist/chunks/export/decoration.js +4 -4
- package/dist/chunks/export/decoration.js.map +1 -1
- package/dist/chunks/export/index.js +20 -20
- package/dist/chunks/export/index.js.map +1 -1
- package/dist/chunks/fields.js +27 -27
- 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.map +1 -1
- package/package.json +3 -3
- package/src/export/decoration.ts +4 -3
- package/src/export/helpers.ts +8 -6
- package/src/export/index.ts +2 -2
- package/src/export/paint.ts +45 -24
- package/src/export/props.ts +9 -9
- package/src/export/text.ts +14 -8
- package/src/export/variables.ts +1 -1
- package/src/overrides/effects.ts +7 -3
- package/src/overrides/fills.ts +6 -3
- package/src/overrides/strokes.ts +9 -5
- package/src/overrides/text.ts +4 -3
- package/src/props-overrides.ts +37 -19
- package/src/reference/authoring.md +1 -1
- package/src/renderer.ts +20 -7
- package/src/shapes-with-text.ts +2 -2
- package/src/variables/graph.ts +1 -1
|
@@ -198,8 +198,8 @@ function parseTransform(field, value) {
|
|
|
198
198
|
if (result.success) return result.output;
|
|
199
199
|
throw new Error(`A paint's ${field} expects Figma's [[a, b, c], [d, e, f]] or { m00, m01, m02, m10, m11, m12 }:\n${v.summarize(result.issues)}`);
|
|
200
200
|
}
|
|
201
|
-
function fillFromValue(value) {
|
|
202
|
-
if (!isFill(value)) return colorToFill(value);
|
|
201
|
+
function fillFromValue(value, profile = "srgb") {
|
|
202
|
+
if (!isFill(value)) return colorToFill(value, profile);
|
|
203
203
|
const fill = structuredClone(value);
|
|
204
204
|
for (const field of TRANSFORM_FIELDS) if (fill[field] !== void 0) fill[field] = parseTransform(field, fill[field]);
|
|
205
205
|
return fill;
|
|
@@ -218,8 +218,8 @@ function dashValue(value) {
|
|
|
218
218
|
const dash = value.filter((item) => typeof item === "number");
|
|
219
219
|
return dash.length > 0 ? dash : void 0;
|
|
220
220
|
}
|
|
221
|
-
function toStroke(value) {
|
|
222
|
-
const color = typeof value.color === "string" ? parseColor(value.color) : value.color;
|
|
221
|
+
function toStroke(value, profile) {
|
|
222
|
+
const color = typeof value.color === "string" ? parseColor(value.color, profile) : value.color;
|
|
223
223
|
const stroke = {
|
|
224
224
|
type: "SOLID",
|
|
225
225
|
color,
|
|
@@ -251,7 +251,7 @@ function applyStrokeWeights(value, o) {
|
|
|
251
251
|
o.borderLeftWeight = sideWeight(value.left);
|
|
252
252
|
}
|
|
253
253
|
/** `strokes` takes structured strokes; `stroke` and its sibling props describe a single one. */
|
|
254
|
-
function applyStrokeOverrides(props, o) {
|
|
254
|
+
function applyStrokeOverrides(props, o, profile = "srgb") {
|
|
255
255
|
applyStrokeWeights(props.strokeWeights, o);
|
|
256
256
|
const nodeCap = STROKE_CAP.parse(props.strokeCap);
|
|
257
257
|
if (nodeCap) o.strokeCap = nodeCap;
|
|
@@ -262,7 +262,7 @@ function applyStrokeOverrides(props, o) {
|
|
|
262
262
|
const strokes = strokeValues(props).map((value) => toStroke({
|
|
263
263
|
...value,
|
|
264
264
|
dash: value.dash ?? nodeDash
|
|
265
|
-
}));
|
|
265
|
+
}, profile));
|
|
266
266
|
if (strokes.length > 0) o.strokes = strokes;
|
|
267
267
|
}
|
|
268
268
|
/** The strokes `strokes` lists, or the one `stroke` and its sibling props describe. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-properties.js","names":["isColor","isColor"],"sources":["../../src/enums.ts","../../src/overrides/fills.ts","../../src/overrides/strokes.ts","../../src/refs.ts","../../src/variables/index.ts","../../src/schema.ts","../../src/component-properties.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type {\n BlendMode,\n ConnectorLineType,\n ConnectorMagnet,\n ConstraintType,\n MaskType,\n SceneNode,\n Stroke,\n StrokeCap,\n StrokeJoin,\n TextAutoResize,\n TextCase,\n TextDecoration,\n TextDecorationStyle,\n TextDirection\n} from '@pairdraw/scene-graph'\nimport type { FigJamTextSize, FigJamTypeface } from '@pairdraw/scene-graph/figjam'\nimport {\n SHAPE_WITH_TEXT_TYPES,\n type ShapeWithTextType\n} from '@pairdraw/scene-graph/shape-with-text'\n\n/**\n * A Figma enum as design JSX spells it. Reading and writing come from one table, so whatever the\n * export writes reads back, and a value the table does not know is reported instead of reaching\n * the document.\n */\nexport interface JSXEnum<T extends string> {\n /** The value a spelling names, read case-insensitively, or undefined for none. */\n parse(value: unknown): T | undefined\n /** How the export spells a value. */\n print(value: T): string\n /** Every spelling it reads, aliases included. */\n readonly names: readonly string[]\n}\n\n/**\n * `spellings` names every value of the enum, which the type checks, and is what the export writes;\n * `aliases` are further spellings it only reads.\n */\nfunction jsxEnum<T extends string>(\n spellings: Readonly<Record<T, string>>,\n aliases: Readonly<Record<string, T>> = {}\n): JSXEnum<T> {\n const entries = Object.entries(spellings) as [T, string][]\n const byName = new Map<string, T>(\n [...entries.map(([value, name]): [string, T] => [name, value]), ...Object.entries(aliases)].map(\n ([name, value]): [string, T] => [name.toLowerCase(), value]\n )\n )\n return {\n parse: (value) => (typeof value === 'string' ? byName.get(value.toLowerCase()) : undefined),\n print: (value) => spellings[value],\n names: [...entries.map(([, name]) => name), ...Object.keys(aliases)]\n }\n}\n\n/** A prop that takes one of the enum's spellings, read as the value it names. */\nexport function enumProp<T extends string>(values: JSXEnum<T>) {\n return v.pipe(\n v.string(),\n v.rawTransform(({ dataset, addIssue, NEVER }) => {\n const value = values.parse(dataset.value)\n if (value !== undefined) return value\n addIssue({ message: `expected ${values.names.join(', ')}` })\n return NEVER\n })\n )\n}\n\n/** An enum spelled by each value's lowercase name, as most of design JSX's enums are. */\nfunction lowercaseEnum<T extends string>(\n values: readonly T[],\n aliases: Readonly<Record<string, T>> = {}\n): JSXEnum<T> {\n const spellings = Object.fromEntries(values.map((value) => [value, value.toLowerCase()]))\n return jsxEnum(spellings as Record<T, string>, aliases)\n}\n\nexport const STROKE_CAP = lowercaseEnum<StrokeCap>([\n 'NONE',\n 'ROUND',\n 'SQUARE',\n 'ARROW_LINES',\n 'ARROW_EQUILATERAL',\n 'TRIANGLE_FILLED',\n 'DIAMOND_FILLED',\n 'CIRCLE_FILLED'\n])\nexport const STROKE_JOIN = lowercaseEnum<StrokeJoin>(['MITER', 'BEVEL', 'ROUND'])\nexport const STROKE_ALIGN = lowercaseEnum<Stroke['align']>(['INSIDE', 'CENTER', 'OUTSIDE'])\nexport const CONSTRAINT = lowercaseEnum<ConstraintType>([\n 'MIN',\n 'CENTER',\n 'MAX',\n 'STRETCH',\n 'SCALE'\n])\nexport const MASK_TYPE = lowercaseEnum<MaskType>(['ALPHA', 'LUMINANCE', 'VECTOR'])\nexport const BLEND_MODE = lowercaseEnum<BlendMode>([\n 'NORMAL',\n 'DARKEN',\n 'MULTIPLY',\n 'LINEAR_BURN',\n 'COLOR_BURN',\n 'LIGHTEN',\n 'SCREEN',\n 'LINEAR_DODGE',\n 'COLOR_DODGE',\n 'OVERLAY',\n 'SOFT_LIGHT',\n 'HARD_LIGHT',\n 'DIFFERENCE',\n 'EXCLUSION',\n 'HUE',\n 'SATURATION',\n 'COLOR',\n 'LUMINOSITY',\n 'PASS_THROUGH'\n])\nexport const TEXT_ALIGN = lowercaseEnum<SceneNode['textAlignHorizontal']>(\n ['LEFT', 'CENTER', 'RIGHT', 'JUSTIFIED'],\n { left_align: 'LEFT', center_align: 'CENTER', right_align: 'RIGHT' }\n)\nexport const TEXT_ALIGN_VERTICAL = lowercaseEnum<SceneNode['textAlignVertical']>([\n 'TOP',\n 'CENTER',\n 'BOTTOM'\n])\nexport const TEXT_AUTO_RESIZE = jsxEnum<TextAutoResize>({\n NONE: 'none',\n WIDTH_AND_HEIGHT: 'width',\n HEIGHT: 'height',\n TRUNCATE: 'truncate'\n})\nexport const TEXT_DIRECTION = lowercaseEnum<TextDirection>(['AUTO', 'LTR', 'RTL'])\nexport const TEXT_DECORATION = lowercaseEnum<TextDecoration>(['NONE', 'UNDERLINE', 'STRIKETHROUGH'])\nexport const TEXT_DECORATION_STYLE = lowercaseEnum<TextDecorationStyle>(['SOLID', 'DOTTED', 'WAVY'])\nexport const TEXT_CASE = lowercaseEnum<TextCase>(['ORIGINAL', 'UPPER', 'LOWER', 'TITLE'])\n\nexport const FIGJAM_TEXT_SIZE = jsxEnum<FigJamTextSize>({\n small: 'small',\n medium: 'medium',\n large: 'large',\n extraLarge: 'extraLarge',\n huge: 'huge'\n})\n/** FigJam's typefaces, as its text menus name them. */\nexport const FIGJAM_TYPEFACE = jsxEnum<FigJamTypeface>({\n simple: 'simple',\n bookish: 'bookish',\n technical: 'technical',\n scribbled: 'scribbled'\n})\n/** The kinds a `<Shape>` draws, as FigJam names them: `rounded_rectangle`, `eng_database`. */\nexport const SHAPE_KIND = lowercaseEnum<ShapeWithTextType>(SHAPE_WITH_TEXT_TYPES)\nexport const CONNECTOR_LINE = lowercaseEnum<ConnectorLineType>(['ELBOWED', 'STRAIGHT', 'CURVED'])\n/** The sides a `<Connector>` end attaches by; the other magnets come only from files. */\nexport const CONNECTOR_SIDE = lowercaseEnum<\n Extract<ConnectorMagnet, 'AUTO' | 'TOP' | 'RIGHT' | 'BOTTOM' | 'LEFT' | 'CENTER'>\n>(['AUTO', 'TOP', 'RIGHT', 'BOTTOM', 'LEFT', 'CENTER'])\n\n/**\n * The layer props whose values are one of an enum's spellings, for checking what JSX passes. An\n * element with a props schema, such as `<Connector>`, checks its enums by `enumProp` instead.\n */\nexport const ENUM_PROPS: Readonly<Partial<Record<string, JSXEnum<string>>>> = {\n strokeCap: STROKE_CAP,\n strokeJoin: STROKE_JOIN,\n strokeAlign: STROKE_ALIGN,\n mask: MASK_TYPE,\n blendMode: BLEND_MODE,\n textAlign: TEXT_ALIGN,\n textAlignVertical: TEXT_ALIGN_VERTICAL,\n textAutoResize: TEXT_AUTO_RESIZE,\n dir: TEXT_DIRECTION,\n textDecoration: TEXT_DECORATION,\n textDecorationStyle: TEXT_DECORATION_STYLE,\n textCase: TEXT_CASE\n}\n","import * as v from 'valibot'\n\nimport type { Fill, GradientTransform } from '@pairdraw/scene-graph'\nimport { colorToFill } from '@pairdraw/scene-graph/color'\nimport { paintTransformSchema } from '@pairdraw/scene-graph/paints'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nexport function isColor(value: unknown): value is Color {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'r' in value &&\n 'g' in value &&\n 'b' in value &&\n 'a' in value\n )\n}\n\nfunction isFill(value: unknown): value is Fill {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'type' in value &&\n 'color' in value &&\n 'visible' in value\n )\n}\n\n/** A paint as props write it: a colour string, a colour, or a paint from a helper. */\nexport function isFillValue(value: unknown): value is string | Color | Fill {\n return typeof value === 'string' || isColor(value) || isFill(value)\n}\n\nconst TRANSFORM_FIELDS = ['gradientTransform', 'imageTransform'] as const\n\n/** Worded as `parseScriptInput` words it; that lives in `schema.ts`, which imports this module. */\nfunction parseTransform(\n field: (typeof TRANSFORM_FIELDS)[number],\n value: unknown\n): GradientTransform {\n const result = v.safeParse(paintTransformSchema, value)\n if (result.success) return result.output\n throw new Error(\n `A paint's ${field} expects Figma's [[a, b, c], [d, e, f]] or { m00, m01, m02, m10, m11, m12 }:\\n${v.summarize(result.issues)}`\n )\n}\n\nexport function fillFromValue(value: string | Color | Fill): Fill {\n if (!isFill(value)) return colorToFill(value)\n const fill = structuredClone(value)\n // A paint written as an object, as export writes an image, gives its transforms as Figma's rows.\n for (const field of TRANSFORM_FIELDS) {\n if (fill[field] !== undefined) fill[field] = parseTransform(field, fill[field])\n }\n return fill\n}\n","import { designJSXProp } from '#design-jsx/definitions'\nimport { STROKE_ALIGN, STROKE_CAP, STROKE_JOIN } from '#design-jsx/enums'\n\nimport type { SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { parseColor } from '@pairdraw/scene-graph/color'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { LayerProps } from '../schema'\n\n/** One entry of the `strokes` prop; enums are lowercase, as `blendMode` is. */\nexport interface StrokeValue {\n color: string | Color\n /** Defaults to the colour's alpha. */\n opacity?: number\n weight?: number\n align?: string\n dash?: number[]\n cap?: string\n join?: string\n visible?: boolean\n}\n\nfunction isColor(value: unknown): value is Color {\n return value !== null && typeof value === 'object' && 'r' in value && 'a' in value\n}\n\nexport function isStrokeValue(value: unknown): value is StrokeValue {\n if (value === null || typeof value !== 'object' || !('color' in value)) return false\n return typeof value.color === 'string' || isColor(value.color)\n}\n\nfunction dashValue(value: unknown): number[] | undefined {\n if (!Array.isArray(value)) return undefined\n const dash = value.filter((item): item is number => typeof item === 'number')\n return dash.length > 0 ? dash : undefined\n}\n\nfunction toStroke(value: StrokeValue): Stroke {\n const color = typeof value.color === 'string' ? parseColor(value.color) : value.color\n const stroke: Stroke = {\n type: 'SOLID',\n color,\n opacity: typeof value.opacity === 'number' ? value.opacity : color.a,\n visible: value.visible ?? true,\n weight: value.weight ?? 1,\n align: STROKE_ALIGN.parse(value.align) ?? 'INSIDE'\n }\n const dash = dashValue(value.dash)\n if (dash) stroke.dashPattern = dash\n const cap = STROKE_CAP.parse(value.cap)\n if (cap) stroke.cap = cap\n const join = STROKE_JOIN.parse(value.join)\n if (join) stroke.join = join\n return stroke\n}\n\n/** `strokeWeights` names each side; a side it leaves out has no stroke. */\ninterface StrokeWeights {\n top?: unknown\n right?: unknown\n bottom?: unknown\n left?: unknown\n}\n\nfunction isStrokeWeights(value: unknown): value is StrokeWeights {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction sideWeight(value: unknown): number {\n return typeof value === 'number' ? value : 0\n}\n\nfunction applyStrokeWeights(value: unknown, o: Partial<SceneNode>): void {\n if (!isStrokeWeights(value)) return\n o.independentStrokeWeights = true\n o.borderTopWeight = sideWeight(value.top)\n o.borderRightWeight = sideWeight(value.right)\n o.borderBottomWeight = sideWeight(value.bottom)\n o.borderLeftWeight = sideWeight(value.left)\n}\n\n/** `strokes` takes structured strokes; `stroke` and its sibling props describe a single one. */\nexport function applyStrokeOverrides(props: LayerProps, o: Partial<SceneNode>): void {\n applyStrokeWeights(props.strokeWeights, o)\n // Node-level cap and join, which strokes without their own use.\n const nodeCap = STROKE_CAP.parse(props.strokeCap)\n if (nodeCap) o.strokeCap = nodeCap\n const nodeJoin = STROKE_JOIN.parse(props.strokeJoin)\n if (nodeJoin) o.strokeJoin = nodeJoin\n // The node's dash, which strokes without their own dash take, as strokes take its cap and join.\n const nodeDash = dashValue(props.dashPattern)\n if (nodeDash) o.dashPattern = nodeDash\n const strokes = strokeValues(props).map((value) =>\n toStroke({ ...value, dash: value.dash ?? nodeDash })\n )\n if (strokes.length > 0) o.strokes = strokes\n}\n\n/** The strokes `strokes` lists, or the one `stroke` and its sibling props describe. */\nfunction strokeValues(props: Record<string, unknown>): StrokeValue[] {\n if (Array.isArray(props.strokes)) return props.strokes.filter(isStrokeValue)\n const color = designJSXProp(props, 'stroke')\n if (typeof color !== 'string' && !isColor(color)) return []\n return [\n {\n color,\n weight:\n (props.strokeWidth as number | undefined) ?? (props.borderWidth as number | undefined),\n align: props.strokeAlign as string | undefined,\n dash: props.strokeDash as number[] | undefined\n }\n ]\n}\n","import type { SceneNode } from '@pairdraw/scene-graph'\n\nconst REF_SYMBOL = Symbol.for('pairdraw.layer-ref')\n\n/**\n * A handle on one layer of the JSX: `ref={card}` marks the layer, and an element that refers to\n * a layer, such as `<Connector from={card}>`, takes the handle where a name could be ambiguous.\n */\nexport interface LayerRef {\n readonly [REF_SYMBOL]: true\n}\n\n/** A new handle for `ref={…}` to mark a layer with. */\nexport function ref(): LayerRef {\n return Object.freeze({ [REF_SYMBOL]: true as const })\n}\n\nexport function isLayerRef(value: unknown): value is LayerRef {\n return typeof value === 'object' && value !== null && REF_SYMBOL in value\n}\n\n/** The layers a render marked with `ref={…}`, for the elements that refer to them. */\nexport class LayerRefs {\n readonly warnings: string[] = []\n private readonly layers = new Map<LayerRef, SceneNode>()\n\n /** Marks `node` with the `ref` prop its element passed, if any. */\n mark(value: unknown, node: SceneNode) {\n if (value === undefined) return\n if (!isLayerRef(value)) {\n this.warnings.push(`ref on \"${node.name}\" is not a ref() and is ignored.`)\n return\n }\n const first = this.layers.get(value)\n if (first) {\n this.warnings.push(\n `One ref() marks both \"${first.name}\" and \"${node.name}\"; it refers to \"${first.name}\".`\n )\n return\n }\n this.layers.set(value, node)\n }\n\n /** The id of the layer `ref` marks, if one does. */\n layerOf(ref: LayerRef): string | undefined {\n return this.layers.get(ref)?.id\n }\n}\n","import { isPlainObject } from 'es-toolkit/predicate'\n\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nconst VAR_SYMBOL = Symbol.for('pairdraw.variable')\nconst MODE_SYMBOL = Symbol.for('pairdraw.variable-mode')\n\n/** The name a collection's first mode has when `defineVars` names none, as Figma names it. */\nexport const DEFAULT_MODE_NAME = 'Mode 1'\n\n/**\n * A value a variable holds in one mode: a color as a string or a `Color`, a number, a boolean,\n * or another variable, which makes it an alias.\n */\nexport type VariableInput = string | Color | number | boolean | DesignVariable\n\n/** A collection as `defineVars` and `defineMode` declare it; the first mode is the default. */\nexport interface CollectionDefinition {\n name: string\n modes: Array<{ name: string; values: Record<string, VariableInput> }>\n}\n\n/**\n * A variable a field binds to. `defineVars` gives one its collection, which a render creates or\n * updates; `designVar` names a variable the document already has, and may name its collection.\n */\nexport interface DesignVariable {\n readonly [VAR_SYMBOL]: true\n /** The variable's name, or for `designVar` without a collection, its name or ID. */\n readonly name: string\n readonly collection?: CollectionDefinition | string\n}\n\n/**\n * A mode a layer shows a collection in. `defineMode` gives it the collection it declares;\n * `designMode` names a collection the document already has.\n */\nexport interface DesignMode {\n readonly [MODE_SYMBOL]: true\n readonly name: string\n readonly collection: CollectionDefinition | string\n}\n\nexport function isVariable(value: unknown): value is DesignVariable {\n return typeof value === 'object' && value !== null && VAR_SYMBOL in value\n}\n\nexport function isMode(value: unknown): value is DesignMode {\n return typeof value === 'object' && value !== null && MODE_SYMBOL in value\n}\n\n/** Whether a value can be a variable's value: a color, a number, a boolean, or a variable. */\nexport function isVariableInput(value: unknown): value is VariableInput {\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')\n return true\n if (isVariable(value)) return true\n return isPlainObject(value) && ['r', 'g', 'b', 'a'].every((key) => typeof value[key] === 'number')\n}\n\n/**\n * A variable the document already has: by its name or ID, or by the names of its collection and\n * itself, as `designMode` names a mode, for a name more than one collection has.\n */\nexport function designVar(idOrName: string): DesignVariable\nexport function designVar(collection: string, name: string): DesignVariable\nexport function designVar(first: string, second?: string): DesignVariable {\n return Object.freeze(\n second === undefined\n ? { [VAR_SYMBOL]: true as const, name: first }\n : { [VAR_SYMBOL]: true as const, name: second, collection: first }\n )\n}\n\n/**\n * Define a variable collection: its variables, by name, with their values in its first mode,\n * named `mode` (Figma's `Mode 1` by default). A render that binds any of them creates the\n * collection, or updates the one with that name, so running the JSX again changes nothing twice.\n */\nexport function defineVars<T extends Record<string, VariableInput>>(\n collection: string,\n values: T,\n options: { mode?: string } = {}\n): { [K in keyof T]: DesignVariable } {\n const definition: CollectionDefinition = {\n name: collection,\n modes: [{ name: options.mode ?? DEFAULT_MODE_NAME, values }]\n }\n const handles = {} as { [K in keyof T]: DesignVariable }\n for (const name of Object.keys(values) as Array<keyof T & string>) {\n handles[name] = Object.freeze({ [VAR_SYMBOL]: true as const, name, collection: definition })\n }\n return handles\n}\n\n/**\n * Add a mode to a collection `defineVars` defined, with the values that differ from its first\n * mode; the rest keep the first mode's values, as a mode Figma adds copies them.\n */\nexport function defineMode(\n vars: Record<string, DesignVariable>,\n name: string,\n values: Record<string, VariableInput>\n): DesignMode {\n const definition = Object.values(vars)[0]?.collection\n if (!definition || typeof definition === 'string')\n throw new Error('defineMode() takes the variables defineVars() returned')\n if (definition.modes.some((mode) => mode.name === name))\n throw new Error(`Collection ${definition.name} already has a mode named ${name}`)\n const known = definition.modes[0].values\n for (const key of Object.keys(values)) {\n if (!Object.hasOwn(known, key))\n throw new Error(`Collection ${definition.name} has no variable named ${key}`)\n }\n definition.modes.push({ name, values })\n return Object.freeze({ [MODE_SYMBOL]: true as const, name, collection: definition })\n}\n\n/**\n * A mode of a collection the document already has, by their names, or by the collection's ID\n * when several collections share its name.\n */\nexport function designMode(collection: string, mode: string): DesignMode {\n return Object.freeze({ [MODE_SYMBOL]: true as const, name: mode, collection })\n}\n","import { mapValues } from 'es-toolkit/object'\nimport * as v from 'valibot'\n\nimport { tryParseColor } from '@pairdraw/scene-graph/color'\nimport { STICKY_COLORS } from '@pairdraw/scene-graph/generated'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport {\n CONNECTOR_LINE,\n CONNECTOR_SIDE,\n enumProp,\n FIGJAM_TEXT_SIZE,\n FIGJAM_TYPEFACE,\n SHAPE_KIND,\n STROKE_ALIGN,\n STROKE_CAP,\n STROKE_JOIN\n} from './enums'\nimport { isColor, isFillValue } from './overrides/fills'\nimport { isStrokeValue } from './overrides/strokes'\nimport { isLayerRef, type LayerRef } from './refs'\nimport { isVariable } from './variables'\n\n/**\n * Parse a value a design JSX script passed, or throw `heading` followed by every problem and\n * where it is, as `v.summarize` lists them. Core words tool arguments the same way.\n */\nexport function parseScriptInput<S extends v.GenericSchema>(\n heading: string,\n schema: S,\n value: unknown\n): v.InferOutput<S> {\n const result = v.safeParse(schema, value)\n if (result.success) return result.output\n throw new Error(`${heading}:\\n${v.summarize(result.issues)}`)\n}\n\n/**\n * The layer props an element that draws its own layer takes, such as a connector's: the\n * renderer makes them into fields and variable bindings as it does for any layer.\n */\nexport const ownLayerPropsSchema = v.object({\n name: v.optional(v.string()),\n key: v.optional(v.unknown()),\n visible: v.optional(v.boolean()),\n opacity: v.optional(v.number())\n})\n\n/** `OwnLayerProps` and the props that place a layer in its parent, such as a sticky note's. */\nexport const placedOwnLayerPropsSchema = v.object({\n ...ownLayerPropsSchema.entries,\n x: v.optional(v.number()),\n y: v.optional(v.number()),\n position: v.optional(v.picklist(['absolute']))\n})\n\nconst finiteNumberSchema = v.pipe(v.number(), v.finite())\n\n/** A length that cannot be negative, such as a size, radius, or stroke weight. */\nconst layoutLengthSchema = v.pipe(\n finiteNumberSchema,\n v.transform((length) => Math.min(1_000_000, Math.max(0, length)))\n)\n\n/** A share from none to all, such as how much a corner is smoothed. */\nconst shareSchema = v.pipe(\n finiteNumberSchema,\n v.transform((share) => Math.min(1, Math.max(0, share)))\n)\n\n/**\n * The layer props every element reads by the same reader, under each name it is written by. A\n * value of the wrong kind is reported and left out, so it never reaches a layer's fields; one out\n * of range is bounded, as a bound variable's value is.\n */\nexport const layerPropsSchema = v.object({\n name: v.optional(v.string()),\n // An artwork's layer name, since its `name` names the icon.\n label: v.optional(v.string()),\n opacity: v.optional(finiteNumberSchema),\n rotate: v.optional(finiteNumberSchema),\n rotation: v.optional(finiteNumberSchema),\n rounded: v.optional(layoutLengthSchema),\n cornerRadius: v.optional(layoutLengthSchema),\n borderRadius: v.optional(layoutLengthSchema),\n roundedTL: v.optional(layoutLengthSchema),\n roundedTR: v.optional(layoutLengthSchema),\n roundedBL: v.optional(layoutLengthSchema),\n roundedBR: v.optional(layoutLengthSchema),\n cornerSmoothing: v.optional(shareSchema),\n strokeWidth: v.optional(layoutLengthSchema),\n borderWidth: v.optional(layoutLengthSchema),\n maxLines: v.optional(v.pipe(v.number(), v.integer('expected a whole number'), v.minValue(1)))\n})\n\n/** An element's props with the layer props read by `layerPropsSchema`. */\nexport type LayerProps = Record<string, unknown> & v.InferOutput<typeof layerPropsSchema>\n\n/**\n * The layer props an inline `<svg>` reads itself. Its other props, such as `strokeWidth=\"2\"`,\n * are attributes of its markup's root, which the SVG service reads as SVG does.\n */\nexport const svgLayerPropsSchema = v.pick(layerPropsSchema, ['label'])\n\n/** `props` with each prop `schema` takes read by it, and every other prop as it is. */\nexport function readKnownProps<S extends ElementPropsSchema>(\n schema: S,\n props: Readonly<Record<string, unknown>>\n): Record<string, unknown> & v.InferOutput<S> {\n const read: Record<string, unknown> = { ...props }\n for (const [key, entry] of Object.entries(schema.entries)) {\n if (props[key] === undefined) continue\n const parsed = v.safeParse(entry, props[key])\n read[key] = parsed.success ? parsed.output : undefined\n }\n return read\n}\n\n/** `props` with its layer props read by `layerPropsSchema`, as every element reads them. */\nexport function readLayerProps(props: Readonly<Record<string, unknown>>): LayerProps {\n return readKnownProps(layerPropsSchema, props)\n}\n\n/** A colour as a string, or as the colour a `designVar()` resolves to. */\nconst colorPropSchema = v.union(\n [\n v.pipe(\n v.string(),\n v.rawTransform(({ dataset, addIssue, NEVER }): Color => {\n const color = tryParseColor(dataset.value)\n if (color) return color\n addIssue({ message: 'expected a colour' })\n return NEVER\n })\n ),\n v.custom<Color>(isColor)\n ],\n 'expected a colour'\n)\n\n/** The props of an element read one at a time, each of them optional. */\nexport type ElementPropsSchema = v.ObjectSchema<v.ObjectEntries, undefined>\n\n/**\n * The props `schema` takes, read from `props`: one that does not fit is left out as if it were\n * not set, since the renderer reports it (`elementPropWarnings`) and goes on.\n */\nexport function readElementProps<S extends ElementPropsSchema>(\n schema: S,\n props: Readonly<Record<string, unknown>>\n): v.InferOutput<S> {\n const fitting = mapValues(schema.entries, (entry, key) =>\n v.is(entry, props[key]) ? props[key] : undefined\n )\n return v.parse(schema, fitting)\n}\n\n/** A value as a warning quotes it; one JSON cannot write, such as a BigInt inside it, by its brackets. */\nfunction quoted(value: unknown): string {\n if (typeof value === 'string') return `\"${value}\"`\n if (typeof value !== 'object' || value === null) return String(value)\n try {\n return JSON.stringify(value)\n } catch {\n return Array.isArray(value) ? '[…]' : '{…}'\n }\n}\n\n/** A warning for each prop `props` sets that does not fit `schema`, naming the element. */\nexport function elementPropWarnings(\n schema: ElementPropsSchema,\n props: Readonly<Record<string, unknown>>,\n element: string\n): string[] {\n return Object.entries(schema.entries).flatMap(([key, entry]) => {\n const value = props[key]\n // A `designVar()` resolves to its value before the element reads it.\n if (value === undefined || isVariable(value)) return []\n const result = v.safeParse(entry, value)\n if (result.success) return []\n const [issue] = result.issues\n const source = `${key} ${quoted(value)} on <${element}> is ignored`\n // A reader of its own, such as an enum's, names what it takes.\n if (issue.kind === 'transformation') return [`Unknown ${source}; ${issue.message}.`]\n // A choice of kinds names them; a single type or bound is Valibot's to name.\n if (issue.type === 'union' || issue.type === 'custom')\n return [`Invalid ${source}; ${issue.message}.`]\n return [`Invalid ${source}; expected ${issue.expected}.`]\n })\n}\n\n/** A layer of the same JSX by name or `ref()`, or a point in the connector's parent. */\nconst connectorEndSchema = v.union(\n [v.string(), v.custom<LayerRef>(isLayerRef), v.object({ x: v.number(), y: v.number() })],\n 'expected a layer name, a ref(), or { x, y }'\n)\n\n/** The props `<Connector>` takes: its own, and the layer props that style its line. */\nexport const connectorPropsSchema = v.object({\n from: v.optional(connectorEndSchema),\n to: v.optional(connectorEndSchema),\n fromSide: v.optional(enumProp(CONNECTOR_SIDE)),\n toSide: v.optional(enumProp(CONNECTOR_SIDE)),\n line: v.optional(enumProp(CONNECTOR_LINE)),\n startCap: v.optional(enumProp(STROKE_CAP)),\n endCap: v.optional(enumProp(STROKE_CAP)),\n ...ownLayerPropsSchema.entries,\n stroke: v.optional(colorPropSchema),\n strokeWidth: v.optional(v.pipe(v.number(), v.gtValue(0))),\n dashPattern: v.optional(v.array(v.number()))\n})\n\nconst sizeSchema = v.pipe(v.number(), v.gtValue(0))\nconst dashSchema = v.array(v.number())\n\n/**\n * The layer props a shape has: its place, the size it is given, which it grows past to fit its\n * label, and its paint. The label is styled as FigJam styles it, and the shape lays it out.\n */\nexport const shapeLayerPropsSchema = v.object({\n ...placedOwnLayerPropsSchema.entries,\n w: v.optional(sizeSchema),\n h: v.optional(sizeSchema),\n rotate: v.optional(v.number()),\n rounded: v.optional(v.pipe(v.number(), v.minValue(0))),\n bg: v.optional(v.custom(isFillValue, 'expected a colour or a paint')),\n fills: v.optional(v.array(v.custom(isFillValue, 'expected a colour or a paint'))),\n stroke: v.optional(colorPropSchema),\n strokeWidth: v.optional(sizeSchema),\n strokeAlign: v.optional(enumProp(STROKE_ALIGN)),\n strokeDash: v.optional(dashSchema),\n strokes: v.optional(v.array(v.custom(isStrokeValue, 'expected a stroke'))),\n strokeCap: v.optional(enumProp(STROKE_CAP)),\n strokeJoin: v.optional(enumProp(STROKE_JOIN)),\n dashPattern: v.optional(dashSchema)\n})\n\n/**\n * The props `<Shape>` takes: its kind, whether it keeps its height and truncates its label as a\n * resized FigJam shape does, and the layer props a shape has.\n */\nexport const shapePropsSchema = v.object({\n kind: v.optional(enumProp(SHAPE_KIND)),\n truncate: v.optional(v.boolean()),\n textSize: v.optional(enumProp(FIGJAM_TEXT_SIZE)),\n typeface: v.optional(enumProp(FIGJAM_TYPEFACE)),\n ...shapeLayerPropsSchema.entries\n})\n\ntype StickyColorName = keyof typeof STICKY_COLORS\n\nfunction isStickyColorName(value: string): value is StickyColorName {\n return value in STICKY_COLORS\n}\n\n/** A palette name such as `\"yellow\"`, or any colour. */\nconst stickyColorSchema = v.pipe(\n v.string(),\n v.rawTransform(({ dataset, addIssue, NEVER }): Color => {\n const name = dataset.value\n if (isStickyColorName(name)) return { ...STICKY_COLORS[name] }\n const color = tryParseColor(name)\n if (color) return color\n addIssue({ message: `expected ${Object.keys(STICKY_COLORS).join(', ')}, or a colour` })\n return NEVER\n })\n)\n\n/** The props `<Sticky>` takes: its own, and the few layer props a note has. */\nexport const stickyPropsSchema = v.object({\n color: v.optional(stickyColorSchema),\n author: v.optional(v.string()),\n authorVisible: v.optional(v.boolean()),\n wide: v.optional(v.boolean()),\n textSize: v.optional(enumProp(FIGJAM_TEXT_SIZE)),\n typeface: v.optional(enumProp(FIGJAM_TYPEFACE)),\n scale: v.optional(v.pipe(v.number(), v.gtValue(0))),\n // A note takes the props that place it, but no size, fills, or layout.\n ...placedOwnLayerPropsSchema.entries\n})\n","import { compact } from 'es-toolkit/array'\nimport { isPlainObject } from 'es-toolkit/predicate'\nimport * as v from 'valibot'\n\nimport type {\n ComponentPropertyDefinition,\n ComponentPropertyReference,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport {\n applyComponentPropertyValue,\n componentPropertyDefinitions,\n createComponentPropertyId,\n exposableInstances,\n exposedInstances,\n instanceExposureIssue\n} from '@pairdraw/scene-graph/components'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport { DESIGN_JSX_SUPPORTED_PROPERTIES } from './definitions'\nimport { parseScriptInput } from './schema'\n\nconst PROPERTY_SYMBOL = Symbol.for('pairdraw.component-property')\n\n/**\n * A component property, by its name in the component that holds it. Where it is placed picks\n * its type: `text` on a text layer makes a TEXT property, `visible` a BOOLEAN one, and `of` on an\n * instance an INSTANCE_SWAP one, whose default is the component that `of` names.\n */\nexport interface ComponentProperty<T extends string | boolean = string | boolean> {\n readonly [PROPERTY_SYMBOL]: true\n readonly name: string\n readonly defaultValue: T\n}\n\nexport function isComponentProperty(value: unknown): value is ComponentProperty {\n return typeof value === 'object' && value !== null && PROPERTY_SYMBOL in value\n}\n\n/**\n * Bind a field to a property of the component it is drawn in, created on first use: on the\n * component set, for a variant, as Figma keeps them, or else on the component.\n */\nexport function property<T extends string | boolean>(\n name: string,\n defaultValue: T\n): ComponentProperty<T> {\n return Object.freeze({ [PROPERTY_SYMBOL]: true as const, name, defaultValue })\n}\n\n/** The prop each property type binds, and the field it binds there. */\nconst BOUND_PROPS = {\n text: { type: 'TEXT', field: 'TEXT', node: 'TEXT' },\n visible: { type: 'BOOLEAN', field: 'VISIBLE', node: undefined },\n of: { type: 'INSTANCE_SWAP', field: 'INSTANCE_SWAP', node: 'INSTANCE' }\n} as const satisfies Record<\n string,\n {\n type: ComponentPropertyDefinition['type']\n field: ComponentPropertyReference['field']\n node: SceneNode['type'] | undefined\n }\n>\n\n/** The component, or the set it is a variant of, that holds properties for layers under `parentId`. */\nfunction propertyOwner(graph: SceneGraph, parentId: string): SceneNode {\n let node = graph.getNode(parentId)\n while (node) {\n if (node.type === 'INSTANCE') throw new Error('property() cannot be used inside an instance')\n if (node.type === 'COMPONENT_SET') return node\n if (node.type === 'COMPONENT') {\n const set = node.parentId ? graph.getNode(node.parentId) : undefined\n return set?.type === 'COMPONENT_SET' ? set : node\n }\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n throw new Error('property() must be inside a <Component> or <ComponentSet>')\n}\n\n/** The ID of the property with this name on `owner`, added if it has none. */\nfunction ensureDefinition(\n graph: SceneGraph,\n owner: SceneNode,\n name: string,\n type: ComponentPropertyDefinition['type'],\n defaultValue: string\n): string {\n const existing = owner.componentPropertyDefinitions.find((item) => item.name === name)\n if (existing) {\n if (existing.type !== type)\n throw new Error(`Component property ${name} is ${existing.type}, not ${type}`)\n if (existing.defaultValue !== defaultValue)\n throw new Error(\n `Component property ${name} has two defaults: ${existing.defaultValue} and ${defaultValue}`\n )\n return existing.id\n }\n const id = createComponentPropertyId()\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [\n ...owner.componentPropertyDefinitions,\n { id, name, type, defaultValue }\n ]\n })\n return id\n}\n\nexport interface BoundProperties {\n /** The props, with each property in place of its default. */\n props: Record<string, unknown>\n references: ComponentPropertyReference[]\n}\n\n/**\n * Bind the fields a layer's props place a `property()` in, creating the properties on its\n * component; `componentId` gives the ID a swap's default component has.\n */\nexport function bindProperties(\n graph: SceneGraph,\n source: Record<string, unknown>,\n type: SceneNode['type'],\n parentId: string,\n componentId: ComponentLookup\n): BoundProperties {\n if (source.properties !== undefined && type !== 'INSTANCE')\n throw new Error('Only instances accept properties; bind a field to property() instead')\n const props = { ...source }\n const references: ComponentPropertyReference[] = []\n for (const [key, value] of Object.entries(source)) {\n if (!isComponentProperty(value)) continue\n if (!Object.hasOwn(BOUND_PROPS, key))\n throw new Error(`property() binds text, visible, or of, not ${key}`)\n const bound = BOUND_PROPS[key as keyof typeof BOUND_PROPS]\n if (bound.node && bound.node !== type)\n throw new Error(\n `property() in ${key} needs ${bound.node === 'TEXT' ? '<Text>' : '<Instance>'}`\n )\n const expected = bound.type === 'BOOLEAN' ? 'boolean' : 'string'\n if (typeof value.defaultValue !== expected)\n throw new Error(`Component property ${value.name} in ${key} takes a ${expected} default`)\n let defaultValue = String(value.defaultValue)\n if (bound.type === 'INSTANCE_SWAP') {\n const id = componentId(defaultValue)\n if (!id) throw new Error(`<Instance> component not found: ${defaultValue}`)\n defaultValue = id\n }\n const owner = propertyOwner(graph, parentId)\n const propertyId = ensureDefinition(graph, owner, value.name, bound.type, defaultValue)\n references.push({ propertyId, field: bound.field })\n props[key] = value.defaultValue\n }\n return { props, references }\n}\n\n/** Match the nearest component scope, including definitions inherited from its set. */\nfunction componentPropertyScope(\n graph: SceneGraph,\n parentId: string\n): readonly ComponentPropertyDefinition[] | undefined {\n let parent = graph.getNode(parentId)\n while (parent) {\n if (parent.type === 'INSTANCE') return componentPropertyDefinitions(graph, parent)\n if (parent.type === 'COMPONENT_SET') return parent.componentPropertyDefinitions\n if (parent.type === 'COMPONENT') {\n const set = parent.parentId ? graph.getNode(parent.parentId) : undefined\n return set?.type === 'COMPONENT_SET'\n ? [...set.componentPropertyDefinitions, ...parent.componentPropertyDefinitions]\n : parent.componentPropertyDefinitions\n }\n parent = parent.parentId ? graph.getNode(parent.parentId) : undefined\n }\n return undefined\n}\n\n/** The one property with this name; a name several properties share is an error. */\nfunction namedDefinition(\n definitions: readonly ComponentPropertyDefinition[],\n name: string\n): ComponentPropertyDefinition | undefined {\n const matches = definitions.filter((item) => item.name === name)\n if (matches.length > 1)\n throw new Error(\n `Component property name ${name} is ambiguous; use one of the IDs: ${matches.map((item) => item.id).join(', ')}`\n )\n return matches[0]\n}\n\n/** The ID of the component a name or ID names, as `<Instance of>` finds it. */\nexport type ComponentLookup = (nameOrId: string) => string | undefined\n\nfunction assignValue(\n graph: SceneGraph,\n instance: SceneNode,\n definition: ComponentPropertyDefinition,\n key: string,\n value: string,\n componentId: ComponentLookup\n): void {\n if (definition.type === 'VARIANT')\n throw new Error('Select a component-set variant when creating the instance')\n if (definition.type === 'BOOLEAN' && value !== 'true' && value !== 'false')\n throw new Error(`Expected true or false for component property: ${key}`)\n // A swap names its component as `of` does: by ID or by name.\n const assigned = definition.type === 'INSTANCE_SWAP' ? (componentId(value) ?? value) : value\n if (!applyComponentPropertyValue(graph, instance.id, definition, assigned))\n throw new Error(`Cannot assign component property: ${key}`)\n}\n\n/** A value an instance gives a property, or an exposed nested instance's values by name. */\nconst assignedValueSchema = v.union([v.string(), v.boolean(), v.number()])\nconst exposedValuesSchema = v.record(v.string(), assignedValueSchema)\n\n/** The one exposed nested instance with this name; a name several share is an error. */\nfunction exposedInstanceNamed(\n graph: SceneGraph,\n instance: SceneNode,\n name: string\n): SceneNode | undefined {\n const matches = exposedInstances(graph, instance).filter((node) => node.name === name)\n if (matches.length > 1)\n throw new Error(`Exposed instance name ${name} is shared by ${matches.length} layers`)\n return matches[0]\n}\n\n/**\n * Pick the variant of an exposed instance's set that has the values it names, keeping its own\n * for the rest, as its panel group does.\n */\nfunction selectNestedVariant(\n graph: SceneGraph,\n nested: SceneNode,\n name: string,\n values: Record<string, string>\n): void {\n if (Object.keys(values).length === 0) return\n const component = instanceMainComponent(graph, nested)\n const set = component?.parentId ? graph.getNode(component.parentId) : undefined\n if (!component || set?.type !== 'COMPONENT_SET') return\n const wanted = { ...component.componentPropertyValues, ...values }\n const variant = graph\n .getChildren(set.id)\n .find(\n (node) =>\n node.type === 'COMPONENT' &&\n Object.entries(wanted).every(([key, value]) => node.componentPropertyValues[key] === value)\n )\n if (!variant)\n throw new Error(\n `${name} has no variant ${Object.entries(values)\n .map(([key, value]) => `${key}=${value}`)\n .join(', ')}`\n )\n if (variant.id !== component.id) graph.swapInstanceComponent(nested.id, variant.id)\n}\n\n/**\n * Give the exposed nested instance named `name` its values: variants and properties by name,\n * the way the instance itself takes them.\n */\nfunction assignExposedInstance(\n graph: SceneGraph,\n instance: SceneNode,\n name: string,\n input: unknown,\n componentId: ComponentLookup\n): void {\n const nested = exposedInstanceNamed(graph, instance, name)\n if (!nested) throw new Error(`Unknown component property or exposed instance: ${name}`)\n const values = parseScriptInput(`Invalid values for ${name}`, exposedValuesSchema, input)\n const variantNames = new Set(\n componentPropertyDefinitions(graph, nested)\n .filter((definition) => definition.type === 'VARIANT')\n .map((definition) => definition.name)\n )\n const variants = Object.fromEntries(\n Object.entries(values)\n .filter(([key]) => variantNames.has(key))\n .map(([key, value]) => [key, String(value)])\n )\n selectNestedVariant(graph, nested, name, variants)\n const definitions = componentPropertyDefinitions(graph, nested)\n for (const [key, value] of Object.entries(values)) {\n if (variantNames.has(key)) continue\n const definition = namedDefinition(definitions, key)\n if (!definition) throw new Error(`Unknown component property on ${name}: ${key}`)\n assignValue(graph, nested, definition, key, String(value), componentId)\n }\n}\n\n/**\n * Set text, boolean, and swap properties an instance names as props, as in `Title=\"Hello\"`, the\n * way it picks a variant, and an exposed nested instance's values, as in `Action={{ Label: 'Save' }}`;\n * design JSX props keep their meaning.\n */\nexport function assignNamedProperties(\n graph: SceneGraph,\n instance: SceneNode,\n props: Record<string, unknown>,\n componentId: ComponentLookup\n): void {\n const definitions = componentPropertyDefinitions(graph, instance).filter(\n (definition) => definition.type !== 'VARIANT'\n )\n for (const [key, value] of Object.entries(props)) {\n if (DESIGN_JSX_SUPPORTED_PROPERTIES.has(key)) continue\n if (isPlainObject(value) && exposedInstanceNamed(graph, instance, key)) {\n assignExposedInstance(graph, instance, key, value, componentId)\n continue\n }\n const definition = namedDefinition(definitions, key)\n if (!definition) continue\n if (typeof value !== 'string' && typeof value !== 'boolean' && typeof value !== 'number')\n throw new Error(`Expected a string or boolean for component property: ${key}`)\n assignValue(graph, instance, definition, key, String(value), componentId)\n }\n}\n\n/**\n * Keys are property IDs or, because saving to `.fig` replaces authored IDs\n * with GUIDs, names, which survive a reload; an object gives an exposed nested instance its values.\n */\nexport function assignComponentProperties(\n graph: SceneGraph,\n instance: SceneNode,\n input: unknown,\n componentId: ComponentLookup\n): void {\n if (input === undefined) return\n const assignments = parseScriptInput(\n 'Invalid properties on <Instance>',\n v.record(v.string(), v.union([assignedValueSchema, exposedValuesSchema])),\n input\n )\n const definitions = componentPropertyDefinitions(graph, instance)\n for (const [key, value] of Object.entries(assignments)) {\n if (isPlainObject(value)) {\n assignExposedInstance(graph, instance, key, value, componentId)\n continue\n }\n const definition =\n definitions.find((item) => item.id === key) ?? namedDefinition(definitions, key)\n if (!definition) throw new Error(`Unknown component property: ${key}`)\n assignValue(graph, instance, definition, key, String(value), componentId)\n }\n}\n\n/** Mark an instance in a component's layers as exposed, under Figma's rules for exposing one. */\nexport function exposeInstance(graph: SceneGraph, instance: SceneNode): void {\n const issue = instanceExposureIssue(graph, instance)\n if (issue === 'not-in-component') throw new Error('exposed needs an <Instance> in a component')\n if (issue === 'not-primary')\n throw new Error('exposed needs an <Instance> in a component, not inside another instance')\n if (issue === 'nothing-to-expose')\n throw new Error(`${instance.name} has no properties or exposed instances to expose`)\n graph.updateNode(instance.id, { isExposedInstance: true })\n}\n\n/** The names an instance of `component` takes: its properties' and its exposed instances'. */\nexport function componentPropNames(graph: SceneGraph, component: SceneNode): string[] {\n return [\n ...(componentPropertyScope(graph, component.id) ?? []).map((definition) => definition.name),\n ...exposableInstances(graph, component.id)\n .filter((node) => node.isExposedInstance)\n .map((node) => node.name)\n ]\n}\n\nfunction parseVariantValues(name: string): Record<string, string> {\n const entries = compact(name.split(',').map((part) => part.trim()))\n const values: Record<string, string> = {}\n for (const entry of entries) {\n const [key = '', ...rest] = entry.split('=')\n const property = key.trim()\n const value = rest.join('=').trim()\n if (property && value) values[property] = value\n }\n return values\n}\n\n/** Variant properties a component set takes from its variants' names, such as `State=On`. */\nexport function inferComponentSetProperties(graph: SceneGraph, componentSetId: string): void {\n const componentSet = graph.getNode(componentSetId)\n if (componentSet?.type !== 'COMPONENT_SET') return\n const existingDefinitions = componentSet.componentPropertyDefinitions\n\n const variants = graph.getChildren(componentSetId).filter((node) => node.type === 'COMPONENT')\n const options = new Map<string, Set<string>>()\n const valuesById = new Map<string, Record<string, string>>()\n\n for (const variant of variants) {\n const values = parseVariantValues(variant.name)\n valuesById.set(variant.id, values)\n for (const [property, value] of Object.entries(values)) {\n let set = options.get(property)\n if (!set) {\n set = new Set()\n options.set(property, set)\n }\n set.add(value)\n }\n }\n\n const definitions: ComponentPropertyDefinition[] = [...options.entries()]\n .filter(\n ([name]) =>\n !existingDefinitions.some(\n (definition) => definition.type === 'VARIANT' && definition.name === name\n )\n )\n .map(([name, values]) => {\n const variantOptions = [...values]\n return {\n id: createComponentPropertyId(),\n name,\n type: 'VARIANT',\n defaultValue: variantOptions[0] ?? '',\n variantOptions\n }\n })\n\n for (const [id, values] of valuesById) {\n graph.updateNode(id, { componentPropertyValues: values })\n }\n graph.updateNode(componentSetId, {\n componentPropertyDefinitions: [...existingDefinitions, ...definitions]\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,SAAS,QACP,WACA,UAAuC,CAAC,GAC5B;CACZ,MAAM,UAAU,OAAO,QAAQ,SAAS;CACxC,MAAM,SAAS,IAAI,IACjB,CAAC,GAAG,QAAQ,KAAK,CAAC,OAAO,UAAuB,CAAC,MAAM,KAAK,CAAC,GAAG,GAAG,OAAO,QAAQ,OAAO,CAAC,CAAC,CAAC,KACzF,CAAC,MAAM,WAAwB,CAAC,KAAK,YAAY,GAAG,KAAK,CAC5D,CACF;CACA,OAAO;EACL,QAAQ,UAAW,OAAO,UAAU,WAAW,OAAO,IAAI,MAAM,YAAY,CAAC,IAAI,KAAA;EACjF,QAAQ,UAAU,UAAU;EAC5B,OAAO,CAAC,GAAG,QAAQ,KAAK,GAAG,UAAU,IAAI,GAAG,GAAG,OAAO,KAAK,OAAO,CAAC;CACrE;AACF;;AAGA,SAAgB,SAA2B,QAAoB;CAC7D,OAAO,EAAE,KACP,EAAE,OAAO,GACT,EAAE,cAAc,EA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AAU,IAAI,IAAyB;CAC7C,MAAM,6BAAa,IAAI,IAAoC;CAE3D,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,SAAS,mBAAmB,QAAQ,IAAI;EAC9C,WAAW,IAAI,QAAQ,IAAI,MAAM;EACjC,KAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,MAAM,GAAG;GACtD,IAAI,MAAM,QAAQ,IAAI,QAAQ;GAC9B,IAAI,CAAC,KAAK;IACR,sBAAM,IAAI,IAAI;IACd,QAAQ,IAAI,UAAU,GAAG;GAC3B;GACA,IAAI,IAAI,KAAK;EACf;CACF;CAEA,MAAM,cAA6C,CAAC,GAAG,QAAQ,QAAQ,CAAC,CAAC,CACtE,QACE,CAAC,UACA,CAAC,oBAAoB,MAClB,eAAe,WAAW,SAAS,aAAa,WAAW,SAAS,IACvE,CACJ,CAAC,CACA,KAAK,CAAC,MAAM,YAAY;EACvB,MAAM,iBAAiB,CAAC,GAAG,MAAM;EACjC,OAAO;GACL,IAAI,0BAA0B;GAC9B;GACA,MAAM;GACN,cAAc,eAAe,MAAM;GACnC;EACF;CACF,CAAC;CAEH,KAAK,MAAM,CAAC,IAAI,WAAW,YACzB,MAAM,WAAW,IAAI,EAAE,yBAAyB,OAAO,CAAC;CAE1D,MAAM,WAAW,gBAAgB,EAC/B,8BAA8B,CAAC,GAAG,qBAAqB,GAAG,WAAW,EACvE,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"component-properties.js","names":["isColor","isColor"],"sources":["../../src/enums.ts","../../src/overrides/fills.ts","../../src/overrides/strokes.ts","../../src/refs.ts","../../src/variables/index.ts","../../src/schema.ts","../../src/component-properties.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type {\n BlendMode,\n ConnectorLineType,\n ConnectorMagnet,\n ConstraintType,\n MaskType,\n SceneNode,\n Stroke,\n StrokeCap,\n StrokeJoin,\n TextAutoResize,\n TextCase,\n TextDecoration,\n TextDecorationStyle,\n TextDirection\n} from '@pairdraw/scene-graph'\nimport type { FigJamTextSize, FigJamTypeface } from '@pairdraw/scene-graph/figjam'\nimport {\n SHAPE_WITH_TEXT_TYPES,\n type ShapeWithTextType\n} from '@pairdraw/scene-graph/shape-with-text'\n\n/**\n * A Figma enum as design JSX spells it. Reading and writing come from one table, so whatever the\n * export writes reads back, and a value the table does not know is reported instead of reaching\n * the document.\n */\nexport interface JSXEnum<T extends string> {\n /** The value a spelling names, read case-insensitively, or undefined for none. */\n parse(value: unknown): T | undefined\n /** How the export spells a value. */\n print(value: T): string\n /** Every spelling it reads, aliases included. */\n readonly names: readonly string[]\n}\n\n/**\n * `spellings` names every value of the enum, which the type checks, and is what the export writes;\n * `aliases` are further spellings it only reads.\n */\nfunction jsxEnum<T extends string>(\n spellings: Readonly<Record<T, string>>,\n aliases: Readonly<Record<string, T>> = {}\n): JSXEnum<T> {\n const entries = Object.entries(spellings) as [T, string][]\n const byName = new Map<string, T>(\n [...entries.map(([value, name]): [string, T] => [name, value]), ...Object.entries(aliases)].map(\n ([name, value]): [string, T] => [name.toLowerCase(), value]\n )\n )\n return {\n parse: (value) => (typeof value === 'string' ? byName.get(value.toLowerCase()) : undefined),\n print: (value) => spellings[value],\n names: [...entries.map(([, name]) => name), ...Object.keys(aliases)]\n }\n}\n\n/** A prop that takes one of the enum's spellings, read as the value it names. */\nexport function enumProp<T extends string>(values: JSXEnum<T>) {\n return v.pipe(\n v.string(),\n v.rawTransform(({ dataset, addIssue, NEVER }) => {\n const value = values.parse(dataset.value)\n if (value !== undefined) return value\n addIssue({ message: `expected ${values.names.join(', ')}` })\n return NEVER\n })\n )\n}\n\n/** An enum spelled by each value's lowercase name, as most of design JSX's enums are. */\nfunction lowercaseEnum<T extends string>(\n values: readonly T[],\n aliases: Readonly<Record<string, T>> = {}\n): JSXEnum<T> {\n const spellings = Object.fromEntries(values.map((value) => [value, value.toLowerCase()]))\n return jsxEnum(spellings as Record<T, string>, aliases)\n}\n\nexport const STROKE_CAP = lowercaseEnum<StrokeCap>([\n 'NONE',\n 'ROUND',\n 'SQUARE',\n 'ARROW_LINES',\n 'ARROW_EQUILATERAL',\n 'TRIANGLE_FILLED',\n 'DIAMOND_FILLED',\n 'CIRCLE_FILLED'\n])\nexport const STROKE_JOIN = lowercaseEnum<StrokeJoin>(['MITER', 'BEVEL', 'ROUND'])\nexport const STROKE_ALIGN = lowercaseEnum<Stroke['align']>(['INSIDE', 'CENTER', 'OUTSIDE'])\nexport const CONSTRAINT = lowercaseEnum<ConstraintType>([\n 'MIN',\n 'CENTER',\n 'MAX',\n 'STRETCH',\n 'SCALE'\n])\nexport const MASK_TYPE = lowercaseEnum<MaskType>(['ALPHA', 'LUMINANCE', 'VECTOR'])\nexport const BLEND_MODE = lowercaseEnum<BlendMode>([\n 'NORMAL',\n 'DARKEN',\n 'MULTIPLY',\n 'LINEAR_BURN',\n 'COLOR_BURN',\n 'LIGHTEN',\n 'SCREEN',\n 'LINEAR_DODGE',\n 'COLOR_DODGE',\n 'OVERLAY',\n 'SOFT_LIGHT',\n 'HARD_LIGHT',\n 'DIFFERENCE',\n 'EXCLUSION',\n 'HUE',\n 'SATURATION',\n 'COLOR',\n 'LUMINOSITY',\n 'PASS_THROUGH'\n])\nexport const TEXT_ALIGN = lowercaseEnum<SceneNode['textAlignHorizontal']>(\n ['LEFT', 'CENTER', 'RIGHT', 'JUSTIFIED'],\n { left_align: 'LEFT', center_align: 'CENTER', right_align: 'RIGHT' }\n)\nexport const TEXT_ALIGN_VERTICAL = lowercaseEnum<SceneNode['textAlignVertical']>([\n 'TOP',\n 'CENTER',\n 'BOTTOM'\n])\nexport const TEXT_AUTO_RESIZE = jsxEnum<TextAutoResize>({\n NONE: 'none',\n WIDTH_AND_HEIGHT: 'width',\n HEIGHT: 'height',\n TRUNCATE: 'truncate'\n})\nexport const TEXT_DIRECTION = lowercaseEnum<TextDirection>(['AUTO', 'LTR', 'RTL'])\nexport const TEXT_DECORATION = lowercaseEnum<TextDecoration>(['NONE', 'UNDERLINE', 'STRIKETHROUGH'])\nexport const TEXT_DECORATION_STYLE = lowercaseEnum<TextDecorationStyle>(['SOLID', 'DOTTED', 'WAVY'])\nexport const TEXT_CASE = lowercaseEnum<TextCase>(['ORIGINAL', 'UPPER', 'LOWER', 'TITLE'])\n\nexport const FIGJAM_TEXT_SIZE = jsxEnum<FigJamTextSize>({\n small: 'small',\n medium: 'medium',\n large: 'large',\n extraLarge: 'extraLarge',\n huge: 'huge'\n})\n/** FigJam's typefaces, as its text menus name them. */\nexport const FIGJAM_TYPEFACE = jsxEnum<FigJamTypeface>({\n simple: 'simple',\n bookish: 'bookish',\n technical: 'technical',\n scribbled: 'scribbled'\n})\n/** The kinds a `<Shape>` draws, as FigJam names them: `rounded_rectangle`, `eng_database`. */\nexport const SHAPE_KIND = lowercaseEnum<ShapeWithTextType>(SHAPE_WITH_TEXT_TYPES)\nexport const CONNECTOR_LINE = lowercaseEnum<ConnectorLineType>(['ELBOWED', 'STRAIGHT', 'CURVED'])\n/** The sides a `<Connector>` end attaches by; the other magnets come only from files. */\nexport const CONNECTOR_SIDE = lowercaseEnum<\n Extract<ConnectorMagnet, 'AUTO' | 'TOP' | 'RIGHT' | 'BOTTOM' | 'LEFT' | 'CENTER'>\n>(['AUTO', 'TOP', 'RIGHT', 'BOTTOM', 'LEFT', 'CENTER'])\n\n/**\n * The layer props whose values are one of an enum's spellings, for checking what JSX passes. An\n * element with a props schema, such as `<Connector>`, checks its enums by `enumProp` instead.\n */\nexport const ENUM_PROPS: Readonly<Partial<Record<string, JSXEnum<string>>>> = {\n strokeCap: STROKE_CAP,\n strokeJoin: STROKE_JOIN,\n strokeAlign: STROKE_ALIGN,\n mask: MASK_TYPE,\n blendMode: BLEND_MODE,\n textAlign: TEXT_ALIGN,\n textAlignVertical: TEXT_ALIGN_VERTICAL,\n textAutoResize: TEXT_AUTO_RESIZE,\n dir: TEXT_DIRECTION,\n textDecoration: TEXT_DECORATION,\n textDecorationStyle: TEXT_DECORATION_STYLE,\n textCase: TEXT_CASE\n}\n","import * as v from 'valibot'\n\nimport type { DocumentColorSpace, Fill, GradientTransform } from '@pairdraw/scene-graph'\nimport { colorToFill } from '@pairdraw/scene-graph/color'\nimport { paintTransformSchema } from '@pairdraw/scene-graph/paints'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nexport function isColor(value: unknown): value is Color {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'r' in value &&\n 'g' in value &&\n 'b' in value &&\n 'a' in value\n )\n}\n\nfunction isFill(value: unknown): value is Fill {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'type' in value &&\n 'color' in value &&\n 'visible' in value\n )\n}\n\n/** A paint as props write it: a colour string, a colour, or a paint from a helper. */\nexport function isFillValue(value: unknown): value is string | Color | Fill {\n return typeof value === 'string' || isColor(value) || isFill(value)\n}\n\nconst TRANSFORM_FIELDS = ['gradientTransform', 'imageTransform'] as const\n\n/** Worded as `parseScriptInput` words it; that lives in `schema.ts`, which imports this module. */\nfunction parseTransform(\n field: (typeof TRANSFORM_FIELDS)[number],\n value: unknown\n): GradientTransform {\n const result = v.safeParse(paintTransformSchema, value)\n if (result.success) return result.output\n throw new Error(\n `A paint's ${field} expects Figma's [[a, b, c], [d, e, f]] or { m00, m01, m02, m10, m11, m12 }:\\n${v.summarize(result.issues)}`\n )\n}\n\nexport function fillFromValue(\n value: string | Color | Fill,\n profile: DocumentColorSpace = 'srgb'\n): Fill {\n if (!isFill(value)) return colorToFill(value, profile)\n const fill = structuredClone(value)\n // A paint written as an object, as export writes an image, gives its transforms as Figma's rows.\n for (const field of TRANSFORM_FIELDS) {\n if (fill[field] !== undefined) fill[field] = parseTransform(field, fill[field])\n }\n return fill\n}\n","import { designJSXProp } from '#design-jsx/definitions'\nimport { STROKE_ALIGN, STROKE_CAP, STROKE_JOIN } from '#design-jsx/enums'\n\nimport type { DocumentColorSpace, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { parseColor } from '@pairdraw/scene-graph/color'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { LayerProps } from '../schema'\n\n/** One entry of the `strokes` prop; enums are lowercase, as `blendMode` is. */\nexport interface StrokeValue {\n color: string | Color\n /** Defaults to the colour's alpha. */\n opacity?: number\n weight?: number\n align?: string\n dash?: number[]\n cap?: string\n join?: string\n visible?: boolean\n}\n\nfunction isColor(value: unknown): value is Color {\n return value !== null && typeof value === 'object' && 'r' in value && 'a' in value\n}\n\nexport function isStrokeValue(value: unknown): value is StrokeValue {\n if (value === null || typeof value !== 'object' || !('color' in value)) return false\n return typeof value.color === 'string' || isColor(value.color)\n}\n\nfunction dashValue(value: unknown): number[] | undefined {\n if (!Array.isArray(value)) return undefined\n const dash = value.filter((item): item is number => typeof item === 'number')\n return dash.length > 0 ? dash : undefined\n}\n\nfunction toStroke(value: StrokeValue, profile: DocumentColorSpace): Stroke {\n const color = typeof value.color === 'string' ? parseColor(value.color, profile) : value.color\n const stroke: Stroke = {\n type: 'SOLID',\n color,\n opacity: typeof value.opacity === 'number' ? value.opacity : color.a,\n visible: value.visible ?? true,\n weight: value.weight ?? 1,\n align: STROKE_ALIGN.parse(value.align) ?? 'INSIDE'\n }\n const dash = dashValue(value.dash)\n if (dash) stroke.dashPattern = dash\n const cap = STROKE_CAP.parse(value.cap)\n if (cap) stroke.cap = cap\n const join = STROKE_JOIN.parse(value.join)\n if (join) stroke.join = join\n return stroke\n}\n\n/** `strokeWeights` names each side; a side it leaves out has no stroke. */\ninterface StrokeWeights {\n top?: unknown\n right?: unknown\n bottom?: unknown\n left?: unknown\n}\n\nfunction isStrokeWeights(value: unknown): value is StrokeWeights {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction sideWeight(value: unknown): number {\n return typeof value === 'number' ? value : 0\n}\n\nfunction applyStrokeWeights(value: unknown, o: Partial<SceneNode>): void {\n if (!isStrokeWeights(value)) return\n o.independentStrokeWeights = true\n o.borderTopWeight = sideWeight(value.top)\n o.borderRightWeight = sideWeight(value.right)\n o.borderBottomWeight = sideWeight(value.bottom)\n o.borderLeftWeight = sideWeight(value.left)\n}\n\n/** `strokes` takes structured strokes; `stroke` and its sibling props describe a single one. */\nexport function applyStrokeOverrides(\n props: LayerProps,\n o: Partial<SceneNode>,\n profile: DocumentColorSpace = 'srgb'\n): void {\n applyStrokeWeights(props.strokeWeights, o)\n // Node-level cap and join, which strokes without their own use.\n const nodeCap = STROKE_CAP.parse(props.strokeCap)\n if (nodeCap) o.strokeCap = nodeCap\n const nodeJoin = STROKE_JOIN.parse(props.strokeJoin)\n if (nodeJoin) o.strokeJoin = nodeJoin\n // The node's dash, which strokes without their own dash take, as strokes take its cap and join.\n const nodeDash = dashValue(props.dashPattern)\n if (nodeDash) o.dashPattern = nodeDash\n const strokes = strokeValues(props).map((value) =>\n toStroke({ ...value, dash: value.dash ?? nodeDash }, profile)\n )\n if (strokes.length > 0) o.strokes = strokes\n}\n\n/** The strokes `strokes` lists, or the one `stroke` and its sibling props describe. */\nfunction strokeValues(props: Record<string, unknown>): StrokeValue[] {\n if (Array.isArray(props.strokes)) return props.strokes.filter(isStrokeValue)\n const color = designJSXProp(props, 'stroke')\n if (typeof color !== 'string' && !isColor(color)) return []\n return [\n {\n color,\n weight:\n (props.strokeWidth as number | undefined) ?? (props.borderWidth as number | undefined),\n align: props.strokeAlign as string | undefined,\n dash: props.strokeDash as number[] | undefined\n }\n ]\n}\n","import type { SceneNode } from '@pairdraw/scene-graph'\n\nconst REF_SYMBOL = Symbol.for('pairdraw.layer-ref')\n\n/**\n * A handle on one layer of the JSX: `ref={card}` marks the layer, and an element that refers to\n * a layer, such as `<Connector from={card}>`, takes the handle where a name could be ambiguous.\n */\nexport interface LayerRef {\n readonly [REF_SYMBOL]: true\n}\n\n/** A new handle for `ref={…}` to mark a layer with. */\nexport function ref(): LayerRef {\n return Object.freeze({ [REF_SYMBOL]: true as const })\n}\n\nexport function isLayerRef(value: unknown): value is LayerRef {\n return typeof value === 'object' && value !== null && REF_SYMBOL in value\n}\n\n/** The layers a render marked with `ref={…}`, for the elements that refer to them. */\nexport class LayerRefs {\n readonly warnings: string[] = []\n private readonly layers = new Map<LayerRef, SceneNode>()\n\n /** Marks `node` with the `ref` prop its element passed, if any. */\n mark(value: unknown, node: SceneNode) {\n if (value === undefined) return\n if (!isLayerRef(value)) {\n this.warnings.push(`ref on \"${node.name}\" is not a ref() and is ignored.`)\n return\n }\n const first = this.layers.get(value)\n if (first) {\n this.warnings.push(\n `One ref() marks both \"${first.name}\" and \"${node.name}\"; it refers to \"${first.name}\".`\n )\n return\n }\n this.layers.set(value, node)\n }\n\n /** The id of the layer `ref` marks, if one does. */\n layerOf(ref: LayerRef): string | undefined {\n return this.layers.get(ref)?.id\n }\n}\n","import { isPlainObject } from 'es-toolkit/predicate'\n\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nconst VAR_SYMBOL = Symbol.for('pairdraw.variable')\nconst MODE_SYMBOL = Symbol.for('pairdraw.variable-mode')\n\n/** The name a collection's first mode has when `defineVars` names none, as Figma names it. */\nexport const DEFAULT_MODE_NAME = 'Mode 1'\n\n/**\n * A value a variable holds in one mode: a color as a string or a `Color`, a number, a boolean,\n * or another variable, which makes it an alias.\n */\nexport type VariableInput = string | Color | number | boolean | DesignVariable\n\n/** A collection as `defineVars` and `defineMode` declare it; the first mode is the default. */\nexport interface CollectionDefinition {\n name: string\n modes: Array<{ name: string; values: Record<string, VariableInput> }>\n}\n\n/**\n * A variable a field binds to. `defineVars` gives one its collection, which a render creates or\n * updates; `designVar` names a variable the document already has, and may name its collection.\n */\nexport interface DesignVariable {\n readonly [VAR_SYMBOL]: true\n /** The variable's name, or for `designVar` without a collection, its name or ID. */\n readonly name: string\n readonly collection?: CollectionDefinition | string\n}\n\n/**\n * A mode a layer shows a collection in. `defineMode` gives it the collection it declares;\n * `designMode` names a collection the document already has.\n */\nexport interface DesignMode {\n readonly [MODE_SYMBOL]: true\n readonly name: string\n readonly collection: CollectionDefinition | string\n}\n\nexport function isVariable(value: unknown): value is DesignVariable {\n return typeof value === 'object' && value !== null && VAR_SYMBOL in value\n}\n\nexport function isMode(value: unknown): value is DesignMode {\n return typeof value === 'object' && value !== null && MODE_SYMBOL in value\n}\n\n/** Whether a value can be a variable's value: a color, a number, a boolean, or a variable. */\nexport function isVariableInput(value: unknown): value is VariableInput {\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')\n return true\n if (isVariable(value)) return true\n return isPlainObject(value) && ['r', 'g', 'b', 'a'].every((key) => typeof value[key] === 'number')\n}\n\n/**\n * A variable the document already has: by its name or ID, or by the names of its collection and\n * itself, as `designMode` names a mode, for a name more than one collection has.\n */\nexport function designVar(idOrName: string): DesignVariable\nexport function designVar(collection: string, name: string): DesignVariable\nexport function designVar(first: string, second?: string): DesignVariable {\n return Object.freeze(\n second === undefined\n ? { [VAR_SYMBOL]: true as const, name: first }\n : { [VAR_SYMBOL]: true as const, name: second, collection: first }\n )\n}\n\n/**\n * Define a variable collection: its variables, by name, with their values in its first mode,\n * named `mode` (Figma's `Mode 1` by default). A render that binds any of them creates the\n * collection, or updates the one with that name, so running the JSX again changes nothing twice.\n */\nexport function defineVars<T extends Record<string, VariableInput>>(\n collection: string,\n values: T,\n options: { mode?: string } = {}\n): { [K in keyof T]: DesignVariable } {\n const definition: CollectionDefinition = {\n name: collection,\n modes: [{ name: options.mode ?? DEFAULT_MODE_NAME, values }]\n }\n const handles = {} as { [K in keyof T]: DesignVariable }\n for (const name of Object.keys(values) as Array<keyof T & string>) {\n handles[name] = Object.freeze({ [VAR_SYMBOL]: true as const, name, collection: definition })\n }\n return handles\n}\n\n/**\n * Add a mode to a collection `defineVars` defined, with the values that differ from its first\n * mode; the rest keep the first mode's values, as a mode Figma adds copies them.\n */\nexport function defineMode(\n vars: Record<string, DesignVariable>,\n name: string,\n values: Record<string, VariableInput>\n): DesignMode {\n const definition = Object.values(vars)[0]?.collection\n if (!definition || typeof definition === 'string')\n throw new Error('defineMode() takes the variables defineVars() returned')\n if (definition.modes.some((mode) => mode.name === name))\n throw new Error(`Collection ${definition.name} already has a mode named ${name}`)\n const known = definition.modes[0].values\n for (const key of Object.keys(values)) {\n if (!Object.hasOwn(known, key))\n throw new Error(`Collection ${definition.name} has no variable named ${key}`)\n }\n definition.modes.push({ name, values })\n return Object.freeze({ [MODE_SYMBOL]: true as const, name, collection: definition })\n}\n\n/**\n * A mode of a collection the document already has, by their names, or by the collection's ID\n * when several collections share its name.\n */\nexport function designMode(collection: string, mode: string): DesignMode {\n return Object.freeze({ [MODE_SYMBOL]: true as const, name: mode, collection })\n}\n","import { mapValues } from 'es-toolkit/object'\nimport * as v from 'valibot'\n\nimport { tryParseColor } from '@pairdraw/scene-graph/color'\nimport { STICKY_COLORS } from '@pairdraw/scene-graph/generated'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport {\n CONNECTOR_LINE,\n CONNECTOR_SIDE,\n enumProp,\n FIGJAM_TEXT_SIZE,\n FIGJAM_TYPEFACE,\n SHAPE_KIND,\n STROKE_ALIGN,\n STROKE_CAP,\n STROKE_JOIN\n} from './enums'\nimport { isColor, isFillValue } from './overrides/fills'\nimport { isStrokeValue } from './overrides/strokes'\nimport { isLayerRef, type LayerRef } from './refs'\nimport { isVariable } from './variables'\n\n/**\n * Parse a value a design JSX script passed, or throw `heading` followed by every problem and\n * where it is, as `v.summarize` lists them. Core words tool arguments the same way.\n */\nexport function parseScriptInput<S extends v.GenericSchema>(\n heading: string,\n schema: S,\n value: unknown\n): v.InferOutput<S> {\n const result = v.safeParse(schema, value)\n if (result.success) return result.output\n throw new Error(`${heading}:\\n${v.summarize(result.issues)}`)\n}\n\n/**\n * The layer props an element that draws its own layer takes, such as a connector's: the\n * renderer makes them into fields and variable bindings as it does for any layer.\n */\nexport const ownLayerPropsSchema = v.object({\n name: v.optional(v.string()),\n key: v.optional(v.unknown()),\n visible: v.optional(v.boolean()),\n opacity: v.optional(v.number())\n})\n\n/** `OwnLayerProps` and the props that place a layer in its parent, such as a sticky note's. */\nexport const placedOwnLayerPropsSchema = v.object({\n ...ownLayerPropsSchema.entries,\n x: v.optional(v.number()),\n y: v.optional(v.number()),\n position: v.optional(v.picklist(['absolute']))\n})\n\nconst finiteNumberSchema = v.pipe(v.number(), v.finite())\n\n/** A length that cannot be negative, such as a size, radius, or stroke weight. */\nconst layoutLengthSchema = v.pipe(\n finiteNumberSchema,\n v.transform((length) => Math.min(1_000_000, Math.max(0, length)))\n)\n\n/** A share from none to all, such as how much a corner is smoothed. */\nconst shareSchema = v.pipe(\n finiteNumberSchema,\n v.transform((share) => Math.min(1, Math.max(0, share)))\n)\n\n/**\n * The layer props every element reads by the same reader, under each name it is written by. A\n * value of the wrong kind is reported and left out, so it never reaches a layer's fields; one out\n * of range is bounded, as a bound variable's value is.\n */\nexport const layerPropsSchema = v.object({\n name: v.optional(v.string()),\n // An artwork's layer name, since its `name` names the icon.\n label: v.optional(v.string()),\n opacity: v.optional(finiteNumberSchema),\n rotate: v.optional(finiteNumberSchema),\n rotation: v.optional(finiteNumberSchema),\n rounded: v.optional(layoutLengthSchema),\n cornerRadius: v.optional(layoutLengthSchema),\n borderRadius: v.optional(layoutLengthSchema),\n roundedTL: v.optional(layoutLengthSchema),\n roundedTR: v.optional(layoutLengthSchema),\n roundedBL: v.optional(layoutLengthSchema),\n roundedBR: v.optional(layoutLengthSchema),\n cornerSmoothing: v.optional(shareSchema),\n strokeWidth: v.optional(layoutLengthSchema),\n borderWidth: v.optional(layoutLengthSchema),\n maxLines: v.optional(v.pipe(v.number(), v.integer('expected a whole number'), v.minValue(1)))\n})\n\n/** An element's props with the layer props read by `layerPropsSchema`. */\nexport type LayerProps = Record<string, unknown> & v.InferOutput<typeof layerPropsSchema>\n\n/**\n * The layer props an inline `<svg>` reads itself. Its other props, such as `strokeWidth=\"2\"`,\n * are attributes of its markup's root, which the SVG service reads as SVG does.\n */\nexport const svgLayerPropsSchema = v.pick(layerPropsSchema, ['label'])\n\n/** `props` with each prop `schema` takes read by it, and every other prop as it is. */\nexport function readKnownProps<S extends ElementPropsSchema>(\n schema: S,\n props: Readonly<Record<string, unknown>>\n): Record<string, unknown> & v.InferOutput<S> {\n const read: Record<string, unknown> = { ...props }\n for (const [key, entry] of Object.entries(schema.entries)) {\n if (props[key] === undefined) continue\n const parsed = v.safeParse(entry, props[key])\n read[key] = parsed.success ? parsed.output : undefined\n }\n return read\n}\n\n/** `props` with its layer props read by `layerPropsSchema`, as every element reads them. */\nexport function readLayerProps(props: Readonly<Record<string, unknown>>): LayerProps {\n return readKnownProps(layerPropsSchema, props)\n}\n\n/** A colour as a string, or as the colour a `designVar()` resolves to. */\nconst colorPropSchema = v.union(\n [\n v.pipe(\n v.string(),\n v.rawTransform(({ dataset, addIssue, NEVER }): Color => {\n const color = tryParseColor(dataset.value)\n if (color) return color\n addIssue({ message: 'expected a colour' })\n return NEVER\n })\n ),\n v.custom<Color>(isColor)\n ],\n 'expected a colour'\n)\n\n/** The props of an element read one at a time, each of them optional. */\nexport type ElementPropsSchema = v.ObjectSchema<v.ObjectEntries, undefined>\n\n/**\n * The props `schema` takes, read from `props`: one that does not fit is left out as if it were\n * not set, since the renderer reports it (`elementPropWarnings`) and goes on.\n */\nexport function readElementProps<S extends ElementPropsSchema>(\n schema: S,\n props: Readonly<Record<string, unknown>>\n): v.InferOutput<S> {\n const fitting = mapValues(schema.entries, (entry, key) =>\n v.is(entry, props[key]) ? props[key] : undefined\n )\n return v.parse(schema, fitting)\n}\n\n/** A value as a warning quotes it; one JSON cannot write, such as a BigInt inside it, by its brackets. */\nfunction quoted(value: unknown): string {\n if (typeof value === 'string') return `\"${value}\"`\n if (typeof value !== 'object' || value === null) return String(value)\n try {\n return JSON.stringify(value)\n } catch {\n return Array.isArray(value) ? '[…]' : '{…}'\n }\n}\n\n/** A warning for each prop `props` sets that does not fit `schema`, naming the element. */\nexport function elementPropWarnings(\n schema: ElementPropsSchema,\n props: Readonly<Record<string, unknown>>,\n element: string\n): string[] {\n return Object.entries(schema.entries).flatMap(([key, entry]) => {\n const value = props[key]\n // A `designVar()` resolves to its value before the element reads it.\n if (value === undefined || isVariable(value)) return []\n const result = v.safeParse(entry, value)\n if (result.success) return []\n const [issue] = result.issues\n const source = `${key} ${quoted(value)} on <${element}> is ignored`\n // A reader of its own, such as an enum's, names what it takes.\n if (issue.kind === 'transformation') return [`Unknown ${source}; ${issue.message}.`]\n // A choice of kinds names them; a single type or bound is Valibot's to name.\n if (issue.type === 'union' || issue.type === 'custom')\n return [`Invalid ${source}; ${issue.message}.`]\n return [`Invalid ${source}; expected ${issue.expected}.`]\n })\n}\n\n/** A layer of the same JSX by name or `ref()`, or a point in the connector's parent. */\nconst connectorEndSchema = v.union(\n [v.string(), v.custom<LayerRef>(isLayerRef), v.object({ x: v.number(), y: v.number() })],\n 'expected a layer name, a ref(), or { x, y }'\n)\n\n/** The props `<Connector>` takes: its own, and the layer props that style its line. */\nexport const connectorPropsSchema = v.object({\n from: v.optional(connectorEndSchema),\n to: v.optional(connectorEndSchema),\n fromSide: v.optional(enumProp(CONNECTOR_SIDE)),\n toSide: v.optional(enumProp(CONNECTOR_SIDE)),\n line: v.optional(enumProp(CONNECTOR_LINE)),\n startCap: v.optional(enumProp(STROKE_CAP)),\n endCap: v.optional(enumProp(STROKE_CAP)),\n ...ownLayerPropsSchema.entries,\n stroke: v.optional(colorPropSchema),\n strokeWidth: v.optional(v.pipe(v.number(), v.gtValue(0))),\n dashPattern: v.optional(v.array(v.number()))\n})\n\nconst sizeSchema = v.pipe(v.number(), v.gtValue(0))\nconst dashSchema = v.array(v.number())\n\n/**\n * The layer props a shape has: its place, the size it is given, which it grows past to fit its\n * label, and its paint. The label is styled as FigJam styles it, and the shape lays it out.\n */\nexport const shapeLayerPropsSchema = v.object({\n ...placedOwnLayerPropsSchema.entries,\n w: v.optional(sizeSchema),\n h: v.optional(sizeSchema),\n rotate: v.optional(v.number()),\n rounded: v.optional(v.pipe(v.number(), v.minValue(0))),\n bg: v.optional(v.custom(isFillValue, 'expected a colour or a paint')),\n fills: v.optional(v.array(v.custom(isFillValue, 'expected a colour or a paint'))),\n stroke: v.optional(colorPropSchema),\n strokeWidth: v.optional(sizeSchema),\n strokeAlign: v.optional(enumProp(STROKE_ALIGN)),\n strokeDash: v.optional(dashSchema),\n strokes: v.optional(v.array(v.custom(isStrokeValue, 'expected a stroke'))),\n strokeCap: v.optional(enumProp(STROKE_CAP)),\n strokeJoin: v.optional(enumProp(STROKE_JOIN)),\n dashPattern: v.optional(dashSchema)\n})\n\n/**\n * The props `<Shape>` takes: its kind, whether it keeps its height and truncates its label as a\n * resized FigJam shape does, and the layer props a shape has.\n */\nexport const shapePropsSchema = v.object({\n kind: v.optional(enumProp(SHAPE_KIND)),\n truncate: v.optional(v.boolean()),\n textSize: v.optional(enumProp(FIGJAM_TEXT_SIZE)),\n typeface: v.optional(enumProp(FIGJAM_TYPEFACE)),\n ...shapeLayerPropsSchema.entries\n})\n\ntype StickyColorName = keyof typeof STICKY_COLORS\n\nfunction isStickyColorName(value: string): value is StickyColorName {\n return value in STICKY_COLORS\n}\n\n/** A palette name such as `\"yellow\"`, or any colour. */\nconst stickyColorSchema = v.pipe(\n v.string(),\n v.rawTransform(({ dataset, addIssue, NEVER }): Color => {\n const name = dataset.value\n if (isStickyColorName(name)) return { ...STICKY_COLORS[name] }\n const color = tryParseColor(name)\n if (color) return color\n addIssue({ message: `expected ${Object.keys(STICKY_COLORS).join(', ')}, or a colour` })\n return NEVER\n })\n)\n\n/** The props `<Sticky>` takes: its own, and the few layer props a note has. */\nexport const stickyPropsSchema = v.object({\n color: v.optional(stickyColorSchema),\n author: v.optional(v.string()),\n authorVisible: v.optional(v.boolean()),\n wide: v.optional(v.boolean()),\n textSize: v.optional(enumProp(FIGJAM_TEXT_SIZE)),\n typeface: v.optional(enumProp(FIGJAM_TYPEFACE)),\n scale: v.optional(v.pipe(v.number(), v.gtValue(0))),\n // A note takes the props that place it, but no size, fills, or layout.\n ...placedOwnLayerPropsSchema.entries\n})\n","import { compact } from 'es-toolkit/array'\nimport { isPlainObject } from 'es-toolkit/predicate'\nimport * as v from 'valibot'\n\nimport type {\n ComponentPropertyDefinition,\n ComponentPropertyReference,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport {\n applyComponentPropertyValue,\n componentPropertyDefinitions,\n createComponentPropertyId,\n exposableInstances,\n exposedInstances,\n instanceExposureIssue\n} from '@pairdraw/scene-graph/components'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport { DESIGN_JSX_SUPPORTED_PROPERTIES } from './definitions'\nimport { parseScriptInput } from './schema'\n\nconst PROPERTY_SYMBOL = Symbol.for('pairdraw.component-property')\n\n/**\n * A component property, by its name in the component that holds it. Where it is placed picks\n * its type: `text` on a text layer makes a TEXT property, `visible` a BOOLEAN one, and `of` on an\n * instance an INSTANCE_SWAP one, whose default is the component that `of` names.\n */\nexport interface ComponentProperty<T extends string | boolean = string | boolean> {\n readonly [PROPERTY_SYMBOL]: true\n readonly name: string\n readonly defaultValue: T\n}\n\nexport function isComponentProperty(value: unknown): value is ComponentProperty {\n return typeof value === 'object' && value !== null && PROPERTY_SYMBOL in value\n}\n\n/**\n * Bind a field to a property of the component it is drawn in, created on first use: on the\n * component set, for a variant, as Figma keeps them, or else on the component.\n */\nexport function property<T extends string | boolean>(\n name: string,\n defaultValue: T\n): ComponentProperty<T> {\n return Object.freeze({ [PROPERTY_SYMBOL]: true as const, name, defaultValue })\n}\n\n/** The prop each property type binds, and the field it binds there. */\nconst BOUND_PROPS = {\n text: { type: 'TEXT', field: 'TEXT', node: 'TEXT' },\n visible: { type: 'BOOLEAN', field: 'VISIBLE', node: undefined },\n of: { type: 'INSTANCE_SWAP', field: 'INSTANCE_SWAP', node: 'INSTANCE' }\n} as const satisfies Record<\n string,\n {\n type: ComponentPropertyDefinition['type']\n field: ComponentPropertyReference['field']\n node: SceneNode['type'] | undefined\n }\n>\n\n/** The component, or the set it is a variant of, that holds properties for layers under `parentId`. */\nfunction propertyOwner(graph: SceneGraph, parentId: string): SceneNode {\n let node = graph.getNode(parentId)\n while (node) {\n if (node.type === 'INSTANCE') throw new Error('property() cannot be used inside an instance')\n if (node.type === 'COMPONENT_SET') return node\n if (node.type === 'COMPONENT') {\n const set = node.parentId ? graph.getNode(node.parentId) : undefined\n return set?.type === 'COMPONENT_SET' ? set : node\n }\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n throw new Error('property() must be inside a <Component> or <ComponentSet>')\n}\n\n/** The ID of the property with this name on `owner`, added if it has none. */\nfunction ensureDefinition(\n graph: SceneGraph,\n owner: SceneNode,\n name: string,\n type: ComponentPropertyDefinition['type'],\n defaultValue: string\n): string {\n const existing = owner.componentPropertyDefinitions.find((item) => item.name === name)\n if (existing) {\n if (existing.type !== type)\n throw new Error(`Component property ${name} is ${existing.type}, not ${type}`)\n if (existing.defaultValue !== defaultValue)\n throw new Error(\n `Component property ${name} has two defaults: ${existing.defaultValue} and ${defaultValue}`\n )\n return existing.id\n }\n const id = createComponentPropertyId()\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [\n ...owner.componentPropertyDefinitions,\n { id, name, type, defaultValue }\n ]\n })\n return id\n}\n\nexport interface BoundProperties {\n /** The props, with each property in place of its default. */\n props: Record<string, unknown>\n references: ComponentPropertyReference[]\n}\n\n/**\n * Bind the fields a layer's props place a `property()` in, creating the properties on its\n * component; `componentId` gives the ID a swap's default component has.\n */\nexport function bindProperties(\n graph: SceneGraph,\n source: Record<string, unknown>,\n type: SceneNode['type'],\n parentId: string,\n componentId: ComponentLookup\n): BoundProperties {\n if (source.properties !== undefined && type !== 'INSTANCE')\n throw new Error('Only instances accept properties; bind a field to property() instead')\n const props = { ...source }\n const references: ComponentPropertyReference[] = []\n for (const [key, value] of Object.entries(source)) {\n if (!isComponentProperty(value)) continue\n if (!Object.hasOwn(BOUND_PROPS, key))\n throw new Error(`property() binds text, visible, or of, not ${key}`)\n const bound = BOUND_PROPS[key as keyof typeof BOUND_PROPS]\n if (bound.node && bound.node !== type)\n throw new Error(\n `property() in ${key} needs ${bound.node === 'TEXT' ? '<Text>' : '<Instance>'}`\n )\n const expected = bound.type === 'BOOLEAN' ? 'boolean' : 'string'\n if (typeof value.defaultValue !== expected)\n throw new Error(`Component property ${value.name} in ${key} takes a ${expected} default`)\n let defaultValue = String(value.defaultValue)\n if (bound.type === 'INSTANCE_SWAP') {\n const id = componentId(defaultValue)\n if (!id) throw new Error(`<Instance> component not found: ${defaultValue}`)\n defaultValue = id\n }\n const owner = propertyOwner(graph, parentId)\n const propertyId = ensureDefinition(graph, owner, value.name, bound.type, defaultValue)\n references.push({ propertyId, field: bound.field })\n props[key] = value.defaultValue\n }\n return { props, references }\n}\n\n/** Match the nearest component scope, including definitions inherited from its set. */\nfunction componentPropertyScope(\n graph: SceneGraph,\n parentId: string\n): readonly ComponentPropertyDefinition[] | undefined {\n let parent = graph.getNode(parentId)\n while (parent) {\n if (parent.type === 'INSTANCE') return componentPropertyDefinitions(graph, parent)\n if (parent.type === 'COMPONENT_SET') return parent.componentPropertyDefinitions\n if (parent.type === 'COMPONENT') {\n const set = parent.parentId ? graph.getNode(parent.parentId) : undefined\n return set?.type === 'COMPONENT_SET'\n ? [...set.componentPropertyDefinitions, ...parent.componentPropertyDefinitions]\n : parent.componentPropertyDefinitions\n }\n parent = parent.parentId ? graph.getNode(parent.parentId) : undefined\n }\n return undefined\n}\n\n/** The one property with this name; a name several properties share is an error. */\nfunction namedDefinition(\n definitions: readonly ComponentPropertyDefinition[],\n name: string\n): ComponentPropertyDefinition | undefined {\n const matches = definitions.filter((item) => item.name === name)\n if (matches.length > 1)\n throw new Error(\n `Component property name ${name} is ambiguous; use one of the IDs: ${matches.map((item) => item.id).join(', ')}`\n )\n return matches[0]\n}\n\n/** The ID of the component a name or ID names, as `<Instance of>` finds it. */\nexport type ComponentLookup = (nameOrId: string) => string | undefined\n\nfunction assignValue(\n graph: SceneGraph,\n instance: SceneNode,\n definition: ComponentPropertyDefinition,\n key: string,\n value: string,\n componentId: ComponentLookup\n): void {\n if (definition.type === 'VARIANT')\n throw new Error('Select a component-set variant when creating the instance')\n if (definition.type === 'BOOLEAN' && value !== 'true' && value !== 'false')\n throw new Error(`Expected true or false for component property: ${key}`)\n // A swap names its component as `of` does: by ID or by name.\n const assigned = definition.type === 'INSTANCE_SWAP' ? (componentId(value) ?? value) : value\n if (!applyComponentPropertyValue(graph, instance.id, definition, assigned))\n throw new Error(`Cannot assign component property: ${key}`)\n}\n\n/** A value an instance gives a property, or an exposed nested instance's values by name. */\nconst assignedValueSchema = v.union([v.string(), v.boolean(), v.number()])\nconst exposedValuesSchema = v.record(v.string(), assignedValueSchema)\n\n/** The one exposed nested instance with this name; a name several share is an error. */\nfunction exposedInstanceNamed(\n graph: SceneGraph,\n instance: SceneNode,\n name: string\n): SceneNode | undefined {\n const matches = exposedInstances(graph, instance).filter((node) => node.name === name)\n if (matches.length > 1)\n throw new Error(`Exposed instance name ${name} is shared by ${matches.length} layers`)\n return matches[0]\n}\n\n/**\n * Pick the variant of an exposed instance's set that has the values it names, keeping its own\n * for the rest, as its panel group does.\n */\nfunction selectNestedVariant(\n graph: SceneGraph,\n nested: SceneNode,\n name: string,\n values: Record<string, string>\n): void {\n if (Object.keys(values).length === 0) return\n const component = instanceMainComponent(graph, nested)\n const set = component?.parentId ? graph.getNode(component.parentId) : undefined\n if (!component || set?.type !== 'COMPONENT_SET') return\n const wanted = { ...component.componentPropertyValues, ...values }\n const variant = graph\n .getChildren(set.id)\n .find(\n (node) =>\n node.type === 'COMPONENT' &&\n Object.entries(wanted).every(([key, value]) => node.componentPropertyValues[key] === value)\n )\n if (!variant)\n throw new Error(\n `${name} has no variant ${Object.entries(values)\n .map(([key, value]) => `${key}=${value}`)\n .join(', ')}`\n )\n if (variant.id !== component.id) graph.swapInstanceComponent(nested.id, variant.id)\n}\n\n/**\n * Give the exposed nested instance named `name` its values: variants and properties by name,\n * the way the instance itself takes them.\n */\nfunction assignExposedInstance(\n graph: SceneGraph,\n instance: SceneNode,\n name: string,\n input: unknown,\n componentId: ComponentLookup\n): void {\n const nested = exposedInstanceNamed(graph, instance, name)\n if (!nested) throw new Error(`Unknown component property or exposed instance: ${name}`)\n const values = parseScriptInput(`Invalid values for ${name}`, exposedValuesSchema, input)\n const variantNames = new Set(\n componentPropertyDefinitions(graph, nested)\n .filter((definition) => definition.type === 'VARIANT')\n .map((definition) => definition.name)\n )\n const variants = Object.fromEntries(\n Object.entries(values)\n .filter(([key]) => variantNames.has(key))\n .map(([key, value]) => [key, String(value)])\n )\n selectNestedVariant(graph, nested, name, variants)\n const definitions = componentPropertyDefinitions(graph, nested)\n for (const [key, value] of Object.entries(values)) {\n if (variantNames.has(key)) continue\n const definition = namedDefinition(definitions, key)\n if (!definition) throw new Error(`Unknown component property on ${name}: ${key}`)\n assignValue(graph, nested, definition, key, String(value), componentId)\n }\n}\n\n/**\n * Set text, boolean, and swap properties an instance names as props, as in `Title=\"Hello\"`, the\n * way it picks a variant, and an exposed nested instance's values, as in `Action={{ Label: 'Save' }}`;\n * design JSX props keep their meaning.\n */\nexport function assignNamedProperties(\n graph: SceneGraph,\n instance: SceneNode,\n props: Record<string, unknown>,\n componentId: ComponentLookup\n): void {\n const definitions = componentPropertyDefinitions(graph, instance).filter(\n (definition) => definition.type !== 'VARIANT'\n )\n for (const [key, value] of Object.entries(props)) {\n if (DESIGN_JSX_SUPPORTED_PROPERTIES.has(key)) continue\n if (isPlainObject(value) && exposedInstanceNamed(graph, instance, key)) {\n assignExposedInstance(graph, instance, key, value, componentId)\n continue\n }\n const definition = namedDefinition(definitions, key)\n if (!definition) continue\n if (typeof value !== 'string' && typeof value !== 'boolean' && typeof value !== 'number')\n throw new Error(`Expected a string or boolean for component property: ${key}`)\n assignValue(graph, instance, definition, key, String(value), componentId)\n }\n}\n\n/**\n * Keys are property IDs or, because saving to `.fig` replaces authored IDs\n * with GUIDs, names, which survive a reload; an object gives an exposed nested instance its values.\n */\nexport function assignComponentProperties(\n graph: SceneGraph,\n instance: SceneNode,\n input: unknown,\n componentId: ComponentLookup\n): void {\n if (input === undefined) return\n const assignments = parseScriptInput(\n 'Invalid properties on <Instance>',\n v.record(v.string(), v.union([assignedValueSchema, exposedValuesSchema])),\n input\n )\n const definitions = componentPropertyDefinitions(graph, instance)\n for (const [key, value] of Object.entries(assignments)) {\n if (isPlainObject(value)) {\n assignExposedInstance(graph, instance, key, value, componentId)\n continue\n }\n const definition =\n definitions.find((item) => item.id === key) ?? namedDefinition(definitions, key)\n if (!definition) throw new Error(`Unknown component property: ${key}`)\n assignValue(graph, instance, definition, key, String(value), componentId)\n }\n}\n\n/** Mark an instance in a component's layers as exposed, under Figma's rules for exposing one. */\nexport function exposeInstance(graph: SceneGraph, instance: SceneNode): void {\n const issue = instanceExposureIssue(graph, instance)\n if (issue === 'not-in-component') throw new Error('exposed needs an <Instance> in a component')\n if (issue === 'not-primary')\n throw new Error('exposed needs an <Instance> in a component, not inside another instance')\n if (issue === 'nothing-to-expose')\n throw new Error(`${instance.name} has no properties or exposed instances to expose`)\n graph.updateNode(instance.id, { isExposedInstance: true })\n}\n\n/** The names an instance of `component` takes: its properties' and its exposed instances'. */\nexport function componentPropNames(graph: SceneGraph, component: SceneNode): string[] {\n return [\n ...(componentPropertyScope(graph, component.id) ?? []).map((definition) => definition.name),\n ...exposableInstances(graph, component.id)\n .filter((node) => node.isExposedInstance)\n .map((node) => node.name)\n ]\n}\n\nfunction parseVariantValues(name: string): Record<string, string> {\n const entries = compact(name.split(',').map((part) => part.trim()))\n const values: Record<string, string> = {}\n for (const entry of entries) {\n const [key = '', ...rest] = entry.split('=')\n const property = key.trim()\n const value = rest.join('=').trim()\n if (property && value) values[property] = value\n }\n return values\n}\n\n/** Variant properties a component set takes from its variants' names, such as `State=On`. */\nexport function inferComponentSetProperties(graph: SceneGraph, componentSetId: string): void {\n const componentSet = graph.getNode(componentSetId)\n if (componentSet?.type !== 'COMPONENT_SET') return\n const existingDefinitions = componentSet.componentPropertyDefinitions\n\n const variants = graph.getChildren(componentSetId).filter((node) => node.type === 'COMPONENT')\n const options = new Map<string, Set<string>>()\n const valuesById = new Map<string, Record<string, string>>()\n\n for (const variant of variants) {\n const values = parseVariantValues(variant.name)\n valuesById.set(variant.id, values)\n for (const [property, value] of Object.entries(values)) {\n let set = options.get(property)\n if (!set) {\n set = new Set()\n options.set(property, set)\n }\n set.add(value)\n }\n }\n\n const definitions: ComponentPropertyDefinition[] = [...options.entries()]\n .filter(\n ([name]) =>\n !existingDefinitions.some(\n (definition) => definition.type === 'VARIANT' && definition.name === name\n )\n )\n .map(([name, values]) => {\n const variantOptions = [...values]\n return {\n id: createComponentPropertyId(),\n name,\n type: 'VARIANT',\n defaultValue: variantOptions[0] ?? '',\n variantOptions\n }\n })\n\n for (const [id, values] of valuesById) {\n graph.updateNode(id, { componentPropertyValues: values })\n }\n graph.updateNode(componentSetId, {\n componentPropertyDefinitions: [...existingDefinitions, ...definitions]\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,SAAS,QACP,WACA,UAAuC,CAAC,GAC5B;CACZ,MAAM,UAAU,OAAO,QAAQ,SAAS;CACxC,MAAM,SAAS,IAAI,IACjB,CAAC,GAAG,QAAQ,KAAK,CAAC,OAAO,UAAuB,CAAC,MAAM,KAAK,CAAC,GAAG,GAAG,OAAO,QAAQ,OAAO,CAAC,CAAC,CAAC,KACzF,CAAC,MAAM,WAAwB,CAAC,KAAK,YAAY,GAAG,KAAK,CAC5D,CACF;CACA,OAAO;EACL,QAAQ,UAAW,OAAO,UAAU,WAAW,OAAO,IAAI,MAAM,YAAY,CAAC,IAAI,KAAA;EACjF,QAAQ,UAAU,UAAU;EAC5B,OAAO,CAAC,GAAG,QAAQ,KAAK,GAAG,UAAU,IAAI,GAAG,GAAG,OAAO,KAAK,OAAO,CAAC;CACrE;AACF;;AAGA,SAAgB,SAA2B,QAAoB;CAC7D,OAAO,EAAE,KACP,EAAE,OAAO,GACT,EAAE,cAAc,EAAE,SAAS,UAAU,YAAY;EAC/C,MAAM,Q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AAU,IAAI,IAAyB;CAC7C,MAAM,6BAAa,IAAI,IAAoC;CAE3D,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,SAAS,mBAAmB,QAAQ,IAAI;EAC9C,WAAW,IAAI,QAAQ,IAAI,MAAM;EACjC,KAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,MAAM,GAAG;GACtD,IAAI,MAAM,QAAQ,IAAI,QAAQ;GAC9B,IAAI,CAAC,KAAK;IACR,sBAAM,IAAI,IAAI;IACd,QAAQ,IAAI,UAAU,GAAG;GAC3B;GACA,IAAI,IAAI,KAAK;EACf;CACF;CAEA,MAAM,cAA6C,CAAC,GAAG,QAAQ,QAAQ,CAAC,CAAC,CACtE,QACE,CAAC,UACA,CAAC,oBAAoB,MAClB,eAAe,WAAW,SAAS,aAAa,WAAW,SAAS,IACvE,CACJ,CAAC,CACA,KAAK,CAAC,MAAM,YAAY;EACvB,MAAM,iBAAiB,CAAC,GAAG,MAAM;EACjC,OAAO;GACL,IAAI,0BAA0B;GAC9B;GACA,MAAM;GACN,cAAc,eAAe,MAAM;GACnC;EACF;CACF,CAAC;CAEH,KAAK,MAAM,CAAC,IAAI,WAAW,YACzB,MAAM,WAAW,IAAI,EAAE,yBAAyB,OAAO,CAAC;CAE1D,MAAM,WAAW,gBAAgB,EAC/B,8BAA8B,CAAC,GAAG,qBAAqB,GAAG,WAAW,EACvE,CAAC;AACH"}
|
package/dist/chunks/elements.js
CHANGED
|
@@ -2,19 +2,24 @@ import { REKA_ELEMENTS, plainTextOf, rekaRole } from "./behaviours/elements.js";
|
|
|
2
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
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
4
|
import { connectorBindingTarget, helperCall, plainValue, renderConnectorNode } from "./connectors.js";
|
|
5
|
-
import { colorToHex, colorToHex8 } from "@pairdraw/scene-graph/color";
|
|
5
|
+
import { colorToDocumentCSS, colorToHex, colorToHex8 } from "@pairdraw/scene-graph/color";
|
|
6
6
|
import { gradientTransformRows, isIdentityGradientTransform } from "@pairdraw/scene-graph/gradient";
|
|
7
7
|
import { isShaderPresetPaint, shaderOfPaint } from "@pairdraw/scene-graph/shaders";
|
|
8
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
9
|
import { difference } from "es-toolkit/array";
|
|
10
10
|
import { figJamTextSize, figJamTextSizeFields, figJamTypeface, figJamTypefaceFields } from "@pairdraw/scene-graph/figjam";
|
|
11
11
|
//#region src/export/helpers.ts
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/** A color as the JSX runtime reads it, in the document's profile, so a P3 color keeps its gamut. */
|
|
13
|
+
function formatColor(color, opacity = 1, profile = "srgb") {
|
|
14
|
+
if (profile === "srgb") return colorToHex8(color, opacity);
|
|
15
|
+
return colorToDocumentCSS({
|
|
16
|
+
...color,
|
|
17
|
+
a: opacity
|
|
18
|
+
}, profile);
|
|
19
|
+
}
|
|
20
|
+
function formatShadow(e, profile = "srgb") {
|
|
16
21
|
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)}`;
|
|
22
|
+
return `${e.offset.x} ${e.offset.y} ${e.radius} ${formatColor(e.color, e.color.a, profile)}`;
|
|
18
23
|
}
|
|
19
24
|
function getNodeContext(node, graph) {
|
|
20
25
|
const parent = node.parentId ? graph.getNode(node.parentId) : null;
|
|
@@ -92,7 +97,7 @@ function blendMode(mode) {
|
|
|
92
97
|
function options(entries) {
|
|
93
98
|
return Object.values(entries).some((value) => value !== void 0) ? entries : void 0;
|
|
94
99
|
}
|
|
95
|
-
function fillValue(fill, node) {
|
|
100
|
+
function fillValue(fill, node, profile) {
|
|
96
101
|
const visible = fill.visible ? void 0 : false;
|
|
97
102
|
const shader = shaderOfPaint(node, fill);
|
|
98
103
|
if (shader && isShaderPresetPaint(shader)) {
|
|
@@ -113,7 +118,7 @@ function fillValue(fill, node) {
|
|
|
113
118
|
}));
|
|
114
119
|
}
|
|
115
120
|
if (fill.type === "SOLID") {
|
|
116
|
-
const color = formatColor(fill.color, fill.color.a);
|
|
121
|
+
const color = formatColor(fill.color, fill.color.a, profile);
|
|
117
122
|
const opacity = fill.opacity === fill.color.a ? void 0 : fill.opacity;
|
|
118
123
|
return helperCall("solid", color, options({
|
|
119
124
|
opacity,
|
|
@@ -123,7 +128,7 @@ function fillValue(fill, node) {
|
|
|
123
128
|
}
|
|
124
129
|
const helper = GRADIENT_HELPERS[fill.type];
|
|
125
130
|
if (helper && fill.gradientStops) {
|
|
126
|
-
const stops = fill.gradientStops.map((stop) => [formatColor(stop.color, stop.color.a), stop.position]);
|
|
131
|
+
const stops = fill.gradientStops.map((stop) => [formatColor(stop.color, stop.color.a, profile), stop.position]);
|
|
127
132
|
return helperCall(helper, stops, options({
|
|
128
133
|
opacity: fill.opacity === 1 ? void 0 : fill.opacity,
|
|
129
134
|
visible,
|
|
@@ -138,29 +143,29 @@ function fillValue(fill, node) {
|
|
|
138
143
|
});
|
|
139
144
|
}
|
|
140
145
|
/** A single visible solid paint fits the `bg` or text `color` shorthand. */
|
|
141
|
-
function solidShorthand(fills) {
|
|
146
|
+
function solidShorthand(fills, profile) {
|
|
142
147
|
if (fills.length !== 1) return null;
|
|
143
148
|
const [fill] = fills;
|
|
144
149
|
if (fill.type !== "SOLID" || !fill.visible || blendMode(fill.blendMode)) return null;
|
|
145
150
|
if (fill.opacity !== fill.color.a) return null;
|
|
146
|
-
return formatColor(fill.color, fill.color.a);
|
|
151
|
+
return formatColor(fill.color, fill.color.a, profile);
|
|
147
152
|
}
|
|
148
153
|
/** 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);
|
|
154
|
+
function paintPropValue(fill, node, profile = "srgb") {
|
|
155
|
+
return solidShorthand([fill], profile) ?? fillValue(fill, node, profile);
|
|
151
156
|
}
|
|
152
|
-
function collectFillProps(node, props) {
|
|
157
|
+
function collectFillProps(node, props, profile = "srgb") {
|
|
153
158
|
if (node.fills.length === 0) {
|
|
154
159
|
if (node.type === "TEXT") props.push(["fills", []]);
|
|
155
160
|
return;
|
|
156
161
|
}
|
|
157
|
-
const shorthand = solidShorthand(node.fills);
|
|
162
|
+
const shorthand = solidShorthand(node.fills, profile);
|
|
158
163
|
if (shorthand) props.push([node.type === "TEXT" ? "color" : "bg", shorthand]);
|
|
159
|
-
else props.push(["fills", node.fills.map((fill) => fillValue(fill, node))]);
|
|
164
|
+
else props.push(["fills", node.fills.map((fill) => fillValue(fill, node, profile))]);
|
|
160
165
|
}
|
|
161
|
-
function strokeValue(stroke) {
|
|
166
|
+
function strokeValue(stroke, profile) {
|
|
162
167
|
return {
|
|
163
|
-
color: formatColor(stroke.color, stroke.color.a),
|
|
168
|
+
color: formatColor(stroke.color, stroke.color.a, profile),
|
|
164
169
|
opacity: stroke.opacity === stroke.color.a ? void 0 : stroke.opacity,
|
|
165
170
|
weight: stroke.weight === 1 ? void 0 : stroke.weight,
|
|
166
171
|
align: stroke.align === "INSIDE" ? void 0 : STROKE_ALIGN.print(stroke.align),
|
|
@@ -189,8 +194,8 @@ function fitsStrokeShorthand(node, stroke) {
|
|
|
189
194
|
const nodeJoin = STROKE_JOIN.print(node.strokeJoin);
|
|
190
195
|
return (stroke.cap ?? nodeCap) === nodeCap && (stroke.join ?? nodeJoin) === nodeJoin;
|
|
191
196
|
}
|
|
192
|
-
function collectStrokeProps(node, props) {
|
|
193
|
-
const strokes = node.strokes.map(strokeValue);
|
|
197
|
+
function collectStrokeProps(node, props, profile = "srgb") {
|
|
198
|
+
const strokes = node.strokes.map((stroke) => strokeValue(stroke, profile));
|
|
194
199
|
const [only] = strokes;
|
|
195
200
|
if (strokes.length === 1 && fitsStrokeShorthand(node, only)) {
|
|
196
201
|
for (const [key, value] of Object.entries(only)) if (value !== void 0 && key !== "cap" && key !== "join") props.push([STROKE_SHORTHAND[key], value]);
|
|
@@ -221,14 +226,14 @@ function noiseSizeValue(size) {
|
|
|
221
226
|
y: size.y
|
|
222
227
|
};
|
|
223
228
|
}
|
|
224
|
-
function effectValue(effect) {
|
|
229
|
+
function effectValue(effect, profile) {
|
|
225
230
|
const visible = effect.visible ? void 0 : false;
|
|
226
231
|
if (effect.type === "DROP_SHADOW" || effect.type === "INNER_SHADOW") return helperCall(EFFECT_HELPERS[effect.type], options({
|
|
227
232
|
x: effect.offset.x,
|
|
228
233
|
y: effect.offset.y,
|
|
229
234
|
radius: effect.radius,
|
|
230
235
|
spread: effect.spread === 0 ? void 0 : effect.spread,
|
|
231
|
-
color: formatColor(effect.color, effect.color.a),
|
|
236
|
+
color: formatColor(effect.color, effect.color.a, profile),
|
|
232
237
|
visible,
|
|
233
238
|
blendMode: blendMode(effect.blendMode),
|
|
234
239
|
showShadowBehindNode: effect.showShadowBehindNode
|
|
@@ -239,8 +244,8 @@ function effectValue(effect) {
|
|
|
239
244
|
noiseType: grain.noiseType,
|
|
240
245
|
noiseSize: noiseSizeValue(grain.noiseSize),
|
|
241
246
|
density: grain.density,
|
|
242
|
-
color: formatColor(effect.color, effect.color.a),
|
|
243
|
-
secondaryColor: grain.secondaryColor ? formatColor(grain.secondaryColor, grain.secondaryColor.a) : void 0,
|
|
247
|
+
color: formatColor(effect.color, effect.color.a, profile),
|
|
248
|
+
secondaryColor: grain.secondaryColor ? formatColor(grain.secondaryColor, grain.secondaryColor.a, profile) : void 0,
|
|
244
249
|
opacity: grain.opacity,
|
|
245
250
|
seed: grain.seed,
|
|
246
251
|
visible
|
|
@@ -261,16 +266,16 @@ function effectValue(effect) {
|
|
|
261
266
|
visible
|
|
262
267
|
});
|
|
263
268
|
}
|
|
264
|
-
function plainDropShadow(effect) {
|
|
265
|
-
return effect.type === "DROP_SHADOW" && effect.spread === 0 && !blendMode(effect.blendMode) && effect.showShadowBehindNode === void 0 ? formatShadow(effect) : null;
|
|
269
|
+
function plainDropShadow(effect, profile) {
|
|
270
|
+
return effect.type === "DROP_SHADOW" && effect.spread === 0 && !blendMode(effect.blendMode) && effect.showShadowBehindNode === void 0 ? formatShadow(effect, profile) : null;
|
|
266
271
|
}
|
|
267
272
|
/**
|
|
268
273
|
* `shadow` and `blur` describe a plain drop shadow followed by a layer blur, each optional,
|
|
269
274
|
* in the order the renderer appends them; anything else needs `effects`.
|
|
270
275
|
*/
|
|
271
|
-
function effectShorthand(effects) {
|
|
276
|
+
function effectShorthand(effects, profile) {
|
|
272
277
|
if (effects.some((effect) => !effect.visible)) return null;
|
|
273
|
-
const shadow = effects.length > 0 ? plainDropShadow(effects[0]) : null;
|
|
278
|
+
const shadow = effects.length > 0 ? plainDropShadow(effects[0], profile) : null;
|
|
274
279
|
const rest = shadow ? effects.slice(1) : effects;
|
|
275
280
|
if (rest.length > 1 || rest.some((effect) => effect.type !== "LAYER_BLUR")) return null;
|
|
276
281
|
const props = [];
|
|
@@ -282,10 +287,10 @@ function effectShorthand(effects) {
|
|
|
282
287
|
function hasJSXHelper(effect) {
|
|
283
288
|
return effect.type !== "SHADER" && Object.hasOwn(EFFECT_HELPERS, effect.type);
|
|
284
289
|
}
|
|
285
|
-
function collectEffectProps(node, props) {
|
|
290
|
+
function collectEffectProps(node, props, profile = "srgb") {
|
|
286
291
|
const effects = node.effects.filter(hasJSXHelper);
|
|
287
292
|
if (effects.length === 0) return;
|
|
288
|
-
props.push(...effectShorthand(effects) ?? [["effects", effects.map(effectValue)]]);
|
|
293
|
+
props.push(...effectShorthand(effects, profile) ?? [["effects", effects.map((effect) => effectValue(effect, profile))]]);
|
|
289
294
|
}
|
|
290
295
|
//#endregion
|
|
291
296
|
//#region src/figjam-text.ts
|
|
@@ -341,8 +346,8 @@ function shapeWithTextProps(graph, node) {
|
|
|
341
346
|
if (height !== SHAPE_WITH_TEXT_SIZE) props.push(["h", height]);
|
|
342
347
|
if (node.shapeTruncates) props.push(["truncate", true]);
|
|
343
348
|
if (node.rotation !== 0) props.push(["rotate", Math.round(node.rotation * 100) / 100]);
|
|
344
|
-
collectFillProps(node, props);
|
|
345
|
-
collectStrokeProps(node, props);
|
|
349
|
+
collectFillProps(node, props, graph.documentColorSpace);
|
|
350
|
+
collectStrokeProps(node, props, graph.documentColorSpace);
|
|
346
351
|
if (node.cornerRadius !== SHAPE_WITH_TEXT_CORNER_RADIUS) props.push(["rounded", node.cornerRadius]);
|
|
347
352
|
return props;
|
|
348
353
|
}
|