@open-pencil/scene-graph 0.16.0-beta.2 → 0.16.0-beta.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["toRGB","toP3","toDisplayableRGB","toDisplayableP3","toRGB"],"sources":["../../../src/geometry.ts","../../../src/instance-overrides.ts","../../../src/node-defaults.ts","../../../src/vector-network.ts","../../../src/copy.ts","../../../src/color/normalize.ts","../../../src/color/okhcl.ts","../../../src/color/management.ts","../../../src/color/index.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Effect, Stroke, StrokeCap, VectorNetwork } from './index'\nimport type { Rect, Vector } from './primitives'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null\n): number {\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n let extra = 0\n if (stroke.align === 'OUTSIDE') extra = stroke.weight\n else if (stroke.align === 'CENTER') extra = stroke.weight / 2\n overflow = Math.max(overflow, extra)\n }\n return Math.max(overflow, arrowCapOverflow(strokes, fallbackCap, network))\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = effect.radius + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<{\n id: string\n width: number\n height: number\n rotation?: number\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\nfunction transformLocalPoint(node: VisualBoundsNode, point: Vector): Vector {\n let x = node.flipX ? node.width - point.x : point.x\n let y = node.flipY ? node.height - point.y : point.y\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n return { x, y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = getAbsolutePosition(node.id)\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n if (node.type === 'TEXT' && node.textDecoration && node.textDecoration !== 'NONE') {\n const fontSize = node.fontSize ?? 14\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n bounds.maxY += underlineOffset + thickness + fontSize * 0.35\n }\n\n return bounds\n}\n\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n const abs = getAbsolutePosition(node.id)\n const nodeClip = {\n minX: abs.x,\n minY: abs.y,\n maxX: abs.x + node.width,\n maxY: abs.y + node.height\n }\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n\n// ── Rotated-rectangle clipping ──\n\nfunction crossProduct(a: Vector, b: Vector, p: Vector): number {\n return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x)\n}\n\nfunction lineSegmentIntersect(p1: Vector, p2: Vector, p3: Vector, p4: Vector): Vector {\n const dx1 = p2.x - p1.x\n const dy1 = p2.y - p1.y\n const dx2 = p4.x - p3.x\n const dy2 = p4.y - p3.y\n const denom = dx1 * dy2 - dy1 * dx2\n if (denom === 0) return p1\n const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom\n return { x: p1.x + t * dx1, y: p1.y + t * dy1 }\n}\n\nfunction clipHalfPlane(polygon: Vector[], a: Vector, b: Vector, wantPositive: boolean): Vector[] {\n const output: Vector[] = []\n const isInside = (p: Vector): boolean => {\n const cross = crossProduct(a, b, p)\n return wantPositive ? cross >= 0 : cross <= 0\n }\n for (let i = 0; i < polygon.length; i++) {\n const curr = polygon[i]\n const prev = polygon[i === 0 ? polygon.length - 1 : i - 1]\n const currInside = isInside(curr)\n const prevInside = isInside(prev)\n if (currInside) {\n if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b))\n output.push(curr)\n } else if (prevInside) {\n output.push(lineSegmentIntersect(prev, curr, a, b))\n }\n }\n return output\n}\n\n/**\n * Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space\n * corners of a rotated clipping ancestor).\n *\n * Uses Sutherland–Hodgman polygon clipping with centroid-based interior\n * detection, making it robust to either winding order of the clip polygon.\n * Returns the clipped polygon, or null if the subject is fully outside the\n * clip polygon. When `clipCorners` has fewer than 3 points the subject is\n * returned unchanged (no clipping).\n *\n * Preserving the polygon (rather than collapsing to an AABB) lets callers\n * chain multiple clips without reintroducing corners removed by an inner clip.\n */\nexport function clipPolygon(subject: Vector[], clipCorners: Vector[]): Vector[] | null {\n if (clipCorners.length < 3) return subject\n\n let cx = 0\n let cy = 0\n for (const c of clipCorners) {\n cx += c.x\n cy += c.y\n }\n cx /= clipCorners.length\n cy /= clipCorners.length\n\n let polygon: Vector[] = subject\n\n for (let i = 0; i < clipCorners.length; i++) {\n if (polygon.length === 0) return null\n const a = clipCorners[i]\n const b = clipCorners[(i + 1) % clipCorners.length]\n const centroidCross = crossProduct(a, b, { x: cx, y: cy })\n polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0)\n }\n\n return polygon.length === 0 ? null : polygon\n}\n\n/**\n * Clip an axis-aligned VisualBounds rectangle against a convex polygon\n * (e.g. the 4 canvas-space corners of a rotated clipping ancestor).\n *\n * Returns the AABB of the intersection, or null if the bounds are fully\n * outside the clip polygon. Delegates to {@link clipPolygon}.\n *\n * For a non-rotated clip (axis-aligned corners) the result is identical\n * to `intersectVisualBounds`.\n */\nexport function clipBoundsToPolygon(\n bounds: VisualBounds,\n clipCorners: Vector[]\n): VisualBounds | null {\n if (clipCorners.length < 3) return bounds\n\n const subject: Vector[] = [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n { x: bounds.minX, y: bounds.maxY }\n ]\n\n const polygon = clipPolygon(subject, clipCorners)\n if (!polygon) return null\n\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (const p of polygon) {\n if (p.x < minX) minX = p.x\n if (p.y < minY) minY = p.y\n if (p.x > maxX) maxX = p.x\n if (p.y > maxY) maxY = p.y\n }\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n","export type InstanceOverrideField = string\n\nexport interface InstanceOverrideState {\n self: Map<InstanceOverrideField, unknown>\n descendants: Map<string, Map<InstanceOverrideField, unknown>>\n}\n\nexport function createInstanceOverrideState(): InstanceOverrideState {\n return { self: new Map(), descendants: new Map() }\n}\n\nexport interface SerializedOverrideValue {\n defined: boolean\n value?: unknown\n}\n\nexport interface SerializedInstanceOverrideState {\n self: Array<[InstanceOverrideField, SerializedOverrideValue]>\n descendants: Array<[string, Array<[InstanceOverrideField, SerializedOverrideValue]>]>\n}\n\nfunction serializeOverrideValue(value: unknown): SerializedOverrideValue {\n return value === undefined ? { defined: false } : { defined: true, value }\n}\n\nfunction deserializeOverrideValue(value: unknown): { valid: boolean; value: unknown } {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return { valid: false, value: undefined }\n }\n if (!('defined' in value) || typeof value.defined !== 'boolean') {\n return { valid: false, value: undefined }\n }\n if (value.defined) {\n return 'value' in value\n ? { valid: true, value: value['value'] }\n : { valid: false, value: undefined }\n }\n return { valid: true, value: undefined }\n}\n\nfunction deserializeEntries(value: unknown): Map<InstanceOverrideField, unknown> {\n const result = new Map<InstanceOverrideField, unknown>()\n if (!Array.isArray(value)) return result\n for (const entry of value) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n const decoded = deserializeOverrideValue(entry[1])\n if (decoded.valid) result.set(entry[0], decoded.value)\n }\n return result\n}\n\nexport function serializeInstanceOverrideState(\n state: InstanceOverrideState\n): SerializedInstanceOverrideState {\n return {\n self: [...state.self].map(([field, value]) => [field, serializeOverrideValue(value)]),\n descendants: [...state.descendants].map(([nodeId, fields]) => [\n nodeId,\n [...fields].map(([field, value]) => [field, serializeOverrideValue(value)])\n ])\n }\n}\n\nexport function deserializeInstanceOverrideState(state: unknown): InstanceOverrideState {\n if (!state || typeof state !== 'object' || Array.isArray(state)) {\n return createInstanceOverrideState()\n }\n const self =\n 'self' in state ? deserializeEntries(state.self) : new Map<InstanceOverrideField, unknown>()\n const descendants = new Map<string, Map<InstanceOverrideField, unknown>>()\n if ('descendants' in state && Array.isArray(state.descendants)) {\n for (const entry of state.descendants) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n descendants.set(entry[0], deserializeEntries(entry[1]))\n }\n }\n return { self, descendants }\n}\n\nexport function cloneInstanceOverrideState(state: InstanceOverrideState): InstanceOverrideState {\n return {\n self: new Map([...state.self].map(([field, value]) => [field, structuredClone(value)])),\n descendants: new Map(\n [...state.descendants].map(([id, fields]) => [\n id,\n new Map([...fields].map(([field, value]) => [field, structuredClone(value)]))\n ])\n )\n }\n}\n\nexport interface InstanceOverrideReferenceMapper {\n node: (id: string) => string\n variable: (id: string) => string\n}\n\n/** Remap runtime identities only; ordinary strings and source-format payloads stay opaque. */\nexport function remapInstanceOverrideState(\n state: InstanceOverrideState,\n references: InstanceOverrideReferenceMapper\n): InstanceOverrideState {\n const remapValue = (field: string, value: unknown): unknown => {\n if (typeof value !== 'string') return structuredClone(value)\n if (field === 'componentId' || field === 'sourceComponentId') return references.node(value)\n if (field.startsWith('boundVariables/')) return references.variable(value)\n return value\n }\n const fields = (entries: ReadonlyMap<string, unknown>) =>\n new Map([...entries].map(([field, value]) => [field, remapValue(field, value)]))\n const descendants = new Map<string, Map<string, unknown>>()\n for (const [id, entries] of state.descendants) {\n const mapped = references.node(id)\n if (descendants.has(mapped)) throw new Error(`Duplicate remapped override target ${mapped}`)\n descendants.set(mapped, fields(entries))\n }\n return { self: fields(state.self), descendants }\n}\n\nexport function getInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): unknown {\n return nodeId === instanceId ? state.self.get(field) : state.descendants.get(nodeId)?.get(field)\n}\n\nexport function hasInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n return fields?.has(field) ?? false\n}\n\nexport function setInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField,\n value: unknown = true\n): void {\n if (nodeId === instanceId) {\n state.self.set(field, value)\n return\n }\n const fields = state.descendants.get(nodeId) ?? new Map<string, unknown>()\n fields.set(field, value)\n state.descendants.set(nodeId, fields)\n}\n\nexport function deleteInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n if (!fields?.delete(field)) return false\n if (nodeId !== instanceId && fields.size === 0) state.descendants.delete(nodeId)\n return true\n}\n\nexport function clearInstanceOverrides(state: InstanceOverrideState): void {\n state.self.clear()\n state.descendants.clear()\n}\n\nexport function forEachInstanceOverride(\n state: InstanceOverrideState,\n callback: (nodeId: string, field: InstanceOverrideField, value: unknown) => void\n): void {\n for (const [field, value] of state.self) callback('', field, value)\n for (const [nodeId, fields] of state.descendants) {\n for (const [field, value] of fields) callback(nodeId, field, value)\n }\n}\n","import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { createInstanceOverrideState } from './instance-overrides'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n return {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: 0,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n pluginData: [],\n pluginRelaunchData: [],\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined,\n ...overrides\n } satisfies CompleteNodeFields\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n","import { isEqual } from 'es-toolkit/predicate'\n\nimport type { Mat3 } from './matrix'\nimport type { Vector } from './primitives'\nimport type { VectorNetwork, VectorSegment } from './types'\n\n/** Concatenate vector networks while preserving independent geometry. */\nexport function mergeVectorNetworks(networks: readonly VectorNetwork[]): VectorNetwork {\n const vertices: VectorNetwork['vertices'] = []\n const segments: VectorNetwork['segments'] = []\n const regions: VectorNetwork['regions'] = []\n let vertexOffset = 0\n let segmentOffset = 0\n\n for (const network of networks) {\n for (const vertex of network.vertices) vertices.push({ ...vertex })\n for (const segment of network.segments) {\n segments.push({\n ...segment,\n start: segment.start + vertexOffset,\n end: segment.end + vertexOffset,\n tangentStart: { ...segment.tangentStart },\n tangentEnd: { ...segment.tangentEnd }\n })\n }\n for (const region of network.regions) {\n const loops: number[][] = []\n for (const loop of region.loops) {\n const shifted: number[] = []\n for (const segmentIndex of loop) shifted.push(segmentIndex + segmentOffset)\n loops.push(shifted)\n }\n regions.push({ windingRule: region.windingRule, loops })\n }\n vertexOffset += network.vertices.length\n segmentOffset += network.segments.length\n }\n\n return { vertices, segments, regions }\n}\n\n/**\n * Map a VectorNetwork through an affine matrix: vertices as points,\n * tangents as direction vectors (linear part only, no translation).\n * Returns a deep copy; the input is not mutated.\n */\nexport function transformVectorNetwork(m: Mat3, vn: VectorNetwork): VectorNetwork {\n const mapVector = (v: Vector): Vector => ({\n x: m[0] * v.x + m[1] * v.y,\n y: m[3] * v.x + m[4] * v.y\n })\n return {\n vertices: vn.vertices.map((v) => ({\n ...v,\n x: m[0] * v.x + m[1] * v.y + m[2],\n y: m[3] * v.x + m[4] * v.y + m[5]\n })),\n segments: vn.segments.map((s) => ({\n ...s,\n tangentStart: mapVector(s.tangentStart),\n tangentEnd: mapVector(s.tangentEnd)\n })),\n regions: vn.regions.map((r) => ({\n windingRule: r.windingRule,\n loops: r.loops.map((l) => [...l])\n }))\n }\n}\n\n/** Structural equality of two VectorNetworks (order-sensitive, exact values). */\nexport function vectorNetworksEqual(a: VectorNetwork, b: VectorNetwork): boolean {\n return (\n isEqual(a.vertices, b.vertices) &&\n isEqual(a.segments, b.segments) &&\n isEqual(a.regions, b.regions)\n )\n}\n\n/** Deep-copy a VectorNetwork, stripping any Vue Proxy wrappers. */\nexport function cloneVectorNetwork(vn: VectorNetwork): VectorNetwork {\n return {\n vertices: vn.vertices.map((v) => ({ ...v })),\n segments: vn.segments.map((s) => ({\n ...s,\n tangentStart: { ...s.tangentStart },\n tangentEnd: { ...s.tangentEnd }\n })),\n regions: vn.regions.map((r) => ({\n windingRule: r.windingRule,\n loops: r.loops.map((l) => [...l])\n }))\n }\n}\n\n/**\n * Validate a VectorNetwork structure, returning an array of error messages.\n * Empty array means the network is valid.\n */\nexport function validateVectorNetwork(value: unknown): string[] {\n if (!isRecord(value)) return ['network must be an object']\n if (!Array.isArray(value.vertices)) return ['vertices must be an array']\n if (!Array.isArray(value.segments)) return ['segments must be an array']\n\n const errors: string[] = []\n validateVertices(value.vertices, errors)\n validateSegments(value.segments, value.vertices.length, errors)\n const typedSegments = value.segments.filter(isSegmentRecord)\n if (value.regions !== undefined) {\n if (Array.isArray(value.regions)) {\n validateRegions(\n value.regions,\n value.segments.length,\n typedSegments.length === value.segments.length ? typedSegments : null,\n errors\n )\n } else {\n errors.push('regions must be an array when provided')\n }\n }\n return errors\n}\n\nfunction validateVertices(vertices: unknown[], errors: string[]): void {\n for (let index = 0; index < vertices.length; index++) {\n if (!isFiniteVector(vertices[index])) {\n errors.push(`vertex[${index}]: x and y must be finite numbers`)\n }\n }\n}\n\nfunction validateSegments(segments: unknown[], vertexCount: number, errors: string[]): void {\n for (let index = 0; index < segments.length; index++) {\n const segment = segments[index]\n if (!isRecord(segment)) {\n errors.push(`segment[${index}] must be an object`)\n continue\n }\n if (!isInteger(segment.start) || !isInteger(segment.end)) {\n errors.push(`segment[${index}]: start and end must be integers`)\n continue\n }\n if (segment.start < 0 || segment.start >= vertexCount) {\n errors.push(`segment[${index}]: start index ${segment.start} out of range`)\n }\n if (segment.end < 0 || segment.end >= vertexCount) {\n errors.push(`segment[${index}]: end index ${segment.end} out of range`)\n }\n validateSegmentTangents(segment, index, errors)\n }\n}\n\nfunction validateSegmentTangents(\n segment: Record<string, unknown>,\n index: number,\n errors: string[]\n): void {\n for (const tangentKey of ['tangentStart', 'tangentEnd'] as const) {\n const tangent = segment[tangentKey]\n if (tangent !== undefined && !isFiniteVector(tangent)) {\n errors.push(`segment[${index}]: ${tangentKey} must contain finite x and y numbers`)\n }\n }\n}\n\nfunction validateRegions(\n regions: unknown[],\n segmentCount: number,\n segments: Array<Record<'start' | 'end', number>> | null,\n errors: string[]\n): void {\n for (let regionIndex = 0; regionIndex < regions.length; regionIndex++) {\n const region = regions[regionIndex]\n if (!isRecord(region) || !Array.isArray(region.loops)) {\n errors.push(`region[${regionIndex}]: loops must be an array`)\n continue\n }\n if (region.windingRule !== 'NONZERO' && region.windingRule !== 'EVENODD') {\n errors.push(`region[${regionIndex}]: windingRule must be NONZERO or EVENODD`)\n }\n if (region.loops.length === 0) {\n errors.push(`region[${regionIndex}]: loops must contain at least one loop`)\n }\n validateRegionLoops(region.loops, regionIndex, segmentCount, segments, errors)\n }\n}\n\nfunction validateRegionLoops(\n loops: unknown[],\n regionIndex: number,\n segmentCount: number,\n segments: Array<Record<'start' | 'end', number>> | null,\n errors: string[]\n): void {\n for (let loopIndex = 0; loopIndex < loops.length; loopIndex++) {\n const loop = loops[loopIndex]\n if (!Array.isArray(loop)) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] must be an array`)\n continue\n }\n if (loop.length === 0) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] must contain at least one segment`)\n continue\n }\n\n const segmentIndices: number[] = []\n for (const segmentIndex of loop) {\n if (!isInteger(segmentIndex) || segmentIndex < 0 || segmentIndex >= segmentCount) {\n errors.push(\n `region[${regionIndex}].loop[${loopIndex}]: segment index ${String(segmentIndex)} out of range`\n )\n } else {\n segmentIndices.push(segmentIndex)\n }\n }\n if (segmentIndices.length !== loop.length) continue\n if (new Set(segmentIndices).size !== segmentIndices.length) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] must not repeat segments`)\n continue\n }\n if (segments && !formsContinuousChain(segmentIndices, segments)) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] segments must form a continuous chain`)\n }\n }\n}\n\nfunction formsContinuousChain(\n indices: number[],\n segments: Array<Record<'start' | 'end', number>>\n): boolean {\n if (indices.length <= 1) return true\n const first = segments[indices[0]]\n return followsChain(indices, segments, first.end) || followsChain(indices, segments, first.start)\n}\n\nfunction followsChain(\n indices: number[],\n segments: Array<Record<'start' | 'end', number>>,\n initialEnd: number\n): boolean {\n let current = initialEnd\n for (let index = 1; index < indices.length; index++) {\n const segment = segments[indices[index]]\n if (segment.start === current) current = segment.end\n else if (segment.end === current) current = segment.start\n else return false\n }\n return true\n}\n\nfunction isSegmentRecord(value: unknown): value is Record<'start' | 'end', number> {\n return isRecord(value) && isInteger(value.start) && isInteger(value.end)\n}\n\nfunction isFiniteVector(value: unknown): value is Vector {\n return (\n isRecord(value) &&\n typeof value.x === 'number' &&\n Number.isFinite(value.x) &&\n typeof value.y === 'number' &&\n Number.isFinite(value.y)\n )\n}\n\nfunction isInteger(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value)\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n\nexport type NormalizableVectorNetwork = Omit<VectorNetwork, 'regions'> & {\n regions?: VectorNetwork['regions']\n}\n\n/**\n * Ensure every segment has tangentStart/tangentEnd and a regions array.\n * Missing tangents default to {x:0, y:0} (straight line segments).\n * Use at system boundaries where input may come from JSON/MCP.\n */\nexport function normalizeVectorNetwork(vn: NormalizableVectorNetwork): VectorNetwork {\n const ZERO: Vector = { x: 0, y: 0 }\n return {\n vertices: vn.vertices,\n segments: vn.segments.map((s) => ({\n start: s.start,\n end: s.end,\n tangentStart: (s as Partial<VectorSegment>).tangentStart ?? { ...ZERO },\n tangentEnd: (s as Partial<VectorSegment>).tangentEnd ?? { ...ZERO }\n })),\n regions: vn.regions ?? []\n }\n}\n","/**\n * Typed shallow-copy helpers for Fill, Stroke, Effect, and StyleRun.\n *\n * These replace `structuredClone` for known scene-graph array types,\n * avoiding the ~24× overhead of the generic deep-clone algorithm.\n * Each helper spreads the top-level object and any nested objects\n * (color, offset, gradientStops, dashPattern, style) to ensure\n * no shared references between source and copy.\n */\n\nimport type {\n ArcData,\n ComponentPropertyDefinition,\n Effect,\n DerivedTextGlyph,\n Fill,\n GeometryPath,\n GradientStop,\n LayoutGrid,\n SceneNode,\n Stroke,\n StyleRun\n} from './'\nimport { geometryCommandCoordCount } from './geometry'\nimport { cloneInstanceOverrideState } from './instance-overrides'\nimport { createDefaultSourceMetadata } from './node-defaults'\nimport { cloneVectorNetwork } from './vector-network'\n\n// --- Individual copy functions ---\n\n/** Generic over the paint shape so a stroke keeps its own fields while the paint deep-copies. */\nexport function copyFill<T extends Fill>(f: T): T {\n const copy: T = { ...f, color: { ...f.color } }\n if (f.gradientStops) copy.gradientStops = f.gradientStops.map(copyGradientStop)\n if (f.gradientTransform) copy.gradientTransform = { ...f.gradientTransform }\n if (f.imageTransform) copy.imageTransform = { ...f.imageTransform }\n if (f.patternSpacing) copy.patternSpacing = { ...f.patternSpacing }\n if (f.noiseSize) copy.noiseSize = { ...f.noiseSize }\n return copy\n}\n\nexport function copyStroke(s: Stroke): Stroke {\n const copy = copyFill(s)\n if (s.dashPattern) {\n copy.dashPattern = [...s.dashPattern]\n }\n return copy\n}\n\nexport function copyEffect(e: Effect): Effect {\n return {\n ...e,\n color: { ...e.color },\n offset: { ...e.offset }\n }\n}\n\nexport function copyStyleRun(r: StyleRun): StyleRun {\n const copy: StyleRun = {\n ...r,\n style: {\n ...r.style,\n fills: r.style.fills ? r.style.fills.map(copyFill) : undefined,\n textDecorationFills: r.style.textDecorationFills\n ? r.style.textDecorationFills.map(copyFill)\n : undefined,\n fontVariations: r.style.fontVariations\n ? r.style.fontVariations.map((v) => ({ ...v }))\n : undefined,\n fontFeatures: r.style.fontFeatures ? r.style.fontFeatures.map((v) => ({ ...v })) : undefined\n }\n }\n if (r.style.hyperlink) copy.style.hyperlink = { ...r.style.hyperlink }\n if (r.style.boundVariables) copy.style.boundVariables = { ...r.style.boundVariables }\n return copy\n}\n\n// --- Array copy functions ---\n\nconst internalCopySources = new WeakMap<object, object>()\n\n/** Record immutable lineage for an internal deep copy without sharing mutable values. */\nexport function markCopySource<T extends object>(source: T, copy: T): T {\n internalCopySources.set(copy, internalCopySources.get(source) ?? source)\n return copy\n}\n\n/** Compare internal deep copies in O(1) without traversing large paint or text payloads. */\nexport function hasSameCopySource(left: object, right: object): boolean {\n if (left === right) return true\n return (internalCopySources.get(left) ?? left) === (internalCopySources.get(right) ?? right)\n}\n\nexport function copyFills(fills: Fill[]): Fill[] {\n return fills.map(copyFill)\n}\n\nexport function copyStrokes(strokes: Stroke[]): Stroke[] {\n return strokes.map(copyStroke)\n}\n\nexport function copyEffects(effects: Effect[]): Effect[] {\n return effects.map(copyEffect)\n}\n\nexport function copyLayoutGrids(grids: LayoutGrid[]): LayoutGrid[] {\n return grids.map((grid) => ({ ...grid, color: grid.color ? { ...grid.color } : undefined }))\n}\n\nexport function copyStyleRuns(runs: StyleRun[]): StyleRun[] {\n return runs.map(copyStyleRun)\n}\n\n/** Keep path-level fills across copy/scale/transform (resize snapshots). */\nfunction withPathPaintMeta(path: GeometryPath, commandsBlob: Uint8Array): GeometryPath {\n return {\n windingRule: path.windingRule,\n commandsBlob,\n ...(path.fills ? { fills: copyFills(path.fills) } : {})\n }\n}\n\nexport function copyGeometryPaths(paths: GeometryPath[]): GeometryPath[] {\n return paths.map((p) => withPathPaintMeta(p, p.commandsBlob.slice()))\n}\n\n/**\n * Affine-transform every coordinate pair in a path command blob (returns a\n * copy): (x, y) → (m00·x + m01·y + tx, m10·x + m11·y + ty).\n * Command layout: 1=move/2=line (1 pair), 3=quad (2 pairs), 4=cubic (3 pairs)\n * — font-glyph blobs are quad-heavy, so skipping command 3 desyncs the walk.\n */\nexport function transformGeometryBlob(\n blob: Uint8Array,\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): Uint8Array {\n const out = blob.slice()\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength)\n let offset = 0\n while (offset < out.length) {\n const command = out[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > out.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n dv.setFloat32(offset, m00 * x + m01 * y + tx, true)\n dv.setFloat32(offset + 4, m10 * x + m11 * y + ty, true)\n offset += 8\n }\n }\n return out\n}\n\nexport function transformGeometryPaths(\n paths: GeometryPath[],\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): GeometryPath[] {\n return paths.map((g) =>\n withPathPaintMeta(g, transformGeometryBlob(g.commandsBlob, m00, m01, m10, m11, tx, ty))\n )\n}\n\n/**\n * Scale path command blob coordinates by (sx, sy).\n * Identity scale returns a deep copy (same as copyGeometryPaths).\n */\nexport function scaleGeometryPaths(paths: GeometryPath[], sx: number, sy: number): GeometryPath[] {\n if (sx === 1 && sy === 1) return copyGeometryPaths(paths)\n return transformGeometryPaths(paths, sx, 0, 0, sy)\n}\n\n// --- Internal helpers ---\n\n/** Copy an optional array: non-empty → mapped, empty → [], undefined → undefined. */\nfunction copyOpt<T, U>(arr: T[] | undefined, fn: (arr: T[]) => U[]): U[] | undefined {\n if (arr === undefined) return undefined\n return arr.length > 0 ? fn(arr) : []\n}\n\nfunction copyGradientStop(gs: GradientStop): GradientStop {\n return { color: { ...gs.color }, position: gs.position }\n}\n\nfunction copySpread<T extends object>(arr: T[] | undefined): T[] {\n return arr?.map((item) => ({ ...item })) ?? []\n}\n\nfunction copyPropertyDefs(\n defs: ComponentPropertyDefinition[] | undefined\n): ComponentPropertyDefinition[] {\n return (\n defs?.map((d) => ({\n ...d,\n variantOptions: d.variantOptions ? [...d.variantOptions] : undefined,\n preferredValues: d.preferredValues ? [...d.preferredValues] : undefined,\n slotSettings: d.slotSettings ? { ...d.slotSettings } : undefined\n })) ?? []\n )\n}\n\n/** Deep-copy path-text glyphs (fresh commandsBlob buffers). */\nexport function copyDerivedGlyphs(glyphs: DerivedTextGlyph[] | null): DerivedTextGlyph[] | null {\n return glyphs ? glyphs.map((g) => ({ ...g, commandsBlob: new Uint8Array(g.commandsBlob) })) : null\n}\n\n// --- Complex structure copy functions ---\n// These replace structuredClone for known types, avoiding its ~24× overhead.\n\nfunction copyArcData(a: ArcData): ArcData {\n return { startingAngle: a.startingAngle, endingAngle: a.endingAngle, innerRadius: a.innerRadius }\n}\n\n// --- Deep-copy clone props ---\n\n/**\n * Build the init props for a deep-copy clone of `src`.\n * Shares logic between SceneGraph.cloneTree and instance child cloning.\n * Explicitly deep-copies all mutable object/array fields that `...rest`\n * would otherwise share by reference. When adding a mutable SceneNode field,\n * add its copy behavior here or document why sharing is intentional.\n */\nexport type NodeCloneMode = 'deep' | 'fig-import'\n\nexport function cloneNodeProps(\n src: SceneNode,\n componentId: string | null,\n mode: NodeCloneMode = 'deep'\n): Partial<SceneNode> {\n const { id: _, parentId: _p, childIds: _c, ...rest } = src\n if (mode === 'fig-import') {\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n source: createDefaultSourceMetadata(),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n\n componentPropertyValues: { ...src.componentPropertyValues }\n }\n }\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n fills: copyOpt(src.fills, (value) => markCopySource(value, copyFills(value))),\n\n strokes: copyOpt(src.strokes, (value) => markCopySource(value, copyStrokes(value))),\n effects: copyOpt(src.effects, (value) => markCopySource(value, copyEffects(value))),\n layoutGrids: copyOpt(src.layoutGrids, copyLayoutGrids),\n guides: copyOpt(src.guides, (guides) => guides.map((guide) => ({ ...guide }))),\n styleRuns: copyOpt(src.styleRuns, (value) => markCopySource(value, copyStyleRuns(value))),\n // Generated instance descendants have no independent Figma provenance. Retaining the source\n // component's opaque raw payload here duplicates megabytes of metadata per instance.\n source: componentId === null ? structuredClone(src.source) : createDefaultSourceMetadata(),\n dashPattern: copyOpt(src.dashPattern, (a) => [...a]),\n fontVariations: copyOpt(src.fontVariations, (a) => a.map((v) => ({ ...v }))),\n fontFeatures: copyOpt(src.fontFeatures, (a) => a.map((v) => ({ ...v }))),\n textParagraphs: copyOpt(src.textParagraphs, (a) => a.map((v) => ({ ...v }))),\n textDecorationFills: copyOpt(src.textDecorationFills, copyFills),\n fillGeometry: copyOpt(src.fillGeometry, copyGeometryPaths),\n strokeGeometry: copyOpt(src.strokeGeometry, copyGeometryPaths),\n gridTemplateColumns: copySpread(src.gridTemplateColumns),\n gridTemplateRows: copySpread(src.gridTemplateRows),\n componentPropertyDefinitions: copyPropertyDefs(src.componentPropertyDefinitions),\n componentPropertyReferences: copySpread(src.componentPropertyReferences),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n symbolLinks: copySpread(src.symbolLinks),\n variantPropSpecs: copySpread(src.variantPropSpecs),\n pluginData: copySpread(src.pluginData),\n pluginRelaunchData: copySpread(src.pluginRelaunchData),\n exportSettings: copySpread(src.exportSettings),\n componentPropertyValues: { ...src.componentPropertyValues },\n derivedLayout: src.derivedLayout ? { ...src.derivedLayout } : null,\n arcData: src.arcData ? copyArcData(src.arcData) : null,\n vectorNetwork: src.vectorNetwork ? cloneVectorNetwork(src.vectorNetwork) : null,\n textPicture: src.textPicture ? new Uint8Array(src.textPicture) : null,\n derivedTextGlyphs: src.derivedTextGlyphs\n ? markCopySource(src.derivedTextGlyphs, copyDerivedGlyphs(src.derivedTextGlyphs) ?? [])\n : null,\n textPathData: src.textPathData ? structuredClone(src.textPathData) : null,\n textPathBox: src.textPathBox ? { ...src.textPathBox } : null,\n gridPosition: src.gridPosition ? { ...src.gridPosition } : null,\n targetAspectRatio: src.targetAspectRatio ? { ...src.targetAspectRatio } : null\n }\n}\n","import { BLACK } from '../constants'\nimport type { Color } from '../primitives'\n\nexport function normalizeColor(color?: Partial<Color>): Color {\n if (!color) return { ...BLACK }\n return { r: color.r ?? 0, g: color.g ?? 0, b: color.b ?? 0, a: color.a ?? 1 }\n}\n","import { converter, toGamut } from 'culori'\n\nimport { copyFill, copyStroke } from '../copy'\nimport { readAllPluginData, withAllPluginData } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { Color } from '../primitives'\nimport type { PluginDataEntry, SceneNode } from '../types'\nimport { normalizeColor } from './normalize'\n\nexport interface OkHCLColor {\n h: number\n c: number\n l: number\n a?: number\n}\n\nexport interface OkHCLPayload {\n version: 1\n kind: 'fill' | 'stroke'\n index: number\n color: OkHCLColor\n}\n\nconst toRGB = converter('rgb')\nconst toP3 = converter('p3')\nconst toOkHCL = converter('oklch')\nconst toDisplayableRGB = toGamut('rgb', 'oklch')\nconst toDisplayableP3 = toGamut('p3', 'oklch')\n\n/** Colour spaces a document's stored numbers can be in. */\nexport type OkHCLColorSpace = 'srgb' | 'display-p3'\n\nfunction clampUnit(value: number): number {\n if (value < 0) return 0\n if (value > 1) return 1\n return value\n}\n\nfunction normalizeHue(value: number): number {\n const hue = value % 360\n return hue < 0 ? hue + 360 : hue\n}\n\nfunction normalizeOkHCLColor(color: OkHCLColor): OkHCLColor {\n return {\n h: normalizeHue(color.h),\n c: Math.max(0, color.c),\n l: clampUnit(color.l),\n a: clampUnit(color.a ?? 1)\n }\n}\n\n/** Coordinates in `colorSpace`, so callers can store colours in the document's profile. */\nexport function okhclToRGBA(color: OkHCLColor, colorSpace: OkHCLColorSpace = 'srgb'): Color {\n const normalized = normalizeOkHCLColor(color)\n const oklch = {\n mode: 'oklch' as const,\n l: normalized.l,\n c: normalized.c,\n h: normalized.h,\n alpha: normalized.a\n }\n if (colorSpace === 'display-p3') {\n const p3 = toP3(toDisplayableP3(oklch))\n return normalizeColor({\n r: p3.r,\n g: p3.g,\n b: p3.b,\n a: p3.alpha ?? normalized.a\n })\n }\n const rgb = toRGB(toDisplayableRGB(oklch))\n return normalizeColor({\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: rgb.alpha ?? normalized.a\n })\n}\n\n/** Reads `color` as coordinates in `colorSpace`, the inverse of {@link okhclToRGBA}. */\nexport function rgbaToOkHCL(color: Color, colorSpace: OkHCLColorSpace = 'srgb'): OkHCLColor {\n const oklch = toOkHCL(\n colorSpace === 'display-p3'\n ? { mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a }\n : { mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a }\n )\n return normalizeOkHCLColor({\n h: oklch.h ?? 0,\n c: oklch.c,\n l: oklch.l,\n a: oklch.alpha ?? color.a\n })\n}\n\nexport function serializeOkHCLPayload(payload: OkHCLPayload): string {\n return OPEN_PENCIL_PLUGIN_DATA.okhcl.encode(payload)\n}\n\nexport function parseOkHCLPayload(value: string): OkHCLPayload | null {\n return OPEN_PENCIL_PLUGIN_DATA.okhcl.decode(value) ?? null\n}\n\nfunction createOkHCLPayload(\n kind: 'fill' | 'stroke',\n index: number,\n color: OkHCLColor\n): OkHCLPayload {\n return {\n version: 1,\n kind,\n index,\n color: normalizeOkHCLColor(color)\n }\n}\n\n/** The node's plugin data with the payload for one paint replaced, or removed without `color`. */\nfunction withOkHCLPayload(\n node: SceneNode,\n kind: 'fill' | 'stroke',\n index: number,\n color?: OkHCLColor\n): PluginDataEntry[] {\n const payloads = getNodeOkHCLPayloads(node).filter(\n (payload) => payload.kind !== kind || payload.index !== index\n )\n if (color) payloads.push(createOkHCLPayload(kind, index, color))\n return withAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.okhcl, payloads)\n}\n\nexport function setNodeFillOkHCL(\n node: SceneNode,\n index: number,\n color: OkHCLColor,\n colorSpace: OkHCLColorSpace = 'srgb'\n): Partial<SceneNode> {\n const fills = node.fills.map(copyFill)\n if (index < 0 || index >= fills.length) throw new Error(`Fill ${index} not found`)\n const fill = fills[index]\n const rgba = okhclToRGBA(color, colorSpace)\n fills[index] = {\n ...fill,\n color: rgba,\n opacity: rgba.a\n }\n\n return {\n fills,\n pluginData: withOkHCLPayload(node, 'fill', index, color)\n }\n}\n\nexport function setNodeStrokeOkHCL(\n node: SceneNode,\n index: number,\n color: OkHCLColor,\n colorSpace: OkHCLColorSpace = 'srgb'\n): Partial<SceneNode> {\n const strokes = node.strokes.map(copyStroke)\n if (index < 0 || index >= strokes.length) throw new Error(`Stroke ${index} not found`)\n const stroke = strokes[index]\n const rgba = okhclToRGBA(color, colorSpace)\n strokes[index] = {\n ...stroke,\n color: rgba,\n opacity: rgba.a\n }\n\n return {\n strokes,\n pluginData: withOkHCLPayload(node, 'stroke', index, color)\n }\n}\n\nexport function clearNodeFillOkHCL(node: SceneNode, index: number): Partial<SceneNode> {\n return { pluginData: withOkHCLPayload(node, 'fill', index) }\n}\n\nexport function clearNodeStrokeOkHCL(node: SceneNode, index: number): Partial<SceneNode> {\n return { pluginData: withOkHCLPayload(node, 'stroke', index) }\n}\n\nexport function getNodeOkHCLPayloads(node: SceneNode): OkHCLPayload[] {\n return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.okhcl)\n}\n\nexport function getFillOkHCL(node: SceneNode, index: number): OkHCLPayload | null {\n return (\n getNodeOkHCLPayloads(node).find(\n (payload) => payload.kind === 'fill' && payload.index === index\n ) ?? null\n )\n}\n\nexport function getStrokeOkHCL(node: SceneNode, index: number): OkHCLPayload | null {\n return (\n getNodeOkHCLPayloads(node).find(\n (payload) => payload.kind === 'stroke' && payload.index === index\n ) ?? null\n )\n}\n","import { converter, formatCss, formatRgb, inGamut, parse, toGamut } from 'culori'\n\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace, Fill, SceneNode, Stroke } from '../types'\nimport { normalizeColor } from './normalize'\nimport { getFillOkHCL, getStrokeOkHCL, type OkHCLColor } from './okhcl'\n\nexport type RenderColorSpace = 'srgb' | 'display-p3'\nexport type ColorIntentSpace = 'oklch' | 'srgb'\n\nexport interface ColorPreviewOptions {\n colorSpace?: RenderColorSpace\n documentColorSpace?: DocumentColorSpace\n}\n\nexport interface ResolvedRenderColor {\n color: Color\n cssColor: string\n sourceSpace: ColorIntentSpace\n targetSpace: RenderColorSpace\n clipped: boolean\n}\n\nconst DEFAULT_COLOR_SPACE: RenderColorSpace = 'srgb'\n\nconst toRGB = converter('rgb')\nconst toP3 = converter('p3')\nconst toDisplayableRGB = toGamut('rgb', 'oklch')\nconst toDisplayableP3 = toGamut('p3', 'oklch')\nconst isDisplayableRGB = inGamut('rgb')\nconst isDisplayableP3 = inGamut('p3')\n\nfunction normalizeOkLCH(color: OkHCLColor) {\n const hue = color.h % 360\n return {\n mode: 'oklch' as const,\n l: Math.max(0, Math.min(1, color.l)),\n c: Math.max(0, color.c),\n h: hue < 0 ? hue + 360 : hue,\n alpha: Math.max(0, Math.min(1, color.a ?? 1))\n }\n}\n\n/**\n * Numbers are stored in the document's profile, so painting into a surface with a different\n * profile has to convert them. Same profile means no work, which is the common case.\n */\nfunction convertComponents(color: Color, from: RenderColorSpace, to: RenderColorSpace): Color {\n if (from === to) return color\n const source =\n from === 'display-p3'\n ? { mode: 'p3' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }\n : { mode: 'rgb' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }\n const converted = to === 'display-p3' ? toP3(source) : toRGB(source)\n return normalizeColor({\n r: converted.r,\n g: converted.g,\n b: converted.b,\n a: converted.alpha ?? color.a\n })\n}\n\nfunction isOutsideGamut(color: Color, space: RenderColorSpace): boolean {\n if (space === 'display-p3') {\n return !isDisplayableP3({ mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a })\n }\n return !isDisplayableRGB({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nfunction resolveTargetSpace(options?: ColorPreviewOptions): RenderColorSpace {\n return options?.colorSpace ?? options?.documentColorSpace ?? DEFAULT_COLOR_SPACE\n}\n\nfunction formatCSSForTarget(color: Color, targetSpace: RenderColorSpace): string {\n if (targetSpace === 'display-p3') {\n const p3 = toP3({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n return formatCss({\n mode: 'p3',\n r: p3.r,\n g: p3.g,\n b: p3.b,\n alpha: p3.alpha ?? color.a\n })\n }\n\n return formatRgb({\n mode: 'rgb',\n r: color.r,\n g: color.g,\n b: color.b,\n alpha: color.a\n })\n}\n\nexport function resolveOkHCLForPreview(\n color: OkHCLColor,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const oklch = normalizeOkLCH(color)\n const targetSpace = resolveTargetSpace(options)\n\n if (targetSpace === 'display-p3') {\n const clipped = !isDisplayableP3(oklch)\n const p3 = toP3(toDisplayableP3(oklch))\n // P3 coordinates, because the caller asked for a P3 target.\n const resolved = normalizeColor({\n r: p3.r,\n g: p3.g,\n b: p3.b,\n a: p3.alpha ?? oklch.alpha\n })\n\n return {\n color: resolved,\n cssColor: formatCss({\n mode: 'p3',\n r: p3.r,\n g: p3.g,\n b: p3.b,\n alpha: p3.alpha ?? oklch.alpha\n }),\n sourceSpace: 'oklch',\n targetSpace,\n clipped\n }\n }\n\n const clipped = !isDisplayableRGB(oklch)\n const rgb = toRGB(toDisplayableRGB(oklch))\n const resolved = normalizeColor({\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: rgb.alpha ?? oklch.alpha\n })\n\n return {\n color: resolved,\n cssColor: formatRgb({\n mode: 'rgb',\n r: resolved.r,\n g: resolved.g,\n b: resolved.b,\n alpha: resolved.a\n }),\n sourceSpace: 'oklch',\n targetSpace,\n clipped\n }\n}\n\n/**\n * A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing\n * chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing\n * (`none`) component reads as zero. Null when `input` is not a color.\n */\nexport function parseDisplayableColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n // Mapping through OKLCH shifts colors already in sRGB by float noise, so only map the rest.\n const rgb = isDisplayableRGB(parsed) ? toRGB(parsed) : toDisplayableRGB(parsed)\n // culori leaves a `none` channel out, which normalizing reads as zero.\n return normalizeColor({ r: rgb.r, g: rgb.g, b: rgb.b, a: parsed.alpha })\n}\n\nexport function resolveRGBAForPreview(\n color: Color,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const documentColorSpace = options?.documentColorSpace ?? DEFAULT_COLOR_SPACE\n const targetSpace = options?.colorSpace ?? documentColorSpace\n const resolved = convertComponents(normalizeColor(color), documentColorSpace, targetSpace)\n return {\n color: resolved,\n cssColor: formatCSSForTarget(resolved, targetSpace),\n sourceSpace: 'srgb',\n targetSpace,\n clipped: targetSpace !== documentColorSpace && isOutsideGamut(resolved, targetSpace)\n }\n}\n\nexport function resolveNodeFillColor(\n fill: Fill,\n fillIndex: number,\n node: SceneNode,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const okhcl = getFillOkHCL(node, fillIndex)?.color\n if (okhcl) return resolveOkHCLForPreview(okhcl, options)\n return resolveRGBAForPreview(fill.color, options)\n}\n\nexport function resolveNodeStrokeColor(\n stroke: Stroke,\n strokeIndex: number,\n node: SceneNode,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const okhcl = getStrokeOkHCL(node, strokeIndex)?.color\n if (okhcl) return resolveOkHCLForPreview(okhcl, options)\n return resolveRGBAForPreview(stroke.color, options)\n}\n\nexport function colorToDisplayCSS(color: Color, options?: ColorPreviewOptions): string {\n return resolveRGBAForPreview(color, options).cssColor\n}\n\nexport function getDefaultRenderColorSpace(): RenderColorSpace {\n return DEFAULT_COLOR_SPACE\n}\n","export * from './contrast'\nexport * from './management'\nexport { normalizeColor } from './normalize'\nexport * from './okhcl'\n\nimport { parse, formatHex, formatHex8, formatRgb, converter, differenceEuclidean } from 'culori'\n\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\n\nconst toRGB = converter('rgb')\n\n/** A CSS color, or null when `input` is not one. */\nexport function tryParseColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n const rgb = toRGB(parsed)\n return {\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: parsed.alpha ?? 1\n }\n}\n\n/** A CSS color, or black when `input` is not one. */\nexport function parseColor(input: string): Color {\n return tryParseColor(input) ?? { ...BLACK }\n}\n\nexport function colorToHex(color: Color): string {\n return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()\n}\n\nexport function colorToHex8(color: Color, alpha?: number): string {\n const a = alpha ?? color.a\n if (a >= 1) return colorToHex(color)\n return formatHex8({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: a }).toUpperCase()\n}\n\nexport function colorToHexRaw(color: Color): string {\n return colorToHex(color).slice(1)\n}\n\nexport function colorToRgba255(color: Color) {\n return {\n r: Math.round(color.r * 255),\n g: Math.round(color.g * 255),\n b: Math.round(color.b * 255),\n a: color.a\n }\n}\n\nexport function colorToCSS(color: Color): string {\n return formatRgb({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nexport function colorToCSSCompact(color: Color): string {\n const { r, g, b } = colorToRgba255(color)\n const a = Number(color.a.toFixed(3))\n if (a >= 1) return `rgb(${r},${g},${b})`\n return `rgba(${r},${g},${b},${a})`\n}\n\nexport function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {\n return { r: r / 255, g: g / 255, b: b / 255, a }\n}\n\nexport function colorToFill(color: string | Color) {\n const rgba = typeof color === 'string' ? parseColor(color) : color\n return {\n type: 'SOLID' as const,\n color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },\n opacity: rgba.a,\n visible: true\n }\n}\n\nconst euclideanRGB255 = differenceEuclidean('rgb')\n\nexport function colorDistance(c1: Color, c2: Color): number {\n return (\n euclideanRGB255(\n { mode: 'rgb', r: c1.r, g: c1.g, b: c1.b },\n { mode: 'rgb', r: c2.r, g: c2.g, b: c2.b }\n ) * 255\n )\n}\n"],"mappings":";;;;;;AAIA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,KAAK,KAAM;AAC/B;AAEA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,MAAO,KAAK;AAChC;AAEA,SAAgB,YAAY,IAAY,IAAY,IAAY,IAAY,KAAqB;CAC/F,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;EACtC,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;CACxC;AACF;AAEA,SAAgB,eACd,IACA,IACA,I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,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAClC;AAEA,SAAgB,eAAe,GAAW,GAAW,GAAW,IAAI,GAAU;CAC5E,OAAO;EAAE,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK;CAAE;AACjD;AAEA,SAAgB,YAAY,OAAuB;CACjD,MAAM,OAAO,OAAO,UAAU,WAAW,WAAW,KAAK,IAAI;CAC7D,OAAO;EACL,MAAM;EACN,OAAO;GAAE,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;EAAE;EACpD,SAAS,KAAK;EACd,SAAS;CACX;AACF;AAEA,MAAM,kBAAkB,oBAAoB,KAAK;AAEjD,SAAgB,cAAc,IAAW,IAAmB;CAC1D,OACE,gBACE;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,GACzC;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,CAC3C,IAAI;AAER"}
1
+ {"version":3,"file":"index.js","names":["toRGB","toP3","toDisplayableRGB","toDisplayableP3","toRGB"],"sources":["../../../src/geometry.ts","../../../src/instance-overrides.ts","../../../src/node-defaults.ts","../../../src/vector-network.ts","../../../src/copy.ts","../../../src/color/normalize.ts","../../../src/color/okhcl.ts","../../../src/color/management.ts","../../../src/color/index.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Effect, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './index'\nimport type { Rect, Vector } from './primitives'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/** A layer's stroke join and miter limit, for the tips mitered path corners reach. */\nexport interface StrokeCorners {\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n corners?: StrokeCorners\n): number {\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n let extra = 0\n if (stroke.align === 'OUTSIDE') extra = stroke.weight\n else if (stroke.align === 'CENTER') extra = stroke.weight / 2\n const miter = network\n ? miterRatio(network, stroke.join ?? corners?.strokeJoin, corners?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n return Math.max(overflow, arrowCapOverflow(strokes, fallbackCap, network))\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = effect.radius + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<\n {\n id: string\n width: number\n height: number\n rotation?: number\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n } & StrokeCorners\n >,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\nfunction transformLocalPoint(node: VisualBoundsNode, point: Vector): Vector {\n let x = node.flipX ? node.width - point.x : point.x\n let y = node.flipY ? node.height - point.y : point.y\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n return { x, y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = getAbsolutePosition(node.id)\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n if (node.type === 'TEXT' && node.textDecoration && node.textDecoration !== 'NONE') {\n const fontSize = node.fontSize ?? 14\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n bounds.maxY += underlineOffset + thickness + fontSize * 0.35\n }\n\n return bounds\n}\n\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n const abs = getAbsolutePosition(node.id)\n const nodeClip = {\n minX: abs.x,\n minY: abs.y,\n maxX: abs.x + node.width,\n maxY: abs.y + node.height\n }\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n\n// ── Rotated-rectangle clipping ──\n\nfunction crossProduct(a: Vector, b: Vector, p: Vector): number {\n return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x)\n}\n\nfunction lineSegmentIntersect(p1: Vector, p2: Vector, p3: Vector, p4: Vector): Vector {\n const dx1 = p2.x - p1.x\n const dy1 = p2.y - p1.y\n const dx2 = p4.x - p3.x\n const dy2 = p4.y - p3.y\n const denom = dx1 * dy2 - dy1 * dx2\n if (denom === 0) return p1\n const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom\n return { x: p1.x + t * dx1, y: p1.y + t * dy1 }\n}\n\nfunction clipHalfPlane(polygon: Vector[], a: Vector, b: Vector, wantPositive: boolean): Vector[] {\n const output: Vector[] = []\n const isInside = (p: Vector): boolean => {\n const cross = crossProduct(a, b, p)\n return wantPositive ? cross >= 0 : cross <= 0\n }\n for (let i = 0; i < polygon.length; i++) {\n const curr = polygon[i]\n const prev = polygon[i === 0 ? polygon.length - 1 : i - 1]\n const currInside = isInside(curr)\n const prevInside = isInside(prev)\n if (currInside) {\n if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b))\n output.push(curr)\n } else if (prevInside) {\n output.push(lineSegmentIntersect(prev, curr, a, b))\n }\n }\n return output\n}\n\n/**\n * Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space\n * corners of a rotated clipping ancestor).\n *\n * Uses Sutherland–Hodgman polygon clipping with centroid-based interior\n * detection, making it robust to either winding order of the clip polygon.\n * Returns the clipped polygon, or null if the subject is fully outside the\n * clip polygon. When `clipCorners` has fewer than 3 points the subject is\n * returned unchanged (no clipping).\n *\n * Preserving the polygon (rather than collapsing to an AABB) lets callers\n * chain multiple clips without reintroducing corners removed by an inner clip.\n */\nexport function clipPolygon(subject: Vector[], clipCorners: Vector[]): Vector[] | null {\n if (clipCorners.length < 3) return subject\n\n let cx = 0\n let cy = 0\n for (const c of clipCorners) {\n cx += c.x\n cy += c.y\n }\n cx /= clipCorners.length\n cy /= clipCorners.length\n\n let polygon: Vector[] = subject\n\n for (let i = 0; i < clipCorners.length; i++) {\n if (polygon.length === 0) return null\n const a = clipCorners[i]\n const b = clipCorners[(i + 1) % clipCorners.length]\n const centroidCross = crossProduct(a, b, { x: cx, y: cy })\n polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0)\n }\n\n return polygon.length === 0 ? null : polygon\n}\n\n/**\n * Clip an axis-aligned VisualBounds rectangle against a convex polygon\n * (e.g. the 4 canvas-space corners of a rotated clipping ancestor).\n *\n * Returns the AABB of the intersection, or null if the bounds are fully\n * outside the clip polygon. Delegates to {@link clipPolygon}.\n *\n * For a non-rotated clip (axis-aligned corners) the result is identical\n * to `intersectVisualBounds`.\n */\nexport function clipBoundsToPolygon(\n bounds: VisualBounds,\n clipCorners: Vector[]\n): VisualBounds | null {\n if (clipCorners.length < 3) return bounds\n\n const subject: Vector[] = [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n { x: bounds.minX, y: bounds.maxY }\n ]\n\n const polygon = clipPolygon(subject, clipCorners)\n if (!polygon) return null\n\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (const p of polygon) {\n if (p.x < minX) minX = p.x\n if (p.y < minY) minY = p.y\n if (p.x > maxX) maxX = p.x\n if (p.y > maxY) maxY = p.y\n }\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n","export type InstanceOverrideField = string\n\nexport interface InstanceOverrideState {\n self: Map<InstanceOverrideField, unknown>\n descendants: Map<string, Map<InstanceOverrideField, unknown>>\n}\n\nexport function createInstanceOverrideState(): InstanceOverrideState {\n return { self: new Map(), descendants: new Map() }\n}\n\nexport interface SerializedOverrideValue {\n defined: boolean\n value?: unknown\n}\n\nexport interface SerializedInstanceOverrideState {\n self: Array<[InstanceOverrideField, SerializedOverrideValue]>\n descendants: Array<[string, Array<[InstanceOverrideField, SerializedOverrideValue]>]>\n}\n\nfunction serializeOverrideValue(value: unknown): SerializedOverrideValue {\n return value === undefined ? { defined: false } : { defined: true, value }\n}\n\nfunction deserializeOverrideValue(value: unknown): { valid: boolean; value: unknown } {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return { valid: false, value: undefined }\n }\n if (!('defined' in value) || typeof value.defined !== 'boolean') {\n return { valid: false, value: undefined }\n }\n if (value.defined) {\n return 'value' in value\n ? { valid: true, value: value['value'] }\n : { valid: false, value: undefined }\n }\n return { valid: true, value: undefined }\n}\n\nfunction deserializeEntries(value: unknown): Map<InstanceOverrideField, unknown> {\n const result = new Map<InstanceOverrideField, unknown>()\n if (!Array.isArray(value)) return result\n for (const entry of value) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n const decoded = deserializeOverrideValue(entry[1])\n if (decoded.valid) result.set(entry[0], decoded.value)\n }\n return result\n}\n\nexport function serializeInstanceOverrideState(\n state: InstanceOverrideState\n): SerializedInstanceOverrideState {\n return {\n self: [...state.self].map(([field, value]) => [field, serializeOverrideValue(value)]),\n descendants: [...state.descendants].map(([nodeId, fields]) => [\n nodeId,\n [...fields].map(([field, value]) => [field, serializeOverrideValue(value)])\n ])\n }\n}\n\nexport function deserializeInstanceOverrideState(state: unknown): InstanceOverrideState {\n if (!state || typeof state !== 'object' || Array.isArray(state)) {\n return createInstanceOverrideState()\n }\n const self =\n 'self' in state ? deserializeEntries(state.self) : new Map<InstanceOverrideField, unknown>()\n const descendants = new Map<string, Map<InstanceOverrideField, unknown>>()\n if ('descendants' in state && Array.isArray(state.descendants)) {\n for (const entry of state.descendants) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n descendants.set(entry[0], deserializeEntries(entry[1]))\n }\n }\n return { self, descendants }\n}\n\nexport function cloneInstanceOverrideState(state: InstanceOverrideState): InstanceOverrideState {\n return {\n self: new Map([...state.self].map(([field, value]) => [field, structuredClone(value)])),\n descendants: new Map(\n [...state.descendants].map(([id, fields]) => [\n id,\n new Map([...fields].map(([field, value]) => [field, structuredClone(value)]))\n ])\n )\n }\n}\n\nexport interface InstanceOverrideReferenceMapper {\n node: (id: string) => string\n variable: (id: string) => string\n}\n\n/** Remap runtime identities only; ordinary strings and source-format payloads stay opaque. */\nexport function remapInstanceOverrideState(\n state: InstanceOverrideState,\n references: InstanceOverrideReferenceMapper\n): InstanceOverrideState {\n const remapValue = (field: string, value: unknown): unknown => {\n if (typeof value !== 'string') return structuredClone(value)\n if (field === 'componentId' || field === 'sourceComponentId') return references.node(value)\n if (field.startsWith('boundVariables/')) return references.variable(value)\n return value\n }\n const fields = (entries: ReadonlyMap<string, unknown>) =>\n new Map([...entries].map(([field, value]) => [field, remapValue(field, value)]))\n const descendants = new Map<string, Map<string, unknown>>()\n for (const [id, entries] of state.descendants) {\n const mapped = references.node(id)\n if (descendants.has(mapped)) throw new Error(`Duplicate remapped override target ${mapped}`)\n descendants.set(mapped, fields(entries))\n }\n return { self: fields(state.self), descendants }\n}\n\nexport function getInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): unknown {\n return nodeId === instanceId ? state.self.get(field) : state.descendants.get(nodeId)?.get(field)\n}\n\nexport function hasInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n return fields?.has(field) ?? false\n}\n\nexport function setInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField,\n value: unknown = true\n): void {\n if (nodeId === instanceId) {\n state.self.set(field, value)\n return\n }\n const fields = state.descendants.get(nodeId) ?? new Map<string, unknown>()\n fields.set(field, value)\n state.descendants.set(nodeId, fields)\n}\n\nexport function deleteInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n if (!fields?.delete(field)) return false\n if (nodeId !== instanceId && fields.size === 0) state.descendants.delete(nodeId)\n return true\n}\n\nexport function clearInstanceOverrides(state: InstanceOverrideState): void {\n state.self.clear()\n state.descendants.clear()\n}\n\nexport function forEachInstanceOverride(\n state: InstanceOverrideState,\n callback: (nodeId: string, field: InstanceOverrideField, value: unknown) => void\n): void {\n for (const [field, value] of state.self) callback('', field, value)\n for (const [nodeId, fields] of state.descendants) {\n for (const [field, value] of fields) callback(nodeId, field, value)\n }\n}\n","import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { createInstanceOverrideState } from './instance-overrides'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n return {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: 0,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n pluginData: [],\n pluginRelaunchData: [],\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined,\n ...overrides\n } satisfies CompleteNodeFields\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n","import { isEqual } from 'es-toolkit/predicate'\n\nimport type { Mat3 } from './matrix'\nimport type { Vector } from './primitives'\nimport type { VectorNetwork, VectorSegment } from './types'\n\n/** Concatenate vector networks while preserving independent geometry. */\nexport function mergeVectorNetworks(networks: readonly VectorNetwork[]): VectorNetwork {\n const vertices: VectorNetwork['vertices'] = []\n const segments: VectorNetwork['segments'] = []\n const regions: VectorNetwork['regions'] = []\n let vertexOffset = 0\n let segmentOffset = 0\n\n for (const network of networks) {\n for (const vertex of network.vertices) vertices.push({ ...vertex })\n for (const segment of network.segments) {\n segments.push({\n ...segment,\n start: segment.start + vertexOffset,\n end: segment.end + vertexOffset,\n tangentStart: { ...segment.tangentStart },\n tangentEnd: { ...segment.tangentEnd }\n })\n }\n for (const region of network.regions) {\n const loops: number[][] = []\n for (const loop of region.loops) {\n const shifted: number[] = []\n for (const segmentIndex of loop) shifted.push(segmentIndex + segmentOffset)\n loops.push(shifted)\n }\n regions.push({ windingRule: region.windingRule, loops })\n }\n vertexOffset += network.vertices.length\n segmentOffset += network.segments.length\n }\n\n return { vertices, segments, regions }\n}\n\n/**\n * Map a VectorNetwork through an affine matrix: vertices as points,\n * tangents as direction vectors (linear part only, no translation).\n * Returns a deep copy; the input is not mutated.\n */\nexport function transformVectorNetwork(m: Mat3, vn: VectorNetwork): VectorNetwork {\n const mapVector = (v: Vector): Vector => ({\n x: m[0] * v.x + m[1] * v.y,\n y: m[3] * v.x + m[4] * v.y\n })\n return {\n vertices: vn.vertices.map((v) => ({\n ...v,\n x: m[0] * v.x + m[1] * v.y + m[2],\n y: m[3] * v.x + m[4] * v.y + m[5]\n })),\n segments: vn.segments.map((s) => ({\n ...s,\n tangentStart: mapVector(s.tangentStart),\n tangentEnd: mapVector(s.tangentEnd)\n })),\n regions: vn.regions.map((r) => ({\n windingRule: r.windingRule,\n loops: r.loops.map((l) => [...l])\n }))\n }\n}\n\n/** Structural equality of two VectorNetworks (order-sensitive, exact values). */\nexport function vectorNetworksEqual(a: VectorNetwork, b: VectorNetwork): boolean {\n return (\n isEqual(a.vertices, b.vertices) &&\n isEqual(a.segments, b.segments) &&\n isEqual(a.regions, b.regions)\n )\n}\n\n/** Deep-copy a VectorNetwork, stripping any Vue Proxy wrappers. */\nexport function cloneVectorNetwork(vn: VectorNetwork): VectorNetwork {\n return {\n vertices: vn.vertices.map((v) => ({ ...v })),\n segments: vn.segments.map((s) => ({\n ...s,\n tangentStart: { ...s.tangentStart },\n tangentEnd: { ...s.tangentEnd }\n })),\n regions: vn.regions.map((r) => ({\n windingRule: r.windingRule,\n loops: r.loops.map((l) => [...l])\n }))\n }\n}\n\n/**\n * Validate a VectorNetwork structure, returning an array of error messages.\n * Empty array means the network is valid.\n */\nexport function validateVectorNetwork(value: unknown): string[] {\n if (!isRecord(value)) return ['network must be an object']\n if (!Array.isArray(value.vertices)) return ['vertices must be an array']\n if (!Array.isArray(value.segments)) return ['segments must be an array']\n\n const errors: string[] = []\n validateVertices(value.vertices, errors)\n validateSegments(value.segments, value.vertices.length, errors)\n const typedSegments = value.segments.filter(isSegmentRecord)\n if (value.regions !== undefined) {\n if (Array.isArray(value.regions)) {\n validateRegions(\n value.regions,\n value.segments.length,\n typedSegments.length === value.segments.length ? typedSegments : null,\n errors\n )\n } else {\n errors.push('regions must be an array when provided')\n }\n }\n return errors\n}\n\nfunction validateVertices(vertices: unknown[], errors: string[]): void {\n for (let index = 0; index < vertices.length; index++) {\n if (!isFiniteVector(vertices[index])) {\n errors.push(`vertex[${index}]: x and y must be finite numbers`)\n }\n }\n}\n\nfunction validateSegments(segments: unknown[], vertexCount: number, errors: string[]): void {\n for (let index = 0; index < segments.length; index++) {\n const segment = segments[index]\n if (!isRecord(segment)) {\n errors.push(`segment[${index}] must be an object`)\n continue\n }\n if (!isInteger(segment.start) || !isInteger(segment.end)) {\n errors.push(`segment[${index}]: start and end must be integers`)\n continue\n }\n if (segment.start < 0 || segment.start >= vertexCount) {\n errors.push(`segment[${index}]: start index ${segment.start} out of range`)\n }\n if (segment.end < 0 || segment.end >= vertexCount) {\n errors.push(`segment[${index}]: end index ${segment.end} out of range`)\n }\n validateSegmentTangents(segment, index, errors)\n }\n}\n\nfunction validateSegmentTangents(\n segment: Record<string, unknown>,\n index: number,\n errors: string[]\n): void {\n for (const tangentKey of ['tangentStart', 'tangentEnd'] as const) {\n const tangent = segment[tangentKey]\n if (tangent !== undefined && !isFiniteVector(tangent)) {\n errors.push(`segment[${index}]: ${tangentKey} must contain finite x and y numbers`)\n }\n }\n}\n\nfunction validateRegions(\n regions: unknown[],\n segmentCount: number,\n segments: Array<Record<'start' | 'end', number>> | null,\n errors: string[]\n): void {\n for (let regionIndex = 0; regionIndex < regions.length; regionIndex++) {\n const region = regions[regionIndex]\n if (!isRecord(region) || !Array.isArray(region.loops)) {\n errors.push(`region[${regionIndex}]: loops must be an array`)\n continue\n }\n if (region.windingRule !== 'NONZERO' && region.windingRule !== 'EVENODD') {\n errors.push(`region[${regionIndex}]: windingRule must be NONZERO or EVENODD`)\n }\n if (region.loops.length === 0) {\n errors.push(`region[${regionIndex}]: loops must contain at least one loop`)\n }\n validateRegionLoops(region.loops, regionIndex, segmentCount, segments, errors)\n }\n}\n\nfunction validateRegionLoops(\n loops: unknown[],\n regionIndex: number,\n segmentCount: number,\n segments: Array<Record<'start' | 'end', number>> | null,\n errors: string[]\n): void {\n for (let loopIndex = 0; loopIndex < loops.length; loopIndex++) {\n const loop = loops[loopIndex]\n if (!Array.isArray(loop)) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] must be an array`)\n continue\n }\n if (loop.length === 0) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] must contain at least one segment`)\n continue\n }\n\n const segmentIndices: number[] = []\n for (const segmentIndex of loop) {\n if (!isInteger(segmentIndex) || segmentIndex < 0 || segmentIndex >= segmentCount) {\n errors.push(\n `region[${regionIndex}].loop[${loopIndex}]: segment index ${String(segmentIndex)} out of range`\n )\n } else {\n segmentIndices.push(segmentIndex)\n }\n }\n if (segmentIndices.length !== loop.length) continue\n if (new Set(segmentIndices).size !== segmentIndices.length) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] must not repeat segments`)\n continue\n }\n if (segments && !formsContinuousChain(segmentIndices, segments)) {\n errors.push(`region[${regionIndex}].loop[${loopIndex}] segments must form a continuous chain`)\n }\n }\n}\n\nfunction formsContinuousChain(\n indices: number[],\n segments: Array<Record<'start' | 'end', number>>\n): boolean {\n if (indices.length <= 1) return true\n const first = segments[indices[0]]\n return followsChain(indices, segments, first.end) || followsChain(indices, segments, first.start)\n}\n\nfunction followsChain(\n indices: number[],\n segments: Array<Record<'start' | 'end', number>>,\n initialEnd: number\n): boolean {\n let current = initialEnd\n for (let index = 1; index < indices.length; index++) {\n const segment = segments[indices[index]]\n if (segment.start === current) current = segment.end\n else if (segment.end === current) current = segment.start\n else return false\n }\n return true\n}\n\nfunction isSegmentRecord(value: unknown): value is Record<'start' | 'end', number> {\n return isRecord(value) && isInteger(value.start) && isInteger(value.end)\n}\n\nfunction isFiniteVector(value: unknown): value is Vector {\n return (\n isRecord(value) &&\n typeof value.x === 'number' &&\n Number.isFinite(value.x) &&\n typeof value.y === 'number' &&\n Number.isFinite(value.y)\n )\n}\n\nfunction isInteger(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value)\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n\nexport type NormalizableVectorNetwork = Omit<VectorNetwork, 'regions'> & {\n regions?: VectorNetwork['regions']\n}\n\n/**\n * Ensure every segment has tangentStart/tangentEnd and a regions array.\n * Missing tangents default to {x:0, y:0} (straight line segments).\n * Use at system boundaries where input may come from JSON/MCP.\n */\nexport function normalizeVectorNetwork(vn: NormalizableVectorNetwork): VectorNetwork {\n const ZERO: Vector = { x: 0, y: 0 }\n return {\n vertices: vn.vertices,\n segments: vn.segments.map((s) => ({\n start: s.start,\n end: s.end,\n tangentStart: (s as Partial<VectorSegment>).tangentStart ?? { ...ZERO },\n tangentEnd: (s as Partial<VectorSegment>).tangentEnd ?? { ...ZERO }\n })),\n regions: vn.regions ?? []\n }\n}\n","/**\n * Typed shallow-copy helpers for Fill, Stroke, Effect, and StyleRun.\n *\n * These replace `structuredClone` for known scene-graph array types,\n * avoiding the ~24× overhead of the generic deep-clone algorithm.\n * Each helper spreads the top-level object and any nested objects\n * (color, offset, gradientStops, dashPattern, style) to ensure\n * no shared references between source and copy.\n */\n\nimport type {\n ArcData,\n ComponentPropertyDefinition,\n Effect,\n DerivedTextGlyph,\n Fill,\n GeometryPath,\n GradientStop,\n LayoutGrid,\n SceneNode,\n Stroke,\n StyleRun\n} from './'\nimport { geometryCommandCoordCount } from './geometry'\nimport { cloneInstanceOverrideState } from './instance-overrides'\nimport { createDefaultSourceMetadata } from './node-defaults'\nimport { cloneVectorNetwork } from './vector-network'\n\n// --- Individual copy functions ---\n\n/** Generic over the paint shape so a stroke keeps its own fields while the paint deep-copies. */\nexport function copyFill<T extends Fill>(f: T): T {\n const copy: T = { ...f, color: { ...f.color } }\n if (f.gradientStops) copy.gradientStops = f.gradientStops.map(copyGradientStop)\n if (f.gradientTransform) copy.gradientTransform = { ...f.gradientTransform }\n if (f.imageTransform) copy.imageTransform = { ...f.imageTransform }\n if (f.patternSpacing) copy.patternSpacing = { ...f.patternSpacing }\n if (f.noiseSize) copy.noiseSize = { ...f.noiseSize }\n return copy\n}\n\nexport function copyStroke(s: Stroke): Stroke {\n const copy = copyFill(s)\n if (s.dashPattern) {\n copy.dashPattern = [...s.dashPattern]\n }\n return copy\n}\n\nexport function copyEffect(e: Effect): Effect {\n return {\n ...e,\n color: { ...e.color },\n offset: { ...e.offset }\n }\n}\n\nexport function copyStyleRun(r: StyleRun): StyleRun {\n const copy: StyleRun = {\n ...r,\n style: {\n ...r.style,\n fills: r.style.fills ? r.style.fills.map(copyFill) : undefined,\n textDecorationFills: r.style.textDecorationFills\n ? r.style.textDecorationFills.map(copyFill)\n : undefined,\n fontVariations: r.style.fontVariations\n ? r.style.fontVariations.map((v) => ({ ...v }))\n : undefined,\n fontFeatures: r.style.fontFeatures ? r.style.fontFeatures.map((v) => ({ ...v })) : undefined\n }\n }\n if (r.style.hyperlink) copy.style.hyperlink = { ...r.style.hyperlink }\n if (r.style.boundVariables) copy.style.boundVariables = { ...r.style.boundVariables }\n return copy\n}\n\n// --- Array copy functions ---\n\nconst internalCopySources = new WeakMap<object, object>()\n\n/** Record immutable lineage for an internal deep copy without sharing mutable values. */\nexport function markCopySource<T extends object>(source: T, copy: T): T {\n internalCopySources.set(copy, internalCopySources.get(source) ?? source)\n return copy\n}\n\n/** Compare internal deep copies in O(1) without traversing large paint or text payloads. */\nexport function hasSameCopySource(left: object, right: object): boolean {\n if (left === right) return true\n return (internalCopySources.get(left) ?? left) === (internalCopySources.get(right) ?? right)\n}\n\nexport function copyFills(fills: Fill[]): Fill[] {\n return fills.map(copyFill)\n}\n\nexport function copyStrokes(strokes: Stroke[]): Stroke[] {\n return strokes.map(copyStroke)\n}\n\nexport function copyEffects(effects: Effect[]): Effect[] {\n return effects.map(copyEffect)\n}\n\nexport function copyLayoutGrids(grids: LayoutGrid[]): LayoutGrid[] {\n return grids.map((grid) => ({ ...grid, color: grid.color ? { ...grid.color } : undefined }))\n}\n\nexport function copyStyleRuns(runs: StyleRun[]): StyleRun[] {\n return runs.map(copyStyleRun)\n}\n\n/** Keep path-level fills across copy/scale/transform (resize snapshots). */\nfunction withPathPaintMeta(path: GeometryPath, commandsBlob: Uint8Array): GeometryPath {\n return {\n windingRule: path.windingRule,\n commandsBlob,\n ...(path.fills ? { fills: copyFills(path.fills) } : {})\n }\n}\n\nexport function copyGeometryPaths(paths: GeometryPath[]): GeometryPath[] {\n return paths.map((p) => withPathPaintMeta(p, p.commandsBlob.slice()))\n}\n\n/**\n * Affine-transform every coordinate pair in a path command blob (returns a\n * copy): (x, y) → (m00·x + m01·y + tx, m10·x + m11·y + ty).\n * Command layout: 1=move/2=line (1 pair), 3=quad (2 pairs), 4=cubic (3 pairs)\n * — font-glyph blobs are quad-heavy, so skipping command 3 desyncs the walk.\n */\nexport function transformGeometryBlob(\n blob: Uint8Array,\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): Uint8Array {\n const out = blob.slice()\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength)\n let offset = 0\n while (offset < out.length) {\n const command = out[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > out.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n dv.setFloat32(offset, m00 * x + m01 * y + tx, true)\n dv.setFloat32(offset + 4, m10 * x + m11 * y + ty, true)\n offset += 8\n }\n }\n return out\n}\n\nexport function transformGeometryPaths(\n paths: GeometryPath[],\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): GeometryPath[] {\n return paths.map((g) =>\n withPathPaintMeta(g, transformGeometryBlob(g.commandsBlob, m00, m01, m10, m11, tx, ty))\n )\n}\n\n/**\n * Scale path command blob coordinates by (sx, sy).\n * Identity scale returns a deep copy (same as copyGeometryPaths).\n */\nexport function scaleGeometryPaths(paths: GeometryPath[], sx: number, sy: number): GeometryPath[] {\n if (sx === 1 && sy === 1) return copyGeometryPaths(paths)\n return transformGeometryPaths(paths, sx, 0, 0, sy)\n}\n\n// --- Internal helpers ---\n\n/** Copy an optional array: non-empty → mapped, empty → [], undefined → undefined. */\nfunction copyOpt<T, U>(arr: T[] | undefined, fn: (arr: T[]) => U[]): U[] | undefined {\n if (arr === undefined) return undefined\n return arr.length > 0 ? fn(arr) : []\n}\n\nfunction copyGradientStop(gs: GradientStop): GradientStop {\n return { color: { ...gs.color }, position: gs.position }\n}\n\nfunction copySpread<T extends object>(arr: T[] | undefined): T[] {\n return arr?.map((item) => ({ ...item })) ?? []\n}\n\nfunction copyPropertyDefs(\n defs: ComponentPropertyDefinition[] | undefined\n): ComponentPropertyDefinition[] {\n return (\n defs?.map((d) => ({\n ...d,\n variantOptions: d.variantOptions ? [...d.variantOptions] : undefined,\n preferredValues: d.preferredValues ? [...d.preferredValues] : undefined,\n slotSettings: d.slotSettings ? { ...d.slotSettings } : undefined\n })) ?? []\n )\n}\n\n/** Deep-copy path-text glyphs (fresh commandsBlob buffers). */\nexport function copyDerivedGlyphs(glyphs: DerivedTextGlyph[] | null): DerivedTextGlyph[] | null {\n return glyphs ? glyphs.map((g) => ({ ...g, commandsBlob: new Uint8Array(g.commandsBlob) })) : null\n}\n\n// --- Complex structure copy functions ---\n// These replace structuredClone for known types, avoiding its ~24× overhead.\n\nfunction copyArcData(a: ArcData): ArcData {\n return { startingAngle: a.startingAngle, endingAngle: a.endingAngle, innerRadius: a.innerRadius }\n}\n\n// --- Deep-copy clone props ---\n\n/**\n * Build the init props for a deep-copy clone of `src`.\n * Shares logic between SceneGraph.cloneTree and instance child cloning.\n * Explicitly deep-copies all mutable object/array fields that `...rest`\n * would otherwise share by reference. When adding a mutable SceneNode field,\n * add its copy behavior here or document why sharing is intentional.\n */\nexport type NodeCloneMode = 'deep' | 'fig-import'\n\nexport function cloneNodeProps(\n src: SceneNode,\n componentId: string | null,\n mode: NodeCloneMode = 'deep'\n): Partial<SceneNode> {\n const { id: _, parentId: _p, childIds: _c, ...rest } = src\n if (mode === 'fig-import') {\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n source: createDefaultSourceMetadata(),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n\n componentPropertyValues: { ...src.componentPropertyValues }\n }\n }\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n fills: copyOpt(src.fills, (value) => markCopySource(value, copyFills(value))),\n\n strokes: copyOpt(src.strokes, (value) => markCopySource(value, copyStrokes(value))),\n effects: copyOpt(src.effects, (value) => markCopySource(value, copyEffects(value))),\n layoutGrids: copyOpt(src.layoutGrids, copyLayoutGrids),\n guides: copyOpt(src.guides, (guides) => guides.map((guide) => ({ ...guide }))),\n styleRuns: copyOpt(src.styleRuns, (value) => markCopySource(value, copyStyleRuns(value))),\n // Generated instance descendants have no independent Figma provenance. Retaining the source\n // component's opaque raw payload here duplicates megabytes of metadata per instance.\n source: componentId === null ? structuredClone(src.source) : createDefaultSourceMetadata(),\n dashPattern: copyOpt(src.dashPattern, (a) => [...a]),\n fontVariations: copyOpt(src.fontVariations, (a) => a.map((v) => ({ ...v }))),\n fontFeatures: copyOpt(src.fontFeatures, (a) => a.map((v) => ({ ...v }))),\n textParagraphs: copyOpt(src.textParagraphs, (a) => a.map((v) => ({ ...v }))),\n textDecorationFills: copyOpt(src.textDecorationFills, copyFills),\n fillGeometry: copyOpt(src.fillGeometry, copyGeometryPaths),\n strokeGeometry: copyOpt(src.strokeGeometry, copyGeometryPaths),\n gridTemplateColumns: copySpread(src.gridTemplateColumns),\n gridTemplateRows: copySpread(src.gridTemplateRows),\n componentPropertyDefinitions: copyPropertyDefs(src.componentPropertyDefinitions),\n componentPropertyReferences: copySpread(src.componentPropertyReferences),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n symbolLinks: copySpread(src.symbolLinks),\n variantPropSpecs: copySpread(src.variantPropSpecs),\n pluginData: copySpread(src.pluginData),\n pluginRelaunchData: copySpread(src.pluginRelaunchData),\n exportSettings: copySpread(src.exportSettings),\n componentPropertyValues: { ...src.componentPropertyValues },\n derivedLayout: src.derivedLayout ? { ...src.derivedLayout } : null,\n arcData: src.arcData ? copyArcData(src.arcData) : null,\n vectorNetwork: src.vectorNetwork ? cloneVectorNetwork(src.vectorNetwork) : null,\n textPicture: src.textPicture ? new Uint8Array(src.textPicture) : null,\n derivedTextGlyphs: src.derivedTextGlyphs\n ? markCopySource(src.derivedTextGlyphs, copyDerivedGlyphs(src.derivedTextGlyphs) ?? [])\n : null,\n textPathData: src.textPathData ? structuredClone(src.textPathData) : null,\n textPathBox: src.textPathBox ? { ...src.textPathBox } : null,\n gridPosition: src.gridPosition ? { ...src.gridPosition } : null,\n targetAspectRatio: src.targetAspectRatio ? { ...src.targetAspectRatio } : null\n }\n}\n","import { BLACK } from '../constants'\nimport type { Color } from '../primitives'\n\nexport function normalizeColor(color?: Partial<Color>): Color {\n if (!color) return { ...BLACK }\n return { r: color.r ?? 0, g: color.g ?? 0, b: color.b ?? 0, a: color.a ?? 1 }\n}\n","import { converter, toGamut } from 'culori'\n\nimport { copyFill, copyStroke } from '../copy'\nimport { readAllPluginData, withAllPluginData } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { Color } from '../primitives'\nimport type { PluginDataEntry, SceneNode } from '../types'\nimport { normalizeColor } from './normalize'\n\nexport interface OkHCLColor {\n h: number\n c: number\n l: number\n a?: number\n}\n\nexport interface OkHCLPayload {\n version: 1\n kind: 'fill' | 'stroke'\n index: number\n color: OkHCLColor\n}\n\nconst toRGB = converter('rgb')\nconst toP3 = converter('p3')\nconst toOkHCL = converter('oklch')\nconst toDisplayableRGB = toGamut('rgb', 'oklch')\nconst toDisplayableP3 = toGamut('p3', 'oklch')\n\n/** Colour spaces a document's stored numbers can be in. */\nexport type OkHCLColorSpace = 'srgb' | 'display-p3'\n\nfunction clampUnit(value: number): number {\n if (value < 0) return 0\n if (value > 1) return 1\n return value\n}\n\nfunction normalizeHue(value: number): number {\n const hue = value % 360\n return hue < 0 ? hue + 360 : hue\n}\n\nfunction normalizeOkHCLColor(color: OkHCLColor): OkHCLColor {\n return {\n h: normalizeHue(color.h),\n c: Math.max(0, color.c),\n l: clampUnit(color.l),\n a: clampUnit(color.a ?? 1)\n }\n}\n\n/** Coordinates in `colorSpace`, so callers can store colours in the document's profile. */\nexport function okhclToRGBA(color: OkHCLColor, colorSpace: OkHCLColorSpace = 'srgb'): Color {\n const normalized = normalizeOkHCLColor(color)\n const oklch = {\n mode: 'oklch' as const,\n l: normalized.l,\n c: normalized.c,\n h: normalized.h,\n alpha: normalized.a\n }\n if (colorSpace === 'display-p3') {\n const p3 = toP3(toDisplayableP3(oklch))\n return normalizeColor({\n r: p3.r,\n g: p3.g,\n b: p3.b,\n a: p3.alpha ?? normalized.a\n })\n }\n const rgb = toRGB(toDisplayableRGB(oklch))\n return normalizeColor({\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: rgb.alpha ?? normalized.a\n })\n}\n\n/** Reads `color` as coordinates in `colorSpace`, the inverse of {@link okhclToRGBA}. */\nexport function rgbaToOkHCL(color: Color, colorSpace: OkHCLColorSpace = 'srgb'): OkHCLColor {\n const oklch = toOkHCL(\n colorSpace === 'display-p3'\n ? { mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a }\n : { mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a }\n )\n return normalizeOkHCLColor({\n h: oklch.h ?? 0,\n c: oklch.c,\n l: oklch.l,\n a: oklch.alpha ?? color.a\n })\n}\n\nexport function serializeOkHCLPayload(payload: OkHCLPayload): string {\n return OPEN_PENCIL_PLUGIN_DATA.okhcl.encode(payload)\n}\n\nexport function parseOkHCLPayload(value: string): OkHCLPayload | null {\n return OPEN_PENCIL_PLUGIN_DATA.okhcl.decode(value) ?? null\n}\n\nfunction createOkHCLPayload(\n kind: 'fill' | 'stroke',\n index: number,\n color: OkHCLColor\n): OkHCLPayload {\n return {\n version: 1,\n kind,\n index,\n color: normalizeOkHCLColor(color)\n }\n}\n\n/** The node's plugin data with the payload for one paint replaced, or removed without `color`. */\nfunction withOkHCLPayload(\n node: SceneNode,\n kind: 'fill' | 'stroke',\n index: number,\n color?: OkHCLColor\n): PluginDataEntry[] {\n const payloads = getNodeOkHCLPayloads(node).filter(\n (payload) => payload.kind !== kind || payload.index !== index\n )\n if (color) payloads.push(createOkHCLPayload(kind, index, color))\n return withAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.okhcl, payloads)\n}\n\nexport function setNodeFillOkHCL(\n node: SceneNode,\n index: number,\n color: OkHCLColor,\n colorSpace: OkHCLColorSpace = 'srgb'\n): Partial<SceneNode> {\n const fills = node.fills.map(copyFill)\n if (index < 0 || index >= fills.length) throw new Error(`Fill ${index} not found`)\n const fill = fills[index]\n const rgba = okhclToRGBA(color, colorSpace)\n fills[index] = {\n ...fill,\n color: rgba,\n opacity: rgba.a\n }\n\n return {\n fills,\n pluginData: withOkHCLPayload(node, 'fill', index, color)\n }\n}\n\nexport function setNodeStrokeOkHCL(\n node: SceneNode,\n index: number,\n color: OkHCLColor,\n colorSpace: OkHCLColorSpace = 'srgb'\n): Partial<SceneNode> {\n const strokes = node.strokes.map(copyStroke)\n if (index < 0 || index >= strokes.length) throw new Error(`Stroke ${index} not found`)\n const stroke = strokes[index]\n const rgba = okhclToRGBA(color, colorSpace)\n strokes[index] = {\n ...stroke,\n color: rgba,\n opacity: rgba.a\n }\n\n return {\n strokes,\n pluginData: withOkHCLPayload(node, 'stroke', index, color)\n }\n}\n\nexport function clearNodeFillOkHCL(node: SceneNode, index: number): Partial<SceneNode> {\n return { pluginData: withOkHCLPayload(node, 'fill', index) }\n}\n\nexport function clearNodeStrokeOkHCL(node: SceneNode, index: number): Partial<SceneNode> {\n return { pluginData: withOkHCLPayload(node, 'stroke', index) }\n}\n\nexport function getNodeOkHCLPayloads(node: SceneNode): OkHCLPayload[] {\n return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.okhcl)\n}\n\nexport function getFillOkHCL(node: SceneNode, index: number): OkHCLPayload | null {\n return (\n getNodeOkHCLPayloads(node).find(\n (payload) => payload.kind === 'fill' && payload.index === index\n ) ?? null\n )\n}\n\nexport function getStrokeOkHCL(node: SceneNode, index: number): OkHCLPayload | null {\n return (\n getNodeOkHCLPayloads(node).find(\n (payload) => payload.kind === 'stroke' && payload.index === index\n ) ?? null\n )\n}\n","import { converter, formatCss, formatRgb, inGamut, parse, toGamut } from 'culori'\n\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace, Fill, SceneNode, Stroke } from '../types'\nimport { normalizeColor } from './normalize'\nimport { getFillOkHCL, getStrokeOkHCL, type OkHCLColor } from './okhcl'\n\nexport type RenderColorSpace = 'srgb' | 'display-p3'\nexport type ColorIntentSpace = 'oklch' | 'srgb'\n\nexport interface ColorPreviewOptions {\n colorSpace?: RenderColorSpace\n documentColorSpace?: DocumentColorSpace\n}\n\nexport interface ResolvedRenderColor {\n color: Color\n cssColor: string\n sourceSpace: ColorIntentSpace\n targetSpace: RenderColorSpace\n clipped: boolean\n}\n\nconst DEFAULT_COLOR_SPACE: RenderColorSpace = 'srgb'\n\nconst toRGB = converter('rgb')\nconst toP3 = converter('p3')\nconst toDisplayableRGB = toGamut('rgb', 'oklch')\nconst toDisplayableP3 = toGamut('p3', 'oklch')\nconst isDisplayableRGB = inGamut('rgb')\nconst isDisplayableP3 = inGamut('p3')\n\nfunction normalizeOkLCH(color: OkHCLColor) {\n const hue = color.h % 360\n return {\n mode: 'oklch' as const,\n l: Math.max(0, Math.min(1, color.l)),\n c: Math.max(0, color.c),\n h: hue < 0 ? hue + 360 : hue,\n alpha: Math.max(0, Math.min(1, color.a ?? 1))\n }\n}\n\n/**\n * Numbers are stored in the document's profile, so painting into a surface with a different\n * profile has to convert them. Same profile means no work, which is the common case.\n */\nfunction convertComponents(color: Color, from: RenderColorSpace, to: RenderColorSpace): Color {\n if (from === to) return color\n const source =\n from === 'display-p3'\n ? { mode: 'p3' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }\n : { mode: 'rgb' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }\n const converted = to === 'display-p3' ? toP3(source) : toRGB(source)\n return normalizeColor({\n r: converted.r,\n g: converted.g,\n b: converted.b,\n a: converted.alpha ?? color.a\n })\n}\n\nfunction isOutsideGamut(color: Color, space: RenderColorSpace): boolean {\n if (space === 'display-p3') {\n return !isDisplayableP3({ mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a })\n }\n return !isDisplayableRGB({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nfunction resolveTargetSpace(options?: ColorPreviewOptions): RenderColorSpace {\n return options?.colorSpace ?? options?.documentColorSpace ?? DEFAULT_COLOR_SPACE\n}\n\nfunction formatCSSForTarget(color: Color, targetSpace: RenderColorSpace): string {\n if (targetSpace === 'display-p3') {\n const p3 = toP3({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n return formatCss({\n mode: 'p3',\n r: p3.r,\n g: p3.g,\n b: p3.b,\n alpha: p3.alpha ?? color.a\n })\n }\n\n return formatRgb({\n mode: 'rgb',\n r: color.r,\n g: color.g,\n b: color.b,\n alpha: color.a\n })\n}\n\nexport function resolveOkHCLForPreview(\n color: OkHCLColor,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const oklch = normalizeOkLCH(color)\n const targetSpace = resolveTargetSpace(options)\n\n if (targetSpace === 'display-p3') {\n const clipped = !isDisplayableP3(oklch)\n const p3 = toP3(toDisplayableP3(oklch))\n // P3 coordinates, because the caller asked for a P3 target.\n const resolved = normalizeColor({\n r: p3.r,\n g: p3.g,\n b: p3.b,\n a: p3.alpha ?? oklch.alpha\n })\n\n return {\n color: resolved,\n cssColor: formatCss({\n mode: 'p3',\n r: p3.r,\n g: p3.g,\n b: p3.b,\n alpha: p3.alpha ?? oklch.alpha\n }),\n sourceSpace: 'oklch',\n targetSpace,\n clipped\n }\n }\n\n const clipped = !isDisplayableRGB(oklch)\n const rgb = toRGB(toDisplayableRGB(oklch))\n const resolved = normalizeColor({\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: rgb.alpha ?? oklch.alpha\n })\n\n return {\n color: resolved,\n cssColor: formatRgb({\n mode: 'rgb',\n r: resolved.r,\n g: resolved.g,\n b: resolved.b,\n alpha: resolved.a\n }),\n sourceSpace: 'oklch',\n targetSpace,\n clipped\n }\n}\n\n/**\n * A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing\n * chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing\n * (`none`) component reads as zero. Null when `input` is not a color.\n */\nexport function parseDisplayableColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n // Mapping through OKLCH shifts colors already in sRGB by float noise, so only map the rest.\n const rgb = isDisplayableRGB(parsed) ? toRGB(parsed) : toDisplayableRGB(parsed)\n // culori leaves a `none` channel out, which normalizing reads as zero.\n return normalizeColor({ r: rgb.r, g: rgb.g, b: rgb.b, a: parsed.alpha })\n}\n\nexport function resolveRGBAForPreview(\n color: Color,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const documentColorSpace = options?.documentColorSpace ?? DEFAULT_COLOR_SPACE\n const targetSpace = options?.colorSpace ?? documentColorSpace\n const resolved = convertComponents(normalizeColor(color), documentColorSpace, targetSpace)\n return {\n color: resolved,\n cssColor: formatCSSForTarget(resolved, targetSpace),\n sourceSpace: 'srgb',\n targetSpace,\n clipped: targetSpace !== documentColorSpace && isOutsideGamut(resolved, targetSpace)\n }\n}\n\nexport function resolveNodeFillColor(\n fill: Fill,\n fillIndex: number,\n node: SceneNode,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const okhcl = getFillOkHCL(node, fillIndex)?.color\n if (okhcl) return resolveOkHCLForPreview(okhcl, options)\n return resolveRGBAForPreview(fill.color, options)\n}\n\nexport function resolveNodeStrokeColor(\n stroke: Stroke,\n strokeIndex: number,\n node: SceneNode,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const okhcl = getStrokeOkHCL(node, strokeIndex)?.color\n if (okhcl) return resolveOkHCLForPreview(okhcl, options)\n return resolveRGBAForPreview(stroke.color, options)\n}\n\nexport function colorToDisplayCSS(color: Color, options?: ColorPreviewOptions): string {\n return resolveRGBAForPreview(color, options).cssColor\n}\n\nexport function getDefaultRenderColorSpace(): RenderColorSpace {\n return DEFAULT_COLOR_SPACE\n}\n","export * from './contrast'\nexport * from './management'\nexport { normalizeColor } from './normalize'\nexport * from './okhcl'\n\nimport { parse, formatHex, formatHex8, formatRgb, converter, differenceEuclidean } from 'culori'\n\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\n\nconst toRGB = converter('rgb')\n\n/** A CSS color, or null when `input` is not one. */\nexport function tryParseColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n const rgb = toRGB(parsed)\n return {\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: parsed.alpha ?? 1\n }\n}\n\n/** A CSS color, or black when `input` is not one. */\nexport function parseColor(input: string): Color {\n return tryParseColor(input) ?? { ...BLACK }\n}\n\nexport function colorToHex(color: Color): string {\n return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()\n}\n\nexport function colorToHex8(color: Color, alpha?: number): string {\n const a = alpha ?? color.a\n if (a >= 1) return colorToHex(color)\n return formatHex8({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: a }).toUpperCase()\n}\n\nexport function colorToHexRaw(color: Color): string {\n return colorToHex(color).slice(1)\n}\n\nexport function colorToRgba255(color: Color) {\n return {\n r: Math.round(color.r * 255),\n g: Math.round(color.g * 255),\n b: Math.round(color.b * 255),\n a: color.a\n }\n}\n\nexport function colorToCSS(color: Color): string {\n return formatRgb({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nexport function colorToCSSCompact(color: Color): string {\n const { r, g, b } = colorToRgba255(color)\n const a = Number(color.a.toFixed(3))\n if (a >= 1) return `rgb(${r},${g},${b})`\n return `rgba(${r},${g},${b},${a})`\n}\n\nexport function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {\n return { r: r / 255, g: g / 255, b: b / 255, a }\n}\n\nexport function colorToFill(color: string | Color) {\n const rgba = typeof color === 'string' ? parseColor(color) : color\n return {\n type: 'SOLID' as const,\n color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },\n opacity: rgba.a,\n visible: true\n }\n}\n\nconst euclideanRGB255 = differenceEuclidean('rgb')\n\nexport function colorDistance(c1: Color, c2: Color): number {\n return (\n euclideanRGB255(\n { mode: 'rgb', r: c1.r, g: c1.g, b: c1.b },\n { mode: 'rgb', r: c2.r, g: c2.g, b: c2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;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,CAC3C,IAAI;AAER"}
@@ -165,7 +165,7 @@ function contentSizedAxes(graph, current, source, updates) {
165
165
  ...updates
166
166
  };
167
167
  if (copy.type === "TEXT") {
168
- if (copy.text === source.text) return {
168
+ if (TEXT_SHAPING_FIELDS.every((field) => isEqual(copy[field], source[field]))) return {
169
169
  width: false,
170
170
  height: false
171
171
  };
@@ -175,13 +175,13 @@ function contentSizedAxes(graph, current, source, updates) {
175
175
  height: mode === "WIDTH_AND_HEIGHT" || mode === "HEIGHT"
176
176
  };
177
177
  }
178
- if (copy.layoutMode === "NONE") return {
179
- width: false,
180
- height: false
178
+ const laidOut = (axis) => {
179
+ const sizing = layoutSizing(graph, copy, axis);
180
+ return sizing === "FILL" || sizing === "HUG" && copy.layoutMode !== "NONE";
181
181
  };
182
182
  return {
183
- width: layoutSizing(graph, copy, "HORIZONTAL") === "HUG",
184
- height: layoutSizing(graph, copy, "VERTICAL") === "HUG"
183
+ width: laidOut("HORIZONTAL"),
184
+ height: laidOut("VERTICAL")
185
185
  };
186
186
  }
187
187
  /**
@@ -784,7 +784,6 @@ const INSTANCE_SYNC_PROPS = [
784
784
  "gridRowGap",
785
785
  "gridPosition",
786
786
  "clipsContent",
787
- "counterAxisAlignContent",
788
787
  "itemReverseZIndex",
789
788
  "strokesIncludedInLayout",
790
789
  "layoutGrids",
@@ -829,6 +828,7 @@ const INSTANCE_FOLLOWED_FIELDS = [
829
828
  "horizontalConstraint",
830
829
  "verticalConstraint",
831
830
  "layoutPositioning",
831
+ "counterAxisAlignContent",
832
832
  "isMask",
833
833
  "maskType",
834
834
  "arcData",