@moondraft/import 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +34 -0
- package/README.md +36 -2
- package/SOURCE.md +169 -0
- package/dist/adapter/convert.d.ts +122 -0
- package/dist/adapter/convert.js +2302 -0
- package/dist/adapter/figma.d.ts +9 -0
- package/dist/adapter/figma.js +30 -0
- package/dist/adapter/file-components.d.ts +14 -0
- package/dist/adapter/file-components.js +262 -0
- package/dist/adapter/file-resources.d.ts +29 -0
- package/dist/adapter/file-resources.js +562 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.js +9 -0
- package/dist/adapter/link.d.ts +45 -0
- package/dist/adapter/link.js +688 -0
- package/dist/adapter/payload.d.ts +31 -0
- package/dist/adapter/payload.js +78 -0
- package/dist/adapter/shapes.d.ts +31 -0
- package/dist/adapter/shapes.js +75 -0
- package/dist/adapter/variables.d.ts +44 -0
- package/dist/adapter/variables.js +103 -0
- package/dist/figma-file.d.ts +38 -0
- package/dist/figma-file.js +97 -0
- package/dist/figma-worker.d.ts +11 -0
- package/dist/figma-worker.js +12 -0
- package/dist/figma.d.ts +26 -0
- package/dist/figma.js +96 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +49 -0
- package/dist/report.d.ts +15 -0
- package/dist/report.js +69 -0
- package/dist/svg.d.ts +33 -0
- package/dist/svg.js +44 -0
- package/dist/syntax.d.ts +8 -0
- package/dist/syntax.js +19 -0
- package/dist/taco/figma-import/clipboard.d.ts +25 -0
- package/dist/taco/figma-import/clipboard.js +87 -0
- package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
- package/dist/taco/figma-import/clipboardSize.js +107 -0
- package/dist/taco/figma-import/container/compression.d.ts +9 -0
- package/dist/taco/figma-import/container/compression.js +174 -0
- package/dist/taco/figma-import/container/error.d.ts +15 -0
- package/dist/taco/figma-import/container/error.js +19 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
- package/dist/taco/figma-import/container/limits.d.ts +22 -0
- package/dist/taco/figma-import/container/limits.js +22 -0
- package/dist/taco/figma-import/container/zip.d.ts +14 -0
- package/dist/taco/figma-import/container/zip.js +154 -0
- package/dist/taco/figma-import/figFile.d.ts +34 -0
- package/dist/taco/figma-import/figFile.js +91 -0
- package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
- package/dist/taco/figma-import/figFileDocument.js +100 -0
- package/dist/taco/figma-import/import/blobs.d.ts +10 -0
- package/dist/taco/figma-import/import/blobs.js +23 -0
- package/dist/taco/figma-import/import/carry.d.ts +11 -0
- package/dist/taco/figma-import/import/carry.js +33 -0
- package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
- package/dist/taco/figma-import/import/componentProps.js +313 -0
- package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
- package/dist/taco/figma-import/import/componentSets.js +647 -0
- package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
- package/dist/taco/figma-import/import/converters/effects.js +127 -0
- package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
- package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/frame.js +55 -0
- package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
- package/dist/taco/figma-import/import/converters/gradient.js +106 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/group.js +39 -0
- package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
- package/dist/taco/figma-import/import/converters/image.js +83 -0
- package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
- package/dist/taco/figma-import/import/converters/layout.js +168 -0
- package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
- package/dist/taco/figma-import/import/converters/line.js +40 -0
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
- package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
- package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
- package/dist/taco/figma-import/import/converters/section.js +35 -0
- package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
- package/dist/taco/figma-import/import/converters/shared.js +362 -0
- package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
- package/dist/taco/figma-import/import/converters/text.js +576 -0
- package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
- package/dist/taco/figma-import/import/converters/vector.js +468 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
- package/dist/taco/figma-import/import/fields.d.ts +15 -0
- package/dist/taco/figma-import/import/fields.js +29 -0
- package/dist/taco/figma-import/import/instances.d.ts +163 -0
- package/dist/taco/figma-import/import/instances.js +1323 -0
- package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
- package/dist/taco/figma-import/import/nestingCycles.js +488 -0
- package/dist/taco/figma-import/import/slots.d.ts +56 -0
- package/dist/taco/figma-import/import/slots.js +96 -0
- package/dist/taco/figma-import/import/styles.d.ts +46 -0
- package/dist/taco/figma-import/import/styles.js +42 -0
- package/dist/taco/figma-import/import/tree.d.ts +66 -0
- package/dist/taco/figma-import/import/tree.js +194 -0
- package/dist/taco/figma-import/import/types.d.ts +232 -0
- package/dist/taco/figma-import/import/types.js +33 -0
- package/dist/taco/figma-import/import/variables.d.ts +136 -0
- package/dist/taco/figma-import/import/variables.js +762 -0
- package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
- package/dist/taco/figma-import/import/variantTrees.js +480 -0
- package/dist/taco/figma-import/import/walk.d.ts +159 -0
- package/dist/taco/figma-import/import/walk.js +1297 -0
- package/dist/taco/figma-import/index.d.ts +22 -0
- package/dist/taco/figma-import/index.js +13 -0
- package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
- package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
- package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
- package/dist/taco/figma-import/kiwi/error.js +29 -0
- package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
- package/dist/taco/figma-import/kiwi/limits.js +18 -0
- package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
- package/dist/taco/figma-import/kiwi/message.js +145 -0
- package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
- package/dist/taco/figma-import/kiwi/schema.js +206 -0
- package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
- package/dist/taco/figma-import/kiwi/types.js +18 -0
- package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
- package/dist/taco/model/agent-hidden-fields.js +29 -0
- package/dist/taco/model/asset-users.d.ts +23 -0
- package/dist/taco/model/asset-users.js +128 -0
- package/dist/taco/model/auto-layout-lines.d.ts +32 -0
- package/dist/taco/model/auto-layout-lines.js +70 -0
- package/dist/taco/model/codec.d.ts +444 -0
- package/dist/taco/model/codec.js +5635 -0
- package/dist/taco/model/color.d.ts +11 -0
- package/dist/taco/model/color.js +61 -0
- package/dist/taco/model/comment-operations.d.ts +102 -0
- package/dist/taco/model/comment-operations.js +227 -0
- package/dist/taco/model/component-evaluation.d.ts +94 -0
- package/dist/taco/model/component-evaluation.js +548 -0
- package/dist/taco/model/component-expressions.d.ts +242 -0
- package/dist/taco/model/component-expressions.js +1082 -0
- package/dist/taco/model/component-properties.d.ts +111 -0
- package/dist/taco/model/component-properties.js +339 -0
- package/dist/taco/model/component-samples.d.ts +83 -0
- package/dist/taco/model/component-samples.js +290 -0
- package/dist/taco/model/component-validity.d.ts +85 -0
- package/dist/taco/model/component-validity.js +397 -0
- package/dist/taco/model/components.d.ts +155 -0
- package/dist/taco/model/components.js +505 -0
- package/dist/taco/model/connector-ends.d.ts +20 -0
- package/dist/taco/model/connector-ends.js +188 -0
- package/dist/taco/model/connector-geometry.d.ts +74 -0
- package/dist/taco/model/connector-geometry.js +293 -0
- package/dist/taco/model/corner-radii.d.ts +26 -0
- package/dist/taco/model/corner-radii.js +47 -0
- package/dist/taco/model/derivations.d.ts +81 -0
- package/dist/taco/model/derivations.js +151 -0
- package/dist/taco/model/export-settings.d.ts +53 -0
- package/dist/taco/model/export-settings.js +156 -0
- package/dist/taco/model/expressions/ast.d.ts +153 -0
- package/dist/taco/model/expressions/ast.js +6 -0
- package/dist/taco/model/expressions/cache.d.ts +23 -0
- package/dist/taco/model/expressions/cache.js +43 -0
- package/dist/taco/model/expressions/check.d.ts +72 -0
- package/dist/taco/model/expressions/check.js +517 -0
- package/dist/taco/model/expressions/completion.d.ts +61 -0
- package/dist/taco/model/expressions/completion.js +421 -0
- package/dist/taco/model/expressions/evaluate.d.ts +32 -0
- package/dist/taco/model/expressions/evaluate.js +519 -0
- package/dist/taco/model/expressions/forms.d.ts +84 -0
- package/dist/taco/model/expressions/forms.js +200 -0
- package/dist/taco/model/expressions/index.d.ts +14 -0
- package/dist/taco/model/expressions/index.js +17 -0
- package/dist/taco/model/expressions/lexer.d.ts +42 -0
- package/dist/taco/model/expressions/lexer.js +213 -0
- package/dist/taco/model/expressions/library.d.ts +33 -0
- package/dist/taco/model/expressions/library.js +117 -0
- package/dist/taco/model/expressions/names.d.ts +43 -0
- package/dist/taco/model/expressions/names.js +99 -0
- package/dist/taco/model/expressions/parser.d.ts +15 -0
- package/dist/taco/model/expressions/parser.js +438 -0
- package/dist/taco/model/expressions/rename.d.ts +34 -0
- package/dist/taco/model/expressions/rename.js +46 -0
- package/dist/taco/model/expressions/source.d.ts +15 -0
- package/dist/taco/model/expressions/source.js +161 -0
- package/dist/taco/model/expressions/types.d.ts +119 -0
- package/dist/taco/model/expressions/types.js +102 -0
- package/dist/taco/model/expressions/values.d.ts +97 -0
- package/dist/taco/model/expressions/values.js +160 -0
- package/dist/taco/model/geometry-limits.d.ts +16 -0
- package/dist/taco/model/geometry-limits.js +67 -0
- package/dist/taco/model/geometry.d.ts +47 -0
- package/dist/taco/model/geometry.js +193 -0
- package/dist/taco/model/group-bounds.d.ts +38 -0
- package/dist/taco/model/group-bounds.js +144 -0
- package/dist/taco/model/id-table.d.ts +37 -0
- package/dist/taco/model/id-table.js +80 -0
- package/dist/taco/model/index.d.ts +25 -0
- package/dist/taco/model/index.js +27 -0
- package/dist/taco/model/instance-resolver.d.ts +372 -0
- package/dist/taco/model/instance-resolver.js +1748 -0
- package/dist/taco/model/layer-syntax.d.ts +340 -0
- package/dist/taco/model/layer-syntax.js +3506 -0
- package/dist/taco/model/layout/constraints.d.ts +84 -0
- package/dist/taco/model/layout/constraints.js +445 -0
- package/dist/taco/model/layout/frame-layout.d.ts +46 -0
- package/dist/taco/model/layout/frame-layout.js +618 -0
- package/dist/taco/model/layout/node-sizing.d.ts +163 -0
- package/dist/taco/model/layout/node-sizing.js +486 -0
- package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
- package/dist/taco/model/legacy-connector-caps.js +70 -0
- package/dist/taco/model/linear-call.d.ts +48 -0
- package/dist/taco/model/linear-call.js +58 -0
- package/dist/taco/model/new-nodes.d.ts +145 -0
- package/dist/taco/model/new-nodes.js +277 -0
- package/dist/taco/model/node-builder.d.ts +449 -0
- package/dist/taco/model/node-builder.js +2294 -0
- package/dist/taco/model/node-table-watch.d.ts +36 -0
- package/dist/taco/model/node-table-watch.js +63 -0
- package/dist/taco/model/node-transform.d.ts +39 -0
- package/dist/taco/model/node-transform.js +79 -0
- package/dist/taco/model/node-users-index.d.ts +10 -0
- package/dist/taco/model/node-users-index.js +82 -0
- package/dist/taco/model/operation-references.d.ts +80 -0
- package/dist/taco/model/operation-references.js +399 -0
- package/dist/taco/model/operations.d.ts +610 -0
- package/dist/taco/model/operations.js +2882 -0
- package/dist/taco/model/overlay-table.d.ts +71 -0
- package/dist/taco/model/overlay-table.js +171 -0
- package/dist/taco/model/override-remap.d.ts +69 -0
- package/dist/taco/model/override-remap.js +230 -0
- package/dist/taco/model/parent-table.d.ts +53 -0
- package/dist/taco/model/parent-table.js +193 -0
- package/dist/taco/model/problem-collector.d.ts +27 -0
- package/dist/taco/model/problem-collector.js +101 -0
- package/dist/taco/model/sha256.d.ts +10 -0
- package/dist/taco/model/sha256.js +74 -0
- package/dist/taco/model/shape-geometry.d.ts +96 -0
- package/dist/taco/model/shape-geometry.js +368 -0
- package/dist/taco/model/shared-node-table.d.ts +97 -0
- package/dist/taco/model/shared-node-table.js +546 -0
- package/dist/taco/model/slots.d.ts +113 -0
- package/dist/taco/model/slots.js +281 -0
- package/dist/taco/model/stroke-settings.d.ts +37 -0
- package/dist/taco/model/stroke-settings.js +90 -0
- package/dist/taco/model/svg-path-import.d.ts +89 -0
- package/dist/taco/model/svg-path-import.js +219 -0
- package/dist/taco/model/text-measurement.d.ts +142 -0
- package/dist/taco/model/text-measurement.js +846 -0
- package/dist/taco/model/text-reads.d.ts +66 -0
- package/dist/taco/model/text-reads.js +128 -0
- package/dist/taco/model/text-sizer.d.ts +358 -0
- package/dist/taco/model/text-sizer.js +996 -0
- package/dist/taco/model/theme-users.d.ts +59 -0
- package/dist/taco/model/theme-users.js +312 -0
- package/dist/taco/model/thumbnail.d.ts +15 -0
- package/dist/taco/model/thumbnail.js +34 -0
- package/dist/taco/model/types.d.ts +2347 -0
- package/dist/taco/model/types.js +366 -0
- package/dist/taco/model/unknown-property.d.ts +5 -0
- package/dist/taco/model/unknown-property.js +7 -0
- package/dist/taco/model/validated-documents.d.ts +22 -0
- package/dist/taco/model/validated-documents.js +22 -0
- package/dist/taco/model/variable-modes.d.ts +61 -0
- package/dist/taco/model/variable-modes.js +438 -0
- package/dist/taco/model/variable-references.d.ts +54 -0
- package/dist/taco/model/variable-references.js +183 -0
- package/dist/taco/model/variables.d.ts +24 -0
- package/dist/taco/model/variables.js +151 -0
- package/dist/taco/model/vector-network.d.ts +34 -0
- package/dist/taco/model/vector-network.js +411 -0
- package/dist/taco/svg-import/import-svg.d.ts +36 -0
- package/dist/taco/svg-import/import-svg.js +729 -0
- package/dist/taco/svg-import/index.d.ts +3 -0
- package/dist/taco/svg-import/index.js +3 -0
- package/dist/taco/svg-import/limits/limits.d.ts +79 -0
- package/dist/taco/svg-import/limits/limits.js +160 -0
- package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
- package/dist/taco/svg-import/paint/gradients.js +429 -0
- package/dist/taco/svg-import/paint/paint.d.ts +32 -0
- package/dist/taco/svg-import/paint/paint.js +162 -0
- package/dist/taco/svg-import/paths/paths.d.ts +58 -0
- package/dist/taco/svg-import/paths/paths.js +205 -0
- package/dist/taco/svg-import/public-types.d.ts +279 -0
- package/dist/taco/svg-import/public-types.js +56 -0
- package/dist/taco/svg-import/report/report.d.ts +44 -0
- package/dist/taco/svg-import/report/report.js +79 -0
- package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
- package/dist/taco/svg-import/reuse/reuse.js +840 -0
- package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
- package/dist/taco/svg-import/shapes/shapes.js +386 -0
- package/dist/taco/svg-import/structure/effects.d.ts +26 -0
- package/dist/taco/svg-import/structure/effects.js +618 -0
- package/dist/taco/svg-import/structure/image.d.ts +24 -0
- package/dist/taco/svg-import/structure/image.js +495 -0
- package/dist/taco/svg-import/structure/walk.d.ts +85 -0
- package/dist/taco/svg-import/structure/walk.js +544 -0
- package/dist/taco/svg-import/style/color.d.ts +40 -0
- package/dist/taco/svg-import/style/color.js +275 -0
- package/dist/taco/svg-import/style/computed.d.ts +214 -0
- package/dist/taco/svg-import/style/computed.js +1534 -0
- package/dist/taco/svg-import/style/css.d.ts +127 -0
- package/dist/taco/svg-import/style/css.js +541 -0
- package/dist/taco/svg-import/style/media.d.ts +25 -0
- package/dist/taco/svg-import/style/media.js +307 -0
- package/dist/taco/svg-import/style/properties.d.ts +43 -0
- package/dist/taco/svg-import/style/properties.js +135 -0
- package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
- package/dist/taco/svg-import/style/selector-reach.js +169 -0
- package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
- package/dist/taco/svg-import/style/selector-validity.js +307 -0
- package/dist/taco/svg-import/text/text.d.ts +29 -0
- package/dist/taco/svg-import/text/text.js +545 -0
- package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
- package/dist/taco/svg-import/transform/matrix.js +229 -0
- package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
- package/dist/taco/svg-import/tree/element-data.js +155 -0
- package/dist/taco/svg-import/tree/elements.d.ts +36 -0
- package/dist/taco/svg-import/tree/elements.js +121 -0
- package/dist/taco/svg-import/units/length.d.ts +43 -0
- package/dist/taco/svg-import/units/length.js +125 -0
- package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
- package/dist/taco/svg-import/units/viewbox.js +77 -0
- package/package.json +54 -4
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { type AutoLayout, type DesignDocument, type FrameNode, type NodeId, type NodeResizing, type SceneNode } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* How a node is sized on one axis, as the width and height menus show it
|
|
4
|
+
* (Figma's resizing menu): a stored size, its content's size, or the space its
|
|
5
|
+
* auto layout parent gives it.
|
|
6
|
+
*/
|
|
7
|
+
export type AxisSizing = "fixed" | "hug" | "fill";
|
|
8
|
+
/** The axis a sizing applies to. */
|
|
9
|
+
export type SizingAxis = "width" | "height";
|
|
10
|
+
type AutoLayoutFrame = FrameNode & {
|
|
11
|
+
readonly layout: AutoLayout;
|
|
12
|
+
};
|
|
13
|
+
/** Whether the node is a frame with a stack or grid auto layout. */
|
|
14
|
+
export declare function isAutoLayoutFrame(node: SceneNode | undefined): node is AutoLayoutFrame;
|
|
15
|
+
/** The container that holds the node, or `undefined` for a page's top level node. */
|
|
16
|
+
export declare function parentNodeOf(document: DesignDocument, nodeId: NodeId): SceneNode | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The node's sizing on an axis: the one reader of it. Nodes that cannot hug
|
|
19
|
+
* or fill are Fixed. An auto layout frame's is its layout's; text and code
|
|
20
|
+
* read their automatic sizing. An instance has no layout of its own: its
|
|
21
|
+
* sizing is its override of its component root's sizing
|
|
22
|
+
* (`LayerSizingOverride`, stored under the root's path), and the root's own
|
|
23
|
+
* sizing where it has none, which is what the instance resolver lays it out
|
|
24
|
+
* with. Fill is the node's own `resizing` for every kind of node.
|
|
25
|
+
*/
|
|
26
|
+
export declare function nodeAxisSizing(document: DesignDocument, node: SceneNode, axis: SizingAxis): AxisSizing;
|
|
27
|
+
/**
|
|
28
|
+
* Auto layout frames hug their children, text and code blocks hug their
|
|
29
|
+
* content, and an instance hugs as its component root does: only when the
|
|
30
|
+
* root has auto layout.
|
|
31
|
+
*/
|
|
32
|
+
export declare function canHugAxis(document: DesignDocument, node: SceneNode): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the node can fill its parent on an axis: it must be a child of an
|
|
35
|
+
* auto layout frame, and not a path, group or connector, a rotated node, or
|
|
36
|
+
* (for the height) a line, whose height is always zero. Figma offers Fill
|
|
37
|
+
* container only on children of auto layout frames.
|
|
38
|
+
*/
|
|
39
|
+
export declare function canFillAxis(document: DesignDocument, node: SceneNode, axis: SizingAxis, parent?: SceneNode | undefined): boolean;
|
|
40
|
+
/** The node without a Fill flag on the axis. */
|
|
41
|
+
export declare function withoutFill(node: SceneNode, axis: SizingAxis): SceneNode;
|
|
42
|
+
/** The node without any Fill flag, keeping its size limits. */
|
|
43
|
+
export declare function withoutAnyFill(node: SceneNode): SceneNode;
|
|
44
|
+
/**
|
|
45
|
+
* The node with its sizing on `axis` set to Fixed or Hug: the one writer of
|
|
46
|
+
* it, the counterpart of `nodeAxisSizing`. An auto layout frame stores it in
|
|
47
|
+
* its layout; an instance stores it as its override of its component root's
|
|
48
|
+
* sizing. A node that has neither (a shape, a frame without auto layout, an
|
|
49
|
+
* instance of a component without auto layout) is returned as it is, and so
|
|
50
|
+
* is text or code, whose automatic sizing has rules of its own
|
|
51
|
+
* (`sizingReplacements`). Fill is not touched: see `withoutFill`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function withAxisSizing(document: DesignDocument, node: SceneNode, axis: SizingAxis, sizing: "fixed" | "hug"): SceneNode;
|
|
54
|
+
/**
|
|
55
|
+
* How a layer's size was changed by hand, as opposed to by a layout, a
|
|
56
|
+
* constraint or its content:
|
|
57
|
+
*
|
|
58
|
+
* - `"resize"`: a resize handle, a typed W or H, the box around a selection,
|
|
59
|
+
* a moved end of a line.
|
|
60
|
+
* - `"scale"`: the Scale tool, on one layer or on the box around a selection.
|
|
61
|
+
* - `"variable"`: a size variable bound to W or H.
|
|
62
|
+
*/
|
|
63
|
+
export type ManualSizeChange = "resize" | "scale" | "variable";
|
|
64
|
+
/**
|
|
65
|
+
* `after`, the node `before` with a size changed by hand, with the sizing
|
|
66
|
+
* that change leaves: the one place the rule "a size set by hand is kept" is
|
|
67
|
+
* written. Every command that changes a size by hand, and every preview of
|
|
68
|
+
* one, passes its node through here, so the release commits what the drag
|
|
69
|
+
* drew and the next layout does not undo it.
|
|
70
|
+
*
|
|
71
|
+
* - A resize, on each axis whose size changed: Fill and Hug become Fixed
|
|
72
|
+
* (an instance's Hug too) and a size variable on the axis is dropped.
|
|
73
|
+
* - The Scale tool, on each axis whose size changed: an instance's Hug
|
|
74
|
+
* becomes Fixed, since its layers are its component's and do not scale. A
|
|
75
|
+
* frame keeps Hug: its children scaled with it, so it hugs the scaled
|
|
76
|
+
* size. Fill and a size variable are left as they are.
|
|
77
|
+
* - A size variable: Fill and Hug become Fixed on `axes`, which the caller
|
|
78
|
+
* names because the variable's value may equal the size the node has.
|
|
79
|
+
*
|
|
80
|
+
* A size that a layout, a constraint or the node's content gives is not a
|
|
81
|
+
* change by hand and does not come here: the sizing stays.
|
|
82
|
+
*/
|
|
83
|
+
export declare function withManualSize(document: DesignDocument, before: SceneNode, after: SceneNode, change: ManualSizeChange, axes?: readonly SizingAxis[]): SceneNode;
|
|
84
|
+
/**
|
|
85
|
+
* `nodes`, the output of a resize or a scale of layers of `document`, each
|
|
86
|
+
* passed through `withManualSize` against the node it replaces. `only`
|
|
87
|
+
* limits the rule to the layers the user changed, where the others were
|
|
88
|
+
* only carried along (the descendants of a resized group or selection).
|
|
89
|
+
*/
|
|
90
|
+
export declare function withManualSizes(document: DesignDocument, nodes: readonly SceneNode[], change: ManualSizeChange, only?: ReadonlySet<NodeId>): readonly SceneNode[];
|
|
91
|
+
/**
|
|
92
|
+
* The nodes that change when `nodeIds` are set to `sizing` on `axis`, by id.
|
|
93
|
+
* Nodes that cannot take that sizing are left out.
|
|
94
|
+
*
|
|
95
|
+
* An instance follows every rule here as an auto layout frame does, through
|
|
96
|
+
* `nodeAxisSizing` and `withAxisSizing`, except the last part of the Hug
|
|
97
|
+
* rule: its layers are its component's, so their Fill is not changed.
|
|
98
|
+
*
|
|
99
|
+
* - Fill turns the node's own Hug on the axis into Fixed (text and code stop
|
|
100
|
+
* sizing that axis to their content), drops a size variable on the axis, and
|
|
101
|
+
* turns a hugging stack parent Fixed on the axis, as Figma does: "If any
|
|
102
|
+
* child objects within an auto layout frame are set to Fill container, the
|
|
103
|
+
* parent frame will no longer hug contents and become Fixed for the axis."
|
|
104
|
+
* - Hug on an auto layout frame turns its stack children that fill the axis
|
|
105
|
+
* into Fixed. A grid keeps its Fill children: they take their cell.
|
|
106
|
+
* - Fixed and Hug drop the node's own Fill on the axis.
|
|
107
|
+
*
|
|
108
|
+
* Hug leaves a stretching constraint on the axis for `applyOperations` to
|
|
109
|
+
* turn into Left or Top, as it does after every edit
|
|
110
|
+
* (`stretchWhereHuggingReplacements`).
|
|
111
|
+
*/
|
|
112
|
+
export declare function sizingReplacements(document: DesignDocument, nodeIds: readonly NodeId[], axis: SizingAxis, sizing: AxisSizing): ReadonlyMap<NodeId, SceneNode>;
|
|
113
|
+
/**
|
|
114
|
+
* The node without a stretching constraint on an axis it hugs: what the
|
|
115
|
+
* rule "no node hugs and stretches on the same axis" does to one node.
|
|
116
|
+
* Commands do not call it; `stretchWhereHuggingReplacements` applies the
|
|
117
|
+
* rule to every edit, on the axes the edit brings to break it.
|
|
118
|
+
*/
|
|
119
|
+
export declare function withoutStretchWhereHugging(document: DesignDocument, node: SceneNode): SceneNode;
|
|
120
|
+
/**
|
|
121
|
+
* The one place the rule "no node has a stretching constraint (Left and
|
|
122
|
+
* right, Top and bottom, Scale) on an axis whose sizing is Hug" is
|
|
123
|
+
* enforced. `applyOperations` calls it for every batch of operations, so
|
|
124
|
+
* every command, preview, paste, undo-able edit and replayed commit passes
|
|
125
|
+
* through it and no command applies the rule itself.
|
|
126
|
+
*
|
|
127
|
+
* `next` is `previous` after the batch and `changedNodeIds` the nodes the
|
|
128
|
+
* batch wrote. The nodes looked at are the ones whose sizing or constraints
|
|
129
|
+
* can have changed:
|
|
130
|
+
*
|
|
131
|
+
* - every changed node that still exists (its own layout, automatic text
|
|
132
|
+
* sizing, overrides, component or constraints may be new);
|
|
133
|
+
* - every instance, at any depth and on any page or inside any component,
|
|
134
|
+
* of a component whose root or root sizing changed. An instance with a
|
|
135
|
+
* sizing override on the axis keeps its own sizing, so only the ones that
|
|
136
|
+
* follow the component can lose a constraint.
|
|
137
|
+
*
|
|
138
|
+
* Only a break of the rule that the batch brings is removed: an axis of a
|
|
139
|
+
* node that hugs and stretches in `next` and did not in `previous` (the
|
|
140
|
+
* node is new, or it kept the rule on that axis there). A node that already
|
|
141
|
+
* hugged and stretched on an axis in `previous`, as a document stored
|
|
142
|
+
* before the rule existed can hold, is left on that axis exactly as the
|
|
143
|
+
* batch leaves it, so a batch that does not touch the break, or keeps it,
|
|
144
|
+
* can be reversed exactly.
|
|
145
|
+
*
|
|
146
|
+
* Returned are those nodes, each with the stretching constraint turned into
|
|
147
|
+
* Left or Top on the axes that newly break the rule, in a stable order (the
|
|
148
|
+
* batch's own, then the document's). The sizing is never changed here, so
|
|
149
|
+
* one pass is enough. The cost is two sizing reads per changed node, two
|
|
150
|
+
* more for one that breaks the rule, and one comparison per component; the
|
|
151
|
+
* walk over every node of the document happens only for a batch that
|
|
152
|
+
* changed a component root's sizing.
|
|
153
|
+
*/
|
|
154
|
+
export declare function stretchWhereHuggingReplacements(previous: DesignDocument, next: DesignDocument, changedNodeIds: ReadonlySet<NodeId>): readonly SceneNode[];
|
|
155
|
+
/** The document with `nodes` replacing their stored versions. */
|
|
156
|
+
export declare function documentWithNodes(document: DesignDocument, nodes: ReadonlyMap<NodeId, SceneNode>): DesignDocument;
|
|
157
|
+
/**
|
|
158
|
+
* The nodes that change when a node's Fill flags and size limits are replaced
|
|
159
|
+
* with `resizing` (`undefined` removes them all). A newly set Fill follows the
|
|
160
|
+
* same rules as choosing Fill container in the sizing menu.
|
|
161
|
+
*/
|
|
162
|
+
export declare function resizingReplacements(document: DesignDocument, nodeId: NodeId, resizing: NodeResizing | undefined): ReadonlyMap<NodeId, SceneNode>;
|
|
163
|
+
export {};
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { findComponentByRoot, layerPathKey } from "../components.js";
|
|
2
|
+
import { isContainerNode, } from "../types.js";
|
|
3
|
+
import { isFrozenNodeMap } from "../derivations.js";
|
|
4
|
+
import { parentMapOf } from "../group-bounds.js";
|
|
5
|
+
import { entryOf } from "../id-table.js";
|
|
6
|
+
import { tableValues } from "../shared-node-table.js";
|
|
7
|
+
/** Whether the node is a frame with a stack or grid auto layout. */
|
|
8
|
+
export function isAutoLayoutFrame(node) {
|
|
9
|
+
return node?.type === "frame" && node.layout.kind !== "absolute";
|
|
10
|
+
}
|
|
11
|
+
function isStackFrame(node) {
|
|
12
|
+
return node?.type === "frame" && (node.layout.kind === "horizontal" || node.layout.kind === "vertical");
|
|
13
|
+
}
|
|
14
|
+
/** The container that holds the node, or `undefined` for a page's top level node. */
|
|
15
|
+
export function parentNodeOf(document, nodeId) {
|
|
16
|
+
// A frozen record keeps one parent table (see `parentMapOf`); a record that
|
|
17
|
+
// can still change is searched.
|
|
18
|
+
if (isFrozenNodeMap(document.nodes)) {
|
|
19
|
+
const parentId = parentMapOf(document.nodes).get(nodeId);
|
|
20
|
+
return parentId === undefined ? undefined : entryOf(document.nodes, parentId);
|
|
21
|
+
}
|
|
22
|
+
return tableValues(document.nodes).find((candidate) => (isContainerNode(candidate) && candidate.children.includes(nodeId)));
|
|
23
|
+
}
|
|
24
|
+
function sizingKey(axis) {
|
|
25
|
+
return axis === "width" ? "widthSizing" : "heightSizing";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The auto layout frame an instance takes its Fixed or Hug sizing from: its
|
|
29
|
+
* component's root. `undefined` for a component without auto layout (its
|
|
30
|
+
* instances are always Fixed) and for an instance whose component is missing.
|
|
31
|
+
*/
|
|
32
|
+
function instanceSizingRoot(document, instance) {
|
|
33
|
+
const rootId = entryOf(document.components, instance.componentId)?.rootId;
|
|
34
|
+
const root = rootId === undefined ? undefined : entryOf(document.nodes, rootId);
|
|
35
|
+
return isAutoLayoutFrame(root) ? root : undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The node's sizing on an axis: the one reader of it. Nodes that cannot hug
|
|
39
|
+
* or fill are Fixed. An auto layout frame's is its layout's; text and code
|
|
40
|
+
* read their automatic sizing. An instance has no layout of its own: its
|
|
41
|
+
* sizing is its override of its component root's sizing
|
|
42
|
+
* (`LayerSizingOverride`, stored under the root's path), and the root's own
|
|
43
|
+
* sizing where it has none, which is what the instance resolver lays it out
|
|
44
|
+
* with. Fill is the node's own `resizing` for every kind of node.
|
|
45
|
+
*/
|
|
46
|
+
export function nodeAxisSizing(document, node, axis) {
|
|
47
|
+
if ("resizing" in node && node.resizing?.[axis] === "fill")
|
|
48
|
+
return "fill";
|
|
49
|
+
if (node.type === "instance") {
|
|
50
|
+
const root = instanceSizingRoot(document, node);
|
|
51
|
+
if (root === undefined)
|
|
52
|
+
return "fixed";
|
|
53
|
+
// Fill under the root's path has no effect: an instance fills through its own `resizing`.
|
|
54
|
+
const own = entryOf(node.overrides, layerPathKey([root.id]))?.sizing?.[axis];
|
|
55
|
+
return own === undefined || own === "fill" ? root.layout[sizingKey(axis)] : own;
|
|
56
|
+
}
|
|
57
|
+
if (isAutoLayoutFrame(node))
|
|
58
|
+
return node.layout[sizingKey(axis)];
|
|
59
|
+
if (node.type === "text" || node.type === "code") {
|
|
60
|
+
if (axis === "width")
|
|
61
|
+
return node.autoResize === "width-and-height" ? "hug" : "fixed";
|
|
62
|
+
return node.autoResize === "none" ? "fixed" : "hug";
|
|
63
|
+
}
|
|
64
|
+
return "fixed";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Auto layout frames hug their children, text and code blocks hug their
|
|
68
|
+
* content, and an instance hugs as its component root does: only when the
|
|
69
|
+
* root has auto layout.
|
|
70
|
+
*/
|
|
71
|
+
export function canHugAxis(document, node) {
|
|
72
|
+
if (node.type === "instance")
|
|
73
|
+
return instanceSizingRoot(document, node) !== undefined;
|
|
74
|
+
return isAutoLayoutFrame(node) || node.type === "text" || node.type === "code";
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Whether the node can fill its parent on an axis: it must be a child of an
|
|
78
|
+
* auto layout frame, and not a path, group or connector, a rotated node, or
|
|
79
|
+
* (for the height) a line, whose height is always zero. Figma offers Fill
|
|
80
|
+
* container only on children of auto layout frames.
|
|
81
|
+
*/
|
|
82
|
+
export function canFillAxis(document, node, axis, parent = parentNodeOf(document, node.id)) {
|
|
83
|
+
if (!isAutoLayoutFrame(parent))
|
|
84
|
+
return false;
|
|
85
|
+
if (node.type === "group" || node.type === "connector")
|
|
86
|
+
return false;
|
|
87
|
+
if (node.type === "shape" && node.shape === "path")
|
|
88
|
+
return false;
|
|
89
|
+
if (node.type === "shape" && node.shape === "line" && axis === "height")
|
|
90
|
+
return false;
|
|
91
|
+
return node.rotation % 360 === 0;
|
|
92
|
+
}
|
|
93
|
+
function withResizing(node, resizing) {
|
|
94
|
+
if (node.type === "shape" && node.shape === "path")
|
|
95
|
+
return node;
|
|
96
|
+
const { resizing: _previous, ...rest } = node;
|
|
97
|
+
return (Object.keys(resizing).length === 0 ? rest : { ...rest, resizing });
|
|
98
|
+
}
|
|
99
|
+
/** The node without a Fill flag on the axis. */
|
|
100
|
+
export function withoutFill(node, axis) {
|
|
101
|
+
if (!("resizing" in node) || node.resizing?.[axis] !== "fill")
|
|
102
|
+
return node;
|
|
103
|
+
const { [axis]: _fill, ...rest } = node.resizing;
|
|
104
|
+
return withResizing(node, rest);
|
|
105
|
+
}
|
|
106
|
+
/** The node without any Fill flag, keeping its size limits. */
|
|
107
|
+
export function withoutAnyFill(node) {
|
|
108
|
+
return withoutFill(withoutFill(node, "width"), "height");
|
|
109
|
+
}
|
|
110
|
+
function withFill(node, axis) {
|
|
111
|
+
if (node.type === "shape" && node.shape === "path")
|
|
112
|
+
return node;
|
|
113
|
+
return withResizing(node, { ...(node.resizing ?? {}), [axis]: "fill" });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The instance with its sizing on `axis` set to Fixed or Hug. The override
|
|
117
|
+
* is kept only where it differs from the component root, so an instance set
|
|
118
|
+
* back to the root's sizing follows the component again.
|
|
119
|
+
*/
|
|
120
|
+
function withInstanceAxisSizing(instance, root, axis, sizing) {
|
|
121
|
+
const key = layerPathKey([root.id]);
|
|
122
|
+
const current = entryOf(instance.overrides, key);
|
|
123
|
+
const stored = current?.sizing?.[axis];
|
|
124
|
+
const wanted = sizing === root.layout[sizingKey(axis)] ? undefined : sizing;
|
|
125
|
+
if (stored === wanted)
|
|
126
|
+
return instance;
|
|
127
|
+
const { sizing: currentSizing, ...restOfEntry } = current ?? {};
|
|
128
|
+
const { [axis]: _replaced, ...otherAxis } = currentSizing ?? {};
|
|
129
|
+
const nextSizing = wanted === undefined ? otherAxis : { ...otherAxis, [axis]: wanted };
|
|
130
|
+
const entry = { ...restOfEntry, ...(Object.keys(nextSizing).length === 0 ? {} : { sizing: nextSizing }) };
|
|
131
|
+
const { [key]: _entry, ...otherOverrides } = instance.overrides ?? {};
|
|
132
|
+
const overrides = Object.keys(entry).length === 0 ? otherOverrides : { ...otherOverrides, [key]: entry };
|
|
133
|
+
const { overrides: _overrides, ...base } = instance;
|
|
134
|
+
return Object.keys(overrides).length === 0 ? base : { ...base, overrides };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The node with its sizing on `axis` set to Fixed or Hug: the one writer of
|
|
138
|
+
* it, the counterpart of `nodeAxisSizing`. An auto layout frame stores it in
|
|
139
|
+
* its layout; an instance stores it as its override of its component root's
|
|
140
|
+
* sizing. A node that has neither (a shape, a frame without auto layout, an
|
|
141
|
+
* instance of a component without auto layout) is returned as it is, and so
|
|
142
|
+
* is text or code, whose automatic sizing has rules of its own
|
|
143
|
+
* (`sizingReplacements`). Fill is not touched: see `withoutFill`.
|
|
144
|
+
*/
|
|
145
|
+
export function withAxisSizing(document, node, axis, sizing) {
|
|
146
|
+
if (node.type === "instance") {
|
|
147
|
+
const root = instanceSizingRoot(document, node);
|
|
148
|
+
return root === undefined ? node : withInstanceAxisSizing(node, root, axis, sizing);
|
|
149
|
+
}
|
|
150
|
+
if (!isAutoLayoutFrame(node) || node.layout[sizingKey(axis)] === sizing)
|
|
151
|
+
return node;
|
|
152
|
+
return { ...node, layout: { ...node.layout, [sizingKey(axis)]: sizing } };
|
|
153
|
+
}
|
|
154
|
+
function withoutSizeBinding(node, axis) {
|
|
155
|
+
if (node.variableBindings?.[axis] === undefined)
|
|
156
|
+
return node;
|
|
157
|
+
const { [axis]: _removed, ...remaining } = node.variableBindings;
|
|
158
|
+
const { variableBindings: _bindings, ...base } = node;
|
|
159
|
+
return (Object.keys(remaining).length === 0 ? base : { ...base, variableBindings: remaining });
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Text and code blocks: the automatic sizing that leaves `axis` at the
|
|
163
|
+
* requested sizing. Auto width hugs both axes, auto height hugs the height.
|
|
164
|
+
*/
|
|
165
|
+
function withContentSizing(node, axis, sizing) {
|
|
166
|
+
if (node.type !== "text" && node.type !== "code")
|
|
167
|
+
return node;
|
|
168
|
+
let autoResize = node.autoResize;
|
|
169
|
+
if (axis === "width") {
|
|
170
|
+
if (sizing === "hug")
|
|
171
|
+
autoResize = "width-and-height";
|
|
172
|
+
else if (autoResize === "width-and-height")
|
|
173
|
+
autoResize = "height";
|
|
174
|
+
}
|
|
175
|
+
else if (sizing === "hug") {
|
|
176
|
+
if (autoResize === "none")
|
|
177
|
+
autoResize = "height";
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
autoResize = "none";
|
|
181
|
+
}
|
|
182
|
+
if (autoResize === node.autoResize)
|
|
183
|
+
return node;
|
|
184
|
+
return node.type === "text"
|
|
185
|
+
? { ...node, autoResize, wrap: autoResize === "width-and-height" ? "none" : "word", overflow: "visible" }
|
|
186
|
+
: { ...node, autoResize, wordWrap: autoResize !== "width-and-height" };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The node after a canvas or typed resize on `axis`: a Fill axis and the Hug
|
|
190
|
+
* axis of an auto layout frame or of an instance become Fixed, as in Figma
|
|
191
|
+
* ("If you manually resize a layer, or specify a value to its width or height
|
|
192
|
+
* field, then the resizing property will be set to fixed on the respective
|
|
193
|
+
* axis"). Without this the next layout would put a hugging instance back to
|
|
194
|
+
* its content's size. Text and code keep their own rules for automatic
|
|
195
|
+
* sizing.
|
|
196
|
+
*/
|
|
197
|
+
function withAxisFixedAfterResize(document, node, axis) {
|
|
198
|
+
return withAxisSizing(document, withoutFill(node, axis), axis, "fixed");
|
|
199
|
+
}
|
|
200
|
+
function changedSizeAxes(before, after) {
|
|
201
|
+
if (!("frame" in before) || !("frame" in after))
|
|
202
|
+
return [];
|
|
203
|
+
return ["width", "height"].filter((axis) => after.frame[axis] !== before.frame[axis]);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* `after`, the node `before` with a size changed by hand, with the sizing
|
|
207
|
+
* that change leaves: the one place the rule "a size set by hand is kept" is
|
|
208
|
+
* written. Every command that changes a size by hand, and every preview of
|
|
209
|
+
* one, passes its node through here, so the release commits what the drag
|
|
210
|
+
* drew and the next layout does not undo it.
|
|
211
|
+
*
|
|
212
|
+
* - A resize, on each axis whose size changed: Fill and Hug become Fixed
|
|
213
|
+
* (an instance's Hug too) and a size variable on the axis is dropped.
|
|
214
|
+
* - The Scale tool, on each axis whose size changed: an instance's Hug
|
|
215
|
+
* becomes Fixed, since its layers are its component's and do not scale. A
|
|
216
|
+
* frame keeps Hug: its children scaled with it, so it hugs the scaled
|
|
217
|
+
* size. Fill and a size variable are left as they are.
|
|
218
|
+
* - A size variable: Fill and Hug become Fixed on `axes`, which the caller
|
|
219
|
+
* names because the variable's value may equal the size the node has.
|
|
220
|
+
*
|
|
221
|
+
* A size that a layout, a constraint or the node's content gives is not a
|
|
222
|
+
* change by hand and does not come here: the sizing stays.
|
|
223
|
+
*/
|
|
224
|
+
export function withManualSize(document, before, after, change, axes = changedSizeAxes(before, after)) {
|
|
225
|
+
let next = after;
|
|
226
|
+
for (const axis of axes) {
|
|
227
|
+
if (change === "scale") {
|
|
228
|
+
if (next.type === "instance" && nodeAxisSizing(document, next, axis) === "hug") {
|
|
229
|
+
next = withAxisSizing(document, next, axis, "fixed");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
next = withAxisFixedAfterResize(document, change === "variable" ? next : withoutSizeBinding(next, axis), axis);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return next;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* `nodes`, the output of a resize or a scale of layers of `document`, each
|
|
240
|
+
* passed through `withManualSize` against the node it replaces. `only`
|
|
241
|
+
* limits the rule to the layers the user changed, where the others were
|
|
242
|
+
* only carried along (the descendants of a resized group or selection).
|
|
243
|
+
*/
|
|
244
|
+
export function withManualSizes(document, nodes, change, only) {
|
|
245
|
+
return nodes.map((node) => {
|
|
246
|
+
const before = entryOf(document.nodes, node.id);
|
|
247
|
+
if (before === undefined || (only !== undefined && !only.has(node.id)))
|
|
248
|
+
return node;
|
|
249
|
+
return withManualSize(document, before, node, change);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The nodes that change when `nodeIds` are set to `sizing` on `axis`, by id.
|
|
254
|
+
* Nodes that cannot take that sizing are left out.
|
|
255
|
+
*
|
|
256
|
+
* An instance follows every rule here as an auto layout frame does, through
|
|
257
|
+
* `nodeAxisSizing` and `withAxisSizing`, except the last part of the Hug
|
|
258
|
+
* rule: its layers are its component's, so their Fill is not changed.
|
|
259
|
+
*
|
|
260
|
+
* - Fill turns the node's own Hug on the axis into Fixed (text and code stop
|
|
261
|
+
* sizing that axis to their content), drops a size variable on the axis, and
|
|
262
|
+
* turns a hugging stack parent Fixed on the axis, as Figma does: "If any
|
|
263
|
+
* child objects within an auto layout frame are set to Fill container, the
|
|
264
|
+
* parent frame will no longer hug contents and become Fixed for the axis."
|
|
265
|
+
* - Hug on an auto layout frame turns its stack children that fill the axis
|
|
266
|
+
* into Fixed. A grid keeps its Fill children: they take their cell.
|
|
267
|
+
* - Fixed and Hug drop the node's own Fill on the axis.
|
|
268
|
+
*
|
|
269
|
+
* Hug leaves a stretching constraint on the axis for `applyOperations` to
|
|
270
|
+
* turn into Left or Top, as it does after every edit
|
|
271
|
+
* (`stretchWhereHuggingReplacements`).
|
|
272
|
+
*/
|
|
273
|
+
export function sizingReplacements(document, nodeIds, axis, sizing) {
|
|
274
|
+
const nodes = new Map();
|
|
275
|
+
const current = (id) => nodes.get(id) ?? entryOf(document.nodes, id);
|
|
276
|
+
for (const nodeId of new Set(nodeIds)) {
|
|
277
|
+
const original = current(nodeId);
|
|
278
|
+
if (original === undefined || original.locked)
|
|
279
|
+
continue;
|
|
280
|
+
if (original.type === "shape" && original.shape === "path")
|
|
281
|
+
continue;
|
|
282
|
+
if (sizing === "hug" && !canHugAxis(document, original))
|
|
283
|
+
continue;
|
|
284
|
+
const parent = parentNodeOf(document, nodeId);
|
|
285
|
+
if (sizing === "fill" && !canFillAxis(document, original, axis, parent))
|
|
286
|
+
continue;
|
|
287
|
+
let next = original;
|
|
288
|
+
if (sizing === "fill") {
|
|
289
|
+
next = withFill(withAxisSizing(document, next, axis, "fixed"), axis);
|
|
290
|
+
next = withContentSizing(next, axis, "fill");
|
|
291
|
+
next = withoutSizeBinding(next, axis);
|
|
292
|
+
if (isStackFrame(parent) && parent.layout[sizingKey(axis)] === "hug" && !parent.locked) {
|
|
293
|
+
const parentNode = current(parent.id) ?? parent;
|
|
294
|
+
nodes.set(parent.id, withAxisSizing(document, parentNode, axis, "fixed"));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
next = withoutFill(next, axis);
|
|
299
|
+
next = withAxisSizing(document, next, axis, sizing);
|
|
300
|
+
next = withContentSizing(next, axis, sizing);
|
|
301
|
+
if (sizing === "hug") {
|
|
302
|
+
// Auto width text hugs both axes, so it cannot fill its height either.
|
|
303
|
+
if ((next.type === "text" || next.type === "code") && axis === "width") {
|
|
304
|
+
next = withoutFill(next, "height");
|
|
305
|
+
}
|
|
306
|
+
if (isStackFrame(next)) {
|
|
307
|
+
for (const childId of next.children) {
|
|
308
|
+
const child = current(childId);
|
|
309
|
+
if (child === undefined || child.locked)
|
|
310
|
+
continue;
|
|
311
|
+
const fixedChild = withoutFill(child, axis);
|
|
312
|
+
if (fixedChild !== child)
|
|
313
|
+
nodes.set(childId, fixedChild);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (next !== original)
|
|
319
|
+
nodes.set(nodeId, next);
|
|
320
|
+
}
|
|
321
|
+
return nodes;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* A layer cannot hug its content and stretch with its frame on the same
|
|
325
|
+
* axis, so a Left and right, Top and bottom or Scale constraint on an axis
|
|
326
|
+
* that hugs becomes Left or Top. The Constraints control makes the axis
|
|
327
|
+
* Fixed for the opposite change.
|
|
328
|
+
*/
|
|
329
|
+
function withoutStretchingConstraint(node, axis) {
|
|
330
|
+
const constraints = node.constraints;
|
|
331
|
+
if (constraints === undefined)
|
|
332
|
+
return node;
|
|
333
|
+
const key = axis === "width" ? "horizontal" : "vertical";
|
|
334
|
+
const value = constraints[key];
|
|
335
|
+
if (value !== "left-right" && value !== "top-bottom" && value !== "scale")
|
|
336
|
+
return node;
|
|
337
|
+
const next = { ...constraints, [key]: axis === "width" ? "left" : "top" };
|
|
338
|
+
if (next.horizontal === "left" && next.vertical === "top") {
|
|
339
|
+
const { constraints: _removed, ...rest } = node;
|
|
340
|
+
return rest;
|
|
341
|
+
}
|
|
342
|
+
return { ...node, constraints: next };
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* The node without a stretching constraint on an axis it hugs: what the
|
|
346
|
+
* rule "no node hugs and stretches on the same axis" does to one node.
|
|
347
|
+
* Commands do not call it; `stretchWhereHuggingReplacements` applies the
|
|
348
|
+
* rule to every edit, on the axes the edit brings to break it.
|
|
349
|
+
*/
|
|
350
|
+
export function withoutStretchWhereHugging(document, node) {
|
|
351
|
+
let next = node;
|
|
352
|
+
for (const axis of ["width", "height"]) {
|
|
353
|
+
if (nodeAxisSizing(document, next, axis) === "hug")
|
|
354
|
+
next = withoutStretchingConstraint(next, axis);
|
|
355
|
+
}
|
|
356
|
+
return next;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* What an instance's sizing is read from in its component: the root's id
|
|
360
|
+
* (the path its sizing override is stored under) and the root's sizing on
|
|
361
|
+
* both axes. Two documents that give the same text give every instance of
|
|
362
|
+
* the component the same sizing.
|
|
363
|
+
*/
|
|
364
|
+
function componentSizingSource(document, componentId) {
|
|
365
|
+
const rootId = entryOf(document.components, componentId)?.rootId;
|
|
366
|
+
const root = rootId === undefined ? undefined : entryOf(document.nodes, rootId);
|
|
367
|
+
return isAutoLayoutFrame(root)
|
|
368
|
+
? `${root.id} ${root.layout.widthSizing} ${root.layout.heightSizing}`
|
|
369
|
+
: `${rootId ?? ""} fixed`;
|
|
370
|
+
}
|
|
371
|
+
/** Whether the node hugs the axis and has a stretching constraint on it. */
|
|
372
|
+
function hugsAndStretches(document, node, axis) {
|
|
373
|
+
const value = node.constraints?.[axis === "width" ? "horizontal" : "vertical"];
|
|
374
|
+
if (value !== "left-right" && value !== "top-bottom" && value !== "scale")
|
|
375
|
+
return false;
|
|
376
|
+
return nodeAxisSizing(document, node, axis) === "hug";
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* The one place the rule "no node has a stretching constraint (Left and
|
|
380
|
+
* right, Top and bottom, Scale) on an axis whose sizing is Hug" is
|
|
381
|
+
* enforced. `applyOperations` calls it for every batch of operations, so
|
|
382
|
+
* every command, preview, paste, undo-able edit and replayed commit passes
|
|
383
|
+
* through it and no command applies the rule itself.
|
|
384
|
+
*
|
|
385
|
+
* `next` is `previous` after the batch and `changedNodeIds` the nodes the
|
|
386
|
+
* batch wrote. The nodes looked at are the ones whose sizing or constraints
|
|
387
|
+
* can have changed:
|
|
388
|
+
*
|
|
389
|
+
* - every changed node that still exists (its own layout, automatic text
|
|
390
|
+
* sizing, overrides, component or constraints may be new);
|
|
391
|
+
* - every instance, at any depth and on any page or inside any component,
|
|
392
|
+
* of a component whose root or root sizing changed. An instance with a
|
|
393
|
+
* sizing override on the axis keeps its own sizing, so only the ones that
|
|
394
|
+
* follow the component can lose a constraint.
|
|
395
|
+
*
|
|
396
|
+
* Only a break of the rule that the batch brings is removed: an axis of a
|
|
397
|
+
* node that hugs and stretches in `next` and did not in `previous` (the
|
|
398
|
+
* node is new, or it kept the rule on that axis there). A node that already
|
|
399
|
+
* hugged and stretched on an axis in `previous`, as a document stored
|
|
400
|
+
* before the rule existed can hold, is left on that axis exactly as the
|
|
401
|
+
* batch leaves it, so a batch that does not touch the break, or keeps it,
|
|
402
|
+
* can be reversed exactly.
|
|
403
|
+
*
|
|
404
|
+
* Returned are those nodes, each with the stretching constraint turned into
|
|
405
|
+
* Left or Top on the axes that newly break the rule, in a stable order (the
|
|
406
|
+
* batch's own, then the document's). The sizing is never changed here, so
|
|
407
|
+
* one pass is enough. The cost is two sizing reads per changed node, two
|
|
408
|
+
* more for one that breaks the rule, and one comparison per component; the
|
|
409
|
+
* walk over every node of the document happens only for a batch that
|
|
410
|
+
* changed a component root's sizing.
|
|
411
|
+
*/
|
|
412
|
+
export function stretchWhereHuggingReplacements(previous, next, changedNodeIds) {
|
|
413
|
+
const candidates = new Set(changedNodeIds);
|
|
414
|
+
const resized = new Set();
|
|
415
|
+
// With the same components record, only a component whose root the edit wrote can size another way.
|
|
416
|
+
const components = next.components !== undefined && next.components === previous.components
|
|
417
|
+
? [...changedNodeIds].flatMap((id) => {
|
|
418
|
+
const component = findComponentByRoot(next, id);
|
|
419
|
+
return component === undefined ? [] : [[component.id, component]];
|
|
420
|
+
})
|
|
421
|
+
: Object.entries(next.components ?? {});
|
|
422
|
+
for (const [componentId, component] of components) {
|
|
423
|
+
const unchanged = entryOf(previous.components, componentId) === component
|
|
424
|
+
&& !changedNodeIds.has(component.rootId);
|
|
425
|
+
if (unchanged)
|
|
426
|
+
continue;
|
|
427
|
+
if (componentSizingSource(previous, componentId) !== componentSizingSource(next, componentId))
|
|
428
|
+
resized.add(componentId);
|
|
429
|
+
}
|
|
430
|
+
if (resized.size > 0) {
|
|
431
|
+
for (const node of tableValues(next.nodes)) {
|
|
432
|
+
if (node.type === "instance" && resized.has(node.componentId))
|
|
433
|
+
candidates.add(node.id);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const replacements = [];
|
|
437
|
+
for (const id of candidates) {
|
|
438
|
+
const node = entryOf(next.nodes, id);
|
|
439
|
+
if (node === undefined || node.constraints === undefined)
|
|
440
|
+
continue;
|
|
441
|
+
const before = entryOf(previous.nodes, id);
|
|
442
|
+
let kept = node;
|
|
443
|
+
for (const axis of ["width", "height"]) {
|
|
444
|
+
if (!hugsAndStretches(next, node, axis))
|
|
445
|
+
continue;
|
|
446
|
+
if (before !== undefined && hugsAndStretches(previous, before, axis))
|
|
447
|
+
continue;
|
|
448
|
+
kept = withoutStretchingConstraint(kept, axis);
|
|
449
|
+
}
|
|
450
|
+
if (kept !== node)
|
|
451
|
+
replacements.push(kept);
|
|
452
|
+
}
|
|
453
|
+
return replacements;
|
|
454
|
+
}
|
|
455
|
+
/** The document with `nodes` replacing their stored versions. */
|
|
456
|
+
export function documentWithNodes(document, nodes) {
|
|
457
|
+
return nodes.size === 0
|
|
458
|
+
? document
|
|
459
|
+
: { ...document, nodes: { ...document.nodes, ...Object.fromEntries(nodes) } };
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* The nodes that change when a node's Fill flags and size limits are replaced
|
|
463
|
+
* with `resizing` (`undefined` removes them all). A newly set Fill follows the
|
|
464
|
+
* same rules as choosing Fill container in the sizing menu.
|
|
465
|
+
*/
|
|
466
|
+
export function resizingReplacements(document, nodeId, resizing) {
|
|
467
|
+
const node = entryOf(document.nodes, nodeId);
|
|
468
|
+
const nodes = new Map();
|
|
469
|
+
if (node === undefined || node.locked || (node.type === "shape" && node.shape === "path")) {
|
|
470
|
+
return nodes;
|
|
471
|
+
}
|
|
472
|
+
const { width, height, ...limits } = resizing ?? {};
|
|
473
|
+
const kept = {
|
|
474
|
+
...limits,
|
|
475
|
+
...(width === "fill" && node.resizing?.width === "fill" ? { width } : {}),
|
|
476
|
+
...(height === "fill" && node.resizing?.height === "fill" ? { height } : {}),
|
|
477
|
+
};
|
|
478
|
+
nodes.set(nodeId, withResizing(node, kept));
|
|
479
|
+
for (const axis of ["width", "height"]) {
|
|
480
|
+
if (resizing?.[axis] !== "fill" || node.resizing?.[axis] === "fill")
|
|
481
|
+
continue;
|
|
482
|
+
sizingReplacements(documentWithNodes(document, nodes), [nodeId], axis, "fill")
|
|
483
|
+
.forEach((replacement, id) => nodes.set(id, replacement));
|
|
484
|
+
}
|
|
485
|
+
return nodes;
|
|
486
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connectors used their own end style names before schema 0.20.0. These
|
|
3
|
+
* helpers give them the line end style names. They are internal to the
|
|
4
|
+
* model package: the codec and the store use them while loading.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Gives connectors in a document the line end style names: `"arrow"`
|
|
8
|
+
* becomes `"triangle-arrow"` and `"dot"` becomes `"circle-arrow"`. Leaves
|
|
9
|
+
* anything else as it is. The 0.19.0 to 0.20.0 step uses it, and so does
|
|
10
|
+
* loading a 0.20.0 document, because unreleased builds of 0.20.0 still wrote
|
|
11
|
+
* the old names.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renameLegacyConnectorCapsInDocument(value: unknown): unknown;
|
|
14
|
+
/** The operation form of `renameLegacyConnectorCapsInDocument`. */
|
|
15
|
+
export declare function renameLegacyConnectorCapsInOperation(operation: unknown): unknown;
|