@pairdraw/dom-css 0.19.0 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -3,6 +3,21 @@ import { CompileTailwindCSSOptions, Fragment, JSXChild, JSXElementProps, JSXStyl
3
3
  import { DesignDocumentToSceneGraphOptions } from "./scene-graph2.js";
4
4
  import { BrowserCSSRuntimeOptions } from "./runtime.js";
5
5
  import { SceneGraph } from "@pairdraw/scene-graph";
6
+ //#region src/import/fonts.d.ts
7
+ interface FontStackOptions {
8
+ /**
9
+ * Whether the document can draw a family, such as the font service answering. Without it every
10
+ * concrete family is taken as available, as a headless import has no faces to ask.
11
+ */
12
+ isAvailable?: (family: string) => boolean;
13
+ }
14
+ /**
15
+ * The family a CSS `font-family` stack asks a document to draw: the first concrete family the
16
+ * font service can provide; a generic keyword maps to a concrete face of its class. Null when the
17
+ * list has no family.
18
+ */
19
+ declare function resolveFontFamilyStack(value: string | undefined, options?: FontStackOptions): string | null;
20
+ //#endregion
6
21
  //#region src/browser.d.ts
7
22
  interface BrowserToDesignDocumentOptions extends BrowserCSSRuntimeOptions {
8
23
  cssText?: string;
@@ -25,5 +40,5 @@ declare function browserJSXToSceneGraph(input: JSXChild, options?: BrowserToScen
25
40
  declare function browserTailwindJSXToDesignDocument(input: JSXChild, candidates: string | Iterable<string>, options?: BrowserTailwindToDesignDocumentOptions): Promise<DesignDocument>;
26
41
  declare function browserTailwindJSXToSceneGraph(input: JSXChild, candidates: string | Iterable<string>, options?: BrowserTailwindToSceneGraphOptions): Promise<SceneGraph>;
27
42
  //#endregion
28
- export { BrowserHTMLToDesignDocumentOptions, BrowserHTMLToSceneGraphOptions, BrowserTailwindHTMLToDesignDocumentOptions, BrowserTailwindHTMLToSceneGraphOptions, BrowserTailwindToDesignDocumentOptions, BrowserTailwindToSceneGraphOptions, BrowserToDesignDocumentOptions, BrowserToSceneGraphOptions, Fragment, type JSXChild, type JSXElementProps, type JSXStyleInput, type JSXTag, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs };
43
+ export { BrowserHTMLToDesignDocumentOptions, BrowserHTMLToSceneGraphOptions, BrowserTailwindHTMLToDesignDocumentOptions, BrowserTailwindHTMLToSceneGraphOptions, BrowserTailwindToDesignDocumentOptions, BrowserTailwindToSceneGraphOptions, BrowserToDesignDocumentOptions, BrowserToSceneGraphOptions, type FontStackOptions, Fragment, type JSXChild, type JSXElementProps, type JSXStyleInput, type JSXTag, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs, resolveFontFamilyStack };
29
44
  //# sourceMappingURL=browser.d.ts.map
package/dist/browser.js CHANGED
@@ -1,2 +1,2 @@
1
- import { Fragment, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs } from "./chunks/browser.js";
2
- export { Fragment, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs };
1
+ import { Fragment, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs, resolveFontFamilyStack } from "./chunks/browser.js";
2
+ export { Fragment, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs, resolveFontFamilyStack };
@@ -1,6 +1,6 @@
1
1
  import { behaviourContract, behaviourOwner, behaviourProperties, booleanBinding, hasBehaviour, layerPath, partBinding, readBehaviour, textBinding } from "@pairdraw/scene-graph/behaviours";
2
2
  import { instanceMainComponent } from "@pairdraw/scene-graph/instances";
3
- import { instanceSlotFrames, slotPropertyId } from "@pairdraw/scene-graph/slots";
3
+ import { slotPropertyId } from "@pairdraw/scene-graph/slots";
4
4
  import { findComponentPropertyTargets } from "@pairdraw/scene-graph/components";
5
5
  //#region src/behaviours/controls.ts
6
6
  function designedBoolean(graph, instance, definition, on) {
@@ -22,6 +22,23 @@ function statesModel(graph, instance, owner, behaviour) {
22
22
  designedDisabled: !!states.disabled && authored === states.disabled
23
23
  };
24
24
  }
25
+ /**
26
+ * The frames an instance binds to slot properties, which its parts are. A slot may sit inside
27
+ * another, as a slider's range in its track: Figma keeps both in the component and makes the
28
+ * inner one part of the outer one's content in an instance, so the search goes through slots
29
+ * but not into nested instances, which are controls of their own.
30
+ */
31
+ function partFrames(graph, instance) {
32
+ const frames = [];
33
+ const visit = (node) => {
34
+ for (const child of graph.getChildren(node.id)) {
35
+ if (slotPropertyId(child)) frames.push(child);
36
+ if (child.type !== "INSTANCE") visit(child);
37
+ }
38
+ };
39
+ visit(instance);
40
+ return frames;
41
+ }
25
42
  function controlModel(graph, rootId, instance) {
26
43
  const component = instanceMainComponent(graph, instance);
27
44
  const owner = component && behaviourOwner(graph, component);
@@ -41,7 +58,8 @@ function controlModel(graph, rootId, instance) {
41
58
  designed: designedBoolean(graph, instance, definition, binding.on)
42
59
  };
43
60
  }
44
- const frames = instanceSlotFrames(graph, instance);
61
+ const choice = choiceModel(behaviour, properties, component);
62
+ const frames = partFrames(graph, instance);
45
63
  const parts = Object.fromEntries(Object.entries(behaviour.parts).flatMap(([partId, propertyId]) => {
46
64
  const frame = frames.find((item) => slotPropertyId(item) === propertyId);
47
65
  return frame ? [[partId, layerPath(graph, rootId, frame.id)]] : [];
@@ -72,6 +90,7 @@ function controlModel(graph, rootId, instance) {
72
90
  kind: behaviour.kind,
73
91
  behaviour,
74
92
  booleans,
93
+ choice,
75
94
  states: statesModel(graph, instance, owner, behaviour),
76
95
  parts,
77
96
  texts,
@@ -81,6 +100,19 @@ function controlModel(graph, rootId, instance) {
81
100
  triggers: behaviour.kind === "tabs" ? childPaths(frameOf("list")) : []
82
101
  };
83
102
  }
103
+ /** The variant property a tabs' choice binds, its options, and the drawn option's index. */
104
+ function choiceModel(behaviour, properties, component) {
105
+ const binding = behaviour.kind === "tabs" ? booleanBinding(behaviour, "value") : void 0;
106
+ const definition = properties.find((item) => item.id === binding?.propertyId && item.type === "VARIANT");
107
+ const options = definition?.variantOptions ?? [];
108
+ if (!definition || options.length === 0) return null;
109
+ const designed = component?.componentPropertyValues[definition.name];
110
+ return {
111
+ definition,
112
+ options,
113
+ designed: Math.max(0, options.indexOf(designed ?? ""))
114
+ };
115
+ }
84
116
  /**
85
117
  * The controls below a root layer, by layer path, outermost first. Items of a group are listed
86
118
  * both in the group's `items` and on their own, since each keeps its own state. Preview runs
@@ -1 +1 @@
1
- {"version":3,"file":"controls.js","names":[],"sources":["../../../src/behaviours/controls.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n behaviourContract,\n behaviourOwner,\n behaviourProperties,\n booleanBinding,\n hasBehaviour,\n layerPath,\n partBinding,\n readBehaviour,\n textBinding,\n type Behaviour\n} from '@pairdraw/scene-graph/behaviours'\nimport { findComponentPropertyTargets } from '@pairdraw/scene-graph/components'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\nimport { instanceSlotFrames, slotPropertyId } from '@pairdraw/scene-graph/slots'\n\n/** A boolean value of a control and the property that draws it. */\nexport interface BooleanModel {\n definition: ComponentPropertyDefinition\n on?: string\n off?: string\n /** The value as the document's instance draws it. */\n designed: boolean\n}\n\n/** The variant property that draws a control's interaction states. */\nexport interface StatesModel {\n name: string\n values: NonNullable<Behaviour['states']>\n /** The value the instance shows at rest. */\n rest: string | undefined\n /** Whether the document's instance is drawn disabled. */\n designedDisabled: boolean\n}\n\n/** An instance with a behaviour below a root layer: its values, states, and bound layers. */\nexport interface ControlModel {\n /** The instance's layer path below the root. */\n path: string\n kind: Behaviour['kind']\n behaviour: Behaviour\n booleans: Record<string, BooleanModel>\n states: StatesModel | null\n /** Each bound part's slot frame, by part id, as a layer path below the root. */\n parts: Record<string, string>\n /** Each bound text value's text layer, by value id, as a layer path below the root. */\n texts: Record<string, { path: string; designed: string }>\n /** The children of the items slot that are controls themselves, in order. */\n items: ControlModel[]\n /**\n * Layers the control decides to show, which the design may hide: tab panels, or a\n * collapsible's content, as layer paths below the root.\n */\n reveal: string[]\n /** For tabs, each panel's layer path, in order. */\n panels: string[]\n /** For tabs, each trigger's layer path, in order. */\n triggers: string[]\n}\n\nfunction designedBoolean(\n graph: SceneGraph,\n instance: SceneNode,\n definition: ComponentPropertyDefinition,\n on: string | undefined\n): boolean {\n if (definition.type === 'BOOLEAN') {\n const assignments = instance.componentPropertyAssignments\n const value = Object.hasOwn(assignments, definition.id)\n ? assignments[definition.id]\n : definition.defaultValue\n return value === 'true'\n }\n return instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name] === on\n}\n\nfunction statesModel(\n graph: SceneGraph,\n instance: SceneNode,\n owner: SceneNode,\n behaviour: Behaviour\n): StatesModel | null {\n const states = behaviour.states\n const definition = states\n ? behaviourProperties(graph, owner).find(\n (item) => item.id === states.propertyId && item.type === 'VARIANT'\n )\n : undefined\n if (!states || !definition) return null\n const authored = instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name]\n return {\n name: definition.name,\n values: states,\n rest: states.rest ?? authored,\n designedDisabled: !!states.disabled && authored === states.disabled\n }\n}\n\nfunction controlModel(graph: SceneGraph, rootId: string, instance: SceneNode): ControlModel | null {\n const component = instanceMainComponent(graph, instance)\n const owner = component && behaviourOwner(graph, component)\n const behaviour = owner && readBehaviour(owner)\n if (!owner || !behaviour) return null\n const path = layerPath(graph, rootId, instance.id)\n const properties = behaviourProperties(graph, owner)\n const booleans: Record<string, BooleanModel> = {}\n for (const valueId of Object.keys(behaviour.booleans)) {\n const binding = booleanBinding(behaviour, valueId)\n const definition = properties.find((item) => item.id === binding?.propertyId)\n if (!binding || !definition) continue\n booleans[valueId] = {\n definition,\n on: binding.on,\n off: binding.off,\n designed: designedBoolean(graph, instance, definition, binding.on)\n }\n }\n const frames = instanceSlotFrames(graph, instance)\n const parts = Object.fromEntries(\n Object.entries(behaviour.parts).flatMap(([partId, propertyId]) => {\n const frame = frames.find((item) => slotPropertyId(item) === propertyId)\n return frame ? [[partId, layerPath(graph, rootId, frame.id)]] : []\n })\n )\n const texts = Object.fromEntries(\n Object.keys(behaviour.texts).flatMap((valueId) => {\n const propertyId = textBinding(behaviour, valueId)\n const target = propertyId\n ? findComponentPropertyTargets(graph, instance, propertyId).find(\n (item) => item.node.type === 'TEXT'\n )\n : undefined\n return target\n ? [\n [\n valueId,\n { path: layerPath(graph, rootId, target.node.id), designed: target.node.text }\n ]\n ]\n : []\n })\n )\n const frameOf = (partId: string) => {\n const propertyId = partBinding(behaviour, partId)\n return propertyId ? frames.find((item) => slotPropertyId(item) === propertyId) : undefined\n }\n const itemsPart = behaviourContract(behaviour.kind).parts.find((part) => part.items)\n const itemsFrame = itemsPart ? frameOf(itemsPart.id) : undefined\n const items = (itemsFrame ? graph.getChildren(itemsFrame.id) : []).flatMap((child) => {\n const item = controlModel(graph, rootId, child)\n return item ? [item] : []\n })\n const childPaths = (frame: SceneNode | undefined) =>\n (frame ? graph.getChildren(frame.id) : []).map((child) => layerPath(graph, rootId, child.id))\n const panels = behaviour.kind === 'tabs' ? childPaths(frameOf('panels')) : []\n const content = behaviour.kind === 'collapsible' ? frameOf('content') : undefined\n return {\n path,\n kind: behaviour.kind,\n behaviour,\n booleans,\n states: statesModel(graph, instance, owner, behaviour),\n parts,\n texts,\n items,\n reveal: content ? [layerPath(graph, rootId, content.id)] : panels,\n panels,\n triggers: behaviour.kind === 'tabs' ? childPaths(frameOf('list')) : []\n }\n}\n\n/**\n * The controls below a root layer, by layer path, outermost first. Items of a group are listed\n * both in the group's `items` and on their own, since each keeps its own state. Preview runs\n * them as live islands; export generates components from them.\n */\nexport function behaviourControls(graph: SceneGraph, rootId: string): Map<string, ControlModel> {\n const controls = new Map<string, ControlModel>()\n const visit = (node: SceneNode) => {\n if (hasBehaviour(graph, node)) {\n const control = controlModel(graph, rootId, node)\n if (control) controls.set(control.path, control)\n }\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n const root = graph.getNode(rootId)\n if (root) visit(root)\n return controls\n}\n\n/** A control's boolean value, if the behaviour binds it. */\nexport function booleanOf(control: ControlModel, valueId: string): BooleanModel | undefined {\n return Object.hasOwn(control.booleans, valueId) ? control.booleans[valueId] : undefined\n}\n"],"mappings":";;;;;AA6DA,SAAS,gBACP,OACA,UACA,YACA,IACS;CACT,IAAI,WAAW,SAAS,WAAW;EACjC,MAAM,cAAc,SAAS;EAI7B,QAHc,OAAO,OAAO,aAAa,WAAW,EAAE,IAClD,YAAY,WAAW,MACvB,WAAW,kBACE;CACnB;CACA,OAAO,sBAAsB,OAAO,QAAQ,CAAC,EAAE,wBAAwB,WAAW,UAAU;AAC9F;AAEA,SAAS,YACP,OACA,UACA,OACA,WACoB;CACpB,MAAM,SAAS,UAAU;CACzB,MAAM,aAAa,SACf,oBAAoB,OAAO,KAAK,CAAC,CAAC,MAC/B,SAAS,KAAK,OAAO,OAAO,cAAc,KAAK,SAAS,SAC3D,IACA,KAAA;CACJ,IAAI,CAAC,UAAU,CAAC,YAAY,OAAO;CACnC,MAAM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CACvE;AACF;;;;;;AAOA,SAAgB,kBAAkB,OAAmB,QAA2C;CAC9F,MAAM,2BAAW,IAAI,IAA0B;CAC/C,MAAM,SAAS,SAAoB;EACjC,IAAI,aAAa,OAAO,IAAI,GAAG;GAC7B,MAAM,UAAU,aAAa,OAAO,QAAQ,IAAI;GAChD,IAAI,SAAS,SAAS,IAAI,QAAQ,MAAM,OAAO;EACjD;EACA,KAAK,MAAM,SAAS,MAAM,YAAY,KAAK,EAAE,GAAG,MAAM,KAAK;CAC7D;CACA,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,MAAM,MAAM,IAAI;CACpB,OAAO;AACT;;AAGA,SAAgB,UAAU,SAAuB,SAA2C;CAC1F,OAAO,OAAO,OAAO,QAAQ,UAAU,OAAO,IAAI,QAAQ,SAAS,WAAW,KAAA;AAChF"}
1
+ {"version":3,"file":"controls.js","names":[],"sources":["../../../src/behaviours/controls.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n behaviourContract,\n behaviourOwner,\n behaviourProperties,\n booleanBinding,\n hasBehaviour,\n layerPath,\n partBinding,\n readBehaviour,\n textBinding,\n type Behaviour\n} from '@pairdraw/scene-graph/behaviours'\nimport { findComponentPropertyTargets } from '@pairdraw/scene-graph/components'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\nimport { slotPropertyId } from '@pairdraw/scene-graph/slots'\n\n/** A boolean value of a control and the property that draws it. */\nexport interface BooleanModel {\n definition: ComponentPropertyDefinition\n on?: string\n off?: string\n /** The value as the document's instance draws it. */\n designed: boolean\n}\n\n/** The variant property a tabs' choice binds, its options, and the one the instance shows. */\nexport interface ChoiceControlModel {\n definition: ComponentPropertyDefinition\n options: string[]\n /** The option's index as the document's instance draws it, 0 when none does. */\n designed: number\n}\n\n/** The variant property that draws a control's interaction states. */\nexport interface StatesModel {\n name: string\n values: NonNullable<Behaviour['states']>\n /** The value the instance shows at rest. */\n rest: string | undefined\n /** Whether the document's instance is drawn disabled. */\n designedDisabled: boolean\n}\n\n/** An instance with a behaviour below a root layer: its values, states, and bound layers. */\nexport interface ControlModel {\n /** The instance's layer path below the root. */\n path: string\n kind: Behaviour['kind']\n behaviour: Behaviour\n booleans: Record<string, BooleanModel>\n /** For tabs bound to a variant property, the tabs the triggers choose among. */\n choice: ChoiceControlModel | null\n states: StatesModel | null\n /** Each bound part's slot frame, by part id, as a layer path below the root. */\n parts: Record<string, string>\n /** Each bound text value's text layer, by value id, as a layer path below the root. */\n texts: Record<string, { path: string; designed: string }>\n /** The children of the items slot that are controls themselves, in order. */\n items: ControlModel[]\n /**\n * Layers the control decides to show, which the design may hide: tab panels, or a\n * collapsible's content, as layer paths below the root.\n */\n reveal: string[]\n /** For tabs, each panel's layer path, in order. */\n panels: string[]\n /** For tabs, each trigger's layer path, in order. */\n triggers: string[]\n}\n\nfunction designedBoolean(\n graph: SceneGraph,\n instance: SceneNode,\n definition: ComponentPropertyDefinition,\n on: string | undefined\n): boolean {\n if (definition.type === 'BOOLEAN') {\n const assignments = instance.componentPropertyAssignments\n const value = Object.hasOwn(assignments, definition.id)\n ? assignments[definition.id]\n : definition.defaultValue\n return value === 'true'\n }\n return instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name] === on\n}\n\nfunction statesModel(\n graph: SceneGraph,\n instance: SceneNode,\n owner: SceneNode,\n behaviour: Behaviour\n): StatesModel | null {\n const states = behaviour.states\n const definition = states\n ? behaviourProperties(graph, owner).find(\n (item) => item.id === states.propertyId && item.type === 'VARIANT'\n )\n : undefined\n if (!states || !definition) return null\n const authored = instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name]\n return {\n name: definition.name,\n values: states,\n rest: states.rest ?? authored,\n designedDisabled: !!states.disabled && authored === states.disabled\n }\n}\n\n/**\n * The frames an instance binds to slot properties, which its parts are. A slot may sit inside\n * another, as a slider's range in its track: Figma keeps both in the component and makes the\n * inner one part of the outer one's content in an instance, so the search goes through slots\n * but not into nested instances, which are controls of their own.\n */\nfunction partFrames(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n const frames: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const child of graph.getChildren(node.id)) {\n if (slotPropertyId(child)) frames.push(child)\n if (child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(instance)\n return frames\n}\n\nfunction controlModel(graph: SceneGraph, rootId: string, instance: SceneNode): ControlModel | null {\n const component = instanceMainComponent(graph, instance)\n const owner = component && behaviourOwner(graph, component)\n const behaviour = owner && readBehaviour(owner)\n if (!owner || !behaviour) return null\n const path = layerPath(graph, rootId, instance.id)\n const properties = behaviourProperties(graph, owner)\n const booleans: Record<string, BooleanModel> = {}\n for (const valueId of Object.keys(behaviour.booleans)) {\n const binding = booleanBinding(behaviour, valueId)\n const definition = properties.find((item) => item.id === binding?.propertyId)\n if (!binding || !definition) continue\n booleans[valueId] = {\n definition,\n on: binding.on,\n off: binding.off,\n designed: designedBoolean(graph, instance, definition, binding.on)\n }\n }\n const choice = choiceModel(behaviour, properties, component)\n\n const frames = partFrames(graph, instance)\n const parts = Object.fromEntries(\n Object.entries(behaviour.parts).flatMap(([partId, propertyId]) => {\n const frame = frames.find((item) => slotPropertyId(item) === propertyId)\n return frame ? [[partId, layerPath(graph, rootId, frame.id)]] : []\n })\n )\n const texts = Object.fromEntries(\n Object.keys(behaviour.texts).flatMap((valueId) => {\n const propertyId = textBinding(behaviour, valueId)\n const target = propertyId\n ? findComponentPropertyTargets(graph, instance, propertyId).find(\n (item) => item.node.type === 'TEXT'\n )\n : undefined\n return target\n ? [\n [\n valueId,\n { path: layerPath(graph, rootId, target.node.id), designed: target.node.text }\n ]\n ]\n : []\n })\n )\n const frameOf = (partId: string) => {\n const propertyId = partBinding(behaviour, partId)\n return propertyId ? frames.find((item) => slotPropertyId(item) === propertyId) : undefined\n }\n const itemsPart = behaviourContract(behaviour.kind).parts.find((part) => part.items)\n const itemsFrame = itemsPart ? frameOf(itemsPart.id) : undefined\n const items = (itemsFrame ? graph.getChildren(itemsFrame.id) : []).flatMap((child) => {\n const item = controlModel(graph, rootId, child)\n return item ? [item] : []\n })\n const childPaths = (frame: SceneNode | undefined) =>\n (frame ? graph.getChildren(frame.id) : []).map((child) => layerPath(graph, rootId, child.id))\n const panels = behaviour.kind === 'tabs' ? childPaths(frameOf('panels')) : []\n const content = behaviour.kind === 'collapsible' ? frameOf('content') : undefined\n return {\n path,\n kind: behaviour.kind,\n behaviour,\n booleans,\n choice,\n states: statesModel(graph, instance, owner, behaviour),\n parts,\n texts,\n items,\n reveal: content ? [layerPath(graph, rootId, content.id)] : panels,\n panels,\n triggers: behaviour.kind === 'tabs' ? childPaths(frameOf('list')) : []\n }\n}\n\n/** The variant property a tabs' choice binds, its options, and the drawn option's index. */\nfunction choiceModel(\n behaviour: Behaviour,\n properties: readonly ComponentPropertyDefinition[],\n component: SceneNode | undefined\n): ChoiceControlModel | null {\n const binding = behaviour.kind === 'tabs' ? booleanBinding(behaviour, 'value') : undefined\n const definition = properties.find(\n (item) => item.id === binding?.propertyId && item.type === 'VARIANT'\n )\n const options = definition?.variantOptions ?? []\n if (!definition || options.length === 0) return null\n const designed = component?.componentPropertyValues[definition.name]\n return { definition, options, designed: Math.max(0, options.indexOf(designed ?? '')) }\n}\n\n/**\n * The controls below a root layer, by layer path, outermost first. Items of a group are listed\n * both in the group's `items` and on their own, since each keeps its own state. Preview runs\n * them as live islands; export generates components from them.\n */\nexport function behaviourControls(graph: SceneGraph, rootId: string): Map<string, ControlModel> {\n const controls = new Map<string, ControlModel>()\n const visit = (node: SceneNode) => {\n if (hasBehaviour(graph, node)) {\n const control = controlModel(graph, rootId, node)\n if (control) controls.set(control.path, control)\n }\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n const root = graph.getNode(rootId)\n if (root) visit(root)\n return controls\n}\n\n/** A control's boolean value, if the behaviour binds it. */\nexport function booleanOf(control: ControlModel, valueId: string): BooleanModel | undefined {\n return Object.hasOwn(control.booleans, valueId) ?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Q,QAAQ,YAAY,EAAE,CAAC;CAAE;AACvF;;;;;;AAOA,SAAgB,kBAAkB,OAAmB,QAA2C;CAC9F,MAAM,2BAAW,IAAI,IAA0B;CAC/C,MAAM,SAAS,SAAoB;EACjC,IAAI,aAAa,OAAO,IAAI,GAAG;GAC7B,MAAM,UAAU,aAAa,OAAO,QAAQ,IAAI;GAChD,IAAI,SAAS,SAAS,IAAI,QAAQ,MAAM,OAAO;EACjD;EACA,KAAK,MAAM,SAAS,MAAM,YAAY,KAAK,EAAE,GAAG,MAAM,KAAK;CAC7D;CACA,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,MAAM,MAAM,IAAI;CACpB,OAAO;AACT;;AAGA,SAAgB,UAAU,SAAuB,SAA2C;CAC1F,OAAO,OAAO,OAAO,QAAQ,UAAU,OAAO,IAAI,QAAQ,SAAS,WAAW,KAAA;AAChF"}
@@ -1686,6 +1686,29 @@ function addBoxSizing(style) {
1686
1686
  const boxed = Object.keys(style).some((property) => property.startsWith("padding") || property.startsWith("border") && !property.endsWith("radius"));
1687
1687
  if (sized && boxed) style["box-sizing"] = "border-box";
1688
1688
  }
1689
+ /**
1690
+ * The CSS keyword for a blend mode, where one paints the same mode. Linear burn would need
1691
+ * `plus-darker`, which Chrome, Edge, and Firefox do not implement, so it gains no keyword and
1692
+ * exports flat. A normal layer or an unscoped pass-through needs none either.
1693
+ */
1694
+ const CSS_BLEND_MODES = {
1695
+ DARKEN: "darken",
1696
+ MULTIPLY: "multiply",
1697
+ COLOR_BURN: "color-burn",
1698
+ LIGHTEN: "lighten",
1699
+ SCREEN: "screen",
1700
+ LINEAR_DODGE: "plus-lighter",
1701
+ COLOR_DODGE: "color-dodge",
1702
+ OVERLAY: "overlay",
1703
+ SOFT_LIGHT: "soft-light",
1704
+ HARD_LIGHT: "hard-light",
1705
+ DIFFERENCE: "difference",
1706
+ EXCLUSION: "exclusion",
1707
+ HUE: "hue",
1708
+ SATURATION: "saturation",
1709
+ COLOR: "color",
1710
+ LUMINOSITY: "luminosity"
1711
+ };
1689
1712
  function styleFromSceneNode(node, parent, css) {
1690
1713
  const style = {};
1691
1714
  addSize(style, node, parent, css);
@@ -1699,6 +1722,8 @@ function styleFromSceneNode(node, parent, css) {
1699
1722
  addStroke(style, node, css);
1700
1723
  Object.assign(style, effectsToCSS(node.effects));
1701
1724
  if (node.opacity < 1) style.opacity = css("opacity", String(node.opacity));
1725
+ const blend = CSS_BLEND_MODES[node.blendMode];
1726
+ if (blend) style["mix-blend-mode"] = blend;
1702
1727
  addCornerRadii(style, node, css);
1703
1728
  if (node.clipsContent) style.overflow = "hidden";
1704
1729
  const alignSelf = alignToCSS(node.layoutAlignSelf);