@pairdraw/core 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/outline-stroke.d.ts.map +1 -1
- package/dist/canvas/outline-stroke.js.map +1 -1
- package/dist/canvas/overlays/prototype.d.ts +2 -5
- package/dist/canvas/overlays/prototype.d.ts.map +1 -1
- package/dist/canvas/overlays/prototype.js +3 -19
- package/dist/canvas/overlays/prototype.js.map +1 -1
- package/dist/canvas/renderer/fonts.js +2 -1
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer.d.ts +4 -0
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +4 -0
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +61 -37
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/text/font-families.d.ts +4 -3
- package/dist/canvas/text/font-families.d.ts.map +1 -1
- package/dist/canvas/text/font-families.js +8 -7
- package/dist/canvas/text/font-families.js.map +1 -1
- package/dist/canvas/text/index.d.ts.map +1 -1
- package/dist/canvas/text/index.js +1 -1
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/paragraph/index.js +2 -2
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/placed.js +2 -2
- package/dist/canvas/text/placed.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -0
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/figma-api/index.d.ts +43 -8
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +48 -6
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/serialization.js +10 -0
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/geometry/connectors.js +2 -14
- package/dist/geometry/connectors.js.map +1 -1
- package/dist/geometry/index.d.ts +2 -2
- package/dist/geometry/scene.d.ts +3 -1
- package/dist/geometry/scene.d.ts.map +1 -1
- package/dist/geometry/scene.js +16 -1
- package/dist/geometry/scene.js.map +1 -1
- package/dist/geometry/types.d.ts +7 -1
- package/dist/geometry/types.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +10 -0
- package/dist/io/formats/drawio/export.js.map +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +32 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/drawio/shapes.d.ts +10 -5
- package/dist/io/formats/drawio/shapes.d.ts.map +1 -1
- package/dist/io/formats/drawio/shapes.js +10 -6
- package/dist/io/formats/drawio/shapes.js.map +1 -1
- package/dist/io/formats/drawio/warnings.d.ts +11 -0
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -0
- package/dist/io/formats/drawio/warnings.js +23 -0
- package/dist/io/formats/drawio/warnings.js.map +1 -0
- package/dist/io/formats/pdf/dom.d.ts +10 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +31 -1
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +3 -2
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts +2 -2
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +2 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/render.d.ts +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +2 -2
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +3 -1
- package/dist/io/formats.js.map +1 -1
- package/dist/io/registry.d.ts +2 -0
- package/dist/io/registry.d.ts.map +1 -1
- package/dist/io/registry.js +5 -0
- package/dist/io/registry.js.map +1 -1
- package/dist/io/types.d.ts +2 -0
- package/dist/io/types.d.ts.map +1 -1
- package/dist/library/snapshot.d.ts.map +1 -1
- package/dist/library/snapshot.js +1 -0
- package/dist/library/snapshot.js.map +1 -1
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +11 -2
- package/dist/lint/linter.js.map +1 -1
- package/dist/rpc/variables-command.d.ts.map +1 -1
- package/dist/rpc/variables-command.js +4 -2
- package/dist/rpc/variables-command.js.map +1 -1
- package/dist/text/coverage.d.ts.map +1 -1
- package/dist/text/coverage.js +6 -3
- package/dist/text/coverage.js.map +1 -1
- package/dist/text/fallbacks.d.ts +8 -2
- package/dist/text/fallbacks.d.ts.map +1 -1
- package/dist/text/fallbacks.js +73 -7
- package/dist/text/fallbacks.js.map +1 -1
- package/dist/text/font/manager.d.ts +14 -6
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +40 -14
- 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/text/outlines.js +1 -1
- package/dist/text/outlines.js.map +1 -1
- package/dist/text/path/caret.d.ts +2 -4
- package/dist/text/path/caret.d.ts.map +1 -1
- package/dist/text/path/caret.js.map +1 -1
- package/dist/text/prepare.d.ts +5 -1
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +19 -2
- package/dist/text/prepare.js.map +1 -1
- package/dist/text/web-font/assets.d.ts.map +1 -1
- package/dist/text/web-font/assets.js +13 -21
- package/dist/text/web-font/assets.js.map +1 -1
- package/dist/text/web-font/resolver.d.ts.map +1 -1
- package/dist/text/web-font/resolver.js +4 -1
- package/dist/text/web-font/resolver.js.map +1 -1
- package/dist/tools/create/components.d.ts +2 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +27 -1
- package/dist/tools/create/components.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +11 -5
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/vector.d.ts.map +1 -1
- package/dist/tools/create/vector.js +9 -6
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/create.d.ts +2 -2
- package/dist/tools/create.js +2 -2
- package/dist/tools/modify/effects.d.ts.map +1 -1
- package/dist/tools/modify/effects.js +5 -3
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +9 -6
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +7 -5
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +28 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/read/libraries.d.ts.map +1 -1
- package/dist/tools/read/libraries.js +16 -4
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/pages.d.ts.map +1 -1
- package/dist/tools/read/pages.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +2 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +24 -5
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +80 -6
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +4 -3
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -2
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/export.d.ts.map +1 -1
- package/dist/tools/vector/export.js +5 -2
- package/dist/tools/vector/export.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/outline-stroke.ts +2 -6
- package/src/canvas/overlays/prototype.ts +5 -27
- package/src/canvas/renderer/fonts.ts +2 -1
- package/src/canvas/renderer.ts +4 -0
- package/src/canvas/scene.ts +92 -63
- package/src/canvas/text/font-families.ts +8 -7
- package/src/canvas/text/index.ts +3 -1
- package/src/canvas/text/paragraph/index.ts +2 -2
- package/src/canvas/text/placed.ts +2 -2
- package/src/canvas/text/renderer.ts +2 -0
- package/src/figma-api/index.ts +90 -9
- package/src/figma-api/serialization.ts +14 -0
- package/src/geometry/connectors.ts +2 -12
- package/src/geometry/index.ts +1 -1
- package/src/geometry/scene.ts +19 -0
- package/src/geometry/types.ts +8 -0
- package/src/io/formats/drawio/export.ts +11 -0
- package/src/io/formats/drawio/index.ts +36 -1
- package/src/io/formats/drawio/shapes.ts +13 -9
- package/src/io/formats/drawio/warnings.ts +27 -0
- package/src/io/formats/pdf/dom.ts +29 -0
- package/src/io/formats/pdf/export.ts +3 -2
- package/src/io/formats/raster/headless.ts +10 -3
- package/src/io/formats/raster/render.ts +4 -2
- package/src/io/formats.ts +3 -1
- package/src/io/registry.ts +12 -0
- package/src/io/types.ts +2 -0
- package/src/library/snapshot.ts +1 -0
- package/src/lint/linter.ts +12 -2
- package/src/rpc/variables-command.ts +6 -5
- package/src/text/coverage.ts +17 -2
- package/src/text/fallbacks.ts +81 -7
- package/src/text/font/manager.ts +50 -17
- package/src/text/outlines.ts +1 -1
- package/src/text/path/caret.ts +3 -4
- package/src/text/prepare.ts +34 -2
- package/src/text/web-font/assets.ts +11 -15
- package/src/text/web-font/resolver.ts +7 -1
- package/src/tools/create/components.ts +33 -0
- package/src/tools/create/icons.ts +13 -5
- package/src/tools/create/vector.ts +16 -6
- package/src/tools/create.ts +1 -0
- package/src/tools/modify/effects.ts +11 -4
- package/src/tools/modify/matching.ts +10 -6
- package/src/tools/modify/paint.ts +13 -5
- package/src/tools/modify/text.ts +53 -20
- package/src/tools/read/libraries.ts +21 -4
- package/src/tools/read/pages.ts +1 -0
- package/src/tools/registry/extended.ts +2 -0
- package/src/tools/schema.ts +109 -5
- package/src/tools/structure/batch.ts +10 -5
- package/src/tools/variables/values.ts +6 -3
- package/src/tools/vector/export.ts +5 -1
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
import type { Canvas } from 'canvaskit-wasm'
|
|
2
2
|
|
|
3
3
|
import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
4
|
-
import Matrix from '@pairdraw/scene-graph/matrix'
|
|
5
4
|
import type { Rect, Vector } from '@pairdraw/scene-graph/primitives'
|
|
6
5
|
|
|
7
6
|
import type { SkiaRenderer } from '#core/canvas/renderer'
|
|
8
|
-
import {
|
|
7
|
+
import type { LineSegment, RotationPreview } from '#core/geometry'
|
|
8
|
+
import { nodeScreenBounds } from '#core/geometry/scene'
|
|
9
9
|
|
|
10
10
|
/** A drawn connection's dash, in screen pixels, and its line weight. */
|
|
11
11
|
const CONNECTION_DASH = [6, 4] as const
|
|
12
12
|
const CONNECTION_WEIGHT = 1.5
|
|
13
13
|
|
|
14
14
|
/** One reaction's arrow, from a layer's edge to the edge of the frame it shows. */
|
|
15
|
-
export
|
|
16
|
-
from: Vector
|
|
17
|
-
to: Vector
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** A node's axis-aligned box on screen. */
|
|
21
|
-
function screenBox(
|
|
22
|
-
graph: SceneGraph,
|
|
23
|
-
node: SceneNode,
|
|
24
|
-
viewport: { panX: number; panY: number; zoom: number },
|
|
25
|
-
preview?: RotationPreview | null
|
|
26
|
-
): Rect {
|
|
27
|
-
const [x0, y0, x1, y1] = Matrix.mapPoints(
|
|
28
|
-
createSceneGeometry(graph, preview).screenMatrix(node, viewport),
|
|
29
|
-
[0, 0, node.width, node.height]
|
|
30
|
-
)
|
|
31
|
-
return {
|
|
32
|
-
x: Math.min(x0, x1),
|
|
33
|
-
y: Math.min(y0, y1),
|
|
34
|
-
width: Math.abs(x1 - x0),
|
|
35
|
-
height: Math.abs(y1 - y0)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
15
|
+
export type PrototypeConnection = LineSegment
|
|
38
16
|
|
|
39
17
|
function center(rect: Rect): Vector {
|
|
40
18
|
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }
|
|
@@ -70,13 +48,13 @@ export function prototypeConnections(
|
|
|
70
48
|
): PrototypeConnection[] {
|
|
71
49
|
const connections: PrototypeConnection[] = []
|
|
72
50
|
for (const node of nodes) {
|
|
73
|
-
const sourceBox =
|
|
51
|
+
const sourceBox = nodeScreenBounds(graph, node, viewport, preview)
|
|
74
52
|
for (const reaction of node.prototypeReactions) {
|
|
75
53
|
for (const action of reaction.actions) {
|
|
76
54
|
if (action.type !== 'NODE' || !action.nodeId) continue
|
|
77
55
|
const target = graph.getNode(action.nodeId)
|
|
78
56
|
if (!target || target.id === node.id) continue
|
|
79
|
-
const targetBox =
|
|
57
|
+
const targetBox = nodeScreenBounds(graph, target, viewport, preview)
|
|
80
58
|
connections.push({
|
|
81
59
|
from: edgePoint(sourceBox, center(targetBox)),
|
|
82
60
|
to: edgePoint(targetBox, center(sourceBox))
|
|
@@ -162,7 +162,8 @@ export async function prepareForExport(
|
|
|
162
162
|
nodeIds: string[]
|
|
163
163
|
): Promise<void> {
|
|
164
164
|
const { computeAllLayouts } = await import('#core/layout')
|
|
165
|
-
await prepareGraphFonts(graph, nodeIds)
|
|
165
|
+
await prepareGraphFonts(graph, nodeIds, '', { settleUnavailable: true })
|
|
166
|
+
r.exportFontsSettled = true
|
|
166
167
|
syncFontGeneration(r)
|
|
167
168
|
withTextMeasurer(
|
|
168
169
|
(node, maxWidth) => r.measureTextNode(node, maxWidth),
|
package/src/canvas/renderer.ts
CHANGED
|
@@ -126,6 +126,8 @@ export class SkiaRenderer {
|
|
|
126
126
|
fontMgr: FontMgr | null = null
|
|
127
127
|
fontProvider: TypefaceFontProvider | null = null
|
|
128
128
|
fontsLoaded = false
|
|
129
|
+
/** Set once fonts are prepared for a one-shot export, so a pending face stops holding text back. */
|
|
130
|
+
exportFontsSettled = false
|
|
129
131
|
fontGeneration = 0
|
|
130
132
|
onFontResolutionSettled:
|
|
131
133
|
| ((snapshot: FontResolutionSnapshot, nodeIds: readonly string[]) => void)
|
|
@@ -143,6 +145,8 @@ export class SkiaRenderer {
|
|
|
143
145
|
imageMemoryGraph: SceneGraph | null = null
|
|
144
146
|
imageMemoryPage: string | null = null
|
|
145
147
|
onImagePreviewReady: (() => void) | null = null
|
|
148
|
+
/** A layer this frame could not draw. Called once per layer and error message. */
|
|
149
|
+
onNodeDrawFailure: ((nodeId: string, error: unknown) => void) | null = null
|
|
146
150
|
readonly imagePreviews = new ImagePreviewCache(() => this.onImagePreviewReady?.())
|
|
147
151
|
nodePaths = new NodePathCaches()
|
|
148
152
|
/** Path-text glyph silhouettes (stroke-and-union, font units) keyed by blob hash + relative weight. */
|
package/src/canvas/scene.ts
CHANGED
|
@@ -324,6 +324,21 @@ function nodeIsolationLayerBounds(
|
|
|
324
324
|
return r.ck.LTRBRect(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
const reportedNodeDrawFailures = new WeakMap<SkiaRenderer, Set<string>>()
|
|
328
|
+
|
|
329
|
+
function reportNodeDrawFailure(renderer: SkiaRenderer, nodeId: string, error: unknown): void {
|
|
330
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
331
|
+
const key = `${nodeId}\0${message}`
|
|
332
|
+
let reported = reportedNodeDrawFailures.get(renderer)
|
|
333
|
+
if (!reported) {
|
|
334
|
+
reported = new Set()
|
|
335
|
+
reportedNodeDrawFailures.set(renderer, reported)
|
|
336
|
+
}
|
|
337
|
+
if (reported.has(key)) return
|
|
338
|
+
reported.add(key)
|
|
339
|
+
renderer.onNodeDrawFailure?.(nodeId, error)
|
|
340
|
+
}
|
|
341
|
+
|
|
327
342
|
/**
|
|
328
343
|
* Whether the canvas draws a node itself: not hidden, a mask, blocked on fonts, drawn live by
|
|
329
344
|
* node-edit mode, or left to a live island while the canvas previews.
|
|
@@ -358,52 +373,69 @@ export function renderNode(
|
|
|
358
373
|
return
|
|
359
374
|
}
|
|
360
375
|
|
|
361
|
-
canvas.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
(e): e is ShadowEffect => e.visible && (e.type === 'LAYER_BLUR' || e.type === 'FOREGROUND_BLUR')
|
|
374
|
-
)
|
|
375
|
-
if (layerBlur) {
|
|
376
|
-
// Entry guard: reset shared paint to known state
|
|
377
|
-
r.effectLayerPaint.setImageFilter(null)
|
|
378
|
-
r.effectLayerPaint.setColorFilter(null)
|
|
379
|
-
r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)
|
|
376
|
+
const depth = canvas.getSaveCount()
|
|
377
|
+
try {
|
|
378
|
+
canvas.save()
|
|
379
|
+
canvas.translate(node.x, node.y)
|
|
380
|
+
|
|
381
|
+
const needsNodeLayer = node.opacity < 1 || needsIsolatedBlendLayer(node.blendMode)
|
|
382
|
+
if (needsNodeLayer) {
|
|
383
|
+
const layerBounds = nodeIsolationLayerBounds(r, graph, node, overlays.rotationPreview)
|
|
384
|
+
r.opacityPaint.setAlphaf(node.opacity)
|
|
385
|
+
setPaintBlendMode(r, r.opacityPaint, node.blendMode)
|
|
386
|
+
canvas.saveLayer(r.opacityPaint, layerBounds)
|
|
387
|
+
}
|
|
380
388
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
r.effectLayerPaint,
|
|
385
|
-
viewportLayerBounds(r, graph, node, blurPadding, overlays.rotationPreview) ??
|
|
386
|
-
r.ck.LTRBRect(
|
|
387
|
-
-blurPadding,
|
|
388
|
-
-blurPadding,
|
|
389
|
-
node.width + blurPadding,
|
|
390
|
-
node.height + blurPadding
|
|
391
|
-
)
|
|
389
|
+
const layerBlur = node.effects.find(
|
|
390
|
+
(e): e is ShadowEffect =>
|
|
391
|
+
e.visible && (e.type === 'LAYER_BLUR' || e.type === 'FOREGROUND_BLUR')
|
|
392
392
|
)
|
|
393
|
-
|
|
393
|
+
if (layerBlur) {
|
|
394
|
+
// Entry guard: reset shared paint to known state
|
|
395
|
+
r.effectLayerPaint.setImageFilter(null)
|
|
396
|
+
r.effectLayerPaint.setColorFilter(null)
|
|
397
|
+
r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)
|
|
398
|
+
|
|
399
|
+
r.effectLayerPaint.setImageFilter(r.getCachedBlur(blurSigma(layerBlur.radius)))
|
|
400
|
+
const blurPadding = layerBlur.radius * 2
|
|
401
|
+
canvas.saveLayer(
|
|
402
|
+
r.effectLayerPaint,
|
|
403
|
+
viewportLayerBounds(r, graph, node, blurPadding, overlays.rotationPreview) ??
|
|
404
|
+
r.ck.LTRBRect(
|
|
405
|
+
-blurPadding,
|
|
406
|
+
-blurPadding,
|
|
407
|
+
node.width + blurPadding,
|
|
408
|
+
node.height + blurPadding
|
|
409
|
+
)
|
|
410
|
+
)
|
|
411
|
+
}
|
|
394
412
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
413
|
+
applyNodeTransforms(canvas, node, overlays)
|
|
414
|
+
renderLayerShadows(r, canvas, graph, node, 'behind')
|
|
415
|
+
const shaderEffects = node.effects.filter(
|
|
416
|
+
(e): e is ShaderEffect => e.visible && e.type === 'SHADER'
|
|
417
|
+
)
|
|
418
|
+
if (shaderEffects.length > 0) {
|
|
419
|
+
drawShaderEffectChain(r, canvas, graph, node, shaderEffects, (target) => {
|
|
420
|
+
renderNodeContent(r, target, graph, node, overlays)
|
|
421
|
+
drawLayoutGrids(r, target, node)
|
|
422
|
+
renderChildren(
|
|
423
|
+
r,
|
|
424
|
+
target,
|
|
425
|
+
graph,
|
|
426
|
+
node,
|
|
427
|
+
overlays,
|
|
428
|
+
absX,
|
|
429
|
+
absY,
|
|
430
|
+
hasTransformedAncestor || hasNodeTransform(projectedNode(node, overlays.rotationPreview))
|
|
431
|
+
)
|
|
432
|
+
})
|
|
433
|
+
} else {
|
|
434
|
+
renderNodeContent(r, canvas, graph, node, overlays)
|
|
435
|
+
drawLayoutGrids(r, canvas, node)
|
|
404
436
|
renderChildren(
|
|
405
437
|
r,
|
|
406
|
-
|
|
438
|
+
canvas,
|
|
407
439
|
graph,
|
|
408
440
|
node,
|
|
409
441
|
overlays,
|
|
@@ -411,36 +443,33 @@ export function renderNode(
|
|
|
411
443
|
absY,
|
|
412
444
|
hasTransformedAncestor || hasNodeTransform(projectedNode(node, overlays.rotationPreview))
|
|
413
445
|
)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
renderNodeContent(r, canvas, graph, node, overlays)
|
|
417
|
-
drawLayoutGrids(r, canvas, node)
|
|
418
|
-
renderChildren(
|
|
419
|
-
r,
|
|
420
|
-
canvas,
|
|
421
|
-
graph,
|
|
422
|
-
node,
|
|
423
|
-
overlays,
|
|
424
|
-
absX,
|
|
425
|
-
absY,
|
|
426
|
-
hasTransformedAncestor || hasNodeTransform(projectedNode(node, overlays.rotationPreview))
|
|
427
|
-
)
|
|
428
|
-
}
|
|
429
|
-
renderLayerShadows(r, canvas, graph, node, 'front')
|
|
446
|
+
}
|
|
447
|
+
renderLayerShadows(r, canvas, graph, node, 'front')
|
|
430
448
|
|
|
431
|
-
|
|
449
|
+
if (layerBlur) {
|
|
450
|
+
canvas.restore()
|
|
451
|
+
// Exit guard: ensure shared paint is in clean state
|
|
452
|
+
r.effectLayerPaint.setImageFilter(null)
|
|
453
|
+
r.effectLayerPaint.setColorFilter(null)
|
|
454
|
+
r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)
|
|
455
|
+
}
|
|
456
|
+
if (needsNodeLayer) {
|
|
457
|
+
canvas.restore()
|
|
458
|
+
r.opacityPaint.setAlphaf(1)
|
|
459
|
+
r.opacityPaint.setBlendMode(r.ck.BlendMode.SrcOver)
|
|
460
|
+
}
|
|
432
461
|
canvas.restore()
|
|
433
|
-
|
|
462
|
+
} catch (error) {
|
|
463
|
+
canvas.restoreToCount(depth)
|
|
464
|
+
// A throw skips the exit guards, so the next layer must not inherit their paints.
|
|
434
465
|
r.effectLayerPaint.setImageFilter(null)
|
|
435
466
|
r.effectLayerPaint.setColorFilter(null)
|
|
436
467
|
r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)
|
|
437
|
-
}
|
|
438
|
-
if (needsNodeLayer) {
|
|
439
|
-
canvas.restore()
|
|
440
468
|
r.opacityPaint.setAlphaf(1)
|
|
441
469
|
r.opacityPaint.setBlendMode(r.ck.BlendMode.SrcOver)
|
|
470
|
+
r.opacityPaint.setImageFilter(null)
|
|
471
|
+
reportNodeDrawFailure(r, node.id, error)
|
|
442
472
|
}
|
|
443
|
-
canvas.restore()
|
|
444
473
|
}
|
|
445
474
|
|
|
446
475
|
function makeNodeRRect(r: SkiaRenderer, node: SceneNode, radius: number): Float32Array {
|
|
@@ -96,19 +96,20 @@ export function loadedFace(
|
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* The families a paragraph's text falls back through, by their own names: its family, the
|
|
99
|
-
* default family, the
|
|
99
|
+
* default family, the fallbacks of scripts written in letters (Arabic, Hebrew, Thai,
|
|
100
|
+
* Devanagari) and CJK, then emoji, so a character a script's font has
|
|
100
101
|
* stays in that font. Fonts are read by these names; CanvasKit is asked for them as
|
|
101
102
|
* {@link resolveParagraphFontFamilies} names them.
|
|
102
103
|
*/
|
|
103
104
|
export function paragraphSourceFamilies(
|
|
104
105
|
primary: string,
|
|
105
|
-
|
|
106
|
+
letterFallbacks: readonly string[] = fontManager.getLetterFallbackFamilies(),
|
|
106
107
|
cjkFallbacks: readonly string[] = fontManager.getCJKFallbackFamilies()
|
|
107
108
|
): string[] {
|
|
108
109
|
return uniq([
|
|
109
110
|
primary,
|
|
110
111
|
...(primary === DEFAULT_FONT_FAMILY ? [] : [DEFAULT_FONT_FAMILY]),
|
|
111
|
-
...
|
|
112
|
+
...letterFallbacks,
|
|
112
113
|
...cjkFallbacks,
|
|
113
114
|
EMOJI_METRICS_FAMILY
|
|
114
115
|
])
|
|
@@ -129,13 +130,13 @@ function renderFamilies(family: string, style: string): string[] {
|
|
|
129
130
|
export function resolveParagraphFontFamilies(
|
|
130
131
|
primary: string,
|
|
131
132
|
face: { weight: number; italic: boolean; style: string },
|
|
132
|
-
|
|
133
|
+
letterFallbacks: readonly string[] = fontManager.getLetterFallbackFamilies(),
|
|
133
134
|
cjkFallbacks: readonly string[] = fontManager.getCJKFallbackFamilies()
|
|
134
135
|
): string[] {
|
|
135
136
|
// The face the family draws it in, which may be the nearest one loaded.
|
|
136
137
|
const drawn = loadedFace(primary, face.weight, face.italic, face.style)
|
|
137
138
|
const renderPrimary = renderFamilies(primary, drawn?.style ?? face.style)
|
|
138
|
-
const
|
|
139
|
+
const renderLetterFallbacks = letterFallbacks.flatMap((family) =>
|
|
139
140
|
renderFamilies(family, 'Regular')
|
|
140
141
|
)
|
|
141
142
|
const renderCJKFallbacks = cjkFallbacks.flatMap((family) => renderFamilies(family, 'Regular'))
|
|
@@ -143,7 +144,7 @@ export function resolveParagraphFontFamilies(
|
|
|
143
144
|
primary,
|
|
144
145
|
...renderPrimary,
|
|
145
146
|
'',
|
|
146
|
-
...
|
|
147
|
+
...renderLetterFallbacks,
|
|
147
148
|
'',
|
|
148
149
|
...renderCJKFallbacks
|
|
149
150
|
].join('\0')
|
|
@@ -152,7 +153,7 @@ export function resolveParagraphFontFamilies(
|
|
|
152
153
|
const resolved = uniq([
|
|
153
154
|
...renderPrimary,
|
|
154
155
|
...(primary === DEFAULT_FONT_FAMILY ? [] : [DEFAULT_FONT_FAMILY]),
|
|
155
|
-
...
|
|
156
|
+
...renderLetterFallbacks,
|
|
156
157
|
...renderCJKFallbacks,
|
|
157
158
|
EMOJI_METRICS_FAMILY
|
|
158
159
|
])
|
package/src/canvas/text/index.ts
CHANGED
|
@@ -158,7 +158,9 @@ function observedGlyphReadiness(r: TextRenderer, node: SceneNode): NodeFontReadi
|
|
|
158
158
|
void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
// An export draws once: a face that has not arrived by then is not coming, and the characters
|
|
162
|
+
// it would have covered keep the text's own fonts rather than leaving the layer blank.
|
|
163
|
+
if (pending) return r.exportFontsSettled ? 'substituted' : 'pending'
|
|
162
164
|
// Once no fallback is left for a character, the text draws with the fonts it has, the font's
|
|
163
165
|
// missing-glyph box standing in for that character, rather than not at all.
|
|
164
166
|
return exhausted ? 'substituted' : 'ready'
|
|
@@ -286,7 +286,7 @@ export function buildSkParagraph(
|
|
|
286
286
|
const baseFontSize = node.fontSize || DEFAULT_FONT_SIZE
|
|
287
287
|
const baseLineHeight = lineHeightPixels(node.lineHeight, baseFontSize)
|
|
288
288
|
const cjkFallbacks = fontManager.getCJKFallbackFamilies()
|
|
289
|
-
const
|
|
289
|
+
const letterFallbacks = fontManager.getLetterFallbackFamilies()
|
|
290
290
|
const textDirection = resolveNodeTextDirection(node)
|
|
291
291
|
|
|
292
292
|
const truncateOpts = block.truncation ?? buildTruncateOpts(node)
|
|
@@ -295,7 +295,7 @@ export function buildSkParagraph(
|
|
|
295
295
|
resolveParagraphFontFamilies(
|
|
296
296
|
primary,
|
|
297
297
|
{ weight: face.fontWeight, italic: face.italic, style: faceStyleKey(face) },
|
|
298
|
-
|
|
298
|
+
letterFallbacks,
|
|
299
299
|
cjkFallbacks
|
|
300
300
|
)
|
|
301
301
|
const nodeKey = faceStyleKey(node)
|
|
@@ -127,12 +127,12 @@ function featuresOf(node: SceneNode, run: StyleRun | undefined): ShapingFeature[
|
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* The style a family of the paragraph is drawn in: the face its own family draws the asked style
|
|
130
|
-
* in, and Regular for the
|
|
130
|
+
* in, and Regular for the script fallbacks, as the paragraph asks CanvasKit for them.
|
|
131
131
|
*/
|
|
132
132
|
function sourceStyle(family: string, font: ReturnType<typeof fontAt>): string | null {
|
|
133
133
|
const scriptFallback =
|
|
134
134
|
family !== font.family &&
|
|
135
|
-
(fontManager.
|
|
135
|
+
(fontManager.getLetterFallbackFamilies().includes(family) ||
|
|
136
136
|
fontManager.getCJKFallbackFamilies().includes(family))
|
|
137
137
|
if (scriptFallback) return fontManager.isStyleLoaded(family, 'Regular') ? 'Regular' : null
|
|
138
138
|
return loadedStyle(family, font.drawn.weight, font.drawn.italic, font.drawn.style)
|
|
@@ -11,6 +11,8 @@ export interface FontReadinessRenderer {
|
|
|
11
11
|
ck?: CanvasKit
|
|
12
12
|
fontProvider?: TypefaceFontProvider | null
|
|
13
13
|
fontsLoaded?: boolean
|
|
14
|
+
/** The renderer has finished preparing its fonts, so a face still pending will not arrive. */
|
|
15
|
+
exportFontsSettled?: boolean
|
|
14
16
|
onFontResolutionSettled?: FontResolutionSettled
|
|
15
17
|
trackFontDemand?: (node: SceneNode, key: string) => void
|
|
16
18
|
}
|
package/src/figma-api/index.ts
CHANGED
|
@@ -53,10 +53,46 @@ import { combineComponentsAsVariants } from './variants'
|
|
|
53
53
|
|
|
54
54
|
const noop = () => undefined
|
|
55
55
|
|
|
56
|
+
/** A view of the document: its centre point and its zoom. */
|
|
57
|
+
export interface FigmaViewport {
|
|
58
|
+
center: Vector
|
|
59
|
+
zoom: number
|
|
60
|
+
}
|
|
61
|
+
|
|
56
62
|
/** What a host passes to `FigmaAPI` beyond the document. */
|
|
57
63
|
export interface FigmaAPIOptions {
|
|
58
64
|
/** Fetches the HTTP(S) URLs `figma.createImageAsync` loads; the global `fetch` by default. */
|
|
59
65
|
fetch?: images.ImageFetch
|
|
66
|
+
/**
|
|
67
|
+
* Runs when a script puts the API on another page, so a host can show that page too. The host
|
|
68
|
+
* owns which page is on screen, and a plugin that switches page expects to see it switched.
|
|
69
|
+
*/
|
|
70
|
+
onPageChange?: (pageId: string) => void | Promise<void>
|
|
71
|
+
/**
|
|
72
|
+
* Runs when a script moves the viewport, so a host can show the same view. A host owns the
|
|
73
|
+
* viewport on screen, and a plugin that pans or zooms expects to see the result.
|
|
74
|
+
*/
|
|
75
|
+
onViewportChange?: (viewport: FigmaViewport) => void
|
|
76
|
+
/**
|
|
77
|
+
* The page the host already shows. Seeded here rather than assigned after construction, so a
|
|
78
|
+
* plain tool call does not ask the host to switch to the page it is already on.
|
|
79
|
+
*/
|
|
80
|
+
pageId?: string
|
|
81
|
+
/**
|
|
82
|
+
* The view the host already shows, seeded for the same reason: a tool that only reads or draws
|
|
83
|
+
* must not move the viewport of whoever is looking at the document.
|
|
84
|
+
*/
|
|
85
|
+
viewport?: FigmaViewport
|
|
86
|
+
/**
|
|
87
|
+
* Runs when a script sets the page selection, so a host can select those layers too. The host
|
|
88
|
+
* owns which layers are selected on screen, and a plugin that selects expects to see them selected.
|
|
89
|
+
*/
|
|
90
|
+
onSelectionChange?: (ids: readonly string[], pageId: string) => void
|
|
91
|
+
/**
|
|
92
|
+
* The selection the host already shows, seeded for the same reason as the page and the viewport:
|
|
93
|
+
* a tool that only reads must not reselect what is already selected.
|
|
94
|
+
*/
|
|
95
|
+
selection?: readonly string[]
|
|
60
96
|
}
|
|
61
97
|
|
|
62
98
|
export { FigmaNodeProxy } from './proxy'
|
|
@@ -121,14 +157,33 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
121
157
|
|
|
122
158
|
/** How `createImageAsync` fetches HTTP(S) URLs; a host passes one that gets past CORS. */
|
|
123
159
|
readonly #fetch: images.ImageFetch
|
|
160
|
+
readonly #onPageChange: ((pageId: string) => void | Promise<void>) | undefined
|
|
161
|
+
readonly #onViewportChange: ((viewport: FigmaViewport) => void) | undefined
|
|
162
|
+
readonly #onSelectionChange: ((ids: readonly string[], pageId: string) => void) | undefined
|
|
163
|
+
/** The last host page switch, so `setCurrentPageAsync` can wait for it. */
|
|
164
|
+
#pageChange: Promise<void> = Promise.resolve()
|
|
124
165
|
|
|
125
166
|
constructor(graph: SceneGraph, options: FigmaAPIOptions = {}) {
|
|
126
167
|
this.graph = graph
|
|
127
168
|
this.#fetch = options.fetch ?? ((input, init) => fetch(input, init))
|
|
169
|
+
this.#onPageChange = options.onPageChange
|
|
170
|
+
this.#onViewportChange = options.onViewportChange
|
|
171
|
+
this.#onSelectionChange = options.onSelectionChange
|
|
128
172
|
this.variables = new FigmaVariablesAPI(graph)
|
|
129
173
|
startPendingLayout(graph)
|
|
130
|
-
|
|
131
|
-
|
|
174
|
+
this._currentPageId = pageIdToStart(graph, options.pageId)
|
|
175
|
+
if (options.viewport) {
|
|
176
|
+
this._viewport = {
|
|
177
|
+
x: options.viewport.center.x,
|
|
178
|
+
y: options.viewport.center.y,
|
|
179
|
+
zoom: options.viewport.zoom
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Seeded here, not assigned through the setter, so a tool that only reads does not ask the
|
|
183
|
+
// host to select the layers it is already showing.
|
|
184
|
+
this._selection = (options.selection ?? []).flatMap((id) =>
|
|
185
|
+
this.graph.getNode(id) ? [this.wrapNode(id)] : []
|
|
186
|
+
)
|
|
132
187
|
}
|
|
133
188
|
|
|
134
189
|
setRenderer(renderer: SkiaRenderer | null): void {
|
|
@@ -159,7 +214,12 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
159
214
|
Object.defineProperty(proxy, 'selection', {
|
|
160
215
|
get: () => this._selection,
|
|
161
216
|
set: (nodes: FigmaNodeProxy[]) => {
|
|
217
|
+
const next = nodes.map((node) => node[INTERNAL_ID])
|
|
218
|
+
const current = this._selection.map((node) => node[INTERNAL_ID])
|
|
162
219
|
this._selection = nodes
|
|
220
|
+
if (next.length === current.length && next.every((id, index) => id === current[index]))
|
|
221
|
+
return
|
|
222
|
+
this.#onSelectionChange?.(next, this._currentPageId)
|
|
163
223
|
},
|
|
164
224
|
enumerable: true,
|
|
165
225
|
configurable: true
|
|
@@ -178,7 +238,10 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
178
238
|
}
|
|
179
239
|
|
|
180
240
|
set currentPage(page: FigmaNodeProxy) {
|
|
181
|
-
|
|
241
|
+
const pageId = page[INTERNAL_ID]
|
|
242
|
+
if (pageId === this._currentPageId) return
|
|
243
|
+
this._currentPageId = pageId
|
|
244
|
+
this.#pageChange = Promise.resolve(this.#onPageChange?.(pageId))
|
|
182
245
|
}
|
|
183
246
|
|
|
184
247
|
getNodeById(id: string): FigmaNodeProxy | null {
|
|
@@ -204,7 +267,8 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
204
267
|
return Promise.reject(new Error('figma.setCurrentPageAsync expects a PageNode'))
|
|
205
268
|
}
|
|
206
269
|
this._currentPageId = this._nodeId(page)
|
|
207
|
-
|
|
270
|
+
this.#pageChange = Promise.resolve(this.#onPageChange?.(this._currentPageId))
|
|
271
|
+
return this.#pageChange
|
|
208
272
|
}
|
|
209
273
|
|
|
210
274
|
// --- Node Creation ---
|
|
@@ -497,9 +561,7 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
497
561
|
|
|
498
562
|
private _viewport = { x: 0, y: 0, zoom: 1 }
|
|
499
563
|
|
|
500
|
-
get viewport(): {
|
|
501
|
-
center: Vector
|
|
502
|
-
zoom: number
|
|
564
|
+
get viewport(): FigmaViewport & {
|
|
503
565
|
scrollAndZoomIntoView: (nodes: readonly { absoluteBoundingBox: Rect }[]) => void
|
|
504
566
|
} {
|
|
505
567
|
return {
|
|
@@ -515,13 +577,26 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
515
577
|
const viewW = IS_BROWSER ? window.innerWidth : 1280
|
|
516
578
|
const viewH = IS_BROWSER ? window.innerHeight : 720
|
|
517
579
|
const zoom = Math.min(viewW / contentW, viewH / contentH, 1)
|
|
580
|
+
// A script scrolling to its own result must not move the view someone else is looking at:
|
|
581
|
+
// only `viewport` and a page switch do that.
|
|
518
582
|
this._viewport = { x: b.x + b.width / 2, y: b.y + b.height / 2, zoom }
|
|
519
583
|
}
|
|
520
584
|
}
|
|
521
585
|
}
|
|
522
586
|
|
|
523
|
-
set viewport(v:
|
|
524
|
-
this.
|
|
587
|
+
set viewport(v: FigmaViewport) {
|
|
588
|
+
this._showViewport({ x: v.center.x, y: v.center.y, zoom: v.zoom })
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Moves the viewport and puts the host on the same view. A tool that scrolls nodes into view
|
|
593
|
+
* does not call this: only a viewport a writer asks for moves the view of whoever is looking.
|
|
594
|
+
*/
|
|
595
|
+
private _showViewport(next: { x: number; y: number; zoom: number }): void {
|
|
596
|
+
const current = this._viewport
|
|
597
|
+
this._viewport = next
|
|
598
|
+
if (current.x === next.x && current.y === next.y && current.zoom === next.zoom) return
|
|
599
|
+
this.#onViewportChange?.({ center: { x: next.x, y: next.y }, zoom: next.zoom })
|
|
525
600
|
}
|
|
526
601
|
|
|
527
602
|
createImage(data: Uint8Array): Image {
|
|
@@ -607,3 +682,9 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
607
682
|
/** The document as it was before the current AI run first edited `pageId`, or null if unedited. */
|
|
608
683
|
changeBaseline?: (pageId: string) => SceneGraph | null
|
|
609
684
|
}
|
|
685
|
+
|
|
686
|
+
/** The page an API starts on: the one the host shows, else the document's first page. */
|
|
687
|
+
function pageIdToStart(graph: SceneGraph, pageId?: string): string {
|
|
688
|
+
const pages = graph.getPages()
|
|
689
|
+
return pageId ?? (pages.length > 0 ? pages[0].id : graph.rootId)
|
|
690
|
+
}
|
|
@@ -58,6 +58,9 @@ export function nodeProxyToJSON(
|
|
|
58
58
|
if (n.strokes.length > 0) obj.strokes = figmaStrokes(graph, n)
|
|
59
59
|
if (n.effects.length > 0) obj.effects = n.effects
|
|
60
60
|
if (n.opacity !== 1) obj.opacity = n.opacity
|
|
61
|
+
// The angle `set_rotation` writes, as the Figma API reports it. The scene stores the turn in
|
|
62
|
+
// the opposite direction and keeps floating-point noise, so read it through the proxy.
|
|
63
|
+
if (n.rotation !== 0) obj.rotation = api.wrapNode(nodeId).rotation
|
|
61
64
|
if (n.cornerRadius > 0) obj.cornerRadius = n.cornerRadius
|
|
62
65
|
if (!n.visible) obj.visible = false
|
|
63
66
|
if (n.text) obj.characters = n.text
|
|
@@ -65,9 +68,20 @@ export function nodeProxyToJSON(
|
|
|
65
68
|
appendTextProps(obj, n)
|
|
66
69
|
}
|
|
67
70
|
if (n.layoutMode !== 'NONE') {
|
|
71
|
+
// An auto layout frame reports the insets and alignment a tool sets, so a caller can read back
|
|
72
|
+
// what it wrote instead of measuring the result.
|
|
73
|
+
const proxy = api.wrapNode(nodeId)
|
|
68
74
|
obj.layoutMode = n.layoutMode
|
|
69
75
|
obj.layoutDirection = n.layoutDirection
|
|
70
76
|
obj.itemSpacing = n.itemSpacing
|
|
77
|
+
obj.paddingTop = proxy.paddingTop
|
|
78
|
+
obj.paddingRight = proxy.paddingRight
|
|
79
|
+
obj.paddingBottom = proxy.paddingBottom
|
|
80
|
+
obj.paddingLeft = proxy.paddingLeft
|
|
81
|
+
obj.primaryAxisAlignItems = proxy.primaryAxisAlignItems
|
|
82
|
+
obj.counterAxisAlignItems = proxy.counterAxisAlignItems
|
|
83
|
+
obj.primaryAxisSizingMode = proxy.primaryAxisSizingMode
|
|
84
|
+
obj.counterAxisSizingMode = proxy.counterAxisSizingMode
|
|
71
85
|
}
|
|
72
86
|
// Include variable bindings with resolved values
|
|
73
87
|
const bindings = resolveBindings(graph, n)
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import Matrix from '@pairdraw/scene-graph/matrix'
|
|
9
9
|
import type { Rect, Vector } from '@pairdraw/scene-graph/primitives'
|
|
10
10
|
|
|
11
|
-
import { createSceneGeometry } from './scene'
|
|
11
|
+
import { createSceneGeometry, nodeScreenBounds } from './scene'
|
|
12
12
|
import type { RotationPreview, ViewportTransform } from './types'
|
|
13
13
|
|
|
14
14
|
/** Where a connector's line starts and ends on screen, where its end handles sit. */
|
|
@@ -88,15 +88,5 @@ export function connectorScreenLabel(
|
|
|
88
88
|
): Rect | null {
|
|
89
89
|
const parts = connectorSublayers(graph, connector)
|
|
90
90
|
if (!parts || parts.label.text === '' || !parts.labelBackground.visible) return null
|
|
91
|
-
|
|
92
|
-
const [x0, y0, x1, y1] = Matrix.mapPoints(
|
|
93
|
-
createSceneGeometry(graph, preview).screenMatrix(plate, viewport),
|
|
94
|
-
[0, 0, plate.width, plate.height]
|
|
95
|
-
)
|
|
96
|
-
return {
|
|
97
|
-
x: Math.min(x0, x1),
|
|
98
|
-
y: Math.min(y0, y1),
|
|
99
|
-
width: Math.abs(x1 - x0),
|
|
100
|
-
height: Math.abs(y1 - y0)
|
|
101
|
-
}
|
|
91
|
+
return nodeScreenBounds(graph, parts.labelBackground, viewport, preview)
|
|
102
92
|
}
|
package/src/geometry/index.ts
CHANGED
|
@@ -98,4 +98,4 @@ export {
|
|
|
98
98
|
} from './transform-zones'
|
|
99
99
|
export type { CornerPosition, HandlePosition, TransformZone } from './transform-zones'
|
|
100
100
|
export type { RotationHandleLayout } from './selection'
|
|
101
|
-
export type { RotationPreview, ViewportTransform } from './types'
|
|
101
|
+
export type { LineSegment, RotationPreview, ViewportTransform } from './types'
|
package/src/geometry/scene.ts
CHANGED
|
@@ -27,6 +27,25 @@ export function viewportMatrix(viewport: ViewportTransform) {
|
|
|
27
27
|
)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** A node's axis-aligned box on screen, around its corners as drawn. */
|
|
31
|
+
export function nodeScreenBounds(
|
|
32
|
+
graph: SceneGraph,
|
|
33
|
+
node: SceneNode,
|
|
34
|
+
viewport: ViewportTransform,
|
|
35
|
+
preview?: RotationPreview | null
|
|
36
|
+
): Rect {
|
|
37
|
+
const [x0, y0, x1, y1] = Matrix.mapPoints(
|
|
38
|
+
createSceneGeometry(graph, preview).screenMatrix(node, viewport),
|
|
39
|
+
[0, 0, node.width, node.height]
|
|
40
|
+
)
|
|
41
|
+
return {
|
|
42
|
+
x: Math.min(x0, x1),
|
|
43
|
+
y: Math.min(y0, y1),
|
|
44
|
+
width: Math.abs(x1 - x0),
|
|
45
|
+
height: Math.abs(y1 - y0)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
30
49
|
/** A read-only view for one draw or input operation. Recreate when the preview changes. */
|
|
31
50
|
export function createSceneGeometry(graph: SceneGraph, preview?: RotationPreview | null) {
|
|
32
51
|
const node = (source: SceneNode) => projectedNode(source, preview)
|
package/src/geometry/types.ts
CHANGED