@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,610 @@
|
|
|
1
|
+
import { ModelError, type ModelProblem } from "./codec.ts";
|
|
2
|
+
import { type Asset, type AssetId, type ComponentDefinition, type ComponentId, type ComponentPropertyId, type InstanceSlots, type DesignDocument, type DocumentTheme, type JsonValue, type NodeId, type SceneNode, type Page, type PageId } from "./types.ts";
|
|
3
|
+
import { type CommentOperation } from "./comment-operations.ts";
|
|
4
|
+
/** A node and all its descendants, as carried by insert operations. */
|
|
5
|
+
export interface SerializedSubtree {
|
|
6
|
+
readonly rootId: NodeId;
|
|
7
|
+
/** The root and every descendant, keyed by `NodeId`. */
|
|
8
|
+
readonly nodes: Readonly<Record<string, SceneNode>>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* One edit to a document. Every change goes through these operations, so
|
|
12
|
+
* each can be recorded, inverted for undo, and sent over the wire as JSON.
|
|
13
|
+
*
|
|
14
|
+
* - `document.set-title`, `document.set-metadata`: change document fields;
|
|
15
|
+
* `null` metadata removes it.
|
|
16
|
+
* - `document.set-thumbnail`: sets the file's thumbnail frame
|
|
17
|
+
* (`DesignDocument.thumbnailNodeId`); `null` removes it. The layer must be
|
|
18
|
+
* a top-level frame of a page; see `canBeThumbnail`.
|
|
19
|
+
* - `node.insert`: adds `subtree` as a child of `parentId` at `index`
|
|
20
|
+
* (0 to the child count). None of its node IDs may exist yet. With `slot`,
|
|
21
|
+
* the subtree is a slot host (a frame with `slotHost: true`) and is added
|
|
22
|
+
* to the slots of the instance `parentId` (which `slot.instanceId` names
|
|
23
|
+
* too) under `slot.path` and `slot.propertyId`; `index` is then 0.
|
|
24
|
+
* - `node.remove`: removes a node and its descendants. Not for a page root.
|
|
25
|
+
* A connector end attached to a removed node becomes a free end. Removing
|
|
26
|
+
* a slot host also drops its entry from the instance's `slots`.
|
|
27
|
+
* - `node.move`: moves a node to `newParentId` at `index`, counted after the
|
|
28
|
+
* node is taken out of its old parent. Not for a page root, and not into
|
|
29
|
+
* the node's own subtree.
|
|
30
|
+
* - `node.replace`: replaces a node's data by ID. It cannot change the
|
|
31
|
+
* node's `type` or a container's `children`; use insert, remove and move.
|
|
32
|
+
* - `node.patch`: writes `fields` into one node by ID and deletes the fields
|
|
33
|
+
* named in `remove`. Plain objects merge recursively, keeping stored fields
|
|
34
|
+
* the patch does not name. Arrays and other values are replaced whole.
|
|
35
|
+
* The result must be a valid node, as for `node.replace`, and the same
|
|
36
|
+
* limits apply: `id` and `type` cannot be patched, and `children` only to
|
|
37
|
+
* the value it has. A field named in both `fields` and `remove` is refused.
|
|
38
|
+
* Its inverse is a `node.replace` with the node as it was.
|
|
39
|
+
* - `page.insert`, `page.remove`, `page.move`: add, delete or reorder pages.
|
|
40
|
+
* An inserted page's `rootId` must match its subtree's root. Removing a
|
|
41
|
+
* page removes its nodes.
|
|
42
|
+
* - `page.replace`: replaces a page's fields; it cannot change `rootId`.
|
|
43
|
+
* - `theme.replace`: replaces the whole theme.
|
|
44
|
+
* - `asset.put`: adds an asset or replaces the one with the same ID.
|
|
45
|
+
* - `asset.remove`: deletes an asset. It fails validation while an image or
|
|
46
|
+
* video node or a text or code style still refers to it.
|
|
47
|
+
*/
|
|
48
|
+
export type DocumentOperation = {
|
|
49
|
+
readonly type: "document.set-title";
|
|
50
|
+
readonly title: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "document.set-metadata";
|
|
53
|
+
readonly metadata: Readonly<Record<string, JsonValue>> | null;
|
|
54
|
+
} | {
|
|
55
|
+
readonly type: "document.set-thumbnail";
|
|
56
|
+
readonly nodeId: NodeId | null;
|
|
57
|
+
} | {
|
|
58
|
+
readonly type: "node.insert";
|
|
59
|
+
readonly parentId: NodeId;
|
|
60
|
+
readonly index: number;
|
|
61
|
+
readonly subtree: SerializedSubtree;
|
|
62
|
+
/**
|
|
63
|
+
* Inserts a slot host into an instance's `slots` instead of a
|
|
64
|
+
* container's children. It is the inverse of removing a slot host.
|
|
65
|
+
* @since 0.37.0
|
|
66
|
+
*/
|
|
67
|
+
readonly slot?: SlotInsertTarget;
|
|
68
|
+
} | {
|
|
69
|
+
readonly type: "node.remove";
|
|
70
|
+
readonly nodeId: NodeId;
|
|
71
|
+
} | {
|
|
72
|
+
readonly type: "node.move";
|
|
73
|
+
readonly nodeId: NodeId;
|
|
74
|
+
readonly newParentId: NodeId;
|
|
75
|
+
readonly index: number;
|
|
76
|
+
} | {
|
|
77
|
+
readonly type: "node.replace";
|
|
78
|
+
readonly node: SceneNode;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Writes some fields of one node; see the list above.
|
|
82
|
+
*/
|
|
83
|
+
| {
|
|
84
|
+
readonly type: "node.patch";
|
|
85
|
+
readonly nodeId: NodeId;
|
|
86
|
+
/** Field values as a node of this kind stores them; checked when the patch is applied. */
|
|
87
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
88
|
+
readonly remove?: readonly string[];
|
|
89
|
+
} | {
|
|
90
|
+
readonly type: "page.insert";
|
|
91
|
+
readonly index: number;
|
|
92
|
+
readonly page: Page;
|
|
93
|
+
readonly subtree: SerializedSubtree;
|
|
94
|
+
} | {
|
|
95
|
+
readonly type: "page.remove";
|
|
96
|
+
readonly pageId: PageId;
|
|
97
|
+
} | {
|
|
98
|
+
readonly type: "page.move";
|
|
99
|
+
readonly pageId: PageId;
|
|
100
|
+
readonly index: number;
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: "page.replace";
|
|
103
|
+
readonly page: Page;
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "theme.replace";
|
|
106
|
+
readonly theme: DocumentTheme;
|
|
107
|
+
} | {
|
|
108
|
+
readonly type: "asset.put";
|
|
109
|
+
readonly asset: Asset;
|
|
110
|
+
} | {
|
|
111
|
+
readonly type: "asset.remove";
|
|
112
|
+
readonly assetId: AssetId;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Adds a component and its layer tree. `subtree.rootId` must equal
|
|
116
|
+
* `component.rootId`; the nodes must not exist yet. Inverse: `component.remove`.
|
|
117
|
+
* @since 0.23.0
|
|
118
|
+
*/
|
|
119
|
+
| {
|
|
120
|
+
readonly type: "component.insert";
|
|
121
|
+
readonly component: ComponentDefinition;
|
|
122
|
+
readonly subtree: SerializedSubtree;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Removes a component and its layer tree. Fails while any stored instance
|
|
126
|
+
* or override still refers to it. Inverse: `component.insert` with the
|
|
127
|
+
* saved subtree.
|
|
128
|
+
* @since 0.23.0
|
|
129
|
+
*/
|
|
130
|
+
| {
|
|
131
|
+
readonly type: "component.remove";
|
|
132
|
+
readonly componentId: ComponentId;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Replaces a component's definition (name, description, metadata). `key`
|
|
136
|
+
* and `rootId` cannot change. Inverse: `component.replace` with the old value.
|
|
137
|
+
* @since 0.23.0
|
|
138
|
+
*/
|
|
139
|
+
| {
|
|
140
|
+
readonly type: "component.replace";
|
|
141
|
+
readonly component: ComponentDefinition;
|
|
142
|
+
}
|
|
143
|
+
/** Operations on comment threads; see `CommentOperation`. @since 0.31.0 */
|
|
144
|
+
| CommentOperation;
|
|
145
|
+
/**
|
|
146
|
+
* Where a `node.insert` with `slot` puts a slot host: the instance, the
|
|
147
|
+
* layer path of the nested instance whose slot it fills (left out or empty
|
|
148
|
+
* for the instance's own slot), and the slot property ID.
|
|
149
|
+
* @since 0.37.0
|
|
150
|
+
*/
|
|
151
|
+
export interface SlotInsertTarget {
|
|
152
|
+
readonly instanceId: NodeId;
|
|
153
|
+
readonly path?: readonly NodeId[];
|
|
154
|
+
readonly propertyId: ComponentPropertyId;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The `type` of every design `DocumentOperation`, in the order the list
|
|
158
|
+
* above gives them. `assertOperation` accepts exactly these and the
|
|
159
|
+
* `COMMENT_OPERATION_TYPES`, which are applied apart from the undo history.
|
|
160
|
+
*/
|
|
161
|
+
export declare const DOCUMENT_OPERATION_TYPES: readonly ["document.set-title", "document.set-metadata", "document.set-thumbnail", "node.insert", "node.remove", "node.move", "node.replace", "node.patch", "page.insert", "page.remove", "page.move", "page.replace", "theme.replace", "asset.put", "asset.remove", "component.insert", "component.remove", "component.replace"];
|
|
162
|
+
/**
|
|
163
|
+
* What an edit changed, used to decide what to redraw and which subscribers
|
|
164
|
+
* to notify. Every ID list is sorted. When nothing changed the value is
|
|
165
|
+
* `EMPTY_CHANGE_SET`.
|
|
166
|
+
*/
|
|
167
|
+
export interface ChangeSet {
|
|
168
|
+
/** False only when the document is unchanged; then every list is empty. */
|
|
169
|
+
readonly documentChanged: boolean;
|
|
170
|
+
readonly themeChanged: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Nodes whose data or position changed, or that may look different. It
|
|
173
|
+
* includes inserted and removed nodes, parents whose children changed,
|
|
174
|
+
* every node in a moved subtree, nodes that use a changed asset, and every
|
|
175
|
+
* node that uses a part of the theme that changed (a style or variable it
|
|
176
|
+
* names, or a variable name its expressions read; see `nodesUsingThemeChange`).
|
|
177
|
+
*/
|
|
178
|
+
readonly changedNodeIds: readonly NodeId[];
|
|
179
|
+
/**
|
|
180
|
+
* Nodes that did not exist before. A node removed and inserted again in
|
|
181
|
+
* the same edit is in neither this list nor `removedNodeIds`.
|
|
182
|
+
*/
|
|
183
|
+
readonly insertedNodeIds: readonly NodeId[];
|
|
184
|
+
/** Nodes that no longer exist. */
|
|
185
|
+
readonly removedNodeIds: readonly NodeId[];
|
|
186
|
+
/** Pages added, removed, changed or moved in `pageOrder`. */
|
|
187
|
+
readonly changedPageIds: readonly PageId[];
|
|
188
|
+
readonly changedAssetIds: readonly AssetId[];
|
|
189
|
+
/**
|
|
190
|
+
* Components added, removed or replaced, and components any of whose
|
|
191
|
+
* layers changed. Their instances, and the instances of every component
|
|
192
|
+
* that nests them, may look different (see `componentsNesting`).
|
|
193
|
+
* @since 0.23.0
|
|
194
|
+
*/
|
|
195
|
+
readonly changedComponentIds: readonly ComponentId[];
|
|
196
|
+
/**
|
|
197
|
+
* Comment threads added, removed or changed. `applyOperations` lists every
|
|
198
|
+
* thread its comment operations wrote; `diffDocuments` compares threads by
|
|
199
|
+
* ID, so a change only to their order in `commentThreads` is not listed.
|
|
200
|
+
* @since 0.31.0
|
|
201
|
+
*/
|
|
202
|
+
readonly changedCommentThreadIds: readonly string[];
|
|
203
|
+
}
|
|
204
|
+
/** What `applyOperations` returns. */
|
|
205
|
+
export interface ApplyOperationsResult {
|
|
206
|
+
/** The new, deeply frozen document; the input document when nothing changed. */
|
|
207
|
+
readonly document: DesignDocument;
|
|
208
|
+
/**
|
|
209
|
+
* Operations that turn `document` back into the input, already in the
|
|
210
|
+
* order to apply them. Empty when nothing changed.
|
|
211
|
+
*
|
|
212
|
+
* One exception: when the input held a node with a stretching constraint
|
|
213
|
+
* on an axis it hugs (a document stored before `applyOperations` kept
|
|
214
|
+
* that rule) and the operations themselves repaired that axis or removed
|
|
215
|
+
* the node, these operations bring it back with Left or Top on that axis.
|
|
216
|
+
*/
|
|
217
|
+
readonly inverseOperations: readonly DocumentOperation[];
|
|
218
|
+
readonly changes: ChangeSet;
|
|
219
|
+
}
|
|
220
|
+
export declare const modelApplyStats: {
|
|
221
|
+
documentDiffs: number;
|
|
222
|
+
/** Node entries `diffDocuments` compared. */
|
|
223
|
+
diffNodesCompared: number;
|
|
224
|
+
operationDeserializes: number;
|
|
225
|
+
positionMapContainersVisited: number;
|
|
226
|
+
/** Node maps `node.replace`, `node.patch` and `node.move` copied. */
|
|
227
|
+
replaceNodeMapCopies: number;
|
|
228
|
+
/** Diffs that read every node entry of both documents to find the ones not shared. */
|
|
229
|
+
diffWholeNodeMapScans: number;
|
|
230
|
+
/** Layout views (`laidOut`) that read every node of the document to find its texts. */
|
|
231
|
+
laidOutWholeDocumentScans: number;
|
|
232
|
+
/** Layout views (`laidOut`) that refitted every instance of the shown pages instead of keeping the earlier view's refit. */
|
|
233
|
+
laidOutWholeInstanceRefits: number;
|
|
234
|
+
/** Operations `deserializeOperations` checked with `assertOperation`. */
|
|
235
|
+
operationChecks: number;
|
|
236
|
+
/** Edited documents `applyOperations` checked with `assertChangedDocument`. */
|
|
237
|
+
changedDocumentChecks: number;
|
|
238
|
+
/** Text layout keys (`textLayoutKey`) the layout views worked out. */
|
|
239
|
+
laidOutTextLayoutKeys: number;
|
|
240
|
+
/** Layout views that refitted every component instance (the component cascade) instead of keeping an earlier view's sizes. */
|
|
241
|
+
laidOutInstanceRefits: number;
|
|
242
|
+
/** Stored texts the layout views checked against their drawn size (and corrected where it differs). */
|
|
243
|
+
laidOutTextsChecked: number;
|
|
244
|
+
/** Layers of a layout view's text index that listed their texts by font asset (on a font asset change). */
|
|
245
|
+
laidOutFontAssetListings: number;
|
|
246
|
+
/**
|
|
247
|
+
* Layout views made by a pass over every text an earlier view corrected, because the view could not be made by
|
|
248
|
+
* writing the edit over the earlier view, counted by the reason it could not (`viewFromEarlierView`).
|
|
249
|
+
*/
|
|
250
|
+
laidOutCorrectionPasses: Record<string, number>;
|
|
251
|
+
/** Layers a layout view made from an earlier one wrote again as stored, with the subtree around an edit it could not write over that view alone. */
|
|
252
|
+
laidOutResetLayers: number;
|
|
253
|
+
/** Indexes of the nodes that use each asset made by reading every node (`nodesUsingAsset`). */
|
|
254
|
+
assetUsersWholeDocumentScans: number;
|
|
255
|
+
/** Indexes of the nodes that use each part of the theme made by reading every node (`nodesUsingThemeChange`). */
|
|
256
|
+
themeUsersWholeDocumentScans: number;
|
|
257
|
+
};
|
|
258
|
+
export declare function resetModelApplyStats(): void;
|
|
259
|
+
/** The frozen `ChangeSet` returned whenever nothing changed. */
|
|
260
|
+
export declare const EMPTY_CHANGE_SET: ChangeSet;
|
|
261
|
+
/**
|
|
262
|
+
* The assets `node` shows or draws with: an image or video layer's asset, an image fill or stroke (in its style, its
|
|
263
|
+
* shared style or a path's regions), an instance override, or a font of its text or code. Each is listed once; the
|
|
264
|
+
* list is empty for a node that uses none. It reads the node and the theme, and no asset entry, so the list holds
|
|
265
|
+
* while those stay the same, whatever assets the document gains or loses.
|
|
266
|
+
*/
|
|
267
|
+
export declare function assetsUsedByNode(document: DesignDocument, node: SceneNode): readonly AssetId[];
|
|
268
|
+
/** True when `node` shows or draws with the asset `assetId` (`assetsUsedByNode`). */
|
|
269
|
+
export declare function nodeUsesAsset(document: DesignDocument, node: SceneNode, assetId: AssetId): boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Checks the shape of one operation: its `type`, its exact keys, and any
|
|
272
|
+
* node, page, theme or asset it carries. Whether it fits a particular
|
|
273
|
+
* document is only checked by `applyOperations`. Throws a `ModelError`.
|
|
274
|
+
*/
|
|
275
|
+
export declare function assertOperation(value: unknown): asserts value is DocumentOperation;
|
|
276
|
+
/**
|
|
277
|
+
* Checks one operation as `assertOperation` does, with the same checks, but
|
|
278
|
+
* returns every problem instead of throwing the first: each field and each
|
|
279
|
+
* node of a subtree is checked, and a value that failed counts once, without
|
|
280
|
+
* the problems inside it. Empty when `assertOperation` accepts it; otherwise
|
|
281
|
+
* the first problem is the error it throws. Problems inside a node of a
|
|
282
|
+
* subtree are at its place there (`$operation.subtree.nodes.n1.rotation`), and
|
|
283
|
+
* those of the node of a `node.replace` at its own paths (`$.rotation`), as
|
|
284
|
+
* `assertOperation` reports them. At most
|
|
285
|
+
* `limit` (`MODEL_PROBLEM_LIMIT` when omitted), then "and N more".
|
|
286
|
+
*/
|
|
287
|
+
export declare function checkOperation(value: unknown, limit?: number): readonly ModelProblem[];
|
|
288
|
+
/**
|
|
289
|
+
* Reads a list of operations from a JSON string or a parsed value, checks
|
|
290
|
+
* each with `assertOperation`, and returns a deeply frozen copy. Throws a
|
|
291
|
+
* `ModelError` (`INVALID_JSON` for a string that does not parse).
|
|
292
|
+
*
|
|
293
|
+
* An operation this function returned before is taken as it is, unchecked:
|
|
294
|
+
* it is frozen, so it cannot have changed since its check; only the list
|
|
295
|
+
* is new. So an edit that passes through
|
|
296
|
+
* several steps (planning, then the store, then `applyOperations`) checks
|
|
297
|
+
* each operation once.
|
|
298
|
+
*/
|
|
299
|
+
export declare function deserializeOperations(input: string | unknown): readonly DocumentOperation[];
|
|
300
|
+
/**
|
|
301
|
+
* Takes `node.replace` operations the model made itself, each a node of a
|
|
302
|
+
* frozen, checked document with a new frame (the layout view's text
|
|
303
|
+
* corrections, `laidOut`, and the layout that follows them), as read by
|
|
304
|
+
* `deserializeOperations`: each is frozen all the way down and is then
|
|
305
|
+
* taken as it is, without the check and the copy. A view corrects every
|
|
306
|
+
* shown text of a page at once, and the copies cost more than laying the
|
|
307
|
+
* page out. Applying them still checks the nodes they write
|
|
308
|
+
* (`assertChangedDocument`). Any other operation is left to the full read.
|
|
309
|
+
* Not for operations read from an agent, a file, a paste or history.
|
|
310
|
+
*/
|
|
311
|
+
export declare function readAsMadeByModel(operations: readonly DocumentOperation[]): readonly DocumentOperation[];
|
|
312
|
+
/**
|
|
313
|
+
* Checks each operation with `assertOperation` and writes the list as JSON
|
|
314
|
+
* with sorted keys. `indentation` is passed to `JSON.stringify`.
|
|
315
|
+
*/
|
|
316
|
+
export declare function serializeOperations(operations: readonly DocumentOperation[], indentation?: number): string;
|
|
317
|
+
/**
|
|
318
|
+
* The IDs of a node and all its descendants. Empty when the node does not
|
|
319
|
+
* exist.
|
|
320
|
+
*/
|
|
321
|
+
export declare function getSubtreeNodeIds(document: DesignDocument, rootId: NodeId): ReadonlySet<NodeId>;
|
|
322
|
+
/**
|
|
323
|
+
* Copies a node and its descendants into a `SerializedSubtree`, ready for a
|
|
324
|
+
* `node.insert` or `page.insert` operation. Throws a `ModelError` when the
|
|
325
|
+
* node does not exist.
|
|
326
|
+
*/
|
|
327
|
+
export declare function serializeSubtree(document: DesignDocument, rootId: NodeId): SerializedSubtree;
|
|
328
|
+
/**
|
|
329
|
+
* Checks a `node.patch` as `checkOperation` does, and then the node it
|
|
330
|
+
* leaves on `document` as `checkSceneNode` does, and returns every problem
|
|
331
|
+
* of both: those of the node at the patch's own paths (`$operation.fields.opacity`
|
|
332
|
+
* for a written field, `$operation.remove.0` for a removed one). A field or
|
|
333
|
+
* removal the first check refused is left out of the node, so it counts once.
|
|
334
|
+
* The node is not checked when the patch names no stored node or its fields
|
|
335
|
+
* are not an object. Empty when applying the patch to `document` would not
|
|
336
|
+
* be refused for the shape of a value. At most `limit` (`MODEL_PROBLEM_LIMIT`
|
|
337
|
+
* when omitted), then "and N more".
|
|
338
|
+
*/
|
|
339
|
+
export declare function checkNodePatch(document: DesignDocument, value: unknown, limit?: number): readonly ModelProblem[];
|
|
340
|
+
/**
|
|
341
|
+
* Refuses the operations when one of them writes a slot host's `frame`,
|
|
342
|
+
* `rotation`, flips or `layout`: the component cascade sets those to follow
|
|
343
|
+
* the slot frame, so a person or an agent edits the slot frame's override on
|
|
344
|
+
* the instance instead. Only `node.replace` and `node.patch` of a host
|
|
345
|
+
* stored in `document` are read; a host the operations insert is theirs to
|
|
346
|
+
* place. Call it on the operations a person or an agent wrote, before
|
|
347
|
+
* `settle` adds the layout and cascade writes of its own, which may move a
|
|
348
|
+
* host; never on settled operations, an inverse or a replay. Neither
|
|
349
|
+
* `applyOperations` nor `settle` calls it, so loading, undo, journal replay,
|
|
350
|
+
* merges and settling settled operations take any valid write.
|
|
351
|
+
* @since 0.37.0
|
|
352
|
+
*/
|
|
353
|
+
export declare function assertNoSlotHostGeometryWrite(document: DesignDocument, operations: readonly DocumentOperation[]): void;
|
|
354
|
+
/**
|
|
355
|
+
* `operations` with every `node.patch` written as the `node.replace` it
|
|
356
|
+
* amounts to where it runs, so code that reads the nodes an edit writes only
|
|
357
|
+
* has to know `node.replace`. The list comes back as it is when it holds no
|
|
358
|
+
* patch. Throws a `ModelError` exactly when `applyOperations` refuses
|
|
359
|
+
* `operations`: the result is checked by `applyOperations`, document-wide
|
|
360
|
+
* rules such as references to styles and components included.
|
|
361
|
+
*/
|
|
362
|
+
export declare function nodePatchesAsReplacements(input: DesignDocument, operations: readonly DocumentOperation[]): readonly DocumentOperation[];
|
|
363
|
+
/** Convert legacy patches against each preceding operation, including commits outside the current head. */
|
|
364
|
+
export declare function legacyNodePatchesAsReplacements(document: DesignDocument, operations: readonly DocumentOperation[]): readonly DocumentOperation[];
|
|
365
|
+
/**
|
|
366
|
+
* `slots` with the entry at `pathKey` and `propertyId` set to `hostId`, or
|
|
367
|
+
* dropped when `hostId` is undefined. Empty maps are left out; undefined
|
|
368
|
+
* when nothing is left.
|
|
369
|
+
* @since 0.37.0
|
|
370
|
+
*/
|
|
371
|
+
export declare function slotsWithEntry(slots: InstanceSlots | undefined, pathKey: string, propertyId: ComponentPropertyId, hostId: NodeId | undefined): InstanceSlots | undefined;
|
|
372
|
+
/**
|
|
373
|
+
* The document each of `operations` is applied to, and the one the last
|
|
374
|
+
* leaves: entry `i` is `input` with the operations before `i` applied, so
|
|
375
|
+
* there is one more entry than there are operations. None has the steps
|
|
376
|
+
* that follow the operations in the same edit (groups refitted or removed,
|
|
377
|
+
* connector ends freed), and none is validated or frozen; do not change
|
|
378
|
+
* them. Use it to learn what an operation sees, for example which layers a
|
|
379
|
+
* removal deletes once earlier operations moved some out.
|
|
380
|
+
*
|
|
381
|
+
* It throws a `ModelError` when an operation does not fit the document.
|
|
382
|
+
*/
|
|
383
|
+
export declare function documentsBeforeEachOperation(input: DesignDocument, operations: readonly DocumentOperation[]): readonly DesignDocument[];
|
|
384
|
+
/**
|
|
385
|
+
* The IDs of the nodes that are in `input` and gone once `operations` have
|
|
386
|
+
* run, in the order `input.nodes` lists them. That is every node the
|
|
387
|
+
* operations remove themselves (`node.remove`, `page.remove` and
|
|
388
|
+
* `component.remove`, each with everything inside) and every group removed
|
|
389
|
+
* because the edit left it with no children. A node that is removed and put
|
|
390
|
+
* back by the same operations is not listed. The IDs come in the order the
|
|
391
|
+
* operations remove the nodes, and finding them reads only those nodes, not
|
|
392
|
+
* every node of the document.
|
|
393
|
+
*
|
|
394
|
+
* It runs the same steps as `applyOperations` but does not validate the
|
|
395
|
+
* result and returns no document. Use it to learn what an edit removes
|
|
396
|
+
* before applying it, for example to let go of the connector ends attached
|
|
397
|
+
* to those nodes, without which `applyOperations` would refuse the edit.
|
|
398
|
+
*
|
|
399
|
+
* It throws a `ModelError` when an operation does not fit the document.
|
|
400
|
+
*/
|
|
401
|
+
export declare function nodeIdsRemovedBy(input: DesignDocument, operations: readonly DocumentOperation[]): readonly NodeId[];
|
|
402
|
+
/**
|
|
403
|
+
* A change was refused because it would delete a page that must not be
|
|
404
|
+
* deleted (`Page.removable` is `false`). Nothing was changed. `pages` lists
|
|
405
|
+
* every such page the change would delete, in the order it deletes them.
|
|
406
|
+
* The `code` is `PAGE_NOT_REMOVABLE` and the message names the pages.
|
|
407
|
+
* @since 0.29.0
|
|
408
|
+
*/
|
|
409
|
+
export declare class PageNotRemovableError extends ModelError {
|
|
410
|
+
/** The pages that must stay, as they are in the document. */
|
|
411
|
+
readonly pages: readonly Page[];
|
|
412
|
+
constructor(pages: readonly Page[]);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* The pages `operations` would delete from `document` although they must not
|
|
416
|
+
* be deleted: each page that a `page.remove` names while its `removable` is
|
|
417
|
+
* `false`. The operations are read in order, so a page counts as it is when
|
|
418
|
+
* its `page.remove` is reached: one that an earlier operation of the same
|
|
419
|
+
* list made removable (a `page.replace` without `removable`) is not listed,
|
|
420
|
+
* and one that an earlier operation made non-removable is. A `page.remove`
|
|
421
|
+
* of a page that does not exist is skipped here; applying it fails.
|
|
422
|
+
*
|
|
423
|
+
* `DocumentStore.dispatch` and `DocumentStore.preview` refuse a change for
|
|
424
|
+
* which this is not empty. `applyOperations` does not ask, because it also
|
|
425
|
+
* runs the inverse of an insertion when history is walked back.
|
|
426
|
+
* @since 0.29.0
|
|
427
|
+
*/
|
|
428
|
+
export declare function nonRemovablePagesRemovedBy(document: DesignDocument, operations: readonly DocumentOperation[]): readonly Page[];
|
|
429
|
+
/**
|
|
430
|
+
* Throws a `PageNotRemovableError` when `operations` would delete a page of
|
|
431
|
+
* `document` that must not be deleted (`nonRemovablePagesRemovedBy`).
|
|
432
|
+
* @since 0.29.0
|
|
433
|
+
*/
|
|
434
|
+
export declare function assertNoNonRemovablePageRemoved(document: DesignDocument, operations: readonly DocumentOperation[]): void;
|
|
435
|
+
/**
|
|
436
|
+
* Applies `operations` in order and returns the new document, the inverse
|
|
437
|
+
* operations, and a `ChangeSet`. It never changes the input.
|
|
438
|
+
*
|
|
439
|
+
* After the operations run, every group that contains a changed node, at any
|
|
440
|
+
* depth, is refitted to its children, and a group left with no children is removed; the inverse
|
|
441
|
+
* operations undo that too. A connector end attached to a node that is gone
|
|
442
|
+
* after that (a removed node, anything inside it, or such a group) becomes a
|
|
443
|
+
* free end at the `x` and `y` it has, so removing a connector's target is
|
|
444
|
+
* never refused; the inverse operations attach the end again. Then every changed node, and every instance of a
|
|
445
|
+
* component whose root's sizing changed, loses a stretching constraint
|
|
446
|
+
* (Left and right, Top and bottom, Scale) on an axis it hugs: it becomes
|
|
447
|
+
* Left or Top, and the inverse operations put it back. That is done only
|
|
448
|
+
* where the operations bring it: an axis of a node that already hugged and
|
|
449
|
+
* stretched in the input document (one stored before this rule) is left as
|
|
450
|
+
* the operations write it. The result is then
|
|
451
|
+
* validated. A document that
|
|
452
|
+
* is not frozen is first validated and copied with `snapshotDocument`.
|
|
453
|
+
*
|
|
454
|
+
* All or nothing: if any operation does not fit the document, or the result
|
|
455
|
+
* is invalid, it throws a `ModelError` and returns nothing.
|
|
456
|
+
*
|
|
457
|
+
* The last few results on frozen documents are kept, four in all, so the
|
|
458
|
+
* same operations applied to the same document again (`settle` previews an
|
|
459
|
+
* edit before the edit is applied) return the same frozen result without
|
|
460
|
+
* copying the node table again. The operations are read
|
|
461
|
+
* (`deserializeOperations`) before a kept result is looked for, so they are
|
|
462
|
+
* checked on every call, and a kept result is returned only for operations
|
|
463
|
+
* that read the same: the result depends on nothing else than the frozen
|
|
464
|
+
* document, the read operations and `options`, so it is the result the call
|
|
465
|
+
* would make.
|
|
466
|
+
*/
|
|
467
|
+
export declare function applyOperations(input: DesignDocument, operations: readonly DocumentOperation[], options?: ApplyOperationsOptions): ApplyOperationsResult;
|
|
468
|
+
/** How `applyOperations` makes its result. */
|
|
469
|
+
export interface ApplyOperationsOptions {
|
|
470
|
+
/**
|
|
471
|
+
* When every operation is a `node.replace` or a `node.patch`, the result's
|
|
472
|
+
* node table is not a copy of the input's: it reads the input's table for
|
|
473
|
+
* every node the operations did not write, so making it costs as much as
|
|
474
|
+
* the written nodes, not as much as the document. Meant for a short-lived
|
|
475
|
+
* document made again and again from one stored document, such as each
|
|
476
|
+
* step of a drag preview. The table is closed to writes, but it is a Proxy
|
|
477
|
+
* that `Object.isFrozen` does not report as frozen and that cannot be
|
|
478
|
+
* passed to `structuredClone`; listing all its entries (`Object.keys`, a
|
|
479
|
+
* spread) costs about twice as much as for a plain table. Other
|
|
480
|
+
* operations, which add or remove nodes, copy the table as usual.
|
|
481
|
+
*
|
|
482
|
+
* When left out, a document whose table is shared shares it again, so the
|
|
483
|
+
* views made from a preview step (`laidOut`) do not copy it either.
|
|
484
|
+
*/
|
|
485
|
+
readonly shareNodeTable?: boolean;
|
|
486
|
+
/**
|
|
487
|
+
* The operations come from editor code that moved nodes of the frozen
|
|
488
|
+
* input, such as each step of a drag preview. A `node.replace` whose node
|
|
489
|
+
* is the stored node with only its position changed (`frame.x` and `frame.y`, or the translation of a path's `transform`)
|
|
490
|
+
* (`differsInPositionOnly`: every other field the stored node's own value)
|
|
491
|
+
* has only those two numbers checked, when it is read and when the result
|
|
492
|
+
* is checked, instead of every field of the node, so a step costs as much
|
|
493
|
+
* as the fields it changes, not as much as the nodes it moves. The result
|
|
494
|
+
* is the one a full check gives. Every other operation is checked in
|
|
495
|
+
* full. Never set for operations read from an agent, a file, a paste or
|
|
496
|
+
* history; ignored for an input that is not frozen.
|
|
497
|
+
*/
|
|
498
|
+
readonly movedStoredNodes?: boolean;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* A sealed node table that reads as `nodes` with `written` put over it, and
|
|
502
|
+
* shares the entries of `nodes` (`sharedTableDraft`, in O(1) and the writes
|
|
503
|
+
* when `nodes` is a shared table), for a view laid out again from `nodes` by
|
|
504
|
+
* a few edits. The parents and whether it holds a group are taken from
|
|
505
|
+
* `nodes`, so those edits read no node they do not write; the parents only
|
|
506
|
+
* when no entry of `written` changes a list of children.
|
|
507
|
+
*
|
|
508
|
+
* With `ownFamily`, the table is a copy of every entry of `nodes` instead
|
|
509
|
+
* (`sharedTableCopy`), starting a family of its own: tables of two families
|
|
510
|
+
* are read by turns without moving each other's head.
|
|
511
|
+
*/
|
|
512
|
+
export declare function sharedNodeTable(nodes: DesignDocument["nodes"], written?: readonly (readonly [NodeId, SceneNode])[], ownFamily?: boolean): DesignDocument["nodes"];
|
|
513
|
+
/**
|
|
514
|
+
* A frozen node table that reads as `nodes` with `entries` put over it, in
|
|
515
|
+
* their order, for a view of a document that draws some nodes otherwise
|
|
516
|
+
* (such as an editor's workspace around a page). When `nodes` is shared
|
|
517
|
+
* (`ApplyOperationsOptions.shareNodeTable`), or `options.share` asks for it,
|
|
518
|
+
* the result reads `nodes` for every other entry and costs as much as
|
|
519
|
+
* `entries`; otherwise it is a frozen copy, as
|
|
520
|
+
* `Object.freeze({ ...nodes, ...entries })` makes. A shared table lists its
|
|
521
|
+
* entries one at a time (see `tableValues`), so share one that is read by ID.
|
|
522
|
+
*/
|
|
523
|
+
export declare function nodeTableWith(nodes: DesignDocument["nodes"], entries: Iterable<readonly [NodeId, SceneNode]>, options?: {
|
|
524
|
+
readonly share?: boolean;
|
|
525
|
+
}): DesignDocument["nodes"];
|
|
526
|
+
/**
|
|
527
|
+
* A frozen node table that reads as `nodes` with the entries of `written`
|
|
528
|
+
* put over it, reading `written` itself rather than a copy: it costs the
|
|
529
|
+
* same at any size of either, so a view of a document that draws many nodes
|
|
530
|
+
* otherwise (such as instances expanded into their layers) passes the same
|
|
531
|
+
* `written` again when an edit changed none of them. `written` must not
|
|
532
|
+
* change once passed. Read it by ID; listing every entry goes through a
|
|
533
|
+
* Proxy one entry at a time. With `sameParents`, the entries of `written`
|
|
534
|
+
* give no node a parent other than the one it has in `nodes` (none for a
|
|
535
|
+
* node `nodes` lacks), so the table keeps the parents of `nodes`
|
|
536
|
+
* (`parentMapOf`) instead of reading every node for them.
|
|
537
|
+
* @since 0.37.0
|
|
538
|
+
*/
|
|
539
|
+
export declare function nodeTableReading(nodes: DesignDocument["nodes"], written: NodeLookup, options?: {
|
|
540
|
+
readonly sameParents?: boolean;
|
|
541
|
+
}): DesignDocument["nodes"];
|
|
542
|
+
/**
|
|
543
|
+
* Nodes read by ID, for `nodeTableReading`: `get` gives undefined for an ID
|
|
544
|
+
* it lacks, and `keys` lists each ID it has once (read only when every entry
|
|
545
|
+
* of the table is listed).
|
|
546
|
+
* @since 0.37.0
|
|
547
|
+
*/
|
|
548
|
+
export interface NodeLookup {
|
|
549
|
+
get(id: NodeId): SceneNode | undefined;
|
|
550
|
+
keys(): Iterable<NodeId>;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* `document` with each of `nodes` in place of the node with its ID, and
|
|
554
|
+
* `addedAssets` added to its assets: what `{ ...document, nodes: { ...document.nodes, ...nodes },
|
|
555
|
+
* assets: { ...document.assets, ...addedAssets } }` makes. For a change made
|
|
556
|
+
* while a document opens, such as binding its text to this computer's fonts,
|
|
557
|
+
* that must not be an undo step or settle any layout.
|
|
558
|
+
*
|
|
559
|
+
* When `document` is known to be valid and frozen (from
|
|
560
|
+
* `deserializeCheckedDocument`, or an edit of such a document), only the
|
|
561
|
+
* written nodes and added assets, and the tree and references around them, are
|
|
562
|
+
* checked (`assertChangedDocument`), and the result is frozen and known to be
|
|
563
|
+
* valid too, so `new DocumentStore` takes it without checking it again. Any
|
|
564
|
+
* other document gets the same result without a check, unfrozen, and is
|
|
565
|
+
* checked in full when it opens.
|
|
566
|
+
*
|
|
567
|
+
* Throws a `ModelError` when a node is not in `document`, an added asset's ID
|
|
568
|
+
* is, or the result is not valid.
|
|
569
|
+
*/
|
|
570
|
+
export declare function writeOpeningChanges(document: DesignDocument, nodes: readonly SceneNode[], addedAssets?: readonly Asset[]): DesignDocument;
|
|
571
|
+
/**
|
|
572
|
+
* The IDs of every node whose entry can differ between two documents, read
|
|
573
|
+
* from the edits that made them (`applyOperations`, `recordDerivedNodes`)
|
|
574
|
+
* without reading any node; the list may hold nodes whose entry is the same
|
|
575
|
+
* object in both. Code that keeps an index per document can update it from
|
|
576
|
+
* these instead of comparing every node. Undefined when neither document
|
|
577
|
+
* came from the other or from a common document within a few recorded
|
|
578
|
+
* steps; the caller then reads the whole document.
|
|
579
|
+
* @since 0.33.0
|
|
580
|
+
*/
|
|
581
|
+
export declare function nodesChangedBetween(previous: DesignDocument, current: DesignDocument): ReadonlySet<NodeId> | undefined;
|
|
582
|
+
/**
|
|
583
|
+
* The IDs of every node that may have been inserted or removed on the way
|
|
584
|
+
* between two documents, a node removed and put back included (it then
|
|
585
|
+
* comes last in the node table's order), read from the edits that made them
|
|
586
|
+
* as `nodesChangedBetween` reads them. A node only written in place is left
|
|
587
|
+
* out, so code that keeps nodes in table order can keep its order when none
|
|
588
|
+
* of its nodes are listed. Where an edit kept no such record, every node it
|
|
589
|
+
* changed is listed. Undefined when `nodesChangedBetween` is.
|
|
590
|
+
* @since 0.35.0
|
|
591
|
+
*/
|
|
592
|
+
export declare function nodesInsertedOrRemovedBetween(previous: DesignDocument, current: DesignDocument): ReadonlySet<NodeId> | undefined;
|
|
593
|
+
/**
|
|
594
|
+
* Records that the frozen document `derived` holds the node entries of
|
|
595
|
+
* `base`, the very same objects, at every ID except `changedNodeIds`. Code
|
|
596
|
+
* that builds a document from another outside `applyOperations` (such as a
|
|
597
|
+
* renderer view that swaps a few nodes for drawn stand-ins) calls this so
|
|
598
|
+
* that `diffDocuments` reads only those nodes when it compares documents
|
|
599
|
+
* built this way, as it does for edits. When a parent table is kept for
|
|
600
|
+
* `base`, the table of `derived` is derived from it too, reading only those
|
|
601
|
+
* nodes and their children. Listing too few nodes makes later diffs miss
|
|
602
|
+
* changes; nothing is recorded when `derived` is not frozen.
|
|
603
|
+
*/
|
|
604
|
+
export declare function recordDerivedNodes(derived: DesignDocument, base: DesignDocument, changedNodeIds: readonly NodeId[]): void;
|
|
605
|
+
/**
|
|
606
|
+
* Works out the `ChangeSet` between two valid documents, for changes that
|
|
607
|
+
* did not come from `applyOperations` (such as undo or checkout in
|
|
608
|
+
* `DocumentStore`). Parts shared by identity are skipped without reading.
|
|
609
|
+
*/
|
|
610
|
+
export declare function diffDocuments(previous: DesignDocument, current: DesignDocument): ChangeSet;
|