@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,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component slots in the stored document: who owns a slot host's content,
|
|
3
|
+
* which slots a component's frames bind, and how an instance's slot entries
|
|
4
|
+
* follow a change of its component. Nothing here resolves or draws a slot.
|
|
5
|
+
*/
|
|
6
|
+
import { isFrozenNodeMap } from "./derivations.js";
|
|
7
|
+
import { layerPathKey, parseLayerPath } from "./components.js";
|
|
8
|
+
import { entryOf } from "./id-table.js";
|
|
9
|
+
import { overridePathResolves, remapLayerPath } from "./override-remap.js";
|
|
10
|
+
import { parentMapOf, recordedChangedNodes } from "./parent-table.js";
|
|
11
|
+
import { ownedChildIds, } from "./types.js";
|
|
12
|
+
/** Per frozen node record, the nearest slot owner of each node asked for so far (`null` for none). */
|
|
13
|
+
const slotOwnerCache = new WeakMap();
|
|
14
|
+
/** The entry of `instance.slots` that lists `hostId`, as a `SlotOwner`. */
|
|
15
|
+
function ownerEntry(instance, hostId) {
|
|
16
|
+
for (const [pathKey, byProperty] of Object.entries(instance.slots ?? {})) {
|
|
17
|
+
for (const [propertyId, id] of Object.entries(byProperty)) {
|
|
18
|
+
if (id === hostId)
|
|
19
|
+
return { instanceId: instance.id, pathKey, propertyId: propertyId, hostId };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The innermost slot whose content holds `id`: the parent table is walked up
|
|
26
|
+
* from `id` (the node itself included, so a host gives its own slot) to the
|
|
27
|
+
* first slot host. Undefined when `id` is in no slot's content. Costs one
|
|
28
|
+
* step per level, and the answers are kept per frozen node record, so the
|
|
29
|
+
* nodes passed on the way are answered at once later.
|
|
30
|
+
* @since 0.37.0
|
|
31
|
+
*/
|
|
32
|
+
export function slotOwnerOf(document, id) {
|
|
33
|
+
const nodes = document.nodes;
|
|
34
|
+
let cache = isFrozenNodeMap(nodes) ? slotOwnerCache.get(nodes) : undefined;
|
|
35
|
+
if (cache === undefined && isFrozenNodeMap(nodes)) {
|
|
36
|
+
cache = new Map();
|
|
37
|
+
slotOwnerCache.set(nodes, cache);
|
|
38
|
+
}
|
|
39
|
+
const parents = parentMapOf(nodes);
|
|
40
|
+
const passed = [];
|
|
41
|
+
let found = null;
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
for (let current = id; current !== undefined && !seen.has(current); current = parents.get(current)) {
|
|
44
|
+
const known = cache?.get(current);
|
|
45
|
+
if (known !== undefined) {
|
|
46
|
+
found = known;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
seen.add(current);
|
|
50
|
+
passed.push(current);
|
|
51
|
+
const node = entryOf(nodes, current);
|
|
52
|
+
if (node?.type === "frame" && node.slotHost === true) {
|
|
53
|
+
const parentId = parents.get(current);
|
|
54
|
+
const parent = parentId === undefined ? undefined : entryOf(nodes, parentId);
|
|
55
|
+
found = parent?.type === "instance" ? ownerEntry(parent, current) ?? null : null;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (cache !== undefined)
|
|
60
|
+
for (const passedId of passed)
|
|
61
|
+
cache.set(passedId, found);
|
|
62
|
+
return found ?? undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Every slot whose content holds `id`, innermost first: the owner of `id`,
|
|
66
|
+
* then the owner of that owner's instance, and so on up. Content of a slot
|
|
67
|
+
* inside the content of another slot changes both.
|
|
68
|
+
* @since 0.37.0
|
|
69
|
+
*/
|
|
70
|
+
export function slotOwnersOf(document, id) {
|
|
71
|
+
const owners = [];
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
for (let owner = slotOwnerOf(document, id); owner !== undefined && !seen.has(owner.hostId); owner = slotOwnerOf(document, owner.instanceId)) {
|
|
74
|
+
seen.add(owner.hostId);
|
|
75
|
+
owners.push(owner);
|
|
76
|
+
}
|
|
77
|
+
return owners;
|
|
78
|
+
}
|
|
79
|
+
/** Per components record, whether any component has a slot property. */
|
|
80
|
+
const hasSlotsCache = new WeakMap();
|
|
81
|
+
/**
|
|
82
|
+
* Whether any component of `document` has a slot property, so that slot
|
|
83
|
+
* content can exist. Reads the component definitions, never the layers, and
|
|
84
|
+
* is kept per frozen components record: code that follows slot owners on every
|
|
85
|
+
* edit asks this first, so a document without slots pays nothing for it.
|
|
86
|
+
* @since 0.37.0
|
|
87
|
+
*/
|
|
88
|
+
export function documentHasSlots(document) {
|
|
89
|
+
const components = document.components;
|
|
90
|
+
if (components === undefined)
|
|
91
|
+
return false;
|
|
92
|
+
const known = hasSlotsCache.get(components);
|
|
93
|
+
if (known !== undefined)
|
|
94
|
+
return known;
|
|
95
|
+
const found = Object.values(components).some((component) => component.properties?.some((property) => property.kind === "slot") === true);
|
|
96
|
+
// A record that can still change is read again next time.
|
|
97
|
+
if (Object.isFrozen(components))
|
|
98
|
+
hasSlotsCache.set(components, found);
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
/** Per node record an edit made, the slot owners whose content the edit changed. */
|
|
102
|
+
const changedOwnersByRecord = new WeakMap();
|
|
103
|
+
/**
|
|
104
|
+
* The slots whose content changes when the document becomes `document` with
|
|
105
|
+
* the nodes `changedNodeIds` written, inserted or removed (a store's
|
|
106
|
+
* `ChangeSet.changedNodeIds`, or `ApplyOperationsResult.changes`): for each
|
|
107
|
+
* of those nodes still in `document`, every owner up the chain
|
|
108
|
+
* (`slotOwnersOf`). A removed node's parent counts for it, as its children
|
|
109
|
+
* changed. Each owner is listed once, innermost first per node, at one
|
|
110
|
+
* parent walk per node.
|
|
111
|
+
*
|
|
112
|
+
* Use this one, with the store's change set, to version slot content (such
|
|
113
|
+
* as an instance's content version when slots are resolved): undo and redo
|
|
114
|
+
* move the store to a stored revision, and `changedSlotOwners` of that
|
|
115
|
+
* revision names the edit that first made it, not the move.
|
|
116
|
+
* @since 0.37.0
|
|
117
|
+
*/
|
|
118
|
+
export function slotOwnersOfChanges(document, changedNodeIds) {
|
|
119
|
+
const owners = [];
|
|
120
|
+
const hosts = new Set();
|
|
121
|
+
for (const id of changedNodeIds) {
|
|
122
|
+
if (entryOf(document.nodes, id) === undefined)
|
|
123
|
+
continue;
|
|
124
|
+
for (const owner of slotOwnersOf(document, id)) {
|
|
125
|
+
if (hosts.has(owner.hostId))
|
|
126
|
+
continue;
|
|
127
|
+
hosts.add(owner.hostId);
|
|
128
|
+
owners.push(owner);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return owners;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The slots whose content the edit that made `document` changed
|
|
135
|
+
* (`slotOwnersOfChanges` with that edit's changed nodes), kept for the node
|
|
136
|
+
* record. Empty for a document no edit made. `applyOperations` records the
|
|
137
|
+
* changed nodes, as it records parents, and the owners are found on the
|
|
138
|
+
* first call. A document reached by undo or redo is one an earlier edit
|
|
139
|
+
* made, so this names that edit's slots; use `slotOwnersOfChanges` with the
|
|
140
|
+
* store's change set to follow every move of the store.
|
|
141
|
+
* @since 0.37.0
|
|
142
|
+
*/
|
|
143
|
+
export function changedSlotOwners(document) {
|
|
144
|
+
const nodes = document.nodes;
|
|
145
|
+
const known = changedOwnersByRecord.get(nodes);
|
|
146
|
+
if (known !== undefined)
|
|
147
|
+
return known;
|
|
148
|
+
const changed = recordedChangedNodes(nodes);
|
|
149
|
+
if (changed === undefined)
|
|
150
|
+
return [];
|
|
151
|
+
const frozen = Object.freeze([...slotOwnersOfChanges(document, changed)]);
|
|
152
|
+
changedOwnersByRecord.set(nodes, frozen);
|
|
153
|
+
return frozen;
|
|
154
|
+
}
|
|
155
|
+
/** Per frozen node record, the slot property IDs each component's frames bind. */
|
|
156
|
+
const boundSlotsCache = new WeakMap();
|
|
157
|
+
/**
|
|
158
|
+
* The slot properties of `componentId` that at least one frame of its tree
|
|
159
|
+
* binds (`FrameNode.slot`). A binding to a property that is missing or not a
|
|
160
|
+
* slot does not count. Walks the component's own tree (content of nested
|
|
161
|
+
* instances' slot hosts included) once per frozen node record, or once per
|
|
162
|
+
* `memo` for a record that can still change.
|
|
163
|
+
* @since 0.37.0
|
|
164
|
+
*/
|
|
165
|
+
export function boundSlotPropertyIds(document, componentId, memo) {
|
|
166
|
+
let cache = memo;
|
|
167
|
+
if (cache === undefined && isFrozenNodeMap(document.nodes)) {
|
|
168
|
+
cache = boundSlotsCache.get(document.nodes);
|
|
169
|
+
if (cache === undefined) {
|
|
170
|
+
cache = new Map();
|
|
171
|
+
boundSlotsCache.set(document.nodes, cache);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const cached = cache?.get(componentId);
|
|
175
|
+
if (cached !== undefined)
|
|
176
|
+
return cached;
|
|
177
|
+
const component = entryOf(document.components, componentId);
|
|
178
|
+
const slotIds = new Set((component?.properties ?? []).filter((property) => property.kind === "slot").map((property) => property.id));
|
|
179
|
+
const bound = new Set();
|
|
180
|
+
if (component !== undefined && slotIds.size > 0) {
|
|
181
|
+
const pending = [component.rootId];
|
|
182
|
+
const seen = new Set();
|
|
183
|
+
while (pending.length > 0) {
|
|
184
|
+
const id = pending.pop();
|
|
185
|
+
if (seen.has(id))
|
|
186
|
+
continue;
|
|
187
|
+
seen.add(id);
|
|
188
|
+
const node = entryOf(document.nodes, id);
|
|
189
|
+
if (node === undefined)
|
|
190
|
+
continue;
|
|
191
|
+
if (node.type === "frame" && node.slot !== undefined && slotIds.has(node.slot))
|
|
192
|
+
bound.add(node.slot);
|
|
193
|
+
pending.push(...ownedChildIds(node));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
cache?.set(componentId, bound);
|
|
197
|
+
return bound;
|
|
198
|
+
}
|
|
199
|
+
/** The component the nested instance at `path` shows on `side`, or the side's own for `[]`; undefined when the path does not resolve. */
|
|
200
|
+
function componentAtPath(side, path) {
|
|
201
|
+
if (path.length === 0)
|
|
202
|
+
return side.componentId;
|
|
203
|
+
const overrides = side.overrides ?? {};
|
|
204
|
+
if (!overridePathResolves(side.document, side.componentId, path, overrides, side.shownComponentAt))
|
|
205
|
+
return undefined;
|
|
206
|
+
const node = entryOf(side.document.nodes, path.at(-1));
|
|
207
|
+
if (node?.type !== "instance")
|
|
208
|
+
return undefined;
|
|
209
|
+
return entryOf(overrides, layerPathKey(path))?.componentId ?? side.shownComponentAt?.(path) ?? node.componentId;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Carries an instance's slot entries from one component (`from`) to another
|
|
213
|
+
* (`to`), at every nested path: a path is kept as it is for the same
|
|
214
|
+
* component and matched by layer name and position for another one
|
|
215
|
+
* (`remapLayerPath`), and must still lead to a nested instance on the `to`
|
|
216
|
+
* side. In the component shown at that path, an entry keeps its
|
|
217
|
+
* property when that is a slot some frame binds; otherwise, when the path
|
|
218
|
+
* shows another component than before, it moves to the bound slot property
|
|
219
|
+
* with the same name. An entry with no match, or one whose target another
|
|
220
|
+
* entry took first (in the order of `ownedChildIds`), is removed: its host
|
|
221
|
+
* is listed in `removedHostIds`. The same `slots` object comes back when
|
|
222
|
+
* nothing changes.
|
|
223
|
+
* @since 0.37.0
|
|
224
|
+
*/
|
|
225
|
+
export function remapSlots(instance, from, to) {
|
|
226
|
+
const slots = instance.slots;
|
|
227
|
+
if (slots === undefined)
|
|
228
|
+
return { slots, removedHostIds: [] };
|
|
229
|
+
// The same component keeps its layer IDs, also from the document before an edit to the one after it.
|
|
230
|
+
const sameRoot = from.componentId === to.componentId;
|
|
231
|
+
const fromRoot = entryOf(from.document.components, from.componentId)?.rootId;
|
|
232
|
+
const toRoot = entryOf(to.document.components, to.componentId)?.rootId;
|
|
233
|
+
const next = {};
|
|
234
|
+
const removedHostIds = [];
|
|
235
|
+
let changed = false;
|
|
236
|
+
for (const pathKey of Object.keys(slots).sort(compareCodeUnits)) {
|
|
237
|
+
const byProperty = slots[pathKey];
|
|
238
|
+
const fromPath = pathKey === "" ? [] : parseLayerPath(pathKey);
|
|
239
|
+
let toPath;
|
|
240
|
+
if (fromPath === null)
|
|
241
|
+
toPath = undefined;
|
|
242
|
+
else if (fromPath.length === 0 || sameRoot)
|
|
243
|
+
toPath = fromPath;
|
|
244
|
+
else if (fromRoot !== undefined && toRoot !== undefined) {
|
|
245
|
+
toPath = remapLayerPath(fromPath, { document: from.document, rootId: fromRoot, ...(from.shownComponentAt === undefined ? {} : { shownComponentAt: from.shownComponentAt }) }, { document: to.document, rootId: toRoot, ...(to.shownComponentAt === undefined ? {} : { shownComponentAt: to.shownComponentAt }) }, from.overrides, to.overrides);
|
|
246
|
+
}
|
|
247
|
+
const fromComponent = fromPath === null ? undefined : componentAtPath(from, fromPath);
|
|
248
|
+
const toComponent = toPath === undefined ? undefined : componentAtPath(to, toPath);
|
|
249
|
+
const toKey = toPath === undefined ? undefined : toPath.length === 0 ? "" : layerPathKey(toPath);
|
|
250
|
+
for (const propertyId of Object.keys(byProperty).sort(compareCodeUnits)) {
|
|
251
|
+
const hostId = byProperty[propertyId];
|
|
252
|
+
let target;
|
|
253
|
+
if (toComponent !== undefined && toKey !== undefined) {
|
|
254
|
+
const bound = boundSlotPropertyIds(to.document, toComponent, to.boundSlots);
|
|
255
|
+
if (bound.has(propertyId))
|
|
256
|
+
target = propertyId;
|
|
257
|
+
else if (fromComponent !== undefined && fromComponent !== toComponent) {
|
|
258
|
+
const name = entryOf(from.document.components, fromComponent)?.properties?.find((property) => property.id === propertyId)?.name;
|
|
259
|
+
const match = name === undefined
|
|
260
|
+
? undefined
|
|
261
|
+
: entryOf(to.document.components, toComponent)?.properties?.find((property) => property.kind === "slot" && property.name === name && bound.has(property.id));
|
|
262
|
+
target = match?.id;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (target === undefined || toKey === undefined || next[toKey]?.[target] !== undefined) {
|
|
266
|
+
removedHostIds.push(hostId);
|
|
267
|
+
changed = true;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (toKey !== pathKey || target !== propertyId)
|
|
271
|
+
changed = true;
|
|
272
|
+
(next[toKey] ??= {})[target] = hostId;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (!changed)
|
|
276
|
+
return { slots, removedHostIds };
|
|
277
|
+
return { slots: Object.keys(next).length === 0 ? undefined : next, removedHostIds };
|
|
278
|
+
}
|
|
279
|
+
const compareCodeUnits = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
|
|
280
|
+
/** Whether `node` is a slot host frame. @since 0.37.0 */
|
|
281
|
+
export const isSlotHost = (node) => node?.type === "frame" && node.slotHost === true;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DashCap, type SceneNode, type Stroke, type StrokeCap, type StrokeJoin, type VectorNetwork, type VectorSegment, type VisualStyle } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The miter limit a miter angle gives, as SVG and Skia use it: the longest a
|
|
4
|
+
* miter may be, as a multiple of half the stroke width, before the join is
|
|
5
|
+
* beveled. A corner sharper than `angle` degrees has a longer miter.
|
|
6
|
+
* @since 0.22.0
|
|
7
|
+
*/
|
|
8
|
+
export declare function miterLimitFromAngle(angle: number): number;
|
|
9
|
+
/** The miter angle, in degrees, that a miter limit of at least 1 gives. */
|
|
10
|
+
export declare function miterAngleFromLimit(limit: number): number;
|
|
11
|
+
/** A stroke's miter angle, or Figma's default when it has none. */
|
|
12
|
+
export declare function strokeMiterAngle(stroke: Pick<Stroke, "miterAngle">): number;
|
|
13
|
+
/**
|
|
14
|
+
* The join a stroke of `node` draws with when it names none: what the layer
|
|
15
|
+
* drew before schema 0.22.0, round on layers stroked along a path and miter
|
|
16
|
+
* on layers stroked around a box. `style` is the layer's resolved style.
|
|
17
|
+
* @since 0.22.0
|
|
18
|
+
*/
|
|
19
|
+
export declare function defaultStrokeJoin(node: SceneNode, style: VisualStyle | undefined): StrokeJoin;
|
|
20
|
+
/**
|
|
21
|
+
* The dash ends a dashed stroke of `node` draws with when it names none:
|
|
22
|
+
* round on layers stroked along a path and none on layers stroked around a
|
|
23
|
+
* box, as before schema 0.22.0.
|
|
24
|
+
* @since 0.22.0
|
|
25
|
+
*/
|
|
26
|
+
export declare function defaultDashCap(node: SceneNode, style: VisualStyle | undefined): DashCap;
|
|
27
|
+
/** The end style an open path draws when it names none: round, as before 0.22.0. */
|
|
28
|
+
export declare const DEFAULT_PATH_STROKE_CAP: StrokeCap;
|
|
29
|
+
/**
|
|
30
|
+
* The segments of `network` when they form one open chain in order: each
|
|
31
|
+
* segment starts where the one before it ends, and the first segment's start
|
|
32
|
+
* and the last segment's end are each touched by that segment only. Only such
|
|
33
|
+
* a path takes end points (`PathNode.startCap` and `endCap`). Returns null
|
|
34
|
+
* for a closed, branched or empty network.
|
|
35
|
+
* @since 0.22.0
|
|
36
|
+
*/
|
|
37
|
+
export declare function openPathChain(network: VectorNetwork): readonly VectorSegment[] | null;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { cornerRadiiAreRounded, styleCornerRadii } from "./corner-radii.js";
|
|
2
|
+
import { DEFAULT_STROKE_MITER_ANGLE, } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The miter limit a miter angle gives, as SVG and Skia use it: the longest a
|
|
5
|
+
* miter may be, as a multiple of half the stroke width, before the join is
|
|
6
|
+
* beveled. A corner sharper than `angle` degrees has a longer miter.
|
|
7
|
+
* @since 0.22.0
|
|
8
|
+
*/
|
|
9
|
+
export function miterLimitFromAngle(angle) {
|
|
10
|
+
return 1 / Math.sin((angle * Math.PI) / 360);
|
|
11
|
+
}
|
|
12
|
+
/** The miter angle, in degrees, that a miter limit of at least 1 gives. */
|
|
13
|
+
export function miterAngleFromLimit(limit) {
|
|
14
|
+
return (2 * Math.asin(1 / Math.max(1, limit)) * 180) / Math.PI;
|
|
15
|
+
}
|
|
16
|
+
/** A stroke's miter angle, or Figma's default when it has none. */
|
|
17
|
+
export function strokeMiterAngle(stroke) {
|
|
18
|
+
return stroke.miterAngle ?? DEFAULT_STROKE_MITER_ANGLE;
|
|
19
|
+
}
|
|
20
|
+
function plainPaint(paint) {
|
|
21
|
+
return paint.visible !== false && (paint.blendMode ?? "normal") === "normal";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether the renderer draws a layer's strokes along a path, rather than
|
|
25
|
+
* around a box. Paths, ellipses, polygons, stars, lines and connectors always
|
|
26
|
+
* are; a rectangle is when it has rounded corners or gradient, image,
|
|
27
|
+
* hidden, blended or several fills, and no side weights. Frames, other
|
|
28
|
+
* rectangles and code blocks are drawn as boxes.
|
|
29
|
+
*/
|
|
30
|
+
function strokedAsPath(node, style) {
|
|
31
|
+
if (node.type === "connector")
|
|
32
|
+
return true;
|
|
33
|
+
if (node.type !== "shape")
|
|
34
|
+
return false;
|
|
35
|
+
if (node.shape !== "rectangle")
|
|
36
|
+
return true;
|
|
37
|
+
if (style?.strokes?.some((stroke) => stroke.sides !== undefined) === true)
|
|
38
|
+
return false;
|
|
39
|
+
const fills = style?.fills ?? [];
|
|
40
|
+
const regionFills = fills.length > 1 ||
|
|
41
|
+
fills.some((paint) => paint.kind !== "solid" || !plainPaint(paint));
|
|
42
|
+
return regionFills || cornerRadiiAreRounded(styleCornerRadii(style));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The join a stroke of `node` draws with when it names none: what the layer
|
|
46
|
+
* drew before schema 0.22.0, round on layers stroked along a path and miter
|
|
47
|
+
* on layers stroked around a box. `style` is the layer's resolved style.
|
|
48
|
+
* @since 0.22.0
|
|
49
|
+
*/
|
|
50
|
+
export function defaultStrokeJoin(node, style) {
|
|
51
|
+
return strokedAsPath(node, style) ? "round" : "miter";
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The dash ends a dashed stroke of `node` draws with when it names none:
|
|
55
|
+
* round on layers stroked along a path and none on layers stroked around a
|
|
56
|
+
* box, as before schema 0.22.0.
|
|
57
|
+
* @since 0.22.0
|
|
58
|
+
*/
|
|
59
|
+
export function defaultDashCap(node, style) {
|
|
60
|
+
return strokedAsPath(node, style) ? "round" : "none";
|
|
61
|
+
}
|
|
62
|
+
/** The end style an open path draws when it names none: round, as before 0.22.0. */
|
|
63
|
+
export const DEFAULT_PATH_STROKE_CAP = "round";
|
|
64
|
+
/**
|
|
65
|
+
* The segments of `network` when they form one open chain in order: each
|
|
66
|
+
* segment starts where the one before it ends, and the first segment's start
|
|
67
|
+
* and the last segment's end are each touched by that segment only. Only such
|
|
68
|
+
* a path takes end points (`PathNode.startCap` and `endCap`). Returns null
|
|
69
|
+
* for a closed, branched or empty network.
|
|
70
|
+
* @since 0.22.0
|
|
71
|
+
*/
|
|
72
|
+
export function openPathChain(network) {
|
|
73
|
+
const segments = network.segments;
|
|
74
|
+
const first = segments[0];
|
|
75
|
+
const last = segments.at(-1);
|
|
76
|
+
if (first === undefined || last === undefined)
|
|
77
|
+
return null;
|
|
78
|
+
for (let index = 1; index < segments.length; index += 1) {
|
|
79
|
+
if (segments[index].start !== segments[index - 1].end)
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const uses = new Map();
|
|
83
|
+
for (const segment of segments) {
|
|
84
|
+
uses.set(segment.start, (uses.get(segment.start) ?? 0) + 1);
|
|
85
|
+
uses.set(segment.end, (uses.get(segment.end) ?? 0) + 1);
|
|
86
|
+
}
|
|
87
|
+
if (uses.get(first.start) !== 1 || uses.get(last.end) !== 1)
|
|
88
|
+
return null;
|
|
89
|
+
return segments;
|
|
90
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { NodeId, PathNode, TransformMatrix, VisualStyle } from "./types.ts";
|
|
2
|
+
/** The values of SVG's `fill-rule` property. */
|
|
3
|
+
export declare const SVG_FILL_RULES: readonly ["nonzero", "evenodd"];
|
|
4
|
+
/** How SVG decides which parts of a path that crosses itself are inside. */
|
|
5
|
+
export type SvgFillRule = (typeof SVG_FILL_RULES)[number];
|
|
6
|
+
/** The values of SVG's `stroke-linecap` property. */
|
|
7
|
+
export declare const SVG_STROKE_CAPS: readonly ["butt", "round", "square"];
|
|
8
|
+
/** How SVG ends the stroke of an open path. */
|
|
9
|
+
export type SvgStrokeCap = (typeof SVG_STROKE_CAPS)[number];
|
|
10
|
+
/** The values of SVG's `stroke-linejoin` property that the model can draw. */
|
|
11
|
+
export declare const SVG_STROKE_JOINS: readonly ["miter", "round", "bevel"];
|
|
12
|
+
/** How SVG joins the corners of a stroke. */
|
|
13
|
+
export type SvgStrokeJoin = (typeof SVG_STROKE_JOINS)[number];
|
|
14
|
+
/**
|
|
15
|
+
* One SVG `<path>` described for `pathNodeFromSvgPath`. The options left out
|
|
16
|
+
* take SVG's own defaults, not the model's: a path layer that names no caps
|
|
17
|
+
* and no join draws round ones, where SVG draws butt caps and miter joins.
|
|
18
|
+
*/
|
|
19
|
+
export interface SvgPathImport {
|
|
20
|
+
readonly id: NodeId;
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/** The `d` attribute. It must draw at least one segment. */
|
|
23
|
+
readonly pathData: string;
|
|
24
|
+
/**
|
|
25
|
+
* The layer's fills and strokes, in the model's terms. A stroke that names
|
|
26
|
+
* its own `join` keeps it; the others take `strokeJoin`. A stroke that
|
|
27
|
+
* names its own `dashCap` keeps it; the others take `strokeCap`, with or
|
|
28
|
+
* without dashes, because a stroke's open ends are drawn with its dash
|
|
29
|
+
* ends where the path's end points are not used. What SVG has and no option here names goes on the stroke:
|
|
30
|
+
* `stroke-dasharray` is `dash` (an odd list repeats, as in SVG), and
|
|
31
|
+
* `stroke-miterlimit` is `miterAngle` (see `miterAngleFromLimit`), which
|
|
32
|
+
* left out is SVG's own default of 4. A stroke has no `stroke-dashoffset`:
|
|
33
|
+
* every dash pattern starts at the start of its subpath. A style with a
|
|
34
|
+
* `styleId` must give its own `strokes` (an empty list for none): the
|
|
35
|
+
* strokes of a shared style cannot take the join and the cap.
|
|
36
|
+
*/
|
|
37
|
+
readonly style: VisualStyle;
|
|
38
|
+
/**
|
|
39
|
+
* Maps the path's coordinates into the parent layer's, as SVG's
|
|
40
|
+
* `matrix(a b c d e f)`. Six finite numbers that can be inverted (see
|
|
41
|
+
* `transformIsInvertible`) and leave the path at finite coordinates.
|
|
42
|
+
* Omitted is the identity.
|
|
43
|
+
*/
|
|
44
|
+
readonly transform?: TransformMatrix;
|
|
45
|
+
/** SVG's `fill-rule`. Omitted is `"nonzero"`. */
|
|
46
|
+
readonly fillRule?: SvgFillRule;
|
|
47
|
+
/**
|
|
48
|
+
* SVG's `stroke-linecap`, for both ends of the path and the dash ends of
|
|
49
|
+
* every stroke. Omitted is `"butt"`, which the model calls `"none"`.
|
|
50
|
+
*/
|
|
51
|
+
readonly strokeCap?: SvgStrokeCap;
|
|
52
|
+
/**
|
|
53
|
+
* SVG's `stroke-linejoin`. Omitted is `"miter"`. Naming one for a style
|
|
54
|
+
* without strokes is refused, because there is nothing to store it on.
|
|
55
|
+
*/
|
|
56
|
+
readonly strokeJoin?: SvgStrokeJoin;
|
|
57
|
+
/** Omitted is `true`. */
|
|
58
|
+
readonly visible?: boolean;
|
|
59
|
+
/** Omitted is `false`. */
|
|
60
|
+
readonly locked?: boolean;
|
|
61
|
+
/** Omitted is `1`. */
|
|
62
|
+
readonly opacity?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds a complete, editable path layer from one SVG `<path>`: its `d`
|
|
66
|
+
* attribute, its `fill-rule`, `stroke-linecap` and `stroke-linejoin`, and the
|
|
67
|
+
* matrix that places it in its parent. Relative, shorthand and quadratic
|
|
68
|
+
* commands are normalized and arcs stay arcs (see
|
|
69
|
+
* `vectorNetworkFromSvgPathData`). A path layer has no frame: its bounds come
|
|
70
|
+
* from the network under `transform` (`getNodeBounds`).
|
|
71
|
+
*
|
|
72
|
+
* Nothing is guessed. Each of these throws a `ModelError` with code
|
|
73
|
+
* `INVALID_SCHEMA` whose `path` names the option, such as
|
|
74
|
+
* `$svgPath.pathData`: path data that is not a string, is empty, cannot be
|
|
75
|
+
* read, draws no segment or holds a number that is not finite; a `transform`
|
|
76
|
+
* that is not six finite numbers, cannot be inverted (see
|
|
77
|
+
* `transformIsInvertible`) or puts the path beyond finite numbers; a `fillRule`,
|
|
78
|
+
* `strokeCap` or `strokeJoin` outside SVG's values; a `strokeJoin` for a style
|
|
79
|
+
* without strokes; a style that names a shared style (`styleId`) and no
|
|
80
|
+
* `strokes` of its own, whose strokes would be the shared style's; a stroke
|
|
81
|
+
* whose own `dashCap` differs from `strokeCap` on a path whose open ends are
|
|
82
|
+
* drawn with the dash ends (several open parts, or a stroke that is inside
|
|
83
|
+
* or outside), because one cap draws both there; and an option this function
|
|
84
|
+
* does not know.
|
|
85
|
+
*
|
|
86
|
+
* The rest of the layer (`id`, `name`, `style`, `opacity`) is checked when
|
|
87
|
+
* the layer enters a document, as for any other layer.
|
|
88
|
+
*/
|
|
89
|
+
export declare function pathNodeFromSvgPath(svgPath: SvgPathImport): PathNode;
|