@moondraft/import 0.0.0-stage → 0.1.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 +7 -0
- package/LICENSE +34 -0
- package/README.md +36 -2
- package/SOURCE.md +169 -0
- package/dist/adapter/convert.d.ts +122 -0
- package/dist/adapter/convert.js +2302 -0
- package/dist/adapter/figma.d.ts +9 -0
- package/dist/adapter/figma.js +30 -0
- package/dist/adapter/file-components.d.ts +14 -0
- package/dist/adapter/file-components.js +262 -0
- package/dist/adapter/file-resources.d.ts +29 -0
- package/dist/adapter/file-resources.js +562 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.js +9 -0
- package/dist/adapter/link.d.ts +45 -0
- package/dist/adapter/link.js +688 -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 +44 -0
- package/dist/adapter/variables.js +103 -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 +96 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +49 -0
- package/dist/report.d.ts +15 -0
- package/dist/report.js +69 -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 +38 -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 +11 -0
- package/dist/taco/figma-import/import/carry.js +33 -0
- package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
- package/dist/taco/figma-import/import/componentProps.js +313 -0
- package/dist/taco/figma-import/import/componentSets.d.ts +83 -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/frame.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/frame.js +55 -0
- package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
- package/dist/taco/figma-import/import/converters/gradient.js +106 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/group.js +39 -0
- package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
- package/dist/taco/figma-import/import/converters/image.js +83 -0
- package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
- package/dist/taco/figma-import/import/converters/layout.js +168 -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 +9 -0
- package/dist/taco/figma-import/import/converters/section.js +35 -0
- package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
- package/dist/taco/figma-import/import/converters/shared.js +362 -0
- package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
- package/dist/taco/figma-import/import/converters/text.js +576 -0
- package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
- package/dist/taco/figma-import/import/converters/vector.js +468 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -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 +163 -0
- package/dist/taco/figma-import/import/instances.js +1323 -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 +46 -0
- package/dist/taco/figma-import/import/styles.js +42 -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 +136 -0
- package/dist/taco/figma-import/import/variables.js +762 -0
- package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
- package/dist/taco/figma-import/import/variantTrees.js +480 -0
- package/dist/taco/figma-import/import/walk.d.ts +159 -0
- package/dist/taco/figma-import/import/walk.js +1297 -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 +10 -0
- package/dist/taco/figma-import/kiwi/message.js +145 -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 +5635 -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 +94 -0
- package/dist/taco/model/component-evaluation.js +548 -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 +372 -0
- package/dist/taco/model/instance-resolver.js +1748 -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 +74 -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 +2347 -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 +54 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which swaps to leave out so that no component contains itself, over one
|
|
3
|
+
* graph of the components (by Figma SYMBOL id) that resolving an instance can
|
|
4
|
+
* step through. `kept` are edges that stay: the instances placed inside
|
|
5
|
+
* components, and swaps an earlier check kept. `swaps` are edges a swap made,
|
|
6
|
+
* as `from>to`, which may be cut.
|
|
7
|
+
*
|
|
8
|
+
* The rule, in one pass: a depth-first search over every edge finds the
|
|
9
|
+
* strongly connected components (Tarjan) and ranks the SYMBOLs by when the
|
|
10
|
+
* search left them, last left first. It starts from each SYMBOL in a
|
|
11
|
+
* topological order of `kept`, by `order` (the Figma file's order) where
|
|
12
|
+
* `kept` leaves it open, so a ring of swaps is entered at the component that
|
|
13
|
+
* holds the others and is closed by the swap back into it. That rank orders the SYMBOLs as far as `kept` allows (a
|
|
14
|
+
* topological order of `kept`, the lowest rank first among those ready).
|
|
15
|
+
* Every swap edge inside one strongly connected component that points back in
|
|
16
|
+
* that order, or at its own SYMBOL, is cut. Any cycle lies inside one strongly
|
|
17
|
+
* connected component and has an edge that points back, and `kept` edges all
|
|
18
|
+
* point forward, so the edges left have no cycle. Where `kept` does not force
|
|
19
|
+
* the order, the edges that point back are the ones the search closed a cycle
|
|
20
|
+
* with, so a ring of swaps loses one. The cut follows the file, not the ids
|
|
21
|
+
* the import gives components. Throws when `kept` has a cycle itself, or
|
|
22
|
+
* names a SYMBOL that is not in `order`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function swapsToCut(order: readonly string[], kept: ReadonlyMap<string, ReadonlySet<string>>, swaps: Iterable<string>): Set<string>;
|
|
25
|
+
/** A swap `from>to` (SYMBOL ids) that `owner` makes: the SYMBOL whose instances make it, or a page instance. */
|
|
26
|
+
export interface OwnedSwap {
|
|
27
|
+
readonly from: string;
|
|
28
|
+
readonly to: string;
|
|
29
|
+
readonly owner: string;
|
|
30
|
+
}
|
|
31
|
+
/** A step of a walk through components: an instance placed inside a component (no `owner`), or an `OwnedSwap`. */
|
|
32
|
+
export interface NestingStep {
|
|
33
|
+
readonly from: string;
|
|
34
|
+
readonly to: string;
|
|
35
|
+
readonly owner?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A search for a walk that resolving a component (or a page instance, by its
|
|
39
|
+
* owner) can take and that meets one component twice, which the resolver
|
|
40
|
+
* refuses. A walk steps through `kept` edges, and through a swap only while
|
|
41
|
+
* its owner is on the walk: a component's swaps apply inside that component,
|
|
42
|
+
* a page instance's inside that instance. So swaps that instances make in
|
|
43
|
+
* components that do not hold each other are never joined into one cycle.
|
|
44
|
+
* The walk keeps the owners on it, less those whose swaps start only in
|
|
45
|
+
* SYMBOLs it cannot reach (over every edge) or reach only through the owner
|
|
46
|
+
* itself, so the walks searched stay few and a ring of swaps keeps few owners.
|
|
47
|
+
* Which owners a walk end keeps depends only on the SYMBOL and the owners it
|
|
48
|
+
* came with, never on the rest of the walk, so a memoized walk end answers
|
|
49
|
+
* for every walk that reaches it.
|
|
50
|
+
* Returns the cycle, from the component met twice back to it, or `null`.
|
|
51
|
+
* `memo` holds each walk end (SYMBOL and owners) found to have no cycle; that
|
|
52
|
+
* stays true while swaps are only taken away, so one memo serves the
|
|
53
|
+
* searches made after each cut.
|
|
54
|
+
*/
|
|
55
|
+
export interface NestingSearch {
|
|
56
|
+
(root: string, rootOwner: string | undefined, memo: NestingMemo): NestingStep[] | null;
|
|
57
|
+
/**
|
|
58
|
+
* Takes away swaps (by identity) that a cut left out: the search then
|
|
59
|
+
* walks as one built without them would, without building it again.
|
|
60
|
+
*/
|
|
61
|
+
remove(swaps: Iterable<OwnedSwap>): void;
|
|
62
|
+
}
|
|
63
|
+
/** The `NestingSearch` over `kept` edges and `swaps`, SYMBOLs by `order`. */
|
|
64
|
+
export declare function nestingSearch(order: readonly string[], kept: ReadonlyMap<string, ReadonlySet<string>>, swaps: readonly OwnedSwap[]): NestingSearch;
|
|
65
|
+
/**
|
|
66
|
+
* What `nestingSearch` keeps across searches: the walk ends found to have no
|
|
67
|
+
* cycle, by SYMBOL and owner set, and the owner sets, interned (0 is none).
|
|
68
|
+
* A set `add` makes is held as the set it grew from and the owner it added,
|
|
69
|
+
* so a walk that adds one owner at each step costs one entry per step, not
|
|
70
|
+
* one per owner; a set `intern` makes is held whole, so a walk that drops an
|
|
71
|
+
* owner at each step costs one set per step. A hash of the owners finds a set
|
|
72
|
+
* however it was made.
|
|
73
|
+
*/
|
|
74
|
+
export interface NestingMemo {
|
|
75
|
+
readonly done: Set<string>;
|
|
76
|
+
/** How many owner sets are interned, the empty one included. */
|
|
77
|
+
readonly size: number;
|
|
78
|
+
/** The owners in a set. */
|
|
79
|
+
owners(id: number): string[];
|
|
80
|
+
/** The id of an owner set. */
|
|
81
|
+
intern(owners: readonly string[]): number;
|
|
82
|
+
/** The id of set `id` with `owner` added; `owner` must not be in it. */
|
|
83
|
+
add(id: number, owner: string): number;
|
|
84
|
+
}
|
|
85
|
+
/** An empty `NestingMemo`. */
|
|
86
|
+
export declare function nestingMemo(): NestingMemo;
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which swaps to leave out so that no component contains itself, over one
|
|
3
|
+
* graph of the components (by Figma SYMBOL id) that resolving an instance can
|
|
4
|
+
* step through. `kept` are edges that stay: the instances placed inside
|
|
5
|
+
* components, and swaps an earlier check kept. `swaps` are edges a swap made,
|
|
6
|
+
* as `from>to`, which may be cut.
|
|
7
|
+
*
|
|
8
|
+
* The rule, in one pass: a depth-first search over every edge finds the
|
|
9
|
+
* strongly connected components (Tarjan) and ranks the SYMBOLs by when the
|
|
10
|
+
* search left them, last left first. It starts from each SYMBOL in a
|
|
11
|
+
* topological order of `kept`, by `order` (the Figma file's order) where
|
|
12
|
+
* `kept` leaves it open, so a ring of swaps is entered at the component that
|
|
13
|
+
* holds the others and is closed by the swap back into it. That rank orders the SYMBOLs as far as `kept` allows (a
|
|
14
|
+
* topological order of `kept`, the lowest rank first among those ready).
|
|
15
|
+
* Every swap edge inside one strongly connected component that points back in
|
|
16
|
+
* that order, or at its own SYMBOL, is cut. Any cycle lies inside one strongly
|
|
17
|
+
* connected component and has an edge that points back, and `kept` edges all
|
|
18
|
+
* point forward, so the edges left have no cycle. Where `kept` does not force
|
|
19
|
+
* the order, the edges that point back are the ones the search closed a cycle
|
|
20
|
+
* with, so a ring of swaps loses one. The cut follows the file, not the ids
|
|
21
|
+
* the import gives components. Throws when `kept` has a cycle itself, or
|
|
22
|
+
* names a SYMBOL that is not in `order`.
|
|
23
|
+
*/
|
|
24
|
+
export function swapsToCut(order, kept, swaps) {
|
|
25
|
+
const index = new Map(order.map((id, at) => [id, at]));
|
|
26
|
+
const indexOf = (id) => {
|
|
27
|
+
const at = index.get(id);
|
|
28
|
+
if (at === undefined)
|
|
29
|
+
throw new Error(`the nesting check met component ${id}, which the import did not make`);
|
|
30
|
+
return at;
|
|
31
|
+
};
|
|
32
|
+
const count = order.length;
|
|
33
|
+
const keptNext = Array.from({ length: count }, () => []);
|
|
34
|
+
const keptBefore = Array.from({ length: count }, () => []);
|
|
35
|
+
for (const [from, tos] of kept) {
|
|
36
|
+
for (const to of tos) {
|
|
37
|
+
keptNext[indexOf(from)].push(indexOf(to));
|
|
38
|
+
keptBefore[indexOf(to)].push(indexOf(from));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const swapEdges = [];
|
|
42
|
+
for (const key of new Set(swaps)) {
|
|
43
|
+
const split = key.indexOf(">");
|
|
44
|
+
if (split < 0)
|
|
45
|
+
throw new Error(`the swap edge ${key} has no ">"`);
|
|
46
|
+
swapEdges.push({ key, from: indexOf(key.slice(0, split)), to: indexOf(key.slice(split + 1)) });
|
|
47
|
+
}
|
|
48
|
+
// Tarjan's strongly connected components over every edge, iteratively. The search starts from each SYMBOL in `kept`'s
|
|
49
|
+
// topological order, by file order where `kept` leaves it open, so it enters the components that hold others first.
|
|
50
|
+
const roots = keptOrder(keptNext, keptBefore, Int32Array.from(order, (_, at) => at), order);
|
|
51
|
+
const next = keptNext.map((list) => [...list]);
|
|
52
|
+
for (const { from, to } of swapEdges)
|
|
53
|
+
next[from].push(to);
|
|
54
|
+
const visitIndex = new Int32Array(count).fill(-1);
|
|
55
|
+
const low = new Int32Array(count);
|
|
56
|
+
const group = new Int32Array(count).fill(-1);
|
|
57
|
+
const onStack = new Uint8Array(count);
|
|
58
|
+
const members = [];
|
|
59
|
+
// Each SYMBOL's rank: the last one the search leaves ranks 0.
|
|
60
|
+
const rank = new Int32Array(count);
|
|
61
|
+
let unranked = count;
|
|
62
|
+
let visited = 0;
|
|
63
|
+
let groups = 0;
|
|
64
|
+
for (const start of roots) {
|
|
65
|
+
if (visitIndex[start] !== -1)
|
|
66
|
+
continue;
|
|
67
|
+
const stack = [{ at: start, next: 0 }];
|
|
68
|
+
visitIndex[start] = low[start] = visited++;
|
|
69
|
+
members.push(start);
|
|
70
|
+
onStack[start] = 1;
|
|
71
|
+
while (stack.length > 0) {
|
|
72
|
+
const top = stack.at(-1);
|
|
73
|
+
const out = next[top.at];
|
|
74
|
+
if (top.next < out.length) {
|
|
75
|
+
const to = out[top.next++];
|
|
76
|
+
if (visitIndex[to] === -1) {
|
|
77
|
+
visitIndex[to] = low[to] = visited++;
|
|
78
|
+
members.push(to);
|
|
79
|
+
onStack[to] = 1;
|
|
80
|
+
stack.push({ at: to, next: 0 });
|
|
81
|
+
}
|
|
82
|
+
else if (onStack[to] === 1) {
|
|
83
|
+
low[top.at] = Math.min(low[top.at], visitIndex[to]);
|
|
84
|
+
}
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
stack.pop();
|
|
88
|
+
rank[top.at] = --unranked;
|
|
89
|
+
const parent = stack.at(-1);
|
|
90
|
+
if (parent !== undefined)
|
|
91
|
+
low[parent.at] = Math.min(low[parent.at], low[top.at]);
|
|
92
|
+
if (low[top.at] === visitIndex[top.at]) {
|
|
93
|
+
for (let member = members.pop(); member !== undefined; member = members.pop()) {
|
|
94
|
+
onStack[member] = 0;
|
|
95
|
+
group[member] = groups;
|
|
96
|
+
if (member === top.at)
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
groups += 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// The order the cut uses: `kept`'s topological order again, by those ranks.
|
|
104
|
+
const position = new Int32Array(count);
|
|
105
|
+
keptOrder(keptNext, keptBefore, rank, order).forEach((at, place) => { position[at] = place; });
|
|
106
|
+
const cut = new Set();
|
|
107
|
+
for (const { key, from, to } of swapEdges) {
|
|
108
|
+
if (group[from] === group[to] && position[to] <= position[from])
|
|
109
|
+
cut.add(key);
|
|
110
|
+
}
|
|
111
|
+
return cut;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A topological order of the `kept` edges (`keptNext`, and `keptBefore` the
|
|
115
|
+
* reverse), taking the ready SYMBOL of the lowest `priority` first (a binary
|
|
116
|
+
* heap). Throws when the edges have a cycle.
|
|
117
|
+
*/
|
|
118
|
+
function keptOrder(keptNext, keptBefore, priority, order) {
|
|
119
|
+
const count = keptNext.length;
|
|
120
|
+
const byPriority = new Int32Array(count);
|
|
121
|
+
for (let at = 0; at < count; at++)
|
|
122
|
+
byPriority[priority[at]] = at;
|
|
123
|
+
const waiting = Int32Array.from(keptBefore, (before) => before.length);
|
|
124
|
+
const heap = [];
|
|
125
|
+
const push = (value) => {
|
|
126
|
+
heap.push(value);
|
|
127
|
+
for (let at = heap.length - 1; at > 0;) {
|
|
128
|
+
const up = (at - 1) >> 1;
|
|
129
|
+
if (heap[up] <= heap[at])
|
|
130
|
+
break;
|
|
131
|
+
[heap[up], heap[at]] = [heap[at], heap[up]];
|
|
132
|
+
at = up;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const pop = () => {
|
|
136
|
+
const first = heap[0];
|
|
137
|
+
const last = heap.pop();
|
|
138
|
+
if (heap.length > 0) {
|
|
139
|
+
heap[0] = last;
|
|
140
|
+
for (let at = 0;;) {
|
|
141
|
+
const left = 2 * at + 1;
|
|
142
|
+
const right = left + 1;
|
|
143
|
+
let least = at;
|
|
144
|
+
if (left < heap.length && heap[left] < heap[least])
|
|
145
|
+
least = left;
|
|
146
|
+
if (right < heap.length && heap[right] < heap[least])
|
|
147
|
+
least = right;
|
|
148
|
+
if (least === at)
|
|
149
|
+
break;
|
|
150
|
+
[heap[least], heap[at]] = [heap[at], heap[least]];
|
|
151
|
+
at = least;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return first;
|
|
155
|
+
};
|
|
156
|
+
for (let at = 0; at < count; at++)
|
|
157
|
+
if (waiting[at] === 0)
|
|
158
|
+
push(priority[at]);
|
|
159
|
+
const sorted = [];
|
|
160
|
+
while (heap.length > 0) {
|
|
161
|
+
const at = byPriority[pop()];
|
|
162
|
+
sorted.push(at);
|
|
163
|
+
for (const to of keptNext[at])
|
|
164
|
+
if (--waiting[to] === 0)
|
|
165
|
+
push(priority[to]);
|
|
166
|
+
}
|
|
167
|
+
if (sorted.length < count) {
|
|
168
|
+
const stuck = waiting.findIndex((left) => left > 0);
|
|
169
|
+
throw new Error(`the instances placed inside components nest a component in itself, at ${order[stuck]} or a component it holds`);
|
|
170
|
+
}
|
|
171
|
+
return sorted;
|
|
172
|
+
}
|
|
173
|
+
/** The `NestingSearch` over `kept` edges and `swaps`, SYMBOLs by `order`. */
|
|
174
|
+
export function nestingSearch(order, kept, swaps) {
|
|
175
|
+
const index = new Map(order.map((id, at) => [id, at]));
|
|
176
|
+
const indexOf = (id) => {
|
|
177
|
+
const at = index.get(id);
|
|
178
|
+
if (at === undefined)
|
|
179
|
+
throw new Error(`the nesting check met component ${id}, which the import did not make`);
|
|
180
|
+
return at;
|
|
181
|
+
};
|
|
182
|
+
const next = Array.from({ length: order.length }, () => []);
|
|
183
|
+
for (const [from, tos] of kept)
|
|
184
|
+
for (const to of tos)
|
|
185
|
+
next[indexOf(from)].push(indexOf(to));
|
|
186
|
+
const swapsFrom = new Map();
|
|
187
|
+
const swapsOf = new Map();
|
|
188
|
+
for (const swap of swaps) {
|
|
189
|
+
next[indexOf(swap.from)].push(indexOf(swap.to));
|
|
190
|
+
for (const [map, key] of [[swapsFrom, swap.from], [swapsOf, swap.owner]]) {
|
|
191
|
+
let list = map.get(key);
|
|
192
|
+
if (list === undefined)
|
|
193
|
+
map.set(key, list = []);
|
|
194
|
+
list.push(swap);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
let reaches = reachability(next);
|
|
198
|
+
// By SYMBOL, the one SYMBOL every edge into it comes from: -1 when no edge does, -2 when more than one SYMBOL does.
|
|
199
|
+
const soleFrom = () => {
|
|
200
|
+
const sole = new Int32Array(order.length).fill(-1);
|
|
201
|
+
next.forEach((outs, from) => { for (const to of outs)
|
|
202
|
+
sole[to] = sole[to] === -1 || sole[to] === from ? from : -2; });
|
|
203
|
+
return sole;
|
|
204
|
+
};
|
|
205
|
+
let sole = soleFrom();
|
|
206
|
+
const fromsOf = (owner, owned) => ({
|
|
207
|
+
self: index.get(owner) ?? -1, froms: [...new Set(owned.map((swap) => swap.from))].map((id) => ({ id, at: indexOf(id) })),
|
|
208
|
+
});
|
|
209
|
+
const ownerFroms = new Map([...swapsOf].map(([owner, owned]) => [owner, fromsOf(owner, owned)]));
|
|
210
|
+
const search = (root, rootOwner, memo) => {
|
|
211
|
+
// Each SYMBOL on the walk, by the index in `steps` of its first step out.
|
|
212
|
+
const onWalk = new Map();
|
|
213
|
+
const steps = [];
|
|
214
|
+
// The owners of the frame on top of the walk.
|
|
215
|
+
const current = new Set(rootOwner === undefined ? [] : [rootOwner]);
|
|
216
|
+
// An owner whose swaps start only in SYMBOLs this one cannot reach cannot step anywhere from here. Nor can a SYMBOL owner
|
|
217
|
+
// whose swaps start only in SYMBOLs that only it holds, from anywhere but itself: the walk would have to pass the owner,
|
|
218
|
+
// which is on the walk, and so meet it twice first. Whether a start is on the walk must not count: the memo key would
|
|
219
|
+
// then depend on the walk, and a walk end memoized on one walk would hide a cycle on another.
|
|
220
|
+
const behind = (self, from) => self >= 0 && sole[from] === self;
|
|
221
|
+
const live = (owner, at, here) => {
|
|
222
|
+
const own = ownerFroms.get(owner);
|
|
223
|
+
return own !== undefined && own.froms.some((from) => from.id === at || (reaches(here, from.at) && (here === own.self || !behind(own.self, from.at))));
|
|
224
|
+
};
|
|
225
|
+
// Whether an owner is live at every SYMBOL in the strongly connected component of this one, which all reach the same.
|
|
226
|
+
const everywhere = (owner, here) => {
|
|
227
|
+
const own = ownerFroms.get(owner);
|
|
228
|
+
return own.froms.some((from) => reaches(here, from.at) && !behind(own.self, from.at));
|
|
229
|
+
};
|
|
230
|
+
const enter = (at, parentOwners, parent) => {
|
|
231
|
+
const here = indexOf(at);
|
|
232
|
+
const added = ownerFroms.has(at) && !current.has(at) && live(at, at, here);
|
|
233
|
+
// A step out of a strongly connected component checks every owner; a step inside one checks only the owners that are
|
|
234
|
+
// not live everywhere in it (`fragile`), as the rest stay live there.
|
|
235
|
+
const dropped = [];
|
|
236
|
+
const fragile = [];
|
|
237
|
+
let left;
|
|
238
|
+
if (parent === undefined || !reaches(here, parent.here)) {
|
|
239
|
+
left = [];
|
|
240
|
+
for (const owner of current) {
|
|
241
|
+
if (!live(owner, at, here)) {
|
|
242
|
+
dropped.push(owner);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
left.push(owner);
|
|
246
|
+
if (!everywhere(owner, here))
|
|
247
|
+
fragile.push(owner);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
for (const owner of parent.fragile)
|
|
252
|
+
(live(owner, at, here) ? fragile : dropped).push(owner);
|
|
253
|
+
}
|
|
254
|
+
if (added && !everywhere(at, here))
|
|
255
|
+
fragile.push(at);
|
|
256
|
+
let active = parentOwners;
|
|
257
|
+
if (dropped.length > 0) {
|
|
258
|
+
const rest = left ?? [...current].filter((owner) => !dropped.includes(owner));
|
|
259
|
+
if (added)
|
|
260
|
+
rest.push(at);
|
|
261
|
+
active = memo.intern(rest);
|
|
262
|
+
}
|
|
263
|
+
else if (added) {
|
|
264
|
+
active = memo.add(active, at);
|
|
265
|
+
}
|
|
266
|
+
const key = `${at}|${String(active)}`;
|
|
267
|
+
if (memo.done.has(key))
|
|
268
|
+
return null;
|
|
269
|
+
for (const owner of dropped)
|
|
270
|
+
current.delete(owner);
|
|
271
|
+
if (added)
|
|
272
|
+
current.add(at);
|
|
273
|
+
const edges = [...kept.get(at) ?? []].map((to) => ({ from: at, to }));
|
|
274
|
+
for (const swap of swapsFrom.get(at) ?? [])
|
|
275
|
+
if (current.has(swap.owner))
|
|
276
|
+
edges.push(swap);
|
|
277
|
+
onWalk.set(at, steps.length);
|
|
278
|
+
return { at, here, owners: active, key, edges, added, dropped, fragile, next: 0 };
|
|
279
|
+
};
|
|
280
|
+
const first = enter(root, rootOwner === undefined ? 0 : memo.intern([rootOwner]), undefined);
|
|
281
|
+
const walk = first === null ? [] : [first];
|
|
282
|
+
while (walk.length > 0) {
|
|
283
|
+
const top = walk.at(-1);
|
|
284
|
+
if (top.next < top.edges.length) {
|
|
285
|
+
const step = top.edges[top.next++];
|
|
286
|
+
steps.push(step);
|
|
287
|
+
const back = onWalk.get(step.to);
|
|
288
|
+
if (back !== undefined)
|
|
289
|
+
return steps.slice(back);
|
|
290
|
+
const frame = enter(step.to, top.owners, top);
|
|
291
|
+
if (frame === null)
|
|
292
|
+
steps.pop();
|
|
293
|
+
else
|
|
294
|
+
walk.push(frame);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
walk.pop();
|
|
298
|
+
onWalk.delete(top.at);
|
|
299
|
+
if (top.added)
|
|
300
|
+
current.delete(top.at);
|
|
301
|
+
for (const owner of top.dropped)
|
|
302
|
+
current.add(owner);
|
|
303
|
+
memo.done.add(top.key);
|
|
304
|
+
if (walk.length > 0)
|
|
305
|
+
steps.pop();
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
};
|
|
309
|
+
const remove = (gone) => {
|
|
310
|
+
const owners = new Set();
|
|
311
|
+
for (const swap of gone) {
|
|
312
|
+
const list = swapsFrom.get(swap.from) ?? [];
|
|
313
|
+
const at = list.indexOf(swap);
|
|
314
|
+
if (at === -1)
|
|
315
|
+
continue;
|
|
316
|
+
list.splice(at, 1);
|
|
317
|
+
const out = next[indexOf(swap.from)];
|
|
318
|
+
out.splice(out.lastIndexOf(indexOf(swap.to)), 1);
|
|
319
|
+
const owned = swapsOf.get(swap.owner);
|
|
320
|
+
owned.splice(owned.indexOf(swap), 1);
|
|
321
|
+
owners.add(swap.owner);
|
|
322
|
+
}
|
|
323
|
+
if (owners.size === 0)
|
|
324
|
+
return;
|
|
325
|
+
for (const owner of owners) {
|
|
326
|
+
const owned = swapsOf.get(owner);
|
|
327
|
+
if (owned.length > 0)
|
|
328
|
+
ownerFroms.set(owner, fromsOf(owner, owned));
|
|
329
|
+
else
|
|
330
|
+
ownerFroms.delete(owner);
|
|
331
|
+
}
|
|
332
|
+
reaches = reachability(next);
|
|
333
|
+
sole = soleFrom();
|
|
334
|
+
};
|
|
335
|
+
return Object.assign(search, { remove });
|
|
336
|
+
}
|
|
337
|
+
/** An empty `NestingMemo`. */
|
|
338
|
+
export function nestingMemo() {
|
|
339
|
+
// By set id: the set it grew from and the owner it added, or (`parents` -1) its owners whole; its size; and the XOR of its
|
|
340
|
+
// owners' hashes.
|
|
341
|
+
const parents = [-1];
|
|
342
|
+
const lasts = [""];
|
|
343
|
+
const wholes = [[]];
|
|
344
|
+
const sizes = [0];
|
|
345
|
+
const hashes = [0];
|
|
346
|
+
const children = new Map();
|
|
347
|
+
const byHash = new Map([[0, [0]]]);
|
|
348
|
+
const ownerHashes = new Map();
|
|
349
|
+
const hashOf = (owner) => {
|
|
350
|
+
let hash = ownerHashes.get(owner);
|
|
351
|
+
if (hash === undefined) {
|
|
352
|
+
// A 32-bit mix (murmur3's finalizer) of a count, so owners hash apart.
|
|
353
|
+
hash = Math.imul(ownerHashes.size + 1, 0x9e3779b1);
|
|
354
|
+
hash = Math.imul(hash ^ (hash >>> 16), 0x85ebca6b);
|
|
355
|
+
hash = Math.imul(hash ^ (hash >>> 13), 0xc2b2ae35);
|
|
356
|
+
ownerHashes.set(owner, hash = (hash ^ (hash >>> 16)) >>> 0);
|
|
357
|
+
}
|
|
358
|
+
return hash;
|
|
359
|
+
};
|
|
360
|
+
const owners = (id) => {
|
|
361
|
+
const list = [];
|
|
362
|
+
let at = id;
|
|
363
|
+
for (; parents[at] >= 0; at = parents[at])
|
|
364
|
+
list.push(lasts[at]);
|
|
365
|
+
list.push(...wholes[at]);
|
|
366
|
+
return list;
|
|
367
|
+
};
|
|
368
|
+
// The set already made with these owners, if any; `wanted` is built only when a set of that hash and size exists.
|
|
369
|
+
const find = (hash, size, wanted) => {
|
|
370
|
+
const same = byHash.get(hash)?.filter((other) => sizes[other] === size) ?? [];
|
|
371
|
+
if (same.length === 0)
|
|
372
|
+
return undefined;
|
|
373
|
+
const set = wanted();
|
|
374
|
+
return same.find((other) => owners(other).every((each) => set.has(each)));
|
|
375
|
+
};
|
|
376
|
+
const make = (parent, last, whole, size, hash) => {
|
|
377
|
+
const made = parents.length;
|
|
378
|
+
parents.push(parent);
|
|
379
|
+
lasts.push(last);
|
|
380
|
+
wholes.push(whole);
|
|
381
|
+
sizes.push(size);
|
|
382
|
+
hashes.push(hash);
|
|
383
|
+
const list = byHash.get(hash);
|
|
384
|
+
if (list === undefined)
|
|
385
|
+
byHash.set(hash, [made]);
|
|
386
|
+
else
|
|
387
|
+
list.push(made);
|
|
388
|
+
return made;
|
|
389
|
+
};
|
|
390
|
+
const add = (id, owner) => {
|
|
391
|
+
const child = `${String(id)} ${owner}`;
|
|
392
|
+
let made = children.get(child);
|
|
393
|
+
if (made !== undefined)
|
|
394
|
+
return made;
|
|
395
|
+
const hash = (hashes[id] ^ hashOf(owner)) >>> 0;
|
|
396
|
+
const size = sizes[id] + 1;
|
|
397
|
+
made = find(hash, size, () => new Set(owners(id)).add(owner)) ?? make(id, owner, undefined, size, hash);
|
|
398
|
+
children.set(child, made);
|
|
399
|
+
return made;
|
|
400
|
+
};
|
|
401
|
+
const intern = (list) => {
|
|
402
|
+
const set = new Set(list);
|
|
403
|
+
let hash = 0;
|
|
404
|
+
for (const owner of set)
|
|
405
|
+
hash = (hash ^ hashOf(owner)) >>> 0;
|
|
406
|
+
return find(hash, set.size, () => set) ?? make(-1, "", [...set], set.size, hash);
|
|
407
|
+
};
|
|
408
|
+
return { done: new Set(), get size() { return parents.length; }, owners, intern, add };
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Whether one node of a graph reaches another (itself included). The
|
|
412
|
+
* strongly connected components (Tarjan, iteratively) and a bit set of the
|
|
413
|
+
* components each reaches are made only for the nodes asked about and what
|
|
414
|
+
* they reach, so a search made again after each cut, which walks a few
|
|
415
|
+
* components, costs only those.
|
|
416
|
+
*/
|
|
417
|
+
function reachability(next) {
|
|
418
|
+
const count = next.length;
|
|
419
|
+
const words = (count + 31) >>> 5;
|
|
420
|
+
const visitIndex = new Int32Array(count).fill(-1);
|
|
421
|
+
const low = new Int32Array(count);
|
|
422
|
+
const group = new Int32Array(count).fill(-1);
|
|
423
|
+
const onStack = new Uint8Array(count);
|
|
424
|
+
const rows = [];
|
|
425
|
+
const members = [];
|
|
426
|
+
let visited = 0;
|
|
427
|
+
const visit = (start) => {
|
|
428
|
+
const stack = [{ at: start, next: 0 }];
|
|
429
|
+
visitIndex[start] = low[start] = visited++;
|
|
430
|
+
members.push(start);
|
|
431
|
+
onStack[start] = 1;
|
|
432
|
+
while (stack.length > 0) {
|
|
433
|
+
const top = stack.at(-1);
|
|
434
|
+
const out = next[top.at];
|
|
435
|
+
if (top.next < out.length) {
|
|
436
|
+
const to = out[top.next++];
|
|
437
|
+
if (visitIndex[to] === -1) {
|
|
438
|
+
visitIndex[to] = low[to] = visited++;
|
|
439
|
+
members.push(to);
|
|
440
|
+
onStack[to] = 1;
|
|
441
|
+
stack.push({ at: to, next: 0 });
|
|
442
|
+
}
|
|
443
|
+
else if (onStack[to] === 1) {
|
|
444
|
+
low[top.at] = Math.min(low[top.at], visitIndex[to]);
|
|
445
|
+
}
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
stack.pop();
|
|
449
|
+
const parent = stack.at(-1);
|
|
450
|
+
if (parent !== undefined)
|
|
451
|
+
low[parent.at] = Math.min(low[parent.at], low[top.at]);
|
|
452
|
+
if (low[top.at] !== visitIndex[top.at])
|
|
453
|
+
continue;
|
|
454
|
+
// Tarjan closes a strongly connected component after every one it reaches, so its row ORs in rows already made.
|
|
455
|
+
const own = rows.length;
|
|
456
|
+
const row = new Uint32Array(words);
|
|
457
|
+
row[own >>> 5] = 1 << (own & 31);
|
|
458
|
+
const inside = [];
|
|
459
|
+
for (let member = members.pop(); member !== undefined; member = members.pop()) {
|
|
460
|
+
onStack[member] = 0;
|
|
461
|
+
group[member] = own;
|
|
462
|
+
inside.push(member);
|
|
463
|
+
if (member === top.at)
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
const seen = new Set([own]);
|
|
467
|
+
for (const at of inside) {
|
|
468
|
+
for (const to of next[at]) {
|
|
469
|
+
const other = group[to];
|
|
470
|
+
if (seen.has(other))
|
|
471
|
+
continue;
|
|
472
|
+
seen.add(other);
|
|
473
|
+
const otherRow = rows[other];
|
|
474
|
+
for (let word = 0; word < words; word++)
|
|
475
|
+
row[word] = row[word] | otherRow[word];
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
rows.push(row);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
return (from, to) => {
|
|
482
|
+
if (group[from] === -1)
|
|
483
|
+
visit(from);
|
|
484
|
+
// A node not yet visited once `from` is done is one `from` does not reach.
|
|
485
|
+
const other = group[to];
|
|
486
|
+
return other !== -1 && ((rows[group[from]][other >>> 5] >>> (other & 31)) & 1) === 1;
|
|
487
|
+
};
|
|
488
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ComponentPropertyId, FrameNode, SceneNode } from "../../model/index.ts";
|
|
2
|
+
import { type ImportedProperty, type PropertyReport } from "./componentProps.ts";
|
|
3
|
+
import type { FigmaTreeNode } from "./tree.ts";
|
|
4
|
+
/**
|
|
5
|
+
* One slot an INSTANCE fills: a `componentPropAssignments` value whose
|
|
6
|
+
* `varValue.value.slotContentIdValue` names the frame (marked
|
|
7
|
+
* `isSlotContent`) whose children go in the slot.
|
|
8
|
+
*/
|
|
9
|
+
export interface FigmaSlotFill {
|
|
10
|
+
/** The override path to the nested instance whose slot this fills, as Figma keys; empty for the instance's own slots. */
|
|
11
|
+
readonly keys: readonly string[];
|
|
12
|
+
/** The id of the SLOT def the value is for. */
|
|
13
|
+
readonly defId: string;
|
|
14
|
+
/** The id of the content frame. */
|
|
15
|
+
readonly contentId: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The slots an INSTANCE fills: its own `componentPropAssignments`, and those
|
|
19
|
+
* of its `symbolOverrides` entries, which fill the slots of nested instances
|
|
20
|
+
* along the entry's `guidPath`. A path naming the instance's own component
|
|
21
|
+
* fills its own slots.
|
|
22
|
+
*/
|
|
23
|
+
export declare function slotFillsOf(instance: FigmaTreeNode): FigmaSlotFill[];
|
|
24
|
+
/** Whether a Figma node is a frame holding the content an instance puts in a slot. */
|
|
25
|
+
export declare function isSlotContent(node: FigmaTreeNode): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The slot property a component layer's `componentPropRefs` binds to
|
|
28
|
+
* `SLOT_CONTENT_ID`, for `FrameNode.slot`. A binding on the component's
|
|
29
|
+
* root, on a layer that is not a frame or is a grid, inside another slot
|
|
30
|
+
* frame's default content (`inSlotFrame`), or to a property that was not
|
|
31
|
+
* imported, is reported and left out.
|
|
32
|
+
*/
|
|
33
|
+
export declare function slotBindingOf(figma: FigmaTreeNode, layer: SceneNode, isRoot: boolean, inSlotFrame: boolean, properties: readonly ImportedProperty[], report: PropertyReport): ComponentPropertyId | undefined;
|
|
34
|
+
/** A filled slot frame and the content frame it shows, with what the instance does to the slot frame's size. */
|
|
35
|
+
export interface SlotSizeCheck {
|
|
36
|
+
readonly slotFrame: FrameNode;
|
|
37
|
+
readonly content: FigmaTreeNode;
|
|
38
|
+
/** The axes the check skips: the slot frame stretches with its parent, the instance is resized, or an override makes it hug. */
|
|
39
|
+
readonly skip: {
|
|
40
|
+
readonly width: boolean;
|
|
41
|
+
readonly height: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** The size an override of the instance gives the slot frame, on the axes it sets. */
|
|
44
|
+
readonly size?: {
|
|
45
|
+
readonly width?: number;
|
|
46
|
+
readonly height?: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The reason to report when a slot's content frame is a size the slot
|
|
51
|
+
* frame will not take: the content's size is not imported, so on an axis
|
|
52
|
+
* where the slot frame keeps its size (its own, or an override's), a
|
|
53
|
+
* difference over 1 px shows. An axis whose size layout or constraints
|
|
54
|
+
* decide (`skip`, Fill, Hug) is not checked.
|
|
55
|
+
*/
|
|
56
|
+
export declare function slotSizeMismatch({ slotFrame, content, skip, size: sized }: SlotSizeCheck): string | undefined;
|