@pairdraw/scene-graph 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +14 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +1 -0
- package/dist/copy.js.map +1 -1
- package/dist/css/gradient.d.ts +23 -0
- package/dist/css/gradient.d.ts.map +1 -0
- package/dist/css/gradient.js +404 -0
- package/dist/css/gradient.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +2 -13
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.js +24 -1
- package/dist/css/values.js.map +1 -1
- package/dist/font-style.d.ts +2 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +31 -6
- package/dist/font-style.js.map +1 -1
- package/dist/geometry.d.ts +10 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +21 -6
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -3
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +179 -17
- package/dist/graph.js.map +1 -1
- package/dist/hit-test.d.ts +3 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +38 -23
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/index.d.ts +2 -2
- package/dist/icons/index.js +2 -2
- package/dist/icons/model.d.ts +8 -2
- package/dist/icons/model.d.ts.map +1 -1
- package/dist/icons/model.js +10 -1
- package/dist/icons/model.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +40 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +18 -1
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +38 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +134 -15
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +10 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +28 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +1 -1
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap-overrides.js +94 -0
- package/dist/instances/swap-overrides.js.map +1 -0
- package/dist/instances/sync.js +90 -12
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/draw-order.d.ts +11 -0
- package/dist/layout/draw-order.d.ts.map +1 -0
- package/dist/layout/draw-order.js +14 -0
- package/dist/layout/draw-order.js.map +1 -0
- package/dist/layout/index.d.ts +2 -1
- package/dist/layout/index.js +2 -1
- package/dist/node-defaults.d.ts +11 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +16 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/resize.d.ts +29 -9
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +95 -62
- package/dist/resize.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +1 -8
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/source-metadata.d.ts +4 -2
- package/dist/source-metadata.d.ts.map +1 -1
- package/dist/source-metadata.js +10 -3
- package/dist/source-metadata.js.map +1 -1
- package/dist/strokes.d.ts +39 -0
- package/dist/strokes.d.ts.map +1 -0
- package/dist/strokes.js +104 -0
- package/dist/strokes.js.map +1 -0
- package/dist/text/direction.d.ts +6 -2
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +2 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +3 -3
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +22 -6
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +24 -6
- package/dist/text/overflow.js.map +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +18 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +36 -1
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +52 -2
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +14 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +42 -67
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +10 -4
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +58 -15
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +101 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +313 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +44 -4
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/package.json +6 -1
- package/src/components/properties.ts +17 -2
- package/src/copy.ts +1 -0
- package/src/css/gradient.ts +438 -0
- package/src/css/index.ts +1 -0
- package/src/css/shadows.ts +2 -18
- package/src/css/values.ts +27 -1
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +25 -6
- package/src/graph.ts +207 -17
- package/src/hit-test.ts +67 -24
- package/src/icons/model.ts +11 -1
- package/src/instances/assignments.ts +65 -7
- package/src/instances/fields.ts +21 -0
- package/src/instances/index.ts +237 -14
- package/src/instances/overrides.ts +36 -1
- package/src/instances/placement.ts +5 -1
- package/src/instances/swap-overrides.ts +123 -0
- package/src/instances/sync.ts +139 -12
- package/src/layout/draw-order.ts +13 -0
- package/src/layout/index.ts +1 -0
- package/src/node-defaults.ts +21 -0
- package/src/order-keys.ts +6 -0
- package/src/resize.ts +133 -69
- package/src/shared-styles.ts +1 -3
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/source-metadata.ts +18 -3
- package/src/strokes.ts +121 -0
- package/src/text/direction.ts +7 -5
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +30 -7
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +17 -0
- package/src/undo.ts +79 -2
- package/src/variables/bindings.ts +52 -74
- package/src/variables/index.ts +80 -14
- package/src/variables/paints.ts +413 -0
- package/src/variables/resolution.ts +56 -5
- package/src/variables/subtree.ts +15 -0
package/dist/resize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\nimport { cloneVectorNetwork } from './vector-network'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n getNode(id: string): SceneNode | undefined\n}\n\nconst CONSTRAINT_CONTAINER_TYPES = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = parentAfter - parentBefore\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') return { position: position + delta / 2, size }\n if (constraint === 'STRETCH') return { position, size: Math.max(1, size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: Math.max(1, size * scale) }\n }\n return { position, size }\n}\n\ntype AxisPlacement = { position: number; size: number }\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal)\n let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical)\n ;({ x, y } = keepLockedRatio(x, y, horizontal, vertical, aspectRatio))\n return {\n x: Math.round(x.position),\n y: Math.round(y.position),\n width: Math.round(x.size),\n height: Math.round(y.size)\n }\n}\n\nfunction layoutConstrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') return { position, size: Math.abs(size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: Math.round(position * scale * 128) / 128, size: size * scale }\n }\n return { position, size }\n}\n\n/**\n * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto\n * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not\n * rounded, so applying a run of changes one at a time lands where applying them at once does.\n */\nexport function layoutConstrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n const placed = keepLockedRatio(\n layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n return {\n x: placed.x.position,\n y: placed.y.position,\n width: placed.x.size,\n height: placed.y.size\n }\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n // A flat side, as a straight line's, has nothing to scale along it.\n const scaleX = originalWidth > 0 ? width / originalWidth : 1\n const scaleY = originalHeight > 0 ? height / originalHeight : 1\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 || origHeight <= 0) return {}\n const sx = width / origWidth\n const sy = height / origHeight\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n Object.assign(changes, scaledPathTextChanges(orig, sx, sy))\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && isScaledPathText(orig)) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\ntype PathTextFields = Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>\n\n// Path text scales with its path, including baked path text that kept only rotated glyphs;\n// other text reflows in the new box, so its glyphs are dropped.\nfunction isScaledPathText(orig: PathTextFields): boolean {\n const glyphs = orig.derivedTextGlyphs ?? []\n return (\n glyphs.length > 0 &&\n (!!orig.textPathData ||\n !!orig.textPathBox ||\n glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0))\n )\n}\n\n/** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */\nexport function scaledPathTextChanges(\n orig: PathTextFields,\n sx: number,\n sy: number\n): Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> {\n if (!isScaledPathText(orig)) return {}\n const changes: Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> = {\n derivedTextGlyphs: scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy)\n }\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n return changes\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Pick<Rect, 'width' | 'height'>,\n rootAfter: Pick<Rect, 'width' | 'height'>,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n\n const compute = (\n parentId: string,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n ) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = parent.type === 'GROUP' || parent.type === 'BOOLEAN_OPERATION'\n for (const childId of parent.childIds) {\n const original = originals.get(childId)\n const child = graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n compute(childId, original, child)\n continue\n }\n const rect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n const childChanges: Partial<SceneNode> = {\n ...rect,\n ...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)\n }\n changes.set(childId, childChanges)\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n compute(childId, original, child.layoutMode === 'NONE' ? rect : child)\n }\n }\n\n compute(rootId, rootBefore, rootAfter)\n return changes\n}\n"],"mappings":";;;;AAsCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBACP,UACA,MACA,cACA,aACA,YACoC;CACpC,MAAM,QAAQ,cAAc;CAC5B,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,WAAW,QAAQ;EAAG;CAAK;CAC3E,IAAI,eAAe,WAAW,OAAO;EAAE;EAAU,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;CAAE;CACjF,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,OAAO;GAAE,UAAU,WAAW;GAAO,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;EAAE;CACvE;CACA,OAAO;EAAE;EAAU;CAAK;AAC1B;AAIA,MAAM,uCAAoD,IAAI,IAAI,CAAC,WAAW,OAAO,CAAC;;AAGtF,SAAS,eACP,QACA,MACA,YACe;CACf,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,OAAO,WAAW,OAAO,OAAO;EAAM;CAAK;CACxF,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,OAA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UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B;GACJ,MAAM,eAAmC;IACvC,GAAG;IACH,GAAG,sBAAsB,UAAU,SAAS,OAAO,SAAS,QAAQ,KAAK,OAAO,KAAK,MAAM;GAC7F;GACA,QAAQ,IAAI,SAAS,YAAY;GAEjC,QAAQ,SAAS,UAAU,MAAM,eAAe,SAAS,OAAO,KAAK;EACvE;CACF;CAEA,QAAQ,QAAQ,YAAY,SAAS;CACrC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\nimport { cloneVectorNetwork } from './vector-network'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'flipX'\n | 'flipY'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n getNode(id: string): SceneNode | undefined\n}\n\nconst CONSTRAINT_CONTAINER_TYPES = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\ntype AxisPlacement = { position: number; size: number; flipped?: boolean }\n\n/** A child's box after its parent resizes, and the axes on which it turned over. */\nexport type ConstrainedRect = Rect & { flipsX?: boolean; flipsY?: boolean }\n\n/**\n * Where a constraint places a child on one axis when its parent goes from `parentBefore` to\n * `parentAfter`, as Figma does: Right and Left & right move or grow it by the change in the\n * parent's size rounded to whole pixels, Center by the change in its rounded half, and Scale by\n * the exact ratio. The child's own box is never rounded, so a resize to the same size changes\n * nothing. Left & right that would leave no size keeps the axis as it was; past zero, the child\n * turns over and its box runs back from the edge it was pinned to, as the layer is mirrored in\n * Figma. `scaleStep` snaps a scaled position to that fraction of a pixel.\n */\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType,\n scaleStep = 0,\n allowFlips = true\n): AxisPlacement {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') {\n const stretched = size + delta\n if (!allowFlips) return { position, size: Math.abs(stretched) }\n if (stretched === 0) return { position, size }\n if (stretched > 0) return { position, size: stretched }\n return { position: position + stretched, size: -stretched, flipped: true }\n }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n const scaled = position * scale\n return {\n position: scaleStep > 0 ? Math.round(scaled / scaleStep) * scaleStep : scaled,\n size: size * scale\n }\n }\n return { position, size }\n}\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\ntype ChildRectPlacer = (\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio?: number | null\n) => ConstrainedRect\n\n/** Places a child by its constraints, snapping a scaled position to `scaleStep` when it is set. */\nfunction childRectPlacer(scaleStep: number, allowFlips = true): ChildRectPlacer {\n return (child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) => {\n const { x, y } = keepLockedRatio(\n constrainedAxis(\n child.x,\n child.width,\n parentBefore.width,\n parentAfter.width,\n horizontal,\n scaleStep,\n allowFlips\n ),\n constrainedAxis(\n child.y,\n child.height,\n parentBefore.height,\n parentAfter.height,\n vertical,\n scaleStep,\n allowFlips\n ),\n horizontal,\n vertical,\n aspectRatio\n )\n const rect: ConstrainedRect = { x: x.position, y: y.position, width: x.size, height: y.size }\n if (x.flipped) rect.flipsX = true\n if (y.flipped) rect.flipsY = true\n return rect\n }\n}\n\n/**\n * A child's box after its parent is resized, by a handle or `resize()`, keeping a locked aspect\n * ratio as Figma does.\n */\nexport const constrainedChildRect = childRectPlacer(0)\n\n/**\n * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto\n * layout when its Hug frame grows (measured on desktop 126): as `constrainedChildRect`, except\n * that a scaled position lands on 1/128 of a pixel.\n */\nexport const layoutConstrainedChildRect = childRectPlacer(1 / 128, false)\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n // A flat side, as a straight line's, has nothing to scale along it.\n const scaleX = originalWidth > 0 ? width / originalWidth : 1\n const scaleY = originalHeight > 0 ? height / originalHeight : 1\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n flipX: node.flipX,\n flipY: node.flipY,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 || origHeight <= 0) return {}\n const sx = width / origWidth\n const sy = height / origHeight\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n Object.assign(changes, scaledPathTextChanges(orig, sx, sy))\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && isScaledPathText(orig)) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\n/**\n * The saved outlines a size change invalidates on a layer drawn from its live box: its fill\n * outline follows the box, and its saved stroke outline goes, so the stroke is drawn again at its\n * weight through the live shape. A vector and text draw from outlines of their own, which scaling\n * keeps. Without this, a layer that came from a `.fig` with frame outlines keeps drawing the old\n * box after layout, the Plugin API or an instance sync resizes it.\n */\nexport function shapeGeometryChanges(\n node: SceneNode,\n width: number,\n height: number\n): Pick<Partial<SceneNode>, 'fillGeometry' | 'strokeGeometry'> {\n if (node.type === 'VECTOR' || node.type === 'TEXT') return {}\n if (node.fillGeometry.length === 0 && node.strokeGeometry.length === 0) return {}\n // A box with no extent has no outline to scale from; the live shape draws both again.\n if (node.width <= 0 || node.height <= 0) return { fillGeometry: [], strokeGeometry: [] }\n const changes = scaledGeometryChanges(\n createResizeSnapshot(node),\n node.width,\n node.height,\n width,\n height\n )\n const geometry: Pick<Partial<SceneNode>, 'fillGeometry' | 'strokeGeometry'> = {}\n if (changes.fillGeometry) geometry.fillGeometry = changes.fillGeometry\n if (changes.strokeGeometry) geometry.strokeGeometry = changes.strokeGeometry\n return geometry\n}\n\ntype PathTextFields = Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>\n\n// Path text scales with its path, including baked path text that kept only rotated glyphs;\n// other text reflows in the new box, so its glyphs are dropped.\nfunction isScaledPathText(orig: PathTextFields): boolean {\n const glyphs = orig.derivedTextGlyphs ?? []\n return (\n glyphs.length > 0 &&\n (!!orig.textPathData ||\n !!orig.textPathBox ||\n glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0))\n )\n}\n\n/** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */\nexport function scaledPathTextChanges(\n orig: PathTextFields,\n sx: number,\n sy: number\n): Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> {\n if (!isScaledPathText(orig)) return {}\n const changes: Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> = {\n derivedTextGlyphs: scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy)\n }\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n return changes\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\n/**\n * The flips a child takes when its constraints place it from `from`, written only where they\n * differ from the ones it has now, so a drag that crosses back undoes its own turn.\n */\nexport function flipChanges(\n from: Pick<SceneNode, 'flipX' | 'flipY'>,\n current: Pick<SceneNode, 'flipX' | 'flipY'>,\n flipsX = false,\n flipsY = false\n): Partial<Pick<SceneNode, 'flipX' | 'flipY'>> {\n const changes: Partial<Pick<SceneNode, 'flipX' | 'flipY'>> = {}\n const flipX = from.flipX !== flipsX\n const flipY = from.flipY !== flipsY\n if (flipX !== current.flipX) changes.flipX = flipX\n if (flipY !== current.flipY) changes.flipY = flipY\n return changes\n}\n\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Pick<Rect, 'width' | 'height'>,\n rootAfter: Pick<Rect, 'width' | 'height'>,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n\n const compute = (\n parentId: string,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n ) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = parent.type === 'GROUP' || parent.type === 'BOOLEAN_OPERATION'\n for (const childId of parent.childIds) {\n const original = originals.get(childId)\n const child = graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n compute(childId, original, child)\n continue\n }\n const rect: ConstrainedRect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n const { flipsX, flipsY, ...box } = rect\n const childChanges: Partial<SceneNode> = {\n ...box,\n ...flipChanges(original, child, flipsX, flipsY),\n ...scaledGeometryChanges(original, original.width, original.height, box.width, box.height)\n }\n changes.set(childId, childChanges)\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n compute(childId, original, child.layoutMode === 'NONE' ? box : child)\n }\n }\n\n compute(rootId, rootBefore, rootAfter)\n return changes\n}\n"],"m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C,GAAG;IACH,GAAG,YAAY,UAAU,OAAO,QAAQ,MAAM;IAC9C,GAAG,sBAAsB,UAAU,SAAS,OAAO,SAAS,QAAQ,IAAI,OAAO,IAAI,MAAM;GAC3F;GACA,QAAQ,IAAI,SAAS,YAAY;GAEjC,QAAQ,SAAS,UAAU,MAAM,eAAe,SAAS,MAAM,KAAK;EACtE;CACF;CAEA,QAAQ,QAAQ,YAAY,SAAS;CACrC,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-styles.d.ts","names":[],"sources":["../src/shared-styles.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"shared-styles.d.ts","names":[],"sources":["../src/shared-styles.ts"],"mappings":";;;cAaM;;;;;;;;cASO;;cAWA;;cAwBA;;;;;;;;cASA;;;;;iBAUG,eACd,MAAM,KAAK,yBACX,OAAO;iBAMO,kBAAkB,MAAM,0BAA0B,gBAAgB;iBAIlE,uBAAuB,MAAM,kBAAkB;iBAI/C,gBAAgB,OAAO,YAAY,MAAM,kBAAkB;iBAuB3D,uBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ"}
|
package/dist/shared-styles.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STROKE_LINE_KEYS } from "./strokes.js";
|
|
1
2
|
import { isEqual, omit } from "es-toolkit";
|
|
2
3
|
//#region src/shared-styles.ts
|
|
3
4
|
const STYLE_REF_KEYS = {
|
|
@@ -80,14 +81,6 @@ function getSharedStyles(graph, kind) {
|
|
|
80
81
|
}
|
|
81
82
|
return styles.sort((left, right) => left.name.localeCompare(right.name));
|
|
82
83
|
}
|
|
83
|
-
/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */
|
|
84
|
-
const STROKE_LINE_KEYS = [
|
|
85
|
-
"weight",
|
|
86
|
-
"align",
|
|
87
|
-
"cap",
|
|
88
|
-
"join",
|
|
89
|
-
"dashPattern"
|
|
90
|
-
];
|
|
91
84
|
/**
|
|
92
85
|
* Whether new strokes only change how their lines run, keeping every paint. A stroke style gives
|
|
93
86
|
* paints only, so such a write keeps it; any other strokes write leaves it, as setting even the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { isEqual, omit } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n
|
|
1
|
+
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { isEqual, omit } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport { STROKE_LINE_KEYS } from './strokes'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n/**\n * Whether new strokes only change how their lines run, keeping every paint. A stroke style gives\n * paints only, so such a write keeps it; any other strokes write leaves it, as setting even the\n * same paints does in Figma (live-verified).\n */\nfunction restylesStrokeLines(current: readonly Stroke[], next: readonly Stroke[]): boolean {\n const paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS))\n const lines = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]))\n return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next))\n}\n\nexport function styleDetachmentChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const next = { ...changes }\n for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {\n const reference = STYLE_REF_KEYS[kind as SharedStyleKind]\n if (reference in changes || !node[reference]) continue\n if (!fields.some((field) => field in changes)) continue\n if (kind === 'stroke' && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes))\n continue\n next[reference] = null\n }\n // A face named for another family, weight, or slant names none; the new one takes its own name.\n const changesFace = FACE_KEYS.some((key) => key in changes && changes[key] !== node[key])\n if (changesFace && !('fontStyle' in changes) && node.fontStyle) {\n next.fontStyle = null\n }\n return next\n}\n"],"mappings":";;;AAaA,MAAM,iBAAiB;CACrB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,oBAAoB,OAAO,OAAO,cAAc;AAE7D,MAAM,cAAc;CAClB,MAAM;CACN,Q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,OAAO,OAAO,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AACvF;AAEA,SAAgB,uBACd,MACA,SACoB;CACpB,MAAM,OAAO,EAAE,GAAG,QAAQ;CAC1B,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,mBAAmB,GAAG;EAChE,MAAM,YAAY,eAAe;EACjC,IAAI,aAAa,WAAW,CAAC,KAAK,YAAY;EAC9C,IAAI,CAAC,OAAO,MAAM,UAAU,SAAS,OAAO,GAAG;EAC/C,IAAI,SAAS,YAAY,QAAQ,WAAW,oBAAoB,KAAK,SAAS,QAAQ,OAAO,GAC3F;EACF,KAAK,aAAa;CACpB;CAGA,IADoB,UAAU,MAAM,QAAQ,OAAO,WAAW,QAAQ,SAAS,KAAK,IACtE,KAAK,EAAE,eAAe,YAAY,KAAK,WACnD,KAAK,YAAY;CAEnB,OAAO;AACT"}
|
|
@@ -4,8 +4,9 @@ import { ComponentPropertyDefinition, SceneNode, SlotSettings } from "../types.j
|
|
|
4
4
|
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
5
5
|
declare const DEFAULT_SLOT_SETTINGS: SlotSettings;
|
|
6
6
|
/**
|
|
7
|
-
* The main component
|
|
8
|
-
* instance are not authored there, so a
|
|
7
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
8
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
9
|
+
* layer under an instance has none.
|
|
9
10
|
*/
|
|
10
11
|
declare function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined;
|
|
11
12
|
/** Whether a frame inside a main component can become a slot. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;cAOa,uBAAuB;;;;;;iBAWpB,UAAU,OAAO,YAAY,MAAM,YAAY;;iBAW/C,cAAc,OAAO,YAAY,MAAM;;;;;;iBAgBvC,mBACd,OAAO,YACP,iBACA,aACC;;KAyBS,oBAAoB,QAC9B,KAAK;EACD,eAAe,QAAQ;;;iBAGb,mBACd,OAAO,YACP,iBACA,oBACA,OAAO"}
|
package/dist/slots/authoring.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { slotPropertyId } from "./frames.js";
|
|
2
|
+
import { propertyOwner } from "../components/properties.js";
|
|
2
3
|
import { numberedName } from "../naming.js";
|
|
3
4
|
//#region src/slots/authoring.ts
|
|
4
5
|
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
@@ -8,13 +9,14 @@ const DEFAULT_SLOT_SETTINGS = {
|
|
|
8
9
|
stretchChildOnInsert: false
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
|
-
* The main component
|
|
12
|
-
* instance are not authored there, so a
|
|
12
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
13
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
14
|
+
* layer under an instance has none.
|
|
13
15
|
*/
|
|
14
16
|
function slotOwner(graph, node) {
|
|
15
17
|
if (!node.parentId) return void 0;
|
|
16
18
|
const owner = graph.closest(node.parentId, (current) => current.type === "COMPONENT" || current.type === "INSTANCE" || current.type === "CANVAS");
|
|
17
|
-
return owner?.type === "COMPONENT" ? owner : void 0;
|
|
19
|
+
return owner?.type === "COMPONENT" ? propertyOwner(graph, owner) : void 0;
|
|
18
20
|
}
|
|
19
21
|
/** Whether a frame inside a main component can become a slot. */
|
|
20
22
|
function canCreateSlot(graph, node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { numberedName } from '../naming'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component a layer belongs to,
|
|
1
|
+
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import { propertyOwner } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport { numberedName } from '../naming'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component or set that defines the slots inside a layer: the component the layer\n * belongs to, or that component's set. Layers of an instance are not authored there, so a\n * layer under an instance has none.\n */\nexport function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n if (!node.parentId) return undefined\n const owner = graph.closest(\n node.parentId,\n (current) =>\n current.type === 'COMPONENT' || current.type === 'INSTANCE' || current.type === 'CANVAS'\n )\n return owner?.type === 'COMPONENT' ? propertyOwner(graph, owner) : undefined\n}\n\n/** Whether a frame inside a main component can become a slot. */\nexport function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && !slotPropertyId(node) && !!slotOwner(graph, node)\n}\n\nfunction uniqueSlotName(owner: SceneNode, base: string): string {\n return numberedName(\n base,\n owner.componentPropertyDefinitions.map((definition) => definition.name)\n )\n}\n\n/**\n * Make a frame of a main component a slot: define a SLOT property, named after the frame, on\n * the component and bind the frame's children to it. Instances pick up the slot on their next\n * sync.\n */\nexport function createSlotProperty(\n graph: SceneGraph,\n frameId: string,\n id: string\n): ComponentPropertyDefinition | null {\n const frame = graph.getNode(frameId)\n const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : undefined\n if (!frame || !owner) return null\n const definition: ComponentPropertyDefinition = {\n id,\n name: uniqueSlotName(owner, frame.name.trim() || 'Slot'),\n type: 'SLOT',\n defaultValue: '',\n preferredValues: [],\n slotSettings: { ...DEFAULT_SLOT_SETTINGS }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition]\n })\n graph.updateNode(frame.id, {\n componentPropertyReferences: [\n ...frame.componentPropertyReferences,\n { propertyId: id, field: 'SLOT_CONTENT' }\n ]\n })\n return definition\n}\n\n/** What a slot's settings panel can change. */\nexport type SlotPropertyPatch = Partial<\n Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>\n> & { slotSettings?: Partial<SlotSettings> }\n\n/** Change a slot property's name, description, preferred components, or limits. */\nexport function updateSlotProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string,\n patch: SlotPropertyPatch\n): boolean {\n const owner = graph.getNode(ownerId)\n const current = owner?.componentPropertyDefinitions.find(\n (definition) => definition.id === propertyId && definition.type === 'SLOT'\n )\n if (!owner || !current) return false\n const { slotSettings, ...fields } = patch\n const next: ComponentPropertyDefinition = {\n ...current,\n ...fields,\n slotSettings: { ...DEFAULT_SLOT_SETTINGS, ...current.slotSettings, ...slotSettings }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) =>\n definition.id === propertyId ? next : definition\n )\n })\n return true\n}\n"],"mappings":";;;;;AAOA,MAAa,wBAAsC;CACjD,0BAA0B;CAC1B,uBAAuB;CACvB,sBAAsB;AACxB;;;;;;AAOA,SAAgB,UAAU,OAAmB,MAAwC;CACnF,IAAI,CAAC,KAAK,UAAU,OAAO,KAAA;CAC3B,MAAM,QAAQ,MAAM,QAClB,KAAK,WACJ,YACC,QAAQ,SAAS,eAAe,QAAQ,SAAS,cAAc,QAAQ,SAAS,QACpF;CACA,OAAO,OAAO,SAAS,cAAc,cAAc,OAAO,KAAK,IAAI,KAAA;AACrE;;AAGA,SAAgB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a,OAAO,UACxC,EACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAeY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAQb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAiChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAwCd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAcd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
|
package/dist/slots/content.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getInstanceOverride, setInstanceOverride } from "../instances/overrides.js";
|
|
2
2
|
import { isGeneratedFrame } from "../generated/index.js";
|
|
3
3
|
import { ownsSlotContent, slotPropertyId } from "./frames.js";
|
|
4
|
+
import { applyBoundPaintColorsIn } from "../variables/paints.js";
|
|
4
5
|
import { cloneChildrenWithMapping } from "../instances/sync.js";
|
|
5
6
|
//#region src/slots/content.ts
|
|
6
7
|
function nearestInstance(graph, node) {
|
|
@@ -80,7 +81,9 @@ function resetSlotContent(graph, scope) {
|
|
|
80
81
|
Reflect.deleteProperty(assignments, propertyId);
|
|
81
82
|
graph.updateNode(instance.id, { componentPropertyAssignments: assignments });
|
|
82
83
|
const source = componentSource(instance, frame);
|
|
83
|
-
if (source
|
|
84
|
+
if (!source || !graph.nodes.has(source)) return;
|
|
85
|
+
cloneChildrenWithMapping(graph, source, frame.id);
|
|
86
|
+
for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId);
|
|
84
87
|
}
|
|
85
88
|
/** Remove everything from the slot; the instance keeps owning it, now empty. */
|
|
86
89
|
function clearSlotContent(graph, scope) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId\n ? graph.closest(node.parentId, (current) => current.type === 'INSTANCE')\n : undefined\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n const owner = graph.closest(\n parentId,\n (current) =>\n !!slotPropertyId(current) || current.type === 'INSTANCE' || isGeneratedFrame(current)\n )\n if (!owner) return { kind: 'free' }\n const propertyId = slotPropertyId(owner)\n if (!propertyId) return { kind: 'locked', owner }\n const instance = nearestInstance(graph, owner)\n return instance ? { kind: 'slot', frame: owner, instance, propertyId } : { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (source
|
|
1
|
+
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn } from '../variables/paints'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId\n ? graph.closest(node.parentId, (current) => current.type === 'INSTANCE')\n : undefined\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n const owner = graph.closest(\n parentId,\n (current) =>\n !!slotPropertyId(current) || current.type === 'INSTANCE' || isGeneratedFrame(current)\n )\n if (!owner) return { kind: 'free' }\n const propertyId = slotPropertyId(owner)\n if (!propertyId) return { kind: 'locked', owner }\n const instance = nearestInstance(graph, owner)\n return instance ? { kind: 'slot', frame: owner, instance, propertyId } : { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (!source || !graph.nodes.has(source)) return\n cloneChildrenWithMapping(graph, source, frame.id)\n for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId)\n}\n\n/** Remove everything from the slot; the instance keeps owning it, now empty. */\nexport function clearSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n claimSlotContent(graph, scope)\n for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId)\n}\n"],"mappings":";;;;;;AAoBA,SAAS,gBAAgB,OAAmB,MAAwC;CAClF,OAAO,KAAK,WACR,MAAM,QAAQ,KAAK,WAAW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field an edit marked for the first time, so a step can take the mark back. */
|
|
4
|
+
type SourceMarkObserver = (nodeId: string, field: string) => void;
|
|
5
|
+
declare function markSourceFieldsEdited(node: SceneNode, changeKeys: string[], observe?: SourceMarkObserver): void;
|
|
4
6
|
//#endregion
|
|
5
|
-
export { markSourceFieldsEdited };
|
|
7
|
+
export { SourceMarkObserver, markSourceFieldsEdited };
|
|
6
8
|
//# sourceMappingURL=source-metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-metadata.d.ts","names":[],"sources":["../src/source-metadata.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"source-metadata.d.ts","names":[],"sources":["../src/source-metadata.ts"],"mappings":";;;KAMY,sBAAsB,gBAAgB;iBAElC,uBACd,MAAM,WACN,sBACA,UAAU"}
|
package/dist/source-metadata.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
//#region src/source-metadata.ts
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/** Values a peer computes for itself; recording one as an edit would differ between replicas. */
|
|
3
|
+
const DERIVED_FIELDS = /* @__PURE__ */ new Set(["textPicture"]);
|
|
4
|
+
function markSourceFieldsEdited(node, changeKeys, observe) {
|
|
5
|
+
const edited = changeKeys.filter((key) => !DERIVED_FIELDS.has(key));
|
|
6
|
+
if (edited.length === 0) return;
|
|
4
7
|
const editedFields = new Set(node.source.editedFields);
|
|
5
|
-
for (const key of
|
|
8
|
+
for (const key of edited) {
|
|
9
|
+
if (editedFields.has(key)) continue;
|
|
10
|
+
observe?.(node.id, key);
|
|
11
|
+
editedFields.add(key);
|
|
12
|
+
}
|
|
6
13
|
node.source.editedFields = [...editedFields];
|
|
7
14
|
}
|
|
8
15
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-metadata.js","names":[],"sources":["../src/source-metadata.ts"],"sourcesContent":["import type { SceneNode } from './types'\n\nexport function markSourceFieldsEdited(node: SceneNode
|
|
1
|
+
{"version":3,"file":"source-metadata.js","names":[],"sources":["../src/source-metadata.ts"],"sourcesContent":["import type { SceneNode } from './types'\n\n/** Values a peer computes for itself; recording one as an edit would differ between replicas. */\nconst DERIVED_FIELDS: ReadonlySet<string> = new Set(['textPicture'])\n\n/** Told each field an edit marked for the first time, so a step can take the mark back. */\nexport type SourceMarkObserver = (nodeId: string, field: string) => void\n\nexport function markSourceFieldsEdited(\n node: SceneNode,\n changeKeys: string[],\n observe?: SourceMarkObserver\n): void {\n const edited = changeKeys.filter((key) => !DERIVED_FIELDS.has(key))\n if (edited.length === 0) return\n const editedFields = new Set(node.source.editedFields)\n for (const key of edited) {\n if (editedFields.has(key)) continue\n observe?.(node.id, key)\n editedFields.add(key)\n }\n node.source.editedFields = [...editedFields]\n}\n"],"mappings":";;AAGA,MAAM,iCAAsC,IAAI,IAAI,CAAC,aAAa,CAAC;AAKnE,SAAgB,uBACd,MACA,YACA,SACM;CACN,MAAM,SAAS,WAAW,QAAQ,QAAQ,CAAC,eAAe,IAAI,GAAG,CAAC;CAClE,IAAI,OAAO,WAAW,GAAG;CACzB,MAAM,eAAe,IAAI,IAAI,KAAK,OAAO,YAAY;CACrD,KAAK,MAAM,OAAO,QAAQ;EACxB,IAAI,aAAa,IAAI,GAAG,GAAG;EAC3B,UAAU,KAAK,IAAI,GAAG;EACtB,aAAa,IAAI,GAAG;CACtB;CACA,KAAK,OAAO,eAAe,CAAC,GAAG,YAAY;AAC7C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SceneNode, Stroke } from "./types.js";
|
|
2
|
+
//#region src/strokes.d.ts
|
|
3
|
+
/** What a stroke draws along beside its paint. */
|
|
4
|
+
declare const STROKE_LINE_KEYS: readonly ["weight", "align", "cap", "join", "dashPattern"];
|
|
5
|
+
type StrokeLineKey = (typeof STROKE_LINE_KEYS)[number];
|
|
6
|
+
/**
|
|
7
|
+
* The layer field that keeps each line value. Figma keeps one of each per layer; a layer here
|
|
8
|
+
* also keeps them on each stroke, which the renderer draws.
|
|
9
|
+
*/
|
|
10
|
+
declare const STROKE_LINE_FIELDS: {
|
|
11
|
+
readonly weight: "strokeWeight";
|
|
12
|
+
readonly align: "strokeAlign";
|
|
13
|
+
readonly cap: "strokeCap";
|
|
14
|
+
readonly join: "strokeJoin";
|
|
15
|
+
readonly dashPattern: "dashPattern";
|
|
16
|
+
};
|
|
17
|
+
type StrokeLines = Partial<Pick<Stroke, StrokeLineKey>>;
|
|
18
|
+
/** The value a stroke draws with; a stroke without a dash draws solid. */
|
|
19
|
+
declare function strokeLine(stroke: Stroke, key: StrokeLineKey): Stroke[StrokeLineKey];
|
|
20
|
+
/** `strokes` with each line field `values` names, as a layer field set alone gives every stroke. */
|
|
21
|
+
declare function withStrokeLines(strokes: readonly Stroke[], values: StrokeLines): Stroke[];
|
|
22
|
+
/**
|
|
23
|
+
* What else `changes` sets so a layer's line fields and its strokes agree: new strokes set the
|
|
24
|
+
* layer's fields to the first stroke's, and a layer field set without strokes goes to every
|
|
25
|
+
* stroke. Strokes win when `changes` sets both, so restoring strokes restores what they draw.
|
|
26
|
+
* Only fields whose value changes are returned, so an instance overrides no more than an edit
|
|
27
|
+
* changed. A layer without strokes keeps its fields for the next stroke (`newStrokeGeometry`).
|
|
28
|
+
*/
|
|
29
|
+
declare function strokeLineChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the strokes `changes` sets differ from `node`'s by more than the layer fields the same
|
|
32
|
+
* write sets: a paint, a stroke added or removed, or a stroke's line that no layer field records.
|
|
33
|
+
* Figma overrides a weight or dash set on an instance layer alone, so a component's later paint
|
|
34
|
+
* change still reaches the copy (live).
|
|
35
|
+
*/
|
|
36
|
+
declare function changesMoreThanStrokeLines(node: SceneNode, changes: Partial<SceneNode>): boolean;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { STROKE_LINE_FIELDS, STROKE_LINE_KEYS, StrokeLines, changesMoreThanStrokeLines, strokeLine, strokeLineChanges, withStrokeLines };
|
|
39
|
+
//# sourceMappingURL=strokes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strokes.d.ts","names":[],"sources":["../src/strokes.ts"],"mappings":";;;cAMa;KAQR,wBAAwB;;;;;cAMhB;;;;;;;KAQD,cAAc,QAAQ,KAAK,QAAQ;;iBAG/B,WAAW,QAAQ,QAAQ,KAAK,gBAAgB,OAAO;;iBAKvD,gBAAgB,kBAAkB,UAAU,QAAQ,cAAc;;;;;;;;iBAkBlE,kBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;;;;;;;iBA6CK,2BAA2B,MAAM,WAAW,SAAS,QAAQ"}
|
package/dist/strokes.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { copyStroke } from "./copy.js";
|
|
2
|
+
import { isEqual } from "es-toolkit";
|
|
3
|
+
//#region src/strokes.ts
|
|
4
|
+
/** What a stroke draws along beside its paint. */
|
|
5
|
+
const STROKE_LINE_KEYS = [
|
|
6
|
+
"weight",
|
|
7
|
+
"align",
|
|
8
|
+
"cap",
|
|
9
|
+
"join",
|
|
10
|
+
"dashPattern"
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* The layer field that keeps each line value. Figma keeps one of each per layer; a layer here
|
|
14
|
+
* also keeps them on each stroke, which the renderer draws.
|
|
15
|
+
*/
|
|
16
|
+
const STROKE_LINE_FIELDS = {
|
|
17
|
+
weight: "strokeWeight",
|
|
18
|
+
align: "strokeAlign",
|
|
19
|
+
cap: "strokeCap",
|
|
20
|
+
join: "strokeJoin",
|
|
21
|
+
dashPattern: "dashPattern"
|
|
22
|
+
};
|
|
23
|
+
/** The value a stroke draws with; a stroke without a dash draws solid. */
|
|
24
|
+
function strokeLine(stroke, key) {
|
|
25
|
+
return key === "dashPattern" ? stroke.dashPattern ?? [] : stroke[key];
|
|
26
|
+
}
|
|
27
|
+
/** `strokes` with each line field `values` names, as a layer field set alone gives every stroke. */
|
|
28
|
+
function withStrokeLines(strokes, values) {
|
|
29
|
+
return strokes.map((stroke) => {
|
|
30
|
+
const next = copyStroke(stroke);
|
|
31
|
+
for (const key of STROKE_LINE_KEYS) {
|
|
32
|
+
const value = values[key];
|
|
33
|
+
if (value !== void 0) Reflect.set(next, key, structuredClone(value));
|
|
34
|
+
}
|
|
35
|
+
return next;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What else `changes` sets so a layer's line fields and its strokes agree: new strokes set the
|
|
40
|
+
* layer's fields to the first stroke's, and a layer field set without strokes goes to every
|
|
41
|
+
* stroke. Strokes win when `changes` sets both, so restoring strokes restores what they draw.
|
|
42
|
+
* Only fields whose value changes are returned, so an instance overrides no more than an edit
|
|
43
|
+
* changed. A layer without strokes keeps its fields for the next stroke (`newStrokeGeometry`).
|
|
44
|
+
*/
|
|
45
|
+
function strokeLineChanges(node, changes) {
|
|
46
|
+
if (changes.strokes) {
|
|
47
|
+
const first = changes.strokes.at(0);
|
|
48
|
+
if (!first) return {};
|
|
49
|
+
const derived = {};
|
|
50
|
+
for (const key of STROKE_LINE_KEYS) {
|
|
51
|
+
const field = STROKE_LINE_FIELDS[key];
|
|
52
|
+
const current = field in changes ? changes[field] : node[field];
|
|
53
|
+
const value = strokeLine(first, key) ?? current;
|
|
54
|
+
if (!isEqual(current, value)) Reflect.set(derived, field, structuredClone(value));
|
|
55
|
+
}
|
|
56
|
+
const cap = derived.strokeCap ?? changes.strokeCap ?? node.strokeCap;
|
|
57
|
+
const join = derived.strokeJoin ?? changes.strokeJoin ?? node.strokeJoin;
|
|
58
|
+
if (changes.strokes.some((stroke) => stroke.cap === void 0 || stroke.join === void 0)) derived.strokes = changes.strokes.map((stroke) => ({
|
|
59
|
+
...copyStroke(stroke),
|
|
60
|
+
cap: stroke.cap ?? cap,
|
|
61
|
+
join: stroke.join ?? join
|
|
62
|
+
}));
|
|
63
|
+
return derived;
|
|
64
|
+
}
|
|
65
|
+
if (node.strokes.length === 0) return {};
|
|
66
|
+
const values = {};
|
|
67
|
+
let set = false;
|
|
68
|
+
for (const key of STROKE_LINE_KEYS) {
|
|
69
|
+
const value = changes[STROKE_LINE_FIELDS[key]];
|
|
70
|
+
if (value === void 0) continue;
|
|
71
|
+
Reflect.set(values, key, value);
|
|
72
|
+
set = true;
|
|
73
|
+
}
|
|
74
|
+
if (!set) return {};
|
|
75
|
+
const strokes = withStrokeLines(node.strokes, values);
|
|
76
|
+
return isEqual(strokes, node.strokes) ? {} : { strokes };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether the strokes `changes` sets differ from `node`'s by more than the layer fields the same
|
|
80
|
+
* write sets: a paint, a stroke added or removed, or a stroke's line that no layer field records.
|
|
81
|
+
* Figma overrides a weight or dash set on an instance layer alone, so a component's later paint
|
|
82
|
+
* change still reaches the copy (live).
|
|
83
|
+
*/
|
|
84
|
+
function changesMoreThanStrokeLines(node, changes) {
|
|
85
|
+
const next = changes.strokes;
|
|
86
|
+
if (!next) return false;
|
|
87
|
+
if (next.length !== node.strokes.length) return true;
|
|
88
|
+
const lines = {};
|
|
89
|
+
for (const key of STROKE_LINE_KEYS) {
|
|
90
|
+
const value = changes[STROKE_LINE_FIELDS[key]];
|
|
91
|
+
if (value !== void 0) Reflect.set(lines, key, value);
|
|
92
|
+
}
|
|
93
|
+
const drawn = (stroke) => ({
|
|
94
|
+
...stroke,
|
|
95
|
+
cap: stroke.cap ?? node.strokeCap,
|
|
96
|
+
join: stroke.join ?? node.strokeJoin,
|
|
97
|
+
dashPattern: stroke.dashPattern ?? []
|
|
98
|
+
});
|
|
99
|
+
return !isEqual(withStrokeLines(node.strokes, lines).map(drawn), next.map(drawn));
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { STROKE_LINE_FIELDS, STROKE_LINE_KEYS, changesMoreThanStrokeLines, strokeLine, strokeLineChanges, withStrokeLines };
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=strokes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strokes.js","names":[],"sources":["../src/strokes.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport { copyStroke } from './copy'\nimport type { SceneNode, Stroke } from './types'\n\n/** What a stroke draws along beside its paint. */\nexport const STROKE_LINE_KEYS = [\n 'weight',\n 'align',\n 'cap',\n 'join',\n 'dashPattern'\n] as const satisfies readonly (keyof Stroke)[]\n\ntype StrokeLineKey = (typeof STROKE_LINE_KEYS)[number]\n\n/**\n * The layer field that keeps each line value. Figma keeps one of each per layer; a layer here\n * also keeps them on each stroke, which the renderer draws.\n */\nexport const STROKE_LINE_FIELDS = {\n weight: 'strokeWeight',\n align: 'strokeAlign',\n cap: 'strokeCap',\n join: 'strokeJoin',\n dashPattern: 'dashPattern'\n} as const satisfies Record<StrokeLineKey, keyof SceneNode>\n\nexport type StrokeLines = Partial<Pick<Stroke, StrokeLineKey>>\n\n/** The value a stroke draws with; a stroke without a dash draws solid. */\nexport function strokeLine(stroke: Stroke, key: StrokeLineKey): Stroke[StrokeLineKey] {\n return key === 'dashPattern' ? (stroke.dashPattern ?? []) : stroke[key]\n}\n\n/** `strokes` with each line field `values` names, as a layer field set alone gives every stroke. */\nexport function withStrokeLines(strokes: readonly Stroke[], values: StrokeLines): Stroke[] {\n return strokes.map((stroke) => {\n const next = copyStroke(stroke)\n for (const key of STROKE_LINE_KEYS) {\n const value = values[key]\n if (value !== undefined) Reflect.set(next, key, structuredClone(value))\n }\n return next\n })\n}\n\n/**\n * What else `changes` sets so a layer's line fields and its strokes agree: new strokes set the\n * layer's fields to the first stroke's, and a layer field set without strokes goes to every\n * stroke. Strokes win when `changes` sets both, so restoring strokes restores what they draw.\n * Only fields whose value changes are returned, so an instance overrides no more than an edit\n * changed. A layer without strokes keeps its fields for the next stroke (`newStrokeGeometry`).\n */\nexport function strokeLineChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n if (changes.strokes) {\n const first = changes.strokes.at(0)\n if (!first) return {}\n const derived: Partial<SceneNode> = {}\n for (const key of STROKE_LINE_KEYS) {\n const field = STROKE_LINE_FIELDS[key]\n const current = field in changes ? changes[field] : node[field]\n // A stroke without its own cap or join draws with the layer's.\n const value = strokeLine(first, key) ?? current\n if (!isEqual(current, value)) Reflect.set(derived, field, structuredClone(value))\n }\n // Strokes without their own cap or join take the layer's, so every stroke says what it draws.\n const cap = derived.strokeCap ?? changes.strokeCap ?? node.strokeCap\n const join = derived.strokeJoin ?? changes.strokeJoin ?? node.strokeJoin\n if (changes.strokes.some((stroke) => stroke.cap === undefined || stroke.join === undefined)) {\n derived.strokes = changes.strokes.map((stroke) => ({\n ...copyStroke(stroke),\n cap: stroke.cap ?? cap,\n join: stroke.join ?? join\n }))\n }\n return derived\n }\n if (node.strokes.length === 0) return {}\n const values: StrokeLines = {}\n let set = false\n for (const key of STROKE_LINE_KEYS) {\n const value = changes[STROKE_LINE_FIELDS[key]]\n if (value === undefined) continue\n Reflect.set(values, key, value)\n set = true\n }\n // Most writes, such as a move or a layout pass, set no line field.\n if (!set) return {}\n const strokes = withStrokeLines(node.strokes, values)\n return isEqual(strokes, node.strokes) ? {} : { strokes }\n}\n\n/**\n * Whether the strokes `changes` sets differ from `node`'s by more than the layer fields the same\n * write sets: a paint, a stroke added or removed, or a stroke's line that no layer field records.\n * Figma overrides a weight or dash set on an instance layer alone, so a component's later paint\n * change still reaches the copy (live).\n */\nexport function changesMoreThanStrokeLines(node: SceneNode, changes: Partial<SceneNode>): boolean {\n const next = changes.strokes\n if (!next) return false\n if (next.length !== node.strokes.length) return true\n const lines: StrokeLines = {}\n for (const key of STROKE_LINE_KEYS) {\n const value = changes[STROKE_LINE_FIELDS[key]]\n if (value !== undefined) Reflect.set(lines, key, value)\n }\n // Strokes written without a cap or join take the layer's, as `strokeLineChanges` gives them,\n // and a stroke without a dash draws as solid as one with an empty dash.\n const drawn = (stroke: Stroke): Stroke => ({\n ...stroke,\n cap: stroke.cap ?? node.strokeCap,\n join: stroke.join ?? node.strokeJoin,\n dashPattern: stroke.dashPattern ?? []\n })\n return !isEqual(withStrokeLines(node.strokes, lines).map(drawn), next.map(drawn))\n}\n"],"mappings":";;;;AAMA,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;AACF;;;;;AAQA,MAAa,qBAAqB;CAChC,QAAQ;CACR,OAAO;CACP,KAAK;CACL,MAAM;CACN,aAAa;AACf;;AAKA,SAAgB,WAAW,QAAgB,KAA2C;CACpF,OAAO,QAAQ,gBAAiB,OAAO,eAAe,CAAC,IAAK,OAAO;AACrE;;AAGA,SAAgB,gBAAgB,SAA4B,QAA+B;CACzF,OAAO,QAAQ,KAAK,WAAW;EAC7B,MAAM,OAAO,WAAW,MAAM;EAC9B,KAAK,MAAM,OAAO,kBAAkB;GAClC,MAAM,QAAQ,OAAO;GACrB,IAAI,UAAU,KAAA,GAAW,QAAQ,IAAI,MAAM,KAAK,gBAAgB,KAAK,CAAC;EACxE;EACA,OAAO;CACT,CAAC;AACH;;;;;;;;AASA,SAAgB,kBACd,MACA,SACoB;CACpB,IAAI,QAAQ,SAAS;EACnB,MAAM,QAAQ,QAAQ,QAAQ,GAAG,CAAC;EAClC,IAAI,CAAC,OAAO,OAAO,CAAC;EACpB,MAAM,UAA8B,CAAC;EACrC,KAAK,MAAM,OAAO,kBAAkB;GAClC,MAAM,QAAQ,mBAAmB;GACjC,MAAM,UAAU,SAAS,UAAU,QAAQ,SAAS,KAAK;GAEzD,MAAM,QAAQ,WAAW,OAAO,GAAG,KAAK;GACxC,IAAI,CAAC,QAAQ,SAAS,KAAK,GAAG,QAAQ,IAAI,SAAS,OAAO,gBAAgB,KAAK,CAAC;EAClF;EAEA,MAAM,MAAM,QAAQ,aAAa,QAAQ,aAAa,KAAK;EAC3D,MAAM,OAAO,QAAQ,cAAc,QAAQ,cAAc,KAAK;EAC9D,IAAI,QAAQ,QAAQ,MAAM,WAAW,OAAO,QAAQ,KAAA,KAAa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
|
|
2
2
|
//#region src/text/direction.d.ts
|
|
3
3
|
declare function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'>;
|
|
4
|
-
|
|
5
|
-
declare function
|
|
4
|
+
/** A node exported without the field, or drawn from partial props, reads as `AUTO`. */
|
|
5
|
+
declare function resolveTextDirection(direction: TextDirection | undefined, text: string): Exclude<TextDirection, 'AUTO'>;
|
|
6
|
+
declare function resolveNodeTextDirection(node: {
|
|
7
|
+
textDirection?: TextDirection;
|
|
8
|
+
text: string;
|
|
9
|
+
}): 'LTR' | 'RTL';
|
|
6
10
|
declare function resolveNodeLayoutDirection(node: {
|
|
7
11
|
layoutDirection?: LayoutDirection;
|
|
8
12
|
}, inheritedDirection?: Exclude<LayoutDirection, 'AUTO'>): Exclude<LayoutDirection, 'AUTO'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":";;iBAMgB,oBAAoB,eAAe,QAAQ
|
|
1
|
+
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":";;iBAMgB,oBAAoB,eAAe,QAAQ;;iBAS3C,qBACd,WAAW,2BACX,eACC,QAAQ;iBAIK,yBAAyB;EACvC,gBAAgB;EAChB;;iBAKc,2BACd;EAAQ,kBAAkB;GAC1B,qBAAoB,QAAQ,2BAC3B,QAAQ;iBAMK,wBACd,MAAM,KAAK;iBASG,sBACd,MAAM,KAAK"}
|
package/dist/text/direction.js
CHANGED
|
@@ -8,8 +8,9 @@ function detectTextDirection(text) {
|
|
|
8
8
|
}
|
|
9
9
|
return "LTR";
|
|
10
10
|
}
|
|
11
|
+
/** A node exported without the field, or drawn from partial props, reads as `AUTO`. */
|
|
11
12
|
function resolveTextDirection(direction, text) {
|
|
12
|
-
return direction === "AUTO" ? detectTextDirection(text) : direction;
|
|
13
|
+
return !direction || direction === "AUTO" ? detectTextDirection(text) : direction;
|
|
13
14
|
}
|
|
14
15
|
function resolveNodeTextDirection(node) {
|
|
15
16
|
return resolveTextDirection(node.textDirection, node.text);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\nconst LTR_CHAR_RE = /\\p{Script=Latin}|\\p{Script=Cyrillic}|\\p{Script=Greek}/u\n\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n for (const char of text) {\n if (RTL_CHAR_RE.test(char)) return 'RTL'\n if (LTR_CHAR_RE.test(char)) return 'LTR'\n }\n return 'LTR'\n}\n\nexport function resolveTextDirection(\n direction: TextDirection,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(\n
|
|
1
|
+
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\nconst LTR_CHAR_RE = /\\p{Script=Latin}|\\p{Script=Cyrillic}|\\p{Script=Greek}/u\n\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n for (const char of text) {\n if (RTL_CHAR_RE.test(char)) return 'RTL'\n if (LTR_CHAR_RE.test(char)) return 'LTR'\n }\n return 'LTR'\n}\n\n/** A node exported without the field, or drawn from partial props, reads as `AUTO`. */\nexport function resolveTextDirection(\n direction: TextDirection | undefined,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return !direction || direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(node: {\n textDirection?: TextDirection\n text: string\n}): 'LTR' | 'RTL' {\n return resolveTextDirection(node.textDirection, node.text)\n}\n\nexport function resolveNodeLayoutDirection(\n node: { layoutDirection?: LayoutDirection },\n inheritedDirection: Exclude<LayoutDirection, 'AUTO'> = 'LTR'\n): Exclude<LayoutDirection, 'AUTO'> {\n return !node.layoutDirection || node.layoutDirection === 'AUTO'\n ? inheritedDirection\n : node.layoutDirection\n}\n\nexport function isLogicalTextAlignStart(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'LEFT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'RIGHT')\n )\n}\n\nexport function isLogicalTextAlignEnd(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n"],"mappings":";AAEA,MAAM,cACJ;AACF,MAAM,cAAc;AAEpB,SAAgB,oBAAoB,MAA8C;CAChF,KAAK,MAAM,QAAQ,MAAM;EACvB,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;EACnC,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;CACrC;CACA,OAAO;AACT;;AAGA,SAAgB,qBACd,WACA,MACgC;CAChC,OAAO,CAAC,aAAa,cAAc,SAAS,oBAAoB,IAAI,IAAI;AAC1E;AAEA,SAAgB,yBAAyB,MAGvB;CAChB,OAAO,qBAAqB,KAAK,eAAe,KAAK,IAAI;AAC3D;AAEA,SAAgB,2BACd,MACA,qBAAuD,OACrB;CAClC,OAAO,CAAC,KAAK,mBAAmB,KAAK,oBAAoB,SACrD,qBACA,KAAK;AACX;AAEA,SAAgB,wBACd,MACS;CACT,MAAM,YAAY,yBAAyB,IAAI;CAC/C,OACG,cAAc,SAAS,KAAK,wBAAwB,UACpD,cAAc,SAAS,KAAK,wBAAwB;AAEzD;AAEA,SAAgB,sBACd,MACS;CACT,MAAM,YAAY,yBAAyB,IAAI;CAC/C,OACG,cAAc,SAAS,KAAK,wBAAwB,WACpD,cAAc,SAAS,KAAK,wBAAwB;AAEzD"}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, TextParagraphRange, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
|
|
2
2
|
import { LIST_BULLET, ListNumberFormat, TextListItem, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
|
|
3
3
|
import { StyleRunReferences, remapStyleRunReferences, styleRunReferences } from "./references.js";
|
|
4
|
-
import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
5
|
-
import {
|
|
4
|
+
import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
5
|
+
import { TextLinesReach, textLinesReach, textVerticalOffset } from "./overflow.js";
|
|
6
6
|
import { textLengthSchema } from "./schema.js";
|
|
7
|
-
export { LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextListItem, TextParagraphRange, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema,
|
|
7
|
+
export { LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextLinesReach, TextListItem, TextParagraphRange, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|