AI-native design editor. Open-source Figma alternative.
feat: write styled text from Markdown (#1670)
Danila Poyarkov2dd8e3adc5a4
diff --git a/bun.lock b/bun.lockindex 93a2e9ece..ca5ea410e 100644--- a/bun.lock+++ b/bun.lock@@ -306,6 +306,10 @@"jsep": "^1.4.0","jsondiffpatch": "^0.7.6","jspdf": "^4.2.1",+ "mdast-util-from-markdown": "^2.0.3",+ "mdast-util-gfm": "^3",+ "mdast-util-to-string": "^4.0.0",+ "micromark-extension-gfm": "^3","nanoevents": "^9.1.0","ofetch": "^1.5.1","parse5": "^8.0.1",@@ -326,6 +330,7 @@"@types/bun": "^1.3.14","@types/culori": "^4.0.1","@types/diff": "^8.0.0",+ "@types/mdast": "^4.0.4","@types/rbush": "^4.0.0","typescript": "npm:@typescript/typescript6@^6.0.2","unplugin-raw": "^0.7.0",diff --git a/changes/1670/added.md b/changes/1670/added.mdnew file mode 100644index 000000000..9a1a09538--- /dev/null+++ b/changes/1670/added.md@@ -0,0 +1 @@+- Text can be written in Markdown: `set_text` with `markdown: true`, `openpencil.setTextMarkdown()` in scripts, and `<Text markdown>` in design JSX turn headings, bold, italic, strikethrough, code, links, lists, and quotes into styled text, sized and set as FigJam styles typed Markdown; Mermaid labels written in Markdown keep their bold and italic.diff --git a/changes/1670/fixed.md b/changes/1670/fixed.mdnew file mode 100644index 000000000..459940a9e--- /dev/null+++ b/changes/1670/fixed.md@@ -0,0 +1 @@+- Design JSX export of several layers is one JSX expression, wrapped in a fragment, so code editors and other JSX tools read it; sticky note, shape, and connector labels styled in ranges export with `<Span>` and `<Paragraph>` and read back the same.diff --git a/packages/core/package.json b/packages/core/package.jsonindex 78ca8f132..27113c051 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -210,6 +210,10 @@"jsep": "^1.4.0","jsondiffpatch": "^0.7.6","jspdf": "^4.2.1",+ "mdast-util-from-markdown": "^2.0.3",+ "mdast-util-gfm": "^3",+ "mdast-util-to-string": "^4.0.0",+ "micromark-extension-gfm": "^3","nanoevents": "^9.1.0","ofetch": "^1.5.1","parse5": "^8.0.1",@@ -230,6 +234,7 @@"@types/bun": "^1.3.14","@types/culori": "^4.0.1","@types/diff": "^8.0.0",+ "@types/mdast": "^4.0.4","@types/rbush": "^4.0.0","typescript": "npm:@typescript/typescript6@^6.0.2","unplugin-raw": "^0.7.0"diff --git a/packages/core/src/design-jsx/renderer.ts b/packages/core/src/design-jsx/renderer.tsindex 0beacc54c..49b71fc21 100644--- a/packages/core/src/design-jsx/renderer.ts+++ b/packages/core/src/design-jsx/renderer.ts@@ -4,6 +4,7 @@ import { defaultIcons, placeIcon, type IconProvider } from '#core/icons'import { extractPaths, extractPathsFromElements, scalePathInfos } from '#core/icons/svg'import type { IconData } from '#core/icons/types'import { layoutAuthoredNodes } from '#core/layout'+import { markdownText } from '#core/text/markdown'import { computeAccurateBounds } from '#core/vector/curve-math'function parseViewBox(viewBox: string | undefined): { w: number; h: number } {@@ -54,7 +55,8 @@ function createRenderer(icons: IconProvider) {identity: icon.prefix !== INLINE_SVG}),layout: layoutAuthoredNodes,- vectorBounds: computeAccurateBounds+ vectorBounds: computeAccurateBounds,+ markdown: markdownText})}diff --git a/packages/core/src/io/formats/mermaid/layers.ts b/packages/core/src/io/formats/mermaid/layers.tsindex a3a31d4e9..e9afaa243 100644--- a/packages/core/src/io/formats/mermaid/layers.ts+++ b/packages/core/src/io/formats/mermaid/layers.ts@@ -13,7 +13,7 @@ import {freeEndpoint} from '@open-pencil/scene-graph/connectors'import { BLACK } from '@open-pencil/scene-graph/constants'-import { createShapeWithText } from '@open-pencil/scene-graph/generated'+import { createShapeWithText, shapeWithTextLabel } from '@open-pencil/scene-graph/generated'import type { Color } from '@open-pencil/scene-graph/primitives'import { newLayerDefaults } from '#core/editor/shapes/defaults'@@ -22,6 +22,7 @@ import { applyArrangement, type ArrangePlacement } from '#core/layout/arrange/apimport { arrangeBoxes, type ArrangeInput } from '#core/layout/arrange/boxes'import { connectorLabelSize } from '#core/layout/arrange/routes'import { shapeWithTextWidthFor } from '#core/layout/shape-with-text'+import { markdownText } from '#core/text/markdown'import { prepareGraphFonts } from '#core/text/prepare'import { figJamShape } from './shapes'@@ -50,10 +51,16 @@ function solid(color: Color): Fill {return { type: 'SOLID', color: { ...color }, opacity: 1, visible: true }}-/** Markdown's emphasis marks taken out, which a label shows as plain text for now. */+/** A label's words, its Markdown read as text, for a layer name or section title. */function labelText(label: FlowLabel): string {if (label.format === 'text') return label.text- return label.text.replace(/(\*\*|__)(.+?)\1/g, '$2').replace(/([*_])(.+?)\1/g, '$2')+ return markdownText(label.text, { fontSize: 1, fontWeight: 400 }).text+}++/** Styles a label layer as its Markdown says, over the label's own style. */+function styleLabel(graph: SceneGraph, labelLayer: SceneNode | null, label: FlowLabel): void {+ if (!labelLayer || label.format === 'text') return+ graph.updateNode(labelLayer.id, markdownText(label.text, labelLayer))}function styledFills(layer: Partial<SceneNode>, style: FlowStyle): Fill[] | undefined {@@ -160,6 +167,7 @@ class FlowchartBuilder {},style.color ? { text, fills: [solid(style.color)] } : { text })+ styleLabel(graph, shapeWithTextLabel(graph, shape), node.label)this.layers.set(node.id, shape.id)}@@ -212,6 +220,7 @@ class FlowchartBuilder {})if (style.color) graph.updateNode(parts.label.id, { fills: [solid(style.color)] })}+ if (parts && edge.label) styleLabel(graph, parts.label, edge.label)this.connectors.set(edge.id, connector.id)}}diff --git a/packages/core/src/openpencil-api/index.ts b/packages/core/src/openpencil-api/index.tsindex ed90d6741..cb0f9d1dd 100644--- a/packages/core/src/openpencil-api/index.ts+++ b/packages/core/src/openpencil-api/index.ts@@ -37,7 +37,8 @@ import {writeFillOkHCL,writeLayoutDirection,writeStrokeOkHCL,- writeTextDirection+ writeTextDirection,+ writeTextMarkdown} from './nodes'import { getStatus, listStatuses, setStatus, type StatusInfo } from './statuses'import { bindVariable, unbindVariable, type VariableRef } from './variables'@@ -239,4 +240,14 @@ export class OpenPencilAPI {setTextDirection(node: NodeRef, direction: string): void {writeTextDirection(this.figma.graph, node, direction)}++ /**+ * Sets a text layer's text from Markdown, styled as FigJam styles Markdown typed into a text:+ * `#` and `##` headings bold at 2.5× and 1.5× the text's size, deeper ones bold at its size,+ * `**bold**`, `*italic*`, `~strike~`, `` `code` `` in Roboto Mono, links, lists, and quotes.+ * Load the fonts it uses first, as for `characters`.+ */+ setTextMarkdown(node: NodeRef, markdown: string): void {+ writeTextMarkdown(this.figma.graph, node, markdown)+ }}diff --git a/packages/core/src/openpencil-api/nodes.ts b/packages/core/src/openpencil-api/nodes.tsindex 6267405e7..8873287d7 100644--- a/packages/core/src/openpencil-api/nodes.ts+++ b/packages/core/src/openpencil-api/nodes.ts@@ -17,6 +17,9 @@ import {import { recordInstanceOverride } from '@open-pencil/scene-graph/instances'import { assertNodeEditable } from '#core/editor/capabilities'+import { assertTextFontsLoaded } from '#core/figma-api/fonts/loaded'+import { textAutoResizeChanges } from '#core/layout/text-auto-resize'+import { markdownText } from '#core/text/markdown'import { nodeOf, type NodeRef } from './behaviours'@@ -87,3 +90,21 @@ export function readTextDirection(graph: SceneGraph, ref: NodeRef): TextDirectioexport function writeTextDirection(graph: SceneGraph, ref: NodeRef, value: string): void {editNode(graph, nodeOf(graph, ref), { textDirection: direction(value) })}++/** The text, ranges, and paragraphs Markdown gives a text layer, as FigJam styles it. */+export function textMarkdownChanges(node: SceneNode, markdown: string): Partial<SceneNode> {+ if (node.type !== 'TEXT')+ throw new Error(`Markdown is written into a text layer, not ${node.type}`)+ return markdownText(markdown, node)+}++/**+ * Writes Markdown as a text layer's text: its own style stays, and headings, emphasis, code,+ * links, lists, and quotes become ranges and paragraphs. The fonts it uses must be loaded.+ */+export function writeTextMarkdown(graph: SceneGraph, ref: NodeRef, markdown: string): void {+ const node = nodeOf(graph, ref)+ const changes = textMarkdownChanges(node, markdown)+ assertTextFontsLoaded('setTextMarkdown', { ...node, ...changes })+ editNode(graph, node, { ...changes, ...textAutoResizeChanges(node, changes) })+}diff --git a/packages/core/src/text/index.ts b/packages/core/src/text/index.tsindex d282b4cb7..c512b242e 100644--- a/packages/core/src/text/index.ts+++ b/packages/core/src/text/index.ts@@ -26,3 +26,4 @@ export {type OutlineCommand} from './font/glyphs'export { layerTextStyleChanges, shownTextStyle } from './character-style'+export { markdownText, type MarkdownBase, type MarkdownText } from './markdown'diff --git a/packages/core/src/text/markdown.ts b/packages/core/src/text/markdown.tsnew file mode 100644index 000000000..da8530bba--- /dev/null+++ b/packages/core/src/text/markdown.ts@@ -0,0 +1,309 @@+import { isEmptyObject, isEqual } from 'es-toolkit/predicate'+import type { Nodes, PhrasingContent, RootContent } from 'mdast'+import { fromMarkdown } from 'mdast-util-from-markdown'+import { gfmFromMarkdown } from 'mdast-util-gfm'+import { toString } from 'mdast-util-to-string'+import { gfm } from 'micromark-extension-gfm'+import { parseFragment, type DefaultTreeAdapterTypes } from 'parse5'++import type {+ CharacterStyleOverride,+ SceneNode,+ StyleRun,+ TextParagraphStyle+} from '@open-pencil/scene-graph'+import {+ MAX_LIST_INDENTATION,+ PLAIN_PARAGRAPH,+ trimParagraphStyles+} from '@open-pencil/scene-graph/text'++/** The style of the text Markdown is written into, which headings and code are relative to. */+export type MarkdownBase = Pick<SceneNode, 'fontSize' | 'fontWeight'>++/** A text's characters, ranges, and paragraphs, as Markdown gives them. */+export interface MarkdownText {+ text: string+ styleRuns: StyleRun[]+ textParagraphs: TextParagraphStyle[]+}++/** FigJam's heading sizes, as multiples of the text's own size; deeper levels keep it. */+const HEADING_SCALE: Readonly<Partial<Record<number, number>>> = { 1: 2.5, 2: 1.5 }+const HEADING_LINE_HEIGHT = { unit: 'PERCENT', value: 150 } as const+const BOLD = 700+/** FigJam sets inline code in Roboto Mono, Medium below SemiBold and Bold from it. */+const CODE_FAMILY = 'Roboto Mono'+const CODE_BOLD_FROM = 600++type Style = CharacterStyleOverride++interface Segment {+ text: string+ style: Style+}++interface Paragraph {+ segments: Segment[]+ style: TextParagraphStyle+}++/** What reading one Markdown source shares: the text's style, and its link definitions by label. */+interface Reading {+ base: MarkdownBase+ definitions: ReadonlyMap<string, string>+}++/** The URL each `[label]: url` definition gives, wherever it sits, by its normalized label. */+function linkDefinitions(node: Nodes, found = new Map<string, string>()): Map<string, string> {+ if (node.type === 'definition' && !found.has(node.identifier))+ found.set(node.identifier, node.url)+ if ('children' in node) for (const child of node.children) linkDefinitions(child, found)+ return found+}++function codeStyle(style: Style, { base }: Reading): Style {+ const weight = style.fontWeight ?? base.fontWeight+ return { ...style, fontFamily: CODE_FAMILY, fontWeight: weight >= CODE_BOLD_FROM ? BOLD : 500 }+}++function phrasing(nodes: readonly PhrasingContent[], style: Style, reading: Reading): Segment[] {+ return nodes.flatMap((node): Segment[] => {+ switch (node.type) {+ case 'text':+ return [{ text: node.value, style }]+ case 'strong':+ return phrasing(node.children, { ...style, fontWeight: BOLD }, reading)+ case 'emphasis':+ return phrasing(node.children, { ...style, italic: true }, reading)+ case 'delete':+ return phrasing(node.children, { ...style, textDecoration: 'STRIKETHROUGH' }, reading)+ case 'inlineCode':+ return [{ text: node.value, style: codeStyle(style, reading) }]+ case 'link':+ return phrasing(node.children, linked(style, node.url), reading)+ case 'linkReference': {+ // `[text][label]` links to the URL its definition gives, wherever that is written.+ const url = reading.definitions.get(node.identifier)+ return phrasing(node.children, url ? linked(style, url) : style, reading)+ }+ case 'break':+ return [{ text: '\n', style }]+ case 'image':+ return node.alt ? [{ text: node.alt, style }] : []+ case 'html': {+ // An inline tag only marks up the words around it; a `<br>` still breaks the line.+ const words = htmlWords(node.value)+ return words ? [{ text: words, style }] : []+ }+ default:+ return [{ text: toString(node), style }]+ }+ })+}++/** Elements whose content HTML never shows. */+const HIDDEN_ELEMENTS = new Set(['script', 'style', 'template', 'head', 'title'])++/** Elements HTML lays out as blocks of their own, which start a line. */+const BLOCK_ELEMENTS = new Set([+ 'address',+ 'article',+ 'aside',+ 'blockquote',+ 'dd',+ 'details',+ 'div',+ 'dl',+ 'dt',+ 'figcaption',+ 'figure',+ 'footer',+ 'form',+ 'h1',+ 'h2',+ 'h3',+ 'h4',+ 'h5',+ 'h6',+ 'header',+ 'hr',+ 'li',+ 'main',+ 'nav',+ 'ol',+ 'p',+ 'pre',+ 'section',+ 'summary',+ 'table',+ 'tr',+ 'ul'+])++/** Where a block element starts or ends, which several in a row make one line break. */+const BLOCK_EDGE = '\u0000'++function htmlContent(nodes: DefaultTreeAdapterTypes.ChildNode[]): string {+ return nodes+ .map((node) => {+ if (node.nodeName === '#text' && 'value' in node) return node.value+ if (node.nodeName === 'br') return '\n'+ if (HIDDEN_ELEMENTS.has(node.nodeName) || !('childNodes' in node)) return ''+ const words = htmlContent(node.childNodes)+ return BLOCK_ELEMENTS.has(node.nodeName) ? `${BLOCK_EDGE}${words}${BLOCK_EDGE}` : words+ })+ .join('')+}++/**+ * The words HTML shows: a `<br>` breaks the line and a block element sits on lines of its own,+ * while inline tags only mark up their words and hidden content shows nothing.+ */+function htmlWords(html: string): string {+ const content = htmlContent(parseFragment(html).childNodes)+ const edges = new RegExp(`${BLOCK_EDGE}+`, 'g')+ return content.replace(edges, (edge, at: number) =>+ at === 0 || at + edge.length === content.length ? '' : '\n'+ )+}++function linked(style: Style, url: string): Style {+ return { ...style, hyperlink: { type: 'URL', value: url } }+}++/** Paragraphs of segments, a hard break inside one starting another of the same style. */+function splitBreaks(segments: Segment[], style: TextParagraphStyle): Paragraph[] {+ const paragraphs: Paragraph[] = [{ segments: [], style }]+ for (const segment of segments) {+ const lines = segment.text.split('\n')+ for (const [index, line] of lines.entries()) {+ if (index > 0) paragraphs.push({ segments: [], style })+ if (line) paragraphs.at(-1)?.segments.push({ text: line, style: segment.style })+ }+ }+ return paragraphs+}++function listStyle(ordered: boolean, depth: number): TextParagraphStyle {+ return {+ listType: ordered ? 'ORDERED' : 'UNORDERED',+ indentation: Math.min(depth, MAX_LIST_INDENTATION)+ }+}++function blocks(+ nodes: readonly RootContent[],+ style: Style,+ paragraph: TextParagraphStyle,+ reading: Reading,+ depth: number+): Paragraph[] {+ return nodes.flatMap((node): Paragraph[] => {+ switch (node.type) {+ case 'paragraph':+ return splitBreaks(phrasing(node.children, style, reading), paragraph)+ case 'heading': {+ const scale = HEADING_SCALE[node.depth]+ const heading: Style = {+ ...style,+ fontWeight: BOLD,+ lineHeight: HEADING_LINE_HEIGHT,+ ...(scale ? { fontSize: reading.base.fontSize * scale } : {})+ }+ return splitBreaks(phrasing(node.children, heading, reading), paragraph)+ }+ case 'blockquote':+ return blocks(node.children, { ...style, italic: true }, paragraph, reading, depth)+ case 'list':+ return node.children.flatMap((item) => {+ const bullet = listStyle(node.ordered === true, depth + 1)+ // An empty item is still a bullet of its own.+ if (item.children.length === 0) return [{ segments: [], style: bullet }]+ return item.children.flatMap((child, index) => {+ // An item's first block is its bullet; a nested list goes a level deeper, under a+ // bullet of the item's own when the item holds nothing before it.+ if (child.type === 'list') {+ const own = index === 0 ? [{ segments: [], style: bullet }] : []+ return [...own, ...blocks([child], style, paragraph, reading, depth + 1)]+ }+ return blocks([child], style, index === 0 ? bullet : paragraph, reading, depth)+ })+ })+ case 'code':+ return node.value.split('\n').map((line) => ({+ segments: line ? [{ text: line, style: codeStyle(style, reading) }] : [],+ style: paragraph+ }))+ case 'table':+ // A row reads as its cells apart by tabs; the text model has no tables.+ return node.children.map((row) => ({+ segments: row.children.flatMap((cell, index) => [+ ...(index > 0 ? [{ text: '\t', style }] : []),+ ...phrasing(cell.children, style, reading)+ ]),+ style: paragraph+ }))+ case 'html': {+ // Only the blank lines around the block go; a `<pre>` keeps the spaces it shows.+ const words = htmlWords(node.value).replace(/^\n+|\n+$/g, '')+ return words ? splitBreaks([{ text: words, style }], paragraph) : []+ }+ case 'thematicBreak':+ case 'definition':+ case 'footnoteDefinition':+ case 'yaml':+ return []+ default:+ return splitBreaks([{ text: toString(node), style }], paragraph)+ }+ })+}++/** The style a run keeps: what differs from the text's own. */+function ownStyle(style: Style, base: MarkdownBase): Style {+ const own = { ...style }+ if (own.fontWeight === base.fontWeight) delete own.fontWeight+ if (own.fontSize === base.fontSize) delete own.fontSize+ return own+}++/**+ * Text written in Markdown as a text's characters, ranges, and paragraphs, styled as FigJam+ * styles Markdown typed into a text: headings bold at 2.5×, 1.5×, or the text's own size with+ * a 150% line height, bold and italic in the text's family, inline code in Roboto Mono, lists+ * and quotes as paragraphs. Links keep their URL; content the text model has no place for, such+ * as images and rules, keeps its words or is left out.+ */+export function markdownText(markdown: string, base: MarkdownBase): MarkdownText {+ const root = fromMarkdown(markdown, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] })+ const reading = { base, definitions: linkDefinitions(root) }+ const paragraphs = blocks(root.children, {}, PLAIN_PARAGRAPH, reading, 0)+ if (paragraphs.length === 0) return { text: '', styleRuns: [], textParagraphs: [] }++ const runs: StyleRun[] = []+ let text = ''+ for (const [index, paragraph] of paragraphs.entries()) {+ // A newline takes the style of the character before it, as in Figma.+ const segments =+ index < paragraphs.length - 1+ ? [...paragraph.segments, { text: '\n', style: paragraph.segments.at(-1)?.style ?? {} }]+ : paragraph.segments+ for (const segment of segments) {+ const style = ownStyle(segment.style, base)+ const previous = runs.at(-1)+ if (!isEmptyObject(style)) {+ if (+ previous &&+ previous.start + previous.length === text.length &&+ isEqual(previous.style, style)+ )+ previous.length += segment.text.length+ else runs.push({ start: text.length, length: segment.text.length, style })+ }+ text += segment.text+ }+ }+ const styles = paragraphs.map((paragraph) => ({ ...paragraph.style }))+ return { text, styleRuns: runs, textParagraphs: trimParagraphStyles(styles, styles.length) }+}diff --git a/packages/core/src/tools/modify/text.ts b/packages/core/src/tools/modify/text.tsindex 40c06c4af..66c228d3e 100644--- a/packages/core/src/tools/modify/text.ts+++ b/packages/core/src/tools/modify/text.ts@@ -6,6 +6,7 @@ import type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'import type { FigmaFontName, FigmaFontNameInput } from '#core/figma-api/fonts/names'import type { FigmaVariationSettings } from '#core/figma-api/fonts/variations'import { OpenPencilAPI } from '#core/openpencil-api'+import { textMarkdownChanges } from '#core/openpencil-api/nodes'import { collectNodeFontFaces } from '#core/text/requirements/collect'import {toolNumber,@@ -24,18 +25,29 @@ export function textFonts(figma: FigmaAPI, id: string): FigmaFontNameInput[] {export const setText = defineTool({name: 'set_text',- description: 'Set text content of a text node.',+ description:+ "Set text content of a text node. With markdown, the text is Markdown: # and ## headings, **bold**, *italic*, ~~strike~~, `code`, [links](url), lists, and > quotes become styled ranges and paragraphs over the text's own style.",execution: { kind: 'sync', mutation: 'properties' },input: v.strictObject({id: nodeIdInputSchema,- text: v.pipe(v.string(), v.description('Text content'))+ text: v.pipe(v.string(), v.description('Text content')),+ markdown: v.optional(v.pipe(v.boolean(), v.description('Read the text as Markdown')))}),- fonts: (figma, { id }) => textFonts(figma, id),- execute: (figma, { id, text }) => {+ fonts: (figma, { id, text, markdown }) => {+ const node = figma.graph.getNode(id)+ if (!markdown || node?.type !== 'TEXT') return textFonts(figma, id)+ return collectNodeFontFaces({ ...node, ...textMarkdownChanges(node, text) })+ },+ execute: (figma, { id, text, markdown }) => {const node = figma.getNodeById(id)if (!node) return { error: `Node "${id}" not found` }- node.characters = text- return { id, text }+ try {+ if (markdown) new OpenPencilAPI(figma).setTextMarkdown(node, text)+ else node.characters = text+ } catch (error) {+ return toolFailure(error)+ }+ return { id, text: node.characters }}})diff --git a/packages/core/tests/design-jsx/figjam/connectors.test.ts b/packages/core/tests/design-jsx/figjam/connectors.test.tsindex a0be7c2a7..718063928 100644--- a/packages/core/tests/design-jsx/figjam/connectors.test.ts+++ b/packages/core/tests/design-jsx/figjam/connectors.test.ts@@ -155,7 +155,7 @@ return <>graph)expect(jsx).toStartWith(- 'const card1 = ref()\nconst card2 = ref()\n\nreturn <>\n<Frame name="Card"'+ 'const card1 = ref()\nconst card2 = ref()\n\nreturn <>\n <Frame name="Card"')expect(jsx).toEndWith('\n</>')const again = new SceneGraph()@@ -310,3 +310,21 @@ return <Frame name="Flow" w={800} h={400}>expect(line?.boundVariables['strokes/0/color']).toBe('var-line')})})++test('a connector label styled in ranges writes back with <Span>s', async () => {+ const graph = new SceneGraph()+ const [flow] = await renderJSX(+ graph,+ `<Frame name="Flow" w={400} h={200}>+ <Frame name="A" w={50} h={50} />+ <Frame name="B" x={300} w={50} h={50} />+ <Connector from="A" to="B"><Span italic>maybe</Span> later</Connector>+ </Frame>`+ )+ const connector = graph.getChildren(flow.id).find((node) => node.type === 'CONNECTOR')+ if (!connector) throw new Error('Expected the connector')+ expect(connectorSublayers(graph, connector)?.label.styleRuns).toEqual([+ { start: 0, length: 5, style: { italic: true } }+ ])+ expect(sceneNodeToJSX(flow.id, graph)).toContain('><Span italic>maybe</Span> later</Connector>')+})diff --git a/packages/core/tests/design-jsx/figjam/shapes-with-text.test.ts b/packages/core/tests/design-jsx/figjam/shapes-with-text.test.tsindex f0fc3988e..6b4c4b066 100644--- a/packages/core/tests/design-jsx/figjam/shapes-with-text.test.ts+++ b/packages/core/tests/design-jsx/figjam/shapes-with-text.test.ts@@ -3,7 +3,7 @@ import { describe, expect, test } from 'bun:test'import { getNodeOrThrow } from '#core-tests/helpers/assert'import { renderJSX } from '@open-pencil/core/design-jsx'-import { sceneNodeToJSX } from '@open-pencil/design-jsx'+import { sceneNodeToJSX, selectionToJSXWithLayers } from '@open-pencil/design-jsx'import { SceneGraph } from '@open-pencil/scene-graph'import { shapeWithTextLabel } from '@open-pencil/scene-graph/generated'@@ -53,6 +53,45 @@ describe('shapes with text in design JSX', () => {expect(sceneNodeToJSX(reread.id, again)).toBe(jsx)})+ test('a label styled in ranges writes back with <Span>s and reads back the same', async () => {+ const graph = new SceneGraph()+ const [rendered] = await renderJSX(+ graph,+ '<Shape><Span weight={700}>Idea</Span> and <Span italic>sketch</Span></Shape>'+ )+ const shape = getNodeOrThrow(graph, rendered.id)+ const label = shapeWithTextLabel(graph, shape)+ expect(label?.text).toBe('Idea and sketch')+ expect(label?.styleRuns).toEqual([+ { start: 0, length: 4, style: { fontWeight: 700 } },+ { start: 9, length: 6, style: { italic: true } }+ ])+ expect(shape.name).toBe('Idea and sketch')+ const jsx = sceneNodeToJSX(shape.id, graph)+ expect(jsx).toBe('<Shape><Span weight="bold">Idea</Span> and <Span italic>sketch</Span></Shape>')+ const again = new SceneGraph()+ const [reread] = await renderJSX(again, jsx)+ expect(shapeWithTextLabel(again, getNodeOrThrow(again, reread.id))?.styleRuns).toEqual(label?.styleRuns)+ })++ test('a styled label’s elements belong to no layer, so later elements map to theirs', async () => {+ const graph = new SceneGraph()+ const [shape, frame] = await renderJSX(+ graph,+ '<><Shape><Span weight={700}>Go</Span> now</Shape><Frame name="After" w={10} h={10} /></>'+ )+ const { layerIds } = selectionToJSXWithLayers([shape.id, frame.id], graph)+ expect(layerIds).toEqual([shape.id, null, frame.id])+ })++ test('a label mixing <Paragraph> with other text fails before the shape is made', async () => {+ const graph = new SceneGraph()+ await expect(+ renderJSX(graph, '<Shape><Paragraph>a</Paragraph>b</Shape>')+ ).rejects.toThrow('mixes <Paragraph> with other content')+ expect([...graph.getAllNodes()].some((node) => node.type === 'SHAPE_WITH_TEXT')).toBe(false)+ })+test('write the size they were given, not the size their label grew them to', async () => {const graph = new SceneGraph()const label = 'A label long enough to need more lines than a small square holds'diff --git a/packages/core/tests/design-jsx/figjam/stickies.test.ts b/packages/core/tests/design-jsx/figjam/stickies.test.tsindex 2d9d49efa..dacc0d24b 100644--- a/packages/core/tests/design-jsx/figjam/stickies.test.ts+++ b/packages/core/tests/design-jsx/figjam/stickies.test.ts@@ -50,6 +50,23 @@ describe('sticky notes in design JSX', () => {expect(sceneNodeToJSX(reread.id, again)).toBe(jsx)})+ test('a body styled in ranges and lists writes back with <Span>s and <Paragraph>s', async () => {+ const graph = new SceneGraph()+ const source =+ '<Sticky color="blue">\n <Paragraph><Span weight="bold">Todo</Span></Paragraph>\n <Paragraph list="unordered">Ship</Paragraph>\n</Sticky>'+ const [rendered] = await renderJSX(graph, source)+ const sticky = getNodeOrThrow(graph, rendered.id)+ const body = stickySublayers(graph, sticky)?.body+ expect(body?.text).toBe('Todo\nShip')+ // The newline after the bold word takes its style, as in Figma.+ expect(body?.styleRuns).toEqual([{ start: 0, length: 5, style: { fontWeight: 700 } }])+ expect(body?.textParagraphs).toEqual([+ { listType: 'NONE', indentation: 0 },+ { listType: 'UNORDERED', indentation: 1 }+ ])+ expect(sceneNodeToJSX(sticky.id, graph)).toBe(source)+ })+test('keep a name given in the JSX, even one that matches the body', async () => {const graph = new SceneGraph()const [result] = await renderJSX(graph, '<Sticky name="Ship it">Ship it</Sticky>')diff --git a/packages/core/tests/design-jsx/markdown.test.ts b/packages/core/tests/design-jsx/markdown.test.tsnew file mode 100644index 000000000..c2b36b9de--- /dev/null+++ b/packages/core/tests/design-jsx/markdown.test.ts@@ -0,0 +1,60 @@+import { describe, expect, test } from 'bun:test'++import { getNodeOrThrow } from '#core-tests/helpers/assert'++import { renderJSX } from '@open-pencil/core/design-jsx'+import { SceneGraph } from '@open-pencil/scene-graph'++describe('<Text markdown>', () => {+ test('reads its text as Markdown over the text’s own style, its shared indent left out', async () => {+ const graph = new SceneGraph()+ const [text] = await renderJSX(+ graph,+ `<Text markdown size={20}>{\`+ ## Plan+ - **ship** it+ \`}</Text>`+ )+ const node = getNodeOrThrow(graph, text.id)+ expect(node.text).toBe('Plan\nship it')+ expect(node.fontSize).toBe(20)+ expect(node.textParagraphs).toEqual([+ { listType: 'NONE', indentation: 0 },+ { listType: 'UNORDERED', indentation: 1 }+ ])+ expect(node.styleRuns).toEqual([+ {+ start: 0,+ length: 5,+ style: { fontWeight: 700, fontSize: 30, lineHeight: { unit: 'PERCENT', value: 150 } }+ },+ { start: 5, length: 4, style: { fontWeight: 700 } }+ ])+ })++ test('keeps a nested list item’s indent beyond the indent its lines share', async () => {+ for (const indent of ['', ' ']) {+ const graph = new SceneGraph()+ const source = ['- one', ' - inner'].map((line) => indent + line).join('\n')+ const [text] = await renderJSX(graph, `<Text markdown>{\`\n${source}\n\`}</Text>`)+ expect(getNodeOrThrow(graph, text.id).textParagraphs).toEqual([+ { listType: 'UNORDERED', indentation: 1 },+ { listType: 'UNORDERED', indentation: 2 }+ ])+ }+ })++ test('takes its Markdown from the text prop too', async () => {+ const graph = new SceneGraph()+ const [text] = await renderJSX(graph, `<Text markdown text="a *b*" />`)+ expect(getNodeOrThrow(graph, text.id).styleRuns).toEqual([+ { start: 2, length: 1, style: { italic: true } }+ ])+ })++ test('holds no <Span>', async () => {+ await expect(+ renderJSX(new SceneGraph(), '<Text markdown>a <Span weight={700}>b</Span></Text>')+ ).rejects.toThrow('<Text markdown> holds only its Markdown text')+ })+})diff --git a/packages/core/tests/io/formats/mermaid/import.test.ts b/packages/core/tests/io/formats/mermaid/import.test.tsindex e4a46149a..35bcc9919 100644--- a/packages/core/tests/io/formats/mermaid/import.test.ts+++ b/packages/core/tests/io/formats/mermaid/import.test.ts@@ -77,6 +77,19 @@ flowchart TDG ~~~ A`describe('opening Mermaid files', () => {+ test('a Markdown label draws its emphasis as ranges of its text', async () => {+ const graph = await read('flowchart LR\n a["`**Ship** _it_`"] -->|"`**go**`"| b')+ const label = shapeWithTextLabel(graph, named(graph, 'Ship it'))+ expect(label?.text).toBe('Ship it')+ expect(label?.styleRuns).toEqual([+ { start: 0, length: 4, style: { fontWeight: 700 } },+ { start: 5, length: 2, style: { italic: true } }+ ])+ const edge = expectDefined(connectorSublayers(graph, connectors(graph)[0])?.label)+ expect(edge.text).toBe('go')+ expect(edge.styleRuns).toEqual([{ start: 0, length: 2, style: { fontWeight: 700 } }])+ })+test('takes .mmd and .mermaid files and refuses diagrams other than flowcharts', async () => {const format = expectDefined(io.getFormat('mermaid'))expect(format.matchesFile?.('flow.mmd')).toBe(true)diff --git a/packages/core/tests/openpencil-api/nodes.test.ts b/packages/core/tests/openpencil-api/nodes.test.tsindex c958f70ea..ad2bf668a 100644--- a/packages/core/tests/openpencil-api/nodes.test.ts+++ b/packages/core/tests/openpencil-api/nodes.test.ts@@ -34,3 +34,39 @@ test('a layer saved without a layout direction reads AUTO', () => {Reflect.deleteProperty(graph.getNode(frame.id) as object, 'layoutDirection')expect(new OpenPencilAPI(figma).getLayoutDirection(frame)).toBe('AUTO')})++/** What the Markdown script reads back from the text it wrote. */+interface MarkdownResult {+ text: string+ heading: number+ size: number | 'mixed'+ bold: unknown+}++test('scripts write Markdown into a text through openpencil, once its fonts are loaded', async () => {+ const figma = new FigmaAPI(new SceneGraph())+ const result = (await compileScript(`+ const text = figma.createText()+ await figma.loadFontAsync({ family: 'Inter', style: 'Regular' })+ await figma.loadFontAsync({ family: 'Inter', style: 'Bold' })+ openpencil.setTextMarkdown(text, '# Hi\\n**there** and here')+ return {+ text: text.characters,+ heading: text.getRangeFontSize(0, 1),+ size: text.fontSize === figma.mixed ? 'mixed' : text.fontSize,+ bold: text.getRangeFontName(3, 4)+ }+ `)(figma)) as MarkdownResult+ expect(result).toMatchObject({+ text: 'Hi\nthere and here',+ heading: 30,+ size: 'mixed',+ bold: { family: 'Inter', style: 'Bold' }+ })+ await expect(+ compileScript(`openpencil.setTextMarkdown(figma.createText(), 'a \`b\`')`)(figma)+ ).rejects.toThrow('unloaded font "Roboto Mono Medium"')+ await expect(compileScript(`openpencil.setTextMarkdown(figma.createFrame(), 'a')`)(figma)).rejects.toThrow(+ 'Markdown is written into a text layer, not FRAME'+ )+})diff --git a/packages/core/tests/text/markdown.test.ts b/packages/core/tests/text/markdown.test.tsnew file mode 100644index 000000000..aef245f09--- /dev/null+++ b/packages/core/tests/text/markdown.test.ts@@ -0,0 +1,117 @@+import { describe, expect, test } from 'bun:test'++import { markdownText } from '@open-pencil/core/text'+import type { CharacterStyleOverride } from '@open-pencil/scene-graph'++const BASE = { fontSize: 24, fontWeight: 500 }++/** Each run's characters with its style, which reads better than offsets. */+function styled(markdown: string, base = BASE): [string, CharacterStyleOverride][] {+ const { text, styleRuns } = markdownText(markdown, base)+ return styleRuns.map((run) => [text.slice(run.start, run.start + run.length), run.style])+}++const HEADING: CharacterStyleOverride = {+ fontWeight: 700,+ lineHeight: { unit: 'PERCENT', value: 150 }+}++describe('Markdown as text, styled as FigJam styles typed Markdown', () => {+ test('headings are bold at 2.5×, 1.5×, and the text’s own size, with a 150% line height', () => {+ expect(styled('# One\n## Two\n### Three\n###### Six')).toEqual([+ ['One\n', { ...HEADING, fontSize: 60 }],+ ['Two\n', { ...HEADING, fontSize: 36 }],+ ['Three\nSix', HEADING]+ ])+ expect(styled('# Big', { fontSize: 40, fontWeight: 400 })).toEqual([+ ['Big', { ...HEADING, fontSize: 100 }]+ ])+ })++ test('emphasis, strikethrough with one tilde or two, and links style their characters', () => {+ const { text } = markdownText('a **b** _c_ ~d~ ~~e~~ [f](https://x.dev)', BASE)+ expect(text).toBe('a b c d e f')+ expect(styled('a **b** _c_ ~d~ ~~e~~ [f](https://x.dev)')).toEqual([+ ['b', { fontWeight: 700 }],+ ['c', { italic: true }],+ ['d', { textDecoration: 'STRIKETHROUGH' }],+ ['e', { textDecoration: 'STRIKETHROUGH' }],+ ['f', { hyperlink: { type: 'URL', value: 'https://x.dev' } }]+ ])+ })++ test('a reference link takes its definition’s URL', () => {+ const source = 'See the [guide][Manual].\n\n[manual]: https://x.dev/guide'+ expect(markdownText(source, BASE).text).toBe('See the guide.')+ expect(styled(source)).toEqual([+ ['guide', { hyperlink: { type: 'URL', value: 'https://x.dev/guide' } }]+ ])+ })++ test('HTML keeps its words, inline or as a block, and a comment leaves nothing', () => {+ expect(markdownText('See <b>this</b>.', BASE).text).toBe('See this.')+ expect(markdownText('<div>\nOne<br>two\n</div>\n\n<!-- note -->\n\nend', BASE).text).toBe(+ 'One\ntwo\nend'+ )+ })++ test('code is Roboto Mono, Medium below SemiBold and Bold from it', () => {+ expect(styled('a `b`', { fontSize: 24, fontWeight: 400 })).toEqual([+ ['b', { fontFamily: 'Roboto Mono', fontWeight: 500 }]+ ])+ expect(styled('a `b` **`c`**')).toEqual([+ ['b', { fontFamily: 'Roboto Mono' }],+ ['c', { fontFamily: 'Roboto Mono', fontWeight: 700 }]+ ])+ expect(styled('```\nconst a = 1\n```', { fontSize: 24, fontWeight: 600 })).toEqual([+ ['const a = 1', { fontFamily: 'Roboto Mono', fontWeight: 700 }]+ ])+ })++ test('lists are list paragraphs, nested a level deeper, and quotes are italic', () => {+ const { text, textParagraphs, styleRuns } = markdownText(+ '- one\n - inner\n1. first\n\n> said',+ BASE+ )+ expect(text).toBe('one\ninner\nfirst\nsaid')+ expect(textParagraphs).toEqual([+ { listType: 'UNORDERED', indentation: 1 },+ { listType: 'UNORDERED', indentation: 2 },+ { listType: 'ORDERED', indentation: 1 }+ ])+ expect(styleRuns).toEqual([{ start: 16, length: 4, style: { italic: true } }])+ })++ test('HTML shows what a browser shows: blocks on lines of their own, no script, a pre’s spaces', () => {+ expect(markdownText('first<br>second', BASE).text).toBe('first\nsecond')+ expect(markdownText('<div>one</div><div>two</div>', BASE).text).toBe('one\ntwo')+ expect(markdownText('<div>a<script>secret()</script><style>p{}</style></div>', BASE).text).toBe('a')+ expect(markdownText('<pre> indented</pre>', BASE).text).toBe(' indented')+ })++ test('an item holding only a nested list keeps a bullet of its own', () => {+ expect(markdownText('-\n - child', BASE).textParagraphs).toEqual([+ { listType: 'UNORDERED', indentation: 1 },+ { listType: 'UNORDERED', indentation: 2 }+ ])+ })++ test('an empty list item is a bullet of its own', () => {+ const { text, textParagraphs } = markdownText('- \n- next', BASE)+ expect(text).toBe('\nnext')+ expect(textParagraphs).toEqual([+ { listType: 'UNORDERED', indentation: 1 },+ { listType: 'UNORDERED', indentation: 1 }+ ])+ })++ test('a hard break starts a paragraph, a table row reads as its cells, a rule is left out', () => {+ expect(markdownText('a \nb\n\n---\n\n| x | y |\n|---|---|\n| 1 | 2 |', BASE).text).toBe(+ 'a\nb\nx\ty\n1\t2'+ )+ })++ test('empty Markdown is empty text', () => {+ expect(markdownText('', BASE)).toEqual({ text: '', styleRuns: [], textParagraphs: [] })+ })+})diff --git a/packages/design-jsx/src/definitions.ts b/packages/design-jsx/src/definitions.tsindex f0a752ba4..c352fc5c3 100644--- a/packages/design-jsx/src/definitions.ts+++ b/packages/design-jsx/src/definitions.ts@@ -141,6 +141,7 @@ export const DESIGN_JSX_SUPPORTED_PROPERTY_NAMES = ['content','value','title',+ 'markdown','textAlign','textAlignHorizontal','textHorizontalAlignment',diff --git a/packages/design-jsx/src/elements/index.ts b/packages/design-jsx/src/elements/index.tsindex 23e3a080c..41fad1720 100644--- a/packages/design-jsx/src/elements/index.ts+++ b/packages/design-jsx/src/elements/index.ts@@ -1,6 +1,7 @@import { difference } from 'es-toolkit'import type { NodeType, SceneGraph, SceneNode } from '@open-pencil/scene-graph'+import { shapeWithTextLabel } from '@open-pencil/scene-graph/generated'import { REKA_ELEMENTS, rekaRole } from '../behaviours'import {@@ -9,9 +10,13 @@ import {DESIGN_JSX_SUPPORTED_PROPERTY_NAMES,DESIGN_JSX_TEXT_PARAGRAPH_PROPERTY_NAMES} from '../definitions'-import { connectorBindingTarget, renderConnectorNode } from '../figjam/connectors'+import {+ connectorBindingTarget,+ connectorLabelLayer,+ renderConnectorNode+} from '../figjam/connectors'import { renderShapeNode } from '../figjam/shapes-with-text'-import { renderStickyNode } from '../figjam/stickies'+import { renderStickyNode, stickyBodyLayer } from '../figjam/stickies'import {connectorPropsSchema,ownLayerPropsSchema,@@ -30,6 +35,8 @@ export interface OwnLayerRenderer {render(graph: SceneGraph, tree: TreeNode, parentId: string, layer: Partial<SceneNode>): SceneNode/** The layer a variable binding of `field` goes on, when not the element's own. */bindingTarget?(graph: SceneGraph, node: SceneNode, field: string): string+ /** The text layer its children write, which `<Span>` and `<Paragraph>` style as in `<Text>`. */+ textLayer(graph: SceneGraph, node: SceneNode): SceneNode | null}/**@@ -188,7 +195,11 @@ export const DESIGN_JSX_ELEMENTS: DesignJSXElementDefinition[] = [runtimeType: 'sticky',description: 'A FigJam sticky note; its text is the body.',schema: stickyPropsSchema,- ownLayer: { layer: placedOwnLayerPropsSchema, render: renderStickyNode },+ ownLayer: {+ layer: placedOwnLayerPropsSchema,+ render: renderStickyNode,+ textLayer: stickyBodyLayer+ },writes: ['STICKY']},{@@ -196,7 +207,11 @@ export const DESIGN_JSX_ELEMENTS: DesignJSXElementDefinition[] = [runtimeType: 'shape',description: 'A FigJam shape with text; its text is the label.',schema: shapePropsSchema,- ownLayer: { layer: shapeLayerPropsSchema, render: renderShapeNode },+ ownLayer: {+ layer: shapeLayerPropsSchema,+ render: renderShapeNode,+ textLayer: shapeWithTextLabel+ },writes: ['SHAPE_WITH_TEXT']},{@@ -208,7 +223,8 @@ export const DESIGN_JSX_ELEMENTS: DesignJSXElementDefinition[] = [ownLayer: {layer: ownLayerPropsSchema,render: renderConnectorNode,- bindingTarget: connectorBindingTarget+ bindingTarget: connectorBindingTarget,+ textLayer: connectorLabelLayer},writes: ['CONNECTOR']},diff --git a/packages/design-jsx/src/export/index.ts b/packages/design-jsx/src/export/index.tsindex 9d658d98d..a7ec1fbaa 100644--- a/packages/design-jsx/src/export/index.ts+++ b/packages/design-jsx/src/export/index.ts@@ -2,18 +2,22 @@ import { compact } from 'es-toolkit'import { jsx, type SyntaxNode } from '@open-pencil/emit'import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'-import { isGeneratedFrame, type GeneratedFrameType } from '@open-pencil/scene-graph/generated'+import {+ isGeneratedFrame,+ shapeWithTextLabel,+ type GeneratedFrameType+} from '@open-pencil/scene-graph/generated'import { rekaExport, type RekaExport } from '../behaviours/export'import { elementTag } from '../elements'import {connectorExportScope,- connectorLabel,+ connectorLabelLayer,connectorProps,type ConnectorExportScope} from '../figjam/connectors'-import { shapeWithTextLabelText, shapeWithTextProps } from '../figjam/shapes-with-text'-import { stickyBody, stickyProps } from '../figjam/stickies'+import { shapeWithTextProps } from '../figjam/shapes-with-text'+import { stickyBodyLayer, stickyProps } from '../figjam/stickies'import { refDeclarations } from '../refs'import { instanceProps } from './components/instances'import { propertyBindingProps, withPropertyBindings } from './components/properties'@@ -64,10 +68,16 @@ function elementCount(nodes: readonly SyntaxNode[]): number {* A layer and the layers below it as JSX elements. A component with a behaviour is written as* Reka UI elements; a container JSX leaves implicit is written as its children alone.*/-/** What an element written its own way holds: its props, and the text it writes as children. */+/** What an element written its own way holds: its props, and the text layer it writes as children. */interface OwnElement {props: JSXProp[]- text: string+ textLayer: SceneNode | null+}++/** An own element's text as children: plain, or with the `<Span>`s and `<Paragraph>`s `<Text>` writes. */+function ownChildren(own: OwnElement, depth: number): { children: SyntaxNode[]; inline: boolean } {+ if (!own.textLayer?.text) return { children: [], inline: true }+ return textChildren(own.textLayer, depth)}/**@@ -93,7 +103,7 @@ const OWN_ELEMENTS: Record<...stickyProps(graph, node).map(([key, value]): JSXProp => [key, plainValue(value)]),...presenceProps(node)],- text: stickyBody(graph, node)+ textLayer: stickyBodyLayer(graph, node)}),SHAPE_WITH_TEXT: (graph, node) => ({props: [@@ -102,14 +112,14 @@ const OWN_ELEMENTS: Record<...shapeWithTextProps(graph, node),...presenceProps(node)],- text: shapeWithTextLabelText(graph, node)+ textLayer: shapeWithTextLabel(graph, node)}),CONNECTOR: (graph, node, scope) => ({props: connectorProps(graph, node, scope).map(([key, value]): JSXProp => [key,plainValue(value)]),- text: connectorLabel(graph, node)+ textLayer: connectorLabelLayer(graph, node)})}@@ -199,8 +209,10 @@ function nodeToJSX(layerIds?.push(node.id)const own = ownElement(graph, node, scope.connectors)if (own) {- const children = own.text ? [jsx.text(own.text)] : []- return [jsx.element(tag, own.props.map(propAttribute), children, depth, true)]+ const { children, inline } = ownChildren(own, depth)+ // Its label's `<Span>`s and `<Paragraph>`s are elements of no layer, as a text's are.+ for (let index = 0; index < elementCount(children); index++) layerIds?.push(null)+ return [jsx.element(tag, own.props.map(propAttribute), children, depth, inline)]}const ownProps = reka.props.get(node.id)// An item names its component; the instance's own layers are the component's to write.@@ -264,7 +276,7 @@ export function sceneNodeAttributes(const own = ownElement(graph, node)const props = instance ?? (own ? own.props : frameProps(node, graph, variables, reference))if (node.type === 'TEXT' && !hasTextProp(props)) props.push(['text', node.text])- if (own?.text) props.push(['text', own.text])+ if (own?.textLayer?.text) props.push(['text', own.textLayer.text])return props.map((prop) => ({name: prop[0],source: oneLine(jsx.printJSX(propAttribute(prop)))@@ -329,8 +341,8 @@ export function designJSXElement(nodeId: string, graph: SceneGraph): DesignJSXEl}if (node.type === 'TEXT' || isInstance) return { tag, attributes, text: null, childIds: [] }if (own) {- const children = own.text ? [jsx.text(own.text)] : []- return { tag, attributes, text: contentBetween(tag, children, true), childIds: [] }+ const { children, inline } = ownChildren(own, 0)+ return { tag, attributes, text: contentBetween(tag, children, inline), childIds: [] }}const childIds = graph.getChildren(node.id)@@ -375,11 +387,12 @@ export function selectionToJSXWithLayers(const layerIds: Array<string | null> = []const reference = componentReferences(graph, refs, onOf)const scope = { connectors, refs, variables, reference }+ // Several roots are children of a fragment, a level in.+ const depth = nodeIds.length > 1 ? 1 : 0const roots = compact(nodeIds.map((id) => {const node = graph.getNode(id)- const syntax = node ? nodeToJSX(node, graph, 0, scope, layerIds).at(0) : undefined- return syntax ? jsx.printJSX(syntax) : ''+ return node ? nodeToJSX(node, graph, depth, scope, layerIds).at(0) : undefined}))return { roots, layerIds, written: new Set(layerIds) }@@ -397,11 +410,12 @@ export function selectionToJSXWithLayers(): connectors.refsconst { roots, layerIds } = refs.size > connectors.refs.size ? write(refs) : first- const elements = roots.join('\n\n')+ // Several roots are siblings in a fragment, so the code is one JSX expression.+ const root = roots.length > 1 ? jsx.fragment(roots, 0) : roots.at(0)+ const elements = root ? jsx.printJSX(root) : ''// Variables first: a ref names a layer, and nothing in a variable's definition refers to one.const declarations = compact([variables.declarations(), refDeclarations(refs)]).join('\n\n')if (!declarations || !elements) return { code: elements, layerIds }- // Statements end with `return` and the JSX; several roots return as siblings in a fragment.- const returned = roots.length > 1 ? `<>\n${elements}\n</>` : elements- return { code: `${declarations}\n\nreturn ${returned}`, layerIds }+ // Statements end with `return` and the JSX.+ return { code: `${declarations}\n\nreturn ${elements}`, layerIds }}diff --git a/packages/design-jsx/src/figjam/connectors.ts b/packages/design-jsx/src/figjam/connectors.tsindex 44be55d66..7e346cf2c 100644--- a/packages/design-jsx/src/figjam/connectors.ts+++ b/packages/design-jsx/src/figjam/connectors.ts@@ -21,7 +21,8 @@ import { CONNECTOR_LINE, CONNECTOR_SIDE, STROKE_CAP } from '../enums'import { Reference } from '../export/value'import { isLayerRef, refName, type LayerRefs } from '../refs'import { connectorPropsSchema, readElementProps } from '../schema'-import { plainTextOf, type TreeNode } from '../tree'+import { textContentText } from '../text-content'+import type { TreeNode } from '../tree'/*** `<Connector from="A" to="B">`: a FigJam connector whose ends name other layers of the same@@ -53,7 +54,7 @@ export function renderConnectorNode(lineType: props.line,startCap: props.startCap ?? 'NONE',endCap: props.endCap ?? 'ARROW_LINES',- text: plainTextOf(tree)+ text: textContentText(tree)},{...layer,@@ -291,7 +292,7 @@ export function connectorProps(return props.filter(([, value]) => value !== undefined && value !== null)}-/** The label a connector writes as its children. */-export function connectorLabel(graph: SceneGraph, node: SceneNode): string {- return connectorSublayers(graph, node)?.label.text ?? ''+/** The text layer of a connector's label, which `<Connector>` writes as its children. */+export function connectorLabelLayer(graph: SceneGraph, node: SceneNode): SceneNode | null {+ return connectorSublayers(graph, node)?.label ?? null}diff --git a/packages/design-jsx/src/figjam/shapes-with-text.ts b/packages/design-jsx/src/figjam/shapes-with-text.tsindex 4864b4069..7b1a4da37 100644--- a/packages/design-jsx/src/figjam/shapes-with-text.ts+++ b/packages/design-jsx/src/figjam/shapes-with-text.ts@@ -10,7 +10,8 @@ import { SHAPE_KIND } from '../enums'import { collectFillProps, collectStrokeProps } from '../export/paints'import type { JSXProp } from '../export/value'import { readElementProps, shapePropsSchema } from '../schema'-import { plainTextOf, type TreeNode } from '../tree'+import { textContentText } from '../text-content'+import type { TreeNode } from '../tree'import { figJamTextFields, figJamTextProps } from './text'/**@@ -30,7 +31,7 @@ export function renderShapeNode(layer: Partial<SceneNode>) {const props = readElementProps(shapePropsSchema, tree.props)- const text = plainTextOf(tree)+ const text = textContentText(tree)const shape = createShapeWithText(graph,parentId,@@ -72,8 +73,3 @@ export function shapeWithTextProps(graph: SceneGraph, node: SceneNode): JSXProp[props.push(['rounded', node.cornerRadius])return props}--/** The label a shape writes as its children. */-export function shapeWithTextLabelText(graph: SceneGraph, node: SceneNode): string {- return shapeWithTextLabel(graph, node)?.text ?? ''-}diff --git a/packages/design-jsx/src/figjam/stickies.ts b/packages/design-jsx/src/figjam/stickies.tsindex b5a3238c4..5e052c8d6 100644--- a/packages/design-jsx/src/figjam/stickies.ts+++ b/packages/design-jsx/src/figjam/stickies.ts@@ -10,7 +10,8 @@ import {import type { Color } from '@open-pencil/scene-graph/primitives'import { readElementProps, stickyPropsSchema } from '../schema'-import { plainTextOf, type TreeNode } from '../tree'+import { textContentText } from '../text-content'+import type { TreeNode } from '../tree'import { figJamTextFields, figJamTextProps } from './text'/**@@ -30,7 +31,7 @@ export function renderStickyNode(layer: Partial<SceneNode>) {const props = readElementProps(stickyPropsSchema, tree.props)- const text = plainTextOf(tree)+ const text = textContentText(tree)const author = props.author ?? ''const sticky = createSticky(graph,@@ -72,7 +73,7 @@ export function stickyProps(graph: SceneGraph, node: SceneNode): Array<[string,return props}-/** The body a note writes as its children. */-export function stickyBody(graph: SceneGraph, node: SceneNode): string {- return stickySublayers(graph, node)?.body.text ?? ''+/** The text layer of a note's body, which `<Sticky>` writes as its children. */+export function stickyBodyLayer(graph: SceneGraph, node: SceneNode): SceneNode | null {+ return stickySublayers(graph, node)?.body ?? null}diff --git a/packages/design-jsx/src/reference/authoring.md b/packages/design-jsx/src/reference/authoring.mdindex 9b1e5ec93..2e1473541 100644--- a/packages/design-jsx/src/reference/authoring.md+++ b/packages/design-jsx/src/reference/authoring.md@@ -24,7 +24,8 @@ This reference describes scene creation, not React DOM output. Use the `render`- `rotate` turns a layer by degrees, and `flipX` and `flipY` reflect it across its centre before it turns, as the canvas places it. `Star` takes `points` and `innerRadius` (0–1, how deep its points go); `Polygon` takes `points`. `Ellipse` draws an arc or a donut with `startAngle` and `endAngle` in degrees, clockwise from three o'clock (0 to 360 by default), and `innerRadius` (0–1, the hole): `<Ellipse w={80} h={80} startAngle={0} endAngle={270} innerRadius={0.6} />`.- `effects` accepts structured effects such as `dropShadow`, `innerShadow`, and `layerBlur`. `shadow` takes a CSS `box-shadow` list, such as `shadow="0 4 8 #0002, inset 0 1 0 #fff"`, and `blur` a layer blur radius; both are convenient shorthands. Effect helpers take `radius`, as Figma's effects do; when a JSX string is rendered, an option a paint or effect helper does not support is reported as a warning.- Text content belongs inside `Text`. Use `size`, `font`, `weight`, `italic`, `lineHeight`, `letterSpacing`, `textAlign`, `textAlignVertical`, `textDecoration`, and `textCase`. Decorations take CSS's names and values: `textDecorationStyle` (`solid`, `dotted`, `wavy`), `textDecorationColor` (`currentColor` follows the text), `textDecorationThickness` and `textUnderlineOffset` (pixels or `auto`), and `textDecorationSkipInk`. `fontFeatures` turns OpenType features on or off by tag (`fontFeatures={{ tnum: true, liga: false }}`), `fontVariations` sets variable-font axes by tag (`fontVariations={{ wght: 650 }}`), and `lang` names the text's language (`lang="de"`) for shaping and font fallback. A variable font's optical size follows the font size unless `fontOpticalSizing="none"`, as in CSS; only then does an `opsz` in `fontVariations` apply. `lineHeight="auto"` follows the font, and `fills={[]}` paints no text. Verify fonts actually load before judging dimensions; do not assume every font is available.-- `Span` styles some characters of a `Text` with `Text`'s own prop names: `size`, `font`, `weight`, `italic`, `color`, `fills`, `lineHeight`, `letterSpacing`, `textDecoration`, the decoration details, `fontFeatures`, `fontVariations`, `lang`, and `textCase`; a span's `fontFeatures` and `fontVariations` replace the text's rather than adding to them, and `fontOpticalSizing` is set on the `Text` for all of it. `href` links its characters to a URL without changing how they look. Spans nest; the inner one wins. `Paragraph` writes one paragraph: `list="ordered"` or `list="unordered"` makes it a list item nested at `level` 1–5, and `spacing`, `listSpacing`, and `indent` override the `Text`'s `paragraphSpacing`, `listSpacing`, and `paragraphIndent` for it; `hangingList` on the `Text` hangs list markers outside the text box. A `Text` holds only `Paragraph`s or none; without them, a line break in its text still starts a paragraph.+- `Span` styles some characters of a `Text`, or of a `Sticky`'s body, a `Shape`'s label, or a `Connector`'s label, with `Text`'s own prop names: `size`, `font`, `weight`, `italic`, `color`, `fills`, `lineHeight`, `letterSpacing`, `textDecoration`, the decoration details, `fontFeatures`, `fontVariations`, `lang`, and `textCase`; a span's `fontFeatures` and `fontVariations` replace the text's rather than adding to them, and `fontOpticalSizing` is set on the `Text` for all of it. `href` links its characters to a URL without changing how they look. Spans nest; the inner one wins. `Paragraph` writes one paragraph: `list="ordered"` or `list="unordered"` makes it a list item nested at `level` 1–5, and `spacing`, `listSpacing`, and `indent` override the `Text`'s `paragraphSpacing`, `listSpacing`, and `paragraphIndent` for it; `hangingList` on the `Text` hangs list markers outside the text box. A `Text` holds only `Paragraph`s or none; without them, a line break in its text still starts a paragraph.+- `Text markdown` reads its text, children or `text`, as Markdown over the `Text`'s own style, as FigJam styles typed Markdown: `#` and `##` headings bold at 2.5× and 1.5× its size, deeper ones bold at its size, all at a 150% line height; `**bold**`, `*italic*`, `~~strike~~`, `` `code` `` in Roboto Mono, `[links](url)`, `-` and `1.` lists, and `>` quotes in italic. Write multiline Markdown as a template literal, ``<Text markdown>{`...`}</Text>``, since JSX folds the line breaks of plain children, and escape a code span's backticks in it as `` \` ``; the indent its lines share is left out. It holds no `Span` or `Paragraph`.- `Icon` uses an Iconify name, size, and color. Prefer icons to emoji when reliable vector output is needed. Image fills belong on appropriate leaf shapes, not containers whose children must remain visible.- Pick artwork by where it comes from. A known icon is an `Icon` by its Iconify name. A shape you draw yourself is a `Vector` with its path in SVG syntax, `<Vector d="M11 2L4 11h5l-1 7 7-9h-5z" bg={designVar(…)} />`: one layer, styled with the same props as any other, so its fills can use variables, stack, and take `strokeAlign` and `effects`. `fillRule="evenodd"` cuts holes. An open path with a `stroke` stays open, a line; with only a `bg` it fills as if closed. Given `w` and `h`, the path is drawn in that box as written, as an icon is in its view box; without them the layer fits the path. `paths` takes several paths as export writes them, each `{ windingRule, data }` with `NONZERO`, `EVENODD`, or `NONE` for an open path: `paths={[{ windingRule: "EVENODD", data: "M0 0L10 0L10 10Z" }]}`. Inline `<svg>` is for artwork copied from elsewhere: it draws the SVG's shapes, a frame with a layer per shape in the SVG's own colours, and leaves out its text, so do not use it for a shape you will style or bind, nor for text.- `Sticky` makes a FigJam sticky note whose text is its body: `<Sticky color="yellow" author="Ada">Ship it</Sticky>`. `color` takes a FigJam palette name (`white`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `violet`, `pink`) or any colour, `author` signs it (`authorVisible={false}` hides the line), `wide` makes it 416 wide instead of 240, `textSize` is `small`, `medium`, `large`, `extraLarge`, or `huge`, `typeface` is `simple`, `bookish`, `technical`, or `scribbled`, and `scale` scales the whole note. A note sizes itself; it takes no `w`, `h`, fills, or layout props.diff --git a/packages/design-jsx/src/render/node.ts b/packages/design-jsx/src/render/node.tsindex 8f7a05c26..9ec0bc16a 100644--- a/packages/design-jsx/src/render/node.ts+++ b/packages/design-jsx/src/render/node.ts@@ -12,7 +12,7 @@ import { applySizeOverrides, propsToOverrides, shapeOverrides } from '../overridimport { placeVectorPaths } from '../overrides/vector'import type { LayerRefs } from '../refs'import { readElementProps } from '../schema'-import type { DesignJSXServices } from '../services'+import type { DesignJSXServices, MarkdownService } from '../services'import { isTextContent, TEXT_CONTENT_NAMES, textContentFields } from '../text-content'import { isTreeNode } from '../tree'import type { TreeNode } from '../tree'@@ -54,6 +54,17 @@ function renderOwnLayerElement((value) => value === undefined)const node = element.render(graph, { ...tree, props }, parentId, layer)+ // `<Span>` and `<Paragraph>` children style the text layer as they style a `<Text>`.+ const textLayer = element.textLayer(graph, node)+ if (textLayer && tree.children.some(isTextContent)) {+ const spanOverrides = (spanProps: Record<string, unknown>) =>+ propsToOverrides(+ preparePropsForRender(graph, spanProps, true, { parentId, modes }).props,+ true,+ 'NONE'+ )+ graph.updateNode(textLayer.id, textContentFields(tree, {}, textLayer, spanOverrides))+ }try {for (const [field, variableId] of Object.entries(bindings)) {graph.bindVariable(element.bindingTarget?.(graph, node, field) ?? node.id, field, variableId)@@ -194,7 +205,8 @@ export function elementOverrides(nodeType: NodeType,tree: TreeNode,parentId: string,- context?: RenderContext+ context?: RenderContext,+ markdown?: MarkdownService): ElementOverrides {const parentLayout = graph.getNode(parentId)?.layoutMode ?? 'NONE'const isText = nodeType === 'TEXT'@@ -219,7 +231,7 @@ export function elementOverrides(// A span's variables give their values; characters keep no bindings of their own.const spanOverrides = (spanProps: Record<string, unknown>) =>propsToOverrides(preparePropsForRender(graph, spanProps, true, layer).props, true, 'NONE')- Object.assign(overrides, textContentFields(tree, props, overrides, spanOverrides))+ Object.assign(overrides, textContentFields(tree, props, overrides, spanOverrides, markdown))}return { overrides, bindings }}@@ -322,7 +334,8 @@ async function renderNodeContent<Artwork>(nodeType,element,elementParentId,- context+ context,+ services.markdown)const created = graph.createNode(nodeType, elementParentId, overrides)context?.created.push(created.id)@@ -344,7 +357,14 @@ async function renderNodeContent<Artwork>(const nodeType = elementNodeType(tree.type)if (!nodeType) throw new Error(`Unknown element: <${tree.type}>`)- const { overrides, bindings } = elementOverrides(graph, nodeType, tree, parentId, context)+ const { overrides, bindings } = elementOverrides(+ graph,+ nodeType,+ tree,+ parentId,+ context,+ services.markdown+ )const node = graph.createNode(nodeType, parentId, overrides)context?.created.push(node.id)applyBindings(graph, node.id, bindings)diff --git a/packages/design-jsx/src/services.ts b/packages/design-jsx/src/services.tsindex a98f1bd7c..24ff9e612 100644--- a/packages/design-jsx/src/services.ts+++ b/packages/design-jsx/src/services.ts@@ -33,4 +33,15 @@ export interface DesignJSXServices<Artwork> {layout(graph: SceneGraph, rootIds: readonly string[]): void/** The tight bounds of a vector network, its curves included, which size a `<Vector>`. */vectorBounds(network: VectorNetwork): Rect+ /**+ * `<Text markdown>`: Markdown as a text's characters, ranges, and paragraphs over `base`. An+ * engine without it renders everything else and refuses only `<Text markdown>`.+ */+ markdown?: MarkdownService}++/** Markdown as a text's characters, ranges, and paragraphs, relative to its own style. */+export type MarkdownService = (+ source: string,+ base: Pick<SceneNode, 'fontSize' | 'fontWeight'>+) => Pick<SceneNode, 'text' | 'styleRuns' | 'textParagraphs'>diff --git a/packages/design-jsx/src/text-content.ts b/packages/design-jsx/src/text-content.tsindex 1f15cb751..46c93876a 100644--- a/packages/design-jsx/src/text-content.ts+++ b/packages/design-jsx/src/text-content.ts@@ -16,6 +16,7 @@ import {} from '@open-pencil/scene-graph/text'import { parseScriptInput } from './schema'+import type { MarkdownService } from './services'import { isTreeNode, type TreeNode } from './tree'/** `<Span>`: characters of a text styled apart from the rest of it. */@@ -162,6 +163,20 @@ function paragraphElements(tree: TreeNode): TreeNode[] | null {return paragraphs}+/**+ * The text an element's children write, `<Span>`s and `<Paragraph>`s included, such as a sticky+ * note's body or a connector's label; other elements among them are not text and are skipped.+ */+export function textContentText(tree: TreeNode): string {+ // Mixed content fails here, before the element makes its layer.+ const paragraphs = paragraphElements(tree) ?? []+ if (paragraphs.length > 0) {+ return paragraphs.map((paragraph) => textOf(paragraph.children)).join('\n')+ }+ const inline = tree.children.filter((child) => typeof child === 'string' || child.type === SPAN)+ return textOf(inline)+}+/** Runs for the segments, holding only what differs from the text's own style. */function styleRuns(segments: readonly Segment[], textStyle: SpanStyle): StyleRun[] {const runs: StyleRun[] = []@@ -193,8 +208,10 @@ export function textContentFields(tree: TreeNode,props: Record<string, unknown>,overrides: Partial<SceneNode>,- spanOverrides: SpanOverrides+ spanOverrides: SpanOverrides,+ markdown?: MarkdownService): TextContentFields {+ if (props.markdown === true) return markdownContentFields(tree, props, overrides, markdown)if (!tree.children.some(isTextContent)) {const childText = tree.children.filter((c): c is string => typeof c === 'string').join('')const propText =@@ -231,3 +248,36 @@ export function textContentFields(textParagraphs: trimParagraphStyles(styles, styles.length)}}++/**+ * `source` without the indent all its lines share, as a template literal written inside JSX+ * indents them; a line indented further, such as a nested list item, keeps the rest.+ */+function withoutSharedIndent(source: string): string {+ const lines = source.split('\n')+ const indents = lines+ .filter((line) => line.trim() !== '')+ .map((line) => line.length - line.trimStart().length)+ if (indents.length === 0) return ''+ const shared = Math.min(...indents)+ return lines.map((line) => line.slice(Math.min(shared, line.length))).join('\n')+}++/**+ * `<Text markdown>`: its text, from children or the `text` prop, read as Markdown over the+ * text's own style. Indentation the source shares, as in a template literal, is left out.+ */+function markdownContentFields(+ tree: TreeNode,+ props: Record<string, unknown>,+ overrides: Partial<SceneNode>,+ markdown: MarkdownService | undefined+): TextContentFields {+ if (tree.children.some(isTreeNode))+ throw new Error('<Text markdown> holds only its Markdown text, not <Span> or <Paragraph>')+ if (!markdown) throw new Error('<Text markdown> needs the renderer to read Markdown')+ const childText = tree.children.filter((c): c is string => typeof c === 'string').join('')+ const source = childText || (typeof props.text === 'string' ? props.text : '')+ const base = createDefaultNode(() => '', 'TEXT', overrides)+ return markdown(withoutSharedIndent(source), base)+}diff --git a/packages/design-jsx/src/tree.ts b/packages/design-jsx/src/tree.tsindex cd3b7135a..ed2aefeef 100644--- a/packages/design-jsx/src/tree.ts+++ b/packages/design-jsx/src/tree.ts@@ -22,14 +22,6 @@ function inlineFragments(children: (TreeNode | string)[]): (TreeNode | string)[])}-/**- * The text an element holds as children, such as a sticky note's body or a connector's label.- * Elements among its children are not text and are skipped.- */-export function plainTextOf(tree: TreeNode): string {- return tree.children.filter((child): child is string => typeof child === 'string').join('')-}-export function isTreeNode(x: unknown): x is TreeNode {if (x === null || typeof x !== 'object') return falsereturn (diff --git a/packages/design-jsx/tests/export/index.test.ts b/packages/design-jsx/tests/export/index.test.tsindex f6fddf6d4..69b85cf43 100644--- a/packages/design-jsx/tests/export/index.test.ts+++ b/packages/design-jsx/tests/export/index.test.ts@@ -547,7 +547,7 @@ describe('sceneNodeAttributes', () => {})describe('selectionToJSX', () => {- test('multiple nodes separated by blank lines', () => {+ test('several nodes are siblings in a fragment, so the code is one JSX expression', () => {const graph = makeGraph()const a = graph.createNode('RECTANGLE', pageId(graph), {name: 'A',@@ -560,8 +560,6 @@ describe('selectionToJSX', () => {height: 20})const jsx = selectionToJSX([a.id, b.id], graph)- expect(jsx).toContain('<Rectangle')- expect(jsx).toContain('<Ellipse')- expect(jsx).toContain('\n\n')+ expect(jsx).toMatch(/^<>\n <Rectangle [^\n]*\/>\n <Ellipse [^\n]*\/>\n<\/>$/)})})diff --git a/packages/docs/programmable/cli/scripting.md b/packages/docs/programmable/cli/scripting.mdindex 4aa57ee3b..5dc2861e7 100644--- a/packages/docs/programmable/cli/scripting.md+++ b/packages/docs/programmable/cli/scripting.md@@ -132,6 +132,16 @@ openpencil eval design.fig -w -c 'Names the component does not have fail with an error that lists the ones it has.+`openpencil.setTextMarkdown(text, markdown)` sets a text layer's text from Markdown, styled over the layer's own style as FigJam styles Markdown typed into a text: `#` and `##` headings bold at 2.5× and 1.5× its size, deeper ones bold at its size, `**bold**`, `*italic*`, `~~strike~~`, `` `code` `` in Roboto Mono, links, lists, and quotes. Load the fonts it uses first, as for `characters`; an unloaded one fails with the font to load. Over MCP, `set_text` takes `markdown: true` for the same.++```sh+openpencil eval design.fig -w -c '+ const text = figma.currentPage.findOne((n) => n.type === "TEXT" && n.name === "Notes")+ await figma.loadFontAsync({ family: "Inter", style: "Bold" })+ openpencil.setTextMarkdown(text, "## Next\n- **Ship** the beta\n- Write the post")+'+```+Comments people leave with the Comment tool are part of the document, so scripts and agents can read the feedback on a file, act on it, and answer:```shdiff --git a/packages/docs/reference/design-authoring.md b/packages/docs/reference/design-authoring.mdindex 4639ce707..a6a91e823 100644--- a/packages/docs/reference/design-authoring.md+++ b/packages/docs/reference/design-authoring.md@@ -26,7 +26,8 @@ This reference describes scene creation, not React DOM output. Use the `render`- `rotate` turns a layer by degrees, and `flipX` and `flipY` reflect it across its centre before it turns, as the canvas places it. `Star` takes `points` and `innerRadius` (0–1, how deep its points go); `Polygon` takes `points`. `Ellipse` draws an arc or a donut with `startAngle` and `endAngle` in degrees, clockwise from three o'clock (0 to 360 by default), and `innerRadius` (0–1, the hole): `<Ellipse w={80} h={80} startAngle={0} endAngle={270} innerRadius={0.6} />`.- `effects` accepts structured effects such as `dropShadow`, `innerShadow`, and `layerBlur`. `shadow` takes a CSS `box-shadow` list, such as `shadow="0 4 8 #0002, inset 0 1 0 #fff"`, and `blur` a layer blur radius; both are convenient shorthands. Effect helpers take `radius`, as Figma's effects do; when a JSX string is rendered, an option a paint or effect helper does not support is reported as a warning.- Text content belongs inside `Text`. Use `size`, `font`, `weight`, `italic`, `lineHeight`, `letterSpacing`, `textAlign`, `textAlignVertical`, `textDecoration`, and `textCase`. Decorations take CSS's names and values: `textDecorationStyle` (`solid`, `dotted`, `wavy`), `textDecorationColor` (`currentColor` follows the text), `textDecorationThickness` and `textUnderlineOffset` (pixels or `auto`), and `textDecorationSkipInk`. `fontFeatures` turns OpenType features on or off by tag (`fontFeatures={{ tnum: true, liga: false }}`), `fontVariations` sets variable-font axes by tag (`fontVariations={{ wght: 650 }}`), and `lang` names the text's language (`lang="de"`) for shaping and font fallback. A variable font's optical size follows the font size unless `fontOpticalSizing="none"`, as in CSS; only then does an `opsz` in `fontVariations` apply. `lineHeight="auto"` follows the font, and `fills={[]}` paints no text. Verify fonts actually load before judging dimensions; do not assume every font is available.-- `Span` styles some characters of a `Text` with `Text`'s own prop names: `size`, `font`, `weight`, `italic`, `color`, `fills`, `lineHeight`, `letterSpacing`, `textDecoration`, the decoration details, `fontFeatures`, `fontVariations`, `lang`, and `textCase`; a span's `fontFeatures` and `fontVariations` replace the text's rather than adding to them, and `fontOpticalSizing` is set on the `Text` for all of it. `href` links its characters to a URL without changing how they look. Spans nest; the inner one wins. `Paragraph` writes one paragraph: `list="ordered"` or `list="unordered"` makes it a list item nested at `level` 1–5, and `spacing`, `listSpacing`, and `indent` override the `Text`'s `paragraphSpacing`, `listSpacing`, and `paragraphIndent` for it; `hangingList` on the `Text` hangs list markers outside the text box. A `Text` holds only `Paragraph`s or none; without them, a line break in its text still starts a paragraph.+- `Span` styles some characters of a `Text`, or of a `Sticky`'s body, a `Shape`'s label, or a `Connector`'s label, with `Text`'s own prop names: `size`, `font`, `weight`, `italic`, `color`, `fills`, `lineHeight`, `letterSpacing`, `textDecoration`, the decoration details, `fontFeatures`, `fontVariations`, `lang`, and `textCase`; a span's `fontFeatures` and `fontVariations` replace the text's rather than adding to them, and `fontOpticalSizing` is set on the `Text` for all of it. `href` links its characters to a URL without changing how they look. Spans nest; the inner one wins. `Paragraph` writes one paragraph: `list="ordered"` or `list="unordered"` makes it a list item nested at `level` 1–5, and `spacing`, `listSpacing`, and `indent` override the `Text`'s `paragraphSpacing`, `listSpacing`, and `paragraphIndent` for it; `hangingList` on the `Text` hangs list markers outside the text box. A `Text` holds only `Paragraph`s or none; without them, a line break in its text still starts a paragraph.+- `Text markdown` reads its text, children or `text`, as Markdown over the `Text`'s own style, as FigJam styles typed Markdown: `#` and `##` headings bold at 2.5× and 1.5× its size, deeper ones bold at its size, all at a 150% line height; `**bold**`, `*italic*`, `~~strike~~`, `` `code` `` in Roboto Mono, `[links](url)`, `-` and `1.` lists, and `>` quotes in italic. Write multiline Markdown as a template literal, ``<Text markdown>{`...`}</Text>``, since JSX folds the line breaks of plain children, and escape a code span's backticks in it as `` \` ``; the indent its lines share is left out. It holds no `Span` or `Paragraph`.- `Icon` uses an Iconify name, size, and color. Prefer icons to emoji when reliable vector output is needed. Image fills belong on appropriate leaf shapes, not containers whose children must remain visible.- Pick artwork by where it comes from. A known icon is an `Icon` by its Iconify name. A shape you draw yourself is a `Vector` with its path in SVG syntax, `<Vector d="M11 2L4 11h5l-1 7 7-9h-5z" bg={designVar(…)} />`: one layer, styled with the same props as any other, so its fills can use variables, stack, and take `strokeAlign` and `effects`. `fillRule="evenodd"` cuts holes. An open path with a `stroke` stays open, a line; with only a `bg` it fills as if closed. Given `w` and `h`, the path is drawn in that box as written, as an icon is in its view box; without them the layer fits the path. `paths` takes several paths as export writes them, each `{ windingRule, data }` with `NONZERO`, `EVENODD`, or `NONE` for an open path: `paths={[{ windingRule: "EVENODD", data: "M0 0L10 0L10 10Z" }]}`. Inline `<svg>` is for artwork copied from elsewhere: it draws the SVG's shapes, a frame with a layer per shape in the SVG's own colours, and leaves out its text, so do not use it for a shape you will style or bind, nor for text.- `Sticky` makes a FigJam sticky note whose text is its body: `<Sticky color="yellow" author="Ada">Ship it</Sticky>`. `color` takes a FigJam palette name (`white`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `violet`, `pink`) or any colour, `author` signs it (`authorVisible={false}` hides the line), `wide` makes it 416 wide instead of 240, `textSize` is `small`, `medium`, `large`, `extraLarge`, or `huge`, `typeface` is `simple`, `bookish`, `technical`, or `scribbled`, and `scale` scales the whole note. A note sizes itself; it takes no `w`, `h`, fills, or layout props.@@ -134,4 +135,4 @@ Generated from the renderer metadata. This inventory lists accepted names, not a**Helpers:** `solid`, `gradient`, `linearGradient`, `radialGradient`, `angularGradient`, `diamondGradient`, `shader`, `dropShadow`, `innerShadow`, `layerBlur`, `backgroundBlur`, `foregroundBlur`, `defineVars`, `defineMode`, `designVar`, `designMode`, `property`, `ref`.-**Properties:** `name`, `key`, `ref`, `flex`, `flow`, `dir`, `gap`, `wrap`, `rowGap`, `columnGap`, `justify`, `justifyContent`, `items`, `align`, `alignItems`, `grow`, `w`, `h`, `width`, `height`, `minW`, `maxW`, `minH`, `maxH`, `x`, `y`, `top`, `left`, `position`, `constraints`, `p`, `padding`, `px`, `py`, `pt`, `pr`, `pb`, `pl`, `bg`, `fill`, `fills`, `background`, `backgroundColor`, `stroke`, `border`, `borderColor`, `strokeWidth`, `borderWidth`, `strokeAlign`, `strokeDash`, `strokeCap`, `strokeJoin`, `dashPattern`, `strokes`, `strokeWeights`, `rounded`, `borderRadius`, `roundedTL`, `roundedTR`, `roundedBL`, `roundedBR`, `cornerRadius`, `cornerSmoothing`, `opacity`, `blendMode`, `rotate`, `rotation`, `flipX`, `flipY`, `overflow`, `mask`, `visible`, `locked`, `shadow`, `blur`, `effects`, `size`, `fontSize`, `font`, `fontFamily`, `weight`, `fontWeight`, `italic`, `color`, `text`, `characters`, `content`, `value`, `title`, `textAlign`, `textAlignHorizontal`, `textHorizontalAlignment`, `textAlignVertical`, `textVerticalAlignment`, `textAutoResize`, `lineHeight`, `letterSpacing`, `textDecoration`, `textDecorationStyle`, `textDecorationColor`, `textDecorationThickness`, `textUnderlineOffset`, `textDecorationSkipInk`, `fontFeatures`, `fontVariations`, `lang`, `fontOpticalSizing`, `textCase`, `paragraphSpacing`, `paragraphIndent`, `hangingList`, `list`, `level`, `spacing`, `listSpacing`, `indent`, `maxLines`, `truncate`, `grid`, `columns`, `rows`, `colStart`, `rowStart`, `col`, `row`, `colSpan`, `rowSpan`, `points`, `pointCount`, `innerRadius`, `startAngle`, `endAngle`, `d`, `fillRule`, `paths`, `label`, `style`, `bind`, `component`, `componentId`, `properties`, `of`, `exposed`, `overrides`, `mode`, `modelValue`, `open`, `disabled`, `filled`, `states`, `min`, `max`, `step`, `defaultValue`.\ No newline at end of file+**Properties:** `name`, `key`, `ref`, `flex`, `flow`, `dir`, `gap`, `wrap`, `rowGap`, `columnGap`, `justify`, `justifyContent`, `items`, `align`, `alignItems`, `grow`, `w`, `h`, `width`, `height`, `minW`, `maxW`, `minH`, `maxH`, `x`, `y`, `top`, `left`, `position`, `constraints`, `p`, `padding`, `px`, `py`, `pt`, `pr`, `pb`, `pl`, `bg`, `fill`, `fills`, `background`, `backgroundColor`, `stroke`, `border`, `borderColor`, `strokeWidth`, `borderWidth`, `strokeAlign`, `strokeDash`, `strokeCap`, `strokeJoin`, `dashPattern`, `strokes`, `strokeWeights`, `rounded`, `borderRadius`, `roundedTL`, `roundedTR`, `roundedBL`, `roundedBR`, `cornerRadius`, `cornerSmoothing`, `opacity`, `blendMode`, `rotate`, `rotation`, `flipX`, `flipY`, `overflow`, `mask`, `visible`, `locked`, `shadow`, `blur`, `effects`, `size`, `fontSize`, `font`, `fontFamily`, `weight`, `fontWeight`, `italic`, `color`, `text`, `characters`, `content`, `value`, `title`, `markdown`, `textAlign`, `textAlignHorizontal`, `textHorizontalAlignment`, `textAlignVertical`, `textVerticalAlignment`, `textAutoResize`, `lineHeight`, `letterSpacing`, `textDecoration`, `textDecorationStyle`, `textDecorationColor`, `textDecorationThickness`, `textUnderlineOffset`, `textDecorationSkipInk`, `fontFeatures`, `fontVariations`, `lang`, `fontOpticalSizing`, `textCase`, `paragraphSpacing`, `paragraphIndent`, `hangingList`, `list`, `level`, `spacing`, `listSpacing`, `indent`, `maxLines`, `truncate`, `grid`, `columns`, `rows`, `colStart`, `rowStart`, `col`, `row`, `colSpan`, `rowSpan`, `points`, `pointCount`, `innerRadius`, `startAngle`, `endAngle`, `d`, `fillRule`, `paths`, `label`, `style`, `bind`, `component`, `componentId`, `properties`, `of`, `exposed`, `overrides`, `mode`, `modelValue`, `open`, `disabled`, `filled`, `states`, `min`, `max`, `step`, `defaultValue`.\ No newline at end of filediff --git a/skills/open-pencil/SKILL.md b/skills/open-pencil/SKILL.mdindex 2a8063858..58a7e9c08 100644--- a/skills/open-pencil/SKILL.md+++ b/skills/open-pencil/SKILL.md@@ -26,7 +26,7 @@ Use `openpencil --help`, per-command help, and the connected MCP server’s toolInside `eval`, use `openpencil.setVariableFormula('Spacing', 'large', '{base} * 2')` for numeric formulas or `openpencil.setVariableFormula('State', 'visible', '{viewport} > 1024 and not {loading}')` for Boolean formulas, which use `and`, `or`, `not` and number comparisons. Collections and variables must already exist. An optional fourth argument selects a mode by name; otherwise the default mode is edited. The call validates before mutation and returns the resolved value. Length formulas use stored pixels. The CSS stylesheet writes number formulas as `calc()`; design-token files hold the result with the formula in `$extensions`.-Variables follow Figma's plugin API: `figma.variables.getLocalVariables()`, `createVariable(name, collection, type)`, `variable.setValueForMode(modeId, value)`, and `node.setBoundVariable(field, variable)` with Figma's field names (`characters`, `width`, `paddingLeft`) and types; paint colours bind through `figma.variables.setBoundVariableForPaint`. To bind as the layer panel does, use `openpencil.bindVariable(node, field, variable)` and `openpencil.unbindVariable(node, field)` with OpenPencil names (`text`, `visible`, `opacity`, `fills/0/color`): text content takes a text or number variable, shown as text; visibility a boolean or text one. `openpencil` also sets layout and text direction (`setLayoutDirection`, `setTextDirection`), OkHCL paint colors (`setFillOkHCL`, `setStrokeOkHCL`), exposes instance swaps (`exposeInstanceSwap`), and reports font availability (`getFontStatus()`); booleans and flattening are Figma's `figma.union`, `subtract`, `intersect`, `exclude` and `figma.flatten`.+Variables follow Figma's plugin API: `figma.variables.getLocalVariables()`, `createVariable(name, collection, type)`, `variable.setValueForMode(modeId, value)`, and `node.setBoundVariable(field, variable)` with Figma's field names (`characters`, `width`, `paddingLeft`) and types; paint colours bind through `figma.variables.setBoundVariableForPaint`. To bind as the layer panel does, use `openpencil.bindVariable(node, field, variable)` and `openpencil.unbindVariable(node, field)` with OpenPencil names (`text`, `visible`, `opacity`, `fills/0/color`): text content takes a text or number variable, shown as text; visibility a boolean or text one. `openpencil` also sets layout and text direction (`setLayoutDirection`, `setTextDirection`), OkHCL paint colors (`setFillOkHCL`, `setStrokeOkHCL`), writes styled text from Markdown (`setTextMarkdown(text, markdown)`, or `set_text` with `markdown: true`), exposes instance swaps (`exposeInstanceSwap`), and reports font availability (`getFontStatus()`); booleans and flattening are Figma's `figma.union`, `subtract`, `intersect`, `exclude` and `figma.flatten`.## Requirementsdiff --git a/skills/open-pencil/references/design-authoring.md b/skills/open-pencil/references/design-authoring.mdindex 4639ce707..a6a91e823 100644--- a/skills/open-pencil/references/design-authoring.md+++ b/skills/open-pencil/references/design-authoring.md@@ -26,7 +26,8 @@ This reference describes scene creation, not React DOM output. Use the `render`- `rotate` turns a layer by degrees, and `flipX` and `flipY` reflect it across its centre before it turns, as the canvas places it. `Star` takes `points` and `innerRadius` (0–1, how deep its points go); `Polygon` takes `points`. `Ellipse` draws an arc or a donut with `startAngle` and `endAngle` in degrees, clockwise from three o'clock (0 to 360 by default), and `innerRadius` (0–1, the hole): `<Ellipse w={80} h={80} startAngle={0} endAngle={270} innerRadius={0.6} />`.- `effects` accepts structured effects such as `dropShadow`, `innerShadow`, and `layerBlur`. `shadow` takes a CSS `box-shadow` list, such as `shadow="0 4 8 #0002, inset 0 1 0 #fff"`, and `blur` a layer blur radius; both are convenient shorthands. Effect helpers take `radius`, as Figma's effects do; when a JSX string is rendered, an option a paint or effect helper does not support is reported as a warning.- Text content belongs inside `Text`. Use `size`, `font`, `weight`, `italic`, `lineHeight`, `letterSpacing`, `textAlign`, `textAlignVertical`, `textDecoration`, and `textCase`. Decorations take CSS's names and values: `textDecorationStyle` (`solid`, `dotted`, `wavy`), `textDecorationColor` (`currentColor` follows the text), `textDecorationThickness` and `textUnderlineOffset` (pixels or `auto`), and `textDecorationSkipInk`. `fontFeatures` turns OpenType features on or off by tag (`fontFeatures={{ tnum: true, liga: false }}`), `fontVariations` sets variable-font axes by tag (`fontVariations={{ wght: 650 }}`), and `lang` names the text's language (`lang="de"`) for shaping and font fallback. A variable font's optical size follows the font size unless `fontOpticalSizing="none"`, as in CSS; only then does an `opsz` in `fontVariations` apply. `lineHeight="auto"` follows the font, and `fills={[]}` paints no text. Verify fonts actually load before judging dimensions; do not assume every font is available.-- `Span` styles some characters of a `Text` with `Text`'s own prop names: `size`, `font`, `weight`, `italic`, `color`, `fills`, `lineHeight`, `letterSpacing`, `textDecoration`, the decoration details, `fontFeatures`, `fontVariations`, `lang`, and `textCase`; a span's `fontFeatures` and `fontVariations` replace the text's rather than adding to them, and `fontOpticalSizing` is set on the `Text` for all of it. `href` links its characters to a URL without changing how they look. Spans nest; the inner one wins. `Paragraph` writes one paragraph: `list="ordered"` or `list="unordered"` makes it a list item nested at `level` 1–5, and `spacing`, `listSpacing`, and `indent` override the `Text`'s `paragraphSpacing`, `listSpacing`, and `paragraphIndent` for it; `hangingList` on the `Text` hangs list markers outside the text box. A `Text` holds only `Paragraph`s or none; without them, a line break in its text still starts a paragraph.+- `Span` styles some characters of a `Text`, or of a `Sticky`'s body, a `Shape`'s label, or a `Connector`'s label, with `Text`'s own prop names: `size`, `font`, `weight`, `italic`, `color`, `fills`, `lineHeight`, `letterSpacing`, `textDecoration`, the decoration details, `fontFeatures`, `fontVariations`, `lang`, and `textCase`; a span's `fontFeatures` and `fontVariations` replace the text's rather than adding to them, and `fontOpticalSizing` is set on the `Text` for all of it. `href` links its characters to a URL without changing how they look. Spans nest; the inner one wins. `Paragraph` writes one paragraph: `list="ordered"` or `list="unordered"` makes it a list item nested at `level` 1–5, and `spacing`, `listSpacing`, and `indent` override the `Text`'s `paragraphSpacing`, `listSpacing`, and `paragraphIndent` for it; `hangingList` on the `Text` hangs list markers outside the text box. A `Text` holds only `Paragraph`s or none; without them, a line break in its text still starts a paragraph.+- `Text markdown` reads its text, children or `text`, as Markdown over the `Text`'s own style, as FigJam styles typed Markdown: `#` and `##` headings bold at 2.5× and 1.5× its size, deeper ones bold at its size, all at a 150% line height; `**bold**`, `*italic*`, `~~strike~~`, `` `code` `` in Roboto Mono, `[links](url)`, `-` and `1.` lists, and `>` quotes in italic. Write multiline Markdown as a template literal, ``<Text markdown>{`...`}</Text>``, since JSX folds the line breaks of plain children, and escape a code span's backticks in it as `` \` ``; the indent its lines share is left out. It holds no `Span` or `Paragraph`.- `Icon` uses an Iconify name, size, and color. Prefer icons to emoji when reliable vector output is needed. Image fills belong on appropriate leaf shapes, not containers whose children must remain visible.- Pick artwork by where it comes from. A known icon is an `Icon` by its Iconify name. A shape you draw yourself is a `Vector` with its path in SVG syntax, `<Vector d="M11 2L4 11h5l-1 7 7-9h-5z" bg={designVar(…)} />`: one layer, styled with the same props as any other, so its fills can use variables, stack, and take `strokeAlign` and `effects`. `fillRule="evenodd"` cuts holes. An open path with a `stroke` stays open, a line; with only a `bg` it fills as if closed. Given `w` and `h`, the path is drawn in that box as written, as an icon is in its view box; without them the layer fits the path. `paths` takes several paths as export writes them, each `{ windingRule, data }` with `NONZERO`, `EVENODD`, or `NONE` for an open path: `paths={[{ windingRule: "EVENODD", data: "M0 0L10 0L10 10Z" }]}`. Inline `<svg>` is for artwork copied from elsewhere: it draws the SVG's shapes, a frame with a layer per shape in the SVG's own colours, and leaves out its text, so do not use it for a shape you will style or bind, nor for text.- `Sticky` makes a FigJam sticky note whose text is its body: `<Sticky color="yellow" author="Ada">Ship it</Sticky>`. `color` takes a FigJam palette name (`white`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `violet`, `pink`) or any colour, `author` signs it (`authorVisible={false}` hides the line), `wide` makes it 416 wide instead of 240, `textSize` is `small`, `medium`, `large`, `extraLarge`, or `huge`, `typeface` is `simple`, `bookish`, `technical`, or `scribbled`, and `scale` scales the whole note. A note sizes itself; it takes no `w`, `h`, fills, or layout props.@@ -134,4 +135,4 @@ Generated from the renderer metadata. This inventory lists accepted names, not a**Helpers:** `solid`, `gradient`, `linearGradient`, `radialGradient`, `angularGradient`, `diamondGradient`, `shader`, `dropShadow`, `innerShadow`, `layerBlur`, `backgroundBlur`, `foregroundBlur`, `defineVars`, `defineMode`, `designVar`, `designMode`, `property`, `ref`.-**Properties:** `name`, `key`, `ref`, `flex`, `flow`, `dir`, `gap`, `wrap`, `rowGap`, `columnGap`, `justify`, `justifyContent`, `items`, `align`, `alignItems`, `grow`, `w`, `h`, `width`, `height`, `minW`, `maxW`, `minH`, `maxH`, `x`, `y`, `top`, `left`, `position`, `constraints`, `p`, `padding`, `px`, `py`, `pt`, `pr`, `pb`, `pl`, `bg`, `fill`, `fills`, `background`, `backgroundColor`, `stroke`, `border`, `borderColor`, `strokeWidth`, `borderWidth`, `strokeAlign`, `strokeDash`, `strokeCap`, `strokeJoin`, `dashPattern`, `strokes`, `strokeWeights`, `rounded`, `borderRadius`, `roundedTL`, `roundedTR`, `roundedBL`, `roundedBR`, `cornerRadius`, `cornerSmoothing`, `opacity`, `blendMode`, `rotate`, `rotation`, `flipX`, `flipY`, `overflow`, `mask`, `visible`, `locked`, `shadow`, `blur`, `effects`, `size`, `fontSize`, `font`, `fontFamily`, `weight`, `fontWeight`, `italic`, `color`, `text`, `characters`, `content`, `value`, `title`, `textAlign`, `textAlignHorizontal`, `textHorizontalAlignment`, `textAlignVertical`, `textVerticalAlignment`, `textAutoResize`, `lineHeight`, `letterSpacing`, `textDecoration`, `textDecorationStyle`, `textDecorationColor`, `textDecorationThickness`, `textUnderlineOffset`, `textDecorationSkipInk`, `fontFeatures`, `fontVariations`, `lang`, `fontOpticalSizing`, `textCase`, `paragraphSpacing`, `paragraphIndent`, `hangingList`, `list`, `level`, `spacing`, `listSpacing`, `indent`, `maxLines`, `truncate`, `grid`, `columns`, `rows`, `colStart`, `rowStart`, `col`, `row`, `colSpan`, `rowSpan`, `points`, `pointCount`, `innerRadius`, `startAngle`, `endAngle`, `d`, `fillRule`, `paths`, `label`, `style`, `bind`, `component`, `componentId`, `properties`, `of`, `exposed`, `overrides`, `mode`, `modelValue`, `open`, `disabled`, `filled`, `states`, `min`, `max`, `step`, `defaultValue`.\ No newline at end of file+**Properties:** `name`, `key`, `ref`, `flex`, `flow`, `dir`, `gap`, `wrap`, `rowGap`, `columnGap`, `justify`, `justifyContent`, `items`, `align`, `alignItems`, `grow`, `w`, `h`, `width`, `height`, `minW`, `maxW`, `minH`, `maxH`, `x`, `y`, `top`, `left`, `position`, `constraints`, `p`, `padding`, `px`, `py`, `pt`, `pr`, `pb`, `pl`, `bg`, `fill`, `fills`, `background`, `backgroundColor`, `stroke`, `border`, `borderColor`, `strokeWidth`, `borderWidth`, `strokeAlign`, `strokeDash`, `strokeCap`, `strokeJoin`, `dashPattern`, `strokes`, `strokeWeights`, `rounded`, `borderRadius`, `roundedTL`, `roundedTR`, `roundedBL`, `roundedBR`, `cornerRadius`, `cornerSmoothing`, `opacity`, `blendMode`, `rotate`, `rotation`, `flipX`, `flipY`, `overflow`, `mask`, `visible`, `locked`, `shadow`, `blur`, `effects`, `size`, `fontSize`, `font`, `fontFamily`, `weight`, `fontWeight`, `italic`, `color`, `text`, `characters`, `content`, `value`, `title`, `markdown`, `textAlign`, `textAlignHorizontal`, `textHorizontalAlignment`, `textAlignVertical`, `textVerticalAlignment`, `textAutoResize`, `lineHeight`, `letterSpacing`, `textDecoration`, `textDecorationStyle`, `textDecorationColor`, `textDecorationThickness`, `textUnderlineOffset`, `textDecorationSkipInk`, `fontFeatures`, `fontVariations`, `lang`, `fontOpticalSizing`, `textCase`, `paragraphSpacing`, `paragraphIndent`, `hangingList`, `list`, `level`, `spacing`, `listSpacing`, `indent`, `maxLines`, `truncate`, `grid`, `columns`, `rows`, `colStart`, `rowStart`, `col`, `row`, `colSpan`, `rowSpan`, `points`, `pointCount`, `innerRadius`, `startAngle`, `endAngle`, `d`, `fillRule`, `paths`, `label`, `style`, `bind`, `component`, `componentId`, `properties`, `of`, `exposed`, `overrides`, `mode`, `modelValue`, `open`, `disabled`, `filled`, `states`, `min`, `max`, `step`, `defaultValue`.\ No newline at end of filediff --git a/tests/engine/tools/modify.test.ts b/tests/engine/tools/modify.test.tsindex 82658da4d..54f51a16f 100644--- a/tests/engine/tools/modify.test.ts+++ b/tests/engine/tools/modify.test.ts@@ -262,6 +262,31 @@ describe('set_font_range', () => {expect(getNodeOrThrow(graph, id).styleRuns).toEqual([])})+ test('sets text from Markdown, its headings and emphasis as ranges over the text’s style', async () => {+ const { figma, graph } = setupToolTest()+ const created = getTool('create_shape').execute(figma, {+ type: 'TEXT',+ x: 0,+ y: 0,+ width: 200,+ height: 20+ }) as ToolResult+ const id = expectDefined(created.id, 'created node id')+ expect(+ await runTool(figma, 'set_text', { id, text: '# Title\n- **one**', markdown: true })+ ).toEqual({ id, text: 'Title\none' })+ const node = getNodeOrThrow(graph, id)+ expect(node.textParagraphs).toEqual([+ { listType: 'NONE', indentation: 0 },+ { listType: 'UNORDERED', indentation: 1 }+ ])+ // The heading carries its size too, so it and the bold item are ranges of their own.+ expect(node.styleRuns.map((run) => [run.start, run.length, run.style.fontWeight])).toEqual([+ [0, 6, 700],+ [6, 3, 700]+ ])+ })+test('applies font style to text range and survives serialization', async () => {const { figma, graph } = setupToolTest()const created = getTool('create_shape').execute(figma, {