@pairdraw/design-jsx 0.19.2 → 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.
@@ -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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AACT;;AAGA,SAAgB,4BAA4B,OAAmB,gBAA8B;CAC3F,MAAM,eAAe,MAAM,QAAQ,cAAc;CACjD,IAAI,cAAc,SAAS,iBAAiB;CAC5C,MAAM,sBAAsB,aAAa;CAEzC,MAAM,WAAW,MAAM,YAAY,cAAc,CAAC,CAAC,QAAQ,SAAS,KAAK,SAAS,WAAW;CAC7F,MAAM,0BAAU,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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AGA,SAAgB,4BAA4B,OAAmB,gBAA8B;CAC3F,MAAM,eAAe,MAAM,QAAQ,cAAc;CACjD,IAAI,cAAc,SAAS,iBAAiB;CAC5C,MAAM,sBAAsB,aAAa;CAEzC,MAAM,WAAW,MAAM,YAAY,cAAc,CAAC,CAAC,QAAQ,SAAS,KAAK,SAAS,WAAW;CAC7F,MAAM,0BAAU,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,6 +1,6 @@
1
1
  import { BLEND_MODE } from "./component-properties.js";
2
2
  import { parseColor } from "@pairdraw/scene-graph/color";
3
- import { TRANSPARENT } from "@pairdraw/scene-graph/constants";
3
+ import { BLACK, DEFAULT_NOISE, DEFAULT_NOISE_COLOR, DEFAULT_TEXTURE, TRANSPARENT } from "@pairdraw/scene-graph/constants";
4
4
  //#region src/effects.ts
5
5
  /** Radius of a shadow or blur that does not set one. */
6
6
  const DEFAULT_EFFECT_RADIUS = 8;
