@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,505 @@
|
|
|
1
|
+
import { parentMapOf } from "./parent-table.js";
|
|
2
|
+
import { LAYER_PATH_SEPARATOR, ownedChildIds, } from "./types.js";
|
|
3
|
+
import { entryOf } from "./id-table.js";
|
|
4
|
+
import { derivedIndexStats, isFrozenNodeMap, nearestDerivationBase } from "./derivations.js";
|
|
5
|
+
import { tableValues } from "./shared-node-table.js";
|
|
6
|
+
/** True when `id` names a layer inside an instance rather than a stored node. */
|
|
7
|
+
export const isVirtualNodeId = (id) => id.includes(LAYER_PATH_SEPARATOR);
|
|
8
|
+
/**
|
|
9
|
+
* Splits a virtual node ID `<instance id>;<layer path>` into its instance and
|
|
10
|
+
* layer path. Returns `null` for a stored node ID (no separator) and for a
|
|
11
|
+
* malformed ID with an empty segment. This is the only place that splits
|
|
12
|
+
* virtual IDs.
|
|
13
|
+
* @since 0.23.0
|
|
14
|
+
*/
|
|
15
|
+
export function parseVirtualNodeId(id) {
|
|
16
|
+
if (!isVirtualNodeId(id))
|
|
17
|
+
return null;
|
|
18
|
+
const segments = id.split(LAYER_PATH_SEPARATOR);
|
|
19
|
+
if (segments.length < 2 || segments.some((segment) => segment.length === 0))
|
|
20
|
+
return null;
|
|
21
|
+
const [instanceId, ...path] = segments;
|
|
22
|
+
return { instanceId: instanceId, path };
|
|
23
|
+
}
|
|
24
|
+
/** Builds the virtual node ID of the layer at `path` inside `instanceId`. */
|
|
25
|
+
export function virtualNodeId(instanceId, path) {
|
|
26
|
+
if (path.length === 0)
|
|
27
|
+
throw new TypeError("A virtual node ID needs a non-empty layer path");
|
|
28
|
+
return [instanceId, ...path].join(LAYER_PATH_SEPARATOR);
|
|
29
|
+
}
|
|
30
|
+
/** The key of `InstanceNode.overrides` for the layer at `path`. */
|
|
31
|
+
export function layerPathKey(path) {
|
|
32
|
+
return path.join(LAYER_PATH_SEPARATOR);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Splits an override key into its component node IDs, or returns `null` when
|
|
36
|
+
* the key is malformed (empty, or with an empty segment). Whether the named
|
|
37
|
+
* nodes still exist is not checked: such a key is allowed and has no effect.
|
|
38
|
+
* @since 0.23.0
|
|
39
|
+
*/
|
|
40
|
+
export function parseLayerPath(key) {
|
|
41
|
+
if (key.length === 0)
|
|
42
|
+
return null;
|
|
43
|
+
const segments = key.split(LAYER_PATH_SEPARATOR);
|
|
44
|
+
if (segments.some((segment) => segment.length === 0))
|
|
45
|
+
return null;
|
|
46
|
+
return segments;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The stored node an ID refers to: the instance for a virtual ID, the ID
|
|
50
|
+
* itself otherwise. Selection code uses it to find the node that moves,
|
|
51
|
+
* deletes or reorders when a layer inside an instance is selected.
|
|
52
|
+
*/
|
|
53
|
+
export function storedNodeIdOf(id) {
|
|
54
|
+
return (parseVirtualNodeId(id)?.instanceId ?? id);
|
|
55
|
+
}
|
|
56
|
+
/** The root node IDs of every component, in `components` order. */
|
|
57
|
+
export function componentRootIds(document) {
|
|
58
|
+
return Object.values(document.components ?? {}).map((component) => component.rootId);
|
|
59
|
+
}
|
|
60
|
+
/** The component whose root is `rootId`, if any. */
|
|
61
|
+
export function findComponentByRoot(document, rootId) {
|
|
62
|
+
const components = document.components;
|
|
63
|
+
if (components === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
let byRoot = componentsByRoot.get(components);
|
|
66
|
+
if (byRoot === undefined) {
|
|
67
|
+
// Checked only before indexing: a record of thousands of components is slow to check.
|
|
68
|
+
if (!Object.isFrozen(components)) {
|
|
69
|
+
return Object.values(components).find((component) => component.rootId === rootId);
|
|
70
|
+
}
|
|
71
|
+
byRoot = new Map();
|
|
72
|
+
// The first component with a root wins, as a search in `components` order finds it.
|
|
73
|
+
for (const component of Object.values(components)) {
|
|
74
|
+
if (!byRoot.has(component.rootId))
|
|
75
|
+
byRoot.set(component.rootId, component);
|
|
76
|
+
}
|
|
77
|
+
componentsByRoot.set(components, byRoot);
|
|
78
|
+
}
|
|
79
|
+
return byRoot.get(rootId);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The components of a frozen `components` record by root ID. A frozen record
|
|
83
|
+
* never changes (this package freezes values all the way down), so the index
|
|
84
|
+
* stays valid for as long as the record is alive.
|
|
85
|
+
*/
|
|
86
|
+
const componentsByRoot = new WeakMap();
|
|
87
|
+
/**
|
|
88
|
+
* The component whose layer tree contains the stored node `nodeId` (the root
|
|
89
|
+
* included), or `undefined` when the node is on a page or does not exist.
|
|
90
|
+
* Pass `parents` (from `buildParentMap`) when calling this for many nodes.
|
|
91
|
+
*/
|
|
92
|
+
export function componentOwningNode(document, nodeId, parents = parentMapOf(document.nodes)) {
|
|
93
|
+
if (document.components === undefined || entryOf(document.nodes, nodeId) === undefined)
|
|
94
|
+
return undefined;
|
|
95
|
+
let current = nodeId;
|
|
96
|
+
while (current !== undefined) {
|
|
97
|
+
const parent = parents.get(current);
|
|
98
|
+
if (parent === undefined)
|
|
99
|
+
return findComponentByRoot(document, current);
|
|
100
|
+
current = parent;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
/** True when the stored node is a component layer (its root included) rather than a page node. */
|
|
105
|
+
export function isComponentLayer(document, nodeId) {
|
|
106
|
+
return componentOwningNode(document, nodeId) !== undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The components a node refers to: an instance's `componentId`, and every
|
|
110
|
+
* component its overrides swap a nested instance to, a swap that only some
|
|
111
|
+
* variants make (`LayerOverride.conditional`) included. Empty for other nodes.
|
|
112
|
+
*/
|
|
113
|
+
export function componentReferencesOf(node) {
|
|
114
|
+
if (node.type !== "instance")
|
|
115
|
+
return [];
|
|
116
|
+
const references = new Set([node.componentId]);
|
|
117
|
+
const addSwaps = (override) => {
|
|
118
|
+
if (override.componentId !== undefined)
|
|
119
|
+
references.add(override.componentId);
|
|
120
|
+
for (const entry of override.conditional ?? [])
|
|
121
|
+
addSwaps(entry.value);
|
|
122
|
+
};
|
|
123
|
+
for (const override of Object.values(node.overrides ?? {}))
|
|
124
|
+
addSwaps(override);
|
|
125
|
+
return [...references];
|
|
126
|
+
}
|
|
127
|
+
/** Instances by the component they are of; swaps in overrides do not count. */
|
|
128
|
+
const instancesByComponent = {
|
|
129
|
+
keysOf: (node) => node.type === "instance" ? [node.componentId] : [],
|
|
130
|
+
kept: new WeakMap(),
|
|
131
|
+
};
|
|
132
|
+
/** Instances by every component they show: the one they are of and the ones their overrides swap in (`componentReferencesOf`). */
|
|
133
|
+
const instancesByReference = {
|
|
134
|
+
keysOf: componentReferencesOf,
|
|
135
|
+
kept: new WeakMap(),
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Instances by every component they can show: those of `instancesByReference`, and every string an instance
|
|
139
|
+
* property value of theirs holds, their own or an override's for a nested instance (an instance swap value
|
|
140
|
+
* names a component by its ID). Strings that name no component are listed too and never asked about.
|
|
141
|
+
*/
|
|
142
|
+
const instancesBySwapValue = {
|
|
143
|
+
keysOf: (node) => {
|
|
144
|
+
if (node.type !== "instance")
|
|
145
|
+
return [];
|
|
146
|
+
const keys = new Set(componentReferencesOf(node));
|
|
147
|
+
const add = (values) => {
|
|
148
|
+
for (const value of Object.values(values ?? {}))
|
|
149
|
+
if (typeof value === "string")
|
|
150
|
+
keys.add(value);
|
|
151
|
+
};
|
|
152
|
+
add(node.propertyValues);
|
|
153
|
+
for (const override of Object.values(node.overrides ?? {}))
|
|
154
|
+
add(override.propertyValues);
|
|
155
|
+
return [...keys];
|
|
156
|
+
},
|
|
157
|
+
kept: new WeakMap(),
|
|
158
|
+
};
|
|
159
|
+
function buildInstanceIndex(kind, nodes) {
|
|
160
|
+
derivedIndexStats.instanceIndexWholeDocumentScans += 1;
|
|
161
|
+
const index = new Map();
|
|
162
|
+
for (const node of tableValues(nodes)) {
|
|
163
|
+
for (const componentId of kind.keysOf(node)) {
|
|
164
|
+
const ids = index.get(componentId);
|
|
165
|
+
if (ids === undefined)
|
|
166
|
+
index.set(componentId, [node.id]);
|
|
167
|
+
else
|
|
168
|
+
ids.push(node.id);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const ids of index.values())
|
|
172
|
+
Object.freeze(ids.sort());
|
|
173
|
+
return index;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The index of `document`, made from the index of a document it was derived
|
|
177
|
+
* from (`nearestDerivationBase`) by reading only the nodes written on the
|
|
178
|
+
* way, or undefined when no such document has an index.
|
|
179
|
+
*/
|
|
180
|
+
function derivedInstanceIndex(kind, document) {
|
|
181
|
+
const found = nearestDerivationBase(document, (candidate) => kind.kept.has(candidate.nodes));
|
|
182
|
+
if (found === undefined)
|
|
183
|
+
return undefined;
|
|
184
|
+
const baseIndex = kind.kept.get(found.base.nodes);
|
|
185
|
+
const removed = new Map();
|
|
186
|
+
const added = new Map();
|
|
187
|
+
const seen = new Set();
|
|
188
|
+
for (const list of found.changedNodeIds) {
|
|
189
|
+
for (const id of list) {
|
|
190
|
+
if (seen.has(id))
|
|
191
|
+
continue;
|
|
192
|
+
seen.add(id);
|
|
193
|
+
const before = entryOf(found.base.nodes, id);
|
|
194
|
+
const after = entryOf(document.nodes, id);
|
|
195
|
+
const beforeKeys = before === undefined ? [] : kind.keysOf(before);
|
|
196
|
+
const afterKeys = after === undefined ? [] : kind.keysOf(after);
|
|
197
|
+
for (const componentId of beforeKeys) {
|
|
198
|
+
if (afterKeys.includes(componentId))
|
|
199
|
+
continue;
|
|
200
|
+
const ids = removed.get(componentId) ?? new Set();
|
|
201
|
+
removed.set(componentId, ids.add(id));
|
|
202
|
+
}
|
|
203
|
+
for (const componentId of afterKeys) {
|
|
204
|
+
if (beforeKeys.includes(componentId))
|
|
205
|
+
continue;
|
|
206
|
+
const ids = added.get(componentId);
|
|
207
|
+
if (ids === undefined)
|
|
208
|
+
added.set(componentId, [id]);
|
|
209
|
+
else
|
|
210
|
+
ids.push(id);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (removed.size === 0 && added.size === 0)
|
|
215
|
+
return baseIndex;
|
|
216
|
+
const index = new Map(baseIndex);
|
|
217
|
+
for (const componentId of new Set([...removed.keys(), ...added.keys()])) {
|
|
218
|
+
const gone = removed.get(componentId);
|
|
219
|
+
const ids = (baseIndex.get(componentId) ?? []).filter((id) => gone?.has(id) !== true);
|
|
220
|
+
ids.push(...(added.get(componentId) ?? []));
|
|
221
|
+
if (ids.length === 0)
|
|
222
|
+
index.delete(componentId);
|
|
223
|
+
else
|
|
224
|
+
index.set(componentId, Object.freeze(ids.sort()));
|
|
225
|
+
}
|
|
226
|
+
return index;
|
|
227
|
+
}
|
|
228
|
+
function instanceIndexOf(kind, document) {
|
|
229
|
+
const kept = kind.kept.get(document.nodes);
|
|
230
|
+
if (kept !== undefined)
|
|
231
|
+
return kept;
|
|
232
|
+
// A node map that is not frozen can change after the index is made.
|
|
233
|
+
if (!isFrozenNodeMap(document.nodes))
|
|
234
|
+
return buildInstanceIndex(kind, document.nodes);
|
|
235
|
+
const index = derivedInstanceIndex(kind, document) ?? buildInstanceIndex(kind, document.nodes);
|
|
236
|
+
kind.kept.set(document.nodes, index);
|
|
237
|
+
return index;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The stored instance nodes of `componentId`, by ID, sorted. Swaps in
|
|
241
|
+
* overrides do not count. A frozen document made by edits from one already
|
|
242
|
+
* asked about reads only the nodes the edits wrote, not the whole document.
|
|
243
|
+
*/
|
|
244
|
+
export function instancesOfComponent(document, componentId) {
|
|
245
|
+
return instanceIndexOf(instancesByComponent, document).get(componentId) ?? [];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The stored instance nodes that show `componentId`, by ID, sorted: its
|
|
249
|
+
* instances and the instances whose overrides swap it in
|
|
250
|
+
* (`componentReferencesOf`). Like `instancesOfComponent`, a frozen document
|
|
251
|
+
* made by edits from one already asked about reads only the nodes the edits
|
|
252
|
+
* wrote.
|
|
253
|
+
* @since 0.33.0
|
|
254
|
+
*/
|
|
255
|
+
export function instancesReferencingComponent(document, componentId) {
|
|
256
|
+
return instanceIndexOf(instancesByReference, document).get(componentId) ?? [];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The stored instance nodes that can show `componentId`, by ID, sorted: those
|
|
260
|
+
* `instancesReferencingComponent` gives, and those whose own property values,
|
|
261
|
+
* or an override's for a nested instance, name it (an instance swap value).
|
|
262
|
+
* Like `instancesOfComponent`, a frozen document made by edits from one
|
|
263
|
+
* already asked about reads only the nodes the edits wrote. A component that
|
|
264
|
+
* shows `componentId` through an instance property's default is not among
|
|
265
|
+
* them: see `componentsSwappingInByDefault`.
|
|
266
|
+
*/
|
|
267
|
+
export function instancesShowingComponent(document, componentId) {
|
|
268
|
+
return instanceIndexOf(instancesBySwapValue, document).get(componentId) ?? [];
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The components with an instance property whose default is `componentId`:
|
|
272
|
+
* each of their instances that keeps the default shows it. Reads the
|
|
273
|
+
* component definitions once per components record, not their layers.
|
|
274
|
+
*/
|
|
275
|
+
export function componentsSwappingInByDefault(document, componentId) {
|
|
276
|
+
const components = document.components;
|
|
277
|
+
if (components === undefined)
|
|
278
|
+
return [];
|
|
279
|
+
let byDefault = swapDefaults.get(components);
|
|
280
|
+
if (byDefault === undefined) {
|
|
281
|
+
byDefault = new Map();
|
|
282
|
+
for (const component of Object.values(components)) {
|
|
283
|
+
// Read once per definition: a new components record keeps most of them.
|
|
284
|
+
let defaults = swapDefaultsOf.get(component);
|
|
285
|
+
if (defaults === undefined) {
|
|
286
|
+
defaults = (component.properties ?? []).flatMap((property) => property.kind === "instance" ? [property.defaultValue] : []);
|
|
287
|
+
swapDefaultsOf.set(component, defaults);
|
|
288
|
+
}
|
|
289
|
+
for (const id of defaults) {
|
|
290
|
+
const set = byDefault.get(id);
|
|
291
|
+
if (set === undefined)
|
|
292
|
+
byDefault.set(id, new Set([component.id]));
|
|
293
|
+
else
|
|
294
|
+
set.add(component.id);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
swapDefaults.set(components, byDefault);
|
|
298
|
+
}
|
|
299
|
+
const found = byDefault.get(componentId);
|
|
300
|
+
return found === undefined ? [] : [...found];
|
|
301
|
+
}
|
|
302
|
+
/** Per components record, the components whose instance properties default to each component. */
|
|
303
|
+
const swapDefaults = new WeakMap();
|
|
304
|
+
/** Per component definition, the defaults of its instance properties. */
|
|
305
|
+
const swapDefaultsOf = new WeakMap();
|
|
306
|
+
/**
|
|
307
|
+
* How many times `componentNestingGraph` has walked every component's tree,
|
|
308
|
+
* for tests that check a list or a check builds the graph at most once.
|
|
309
|
+
* @since 0.37.0
|
|
310
|
+
*/
|
|
311
|
+
export const componentNestingStats = { builds: 0 };
|
|
312
|
+
/** Builds the `ComponentNestingGraph` of a document. Missing component references are kept as edges. */
|
|
313
|
+
export function componentNestingGraph(document) {
|
|
314
|
+
componentNestingStats.builds += 1;
|
|
315
|
+
const nests = new Map();
|
|
316
|
+
const nestedBy = new Map();
|
|
317
|
+
const components = Object.values(document.components ?? {});
|
|
318
|
+
for (const component of components) {
|
|
319
|
+
nests.set(component.id, new Set());
|
|
320
|
+
nestedBy.set(component.id, new Set());
|
|
321
|
+
}
|
|
322
|
+
const addEdge = (from, to) => {
|
|
323
|
+
nests.get(from)?.add(to);
|
|
324
|
+
let reverse = nestedBy.get(to);
|
|
325
|
+
if (reverse === undefined) {
|
|
326
|
+
reverse = new Set();
|
|
327
|
+
nestedBy.set(to, reverse);
|
|
328
|
+
}
|
|
329
|
+
reverse.add(from);
|
|
330
|
+
};
|
|
331
|
+
for (const component of components) {
|
|
332
|
+
const pending = [component.rootId];
|
|
333
|
+
const seen = new Set();
|
|
334
|
+
while (pending.length > 0) {
|
|
335
|
+
const id = pending.pop();
|
|
336
|
+
if (seen.has(id))
|
|
337
|
+
continue;
|
|
338
|
+
seen.add(id);
|
|
339
|
+
const node = entryOf(document.nodes, id);
|
|
340
|
+
if (node === undefined)
|
|
341
|
+
continue;
|
|
342
|
+
componentReferencesOf(node).forEach((reference) => addEdge(component.id, reference));
|
|
343
|
+
pending.push(...ownedChildIds(node));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return { nests, nestedBy };
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Finds a cycle in the nesting graph: a list of component IDs where each
|
|
350
|
+
* nests the next and the last equals the first. Returns `null` when the
|
|
351
|
+
* graph has no cycle.
|
|
352
|
+
* @since 0.23.0
|
|
353
|
+
*/
|
|
354
|
+
export function findComponentCycle(graph) {
|
|
355
|
+
const state = new Map();
|
|
356
|
+
const stack = [];
|
|
357
|
+
const visit = (id) => {
|
|
358
|
+
const known = state.get(id);
|
|
359
|
+
if (known === "active") {
|
|
360
|
+
const start = stack.indexOf(id);
|
|
361
|
+
return [...stack.slice(start), id];
|
|
362
|
+
}
|
|
363
|
+
if (known === "done")
|
|
364
|
+
return null;
|
|
365
|
+
state.set(id, "active");
|
|
366
|
+
stack.push(id);
|
|
367
|
+
for (const next of graph.nests.get(id) ?? []) {
|
|
368
|
+
const cycle = visit(next);
|
|
369
|
+
if (cycle !== null)
|
|
370
|
+
return cycle;
|
|
371
|
+
}
|
|
372
|
+
stack.pop();
|
|
373
|
+
state.set(id, "done");
|
|
374
|
+
return null;
|
|
375
|
+
};
|
|
376
|
+
for (const id of [...graph.nests.keys()].sort()) {
|
|
377
|
+
const cycle = visit(id);
|
|
378
|
+
if (cycle !== null)
|
|
379
|
+
return cycle;
|
|
380
|
+
}
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
const closure = (edges, start) => {
|
|
384
|
+
const result = new Set();
|
|
385
|
+
const pending = [...(edges.get(start) ?? [])];
|
|
386
|
+
while (pending.length > 0) {
|
|
387
|
+
const id = pending.pop();
|
|
388
|
+
if (result.has(id))
|
|
389
|
+
continue;
|
|
390
|
+
result.add(id);
|
|
391
|
+
pending.push(...(edges.get(id) ?? []));
|
|
392
|
+
}
|
|
393
|
+
return result;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Every component whose tree contains `componentId`, directly or through
|
|
397
|
+
* nesting. A change to `componentId` also changes the instances of these.
|
|
398
|
+
*/
|
|
399
|
+
export function componentsNesting(graph, componentId) {
|
|
400
|
+
return closure(graph.nestedBy, componentId);
|
|
401
|
+
}
|
|
402
|
+
/** Every component that `componentId`'s tree contains, directly or through nesting. */
|
|
403
|
+
export function componentsNestedIn(graph, componentId) {
|
|
404
|
+
return closure(graph.nests, componentId);
|
|
405
|
+
}
|
|
406
|
+
const nestingGraphs = new WeakMap();
|
|
407
|
+
/** Per working view, the document whose component trees it shares (`shareComponentTrees`). */
|
|
408
|
+
const sameComponentTrees = new WeakMap();
|
|
409
|
+
/**
|
|
410
|
+
* Notes that `view`, a working view whose node record is written in place,
|
|
411
|
+
* holds the same components and component layers as `document` for as long
|
|
412
|
+
* as it is read: `nestingGraphOf(view)` is then the graph of `document`,
|
|
413
|
+
* not one built again from a record that is not frozen.
|
|
414
|
+
*/
|
|
415
|
+
export function shareComponentTrees(view, document) {
|
|
416
|
+
sameComponentTrees.set(view, document);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* The `ComponentNestingGraph` of `document`, built once per document object,
|
|
420
|
+
* or kept from a document it was made from when no component tree changed
|
|
421
|
+
* on the way (`derivedNestingGraph`). Callers
|
|
422
|
+
* must not change the returned graph.
|
|
423
|
+
* @since 0.37.0
|
|
424
|
+
*/
|
|
425
|
+
export function nestingGraphOf(document) {
|
|
426
|
+
const same = sameComponentTrees.get(document);
|
|
427
|
+
if (same !== undefined)
|
|
428
|
+
return nestingGraphOf(same);
|
|
429
|
+
let graph = nestingGraphs.get(document) ?? derivedNestingGraph(document);
|
|
430
|
+
if (graph === undefined)
|
|
431
|
+
graph = componentNestingGraph(document);
|
|
432
|
+
nestingGraphs.set(document, graph);
|
|
433
|
+
return graph;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* The graph of a document `document` was made from (`nearestDerivationBase`)
|
|
437
|
+
* with the same component roots, when every node written on the way is on a
|
|
438
|
+
* page in both, or is a component layer that stays in its component, names
|
|
439
|
+
* the same components (`componentReferencesOf`) and keeps its children: the
|
|
440
|
+
* graph is read from the component trees alone, so a property value set on a
|
|
441
|
+
* page instance, a value set on a nested instance in a component and a new
|
|
442
|
+
* property default keep it. Undefined when a written node changes a
|
|
443
|
+
* component tree, or no such document has a graph.
|
|
444
|
+
*/
|
|
445
|
+
function derivedNestingGraph(document) {
|
|
446
|
+
if (!isFrozenNodeMap(document.nodes))
|
|
447
|
+
return undefined;
|
|
448
|
+
const found = nearestDerivationBase(document, (candidate) => nestingGraphs.has(candidate) && sameComponentRoots(candidate.components, document.components));
|
|
449
|
+
if (found === undefined)
|
|
450
|
+
return undefined;
|
|
451
|
+
const { base } = found;
|
|
452
|
+
for (const list of found.changedNodeIds) {
|
|
453
|
+
for (const id of list) {
|
|
454
|
+
const now = entryOf(document.nodes, id);
|
|
455
|
+
const before = entryOf(base.nodes, id);
|
|
456
|
+
if (now === before)
|
|
457
|
+
continue;
|
|
458
|
+
// A layer not in either tree (being moved, say) is not known to be on a page.
|
|
459
|
+
if (now === undefined && before === undefined)
|
|
460
|
+
return undefined;
|
|
461
|
+
const ownerNow = now === undefined ? undefined : componentOwningNode(document, id);
|
|
462
|
+
const ownerBefore = before === undefined ? undefined : componentOwningNode(base, id);
|
|
463
|
+
if (ownerNow === undefined && ownerBefore === undefined)
|
|
464
|
+
continue;
|
|
465
|
+
if (now === undefined || before === undefined || ownerNow?.id !== ownerBefore?.id)
|
|
466
|
+
return undefined;
|
|
467
|
+
if (!sameIdList(componentReferencesOf(now), componentReferencesOf(before)))
|
|
468
|
+
return undefined;
|
|
469
|
+
if (!sameIdList(ownedChildIds(now), ownedChildIds(before)))
|
|
470
|
+
return undefined;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return nestingGraphs.get(base);
|
|
474
|
+
}
|
|
475
|
+
/** Whether two component records hold the same component IDs with the same roots, which is all the nesting graph reads of them. */
|
|
476
|
+
function sameComponentRoots(left, right) {
|
|
477
|
+
if (left === right)
|
|
478
|
+
return true;
|
|
479
|
+
if (left === undefined || right === undefined)
|
|
480
|
+
return false;
|
|
481
|
+
const ids = Object.keys(right);
|
|
482
|
+
if (Object.keys(left).length !== ids.length)
|
|
483
|
+
return false;
|
|
484
|
+
return ids.every((id) => entryOf(left, id)?.rootId === entryOf(right, id)?.rootId);
|
|
485
|
+
}
|
|
486
|
+
function sameIdList(left, right) {
|
|
487
|
+
return left.length === right.length && left.every((id, index) => right[index] === id);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Reports whether placing an instance of `placedId` inside `hostId`'s tree,
|
|
491
|
+
* or swapping a nested instance there to `placedId`, would make a component
|
|
492
|
+
* contain itself. The editor disables such choices; `assertDocument` rejects
|
|
493
|
+
* the result.
|
|
494
|
+
* @since 0.23.0
|
|
495
|
+
*/
|
|
496
|
+
export function wouldNestCycle(document, hostId, placedId) {
|
|
497
|
+
if (hostId === placedId)
|
|
498
|
+
return true;
|
|
499
|
+
return componentsNestedIn(nestingGraphOf(document), placedId).has(hostId);
|
|
500
|
+
}
|
|
501
|
+
/** The node an instance ID names, checked to be an `InstanceNode`. */
|
|
502
|
+
export function instanceNodeOf(document, instanceId) {
|
|
503
|
+
const node = entryOf(document.nodes, instanceId);
|
|
504
|
+
return node?.type === "instance" ? node : undefined;
|
|
505
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DesignDocument, NodeId, SceneNode } from "./types.ts";
|
|
2
|
+
/** Counts of the work done here, for tests that check what an edit costs. */
|
|
3
|
+
export declare const connectorEndStats: {
|
|
4
|
+
/** Indexes built by reading every node of a document. */
|
|
5
|
+
wholeDocumentScans: number;
|
|
6
|
+
};
|
|
7
|
+
/** The layers `node` has a connector end attached to, or null when it is not an attached connector. */
|
|
8
|
+
export declare function connectorTargets(node: SceneNode | undefined): readonly NodeId[] | null;
|
|
9
|
+
/**
|
|
10
|
+
* The IDs of the connectors in `document` with an end attached to one of
|
|
11
|
+
* `targetIds`. A frozen document keeps an index for this, so after the first
|
|
12
|
+
* question the answer costs in proportion to the connectors found and the
|
|
13
|
+
* nodes each edit since wrote, not to the document.
|
|
14
|
+
*/
|
|
15
|
+
export declare function connectorsAttachedTo(document: DesignDocument, targetIds: Iterable<NodeId>): ReadonlySet<NodeId>;
|
|
16
|
+
/**
|
|
17
|
+
* Keeps the index of `derived`, made by an edit of `base`, when `base` has
|
|
18
|
+
* one: so a run of edits keeps it, reading only the nodes each edit wrote.
|
|
19
|
+
*/
|
|
20
|
+
export declare function keepConnectorEnds(base: DesignDocument, derived: DesignDocument): void;
|