@pairdraw/core 0.19.1 → 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/canvas/images/previews.d.ts +1 -1
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/selection.d.ts +1 -2
- package/dist/canvas/overlays/selection.d.ts.map +1 -1
- package/dist/canvas/overlays/selection.js +2 -9
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +2 -0
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +0 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -4
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +0 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +0 -1
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +0 -1
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +0 -1
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/design-jsx/index.d.ts +2 -2
- package/dist/design-jsx/index.js +2 -2
- package/dist/design-jsx/renderer.d.ts +3 -2
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/design-jsx/renderer.js +2 -2
- package/dist/design-jsx/renderer.js.map +1 -1
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +12 -4
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +2 -7
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/color-space.d.ts.map +1 -1
- package/dist/editor/color-space.js +33 -38
- package/dist/editor/color-space.js.map +1 -1
- package/dist/editor/create.d.ts +9 -5
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +10 -1
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +2 -1
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/nudge.js +1 -1
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/read-only/actions.js +2 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/container.d.ts +2 -0
- package/dist/editor/selection/container.d.ts.map +1 -1
- package/dist/editor/selection/container.js +17 -1
- package/dist/editor/selection/container.js.map +1 -1
- package/dist/editor/selection/navigation.js +7 -4
- package/dist/editor/selection/navigation.js.map +1 -1
- package/dist/editor/selection/read.d.ts +2 -2
- package/dist/editor/selection.d.ts +4 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.js +2 -5
- package/dist/editor/shapes/with-text.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +1 -1
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +2 -3
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +1 -3
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/outline-stroke.js +3 -3
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +7 -14
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -2
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +3 -3
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/types.d.ts +4 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +57 -1
- package/dist/editor/variables.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +4 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/fonts/loaded.d.ts +3 -1
- package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
- package/dist/figma-api/fonts/loaded.js +8 -1
- package/dist/figma-api/fonts/loaded.js.map +1 -1
- package/dist/figma-api/index.d.ts +13 -0
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +13 -0
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/serialization.d.ts.map +1 -1
- package/dist/figma-api/serialization.js +2 -1
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/shape-details.d.ts +26 -0
- package/dist/figma-api/shape-details.d.ts.map +1 -0
- package/dist/figma-api/shape-details.js +28 -0
- package/dist/figma-api/shape-details.js.map +1 -0
- package/dist/figma-api/shape-with-text.js +2 -5
- package/dist/figma-api/shape-with-text.js.map +1 -1
- package/dist/figma-api/surface.d.ts +1 -1
- package/dist/figma-api/surface.d.ts.map +1 -1
- package/dist/figma-api/surface.js +1 -0
- package/dist/figma-api/surface.js.map +1 -1
- package/dist/icons/svg.js +1 -1
- package/dist/icons/svg.js.map +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +1 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +7 -4
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +4 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts +6 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +9 -22
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -1
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +3 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +52 -16
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +50 -12
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/derived.d.ts +7 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +11 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/grid.d.ts +7 -2
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +27 -9
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/mutations.d.ts +1 -0
- package/dist/layout/mutations.d.ts.map +1 -1
- package/dist/layout/mutations.js +10 -0
- package/dist/layout/mutations.js.map +1 -1
- package/dist/layout/strokes.d.ts +9 -1
- package/dist/layout/strokes.d.ts.map +1 -1
- package/dist/layout/strokes.js +12 -1
- package/dist/layout/strokes.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +3 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +16 -2
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +71 -38
- package/dist/layout.js.map +1 -1
- package/dist/lint/linter.d.ts +1 -0
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +13 -1
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/rules/effect-style-required.js +1 -0
- package/dist/lint/rules/effect-style-required.js.map +1 -1
- package/dist/lint/rules/text-style-required.js +1 -0
- package/dist/lint/rules/text-style-required.js.map +1 -1
- package/dist/lint/types.d.ts +7 -0
- package/dist/lint/types.d.ts.map +1 -1
- package/dist/rpc/commands.d.ts +2 -2
- package/dist/rpc/index.d.ts +2 -2
- package/dist/rpc/read-commands.d.ts +18 -8
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +18 -9
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/font/faces.d.ts +12 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +15 -1
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +6 -11
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +1 -0
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +14 -0
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +39 -7
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/xpath.d.ts +3 -0
- package/dist/xpath.d.ts.map +1 -1
- package/dist/xpath.js +3 -1
- package/dist/xpath.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/selection.ts +1 -12
- package/src/canvas/renderer/fonts.ts +2 -0
- package/src/canvas/renderer/methods.ts +0 -9
- package/src/canvas/renderer/overlay-pass.ts +0 -1
- package/src/canvas/renderer/pipeline.ts +0 -1
- package/src/canvas/renderer/types.ts +0 -1
- package/src/canvas/renderer.ts +0 -1
- package/src/design-jsx/index.ts +1 -1
- package/src/design-jsx/renderer.ts +1 -1
- package/src/editor/clipboard/snapshot.ts +21 -4
- package/src/editor/clipboard.ts +4 -14
- package/src/editor/color-space.ts +47 -38
- package/src/editor/create.ts +14 -2
- package/src/editor/history/edit.ts +5 -1
- package/src/editor/nudge.ts +1 -1
- package/src/editor/read-only/actions.ts +2 -0
- package/src/editor/selection/container.ts +24 -1
- package/src/editor/selection/navigation.ts +8 -6
- package/src/editor/shapes/with-text.ts +2 -5
- package/src/editor/structure/auto-layout-wrap.ts +1 -1
- package/src/editor/structure/boolean.ts +1 -3
- package/src/editor/structure/group/bounds.ts +1 -5
- package/src/editor/structure/outline-stroke.ts +3 -3
- package/src/editor/structure/reorder.ts +8 -14
- package/src/editor/structure/state.ts +1 -1
- package/src/editor/structure.ts +5 -8
- package/src/editor/types.ts +4 -1
- package/src/editor/variables.ts +74 -2
- package/src/figma-api/accessors/text/index.ts +10 -1
- package/src/figma-api/fonts/loaded.ts +9 -0
- package/src/figma-api/index.ts +25 -0
- package/src/figma-api/serialization.ts +2 -1
- package/src/figma-api/shape-details.ts +50 -0
- package/src/figma-api/shape-with-text.ts +2 -5
- package/src/figma-api/surface.ts +1 -0
- package/src/global.d.ts +5 -0
- package/src/icons/svg.ts +3 -1
- package/src/io/formats/drawio/index.ts +3 -1
- package/src/io/formats/html/layers.ts +11 -2
- package/src/io/formats/pdf/dom.ts +10 -18
- package/src/io/formats/pdf/export.ts +1 -1
- package/src/io/formats/svg/defs.ts +10 -1
- package/src/io/formats/svg/export.ts +94 -19
- package/src/layout/apply.ts +87 -21
- package/src/layout/derived.ts +14 -0
- package/src/layout/grid.ts +33 -9
- package/src/layout/mutations.ts +13 -1
- package/src/layout/strokes.ts +12 -0
- package/src/layout/yoga-helpers.ts +18 -1
- package/src/layout.ts +94 -49
- package/src/lint/linter.ts +17 -2
- package/src/lint/rules/effect-style-required.ts +2 -0
- package/src/lint/rules/text-style-required.ts +2 -0
- package/src/lint/types.ts +8 -0
- package/src/rpc/index.ts +1 -0
- package/src/rpc/read-commands.ts +40 -23
- package/src/text/font/faces.ts +22 -0
- package/src/text/font/manager.ts +9 -11
- package/src/tools/modify/layout.ts +5 -0
- package/src/tools/read/nodes.ts +0 -1
- package/src/tools/structure/batch.ts +22 -0
- package/src/tools/vector/path.ts +30 -6
- package/src/xpath.ts +6 -1
package/src/layout.ts
CHANGED
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
setCrossAxisSizing,
|
|
20
20
|
setMainAxisSizing
|
|
21
21
|
} from './layout/axis-sizing'
|
|
22
|
-
import { keepsSavedLayout, usesDetachedDerivedLayout } from './layout/derived'
|
|
22
|
+
import { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './layout/derived'
|
|
23
23
|
import { applyEffectiveGeneratedTextLayout } from './layout/effective-generated-text'
|
|
24
24
|
import { insertFlowBox, setFlexFlow, setFlowEdges } from './layout/flow-edges'
|
|
25
|
-
import { buildGridTree, createGridChildNode } from './layout/grid'
|
|
25
|
+
import { buildGridTree, createGridChildNode, gridTracksForAxis } from './layout/grid'
|
|
26
26
|
import { sizeAutoResizingText } from './layout/text-auto-resize'
|
|
27
27
|
export { sizeAutoResizingText } from './layout/text-auto-resize'
|
|
28
28
|
export {
|
|
@@ -37,7 +37,12 @@ import { connectorSublayers, layoutConnector } from '@pairdraw/scene-graph/conne
|
|
|
37
37
|
import { layoutSizing } from '@pairdraw/scene-graph/layout'
|
|
38
38
|
|
|
39
39
|
import { fitShapeWithTextFrame } from './layout/shape-with-text'
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
applyContentInsets,
|
|
42
|
+
applyStrokeMargins,
|
|
43
|
+
contentInsetsSize,
|
|
44
|
+
strokeRoom
|
|
45
|
+
} from './layout/strokes'
|
|
41
46
|
import {
|
|
42
47
|
autoWidthWrapWidth,
|
|
43
48
|
estimateTextSize,
|
|
@@ -77,13 +82,19 @@ function computeLayoutInternal(graph: SceneGraph, frameId: string): void {
|
|
|
77
82
|
|
|
78
83
|
const rootDirection = resolveComputedLayoutDirection(graph, frame)
|
|
79
84
|
const yogaDirection = rootDirection === 'RTL' ? Direction.RTL : Direction.LTR
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
// The tree is freed on every path, a refused pass included: Yoga's nodes are WebAssembly memory
|
|
86
|
+
// the caller owns, so a throw must not leave them behind.
|
|
87
|
+
let yogaRoot: YogaNode | null = null
|
|
88
|
+
try {
|
|
89
|
+
yogaRoot =
|
|
90
|
+
frame.layoutMode === 'GRID'
|
|
91
|
+
? buildGridTree(graph, frame, rootDirection)
|
|
92
|
+
: buildYogaTree(graph, frame, rootDirection)
|
|
93
|
+
yogaRoot.calculateLayout(undefined, undefined, yogaDirection)
|
|
94
|
+
applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal)
|
|
95
|
+
} finally {
|
|
96
|
+
if (yogaRoot) freeYogaTree(yogaRoot)
|
|
97
|
+
}
|
|
87
98
|
}
|
|
88
99
|
function resolveComputedLayoutDirection(
|
|
89
100
|
graph: SceneGraph,
|
|
@@ -175,27 +186,37 @@ function buildYogaTree(
|
|
|
175
186
|
): YogaNode {
|
|
176
187
|
const root = createYogaNode()
|
|
177
188
|
const direction = resolveNodeLayoutDirection(frame, inheritedDirection)
|
|
189
|
+
const insets = keepsSavedFrameSize(graph, frame) ? null : contentInsetsSize(frame)
|
|
190
|
+
const width = insets ? Math.max(frame.width, insets.width) : frame.width
|
|
191
|
+
const height = insets ? Math.max(frame.height, insets.height) : frame.height
|
|
178
192
|
|
|
179
193
|
if (frame.primaryAxisSizing === 'FIXED') {
|
|
180
|
-
if (frame.layoutMode === 'HORIZONTAL') root.setWidth(
|
|
181
|
-
else root.setHeight(
|
|
194
|
+
if (frame.layoutMode === 'HORIZONTAL') root.setWidth(width)
|
|
195
|
+
else root.setHeight(height)
|
|
182
196
|
}
|
|
183
197
|
if (frame.counterAxisSizing === 'FIXED') {
|
|
184
|
-
if (frame.layoutMode === 'HORIZONTAL') root.setHeight(
|
|
185
|
-
else root.setWidth(
|
|
198
|
+
if (frame.layoutMode === 'HORIZONTAL') root.setHeight(height)
|
|
199
|
+
else root.setWidth(width)
|
|
186
200
|
}
|
|
187
201
|
// Laid out on its own, a frame its parent stretches keeps the size the parent gave it on
|
|
188
202
|
// that axis, so its content aligns within that size rather than within a hug.
|
|
189
203
|
const stretchedAxis = parentStretchedAxis(graph, frame)
|
|
190
|
-
if (stretchedAxis === 'width') root.setWidth(
|
|
191
|
-
if (stretchedAxis === 'height') root.setHeight(
|
|
204
|
+
if (stretchedAxis === 'width') root.setWidth(width)
|
|
205
|
+
if (stretchedAxis === 'height') root.setHeight(height)
|
|
192
206
|
const heldAxis = heldHugAxis(graph, frame)
|
|
193
|
-
if (heldAxis === 'width') root.setWidth(
|
|
194
|
-
if (heldAxis === 'height') root.setHeight(
|
|
207
|
+
if (heldAxis === 'width') root.setWidth(width)
|
|
208
|
+
if (heldAxis === 'height') root.setHeight(height)
|
|
195
209
|
|
|
196
210
|
configureFlexContainer(root, frame, direction)
|
|
197
211
|
|
|
198
|
-
|
|
212
|
+
try {
|
|
213
|
+
insertFlexChildren(root, frame, graph, direction, 1)
|
|
214
|
+
} catch (error) {
|
|
215
|
+
// The depth check refuses a chain while the tree is half built; every node made so far hangs
|
|
216
|
+
// from the root, which has no other holder.
|
|
217
|
+
freeYogaTree(root)
|
|
218
|
+
throw error
|
|
219
|
+
}
|
|
199
220
|
|
|
200
221
|
return root
|
|
201
222
|
}
|
|
@@ -213,6 +234,39 @@ function configureFlexContainer(
|
|
|
213
234
|
applyMinMaxConstraints(yogaNode, node)
|
|
214
235
|
}
|
|
215
236
|
|
|
237
|
+
/**
|
|
238
|
+
* A grid child's box in its flex parent: grow takes the free space, a fixed size is stored, and
|
|
239
|
+
* an axis the grid hugs takes its tracks' size there, as configureAsGrid lays it out.
|
|
240
|
+
*/
|
|
241
|
+
function applyGridChildBox(yogaChild: YogaNode, child: SceneNode, parent: SceneNode): void {
|
|
242
|
+
const isParentRow = parent.layoutMode === 'HORIZONTAL'
|
|
243
|
+
const selfOverride = child.layoutAlignSelf !== 'AUTO'
|
|
244
|
+
const stretchCross = selfOverride
|
|
245
|
+
? child.layoutAlignSelf === 'STRETCH'
|
|
246
|
+
: parent.counterAxisAlign === 'STRETCH'
|
|
247
|
+
const hugWidth = ownAxisSizing(child, 'width') === 'HUG'
|
|
248
|
+
const hugHeight = ownAxisSizing(child, 'height') === 'HUG'
|
|
249
|
+
if (child.layoutGrow > 0) {
|
|
250
|
+
yogaChild.setFlexGrow(child.layoutGrow)
|
|
251
|
+
yogaChild.setFlexShrink(1)
|
|
252
|
+
yogaChild.setFlexBasis(0)
|
|
253
|
+
if (stretchCross) return
|
|
254
|
+
if (isParentRow) {
|
|
255
|
+
if (!hugHeight) yogaChild.setHeight(child.height)
|
|
256
|
+
} else if (!hugWidth) {
|
|
257
|
+
yogaChild.setWidth(child.width)
|
|
258
|
+
}
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
if (isParentRow) {
|
|
262
|
+
if (!hugWidth) yogaChild.setWidth(child.width)
|
|
263
|
+
if (!stretchCross && !hugHeight) yogaChild.setHeight(child.height)
|
|
264
|
+
return
|
|
265
|
+
}
|
|
266
|
+
if (child.gridTemplateRows.length > 0 && !hugHeight) yogaChild.setHeight(child.height)
|
|
267
|
+
if (!stretchCross && !hugWidth) yogaChild.setWidth(child.width)
|
|
268
|
+
}
|
|
269
|
+
|
|
216
270
|
function configureChildAsGrid(
|
|
217
271
|
yogaChild: YogaNode,
|
|
218
272
|
child: SceneNode,
|
|
@@ -225,40 +279,17 @@ function configureChildAsGrid(
|
|
|
225
279
|
yogaChild.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)
|
|
226
280
|
|
|
227
281
|
if (child.gridTemplateColumns.length > 0) {
|
|
228
|
-
yogaChild.setGridTemplateColumns(child.
|
|
282
|
+
yogaChild.setGridTemplateColumns(gridTracksForAxis(child, 'width').map(mapGridTrack))
|
|
229
283
|
}
|
|
230
284
|
if (child.gridTemplateRows.length > 0) {
|
|
231
|
-
yogaChild.setGridTemplateRows(child.
|
|
285
|
+
yogaChild.setGridTemplateRows(gridTracksForAxis(child, 'height').map(mapGridTrack))
|
|
232
286
|
}
|
|
233
287
|
|
|
234
288
|
yogaChild.setGap(Gutter.Column, child.gridColumnGap)
|
|
235
289
|
yogaChild.setGap(Gutter.Row, child.gridRowGap)
|
|
236
290
|
|
|
237
291
|
applyContentInsets(yogaChild, child)
|
|
238
|
-
|
|
239
|
-
const isParentRow = parent.layoutMode === 'HORIZONTAL'
|
|
240
|
-
const selfOverride = child.layoutAlignSelf !== 'AUTO'
|
|
241
|
-
const stretchCross = selfOverride
|
|
242
|
-
? child.layoutAlignSelf === 'STRETCH'
|
|
243
|
-
: parent.counterAxisAlign === 'STRETCH'
|
|
244
|
-
|
|
245
|
-
if (child.layoutGrow > 0) {
|
|
246
|
-
yogaChild.setFlexGrow(child.layoutGrow)
|
|
247
|
-
yogaChild.setFlexShrink(1)
|
|
248
|
-
yogaChild.setFlexBasis(0)
|
|
249
|
-
if (!stretchCross) {
|
|
250
|
-
if (isParentRow) yogaChild.setHeight(child.height)
|
|
251
|
-
else yogaChild.setWidth(child.width)
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
if (isParentRow) {
|
|
255
|
-
yogaChild.setWidth(child.width)
|
|
256
|
-
if (!stretchCross) yogaChild.setHeight(child.height)
|
|
257
|
-
} else {
|
|
258
|
-
if (child.gridTemplateRows.length > 0) yogaChild.setHeight(child.height)
|
|
259
|
-
if (!stretchCross) yogaChild.setWidth(child.width)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
292
|
+
applyGridChildBox(yogaChild, child, parent)
|
|
262
293
|
|
|
263
294
|
const selfAlign = mapAlignSelf(child.layoutAlignSelf)
|
|
264
295
|
if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)
|
|
@@ -399,6 +430,9 @@ function insertFlexChildren(
|
|
|
399
430
|
.getChildren(parent.id)
|
|
400
431
|
.map((node) => asLaidOutIn(graph, node, parent))) {
|
|
401
432
|
const yogaChild = createYogaNode()
|
|
433
|
+
// Attached before it is configured, so a child the depth check refuses still hangs from the
|
|
434
|
+
// root and is freed with it rather than left in WebAssembly memory.
|
|
435
|
+
box.insertChild(yogaChild, box.getChildCount())
|
|
402
436
|
|
|
403
437
|
if (child.layoutPositioning === 'ABSOLUTE') {
|
|
404
438
|
configureAbsoluteChild(yogaChild, child)
|
|
@@ -415,8 +449,6 @@ function insertFlexChildren(
|
|
|
415
449
|
flow.push(yogaChild)
|
|
416
450
|
}
|
|
417
451
|
applyStrokeMargins(yogaChild, child, parent)
|
|
418
|
-
|
|
419
|
-
box.insertChild(yogaChild, box.getChildCount())
|
|
420
452
|
}
|
|
421
453
|
setFlowEdges(yogaParent, box, parent, flow, direction)
|
|
422
454
|
}
|
|
@@ -478,7 +510,14 @@ function configureTextLeafWithoutMeasurer(
|
|
|
478
510
|
}
|
|
479
511
|
return
|
|
480
512
|
}
|
|
481
|
-
if (child.textAutoResize !== 'HEIGHT')
|
|
513
|
+
if (child.textAutoResize !== 'HEIGHT') {
|
|
514
|
+
// A truncating text keeps the box it has, as Figma clips it to that box.
|
|
515
|
+
if (child.width > 0 && child.height > 0) {
|
|
516
|
+
yogaChild.setWidth(child.width)
|
|
517
|
+
yogaChild.setHeight(child.height)
|
|
518
|
+
}
|
|
519
|
+
return
|
|
520
|
+
}
|
|
482
521
|
|
|
483
522
|
const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)
|
|
484
523
|
const isRow = parent.layoutMode === 'HORIZONTAL'
|
|
@@ -510,7 +549,8 @@ function configureChildAsLeaf(
|
|
|
510
549
|
|
|
511
550
|
const isText = child.type === 'TEXT'
|
|
512
551
|
const textMeasurer = getTextMeasurer()
|
|
513
|
-
|
|
552
|
+
// A truncating or fixed text keeps its box, so Yoga measures only text that grows.
|
|
553
|
+
const needsMeasureFunc = isText && textMeasurer && growsText(child)
|
|
514
554
|
|
|
515
555
|
const fixedDerivedMainAxis = isRow
|
|
516
556
|
? derivedGrowingLeafFitsParent(graph, parent, child, 'width')
|
|
@@ -542,6 +582,11 @@ function configureChildAsLeaf(
|
|
|
542
582
|
applyMinMaxConstraints(yogaChild, child)
|
|
543
583
|
}
|
|
544
584
|
|
|
585
|
+
/** Whether layout measures a text to size it, which only the two growing modes need. */
|
|
586
|
+
function growsText(node: SceneNode): boolean {
|
|
587
|
+
return node.textAutoResize === 'WIDTH_AND_HEIGHT' || node.textAutoResize === 'HEIGHT'
|
|
588
|
+
}
|
|
589
|
+
|
|
545
590
|
function configureTextLeaf(
|
|
546
591
|
yogaChild: YogaNode,
|
|
547
592
|
child: SceneNode,
|
package/src/lint/linter.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { uniq } from 'es-toolkit'
|
|
2
2
|
|
|
3
|
-
import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
3
|
+
import type { SceneGraph, SceneNode, SharedStyleType } from '@pairdraw/scene-graph'
|
|
4
4
|
import { colorToHex } from '@pairdraw/scene-graph/color'
|
|
5
|
+
import { sharedStyleLayers, sharedStyleTypeForKind } from '@pairdraw/scene-graph/shared-styles'
|
|
5
6
|
|
|
6
7
|
import { presets } from './presets'
|
|
7
8
|
import { allRules } from './rules'
|
|
@@ -49,6 +50,7 @@ export class Linter {
|
|
|
49
50
|
counts: { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 },
|
|
50
51
|
colorsByHex: new Map()
|
|
51
52
|
}
|
|
53
|
+
private sharedStyleTypes: ReadonlyMap<string, SharedStyleType> = new Map()
|
|
52
54
|
|
|
53
55
|
constructor(options: { config?: LintConfig; preset?: string; rules?: string[] } = {}) {
|
|
54
56
|
let baseConfig: Record<
|
|
@@ -80,6 +82,7 @@ export class Linter {
|
|
|
80
82
|
this.nodes.clear()
|
|
81
83
|
this.graph = graph
|
|
82
84
|
this.variables = describeVariables(graph)
|
|
85
|
+
this.sharedStyleTypes = sharedStyleTypes(graph)
|
|
83
86
|
this.checks = this.ruleChecks()
|
|
84
87
|
const roots = rootIds && rootIds.length > 0 ? rootIds : graph.getPages().map((p) => p.id)
|
|
85
88
|
for (const id of outermostRoots(graph, roots)) this.lintNode(id, undefined)
|
|
@@ -165,7 +168,9 @@ export class Linter {
|
|
|
165
168
|
type: effect.type,
|
|
166
169
|
visible: effect.visible,
|
|
167
170
|
radius: effect.type === 'SHADER' ? 0 : effect.radius
|
|
168
|
-
}))
|
|
171
|
+
})),
|
|
172
|
+
textStyleId: raw.textStyleId,
|
|
173
|
+
effectStyleId: raw.effectStyleId
|
|
169
174
|
}
|
|
170
175
|
}
|
|
171
176
|
|
|
@@ -179,6 +184,8 @@ export class Linter {
|
|
|
179
184
|
rule,
|
|
180
185
|
context: {
|
|
181
186
|
variables: this.variables,
|
|
187
|
+
isSharedStyle: (kind, id) =>
|
|
188
|
+
id !== null && this.sharedStyleTypes.get(id) === sharedStyleTypeForKind(kind),
|
|
182
189
|
report: ({ node, message, suggest, data, fix, suggestions }) => {
|
|
183
190
|
this.messages.push({
|
|
184
191
|
ruleId,
|
|
@@ -234,6 +241,14 @@ function outermostRoots(graph: SceneGraph, ids: readonly string[]): string[] {
|
|
|
234
241
|
})
|
|
235
242
|
}
|
|
236
243
|
|
|
244
|
+
/** The type of each shared style in the document, by the source id layers link it by. */
|
|
245
|
+
function sharedStyleTypes(graph: SceneGraph): ReadonlyMap<string, SharedStyleType> {
|
|
246
|
+
const types = new Map<string, SharedStyleType>()
|
|
247
|
+
for (const [id, style] of sharedStyleLayers(graph))
|
|
248
|
+
if (style.sharedStyleType) types.set(id, style.sharedStyleType)
|
|
249
|
+
return types
|
|
250
|
+
}
|
|
251
|
+
|
|
237
252
|
function describeVariables(graph: SceneGraph): LintVariables {
|
|
238
253
|
const counts = { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 }
|
|
239
254
|
const colorsByHex = new Map<string, { id: string; name: string }>()
|
|
@@ -9,6 +9,8 @@ export default defineRule({
|
|
|
9
9
|
check(node, context) {
|
|
10
10
|
const visibleEffects = node.effects.filter((effect) => effect.visible)
|
|
11
11
|
if (visibleEffects.length === 0) return
|
|
12
|
+
// A link to a shared EFFECT style is already the preset this rule asks for.
|
|
13
|
+
if (context.isSharedStyle('effect', node.effectStyleId)) return
|
|
12
14
|
context.report({
|
|
13
15
|
node,
|
|
14
16
|
message: `Effect without shared style: ${visibleEffects.map((effect) => `${effect.type} ${effect.radius}px`).join(', ')}`,
|
|
@@ -9,6 +9,8 @@ export default defineRule({
|
|
|
9
9
|
match: ['TEXT'],
|
|
10
10
|
check(node, context) {
|
|
11
11
|
if (node.text.length <= 2) return
|
|
12
|
+
// A shared text style is already the shared typography this rule asks for.
|
|
13
|
+
if (context.isSharedStyle('text', node.textStyleId)) return
|
|
12
14
|
if (node.boundVariables.fontSize || node.boundVariables.fontFamily) return
|
|
13
15
|
// Suggesting a binding is only actionable when the document has typography values to bind.
|
|
14
16
|
const { FLOAT, STRING } = context.variables.counts
|
package/src/lint/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { SharedStyleKind } from '@pairdraw/scene-graph'
|
|
2
|
+
|
|
1
3
|
export type Severity = 'error' | 'warning' | 'info' | 'off'
|
|
2
4
|
|
|
3
5
|
export type Category =
|
|
@@ -124,6 +126,10 @@ export interface LintNode {
|
|
|
124
126
|
visible: boolean
|
|
125
127
|
radius: number
|
|
126
128
|
}>
|
|
129
|
+
/** The shared text style this layer uses, when it has one. */
|
|
130
|
+
textStyleId: string | null
|
|
131
|
+
/** The shared effect style this layer uses, when it has one. */
|
|
132
|
+
effectStyleId: string | null
|
|
127
133
|
parent?: LintNode
|
|
128
134
|
}
|
|
129
135
|
|
|
@@ -137,6 +143,8 @@ export interface LintVariables {
|
|
|
137
143
|
|
|
138
144
|
export interface RuleContext {
|
|
139
145
|
variables: LintVariables
|
|
146
|
+
/** Whether `id`, a layer's style link, names a shared style of that kind in the document. */
|
|
147
|
+
isSharedStyle(kind: SharedStyleKind, id: string | null): boolean
|
|
140
148
|
report(issue: {
|
|
141
149
|
node: LintNode
|
|
142
150
|
message: string
|
package/src/rpc/index.ts
CHANGED
package/src/rpc/read-commands.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { sumBy } from 'es-toolkit'
|
|
2
2
|
|
|
3
|
-
import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
3
|
+
import type { BooleanOperation, MaskType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
4
4
|
|
|
5
|
+
import { shapeDetailFields } from '#core/figma-api/shape-details'
|
|
5
6
|
import { ELLIPSIS } from '#core/text/ellipsis'
|
|
6
7
|
import type { DocumentFontStatus } from '#core/text/font/status'
|
|
7
8
|
import { prepareGraphFonts } from '#core/text/prepare'
|
|
@@ -20,6 +21,28 @@ function walkNodes(graph: SceneGraph, rootId: string, fn: (node: SceneNode) => b
|
|
|
20
21
|
return true
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
/** A page picked by its ID, `page_id`, or by its name, `page`; the ID wins when both are given. */
|
|
25
|
+
export interface PageArgs {
|
|
26
|
+
page?: string
|
|
27
|
+
page_id?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The pages `args` picks: the one it names, none when it names a missing page, else `fallback`. */
|
|
31
|
+
function pickedPages(graph: SceneGraph, args: PageArgs, fallback: SceneNode[]): SceneNode[] {
|
|
32
|
+
const pages = graph.getPages()
|
|
33
|
+
if (args.page_id) return pages.filter((page) => page.id === args.page_id)
|
|
34
|
+
if (args.page) return pages.filter((page) => page.name === args.page).slice(0, 1)
|
|
35
|
+
return fallback
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function missingPageError(graph: SceneGraph, args: PageArgs): string {
|
|
39
|
+
const pages = graph.getPages()
|
|
40
|
+
const [label, available] = args.page_id
|
|
41
|
+
? [args.page_id, pages.map((page) => page.id)]
|
|
42
|
+
: [args.page ?? '', pages.map((page) => page.name)]
|
|
43
|
+
return `Page "${label}" not found. Available: ${available.join(', ')}`
|
|
44
|
+
}
|
|
45
|
+
|
|
23
46
|
function countDescendants(graph: SceneGraph, rootId: string): number {
|
|
24
47
|
let count = 0
|
|
25
48
|
walkNodes(graph, rootId, () => {
|
|
@@ -106,8 +129,7 @@ export const pagesCommand: RPCCommand<void, PageItem[]> = {
|
|
|
106
129
|
|
|
107
130
|
// ── tree ──
|
|
108
131
|
|
|
109
|
-
export interface TreeArgs {
|
|
110
|
-
page?: string
|
|
132
|
+
export interface TreeArgs extends PageArgs {
|
|
111
133
|
depth?: number
|
|
112
134
|
}
|
|
113
135
|
|
|
@@ -152,13 +174,9 @@ export interface TreeResult {
|
|
|
152
174
|
export const treeCommand: RPCCommand<TreeArgs, TreeResult | { error: string }> = {
|
|
153
175
|
name: 'tree',
|
|
154
176
|
execute: (graph, args) => {
|
|
155
|
-
const pages = graph.getPages()
|
|
156
177
|
const maxDepth = args.depth ?? Infinity
|
|
157
|
-
const page = args
|
|
158
|
-
if (!page)
|
|
159
|
-
return {
|
|
160
|
-
error: `Page "${args.page}" not found. Available: ${pages.map((p) => p.name).join(', ')}`
|
|
161
|
-
}
|
|
178
|
+
const page = pickedPages(graph, args, graph.getPages().slice(0, 1)).at(0)
|
|
179
|
+
if (!page) return { error: missingPageError(graph, args) }
|
|
162
180
|
|
|
163
181
|
return {
|
|
164
182
|
page: { id: page.id, name: page.name, type: page.type },
|
|
@@ -171,10 +189,9 @@ export const treeCommand: RPCCommand<TreeArgs, TreeResult | { error: string }> =
|
|
|
171
189
|
|
|
172
190
|
// ── find ──
|
|
173
191
|
|
|
174
|
-
export interface FindArgs {
|
|
192
|
+
export interface FindArgs extends PageArgs {
|
|
175
193
|
name?: string
|
|
176
194
|
type?: string
|
|
177
|
-
page?: string
|
|
178
195
|
limit?: number
|
|
179
196
|
}
|
|
180
197
|
|
|
@@ -189,7 +206,6 @@ export interface FindNodeResult {
|
|
|
189
206
|
export const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {
|
|
190
207
|
name: 'find',
|
|
191
208
|
execute: (graph, args) => {
|
|
192
|
-
const pages = graph.getPages()
|
|
193
209
|
const max = args.limit ?? 100
|
|
194
210
|
const namePattern = args.name?.toLowerCase()
|
|
195
211
|
const typeFilter = args.type?.toUpperCase()
|
|
@@ -216,12 +232,7 @@ export const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {
|
|
|
216
232
|
}
|
|
217
233
|
}
|
|
218
234
|
|
|
219
|
-
|
|
220
|
-
const page = pages.find((p) => p.name === args.page)
|
|
221
|
-
if (page) searchPage(page)
|
|
222
|
-
} else {
|
|
223
|
-
for (const page of pages) searchPage(page)
|
|
224
|
-
}
|
|
235
|
+
for (const page of pickedPages(graph, args, graph.getPages())) searchPage(page)
|
|
225
236
|
|
|
226
237
|
return results
|
|
227
238
|
}
|
|
@@ -229,9 +240,8 @@ export const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {
|
|
|
229
240
|
|
|
230
241
|
// ── query (xpath) ──
|
|
231
242
|
|
|
232
|
-
export interface QueryArgs {
|
|
243
|
+
export interface QueryArgs extends PageArgs {
|
|
233
244
|
selector: string
|
|
234
|
-
page?: string
|
|
235
245
|
limit?: number
|
|
236
246
|
}
|
|
237
247
|
|
|
@@ -251,6 +261,7 @@ export const queryCommand: RPCCommand<QueryArgs, QueryNodeResult[] | { error: st
|
|
|
251
261
|
try {
|
|
252
262
|
const nodes = await queryByXPath(graph, args.selector, {
|
|
253
263
|
page: args.page,
|
|
264
|
+
pageId: args.page_id,
|
|
254
265
|
limit: args.limit
|
|
255
266
|
})
|
|
256
267
|
return nodes.map((n) => ({
|
|
@@ -289,7 +300,14 @@ export interface NodeResult {
|
|
|
289
300
|
fills: unknown[]
|
|
290
301
|
strokes: unknown[]
|
|
291
302
|
effects: unknown[]
|
|
292
|
-
cornerRadius
|
|
303
|
+
cornerRadius?: number
|
|
304
|
+
topLeftRadius?: number
|
|
305
|
+
topRightRadius?: number
|
|
306
|
+
bottomRightRadius?: number
|
|
307
|
+
bottomLeftRadius?: number
|
|
308
|
+
isMask?: boolean
|
|
309
|
+
maskType?: MaskType
|
|
310
|
+
booleanOperation?: BooleanOperation
|
|
293
311
|
blendMode: string
|
|
294
312
|
layoutMode: string
|
|
295
313
|
layoutDirection: string
|
|
@@ -315,7 +333,6 @@ export const nodeCommand: RPCCommand<NodeArgs, NodeResult | { error: string }> =
|
|
|
315
333
|
const variable = graph.variables.get(varId)
|
|
316
334
|
boundVars[field] = variable?.name ?? varId
|
|
317
335
|
}
|
|
318
|
-
|
|
319
336
|
return {
|
|
320
337
|
id: node.id,
|
|
321
338
|
name: node.name,
|
|
@@ -328,7 +345,7 @@ export const nodeCommand: RPCCommand<NodeArgs, NodeResult | { error: string }> =
|
|
|
328
345
|
fills: node.fills,
|
|
329
346
|
strokes: node.strokes,
|
|
330
347
|
effects: node.effects,
|
|
331
|
-
|
|
348
|
+
...shapeDetailFields(node),
|
|
332
349
|
blendMode: node.blendMode,
|
|
333
350
|
layoutMode: node.layoutMode,
|
|
334
351
|
layoutDirection: node.layoutDirection,
|
package/src/text/font/faces.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
type ParsedFontStyle
|
|
8
8
|
} from '@pairdraw/scene-graph/font-style'
|
|
9
9
|
|
|
10
|
+
import { fontAxes } from './variation'
|
|
11
|
+
|
|
10
12
|
/** A weight, upright or italic. */
|
|
11
13
|
export interface FaceWeight {
|
|
12
14
|
weight: number
|
|
@@ -92,3 +94,23 @@ export function fontFaceFromFigmaFontName(fontName: {
|
|
|
92
94
|
export function fontFaceRenderFamily(family: string, style: string): string {
|
|
93
95
|
return `__pairdraw_font__${family.replace(/[^a-z0-9_-]+/giu, '_')}__${style.replace(/[^a-z0-9_-]+/giu, '_')}`
|
|
94
96
|
}
|
|
97
|
+
|
|
98
|
+
/** What a font file is registered with in the page's `document.fonts`. */
|
|
99
|
+
export interface BrowserFaceDescriptors {
|
|
100
|
+
weight: string
|
|
101
|
+
style: 'normal' | 'italic'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The page face for a font file loaded as `style`. A variable font covers its whole `wght` range,
|
|
106
|
+
* so text at any weight draws from the font's own instance; registered at the one weight `style`
|
|
107
|
+
* names, every other weight would fall back to that instance, synthesized bold or not at all.
|
|
108
|
+
*/
|
|
109
|
+
export function browserFaceDescriptors(style: string, data: ArrayBuffer): BrowserFaceDescriptors {
|
|
110
|
+
const { weight, italic } = parseFontStyle(style)
|
|
111
|
+
const wght = fontAxes(data)?.find((axis) => axis.tag === 'wght')
|
|
112
|
+
return {
|
|
113
|
+
weight: wght ? `${wght.min} ${wght.max}` : String(weight),
|
|
114
|
+
style: italic ? 'italic' : 'normal'
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/text/font/manager.ts
CHANGED
|
@@ -8,8 +8,7 @@ import {
|
|
|
8
8
|
faceLoadKey,
|
|
9
9
|
namesWeight,
|
|
10
10
|
normalizeFontFamily,
|
|
11
|
-
parseFontStyle
|
|
12
|
-
styleToWeight
|
|
11
|
+
parseFontStyle
|
|
13
12
|
} from '@pairdraw/scene-graph/font-style'
|
|
14
13
|
|
|
15
14
|
import { DEFAULT_FONT_FAMILY, IS_BROWSER } from '#core/constants'
|
|
@@ -23,8 +22,12 @@ import {
|
|
|
23
22
|
} from '#core/text/fallbacks'
|
|
24
23
|
import { BundledFonts, type BundledFontLocator } from '#core/text/font/bundled'
|
|
25
24
|
import { FamilyFaceCatalog, type HostFontFamily } from '#core/text/font/catalog'
|
|
26
|
-
import { resetFontCollection } from '#core/text/font/collection'
|
|
27
|
-
import {
|
|
25
|
+
import { makeParagraphBuilder, resetFontCollection } from '#core/text/font/collection'
|
|
26
|
+
import {
|
|
27
|
+
browserFaceDescriptors,
|
|
28
|
+
fontFaceRenderFamily,
|
|
29
|
+
type FamilyFace
|
|
30
|
+
} from '#core/text/font/faces'
|
|
28
31
|
import { loadHarfBuzz } from '#core/text/font/harfbuzz'
|
|
29
32
|
import { LocalFonts } from '#core/text/font/local'
|
|
30
33
|
import { sameFontFile, SharedReads, withHarfBuzz } from '#core/text/font/reads'
|
|
@@ -851,7 +854,7 @@ export class FontManager {
|
|
|
851
854
|
const style = new canvasKit.ParagraphStyle({
|
|
852
855
|
textStyle: { fontFamilies: [...families], fontSize: 16 }
|
|
853
856
|
})
|
|
854
|
-
const builder = canvasKit
|
|
857
|
+
const builder = makeParagraphBuilder(canvasKit, style, provider)
|
|
855
858
|
try {
|
|
856
859
|
builder.addText(characters.join(''))
|
|
857
860
|
const paragraph = builder.build()
|
|
@@ -1020,12 +1023,7 @@ export class FontManager {
|
|
|
1020
1023
|
/** Makes a face available to the page's own text, such as fields over canvas labels. */
|
|
1021
1024
|
registerFontInBrowser(family: string, style: string, data: ArrayBuffer) {
|
|
1022
1025
|
if (!IS_BROWSER) return
|
|
1023
|
-
const
|
|
1024
|
-
const italic = style.toLowerCase().includes('italic') ? 'italic' : 'normal'
|
|
1025
|
-
const face = new FontFace(family, data, {
|
|
1026
|
-
weight: String(weight),
|
|
1027
|
-
style: italic
|
|
1028
|
-
})
|
|
1026
|
+
const face = new FontFace(family, data, browserFaceDescriptors(style, data))
|
|
1029
1027
|
face
|
|
1030
1028
|
.load()
|
|
1031
1029
|
.then(() => document.fonts.add(face))
|
|
@@ -66,6 +66,11 @@ export const setLayout = defineTool({
|
|
|
66
66
|
if (!node) return nodeNotFound(args.id)
|
|
67
67
|
|
|
68
68
|
const raw = figma.graph.getNode(args.id)
|
|
69
|
+
// A page holds layers; it is not a frame, so nothing lays it out.
|
|
70
|
+
if (raw?.type === 'CANVAS')
|
|
71
|
+
return {
|
|
72
|
+
error: `A page cannot hold auto layout. Set it on a frame inside the page (${args.id}).`
|
|
73
|
+
}
|
|
69
74
|
if (!args.direction && raw?.layoutMode === 'NONE') {
|
|
70
75
|
return {
|
|
71
76
|
error: 'Frame has no auto-layout. Pass direction ("HORIZONTAL" or "VERTICAL") to enable it.'
|
package/src/tools/read/nodes.ts
CHANGED
|
@@ -106,7 +106,6 @@ export const getPageTree = defineTool({
|
|
|
106
106
|
// A page root exists before its layers load; only the async path can answer it.
|
|
107
107
|
if (figma.graph.getNode(root.id)?.type === 'CANVAS') return undefined
|
|
108
108
|
return { root: root.id, tree: nodeToTreeEntry(root, 1, depth, typeFilter) }
|
|
109
|
-
|
|
110
109
|
}
|
|
111
110
|
return currentPageTree(figma, depth, typeFilter)
|
|
112
111
|
},
|
|
@@ -50,6 +50,20 @@ function parseOperations(operations: BatchOp[] | string): BatchOp[] | { error: s
|
|
|
50
50
|
return { error: `Invalid operations:\n${v.summarize(result.issues)}` }
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** The props a frame's auto layout holds; a page holds no layout, so it takes none of them. */
|
|
54
|
+
const LAYOUT_PROPS = [
|
|
55
|
+
'spacing',
|
|
56
|
+
'padding',
|
|
57
|
+
'padding_horizontal',
|
|
58
|
+
'padding_vertical',
|
|
59
|
+
'align',
|
|
60
|
+
'counter_align',
|
|
61
|
+
'sizing_horizontal',
|
|
62
|
+
'sizing_vertical',
|
|
63
|
+
'grow',
|
|
64
|
+
'direction'
|
|
65
|
+
] as const satisfies readonly (keyof BatchProps)[]
|
|
66
|
+
|
|
53
67
|
function applyBatchProps(node: FigmaNodeProxy, props: BatchProps): void {
|
|
54
68
|
if (props.spacing !== undefined) node.itemSpacing = props.spacing
|
|
55
69
|
if (props.padding !== undefined) {
|
|
@@ -113,6 +127,14 @@ export const batchUpdate = defineTool({
|
|
|
113
127
|
for (const op of ops) {
|
|
114
128
|
const node = figma.getNodeById(op.id)
|
|
115
129
|
if (!node) return nodeNotFound(op.id)
|
|
130
|
+
// Refused before anything is written, so the batch stays all or nothing.
|
|
131
|
+
if (
|
|
132
|
+
figma.graph.getNode(op.id)?.type === 'CANVAS' &&
|
|
133
|
+
LAYOUT_PROPS.some((key) => op.props[key] !== undefined)
|
|
134
|
+
)
|
|
135
|
+
return {
|
|
136
|
+
error: `A page cannot hold auto layout. Set it on a frame inside the page (${op.id}).`
|
|
137
|
+
}
|
|
116
138
|
targets.push({ node, props: op.props })
|
|
117
139
|
}
|
|
118
140
|
|