@pairdraw/design-jsx 0.0.0-stage → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/chunks/attributes.js +32 -0
  4. package/dist/chunks/attributes.js.map +1 -0
  5. package/dist/chunks/behaviours/elements.js +321 -0
  6. package/dist/chunks/behaviours/elements.js.map +1 -0
  7. package/dist/chunks/behaviours/render.js +368 -0
  8. package/dist/chunks/behaviours/render.js.map +1 -0
  9. package/dist/chunks/component-properties.js +809 -0
  10. package/dist/chunks/component-properties.js.map +1 -0
  11. package/dist/chunks/components.js +78 -0
  12. package/dist/chunks/components.js.map +1 -0
  13. package/dist/chunks/connectors.js +290 -0
  14. package/dist/chunks/connectors.js.map +1 -0
  15. package/dist/chunks/effects.js +57 -0
  16. package/dist/chunks/effects.js.map +1 -0
  17. package/dist/chunks/elements.js +618 -0
  18. package/dist/chunks/elements.js.map +1 -0
  19. package/dist/chunks/export/behaviours.js +113 -0
  20. package/dist/chunks/export/behaviours.js.map +1 -0
  21. package/dist/chunks/export/bindings.js +273 -0
  22. package/dist/chunks/export/bindings.js.map +1 -0
  23. package/dist/chunks/export/decoration.js +96 -0
  24. package/dist/chunks/export/decoration.js.map +1 -0
  25. package/dist/chunks/export/font.js +17 -0
  26. package/dist/chunks/export/font.js.map +1 -0
  27. package/dist/chunks/export/icons.js +34 -0
  28. package/dist/chunks/export/icons.js.map +1 -0
  29. package/dist/chunks/export/index.js +1390 -0
  30. package/dist/chunks/export/index.js.map +1 -0
  31. package/dist/chunks/fields.js +1065 -0
  32. package/dist/chunks/fields.js.map +1 -0
  33. package/dist/chunks/index.js +438 -0
  34. package/dist/chunks/index.js.map +1 -0
  35. package/dist/chunks/jsx-dev-runtime.js +16 -0
  36. package/dist/chunks/jsx-dev-runtime.js.map +1 -0
  37. package/dist/index.d.ts +543 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +11 -0
  40. package/dist/jsx-dev-runtime.d.ts +2 -0
  41. package/dist/jsx-dev-runtime.js +2 -0
  42. package/dist/jsx-runtime.d.ts +44 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/tree.d.ts +261 -0
  46. package/dist/tree.d.ts.map +1 -0
  47. package/package.json +54 -4
  48. package/src/attributes.ts +30 -0
  49. package/src/behaviours/elements.ts +47 -0
  50. package/src/behaviours/index.ts +253 -0
  51. package/src/behaviours/render.ts +144 -0
  52. package/src/component-properties.ts +428 -0
  53. package/src/components.ts +109 -0
  54. package/src/connectors.ts +316 -0
  55. package/src/definitions.ts +277 -0
  56. package/src/effects.ts +80 -0
  57. package/src/elements.ts +321 -0
  58. package/src/enums.ts +182 -0
  59. package/src/export/behaviours.ts +143 -0
  60. package/src/export/bindings.ts +155 -0
  61. package/src/export/decoration.ts +39 -0
  62. package/src/export/font.ts +25 -0
  63. package/src/export/helpers.ts +75 -0
  64. package/src/export/icons.ts +42 -0
  65. package/src/export/index.ts +297 -0
  66. package/src/export/paint.ts +276 -0
  67. package/src/export/props.ts +369 -0
  68. package/src/export/state.ts +52 -0
  69. package/src/export/text.ts +155 -0
  70. package/src/export/value.ts +99 -0
  71. package/src/export/variables.ts +393 -0
  72. package/src/fields.ts +39 -0
  73. package/src/figjam-text.ts +37 -0
  74. package/src/global.d.ts +4 -0
  75. package/src/helpers.ts +135 -0
  76. package/src/index.ts +155 -0
  77. package/src/jsx-dev-runtime.ts +1 -0
  78. package/src/jsx-runtime.ts +51 -0
  79. package/src/mini-react.ts +23 -0
  80. package/src/overrides/effects.ts +39 -0
  81. package/src/overrides/fills.ts +56 -0
  82. package/src/overrides/state.ts +55 -0
  83. package/src/overrides/strokes.ts +109 -0
  84. package/src/overrides/text.ts +116 -0
  85. package/src/overrides/vector.ts +122 -0
  86. package/src/paints.ts +230 -0
  87. package/src/props-overrides.ts +481 -0
  88. package/src/reconcile.ts +134 -0
  89. package/src/reference/authoring.md +76 -0
  90. package/src/reference/examples.ts +49 -0
  91. package/src/reference.ts +19 -0
  92. package/src/refs.ts +48 -0
  93. package/src/render.ts +147 -0
  94. package/src/renderer.ts +598 -0
  95. package/src/scalar-bindings.ts +36 -0
  96. package/src/schema.ts +213 -0
  97. package/src/services.ts +36 -0
  98. package/src/shapes-with-text.ts +73 -0
  99. package/src/stickies.ts +72 -0
  100. package/src/streaming/index.ts +47 -0
  101. package/src/streaming/literals.ts +82 -0
  102. package/src/streaming/projection.ts +189 -0
  103. package/src/text-content.ts +233 -0
  104. package/src/transform.ts +78 -0
  105. package/src/tree.ts +285 -0
  106. package/src/types.ts +13 -0
  107. package/src/variables/graph.ts +265 -0
  108. package/src/variables/index.ts +124 -0
  109. package/src/variables/props.ts +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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\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: Record<string, unknown>, 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 own dash pattern, separate from the stroke-local dash `strokeDash` sets.\n const nodeDash = dashValue(props.dashPattern)\n if (nodeDash) o.dashPattern = nodeDash\n\n if (Array.isArray(props.strokes)) {\n const strokes = props.strokes.filter(isStrokeValue).map(toStroke)\n if (strokes.length > 0) o.strokes = strokes\n return\n }\n\n const color = designJSXProp(props, 'stroke')\n if (typeof color !== 'string' && !isColor(color)) return\n o.strokes = [\n toStroke({\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\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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AAa;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"}
@@ -0,0 +1,78 @@
1
+ import { node } from "./behaviours/elements.js";
2
+ //#region src/components.ts
3
+ function withChildren(type, props, children) {
4
+ if (children.length > 0) return node(type, {
5
+ ...props,
6
+ children
7
+ });
8
+ return node(type, props);
9
+ }
10
+ function Frame(props, ...children) {
11
+ return withChildren("frame", props, children);
12
+ }
13
+ function Text(props, ...children) {
14
+ return withChildren("text", props, children);
15
+ }
16
+ function Span(props, ...children) {
17
+ return withChildren("text-span", props, children);
18
+ }
19
+ function Paragraph(props, ...children) {
20
+ return withChildren("text-paragraph", props, children);
21
+ }
22
+ function Rectangle(props, ...children) {
23
+ return withChildren("rectangle", props, children);
24
+ }
25
+ function Ellipse(props, ...children) {
26
+ return withChildren("ellipse", props, children);
27
+ }
28
+ function Line(props, ...children) {
29
+ return withChildren("line", props, children);
30
+ }
31
+ function Star(props, ...children) {
32
+ return withChildren("star", props, children);
33
+ }
34
+ function Polygon(props, ...children) {
35
+ return withChildren("polygon", props, children);
36
+ }
37
+ function Vector(props, ...children) {
38
+ return withChildren("vector", props, children);
39
+ }
40
+ function Group(props, ...children) {
41
+ return withChildren("group", props, children);
42
+ }
43
+ function Section(props, ...children) {
44
+ return withChildren("section", props, children);
45
+ }
46
+ function Component(props, ...children) {
47
+ return withChildren("component", props, children);
48
+ }
49
+ function ComponentSet(props, ...children) {
50
+ return withChildren("component-set", props, children);
51
+ }
52
+ function Instance(props, ...children) {
53
+ return withChildren("instance", props, children);
54
+ }
55
+ const View = Frame;
56
+ const Rect = Rectangle;
57
+ const Page = Frame;
58
+ const INTRINSIC_ELEMENTS = [
59
+ "frame",
60
+ "text",
61
+ "text-span",
62
+ "text-paragraph",
63
+ "rectangle",
64
+ "ellipse",
65
+ "line",
66
+ "star",
67
+ "polygon",
68
+ "vector",
69
+ "group",
70
+ "section",
71
+ "component",
72
+ "component-set",
73
+ "instance"
74
+ ];
75
+ //#endregion
76
+ export { Component, ComponentSet, Ellipse, Frame, Group, INTRINSIC_ELEMENTS, Instance, Line, Page, Paragraph, Polygon, Rect, Rectangle, Section, Span, Star, Text, Vector, View };
77
+
78
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","names":[],"sources":["../../src/components.ts"],"sourcesContent":["import {\n node,\n type BaseProps,\n type EllipseProps,\n type VectorProps,\n type ComponentProps,\n type InstanceProps,\n type ParagraphProps,\n type SpanProps,\n type TextProps,\n type TreeNode\n} from './tree'\n\ntype Child = TreeNode | string\n\nfunction withChildren(type: string, props: Record<string, unknown>, children: Child[]): TreeNode {\n if (children.length > 0) {\n return node(type, { ...props, children })\n }\n return node(type, props)\n}\n\nexport function Frame(props: BaseProps, ...children: Child[]): TreeNode {\n return withChildren('frame', props, children)\n}\n\nexport function Text(props: TextProps, ...children: Child[]): TreeNode {\n return withChildren('text', props, children)\n}\n\nexport function Span(props: SpanProps, ...children: Child[]): TreeNode {\n return withChildren('text-span', props, children)\n}\n\nexport function Paragraph(props: ParagraphProps, ...children: Child[]): TreeNode {\n return withChildren('text-paragraph', props, children)\n}\n\nexport function Rectangle(props: BaseProps, ...children: Child[]): TreeNode {\n return withChildren('rectangle', props, children)\n}\n\nexport function Ellipse(props: BaseProps & EllipseProps, ...children: Child[]): TreeNode {\n return withChildren('ellipse', props, children)\n}\n\nexport function Line(props: BaseProps, ...children: Child[]): TreeNode {\n return withChildren('line', props, children)\n}\n\nexport function Star(\n props: BaseProps & { points?: number; innerRadius?: number },\n ...children: Child[]\n): TreeNode {\n return withChildren('star', props, children)\n}\n\nexport function Polygon(\n props: BaseProps & { pointCount?: number },\n ...children: Child[]\n): TreeNode {\n return withChildren('polygon', props, children)\n}\n\nexport function Vector(props: BaseProps & VectorProps, ...children: Child[]): TreeNode {\n return withChildren('vector', props, children)\n}\n\nexport function Group(props: BaseProps, ...children: Child[]): TreeNode {\n return withChildren('group', props, children)\n}\n\nexport function Section(props: BaseProps, ...children: Child[]): TreeNode {\n return withChildren('section', props, children)\n}\n\nexport function Component(props: ComponentProps, ...children: Child[]): TreeNode {\n return withChildren('component', props, children)\n}\n\nexport function ComponentSet(props: ComponentProps, ...children: Child[]): TreeNode {\n return withChildren('component-set', props, children)\n}\n\nexport function Instance(props: InstanceProps, ...children: Child[]): TreeNode {\n return withChildren('instance', props, children)\n}\n\nexport const View = Frame\nexport const Rect = Rectangle\nexport const Page = Frame\n\nexport const INTRINSIC_ELEMENTS = [\n 'frame',\n 'text',\n 'text-span',\n 'text-paragraph',\n 'rectangle',\n 'ellipse',\n 'line',\n 'star',\n 'polygon',\n 'vector',\n 'group',\n 'section',\n 'component',\n 'component-set',\n 'instance'\n] as const\n"],"mappings":";;AAeA,SAAS,aAAa,MAAc,OAAgC,UAA6B;CAC/F,IAAI,SAAS,SAAS,GACpB,OAAO,KAAK,MAAM;EAAE,GAAG;EAAO;CAAS,CAAC;CAE1C,OAAO,KAAK,MAAM,KAAK;AACzB;AAEA,SAAgB,MAAM,OAAkB,GAAG,UAA6B;CACtE,OAAO,aAAa,SAAS,OAAO,QAAQ;AAC9C;AAEA,SAAgB,KAAK,OAAkB,GAAG,UAA6B;CACrE,OAAO,aAAa,QAAQ,OAAO,QAAQ;AAC7C;AAEA,SAAgB,KAAK,OAAkB,GAAG,UAA6B;CACrE,OAAO,aAAa,aAAa,OAAO,QAAQ;AAClD;AAEA,SAAgB,UAAU,OAAuB,GAAG,UAA6B;CAC/E,OAAO,aAAa,kBAAkB,OAAO,QAAQ;AACvD;AAEA,SAAgB,UAAU,OAAkB,GAAG,UAA6B;CAC1E,OAAO,aAAa,aAAa,OAAO,QAAQ;AAClD;AAEA,SAAgB,QAAQ,OAAiC,GAAG,UAA6B;CACvF,OAAO,aAAa,WAAW,OAAO,QAAQ;AAChD;AAEA,SAAgB,KAAK,OAAkB,GAAG,UAA6B;CACrE,OAAO,aAAa,QAAQ,OAAO,QAAQ;AAC7C;AAEA,SAAgB,KACd,OACA,GAAG,UACO;CACV,OAAO,aAAa,QAAQ,OAAO,QAAQ;AAC7C;AAEA,SAAgB,QACd,OACA,GAAG,UACO;CACV,OAAO,aAAa,WAAW,OAAO,QAAQ;AAChD;AAEA,SAAgB,OAAO,OAAgC,GAAG,UAA6B;CACrF,OAAO,aAAa,UAAU,OAAO,QAAQ;AAC/C;AAEA,SAAgB,MAAM,OAAkB,GAAG,UAA6B;CACtE,OAAO,aAAa,SAAS,OAAO,QAAQ;AAC9C;AAEA,SAAgB,QAAQ,OAAkB,GAAG,UAA6B;CACxE,OAAO,aAAa,WAAW,OAAO,QAAQ;AAChD;AAEA,SAAgB,UAAU,OAAuB,GAAG,UAA6B;CAC/E,OAAO,aAAa,aAAa,OAAO,QAAQ;AAClD;AAEA,SAAgB,aAAa,OAAuB,GAAG,UAA6B;CAClF,OAAO,aAAa,iBAAiB,OAAO,QAAQ;AACtD;AAEA,SAAgB,SAAS,OAAsB,GAAG,UAA6B;CAC7E,OAAO,aAAa,YAAY,OAAO,QAAQ;AACjD;AAEA,MAAa,OAAO;AACpB,MAAa,OAAO;AACpB,MAAa,OAAO;AAEpB,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,290 @@
1
+ import { plainTextOf } from "./behaviours/elements.js";
2
+ import { CONNECTOR_LINE, CONNECTOR_SIDE, STROKE_CAP, connectorPropsSchema, isLayerRef, readElementProps } from "./component-properties.js";
3
+ import { colorToHex } from "@pairdraw/scene-graph/color";
4
+ import { isGeneratedFrame } from "@pairdraw/scene-graph/generated";
5
+ import { compact, countBy } from "es-toolkit/array";
6
+ import { camelCase } from "es-toolkit/string";
7
+ import { es, jsx } from "@pairdraw/emit";
8
+ import { CONNECTOR_COLOR, CONNECTOR_NAME, CONNECTOR_STROKE_WEIGHT, boundEndpoint, connectorRouteEnds, connectorStroke, connectorSublayers, createConnector, freeEndpoint } from "@pairdraw/scene-graph/connectors";
9
+ //#region src/export/value.ts
10
+ /** A paint, effect, or variable helper call inside a prop value, such as `solid("#FF0000")`. */
11
+ var HelperCall = class {
12
+ helper;
13
+ args;
14
+ constructor(helper, args) {
15
+ this.helper = helper;
16
+ this.args = args;
17
+ }
18
+ };
19
+ /**
20
+ * A name the export declares before the JSX, such as the `card1` of `ref={card1}`, or one of its
21
+ * members, such as the `theme.Page` of a variable `defineVars` declared.
22
+ */
23
+ var Reference = class {
24
+ name;
25
+ member;
26
+ constructor(name, member) {
27
+ this.name = name;
28
+ this.member = member;
29
+ }
30
+ };
31
+ /** A call with trailing undefined arguments dropped, so defaults stay implicit. */
32
+ function helperCall(helper, ...args) {
33
+ const last = args.findLastIndex((arg) => arg !== void 0);
34
+ return new HelperCall(helper, args.slice(0, last + 1).map((arg) => arg ?? null));
35
+ }
36
+ function isRecord(value) {
37
+ return typeof value === "object" && value !== null && !Array.isArray(value);
38
+ }
39
+ /**
40
+ * Plain scene data, such as a paint with no helper, as a prop value. Throws on values JSX
41
+ * cannot write back, such as binary data.
42
+ */
43
+ function plainValue(value) {
44
+ if (value instanceof Reference) return value;
45
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
46
+ if (typeof value === "number" && Number.isFinite(value)) return value;
47
+ if (Array.isArray(value)) return value.map(plainValue);
48
+ if (isRecord(value)) return Object.fromEntries(Object.entries(value).flatMap(([key, item]) => item === void 0 ? [] : [[key, plainValue(item)]]));
49
+ throw new TypeError(`Cannot write a ${typeof value} value as JSX`);
50
+ }
51
+ /** The expression for a value, printed through the emit builders. */
52
+ function valueSyntax(value) {
53
+ if (value === null) return {
54
+ type: "Literal",
55
+ value: null
56
+ };
57
+ if (value instanceof HelperCall) return es.call(value.helper, value.args.map(valueSyntax));
58
+ if (value instanceof Reference) return value.member === void 0 ? es.identifier(value.name) : es.member(es.identifier(value.name), value.member);
59
+ if (Array.isArray(value)) return es.array(value.map(valueSyntax));
60
+ if (typeof value === "object") return es.object(Object.entries(value).flatMap(([key, item]) => item === void 0 ? [] : [[key, valueSyntax(item)]]));
61
+ return jsx.literal(value);
62
+ }
63
+ function propValue(value) {
64
+ if (value === true) return null;
65
+ if (typeof value === "string") return jsx.stringValue(value);
66
+ return jsx.container(valueSyntax(value));
67
+ }
68
+ /**
69
+ * A prop as a JSX attribute: `true` prints the bare name, strings as attribute strings, and
70
+ * other values as expressions, with paint and effect helpers as calls.
71
+ */
72
+ function propAttribute([name, value]) {
73
+ return jsx.attribute(name, propValue(value));
74
+ }
75
+ //#endregion
76
+ //#region src/connectors.ts
77
+ /**
78
+ * `<Connector from="A" to="B">`: a FigJam connector whose ends name other layers of the same
79
+ * JSX, or give `{ x, y }` points in its parent. Ends resolve once the whole tree is rendered, and
80
+ * the connector routes once it is laid out.
81
+ */
82
+ const CONNECTOR_ELEMENT = "connector";
83
+ /**
84
+ * Makes the connector an element describes, with `layer`'s fields, its ends free until
85
+ * `resolveConnectorEnds`.
86
+ */
87
+ function renderConnectorNode(graph, tree, parentId, layer) {
88
+ const props = readElementProps(connectorPropsSchema, tree.props);
89
+ const parent = graph.getNode(parentId);
90
+ const connector = createConnector(graph, parentId, {
91
+ start: freeEndpoint(0, 0),
92
+ end: freeEndpoint(0, 0),
93
+ lineType: props.line,
94
+ startCap: props.startCap ?? "NONE",
95
+ endCap: props.endCap ?? "ARROW_LINES",
96
+ text: plainTextOf(tree)
97
+ }, {
98
+ ...layer,
99
+ ...parent && parent.layoutMode !== "NONE" && { layoutPositioning: "ABSOLUTE" }
100
+ });
101
+ const lineLayer = connectorSublayers(graph, connector)?.line;
102
+ if (lineLayer) styleLine(graph, lineLayer, props);
103
+ return connector;
104
+ }
105
+ /** The layer a connector's variable binding goes on: its line for the stroke, else itself. */
106
+ function connectorBindingTarget(graph, connector, field) {
107
+ return (field.startsWith("strokes/") || field === "strokeWeight") && connectorSublayers(graph, connector)?.line.id || connector.id;
108
+ }
109
+ /** Restyles the line by `stroke`, `strokeWidth`, and `dashPattern`; each left out keeps FigJam's. */
110
+ function styleLine(graph, line, props) {
111
+ const [stroke = connectorStroke()] = line.strokes;
112
+ const color = props.stroke ?? stroke.color;
113
+ const weight = props.strokeWidth ?? stroke.weight;
114
+ const dashPattern = props.dashPattern ?? line.dashPattern;
115
+ graph.updateNode(line.id, {
116
+ strokes: [{
117
+ ...stroke,
118
+ color,
119
+ weight,
120
+ dashPattern: [...dashPattern]
121
+ }],
122
+ strokeWeight: weight,
123
+ dashPattern
124
+ });
125
+ }
126
+ /**
127
+ * The layers JSX writes under `rootIds`, in order, each before its descendants: the layers a
128
+ * connector or sticky note generates are not, so an end never names them.
129
+ */
130
+ function layersUnder(graph, rootIds) {
131
+ const layers = [];
132
+ const visit = (id) => {
133
+ const node = graph.getNode(id);
134
+ if (!node) return;
135
+ layers.push(node);
136
+ if (!isGeneratedFrame(node)) for (const childId of node.childIds) visit(childId);
137
+ };
138
+ for (const id of rootIds) visit(id);
139
+ return layers;
140
+ }
141
+ /** A connector end's prop as a warning quotes it. */
142
+ function endSource(prop, value) {
143
+ if (isLayerRef(value)) return `${prop}={ref}`;
144
+ return `${prop}="${String(value)}"`;
145
+ }
146
+ /**
147
+ * Binds the ends of connectors rendered from `trees` to the layers they refer to: a `ref()` a
148
+ * layer was marked with, or a name among `rootIds`' layers, the first of a name winning. Returns
149
+ * warnings for ends that refer to no layer, and for names that more than one layer has.
150
+ */
151
+ function resolveConnectorEnds(graph, rootIds, connectors, refs) {
152
+ if (connectors.length === 0) return [];
153
+ const named = /* @__PURE__ */ new Map();
154
+ for (const layer of layersUnder(graph, rootIds)) {
155
+ if (layer.type === "CONNECTOR") continue;
156
+ const ids = named.get(layer.name);
157
+ if (ids) ids.push(layer.id);
158
+ else named.set(layer.name, [layer.id]);
159
+ }
160
+ const warnings = [];
161
+ const endpoint = (prop, props, written, straight) => {
162
+ const value = props[prop];
163
+ let id;
164
+ if (isLayerRef(value)) id = refs.layerOf(value);
165
+ else if (typeof value === "object") return freeEndpoint(value.x, value.y);
166
+ else if (typeof value === "string") {
167
+ const ids = named.get(value) ?? [];
168
+ if (ids.length > 1) warnings.push(`<Connector> ${endSource(prop, value)} names ${ids.length} layers and joins the first; mark the one to join with ref().`);
169
+ id = ids.at(0);
170
+ }
171
+ if (!id) {
172
+ const missing = isLayerRef(value) ? "refers to no layer" : "names no layer";
173
+ warnings.push(`<Connector> ${endSource(prop, written[prop])} ${missing}.`);
174
+ return null;
175
+ }
176
+ const side = props[prop === "from" ? "fromSide" : "toSide"];
177
+ return boundEndpoint(id, straight ? "CENTER" : side ?? "AUTO");
178
+ };
179
+ for (const { node, tree } of connectors) {
180
+ const straight = node.connectorLineType === "STRAIGHT";
181
+ const props = readElementProps(connectorPropsSchema, tree.props);
182
+ const start = endpoint("from", props, tree.props, straight);
183
+ const end = endpoint("to", props, tree.props, straight);
184
+ graph.updateNode(node.id, {
185
+ ...start && { connectorStart: start },
186
+ ...end && { connectorEnd: end }
187
+ });
188
+ }
189
+ return warnings;
190
+ }
191
+ /** `card1` for a layer named "Card": a name a declaration can take, numbered to stay unique. */
192
+ function refName(layerName, taken) {
193
+ const camel = camelCase(layerName);
194
+ const base = es.isIdentifierName(camel) ? camel : "layer";
195
+ let count = 1;
196
+ while (taken.has(`${base}${count}`)) count++;
197
+ const name = `${base}${count}`;
198
+ taken.add(name);
199
+ return name;
200
+ }
201
+ /**
202
+ * Plans how the connectors under `rootIds` write their ends. With `declare`, a joined layer
203
+ * whose name is not unique gets a `ref()` the export declares before its JSX.
204
+ */
205
+ function connectorExportScope(graph, rootIds, declare) {
206
+ const layers = layersUnder(graph, rootIds);
207
+ const connectors = layers.filter((layer) => layer.type === "CONNECTOR");
208
+ const refs = /* @__PURE__ */ new Map();
209
+ if (connectors.length === 0) return {
210
+ roots: new Set(rootIds),
211
+ refs
212
+ };
213
+ const joined = new Set(connectors.flatMap((connector) => [connector.connectorStart?.nodeId, connector.connectorEnd?.nodeId]));
214
+ const named = countBy(layers.filter((layer) => layer.type !== "CONNECTOR"), (layer) => layer.name);
215
+ const taken = /* @__PURE__ */ new Set();
216
+ for (const layer of layers) {
217
+ if (!joined.has(layer.id) || (named[layer.name] ?? 0) < 2) continue;
218
+ refs.set(layer.id, declare ? refName(layer.name, taken) : null);
219
+ }
220
+ return {
221
+ roots: new Set(rootIds),
222
+ refs
223
+ };
224
+ }
225
+ /** `const card1 = ref()` for each ref the scope declares, one per line. */
226
+ function connectorRefDeclarations(scope) {
227
+ return compact([...scope.refs.values()]).map((name) => `const ${name} = ref()`).join("\n");
228
+ }
229
+ function endTarget(graph, endpoint, drawn, scope) {
230
+ const layer = endpoint.nodeId ? graph.getNode(endpoint.nodeId) : void 0;
231
+ if (!layer) return { point: endpoint.position };
232
+ const exported = !scope || graph.closest(layer.id, (ancestor) => scope.roots.has(ancestor.id)) !== void 0;
233
+ const ref = scope?.refs.get(layer.id);
234
+ if (exported && ref !== null) return {
235
+ layer,
236
+ ref
237
+ };
238
+ return { point: drawn ?? endpoint.position };
239
+ }
240
+ /**
241
+ * A connector's props as `<Connector>` writes them, its ends by the names of their layers, or by
242
+ * the refs `scope` declares for layers whose names are not unique. An end on a layer outside the
243
+ * export, or one the scope gives no ref, is written as the point it is drawn at.
244
+ */
245
+ function connectorProps(graph, node, scope) {
246
+ const drawn = connectorRouteEnds(graph, node);
247
+ const target = (endpoint, at) => endpoint ? endTarget(graph, endpoint, at, scope) : null;
248
+ const start = target(node.connectorStart, drawn?.start);
249
+ const end = target(node.connectorEnd, drawn?.end);
250
+ const value = (written) => {
251
+ if (!written) return null;
252
+ if ("point" in written) return {
253
+ x: written.point.x,
254
+ y: written.point.y
255
+ };
256
+ return written.ref ? new Reference(written.ref) : written.layer.name;
257
+ };
258
+ const side = (endpoint, written) => {
259
+ if (!endpoint || !written || "point" in written) return void 0;
260
+ const magnet = endpoint.magnet;
261
+ if (magnet !== "TOP" && magnet !== "RIGHT" && magnet !== "BOTTOM" && magnet !== "LEFT") return;
262
+ return CONNECTOR_SIDE.print(magnet);
263
+ };
264
+ const props = [
265
+ ["name", node.name === CONNECTOR_NAME ? void 0 : node.name],
266
+ ["from", value(start)],
267
+ ["to", value(end)],
268
+ ["fromSide", side(node.connectorStart, start)],
269
+ ["toSide", side(node.connectorEnd, end)],
270
+ ["line", node.connectorLineType === "ELBOWED" ? void 0 : CONNECTOR_LINE.print(node.connectorLineType)],
271
+ ["startCap", node.connectorStartCap === "NONE" ? void 0 : STROKE_CAP.print(node.connectorStartCap)],
272
+ ["endCap", node.connectorEndCap === "ARROW_LINES" ? void 0 : STROKE_CAP.print(node.connectorEndCap)]
273
+ ];
274
+ const line = connectorSublayers(graph, node)?.line;
275
+ const stroke = line?.strokes[0];
276
+ if (stroke && colorToHex(stroke.color) !== colorToHex(CONNECTOR_COLOR)) props.push(["stroke", colorToHex(stroke.color)]);
277
+ if (stroke && stroke.weight !== CONNECTOR_STROKE_WEIGHT) props.push(["strokeWidth", stroke.weight]);
278
+ if (line && line.dashPattern.length > 0) props.push(["dashPattern", [...line.dashPattern]]);
279
+ if (node.opacity < 1) props.push(["opacity", Math.round(node.opacity * 100) / 100]);
280
+ if (!node.visible) props.push(["visible", false]);
281
+ return props.filter(([, value]) => value !== void 0 && value !== null);
282
+ }
283
+ /** The label a connector writes as its children. */
284
+ function connectorLabel(graph, node) {
285
+ return connectorSublayers(graph, node)?.label.text ?? "";
286
+ }
287
+ //#endregion
288
+ export { CONNECTOR_ELEMENT, Reference, connectorBindingTarget, connectorExportScope, connectorLabel, connectorProps, connectorRefDeclarations, helperCall, layersUnder, plainValue, propAttribute, renderConnectorNode, resolveConnectorEnds, valueSyntax };
289
+
290
+ //# sourceMappingURL=connectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectors.js","names":[],"sources":["../../src/export/value.ts","../../src/connectors.ts"],"sourcesContent":["import { es, jsx, type SyntaxNode } from '@pairdraw/emit'\n\n/** A paint, effect, or variable helper call inside a prop value, such as `solid(\"#FF0000\")`. */\nexport class HelperCall {\n constructor(\n readonly helper: string,\n readonly args: JSXValue[]\n ) {}\n}\n\n/**\n * A name the export declares before the JSX, such as the `card1` of `ref={card1}`, or one of its\n * members, such as the `theme.Page` of a variable `defineVars` declared.\n */\nexport class Reference {\n constructor(\n readonly name: string,\n readonly member?: string\n ) {}\n}\n\n/** A prop value: plain data, possibly holding helper calls. Undefined object fields are left out. */\nexport type JSXValue =\n | string\n | number\n | boolean\n | null\n | HelperCall\n | Reference\n | JSXValue[]\n | { [key: string]: JSXValue | undefined }\n\n/** A prop name and its value. */\nexport type JSXProp = [name: string, value: JSXValue]\n\n/** A call with trailing undefined arguments dropped, so defaults stay implicit. */\nexport function helperCall(helper: string, ...args: (JSXValue | undefined)[]): HelperCall {\n const last = args.findLastIndex((arg) => arg !== undefined)\n return new HelperCall(\n helper,\n args.slice(0, last + 1).map((arg) => arg ?? null)\n )\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/**\n * Plain scene data, such as a paint with no helper, as a prop value. Throws on values JSX\n * cannot write back, such as binary data.\n */\nexport function plainValue(value: unknown): JSXValue {\n if (value instanceof Reference) return value\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return value\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (Array.isArray(value)) return value.map(plainValue)\n if (isRecord(value)) {\n return Object.fromEntries(\n Object.entries(value).flatMap(([key, item]) =>\n item === undefined ? [] : [[key, plainValue(item)]]\n )\n )\n }\n throw new TypeError(`Cannot write a ${typeof value} value as JSX`)\n}\n\n/** The expression for a value, printed through the emit builders. */\nexport function valueSyntax(value: JSXValue): SyntaxNode {\n if (value === null) return { type: 'Literal', value: null }\n if (value instanceof HelperCall) return es.call(value.helper, value.args.map(valueSyntax))\n if (value instanceof Reference)\n return value.member === undefined\n ? es.identifier(value.name)\n : es.member(es.identifier(value.name), value.member)\n if (Array.isArray(value)) return es.array(value.map(valueSyntax))\n if (typeof value === 'object') {\n return es.object(\n Object.entries(value).flatMap(([key, item]) =>\n item === undefined ? [] : [[key, valueSyntax(item)] as const]\n )\n )\n }\n return jsx.literal(value)\n}\n\nfunction propValue(value: JSXValue): SyntaxNode | null {\n if (value === true) return null\n if (typeof value === 'string') return jsx.stringValue(value)\n return jsx.container(valueSyntax(value))\n}\n\n/**\n * A prop as a JSX attribute: `true` prints the bare name, strings as attribute strings, and\n * other values as expressions, with paint and effect helpers as calls.\n */\nexport function propAttribute([name, value]: JSXProp): SyntaxNode {\n return jsx.attribute(name, propValue(value))\n}\n","import { compact, countBy } from 'es-toolkit/array'\nimport { camelCase } from 'es-toolkit/string'\nimport type * as v from 'valibot'\n\nimport { es } from '@pairdraw/emit'\nimport type { ConnectorEndpoint, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport {\n boundEndpoint,\n CONNECTOR_COLOR,\n CONNECTOR_NAME,\n CONNECTOR_STROKE_WEIGHT,\n connectorRouteEnds,\n connectorStroke,\n connectorSublayers,\n createConnector,\n freeEndpoint\n} from '@pairdraw/scene-graph/connectors'\nimport { isGeneratedFrame } from '@pairdraw/scene-graph/generated'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { CONNECTOR_LINE, CONNECTOR_SIDE, STROKE_CAP } from './enums'\nimport { Reference } from './export/value'\nimport { isLayerRef, type LayerRefs } from './refs'\nimport { connectorPropsSchema, readElementProps } from './schema'\nimport { plainTextOf, type TreeNode } from './tree'\n\n/**\n * `<Connector from=\"A\" to=\"B\">`: a FigJam connector whose ends name other layers of the same\n * JSX, or give `{ x, y }` points in its parent. Ends resolve once the whole tree is rendered, and\n * the connector routes once it is laid out.\n */\nexport const CONNECTOR_ELEMENT = 'connector'\n\ntype ConnectorPropValues = v.InferOutput<typeof connectorPropsSchema>\n\n/**\n * Makes the connector an element describes, with `layer`'s fields, its ends free until\n * `resolveConnectorEnds`.\n */\nexport function renderConnectorNode(\n graph: SceneGraph,\n tree: TreeNode,\n parentId: string,\n layer: Partial<SceneNode>\n) {\n const props = readElementProps(connectorPropsSchema, tree.props)\n const parent = graph.getNode(parentId)\n const connector = createConnector(\n graph,\n parentId,\n {\n start: freeEndpoint(0, 0),\n end: freeEndpoint(0, 0),\n lineType: props.line,\n startCap: props.startCap ?? 'NONE',\n endCap: props.endCap ?? 'ARROW_LINES',\n text: plainTextOf(tree)\n },\n {\n ...layer,\n // A connector is drawn between layers, not placed by its parent's auto layout.\n ...(parent && parent.layoutMode !== 'NONE' && { layoutPositioning: 'ABSOLUTE' as const })\n }\n )\n const lineLayer = connectorSublayers(graph, connector)?.line\n if (lineLayer) styleLine(graph, lineLayer, props)\n return connector\n}\n\n/** The layer a connector's variable binding goes on: its line for the stroke, else itself. */\nexport function connectorBindingTarget(graph: SceneGraph, connector: SceneNode, field: string) {\n const onLine = field.startsWith('strokes/') || field === 'strokeWeight'\n return (onLine && connectorSublayers(graph, connector)?.line.id) || connector.id\n}\n\n/** Restyles the line by `stroke`, `strokeWidth`, and `dashPattern`; each left out keeps FigJam's. */\nfunction styleLine(graph: SceneGraph, line: SceneNode, props: ConnectorPropValues) {\n const [stroke = connectorStroke()] = line.strokes\n const color = props.stroke ?? stroke.color\n const weight = props.strokeWidth ?? stroke.weight\n const dashPattern = props.dashPattern ?? line.dashPattern\n graph.updateNode(line.id, {\n // The stroke draws with its own dash, and files keep the line's.\n strokes: [{ ...stroke, color, weight, dashPattern: [...dashPattern] }],\n strokeWeight: weight,\n dashPattern\n })\n}\n\n/**\n * The layers JSX writes under `rootIds`, in order, each before its descendants: the layers a\n * connector or sticky note generates are not, so an end never names them.\n */\nexport function layersUnder(graph: SceneGraph, rootIds: readonly string[]): SceneNode[] {\n const layers: SceneNode[] = []\n const visit = (id: string) => {\n const node = graph.getNode(id)\n if (!node) return\n layers.push(node)\n if (!isGeneratedFrame(node)) for (const childId of node.childIds) visit(childId)\n }\n for (const id of rootIds) visit(id)\n return layers\n}\n\n/** A connector end's prop as a warning quotes it. */\nfunction endSource(prop: string, value: unknown): string {\n if (isLayerRef(value)) return `${prop}={ref}`\n return `${prop}=\"${String(value)}\"`\n}\n\n/**\n * Binds the ends of connectors rendered from `trees` to the layers they refer to: a `ref()` a\n * layer was marked with, or a name among `rootIds`' layers, the first of a name winning. Returns\n * warnings for ends that refer to no layer, and for names that more than one layer has.\n */\nexport function resolveConnectorEnds(\n graph: SceneGraph,\n rootIds: readonly string[],\n connectors: ReadonlyArray<{ node: SceneNode; tree: TreeNode }>,\n refs: LayerRefs\n): string[] {\n if (connectors.length === 0) return []\n const named = new Map<string, string[]>()\n for (const layer of layersUnder(graph, rootIds)) {\n if (layer.type === 'CONNECTOR') continue\n const ids = named.get(layer.name)\n if (ids) ids.push(layer.id)\n else named.set(layer.name, [layer.id])\n }\n const warnings: string[] = []\n const endpoint = (\n prop: 'from' | 'to',\n props: ConnectorPropValues,\n written: TreeNode['props'],\n straight: boolean\n ) => {\n const value = props[prop]\n let id: string | undefined\n if (isLayerRef(value)) id = refs.layerOf(value)\n else if (typeof value === 'object') return freeEndpoint(value.x, value.y)\n else if (typeof value === 'string') {\n const ids = named.get(value) ?? []\n if (ids.length > 1) {\n warnings.push(\n `<Connector> ${endSource(prop, value)} names ${ids.length} layers and joins the first; mark the one to join with ref().`\n )\n }\n id = ids.at(0)\n }\n if (!id) {\n const missing = isLayerRef(value) ? 'refers to no layer' : 'names no layer'\n warnings.push(`<Connector> ${endSource(prop, written[prop])} ${missing}.`)\n return null\n }\n const side = props[prop === 'from' ? 'fromSide' : 'toSide']\n return boundEndpoint(id, straight ? 'CENTER' : (side ?? 'AUTO'))\n }\n for (const { node, tree } of connectors) {\n const straight = node.connectorLineType === 'STRAIGHT'\n const props = readElementProps(connectorPropsSchema, tree.props)\n const start = endpoint('from', props, tree.props, straight)\n const end = endpoint('to', props, tree.props, straight)\n graph.updateNode(node.id, {\n ...(start && { connectorStart: start }),\n ...(end && { connectorEnd: end })\n })\n }\n return warnings\n}\n\n/** `card1` for a layer named \"Card\": a name a declaration can take, numbered to stay unique. */\nfunction refName(layerName: string, taken: Set<string>): string {\n const camel = camelCase(layerName)\n const base = es.isIdentifierName(camel) ? camel : 'layer'\n let count = 1\n while (taken.has(`${base}${count}`)) count++\n const name = `${base}${count}`\n taken.add(name)\n return name\n}\n\n/** What an export of connectors writes: the layers under its roots, and how ends name them. */\nexport interface ConnectorExportScope {\n roots: ReadonlySet<string>\n /**\n * The layers connector ends join whose name another layer of the export has too, so the name\n * would not say which: each with the `ref()` the export declares for it, or `null` when the\n * export declares nothing and such an end is written as the point it is drawn at.\n */\n refs: ReadonlyMap<string, string | null>\n}\n\n/**\n * Plans how the connectors under `rootIds` write their ends. With `declare`, a joined layer\n * whose name is not unique gets a `ref()` the export declares before its JSX.\n */\nexport function connectorExportScope(\n graph: SceneGraph,\n rootIds: readonly string[],\n declare: boolean\n): ConnectorExportScope {\n const layers = layersUnder(graph, rootIds)\n const connectors = layers.filter((layer) => layer.type === 'CONNECTOR')\n const refs = new Map<string, string | null>()\n if (connectors.length === 0) return { roots: new Set(rootIds), refs }\n const joined = new Set(\n connectors.flatMap((connector) => [\n connector.connectorStart?.nodeId,\n connector.connectorEnd?.nodeId\n ])\n )\n const named = countBy(\n layers.filter((layer) => layer.type !== 'CONNECTOR'),\n (layer) => layer.name\n )\n const taken = new Set<string>()\n for (const layer of layers) {\n if (!joined.has(layer.id) || (named[layer.name] ?? 0) < 2) continue\n refs.set(layer.id, declare ? refName(layer.name, taken) : null)\n }\n return { roots: new Set(rootIds), refs }\n}\n\n/** `const card1 = ref()` for each ref the scope declares, one per line. */\nexport function connectorRefDeclarations(scope: ConnectorExportScope): string {\n return compact([...scope.refs.values()])\n .map((name) => `const ${name} = ref()`)\n .join('\\n')\n}\n\n/** How a connector end is written: by its layer's name or ref, or as the point it is drawn at. */\ntype EndTarget = { layer: SceneNode; ref?: string } | { point: Vector }\n\nfunction endTarget(\n graph: SceneGraph,\n endpoint: ConnectorEndpoint,\n drawn: Vector | undefined,\n scope: ConnectorExportScope | undefined\n): EndTarget {\n const layer = endpoint.nodeId ? graph.getNode(endpoint.nodeId) : undefined\n if (!layer) return { point: endpoint.position }\n const exported =\n !scope || graph.closest(layer.id, (ancestor) => scope.roots.has(ancestor.id)) !== undefined\n const ref = scope?.refs.get(layer.id)\n if (exported && ref !== null) return { layer, ref }\n return { point: drawn ?? endpoint.position }\n}\n\n/**\n * A connector's props as `<Connector>` writes them, its ends by the names of their layers, or by\n * the refs `scope` declares for layers whose names are not unique. An end on a layer outside the\n * export, or one the scope gives no ref, is written as the point it is drawn at.\n */\nexport function connectorProps(\n graph: SceneGraph,\n node: SceneNode,\n scope?: ConnectorExportScope\n): Array<[string, unknown]> {\n const drawn = connectorRouteEnds(graph, node)\n const target = (endpoint: ConnectorEndpoint | null, at: Vector | undefined) =>\n endpoint ? endTarget(graph, endpoint, at, scope) : null\n const start = target(node.connectorStart, drawn?.start)\n const end = target(node.connectorEnd, drawn?.end)\n const value = (written: EndTarget | null) => {\n if (!written) return null\n if ('point' in written) return { x: written.point.x, y: written.point.y }\n return written.ref ? new Reference(written.ref) : written.layer.name\n }\n const side = (endpoint: ConnectorEndpoint | null, written: EndTarget | null) => {\n if (!endpoint || !written || 'point' in written) return undefined\n const magnet = endpoint.magnet\n if (magnet !== 'TOP' && magnet !== 'RIGHT' && magnet !== 'BOTTOM' && magnet !== 'LEFT') {\n return undefined\n }\n return CONNECTOR_SIDE.print(magnet)\n }\n const props: Array<[string, unknown]> = [\n ['name', node.name === CONNECTOR_NAME ? undefined : node.name],\n ['from', value(start)],\n ['to', value(end)],\n ['fromSide', side(node.connectorStart, start)],\n ['toSide', side(node.connectorEnd, end)],\n [\n 'line',\n node.connectorLineType === 'ELBOWED'\n ? undefined\n : CONNECTOR_LINE.print(node.connectorLineType)\n ],\n [\n 'startCap',\n node.connectorStartCap === 'NONE' ? undefined : STROKE_CAP.print(node.connectorStartCap)\n ],\n [\n 'endCap',\n node.connectorEndCap === 'ARROW_LINES' ? undefined : STROKE_CAP.print(node.connectorEndCap)\n ]\n ]\n const line = connectorSublayers(graph, node)?.line\n const stroke = line?.strokes[0]\n if (stroke && colorToHex(stroke.color) !== colorToHex(CONNECTOR_COLOR)) {\n props.push(['stroke', colorToHex(stroke.color)])\n }\n if (stroke && stroke.weight !== CONNECTOR_STROKE_WEIGHT)\n props.push(['strokeWidth', stroke.weight])\n if (line && line.dashPattern.length > 0) props.push(['dashPattern', [...line.dashPattern]])\n if (node.opacity < 1) props.push(['opacity', Math.round(node.opacity * 100) / 100])\n if (!node.visible) props.push(['visible', false])\n return props.filter(([, value]) => value !== undefined && value !== null)\n}\n\n/** The label a connector writes as its children. */\nexport function connectorLabel(graph: SceneGraph, node: SceneNode): string {\n return connectorSublayers(graph, node)?.label.text ?? ''\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAa,aAAb,MAAwB;CAEX;CACA;CAFX,YACE,QACA,MACA;EAFS,KAAA,SAAA;EACA,KAAA,OAAA;CACR;AACL;;;;;AAMA,IAAa,YAAb,MAAuB;CAEV;CACA;CAFX,YACE,MACA,QACA;EAFS,KAAA,OAAA;EACA,KAAA,SAAA;CACR;AACL;;AAiBA,SAAgB,WAAW,QAAgB,GAAG,MAA4C;CACxF,MAAM,OAAO,KAAK,eAAe,QAAQ,QAAQ,KAAA,CAAS;CAC1D,OAAO,IAAI,WACT,QACA,KAAK,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,OAAO,IAAI,CAClD;AACF;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;;;AAMA,SAAgB,WAAW,OAA0B;CACnD,IAAI,iBAAiB,WAAW,OAAO;CACvC,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO;CACtF,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO;CAChE,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,UAAU;CACrD,IAAI,SAAS,KAAK,GAChB,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,UACnC,SAAS,KAAA,IAAY,CAAC,IAAI,CAAC,CAAC,KAAK,WAAW,IAAI,CAAC,CAAC,CACpD,CACF;CAEF,MAAM,IAAI,UAAU,kBAAkB,OAAO,MAAM,cAAc;AACnE;;AAGA,SAAgB,YAAY,OAA6B;CACvD,IAAI,UAAU,MAAM,OAAO;EAAE,MAAM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K,CAAC;EAC7C,CAAC,UAAU,KAAK,KAAK,cAAc,GAAG,CAAC;EACvC,CACE,QACA,KAAK,sBAAsB,YACvB,KAAA,IACA,eAAe,MAAM,KAAK,iBAAiB,CACjD;EACA,CACE,YACA,KAAK,sBAAsB,SAAS,KAAA,IAAY,WAAW,MAAM,KAAK,iBAAiB,CACzF;EACA,CACE,UACA,KAAK,oBAAoB,gBAAgB,KAAA,IAAY,WAAW,MAAM,KAAK,eAAe,CAC5F;CACF;CACA,MAAM,OAAO,mBAAmB,OAAO,IAAI,CAAC,EAAE;CAC9C,MAAM,SAAS,MAAM,QAAQ;CAC7B,IAAI,UAAU,WAAW,OAAO,KAAK,MAAM,WAAW,eAAe,GACnE,MAAM,KAAK,CAAC,UAAU,WAAW,OAAO,KAAK,CAAC,CAAC;CAEjD,IAAI,UAAU,OAAO,WAAW,yBAC9B,MAAM,KAAK,CAAC,eAAe,OAAO,MAAM,CAAC;CAC3C,IAAI,QAAQ,KAAK,YAAY,SAAS,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,WAAW,CAAC,CAAC;CAC1F,IAAI,KAAK,UAAU,GAAG,MAAM,KAAK,CAAC,WAAW,KAAK,MAAM,KAAK,UAAU,GAAG,IAAI,GAAG,CAAC;CAClF,IAAI,CAAC,KAAK,SAAS,MAAM,KAAK,CAAC,WAAW,KAAK,CAAC;CAChD,OAAO,MAAM,QAAQ,GAAG,WAAW,UAAU,KAAA,KAAa,UAAU,IAAI;AAC1E;;AAGA,SAAgB,eAAe,OAAmB,MAAyB;CACzE,OAAO,mBAAmB,OAAO,IAAI,CAAC,EAAE,MAAM,QAAQ;AACxD"}
@@ -0,0 +1,57 @@
1
+ import { parseColor } from "@pairdraw/scene-graph/color";
2
+ import { TRANSPARENT } from "@pairdraw/scene-graph/constants";
3
+ //#region src/effects.ts
4
+ /** Radius of a shadow or blur that does not set one. */
5
+ const DEFAULT_EFFECT_RADIUS = 8;
6
+ function toColor(color) {
7
+ if (color === void 0) return { ...TRANSPARENT };
8
+ return typeof color === "string" ? parseColor(color) : color;
9
+ }
10
+ function shadowEffect(type, options) {
11
+ return {
12
+ type,
13
+ color: toColor(options.color ?? "rgba(0, 0, 0, 0.25)"),
14
+ offset: options.offset ?? {
15
+ x: options.x ?? 0,
16
+ y: options.y ?? 4
17
+ },
18
+ radius: options.radius ?? DEFAULT_EFFECT_RADIUS,
19
+ spread: options.spread ?? 0,
20
+ visible: options.visible ?? true,
21
+ blendMode: options.blendMode,
22
+ showShadowBehindNode: options.showShadowBehindNode
23
+ };
24
+ }
25
+ function blurEffect(type, radiusOrOptions = {}) {
26
+ const options = typeof radiusOrOptions === "number" ? { radius: radiusOrOptions } : radiusOrOptions;
27
+ return {
28
+ type,
29
+ color: { ...TRANSPARENT },
30
+ offset: {
31
+ x: 0,
32
+ y: 0
33
+ },
34
+ radius: options.radius ?? DEFAULT_EFFECT_RADIUS,
35
+ spread: 0,
36
+ visible: options.visible ?? true
37
+ };
38
+ }
39
+ function dropShadow(options = {}) {
40
+ return shadowEffect("DROP_SHADOW", options);
41
+ }
42
+ function innerShadow(options = {}) {
43
+ return shadowEffect("INNER_SHADOW", options);
44
+ }
45
+ function layerBlur(radiusOrOptions) {
46
+ return blurEffect("LAYER_BLUR", radiusOrOptions);
47
+ }
48
+ function backgroundBlur(radiusOrOptions) {
49
+ return blurEffect("BACKGROUND_BLUR", radiusOrOptions);
50
+ }
51
+ function foregroundBlur(radiusOrOptions) {
52
+ return blurEffect("FOREGROUND_BLUR", radiusOrOptions);
53
+ }
54
+ //#endregion
55
+ export { backgroundBlur, dropShadow, foregroundBlur, innerShadow, layerBlur };
56
+
57
+ //# sourceMappingURL=effects.js.map