AI-native design editor. Open-source Figma alternative.
fix(figma-api): implement layout compatibility gaps
Danila Poyarkov71bb3b20a6b7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4b609a58f..0c3b1ec2a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,7 @@### Fixed+- Match Figma Plugin API behavior for `rescale()`, page `backgrounds`, and nullable visual `absoluteRenderBounds`. (#442)- Keep imported Figma instances linked to their remapped source components so later component edits update existing instances. (#385)- Restore native copy, cut, and paste shortcuts in desktop text inputs while preserving design clipboard handling on the canvas.- Remove the permanent CORS configuration action from cloud-storage settings and report connection results through standard toasts with clear browser-specific guidance.diff --git a/packages/core/src/figma-api/accessors/basic.ts b/packages/core/src/figma-api/accessors/basic.tsindex fc99848fa..6cc3288fb 100644--- a/packages/core/src/figma-api/accessors/basic.ts+++ b/packages/core/src/figma-api/accessors/basic.ts@@ -9,6 +9,8 @@ import {type ProxyThis} from '#core/figma-api/accessor-utils'import type { NodeProxyHost } from '#core/figma-api/proxy'+import { computeAbsoluteRenderBounds } from '#core/figma-api/render-bounds'+import { rescaleNodeTree } from '#core/figma-api/rescale'import type { FigmaTransform } from '#core/figma-api/types'const TRANSFORM_FIELDS = new Set(['x', 'y', 'rotation', 'flipX', 'flipY'])@@ -129,8 +131,8 @@ export function installBasicNodeProxyAccessors(}},absoluteRenderBounds: {- get(this: ProxyThis): Rect {- return graph(this, internals).getAbsoluteBounds(nodeId(this, internals))+ get(this: ProxyThis): Rect | null {+ return computeAbsoluteRenderBounds(graph(this, internals), raw(this, internals))}}})@@ -141,6 +143,9 @@ export function installBasicNodeProxyAccessors(},resizeWithoutConstraints(this: ProxyThis, width: number, height: number): void {;(this as { resize(width: number, height: number): void }).resize(width, height)+ },+ rescale(this: ProxyThis, scale: number): void {+ rescaleNodeTree(graph(this, internals), nodeId(this, internals), scale)}})}diff --git a/packages/core/src/figma-api/page-backgrounds.ts b/packages/core/src/figma-api/page-backgrounds.tsnew file mode 100644index 000000000..938f8bdf2--- /dev/null+++ b/packages/core/src/figma-api/page-backgrounds.ts@@ -0,0 +1,52 @@+import { convertFills, fillToKiwiPaint } from '@open-pencil/fig/node-change'+import type { Fill, SceneGraph, SceneNode } from '@open-pencil/scene-graph'+import { copyFills } from '@open-pencil/scene-graph/copy'+import type { Color } from '@open-pencil/scene-graph/primitives'++import { CANVAS_BG_COLOR } from '#core/constants'++function isColor(value: unknown): value is Color {+ if (!value || typeof value !== 'object') return false+ const color = value as Partial<Color>+ return (+ typeof color.r === 'number' &&+ typeof color.g === 'number' &&+ typeof color.b === 'number' &&+ typeof color.a === 'number'+ )+}++function fallbackBackground(page: SceneNode): Fill[] {+ const rawColor = page.source.fig.rawNodeFields.backgroundColor+ const color = isColor(rawColor) ? structuredClone(rawColor) : { ...CANVAS_BG_COLOR }+ return [{ type: 'SOLID', color, opacity: 1, visible: true, blendMode: 'NORMAL' }]+}++export function getPageBackgrounds(page: SceneNode): readonly Fill[] {+ const rawPaints = page.source.fig.rawNodeFields.backgroundPaints+ const fills = Array.isArray(rawPaints)+ ? convertFills(rawPaints as Parameters<typeof convertFills>[0])+ : fallbackBackground(page)+ return Object.freeze(copyFills(fills))+}++export function setPageBackgrounds(+ graph: SceneGraph,+ page: SceneNode,+ backgrounds: readonly Fill[]+): void {+ if (page.type !== 'CANVAS') throw new Error('backgrounds is only supported on pages')+ if (backgrounds.length > 1 || backgrounds.some((paint) => paint.type !== 'SOLID')) {+ throw new Error('Page backgrounds currently support at most one solid paint')+ }++ const rawNodeFields = structuredClone(page.source.fig.rawNodeFields)+ rawNodeFields.backgroundPaints = backgrounds.map((fill) => fillToKiwiPaint(fill))+ if (backgrounds[0]) rawNodeFields.backgroundColor = structuredClone(backgrounds[0].color)+ graph.updateNode(page.id, {+ source: {+ ...structuredClone(page.source),+ fig: { ...structuredClone(page.source.fig), rawNodeFields }+ }+ })+}diff --git a/packages/core/src/figma-api/proxy.ts b/packages/core/src/figma-api/proxy.tsindex 1ca98ccef..1984a6009 100644--- a/packages/core/src/figma-api/proxy.ts+++ b/packages/core/src/figma-api/proxy.ts@@ -27,6 +27,7 @@ import {} from './accessors/vector'import { installVisualNodeProxyAccessors } from './accessors/visual'import type { FigmaFontName } from './fonts'+import { getPageBackgrounds, setPageBackgrounds } from './page-backgrounds'import * as PluginData from './plugin-data'import { nodeProxyToJSON } from './serialization'import { setFirstStrokeAlign, setFirstStrokeWeight, setIndependentStrokeWeight } from './strokes'@@ -66,9 +67,10 @@ export class FigmaNodeProxy {declare readonly relativeTransform: FigmaTransformdeclare resize: (width: number, height: number) => voiddeclare resizeWithoutConstraints: (width: number, height: number) => void+ declare rescale: (scale: number) => voiddeclare readonly absoluteTransform: FigmaTransformdeclare readonly absoluteBoundingBox: Rect- declare readonly absoluteRenderBounds: Rect+ declare readonly absoluteRenderBounds: Rect | nulldeclare fills: readonly Fill[]declare strokes: readonly Stroke[]@@ -401,6 +403,14 @@ export class FigmaNodeProxy {// --- Components ---+ get backgrounds(): readonly Fill[] {+ return getPageBackgrounds(this._raw())+ }++ set backgrounds(value: readonly Fill[]) {+ setPageBackgrounds(this[INTERNAL_GRAPH], this._raw(), value)+ }+get mainComponent(): FigmaNodeProxy | null {const n = this._raw()if (!n.componentId) return nulldiff --git a/packages/core/src/figma-api/render-bounds.ts b/packages/core/src/figma-api/render-bounds.tsnew file mode 100644index 000000000..07c5c8f0e--- /dev/null+++ b/packages/core/src/figma-api/render-bounds.ts@@ -0,0 +1,174 @@+import { getWorldMatrix, type SceneGraph, type SceneNode } from '@open-pencil/scene-graph'+import {+ geometryBlobBounds,+ intersectVisualBounds,+ strokeOverflow,+ unionVisualBounds,+ type VisualBounds+} from '@open-pencil/scene-graph/geometry'+import Matrix from '@open-pencil/scene-graph/matrix'+import type { Rect } from '@open-pencil/scene-graph/primitives'++const INTRINSIC_CONTAINER_TYPES = new Set([+ 'FRAME',+ 'COMPONENT',+ 'COMPONENT_SET',+ 'INSTANCE',+ 'SECTION'+])++function aabb(points: number[]): VisualBounds {+ let minX = Infinity+ let minY = Infinity+ let maxX = -Infinity+ let maxY = -Infinity+ for (let index = 0; index < points.length; index += 2) {+ minX = Math.min(minX, points[index])+ minY = Math.min(minY, points[index + 1])+ maxX = Math.max(maxX, points[index])+ maxY = Math.max(maxY, points[index + 1])+ }+ return { minX, minY, maxX, maxY }+}++function transformedRect(+ node: SceneNode,+ graph: SceneGraph,+ x: number,+ y: number,+ width: number,+ height: number+): VisualBounds {+ return aabb(+ Matrix.mapPoints(getWorldMatrix(node, graph), [+ x,+ y,+ x + width,+ y,+ x + width,+ y + height,+ x,+ y + height+ ])+ )+}++function hasRenderableGeometry(node: SceneNode): boolean {+ if (INTRINSIC_CONTAINER_TYPES.has(node.type)) return true+ if (node.type === 'GROUP') return false+ if (node.type === 'TEXT') return node.text.length > 0 && node.fills.some((fill) => fill.visible)+ if (node.fills.some((fill) => fill.visible) || node.strokes.some((stroke) => stroke.visible)) {+ return true+ }+ return node.fillGeometry.length > 0 || node.strokeGeometry.length > 0+}++function translatedBounds(+ bounds: VisualBounds,+ offset: { x: number; y: number },+ overflow: number+): VisualBounds {+ return {+ minX: bounds.minX + offset.x - overflow,+ minY: bounds.minY + offset.y - overflow,+ maxX: bounds.maxX + offset.x + overflow,+ maxY: bounds.maxY + offset.y + overflow+ }+}++function ownRenderBounds(node: SceneNode, graph: SceneGraph): VisualBounds | null {+ if (!hasRenderableGeometry(node)) return null++ const base = transformedRect(node, graph, 0, 0, node.width, node.height)+ const stroke = strokeOverflow(node.strokes)+ let bounds = transformedRect(+ node,+ graph,+ -stroke,+ -stroke,+ node.width + stroke * 2,+ node.height + stroke * 2+ )+ const localGeometry = geometryBlobBounds([...node.fillGeometry, ...node.strokeGeometry])+ if (localGeometry) {+ bounds =+ unionVisualBounds(+ bounds,+ transformedRect(+ node,+ graph,+ localGeometry.x,+ localGeometry.y,+ localGeometry.width,+ localGeometry.height+ )+ ) ?? bounds+ }++ for (const effect of node.effects) {+ if (!effect.visible) continue+ if (effect.type === 'DROP_SHADOW') {+ bounds =+ unionVisualBounds(+ bounds,+ translatedBounds(base, effect.offset, effect.radius * 3 + effect.spread)+ ) ?? bounds+ } else if (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR') {+ bounds = translatedBounds(bounds, { x: 0, y: 0 }, effect.radius + effect.spread)+ }+ }+ return bounds+}++function effectiveClip(node: SceneNode, graph: SceneGraph): VisualBounds | null | undefined {+ let clip: VisualBounds | null | undefined+ let current: SceneNode | undefined = node+ while (current) {+ if (!current.visible || current.opacity <= 0) return null+ if (+ current.id !== node.id &&+ current.clipsContent &&+ (current.type === 'FRAME' || current.type === 'COMPONENT' || current.type === 'INSTANCE')+ ) {+ const currentClip = transformedRect(current, graph, 0, 0, current.width, current.height)+ clip = clip ? intersectVisualBounds(clip, currentClip) : currentClip+ if (!clip) return null+ }+ current = current.parentId ? graph.getNode(current.parentId) : undefined+ }+ return clip+}++function groupRenderBounds(node: SceneNode, graph: SceneGraph): VisualBounds | null {+ let bounds: VisualBounds | null = null+ for (const childId of node.childIds) {+ const child = graph.getNode(childId)+ if (!child) continue+ const childBounds = computeAbsoluteRenderBounds(graph, child)+ if (!childBounds) continue+ bounds = unionVisualBounds(bounds, {+ minX: childBounds.x,+ minY: childBounds.y,+ maxX: childBounds.x + childBounds.width,+ maxY: childBounds.y + childBounds.height+ })+ }+ return bounds+}++/** Return Figma-compatible rendered bounds, or null when the node paints no visible pixels. */+export function computeAbsoluteRenderBounds(graph: SceneGraph, node: SceneNode): Rect | null {+ const clip = effectiveClip(node, graph)+ if (clip === null) return null++ const visual =+ node.type === 'GROUP' ? groupRenderBounds(node, graph) : ownRenderBounds(node, graph)+ const clipped = visual && clip ? intersectVisualBounds(visual, clip) : visual+ if (!clipped || clipped.maxX <= clipped.minX || clipped.maxY <= clipped.minY) return null+ return {+ x: clipped.minX,+ y: clipped.minY,+ width: clipped.maxX - clipped.minX,+ height: clipped.maxY - clipped.minY+ }+}diff --git a/packages/core/src/figma-api/rescale.ts b/packages/core/src/figma-api/rescale.tsnew file mode 100644index 000000000..b570c1573--- /dev/null+++ b/packages/core/src/figma-api/rescale.ts@@ -0,0 +1,188 @@+import {+ cloneVectorNetwork,+ scaleGeometryPaths,+ type Effect,+ type Fill,+ type GridTrack,+ type LayoutGrid,+ type SceneGraph,+ type SceneNode,+ type Stroke,+ type StyleRun+} from '@open-pencil/scene-graph'++const MIN_SCALE = 0.01+const RESCALABLE_NODE_TYPES = new Set<SceneNode['type']>([+ 'BOOLEAN_OPERATION',+ 'COMPONENT',+ 'COMPONENT_SET',+ 'ELLIPSE',+ 'FRAME',+ 'GROUP',+ 'INSTANCE',+ 'LINE',+ 'POLYGON',+ 'RECTANGLE',+ 'SLICE',+ 'STAR',+ 'TEXT',+ 'VECTOR'+])++function scaledOptional(value: number | null, scale: number): number | null {+ return value == null ? null : value * scale+}++function scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {+ return strokes.map((stroke) => ({+ ...structuredClone(stroke),+ weight: stroke.weight * scale,+ dashPattern: stroke.dashPattern?.map((value) => value * scale)+ }))+}++function scaledEffects(effects: readonly Effect[], scale: number): Effect[] {+ return effects.map((effect) => ({+ ...structuredClone(effect),+ offset: { x: effect.offset.x * scale, y: effect.offset.y * scale },+ radius: effect.radius * scale,+ spread: effect.spread * scale+ }))+}++function scaledFills(fills: readonly Fill[], scale: number): Fill[] {+ return fills.map((fill) => ({+ ...structuredClone(fill),+ scale: fill.scale == null ? undefined : fill.scale * scale,+ spacing: fill.spacing == null ? undefined : fill.spacing * scale,+ patternSpacing: fill.patternSpacing+ ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }+ : undefined,+ noiseSize: fill.noiseSize+ ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }+ : undefined+ }))+}++function scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {+ return styleRuns.map((run) => ({+ ...structuredClone(run),+ style: {+ ...structuredClone(run.style),+ fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,+ letterSpacing: run.style.letterSpacing == null ? undefined : run.style.letterSpacing * scale,+ lineHeight: scaledOptional(run.style.lineHeight ?? null, scale),+ textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),+ textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)+ }+ }))+}++function scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {+ return grids.map((grid) => ({+ ...structuredClone(grid),+ offset: grid.offset == null ? undefined : grid.offset * scale,+ sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,+ gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale+ }))+}++function scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {+ return tracks.map((track) => ({+ ...track,+ value: track.sizing === 'FIXED' ? track.value * scale : track.value+ }))+}++function scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {+ if (!node.vectorNetwork) return null+ const network = cloneVectorNetwork(node.vectorNetwork)+ for (const vertex of network.vertices) {+ vertex.x *= scale+ vertex.y *= scale+ }+ for (const segment of network.segments) {+ segment.tangentStart.x *= scale+ segment.tangentStart.y *= scale+ segment.tangentEnd.x *= scale+ segment.tangentEnd.y *= scale+ }+ return network+}++function scaleNodeChanges(+ node: SceneNode,+ scale: number,+ scalePosition: boolean+): Partial<SceneNode> {+ return {+ x: scalePosition ? node.x * scale : node.x,+ y: scalePosition ? node.y * scale : node.y,+ width: node.width * scale,+ height: node.height * scale,+ minWidth: scaledOptional(node.minWidth, scale),+ maxWidth: scaledOptional(node.maxWidth, scale),+ minHeight: scaledOptional(node.minHeight, scale),+ maxHeight: scaledOptional(node.maxHeight, scale),+ cornerRadius: node.cornerRadius * scale,+ topLeftRadius: node.topLeftRadius * scale,+ topRightRadius: node.topRightRadius * scale,+ bottomRightRadius: node.bottomRightRadius * scale,+ bottomLeftRadius: node.bottomLeftRadius * scale,+ fontSize: node.fontSize * scale,+ letterSpacing: node.letterSpacing * scale,+ lineHeight: scaledOptional(node.lineHeight, scale),+ textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),+ textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),+ styleRuns: scaledStyleRuns(node.styleRuns, scale),+ itemSpacing: node.itemSpacing * scale,+ counterAxisSpacing: node.counterAxisSpacing * scale,+ paddingTop: node.paddingTop * scale,+ paddingRight: node.paddingRight * scale,+ paddingBottom: node.paddingBottom * scale,+ paddingLeft: node.paddingLeft * scale,+ gridColumnGap: node.gridColumnGap * scale,+ gridRowGap: node.gridRowGap * scale,+ gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),+ gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),+ strokes: scaledStrokes(node.strokes, scale),+ dashPattern: node.dashPattern.map((value) => value * scale),+ borderTopWeight: node.borderTopWeight * scale,+ borderRightWeight: node.borderRightWeight * scale,+ borderBottomWeight: node.borderBottomWeight * scale,+ borderLeftWeight: node.borderLeftWeight * scale,+ strokeMiterLimit: node.strokeMiterLimit,+ effects: scaledEffects(node.effects, scale),+ fills: scaledFills(node.fills, scale),+ layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),+ vectorNetwork: scaledVectorNetwork(node, scale),+ fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),+ strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)+ }+}++/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */+export function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void {+ if (!Number.isFinite(scale)) throw new TypeError('Scale must be a finite number')+ if (scale < MIN_SCALE) throw new RangeError(`Scale must be at least ${MIN_SCALE}`)++ const root = graph.getNode(rootId)+ if (!root || !RESCALABLE_NODE_TYPES.has(root.type)) {+ throw new Error('rescale() is not supported on this node')+ }++ const nodes: SceneNode[] = [root]+ const collect = (node: SceneNode): void => {+ for (const childId of node.childIds) {+ const child = graph.getNode(childId)+ if (!child) continue+ nodes.push(child)+ collect(child)+ }+ }+ collect(root)++ for (const node of nodes) {+ graph.updateNode(node.id, scaleNodeChanges(node, scale, node.id !== rootId))+ }+}diff --git a/tests/engine/figma/api/layout/plugin-compat.test.ts b/tests/engine/figma/api/layout/plugin-compat.test.tsnew file mode 100644index 000000000..9b76b8562--- /dev/null+++ b/tests/engine/figma/api/layout/plugin-compat.test.ts@@ -0,0 +1,176 @@+import { describe, expect, test } from 'bun:test'++import { FigmaAPI } from '@open-pencil/core/figma-api'+import { SceneGraph } from '@open-pencil/scene-graph'++function setup() {+ const graph = new SceneGraph()+ return { graph, api: new FigmaAPI(graph) }+}++describe('Figma Plugin API layout compatibility', () => {+ test('rescale scales geometry, visual properties, and descendants from the root top-left', () => {+ const { api, graph } = setup()+ const frame = api.createFrame()+ frame.x = 30+ frame.y = 40+ frame.resize(100, 80)+ frame.paddingLeft = 10+ frame.paddingRight = 12+ frame.paddingTop = 6+ frame.paddingBottom = 8+ frame.itemSpacing = 5+ frame.cornerRadius = 7+ frame.strokes = [+ {+ color: { r: 0, g: 0, b: 0, a: 1 },+ weight: 3,+ opacity: 1,+ visible: true,+ align: 'CENTER'+ }+ ]+ frame.effects = [+ {+ type: 'DROP_SHADOW',+ color: { r: 0, g: 0, b: 0, a: 1 },+ offset: { x: 5, y: -3 },+ radius: 2,+ spread: 1,+ visible: true,+ blendMode: 'NORMAL'+ }+ ]++ const text = api.createText()+ text.characters = 'Hi'+ text.fontSize = 10+ text.letterSpacing = 2+ text.lineHeight = 14+ frame.appendChild(text)+ text.x = 11+ text.y = 13++ frame.rescale(2)++ expect(frame.x).toBe(30)+ expect(frame.y).toBe(40)+ expect(frame.width).toBe(200)+ expect(frame.height).toBe(160)+ expect(frame.paddingLeft).toBe(20)+ expect(frame.paddingRight).toBe(24)+ expect(frame.paddingTop).toBe(12)+ expect(frame.paddingBottom).toBe(16)+ expect(frame.itemSpacing).toBe(10)+ expect(frame.cornerRadius).toBe(14)+ expect(frame.strokeWeight).toBe(6)+ expect(frame.effects[0]?.offset).toEqual({ x: 10, y: -6 })+ expect(frame.effects[0]?.radius).toBe(4)+ expect(frame.effects[0]?.spread).toBe(2)+ expect(text.x).toBe(22)+ expect(text.y).toBe(26)+ expect(text.fontSize).toBe(20)+ expect(text.letterSpacing).toBe(4)+ expect(text.lineHeight).toBe(28)+ expect(graph.getNode(text.id)?.width).toBe(200)+ })++ test('rescale rejects non-Figma scale factors and pages', () => {+ const { api } = setup()+ const rect = api.createRectangle()+ expect(() => rect.rescale(0.009)).toThrow('Scale must be at least 0.01')+ expect(() => rect.rescale(Number.POSITIVE_INFINITY)).toThrow('Scale must be a finite number')+ expect(() => api.currentPage.rescale(2)).toThrow('rescale() is not supported on this node')+ const section = api.createSection()+ expect(() => section.rescale(2)).toThrow('rescale() is not supported on this node')+ })++ test('page backgrounds expose imported canvas paints and support assignment', () => {+ const { api, graph } = setup()+ const page = graph.getNode(api.currentPage.id)+ expect(page).toBeDefined()+ if (!page) return+ page.source.fig.rawNodeFields.backgroundPaints = [+ {+ type: 'SOLID',+ color: { r: 0.5, g: 0.75, b: 1, a: 1 },+ opacity: 1,+ visible: true,+ blendMode: 'NORMAL'+ }+ ]++ expect(api.currentPage.backgrounds).toEqual([+ {+ type: 'SOLID',+ color: { r: 0.5, g: 0.75, b: 1, a: 1 },+ opacity: 1,+ visible: true,+ blendMode: 'NORMAL'+ }+ ])++ api.currentPage.backgrounds = [+ {+ type: 'SOLID',+ color: { r: 1, g: 0, b: 0, a: 1 },+ opacity: 0.5,+ visible: true,+ blendMode: 'NORMAL'+ }+ ]+ expect(api.currentPage.backgrounds[0]?.color).toEqual({ r: 1, g: 0, b: 0, a: 1 })+ expect(page.source.fig.rawNodeFields.backgroundColor).toEqual({ r: 1, g: 0, b: 0, a: 1 })+ })++ test('absoluteRenderBounds includes strokes and effects and returns null for invisible pixels', () => {+ const { api } = setup()+ const rect = api.createRectangle()+ rect.x = 3+ rect.y = 4+ rect.resize(10, 20)+ rect.strokes = [+ {+ color: { r: 1, g: 0, b: 0, a: 1 },+ weight: 4,+ opacity: 1,+ visible: true,+ align: 'OUTSIDE'+ }+ ]+ rect.effects = [+ {+ type: 'DROP_SHADOW',+ color: { r: 0, g: 0, b: 0, a: 1 },+ offset: { x: 5, y: -3 },+ radius: 2,+ spread: 1,+ visible: true,+ blendMode: 'NORMAL'+ }+ ]++ expect(rect.absoluteBoundingBox).toEqual({ x: 3, y: 4, width: 10, height: 20 })+ expect(rect.absoluteRenderBounds).toEqual({ x: -1, y: -6, width: 26, height: 34 })++ rect.visible = false+ expect(rect.absoluteBoundingBox).toEqual({ x: 3, y: 4, width: 10, height: 20 })+ expect(rect.absoluteRenderBounds).toBeNull()++ const emptyVector = api.createVector()+ expect(emptyVector.absoluteRenderBounds).toBeNull()+ })++ test('absoluteRenderBounds is clipped by ancestor frames', () => {+ const { api } = setup()+ const frame = api.createFrame()+ frame.resize(100, 100)+ frame.clipsContent = true+ const rect = api.createRectangle()+ rect.x = 150+ rect.resize(20, 20)+ frame.appendChild(rect)++ expect(rect.absoluteRenderBounds).toBeNull()+ })+})