@pairdraw/scene-graph 0.19.2 → 0.20.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/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/variants.d.ts +12 -1
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +30 -1
- package/dist/components/variants.js.map +1 -1
- package/dist/constants.d.ts +25 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +94 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/text.d.ts +17 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +62 -1
- package/dist/css/text.js.map +1 -1
- package/dist/design-memory/index.d.ts +3 -0
- package/dist/design-memory/index.js +3 -0
- package/dist/design-memory/model.d.ts +33 -0
- package/dist/design-memory/model.d.ts.map +1 -0
- package/dist/design-memory/model.js +142 -0
- package/dist/design-memory/model.js.map +1 -0
- package/dist/design-memory/schema.d.ts +76 -0
- package/dist/design-memory/schema.d.ts.map +1 -0
- package/dist/design-memory/schema.js +72 -0
- package/dist/design-memory/schema.js.map +1 -0
- package/dist/effects.d.ts +7 -4
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +9 -4
- package/dist/effects.js.map +1 -1
- package/dist/empty-values.js +93 -0
- package/dist/empty-values.js.map +1 -0
- package/dist/fields/components.d.ts +9 -0
- package/dist/fields/components.d.ts.map +1 -0
- package/dist/fields/components.js +24 -0
- package/dist/fields/components.js.map +1 -0
- package/dist/fields/index.d.ts +3 -2
- package/dist/fields/index.js +3 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +10 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/graph.d.ts +8 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +28 -5
- package/dist/graph.js.map +1 -1
- package/dist/grid-values.d.ts +10 -0
- package/dist/grid-values.d.ts.map +1 -0
- package/dist/grid-values.js +53 -0
- package/dist/grid-values.js.map +1 -0
- package/dist/hit-test/drop.d.ts +20 -0
- package/dist/hit-test/drop.d.ts.map +1 -0
- package/dist/hit-test/drop.js +54 -0
- package/dist/hit-test/drop.js.map +1 -0
- package/dist/hit-test/geometry.js +86 -0
- package/dist/hit-test/geometry.js.map +1 -0
- package/dist/hit-test/masks.d.ts +14 -0
- package/dist/hit-test/masks.d.ts.map +1 -0
- package/dist/hit-test/masks.js +41 -0
- package/dist/hit-test/masks.js.map +1 -0
- package/dist/hit-test/paint.d.ts +6 -0
- package/dist/hit-test/paint.d.ts.map +1 -0
- package/dist/hit-test/paint.js +19 -0
- package/dist/hit-test/paint.js.map +1 -0
- package/dist/hit-test.d.ts +4 -15
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +5 -173
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +2 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +1 -1
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/source-walk.d.ts +12 -0
- package/dist/instances/source-walk.d.ts.map +1 -0
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +41 -36
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +75 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +18 -1
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/token-sources/document.d.ts +26 -0
- package/dist/token-sources/document.d.ts.map +1 -0
- package/dist/token-sources/document.js +80 -0
- package/dist/token-sources/document.js.map +1 -0
- package/dist/token-sources/index.d.ts +3 -0
- package/dist/token-sources/index.js +3 -0
- package/dist/token-sources/schema.d.ts +43 -0
- package/dist/token-sources/schema.d.ts.map +1 -0
- package/dist/token-sources/schema.js +50 -0
- package/dist/token-sources/schema.js.map +1 -0
- package/dist/types.d.ts +102 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variations/copy.d.ts +16 -0
- package/dist/variations/copy.d.ts.map +1 -0
- package/dist/variations/copy.js +78 -0
- package/dist/variations/copy.js.map +1 -0
- package/dist/variations/index.d.ts +6 -0
- package/dist/variations/index.js +6 -0
- package/dist/variations/match.d.ts +23 -0
- package/dist/variations/match.d.ts.map +1 -0
- package/dist/variations/match.js +80 -0
- package/dist/variations/match.js.map +1 -0
- package/dist/variations/model.d.ts +39 -0
- package/dist/variations/model.d.ts.map +1 -0
- package/dist/variations/model.js +90 -0
- package/dist/variations/model.js.map +1 -0
- package/dist/variations/pick.d.ts +43 -0
- package/dist/variations/pick.d.ts.map +1 -0
- package/dist/variations/pick.js +211 -0
- package/dist/variations/pick.js.map +1 -0
- package/dist/variations/schema.d.ts +27 -0
- package/dist/variations/schema.d.ts.map +1 -0
- package/dist/variations/schema.js +27 -0
- package/dist/variations/schema.js.map +1 -0
- package/package.json +21 -1
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +7 -1
- package/src/css/text.ts +62 -0
- package/src/design-memory/index.ts +2 -0
- package/src/design-memory/model.ts +143 -0
- package/src/design-memory/schema.ts +84 -0
- package/src/effects.ts +16 -7
- package/src/empty-values.ts +101 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/graph.ts +37 -5
- package/src/grid-values.ts +47 -0
- package/src/hit-test/drop.ts +90 -0
- package/src/hit-test/geometry.ts +131 -0
- package/src/hit-test/masks.ts +57 -0
- package/src/hit-test/paint.ts +24 -0
- package/src/hit-test.ts +8 -277
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +1 -0
- package/src/node-defaults.ts +49 -39
- package/src/plugin-data/fields.ts +18 -1
- package/src/preview.ts +2 -0
- package/src/scaling/node.ts +7 -2
- package/src/token-sources/document.ts +104 -0
- package/src/token-sources/index.ts +2 -0
- package/src/token-sources/schema.ts +59 -0
- package/src/types.ts +115 -13
- package/src/variations/copy.ts +89 -0
- package/src/variations/index.ts +5 -0
- package/src/variations/match.ts +100 -0
- package/src/variations/model.ts +132 -0
- package/src/variations/pick.ts +293 -0
- package/src/variations/schema.ts +29 -0
package/dist/hit-test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport { geometryBlobPolylines } from './geometry'\nimport type { SceneGraph } from './graph'\nimport { drawnChildIds } from './layout/draw-order'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n/**\n * How far from a zero-width or zero-height layer, in canvas units, a point still lands on it, so\n * a flat line or an empty box stays clickable; matches a connector line's slop (`connectors/hit.ts`).\n */\nconst DEGENERATE_AXIS_SLOP = 4\n\n/**\n * Whether a paint shows, so its container's empty area counts when a click reaches past\n * containers: a paint at 0% opacity, or a gradient whose stops are all transparent, does not,\n * while 1% does, and the layer's own opacity does not matter.\n */\nfunction isHitPaint(paint: SceneNode['fills'][number]): boolean {\n if (!paint.visible || !(paint.opacity > 0)) return false\n if (paint.type === 'SOLID') return paint.color.a > 0\n if (\n paint.type === 'GRADIENT_LINEAR' ||\n paint.type === 'GRADIENT_RADIAL' ||\n paint.type === 'GRADIENT_ANGULAR' ||\n paint.type === 'GRADIENT_DIAMOND'\n )\n return (paint.gradientStops ?? []).some((stop) => stop.color.a > 0)\n return true\n}\n\nfunction showsPaint(node: SceneNode): boolean {\n return node.fills.some(isHitPaint) || node.strokes.some(isHitPaint)\n}\n\n/**\n * Whether a container's empty area takes the click. Figma counts it only where a paint shows,\n * except a main component's, which always counts, and an instance's when the click is a plain one.\n */\nfunction takesEmptyArea(graph: SceneGraph, node: SceneNode, instanceBodies: boolean): boolean {\n if (node.type === 'COMPONENT' || showsPaint(node) || ownsItsEmptyArea(graph, node)) return true\n return instanceBodies && node.type === 'INSTANCE'\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/**\n * Where the point lies in the node's own coordinates: its offset from the position when nothing\n * above it is turned, else through the inverse world matrix. Null when that cannot be inverted.\n */\nfunction localPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): Vector | null {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return { x: px - absolute.x, y: py - absolute.y }\n }\n const inv = Matrix.invert(getWorldMatrix(node, graph))\n if (!inv) return null\n const [x, y] = Matrix.mapPoints(inv, [px, py])\n return { x, y }\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n const local = localPoint(px, py, node, graph, transformCache)\n if (!local) return false\n const padX = node.width > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n const padY = node.height > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n return (\n local.x >= -padX &&\n local.x <= node.width + padX &&\n local.y >= -padY &&\n local.y <= node.height + padY\n )\n}\n\n/** Whether a rounded rectangle of `width` × `height` holds the point. */\nfunction roundedRectContains(\n point: Vector,\n width: number,\n height: number,\n radius: number\n): boolean {\n if (point.x < 0 || point.y < 0 || point.x > width || point.y > height) return false\n const r = Math.max(0, Math.min(radius, width / 2, height / 2))\n const cx = Math.min(Math.max(point.x, r), width - r)\n const cy = Math.min(Math.max(point.y, r), height - r)\n return Math.hypot(point.x - cx, point.y - cy) <= r\n}\n\n/** Whether the point is inside a closed polyline, by the even-odd rule. */\nfunction insidePolyline(polyline: readonly Vector[], x: number, y: number): boolean {\n let inside = false\n for (let i = 0, j = polyline.length - 1; i < polyline.length; j = i++) {\n const a = polyline[i]\n const b = polyline[j]\n if (a.y > y === b.y > y) continue\n if (x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x) inside = !inside\n }\n return inside\n}\n\n/**\n * Whether a mask lets the point through, by the outline it draws: an ellipse's curve, a rounded\n * rectangle's corners, or a vector's filled path. Other shapes clip by their box.\n */\nfunction maskContainsPoint(\n px: number,\n py: number,\n mask: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n const outlined =\n (mask.type === 'ELLIPSE' && mask.width > 0 && mask.height > 0) ||\n (mask.type === 'RECTANGLE' && mask.cornerRadius > 0) ||\n (mask.type === 'VECTOR' && mask.fillGeometry.length > 0)\n if (!outlined) return containsPoint(px, py, mask, graph, transformCache)\n const local = localPoint(px, py, mask, graph, transformCache)\n if (!local) return false\n if (mask.type === 'ELLIPSE') {\n const rx = mask.width / 2\n const ry = mask.height / 2\n const dx = (local.x - rx) / rx\n const dy = (local.y - ry) / ry\n return dx * dx + dy * dy <= 1\n }\n if (mask.type === 'RECTANGLE') {\n return roundedRectContains(local, mask.width, mask.height, mask.cornerRadius)\n }\n return geometryBlobPolylines(mask.fillGeometry).some((points) =>\n insidePolyline(points, local.x, local.y)\n )\n}\n\nfunction isVisibleMask(node: SceneNode | undefined): node is SceneNode {\n return node !== undefined && node.visible && node.isMask\n}\n\n/**\n * The masks that clip each child, by index, as the renderer groups them (`core/canvas/masks.ts`):\n * a run of visible masks clips the layers after it up to the next visible mask. Empty when the\n * container has no visible mask.\n */\nfunction clippingMasks(graph: SceneGraph, childIds: readonly string[]): SceneNode[][] {\n const children = childIds.map((childId) => graph.nodes.get(childId))\n if (!children.some(isVisibleMask)) return []\n const result: SceneNode[][] = []\n let run: SceneNode[] = []\n let previousWasMask = false\n for (const child of children) {\n if (isVisibleMask(child)) {\n run = previousWasMask ? [...run, child] : [child]\n previousWasMask = true\n result.push([])\n continue\n }\n previousWasMask = false\n result.push(run)\n }\n return result\n}\n\n/**\n * What a click inside a container reports. `opaque` is an instance or component whose body takes\n * the click without looking through it; every other container looks through to its children first.\n */\nfunction hitTestContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number,\n locked = false,\n instanceBodies = false,\n opaque = false\n): SceneNode | null {\n if (opaque) {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(\n graph,\n px,\n py,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (childHit) return child\n if (takesEmptyArea(graph, child, instanceBodies)) return child\n return null\n }\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(\n graph,\n px,\n py,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (childHit) return standIn(child, childHit, deep)\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(\n graph,\n px,\n py,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (childHit) return standIn(child, childHit, true)\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n takesEmptyArea(graph, child, instanceBodies)\n )\n return child\n return null\n}\n/**\n * What a hit inside a container reports: the container itself when it is locked (a locked layer,\n * where one is hit at all, stands in for everything inside it) or the walk stops at containers.\n */\nfunction standIn(container: SceneNode, hit: SceneNode, deep: boolean): SceneNode {\n return container.locked || !deep ? container : hit\n}\n\n/** Whether the masks that clip a layer leave the point outside every one of their outlines. */\nfunction isMaskedOut(\n px: number,\n py: number,\n masks: readonly SceneNode[] | undefined,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n if (!masks) return false\n return (\n masks.length > 0 &&\n !masks.some((mask) => maskContainsPoint(px, py, mask, graph, transformCache))\n )\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\n/**\n * Whether a layer under the point can take the click. A locked layer and everything in it are\n * invisible to a press and to hover, as in Figma: a click falls through to what lies under it, and\n * a drag from it draws a marquee.\n */\nfunction takesClick(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode | undefined,\n mask: readonly SceneNode[] | undefined,\n locked: boolean,\n transformCache: Map<string, boolean>\n): child is SceneNode {\n if (!child || child.internalOnly || !child.visible || (child.locked && !locked)) return false\n return !isMaskedOut(px, py, mask, graph, transformCache)\n}\n\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0,\n locked = false,\n instanceBodies = false\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n // Front to back, as the layers are drawn: a reversed auto layout puts the first child on top.\n const drawn = drawnChildIds(parent)\n const masks = clippingMasks(graph, drawn)\n for (let i = drawn.length - 1; i >= 0; i--) {\n const childId = drawn[i]\n const child = graph.nodes.get(childId)\n if (!takesClick(graph, px, py, child, masks[i], locked, transformCache)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies,\n true\n )\n if (hit) return hit\n continue\n }\n\n const hit = hitTestContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false, new Map(), 0, false, true)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number,\n locked = false\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n if (child.locked && !locked) continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0,\n /** Whether locked layers are hit, as a right-click hits them; see `hitTestAtPoint`. */\n locked = false\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad, locked, true)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py, locked) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer, hit only with `locked`, stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py, locked)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), 0, false, false)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return showsPaint(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (\n parent.type !== 'CANVAS' &&\n parent.clipsContent &&\n !containsPoint(px, py, parent, graph, transformCache)\n )\n return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;;;AASA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;;;;;AAK1E,MAAM,uBAAuB;;;;;;AAO7B,SAAS,WAAW,OAA4C;CAC9D,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,UAAU,IAAI,OAAO;CACnD,IAAI,MAAM,SAAS,SAAS,OAAO,MAAM,MAAM,IAAI;CACnD,IACE,MAAM,SAAS,qBACf,MAAM,SAAS,qBACf,MAAM,SAAS,sBACf,M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,OAAO,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport { containsPoint } from './hit-test/geometry'\nimport { clippingMasks, isMaskedOut } from './hit-test/masks'\nimport { showsPaint } from './hit-test/paint'\nimport { drawnChildIds } from './layout/draw-order'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nexport { clippingMasks, isPointMaskedOut } from './hit-test/masks'\nexport { hitTestDropTarget, type DropTargetOptions } from './hit-test/drop'\nexport { showsPaint } from './hit-test/paint'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n/**\n * Whether a container's empty area takes the click. Figma counts it only where a paint shows,\n * except a main component's, which always counts, and an instance's when the click is a plain one.\n */\nfunction takesEmptyArea(graph: SceneGraph, node: SceneNode, instanceBodies: boolean): boolean {\n if (node.type === 'COMPONENT' || showsPaint(node) || ownsItsEmptyArea(graph, node)) return true\n return instanceBodies && node.type === 'INSTANCE'\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\n/**\n * What a click inside a container reports. `opaque` is an instance or component whose body takes\n * the click without looking through it; every other container looks through to its children first.\n */\nfunction hitTestContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number,\n locked = false,\n instanceBodies = false,\n opaque = false\n): SceneNode | null {\n if (opaque) {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(\n graph,\n px,\n py,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (childHit) return child\n if (takesEmptyArea(graph, child, instanceBodies)) return child\n return null\n }\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(\n graph,\n px,\n py,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (childHit) return standIn(child, childHit, deep)\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(\n graph,\n px,\n py,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (childHit) return standIn(child, childHit, true)\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n takesEmptyArea(graph, child, instanceBodies)\n )\n return child\n return null\n}\n/**\n * What a hit inside a container reports: the container itself when it is locked (a locked layer,\n * where one is hit at all, stands in for everything inside it) or the walk stops at containers.\n */\nfunction standIn(container: SceneNode, hit: SceneNode, deep: boolean): SceneNode {\n return container.locked || !deep ? container : hit\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\n/**\n * Whether a layer under the point can take the click. A locked layer and everything in it are\n * invisible to a press and to hover, as in Figma: a click falls through to what lies under it, and\n * a drag from it draws a marquee.\n */\nfunction takesClick(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode | undefined,\n mask: readonly SceneNode[] | undefined,\n locked: boolean,\n transformCache: Map<string, boolean>\n): child is SceneNode {\n if (!child || child.internalOnly || !child.visible || (child.locked && !locked)) return false\n return !isMaskedOut(px, py, mask, graph, transformCache)\n}\n\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0,\n locked = false,\n instanceBodies = false\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n // Front to back, as the layers are drawn: a reversed auto layout puts the first child on top.\n const drawn = drawnChildIds(parent)\n const masks = clippingMasks(graph, drawn)\n for (let i = drawn.length - 1; i >= 0; i--) {\n const childId = drawn[i]\n const child = graph.nodes.get(childId)\n if (!takesClick(graph, px, py, child, masks[i], locked, transformCache)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies,\n true\n )\n if (hit) return hit\n continue\n }\n\n const hit = hitTestContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad,\n locked,\n instanceBodies\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false, new Map(), 0, false, true)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number,\n locked = false\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n if (child.locked && !locked) continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0,\n /** Whether locked layers are hit, as a right-click hits them; see `hitTestAtPoint`. */\n locked = false\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad, locked, true)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py, locked) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer, hit only with `locked`, stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py, locked)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), 0, false, false)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return showsPaint(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n"],"mappings":";;;;;;;;;AAeA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;;;;;AAK1E,SAAS,eAAe,OAAmB,MAAiB,gBAAkC;CAC5F,IAAI,KAAK,SAAS,eAAe,WAAW,IAAI,KAAK,iBAAiB,OAAO,IAAI,GAAG,OAAO;CAC3F,OAAO,kBAAkB,KAAK,SAAS;AACzC;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/D,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAChE,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS;AACvD;;;;;;;AAQA,SAAS,iBAAiB,OAAmB,MAA0B;CACrE,OAAO,KAAK,SAAS,WAAW,KAAK,eAAe,UAAU,WAAW,OAAO,IAAI;AACtF;;;;;AAMA,SAAS,iBACP,OACA,IAC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,MAAM,UAAU,WAAW,MAAM,uBAAuB,OAAO,KAAK,CAAC;EACrE,IAAI,CAAC,gBAAgB,IAAI,MAAM,IAAI,KAAK,MAAM,SAAS,WAAW,GAAG;GACnE,IAAI,SAAS,KAAK,KAAK,KAAK;GAC5B;EACF;EACA,MAAM,SAAS,KAAK;EACpB,qBAAqB,OAAO,OAAO,OAAO,MAAM,IAAI;EACpD,IAAI,KAAK,WAAW,UAAU,WAAW,iBAAiB,OAAO,KAAK,GAAG,KAAK,KAAK,KAAK;CAC1F;AACF;;;;;;;;AASA,SAAgB,kBAAkB,OAAmB,MAAY,SAA8B;CAC7F,MAAM,QAAQ,MAAM,MAAM,IAAI,OAAO;CACrC,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,MAAM,OAAoB,CAAC;CAC3B,qBAAqB,OAAO,OAAO,eAAe,OAAO,KAAK,GAAG,MAAM,IAAI;CAC3E,OAAO;AACT;;AAGA,SAAgB,cAAc,OAAmB,QAAgB,IAAY,IAAqB;CAChG,MAAM,OAAO,MAAM,MAAM,IAAI,MAAM;CACnC,OAAO,SAAS,KAAA,KAAa,cAAc,IAAI,IAAI,MAAM,uBAAO,IAAI,IAAI,CAAC;AAC3E"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
2
|
import { SceneGraph } from "./graph.js";
|
|
3
|
-
import { ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
3
|
+
import { ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, DrawIOEdgeSource, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseEffect, NoiseEffectParams, NoiseType, NumericNodeProperty, OverflowDirection, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeEasingType, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ScrollBehavior, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffect, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
4
|
import { generateId, setIdSession } from "./ids.js";
|
|
5
|
-
export { ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
5
|
+
export { ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, DrawIOEdgeSource, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseEffect, NoiseEffectParams, NoiseType, NumericNodeProperty, OverflowDirection, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeEasingType, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ScrollBehavior, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffect, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;cA4BA;;cAsBA,4BAA4B;;
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;cA4BA;;cAsBA,4BAA4B;;cA6B5B,8CAAwB;;cAQxB,0CAAoB"}
|
package/dist/instances/fields.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/instances/fields.ts"],"sourcesContent":["import { difference } from 'es-toolkit/array'\n\nimport { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from '../fields/appearance'\nimport { SIZE_FIELDS, TRANSFORM_FIELDS } from '../fields/geometry'\nimport { AUTO_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from '../fields/layout'\nimport { TEXT_STYLE_FIELDS } from '../fields/text'\nimport { STYLE_LINK_FIELDS } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\nexport const INSTANCE_SYNC_TEXT_PROPS = [\n 'name',\n 'text',\n ...TEXT_STYLE_FIELDS,\n 'textDirection',\n 'textAutoResize',\n 'textTruncation',\n 'maxLines',\n 'leadingTrim',\n 'listSpacing',\n 'hangingList',\n // Styled ranges belong to the characters: an instance that overrides its text keeps them.\n 'styleRuns',\n 'textParagraphs'\n] as const\n\n/** Fields that belong to another one: overriding the owner keeps them too. */\nexport const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>> = {\n fillStyleId: 'fills',\n styleRuns: 'text',\n textParagraphs: 'text'\n}\n\n/**\n * Where a component's layer sits and how it is shaped, which Figma refuses to override in an\n * instance (\"This property cannot be overridden in an instance\"), so its copies always follow.\n * A layer in an auto layout flow takes its position from the layout instead.\n */\nexport const INSTANCE_FOLLOWED_FIELDS = [\n ...TRANSFORM_FIELDS,\n // A size limit has no field of its own in the file, so an instance cannot keep one of its own.\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'horizontalConstraint',\n 'verticalConstraint',\n 'layoutPositioning',\n 'counterAxisAlignContent',\n 'isMask',\n 'maskType',\n 'arcData',\n 'pointCount',\n 'starInnerRadius',\n 'shapeWithTextType',\n 'shapeUserHeight',\n 'shapeTruncates'\n] as const\n\n/** Fields a component's layer gives its copies unless an instance overrides them. */\nexport const INSTANCE_SYNC_PROPS: (keyof SceneNode)[] = difference(\n [\n ...SIZE_FIELDS,\n ...SIZE_CONSTRAINT_FIELDS,\n ...PAINT_FIELDS,\n ...STROKE_FIELDS,\n ...CORNER_FIELDS,\n ...AUTO_LAYOUT_FIELDS,\n // An instance frame and its component share one alignment in the file, so the instance\n // follows the component's instead of keeping its own.\n 'layoutAlignSelf',\n 'itemReverseZIndex',\n 'gridPosition',\n 'clipsContent',\n 'layoutGrids',\n 'boundVariables',\n 'variableModes',\n // Applied shared styles follow the component unless an instance overrides them.\n ...STYLE_LINK_FIELDS\n ],\n INSTANCE_FOLLOWED_FIELDS\n)\n\n/** How a layer inside an instance sits in its parent and whether it is locked, which its overrides may change. */\nconst INSTANCE_SYNC_CHILD_PROPS = ['layoutGrow', 'layoutAlignSelf', 'locked'] as const\n\n/** Fields an edit to a layer inside an instance records as that instance's override. */\nexport const INSTANCE_OVERRIDE_FIELDS = [\n ...INSTANCE_SYNC_PROPS,\n ...INSTANCE_SYNC_TEXT_PROPS,\n ...INSTANCE_SYNC_CHILD_PROPS,\n 'visible'\n] as const\n\n/** Fields a component's layer gives the copies of it in every instance. */\nexport const INSTANCE_SYNC_FIELDS = [\n ...INSTANCE_OVERRIDE_FIELDS,\n ...INSTANCE_FOLLOWED_FIELDS\n] as const\n\n/**\n * Fields an instance frame takes from its component frame, where the file keeps one value for\n * both: a layer inside an instance has no field of its own for them.\n */\nexport const INSTANCE_FRAME_FOLLOWED_FIELDS: (keyof SceneNode)[] = [\n 'layoutPositioning',\n 'layoutGrow',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight'\n]\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;CACtC;CACA;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;AAGA,MAAa,6BAAwE;CACnF,aAAa;CACb,WAAW;CACX,gBAAgB;AAClB;;;;;;AAOA,MAAa,2BAA2B;CACtC,GAAG;CAEH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,sBAA2C,WACtD;CACE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CAGH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,GAAG;AACL,GACA,wBACF;;AAGA,MAAM,4BAA4B;CAAC;CAAc;CAAmB;AAAQ;;AAG5E,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;CACH;AACF;;AAGA,MAAa,uBAAuB,CAClC,GAAG,0BACH,GAAG,wBACL;;;;;AAMA,MAAa,iCAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"fields.js","names":[],"sources":["../../src/instances/fields.ts"],"sourcesContent":["import { difference } from 'es-toolkit/array'\n\nimport { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from '../fields/appearance'\nimport { SIZE_FIELDS, TRANSFORM_FIELDS } from '../fields/geometry'\nimport { AUTO_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from '../fields/layout'\nimport { TEXT_STYLE_FIELDS } from '../fields/text'\nimport { STYLE_LINK_FIELDS } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\nexport const INSTANCE_SYNC_TEXT_PROPS = [\n 'name',\n 'text',\n ...TEXT_STYLE_FIELDS,\n 'textDirection',\n 'textAutoResize',\n 'textTruncation',\n 'maxLines',\n 'leadingTrim',\n 'listSpacing',\n 'hangingList',\n // Styled ranges belong to the characters: an instance that overrides its text keeps them.\n 'styleRuns',\n 'textParagraphs'\n] as const\n\n/** Fields that belong to another one: overriding the owner keeps them too. */\nexport const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>> = {\n fillStyleId: 'fills',\n styleRuns: 'text',\n textParagraphs: 'text'\n}\n\n/**\n * Where a component's layer sits and how it is shaped, which Figma refuses to override in an\n * instance (\"This property cannot be overridden in an instance\"), so its copies always follow.\n * A layer in an auto layout flow takes its position from the layout instead.\n */\nexport const INSTANCE_FOLLOWED_FIELDS = [\n ...TRANSFORM_FIELDS,\n // A size limit has no field of its own in the file, so an instance cannot keep one of its own.\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'horizontalConstraint',\n 'verticalConstraint',\n 'layoutPositioning',\n 'counterAxisAlignContent',\n 'isMask',\n 'maskType',\n 'arcData',\n 'pointCount',\n 'starInnerRadius',\n 'shapeWithTextType',\n 'shapeUserHeight',\n 'shapeTruncates'\n] as const\n\n/** Fields a component's layer gives its copies unless an instance overrides them. */\nexport const INSTANCE_SYNC_PROPS: (keyof SceneNode)[] = difference(\n [\n ...SIZE_FIELDS,\n ...SIZE_CONSTRAINT_FIELDS,\n ...PAINT_FIELDS,\n ...STROKE_FIELDS,\n ...CORNER_FIELDS,\n ...AUTO_LAYOUT_FIELDS,\n // An instance frame and its component share one alignment in the file, so the instance\n // follows the component's instead of keeping its own.\n 'layoutAlignSelf',\n 'itemReverseZIndex',\n 'gridPosition',\n 'clipsContent',\n 'overflowDirection',\n 'scrollBehavior',\n 'layoutGrids',\n 'boundVariables',\n 'variableModes',\n // Applied shared styles follow the component unless an instance overrides them.\n ...STYLE_LINK_FIELDS\n ],\n INSTANCE_FOLLOWED_FIELDS\n)\n\n/** How a layer inside an instance sits in its parent and whether it is locked, which its overrides may change. */\nconst INSTANCE_SYNC_CHILD_PROPS = ['layoutGrow', 'layoutAlignSelf', 'locked'] as const\n\n/** Fields an edit to a layer inside an instance records as that instance's override. */\nexport const INSTANCE_OVERRIDE_FIELDS = [\n ...INSTANCE_SYNC_PROPS,\n ...INSTANCE_SYNC_TEXT_PROPS,\n ...INSTANCE_SYNC_CHILD_PROPS,\n 'visible'\n] as const\n\n/** Fields a component's layer gives the copies of it in every instance. */\nexport const INSTANCE_SYNC_FIELDS = [\n ...INSTANCE_OVERRIDE_FIELDS,\n ...INSTANCE_FOLLOWED_FIELDS\n] as const\n\n/**\n * Fields an instance frame takes from its component frame, where the file keeps one value for\n * both: a layer inside an instance has no field of its own for them.\n */\nexport const INSTANCE_FRAME_FOLLOWED_FIELDS: (keyof SceneNode)[] = [\n 'layoutPositioning',\n 'layoutGrow',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight'\n]\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;CACtC;CACA;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;AAGA,MAAa,6BAAwE;CACnF,aAAa;CACb,WAAW;CACX,gBAAgB;AAClB;;;;;;AAOA,MAAa,2BAA2B;CACtC,GAAG;CAEH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,sBAA2C,WACtD;CACE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CAGH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,GAAG;AACL,GACA,wBACF;;AAGA,MAAM,4BAA4B;CAAC;CAAc;CAAmB;AAAQ;;AAG5E,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;CACH;AACF;;AAGA,MAAa,uBAAuB,CAClC,GAAG,0BACH,GAAG,wBACL;;;;;AAMA,MAAa,iCAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NodeCloneMode } from "../copy.js";
|
|
2
2
|
import { InstanceOverrideState } from "./overrides.js";
|
|
3
3
|
import { canCreateInstance, createsComponentCycle, cycleSafeParent } from "./cycles.js";
|
|
4
|
+
import { walkInstanceSources } from "./source-walk.js";
|
|
4
5
|
import { instanceMainComponent } from "./main-component.js";
|
|
5
6
|
import { isInShownReplacedLayer, isReplacedLayer, owningInstance, replacedComponentLayerId, showsReplacedLayer } from "./replacements.js";
|
|
6
7
|
import { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS } from "./fields.js";
|
|
@@ -95,5 +96,5 @@ declare function replaceInstanceLayer(graph: SceneGraph, targetId: string, repla
|
|
|
95
96
|
*/
|
|
96
97
|
declare function restoreReplacedLayer(graph: SceneGraph, nodeId: string): boolean;
|
|
97
98
|
//#endregion
|
|
98
|
-
export { AssignmentOverrideState, INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, SwapInstanceOptions, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize };
|
|
99
|
+
export { AssignmentOverrideState, INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, SwapInstanceOptions, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize, walkInstanceSources };
|
|
99
100
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;;;;iBAiEgB,2BAA2B,WAAW,YAAY,QAAQ;iBAiB1D,eACd,OAAO,YACP,qBACA,kBACA,YAAW,QAAQ,aAClB;iBAoBa,yBACd,OAAO,YACP,oBACA,qBACA,OAAM;UAmCS;;;;;;EAMf;;;;;;;EAOA;;iBAGc,sBACd,OAAO,YACP,oBACA,uBACE,UAAkB,qBAA2B;iBA+DjC,cAAc,OAAO,YAAY;;;;;iBAQjC,sBAAsB,OAAO,YAAY,cAAc;;iBAOvD,aAAa,OAAO,YAAY;;;;;;iBAwEhC,wBACd,OAAO,YACP,QAAQ;iBAeM,eAAe,OAAO,YAAY;iBAmElC,iBAAiB,OAAO,YAAY,qBAAqB;iBAMzD,aAAa,OAAO,YAAY,sBAAsB;;iBAYtD,qBAAqB,OAAO,YAAY,iBAAiB;;;;;iBAazD,aAAa,OAAO,YAAY,MAAM;;;;iBAOtC,oBAAoB,OAAO,YAAY,gBAAgB;;;;;iBA2CvD,wBACd,OAAO,YACP,qBACC;;UAMc;EACf;EACA,WAAW;;iBAGG,4BACd,OAAO,YACP,qBACC;iBAOa,+BACd,OAAO,YACP,OAAO;;;;;;iBAYO,yBACd,OAAO,YACP,oBACA,oBACA;;;;;iBAkBc,uBAAuB,MAAM,WAAW,SAAS,QAAQ;iBAMzD,uBACd,OAAO,YACP,gBACA,QAAQ;;iBAsDM,wBAAwB,OAAO,YAAY;;;;;;;;;iBAqB3C,qBACd,OAAO,YACP,kBACA;;;;;iBAmDc,qBAAqB,OAAO,YAAY"}
|
package/dist/instances/index.js
CHANGED
|
@@ -422,6 +422,6 @@ function restoreReplacedLayer(graph, nodeId) {
|
|
|
422
422
|
return true;
|
|
423
423
|
}
|
|
424
424
|
//#endregion
|
|
425
|
-
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize };
|
|
425
|
+
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize, walkInstanceSources };
|
|
426
426
|
|
|
427
427
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/index.ts"],"sourcesContent":["import type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { shapeGeometryChanges } from '../resize'\nimport { slotScope } from '../slots/content'\nimport { detachOwnedSlotContent, restoreOwnedSlotContent } from '../slots/frames'\nimport { changesMoreThanStrokeLines } from '../strokes'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn, keepCopyBoundPaints } from '../variables/paints'\nimport { keepOwnContentSize } from './content-size'\nimport { createInstanceSyncContext, groupCopyRemovals, removeLeftoverCopies } from './copies'\nimport { canCreateInstance, createsComponentCycle } from './cycles'\nimport {\n INSTANCE_FRAME_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_PROPS\n} from './fields'\nimport { differingVariableModeCollections } from './modes'\nimport {\n assignmentOverrideField,\n cloneInstanceOverrideState,\n copiedComponentLayerId,\n createInstanceOverrideState,\n getInstanceOverride,\n hasInstanceOverride as hasNodeInstanceOverride,\n type InstanceOverrideState,\n overriddenAssignmentId,\n REPLACED_LAYER_OVERRIDE,\n setInstanceOverride,\n variableModeOverrideField\n} from './overrides'\nimport { owningInstance, replacedLayerIn } from './replacements'\nimport { walkInstanceSources } from './source-walk'\nimport { captureInstanceOverrides, restoreInstanceOverrides } from './swap-overrides'\nimport {\n applySyncedStrokeLines,\n bindingProtection,\n cloneChildrenWithMapping,\n copyProp,\n enclosingInstanceOverrideFields,\n isProtectedSyncField,\n sourceInTargetCoordinates,\n syncBindingFields,\n syncChildren,\n syncVariableModeFields,\n updateSyncedProps\n} from './sync'\n\nexport { canCreateInstance, createsComponentCycle, cycleSafeParent } from './cycles'\nexport { instanceMainComponent } from './main-component'\nexport {\n isInShownReplacedLayer,\n isReplacedLayer,\n owningInstance,\n replacedComponentLayerId,\n showsReplacedLayer\n} from './replacements'\nexport {\n INSTANCE_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_FIELDS,\n INSTANCE_SYNC_PROPS,\n INSTANCE_SYNC_TEXT_PROPS\n} from './fields'\n\nexport function copyInstanceComponentProps(component: SceneNode): Partial<SceneNode> {\n const props: Partial<SceneNode> = {}\n // A new instance starts with the fields its component frame lends it, as resyncing one does.\n for (const key of [...INSTANCE_SYNC_PROPS, ...INSTANCE_FRAME_FOLLOWED_FIELDS])\n copyProp(props, component, key)\n return props\n}\n\n/**\n * The name Figma gives a new instance of `component`: its component set's name for a variant,\n * whose own name only says which variant it is, and the component's own name otherwise.\n */\nfunction instanceComponentName(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.nodes.get(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.name : component.name\n}\n\nexport function createInstance(\n graph: SceneGraph,\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n): SceneNode | null {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT' || !canCreateInstance(graph, componentId, parentId))\n return null\n\n const props: Partial<SceneNode> = {\n ...copyInstanceComponentProps(component),\n name: instanceComponentName(graph, component)\n }\n\n // The component checked above is the one the instance shows, whatever `overrides` holds.\n const instance = graph.createNode('INSTANCE', parentId, { ...props, ...overrides, componentId })\n\n cloneChildrenWithMapping(graph, component.id, instance.id)\n // A copy shows its bound paints in its own context, not as its component's paints hold them.\n applyBoundPaintColorsIn(graph, instance.id)\n\n return instance\n}\n\nexport function populateInstanceChildren(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || !component || instance.type !== 'INSTANCE') return\n cloneChildrenWithMapping(graph, componentId, instanceId, mode)\n}\n\n/**\n * A nested instance's link to the enclosing component's record is its `componentId` when it\n * was populated by cloning. A swap replaces that field, so keep the correspondence as the\n * owner's `sourceComponentId` override and record the swap itself; materialized documents\n * already carry the correspondence and only gain the swap.\n */\nfunction recordNestedSwap(graph: SceneGraph, instance: SceneNode, componentId: string): void {\n const owner = instance.parentId ? findInstanceAncestor(graph, instance.parentId) : undefined\n if (!owner) return\n const existing = getInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n 'sourceComponentId'\n )\n if (typeof existing !== 'string' && instance.componentId)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n 'sourceComponentId',\n instance.componentId\n )\n setInstanceOverride(owner.instanceOverrides, owner.id, instance.id, 'componentId', componentId)\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n}\n\nexport interface SwapInstanceOptions {\n /**\n * Keep the instance's name even when it is its old component's. A swap otherwise renames such\n * an instance after the new component, as Figma does; a view that only shows another variant,\n * such as preview, keeps names so layer paths stay the same.\n */\n keepName?: boolean\n /**\n * Keep the overrides the instance's layers record, matched to the layers of the new component\n * that take their places, as Figma keeps them when a variant changes. A swap that only\n * materializes a layer the caller re-applies itself, such as a pen icon's glyph, skips this:\n * what the placeholder recorded is scaffolding, not a user's edit.\n */\n restoreOverrides?: boolean\n}\n\nexport function swapInstanceComponent(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n { keepName = false, restoreOverrides = true }: SwapInstanceOptions = {}\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || component?.type !== 'COMPONENT' || instance.type !== 'INSTANCE') return\n if (instance.parentId && !canCreateInstance(graph, componentId, instance.parentId)) return\n\n const previousComponent = instance.componentId ? graph.nodes.get(instance.componentId) : undefined\n recordNestedSwap(graph, instance, componentId)\n const updates: Partial<SceneNode> = { componentId }\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const overridden = (field: string) =>\n hasNodeInstanceOverride(instance.instanceOverrides, instance.id, instance.id, field)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'variableModes' || overridden(key)) continue\n copyProp(updates, source, key)\n }\n syncVariableModeFields(instance, source, updates, overridden)\n applySyncedStrokeLines(graph, instance, updates, overridden)\n\n if (\n !keepName &&\n (!previousComponent || instance.name === instanceComponentName(graph, previousComponent))\n )\n updates.name = instanceComponentName(graph, component)\n\n keepCopyBoundPaints(graph, instance, updates)\n const childIds = Array.from(instance.childIds)\n const slotContent = detachOwnedSlotContent(graph, instance)\n swapInstanceLayers(graph, instanceId, componentId, updates, childIds, restoreOverrides)\n restoreOwnedSlotContent(graph, instance, slotContent)\n}\n\n/**\n * Replaces the instance's layers with clones of its new component's and gives the recorded\n * overrides back to the layers that take the old ones' places, matched by name path.\n */\nfunction swapInstanceLayers(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n updates: Partial<SceneNode>,\n childIds: string[],\n restoreOverrides: boolean\n): void {\n // The clones take new IDs, so what was recorded for the removed layers only applies again once\n // it is matched to the layers of the new component that take their places.\n const capturedOverrides = restoreOverrides\n ? captureInstanceOverrides(graph, graph.nodes.get(instanceId) as SceneNode)\n : undefined\n for (const childId of childIds) {\n forgetOverridesOf(graph, childId)\n graph.deleteNode(childId)\n }\n graph.updateNode(instanceId, updates)\n cloneChildrenWithMapping(graph, componentId, instanceId)\n applyBoundPaintColorsIn(graph, instanceId)\n const swapped = graph.nodes.get(instanceId)\n if (swapped && capturedOverrides) restoreInstanceOverrides(graph, swapped, capturedOverrides)\n}\n\nconst syncingComponentsByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nexport function syncInstances(graph: SceneGraph, componentId: string): void {\n syncInstancesOf(graph, componentId, getInstances(graph, componentId))\n}\n\n/**\n * Syncs each component's instances, in order, as one edit: the copies they remove stay\n * restorable together for as long as undo keeps that edit.\n */\nexport function syncInstancesTogether(graph: SceneGraph, componentIds: Iterable<string>): void {\n groupCopyRemovals(graph, () => {\n for (const id of componentIds) syncInstances(graph, id)\n })\n}\n\n/** Syncs one instance from its component, as `syncInstances` does for every instance. */\nexport function syncInstance(graph: SceneGraph, instanceId: string): void {\n const instance = graph.nodes.get(instanceId)\n if (instance?.type !== 'INSTANCE' || !instance.componentId) return\n syncInstancesOf(graph, instance.componentId, [instance])\n}\n\nfunction syncInstancesOf(\n graph: SceneGraph,\n componentId: string,\n instances: Iterable<SceneNode>\n): void {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT') return\n let syncing = syncingComponentsByGraph.get(graph)\n if (!syncing) {\n syncing = new Set()\n syncingComponentsByGraph.set(graph, syncing)\n }\n if (syncing.has(componentId)) return\n syncing.add(componentId)\n try {\n groupCopyRemovals(graph, (removals) => {\n for (const instance of instances) {\n const enclosing = enclosingInstanceOverrideFields(graph, instance)\n enclosing.push(new Set(instance.instanceOverrides.self.keys()))\n const protectedField = bindingProtection(enclosing)\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const updates: Partial<SceneNode> = {}\n syncBindingFields(instance, source, updates, protectedField)\n syncVariableModeFields(instance, source, updates, protectedField)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (isProtectedSyncField(instance, key, protectedField)) continue\n copyProp(updates, source, key)\n }\n // The file keeps one value for the instance frame and its component, so the frame takes\n // those the layers inside an instance may not set.\n for (const key of INSTANCE_FRAME_FOLLOWED_FIELDS) {\n if (!isProtectedSyncField(instance, key, protectedField)) copyProp(updates, source, key)\n }\n // An instance that hugs its layers sizes to what it shows, not to the component.\n keepOwnContentSize(graph, updates, instance, source)\n // A size that follows the component invalidates outlines the file saved on the instance;\n // its live box draws them again.\n if (updates.width !== undefined || updates.height !== undefined) {\n Object.assign(\n updates,\n shapeGeometryChanges(\n instance,\n updates.width ?? instance.width,\n updates.height ?? instance.height\n )\n )\n }\n updateSyncedProps(graph, instance, updates, (key) =>\n isProtectedSyncField(instance, key, protectedField)\n )\n const context = createInstanceSyncContext(instance.id, instance.instanceOverrides)\n syncChildren(graph, component.id, instance.id, instance.instanceOverrides, context)\n removeLeftoverCopies(graph, context, removals)\n }\n })\n } finally {\n syncing.delete(componentId)\n }\n}\n\n/**\n * Renames the layers that the copied instances among `copies` record overrides for to their\n * copies, as a copied instance records its own layers' overrides. The values keep naming what\n * they name, since a copy shows the same components as its source.\n */\nexport function retargetCopiedOverrides(\n graph: SceneGraph,\n copies: ReadonlyMap<string, string>\n): void {\n for (const id of copies.values()) {\n const node = graph.nodes.get(id)\n if (node?.type !== 'INSTANCE' || node.instanceOverrides.descendants.size === 0) continue\n const descendants = new Map(\n [...node.instanceOverrides.descendants].map(([target, fields]) => [\n copies.get(target) ?? target,\n fields\n ])\n )\n graph.updateNode(id, { instanceOverrides: { ...node.instanceOverrides, descendants } })\n }\n}\n\nexport function detachInstance(graph: SceneGraph, instanceId: string): void {\n const node = graph.nodes.get(instanceId)\n if (node?.type !== 'INSTANCE') return\n for (const nested of outermostNestedInstances(graph, node))\n adoptNestedOverrides(graph, node, nested)\n // Through `updateNode`, so the instance index, change observers, and undo recorders see it.\n graph.updateNode(instanceId, {\n type: 'FRAME',\n componentId: null,\n instanceOverrides: createInstanceOverrideState()\n })\n // Its mirrored layers stand on their own: a component child id would name a layer of another\n // node, which the format never stores and a later sync would read as a link back. A nested\n // instance is not a mirror and keeps its own links, which its overrides are written through.\n const detachLinks = (parentId: string): void => {\n for (const child of graph.getChildren(parentId)) {\n if (child.type === 'INSTANCE') continue\n if (child.componentId) graph.updateNode(child.id, { componentId: null })\n detachLinks(child.id)\n }\n }\n detachLinks(instanceId)\n}\n\n// A swap's bookkeeping belongs to the instance enclosing the swapped one, never to the swapped one.\nconst OWNER_ONLY_FIELDS = new Set(['componentId', 'sourceComponentId'])\n\nfunction outermostNestedInstances(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n return graph\n .getChildren(instance.id)\n .flatMap((child) =>\n child.type === 'INSTANCE' ? [child] : outermostNestedInstances(graph, child)\n )\n}\n\n/**\n * An instance a detached one holds stands on its own once that one is a frame, and so must what\n * makes it differ from its component. Cloned in, it kept the overrides of the instance it copies,\n * under that instance's layers; those, and the ones the detached instance recorded on its layers,\n * now go under its own.\n */\nfunction adoptNestedOverrides(graph: SceneGraph, detached: SceneNode, nested: SceneNode): void {\n const ownLayer = new Map<string, string>()\n walkInstanceSources(graph, nested, (source, target) => {\n ownLayer.set(source.id, target.id)\n return true\n })\n const { self, descendants: kept } = cloneInstanceOverrideState(nested.instanceOverrides)\n const outer = cloneInstanceOverrideState(detached.instanceOverrides).descendants\n const descendants = new Map<string, Map<string, unknown>>()\n const claim = (layerId: string, fields: Map<string, unknown>): void => {\n const merged = descendants.get(layerId)\n if (!merged) descendants.set(layerId, fields)\n else for (const [field, value] of fields) merged.set(field, value)\n }\n // What was recorded on its own layers is more recent than what it copied, so it is laid on top.\n for (const [layerId, fields] of kept)\n if (ownLayer.has(layerId)) claim(ownLayer.get(layerId) ?? layerId, fields)\n for (const [layerId, fields] of kept) if (!ownLayer.has(layerId)) claim(layerId, fields)\n for (const [layerId, fields] of outer) {\n if (layerId === nested.id) {\n for (const [field, value] of fields) if (!OWNER_ONLY_FIELDS.has(field)) self.set(field, value)\n } else if (graph.isDescendant(layerId, nested.id)) claim(layerId, fields)\n }\n graph.updateNode(nested.id, { instanceOverrides: { self, descendants } })\n}\n\nexport function getMainComponent(graph: SceneGraph, instanceId: string): SceneNode | undefined {\n const node = graph.nodes.get(instanceId)\n if (!node?.componentId) return undefined\n return graph.nodes.get(node.componentId)\n}\n\nexport function getInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n const ids = graph.instanceIndex.get(componentId)\n if (!ids) return []\n const instances: SceneNode[] = []\n for (const id of ids) {\n const node = graph.nodes.get(id)\n if (node) instances.push(node)\n }\n return instances\n}\n\n/** Nearest INSTANCE at or above `nodeId` — self, parent, grandparent, etc. */\nexport function findInstanceAncestor(graph: SceneGraph, nodeId: string): SceneNode | undefined {\n let current = graph.nodes.get(nodeId)\n while (current) {\n if (current.type === 'INSTANCE') return current\n current = current.parentId ? graph.nodes.get(current.parentId) : undefined\n }\n return undefined\n}\n\n/**\n * Whether Figma lets this layer take a size of its own: a layer inside an instance shows its\n * component's size and cannot be resized, while an instance nested in another may be.\n */\nexport function takesOwnSize(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'INSTANCE' || !node.parentId || !findInstanceAncestor(graph, node.parentId)\n}\n\n/**\n * True when a node field is protected from instance synchronization.\n */\nexport function hasInstanceOverride(graph: SceneGraph, nodeId: string, field: string): boolean {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return false\n return hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n}\n\n/**\n * The layer of the component an instance layer copies, which its overrides are measured\n * against: the instance's component for the instance itself.\n */\nfunction copiedLayer(graph: SceneGraph, instance: SceneNode, node: SceneNode) {\n const id =\n node.id === instance.id\n ? instance.componentId\n : copiedComponentLayerId(instance.instanceOverrides, instance.id, node)\n return id ? graph.nodes.get(id) : undefined\n}\n\n/**\n * The override fields an edit of these fields records. A mode edit claims only the collections\n * whose mode now differs from the component layer's, so the component's other modes still\n * reach the layer; with no layer to compare, it claims every mode.\n */\nfunction overrideFieldsOf(\n graph: SceneGraph,\n instance: SceneNode,\n nodeId: string,\n fields: string[]\n): string[] {\n if (!fields.includes('variableModes')) return fields\n const node = graph.nodes.get(nodeId)\n const source = node && copiedLayer(graph, instance, node)\n if (!node || !source) return fields\n return [\n ...fields.filter((field) => field !== 'variableModes'),\n ...differingVariableModeCollections(node, source).map(variableModeOverrideField)\n ]\n}\n\n/**\n * The instance above `instanceId` that records an assignment made through it: an assignment of a\n * nested instance's property is an edit of the instance it sits in, not of the nested instance.\n */\nexport function assignmentOverrideOwner(\n graph: SceneGraph,\n instanceId: string\n): SceneNode | undefined {\n const parentId = graph.nodes.get(instanceId)?.parentId\n return parentId ? findInstanceAncestor(graph, parentId) : undefined\n}\n\n/** The overrides an assignment edit writes on the instance above it, for undo to restore. */\nexport interface AssignmentOverrideState {\n ownerId: string\n overrides: InstanceOverrideState\n}\n\nexport function takeAssignmentOverrideState(\n graph: SceneGraph,\n instanceId: string\n): AssignmentOverrideState | undefined {\n const owner = assignmentOverrideOwner(graph, instanceId)\n return owner\n ? { ownerId: owner.id, overrides: cloneInstanceOverrideState(owner.instanceOverrides) }\n : undefined\n}\n\nexport function restoreAssignmentOverrideState(\n graph: SceneGraph,\n state: AssignmentOverrideState\n): void {\n graph.updateNode(state.ownerId, {\n instanceOverrides: cloneInstanceOverrideState(state.overrides)\n })\n}\n\n/**\n * Records that an instance assigned one of its component properties, as an edit of the instance\n * above it: the assignment is made through the outer instance, so a text override of the same\n * level does not outrank it. A top-level instance has no outer instance to record it on.\n */\nexport function recordAssignmentOverride(\n graph: SceneGraph,\n instanceId: string,\n propertyId: string,\n value: string\n): void {\n const outer = assignmentOverrideOwner(graph, instanceId)\n if (!outer) return\n setInstanceOverride(\n outer.instanceOverrides,\n outer.id,\n instanceId,\n assignmentOverrideField(propertyId),\n value\n )\n graph.updateNode(outer.id, { instanceOverrides: outer.instanceOverrides })\n}\n\n/**\n * The fields `changes` overrides on an instance layer. New strokes that change only what the\n * layer's line fields say override those fields, not the paints (`changesMoreThanStrokeLines`).\n */\nexport function instanceOverrideFields(node: SceneNode, changes: Partial<SceneNode>): string[] {\n const fields = Object.keys(changes)\n if (!changes.strokes || changesMoreThanStrokeLines(node, changes)) return fields\n return fields.filter((field) => field !== 'strokes')\n}\n\nexport function recordInstanceOverride(\n graph: SceneGraph,\n nodeId: string,\n fields: Iterable<string>\n): void {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return\n\n const relevant = overrideFieldsOf(\n graph,\n instance,\n nodeId,\n [...fields].filter(\n (field) =>\n (INSTANCE_OVERRIDE_FIELDS as readonly string[]).includes(field) ||\n overriddenAssignmentId(field) !== null\n )\n )\n\n const added = relevant.filter(\n (field) => !hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n )\n if (added.length === 0) return\n\n // A new state rather than an edit of the old one, so a preview that captured the old state\n // puts it back on cancel.\n const overrides = cloneInstanceOverrideState(instance.instanceOverrides)\n for (const field of added) setInstanceOverride(overrides, instance.id, nodeId, field)\n graph.updateNode(instance.id, { instanceOverrides: overrides })\n}\n\n/** Every layer at or below `rootId`. */\nfunction subtreeIds(graph: SceneGraph, rootId: string): string[] {\n const ids: string[] = []\n const visit = (id: string) => {\n ids.push(id)\n for (const childId of graph.nodes.get(id)?.childIds ?? []) visit(childId)\n }\n visit(rootId)\n return ids\n}\n\n/** Forget what the instances above `nodeId` recorded for it and the layers inside it. */\nfunction forgetOverridesOf(graph: SceneGraph, nodeId: string): void {\n const ids = subtreeIds(graph, nodeId)\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (!parentId) return\n graph.closest(parentId, (ancestor) => {\n if (ancestor.type !== 'INSTANCE') return false\n const { descendants } = ancestor.instanceOverrides\n if (ids.some((id) => descendants.delete(id)))\n graph.updateNode(ancestor.id, { instanceOverrides: ancestor.instanceOverrides })\n return false\n })\n}\n\n/** Whether a layer can be replaced in its instance: it sits in the part the component owns. */\nexport function canReplaceInstanceLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node?.parentId || !owner) return false\n // Slot content is the instance's own already, and a generated frame's layers are fixed.\n const scope = slotScope(graph, node.parentId)\n if (scope.kind !== 'locked' || scope.owner.type !== 'INSTANCE') return false\n return (\n replacedLayerIn(owner, node.id) !== undefined ||\n copiedComponentLayerId(owner.instanceOverrides, owner.id, node) !== undefined\n )\n}\n\n/**\n * Put `replacementId` in place of `targetId`, a layer an instance copies from its component, as\n * an override of the nearest instance above it, as pen.dev replaces a layer inside an instance.\n * The replacement takes the target's place among its siblings and its position, the target\n * goes, and syncs keep the replacement in place of the component layer the target copied. A\n * replaced layer can be replaced again. Returns false and changes nothing when the target is no\n * such layer, or the replacement cannot go there.\n */\nexport function replaceInstanceLayer(\n graph: SceneGraph,\n targetId: string,\n replacementId: string\n): boolean {\n const target = graph.nodes.get(targetId)\n const replacement = graph.nodes.get(replacementId)\n const parentId = target?.parentId\n if (!target || !replacement || !parentId || targetId === replacementId) return false\n const owner = owningInstance(graph, target)\n if (!owner || graph.isDescendant(parentId, replacementId)) return false\n if (createsComponentCycle(graph, replacementId, parentId)) return false\n const layerId =\n replacedLayerIn(owner, target.id) ??\n copiedComponentLayerId(owner.instanceOverrides, owner.id, target)\n if (!layerId) return false\n\n // The replacement copies no layer of the component, so its own layers lose such links; an\n // instance among them keeps its own component and layers.\n const unlink = (id: string) => {\n const node = graph.nodes.get(id)\n if (!node) return\n if (node.type !== 'INSTANCE' && node.componentId) graph.updateNode(id, { componentId: null })\n if (node.type !== 'INSTANCE') node.childIds.forEach(unlink)\n }\n unlink(replacementId)\n\n const index = graph.nodes.get(parentId)?.childIds.indexOf(target.id) ?? -1\n forgetOverridesOf(graph, target.id)\n forgetOverridesOf(graph, replacementId)\n graph.insertChildAt(replacementId, parentId, index < 0 ? Number.MAX_SAFE_INTEGER : index)\n graph.updateNode(replacementId, {\n x: target.x,\n y: target.y,\n layoutPositioning: target.layoutPositioning,\n horizontalConstraint: target.horizontalConstraint,\n verticalConstraint: target.verticalConstraint\n })\n graph.deleteNode(target.id)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n replacementId,\n REPLACED_LAYER_OVERRIDE,\n layerId\n )\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n return true\n}\n\n/**\n * Take a replaced layer out and bring back the component layer it stood in for, synced from the\n * outermost instance as a reset syncs. Returns false when the layer is not a replaced one.\n */\nexport function restoreReplacedLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node || !owner || replacedLayerIn(owner, nodeId) === undefined) return false\n let outermost = owner\n for (let above = owningInstance(graph, owner); above; above = owningInstance(graph, above))\n outermost = above\n forgetOverridesOf(graph, nodeId)\n graph.deleteNode(nodeId)\n syncInstance(graph, outermost.id)\n // An enclosing sync stops at a swapped instance, which brings its layers back itself.\n const above = owningInstance(graph, owner)\n if (above && getInstanceOverride(above.instanceOverrides, above.id, owner.id, 'componentId'))\n syncInstance(graph, owner.id)\n return true\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgEA,SAAgB,2BAA2B,WAA0C;CACnF,MAAM,QAA4B,CAAC;CAEnC,KAAK,MAAM,OAAO,CAAC,GAAG,qBAAqB,GAAG,8BAA8B,GAC1E,SAAS,OAAO,WAAW,GAAG;CAChC,OAAO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O,KAAK,GACvF,YAAY;CACd,kBAAkB,OAAO,MAAM;CAC/B,MAAM,WAAW,MAAM;CACvB,aAAa,OAAO,UAAU,EAAE;CAEhC,MAAM,QAAQ,eAAe,OAAO,KAAK;CACzC,IAAI,SAAS,oBAAoB,MAAM,mBAAmB,MAAM,IAAI,MAAM,IAAI,aAAa,GACzF,aAAa,OAAO,MAAM,EAAE;CAC9B,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/index.ts"],"sourcesContent":["import type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { shapeGeometryChanges } from '../resize'\nimport { slotScope } from '../slots/content'\nimport { detachOwnedSlotContent, restoreOwnedSlotContent } from '../slots/frames'\nimport { changesMoreThanStrokeLines } from '../strokes'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn, keepCopyBoundPaints } from '../variables/paints'\nimport { keepOwnContentSize } from './content-size'\nimport { createInstanceSyncContext, groupCopyRemovals, removeLeftoverCopies } from './copies'\nimport { canCreateInstance, createsComponentCycle } from './cycles'\nimport {\n INSTANCE_FRAME_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_PROPS\n} from './fields'\nimport { differingVariableModeCollections } from './modes'\nimport {\n assignmentOverrideField,\n cloneInstanceOverrideState,\n copiedComponentLayerId,\n createInstanceOverrideState,\n getInstanceOverride,\n hasInstanceOverride as hasNodeInstanceOverride,\n type InstanceOverrideState,\n overriddenAssignmentId,\n REPLACED_LAYER_OVERRIDE,\n setInstanceOverride,\n variableModeOverrideField\n} from './overrides'\nimport { owningInstance, replacedLayerIn } from './replacements'\nimport { walkInstanceSources } from './source-walk'\nimport { captureInstanceOverrides, restoreInstanceOverrides } from './swap-overrides'\nimport {\n applySyncedStrokeLines,\n bindingProtection,\n cloneChildrenWithMapping,\n copyProp,\n enclosingInstanceOverrideFields,\n isProtectedSyncField,\n sourceInTargetCoordinates,\n syncBindingFields,\n syncChildren,\n syncVariableModeFields,\n updateSyncedProps\n} from './sync'\n\nexport { canCreateInstance, createsComponentCycle, cycleSafeParent } from './cycles'\nexport { walkInstanceSources } from './source-walk'\nexport { instanceMainComponent } from './main-component'\nexport {\n isInShownReplacedLayer,\n isReplacedLayer,\n owningInstance,\n replacedComponentLayerId,\n showsReplacedLayer\n} from './replacements'\nexport {\n INSTANCE_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_FIELDS,\n INSTANCE_SYNC_PROPS,\n INSTANCE_SYNC_TEXT_PROPS\n} from './fields'\n\nexport function copyInstanceComponentProps(component: SceneNode): Partial<SceneNode> {\n const props: Partial<SceneNode> = {}\n // A new instance starts with the fields its component frame lends it, as resyncing one does.\n for (const key of [...INSTANCE_SYNC_PROPS, ...INSTANCE_FRAME_FOLLOWED_FIELDS])\n copyProp(props, component, key)\n return props\n}\n\n/**\n * The name Figma gives a new instance of `component`: its component set's name for a variant,\n * whose own name only says which variant it is, and the component's own name otherwise.\n */\nfunction instanceComponentName(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.nodes.get(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.name : component.name\n}\n\nexport function createInstance(\n graph: SceneGraph,\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n): SceneNode | null {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT' || !canCreateInstance(graph, componentId, parentId))\n return null\n\n const props: Partial<SceneNode> = {\n ...copyInstanceComponentProps(component),\n name: instanceComponentName(graph, component)\n }\n\n // The component checked above is the one the instance shows, whatever `overrides` holds.\n const instance = graph.createNode('INSTANCE', parentId, { ...props, ...overrides, componentId })\n\n cloneChildrenWithMapping(graph, component.id, instance.id)\n // A copy shows its bound paints in its own context, not as its component's paints hold them.\n applyBoundPaintColorsIn(graph, instance.id)\n\n return instance\n}\n\nexport function populateInstanceChildren(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || !component || instance.type !== 'INSTANCE') return\n cloneChildrenWithMapping(graph, componentId, instanceId, mode)\n}\n\n/**\n * A nested instance's link to the enclosing component's record is its `componentId` when it\n * was populated by cloning. A swap replaces that field, so keep the correspondence as the\n * owner's `sourceComponentId` override and record the swap itself; materialized documents\n * already carry the correspondence and only gain the swap.\n */\nfunction recordNestedSwap(graph: SceneGraph, instance: SceneNode, componentId: string): void {\n const owner = instance.parentId ? findInstanceAncestor(graph, instance.parentId) : undefined\n if (!owner) return\n const existing = getInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n 'sourceComponentId'\n )\n if (typeof existing !== 'string' && instance.componentId)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n 'sourceComponentId',\n instance.componentId\n )\n setInstanceOverride(owner.instanceOverrides, owner.id, instance.id, 'componentId', componentId)\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n}\n\nexport interface SwapInstanceOptions {\n /**\n * Keep the instance's name even when it is its old component's. A swap otherwise renames such\n * an instance after the new component, as Figma does; a view that only shows another variant,\n * such as preview, keeps names so layer paths stay the same.\n */\n keepName?: boolean\n /**\n * Keep the overrides the instance's layers record, matched to the layers of the new component\n * that take their places, as Figma keeps them when a variant changes. A swap that only\n * materializes a layer the caller re-applies itself, such as a pen icon's glyph, skips this:\n * what the placeholder recorded is scaffolding, not a user's edit.\n */\n restoreOverrides?: boolean\n}\n\nexport function swapInstanceComponent(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n { keepName = false, restoreOverrides = true }: SwapInstanceOptions = {}\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || component?.type !== 'COMPONENT' || instance.type !== 'INSTANCE') return\n if (instance.parentId && !canCreateInstance(graph, componentId, instance.parentId)) return\n\n const previousComponent = instance.componentId ? graph.nodes.get(instance.componentId) : undefined\n recordNestedSwap(graph, instance, componentId)\n const updates: Partial<SceneNode> = { componentId }\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const overridden = (field: string) =>\n hasNodeInstanceOverride(instance.instanceOverrides, instance.id, instance.id, field)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'variableModes' || overridden(key)) continue\n copyProp(updates, source, key)\n }\n syncVariableModeFields(instance, source, updates, overridden)\n applySyncedStrokeLines(graph, instance, updates, overridden)\n\n if (\n !keepName &&\n (!previousComponent || instance.name === instanceComponentName(graph, previousComponent))\n )\n updates.name = instanceComponentName(graph, component)\n\n keepCopyBoundPaints(graph, instance, updates)\n const childIds = Array.from(instance.childIds)\n const slotContent = detachOwnedSlotContent(graph, instance)\n swapInstanceLayers(graph, instanceId, componentId, updates, childIds, restoreOverrides)\n restoreOwnedSlotContent(graph, instance, slotContent)\n}\n\n/**\n * Replaces the instance's layers with clones of its new component's and gives the recorded\n * overrides back to the layers that take the old ones' places, matched by name path.\n */\nfunction swapInstanceLayers(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n updates: Partial<SceneNode>,\n childIds: string[],\n restoreOverrides: boolean\n): void {\n // The clones take new IDs, so what was recorded for the removed layers only applies again once\n // it is matched to the layers of the new component that take their places.\n const capturedOverrides = restoreOverrides\n ? captureInstanceOverrides(graph, graph.nodes.get(instanceId) as SceneNode)\n : undefined\n for (const childId of childIds) {\n forgetOverridesOf(graph, childId)\n graph.deleteNode(childId)\n }\n graph.updateNode(instanceId, updates)\n cloneChildrenWithMapping(graph, componentId, instanceId)\n applyBoundPaintColorsIn(graph, instanceId)\n const swapped = graph.nodes.get(instanceId)\n if (swapped && capturedOverrides) restoreInstanceOverrides(graph, swapped, capturedOverrides)\n}\n\nconst syncingComponentsByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nexport function syncInstances(graph: SceneGraph, componentId: string): void {\n syncInstancesOf(graph, componentId, getInstances(graph, componentId))\n}\n\n/**\n * Syncs each component's instances, in order, as one edit: the copies they remove stay\n * restorable together for as long as undo keeps that edit.\n */\nexport function syncInstancesTogether(graph: SceneGraph, componentIds: Iterable<string>): void {\n groupCopyRemovals(graph, () => {\n for (const id of componentIds) syncInstances(graph, id)\n })\n}\n\n/** Syncs one instance from its component, as `syncInstances` does for every instance. */\nexport function syncInstance(graph: SceneGraph, instanceId: string): void {\n const instance = graph.nodes.get(instanceId)\n if (instance?.type !== 'INSTANCE' || !instance.componentId) return\n syncInstancesOf(graph, instance.componentId, [instance])\n}\n\nfunction syncInstancesOf(\n graph: SceneGraph,\n componentId: string,\n instances: Iterable<SceneNode>\n): void {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT') return\n let syncing = syncingComponentsByGraph.get(graph)\n if (!syncing) {\n syncing = new Set()\n syncingComponentsByGraph.set(graph, syncing)\n }\n if (syncing.has(componentId)) return\n syncing.add(componentId)\n try {\n groupCopyRemovals(graph, (removals) => {\n for (const instance of instances) {\n const enclosing = enclosingInstanceOverrideFields(graph, instance)\n enclosing.push(new Set(instance.instanceOverrides.self.keys()))\n const protectedField = bindingProtection(enclosing)\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const updates: Partial<SceneNode> = {}\n syncBindingFields(instance, source, updates, protectedField)\n syncVariableModeFields(instance, source, updates, protectedField)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (isProtectedSyncField(instance, key, protectedField)) continue\n copyProp(updates, source, key)\n }\n // The file keeps one value for the instance frame and its component, so the frame takes\n // those the layers inside an instance may not set.\n for (const key of INSTANCE_FRAME_FOLLOWED_FIELDS) {\n if (!isProtectedSyncField(instance, key, protectedField)) copyProp(updates, source, key)\n }\n // An instance that hugs its layers sizes to what it shows, not to the component.\n keepOwnContentSize(graph, updates, instance, source)\n // A size that follows the component invalidates outlines the file saved on the instance;\n // its live box draws them again.\n if (updates.width !== undefined || updates.height !== undefined) {\n Object.assign(\n updates,\n shapeGeometryChanges(\n instance,\n updates.width ?? instance.width,\n updates.height ?? instance.height\n )\n )\n }\n updateSyncedProps(graph, instance, updates, (key) =>\n isProtectedSyncField(instance, key, protectedField)\n )\n const context = createInstanceSyncContext(instance.id, instance.instanceOverrides)\n syncChildren(graph, component.id, instance.id, instance.instanceOverrides, context)\n removeLeftoverCopies(graph, context, removals)\n }\n })\n } finally {\n syncing.delete(componentId)\n }\n}\n\n/**\n * Renames the layers that the copied instances among `copies` record overrides for to their\n * copies, as a copied instance records its own layers' overrides. The values keep naming what\n * they name, since a copy shows the same components as its source.\n */\nexport function retargetCopiedOverrides(\n graph: SceneGraph,\n copies: ReadonlyMap<string, string>\n): void {\n for (const id of copies.values()) {\n const node = graph.nodes.get(id)\n if (node?.type !== 'INSTANCE' || node.instanceOverrides.descendants.size === 0) continue\n const descendants = new Map(\n [...node.instanceOverrides.descendants].map(([target, fields]) => [\n copies.get(target) ?? target,\n fields\n ])\n )\n graph.updateNode(id, { instanceOverrides: { ...node.instanceOverrides, descendants } })\n }\n}\n\nexport function detachInstance(graph: SceneGraph, instanceId: string): void {\n const node = graph.nodes.get(instanceId)\n if (node?.type !== 'INSTANCE') return\n for (const nested of outermostNestedInstances(graph, node))\n adoptNestedOverrides(graph, node, nested)\n // Through `updateNode`, so the instance index, change observers, and undo recorders see it.\n graph.updateNode(instanceId, {\n type: 'FRAME',\n componentId: null,\n instanceOverrides: createInstanceOverrideState()\n })\n // Its mirrored layers stand on their own: a component child id would name a layer of another\n // node, which the format never stores and a later sync would read as a link back. A nested\n // instance is not a mirror and keeps its own links, which its overrides are written through.\n const detachLinks = (parentId: string): void => {\n for (const child of graph.getChildren(parentId)) {\n if (child.type === 'INSTANCE') continue\n if (child.componentId) graph.updateNode(child.id, { componentId: null })\n detachLinks(child.id)\n }\n }\n detachLinks(instanceId)\n}\n\n// A swap's bookkeeping belongs to the instance enclosing the swapped one, never to the swapped one.\nconst OWNER_ONLY_FIELDS = new Set(['componentId', 'sourceComponentId'])\n\nfunction outermostNestedInstances(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n return graph\n .getChildren(instance.id)\n .flatMap((child) =>\n child.type === 'INSTANCE' ? [child] : outermostNestedInstances(graph, child)\n )\n}\n\n/**\n * An instance a detached one holds stands on its own once that one is a frame, and so must what\n * makes it differ from its component. Cloned in, it kept the overrides of the instance it copies,\n * under that instance's layers; those, and the ones the detached instance recorded on its layers,\n * now go under its own.\n */\nfunction adoptNestedOverrides(graph: SceneGraph, detached: SceneNode, nested: SceneNode): void {\n const ownLayer = new Map<string, string>()\n walkInstanceSources(graph, nested, (source, target) => {\n ownLayer.set(source.id, target.id)\n return true\n })\n const { self, descendants: kept } = cloneInstanceOverrideState(nested.instanceOverrides)\n const outer = cloneInstanceOverrideState(detached.instanceOverrides).descendants\n const descendants = new Map<string, Map<string, unknown>>()\n const claim = (layerId: string, fields: Map<string, unknown>): void => {\n const merged = descendants.get(layerId)\n if (!merged) descendants.set(layerId, fields)\n else for (const [field, value] of fields) merged.set(field, value)\n }\n // What was recorded on its own layers is more recent than what it copied, so it is laid on top.\n for (const [layerId, fields] of kept)\n if (ownLayer.has(layerId)) claim(ownLayer.get(layerId) ?? layerId, fields)\n for (const [layerId, fields] of kept) if (!ownLayer.has(layerId)) claim(layerId, fields)\n for (const [layerId, fields] of outer) {\n if (layerId === nested.id) {\n for (const [field, value] of fields) if (!OWNER_ONLY_FIELDS.has(field)) self.set(field, value)\n } else if (graph.isDescendant(layerId, nested.id)) claim(layerId, fields)\n }\n graph.updateNode(nested.id, { instanceOverrides: { self, descendants } })\n}\n\nexport function getMainComponent(graph: SceneGraph, instanceId: string): SceneNode | undefined {\n const node = graph.nodes.get(instanceId)\n if (!node?.componentId) return undefined\n return graph.nodes.get(node.componentId)\n}\n\nexport function getInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n const ids = graph.instanceIndex.get(componentId)\n if (!ids) return []\n const instances: SceneNode[] = []\n for (const id of ids) {\n const node = graph.nodes.get(id)\n if (node) instances.push(node)\n }\n return instances\n}\n\n/** Nearest INSTANCE at or above `nodeId` — self, parent, grandparent, etc. */\nexport function findInstanceAncestor(graph: SceneGraph, nodeId: string): SceneNode | undefined {\n let current = graph.nodes.get(nodeId)\n while (current) {\n if (current.type === 'INSTANCE') return current\n current = current.parentId ? graph.nodes.get(current.parentId) : undefined\n }\n return undefined\n}\n\n/**\n * Whether Figma lets this layer take a size of its own: a layer inside an instance shows its\n * component's size and cannot be resized, while an instance nested in another may be.\n */\nexport function takesOwnSize(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'INSTANCE' || !node.parentId || !findInstanceAncestor(graph, node.parentId)\n}\n\n/**\n * True when a node field is protected from instance synchronization.\n */\nexport function hasInstanceOverride(graph: SceneGraph, nodeId: string, field: string): boolean {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return false\n return hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n}\n\n/**\n * The layer of the component an instance layer copies, which its overrides are measured\n * against: the instance's component for the instance itself.\n */\nfunction copiedLayer(graph: SceneGraph, instance: SceneNode, node: SceneNode) {\n const id =\n node.id === instance.id\n ? instance.componentId\n : copiedComponentLayerId(instance.instanceOverrides, instance.id, node)\n return id ? graph.nodes.get(id) : undefined\n}\n\n/**\n * The override fields an edit of these fields records. A mode edit claims only the collections\n * whose mode now differs from the component layer's, so the component's other modes still\n * reach the layer; with no layer to compare, it claims every mode.\n */\nfunction overrideFieldsOf(\n graph: SceneGraph,\n instance: SceneNode,\n nodeId: string,\n fields: string[]\n): string[] {\n if (!fields.includes('variableModes')) return fields\n const node = graph.nodes.get(nodeId)\n const source = node && copiedLayer(graph, instance, node)\n if (!node || !source) return fields\n return [\n ...fields.filter((field) => field !== 'variableModes'),\n ...differingVariableModeCollections(node, source).map(variableModeOverrideField)\n ]\n}\n\n/**\n * The instance above `instanceId` that records an assignment made through it: an assignment of a\n * nested instance's property is an edit of the instance it sits in, not of the nested instance.\n */\nexport function assignmentOverrideOwner(\n graph: SceneGraph,\n instanceId: string\n): SceneNode | undefined {\n const parentId = graph.nodes.get(instanceId)?.parentId\n return parentId ? findInstanceAncestor(graph, parentId) : undefined\n}\n\n/** The overrides an assignment edit writes on the instance above it, for undo to restore. */\nexport interface AssignmentOverrideState {\n ownerId: string\n overrides: InstanceOverrideState\n}\n\nexport function takeAssignmentOverrideState(\n graph: SceneGraph,\n instanceId: string\n): AssignmentOverrideState | undefined {\n const owner = assignmentOverrideOwner(graph, instanceId)\n return owner\n ? { ownerId: owner.id, overrides: cloneInstanceOverrideState(owner.instanceOverrides) }\n : undefined\n}\n\nexport function restoreAssignmentOverrideState(\n graph: SceneGraph,\n state: AssignmentOverrideState\n): void {\n graph.updateNode(state.ownerId, {\n instanceOverrides: cloneInstanceOverrideState(state.overrides)\n })\n}\n\n/**\n * Records that an instance assigned one of its component properties, as an edit of the instance\n * above it: the assignment is made through the outer instance, so a text override of the same\n * level does not outrank it. A top-level instance has no outer instance to record it on.\n */\nexport function recordAssignmentOverride(\n graph: SceneGraph,\n instanceId: string,\n propertyId: string,\n value: string\n): void {\n const outer = assignmentOverrideOwner(graph, instanceId)\n if (!outer) return\n setInstanceOverride(\n outer.instanceOverrides,\n outer.id,\n instanceId,\n assignmentOverrideField(propertyId),\n value\n )\n graph.updateNode(outer.id, { instanceOverrides: outer.instanceOverrides })\n}\n\n/**\n * The fields `changes` overrides on an instance layer. New strokes that change only what the\n * layer's line fields say override those fields, not the paints (`changesMoreThanStrokeLines`).\n */\nexport function instanceOverrideFields(node: SceneNode, changes: Partial<SceneNode>): string[] {\n const fields = Object.keys(changes)\n if (!changes.strokes || changesMoreThanStrokeLines(node, changes)) return fields\n return fields.filter((field) => field !== 'strokes')\n}\n\nexport function recordInstanceOverride(\n graph: SceneGraph,\n nodeId: string,\n fields: Iterable<string>\n): void {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return\n\n const relevant = overrideFieldsOf(\n graph,\n instance,\n nodeId,\n [...fields].filter(\n (field) =>\n (INSTANCE_OVERRIDE_FIELDS as readonly string[]).includes(field) ||\n overriddenAssignmentId(field) !== null\n )\n )\n\n const added = relevant.filter(\n (field) => !hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n )\n if (added.length === 0) return\n\n // A new state rather than an edit of the old one, so a preview that captured the old state\n // puts it back on cancel.\n const overrides = cloneInstanceOverrideState(instance.instanceOverrides)\n for (const field of added) setInstanceOverride(overrides, instance.id, nodeId, field)\n graph.updateNode(instance.id, { instanceOverrides: overrides })\n}\n\n/** Every layer at or below `rootId`. */\nfunction subtreeIds(graph: SceneGraph, rootId: string): string[] {\n const ids: string[] = []\n const visit = (id: string) => {\n ids.push(id)\n for (const childId of graph.nodes.get(id)?.childIds ?? []) visit(childId)\n }\n visit(rootId)\n return ids\n}\n\n/** Forget what the instances above `nodeId` recorded for it and the layers inside it. */\nfunction forgetOverridesOf(graph: SceneGraph, nodeId: string): void {\n const ids = subtreeIds(graph, nodeId)\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (!parentId) return\n graph.closest(parentId, (ancestor) => {\n if (ancestor.type !== 'INSTANCE') return false\n const { descendants } = ancestor.instanceOverrides\n if (ids.some((id) => descendants.delete(id)))\n graph.updateNode(ancestor.id, { instanceOverrides: ancestor.instanceOverrides })\n return false\n })\n}\n\n/** Whether a layer can be replaced in its instance: it sits in the part the component owns. */\nexport function canReplaceInstanceLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node?.parentId || !owner) return false\n // Slot content is the instance's own already, and a generated frame's layers are fixed.\n const scope = slotScope(graph, node.parentId)\n if (scope.kind !== 'locked' || scope.owner.type !== 'INSTANCE') return false\n return (\n replacedLayerIn(owner, node.id) !== undefined ||\n copiedComponentLayerId(owner.instanceOverrides, owner.id, node) !== undefined\n )\n}\n\n/**\n * Put `replacementId` in place of `targetId`, a layer an instance copies from its component, as\n * an override of the nearest instance above it, as pen.dev replaces a layer inside an instance.\n * The replacement takes the target's place among its siblings and its position, the target\n * goes, and syncs keep the replacement in place of the component layer the target copied. A\n * replaced layer can be replaced again. Returns false and changes nothing when the target is no\n * such layer, or the replacement cannot go there.\n */\nexport function replaceInstanceLayer(\n graph: SceneGraph,\n targetId: string,\n replacementId: string\n): boolean {\n const target = graph.nodes.get(targetId)\n const replacement = graph.nodes.get(replacementId)\n const parentId = target?.parentId\n if (!target || !replacement || !parentId || targetId === replacementId) return false\n const owner = owningInstance(graph, target)\n if (!owner || graph.isDescendant(parentId, replacementId)) return false\n if (createsComponentCycle(graph, replacementId, parentId)) return false\n const layerId =\n replacedLayerIn(owner, target.id) ??\n copiedComponentLayerId(owner.instanceOverrides, owner.id, target)\n if (!layerId) return false\n\n // The replacement copies no layer of the component, so its own layers lose such links; an\n // instance among them keeps its own component and layers.\n const unlink = (id: string) => {\n const node = graph.nodes.get(id)\n if (!node) return\n if (node.type !== 'INSTANCE' && node.componentId) graph.updateNode(id, { componentId: null })\n if (node.type !== 'INSTANCE') node.childIds.forEach(unlink)\n }\n unlink(replacementId)\n\n const index = graph.nodes.get(parentId)?.childIds.indexOf(target.id) ?? -1\n forgetOverridesOf(graph, target.id)\n forgetOverridesOf(graph, replacementId)\n graph.insertChildAt(replacementId, parentId, index < 0 ? Number.MAX_SAFE_INTEGER : index)\n graph.updateNode(replacementId, {\n x: target.x,\n y: target.y,\n layoutPositioning: target.layoutPositioning,\n horizontalConstraint: target.horizontalConstraint,\n verticalConstraint: target.verticalConstraint\n })\n graph.deleteNode(target.id)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n replacementId,\n REPLACED_LAYER_OVERRIDE,\n layerId\n )\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n return true\n}\n\n/**\n * Take a replaced layer out and bring back the component layer it stood in for, synced from the\n * outermost instance as a reset syncs. Returns false when the layer is not a replaced one.\n */\nexport function restoreReplacedLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node || !owner || replacedLayerIn(owner, nodeId) === undefined) return false\n let outermost = owner\n for (let above = owningInstance(graph, owner); above; above = owningInstance(graph, above))\n outermost = above\n forgetOverridesOf(graph, nodeId)\n graph.deleteNode(nodeId)\n syncInstance(graph, outermost.id)\n // An enclosing sync stops at a swapped instance, which brings its layers back itself.\n const above = owningInstance(graph, owner)\n if (above && getInstanceOverride(above.instanceOverrides, above.id, owner.id, 'componentId'))\n syncInstance(graph, owner.id)\n return true\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiEA,SAAgB,2BAA2B,WAA0C;CACnF,MAAM,QAA4B,CAAC;CAEnC,KAAK,MAAM,OAAO,CAAC,GAAG,qBAAqB,GAAG,8BAA8B,GAC1E,SAAS,OAAO,WAAW,GAAG;CAChC,OAAO;AACT;;;;;AAMA,SAAS,sBAAsB,OAAmB,WAA8B;CAC9E,MAAM,SAAS,UAAU,WAAW,MAAM,MAAM,IAAI,UAAU,QAAQ,IAAI,KAAA;CAC1E,OAAO,QAAQ,SAAS,kBAAkB,OAAO,OAAO,UAAU;AACpE;AAEA,SAAgB,eACd,OACA,aACA,UACA,YAAgC,CAAC,GACf;CAClB,MAAM,YAAY,MAAM,MAAM,IAAI,WAAW;CAC7C,IAAI,WAAW,SAAS,eAAe,CAAC,kBAAkB,OAAO,aAAa,QAAQ,GACpF,OAAO;CAET,MAAM,QAA4B;EAChC,GAAG,2BAA2B,SAAS;EACvC,MAAM,sBAAsB,OAAO,SAAS;CAC9C;CAGA,MAAM,WAAW,MAAM,WAAW,YAAY,UAAU;EAAE,GAAG;EAAO,GAAG;EAAW;CAAY,CAAC;CAE/F,yBAAyB,OAAO,UAAU,IAAI,SAAS,EAAE;CAEzD,wBAAwB,OAAO,SAAS,EAAE;CAE1C,OAAO;AACT;AAEA,SAAgB,yBACd,OACA,YACA,aACA,OAAsB,QAChB;CACN,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU;CA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,OAAO;EAC1B,sBAAsB,OAAO;EAC7B,oBAAoB,OAAO;CAC7B,CAAC;CACD,MAAM,WAAW,OAAO,EAAE;CAC1B,oBACE,MAAM,mBACN,MAAM,IACN,eACA,yBACA,OACF;CACA,MAAM,WAAW,MAAM,IAAI,EAAE,mBAAmB,MAAM,kBAAkB,CAAC;CACzE,OAAO;AACT;;;;;AAMA,SAAgB,qBAAqB,OAAmB,QAAyB;CAC/E,MAAM,OAAO,MAAM,MAAM,IAAI,MAAM;CACnC,MAAM,QAAQ,QAAQ,eAAe,OAAO,IAAI;CAChD,IAAI,CAAC,QAAQ,CAAC,SAAS,gBAAgB,OAAO,MAAM,MAAM,KAAA,GAAW,OAAO;CAC5E,IAAI,YAAY;CAChB,KAAK,IAAI,QAAQ,eAAe,OAAO,KAAK,GAAG,OAAO,QAAQ,eAAe,OAAO,KAAK,GACvF,YAAY;CACd,kBAAkB,OAAO,MAAM;CAC/B,MAAM,WAAW,MAAM;CACvB,aAAa,OAAO,UAAU,EAAE;CAEhC,MAAM,QAAQ,eAAe,OAAO,KAAK;CACzC,IAAI,SAAS,oBAAoB,MAAM,mBAAmB,MAAM,IAAI,MAAM,IAAI,aAAa,GACzF,aAAa,OAAO,MAAM,EAAE;CAC9B,OAAO;AACT"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
3
|
+
//#region src/instances/source-walk.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Walk an instance's layers beside the component layers they copy, matched the way instance
|
|
6
|
+
* sync matches them. `visit` returns whether to continue into that pair's children. With
|
|
7
|
+
* `strict`, two layers claiming one source throw instead of the later one winning.
|
|
8
|
+
*/
|
|
9
|
+
declare function walkInstanceSources(graph: SceneGraph, instance: SceneNode, visit: (source: SceneNode, target: SceneNode) => boolean, strict?: boolean): void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { walkInstanceSources };
|
|
12
|
+
//# sourceMappingURL=source-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-walk.d.ts","names":[],"sources":["../../src/instances/source-walk.ts"],"mappings":";;;;;;;;iBASgB,oBACd,OAAO,YACP,UAAU,WACV,QAAQ,QAAQ,WAAW,QAAQ,uBACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAYgB,+BAA+B;;iBA6B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;;;;;iBASQ,gBAAgB,MAAM;;;;;iBAStB,cAAc,MAAM,UAAU;;;;;;cAajC;;;;;;;;;;;;;;;iBAgBG,kBACd,0BACA,MAAM,UACN,YAAW,QAAQ,aAClB;;cAgLU,wBAAwB,YAAY;;cAMpC,mBAAmB,YAAY;cAQ/B,iBAAe,IAAA"}
|