@moondraft/import 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/LICENSE +34 -0
- package/README.md +36 -2
- package/SOURCE.md +394 -0
- package/dist/adapter/convert.d.ts +144 -0
- package/dist/adapter/convert.js +2811 -0
- package/dist/adapter/figma-descriptions.d.ts +7 -0
- package/dist/adapter/figma-descriptions.js +34 -0
- package/dist/adapter/figma-grids.d.ts +12 -0
- package/dist/adapter/figma-grids.js +175 -0
- package/dist/adapter/figma-handoff.d.ts +12 -0
- package/dist/adapter/figma-handoff.js +167 -0
- package/dist/adapter/figma-hyperlinks.d.ts +13 -0
- package/dist/adapter/figma-hyperlinks.js +77 -0
- package/dist/adapter/figma.d.ts +12 -0
- package/dist/adapter/figma.js +40 -0
- package/dist/adapter/file-components.d.ts +20 -0
- package/dist/adapter/file-components.js +352 -0
- package/dist/adapter/file-resources.d.ts +29 -0
- package/dist/adapter/file-resources.js +851 -0
- package/dist/adapter/image-crop.d.ts +18 -0
- package/dist/adapter/image-crop.js +30 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.js +9 -0
- package/dist/adapter/link.d.ts +49 -0
- package/dist/adapter/link.js +892 -0
- package/dist/adapter/payload.d.ts +31 -0
- package/dist/adapter/payload.js +78 -0
- package/dist/adapter/shapes.d.ts +31 -0
- package/dist/adapter/shapes.js +75 -0
- package/dist/adapter/variables.d.ts +45 -0
- package/dist/adapter/variables.js +106 -0
- package/dist/figma-file.d.ts +38 -0
- package/dist/figma-file.js +97 -0
- package/dist/figma-worker.d.ts +11 -0
- package/dist/figma-worker.js +12 -0
- package/dist/figma.d.ts +26 -0
- package/dist/figma.js +230 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +50 -0
- package/dist/report.d.ts +42 -0
- package/dist/report.js +142 -0
- package/dist/serialize.d.ts +7 -0
- package/dist/serialize.js +79 -0
- package/dist/svg.d.ts +33 -0
- package/dist/svg.js +44 -0
- package/dist/syntax.d.ts +8 -0
- package/dist/syntax.js +19 -0
- package/dist/taco/figma-import/clipboard.d.ts +25 -0
- package/dist/taco/figma-import/clipboard.js +87 -0
- package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
- package/dist/taco/figma-import/clipboardSize.js +107 -0
- package/dist/taco/figma-import/container/compression.d.ts +9 -0
- package/dist/taco/figma-import/container/compression.js +174 -0
- package/dist/taco/figma-import/container/error.d.ts +15 -0
- package/dist/taco/figma-import/container/error.js +19 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
- package/dist/taco/figma-import/container/limits.d.ts +22 -0
- package/dist/taco/figma-import/container/limits.js +22 -0
- package/dist/taco/figma-import/container/zip.d.ts +14 -0
- package/dist/taco/figma-import/container/zip.js +154 -0
- package/dist/taco/figma-import/figFile.d.ts +34 -0
- package/dist/taco/figma-import/figFile.js +91 -0
- package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
- package/dist/taco/figma-import/figFileDocument.js +100 -0
- package/dist/taco/figma-import/import/blobs.d.ts +10 -0
- package/dist/taco/figma-import/import/blobs.js +23 -0
- package/dist/taco/figma-import/import/carry.d.ts +24 -0
- package/dist/taco/figma-import/import/carry.js +66 -0
- package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
- package/dist/taco/figma-import/import/componentProps.js +329 -0
- package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
- package/dist/taco/figma-import/import/componentSets.js +647 -0
- package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
- package/dist/taco/figma-import/import/converters/effects.js +127 -0
- package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
- package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
- package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
- package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/frame.js +63 -0
- package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
- package/dist/taco/figma-import/import/converters/gradient.js +108 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
- package/dist/taco/figma-import/import/converters/group.js +30 -0
- package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
- package/dist/taco/figma-import/import/converters/image.js +94 -0
- package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
- package/dist/taco/figma-import/import/converters/layout.js +187 -0
- package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
- package/dist/taco/figma-import/import/converters/line.js +40 -0
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
- package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
- package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
- package/dist/taco/figma-import/import/converters/section.js +29 -0
- package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
- package/dist/taco/figma-import/import/converters/shared.js +372 -0
- package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
- package/dist/taco/figma-import/import/converters/text.js +707 -0
- package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
- package/dist/taco/figma-import/import/converters/vector.js +609 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
- package/dist/taco/figma-import/import/fields.d.ts +15 -0
- package/dist/taco/figma-import/import/fields.js +29 -0
- package/dist/taco/figma-import/import/instances.d.ts +184 -0
- package/dist/taco/figma-import/import/instances.js +1530 -0
- package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
- package/dist/taco/figma-import/import/nestingCycles.js +488 -0
- package/dist/taco/figma-import/import/slots.d.ts +56 -0
- package/dist/taco/figma-import/import/slots.js +96 -0
- package/dist/taco/figma-import/import/styles.d.ts +48 -0
- package/dist/taco/figma-import/import/styles.js +48 -0
- package/dist/taco/figma-import/import/tree.d.ts +66 -0
- package/dist/taco/figma-import/import/tree.js +194 -0
- package/dist/taco/figma-import/import/types.d.ts +232 -0
- package/dist/taco/figma-import/import/types.js +33 -0
- package/dist/taco/figma-import/import/variables.d.ts +137 -0
- package/dist/taco/figma-import/import/variables.js +769 -0
- package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
- package/dist/taco/figma-import/import/variantTrees.js +520 -0
- package/dist/taco/figma-import/import/walk.d.ts +207 -0
- package/dist/taco/figma-import/import/walk.js +1464 -0
- package/dist/taco/figma-import/index.d.ts +22 -0
- package/dist/taco/figma-import/index.js +13 -0
- package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
- package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
- package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
- package/dist/taco/figma-import/kiwi/error.js +29 -0
- package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
- package/dist/taco/figma-import/kiwi/limits.js +18 -0
- package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
- package/dist/taco/figma-import/kiwi/message.js +147 -0
- package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
- package/dist/taco/figma-import/kiwi/schema.js +206 -0
- package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
- package/dist/taco/figma-import/kiwi/types.js +18 -0
- package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
- package/dist/taco/model/agent-hidden-fields.js +29 -0
- package/dist/taco/model/asset-users.d.ts +23 -0
- package/dist/taco/model/asset-users.js +128 -0
- package/dist/taco/model/auto-layout-lines.d.ts +32 -0
- package/dist/taco/model/auto-layout-lines.js +70 -0
- package/dist/taco/model/codec.d.ts +444 -0
- package/dist/taco/model/codec.js +5665 -0
- package/dist/taco/model/color.d.ts +11 -0
- package/dist/taco/model/color.js +61 -0
- package/dist/taco/model/comment-operations.d.ts +102 -0
- package/dist/taco/model/comment-operations.js +227 -0
- package/dist/taco/model/component-evaluation.d.ts +96 -0
- package/dist/taco/model/component-evaluation.js +555 -0
- package/dist/taco/model/component-expressions.d.ts +242 -0
- package/dist/taco/model/component-expressions.js +1082 -0
- package/dist/taco/model/component-properties.d.ts +111 -0
- package/dist/taco/model/component-properties.js +339 -0
- package/dist/taco/model/component-samples.d.ts +83 -0
- package/dist/taco/model/component-samples.js +290 -0
- package/dist/taco/model/component-validity.d.ts +85 -0
- package/dist/taco/model/component-validity.js +397 -0
- package/dist/taco/model/components.d.ts +155 -0
- package/dist/taco/model/components.js +505 -0
- package/dist/taco/model/connector-ends.d.ts +20 -0
- package/dist/taco/model/connector-ends.js +188 -0
- package/dist/taco/model/connector-geometry.d.ts +74 -0
- package/dist/taco/model/connector-geometry.js +293 -0
- package/dist/taco/model/corner-radii.d.ts +26 -0
- package/dist/taco/model/corner-radii.js +47 -0
- package/dist/taco/model/derivations.d.ts +81 -0
- package/dist/taco/model/derivations.js +151 -0
- package/dist/taco/model/export-settings.d.ts +53 -0
- package/dist/taco/model/export-settings.js +156 -0
- package/dist/taco/model/expressions/ast.d.ts +153 -0
- package/dist/taco/model/expressions/ast.js +6 -0
- package/dist/taco/model/expressions/cache.d.ts +23 -0
- package/dist/taco/model/expressions/cache.js +43 -0
- package/dist/taco/model/expressions/check.d.ts +72 -0
- package/dist/taco/model/expressions/check.js +517 -0
- package/dist/taco/model/expressions/completion.d.ts +61 -0
- package/dist/taco/model/expressions/completion.js +421 -0
- package/dist/taco/model/expressions/evaluate.d.ts +32 -0
- package/dist/taco/model/expressions/evaluate.js +519 -0
- package/dist/taco/model/expressions/forms.d.ts +84 -0
- package/dist/taco/model/expressions/forms.js +200 -0
- package/dist/taco/model/expressions/index.d.ts +14 -0
- package/dist/taco/model/expressions/index.js +17 -0
- package/dist/taco/model/expressions/lexer.d.ts +42 -0
- package/dist/taco/model/expressions/lexer.js +213 -0
- package/dist/taco/model/expressions/library.d.ts +33 -0
- package/dist/taco/model/expressions/library.js +117 -0
- package/dist/taco/model/expressions/names.d.ts +43 -0
- package/dist/taco/model/expressions/names.js +99 -0
- package/dist/taco/model/expressions/parser.d.ts +15 -0
- package/dist/taco/model/expressions/parser.js +438 -0
- package/dist/taco/model/expressions/rename.d.ts +34 -0
- package/dist/taco/model/expressions/rename.js +46 -0
- package/dist/taco/model/expressions/source.d.ts +15 -0
- package/dist/taco/model/expressions/source.js +161 -0
- package/dist/taco/model/expressions/types.d.ts +119 -0
- package/dist/taco/model/expressions/types.js +102 -0
- package/dist/taco/model/expressions/values.d.ts +97 -0
- package/dist/taco/model/expressions/values.js +160 -0
- package/dist/taco/model/geometry-limits.d.ts +16 -0
- package/dist/taco/model/geometry-limits.js +67 -0
- package/dist/taco/model/geometry.d.ts +47 -0
- package/dist/taco/model/geometry.js +193 -0
- package/dist/taco/model/group-bounds.d.ts +38 -0
- package/dist/taco/model/group-bounds.js +144 -0
- package/dist/taco/model/id-table.d.ts +37 -0
- package/dist/taco/model/id-table.js +80 -0
- package/dist/taco/model/index.d.ts +25 -0
- package/dist/taco/model/index.js +27 -0
- package/dist/taco/model/instance-resolver.d.ts +376 -0
- package/dist/taco/model/instance-resolver.js +1778 -0
- package/dist/taco/model/layer-syntax.d.ts +340 -0
- package/dist/taco/model/layer-syntax.js +3506 -0
- package/dist/taco/model/layout/constraints.d.ts +84 -0
- package/dist/taco/model/layout/constraints.js +445 -0
- package/dist/taco/model/layout/frame-layout.d.ts +46 -0
- package/dist/taco/model/layout/frame-layout.js +618 -0
- package/dist/taco/model/layout/node-sizing.d.ts +163 -0
- package/dist/taco/model/layout/node-sizing.js +486 -0
- package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
- package/dist/taco/model/legacy-connector-caps.js +70 -0
- package/dist/taco/model/linear-call.d.ts +48 -0
- package/dist/taco/model/linear-call.js +58 -0
- package/dist/taco/model/new-nodes.d.ts +145 -0
- package/dist/taco/model/new-nodes.js +277 -0
- package/dist/taco/model/node-builder.d.ts +449 -0
- package/dist/taco/model/node-builder.js +2294 -0
- package/dist/taco/model/node-table-watch.d.ts +36 -0
- package/dist/taco/model/node-table-watch.js +63 -0
- package/dist/taco/model/node-transform.d.ts +39 -0
- package/dist/taco/model/node-transform.js +79 -0
- package/dist/taco/model/node-users-index.d.ts +10 -0
- package/dist/taco/model/node-users-index.js +82 -0
- package/dist/taco/model/operation-references.d.ts +80 -0
- package/dist/taco/model/operation-references.js +399 -0
- package/dist/taco/model/operations.d.ts +610 -0
- package/dist/taco/model/operations.js +2882 -0
- package/dist/taco/model/overlay-table.d.ts +71 -0
- package/dist/taco/model/overlay-table.js +171 -0
- package/dist/taco/model/override-remap.d.ts +69 -0
- package/dist/taco/model/override-remap.js +230 -0
- package/dist/taco/model/parent-table.d.ts +53 -0
- package/dist/taco/model/parent-table.js +193 -0
- package/dist/taco/model/problem-collector.d.ts +27 -0
- package/dist/taco/model/problem-collector.js +101 -0
- package/dist/taco/model/sha256.d.ts +10 -0
- package/dist/taco/model/sha256.js +79 -0
- package/dist/taco/model/shape-geometry.d.ts +96 -0
- package/dist/taco/model/shape-geometry.js +368 -0
- package/dist/taco/model/shared-node-table.d.ts +97 -0
- package/dist/taco/model/shared-node-table.js +546 -0
- package/dist/taco/model/slots.d.ts +113 -0
- package/dist/taco/model/slots.js +281 -0
- package/dist/taco/model/stroke-settings.d.ts +37 -0
- package/dist/taco/model/stroke-settings.js +90 -0
- package/dist/taco/model/svg-path-import.d.ts +89 -0
- package/dist/taco/model/svg-path-import.js +219 -0
- package/dist/taco/model/text-measurement.d.ts +142 -0
- package/dist/taco/model/text-measurement.js +846 -0
- package/dist/taco/model/text-reads.d.ts +66 -0
- package/dist/taco/model/text-reads.js +128 -0
- package/dist/taco/model/text-sizer.d.ts +358 -0
- package/dist/taco/model/text-sizer.js +996 -0
- package/dist/taco/model/theme-users.d.ts +59 -0
- package/dist/taco/model/theme-users.js +312 -0
- package/dist/taco/model/thumbnail.d.ts +15 -0
- package/dist/taco/model/thumbnail.js +34 -0
- package/dist/taco/model/types.d.ts +2369 -0
- package/dist/taco/model/types.js +366 -0
- package/dist/taco/model/unknown-property.d.ts +5 -0
- package/dist/taco/model/unknown-property.js +7 -0
- package/dist/taco/model/validated-documents.d.ts +22 -0
- package/dist/taco/model/validated-documents.js +22 -0
- package/dist/taco/model/variable-modes.d.ts +61 -0
- package/dist/taco/model/variable-modes.js +438 -0
- package/dist/taco/model/variable-references.d.ts +54 -0
- package/dist/taco/model/variable-references.js +183 -0
- package/dist/taco/model/variables.d.ts +24 -0
- package/dist/taco/model/variables.js +151 -0
- package/dist/taco/model/vector-network.d.ts +34 -0
- package/dist/taco/model/vector-network.js +411 -0
- package/dist/taco/svg-import/import-svg.d.ts +36 -0
- package/dist/taco/svg-import/import-svg.js +729 -0
- package/dist/taco/svg-import/index.d.ts +3 -0
- package/dist/taco/svg-import/index.js +3 -0
- package/dist/taco/svg-import/limits/limits.d.ts +79 -0
- package/dist/taco/svg-import/limits/limits.js +160 -0
- package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
- package/dist/taco/svg-import/paint/gradients.js +429 -0
- package/dist/taco/svg-import/paint/paint.d.ts +32 -0
- package/dist/taco/svg-import/paint/paint.js +162 -0
- package/dist/taco/svg-import/paths/paths.d.ts +58 -0
- package/dist/taco/svg-import/paths/paths.js +205 -0
- package/dist/taco/svg-import/public-types.d.ts +279 -0
- package/dist/taco/svg-import/public-types.js +56 -0
- package/dist/taco/svg-import/report/report.d.ts +44 -0
- package/dist/taco/svg-import/report/report.js +79 -0
- package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
- package/dist/taco/svg-import/reuse/reuse.js +840 -0
- package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
- package/dist/taco/svg-import/shapes/shapes.js +386 -0
- package/dist/taco/svg-import/structure/effects.d.ts +26 -0
- package/dist/taco/svg-import/structure/effects.js +618 -0
- package/dist/taco/svg-import/structure/image.d.ts +24 -0
- package/dist/taco/svg-import/structure/image.js +495 -0
- package/dist/taco/svg-import/structure/walk.d.ts +85 -0
- package/dist/taco/svg-import/structure/walk.js +544 -0
- package/dist/taco/svg-import/style/color.d.ts +40 -0
- package/dist/taco/svg-import/style/color.js +275 -0
- package/dist/taco/svg-import/style/computed.d.ts +214 -0
- package/dist/taco/svg-import/style/computed.js +1534 -0
- package/dist/taco/svg-import/style/css.d.ts +127 -0
- package/dist/taco/svg-import/style/css.js +541 -0
- package/dist/taco/svg-import/style/media.d.ts +25 -0
- package/dist/taco/svg-import/style/media.js +307 -0
- package/dist/taco/svg-import/style/properties.d.ts +43 -0
- package/dist/taco/svg-import/style/properties.js +135 -0
- package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
- package/dist/taco/svg-import/style/selector-reach.js +169 -0
- package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
- package/dist/taco/svg-import/style/selector-validity.js +307 -0
- package/dist/taco/svg-import/text/text.d.ts +29 -0
- package/dist/taco/svg-import/text/text.js +545 -0
- package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
- package/dist/taco/svg-import/transform/matrix.js +229 -0
- package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
- package/dist/taco/svg-import/tree/element-data.js +155 -0
- package/dist/taco/svg-import/tree/elements.d.ts +36 -0
- package/dist/taco/svg-import/tree/elements.js +121 -0
- package/dist/taco/svg-import/units/length.d.ts +43 -0
- package/dist/taco/svg-import/units/length.js +125 -0
- package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
- package/dist/taco/svg-import/units/viewbox.js +77 -0
- package/package.json +55 -4
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { propertyValueFits } from "./component-properties.js";
|
|
2
|
+
import { parseLayerPath } from "./components.js";
|
|
3
|
+
import { entryOf } from "./id-table.js";
|
|
4
|
+
import { resolvedInstanceComponents, resolveInstance } from "./instance-resolver.js";
|
|
5
|
+
import { resolvedShownComponents } from "./override-remap.js";
|
|
6
|
+
import { tableEntries } from "./shared-node-table.js";
|
|
7
|
+
/** `value` when it is a record (not a list), else undefined. */
|
|
8
|
+
const recordOf = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
9
|
+
/** `value` when it is a list, else an empty one. */
|
|
10
|
+
const listOf = (value) => Array.isArray(value) ? value : [];
|
|
11
|
+
/** The values of `value` when it is a record, else none. */
|
|
12
|
+
const valuesOf = (value) => Object.values(recordOf(value) ?? {});
|
|
13
|
+
/**
|
|
14
|
+
* Every part `operation` names by ID, each once, in the order the operation
|
|
15
|
+
* names them: the part it changes (such as `node.patch`'s `nodeId` or the ID of
|
|
16
|
+
* the asset `asset.put` writes), the parts it places it under (`parentId`,
|
|
17
|
+
* `newParentId`), every node of an inserted subtree, and each part a node, page,
|
|
18
|
+
* component, theme or comment thread in it refers to (such as a connector's
|
|
19
|
+
* ends, an instance's component, an image's asset or a text run's font asset).
|
|
20
|
+
* The theme counts as one part, named when the operation names any node, text
|
|
21
|
+
* or code style or any variable or variable mode, writes a whole text or code
|
|
22
|
+
* node (whose runs or code without a style ID take the theme's default style)
|
|
23
|
+
* or a layer override that sets a text layer's text or style (also one that
|
|
24
|
+
* clears its style), or replaces the theme. A `node.patch` of a text or code node names it too,
|
|
25
|
+
* which only the document can tell (`textStyleThemeReads`).
|
|
26
|
+
*
|
|
27
|
+
* The records are walked by their types, field by field, so only a field the
|
|
28
|
+
* schema types as an ID is read as one: a word in a text, a name, a field name,
|
|
29
|
+
* a key a person chose (such as a named color or a layer path of an instance's
|
|
30
|
+
* overrides) and anything in the free-form `metadata` of a node, page or
|
|
31
|
+
* component are never taken for an ID. Component property values are not read
|
|
32
|
+
* either, since an instance's value is a component ID only for a property of
|
|
33
|
+
* kind `instance`, which the component's definition says; the component whose
|
|
34
|
+
* definition gives the values their meaning is found in a document with
|
|
35
|
+
* `propertyValueComponents`. The operation is
|
|
36
|
+
* read as given, so a field of the wrong type is skipped rather than refused;
|
|
37
|
+
* applying the operation refuses it.
|
|
38
|
+
*/
|
|
39
|
+
export function operationReferences(operation) {
|
|
40
|
+
const found = new Map();
|
|
41
|
+
const add = (kind, id) => {
|
|
42
|
+
if (typeof id !== "string")
|
|
43
|
+
return;
|
|
44
|
+
const key = `${kind}\u0000${id}`;
|
|
45
|
+
if (!found.has(key))
|
|
46
|
+
found.set(key, { kind, id });
|
|
47
|
+
};
|
|
48
|
+
const addAll = (kind, ids) => listOf(ids).forEach((id) => add(kind, id));
|
|
49
|
+
const theme = () => {
|
|
50
|
+
if (!found.has("theme"))
|
|
51
|
+
found.set("theme", { kind: "theme" });
|
|
52
|
+
};
|
|
53
|
+
/** A style ID names the theme; `null` clears one and names nothing. */
|
|
54
|
+
const themeId = (id) => {
|
|
55
|
+
if (typeof id === "string")
|
|
56
|
+
theme();
|
|
57
|
+
};
|
|
58
|
+
/** Variable bindings (property to variable ID) and variable modes (collection ID to mode ID) name the theme. */
|
|
59
|
+
const themeTable = (table) => valuesOf(table).forEach(themeId);
|
|
60
|
+
const paint = (value) => {
|
|
61
|
+
const record = recordOf(value);
|
|
62
|
+
if (record?.kind === "image")
|
|
63
|
+
add("asset", record.assetId);
|
|
64
|
+
};
|
|
65
|
+
const stroke = (value) => paint(recordOf(value)?.paint);
|
|
66
|
+
/** A node's `style`, a theme node style, or the paints of a layer override. */
|
|
67
|
+
const visualStyle = (value) => {
|
|
68
|
+
const record = recordOf(value);
|
|
69
|
+
if (record === undefined)
|
|
70
|
+
return;
|
|
71
|
+
themeId(record.styleId);
|
|
72
|
+
listOf(record.fills).forEach(paint);
|
|
73
|
+
listOf(record.strokes).forEach(stroke);
|
|
74
|
+
};
|
|
75
|
+
/** A theme text or code style, or a text run's overrides. */
|
|
76
|
+
const fonts = (value) => {
|
|
77
|
+
const record = recordOf(value);
|
|
78
|
+
add("asset", record?.fontAssetId);
|
|
79
|
+
addAll("asset", record?.fontFallbackAssetIds);
|
|
80
|
+
};
|
|
81
|
+
/** A text run or a list marker. */
|
|
82
|
+
const textRun = (value) => {
|
|
83
|
+
const record = recordOf(value);
|
|
84
|
+
themeId(record?.styleId);
|
|
85
|
+
fonts(record?.overrides);
|
|
86
|
+
};
|
|
87
|
+
const paragraphs = (value) => {
|
|
88
|
+
for (const paragraph of listOf(value)) {
|
|
89
|
+
listOf(recordOf(paragraph)?.runs).forEach(textRun);
|
|
90
|
+
textRun(recordOf(recordOf(paragraph)?.list)?.marker);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const layerOverride = (value) => {
|
|
94
|
+
const record = recordOf(value);
|
|
95
|
+
if (record === undefined)
|
|
96
|
+
return;
|
|
97
|
+
add("component", record.componentId);
|
|
98
|
+
add("asset", record.imageAssetId);
|
|
99
|
+
visualStyle(record);
|
|
100
|
+
themeId(record.textStyleId);
|
|
101
|
+
fonts(record.textStyle);
|
|
102
|
+
paragraphs(record.paragraphs);
|
|
103
|
+
themeTable(record.variableBindings);
|
|
104
|
+
// An override that sets a text layer's text or style, also one clearing its style, renders through the theme's default text style.
|
|
105
|
+
if ([record.characters, record.paragraphs, record.textStyle, record.textStyleId].some((field) => field !== undefined))
|
|
106
|
+
theme();
|
|
107
|
+
};
|
|
108
|
+
/** A node, or the fields a `node.patch` writes; not its own `id`, which is read from where the node is. */
|
|
109
|
+
const node = (value) => {
|
|
110
|
+
const record = recordOf(value);
|
|
111
|
+
if (record === undefined)
|
|
112
|
+
return;
|
|
113
|
+
addAll("node", record.children);
|
|
114
|
+
add("node", recordOf(record.start)?.nodeId);
|
|
115
|
+
add("node", recordOf(record.end)?.nodeId);
|
|
116
|
+
add("component", record.componentId);
|
|
117
|
+
// Only an instance has `overrides` at the top of a node; a text run's are its own.
|
|
118
|
+
valuesOf(record.overrides).forEach(layerOverride);
|
|
119
|
+
add("asset", record.assetId);
|
|
120
|
+
visualStyle(record.style);
|
|
121
|
+
stroke(record.stroke);
|
|
122
|
+
for (const region of listOf(recordOf(record.vectorNetwork)?.regions))
|
|
123
|
+
listOf(recordOf(region)?.fills).forEach(paint);
|
|
124
|
+
paragraphs(record.paragraphs);
|
|
125
|
+
themeId(record.codeStyleId);
|
|
126
|
+
themeTable(record.variableBindings);
|
|
127
|
+
themeTable(record.variableModes);
|
|
128
|
+
// A text or code node's runs and code without a style ID take the theme's default style.
|
|
129
|
+
if (record.type === "text" || record.type === "code")
|
|
130
|
+
theme();
|
|
131
|
+
};
|
|
132
|
+
const page = (value) => {
|
|
133
|
+
const record = recordOf(value);
|
|
134
|
+
add("page", record?.id);
|
|
135
|
+
add("node", record?.rootId);
|
|
136
|
+
themeTable(record?.variableModes);
|
|
137
|
+
};
|
|
138
|
+
const subtree = (value) => {
|
|
139
|
+
add("node", value.rootId);
|
|
140
|
+
for (const [id, inner] of tableEntries(value.nodes)) {
|
|
141
|
+
add("node", id);
|
|
142
|
+
node(inner);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const component = (value) => {
|
|
146
|
+
add("component", value.id);
|
|
147
|
+
add("node", value.rootId);
|
|
148
|
+
for (const property of value.properties ?? []) {
|
|
149
|
+
// An instance swap names components in its default and preferred list, a slot in its preferred list.
|
|
150
|
+
if (property.kind === "instance")
|
|
151
|
+
add("component", property.defaultValue);
|
|
152
|
+
else if (property.kind !== "slot")
|
|
153
|
+
continue;
|
|
154
|
+
for (const preferred of property.preferred ?? [])
|
|
155
|
+
add("component", preferred);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
switch (operation.type) {
|
|
159
|
+
case "document.set-title":
|
|
160
|
+
case "document.set-metadata":
|
|
161
|
+
break;
|
|
162
|
+
case "document.set-thumbnail":
|
|
163
|
+
if (operation.nodeId !== null)
|
|
164
|
+
add("node", operation.nodeId);
|
|
165
|
+
break;
|
|
166
|
+
case "node.insert":
|
|
167
|
+
add("node", operation.parentId);
|
|
168
|
+
subtree(operation.subtree);
|
|
169
|
+
break;
|
|
170
|
+
case "node.remove":
|
|
171
|
+
add("node", operation.nodeId);
|
|
172
|
+
break;
|
|
173
|
+
case "node.move":
|
|
174
|
+
add("node", operation.nodeId);
|
|
175
|
+
add("node", operation.newParentId);
|
|
176
|
+
break;
|
|
177
|
+
case "node.replace":
|
|
178
|
+
add("node", operation.node.id);
|
|
179
|
+
node(operation.node);
|
|
180
|
+
break;
|
|
181
|
+
case "node.patch":
|
|
182
|
+
add("node", operation.nodeId);
|
|
183
|
+
node(operation.fields);
|
|
184
|
+
break;
|
|
185
|
+
case "page.insert":
|
|
186
|
+
page(operation.page);
|
|
187
|
+
subtree(operation.subtree);
|
|
188
|
+
break;
|
|
189
|
+
case "page.remove":
|
|
190
|
+
case "page.move":
|
|
191
|
+
add("page", operation.pageId);
|
|
192
|
+
break;
|
|
193
|
+
case "page.replace":
|
|
194
|
+
page(operation.page);
|
|
195
|
+
break;
|
|
196
|
+
case "theme.replace":
|
|
197
|
+
theme();
|
|
198
|
+
valuesOf(operation.theme.nodeStyles).forEach(visualStyle);
|
|
199
|
+
valuesOf(operation.theme.textStyles).forEach(fonts);
|
|
200
|
+
valuesOf(operation.theme.codeStyles).forEach(fonts);
|
|
201
|
+
break;
|
|
202
|
+
case "asset.put":
|
|
203
|
+
add("asset", operation.asset.id);
|
|
204
|
+
break;
|
|
205
|
+
case "asset.remove":
|
|
206
|
+
add("asset", operation.assetId);
|
|
207
|
+
break;
|
|
208
|
+
case "component.insert":
|
|
209
|
+
component(operation.component);
|
|
210
|
+
subtree(operation.subtree);
|
|
211
|
+
break;
|
|
212
|
+
case "component.remove":
|
|
213
|
+
add("component", operation.componentId);
|
|
214
|
+
break;
|
|
215
|
+
case "component.replace":
|
|
216
|
+
component(operation.component);
|
|
217
|
+
break;
|
|
218
|
+
case "comment.insert":
|
|
219
|
+
add("page", operation.thread.pageId);
|
|
220
|
+
add("node", recordOf(operation.thread.anchor)?.attachedNodeId);
|
|
221
|
+
break;
|
|
222
|
+
case "comment.remove":
|
|
223
|
+
case "comment.add-message":
|
|
224
|
+
case "comment.remove-message":
|
|
225
|
+
case "comment.edit-message":
|
|
226
|
+
case "comment.set-resolved":
|
|
227
|
+
case "comment.set-agent-state":
|
|
228
|
+
case "comment.add-digest":
|
|
229
|
+
case "comment.remove-digest":
|
|
230
|
+
case "comment.add-edit-record":
|
|
231
|
+
case "comment.remove-edit-record":
|
|
232
|
+
break;
|
|
233
|
+
default: {
|
|
234
|
+
// Fails to compile when an operation type is not handled above.
|
|
235
|
+
const unhandled = operation;
|
|
236
|
+
throw new RangeError(`Unknown operation type ${unhandled.type}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return [...found.values()];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The theme, when `operation` patches or replaces a node that is a text or code
|
|
243
|
+
* node, as the operation says (`node.replace`) or else as `document` has it: its
|
|
244
|
+
* rendering always goes through the theme, through the styles it names or, for
|
|
245
|
+
* runs and code without a style ID, the theme's default text or code style.
|
|
246
|
+
* `operationReferences` reads the operation alone, and a patch does not say the
|
|
247
|
+
* type of the node it writes.
|
|
248
|
+
*/
|
|
249
|
+
export function textStyleThemeReads(document, operation) {
|
|
250
|
+
let type;
|
|
251
|
+
if (operation.type === "node.patch")
|
|
252
|
+
type = entryOf(document.nodes, operation.nodeId)?.type;
|
|
253
|
+
else if (operation.type === "node.replace")
|
|
254
|
+
type = operation.node.type;
|
|
255
|
+
else
|
|
256
|
+
return [];
|
|
257
|
+
return type === "text" || type === "code" ? [{ kind: "theme" }] : [];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Every component that each instance `operation` writes resolves through in `document` (`resolvedInstanceComponents`),
|
|
261
|
+
* each once: writing an instance reads every component it resolves through. An operation writes an instance when it
|
|
262
|
+
* patches or replaces the node, or inserts it in a subtree (of `node.insert`, `page.insert` or `component.insert`).
|
|
263
|
+
* Its rendering depends on its component, each nested component after overrides, and the components its property
|
|
264
|
+
* values or their defaults select, so call this with the document both before and after the operation: before, for
|
|
265
|
+
* what an override or value it clears had covered, and after, for what it shows now. A written node that `document`
|
|
266
|
+
* does not hold as an instance counts for nothing. Throws the resolver's `ModelError` when an instance there does not
|
|
267
|
+
* resolve.
|
|
268
|
+
*/
|
|
269
|
+
export function instanceComponentReads(document, operation) {
|
|
270
|
+
let written;
|
|
271
|
+
switch (operation.type) {
|
|
272
|
+
case "node.patch":
|
|
273
|
+
written = [operation.nodeId];
|
|
274
|
+
break;
|
|
275
|
+
case "node.replace":
|
|
276
|
+
written = [operation.node.id];
|
|
277
|
+
break;
|
|
278
|
+
case "node.insert":
|
|
279
|
+
case "page.insert":
|
|
280
|
+
case "component.insert":
|
|
281
|
+
written = Object.keys(operation.subtree.nodes);
|
|
282
|
+
break;
|
|
283
|
+
default:
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
const found = new Set();
|
|
287
|
+
for (const nodeId of written) {
|
|
288
|
+
if (entryOf(document.nodes, nodeId)?.type !== "instance")
|
|
289
|
+
continue;
|
|
290
|
+
for (const componentId of resolvedInstanceComponents(resolveInstance(document, nodeId)))
|
|
291
|
+
found.add(componentId);
|
|
292
|
+
}
|
|
293
|
+
return [...found].map((id) => ({ kind: "component", id }));
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The components whose property definitions give meaning to the property values `operation` writes, as `document`
|
|
297
|
+
* has them, each once. An operation writes values when it sets them or clears ones stored (`node.patch`'s `remove`, a
|
|
298
|
+
* `node.replace` without them, an override it removes with its values): for each instance whose `propertyValues` it
|
|
299
|
+
* writes, the component the instance shows (the one the operation writes, else the one `document` stores for it),
|
|
300
|
+
* and for each layer override whose `propertyValues` it writes, that component and the one the nested instance at
|
|
301
|
+
* the override's layer path shows (the override's swap, else the one it shows once the instance resolves in
|
|
302
|
+
* `document`, else the one stored on the nested instance). Each written value is then resolved against that component's property definitions in `document`:
|
|
303
|
+
* a value of an `instance`-kind property is a component ID, so the component it selects counts too, and when the
|
|
304
|
+
* written values leave such a property without a value it had (it is cleared), the property's default, which the
|
|
305
|
+
* instance then shows, counts. `operationReferences` reads the operation alone, so it cannot tell which component a
|
|
306
|
+
* stored instance shows or which values are component IDs. A node `document` does not have counts only through what
|
|
307
|
+
* the operation writes, and an override key that is not a layer path names no nested component.
|
|
308
|
+
*/
|
|
309
|
+
export function propertyValueComponents(document, operation) {
|
|
310
|
+
const found = new Map();
|
|
311
|
+
const add = (id) => {
|
|
312
|
+
if (typeof id === "string" && !found.has(id))
|
|
313
|
+
found.set(id, { kind: "component", id });
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* One node as the operation writes it: `fields` holds the fields it writes, `nodeId` is where it is, and `cleared`
|
|
317
|
+
* says which fields it removes: those `node.patch` names in `remove`, or for a node it replaces whole, every field
|
|
318
|
+
* the new node does not have. The values an instance shows change when they are written or a stored one is cleared,
|
|
319
|
+
* and a layer override's values change when its override is written, or removed with the whole `overrides` map.
|
|
320
|
+
*/
|
|
321
|
+
const written = (nodeId, fields, cleared) => {
|
|
322
|
+
const record = recordOf(fields);
|
|
323
|
+
if (record === undefined)
|
|
324
|
+
return;
|
|
325
|
+
const isCleared = (field) => cleared === "absent" ? record[field] === undefined : cleared.has(field);
|
|
326
|
+
const stored = entryOf(document.nodes, nodeId);
|
|
327
|
+
const storedInstance = stored?.type === "instance" ? stored : undefined;
|
|
328
|
+
const componentId = typeof record.componentId === "string" ? record.componentId : storedInstance?.componentId;
|
|
329
|
+
if (record.propertyValues !== undefined || (isCleared("propertyValues") && storedInstance?.propertyValues !== undefined)) {
|
|
330
|
+
add(componentId);
|
|
331
|
+
selected(componentId, record.propertyValues, storedInstance?.propertyValues);
|
|
332
|
+
}
|
|
333
|
+
const overrides = recordOf(record.overrides);
|
|
334
|
+
// A written `overrides` map replaces the stored one whole, so a stored override it leaves out is removed.
|
|
335
|
+
const storedOverrides = overrides !== undefined || isCleared("overrides") ? storedInstance?.overrides : undefined;
|
|
336
|
+
let shownAt;
|
|
337
|
+
for (const key of new Set([...Object.keys(overrides ?? {}), ...Object.keys(storedOverrides ?? {})])) {
|
|
338
|
+
const overrideRecord = recordOf(entryOf(overrides, key));
|
|
339
|
+
const storedValues = entryOf(storedOverrides, key)?.propertyValues;
|
|
340
|
+
if (overrideRecord?.propertyValues === undefined && storedValues === undefined)
|
|
341
|
+
continue;
|
|
342
|
+
add(componentId);
|
|
343
|
+
let nestedComponentId;
|
|
344
|
+
if (typeof overrideRecord?.componentId === "string") {
|
|
345
|
+
nestedComponentId = overrideRecord.componentId;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
const path = parseLayerPath(key);
|
|
349
|
+
if (path === null)
|
|
350
|
+
continue;
|
|
351
|
+
if (storedInstance !== undefined)
|
|
352
|
+
shownAt ??= resolvedShownComponents(document, storedInstance.id);
|
|
353
|
+
const nested = entryOf(document.nodes, path.at(-1));
|
|
354
|
+
nestedComponentId = shownAt?.(path) ?? (nested?.type === "instance" ? nested.componentId : undefined);
|
|
355
|
+
}
|
|
356
|
+
add(nestedComponentId);
|
|
357
|
+
selected(nestedComponentId, overrideRecord?.propertyValues, storedValues);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* The components that `values`, written for an instance of `componentId`, select through its `instance`-kind
|
|
362
|
+
* properties: a written value that fits, else the default when `before` (the values stored before) had one.
|
|
363
|
+
*/
|
|
364
|
+
const selected = (componentId, values, before) => {
|
|
365
|
+
const definition = typeof componentId === "string" ? entryOf(document.components, componentId) : undefined;
|
|
366
|
+
const written = recordOf(values);
|
|
367
|
+
const stored = recordOf(before);
|
|
368
|
+
for (const property of definition?.properties ?? []) {
|
|
369
|
+
if (property.kind !== "instance")
|
|
370
|
+
continue;
|
|
371
|
+
const value = written?.[property.id];
|
|
372
|
+
const storedValue = stored?.[property.id];
|
|
373
|
+
if (value !== undefined && propertyValueFits(property, value))
|
|
374
|
+
add(value);
|
|
375
|
+
else if (storedValue !== undefined && propertyValueFits(property, storedValue))
|
|
376
|
+
add(property.defaultValue);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const subtree = (value) => {
|
|
380
|
+
for (const [id, inner] of tableEntries(value.nodes))
|
|
381
|
+
written(id, inner, new Set());
|
|
382
|
+
};
|
|
383
|
+
switch (operation.type) {
|
|
384
|
+
case "node.patch":
|
|
385
|
+
written(operation.nodeId, operation.fields, new Set(operation.remove ?? []));
|
|
386
|
+
break;
|
|
387
|
+
case "node.replace":
|
|
388
|
+
written(operation.node.id, operation.node, "absent");
|
|
389
|
+
break;
|
|
390
|
+
case "node.insert":
|
|
391
|
+
case "page.insert":
|
|
392
|
+
case "component.insert":
|
|
393
|
+
subtree(operation.subtree);
|
|
394
|
+
break;
|
|
395
|
+
default:
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
return [...found.values()];
|
|
399
|
+
}
|