@pairdraw/core 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/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/design-tokens/apply.d.ts +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/editor/create.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { createNanoEvents } from 'nanoevents'
|
|
|
3
3
|
import type { Emitter } from 'nanoevents'
|
|
4
4
|
|
|
5
5
|
import { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'
|
|
6
|
-
import { UndoManager, type UndoHistory } from '@pairdraw/scene-graph/undo'
|
|
6
|
+
import { UndoManager, type UndoEntry, type UndoHistory } from '@pairdraw/scene-graph/undo'
|
|
7
7
|
|
|
8
8
|
import type { SkiaRenderer } from '#core/canvas/renderer'
|
|
9
9
|
import { prefetchFigmaSchema } from '#core/clipboard'
|
|
@@ -257,7 +257,9 @@ export function createEditor(options?: EditorOptions) {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
const graphReads = createGraphReadActions(() => _graph)
|
|
260
|
-
const { runLayoutForNode, runMutationWithLayout } = createLayoutRunner(
|
|
260
|
+
const { runLayoutForNode, runLayoutForParents, runMutationWithLayout } = createLayoutRunner(
|
|
261
|
+
() => _graph
|
|
262
|
+
)
|
|
261
263
|
const pendingTextLayout = createPendingTextLayout({
|
|
262
264
|
getGraph: () => _graph,
|
|
263
265
|
runLayoutForNode,
|
|
@@ -294,6 +296,7 @@ export function createEditor(options?: EditorOptions) {
|
|
|
294
296
|
_graph = g
|
|
295
297
|
},
|
|
296
298
|
undo,
|
|
299
|
+
parkStep,
|
|
297
300
|
state,
|
|
298
301
|
loadFont: _loadFont,
|
|
299
302
|
resolveFigmaClipboardImages: options?.resolveFigmaClipboardImages ?? null,
|
|
@@ -315,6 +318,7 @@ export function createEditor(options?: EditorOptions) {
|
|
|
315
318
|
setActiveTool,
|
|
316
319
|
setNavigationPhase,
|
|
317
320
|
runLayoutForNode,
|
|
321
|
+
runLayoutForParents,
|
|
318
322
|
runMutationWithLayout,
|
|
319
323
|
subscribeToGraph
|
|
320
324
|
}
|
|
@@ -429,6 +433,12 @@ export function createEditor(options?: EditorOptions) {
|
|
|
429
433
|
/** Each graph's committed history, kept aside while another graph is open in this editor. */
|
|
430
434
|
const histories = new WeakMap<SceneGraph, UndoHistory>()
|
|
431
435
|
|
|
436
|
+
/** A step recorded while its document was swapped away joins that document's own history. */
|
|
437
|
+
function parkStep(graph: SceneGraph, entry: UndoEntry) {
|
|
438
|
+
const history = histories.get(graph)
|
|
439
|
+
if (history) histories.set(graph, undo.pushIntoParked(history, entry))
|
|
440
|
+
}
|
|
441
|
+
|
|
432
442
|
function replaceGraph(newGraph: SceneGraph) {
|
|
433
443
|
nodes.cancelNodePreviews()
|
|
434
444
|
if (newGraph !== _graph) {
|
|
@@ -496,10 +506,12 @@ export function createEditor(options?: EditorOptions) {
|
|
|
496
506
|
return _textEditor
|
|
497
507
|
},
|
|
498
508
|
undo: guardUndo(undo, readsOnly),
|
|
509
|
+
parkStep,
|
|
499
510
|
state,
|
|
500
511
|
|
|
501
512
|
// Graph reads
|
|
502
513
|
runLayoutForNode,
|
|
514
|
+
runLayoutForParents,
|
|
503
515
|
runMutationWithLayout,
|
|
504
516
|
...graphReads,
|
|
505
517
|
|
|
@@ -176,7 +176,11 @@ function begin(ctx: EditorContext, options: RecordEditOptions, awaits = false) {
|
|
|
176
176
|
// An edit that changed nothing, such as a read-only script, leaves no empty step behind.
|
|
177
177
|
if (options.push !== false && !empty) {
|
|
178
178
|
const entry = changeStep(ctx, options.label, change)
|
|
179
|
-
if (
|
|
179
|
+
if (ctx.graph !== graph) {
|
|
180
|
+
// The document the edit began on was swapped away while it awaited: its step stays with
|
|
181
|
+
// that document, and the one now open never carries an edit it did not see.
|
|
182
|
+
ctx.parkStep(graph, entry)
|
|
183
|
+
} else if (options.ownStep) ctx.undo.pushStep(entry)
|
|
180
184
|
else ctx.undo.push(entry)
|
|
181
185
|
}
|
|
182
186
|
options.onRecorded?.(change)
|
package/src/editor/nudge.ts
CHANGED
|
@@ -57,7 +57,7 @@ export function createNudgeActions(ctx: EditorContext) {
|
|
|
57
57
|
|
|
58
58
|
function applyOrder(parentId: string, order: readonly string[]) {
|
|
59
59
|
order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))
|
|
60
|
-
ctx.
|
|
60
|
+
ctx.runLayoutForParents([parentId])
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function commitReorder() {
|
|
@@ -11,6 +11,18 @@ export function createSelectionContainerActions(ctx: EditorContext) {
|
|
|
11
11
|
ctx.state.enteredContainerId = id
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Enters the container a click reached the layer through, as a double-click would have: its
|
|
16
|
+
* direct parent, unless that is the page or a container a click looks into by itself (a top-level
|
|
17
|
+
* frame, a section, a component set), which is never entered.
|
|
18
|
+
*/
|
|
19
|
+
function enterContainerOf(nodeId: string) {
|
|
20
|
+
const parentId = ctx.graph.getNode(nodeId)?.parentId ?? null
|
|
21
|
+
const entered =
|
|
22
|
+
parentId && parentId !== ctx.state.currentPageId && !ctx.graph.isOpenContainer(parentId)
|
|
23
|
+
ctx.state.enteredContainerId = entered ? parentId : null
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
function exitContainer() {
|
|
15
27
|
const entered = ctx.state.enteredContainerId
|
|
16
28
|
if (!entered) return
|
|
@@ -24,5 +36,16 @@ export function createSelectionContainerActions(ctx: EditorContext) {
|
|
|
24
36
|
ctx.setSelectedIds(new Set(entered ? [entered] : []))
|
|
25
37
|
}
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
/** Leaves every entered container; Escape then lands on the page and clears the selection. */
|
|
40
|
+
function exitContainers() {
|
|
41
|
+
ctx.state.enteredContainerId = null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
validateEnteredContainer,
|
|
46
|
+
enterContainer,
|
|
47
|
+
enterContainerOf,
|
|
48
|
+
exitContainer,
|
|
49
|
+
exitContainers
|
|
50
|
+
}
|
|
28
51
|
}
|
|
@@ -14,14 +14,16 @@ export function createSelectionNavigationActions(ctx: EditorContext, select: Sel
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* Replaces each selected layer that has children with its children, as Figma's Enter does, and
|
|
18
|
+
* keeps the others selected; a selection where none has children stays. A generated frame, such
|
|
19
|
+
* as a sticky note, has none to offer: its template owns its layers.
|
|
19
20
|
*/
|
|
20
21
|
function selectChildren() {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
22
|
+
const nodes = selectedNodes()
|
|
23
|
+
const opens = (node: (typeof nodes)[number]) =>
|
|
24
|
+
!isGeneratedFrame(node) && node.childIds.length > 0
|
|
25
|
+
if (!nodes.some(opens)) return
|
|
26
|
+
select(nodes.flatMap((node) => (opens(node) ? node.childIds : [node.id])))
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/** Selects the parents of the selected layers; layers directly on the page stay selected. */
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type FigJamLineStyle,
|
|
13
13
|
type FigJamTextSize
|
|
14
14
|
} from '@pairdraw/scene-graph/figjam'
|
|
15
|
-
import {
|
|
15
|
+
import { shapeWithTextKindFields, shapeWithTextLabel } from '@pairdraw/scene-graph/generated'
|
|
16
16
|
import type { ShapeWithTextType } from '@pairdraw/scene-graph/shape-with-text'
|
|
17
17
|
|
|
18
18
|
import { recordSubtreeEdit } from '#core/editor/components/slots/history'
|
|
@@ -60,10 +60,7 @@ export function createShapeWithTextActions(ctx: EditorContext, nodes: NodeAction
|
|
|
60
60
|
'Change shape',
|
|
61
61
|
changing.map((shape) => shape.id),
|
|
62
62
|
(shape) => {
|
|
63
|
-
nodes.updateNode(shape.id,
|
|
64
|
-
shapeWithTextType: kind,
|
|
65
|
-
...shapeWithTextFrameFields(kind, shape.width, shape.height)
|
|
66
|
-
})
|
|
63
|
+
nodes.updateNode(shape.id, shapeWithTextKindFields(shape, kind))
|
|
67
64
|
}
|
|
68
65
|
)
|
|
69
66
|
}
|
|
@@ -105,7 +105,7 @@ export function wrapInAutoLayout(ctx: EditorContext, selectedNodes: SceneNode[])
|
|
|
105
105
|
ctx.graph.deleteNode(frameId)
|
|
106
106
|
order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))
|
|
107
107
|
for (const [id, rect] of geometry) ctx.graph.updateNode(id, rect)
|
|
108
|
-
ctx.
|
|
108
|
+
ctx.runLayoutForParents([parentId])
|
|
109
109
|
ctx.setSelectedIds(prevSelection)
|
|
110
110
|
}
|
|
111
111
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
1
|
+
import type { BooleanOperation, SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
2
2
|
import { copyFills } from '@pairdraw/scene-graph/copy'
|
|
3
3
|
import {
|
|
4
4
|
fitEnclosingGroups,
|
|
@@ -15,8 +15,6 @@ import type { EditorContext } from '#core/editor/types'
|
|
|
15
15
|
import { canvasWrapIndex, inStackOrder, wrapNodes } from './container-wrap'
|
|
16
16
|
import { selectedNodesInSharedParent } from './selection'
|
|
17
17
|
|
|
18
|
-
export type BooleanOperation = 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE'
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Wraps sibling layers in a boolean operation named after it, as Figma names one from the canvas
|
|
22
20
|
* and from the plugin API. Shared by the editor command and the plugin API; `props` gives the look.
|
|
@@ -22,11 +22,7 @@ export function fitEnclosingGroupsWithUndo(ctx: EditorContext, parentIds: Iterab
|
|
|
22
22
|
...[...fit.before.keys()].map((id) => ctx.graph.getNode(id)?.parentId),
|
|
23
23
|
...fit.removed.map(({ node }) => node.parentId)
|
|
24
24
|
])
|
|
25
|
-
const layoutAround = () =>
|
|
26
|
-
for (const parentId of new Set(fittedParents)) {
|
|
27
|
-
if (parentId) ctx.runLayoutForNode(parentId)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
25
|
+
const layoutAround = () => ctx.runLayoutForParents(fittedParents)
|
|
30
26
|
layoutAround()
|
|
31
27
|
ctx.undo.push({
|
|
32
28
|
label: 'Fit groups',
|
|
@@ -87,7 +87,7 @@ export function outlineStrokeSelected(
|
|
|
87
87
|
})
|
|
88
88
|
const parentIds = new Set(plan.map((entry) => entry.parentId))
|
|
89
89
|
const prevSelection = new Set(ctx.state.selectedIds)
|
|
90
|
-
|
|
90
|
+
ctx.runLayoutForParents(parentIds)
|
|
91
91
|
ctx.setSelectedIds(new Set(madeIds))
|
|
92
92
|
|
|
93
93
|
// Groups around the outlines fit them, which can reach past the layers they replace, in the
|
|
@@ -121,7 +121,7 @@ function pushOutlineUndo(
|
|
|
121
121
|
forward: () => {
|
|
122
122
|
for (const { node } of plan) ctx.graph.deleteNode(node.id)
|
|
123
123
|
restoreAt(ctx, made)
|
|
124
|
-
|
|
124
|
+
ctx.runLayoutForParents(parentIds)
|
|
125
125
|
ctx.setSelectedIds(new Set(madeIds))
|
|
126
126
|
},
|
|
127
127
|
inverse: () => {
|
|
@@ -135,7 +135,7 @@ function pushOutlineUndo(
|
|
|
135
135
|
snapshot
|
|
136
136
|
}))
|
|
137
137
|
)
|
|
138
|
-
|
|
138
|
+
ctx.runLayoutForParents(parentIds)
|
|
139
139
|
ctx.setSelectedIds(new Set(prevSelection))
|
|
140
140
|
}
|
|
141
141
|
})
|
|
@@ -7,7 +7,6 @@ import { assertNodeEditable } from '#core/editor/capabilities'
|
|
|
7
7
|
import { prepareSlotEdits } from '#core/editor/components/slots'
|
|
8
8
|
import { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'
|
|
9
9
|
import type { EditorContext } from '#core/editor/types'
|
|
10
|
-
import { computeLayout } from '#core/layout'
|
|
11
10
|
|
|
12
11
|
export function createStructureReorderActions(ctx: EditorContext) {
|
|
13
12
|
function doReorderChild(nodeId: string, parentId: string, insertIndex: number) {
|
|
@@ -23,8 +22,7 @@ export function createStructureReorderActions(ctx: EditorContext) {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
ctx.graph.insertChildAt(nodeId, parentId, insertIndex)
|
|
26
|
-
|
|
27
|
-
ctx.runLayoutForNode(parentId)
|
|
25
|
+
ctx.runLayoutForParents([parentId])
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
function reorderInAutoLayout(nodeId: string, parentId: string, insertIndex: number) {
|
|
@@ -54,12 +52,7 @@ export function createStructureReorderActions(ctx: EditorContext) {
|
|
|
54
52
|
inverse: () => {
|
|
55
53
|
ctx.graph.insertChildAt(nodeId, origParentId, origIndex >= 0 ? origIndex : 0)
|
|
56
54
|
ctx.graph.updateNode(nodeId, { x: origX, y: origY })
|
|
57
|
-
|
|
58
|
-
ctx.runLayoutForNode(origParentId)
|
|
59
|
-
if (origParentId !== parentId) {
|
|
60
|
-
computeLayout(ctx.graph, parentId)
|
|
61
|
-
ctx.runLayoutForNode(parentId)
|
|
62
|
-
}
|
|
55
|
+
ctx.runLayoutForParents([origParentId, parentId])
|
|
63
56
|
}
|
|
64
57
|
})
|
|
65
58
|
fitEnclosingGroupsWithUndo(ctx, [origParentId])
|
|
@@ -90,8 +83,9 @@ export function createStructureReorderActions(ctx: EditorContext) {
|
|
|
90
83
|
const place = () => {
|
|
91
84
|
if (reparents) ctx.graph.reparentNode(nodeId, newParentId)
|
|
92
85
|
ctx.graph.insertChildAt(nodeId, newParentId, insertIndex)
|
|
93
|
-
|
|
94
|
-
if (reparents) ctx.runLayoutForNode(
|
|
86
|
+
// A new parent can change what the layer inherits, such as its layout direction.
|
|
87
|
+
if (reparents) ctx.runLayoutForNode(nodeId)
|
|
88
|
+
ctx.runLayoutForParents([newParentId, origParentId])
|
|
95
89
|
}
|
|
96
90
|
place()
|
|
97
91
|
|
|
@@ -101,8 +95,8 @@ export function createStructureReorderActions(ctx: EditorContext) {
|
|
|
101
95
|
inverse: () => {
|
|
102
96
|
ctx.graph.insertChildAt(nodeId, origParentId, origIndex)
|
|
103
97
|
ctx.graph.updateNode(nodeId, origPlace)
|
|
104
|
-
ctx.runLayoutForNode(
|
|
105
|
-
|
|
98
|
+
if (reparents) ctx.runLayoutForNode(nodeId)
|
|
99
|
+
ctx.runLayoutForParents([origParentId, newParentId])
|
|
106
100
|
}
|
|
107
101
|
})
|
|
108
102
|
// Groups the layer left or joined fit their layers; a stacking change can move a group's box
|
|
@@ -123,7 +117,7 @@ export function createStructureReorderActions(ctx: EditorContext) {
|
|
|
123
117
|
if (ctx.graph.getNode(parentId)?.childIds[index] === childId) continue
|
|
124
118
|
ctx.graph.insertChildAt(childId, parentId, index)
|
|
125
119
|
}
|
|
126
|
-
ctx.
|
|
120
|
+
ctx.runLayoutForParents([parentId])
|
|
127
121
|
ctx.requestRender()
|
|
128
122
|
}
|
|
129
123
|
|
|
@@ -26,7 +26,7 @@ export function createStructureStateActions(ctx: EditorContext) {
|
|
|
26
26
|
ctx.graph.updateNode(id, { visible: shown })
|
|
27
27
|
const parentId = ctx.graph.getNode(id)?.parentId
|
|
28
28
|
if (!parentId) return
|
|
29
|
-
ctx.
|
|
29
|
+
ctx.runLayoutForParents([parentId])
|
|
30
30
|
refitGroupsAroundLayers(ctx, [id])
|
|
31
31
|
}
|
|
32
32
|
const forward = () => {
|
package/src/editor/structure.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pick } from 'es-toolkit'
|
|
2
2
|
|
|
3
|
-
import type { SceneNode } from '@pairdraw/scene-graph'
|
|
3
|
+
import type { BooleanOperation, SceneNode } from '@pairdraw/scene-graph'
|
|
4
4
|
import { TRANSFORM_FIELDS } from '@pairdraw/scene-graph/fields'
|
|
5
5
|
import { createsComponentCycle } from '@pairdraw/scene-graph/instances'
|
|
6
6
|
import { defaultNodeName } from '@pairdraw/scene-graph/node-defaults'
|
|
@@ -9,10 +9,7 @@ import { acceptingParent, acceptsChildren, prepareSlotEdits } from '#core/editor
|
|
|
9
9
|
import { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'
|
|
10
10
|
|
|
11
11
|
import { wrapInAutoLayout as wrapInAutoLayoutImpl } from './structure/auto-layout-wrap'
|
|
12
|
-
import {
|
|
13
|
-
booleanOperationSelected as booleanOperationSelectedImpl,
|
|
14
|
-
type BooleanOperation
|
|
15
|
-
} from './structure/boolean'
|
|
12
|
+
import { booleanOperationSelected as booleanOperationSelectedImpl } from './structure/boolean'
|
|
16
13
|
import { wrapSelectionInContainer as wrapSelectionInContainerImpl } from './structure/container-wrap'
|
|
17
14
|
import { flattenSelected as flattenSelectedImpl } from './structure/flatten'
|
|
18
15
|
import { ungroupSelected as ungroupImpl } from './structure/group/ungroup'
|
|
@@ -167,11 +164,11 @@ export function createStructureActions(ctx: EditorContext) {
|
|
|
167
164
|
})
|
|
168
165
|
.sort((a, b) => a.index - b.index)
|
|
169
166
|
if (origins.length === 0) return
|
|
170
|
-
const parentIds =
|
|
167
|
+
const parentIds = origins.map((origin) => origin.parentId)
|
|
171
168
|
const prevSelection = new Set(ctx.state.selectedIds)
|
|
172
169
|
const move = () => {
|
|
173
170
|
for (const { id } of origins) ctx.graph.reparentNode(id, pageId)
|
|
174
|
-
|
|
171
|
+
ctx.runLayoutForParents(parentIds)
|
|
175
172
|
ctx.setSelectedIds(new Set())
|
|
176
173
|
}
|
|
177
174
|
move()
|
|
@@ -185,7 +182,7 @@ export function createStructureActions(ctx: EditorContext) {
|
|
|
185
182
|
ctx.graph.insertChildAt(id, parentId, index)
|
|
186
183
|
ctx.graph.updateNode(id, place)
|
|
187
184
|
}
|
|
188
|
-
|
|
185
|
+
ctx.runLayoutForParents(parentIds)
|
|
189
186
|
ctx.setSelectedIds(new Set(prevSelection))
|
|
190
187
|
}
|
|
191
188
|
})
|
package/src/editor/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { SceneMutationImpact } from '@pairdraw/scene-graph/mutation-impact'
|
|
|
15
15
|
import type { Color, Rect, Vector } from '@pairdraw/scene-graph/primitives'
|
|
16
16
|
import type { ShapeWithTextType } from '@pairdraw/scene-graph/shape-with-text'
|
|
17
17
|
import type { SnapGuide } from '@pairdraw/scene-graph/snap'
|
|
18
|
-
import type { UndoManager } from '@pairdraw/scene-graph/undo'
|
|
18
|
+
import type { UndoEntry, UndoManager } from '@pairdraw/scene-graph/undo'
|
|
19
19
|
|
|
20
20
|
import type { GuideOverlayState } from '#core/canvas/guides/types'
|
|
21
21
|
import type { DesignIssueHighlight } from '#core/canvas/issues/types'
|
|
@@ -305,6 +305,8 @@ export interface EditorContext {
|
|
|
305
305
|
get graph(): SceneGraph
|
|
306
306
|
set graph(g: SceneGraph)
|
|
307
307
|
undo: UndoManager
|
|
308
|
+
/** Adds a step to the history of a graph that is not the open one, kept aside with it. */
|
|
309
|
+
parkStep: (graph: SceneGraph, entry: UndoEntry) => void
|
|
308
310
|
state: EditorState
|
|
309
311
|
loadFont: (
|
|
310
312
|
family: string,
|
|
@@ -336,6 +338,7 @@ export interface EditorContext {
|
|
|
336
338
|
setActiveTool: (tool: Tool) => void
|
|
337
339
|
setNavigationPhase: (phase: NavigationPhase, inputAt?: number) => void
|
|
338
340
|
runLayoutForNode: (id: string) => void
|
|
341
|
+
runLayoutForParents: (parentIds: Iterable<string>) => void
|
|
339
342
|
runMutationWithLayout: <T>(
|
|
340
343
|
operation: () => T | Promise<T>,
|
|
341
344
|
fallbackId?: string,
|
package/src/editor/variables.ts
CHANGED
|
@@ -9,7 +9,13 @@ import {
|
|
|
9
9
|
type VariableType,
|
|
10
10
|
type VariableValue
|
|
11
11
|
} from '@pairdraw/scene-graph'
|
|
12
|
-
import {
|
|
12
|
+
import { findInstanceAncestor } from '@pairdraw/scene-graph/instances'
|
|
13
|
+
import { cloneInstanceOverrideState } from '@pairdraw/scene-graph/instances/overrides'
|
|
14
|
+
import {
|
|
15
|
+
tokenExpressionForValue,
|
|
16
|
+
variableBindingOwner,
|
|
17
|
+
type BindingScope
|
|
18
|
+
} from '@pairdraw/scene-graph/variables'
|
|
13
19
|
|
|
14
20
|
import { reconcileVariableLayouts } from '#core/layout/variables'
|
|
15
21
|
|
|
@@ -168,6 +174,14 @@ export function createVariableActions(ctx: EditorContext) {
|
|
|
168
174
|
.map((vid) => ctx.graph.variables.get(vid))
|
|
169
175
|
.filter((v): v is Variable => v != null)
|
|
170
176
|
.map((v) => structuredClone(v))
|
|
177
|
+
const bindings = bindingSnapshots(snapshot.variableIds)
|
|
178
|
+
// The mode the collection showed and the one each layer chose, which the removal drops, so
|
|
179
|
+
// undo resolves the restored bindings to the values they had before it.
|
|
180
|
+
const activeMode = ctx.graph.activeMode.get(id)
|
|
181
|
+
const modeChoices = new Map<string, string>()
|
|
182
|
+
for (const node of ctx.graph.getAllNodes()) {
|
|
183
|
+
if (Object.hasOwn(node.variableModes, id)) modeChoices.set(node.id, node.variableModes[id])
|
|
184
|
+
}
|
|
171
185
|
ctx.graph.removeCollection(id)
|
|
172
186
|
ctx.undo.push({
|
|
173
187
|
label: 'Remove collection',
|
|
@@ -178,6 +192,15 @@ export function createVariableActions(ctx: EditorContext) {
|
|
|
178
192
|
inverse: () => {
|
|
179
193
|
ctx.graph.addCollection(snapshot)
|
|
180
194
|
for (const v of variables) ctx.graph.addVariable(v)
|
|
195
|
+
if (activeMode !== undefined) ctx.graph.setActiveMode(id, activeMode)
|
|
196
|
+
for (const [nodeId, modeId] of modeChoices) {
|
|
197
|
+
const node = ctx.graph.getNode(nodeId)
|
|
198
|
+
if (!node) continue
|
|
199
|
+
ctx.graph.updateNode(nodeId, {
|
|
200
|
+
variableModes: { ...node.variableModes, [id]: modeId }
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
restoreBindings(bindings)
|
|
181
204
|
refreshVariables(scope)
|
|
182
205
|
}
|
|
183
206
|
})
|
|
@@ -200,11 +223,58 @@ export function createVariableActions(ctx: EditorContext) {
|
|
|
200
223
|
ctx.requestRefresh()
|
|
201
224
|
}
|
|
202
225
|
|
|
226
|
+
/**
|
|
227
|
+
* The bindings removing these variables strips from layers, and the instance overrides it
|
|
228
|
+
* records, so undo can put both back. A layer keeps the value its variable last gave it.
|
|
229
|
+
*/
|
|
230
|
+
function bindingSnapshots(ids: Iterable<string>) {
|
|
231
|
+
const removed = new Set(ids)
|
|
232
|
+
const snapshots = []
|
|
233
|
+
for (const node of ctx.graph.getAllNodes()) {
|
|
234
|
+
const entries = Object.entries(node.boundVariables).filter(([, id]) => removed.has(id))
|
|
235
|
+
if (entries.length === 0) continue
|
|
236
|
+
const owner = variableBindingOwner(ctx.graph, node)
|
|
237
|
+
const nearest = findInstanceAncestor(ctx.graph, node.id)
|
|
238
|
+
snapshots.push({
|
|
239
|
+
nodeId: node.id,
|
|
240
|
+
boundVariables: Object.fromEntries(entries),
|
|
241
|
+
variableBindingScales: Object.fromEntries(
|
|
242
|
+
entries
|
|
243
|
+
.map(([field]) => field)
|
|
244
|
+
.filter((field) => field in node.variableBindingScales)
|
|
245
|
+
.map((field) => [field, node.variableBindingScales[field]])
|
|
246
|
+
),
|
|
247
|
+
owners: new Map(
|
|
248
|
+
[owner, ...(nearest ? [nearest] : [])].map((item) => [
|
|
249
|
+
item.id,
|
|
250
|
+
cloneInstanceOverrideState(item.instanceOverrides)
|
|
251
|
+
])
|
|
252
|
+
)
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
return snapshots
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function restoreBindings(snapshots: ReturnType<typeof bindingSnapshots>) {
|
|
259
|
+
for (const snapshot of snapshots) {
|
|
260
|
+
for (const [ownerId, state] of snapshot.owners) {
|
|
261
|
+
ctx.graph.updateNode(ownerId, { instanceOverrides: cloneInstanceOverrideState(state) })
|
|
262
|
+
}
|
|
263
|
+
const node = ctx.graph.getNode(snapshot.nodeId)
|
|
264
|
+
if (!node) continue
|
|
265
|
+
ctx.graph.updateNode(snapshot.nodeId, {
|
|
266
|
+
boundVariables: { ...node.boundVariables, ...snapshot.boundVariables },
|
|
267
|
+
variableBindingScales: { ...node.variableBindingScales, ...snapshot.variableBindingScales }
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
203
272
|
function removeVariable(id: string) {
|
|
204
273
|
const variable = ctx.graph.variables.get(id)
|
|
205
274
|
if (!variable) return
|
|
206
275
|
const snapshot = structuredClone(variable)
|
|
207
276
|
const order = [...(ctx.graph.variableCollections.get(variable.collectionId)?.variableIds ?? [])]
|
|
277
|
+
const bindings = bindingSnapshots([id])
|
|
208
278
|
ctx.graph.removeVariable(id)
|
|
209
279
|
ctx.undo.push({
|
|
210
280
|
label: 'Remove variable',
|
|
@@ -212,10 +282,12 @@ export function createVariableActions(ctx: EditorContext) {
|
|
|
212
282
|
ctx.graph.removeVariable(id)
|
|
213
283
|
refreshVariables({ variables: [id] })
|
|
214
284
|
},
|
|
215
|
-
// Undo puts the variable back where it was, not at the end of its collection
|
|
285
|
+
// Undo puts the variable back where it was, not at the end of its collection, with the
|
|
286
|
+
// bindings deleting it stripped.
|
|
216
287
|
inverse: () => {
|
|
217
288
|
ctx.graph.addVariable(structuredClone(snapshot))
|
|
218
289
|
placeVariables(snapshot.collectionId, order)
|
|
290
|
+
restoreBindings(bindings)
|
|
219
291
|
refreshVariables({ variables: [id] })
|
|
220
292
|
}
|
|
221
293
|
})
|
|
@@ -14,7 +14,11 @@ import {
|
|
|
14
14
|
type NodeProxyInternals,
|
|
15
15
|
type ProxyThis
|
|
16
16
|
} from '#core/figma-api/accessor-utils'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
assertFontLoaded,
|
|
19
|
+
assertTextFontsLoaded,
|
|
20
|
+
textHasMissingFont
|
|
21
|
+
} from '#core/figma-api/fonts/loaded'
|
|
18
22
|
import type { FigmaFontNameInput } from '#core/figma-api/fonts/names'
|
|
19
23
|
import {
|
|
20
24
|
getParagraphSpacing,
|
|
@@ -147,6 +151,11 @@ export function installTextNodeProxyAccessors(
|
|
|
147
151
|
textAlignHorizontal: field(internals, 'textAlignHorizontal'),
|
|
148
152
|
textAlignVertical: field(internals, 'textAlignVertical'),
|
|
149
153
|
textAutoResize: field(internals, 'textAutoResize'),
|
|
154
|
+
hasMissingFont: {
|
|
155
|
+
get(this: ProxyThis): boolean {
|
|
156
|
+
return textHasMissingFont(raw(this, internals))
|
|
157
|
+
}
|
|
158
|
+
},
|
|
150
159
|
// Figma's plugin API reads and writes these as { unit, value }; a bare object stored on the
|
|
151
160
|
// node instead of pixels would leave the text unmeasurable.
|
|
152
161
|
letterSpacing: characterStyle<FigmaLetterSpacing | number>(
|
|
@@ -38,6 +38,15 @@ function textFaces(node: SceneNode): DescribedFace[] {
|
|
|
38
38
|
return uniqBy(faces, (face) => `${face.family}\0${face.loadStyle}`)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** Whether every face the text draws in is one the document can use, loaded or from a known family. */
|
|
42
|
+
export function textHasMissingFont(node: SceneNode): boolean {
|
|
43
|
+
return textFaces(node).some((face) => {
|
|
44
|
+
if (isLoaded(face)) return false
|
|
45
|
+
const known = fontManager.familyFacesSync(face.family) ?? []
|
|
46
|
+
return !known.some((faceOfFamily) => faceOfFamily.style === face.loadStyle)
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
/**
|
|
42
51
|
* Figma refuses an edit that lays text out again until every font the text uses is loaded, so
|
|
43
52
|
* the text is never measured in a stand-in font. Paints and links need no font. Callers check
|
package/src/figma-api/index.ts
CHANGED
|
@@ -719,6 +719,31 @@ export class FigmaAPI implements NodeProxyHost {
|
|
|
719
719
|
return toUint8Array(data)
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
+
/**
|
|
723
|
+
* A script run in the editor has no UI to talk to, and Figma still gives every plugin a UI
|
|
724
|
+
* object, so scripts that guard on `figma.ui` keep working here: the calls do nothing.
|
|
725
|
+
*/
|
|
726
|
+
readonly ui: {
|
|
727
|
+
onmessage: ((message: unknown, props: unknown) => void) | undefined
|
|
728
|
+
postMessage(message: unknown): void
|
|
729
|
+
resize(width: number, height: number): void
|
|
730
|
+
close(): void
|
|
731
|
+
show(): void
|
|
732
|
+
hide(): void
|
|
733
|
+
} = {
|
|
734
|
+
onmessage: undefined,
|
|
735
|
+
postMessage: noop,
|
|
736
|
+
resize: noop,
|
|
737
|
+
close: noop,
|
|
738
|
+
show: noop,
|
|
739
|
+
hide: noop
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
showUI(html?: string, options?: unknown): void {
|
|
743
|
+
void html
|
|
744
|
+
void options
|
|
745
|
+
}
|
|
746
|
+
|
|
722
747
|
notify(message: string): { cancel: () => void } {
|
|
723
748
|
if (typeof console !== 'undefined') console.warn(`[figma.notify] ${message}`)
|
|
724
749
|
return { cancel: noop }
|
|
@@ -3,6 +3,7 @@ import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
|
3
3
|
import { pluginChildren } from './accessors/sticky'
|
|
4
4
|
import { figmaFills, figmaStrokes } from './accessors/visual'
|
|
5
5
|
import type { NodeProxyHost } from './proxy'
|
|
6
|
+
import { shapeDetailFields } from './shape-details'
|
|
6
7
|
|
|
7
8
|
function resolveBindings(graph: SceneGraph, node: SceneNode): Record<string, unknown> | undefined {
|
|
8
9
|
const keys = Object.keys(node.boundVariables)
|
|
@@ -61,7 +62,7 @@ export function nodeProxyToJSON(
|
|
|
61
62
|
// The angle `set_rotation` writes, as the Figma API reports it. The scene stores the turn in
|
|
62
63
|
// the opposite direction and keeps floating-point noise, so read it through the proxy.
|
|
63
64
|
if (n.rotation !== 0) obj.rotation = api.wrapNode(nodeId).rotation
|
|
64
|
-
|
|
65
|
+
Object.assign(obj, shapeDetailFields(n))
|
|
65
66
|
if (!n.visible) obj.visible = false
|
|
66
67
|
if (n.text) obj.characters = n.text
|
|
67
68
|
if (n.type === 'TEXT') {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BooleanOperation, MaskType, SceneNode } from '@pairdraw/scene-graph'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The shape details a node summary reports, under Figma's plugin-API names: the per-corner radii
|
|
5
|
+
* once the corners are drawn one by one and disagree, the mask flag and type while the layer masks,
|
|
6
|
+
* and a boolean layer's operation. A plain layer carries none of them.
|
|
7
|
+
*
|
|
8
|
+
* The per-corner fields are live only while `independentCorners` is set; otherwise the shape renders
|
|
9
|
+
* the uniform `cornerRadius` and any stored per-corner values are stale (a .fig import or a uniform
|
|
10
|
+
* radius-handle write leaves them), so they stay out. While the corners disagree the proxy reads
|
|
11
|
+
* `cornerRadius` as `mixed`, which JSON cannot hold, so the uniform field stays out too.
|
|
12
|
+
*/
|
|
13
|
+
export interface ShapeDetailFields {
|
|
14
|
+
cornerRadius?: number
|
|
15
|
+
topLeftRadius?: number
|
|
16
|
+
topRightRadius?: number
|
|
17
|
+
bottomRightRadius?: number
|
|
18
|
+
bottomLeftRadius?: number
|
|
19
|
+
isMask?: boolean
|
|
20
|
+
maskType?: MaskType
|
|
21
|
+
booleanOperation?: BooleanOperation
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function shapeDetailFields(node: SceneNode): ShapeDetailFields {
|
|
25
|
+
const fields: ShapeDetailFields = {}
|
|
26
|
+
const corners = [
|
|
27
|
+
node.topLeftRadius,
|
|
28
|
+
node.topRightRadius,
|
|
29
|
+
node.bottomRightRadius,
|
|
30
|
+
node.bottomLeftRadius
|
|
31
|
+
]
|
|
32
|
+
const differ = node.independentCorners && corners.some((radius) => radius !== corners[0])
|
|
33
|
+
// Figma reads independent corners that agree as one radius, so the reported radius must come from
|
|
34
|
+
// that agreement rather than the stale uniform field the corner edits leave behind.
|
|
35
|
+
const uniform = node.independentCorners ? corners[0] : node.cornerRadius
|
|
36
|
+
if (differ) {
|
|
37
|
+
fields.topLeftRadius = node.topLeftRadius
|
|
38
|
+
fields.topRightRadius = node.topRightRadius
|
|
39
|
+
fields.bottomRightRadius = node.bottomRightRadius
|
|
40
|
+
fields.bottomLeftRadius = node.bottomLeftRadius
|
|
41
|
+
} else if (uniform > 0) {
|
|
42
|
+
fields.cornerRadius = uniform
|
|
43
|
+
}
|
|
44
|
+
if (node.isMask) {
|
|
45
|
+
fields.isMask = true
|
|
46
|
+
fields.maskType = node.maskType
|
|
47
|
+
}
|
|
48
|
+
if (node.booleanOperation) fields.booleanOperation = node.booleanOperation
|
|
49
|
+
return fields
|
|
50
|
+
}
|