@moondraft/import 0.0.0-stage → 0.2.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/CHANGELOG.md +36 -0
- package/LICENSE +34 -0
- package/README.md +36 -2
- package/SOURCE.md +394 -0
- package/dist/adapter/convert.d.ts +144 -0
- package/dist/adapter/convert.js +2811 -0
- package/dist/adapter/figma-descriptions.d.ts +7 -0
- package/dist/adapter/figma-descriptions.js +34 -0
- package/dist/adapter/figma-grids.d.ts +12 -0
- package/dist/adapter/figma-grids.js +175 -0
- package/dist/adapter/figma-handoff.d.ts +12 -0
- package/dist/adapter/figma-handoff.js +167 -0
- package/dist/adapter/figma-hyperlinks.d.ts +13 -0
- package/dist/adapter/figma-hyperlinks.js +77 -0
- package/dist/adapter/figma.d.ts +12 -0
- package/dist/adapter/figma.js +40 -0
- package/dist/adapter/file-components.d.ts +20 -0
- package/dist/adapter/file-components.js +352 -0
- package/dist/adapter/file-resources.d.ts +29 -0
- package/dist/adapter/file-resources.js +851 -0
- package/dist/adapter/image-crop.d.ts +18 -0
- package/dist/adapter/image-crop.js +30 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.js +9 -0
- package/dist/adapter/link.d.ts +49 -0
- package/dist/adapter/link.js +892 -0
- package/dist/adapter/payload.d.ts +31 -0
- package/dist/adapter/payload.js +78 -0
- package/dist/adapter/shapes.d.ts +31 -0
- package/dist/adapter/shapes.js +75 -0
- package/dist/adapter/variables.d.ts +45 -0
- package/dist/adapter/variables.js +106 -0
- package/dist/figma-file.d.ts +38 -0
- package/dist/figma-file.js +97 -0
- package/dist/figma-worker.d.ts +11 -0
- package/dist/figma-worker.js +12 -0
- package/dist/figma.d.ts +26 -0
- package/dist/figma.js +230 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +50 -0
- package/dist/report.d.ts +42 -0
- package/dist/report.js +142 -0
- package/dist/serialize.d.ts +7 -0
- package/dist/serialize.js +79 -0
- package/dist/svg.d.ts +33 -0
- package/dist/svg.js +44 -0
- package/dist/syntax.d.ts +8 -0
- package/dist/syntax.js +19 -0
- package/dist/taco/figma-import/clipboard.d.ts +25 -0
- package/dist/taco/figma-import/clipboard.js +87 -0
- package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
- package/dist/taco/figma-import/clipboardSize.js +107 -0
- package/dist/taco/figma-import/container/compression.d.ts +9 -0
- package/dist/taco/figma-import/container/compression.js +174 -0
- package/dist/taco/figma-import/container/error.d.ts +15 -0
- package/dist/taco/figma-import/container/error.js +19 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
- package/dist/taco/figma-import/container/limits.d.ts +22 -0
- package/dist/taco/figma-import/container/limits.js +22 -0
- package/dist/taco/figma-import/container/zip.d.ts +14 -0
- package/dist/taco/figma-import/container/zip.js +154 -0
- package/dist/taco/figma-import/figFile.d.ts +34 -0
- package/dist/taco/figma-import/figFile.js +91 -0
- package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
- package/dist/taco/figma-import/figFileDocument.js +100 -0
- package/dist/taco/figma-import/import/blobs.d.ts +10 -0
- package/dist/taco/figma-import/import/blobs.js +23 -0
- package/dist/taco/figma-import/import/carry.d.ts +24 -0
- package/dist/taco/figma-import/import/carry.js +66 -0
- package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
- package/dist/taco/figma-import/import/componentProps.js +329 -0
- package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
- package/dist/taco/figma-import/import/componentSets.js +647 -0
- package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
- package/dist/taco/figma-import/import/converters/effects.js +127 -0
- package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
- package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
- package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
- package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/frame.js +63 -0
- package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
- package/dist/taco/figma-import/import/converters/gradient.js +108 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
- package/dist/taco/figma-import/import/converters/group.js +30 -0
- package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
- package/dist/taco/figma-import/import/converters/image.js +94 -0
- package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
- package/dist/taco/figma-import/import/converters/layout.js +187 -0
- package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
- package/dist/taco/figma-import/import/converters/line.js +40 -0
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
- package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
- package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
- package/dist/taco/figma-import/import/converters/section.js +29 -0
- package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
- package/dist/taco/figma-import/import/converters/shared.js +372 -0
- package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
- package/dist/taco/figma-import/import/converters/text.js +707 -0
- package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
- package/dist/taco/figma-import/import/converters/vector.js +609 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
- package/dist/taco/figma-import/import/fields.d.ts +15 -0
- package/dist/taco/figma-import/import/fields.js +29 -0
- package/dist/taco/figma-import/import/instances.d.ts +184 -0
- package/dist/taco/figma-import/import/instances.js +1530 -0
- package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
- package/dist/taco/figma-import/import/nestingCycles.js +488 -0
- package/dist/taco/figma-import/import/slots.d.ts +56 -0
- package/dist/taco/figma-import/import/slots.js +96 -0
- package/dist/taco/figma-import/import/styles.d.ts +48 -0
- package/dist/taco/figma-import/import/styles.js +48 -0
- package/dist/taco/figma-import/import/tree.d.ts +66 -0
- package/dist/taco/figma-import/import/tree.js +194 -0
- package/dist/taco/figma-import/import/types.d.ts +232 -0
- package/dist/taco/figma-import/import/types.js +33 -0
- package/dist/taco/figma-import/import/variables.d.ts +137 -0
- package/dist/taco/figma-import/import/variables.js +769 -0
- package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
- package/dist/taco/figma-import/import/variantTrees.js +520 -0
- package/dist/taco/figma-import/import/walk.d.ts +207 -0
- package/dist/taco/figma-import/import/walk.js +1464 -0
- package/dist/taco/figma-import/index.d.ts +22 -0
- package/dist/taco/figma-import/index.js +13 -0
- package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
- package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
- package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
- package/dist/taco/figma-import/kiwi/error.js +29 -0
- package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
- package/dist/taco/figma-import/kiwi/limits.js +18 -0
- package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
- package/dist/taco/figma-import/kiwi/message.js +147 -0
- package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
- package/dist/taco/figma-import/kiwi/schema.js +206 -0
- package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
- package/dist/taco/figma-import/kiwi/types.js +18 -0
- package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
- package/dist/taco/model/agent-hidden-fields.js +29 -0
- package/dist/taco/model/asset-users.d.ts +23 -0
- package/dist/taco/model/asset-users.js +128 -0
- package/dist/taco/model/auto-layout-lines.d.ts +32 -0
- package/dist/taco/model/auto-layout-lines.js +70 -0
- package/dist/taco/model/codec.d.ts +444 -0
- package/dist/taco/model/codec.js +5665 -0
- package/dist/taco/model/color.d.ts +11 -0
- package/dist/taco/model/color.js +61 -0
- package/dist/taco/model/comment-operations.d.ts +102 -0
- package/dist/taco/model/comment-operations.js +227 -0
- package/dist/taco/model/component-evaluation.d.ts +96 -0
- package/dist/taco/model/component-evaluation.js +555 -0
- package/dist/taco/model/component-expressions.d.ts +242 -0
- package/dist/taco/model/component-expressions.js +1082 -0
- package/dist/taco/model/component-properties.d.ts +111 -0
- package/dist/taco/model/component-properties.js +339 -0
- package/dist/taco/model/component-samples.d.ts +83 -0
- package/dist/taco/model/component-samples.js +290 -0
- package/dist/taco/model/component-validity.d.ts +85 -0
- package/dist/taco/model/component-validity.js +397 -0
- package/dist/taco/model/components.d.ts +155 -0
- package/dist/taco/model/components.js +505 -0
- package/dist/taco/model/connector-ends.d.ts +20 -0
- package/dist/taco/model/connector-ends.js +188 -0
- package/dist/taco/model/connector-geometry.d.ts +74 -0
- package/dist/taco/model/connector-geometry.js +293 -0
- package/dist/taco/model/corner-radii.d.ts +26 -0
- package/dist/taco/model/corner-radii.js +47 -0
- package/dist/taco/model/derivations.d.ts +81 -0
- package/dist/taco/model/derivations.js +151 -0
- package/dist/taco/model/export-settings.d.ts +53 -0
- package/dist/taco/model/export-settings.js +156 -0
- package/dist/taco/model/expressions/ast.d.ts +153 -0
- package/dist/taco/model/expressions/ast.js +6 -0
- package/dist/taco/model/expressions/cache.d.ts +23 -0
- package/dist/taco/model/expressions/cache.js +43 -0
- package/dist/taco/model/expressions/check.d.ts +72 -0
- package/dist/taco/model/expressions/check.js +517 -0
- package/dist/taco/model/expressions/completion.d.ts +61 -0
- package/dist/taco/model/expressions/completion.js +421 -0
- package/dist/taco/model/expressions/evaluate.d.ts +32 -0
- package/dist/taco/model/expressions/evaluate.js +519 -0
- package/dist/taco/model/expressions/forms.d.ts +84 -0
- package/dist/taco/model/expressions/forms.js +200 -0
- package/dist/taco/model/expressions/index.d.ts +14 -0
- package/dist/taco/model/expressions/index.js +17 -0
- package/dist/taco/model/expressions/lexer.d.ts +42 -0
- package/dist/taco/model/expressions/lexer.js +213 -0
- package/dist/taco/model/expressions/library.d.ts +33 -0
- package/dist/taco/model/expressions/library.js +117 -0
- package/dist/taco/model/expressions/names.d.ts +43 -0
- package/dist/taco/model/expressions/names.js +99 -0
- package/dist/taco/model/expressions/parser.d.ts +15 -0
- package/dist/taco/model/expressions/parser.js +438 -0
- package/dist/taco/model/expressions/rename.d.ts +34 -0
- package/dist/taco/model/expressions/rename.js +46 -0
- package/dist/taco/model/expressions/source.d.ts +15 -0
- package/dist/taco/model/expressions/source.js +161 -0
- package/dist/taco/model/expressions/types.d.ts +119 -0
- package/dist/taco/model/expressions/types.js +102 -0
- package/dist/taco/model/expressions/values.d.ts +97 -0
- package/dist/taco/model/expressions/values.js +160 -0
- package/dist/taco/model/geometry-limits.d.ts +16 -0
- package/dist/taco/model/geometry-limits.js +67 -0
- package/dist/taco/model/geometry.d.ts +47 -0
- package/dist/taco/model/geometry.js +193 -0
- package/dist/taco/model/group-bounds.d.ts +38 -0
- package/dist/taco/model/group-bounds.js +144 -0
- package/dist/taco/model/id-table.d.ts +37 -0
- package/dist/taco/model/id-table.js +80 -0
- package/dist/taco/model/index.d.ts +25 -0
- package/dist/taco/model/index.js +27 -0
- package/dist/taco/model/instance-resolver.d.ts +376 -0
- package/dist/taco/model/instance-resolver.js +1778 -0
- package/dist/taco/model/layer-syntax.d.ts +340 -0
- package/dist/taco/model/layer-syntax.js +3506 -0
- package/dist/taco/model/layout/constraints.d.ts +84 -0
- package/dist/taco/model/layout/constraints.js +445 -0
- package/dist/taco/model/layout/frame-layout.d.ts +46 -0
- package/dist/taco/model/layout/frame-layout.js +618 -0
- package/dist/taco/model/layout/node-sizing.d.ts +163 -0
- package/dist/taco/model/layout/node-sizing.js +486 -0
- package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
- package/dist/taco/model/legacy-connector-caps.js +70 -0
- package/dist/taco/model/linear-call.d.ts +48 -0
- package/dist/taco/model/linear-call.js +58 -0
- package/dist/taco/model/new-nodes.d.ts +145 -0
- package/dist/taco/model/new-nodes.js +277 -0
- package/dist/taco/model/node-builder.d.ts +449 -0
- package/dist/taco/model/node-builder.js +2294 -0
- package/dist/taco/model/node-table-watch.d.ts +36 -0
- package/dist/taco/model/node-table-watch.js +63 -0
- package/dist/taco/model/node-transform.d.ts +39 -0
- package/dist/taco/model/node-transform.js +79 -0
- package/dist/taco/model/node-users-index.d.ts +10 -0
- package/dist/taco/model/node-users-index.js +82 -0
- package/dist/taco/model/operation-references.d.ts +80 -0
- package/dist/taco/model/operation-references.js +399 -0
- package/dist/taco/model/operations.d.ts +610 -0
- package/dist/taco/model/operations.js +2882 -0
- package/dist/taco/model/overlay-table.d.ts +71 -0
- package/dist/taco/model/overlay-table.js +171 -0
- package/dist/taco/model/override-remap.d.ts +69 -0
- package/dist/taco/model/override-remap.js +230 -0
- package/dist/taco/model/parent-table.d.ts +53 -0
- package/dist/taco/model/parent-table.js +193 -0
- package/dist/taco/model/problem-collector.d.ts +27 -0
- package/dist/taco/model/problem-collector.js +101 -0
- package/dist/taco/model/sha256.d.ts +10 -0
- package/dist/taco/model/sha256.js +79 -0
- package/dist/taco/model/shape-geometry.d.ts +96 -0
- package/dist/taco/model/shape-geometry.js +368 -0
- package/dist/taco/model/shared-node-table.d.ts +97 -0
- package/dist/taco/model/shared-node-table.js +546 -0
- package/dist/taco/model/slots.d.ts +113 -0
- package/dist/taco/model/slots.js +281 -0
- package/dist/taco/model/stroke-settings.d.ts +37 -0
- package/dist/taco/model/stroke-settings.js +90 -0
- package/dist/taco/model/svg-path-import.d.ts +89 -0
- package/dist/taco/model/svg-path-import.js +219 -0
- package/dist/taco/model/text-measurement.d.ts +142 -0
- package/dist/taco/model/text-measurement.js +846 -0
- package/dist/taco/model/text-reads.d.ts +66 -0
- package/dist/taco/model/text-reads.js +128 -0
- package/dist/taco/model/text-sizer.d.ts +358 -0
- package/dist/taco/model/text-sizer.js +996 -0
- package/dist/taco/model/theme-users.d.ts +59 -0
- package/dist/taco/model/theme-users.js +312 -0
- package/dist/taco/model/thumbnail.d.ts +15 -0
- package/dist/taco/model/thumbnail.js +34 -0
- package/dist/taco/model/types.d.ts +2369 -0
- package/dist/taco/model/types.js +366 -0
- package/dist/taco/model/unknown-property.d.ts +5 -0
- package/dist/taco/model/unknown-property.js +7 -0
- package/dist/taco/model/validated-documents.d.ts +22 -0
- package/dist/taco/model/validated-documents.js +22 -0
- package/dist/taco/model/variable-modes.d.ts +61 -0
- package/dist/taco/model/variable-modes.js +438 -0
- package/dist/taco/model/variable-references.d.ts +54 -0
- package/dist/taco/model/variable-references.js +183 -0
- package/dist/taco/model/variables.d.ts +24 -0
- package/dist/taco/model/variables.js +151 -0
- package/dist/taco/model/vector-network.d.ts +34 -0
- package/dist/taco/model/vector-network.js +411 -0
- package/dist/taco/svg-import/import-svg.d.ts +36 -0
- package/dist/taco/svg-import/import-svg.js +729 -0
- package/dist/taco/svg-import/index.d.ts +3 -0
- package/dist/taco/svg-import/index.js +3 -0
- package/dist/taco/svg-import/limits/limits.d.ts +79 -0
- package/dist/taco/svg-import/limits/limits.js +160 -0
- package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
- package/dist/taco/svg-import/paint/gradients.js +429 -0
- package/dist/taco/svg-import/paint/paint.d.ts +32 -0
- package/dist/taco/svg-import/paint/paint.js +162 -0
- package/dist/taco/svg-import/paths/paths.d.ts +58 -0
- package/dist/taco/svg-import/paths/paths.js +205 -0
- package/dist/taco/svg-import/public-types.d.ts +279 -0
- package/dist/taco/svg-import/public-types.js +56 -0
- package/dist/taco/svg-import/report/report.d.ts +44 -0
- package/dist/taco/svg-import/report/report.js +79 -0
- package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
- package/dist/taco/svg-import/reuse/reuse.js +840 -0
- package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
- package/dist/taco/svg-import/shapes/shapes.js +386 -0
- package/dist/taco/svg-import/structure/effects.d.ts +26 -0
- package/dist/taco/svg-import/structure/effects.js +618 -0
- package/dist/taco/svg-import/structure/image.d.ts +24 -0
- package/dist/taco/svg-import/structure/image.js +495 -0
- package/dist/taco/svg-import/structure/walk.d.ts +85 -0
- package/dist/taco/svg-import/structure/walk.js +544 -0
- package/dist/taco/svg-import/style/color.d.ts +40 -0
- package/dist/taco/svg-import/style/color.js +275 -0
- package/dist/taco/svg-import/style/computed.d.ts +214 -0
- package/dist/taco/svg-import/style/computed.js +1534 -0
- package/dist/taco/svg-import/style/css.d.ts +127 -0
- package/dist/taco/svg-import/style/css.js +541 -0
- package/dist/taco/svg-import/style/media.d.ts +25 -0
- package/dist/taco/svg-import/style/media.js +307 -0
- package/dist/taco/svg-import/style/properties.d.ts +43 -0
- package/dist/taco/svg-import/style/properties.js +135 -0
- package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
- package/dist/taco/svg-import/style/selector-reach.js +169 -0
- package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
- package/dist/taco/svg-import/style/selector-validity.js +307 -0
- package/dist/taco/svg-import/text/text.d.ts +29 -0
- package/dist/taco/svg-import/text/text.js +545 -0
- package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
- package/dist/taco/svg-import/transform/matrix.js +229 -0
- package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
- package/dist/taco/svg-import/tree/element-data.js +155 -0
- package/dist/taco/svg-import/tree/elements.d.ts +36 -0
- package/dist/taco/svg-import/tree/elements.js +121 -0
- package/dist/taco/svg-import/units/length.d.ts +43 -0
- package/dist/taco/svg-import/units/length.js +125 -0
- package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
- package/dist/taco/svg-import/units/viewbox.js +77 -0
- package/package.json +55 -4
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { definitions as propertyDefinitions, effectiveRecord, isInstance, ownerOf, resolveVirtual, splitVirtual } from '@moondraft/editor/core';
|
|
2
|
+
import { guidText } from '../taco/figma-import/import/fields.js';
|
|
3
|
+
import { formatExpressionName, parseLayerPath } from '../taco/model/index.js';
|
|
4
|
+
import { keepDescription } from './figma-descriptions.js';
|
|
5
|
+
/** Installs local property IDs, their bindings, instance assignments and slot content.
|
|
6
|
+
* @param result - Original Figma component declarations and placements.
|
|
7
|
+
* @param doc - Linked document, with source IDs for the original nodes.
|
|
8
|
+
* @param nestedBooleans - Enclosing instance assignments carried through expanded layers and their linked paths.
|
|
9
|
+
* @param report - Receives occurrences the native document cannot represent.
|
|
10
|
+
* @returns Authored override fields and the Figma sources of newly created sets.
|
|
11
|
+
*/
|
|
12
|
+
export function fileComponents(result, doc, nestedBooleans, report) {
|
|
13
|
+
const models = doc.models;
|
|
14
|
+
const byId = new Map(models.map(m => [m.id, m]));
|
|
15
|
+
const mains = new Map(), bySource = new Map();
|
|
16
|
+
const source = new Map(result.nodes.map(n => [n.id, n]));
|
|
17
|
+
const componentOfRoot = new Map(result.components.map(c => [c.rootId, c.id]));
|
|
18
|
+
const componentSources = new Map(Object.entries(result.componentIds).map(([guid, id]) => [id, result.sources.tree.nodes.get(guid)]));
|
|
19
|
+
for (const m of models) {
|
|
20
|
+
if (m.component === m.id)
|
|
21
|
+
mains.set(componentOfRoot.get(m.sourceId), m);
|
|
22
|
+
if (m.fileInstance) {
|
|
23
|
+
m.sourceId = m.fileInstance;
|
|
24
|
+
delete m.fileInstance;
|
|
25
|
+
}
|
|
26
|
+
if (m.sourceId)
|
|
27
|
+
bySource.set(m.sourceId, m);
|
|
28
|
+
}
|
|
29
|
+
const definitions = new Map();
|
|
30
|
+
const nameOf = (name) => name.replace(/#\d+(?::\d+)*$/, '').trim() || 'Property';
|
|
31
|
+
function declare(owner, properties, isSet) {
|
|
32
|
+
const refs = new Map(), names = new Set();
|
|
33
|
+
for (const p of properties) {
|
|
34
|
+
if (refs.has(p.id) || p.kind === 'slot')
|
|
35
|
+
continue;
|
|
36
|
+
const base = nameOf(p.name);
|
|
37
|
+
let name = base;
|
|
38
|
+
for (let i = 2; names.has(name); i++)
|
|
39
|
+
name = base + ' ' + i;
|
|
40
|
+
if (name !== base)
|
|
41
|
+
report.push({ kind: 'approximated', what: `property renamed from ${base} to ${name}`, count: 1, ids: [owner.id] });
|
|
42
|
+
names.add(name);
|
|
43
|
+
const id = 'p' + (refs.size + 1);
|
|
44
|
+
const def = { id, name, kind: p.kind, default: p.defaultValue };
|
|
45
|
+
if (p.kind === 'variant') {
|
|
46
|
+
def.options = p.options;
|
|
47
|
+
}
|
|
48
|
+
else if (p.kind === 'instance') {
|
|
49
|
+
def.kind = 'swap';
|
|
50
|
+
def.default = mains.get(p.defaultValue).id;
|
|
51
|
+
if (p.preferred)
|
|
52
|
+
def.preferred = p.preferred.flatMap((key) => mains.get(key)?.id ?? []);
|
|
53
|
+
}
|
|
54
|
+
refs.set(p.id, def);
|
|
55
|
+
}
|
|
56
|
+
const props = [...refs.values()];
|
|
57
|
+
if (isSet)
|
|
58
|
+
owner.variantSet = { props };
|
|
59
|
+
else if (props.length)
|
|
60
|
+
owner.props = props;
|
|
61
|
+
if (props.length)
|
|
62
|
+
owner.propSeq = props.length;
|
|
63
|
+
return refs;
|
|
64
|
+
}
|
|
65
|
+
const components = new Map(result.components.map(c => [c.id, c]));
|
|
66
|
+
const importedSets = new Map(result.sources.imported.filter(({ figma }) => figma.change.isStateGroup === true)
|
|
67
|
+
.map(({ node, figma }) => [figma.id, node.id]));
|
|
68
|
+
const setSources = new Map();
|
|
69
|
+
for (const [guid, { plan, properties }] of result.sources.variants) {
|
|
70
|
+
const members = plan.variants;
|
|
71
|
+
const sourceId = importedSets.get(guid);
|
|
72
|
+
let set = sourceId === undefined ? undefined : bySource.get(sourceId);
|
|
73
|
+
if (!set) {
|
|
74
|
+
set = { id: 'set-' + guid, kind: 'frame', name: plan.set.name, parent: '@components', w: 0, h: 0 };
|
|
75
|
+
set.sourceId = set.id;
|
|
76
|
+
result.layerIds[guid] = set.sourceId;
|
|
77
|
+
setSources.set(set.sourceId, plan.set);
|
|
78
|
+
models.push(set);
|
|
79
|
+
byId.set(set.id, set);
|
|
80
|
+
}
|
|
81
|
+
set.key = plan.set.change.componentKey || 'figma-' + guid;
|
|
82
|
+
keepDescription(plan.set, set, report);
|
|
83
|
+
const variantDefs = new Map(plan.set.change.componentPropDefs.map(d => ['figma-' + guidText(d.id, guid), d]));
|
|
84
|
+
const orders = new Map((plan.set.change.stateGroupPropertyValueOrders ?? []).map(o => [o.property, o.values]));
|
|
85
|
+
const axes = plan.properties.flatMap(p => {
|
|
86
|
+
const def = variantDefs.get(p.id);
|
|
87
|
+
const option = (id) => id.slice(p.id.length + 1);
|
|
88
|
+
const options = [...new Set([...orders.get(def.name) ?? [], ...p.options.map(o => option(o.id))])];
|
|
89
|
+
const initial = def.initialValue?.textValue?.characters;
|
|
90
|
+
if (!members.length && typeof initial === 'string' && !options.includes(initial))
|
|
91
|
+
options.push(initial);
|
|
92
|
+
if (!options.length) {
|
|
93
|
+
report.push({ kind: 'left-out', what: 'variant property without options', count: 1, ids: [set.id] });
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
return [{ ...p, name: def.name, kind: 'variant', options, defaultValue: options.includes(initial) ? initial : option(p.defaultValue) }];
|
|
97
|
+
});
|
|
98
|
+
const declarations = [...axes, ...properties.map(p => p.definition),
|
|
99
|
+
...members.flatMap(v => components.get(v.componentId).properties ?? [])];
|
|
100
|
+
const refs = declare(set, declarations, true);
|
|
101
|
+
for (const { variant } of plan.duplicates) {
|
|
102
|
+
const main = mains.get(variant.componentId);
|
|
103
|
+
if (main.parent !== '@components') {
|
|
104
|
+
const placement = { id: 'duplicate-' + main.id, kind: 'frame', name: main.name, parent: main.parent, t: main.t,
|
|
105
|
+
w: main.w, h: main.h, opacity: main.opacity, component: main.id };
|
|
106
|
+
models.splice(models.indexOf(main), 0, placement);
|
|
107
|
+
}
|
|
108
|
+
main.parent = '@components';
|
|
109
|
+
report.push({ kind: 'approximated', what: 'duplicate variant kept as a standalone main', count: 1, ids: [main.id] });
|
|
110
|
+
}
|
|
111
|
+
for (const [i, member] of members.entries()) {
|
|
112
|
+
const main = mains.get(member.componentId);
|
|
113
|
+
const values = plan.values[i];
|
|
114
|
+
main.parent = set.id;
|
|
115
|
+
main.variant = Object.fromEntries(plan.properties.map(p => [
|
|
116
|
+
refs.get(p.id).id, values[p.id].slice(p.id.length + 1),
|
|
117
|
+
]));
|
|
118
|
+
definitions.set(member.componentId, refs);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const sourceComponent = new Map();
|
|
122
|
+
for (const c of result.components) {
|
|
123
|
+
const main = mains.get(c.id);
|
|
124
|
+
main.key = c.key;
|
|
125
|
+
keepDescription(componentSources.get(c.id), main, report);
|
|
126
|
+
if (!definitions.has(c.id))
|
|
127
|
+
definitions.set(c.id, declare(main, c.properties ?? [], false));
|
|
128
|
+
else
|
|
129
|
+
for (const p of c.properties ?? []) {
|
|
130
|
+
if (p.kind === 'slot')
|
|
131
|
+
continue;
|
|
132
|
+
const shared = definitions.get(c.id).get(p.id);
|
|
133
|
+
const value = p.kind === 'instance' ? mains.get(p.defaultValue).id : p.defaultValue;
|
|
134
|
+
if (value !== shared.default)
|
|
135
|
+
report.push({ kind: 'approximated', what: 'variant member property default', count: 1, ids: [main.id] });
|
|
136
|
+
}
|
|
137
|
+
const pending = [c.rootId];
|
|
138
|
+
while (pending.length) {
|
|
139
|
+
const id = pending.pop(), layer = source.get(id);
|
|
140
|
+
sourceComponent.set(id, c);
|
|
141
|
+
for (const child of layer.children ?? [])
|
|
142
|
+
pending.push(child);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const componentOfMain = (id) => componentOfRoot.get(byId.get(id)?.sourceId);
|
|
146
|
+
function values(component, assignments, id) {
|
|
147
|
+
const refs = definitions.get(component);
|
|
148
|
+
return Object.fromEntries(Object.entries(assignments).flatMap(([key, value]) => {
|
|
149
|
+
const p = refs.get(key);
|
|
150
|
+
// The selected variant is already represented by the linked main.
|
|
151
|
+
if (p?.kind === 'variant')
|
|
152
|
+
return [];
|
|
153
|
+
if (!p) {
|
|
154
|
+
report.push({ kind: 'left-out', what: 'component property unavailable on the imported instance', count: 1, ids: [id] });
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
return [[p.id, p.kind === 'swap' ? mains.get(value).id : value]];
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
// Reader paths cross instances and name the final layer. Native paths also include each ordinary parent.
|
|
161
|
+
function overridePath(key) {
|
|
162
|
+
return (parseLayerPath(key) ?? []).flatMap(sourceId => {
|
|
163
|
+
const chain = [];
|
|
164
|
+
for (let layer = bySource.get(sourceId); layer && layer.component !== layer.id; layer = byId.get(layer.parent))
|
|
165
|
+
chain.unshift(layer.id);
|
|
166
|
+
return chain;
|
|
167
|
+
}).join(';');
|
|
168
|
+
}
|
|
169
|
+
const occurrences = new Map();
|
|
170
|
+
const instanceOverrides = new Map();
|
|
171
|
+
const hosts = new Set(result.nodes.filter(n => n.type === 'frame' && n.slotHost).map(n => n.id));
|
|
172
|
+
const usedHosts = new Set();
|
|
173
|
+
const slots = new Set();
|
|
174
|
+
const enclosing = new Map();
|
|
175
|
+
for (const m of models) {
|
|
176
|
+
const main = m.component === m.id ? m : enclosing.get(m.parent);
|
|
177
|
+
enclosing.set(m.id, main);
|
|
178
|
+
const owner = sourceComponent.get(m.sourceId);
|
|
179
|
+
if (owner && main === mains.get(owner.id))
|
|
180
|
+
bySource.set(m.sourceId, m);
|
|
181
|
+
}
|
|
182
|
+
for (const m of models) {
|
|
183
|
+
const n = source.get(m.sourceId);
|
|
184
|
+
if (!n)
|
|
185
|
+
continue;
|
|
186
|
+
const component = sourceComponent.get(n.id);
|
|
187
|
+
const original = component && enclosing.get(m.id) === mains.get(component.id);
|
|
188
|
+
const properties = original ? component.properties ?? [] : [];
|
|
189
|
+
if (m.component && m.overrides) {
|
|
190
|
+
for (const [path, entry] of Object.entries(m.overrides)) {
|
|
191
|
+
if (entry.component && Object.keys(entry).some(k => k.startsWith('look.') || k === 'radius' || k === 'smoothing'))
|
|
192
|
+
report.push({ kind: 'approximated', what: 'swapped root appearance', count: 1, ids: [m.id + ';' + path] });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
for (const [field, expression] of Object.entries(n.expressions ?? {})) {
|
|
196
|
+
const p = properties.find(p => formatExpressionName(p.name) === expression);
|
|
197
|
+
const bind = { characters: 'content', visible: 'visible', componentId: 'component' }[field];
|
|
198
|
+
const ref = p && definitions.get(component.id).get(p.id);
|
|
199
|
+
if (ref && ref.kind !== 'variant' && bind && original && (bind !== 'component' || m.component)) {
|
|
200
|
+
(m.bind ??= {})[bind] = ref.id;
|
|
201
|
+
}
|
|
202
|
+
else
|
|
203
|
+
report.push({ kind: 'approximated', what: 'expression', count: 1, ids: [m.id] });
|
|
204
|
+
}
|
|
205
|
+
if (n.slot && original) {
|
|
206
|
+
const key = component.id + '/' + n.slot;
|
|
207
|
+
if (slots.has(key))
|
|
208
|
+
report.push({ kind: 'approximated', what: 'repeated slot', ids: [m.id], count: 1 });
|
|
209
|
+
else {
|
|
210
|
+
const declaration = properties.find(p => p.id === n.slot);
|
|
211
|
+
m.slot = { id: n.slot, name: nameOf(declaration.name) };
|
|
212
|
+
for (const field of ['minChildren', 'maxChildren', 'preferredOnly', 'preferred', 'fillCrossAxisOnInsert', 'displayEmptyByDefault'])
|
|
213
|
+
if (field in declaration)
|
|
214
|
+
report.push({ kind: 'left-out', what: 'slot ' + field, count: 1, ids: [m.id] });
|
|
215
|
+
slots.add(key);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (n.type !== 'instance' || m.component === m.id)
|
|
219
|
+
continue;
|
|
220
|
+
const fills = n.slots ?? {};
|
|
221
|
+
for (const [path, nested] of Object.entries(fills)) {
|
|
222
|
+
if (path)
|
|
223
|
+
report.push({ kind: 'approximated', what: 'a nested slot assignment cannot be kept editable because its fill needs a stored instance owner',
|
|
224
|
+
count: Object.keys(nested).length, ids: [m.id] });
|
|
225
|
+
}
|
|
226
|
+
if (!m.component) {
|
|
227
|
+
report.push({ kind: 'approximated', what: 'expanded instance', count: 1, ids: [m.id] });
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const fields = result.sources.occurrenceFields.get(n.id);
|
|
231
|
+
if (fields)
|
|
232
|
+
occurrences.set(m.id, new Map([...fields].map(([key, change]) => [overridePath(key), change])));
|
|
233
|
+
// The editor resolves a stored bound swap from the enclosing main or set's declaration.
|
|
234
|
+
let retainedMain = m.component;
|
|
235
|
+
if (m.bind?.component) {
|
|
236
|
+
const owner = ownerOf(id => byId.get(id), enclosing.get(m.id));
|
|
237
|
+
const swap = propertyDefinitions(owner).find(p => p.id === m.bind.component);
|
|
238
|
+
if (swap?.kind === 'swap')
|
|
239
|
+
retainedMain = swap.default;
|
|
240
|
+
}
|
|
241
|
+
const shown = componentOfMain(retainedMain), refs = definitions.get(shown);
|
|
242
|
+
const inherited = nestedBooleans.get(m.id);
|
|
243
|
+
const assignments = values(shown, inherited?.componentId === shown
|
|
244
|
+
? { ...n.propertyValues, ...inherited.values } : n.propertyValues ?? {}, m.id);
|
|
245
|
+
// A member may override a set declaration's default. A variant axis is selected by the component itself.
|
|
246
|
+
for (const p of components.get(shown).properties ?? []) {
|
|
247
|
+
const ref = refs.get(p.id);
|
|
248
|
+
if (!ref || ref.kind === 'variant' || ref.id in assignments)
|
|
249
|
+
continue;
|
|
250
|
+
const value = p.kind === 'instance' ? mains.get(p.defaultValue).id : p.defaultValue;
|
|
251
|
+
if (value !== ref.default)
|
|
252
|
+
assignments[ref.id] = value;
|
|
253
|
+
}
|
|
254
|
+
if (Object.keys(assignments).length)
|
|
255
|
+
m.props = assignments;
|
|
256
|
+
if (n.overrides)
|
|
257
|
+
instanceOverrides.set(m.id, n.overrides);
|
|
258
|
+
for (const [slot, id] of Object.entries(fills[''] ?? {})) {
|
|
259
|
+
const host = bySource.get(id);
|
|
260
|
+
usedHosts.add(host.id);
|
|
261
|
+
host.parent = m.id;
|
|
262
|
+
host.fillsSlot = slot;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Reparented private fills and hidden set members must follow their stored parents on load.
|
|
266
|
+
const children = new Map();
|
|
267
|
+
for (const m of models) {
|
|
268
|
+
if (hosts.has(m.sourceId) && !usedHosts.has(m.id) && !m.parent)
|
|
269
|
+
continue;
|
|
270
|
+
const parent = m.parent ?? '';
|
|
271
|
+
const list = children.get(parent);
|
|
272
|
+
if (list)
|
|
273
|
+
list.push(m);
|
|
274
|
+
else
|
|
275
|
+
children.set(parent, [m]);
|
|
276
|
+
}
|
|
277
|
+
// Resolve virtual paths after slot fills have moved to their native parents.
|
|
278
|
+
const get = (id) => {
|
|
279
|
+
const layer = byId.get(id);
|
|
280
|
+
return isInstance(layer) ? { ...layer, children: children.get(id)?.map(child => child.id) ?? [] } : layer;
|
|
281
|
+
};
|
|
282
|
+
for (const [holderId, overrides] of instanceOverrides) {
|
|
283
|
+
const holder = byId.get(holderId);
|
|
284
|
+
for (const [key, entry] of Object.entries(overrides)) {
|
|
285
|
+
if (!entry.componentId && !entry.propertyValues)
|
|
286
|
+
continue;
|
|
287
|
+
const path = overridePath(key), id = holderId + ';' + path;
|
|
288
|
+
const target = resolveVirtual(get, id, true);
|
|
289
|
+
// The linker compares appearances. An explicit swap can select the same main as an inherited swap.
|
|
290
|
+
if (entry.componentId && target?.component && target.component === mains.get(entry.componentId)?.id) {
|
|
291
|
+
((holder.overrides ??= {})[path] ??= {}).component = target.component;
|
|
292
|
+
}
|
|
293
|
+
if (!entry.propertyValues)
|
|
294
|
+
continue;
|
|
295
|
+
if (!target?.component || !isInstance(target.layer)) {
|
|
296
|
+
report.push({ kind: 'left-out', what: 'component property override requires a nested instance', count: 1, ids: [path && target ? id : holderId] });
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const assignments = values(componentOfMain(target.component), entry.propertyValues, id);
|
|
300
|
+
if (Object.keys(assignments).length)
|
|
301
|
+
((holder.overrides ??= {})[path] ??= {}).props = assignments;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// Load derives a bound component from the property on its enclosing instance occurrence.
|
|
305
|
+
// Keep the literal for path resolution and store its controlling value alongside the other assignments.
|
|
306
|
+
for (const holder of models) {
|
|
307
|
+
if (!isInstance(holder))
|
|
308
|
+
continue;
|
|
309
|
+
for (const [path, entry] of Object.entries(holder.overrides ?? {})) {
|
|
310
|
+
if (!entry.component)
|
|
311
|
+
continue;
|
|
312
|
+
const target = resolveVirtual(get, holder.id + ';' + path, true);
|
|
313
|
+
const binding = target?.layer.bind?.component;
|
|
314
|
+
if (!target || !binding)
|
|
315
|
+
continue;
|
|
316
|
+
const at = target.levels.at(-1)[1];
|
|
317
|
+
const owner = at === 0 ? holder : (holder.overrides[target.parts.slice(1, at + 1).join(';')] ??= {});
|
|
318
|
+
(owner.props ??= {})[binding] = entry.component;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// A flattened ancestor can also leave an assignment inside a surviving linked instance.
|
|
322
|
+
// Apply inherited paths before the longer paths of the instances that use them.
|
|
323
|
+
for (const [id, inherited] of [...nestedBooleans].filter(([id]) => id.includes(';')).sort(([a], [b]) => a.length - b.length)) {
|
|
324
|
+
const target = resolveVirtual(get, id);
|
|
325
|
+
if (!target?.component || componentOfMain(target.component) !== inherited.componentId)
|
|
326
|
+
continue;
|
|
327
|
+
const current = effectiveRecord(get, id)?.props;
|
|
328
|
+
const refs = definitions.get(inherited.componentId);
|
|
329
|
+
const assignments = {};
|
|
330
|
+
for (const [key, value] of Object.entries(inherited.values)) {
|
|
331
|
+
const def = refs.get(key);
|
|
332
|
+
if (def?.kind !== 'boolean' || current?.[def.id] === value)
|
|
333
|
+
continue;
|
|
334
|
+
assignments[def.id] = value;
|
|
335
|
+
}
|
|
336
|
+
if (Object.keys(assignments).length) {
|
|
337
|
+
const [holderId, path] = splitVirtual(id), holder = byId.get(holderId);
|
|
338
|
+
const entry = ((holder.overrides ??= {})[path] ??= {});
|
|
339
|
+
entry.props = { ...entry.props, ...assignments };
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
doc.models = [];
|
|
343
|
+
function append(parent) {
|
|
344
|
+
for (const m of children.get(parent) ?? []) {
|
|
345
|
+
doc.models.push(m);
|
|
346
|
+
append(m.id);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
append('');
|
|
350
|
+
append('@components');
|
|
351
|
+
return { occurrences, setSources };
|
|
352
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ImportReportEntry } from '@moondraft/editor/core';
|
|
2
|
+
import { type DocumentJSON } from '@moondraft/editor/schema';
|
|
3
|
+
import { type FigmaObject } from '../taco/figma-import/import/fields.ts';
|
|
4
|
+
import type { FileMessage } from './file-components.ts';
|
|
5
|
+
type Corner = {
|
|
6
|
+
value: number;
|
|
7
|
+
binding?: {
|
|
8
|
+
data: unknown;
|
|
9
|
+
specific: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Finds instance roots that need their own radius bindings. Native instance roots take bindings from their main.
|
|
13
|
+
* @param result - File definitions and original instance fields.
|
|
14
|
+
* @returns The effective corners for each root that must remain an expanded frame.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function expandedRadiusRoots(result: FileMessage): Map<string, Corner[]>;
|
|
18
|
+
/** Writes the shared resources, layer references and mode choices of a saved file.
|
|
19
|
+
* @param result - Reader output retaining the source relationships.
|
|
20
|
+
* @param doc - Converted layers to associate with their definitions.
|
|
21
|
+
* @param occurrences - Original override fields at their native instance paths.
|
|
22
|
+
* @param expanded - Converted instance literals before the linker removes equal fields.
|
|
23
|
+
* @param expandedRadii - Effective corners of instance roots kept as frames.
|
|
24
|
+
* @param report - Receives unsupported bindings and style uses.
|
|
25
|
+
* @param fileId - Stable Figma file key or digest for unpublished resources.
|
|
26
|
+
* @returns Nothing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function fileResources(result: FileMessage, doc: DocumentJSON, occurrences: Map<string, Map<string, FigmaObject>>, expanded: ReadonlyMap<string, any>, expandedRadii: ReadonlyMap<string, Corner[]>, report: ImportReportEntry[], fileId: () => string): void;
|
|
29
|
+
export {};
|