@@ -56,7 +56,59 @@ function backgroundBlur(radiusOrOptions) {
56
56
  function foregroundBlur(radiusOrOptions) {
57
57
  return blurEffect("FOREGROUND_BLUR", radiusOrOptions);
58
58
  }
59
+ /** Radius of a new texture effect, as Figma's effects panel starts one. */
60
+ const DEFAULT_TEXTURE_RADIUS = 4;
61
+ function noiseSize(size, fallback) {
62
+ if (size === void 0) return { ...fallback };
63
+ return typeof size === "number" ? {
64
+ x: size,
65
+ y: size
66
+ } : { ...size };
67
+ }
68
+ /**
69
+ * A noise effect. A duotone's second colour starts white at the first colour's opacity and a
70
+ * multitone's opacity at that opacity, as Figma's panel switches them.
71
+ */
72
+ function noise(options = {}) {
73
+ const color = options.color === void 0 ? { ...DEFAULT_NOISE_COLOR } : toColor(options.color);
74
+ const params = {
75
+ noiseType: options.noiseType ?? DEFAULT_NOISE.noiseType,
76
+ noiseSize: noiseSize(options.noiseSize, DEFAULT_NOISE.noiseSize),
77
+ density: options.density ?? DEFAULT_NOISE.density
78
+ };
79
+ if (options.secondaryColor !== void 0) params.secondaryColor = toColor(options.secondaryColor);
80
+ else if (params.noiseType === "DUOTONE") params.secondaryColor = {
81
+ r: 1,
82
+ g: 1,
83
+ b: 1,
84
+ a: color.a
85
+ };
86
+ if (options.opacity !== void 0) params.opacity = options.opacity;
87
+ else if (params.noiseType === "MULTITONE") params.opacity = color.a;
88
+ if (options.seed !== void 0) params.seed = options.seed;
89
+ return {
90
+ type: "NOISE",
91
+ color,
92
+ visible: options.visible ?? true,
93
+ noise: params
94
+ };
95
+ }
96
+ /** A texture effect, which roughens the layer's edges by `radius`. */
97
+ function texture(options = {}) {
98
+ const params = {
99
+ noiseSize: noiseSize(options.noiseSize, DEFAULT_TEXTURE.noiseSize),
100
+ clipToShape: options.clipToShape ?? DEFAULT_TEXTURE.clipToShape
101
+ };
102
+ if (options.seed !== void 0) params.seed = options.seed;
103
+ return {
104
+ type: "TEXTURE",
105
+ color: { ...BLACK },
106
+ radius: options.radius ?? DEFAULT_TEXTURE_RADIUS,
107
+ visible: options.visible ?? true,
108
+ texture: params
109
+ };
110
+ }
59
111
  //#endregion
60
- export { backgroundBlur, dropShadow, foregroundBlur, innerShadow, layerBlur };
112
+ export { backgroundBlur, dropShadow, foregroundBlur, innerShadow, layerBlur, noise, texture };
61
113
 
62
114
  //# sourceMappingURL=effects.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"effects.js","names":[],"sources":["../../src/effects.ts"],"sourcesContent":["import type { BlendMode, Effect } from '@pairdraw/scene-graph'\nimport { parseColor } from '@pairdraw/scene-graph/color'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport type { Color, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { BLEND_MODE } from './enums'\n\nexport type EffectColor = string | Color\n\nexport interface ShadowEffectOptions {\n color?: EffectColor\n x?: number\n y?: number\n offset?: Vector\n radius?: number\n spread?: number\n visible?: boolean\n /** Same spellings as a layer's `blendMode`, read case-insensitively. */\n blendMode?: string\n showShadowBehindNode?: boolean\n}\n\nexport interface BlurEffectOptions {\n radius?: number\n visible?: boolean\n}\n\n/** Radius of a shadow or blur that does not set one. */\nconst DEFAULT_EFFECT_RADIUS = 8\n\nfunction toColor(color: EffectColor | undefined): Color {\n if (color === undefined) return { ...TRANSPARENT }\n return typeof color === 'string' ? parseColor(color) : color\n}\n\n/** A layer's `blendMode` spelling, or undefined when the helper omits it or names none. */\nfunction parsedBlendMode(blendMode: string | undefined): BlendMode | undefined {\n return blendMode === undefined ? undefined : BLEND_MODE.parse(blendMode)\n}\n\nfunction shadowEffect(type: 'DROP_SHADOW' | 'INNER_SHADOW', options: ShadowEffectOptions): Effect {\n return {\n type,\n color: toColor(options.color ?? 'rgba(0, 0, 0, 0.25)'),\n offset: options.offset ?? { x: options.x ?? 0, y: options.y ?? 4 },\n radius: options.radius ?? DEFAULT_EFFECT_RADIUS,\n spread: options.spread ?? 0,\n visible: options.visible ?? true,\n blendMode: parsedBlendMode(options.blendMode),\n showShadowBehindNode: options.showShadowBehindNode\n }\n}\n\nfunction blurEffect(\n type: 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR',\n radiusOrOptions: number | BlurEffectOptions = {}\n): Effect {\n const options =\n typeof radiusOrOptions === 'number' ? { radius: radiusOrOptions } : radiusOrOptions\n return {\n type,\n color: { ...TRANSPARENT },\n offset: { x: 0, y: 0 },\n radius: options.radius ?? DEFAULT_EFFECT_RADIUS,\n spread: 0,\n visible: options.visible ?? true\n }\n}\n\nexport function dropShadow(options: ShadowEffectOptions = {}): Effect {\n return shadowEffect('DROP_SHADOW', options)\n}\n\nexport function innerShadow(options: ShadowEffectOptions = {}): Effect {\n return shadowEffect('INNER_SHADOW', options)\n}\n\nexport function layerBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('LAYER_BLUR', radiusOrOptions)\n}\n\nexport function backgroundBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('BACKGROUND_BLUR', radiusOrOptions)\n}\n\nexport function foregroundBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('FOREGROUND_BLUR', radiusOrOptions)\n}\n"],"mappings":";;;;;AA4BA,MAAM,wBAAwB;AAE9B,SAAS,QAAQ,OAAuC;CACtD,IAAI,UAAU,KAAA,GAAW,OAAO,EAAE,GAAG,YAAY;CACjD,OAAO,OAAO,UAAU,WAAW,WAAW,KAAK,IAAI;AACzD;;AAGA,SAAS,gBAAgB,WAAsD;CAC7E,OAAO,cAAc,KAAA,IAAY,KAAA,IAAY,WAAW,MAAM,SAAS;AACzE;AAEA,SAAS,aAAa,MAAsC,SAAsC;CAChG,OAAO;EACL;EACA,OAAO,QAAQ,QAAQ,SAAS,qBAAqB;EACrD,QAAQ,QAAQ,UAAU;GAAE,GAAG,QAAQ,KAAK;GAAG,GAAG,QAAQ,KAAK;EAAE;EACjE,QAAQ,QAAQ,UAAU;EAC1B,QAAQ,QAAQ,UAAU;EAC1B,SAAS,QAAQ,WAAW;EAC5B,WAAW,gBAAgB,QAAQ,SAAS;EAC5C,sBAAsB,QAAQ;CAChC;AACF;AAEA,SAAS,WACP,MACA,kBAA8C,CAAC,GACvC;CACR,MAAM,UACJ,OAAO,oBAAoB,WAAW,EAAE,QAAQ,gBAAgB,IAAI;CACtE,OAAO;EACL;EACA,OAAO,EAAE,GAAG,YAAY;EACxB,QAAQ;GAAE,GAAG;GAAG,GAAG;EAAE;EACrB,QAAQ,QAAQ,UAAU;EAC1B,QAAQ;EACR,SAAS,QAAQ,WAAW;CAC9B;AACF;AAEA,SAAgB,WAAW,UAA+B,CAAC,GAAW;CACpE,OAAO,aAAa,eAAe,OAAO;AAC5C;AAEA,SAAgB,YAAY,UAA+B,CAAC,GAAW;CACrE,OAAO,aAAa,gBAAgB,OAAO;AAC7C;AAEA,SAAgB,UAAU,iBAAsD;CAC9E,OAAO,WAAW,cAAc,eAAe;AACjD;AAEA,SAAgB,eAAe,iBAAsD;CACnF,OAAO,WAAW,mBAAmB,eAAe;AACtD;AAEA,SAAgB,eAAe,iBAAsD;CACnF,OAAO,WAAW,mBAAmB,eAAe;AACtD"}
1
+ {"version":3,"file":"effects.js","names":[],"sources":["../../src/effects.ts"],"sourcesContent":["import type {\n BlendMode,\n Effect,\n NoiseEffectParams,\n TextureEffectParams\n} from '@pairdraw/scene-graph'\nimport { parseColor } from '@pairdraw/scene-graph/color'\nimport {\n BLACK,\n DEFAULT_NOISE,\n DEFAULT_NOISE_COLOR,\n DEFAULT_TEXTURE,\n TRANSPARENT\n} from '@pairdraw/scene-graph/constants'\nimport type { Color, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { BLEND_MODE } from './enums'\n\nexport type EffectColor = string | Color\n\nexport interface ShadowEffectOptions {\n color?: EffectColor\n x?: number\n y?: number\n offset?: Vector\n radius?: number\n spread?: number\n visible?: boolean\n /** Same spellings as a layer's `blendMode`, read case-insensitively. */\n blendMode?: string\n showShadowBehindNode?: boolean\n}\n\nexport interface BlurEffectOptions {\n radius?: number\n visible?: boolean\n}\n\n/** Radius of a shadow or blur that does not set one. */\nconst DEFAULT_EFFECT_RADIUS = 8\n\nfunction toColor(color: EffectColor | undefined): Color {\n if (color === undefined) return { ...TRANSPARENT }\n return typeof color === 'string' ? parseColor(color) : color\n}\n\n/** A layer's `blendMode` spelling, or undefined when the helper omits it or names none. */\nfunction parsedBlendMode(blendMode: string | undefined): BlendMode | undefined {\n return blendMode === undefined ? undefined : BLEND_MODE.parse(blendMode)\n}\n\nfunction shadowEffect(type: 'DROP_SHADOW' | 'INNER_SHADOW', options: ShadowEffectOptions): Effect {\n return {\n type,\n color: toColor(options.color ?? 'rgba(0, 0, 0, 0.25)'),\n offset: options.offset ?? { x: options.x ?? 0, y: options.y ?? 4 },\n radius: options.radius ?? DEFAULT_EFFECT_RADIUS,\n spread: options.spread ?? 0,\n visible: options.visible ?? true,\n blendMode: parsedBlendMode(options.blendMode),\n showShadowBehindNode: options.showShadowBehindNode\n }\n}\n\nfunction blurEffect(\n type: 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR',\n radiusOrOptions: number | BlurEffectOptions = {}\n): Effect {\n const options =\n typeof radiusOrOptions === 'number' ? { radius: radiusOrOptions } : radiusOrOptions\n return {\n type,\n color: { ...TRANSPARENT },\n offset: { x: 0, y: 0 },\n radius: options.radius ?? DEFAULT_EFFECT_RADIUS,\n spread: 0,\n visible: options.visible ?? true\n }\n}\n\nexport function dropShadow(options: ShadowEffectOptions = {}): Effect {\n return shadowEffect('DROP_SHADOW', options)\n}\n\nexport function innerShadow(options: ShadowEffectOptions = {}): Effect {\n return shadowEffect('INNER_SHADOW', options)\n}\n\nexport function layerBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('LAYER_BLUR', radiusOrOptions)\n}\n\nexport function backgroundBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('BACKGROUND_BLUR', radiusOrOptions)\n}\n\nexport function foregroundBlur(radiusOrOptions?: number | BlurEffectOptions): Effect {\n return blurEffect('FOREGROUND_BLUR', radiusOrOptions)\n}\n\n/** A grain size as Figma's plugin API takes it, one number for both axes, or each axis apart. */\nexport type NoiseSize = number | Vector\n\n/**\n * A noise effect in Figma's terms: grains in `color`, a duotone's `secondaryColor` too, or a\n * multitone's many colours at `opacity`. Left out, each value is what Figma's panel starts with.\n */\nexport interface NoiseEffectOptions extends Partial<\n Omit<NoiseEffectParams, 'noiseSize' | 'secondaryColor'>\n> {\n noiseSize?: NoiseSize\n color?: EffectColor\n secondaryColor?: EffectColor\n visible?: boolean\n}\n\n/** A texture effect in Figma's terms, `radius` being how far its grain moves the edges. */\nexport interface TextureEffectOptions extends Partial<Omit<TextureEffectParams, 'noiseSize'>> {\n noiseSize?: NoiseSize\n radius?: number\n visible?: boolean\n}\n\n/** Radius of a new texture effect, as Figma's effects panel starts one. */\nconst DEFAULT_TEXTURE_RADIUS = 4\n\nfunction noiseSize(size: NoiseSize | undefined, fallback: Vector): Vector {\n if (size === undefined) return { ...fallback }\n return typeof size === 'number' ? { x: size, y: size } : { ...size }\n}\n\n/**\n * A noise effect. A duotone's second colour starts white at the first colour's opacity and a\n * multitone's opacity at that opacity, as Figma's panel switches them.\n */\nexport function noise(options: NoiseEffectOptions = {}): Effect {\n const color = options.color === undefined ? { ...DEFAULT_NOISE_COLOR } : toColor(options.color)\n const params: NoiseEffectParams = {\n noiseType: options.noiseType ?? DEFAULT_NOISE.noiseType,\n noiseSize: noiseSize(options.noiseSize, DEFAULT_NOISE.noiseSize),\n density: options.density ?? DEFAULT_NOISE.density\n }\n // A second colour or opacity given is kept whatever the type, so switching back finds it; a\n // duotone or multitone that lacks one starts where Figma's panel does.\n if (options.secondaryColor !== undefined) params.secondaryColor = toColor(options.secondaryColor)\n else if (params.noiseType === 'DUOTONE') params.secondaryColor = { r: 1, g: 1, b: 1, a: color.a }\n if (options.opacity !== undefined) params.opacity = options.opacity\n else if (params.noiseType === 'MULTITONE') params.opacity = color.a\n if (options.seed !== undefined) params.seed = options.seed\n return { type: 'NOISE', color, visible: options.visible ?? true, noise: params }\n}\n\n/** A texture effect, which roughens the layer's edges by `radius`. */\nexport function texture(options: TextureEffectOptions = {}): Effect {\n const params: TextureEffectParams = {\n noiseSize: noiseSize(options.noiseSize, DEFAULT_TEXTURE.noiseSize),\n clipToShape: options.clipToShape ?? DEFAULT_TEXTURE.clipToShape\n }\n if (options.seed !== undefined) params.seed = options.seed\n return {\n type: 'TEXTURE',\n color: { ...BLACK },\n radius: options.radius ?? DEFAULT_TEXTURE_RADIUS,\n visible: options.visible ?? true,\n texture: params\n }\n}\n"],"mappings":";;;;;AAuCA,MAAM,wBAAwB;AAE9B,SAAS,QAAQ,OAAuC;CACtD,IAAI,UAAU,KAAA,GAAW,OAAO,EAAE,GAAG,YAAY;CACjD,OAAO,OAAO,UAAU,WAAW,WAAW,KAAK,IAAI;AACzD;;AAGA,SAAS,gBAAgB,WAAsD;CAC7E,OAAO,cAAc,KAAA,IAAY,KAAA,IAAY,WAAW,MAAM,SAAS;AACzE;AAEA,SAAS,aAAa,MAAsC,SAAsC;CAChG,OAAO;EACL;EACA,OAAO,QAAQ,QAAQ,SAAS,qBAAqB;EACrD,QAAQ,QAAQ,UAAU;GAAE,GAAG,QAAQ,KAAK;GAAG,GAAG,QAAQ,KAAK;EAAE;EACjE,QAAQ,QAAQ,UAAU;EAC1B,QAAQ,QAAQ,UAAU;EAC1B,SAAS,QAAQ,WAAW;EAC5B,WAAW,gBAAgB,QAAQ,SAAS;EAC5C,sBAAsB,QAAQ;CAChC;AACF;AAEA,SAAS,WACP,MACA,kBAA8C,CAAC,GACvC;CACR,MAAM,UACJ,OAAO,oBA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