@pairdraw/design-jsx 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/component-properties.js +6 -6
- package/dist/chunks/component-properties.js.map +1 -1
- package/dist/chunks/elements.js +37 -32
- package/dist/chunks/elements.js.map +1 -1
- package/dist/chunks/export/decoration.js +4 -4
- package/dist/chunks/export/decoration.js.map +1 -1
- package/dist/chunks/export/index.js +20 -20
- package/dist/chunks/export/index.js.map +1 -1
- package/dist/chunks/fields.js +27 -27
- package/dist/chunks/fields.js.map +1 -1
- package/dist/chunks/index.js +1 -1
- package/dist/chunks/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/export/decoration.ts +4 -3
- package/src/export/helpers.ts +8 -6
- package/src/export/index.ts +2 -2
- package/src/export/paint.ts +45 -24
- package/src/export/props.ts +9 -9
- package/src/export/text.ts +14 -8
- package/src/export/variables.ts +1 -1
- package/src/overrides/effects.ts +7 -3
- package/src/overrides/fills.ts +6 -3
- package/src/overrides/strokes.ts +9 -5
- package/src/overrides/text.ts +4 -3
- package/src/props-overrides.ts +37 -19
- package/src/reference/authoring.md +1 -1
- package/src/renderer.ts +20 -7
- package/src/shapes-with-text.ts +2 -2
- package/src/variables/graph.ts +1 -1
package/src/renderer.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { omitBy } from 'es-toolkit/object'
|
|
|
2
2
|
|
|
3
3
|
import type { NodeType, SceneGraph, SceneNode, VariableModeMap } from '@pairdraw/scene-graph'
|
|
4
4
|
import { parseColor } from '@pairdraw/scene-graph/color'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ownInstanceOverrides,
|
|
7
|
+
setInstanceOverride
|
|
8
|
+
} from '@pairdraw/scene-graph/instances/overrides'
|
|
6
9
|
import { textLayerName } from '@pairdraw/scene-graph/node-defaults'
|
|
7
10
|
|
|
8
11
|
import type { RekaScope } from './behaviours'
|
|
@@ -183,7 +186,12 @@ function renderOwnLayerElement(
|
|
|
183
186
|
const parentLayout = graph.getNode(parentId)?.layoutMode ?? 'NONE'
|
|
184
187
|
const layer = omitBy(
|
|
185
188
|
{
|
|
186
|
-
...propsToOverrides(
|
|
189
|
+
...propsToOverrides(
|
|
190
|
+
readElementProps(element.layer, props),
|
|
191
|
+
false,
|
|
192
|
+
parentLayout,
|
|
193
|
+
graph.documentColorSpace
|
|
194
|
+
),
|
|
187
195
|
...(modes && { variableModes: modes })
|
|
188
196
|
},
|
|
189
197
|
(value) => value === undefined
|
|
@@ -426,7 +434,7 @@ async function renderInstanceNode(
|
|
|
426
434
|
throw new Error(`<Instance> component not found: ${label}`)
|
|
427
435
|
}
|
|
428
436
|
const overrides: Partial<SceneNode> = {
|
|
429
|
-
...propsToOverrides(props, false, parentLayout),
|
|
437
|
+
...propsToOverrides(props, false, parentLayout, graph.documentColorSpace),
|
|
430
438
|
...layerMetadata(modes, bound.references)
|
|
431
439
|
}
|
|
432
440
|
// Instances inherit their container layout, but explicitly authored dimensions
|
|
@@ -450,7 +458,7 @@ async function renderInstanceNode(
|
|
|
450
458
|
graph.createInstance(component.id, parentId, overrides) ?? graph.createNode('FRAME', parentId)
|
|
451
459
|
try {
|
|
452
460
|
for (const [field, value] of Object.entries(overrides)) {
|
|
453
|
-
setInstanceOverride(instance
|
|
461
|
+
setInstanceOverride(ownInstanceOverrides(instance), instance.id, instance.id, field, value)
|
|
454
462
|
}
|
|
455
463
|
graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides })
|
|
456
464
|
applyBindings(graph, instance.id, bindings)
|
|
@@ -499,7 +507,7 @@ function applyInstanceOverrides(
|
|
|
499
507
|
const child = descendants.find((n) => n.name === childName)
|
|
500
508
|
if (!child || !(prop in child)) continue
|
|
501
509
|
graph.updateNode(child.id, { [prop]: value })
|
|
502
|
-
setInstanceOverride(instance
|
|
510
|
+
setInstanceOverride(ownInstanceOverrides(instance), instance.id, child.id, prop, value)
|
|
503
511
|
mutated = true
|
|
504
512
|
}
|
|
505
513
|
if (mutated) {
|
|
@@ -561,7 +569,7 @@ export function elementOverrides(
|
|
|
561
569
|
const layer = { parentId, modes }
|
|
562
570
|
const { props, bindings } = preparePropsForRender(graph, bound.props, isText, layer)
|
|
563
571
|
const overrides = {
|
|
564
|
-
...propsToOverrides(props, isText, parentLayout),
|
|
572
|
+
...propsToOverrides(props, isText, parentLayout, graph.documentColorSpace),
|
|
565
573
|
...shapeOverrides(nodeType, props),
|
|
566
574
|
...layerMetadata(modes, bound.references)
|
|
567
575
|
}
|
|
@@ -569,7 +577,12 @@ export function elementOverrides(
|
|
|
569
577
|
if (isText) {
|
|
570
578
|
// A span's variables give their values; characters keep no bindings of their own.
|
|
571
579
|
const spanOverrides = (spanProps: Record<string, unknown>) =>
|
|
572
|
-
propsToOverrides(
|
|
580
|
+
propsToOverrides(
|
|
581
|
+
preparePropsForRender(graph, spanProps, true, layer).props,
|
|
582
|
+
true,
|
|
583
|
+
'NONE',
|
|
584
|
+
graph.documentColorSpace
|
|
585
|
+
)
|
|
573
586
|
Object.assign(overrides, textContentFields(tree, props, overrides, spanOverrides))
|
|
574
587
|
// As Figma does, a text layer follows its characters until a name is given, and keeps a given
|
|
575
588
|
// name through later edits.
|
package/src/shapes-with-text.ts
CHANGED
|
@@ -60,8 +60,8 @@ export function shapeWithTextProps(graph: SceneGraph, node: SceneNode): JSXProp[
|
|
|
60
60
|
if (height !== SHAPE_WITH_TEXT_SIZE) props.push(['h', height])
|
|
61
61
|
if (node.shapeTruncates) props.push(['truncate', true])
|
|
62
62
|
if (node.rotation !== 0) props.push(['rotate', Math.round(node.rotation * 100) / 100])
|
|
63
|
-
collectFillProps(node, props)
|
|
64
|
-
collectStrokeProps(node, props)
|
|
63
|
+
collectFillProps(node, props, graph.documentColorSpace)
|
|
64
|
+
collectStrokeProps(node, props, graph.documentColorSpace)
|
|
65
65
|
if (node.cornerRadius !== SHAPE_WITH_TEXT_CORNER_RADIUS)
|
|
66
66
|
props.push(['rounded', node.cornerRadius])
|
|
67
67
|
return props
|
package/src/variables/graph.ts
CHANGED
|
@@ -173,7 +173,7 @@ export function resolveVariableId(graph: SceneGraph, variable: DesignVariable):
|
|
|
173
173
|
return collection && variableNamed(graph, collection, variable.name)?.id
|
|
174
174
|
}
|
|
175
175
|
if (graph.variables.has(variable.name)) return variable.name
|
|
176
|
-
const matches =
|
|
176
|
+
const matches = graph.getLiveVariables().filter((item) => item.name === variable.name)
|
|
177
177
|
if (matches.length > 1) {
|
|
178
178
|
const [first] = matches
|
|
179
179
|
const collection = graph.variableCollections.get(first.collectionId)?.name ?? ''
|