@pairdraw/scene-graph 0.19.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/spec.d.ts +6 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +62 -5
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/canvas-layout.js +66 -0
- package/dist/canvas-layout.js.map +1 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/variants.d.ts +12 -1
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +30 -1
- package/dist/components/variants.js.map +1 -1
- package/dist/constants.d.ts +25 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +94 -1
- package/dist/constants.js.map +1 -1
- package/dist/coordinate.js +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/text.d.ts +22 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +81 -1
- package/dist/css/text.js.map +1 -1
- package/dist/design-memory/index.d.ts +3 -0
- package/dist/design-memory/index.js +3 -0
- package/dist/design-memory/model.d.ts +33 -0
- package/dist/design-memory/model.d.ts.map +1 -0
- package/dist/design-memory/model.js +142 -0
- package/dist/design-memory/model.js.map +1 -0
- package/dist/design-memory/schema.d.ts +76 -0
- package/dist/design-memory/schema.d.ts.map +1 -0
- package/dist/design-memory/schema.js +72 -0
- package/dist/design-memory/schema.js.map +1 -0
- package/dist/effects.d.ts +7 -4
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +9 -4
- package/dist/effects.js.map +1 -1
- package/dist/empty-values.js +93 -0
- package/dist/empty-values.js.map +1 -0
- package/dist/fields/components.d.ts +9 -0
- package/dist/fields/components.d.ts.map +1 -0
- package/dist/fields/components.js +24 -0
- package/dist/fields/components.js.map +1 -0
- package/dist/fields/index.d.ts +3 -2
- package/dist/fields/index.js +3 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +10 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/graph.d.ts +8 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +36 -7
- package/dist/graph.js.map +1 -1
- package/dist/grid-values.d.ts +10 -0
- package/dist/grid-values.d.ts.map +1 -0
- package/dist/grid-values.js +53 -0
- package/dist/grid-values.js.map +1 -0
- package/dist/group-bounds.d.ts +4 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +11 -1
- package/dist/group-bounds.js.map +1 -1
- package/dist/hit-test/drop.d.ts +20 -0
- package/dist/hit-test/drop.d.ts.map +1 -0
- package/dist/hit-test/drop.js +54 -0
- package/dist/hit-test/drop.js.map +1 -0
- package/dist/hit-test/geometry.js +86 -0
- package/dist/hit-test/geometry.js.map +1 -0
- package/dist/hit-test/masks.d.ts +14 -0
- package/dist/hit-test/masks.d.ts.map +1 -0
- package/dist/hit-test/masks.js +41 -0
- package/dist/hit-test/masks.js.map +1 -0
- package/dist/hit-test/paint.d.ts +6 -0
- package/dist/hit-test/paint.d.ts.map +1 -0
- package/dist/hit-test/paint.js +19 -0
- package/dist/hit-test/paint.js.map +1 -0
- package/dist/hit-test.d.ts +4 -15
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +33 -178
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +2 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +1 -1
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/source-walk.d.ts +12 -0
- package/dist/instances/source-walk.d.ts.map +1 -0
- package/dist/node-defaults.d.ts +21 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +63 -50
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +75 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +18 -1
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -1
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +3 -6
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +28 -4
- package/dist/scaling/node.js.map +1 -1
- package/dist/shared-styles.d.ts +3 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +7 -1
- package/dist/shared-styles.js.map +1 -1
- package/dist/text/path.js +11 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.js.map +1 -1
- package/dist/token-sources/document.d.ts +26 -0
- package/dist/token-sources/document.d.ts.map +1 -0
- package/dist/token-sources/document.js +80 -0
- package/dist/token-sources/document.js.map +1 -0
- package/dist/token-sources/index.d.ts +3 -0
- package/dist/token-sources/index.js +3 -0
- package/dist/token-sources/schema.d.ts +43 -0
- package/dist/token-sources/schema.d.ts.map +1 -0
- package/dist/token-sources/schema.js +50 -0
- package/dist/token-sources/schema.js.map +1 -0
- package/dist/transfer/copied.d.ts +14 -0
- package/dist/transfer/copied.d.ts.map +1 -0
- package/dist/transfer/copied.js +52 -0
- package/dist/transfer/copied.js.map +1 -0
- package/dist/transfer/index.d.ts +2 -1
- package/dist/transfer/index.js +2 -1
- package/dist/transfer/nodes.js +7 -0
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +104 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +6 -0
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +13 -0
- package/dist/undo.js.map +1 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js.map +1 -1
- package/dist/variations/copy.d.ts +16 -0
- package/dist/variations/copy.d.ts.map +1 -0
- package/dist/variations/copy.js +78 -0
- package/dist/variations/copy.js.map +1 -0
- package/dist/variations/index.d.ts +6 -0
- package/dist/variations/index.js +6 -0
- package/dist/variations/match.d.ts +23 -0
- package/dist/variations/match.d.ts.map +1 -0
- package/dist/variations/match.js +80 -0
- package/dist/variations/match.js.map +1 -0
- package/dist/variations/model.d.ts +39 -0
- package/dist/variations/model.d.ts.map +1 -0
- package/dist/variations/model.js +90 -0
- package/dist/variations/model.js.map +1 -0
- package/dist/variations/pick.d.ts +43 -0
- package/dist/variations/pick.d.ts.map +1 -0
- package/dist/variations/pick.js +211 -0
- package/dist/variations/pick.js.map +1 -0
- package/dist/variations/schema.d.ts +27 -0
- package/dist/variations/schema.d.ts.map +1 -0
- package/dist/variations/schema.js +27 -0
- package/dist/variations/schema.js.map +1 -0
- package/package.json +21 -1
- package/src/behaviours/spec.ts +94 -4
- package/src/canvas-layout.ts +76 -0
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +12 -1
- package/src/css/text.ts +86 -0
- package/src/design-memory/index.ts +2 -0
- package/src/design-memory/model.ts +143 -0
- package/src/design-memory/schema.ts +84 -0
- package/src/effects.ts +16 -7
- package/src/empty-values.ts +101 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/generated/shape-with-text.ts +28 -2
- package/src/graph.ts +48 -6
- package/src/grid-values.ts +47 -0
- package/src/group-bounds.ts +13 -0
- package/src/hit-test/drop.ts +90 -0
- package/src/hit-test/geometry.ts +131 -0
- package/src/hit-test/masks.ts +57 -0
- package/src/hit-test/paint.ts +24 -0
- package/src/hit-test.ts +78 -291
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +1 -0
- package/src/node-defaults.ts +71 -52
- package/src/plugin-data/fields.ts +18 -1
- package/src/preview.ts +2 -0
- package/src/resize.ts +3 -14
- package/src/scaling/node.ts +34 -5
- package/src/shared-styles.ts +8 -0
- package/src/text/path.ts +14 -0
- package/src/text/picture.ts +5 -2
- package/src/token-sources/document.ts +104 -0
- package/src/token-sources/index.ts +2 -0
- package/src/token-sources/schema.ts +59 -0
- package/src/transfer/copied.ts +72 -0
- package/src/transfer/index.ts +1 -0
- package/src/transfer/nodes.ts +10 -0
- package/src/types.ts +117 -14
- package/src/undo.ts +11 -0
- package/src/variables/index.ts +1 -4
- package/src/variations/copy.ts +89 -0
- package/src/variations/index.ts +5 -0
- package/src/variations/match.ts +100 -0
- package/src/variations/model.ts +132 -0
- package/src/variations/pick.ts +293 -0
- package/src/variations/schema.ts +29 -0
package/dist/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 | '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"],"mappings":";;;;AAwCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;AAgBD,SAAS,gBACP,UACA,MACA,cACA,aACA,YACA,YAAY,GACZ,aAAa,MACE;CACf,MAAM,QAAQ,KAAK,MAAM,WAAW,IAAI,KAAK,MAAM,YAAY;CAC/D,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UACjB,OAAO;EAAE,UAAU,WAAW,KAAK,MAAM,cAAc,CAAC,IAAI,KAAK,MAAM,eAAe,CAAC;EAAG;CAAK;CAEjG,IAAI,eAAe,WAAW;EAC5B,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,YAAY,OAAO;GAAE;GAAU,MAAM,KAAK,IAAI,SAAS;EAAE;EAC9D,IAAI,cAAc,GAAG,OAAO;GAAE;GAAU;EAAK;EAC7C,IAAI,YAAY,GAAG,OAAO;GAAE;GAAU,MAAM;EAAU;EACtD,OAAO;GAAE,UAAU,WAAW;GAAW,MAAM,CAAC;GAAW,SAAS;EAAK;CAC3E;CACA,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,MAA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,MAAM,iBAAiB,OAAO,SAAS,WAAW,OAAO,SAAS;EAClE,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,WAAW,UAAU,IAAI,OAAO;GACtC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,YAAY,CAAC,OAAO;GAEzB,IADiB,OAAO,eAAe,UAAU,MAAM,sBAAsB,YAC/D;IACZ,QAAQ,SAAS,UAAU,KAAK;IAChC;GACF;GAWA,MAAM,EAAE,QAAQ,QAAQ,GAAG,QAVG,iBAC1B,gBAAgB,UAAU,cAAc,WAAW,IACnD,qBACE,UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B;GAEJ,MAAM,eAAmC;IACvC,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
|
+
{"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 { followsPath } from './text/path'\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 && followsPath(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/** 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 (!followsPath(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"],"mappings":";;;;;AAyCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;AAgBD,SAAS,gBACP,UACA,MACA,cACA,aACA,YACA,YAAY,GACZ,aAAa,MACE;CACf,MAAM,QAAQ,KAAK,MAAM,WAAW,IAAI,KAAK,MAAM,YAAY;CAC/D,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UACjB,OAAO;EAAE,UAAU,WAAW,KAAK,MAAM,cAAc,CAAC,IAAI,KAAK,MAAM,eAAe,CAAC;EAAG;CAAK;CAEjG,IAAI,eAAe,WAAW;EAC5B,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,YAAY,OAAO;GAAE;GAAU,MAAM,KAAK,IAAI,SAAS;EAAE;EAC9D,IAAI,cAAc,GAAG,OAAO;GAAE;GAAU;EAAK;EAC7C,IAAI,YAAY,GAAG,OAAO;GAAE;GAAU,MAAM;EAAU;EACtD,OAAO;GAAE,UAAU,WAAW;GAAW,MAAM,CAAC;GAAW,SAAS;EAAK;CAC3E;CACA,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,MAAM,SAAS,WAAW;EAC1B,OAAO;GACL,UAAU,YAAY,IAAI,KAAK,MAAM,SAAS,SAAS,IAAI,YAAY;GACvE,MAAM,OAAO;EACf;CACF;CACA,OAAO;EAAE;EAAU;CAAK;AAC1B;AAEA,MAAM,uCAAoD,IAAI,IAAI,CAAC,WAAW,OAAO,CAAC;;AAGtF,SAAS,eACP,QACA,MACA,YACe;CACf,IAAI,eAAe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M,eAAmC;IACvC,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":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBA8IgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
|
package/dist/scaling/node.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { scaledTextLength } from "../text/lengths.js";
|
|
2
2
|
import { cloneVectorNetwork } from "../vector-network.js";
|
|
3
|
-
import { scaleGeometryPaths } from "../copy.js";
|
|
4
|
-
import {
|
|
3
|
+
import { copyDerivedGlyphs, scaleGeometryPaths } from "../copy.js";
|
|
4
|
+
import { followsPath } from "../text/path.js";
|
|
5
5
|
import { TEXT_PARAGRAPH_SPACING_FIELDS } from "../text/paragraphs.js";
|
|
6
6
|
//#region src/scaling/node.ts
|
|
7
|
+
function scaledPathText(node, scale) {
|
|
8
|
+
if (!node.textPathData && !followsPath(node)) return {};
|
|
9
|
+
const box = node.textPathBox;
|
|
10
|
+
return {
|
|
11
|
+
derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({
|
|
12
|
+
...glyph,
|
|
13
|
+
x: glyph.x * scale,
|
|
14
|
+
y: glyph.y * scale,
|
|
15
|
+
fontSize: glyph.fontSize * scale,
|
|
16
|
+
...glyph.advance === void 0 ? {} : { advance: glyph.advance * scale }
|
|
17
|
+
})) ?? null,
|
|
18
|
+
textPathBox: box && {
|
|
19
|
+
x: box.x * scale,
|
|
20
|
+
y: box.y * scale,
|
|
21
|
+
width: box.width * scale,
|
|
22
|
+
height: box.height * scale
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
7
26
|
function scaledOptional(value, scale) {
|
|
8
27
|
return value == null ? null : value * scale;
|
|
9
28
|
}
|
|
@@ -17,7 +36,11 @@ function scaledStrokes(strokes, scale) {
|
|
|
17
36
|
function scaledEffects(effects, scale) {
|
|
18
37
|
return effects.map((effect) => {
|
|
19
38
|
const copy = structuredClone(effect);
|
|
20
|
-
if (copy.type === "SHADER") return copy;
|
|
39
|
+
if (copy.type === "SHADER" || copy.type === "NOISE") return copy;
|
|
40
|
+
if (copy.type === "TEXTURE") {
|
|
41
|
+
copy.radius *= scale;
|
|
42
|
+
return copy;
|
|
43
|
+
}
|
|
21
44
|
copy.offset = {
|
|
22
45
|
x: copy.offset.x * scale,
|
|
23
46
|
y: copy.offset.y * scale
|
|
@@ -119,6 +142,7 @@ function scaleNodeChanges(node, scale, scalePosition) {
|
|
|
119
142
|
paragraphSpacing: node.paragraphSpacing * scale,
|
|
120
143
|
paragraphIndent: node.paragraphIndent * scale,
|
|
121
144
|
textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),
|
|
145
|
+
derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),
|
|
122
146
|
itemSpacing: node.itemSpacing * scale,
|
|
123
147
|
counterAxisSpacing: node.counterAxisSpacing * scale,
|
|
124
148
|
paddingTop: node.paddingTop * scale,
|
|
@@ -143,7 +167,7 @@ function scaleNodeChanges(node, scale, scalePosition) {
|
|
|
143
167
|
vectorNetwork: scaledVectorNetwork(node, scale),
|
|
144
168
|
fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),
|
|
145
169
|
strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),
|
|
146
|
-
...
|
|
170
|
+
...scaledPathText(node, scale)
|
|
147
171
|
};
|
|
148
172
|
}
|
|
149
173
|
//#endregion
|
package/dist/scaling/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { scaleGeometryPaths } from '../copy'\nimport { scaledPathTextChanges } from '../resize'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\nimport { cloneVectorNetwork } from '../vector-network'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => {\n const copy = structuredClone(effect)\n // A shader effect has no geometry of its own; only a shadow's measures follow the layer.\n if (copy.type === 'SHADER') return copy\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\n })\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, sc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KAAK,SAAS,KAAK;EAC1C,cAAc,KAAK,eAAe;EAClC,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;EACpE,GAAG,sBAAsB,MAAM,OAAO,KAAK;CAC7C;AACF"}
|
|
1
|
+
{"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { copyDerivedGlyphs, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport { followsPath } from '../text/path'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\nimport { cloneVectorNetwork } from '../vector-network'\n\nfunction scaledPathText(node: SceneNode, scale: number): Partial<SceneNode> {\n if (!node.textPathData && !followsPath(node)) {\n return {}\n }\n const box = node.textPathBox\n return {\n derivedTextGlyphs:\n copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({\n ...glyph,\n x: glyph.x * scale,\n y: glyph.y * scale,\n fontSize: glyph.fontSize * scale,\n ...(glyph.advance === undefined ? {} : { advance: glyph.advance * scale })\n })) ?? null,\n textPathBox: box && {\n x: box.x * scale,\n y: box.y * scale,\n width: box.width * scale,\n height: box.height * scale\n }\n }\n}\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => {\n const copy = structuredClone(effect)\n // A shader effect has no geometry of its own, and a noise's grain keeps its size.\n if (copy.type === 'SHADER' || copy.type === 'NOISE') return copy\n // A texture roughens the edges by its radius; its grain keeps its size too.\n if (copy.type === 'TEXTURE') {\n copy.radius *= scale\n return copy\n }\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\n })\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),\n ...scaledPathText(node, scale)\n }\n}\n"],"mappings":";;;;;;AAgBA,SAAS,eAAe,MAAiB,OAAmC;CAC1E,IAAI,CAAC,KAAK,gBAAgB,CAAC,YAAY,IAAI,GACzC,OAAO,CAAC;CAEV,MAAM,MAAM,KAAK;CACjB,OAAO;EACL,mBACE,kBAAkB,KAAK,iBAAiB,CAAC,EAAE,KAAK,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AAe,KAAK,mBAAmB,KAAK;EAC/D,aAAa,KAAK,cAAc;EAChC,oBAAoB,KAAK,qBAAqB;EAC9C,YAAY,KAAK,aAAa;EAC9B,cAAc,KAAK,eAAe;EAClC,eAAe,KAAK,gBAAgB;EACpC,aAAa,KAAK,cAAc;EAChC,eAAe,KAAK,gBAAgB;EACpC,YAAY,KAAK,aAAa;EAC9B,qBAAqB,iBAAiB,KAAK,qBAAqB,KAAK;EACrE,kBAAkB,iBAAiB,KAAK,kBAAkB,KAAK;EAC/D,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,cAAc,KAAK,eAAe;EAClC,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;EACpE,GAAG,eAAe,MAAM,KAAK;CAC/B;AACF"}
|
package/dist/shared-styles.d.ts
CHANGED
|
@@ -29,8 +29,10 @@ declare const FACE_KEYS: readonly ["fontFamily", "fontWeight", "italic"];
|
|
|
29
29
|
declare function rangeFontStyle(node: Pick<SceneNode, 'fontStyle'>, style: CharacterStyleOverride): string | null;
|
|
30
30
|
declare function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind];
|
|
31
31
|
declare function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType;
|
|
32
|
+
/** The document's shared style layers, by the source ID layers link them by. */
|
|
33
|
+
declare function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode>;
|
|
32
34
|
declare function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[];
|
|
33
35
|
declare function styleDetachmentChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
34
36
|
//#endregion
|
|
35
|
-
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, getSharedStyles, rangeFontStyle, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
37
|
+
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, getSharedStyles, rangeFontStyle, sharedStyleLayers, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
36
38
|
//# sourceMappingURL=shared-styles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;iBAK/C,kBAAkB,OAAO,aAAa,YAAY;iBAOlD,gBAAgB,OAAO,YAAY,MAAM,kBAAkB;iBAuB3D,uBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ"}
|
package/dist/shared-styles.js
CHANGED
|
@@ -67,6 +67,12 @@ function sharedStyleRefKey(kind) {
|
|
|
67
67
|
function sharedStyleTypeForKind(kind) {
|
|
68
68
|
return STYLE_TYPES[kind];
|
|
69
69
|
}
|
|
70
|
+
/** The document's shared style layers, by the source ID layers link them by. */
|
|
71
|
+
function sharedStyleLayers(graph) {
|
|
72
|
+
const styles = /* @__PURE__ */ new Map();
|
|
73
|
+
for (const node of graph.getAllNodes()) if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node);
|
|
74
|
+
return styles;
|
|
75
|
+
}
|
|
70
76
|
function getSharedStyles(graph, kind) {
|
|
71
77
|
const type = sharedStyleTypeForKind(kind);
|
|
72
78
|
const styles = [];
|
|
@@ -104,6 +110,6 @@ function styleDetachmentChanges(node, changes) {
|
|
|
104
110
|
return next;
|
|
105
111
|
}
|
|
106
112
|
//#endregion
|
|
107
|
-
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, getSharedStyles, rangeFontStyle, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
113
|
+
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, getSharedStyles, rangeFontStyle, sharedStyleLayers, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
108
114
|
|
|
109
115
|
//# sourceMappingURL=shared-styles.js.map
|
|
@@ -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 { 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,oBAAo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iBAAiB,KAAK,QAAQ,OAAO,IAAI,CAAC;CACpE,OAAO,QAAQ,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"}
|
|
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\n/** The document's shared style layers, by the source ID layers link them by. */\nexport function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode> {\n const styles = new Map<string, SceneNode>()\n for (const node of graph.getAllNodes())\n if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node)\n return styles\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,cA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IAAI,CAAC;AACzE;;;;;;AAOA,SAAS,oBAAoB,SAA4B,MAAkC;CACzF,MAAM,UAAU,YACd,QAAQ,KAAK,WAAW,KAAK,QAAQ,gBAAgB,CAAC;CACxD,MAAM,SAAS,YACb,QAAQ,KAAK,WAAW,iBAAiB,KAAK,QAAQ,OAAO,IAAI,CAAC;CACpE,OAAO,QAAQ,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/text/path.ts
|
|
2
|
+
/** Whether the node's glyphs were baked along a path, including rotated-as-a-picture text. */
|
|
3
|
+
function followsPath(node) {
|
|
4
|
+
const glyphs = node.derivedTextGlyphs ?? [];
|
|
5
|
+
if (glyphs.length === 0) return false;
|
|
6
|
+
return !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { followsPath };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","names":[],"sources":["../../src/text/path.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\n/** Whether the node's glyphs were baked along a path, including rotated-as-a-picture text. */\nexport function followsPath(\n node: Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>\n): boolean {\n const glyphs = node.derivedTextGlyphs ?? []\n if (glyphs.length === 0) {\n return false\n }\n return (\n !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n )\n}\n"],"mappings":";;AAGA,SAAgB,YACd,MACS;CACT,MAAM,SAAS,KAAK,qBAAqB,CAAC;CAC1C,IAAI,OAAO,WAAW,GACpB,OAAO;CAET,OACE,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,KAAK,eAAe,OAAO,MAAM,WAAW,MAAM,YAAY,OAAO,CAAC;AAEnG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../src/text/picture.ts"],"mappings":";;;;;;cASa,mBAAmB;cAQnB,sBAAsB;;;;;;iBAOnB,6BACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;
|
|
1
|
+
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../src/text/picture.ts"],"mappings":";;;;;;cASa,mBAAmB;cAQnB,sBAAsB;;;;;;iBAOnB,6BACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;iBA8BK,qBAAqB,MAAM,WAAW,SAAS,QAAQ"}
|
package/dist/text/picture.js
CHANGED
|
@@ -24,11 +24,11 @@ function textCacheInvalidationChanges(node, changes) {
|
|
|
24
24
|
if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key))) invalidated.textPicture = null;
|
|
25
25
|
const glyphsInvalidated = keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) || TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key));
|
|
26
26
|
if (glyphsInvalidated && !("derivedLayout" in changes)) invalidated.derivedLayout = null;
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (glyphsInvalidated && !changes.derivedTextGlyphs) {
|
|
28
|
+
const onlyPathBoxResize = !!node.textPathData && keys.every((key) => key === "width" || key === "height");
|
|
29
|
+
const placesPath = keys.includes("textPathBox") && !!changes.textPathBox;
|
|
30
|
+
if (node.derivedTextGlyphs && !onlyPathBoxResize) invalidated.derivedTextGlyphs = null;
|
|
31
|
+
if (node.textPathData && !onlyPathBoxResize && !placesPath) invalidated.textPathData = null;
|
|
32
32
|
}
|
|
33
33
|
return invalidated;
|
|
34
34
|
}
|
package/dist/text/picture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n // A successful path-text edit supplies reflowed glyphs in `changes`. Every\n // other mutation path must drop stale baked glyphs and path identity rather\n // than pair new text/style with old visible outlines.\n if (
|
|
1
|
+
{"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n // A successful path-text edit supplies reflowed glyphs in `changes`. Every\n // other mutation path must drop stale baked glyphs and path identity rather\n // than pair new text/style with old visible outlines.\n if (glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n const placesPath = keys.includes('textPathBox') && !!changes.textPathBox\n if (node.derivedTextGlyphs && !onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n }\n if (node.textPathData && !onlyPathBoxResize && !placesPath) {\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n\nexport function invalidateTextCaches(node: SceneNode, changes: Partial<SceneNode>): void {\n Object.assign(node, textCacheInvalidationChanges(node, changes))\n}\n"],"mappings":";;;;;;;AASA,MAAa,oCAAyC,IAAI,IAAI;CAC5D,GAAG;CACH;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,uBAA4C,IAAI,IAAI,mBAAmB;;;;;;AAOpF,SAAgB,6BACd,MACA,SACoB;CACpB,MAAM,cAAkC,CAAC;CACzC,MAAM,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,QAC/B,QAAQ,CAAC,QAAQ,KAAK,MAAyB,QAAQ,IAAuB,CACjF;CACA,IAAI,KAAK,eAAe,KAAK,MAAM,QAAQ,kBAAkB,IAAI,GAAG,CAAC,GACnE,YAAY,cAAc;CAC5B,MAAM,oBACJ,KAAK,MAAM,QAAQ,qBAAqB,IAAI,GAAG,CAAC,KAChD,mBAAmB,MAAM,QAAQ,KAAK,SAAS,GAAG,CAAC;CACrD,IAAI,qBAAqB,EAAE,mBAAmB,UAAU,YAAY,gBAAgB;CAIpF,IAAI,qBAAqB,CAAC,QAAQ,mBAAmB;EAGnD,MAAM,oBACJ,CAAC,CAAC,KAAK,gBAAgB,KAAK,OAAO,QAAQ,QAAQ,WAAW,QAAQ,QAAQ;EAChF,MAAM,aAAa,KAAK,SAAS,aAAa,KAAK,CAAC,CAAC,QAAQ;EAC7D,IAAI,KAAK,qBAAqB,CAAC,mBAC7B,YAAY,oBAAoB;EAElC,IAAI,KAAK,gBAAgB,CAAC,qBAAqB,CAAC,YAC9C,YAAY,eAAe;CAE/B;CACA,OAAO;AACT;AAEA,SAAgB,qBAAqB,MAAiB,SAAmC;CACvF,OAAO,OAAO,MAAM,6BAA6B,MAAM,OAAO,CAAC;AACjE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { PluginDataEntry } from "../types.js";
|
|
3
|
+
import { TokenSource } from "./schema.js";
|
|
4
|
+
//#region src/token-sources/document.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The code a document's variables are linked to, with what it held at the last sync. The links
|
|
7
|
+
* live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and
|
|
8
|
+
* Figma ignores them; where each file is on this computer stays with the app, not the document.
|
|
9
|
+
*/
|
|
10
|
+
declare function readTokenSources(graph: SceneGraph): TokenSource[];
|
|
11
|
+
/**
|
|
12
|
+
* The links with their snapshots keyed by the graph's variable and mode ids. A format that keys
|
|
13
|
+
* variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the
|
|
14
|
+
* names the file stored when it was saved, or the last sync's where the file recorded none, find
|
|
15
|
+
* them again. `names` and the snapshot's token identities are kept as they were. Links whose
|
|
16
|
+
* variables are all gone are left as they are.
|
|
17
|
+
*/
|
|
18
|
+
declare function rekeyTokenSources(graph: SceneGraph, sources: readonly TokenSource[]): TokenSource[];
|
|
19
|
+
/**
|
|
20
|
+
* The document node's plugin data holding `sources` in place of its links, for an edit that
|
|
21
|
+
* writes them, undoably or not, as one change to the node.
|
|
22
|
+
*/
|
|
23
|
+
declare function tokenSourcesPluginData(graph: SceneGraph, sources: readonly TokenSource[]): PluginDataEntry[];
|
|
24
|
+
//#endregion
|
|
25
|
+
export { readTokenSources, rekeyTokenSources, tokenSourcesPluginData };
|
|
26
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","names":[],"sources":["../../src/token-sources/document.ts"],"mappings":";;;;;;;;;iBAegB,iBAAiB,OAAO,aAAa;;;;;;;;iBAWrC,kBACd,OAAO,YACP,kBAAkB,gBACjB;;;;;iBA4Da,uBACd,OAAO,YACP,kBAAkB,gBACjB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
2
|
+
import { relativeTokenPathSchema } from "./schema.js";
|
|
3
|
+
import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
4
|
+
import * as v from "valibot";
|
|
5
|
+
//#region src/token-sources/document.ts
|
|
6
|
+
const { tokenSources } = PAIRDRAW_PLUGIN_DATA;
|
|
7
|
+
/**
|
|
8
|
+
* The code a document's variables are linked to, with what it held at the last sync. The links
|
|
9
|
+
* live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and
|
|
10
|
+
* Figma ignores them; where each file is on this computer stays with the app, not the document.
|
|
11
|
+
*/
|
|
12
|
+
function readTokenSources(graph) {
|
|
13
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, tokenSources) ?? [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The links with their snapshots keyed by the graph's variable and mode ids. A format that keys
|
|
17
|
+
* variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the
|
|
18
|
+
* names the file stored when it was saved, or the last sync's where the file recorded none, find
|
|
19
|
+
* them again. `names` and the snapshot's token identities are kept as they were. Links whose
|
|
20
|
+
* variables are all gone are left as they are.
|
|
21
|
+
*/
|
|
22
|
+
function rekeyTokenSources(graph, sources) {
|
|
23
|
+
const collectionsByName = new Map([...graph.variableCollections.values()].map((collection) => [collection.name, collection]));
|
|
24
|
+
const variablesByKey = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const variable of graph.variables.values()) {
|
|
26
|
+
const collection = graph.variableCollections.get(variable.collectionId);
|
|
27
|
+
if (collection) variablesByKey.set(`${collection.name}/${variable.name}`, variable.id);
|
|
28
|
+
}
|
|
29
|
+
const currentModeId = (collectionName, modeId, modes) => {
|
|
30
|
+
const name = modes?.[collectionName]?.[modeId];
|
|
31
|
+
if (name === void 0) return modeId;
|
|
32
|
+
return (collectionsByName.get(collectionName)?.modes.find((entry) => entry.name === name))?.modeId ?? modeId;
|
|
33
|
+
};
|
|
34
|
+
return sources.map((source) => {
|
|
35
|
+
const ids = /* @__PURE__ */ new Map();
|
|
36
|
+
for (const [id, key] of Object.entries(source.currentNames ?? source.names ?? {})) {
|
|
37
|
+
const current = variablesByKey.get(key);
|
|
38
|
+
if (current !== void 0) ids.set(id, current);
|
|
39
|
+
}
|
|
40
|
+
if (ids.size === 0) return source;
|
|
41
|
+
const collectionOf = (id) => {
|
|
42
|
+
const variable = graph.variables.get(id);
|
|
43
|
+
return variable ? graph.variableCollections.get(variable.collectionId)?.name : void 0;
|
|
44
|
+
};
|
|
45
|
+
const snapshot = {};
|
|
46
|
+
for (const [oldId, values] of Object.entries(source.snapshot)) {
|
|
47
|
+
const id = ids.get(oldId) ?? oldId;
|
|
48
|
+
const collection = collectionOf(id);
|
|
49
|
+
const entry = {};
|
|
50
|
+
for (const [modeId, signature] of Object.entries(values)) entry[collection ? currentModeId(collection, modeId, source.modes) : modeId] = signature;
|
|
51
|
+
snapshot[id] = {
|
|
52
|
+
...snapshot[id],
|
|
53
|
+
...entry
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const names = Object.fromEntries(Object.entries(source.names ?? {}).map(([id, key]) => [ids.get(id) ?? id, key]));
|
|
57
|
+
const modes = source.modes ? Object.fromEntries(Object.entries(source.modes).map(([collectionName, byMode]) => [collectionName, Object.fromEntries(Object.entries(byMode).map(([modeId, name]) => [currentModeId(collectionName, modeId, source.modes), name]))])) : void 0;
|
|
58
|
+
return {
|
|
59
|
+
...source,
|
|
60
|
+
snapshot,
|
|
61
|
+
names,
|
|
62
|
+
...modes ? { modes } : {}
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The document node's plugin data holding `sources` in place of its links, for an edit that
|
|
68
|
+
* writes them, undoably or not, as one change to the node.
|
|
69
|
+
*/
|
|
70
|
+
function tokenSourcesPluginData(graph, sources) {
|
|
71
|
+
const stored = sources.map(({ path, ...source }) => path !== void 0 && v.is(relativeTokenPathSchema, path) ? {
|
|
72
|
+
...source,
|
|
73
|
+
path
|
|
74
|
+
} : source);
|
|
75
|
+
return withPluginData(graph.getNode(graph.rootId)?.pluginData ?? [], tokenSources, stored.length > 0 ? stored : void 0);
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { readTokenSources, rekeyTokenSources, tokenSourcesPluginData };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","names":[],"sources":["../../src/token-sources/document.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { PluginDataEntry } from '../types'\nimport { relativeTokenPathSchema, type TokenSource } from './schema'\n\nconst { tokenSources } = PAIRDRAW_PLUGIN_DATA\n\n/**\n * The code a document's variables are linked to, with what it held at the last sync. The links\n * live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and\n * Figma ignores them; where each file is on this computer stays with the app, not the document.\n */\nexport function readTokenSources(graph: SceneGraph): TokenSource[] {\n return readPluginData(graph.getNode(graph.rootId)?.pluginData, tokenSources) ?? []\n}\n\n/**\n * The links with their snapshots keyed by the graph's variable and mode ids. A format that keys\n * variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the\n * names the file stored when it was saved, or the last sync's where the file recorded none, find\n * them again. `names` and the snapshot's token identities are kept as they were. Links whose\n * variables are all gone are left as they are.\n */\nexport function rekeyTokenSources(\n graph: SceneGraph,\n sources: readonly TokenSource[]\n): TokenSource[] {\n const collectionsByName = new Map(\n [...graph.variableCollections.values()].map((collection) => [collection.name, collection])\n )\n const variablesByKey = new Map<string, string>()\n for (const variable of graph.variables.values()) {\n const collection = graph.variableCollections.get(variable.collectionId)\n if (collection) variablesByKey.set(`${collection.name}/${variable.name}`, variable.id)\n }\n const currentModeId = (collectionName: string, modeId: string, modes: TokenSource['modes']) => {\n const name = modes?.[collectionName]?.[modeId]\n if (name === undefined) return modeId\n const mode = collectionsByName.get(collectionName)?.modes.find((entry) => entry.name === name)\n return mode?.modeId ?? modeId\n }\n return sources.map((source) => {\n const ids = new Map<string, string>()\n for (const [id, key] of Object.entries(source.currentNames ?? source.names ?? {})) {\n const current = variablesByKey.get(key)\n if (current !== undefined) ids.set(id, current)\n }\n if (ids.size === 0) return source\n const collectionOf = (id: string) => {\n const variable = graph.variables.get(id)\n return variable ? graph.variableCollections.get(variable.collectionId)?.name : undefined\n }\n const snapshot: TokenSource['snapshot'] = {}\n for (const [oldId, values] of Object.entries(source.snapshot)) {\n const id = ids.get(oldId) ?? oldId\n const collection = collectionOf(id)\n const entry: Record<string, string> = {}\n for (const [modeId, signature] of Object.entries(values)) {\n entry[collection ? currentModeId(collection, modeId, source.modes) : modeId] = signature\n }\n snapshot[id] = { ...snapshot[id], ...entry }\n }\n const names = Object.fromEntries(\n Object.entries(source.names ?? {}).map(([id, key]) => [ids.get(id) ?? id, key])\n )\n const modes = source.modes\n ? Object.fromEntries(\n Object.entries(source.modes).map(([collectionName, byMode]) => [\n collectionName,\n Object.fromEntries(\n Object.entries(byMode).map(([modeId, name]) => [\n currentModeId(collectionName, modeId, source.modes),\n name\n ])\n )\n ])\n )\n : undefined\n return { ...source, snapshot, names, ...(modes ? { modes } : {}) }\n })\n}\n\n/**\n * The document node's plugin data holding `sources` in place of its links, for an edit that\n * writes them, undoably or not, as one change to the node.\n */\nexport function tokenSourcesPluginData(\n graph: SceneGraph,\n sources: readonly TokenSource[]\n): PluginDataEntry[] {\n // A path that is not relative would make the reader drop the whole link; the link keeps going\n // by its name instead.\n const stored = sources.map(({ path, ...source }) =>\n path !== undefined && v.is(relativeTokenPathSchema, path) ? { ...source, path } : source\n )\n return withPluginData(\n graph.getNode(graph.rootId)?.pluginData ?? [],\n tokenSources,\n stored.length > 0 ? stored : undefined\n )\n}\n"],"mappings":";;;;;AAQA,MAAM,EAAE,iBAAiB;;;;;;AAOzB,SAAgB,iBAAiB,OAAkC;CACjE,OAAO,eAAe,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,YAAY,YAAY,KAAK,CAAC;AACnF;;;;;;;;AASA,SAAgB,kBACd,OACA,SACe;CACf,MAAM,oBAAoB,IAAI,IAC5B,CAAC,GAAG,MAAM,oBAAoB,OAAO,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,WAAW,MAAM,UAAU,CAAC,CAC3F;CACA,MAAM,iCAAiB,IAAI,IAAoB;CAC/C,KAAK,MAAM,YAAY,MAAM,UAAU,OAAO,GAAG;EAC/C,MAAM,aAAa,MAAM,oBAAoB,IAAI,SAAS,YAAY;EACtE,IAAI,YAAY,eAAe,IAAI,GAAG,WAAW,KAAK,GAAG,SAAS,QAAQ,SAAS,EAAE;CACvF;CACA,MAAM,iBAAiB,gBAAwB,QAAgB,UAAgC;EAC7F,MAAM,OAAO,QAAQ,eAAe,GAAG;EACvC,IAAI,SAAS,KAAA,GAAW,OAAO;EAE/B,QADa,kBAAkB,IAAI,cAAc,CAAC,EAAE,MAAM,MAAM,UAAU,MAAM,SAAS,IAAI,EAAA,EAChF,UAAU;CACzB;CACA,OAAO,QAAQ,KAAK,WAAW;EAC7B,MAAM,sBAAM,IAAI,IAAoB;EACpC,KAAK,MAAM,CAAC,IAAI,QAAQ,OAAO,QAAQ,OAAO,gBAAgB,OAAO,SAAS,CAAC,CAAC,GAAG;GACjF,MAAM,UAAU,eAAe,IAAI,GAAG;GACtC,IAAI,YAAY,KAAA,GAAW,IAAI,IAAI,IAAI,OAAO;EAChD;EACA,IAAI,IAAI,S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AAQ;CAAK,IAAI,MACpF;CACA,OAAO,eACL,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,cAAc,CAAC,GAC5C,cACA,OAAO,SAAS,IAAI,SAAS,KAAA,CAC/B;AACF"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TokenSource, relativeTokenPathSchema, tokenSourcesSchema } from "./schema.js";
|
|
2
|
+
import { readTokenSources, rekeyTokenSources, tokenSourcesPluginData } from "./document.js";
|
|
3
|
+
export { TokenSource, readTokenSources, rekeyTokenSources, relativeTokenPathSchema, tokenSourcesPluginData, tokenSourcesSchema };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { relativeTokenPathSchema, tokenSourcesSchema } from "./schema.js";
|
|
2
|
+
import { readTokenSources, rekeyTokenSources, tokenSourcesPluginData } from "./document.js";
|
|
3
|
+
export { readTokenSources, rekeyTokenSources, relativeTokenPathSchema, tokenSourcesPluginData, tokenSourcesSchema };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/token-sources/schema.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A path from the document's folder, never one that names a place on its own: no leading `/` or
|
|
5
|
+
* `\\` (POSIX roots, UNC shares), no `~` (a home folder), and no drive letter or URL scheme such
|
|
6
|
+
* as `C:` or `file:`.
|
|
7
|
+
*/
|
|
8
|
+
declare const relativeTokenPathSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 1024, undefined>, v.CheckAction<string, "A linked path is relative to the document">]>;
|
|
9
|
+
declare const tokenSourceSchema: v.ObjectSchema<{
|
|
10
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 64, undefined>]>;
|
|
11
|
+
/** A stylesheet, a project folder, or W3C design token files. */
|
|
12
|
+
readonly kind: v.PicklistSchema<["css", "folder", "dtcg"], undefined>;
|
|
13
|
+
/** The file or folder name, for people. */
|
|
14
|
+
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>]>;
|
|
15
|
+
/** Where it is from the document's folder, when the document has one. */
|
|
16
|
+
readonly path: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 1024, undefined>, v.CheckAction<string, "A linked path is relative to the document">]>, undefined>;
|
|
17
|
+
readonly syncedAt: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>, undefined>;
|
|
18
|
+
/** What the code held at the last sync: a value signature by variable id and mode id. */
|
|
19
|
+
readonly snapshot: v.RecordSchema<v.StringSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* The token each variable was at the last sync, `Collection/name` by variable id, so a variable
|
|
22
|
+
* deleted on the canvas is known when the code still has it.
|
|
23
|
+
*/
|
|
24
|
+
readonly names: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* The names the document held when it was saved, `Collection/name` by variable id. A format that
|
|
27
|
+
* keys variables by name gives them new ids when it reads them back; this finds a renamed
|
|
28
|
+
* variable's new id while `names` keeps the token it was at the last sync.
|
|
29
|
+
*/
|
|
30
|
+
readonly currentNames: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* The mode names the document holds, by collection name and mode id. A format that keys variables
|
|
33
|
+
* and modes by name gives them new ids when it reads them back, and this maps the snapshot onto
|
|
34
|
+
* those.
|
|
35
|
+
*/
|
|
36
|
+
readonly modes: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>, undefined>;
|
|
37
|
+
}, undefined>;
|
|
38
|
+
type TokenSource = v.InferOutput<typeof tokenSourceSchema>;
|
|
39
|
+
/** The code a document's variables are linked to; entries that cannot be read are left out. */
|
|
40
|
+
declare const tokenSourcesSchema: v.GenericSchema<unknown, TokenSource[]>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { TokenSource, relativeTokenPathSchema, tokenSourcesSchema };
|
|
43
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/token-sources/schema.ts"],"mappings":";;;;;;;cAOa,yBAAuB,EAAA,yBAAA,EAAA,yBAAA,EAAA,mCAAA,EAAA,0CAAA,EAAA;cAU9B,mBAAiB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BX,cAAc,EAAE,mBAAmB;;cAGlC,oBAAoB,EAAE,uBAAuB"}
|