@pairdraw/scene-graph 0.21.0 → 0.22.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/constants.d.ts +10 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +60 -2
- package/dist/constants.js.map +1 -1
- package/dist/copy.js +7 -0
- package/dist/copy.js.map +1 -1
- package/dist/effects.d.ts +9 -1
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +10 -1
- package/dist/effects.js.map +1 -1
- package/dist/fields/layout.d.ts +1 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +3 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +3 -3
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +4 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +9 -0
- package/dist/graph.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +1 -1
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +17 -1
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +41 -1
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +5 -3
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +5 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +2 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +8 -3
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/placement.js +1 -1
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/sync.js +24 -5
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +4 -0
- package/dist/node-defaults.js.map +1 -1
- package/dist/resize.d.ts +9 -2
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +20 -8
- package/dist/resize.js.map +1 -1
- package/dist/slots/content.d.ts +46 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +146 -2
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/index.d.ts +3 -2
- package/dist/slots/index.js +3 -2
- package/dist/slots/owners.d.ts +17 -0
- package/dist/slots/owners.d.ts.map +1 -0
- package/dist/slots/owners.js +39 -0
- package/dist/slots/owners.js.map +1 -0
- package/dist/types.d.ts +115 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +9 -3
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +128 -26
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +20 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +29 -3
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/index.d.ts +3 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +25 -4
- package/dist/variables/index.js.map +1 -1
- package/dist/variant-properties.d.ts +7 -2
- package/dist/variant-properties.d.ts.map +1 -1
- package/dist/variant-properties.js +35 -3
- package/dist/variant-properties.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +32 -3
- package/src/copy.ts +7 -0
- package/src/effects.ts +21 -0
- package/src/fields/layout.ts +3 -1
- package/src/geometry.ts +5 -3
- package/src/graph.ts +13 -0
- package/src/hit-test.ts +7 -1
- package/src/images.ts +61 -2
- package/src/instances/fields.ts +5 -0
- package/src/instances/index.ts +10 -1
- package/src/instances/placement.ts +2 -1
- package/src/instances/sync.ts +38 -5
- package/src/node-defaults.ts +4 -0
- package/src/resize.ts +44 -6
- package/src/slots/content.ts +208 -1
- package/src/slots/index.ts +1 -0
- package/src/slots/owners.ts +45 -0
- package/src/types.ts +207 -3
- package/src/variables/bindings.ts +155 -33
- package/src/variables/fields.ts +41 -2
- package/src/variables/index.ts +40 -1
- package/src/variant-properties.ts +36 -2
package/dist/images.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images.js","names":["readImageHeader"],"sources":["../src/images.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex } from '@noble/hashes/utils.js'\nimport { imageSize as readImageHeader } from 'image-size'\n\nimport type { Matrix, Size } from './primitives'\n\n/**\n * The name an image's bytes are stored under: the hex SHA-1 of the bytes, as Figma names images,\n * so `.fig` files and the Figma clipboard can carry the name as it is. Documents saved before may\n * hold images under other names; anything that hands images to Figma still checks.\n */\nexport function computeImageHash(data: Uint8Array): string {\n return bytesToHex(sha1(data))\n}\n\nexport type ImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/avif'\n\n/** The image types documents store, by the name `image-size` gives each format. */\nconst IMAGE_MIME_TYPES: Partial<Record<string, ImageMimeType>> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp'\n}\n\n/** The raster types a dropped or pasted file can be imported as an image fill from. */\nexport const IMPORTABLE_RASTER_TYPES: ReadonlySet<string> = new Set([\n 'image/png',\n 'image/jpeg',\n 'image/webp',\n 'image/gif',\n 'image/avif'\n])\n\n/** Whether a file is an SVG image, which some systems report without a media type. */\nexport function isSVGFile(file: { name: string; type: string }): boolean {\n return (\n file.type === 'image/svg+xml' || (file.type === '' && file.name.toLowerCase().endsWith('.svg'))\n )\n}\n\nexport interface ImageHeader extends Size {\n type: ImageMimeType\n}\n\n/**\n * The type and size of a PNG, JPEG, GIF, or WebP, read from its header by `image-size`; null for\n * bytes it cannot read and for other formats.\n */\nexport function imageHeader(data: Uint8Array): ImageHeader | null {\n let header: ReturnType<typeof readImageHeader>\n try {\n header = readImageHeader(data)\n } catch {\n return null\n }\n const type = header.type === undefined ? undefined : IMAGE_MIME_TYPES[header.type]\n return type ? { type, width: header.width, height: header.height } : null\n}\n\n/** A four-character ISO media brand at `start`, or an empty string when the bytes are short. */\nfunction isoBrand(data: Uint8Array, start: number): string {\n if (start + 4 > data.length) return ''\n return String.fromCharCode(\n data[start] ?? 0,\n data[start + 1] ?? 0,\n data[start + 2] ?? 0,\n data[start + 3] ?? 0\n )\n}\n\n/** Whether bytes are an AVIF image, whose `ftyp` box names the brand or lists it as compatible. */\nfunction isAVIF(data: Uint8Array): boolean {\n if (isoBrand(data, 4) !== 'ftyp') return false\n const size = ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]) >>> 0\n const isAvif = (brand: string) => brand === 'avif' || brand === 'avis'\n if (isAvif(isoBrand(data, 8))) return true\n const end = Math.min(size >= 16 ? size : data.length, data.length)\n // The major brand is followed by a minor version, then the compatible brands.\n for (let start = 16; start + 4 <= end; start += 4) if (isAvif(isoBrand(data, start))) return true\n return false\n}\n\n/**\n * The media type of encoded image bytes, read from their header, for writing them out as a data\n * URL or file. AVIF is read from its ISO media brand, which `image-size` does not decode. Bytes it\n * cannot read are reported as PNG, as image fills began.\n */\nexport function imageMimeType(data: Uint8Array): ImageMimeType {\n return imageHeader(data)?.type ?? (isAVIF(data) ? 'image/avif' : 'image/png')\n}\n\n/** An image's size in pixels, read from its header; null for bytes it cannot read. */\nexport function imageSize(data: Uint8Array): Size | null {\n const header = imageHeader(data)\n return header && { width: header.width, height: header.height }\n}\n\n/**\n * The crop that shows an image as Fill does: scaled to cover a `width` × `height` layer and\n * centred. Figma starts a crop from it, as the image-space window a crop's transform holds.\n */\nexport function coverImageTransform(\n width: number,\n height: number,\n imageWidth: number,\n imageHeight: number\n):
|
|
1
|
+
{"version":3,"file":"images.js","names":["readImageHeader"],"sources":["../src/images.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex } from '@noble/hashes/utils.js'\nimport { imageSize as readImageHeader } from 'image-size'\n\nimport Matrix from './matrix'\nimport type { Matrix as MatrixType, Size } from './primitives'\nimport type { Fill, SceneNode } from './types'\n\n/**\n * The name an image's bytes are stored under: the hex SHA-1 of the bytes, as Figma names images,\n * so `.fig` files and the Figma clipboard can carry the name as it is. Documents saved before may\n * hold images under other names; anything that hands images to Figma still checks.\n */\nexport function computeImageHash(data: Uint8Array): string {\n return bytesToHex(sha1(data))\n}\n\n/**\n * Maps `img`'s pixels onto `node` as `fill` places them. `size` is the image's own size when `img`\n * is a downscaled preview, so a tile keeps its size. A crop places the image by its transform;\n * Fill, Fit and Tile ignore it, as Figma does, and turn the image by `imageRotation` first.\n */\nexport function makeImageFillLocalMatrix(\n fill: Fill,\n node: SceneNode,\n imgW: number,\n imgH: number,\n size: { width: number; height: number } = { width: imgW, height: imgH }\n) {\n const scaleMode = fill.imageScaleMode ?? 'FILL'\n if (scaleMode === 'CROP') {\n // Figma turns the crop by its transform alone: `rotation` is automatic for a crop, so an\n // unset transform stretches the image to the layer however the paint's rotation reads.\n const t = fill.imageTransform\n const inverse = t && Matrix.invert([t.m00, t.m01, t.m02, t.m10, t.m11, t.m12, 0, 0, 1])\n if (inverse)\n return Matrix.multiply(\n Matrix.scaled(node.width, node.height),\n inverse,\n Matrix.scaled(1 / imgW, 1 / imgH)\n )\n return Matrix.scaled(node.width / imgW, node.height / imgH)\n }\n\n const radians = ((fill.imageRotation ?? 0) * Math.PI) / 180\n const cos = Math.abs(Math.cos(radians))\n const sin = Math.abs(Math.sin(radians))\n const turnedW = size.width * cos + size.height * sin\n const turnedH = size.width * sin + size.height * cos\n const turned = Matrix.multiply(\n Matrix.translated(turnedW / 2, turnedH / 2),\n Matrix.rotated(radians),\n Matrix.translated(-size.width / 2, -size.height / 2),\n Matrix.scaled(size.width / imgW, size.height / imgH)\n )\n if (scaleMode === 'TILE') {\n const scale = fill.scale && fill.scale > 0 ? fill.scale : 1\n return Matrix.multiply(Matrix.scaled(scale, scale), turned)\n }\n const fit = scaleMode === 'FIT'\n const scale = (fit ? Math.min : Math.max)(node.width / turnedW, node.height / turnedH)\n return Matrix.multiply(\n Matrix.translated((node.width - turnedW * scale) / 2, (node.height - turnedH * scale) / 2),\n Matrix.scaled(scale, scale),\n turned\n )\n}\n\n/** An image fill that CSS draws as a background: its data URL and how it repeats. */\nexport interface ImagePlacement {\n url: string\n mode: 'CROP' | 'TILE'\n}\n\nexport type ImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/avif'\n\n/** The image types documents store, by the name `image-size` gives each format. */\nconst IMAGE_MIME_TYPES: Partial<Record<string, ImageMimeType>> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp'\n}\n\n/** The raster types a dropped or pasted file can be imported as an image fill from. */\nexport const IMPORTABLE_RASTER_TYPES: ReadonlySet<string> = new Set([\n 'image/png',\n 'image/jpeg',\n 'image/webp',\n 'image/gif',\n 'image/avif'\n])\n\n/** Whether a file is an SVG image, which some systems report without a media type. */\nexport function isSVGFile(file: { name: string; type: string }): boolean {\n return (\n file.type === 'image/svg+xml' || (file.type === '' && file.name.toLowerCase().endsWith('.svg'))\n )\n}\n\nexport interface ImageHeader extends Size {\n type: ImageMimeType\n}\n\n/**\n * The type and size of a PNG, JPEG, GIF, or WebP, read from its header by `image-size`; null for\n * bytes it cannot read and for other formats.\n */\nexport function imageHeader(data: Uint8Array): ImageHeader | null {\n let header: ReturnType<typeof readImageHeader>\n try {\n header = readImageHeader(data)\n } catch {\n return null\n }\n const type = header.type === undefined ? undefined : IMAGE_MIME_TYPES[header.type]\n return type ? { type, width: header.width, height: header.height } : null\n}\n\n/** A four-character ISO media brand at `start`, or an empty string when the bytes are short. */\nfunction isoBrand(data: Uint8Array, start: number): string {\n if (start + 4 > data.length) return ''\n return String.fromCharCode(\n data[start] ?? 0,\n data[start + 1] ?? 0,\n data[start + 2] ?? 0,\n data[start + 3] ?? 0\n )\n}\n\n/** Whether bytes are an AVIF image, whose `ftyp` box names the brand or lists it as compatible. */\nfunction isAVIF(data: Uint8Array): boolean {\n if (isoBrand(data, 4) !== 'ftyp') return false\n const size = ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]) >>> 0\n const isAvif = (brand: string) => brand === 'avif' || brand === 'avis'\n if (isAvif(isoBrand(data, 8))) return true\n const end = Math.min(size >= 16 ? size : data.length, data.length)\n // The major brand is followed by a minor version, then the compatible brands.\n for (let start = 16; start + 4 <= end; start += 4) if (isAvif(isoBrand(data, start))) return true\n return false\n}\n\n/**\n * The media type of encoded image bytes, read from their header, for writing them out as a data\n * URL or file. AVIF is read from its ISO media brand, which `image-size` does not decode. Bytes it\n * cannot read are reported as PNG, as image fills began.\n */\nexport function imageMimeType(data: Uint8Array): ImageMimeType {\n return imageHeader(data)?.type ?? (isAVIF(data) ? 'image/avif' : 'image/png')\n}\n\n/** An image's size in pixels, read from its header; null for bytes it cannot read. */\nexport function imageSize(data: Uint8Array): Size | null {\n const header = imageHeader(data)\n return header && { width: header.width, height: header.height }\n}\n\n/**\n * The crop that shows an image as Fill does: scaled to cover a `width` × `height` layer and\n * centred. Figma starts a crop from it, as the image-space window a crop's transform holds.\n */\nexport function coverImageTransform(\n width: number,\n height: number,\n imageWidth: number,\n imageHeight: number\n): MatrixType {\n const scale = Math.max(width / imageWidth, height / imageHeight)\n const m00 = width / scale / imageWidth\n const m11 = height / scale / imageHeight\n return { m00, m01: 0, m02: (1 - m00) / 2, m10: 0, m11, m12: (1 - m11) / 2 }\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,iBAAiB,MAA0B;CACzD,OAAO,WAAW,KAAK,IAAI,CAAC;AAC9B;;;;;;AAOA,SAAgB,yBACd,MACA,MACA,MACA,MACA,OAA0C;CAAE,OAAO;CAAM,QAAQ;AAAK,GACtE;CACA,MAAM,YAAY,KAAK,kBAAkB;CACzC,IAAI,cAAc,QAAQ;EAGxB,MAAM,IAAI,KAAK;EACf,MAAM,UAAU,KAAK,OAAO,OAAO;GAAC,EAAE;GAAK,EAAE;GAAK,EAAE;GAAK,EAAE;GAAK,EAAE;GAAK,EAAE;GAAK;GAAG;GAAG;EAAC,CAAC;EACtF,IAAI,SACF,OAAO,OAAO,SACZ,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AAgB,oBACd,OACA,QACA,YACA,aACY;CACZ,MAAM,QAAQ,KAAK,IAAI,QAAQ,YAAY,SAAS,WAAW;CAC/D,MAAM,MAAM,QAAQ,QAAQ;CAC5B,MAAM,MAAM,SAAS,QAAQ;CAC7B,OAAO;EAAE;EAAK,KAAK;EAAG,MAAM,IAAI,OAAO;EAAG,KAAK;EAAG;EAAK,MAAM,IAAI,OAAO;CAAE;AAC5E"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
2
|
import { SceneGraph } from "./graph.js";
|
|
3
|
-
import { ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentRegion, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, DrawIOEdgeSource, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseEffect, NoiseEffectParams, NoiseType, NumericNodeProperty, OverflowDirection, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeEasingType, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ScrollBehavior, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffect, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
3
|
+
import { Annotation, AnnotationCategory, AnnotationCategoryColor, AnnotationMeasurement, AnnotationMeasurementSide, AnnotationPropertyName, ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentRegion, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, DrawIOEdgeSource, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridChildAlign, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseEffect, NoiseEffectParams, NoiseType, NumericNodeProperty, OverflowDirection, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeConditionalAction, PrototypeConditionalBlock, PrototypeCubicBezier, PrototypeEasingType, PrototypeExpressionFunction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeSetVariableAction, PrototypeSetVariableModeAction, PrototypeSpring, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, PrototypeVariableValue, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ScrollBehavior, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffect, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
4
|
import { generateId, setIdSession } from "./ids.js";
|
|
5
|
-
export { ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentRegion, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, DrawIOEdgeSource, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseEffect, NoiseEffectParams, NoiseType, NumericNodeProperty, OverflowDirection, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeEasingType, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ScrollBehavior, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffect, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
5
|
+
export { Annotation, AnnotationCategory, AnnotationCategoryColor, AnnotationMeasurement, AnnotationMeasurementSide, AnnotationPropertyName, ArcData, AxisSizingMode, BlendMode, BooleanOperation, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentRegion, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, DrawIOEdgeSource, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridChildAlign, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseEffect, NoiseEffectParams, NoiseType, NumericNodeProperty, OverflowDirection, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeConditionalAction, PrototypeConditionalBlock, PrototypeCubicBezier, PrototypeEasingType, PrototypeExpressionFunction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeSetVariableAction, PrototypeSetVariableModeAction, PrototypeSpring, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, PrototypeVariableValue, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ScrollBehavior, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffect, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { SceneNode } from "../types.js";
|
|
2
2
|
//#region src/instances/fields.d.ts
|
|
3
3
|
declare const INSTANCE_SYNC_TEXT_PROPS: readonly ["name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs"];
|
|
4
|
+
/** Fields that belong to another one: overriding the owner keeps them too. */
|
|
5
|
+
declare const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>>;
|
|
4
6
|
/**
|
|
5
7
|
* Where a component's layer sits and how it is shaped, which Figma refuses to override in an
|
|
6
8
|
* instance ("This property cannot be overridden in an instance"), so its copies always follow.
|
|
7
9
|
* A layer in an auto layout flow takes its position from the layout instead.
|
|
8
10
|
*/
|
|
9
|
-
declare const INSTANCE_FOLLOWED_FIELDS: readonly ["x", "y", "rotation", "flipX", "flipY", "minWidth", "maxWidth", "minHeight", "maxHeight", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
11
|
+
declare const INSTANCE_FOLLOWED_FIELDS: readonly ["x", "y", "rotation", "flipX", "flipY", "minWidth", "maxWidth", "minHeight", "maxHeight", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "booleanOperation", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
10
12
|
/** Fields a component's layer gives its copies unless an instance overrides them. */
|
|
11
13
|
declare const INSTANCE_SYNC_PROPS: (keyof SceneNode)[];
|
|
12
14
|
/** Fields an edit to a layer inside an instance records as that instance's override. */
|
|
13
15
|
declare const INSTANCE_OVERRIDE_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible"];
|
|
14
16
|
/** Fields a component's layer gives the copies of it in every instance. */
|
|
15
|
-
declare const INSTANCE_SYNC_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible", "x", "y", "rotation", "flipX", "flipY", "minWidth", "maxWidth", "minHeight", "maxHeight", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
17
|
+
declare const INSTANCE_SYNC_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible", "x", "y", "rotation", "flipX", "flipY", "minWidth", "maxWidth", "minHeight", "maxHeight", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "booleanOperation", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
16
18
|
//#endregion
|
|
17
|
-
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS };
|
|
19
|
+
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS };
|
|
18
20
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;cAiBA,4BAA4B,SAAS,QAAQ;;;;;;cAe7C;;cAuBA,4BAA4B;;cA6B5B,8CAAwB;;cAQxB,0CAAoB"}
|
package/dist/instances/fields.js
CHANGED
|
@@ -22,6 +22,10 @@ const INSTANCE_SYNC_TEXT_PROPS = [
|
|
|
22
22
|
/** Fields that belong to another one: overriding the owner keeps them too. */
|
|
23
23
|
const INSTANCE_SYNC_FIELD_OWNERS = {
|
|
24
24
|
fillStyleId: "fills",
|
|
25
|
+
strokeStyleId: "strokes",
|
|
26
|
+
effectStyleId: "effects",
|
|
27
|
+
textStyleId: "text",
|
|
28
|
+
gridStyleId: "layoutGrids",
|
|
25
29
|
styleRuns: "text",
|
|
26
30
|
textParagraphs: "text"
|
|
27
31
|
};
|
|
@@ -45,6 +49,7 @@ const INSTANCE_FOLLOWED_FIELDS = [
|
|
|
45
49
|
"arcData",
|
|
46
50
|
"pointCount",
|
|
47
51
|
"starInnerRadius",
|
|
52
|
+
"booleanOperation",
|
|
48
53
|
"shapeWithTextType",
|
|
49
54
|
"shapeUserHeight",
|
|
50
55
|
"shapeTruncates"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/instances/fields.ts"],"sourcesContent":["import { difference } from 'es-toolkit/array'\n\nimport { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from '../fields/appearance'\nimport { SIZE_FIELDS, TRANSFORM_FIELDS } from '../fields/geometry'\nimport { AUTO_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from '../fields/layout'\nimport { TEXT_STYLE_FIELDS } from '../fields/text'\nimport { STYLE_LINK_FIELDS } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\nexport const INSTANCE_SYNC_TEXT_PROPS = [\n 'name',\n 'text',\n ...TEXT_STYLE_FIELDS,\n 'textDirection',\n 'textAutoResize',\n 'textTruncation',\n 'maxLines',\n 'leadingTrim',\n 'listSpacing',\n 'hangingList',\n // Styled ranges belong to the characters: an instance that overrides its text keeps them.\n 'styleRuns',\n 'textParagraphs'\n] as const\n\n/** Fields that belong to another one: overriding the owner keeps them too. */\nexport const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>> = {\n fillStyleId: 'fills',\n styleRuns: 'text',\n textParagraphs: 'text'\n}\n\n/**\n * Where a component's layer sits and how it is shaped, which Figma refuses to override in an\n * instance (\"This property cannot be overridden in an instance\"), so its copies always follow.\n * A layer in an auto layout flow takes its position from the layout instead.\n */\nexport const INSTANCE_FOLLOWED_FIELDS = [\n ...TRANSFORM_FIELDS,\n // A size limit has no field of its own in the file, so an instance cannot keep one of its own.\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'horizontalConstraint',\n 'verticalConstraint',\n 'layoutPositioning',\n 'counterAxisAlignContent',\n 'isMask',\n 'maskType',\n 'arcData',\n 'pointCount',\n 'starInnerRadius',\n 'shapeWithTextType',\n 'shapeUserHeight',\n 'shapeTruncates'\n] as const\n\n/** Fields a component's layer gives its copies unless an instance overrides them. */\nexport const INSTANCE_SYNC_PROPS: (keyof SceneNode)[] = difference(\n [\n ...SIZE_FIELDS,\n ...SIZE_CONSTRAINT_FIELDS,\n ...PAINT_FIELDS,\n ...STROKE_FIELDS,\n ...CORNER_FIELDS,\n ...AUTO_LAYOUT_FIELDS,\n // An instance frame and its component share one alignment in the file, so the instance\n // follows the component's instead of keeping its own.\n 'layoutAlignSelf',\n 'itemReverseZIndex',\n 'gridPosition',\n 'clipsContent',\n 'overflowDirection',\n 'scrollBehavior',\n 'layoutGrids',\n 'boundVariables',\n 'variableModes',\n // Applied shared styles follow the component unless an instance overrides them.\n ...STYLE_LINK_FIELDS\n ],\n INSTANCE_FOLLOWED_FIELDS\n)\n\n/** How a layer inside an instance sits in its parent and whether it is locked, which its overrides may change. */\nconst INSTANCE_SYNC_CHILD_PROPS = ['layoutGrow', 'layoutAlignSelf', 'locked'] as const\n\n/** Fields an edit to a layer inside an instance records as that instance's override. */\nexport const INSTANCE_OVERRIDE_FIELDS = [\n ...INSTANCE_SYNC_PROPS,\n ...INSTANCE_SYNC_TEXT_PROPS,\n ...INSTANCE_SYNC_CHILD_PROPS,\n 'visible'\n] as const\n\n/** Fields a component's layer gives the copies of it in every instance. */\nexport const INSTANCE_SYNC_FIELDS = [\n ...INSTANCE_OVERRIDE_FIELDS,\n ...INSTANCE_FOLLOWED_FIELDS\n] as const\n\n/**\n * Fields an instance frame takes from its component frame, where the file keeps one value for\n * both: a layer inside an instance has no field of its own for them.\n */\nexport const INSTANCE_FRAME_FOLLOWED_FIELDS: (keyof SceneNode)[] = [\n 'layoutPositioning',\n 'layoutGrow',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight'\n]\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;CACtC;CACA;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;AAGA,MAAa,6BAAwE;CACnF,aAAa;CACb,WAAW;CACX,gBAAgB;AAClB;;;;;;AAOA,MAAa,2BAA2B;CACtC,GAAG;CAEH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,sBAA2C,WACtD;CACE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CAGH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,GAAG;AACL,GACA,wBACF;;AAGA,MAAM,4BAA4B;CAAC;CAAc;CAAmB;AAAQ;;AAG5E,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;CACH;AACF;;AAGA,MAAa,uBAAuB,CAClC,GAAG,0BACH,GAAG,wBACL;;;;;AAMA,MAAa,iCAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"fields.js","names":[],"sources":["../../src/instances/fields.ts"],"sourcesContent":["import { difference } from 'es-toolkit/array'\n\nimport { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from '../fields/appearance'\nimport { SIZE_FIELDS, TRANSFORM_FIELDS } from '../fields/geometry'\nimport { AUTO_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from '../fields/layout'\nimport { TEXT_STYLE_FIELDS } from '../fields/text'\nimport { STYLE_LINK_FIELDS } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\nexport const INSTANCE_SYNC_TEXT_PROPS = [\n 'name',\n 'text',\n ...TEXT_STYLE_FIELDS,\n 'textDirection',\n 'textAutoResize',\n 'textTruncation',\n 'maxLines',\n 'leadingTrim',\n 'listSpacing',\n 'hangingList',\n // Styled ranges belong to the characters: an instance that overrides its text keeps them.\n 'styleRuns',\n 'textParagraphs'\n] as const\n\n/** Fields that belong to another one: overriding the owner keeps them too. */\nexport const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>> = {\n fillStyleId: 'fills',\n strokeStyleId: 'strokes',\n effectStyleId: 'effects',\n textStyleId: 'text',\n gridStyleId: 'layoutGrids',\n styleRuns: 'text',\n textParagraphs: 'text'\n}\n\n/**\n * Where a component's layer sits and how it is shaped, which Figma refuses to override in an\n * instance (\"This property cannot be overridden in an instance\"), so its copies always follow.\n * A layer in an auto layout flow takes its position from the layout instead.\n */\nexport const INSTANCE_FOLLOWED_FIELDS = [\n ...TRANSFORM_FIELDS,\n // A size limit has no field of its own in the file, so an instance cannot keep one of its own.\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'horizontalConstraint',\n 'verticalConstraint',\n 'layoutPositioning',\n 'counterAxisAlignContent',\n 'isMask',\n 'maskType',\n 'arcData',\n 'pointCount',\n 'starInnerRadius',\n 'booleanOperation',\n 'shapeWithTextType',\n 'shapeUserHeight',\n 'shapeTruncates'\n] as const\n\n/** Fields a component's layer gives its copies unless an instance overrides them. */\nexport const INSTANCE_SYNC_PROPS: (keyof SceneNode)[] = difference(\n [\n ...SIZE_FIELDS,\n ...SIZE_CONSTRAINT_FIELDS,\n ...PAINT_FIELDS,\n ...STROKE_FIELDS,\n ...CORNER_FIELDS,\n ...AUTO_LAYOUT_FIELDS,\n // An instance frame and its component share one alignment in the file, so the instance\n // follows the component's instead of keeping its own.\n 'layoutAlignSelf',\n 'itemReverseZIndex',\n 'gridPosition',\n 'clipsContent',\n 'overflowDirection',\n 'scrollBehavior',\n 'layoutGrids',\n 'boundVariables',\n 'variableModes',\n // Applied shared styles follow the component unless an instance overrides them.\n ...STYLE_LINK_FIELDS\n ],\n INSTANCE_FOLLOWED_FIELDS\n)\n\n/** How a layer inside an instance sits in its parent and whether it is locked, which its overrides may change. */\nconst INSTANCE_SYNC_CHILD_PROPS = ['layoutGrow', 'layoutAlignSelf', 'locked'] as const\n\n/** Fields an edit to a layer inside an instance records as that instance's override. */\nexport const INSTANCE_OVERRIDE_FIELDS = [\n ...INSTANCE_SYNC_PROPS,\n ...INSTANCE_SYNC_TEXT_PROPS,\n ...INSTANCE_SYNC_CHILD_PROPS,\n 'visible'\n] as const\n\n/** Fields a component's layer gives the copies of it in every instance. */\nexport const INSTANCE_SYNC_FIELDS = [\n ...INSTANCE_OVERRIDE_FIELDS,\n ...INSTANCE_FOLLOWED_FIELDS\n] as const\n\n/**\n * Fields an instance frame takes from its component frame, where the file keeps one value for\n * both: a layer inside an instance has no field of its own for them.\n */\nexport const INSTANCE_FRAME_FOLLOWED_FIELDS: (keyof SceneNode)[] = [\n 'layoutPositioning',\n 'layoutGrow',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight'\n]\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;CACtC;CACA;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;AAGA,MAAa,6BAAwE;CACnF,aAAa;CACb,eAAe;CACf,eAAe;CACf,aAAa;CACb,aAAa;CACb,WAAW;CACX,gBAAgB;AAClB;;;;;;AAOA,MAAa,2BAA2B;CACtC,GAAG;CAEH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,sBAA2C,WACtD;CACE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CAGH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,GAAG;AACL,GACA,wBACF;;AAGA,MAAM,4BAA4B;CAAC;CAAc;CAAmB;AAAQ;;AAG5E,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;CACH;AACF;;AAGA,MAAa,uBAAuB,CAClC,GAAG,0BACH,GAAG,wBACL;;;;;AAMA,MAAa,iCAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -4,7 +4,7 @@ import { canCreateInstance, createsComponentCycle, cycleSafeParent } from "./cyc
|
|
|
4
4
|
import { walkInstanceSources } from "./source-walk.js";
|
|
5
5
|
import { instanceMainComponent } from "./main-component.js";
|
|
6
6
|
import { isInShownReplacedLayer, isReplacedLayer, owningInstance, replacedComponentLayerId, showsReplacedLayer } from "./replacements.js";
|
|
7
|
-
import { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS } from "./fields.js";
|
|
7
|
+
import { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS } from "./fields.js";
|
|
8
8
|
import { SceneGraph } from "../graph.js";
|
|
9
9
|
import { SceneNode } from "../types.js";
|
|
10
10
|
//#region src/instances/index.d.ts
|
|
@@ -96,5 +96,5 @@ declare function replaceInstanceLayer(graph: SceneGraph, targetId: string, repla
|
|
|
96
96
|
*/
|
|
97
97
|
declare function restoreReplacedLayer(graph: SceneGraph, nodeId: string): boolean;
|
|
98
98
|
//#endregion
|
|
99
|
-
export { AssignmentOverrideState, INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, SwapInstanceOptions, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize, walkInstanceSources };
|
|
99
|
+
export { AssignmentOverrideState, INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, SwapInstanceOptions, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize, walkInstanceSources };
|
|
100
100
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;;;;iBAmEgB,2BAA2B,WAAW,YAAY,QAAQ;iBAiB1D,eACd,OAAO,YACP,qBACA,kBACA,YAAW,QAAQ,aAClB;iBAoBa,yBACd,OAAO,YACP,oBACA,qBACA,OAAM;UAyCS;;;;;;EAMf;;;;;;;EAOA;;iBAGc,sBACd,OAAO,YACP,oBACA,uBACE,UAAkB,qBAA2B;iBA+DjC,cAAc,OAAO,YAAY;;;;;iBAQjC,sBAAsB,OAAO,YAAY,cAAc;;iBAOvD,aAAa,OAAO,YAAY;;;;;;iBAyEhC,wBACd,OAAO,YACP,QAAQ;iBAeM,eAAe,OAAO,YAAY;iBAmElC,iBAAiB,OAAO,YAAY,qBAAqB;iBAMzD,aAAa,OAAO,YAAY,sBAAsB;;iBAYtD,qBAAqB,OAAO,YAAY,iBAAiB;;;;;iBAazD,aAAa,OAAO,YAAY,MAAM;;;;iBAOtC,oBAAoB,OAAO,YAAY,gBAAgB;;;;;iBA2CvD,wBACd,OAAO,YACP,qBACC;;UAMc;EACf;EACA,WAAW;;iBAGG,4BACd,OAAO,YACP,qBACC;iBAOa,+BACd,OAAO,YACP,OAAO;;;;;;iBAYO,yBACd,OAAO,YACP,oBACA,oBACA;;;;;iBAkBc,uBAAuB,MAAM,WAAW,SAAS,QAAQ;iBAMzD,uBACd,OAAO,YACP,gBACA,QAAQ;;iBA8DM,wBAAwB,OAAO,YAAY;;;;;;;;;iBAqB3C,qBACd,OAAO,YACP,kBACA;;;;;iBAmDc,qBAAqB,OAAO,YAAY"}
|
package/dist/instances/index.js
CHANGED
|
@@ -7,10 +7,10 @@ import { applyBoundPaintColorsIn, keepCopyBoundPaints } from "../variables/paint
|
|
|
7
7
|
import { keepOwnContentSize } from "./content-size.js";
|
|
8
8
|
import { isInShownReplacedLayer, isReplacedLayer, owningInstance, replacedComponentLayerId, replacedLayerIn, showsReplacedLayer } from "./replacements.js";
|
|
9
9
|
import { createInstanceSyncContext, groupCopyRemovals, removeLeftoverCopies } from "./copies.js";
|
|
10
|
-
import { INSTANCE_FOLLOWED_FIELDS, INSTANCE_FRAME_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS } from "./fields.js";
|
|
10
|
+
import { INSTANCE_FOLLOWED_FIELDS, INSTANCE_FRAME_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS } from "./fields.js";
|
|
11
11
|
import { differingVariableModeCollections } from "./modes.js";
|
|
12
12
|
import { applySyncedStrokeLines, bindingProtection, cloneChildrenWithMapping, copyProp, enclosingInstanceOverrideFields, isProtectedSyncField, sourceInTargetCoordinates, syncBindingFields, syncChildren, syncVariableModeFields, updateSyncedProps } from "./sync.js";
|
|
13
|
-
import { slotScope } from "../slots/content.js";
|
|
13
|
+
import { claimSlotContent, enclosingSlotScope, slotScope } from "../slots/content.js";
|
|
14
14
|
import { canCreateInstance, createsComponentCycle, cycleSafeParent } from "./cycles.js";
|
|
15
15
|
import { walkInstanceSources } from "./source-walk.js";
|
|
16
16
|
import { captureInstanceOverrides, restoreInstanceOverrides } from "./swap-overrides.js";
|
|
@@ -327,6 +327,11 @@ function instanceOverrideFields(node, changes) {
|
|
|
327
327
|
function recordInstanceOverride(graph, nodeId, fields) {
|
|
328
328
|
const instance = findInstanceAncestor(graph, nodeId);
|
|
329
329
|
if (!instance) return;
|
|
330
|
+
const parentId = graph.nodes.get(nodeId)?.parentId;
|
|
331
|
+
if (parentId) {
|
|
332
|
+
const scope = enclosingSlotScope(graph, parentId);
|
|
333
|
+
if (scope) claimSlotContent(graph, scope);
|
|
334
|
+
}
|
|
330
335
|
const added = overrideFieldsOf(graph, instance, nodeId, [...fields].filter((field) => INSTANCE_OVERRIDE_FIELDS.includes(field) || overriddenAssignmentId(field) !== null)).filter((field) => !hasInstanceOverride$1(instance.instanceOverrides, instance.id, nodeId, field));
|
|
331
336
|
if (added.length === 0) return;
|
|
332
337
|
const overrides = cloneInstanceOverrideState(instance.instanceOverrides);
|
|
@@ -423,6 +428,6 @@ function restoreReplacedLayer(graph, nodeId) {
|
|
|
423
428
|
return true;
|
|
424
429
|
}
|
|
425
430
|
//#endregion
|
|
426
|
-
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize, walkInstanceSources };
|
|
431
|
+
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, assignmentOverrideOwner, canCreateInstance, canReplaceInstanceLayer, copyInstanceComponentProps, createInstance, createsComponentCycle, cycleSafeParent, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, instanceMainComponent, instanceOverrideFields, isInShownReplacedLayer, isReplacedLayer, owningInstance, populateInstanceChildren, recordAssignmentOverride, recordInstanceOverride, replaceInstanceLayer, replacedComponentLayerId, restoreAssignmentOverrideState, restoreReplacedLayer, retargetCopiedOverrides, showsReplacedLayer, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, takeAssignmentOverrideState, takesOwnSize, walkInstanceSources };
|
|
427
432
|
|
|
428
433
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/index.ts"],"sourcesContent":["import type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { shapeGeometryChanges } from '../resize'\nimport { slotScope } from '../slots/content'\nimport { detachOwnedSlotContent, restoreOwnedSlotContent } from '../slots/frames'\nimport { changesMoreThanStrokeLines } from '../strokes'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn, keepCopyBoundPaints } from '../variables/paints'\nimport { keepOwnContentSize } from './content-size'\nimport { createInstanceSyncContext, groupCopyRemovals, removeLeftoverCopies } from './copies'\nimport { canCreateInstance, createsComponentCycle } from './cycles'\nimport {\n INSTANCE_FRAME_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_PROPS\n} from './fields'\nimport { differingVariableModeCollections } from './modes'\nimport {\n assignmentOverrideField,\n cloneInstanceOverrideState,\n copiedComponentLayerId,\n createInstanceOverrideState,\n getInstanceOverride,\n hasInstanceOverride as hasNodeInstanceOverride,\n type InstanceOverrideState,\n overriddenAssignmentId,\n ownInstanceOverrides,\n REPLACED_LAYER_OVERRIDE,\n setInstanceOverride,\n variableModeOverrideField\n} from './overrides'\nimport { owningInstance, replacedLayerIn } from './replacements'\nimport { walkInstanceSources } from './source-walk'\nimport { captureInstanceOverrides, restoreInstanceOverrides } from './swap-overrides'\nimport {\n applySyncedStrokeLines,\n bindingProtection,\n cloneChildrenWithMapping,\n copyProp,\n enclosingInstanceOverrideFields,\n isProtectedSyncField,\n sourceInTargetCoordinates,\n syncBindingFields,\n syncChildren,\n syncVariableModeFields,\n updateSyncedProps\n} from './sync'\n\nexport { canCreateInstance, createsComponentCycle, cycleSafeParent } from './cycles'\nexport { walkInstanceSources } from './source-walk'\nexport { instanceMainComponent } from './main-component'\nexport {\n isInShownReplacedLayer,\n isReplacedLayer,\n owningInstance,\n replacedComponentLayerId,\n showsReplacedLayer\n} from './replacements'\nexport {\n INSTANCE_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_FIELDS,\n INSTANCE_SYNC_PROPS,\n INSTANCE_SYNC_TEXT_PROPS\n} from './fields'\n\nexport function copyInstanceComponentProps(component: SceneNode): Partial<SceneNode> {\n const props: Partial<SceneNode> = {}\n // A new instance starts with the fields its component frame lends it, as resyncing one does.\n for (const key of [...INSTANCE_SYNC_PROPS, ...INSTANCE_FRAME_FOLLOWED_FIELDS])\n copyProp(props, component, key)\n return props\n}\n\n/**\n * The name Figma gives a new instance of `component`: its component set's name for a variant,\n * whose own name only says which variant it is, and the component's own name otherwise.\n */\nfunction instanceComponentName(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.nodes.get(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.name : component.name\n}\n\nexport function createInstance(\n graph: SceneGraph,\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n): SceneNode | null {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT' || !canCreateInstance(graph, componentId, parentId))\n return null\n\n const props: Partial<SceneNode> = {\n ...copyInstanceComponentProps(component),\n name: instanceComponentName(graph, component)\n }\n\n // The component checked above is the one the instance shows, whatever `overrides` holds.\n const instance = graph.createNode('INSTANCE', parentId, { ...props, ...overrides, componentId })\n\n cloneChildrenWithMapping(graph, component.id, instance.id)\n // A copy shows its bound paints in its own context, not as its component's paints hold them.\n applyBoundPaintColorsIn(graph, instance.id)\n\n return instance\n}\n\nexport function populateInstanceChildren(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || !component || instance.type !== 'INSTANCE') return\n cloneChildrenWithMapping(graph, componentId, instanceId, mode)\n}\n\n/**\n * A nested instance's link to the enclosing component's record is its `componentId` when it\n * was populated by cloning. A swap replaces that field, so keep the correspondence as the\n * owner's `sourceComponentId` override and record the swap itself; materialized documents\n * already carry the correspondence and only gain the swap.\n */\nfunction recordNestedSwap(graph: SceneGraph, instance: SceneNode, componentId: string): void {\n const owner = instance.parentId ? findInstanceAncestor(graph, instance.parentId) : undefined\n if (!owner) return\n const existing = getInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n 'sourceComponentId'\n )\n if (typeof existing !== 'string' && instance.componentId)\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n instance.id,\n 'sourceComponentId',\n instance.componentId\n )\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n instance.id,\n 'componentId',\n componentId\n )\n graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) })\n}\n\nexport interface SwapInstanceOptions {\n /**\n * Keep the instance's name even when it is its old component's. A swap otherwise renames such\n * an instance after the new component, as Figma does; a view that only shows another variant,\n * such as preview, keeps names so layer paths stay the same.\n */\n keepName?: boolean\n /**\n * Keep the overrides the instance's layers record, matched to the layers of the new component\n * that take their places, as Figma keeps them when a variant changes. A swap that only\n * materializes a layer the caller re-applies itself, such as a pen icon's glyph, skips this:\n * what the placeholder recorded is scaffolding, not a user's edit.\n */\n restoreOverrides?: boolean\n}\n\nexport function swapInstanceComponent(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n { keepName = false, restoreOverrides = true }: SwapInstanceOptions = {}\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || component?.type !== 'COMPONENT' || instance.type !== 'INSTANCE') return\n if (instance.parentId && !canCreateInstance(graph, componentId, instance.parentId)) return\n\n const previousComponent = instance.componentId ? graph.nodes.get(instance.componentId) : undefined\n recordNestedSwap(graph, instance, componentId)\n const updates: Partial<SceneNode> = { componentId }\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const overridden = (field: string) =>\n hasNodeInstanceOverride(instance.instanceOverrides, instance.id, instance.id, field)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'variableModes' || overridden(key)) continue\n copyProp(updates, source, key)\n }\n syncVariableModeFields(instance, source, updates, overridden)\n applySyncedStrokeLines(graph, instance, updates, overridden)\n\n if (\n !keepName &&\n (!previousComponent || instance.name === instanceComponentName(graph, previousComponent))\n )\n updates.name = instanceComponentName(graph, component)\n\n keepCopyBoundPaints(graph, instance, updates)\n const childIds = Array.from(instance.childIds)\n const slotContent = detachOwnedSlotContent(graph, instance)\n swapInstanceLayers(graph, instanceId, componentId, updates, childIds, restoreOverrides)\n restoreOwnedSlotContent(graph, instance, slotContent)\n}\n\n/**\n * Replaces the instance's layers with clones of its new component's and gives the recorded\n * overrides back to the layers that take the old ones' places, matched by name path.\n */\nfunction swapInstanceLayers(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n updates: Partial<SceneNode>,\n childIds: string[],\n restoreOverrides: boolean\n): void {\n // The clones take new IDs, so what was recorded for the removed layers only applies again once\n // it is matched to the layers of the new component that take their places.\n const capturedOverrides = restoreOverrides\n ? captureInstanceOverrides(graph, graph.nodes.get(instanceId) as SceneNode)\n : undefined\n for (const childId of childIds) {\n forgetOverridesOf(graph, childId)\n graph.deleteNode(childId)\n }\n graph.updateNode(instanceId, updates)\n cloneChildrenWithMapping(graph, componentId, instanceId)\n applyBoundPaintColorsIn(graph, instanceId)\n const swapped = graph.nodes.get(instanceId)\n if (swapped && capturedOverrides) restoreInstanceOverrides(graph, swapped, capturedOverrides)\n}\n\nconst syncingComponentsByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nexport function syncInstances(graph: SceneGraph, componentId: string): void {\n syncInstancesOf(graph, componentId, getInstances(graph, componentId))\n}\n\n/**\n * Syncs each component's instances, in order, as one edit: the copies they remove stay\n * restorable together for as long as undo keeps that edit.\n */\nexport function syncInstancesTogether(graph: SceneGraph, componentIds: Iterable<string>): void {\n groupCopyRemovals(graph, () => {\n for (const id of componentIds) syncInstances(graph, id)\n })\n}\n\n/** Syncs one instance from its component, as `syncInstances` does for every instance. */\nexport function syncInstance(graph: SceneGraph, instanceId: string): void {\n const instance = graph.nodes.get(instanceId)\n if (instance?.type !== 'INSTANCE' || !instance.componentId) return\n syncInstancesOf(graph, instance.componentId, [instance])\n}\n\nfunction syncInstancesOf(\n graph: SceneGraph,\n componentId: string,\n instances: Iterable<SceneNode>\n): void {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT') return\n let syncing = syncingComponentsByGraph.get(graph)\n if (!syncing) {\n syncing = new Set()\n syncingComponentsByGraph.set(graph, syncing)\n }\n if (syncing.has(componentId)) return\n syncing.add(componentId)\n try {\n groupCopyRemovals(graph, (removals) => {\n for (const instance of instances) {\n const enclosing = enclosingInstanceOverrideFields(graph, instance)\n enclosing.push(new Set(instance.instanceOverrides.self.keys()))\n const protectedField = bindingProtection(enclosing)\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const updates: Partial<SceneNode> = {}\n syncBindingFields(instance, source, updates, protectedField)\n syncVariableModeFields(instance, source, updates, protectedField)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (isProtectedSyncField(instance, key, protectedField)) continue\n copyProp(updates, source, key)\n }\n // The file keeps one value for the instance frame and its component, so the frame takes\n // those the layers inside an instance may not set.\n for (const key of INSTANCE_FRAME_FOLLOWED_FIELDS) {\n if (!isProtectedSyncField(instance, key, protectedField)) copyProp(updates, source, key)\n }\n // An instance that hugs its layers sizes to what it shows, not to the component.\n keepOwnContentSize(graph, updates, instance, source)\n // A size that follows the component invalidates outlines the file saved on the instance;\n // its live box draws them again.\n if (updates.width !== undefined || updates.height !== undefined) {\n Object.assign(\n updates,\n shapeGeometryChanges(\n instance,\n updates.width ?? instance.width,\n updates.height ?? instance.height\n )\n )\n }\n updateSyncedProps(graph, instance, updates, (key) =>\n isProtectedSyncField(instance, key, protectedField)\n )\n const owned = ownInstanceOverrides(instance)\n const context = createInstanceSyncContext(instance.id, owned)\n syncChildren(graph, component.id, instance.id, owned, context)\n removeLeftoverCopies(graph, context, removals)\n }\n })\n } finally {\n syncing.delete(componentId)\n }\n}\n\n/**\n * Renames the layers that the copied instances among `copies` record overrides for to their\n * copies, as a copied instance records its own layers' overrides. The values keep naming what\n * they name, since a copy shows the same components as its source.\n */\nexport function retargetCopiedOverrides(\n graph: SceneGraph,\n copies: ReadonlyMap<string, string>\n): void {\n for (const id of copies.values()) {\n const node = graph.nodes.get(id)\n if (node?.type !== 'INSTANCE' || node.instanceOverrides.descendants.size === 0) continue\n const descendants = new Map(\n [...node.instanceOverrides.descendants].map(([target, fields]) => [\n copies.get(target) ?? target,\n fields\n ])\n )\n graph.updateNode(id, { instanceOverrides: { ...node.instanceOverrides, descendants } })\n }\n}\n\nexport function detachInstance(graph: SceneGraph, instanceId: string): void {\n const node = graph.nodes.get(instanceId)\n if (node?.type !== 'INSTANCE') return\n for (const nested of outermostNestedInstances(graph, node))\n adoptNestedOverrides(graph, node, nested)\n // Through `updateNode`, so the instance index, change observers, and undo recorders see it.\n graph.updateNode(instanceId, {\n type: 'FRAME',\n componentId: null,\n instanceOverrides: createInstanceOverrideState()\n })\n // Its mirrored layers stand on their own: a component child id would name a layer of another\n // node, which the format never stores and a later sync would read as a link back. A nested\n // instance is not a mirror and keeps its own links, which its overrides are written through.\n const detachLinks = (parentId: string): void => {\n for (const child of graph.getChildren(parentId)) {\n if (child.type === 'INSTANCE') continue\n if (child.componentId) graph.updateNode(child.id, { componentId: null })\n detachLinks(child.id)\n }\n }\n detachLinks(instanceId)\n}\n\n// A swap's bookkeeping belongs to the instance enclosing the swapped one, never to the swapped one.\nconst OWNER_ONLY_FIELDS = new Set(['componentId', 'sourceComponentId'])\n\nfunction outermostNestedInstances(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n return graph\n .getChildren(instance.id)\n .flatMap((child) =>\n child.type === 'INSTANCE' ? [child] : outermostNestedInstances(graph, child)\n )\n}\n\n/**\n * An instance a detached one holds stands on its own once that one is a frame, and so must what\n * makes it differ from its component. Cloned in, it kept the overrides of the instance it copies,\n * under that instance's layers; those, and the ones the detached instance recorded on its layers,\n * now go under its own.\n */\nfunction adoptNestedOverrides(graph: SceneGraph, detached: SceneNode, nested: SceneNode): void {\n const ownLayer = new Map<string, string>()\n walkInstanceSources(graph, nested, (source, target) => {\n ownLayer.set(source.id, target.id)\n return true\n })\n const { self, descendants: kept } = cloneInstanceOverrideState(nested.instanceOverrides)\n const outer = cloneInstanceOverrideState(detached.instanceOverrides).descendants\n const descendants = new Map<string, Map<string, unknown>>()\n const claim = (layerId: string, fields: Map<string, unknown>): void => {\n const merged = descendants.get(layerId)\n if (!merged) descendants.set(layerId, fields)\n else for (const [field, value] of fields) merged.set(field, value)\n }\n // What was recorded on its own layers is more recent than what it copied, so it is laid on top.\n for (const [layerId, fields] of kept)\n if (ownLayer.has(layerId)) claim(ownLayer.get(layerId) ?? layerId, fields)\n for (const [layerId, fields] of kept) if (!ownLayer.has(layerId)) claim(layerId, fields)\n for (const [layerId, fields] of outer) {\n if (layerId === nested.id) {\n for (const [field, value] of fields) if (!OWNER_ONLY_FIELDS.has(field)) self.set(field, value)\n } else if (graph.isDescendant(layerId, nested.id)) claim(layerId, fields)\n }\n graph.updateNode(nested.id, { instanceOverrides: { self, descendants } })\n}\n\nexport function getMainComponent(graph: SceneGraph, instanceId: string): SceneNode | undefined {\n const node = graph.nodes.get(instanceId)\n if (!node?.componentId) return undefined\n return graph.nodes.get(node.componentId)\n}\n\nexport function getInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n const ids = graph.instanceIndex.get(componentId)\n if (!ids) return []\n const instances: SceneNode[] = []\n for (const id of ids) {\n const node = graph.nodes.get(id)\n if (node) instances.push(node)\n }\n return instances\n}\n\n/** Nearest INSTANCE at or above `nodeId` — self, parent, grandparent, etc. */\nexport function findInstanceAncestor(graph: SceneGraph, nodeId: string): SceneNode | undefined {\n let current = graph.nodes.get(nodeId)\n while (current) {\n if (current.type === 'INSTANCE') return current\n current = current.parentId ? graph.nodes.get(current.parentId) : undefined\n }\n return undefined\n}\n\n/**\n * Whether Figma lets this layer take a size of its own: a layer inside an instance shows its\n * component's size and cannot be resized, while an instance nested in another may be.\n */\nexport function takesOwnSize(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'INSTANCE' || !node.parentId || !findInstanceAncestor(graph, node.parentId)\n}\n\n/**\n * True when a node field is protected from instance synchronization.\n */\nexport function hasInstanceOverride(graph: SceneGraph, nodeId: string, field: string): boolean {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return false\n return hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n}\n\n/**\n * The layer of the component an instance layer copies, which its overrides are measured\n * against: the instance's component for the instance itself.\n */\nfunction copiedLayer(graph: SceneGraph, instance: SceneNode, node: SceneNode) {\n const id =\n node.id === instance.id\n ? instance.componentId\n : copiedComponentLayerId(instance.instanceOverrides, instance.id, node)\n return id ? graph.nodes.get(id) : undefined\n}\n\n/**\n * The override fields an edit of these fields records. A mode edit claims only the collections\n * whose mode now differs from the component layer's, so the component's other modes still\n * reach the layer; with no layer to compare, it claims every mode.\n */\nfunction overrideFieldsOf(\n graph: SceneGraph,\n instance: SceneNode,\n nodeId: string,\n fields: string[]\n): string[] {\n if (!fields.includes('variableModes')) return fields\n const node = graph.nodes.get(nodeId)\n const source = node && copiedLayer(graph, instance, node)\n if (!node || !source) return fields\n return [\n ...fields.filter((field) => field !== 'variableModes'),\n ...differingVariableModeCollections(node, source).map(variableModeOverrideField)\n ]\n}\n\n/**\n * The instance above `instanceId` that records an assignment made through it: an assignment of a\n * nested instance's property is an edit of the instance it sits in, not of the nested instance.\n */\nexport function assignmentOverrideOwner(\n graph: SceneGraph,\n instanceId: string\n): SceneNode | undefined {\n const parentId = graph.nodes.get(instanceId)?.parentId\n return parentId ? findInstanceAncestor(graph, parentId) : undefined\n}\n\n/** The overrides an assignment edit writes on the instance above it, for undo to restore. */\nexport interface AssignmentOverrideState {\n ownerId: string\n overrides: InstanceOverrideState\n}\n\nexport function takeAssignmentOverrideState(\n graph: SceneGraph,\n instanceId: string\n): AssignmentOverrideState | undefined {\n const owner = assignmentOverrideOwner(graph, instanceId)\n return owner\n ? { ownerId: owner.id, overrides: cloneInstanceOverrideState(owner.instanceOverrides) }\n : undefined\n}\n\nexport function restoreAssignmentOverrideState(\n graph: SceneGraph,\n state: AssignmentOverrideState\n): void {\n graph.updateNode(state.ownerId, {\n instanceOverrides: cloneInstanceOverrideState(state.overrides)\n })\n}\n\n/**\n * Records that an instance assigned one of its component properties, as an edit of the instance\n * above it: the assignment is made through the outer instance, so a text override of the same\n * level does not outrank it. A top-level instance has no outer instance to record it on.\n */\nexport function recordAssignmentOverride(\n graph: SceneGraph,\n instanceId: string,\n propertyId: string,\n value: string\n): void {\n const outer = assignmentOverrideOwner(graph, instanceId)\n if (!outer) return\n setInstanceOverride(\n ownInstanceOverrides(outer),\n outer.id,\n instanceId,\n assignmentOverrideField(propertyId),\n value\n )\n graph.updateNode(outer.id, { instanceOverrides: outer.instanceOverrides })\n}\n\n/**\n * The fields `changes` overrides on an instance layer. New strokes that change only what the\n * layer's line fields say override those fields, not the paints (`changesMoreThanStrokeLines`).\n */\nexport function instanceOverrideFields(node: SceneNode, changes: Partial<SceneNode>): string[] {\n const fields = Object.keys(changes)\n if (!changes.strokes || changesMoreThanStrokeLines(node, changes)) return fields\n return fields.filter((field) => field !== 'strokes')\n}\n\nexport function recordInstanceOverride(\n graph: SceneGraph,\n nodeId: string,\n fields: Iterable<string>\n): void {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return\n\n const relevant = overrideFieldsOf(\n graph,\n instance,\n nodeId,\n [...fields].filter(\n (field) =>\n (INSTANCE_OVERRIDE_FIELDS as readonly string[]).includes(field) ||\n overriddenAssignmentId(field) !== null\n )\n )\n\n const added = relevant.filter(\n (field) => !hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n )\n if (added.length === 0) return\n\n // A new state rather than an edit of the old one, so a preview that captured the old state\n // puts it back on cancel.\n const overrides = cloneInstanceOverrideState(instance.instanceOverrides)\n for (const field of added) setInstanceOverride(overrides, instance.id, nodeId, field)\n graph.updateNode(instance.id, { instanceOverrides: overrides })\n}\n\n/** Every layer at or below `rootId`. */\nfunction subtreeIds(graph: SceneGraph, rootId: string): string[] {\n const ids: string[] = []\n const visit = (id: string) => {\n ids.push(id)\n for (const childId of graph.nodes.get(id)?.childIds ?? []) visit(childId)\n }\n visit(rootId)\n return ids\n}\n\n/** Forget what the instances above `nodeId` recorded for it and the layers inside it. */\nfunction forgetOverridesOf(graph: SceneGraph, nodeId: string): void {\n const ids = subtreeIds(graph, nodeId)\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (!parentId) return\n graph.closest(parentId, (ancestor) => {\n if (ancestor.type !== 'INSTANCE') return false\n const owned = ownInstanceOverrides(ancestor)\n if (ids.some((id) => owned.descendants.delete(id)))\n graph.updateNode(ancestor.id, { instanceOverrides: owned })\n return false\n })\n}\n\n/** Whether a layer can be replaced in its instance: it sits in the part the component owns. */\nexport function canReplaceInstanceLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node?.parentId || !owner) return false\n // Slot content is the instance's own already, and a generated frame's layers are fixed.\n const scope = slotScope(graph, node.parentId)\n if (scope.kind !== 'locked' || scope.owner.type !== 'INSTANCE') return false\n return (\n replacedLayerIn(owner, node.id) !== undefined ||\n copiedComponentLayerId(owner.instanceOverrides, owner.id, node) !== undefined\n )\n}\n\n/**\n * Put `replacementId` in place of `targetId`, a layer an instance copies from its component, as\n * an override of the nearest instance above it, as pen.dev replaces a layer inside an instance.\n * The replacement takes the target's place among its siblings and its position, the target\n * goes, and syncs keep the replacement in place of the component layer the target copied. A\n * replaced layer can be replaced again. Returns false and changes nothing when the target is no\n * such layer, or the replacement cannot go there.\n */\nexport function replaceInstanceLayer(\n graph: SceneGraph,\n targetId: string,\n replacementId: string\n): boolean {\n const target = graph.nodes.get(targetId)\n const replacement = graph.nodes.get(replacementId)\n const parentId = target?.parentId\n if (!target || !replacement || !parentId || targetId === replacementId) return false\n const owner = owningInstance(graph, target)\n if (!owner || graph.isDescendant(parentId, replacementId)) return false\n if (createsComponentCycle(graph, replacementId, parentId)) return false\n const layerId =\n replacedLayerIn(owner, target.id) ??\n copiedComponentLayerId(owner.instanceOverrides, owner.id, target)\n if (!layerId) return false\n\n // The replacement copies no layer of the component, so its own layers lose such links; an\n // instance among them keeps its own component and layers.\n const unlink = (id: string) => {\n const node = graph.nodes.get(id)\n if (!node) return\n if (node.type !== 'INSTANCE' && node.componentId) graph.updateNode(id, { componentId: null })\n if (node.type !== 'INSTANCE') node.childIds.forEach(unlink)\n }\n unlink(replacementId)\n\n const index = graph.nodes.get(parentId)?.childIds.indexOf(target.id) ?? -1\n forgetOverridesOf(graph, target.id)\n forgetOverridesOf(graph, replacementId)\n graph.insertChildAt(replacementId, parentId, index < 0 ? Number.MAX_SAFE_INTEGER : index)\n graph.updateNode(replacementId, {\n x: target.x,\n y: target.y,\n layoutPositioning: target.layoutPositioning,\n horizontalConstraint: target.horizontalConstraint,\n verticalConstraint: target.verticalConstraint\n })\n graph.deleteNode(target.id)\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n replacementId,\n REPLACED_LAYER_OVERRIDE,\n layerId\n )\n graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) })\n return true\n}\n\n/**\n * Take a replaced layer out and bring back the component layer it stood in for, synced from the\n * outermost instance as a reset syncs. Returns false when the layer is not a replaced one.\n */\nexport function restoreReplacedLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node || !owner || replacedLayerIn(owner, nodeId) === undefined) return false\n let outermost = owner\n for (let above = owningInstance(graph, owner); above; above = owningInstance(graph, above))\n outermost = above\n forgetOverridesOf(graph, nodeId)\n graph.deleteNode(nodeId)\n syncInstance(graph, outermost.id)\n // An enclosing sync stops at a swapped instance, which brings its layers back itself.\n const above = owningInstance(graph, owner)\n if (above && getInstanceOverride(above.instanceOverrides, above.id, owner.id, 'componentId'))\n syncInstance(graph, owner.id)\n return true\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,SAAgB,2BAA2B,WAA0C;CACnF,MAAM,QAA4B,CAAC;CAEnC,KAAK,MAAM,OAAO,CAAC,GAAG,qBAAqB,GAAG,8BAA8B,GAC1E,SAAS,OAAO,WAAW,GAAG;CAChC,OAAO;AACT;;;;;AAMA,SAAS,sBAAsB,OAAmB,WAA8B;CAC9E,MAAM,SAAS,UAAU,WAAW,MAAM,MAAM,I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kBAAkB,OAAO,MAAM;CAC/B,MAAM,WAAW,MAAM;CACvB,aAAa,OAAO,UAAU,EAAE;CAEhC,MAAM,QAAQ,eAAe,OAAO,KAAK;CACzC,IAAI,SAAS,oBAAoB,MAAM,mBAAmB,MAAM,IAAI,MAAM,IAAI,aAAa,GACzF,aAAa,OAAO,MAAM,EAAE;CAC9B,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/index.ts"],"sourcesContent":["import type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { shapeGeometryChanges } from '../resize'\nimport { claimSlotContent, enclosingSlotScope, slotScope } from '../slots/content'\nimport { detachOwnedSlotContent, restoreOwnedSlotContent } from '../slots/frames'\nimport { changesMoreThanStrokeLines } from '../strokes'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn, keepCopyBoundPaints } from '../variables/paints'\nimport { keepOwnContentSize } from './content-size'\nimport { createInstanceSyncContext, groupCopyRemovals, removeLeftoverCopies } from './copies'\nimport { canCreateInstance, createsComponentCycle } from './cycles'\nimport {\n INSTANCE_FRAME_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_PROPS\n} from './fields'\nimport { differingVariableModeCollections } from './modes'\nimport {\n assignmentOverrideField,\n cloneInstanceOverrideState,\n copiedComponentLayerId,\n createInstanceOverrideState,\n getInstanceOverride,\n hasInstanceOverride as hasNodeInstanceOverride,\n type InstanceOverrideState,\n overriddenAssignmentId,\n ownInstanceOverrides,\n REPLACED_LAYER_OVERRIDE,\n setInstanceOverride,\n variableModeOverrideField\n} from './overrides'\nimport { owningInstance, replacedLayerIn } from './replacements'\nimport { walkInstanceSources } from './source-walk'\nimport { captureInstanceOverrides, restoreInstanceOverrides } from './swap-overrides'\nimport {\n applySyncedStrokeLines,\n bindingProtection,\n cloneChildrenWithMapping,\n copyProp,\n enclosingInstanceOverrideFields,\n isProtectedSyncField,\n sourceInTargetCoordinates,\n syncBindingFields,\n syncChildren,\n syncVariableModeFields,\n updateSyncedProps\n} from './sync'\n\nexport { canCreateInstance, createsComponentCycle, cycleSafeParent } from './cycles'\nexport { walkInstanceSources } from './source-walk'\nexport { instanceMainComponent } from './main-component'\nexport {\n isInShownReplacedLayer,\n isReplacedLayer,\n owningInstance,\n replacedComponentLayerId,\n showsReplacedLayer\n} from './replacements'\nexport {\n INSTANCE_FOLLOWED_FIELDS,\n INSTANCE_OVERRIDE_FIELDS,\n INSTANCE_SYNC_FIELD_OWNERS,\n INSTANCE_SYNC_FIELDS,\n INSTANCE_SYNC_PROPS,\n INSTANCE_SYNC_TEXT_PROPS\n} from './fields'\n\nexport function copyInstanceComponentProps(component: SceneNode): Partial<SceneNode> {\n const props: Partial<SceneNode> = {}\n // A new instance starts with the fields its component frame lends it, as resyncing one does.\n for (const key of [...INSTANCE_SYNC_PROPS, ...INSTANCE_FRAME_FOLLOWED_FIELDS])\n copyProp(props, component, key)\n return props\n}\n\n/**\n * The name Figma gives a new instance of `component`: its component set's name for a variant,\n * whose own name only says which variant it is, and the component's own name otherwise.\n */\nfunction instanceComponentName(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.nodes.get(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.name : component.name\n}\n\nexport function createInstance(\n graph: SceneGraph,\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n): SceneNode | null {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT' || !canCreateInstance(graph, componentId, parentId))\n return null\n\n const props: Partial<SceneNode> = {\n ...copyInstanceComponentProps(component),\n name: instanceComponentName(graph, component)\n }\n\n // The component checked above is the one the instance shows, whatever `overrides` holds.\n const instance = graph.createNode('INSTANCE', parentId, { ...props, ...overrides, componentId })\n\n cloneChildrenWithMapping(graph, component.id, instance.id)\n // A copy shows its bound paints in its own context, not as its component's paints hold them.\n applyBoundPaintColorsIn(graph, instance.id)\n\n return instance\n}\n\nexport function populateInstanceChildren(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || !component || instance.type !== 'INSTANCE') return\n cloneChildrenWithMapping(graph, componentId, instanceId, mode)\n}\n\n/**\n * A nested instance's link to the enclosing component's record is its `componentId` when it\n * was populated by cloning. A swap replaces that field, so keep the correspondence as the\n * owner's `sourceComponentId` override and record the swap itself; materialized documents\n * already carry the correspondence and only gain the swap.\n */\nfunction recordNestedSwap(graph: SceneGraph, instance: SceneNode, componentId: string): void {\n const owner = instance.parentId ? findInstanceAncestor(graph, instance.parentId) : undefined\n if (!owner) return\n const existing = getInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n 'sourceComponentId'\n )\n if (typeof existing !== 'string' && instance.componentId)\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n instance.id,\n 'sourceComponentId',\n instance.componentId\n )\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n instance.id,\n 'componentId',\n componentId\n )\n graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) })\n}\n\nexport interface SwapInstanceOptions {\n /**\n * Keep the instance's name even when it is its old component's. A swap otherwise renames such\n * an instance after the new component, as Figma does; a view that only shows another variant,\n * such as preview, keeps names so layer paths stay the same.\n */\n keepName?: boolean\n /**\n * Keep the overrides the instance's layers record, matched to the layers of the new component\n * that take their places, as Figma keeps them when a variant changes. A swap that only\n * materializes a layer the caller re-applies itself, such as a pen icon's glyph, skips this:\n * what the placeholder recorded is scaffolding, not a user's edit.\n */\n restoreOverrides?: boolean\n}\n\nexport function swapInstanceComponent(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n { keepName = false, restoreOverrides = true }: SwapInstanceOptions = {}\n): void {\n const instance = graph.nodes.get(instanceId)\n const component = graph.nodes.get(componentId)\n if (!instance || component?.type !== 'COMPONENT' || instance.type !== 'INSTANCE') return\n if (instance.parentId && !canCreateInstance(graph, componentId, instance.parentId)) return\n\n const previousComponent = instance.componentId ? graph.nodes.get(instance.componentId) : undefined\n recordNestedSwap(graph, instance, componentId)\n const updates: Partial<SceneNode> = { componentId }\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const overridden = (field: string) =>\n hasNodeInstanceOverride(instance.instanceOverrides, instance.id, instance.id, field)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'variableModes' || overridden(key)) continue\n copyProp(updates, source, key)\n }\n syncVariableModeFields(instance, source, updates, overridden)\n applySyncedStrokeLines(graph, instance, updates, overridden)\n\n if (\n !keepName &&\n (!previousComponent || instance.name === instanceComponentName(graph, previousComponent))\n )\n updates.name = instanceComponentName(graph, component)\n\n keepCopyBoundPaints(graph, instance, updates)\n const childIds = Array.from(instance.childIds)\n const slotContent = detachOwnedSlotContent(graph, instance)\n swapInstanceLayers(graph, instanceId, componentId, updates, childIds, restoreOverrides)\n restoreOwnedSlotContent(graph, instance, slotContent)\n}\n\n/**\n * Replaces the instance's layers with clones of its new component's and gives the recorded\n * overrides back to the layers that take the old ones' places, matched by name path.\n */\nfunction swapInstanceLayers(\n graph: SceneGraph,\n instanceId: string,\n componentId: string,\n updates: Partial<SceneNode>,\n childIds: string[],\n restoreOverrides: boolean\n): void {\n // The clones take new IDs, so what was recorded for the removed layers only applies again once\n // it is matched to the layers of the new component that take their places.\n const capturedOverrides = restoreOverrides\n ? captureInstanceOverrides(graph, graph.nodes.get(instanceId) as SceneNode)\n : undefined\n for (const childId of childIds) {\n forgetOverridesOf(graph, childId)\n graph.deleteNode(childId)\n }\n graph.updateNode(instanceId, updates)\n cloneChildrenWithMapping(graph, componentId, instanceId)\n applyBoundPaintColorsIn(graph, instanceId)\n const swapped = graph.nodes.get(instanceId)\n if (swapped && capturedOverrides) restoreInstanceOverrides(graph, swapped, capturedOverrides)\n}\n\nconst syncingComponentsByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nexport function syncInstances(graph: SceneGraph, componentId: string): void {\n syncInstancesOf(graph, componentId, getInstances(graph, componentId))\n}\n\n/**\n * Syncs each component's instances, in order, as one edit: the copies they remove stay\n * restorable together for as long as undo keeps that edit.\n */\nexport function syncInstancesTogether(graph: SceneGraph, componentIds: Iterable<string>): void {\n groupCopyRemovals(graph, () => {\n for (const id of componentIds) syncInstances(graph, id)\n })\n}\n\n/** Syncs one instance from its component, as `syncInstances` does for every instance. */\nexport function syncInstance(graph: SceneGraph, instanceId: string): void {\n const instance = graph.nodes.get(instanceId)\n if (instance?.type !== 'INSTANCE' || !instance.componentId) return\n syncInstancesOf(graph, instance.componentId, [instance])\n}\n\nfunction syncInstancesOf(\n graph: SceneGraph,\n componentId: string,\n instances: Iterable<SceneNode>\n): void {\n const component = graph.nodes.get(componentId)\n if (component?.type !== 'COMPONENT') return\n let syncing = syncingComponentsByGraph.get(graph)\n if (!syncing) {\n syncing = new Set()\n syncingComponentsByGraph.set(graph, syncing)\n }\n if (syncing.has(componentId)) return\n syncing.add(componentId)\n try {\n groupCopyRemovals(graph, (removals) => {\n for (const instance of instances) {\n const enclosing = enclosingInstanceOverrideFields(graph, instance)\n enclosing.push(new Set(instance.instanceOverrides.self.keys()))\n const protectedField = bindingProtection(enclosing)\n const source = sourceInTargetCoordinates(component, instance.componentScale)\n const updates: Partial<SceneNode> = {}\n syncBindingFields(instance, source, updates, protectedField)\n syncVariableModeFields(instance, source, updates, protectedField)\n for (const key of INSTANCE_SYNC_PROPS) {\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (isProtectedSyncField(instance, key, protectedField)) continue\n copyProp(updates, source, key)\n }\n // The file keeps one value for the instance frame and its component, so the frame takes\n // those the layers inside an instance may not set.\n for (const key of INSTANCE_FRAME_FOLLOWED_FIELDS) {\n if (!isProtectedSyncField(instance, key, protectedField)) copyProp(updates, source, key)\n }\n // An instance that hugs its layers sizes to what it shows, not to the component.\n keepOwnContentSize(graph, updates, instance, source)\n // A size that follows the component invalidates outlines the file saved on the instance;\n // its live box draws them again.\n if (updates.width !== undefined || updates.height !== undefined) {\n Object.assign(\n updates,\n shapeGeometryChanges(\n instance,\n updates.width ?? instance.width,\n updates.height ?? instance.height\n )\n )\n }\n updateSyncedProps(graph, instance, updates, (key) =>\n isProtectedSyncField(instance, key, protectedField)\n )\n const owned = ownInstanceOverrides(instance)\n const context = createInstanceSyncContext(instance.id, owned)\n syncChildren(graph, component.id, instance.id, owned, context)\n removeLeftoverCopies(graph, context, removals)\n }\n })\n } finally {\n syncing.delete(componentId)\n }\n}\n\n/**\n * Renames the layers that the copied instances among `copies` record overrides for to their\n * copies, as a copied instance records its own layers' overrides. The values keep naming what\n * they name, since a copy shows the same components as its source.\n */\nexport function retargetCopiedOverrides(\n graph: SceneGraph,\n copies: ReadonlyMap<string, string>\n): void {\n for (const id of copies.values()) {\n const node = graph.nodes.get(id)\n if (node?.type !== 'INSTANCE' || node.instanceOverrides.descendants.size === 0) continue\n const descendants = new Map(\n [...node.instanceOverrides.descendants].map(([target, fields]) => [\n copies.get(target) ?? target,\n fields\n ])\n )\n graph.updateNode(id, { instanceOverrides: { ...node.instanceOverrides, descendants } })\n }\n}\n\nexport function detachInstance(graph: SceneGraph, instanceId: string): void {\n const node = graph.nodes.get(instanceId)\n if (node?.type !== 'INSTANCE') return\n for (const nested of outermostNestedInstances(graph, node))\n adoptNestedOverrides(graph, node, nested)\n // Through `updateNode`, so the instance index, change observers, and undo recorders see it.\n graph.updateNode(instanceId, {\n type: 'FRAME',\n componentId: null,\n instanceOverrides: createInstanceOverrideState()\n })\n // Its mirrored layers stand on their own: a component child id would name a layer of another\n // node, which the format never stores and a later sync would read as a link back. A nested\n // instance is not a mirror and keeps its own links, which its overrides are written through.\n const detachLinks = (parentId: string): void => {\n for (const child of graph.getChildren(parentId)) {\n if (child.type === 'INSTANCE') continue\n if (child.componentId) graph.updateNode(child.id, { componentId: null })\n detachLinks(child.id)\n }\n }\n detachLinks(instanceId)\n}\n\n// A swap's bookkeeping belongs to the instance enclosing the swapped one, never to the swapped one.\nconst OWNER_ONLY_FIELDS = new Set(['componentId', 'sourceComponentId'])\n\nfunction outermostNestedInstances(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n return graph\n .getChildren(instance.id)\n .flatMap((child) =>\n child.type === 'INSTANCE' ? [child] : outermostNestedInstances(graph, child)\n )\n}\n\n/**\n * An instance a detached one holds stands on its own once that one is a frame, and so must what\n * makes it differ from its component. Cloned in, it kept the overrides of the instance it copies,\n * under that instance's layers; those, and the ones the detached instance recorded on its layers,\n * now go under its own.\n */\nfunction adoptNestedOverrides(graph: SceneGraph, detached: SceneNode, nested: SceneNode): void {\n const ownLayer = new Map<string, string>()\n walkInstanceSources(graph, nested, (source, target) => {\n ownLayer.set(source.id, target.id)\n return true\n })\n const { self, descendants: kept } = cloneInstanceOverrideState(nested.instanceOverrides)\n const outer = cloneInstanceOverrideState(detached.instanceOverrides).descendants\n const descendants = new Map<string, Map<string, unknown>>()\n const claim = (layerId: string, fields: Map<string, unknown>): void => {\n const merged = descendants.get(layerId)\n if (!merged) descendants.set(layerId, fields)\n else for (const [field, value] of fields) merged.set(field, value)\n }\n // What was recorded on its own layers is more recent than what it copied, so it is laid on top.\n for (const [layerId, fields] of kept)\n if (ownLayer.has(layerId)) claim(ownLayer.get(layerId) ?? layerId, fields)\n for (const [layerId, fields] of kept) if (!ownLayer.has(layerId)) claim(layerId, fields)\n for (const [layerId, fields] of outer) {\n if (layerId === nested.id) {\n for (const [field, value] of fields) if (!OWNER_ONLY_FIELDS.has(field)) self.set(field, value)\n } else if (graph.isDescendant(layerId, nested.id)) claim(layerId, fields)\n }\n graph.updateNode(nested.id, { instanceOverrides: { self, descendants } })\n}\n\nexport function getMainComponent(graph: SceneGraph, instanceId: string): SceneNode | undefined {\n const node = graph.nodes.get(instanceId)\n if (!node?.componentId) return undefined\n return graph.nodes.get(node.componentId)\n}\n\nexport function getInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n const ids = graph.instanceIndex.get(componentId)\n if (!ids) return []\n const instances: SceneNode[] = []\n for (const id of ids) {\n const node = graph.nodes.get(id)\n if (node) instances.push(node)\n }\n return instances\n}\n\n/** Nearest INSTANCE at or above `nodeId` — self, parent, grandparent, etc. */\nexport function findInstanceAncestor(graph: SceneGraph, nodeId: string): SceneNode | undefined {\n let current = graph.nodes.get(nodeId)\n while (current) {\n if (current.type === 'INSTANCE') return current\n current = current.parentId ? graph.nodes.get(current.parentId) : undefined\n }\n return undefined\n}\n\n/**\n * Whether Figma lets this layer take a size of its own: a layer inside an instance shows its\n * component's size and cannot be resized, while an instance nested in another may be.\n */\nexport function takesOwnSize(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'INSTANCE' || !node.parentId || !findInstanceAncestor(graph, node.parentId)\n}\n\n/**\n * True when a node field is protected from instance synchronization.\n */\nexport function hasInstanceOverride(graph: SceneGraph, nodeId: string, field: string): boolean {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return false\n return hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n}\n\n/**\n * The layer of the component an instance layer copies, which its overrides are measured\n * against: the instance's component for the instance itself.\n */\nfunction copiedLayer(graph: SceneGraph, instance: SceneNode, node: SceneNode) {\n const id =\n node.id === instance.id\n ? instance.componentId\n : copiedComponentLayerId(instance.instanceOverrides, instance.id, node)\n return id ? graph.nodes.get(id) : undefined\n}\n\n/**\n * The override fields an edit of these fields records. A mode edit claims only the collections\n * whose mode now differs from the component layer's, so the component's other modes still\n * reach the layer; with no layer to compare, it claims every mode.\n */\nfunction overrideFieldsOf(\n graph: SceneGraph,\n instance: SceneNode,\n nodeId: string,\n fields: string[]\n): string[] {\n if (!fields.includes('variableModes')) return fields\n const node = graph.nodes.get(nodeId)\n const source = node && copiedLayer(graph, instance, node)\n if (!node || !source) return fields\n return [\n ...fields.filter((field) => field !== 'variableModes'),\n ...differingVariableModeCollections(node, source).map(variableModeOverrideField)\n ]\n}\n\n/**\n * The instance above `instanceId` that records an assignment made through it: an assignment of a\n * nested instance's property is an edit of the instance it sits in, not of the nested instance.\n */\nexport function assignmentOverrideOwner(\n graph: SceneGraph,\n instanceId: string\n): SceneNode | undefined {\n const parentId = graph.nodes.get(instanceId)?.parentId\n return parentId ? findInstanceAncestor(graph, parentId) : undefined\n}\n\n/** The overrides an assignment edit writes on the instance above it, for undo to restore. */\nexport interface AssignmentOverrideState {\n ownerId: string\n overrides: InstanceOverrideState\n}\n\nexport function takeAssignmentOverrideState(\n graph: SceneGraph,\n instanceId: string\n): AssignmentOverrideState | undefined {\n const owner = assignmentOverrideOwner(graph, instanceId)\n return owner\n ? { ownerId: owner.id, overrides: cloneInstanceOverrideState(owner.instanceOverrides) }\n : undefined\n}\n\nexport function restoreAssignmentOverrideState(\n graph: SceneGraph,\n state: AssignmentOverrideState\n): void {\n graph.updateNode(state.ownerId, {\n instanceOverrides: cloneInstanceOverrideState(state.overrides)\n })\n}\n\n/**\n * Records that an instance assigned one of its component properties, as an edit of the instance\n * above it: the assignment is made through the outer instance, so a text override of the same\n * level does not outrank it. A top-level instance has no outer instance to record it on.\n */\nexport function recordAssignmentOverride(\n graph: SceneGraph,\n instanceId: string,\n propertyId: string,\n value: string\n): void {\n const outer = assignmentOverrideOwner(graph, instanceId)\n if (!outer) return\n setInstanceOverride(\n ownInstanceOverrides(outer),\n outer.id,\n instanceId,\n assignmentOverrideField(propertyId),\n value\n )\n graph.updateNode(outer.id, { instanceOverrides: outer.instanceOverrides })\n}\n\n/**\n * The fields `changes` overrides on an instance layer. New strokes that change only what the\n * layer's line fields say override those fields, not the paints (`changesMoreThanStrokeLines`).\n */\nexport function instanceOverrideFields(node: SceneNode, changes: Partial<SceneNode>): string[] {\n const fields = Object.keys(changes)\n if (!changes.strokes || changesMoreThanStrokeLines(node, changes)) return fields\n return fields.filter((field) => field !== 'strokes')\n}\n\nexport function recordInstanceOverride(\n graph: SceneGraph,\n nodeId: string,\n fields: Iterable<string>\n): void {\n const instance = findInstanceAncestor(graph, nodeId)\n if (!instance) return\n // An edit inside a slot makes that frame the instance's own content, as Figma does: from then\n // on the layers stop following the component, and the writer saves them as content instead of\n // dropping an override with no component layer to address.\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (parentId) {\n const scope = enclosingSlotScope(graph, parentId)\n if (scope) claimSlotContent(graph, scope)\n }\n\n const relevant = overrideFieldsOf(\n graph,\n instance,\n nodeId,\n [...fields].filter(\n (field) =>\n (INSTANCE_OVERRIDE_FIELDS as readonly string[]).includes(field) ||\n overriddenAssignmentId(field) !== null\n )\n )\n\n const added = relevant.filter(\n (field) => !hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n )\n if (added.length === 0) return\n\n // A new state rather than an edit of the old one, so a preview that captured the old state\n // puts it back on cancel.\n const overrides = cloneInstanceOverrideState(instance.instanceOverrides)\n for (const field of added) setInstanceOverride(overrides, instance.id, nodeId, field)\n graph.updateNode(instance.id, { instanceOverrides: overrides })\n}\n\n/** Every layer at or below `rootId`. */\nfunction subtreeIds(graph: SceneGraph, rootId: string): string[] {\n const ids: string[] = []\n const visit = (id: string) => {\n ids.push(id)\n for (const childId of graph.nodes.get(id)?.childIds ?? []) visit(childId)\n }\n visit(rootId)\n return ids\n}\n\n/** Forget what the instances above `nodeId` recorded for it and the layers inside it. */\nfunction forgetOverridesOf(graph: SceneGraph, nodeId: string): void {\n const ids = subtreeIds(graph, nodeId)\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (!parentId) return\n graph.closest(parentId, (ancestor) => {\n if (ancestor.type !== 'INSTANCE') return false\n const owned = ownInstanceOverrides(ancestor)\n if (ids.some((id) => owned.descendants.delete(id)))\n graph.updateNode(ancestor.id, { instanceOverrides: owned })\n return false\n })\n}\n\n/** Whether a layer can be replaced in its instance: it sits in the part the component owns. */\nexport function canReplaceInstanceLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node?.parentId || !owner) return false\n // Slot content is the instance's own already, and a generated frame's layers are fixed.\n const scope = slotScope(graph, node.parentId)\n if (scope.kind !== 'locked' || scope.owner.type !== 'INSTANCE') return false\n return (\n replacedLayerIn(owner, node.id) !== undefined ||\n copiedComponentLayerId(owner.instanceOverrides, owner.id, node) !== undefined\n )\n}\n\n/**\n * Put `replacementId` in place of `targetId`, a layer an instance copies from its component, as\n * an override of the nearest instance above it, as pen.dev replaces a layer inside an instance.\n * The replacement takes the target's place among its siblings and its position, the target\n * goes, and syncs keep the replacement in place of the component layer the target copied. A\n * replaced layer can be replaced again. Returns false and changes nothing when the target is no\n * such layer, or the replacement cannot go there.\n */\nexport function replaceInstanceLayer(\n graph: SceneGraph,\n targetId: string,\n replacementId: string\n): boolean {\n const target = graph.nodes.get(targetId)\n const replacement = graph.nodes.get(replacementId)\n const parentId = target?.parentId\n if (!target || !replacement || !parentId || targetId === replacementId) return false\n const owner = owningInstance(graph, target)\n if (!owner || graph.isDescendant(parentId, replacementId)) return false\n if (createsComponentCycle(graph, replacementId, parentId)) return false\n const layerId =\n replacedLayerIn(owner, target.id) ??\n copiedComponentLayerId(owner.instanceOverrides, owner.id, target)\n if (!layerId) return false\n\n // The replacement copies no layer of the component, so its own layers lose such links; an\n // instance among them keeps its own component and layers.\n const unlink = (id: string) => {\n const node = graph.nodes.get(id)\n if (!node) return\n if (node.type !== 'INSTANCE' && node.componentId) graph.updateNode(id, { componentId: null })\n if (node.type !== 'INSTANCE') node.childIds.forEach(unlink)\n }\n unlink(replacementId)\n\n const index = graph.nodes.get(parentId)?.childIds.indexOf(target.id) ?? -1\n forgetOverridesOf(graph, target.id)\n forgetOverridesOf(graph, replacementId)\n graph.insertChildAt(replacementId, parentId, index < 0 ? Number.MAX_SAFE_INTEGER : index)\n graph.updateNode(replacementId, {\n x: target.x,\n y: target.y,\n layoutPositioning: target.layoutPositioning,\n horizontalConstraint: target.horizontalConstraint,\n verticalConstraint: target.verticalConstraint\n })\n graph.deleteNode(target.id)\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n replacementId,\n REPLACED_LAYER_OVERRIDE,\n layerId\n )\n graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) })\n return true\n}\n\n/**\n * Take a replaced layer out and bring back the component layer it stood in for, synced from the\n * outermost instance as a reset syncs. Returns false when the layer is not a replaced one.\n */\nexport function restoreReplacedLayer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n const owner = node && owningInstance(graph, node)\n if (!node || !owner || replacedLayerIn(owner, nodeId) === undefined) return false\n let outermost = owner\n for (let above = owningInstance(graph, owner); above; above = owningInstance(graph, above))\n outermost = above\n forgetOverridesOf(graph, nodeId)\n graph.deleteNode(nodeId)\n syncInstance(graph, outermost.id)\n // An enclosing sync stops at a swapped instance, which brings its layers back itself.\n const above = owningInstance(graph, owner)\n if (above && getInstanceOverride(above.instanceOverrides, above.id, owner.id, 'componentId'))\n syncInstance(graph, owner.id)\n return true\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmEA,SAAgB,2BAA2B,WAA0C;CACnF,MAAM,QAA4B,CAAC;CAEnC,KAAK,MAAM,OAAO,CAAC,GAAG,qBAAqB,GAAG,8BAA8B,GAC1E,SAAS,OAAO,WAAW,GAAG;CAChC,OAAO;AACT;;;;;AAMA,SAAS,sBAAsB,OAAmB,WAA8B;CAC9E,MAAM,SAAS,UAAU,WAAW,MAAM,MAAM,IAAI,UAAU,QAAQ,IAAI,KAAA;CAC1E,OAAO,QAAQ,SAAS,kBAAkB,OAAO,OAAO,UAAU;AACpE;AAEA,SAAgB,eACd,OACA,aACA,UACA,YAAgC,CAAC,GACf;CAClB,MAAM,YAAY,MAAM,MAAM,IAAI,WAAW;CAC7C,IAAI,WAAW,SAAS,eAAe,CAAC,kBAAkB,OAAO,aAAa,QAAQ,GACpF,OAAO;CAET,MAAM,QAA4B;EAChC,GAAG,2BAA2B,SAAS;EACvC,MAAM,sBAAsB,OAAO,SAAS;CAC9C;CAGA,MA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aAAa,OAAO,MAAM,EAAE;CAC9B,OAAO;AACT"}
|
|
@@ -18,7 +18,7 @@ function placedByConstraints(source, compParent, instParent, factor) {
|
|
|
18
18
|
height: compParent.height * factor
|
|
19
19
|
};
|
|
20
20
|
if (before.width === instParent.width && before.height === instParent.height) return source;
|
|
21
|
-
const { flipsX: _flipsX, flipsY: _flipsY, ...rect } = layoutConstrainedChildRect(source, before, instParent, source.horizontalConstraint, source.verticalConstraint, enforcedAspectRatio(source));
|
|
21
|
+
const { flipsX: _flipsX, flipsY: _flipsY, ...rect } = layoutConstrainedChildRect(source, before, instParent, source.horizontalConstraint, source.verticalConstraint, enforcedAspectRatio(source), source);
|
|
22
22
|
return {
|
|
23
23
|
...source,
|
|
24
24
|
...rect
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement.js","names":[],"sources":["../../src/instances/placement.ts"],"sourcesContent":["import { enforcedAspectRatio } from '../layout/aspect-ratio'\nimport { layoutConstrainedChildRect } from '../resize'\nimport type { SceneNode } from '../types'\n\n/** The fields that say where a copy sits in its parent. */\nexport const PLACEMENT_FIELDS: ReadonlySet<string> = new Set(['x', 'y', 'width', 'height'])\n\n/**\n * The component's layer placed in the copy's parent: where its constraints put it when the\n * instance's frame has another size than the component's, as Figma resizes an instance.\n */\nexport function placedByConstraints(\n source: SceneNode,\n compParent: SceneNode,\n instParent: SceneNode,\n factor: number\n): SceneNode {\n const before = { width: compParent.width * factor, height: compParent.height * factor }\n if (before.width === instParent.width && before.height === instParent.height) return source\n const {\n flipsX: _flipsX,\n flipsY: _flipsY,\n ...rect\n } = layoutConstrainedChildRect(\n source,\n before,\n instParent,\n source.horizontalConstraint,\n source.verticalConstraint,\n enforcedAspectRatio(source)\n )\n return { ...source, ...rect }\n}\n"],"mappings":";;;;AAKA,MAAa,mCAAwC,IAAI,IAAI;CAAC;CAAK;CAAK;CAAS;AAAQ,CAAC;;;;;AAM1F,SAAgB,oBACd,QACA,YACA,YACA,QACW;CACX,MAAM,SAAS;EAAE,OAAO,WAAW,QAAQ;EAAQ,QAAQ,WAAW,SAAS;CAAO;CACtF,IAAI,OAAO,UAAU,WAAW,SAAS,OAAO,WAAW,WAAW,QAAQ,OAAO;CACrF,MAAM,EACJ,QAAQ,SACR,QAAQ,SACR,GAAG,SACD,2BACF,QACA,QACA,YACA,OAAO,sBACP,OAAO,oBACP,oBAAoB,MAAM,
|
|
1
|
+
{"version":3,"file":"placement.js","names":[],"sources":["../../src/instances/placement.ts"],"sourcesContent":["import { enforcedAspectRatio } from '../layout/aspect-ratio'\nimport { layoutConstrainedChildRect } from '../resize'\nimport type { SceneNode } from '../types'\n\n/** The fields that say where a copy sits in its parent. */\nexport const PLACEMENT_FIELDS: ReadonlySet<string> = new Set(['x', 'y', 'width', 'height'])\n\n/**\n * The component's layer placed in the copy's parent: where its constraints put it when the\n * instance's frame has another size than the component's, as Figma resizes an instance.\n */\nexport function placedByConstraints(\n source: SceneNode,\n compParent: SceneNode,\n instParent: SceneNode,\n factor: number\n): SceneNode {\n const before = { width: compParent.width * factor, height: compParent.height * factor }\n if (before.width === instParent.width && before.height === instParent.height) return source\n const {\n flipsX: _flipsX,\n flipsY: _flipsY,\n ...rect\n } = layoutConstrainedChildRect(\n source,\n before,\n instParent,\n source.horizontalConstraint,\n source.verticalConstraint,\n enforcedAspectRatio(source),\n source\n )\n return { ...source, ...rect }\n}\n"],"mappings":";;;;AAKA,MAAa,mCAAwC,IAAI,IAAI;CAAC;CAAK;CAAK;CAAS;AAAQ,CAAC;;;;;AAM1F,SAAgB,oBACd,QACA,YACA,YACA,QACW;CACX,MAAM,SAAS;EAAE,OAAO,WAAW,QAAQ;EAAQ,QAAQ,WAAW,SAAS;CAAO;CACtF,IAAI,OAAO,UAAU,WAAW,SAAS,OAAO,WAAW,WAAW,QAAQ,OAAO;CACrF,MAAM,EACJ,QAAQ,SACR,QAAQ,SACR,GAAG,SACD,2BACF,QACA,QACA,YACA,OAAO,sBACP,OAAO,oBACP,oBAAoB,MAAM,GAC1B,MACF;CACA,OAAO;EAAE,GAAG;EAAQ,GAAG;CAAK;AAC9B"}
|
package/dist/instances/sync.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { bindingOverrideField, copiedComponentLayerId, hasInstanceOverride, overriddenBindingField, setInstanceOverride } from "./overrides.js";
|
|
2
2
|
import { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from "../copy.js";
|
|
3
3
|
import { scaleNodeChanges } from "../scaling/node.js";
|
|
4
|
-
import { isNumericVariableBindingField, paintBindingTarget } from "../variables/fields.js";
|
|
4
|
+
import { effectBindingTarget, effectColorBindingTarget, isNumericVariableBindingField, layoutGridBindingTarget, paintBindingTarget } from "../variables/fields.js";
|
|
5
5
|
import { ownsSelfFillField, sourceWithEffectiveFill } from "./main-component.js";
|
|
6
6
|
import { ownsSlotContent, slotPropertyId } from "../slots/frames.js";
|
|
7
7
|
import { STROKE_LINE_FIELDS, STROKE_LINE_KEYS, strokeLine, withStrokeLines } from "../strokes.js";
|
|
8
8
|
import { createVariableResolver } from "../variables/resolver.js";
|
|
9
9
|
import { applyBoundPaintColorsIn, copyAppliedBoundPaints, keepCopyBoundPaints } from "../variables/paints.js";
|
|
10
10
|
import { scaleVariableBindingUnits } from "../variables/units.js";
|
|
11
|
-
import { resolvedNumericBindings } from "../variables/bindings.js";
|
|
11
|
+
import { resolvedEffectColorBindings, resolvedNumericBindings } from "../variables/bindings.js";
|
|
12
12
|
import { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from "./assignments.js";
|
|
13
13
|
import { keepOwnContentSize, remeasureChangedText } from "./content-size.js";
|
|
14
14
|
import { replacedLayerIn, replacedLayerMatch } from "./replacements.js";
|
|
@@ -139,14 +139,33 @@ function updateSyncedProps(graph, target, updates, kept = () => false) {
|
|
|
139
139
|
function resolveBoundNumbersInPlace(graph, target, updates, kept, resolver) {
|
|
140
140
|
const bound = updates.boundVariables ?? target.boundVariables;
|
|
141
141
|
const rebound = updates.boundVariables ? Object.keys(bound).filter((field) => bound[field] !== target.boundVariables[field]) : [];
|
|
142
|
-
const
|
|
142
|
+
const lists = Object.keys(bound).flatMap((field) => {
|
|
143
|
+
let list = null;
|
|
144
|
+
if (effectBindingTarget(field) || effectColorBindingTarget(field)) list = "effects";
|
|
145
|
+
else if (layoutGridBindingTarget(field)) list = "layoutGrids";
|
|
146
|
+
return list && list in updates ? [list] : [];
|
|
147
|
+
});
|
|
148
|
+
const hasBinding = (field) => field === "effects" || field === "layoutGrids" ? Object.keys(bound).some((key) => key.startsWith(`${field}/`)) : Boolean(bound[field]);
|
|
149
|
+
const synced = uniq([
|
|
150
|
+
...Object.keys(updates),
|
|
151
|
+
...rebound,
|
|
152
|
+
...lists
|
|
153
|
+
]).filter((field) => (isNumericVariableBindingField(field) || field === "effects" || field === "layoutGrids") && hasBinding(field) && !kept(field));
|
|
143
154
|
if (synced.length === 0) return;
|
|
144
155
|
applySyncedModes(graph, target, updates);
|
|
145
|
-
const
|
|
156
|
+
const merged = {
|
|
146
157
|
...target,
|
|
147
158
|
...updates
|
|
148
|
-
}
|
|
159
|
+
};
|
|
160
|
+
const resolved = resolvedNumericBindings(graph, merged, "active", resolver);
|
|
149
161
|
Object.assign(updates, pick(resolved, synced));
|
|
162
|
+
if (synced.includes("effects")) {
|
|
163
|
+
const colors = resolvedEffectColorBindings(graph, {
|
|
164
|
+
...merged,
|
|
165
|
+
...updates.effects ? { effects: updates.effects } : {}
|
|
166
|
+
}, resolver);
|
|
167
|
+
if (colors) updates.effects = colors;
|
|
168
|
+
}
|
|
150
169
|
}
|
|
151
170
|
/** The modes the copy takes in this sync decide what its bindings resolve to. */
|
|
152
171
|
function applySyncedModes(graph, target, updates) {
|