@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,548 @@
|
|
|
1
|
+
// Conditions and computed fields of a component's layers (docs/components/
|
|
2
|
+
// design.md 8.6): each expression is parsed and checked once per component
|
|
3
|
+
// version, evaluated for one set of property values, and its result written
|
|
4
|
+
// into the layer's model field, clamped to the field's range (8.4, "Defined
|
|
5
|
+
// results"). An expression that does not check is left out, so the field
|
|
6
|
+
// keeps its stored value and an invalid condition counts as no condition
|
|
7
|
+
// (8.5).
|
|
8
|
+
import { paintBox } from "./linear-call.js";
|
|
9
|
+
import { componentPropertyExpressionValue, computableFieldType, componentExpressionEnvironment, storedFieldValue, variableExpressionValue, variablesByExpressionName, } from "./component-expressions.js";
|
|
10
|
+
import { computableFieldsOf, effectivePropertyValue, findComponentProperty, propertyValueFieldId, } from "./component-properties.js";
|
|
11
|
+
import { ExpressionCache } from "./expressions/cache.js";
|
|
12
|
+
import { evaluateExpression } from "./expressions/evaluate.js";
|
|
13
|
+
import { expressionColorToHex } from "./expressions/values.js";
|
|
14
|
+
import { getDerivedAutoSizedTextFrame, resolveTextStyle, splitCssFontFamilies } from "./text-measurement.js";
|
|
15
|
+
import { inheritVariableModes } from "./variable-modes.js";
|
|
16
|
+
import { isContainerNode, isValuedComponentProperty, } from "./types.js";
|
|
17
|
+
import { entryOf } from "./id-table.js";
|
|
18
|
+
/** The result for a component with nothing to compute. */
|
|
19
|
+
export const UNCOMPUTED_COMPONENT = { nodes: new Map(), leftOut: new Set(), errors: [] };
|
|
20
|
+
/**
|
|
21
|
+
* Parses and checks every expression and condition on `component`'s layers
|
|
22
|
+
* (nested components are not entered). `cache` and `version` let a later
|
|
23
|
+
* call reuse the parsed forms while the component and variables are
|
|
24
|
+
* unchanged.
|
|
25
|
+
*/
|
|
26
|
+
export function checkComponentProgram(document, component, cache = new ExpressionCache(), version = 0) {
|
|
27
|
+
const layers = new Map();
|
|
28
|
+
const errors = [];
|
|
29
|
+
const environments = new Map();
|
|
30
|
+
const environment = (storedType) => {
|
|
31
|
+
const key = storedType === undefined ? "" : JSON.stringify(storedType);
|
|
32
|
+
let found = environments.get(key);
|
|
33
|
+
if (found === undefined) {
|
|
34
|
+
found = componentExpressionEnvironment(document, component, storedType);
|
|
35
|
+
environments.set(key, found);
|
|
36
|
+
}
|
|
37
|
+
return found;
|
|
38
|
+
};
|
|
39
|
+
const check = (node, field, source) => {
|
|
40
|
+
const expected = computableFieldType(document, node, field);
|
|
41
|
+
if (expected === undefined) {
|
|
42
|
+
errors.push({
|
|
43
|
+
nodeId: node.id,
|
|
44
|
+
field,
|
|
45
|
+
source,
|
|
46
|
+
errors: [{ message: `The field ${field} cannot be computed on this layer`, span: { start: 0, end: source.length } }],
|
|
47
|
+
});
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const checked = cache.check(source, expected, environment(field === "condition" ? undefined : expected), version);
|
|
51
|
+
if (checked.result.ok && checked.expression !== undefined)
|
|
52
|
+
return checked.expression;
|
|
53
|
+
errors.push({ nodeId: node.id, field, source, errors: checked.result.errors });
|
|
54
|
+
return undefined;
|
|
55
|
+
};
|
|
56
|
+
const visit = (id, isRoot) => {
|
|
57
|
+
const node = entryOf(document.nodes, id);
|
|
58
|
+
if (node === undefined)
|
|
59
|
+
return;
|
|
60
|
+
const fields = [];
|
|
61
|
+
for (const [field, source] of Object.entries(node.expressions ?? {})) {
|
|
62
|
+
if (source === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
const expression = check(node, field, source);
|
|
65
|
+
if (expression !== undefined)
|
|
66
|
+
fields.push({ field: field, expression });
|
|
67
|
+
}
|
|
68
|
+
const condition = node.condition === undefined || isRoot ? undefined : check(node, "condition", node.condition);
|
|
69
|
+
if (fields.length > 0 || condition !== undefined) {
|
|
70
|
+
layers.set(id, { ...(condition === undefined ? {} : { condition }), fields });
|
|
71
|
+
}
|
|
72
|
+
// A nested instance's own component is a separate program.
|
|
73
|
+
if (isContainerNode(node))
|
|
74
|
+
node.children.forEach((childId) => visit(childId, false));
|
|
75
|
+
};
|
|
76
|
+
visit(component.rootId, true);
|
|
77
|
+
return { layers, errors, empty: layers.size === 0 };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The instance's values for `component`'s properties with defaults filled
|
|
81
|
+
* in, in the component's property order: the key of a computed result.
|
|
82
|
+
* @since 0.25.0
|
|
83
|
+
*/
|
|
84
|
+
export function filledPropertyValues(component, values = {}) {
|
|
85
|
+
return (component.properties ?? []).filter(isValuedComponentProperty).map((property) => effectivePropertyValue(property, entryOf(values, property.id)));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Evaluates `program` for an instance with `propertyValues`: conditions
|
|
89
|
+
* first (a left-out layer's fields are not computed), then the computed
|
|
90
|
+
* fields, written into the layer's model fields. Variables read in `modes`,
|
|
91
|
+
* the modes in effect at the instance (its component root's and its own
|
|
92
|
+
* choices included), with each layer's own `variableModes` on top for that
|
|
93
|
+
* layer and its sublayers.
|
|
94
|
+
*/
|
|
95
|
+
export function evaluateComponentProgram(document, component, program, propertyValues = {}, modes) {
|
|
96
|
+
if (program.empty)
|
|
97
|
+
return UNCOMPUTED_COMPONENT;
|
|
98
|
+
const properties = new Map((component.properties ?? []).filter(isValuedComponentProperty).map((property) => [
|
|
99
|
+
property.name,
|
|
100
|
+
componentPropertyExpressionValue(property, entryOf(propertyValues, property.id)),
|
|
101
|
+
]));
|
|
102
|
+
const variables = variablesByExpressionName(document.theme);
|
|
103
|
+
const environments = new Map();
|
|
104
|
+
const environmentFor = (layerModes) => {
|
|
105
|
+
let found = environments.get(layerModes);
|
|
106
|
+
if (found === undefined) {
|
|
107
|
+
found = {
|
|
108
|
+
propertyValue: (name) => properties.get(name),
|
|
109
|
+
variableValue: (name) => {
|
|
110
|
+
const located = variables.get(name);
|
|
111
|
+
return located === undefined ? undefined : variableExpressionValue(located, layerModes);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
environments.set(layerModes, found);
|
|
115
|
+
}
|
|
116
|
+
return found;
|
|
117
|
+
};
|
|
118
|
+
const nodes = new Map();
|
|
119
|
+
const leftOut = new Set();
|
|
120
|
+
const errors = [];
|
|
121
|
+
const visit = (id, parentModes) => {
|
|
122
|
+
const node = entryOf(document.nodes, id);
|
|
123
|
+
if (node === undefined)
|
|
124
|
+
return;
|
|
125
|
+
// The root's own modes are already in `modes`, under the instance's.
|
|
126
|
+
const layerModes = id === component.rootId ? parentModes : inheritVariableModes(parentModes, node.variableModes);
|
|
127
|
+
const base = environmentFor(layerModes);
|
|
128
|
+
const layer = program.layers.get(id);
|
|
129
|
+
if (layer?.condition !== undefined) {
|
|
130
|
+
const shown = evaluateExpression(layer.condition, base);
|
|
131
|
+
if (shown.kind === "boolean" && !shown.value) {
|
|
132
|
+
leftOut.add(id);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (layer !== undefined && layer.fields.length > 0) {
|
|
137
|
+
const results = layer.fields.map(({ field, expression }) => {
|
|
138
|
+
const stored = storedFieldValue(document, node, field);
|
|
139
|
+
const value = evaluateExpression(expression, { ...base, ...(stored !== undefined && { stored }), paintBox: () => paintBox(node) });
|
|
140
|
+
return { field, value };
|
|
141
|
+
});
|
|
142
|
+
nodes.set(id, applyComputedFields(document, node, results, (field, message) => {
|
|
143
|
+
const source = node.expressions?.[field] ?? "";
|
|
144
|
+
errors.push({ nodeId: id, field, source, errors: [{ message, span: { start: 0, end: source.length } }] });
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
if (isContainerNode(node))
|
|
148
|
+
node.children.forEach((childId) => visit(childId, layerModes));
|
|
149
|
+
};
|
|
150
|
+
visit(component.rootId, modes);
|
|
151
|
+
return { nodes, leftOut, errors };
|
|
152
|
+
}
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
// Writing results into model fields
|
|
155
|
+
const atLeastZero = (value) => Math.max(0, value);
|
|
156
|
+
const between = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
157
|
+
/**
|
|
158
|
+
* Text layers: the whole text as one plain string, paragraphs separated by
|
|
159
|
+
* `"\n"`, every character taking the style of the first run and every
|
|
160
|
+
* paragraph the fields of the first paragraph. The paragraphs after the first
|
|
161
|
+
* take the space above of the source's second paragraph, or the first's when
|
|
162
|
+
* it has one; without one of their own, the text's `paragraphSpacing` puts
|
|
163
|
+
* them apart.
|
|
164
|
+
*/
|
|
165
|
+
export function paragraphsFromCharacters(characters, source) {
|
|
166
|
+
const first = source[0];
|
|
167
|
+
const firstRun = first?.runs[0];
|
|
168
|
+
const { runs: _runs, ...paragraphFields } = first ?? { runs: [] };
|
|
169
|
+
const second = source[1];
|
|
170
|
+
const { spacingBefore: _spacing, ...laterFields } = paragraphFields;
|
|
171
|
+
const later = second === undefined ? paragraphFields
|
|
172
|
+
: second.spacingBefore === undefined ? laterFields : { ...laterFields, spacingBefore: second.spacingBefore };
|
|
173
|
+
return characters.split("\n").map((text, index) => ({
|
|
174
|
+
...(index === 0 ? paragraphFields : later),
|
|
175
|
+
runs: [{ ...(firstRun ?? {}), text }],
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
function restyledRuns(paragraphs, overrides) {
|
|
179
|
+
const restyle = (run) => ({ ...run, overrides: { ...run.overrides, ...overrides } });
|
|
180
|
+
return paragraphs.map((paragraph) => ({ ...paragraph, runs: paragraph.runs.map(restyle) }));
|
|
181
|
+
}
|
|
182
|
+
/** Font size, weight and the rest, clamped to the ranges the panel allows. */
|
|
183
|
+
function textOverrides(field, value, storedLineHeight) {
|
|
184
|
+
switch (field) {
|
|
185
|
+
case "fontFamily":
|
|
186
|
+
return value.kind === "string" ? { fontFamily: value.value } : {};
|
|
187
|
+
case "fontSize":
|
|
188
|
+
return value.kind === "length" ? { fontSize: atLeastZero(value.value) } : {};
|
|
189
|
+
case "fontWeight":
|
|
190
|
+
return value.kind === "number" ? { fontWeight: between(value.value, 1, 1000) } : {};
|
|
191
|
+
case "lineHeight":
|
|
192
|
+
// A percent of the font size; the model stores the multiplier.
|
|
193
|
+
return value.kind === "percent" ? { lineHeight: atLeastZero(value.value / 100) } : {};
|
|
194
|
+
case "letterSpacing":
|
|
195
|
+
return value.kind === "length" ? { letterSpacing: value.value } : {};
|
|
196
|
+
case "textColor":
|
|
197
|
+
return value.kind === "color" ? { color: expressionColorToHex(value.value) } : {};
|
|
198
|
+
case "textStyle": {
|
|
199
|
+
if (value.kind !== "text_style")
|
|
200
|
+
return {};
|
|
201
|
+
const size = atLeastZero(value.value.fontSize);
|
|
202
|
+
return {
|
|
203
|
+
fontFamily: value.value.fontFamily,
|
|
204
|
+
fontWeight: between(value.value.fontWeight, 1, 1000),
|
|
205
|
+
fontSize: size,
|
|
206
|
+
// `line_height` is a length: the multiplier is it divided by the font
|
|
207
|
+
// size. At a zero font size the stored multiplier stays.
|
|
208
|
+
lineHeight: size > 0 ? atLeastZero(value.value.lineHeightPixels / size) : storedLineHeight,
|
|
209
|
+
letterSpacing: value.value.letterSpacing,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
default:
|
|
213
|
+
return {};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The document's font asset for `fontFamily` (its first CSS family, case
|
|
218
|
+
* insensitive), the run's italic style first, then the nearest weight.
|
|
219
|
+
*/
|
|
220
|
+
function documentFontAsset(document, fontFamily, weight, italic) {
|
|
221
|
+
const family = (splitCssFontFamilies(fontFamily)[0] ?? fontFamily).replace(/^(["'])(.*)\1$/, "$2").toLowerCase();
|
|
222
|
+
const style = italic ? "italic" : "normal";
|
|
223
|
+
const rank = (asset) => (asset.style === style ? 0 : asset.style === "normal" ? 1 : 2);
|
|
224
|
+
return Object.values(document.assets)
|
|
225
|
+
.filter((asset) => asset.kind === "font" && asset.family.toLowerCase() === family)
|
|
226
|
+
.sort((left, right) => rank(left) - rank(right) || Math.abs(left.weight - weight) - Math.abs(right.weight - weight))[0];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Runs whose font family or weight is computed take the document's font
|
|
230
|
+
* asset for their family and weight, since the font asset, not the family
|
|
231
|
+
* name, is what draws them. A computed family with no font in the document
|
|
232
|
+
* is an error message; a computed weight in a family with none keeps the
|
|
233
|
+
* run's font.
|
|
234
|
+
*/
|
|
235
|
+
function withFontAssets(document, paragraphs, familyComputed) {
|
|
236
|
+
let missing;
|
|
237
|
+
const refont = (run) => {
|
|
238
|
+
const style = resolveTextStyle(document, run.styleId, run.overrides);
|
|
239
|
+
const asset = documentFontAsset(document, style.fontFamily, style.fontWeight, style.italic === true);
|
|
240
|
+
if (asset === undefined) {
|
|
241
|
+
if (familyComputed)
|
|
242
|
+
missing ??= `No font in this document has the family "${style.fontFamily}"`;
|
|
243
|
+
return run;
|
|
244
|
+
}
|
|
245
|
+
return { ...run, overrides: { ...run.overrides, fontAssetId: asset.id } };
|
|
246
|
+
};
|
|
247
|
+
const next = paragraphs.map((paragraph) => ({ ...paragraph, runs: paragraph.runs.map(refont) }));
|
|
248
|
+
return missing ?? next;
|
|
249
|
+
}
|
|
250
|
+
/** Sorts a list of effects into the model's shadows and its two blurs; the last blur of each kind wins. */
|
|
251
|
+
function sortedEffects(items) {
|
|
252
|
+
const shadows = [];
|
|
253
|
+
let layerBlur;
|
|
254
|
+
let backgroundBlur;
|
|
255
|
+
for (const item of items) {
|
|
256
|
+
if (item.kind !== "effect")
|
|
257
|
+
continue;
|
|
258
|
+
const effect = item.value;
|
|
259
|
+
if (effect.kind === "shadow")
|
|
260
|
+
shadows.push({ ...effect.shadow, blur: atLeastZero(effect.shadow.blur) });
|
|
261
|
+
else if (effect.kind === "layer_blur")
|
|
262
|
+
layerBlur = atLeastZero(effect.radius);
|
|
263
|
+
else
|
|
264
|
+
backgroundBlur = atLeastZero(effect.radius);
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
shadows,
|
|
268
|
+
...(layerBlur === undefined ? {} : { layerBlur }),
|
|
269
|
+
...(backgroundBlur === undefined ? {} : { backgroundBlur }),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function propertyValueOf(document, node, propertyId, value) {
|
|
273
|
+
if (node.type !== "instance")
|
|
274
|
+
return undefined;
|
|
275
|
+
const nested = entryOf(document.components, node.componentId);
|
|
276
|
+
const property = nested === undefined ? undefined : findComponentProperty(nested, propertyId);
|
|
277
|
+
if (property === undefined)
|
|
278
|
+
return undefined;
|
|
279
|
+
switch (value.kind) {
|
|
280
|
+
case "boolean":
|
|
281
|
+
case "string":
|
|
282
|
+
return value.value;
|
|
283
|
+
case "number":
|
|
284
|
+
case "length":
|
|
285
|
+
case "percent":
|
|
286
|
+
case "angle":
|
|
287
|
+
return value.value;
|
|
288
|
+
case "color":
|
|
289
|
+
return expressionColorToHex(value.value);
|
|
290
|
+
case "component":
|
|
291
|
+
return value.id;
|
|
292
|
+
case "enum":
|
|
293
|
+
return property.kind === "enum" ? property.options.find((option) => option.name === value.option)?.id : undefined;
|
|
294
|
+
default:
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Write order: `characters` and `textStyle` before the others, since they
|
|
300
|
+
* rebuild what the others restyle, and `cornerRadius` last, since it clears
|
|
301
|
+
* `cornerRadii`.
|
|
302
|
+
*/
|
|
303
|
+
const FIELD_ORDER = { characters: 0, textStyle: 1, cornerRadius: 3, lineHeightMultiplier: 3 };
|
|
304
|
+
/**
|
|
305
|
+
* `node` with each computed value written into its model field and clamped
|
|
306
|
+
* to the field's range. Fields the node type cannot compute are ignored. A
|
|
307
|
+
* text layer that sizes itself is measured again when its text changed.
|
|
308
|
+
* @since 0.25.0
|
|
309
|
+
*/
|
|
310
|
+
export function applyComputedFields(document, node, results, onError) {
|
|
311
|
+
const allowed = new Set(computableFieldsOf(node));
|
|
312
|
+
const next = { ...node };
|
|
313
|
+
let textChanged = false;
|
|
314
|
+
const style = () => {
|
|
315
|
+
const current = { ...next.style };
|
|
316
|
+
next.style = current;
|
|
317
|
+
return current;
|
|
318
|
+
};
|
|
319
|
+
const layout = () => {
|
|
320
|
+
const current = next.layout;
|
|
321
|
+
if (current === undefined || current.kind === "absolute")
|
|
322
|
+
return undefined;
|
|
323
|
+
const copy = { ...current };
|
|
324
|
+
next.layout = copy;
|
|
325
|
+
return copy;
|
|
326
|
+
};
|
|
327
|
+
const firstStyle = () => {
|
|
328
|
+
const run = next.paragraphs?.[0]?.runs[0];
|
|
329
|
+
return resolveTextStyle(document, run?.styleId, run?.overrides);
|
|
330
|
+
};
|
|
331
|
+
const ordered = [...results].sort((a, b) => (FIELD_ORDER[a.field] ?? 2) - (FIELD_ORDER[b.field] ?? 2));
|
|
332
|
+
for (const { field, value } of ordered) {
|
|
333
|
+
const propertyId = propertyValueFieldId(field);
|
|
334
|
+
if (propertyId !== undefined) {
|
|
335
|
+
const converted = propertyValueOf(document, node, propertyId, value);
|
|
336
|
+
if (converted !== undefined) {
|
|
337
|
+
next.propertyValues = { ...next.propertyValues, [propertyId]: converted };
|
|
338
|
+
}
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (!allowed.has(field))
|
|
342
|
+
continue;
|
|
343
|
+
const number = "value" in value && typeof value.value === "number" ? value.value : 0;
|
|
344
|
+
switch (field) {
|
|
345
|
+
case "x":
|
|
346
|
+
case "y":
|
|
347
|
+
next.frame = { ...next.frame, [field]: number };
|
|
348
|
+
break;
|
|
349
|
+
case "rotation":
|
|
350
|
+
next.rotation = number;
|
|
351
|
+
break;
|
|
352
|
+
case "transform":
|
|
353
|
+
if (value.kind === "list" && value.items.length === 6 && value.items.every((item) => item.kind === "number")) {
|
|
354
|
+
next.transform = value.items.map((item) => item.value);
|
|
355
|
+
}
|
|
356
|
+
else
|
|
357
|
+
onError?.(field, "A transform needs six numbers");
|
|
358
|
+
break;
|
|
359
|
+
case "clipContent":
|
|
360
|
+
if (value.kind === "boolean")
|
|
361
|
+
next.clipContent = value.value;
|
|
362
|
+
break;
|
|
363
|
+
case "constraintSize":
|
|
364
|
+
if (value.kind === "size")
|
|
365
|
+
next.constraintSize = { width: atLeastZero(value.width), height: atLeastZero(value.height) };
|
|
366
|
+
break;
|
|
367
|
+
case "lineHeightMultiplier":
|
|
368
|
+
if (node.type === "text") {
|
|
369
|
+
next.paragraphs = restyledRuns(next.paragraphs, { lineHeight: atLeastZero(number) });
|
|
370
|
+
textChanged = true;
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
case "paragraphSpacing":
|
|
374
|
+
next.paragraphSpacing = atLeastZero(number);
|
|
375
|
+
textChanged = true;
|
|
376
|
+
break;
|
|
377
|
+
case "resizing.width":
|
|
378
|
+
case "resizing.height":
|
|
379
|
+
if (value.kind === "enum")
|
|
380
|
+
next.resizing = { ...next.resizing, [field.slice(9)]: value.option };
|
|
381
|
+
break;
|
|
382
|
+
case "layout.widthSizing":
|
|
383
|
+
case "layout.heightSizing": {
|
|
384
|
+
const target = layout();
|
|
385
|
+
if (target !== undefined && value.kind === "enum")
|
|
386
|
+
target[field.slice(7)] = value.option;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
case "constraints.horizontal":
|
|
390
|
+
case "constraints.vertical":
|
|
391
|
+
if (value.kind === "enum")
|
|
392
|
+
next.constraints = { horizontal: "left", vertical: "top", ...next.constraints, [field.slice(12)]: value.option };
|
|
393
|
+
break;
|
|
394
|
+
case "startCap":
|
|
395
|
+
case "endCap":
|
|
396
|
+
if (value.kind === "enum")
|
|
397
|
+
next[field] = value.option;
|
|
398
|
+
break;
|
|
399
|
+
case "visible":
|
|
400
|
+
if (value.kind === "boolean")
|
|
401
|
+
next.visible = value.value;
|
|
402
|
+
break;
|
|
403
|
+
case "opacity":
|
|
404
|
+
next.opacity = between(number, 0, 1);
|
|
405
|
+
break;
|
|
406
|
+
case "fills":
|
|
407
|
+
if (value.kind === "list") {
|
|
408
|
+
style().fills = value.items.flatMap((item) => (item.kind === "paint" ? [item.value] : []));
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
case "strokes":
|
|
412
|
+
if (value.kind === "list") {
|
|
413
|
+
style().strokes = value.items.flatMap((item) => (item.kind === "stroke" ? [{ ...item.value, width: atLeastZero(item.value.width) }] : []));
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
case "effects":
|
|
417
|
+
if (value.kind === "list") {
|
|
418
|
+
const sorted = sortedEffects(value.items);
|
|
419
|
+
const target = style();
|
|
420
|
+
target.shadows = sorted.shadows;
|
|
421
|
+
if (sorted.layerBlur === undefined)
|
|
422
|
+
delete target.layerBlur;
|
|
423
|
+
else
|
|
424
|
+
target.layerBlur = sorted.layerBlur;
|
|
425
|
+
if (sorted.backgroundBlur === undefined)
|
|
426
|
+
delete target.backgroundBlur;
|
|
427
|
+
else
|
|
428
|
+
target.backgroundBlur = sorted.backgroundBlur;
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
case "cornerRadius": {
|
|
432
|
+
// One radius for every corner, as the panel's single field sets it.
|
|
433
|
+
const target = style();
|
|
434
|
+
target.cornerRadius = atLeastZero(number);
|
|
435
|
+
delete target.cornerRadii;
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
case "cornerRadii":
|
|
439
|
+
if (value.kind === "corners") {
|
|
440
|
+
const radii = value.value;
|
|
441
|
+
style().cornerRadii = {
|
|
442
|
+
topLeft: atLeastZero(radii.topLeft),
|
|
443
|
+
topRight: atLeastZero(radii.topRight),
|
|
444
|
+
bottomRight: atLeastZero(radii.bottomRight),
|
|
445
|
+
bottomLeft: atLeastZero(radii.bottomLeft),
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
case "cornerSmoothing":
|
|
450
|
+
style().cornerSmoothing = between(number, 0, 1);
|
|
451
|
+
break;
|
|
452
|
+
case "width":
|
|
453
|
+
case "height":
|
|
454
|
+
next.frame = { ...next.frame, [field]: atLeastZero(number) };
|
|
455
|
+
break;
|
|
456
|
+
case "minWidth":
|
|
457
|
+
case "maxWidth":
|
|
458
|
+
case "minHeight":
|
|
459
|
+
case "maxHeight":
|
|
460
|
+
next.resizing = { ...next.resizing, [field]: atLeastZero(number) };
|
|
461
|
+
break;
|
|
462
|
+
case "gap":
|
|
463
|
+
case "wrapGap":
|
|
464
|
+
case "direction":
|
|
465
|
+
case "align":
|
|
466
|
+
case "justify":
|
|
467
|
+
case "wrap": {
|
|
468
|
+
const target = layout();
|
|
469
|
+
if (target === undefined || target.kind === "grid")
|
|
470
|
+
break;
|
|
471
|
+
if (field === "gap" || field === "wrapGap")
|
|
472
|
+
target[field] = number;
|
|
473
|
+
else if (field === "wrap")
|
|
474
|
+
target.wrap = value.kind === "boolean" && value.value;
|
|
475
|
+
else if (value.kind === "enum") {
|
|
476
|
+
const option = value.option.replace(/_/g, "-");
|
|
477
|
+
if (field === "direction")
|
|
478
|
+
target.kind = option;
|
|
479
|
+
else
|
|
480
|
+
target[field] = option;
|
|
481
|
+
}
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
case "columnGap":
|
|
485
|
+
case "rowGap": {
|
|
486
|
+
const target = layout();
|
|
487
|
+
if (target?.kind === "grid")
|
|
488
|
+
target[field] = number;
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
case "padding": {
|
|
492
|
+
const target = layout();
|
|
493
|
+
if (target !== undefined && value.kind === "insets") {
|
|
494
|
+
const padding = value.value;
|
|
495
|
+
target.padding = {
|
|
496
|
+
top: atLeastZero(padding.top),
|
|
497
|
+
right: atLeastZero(padding.right),
|
|
498
|
+
bottom: atLeastZero(padding.bottom),
|
|
499
|
+
left: atLeastZero(padding.left),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
case "characters":
|
|
505
|
+
if (value.kind === "string" && node.type === "text") {
|
|
506
|
+
next.paragraphs = paragraphsFromCharacters(value.value, node.paragraphs);
|
|
507
|
+
textChanged = true;
|
|
508
|
+
}
|
|
509
|
+
break;
|
|
510
|
+
case "fontFamily":
|
|
511
|
+
case "fontSize":
|
|
512
|
+
case "fontWeight":
|
|
513
|
+
case "lineHeight":
|
|
514
|
+
case "letterSpacing":
|
|
515
|
+
case "textColor":
|
|
516
|
+
case "textStyle": {
|
|
517
|
+
if (node.type !== "text")
|
|
518
|
+
break;
|
|
519
|
+
const before = firstStyle();
|
|
520
|
+
const overrides = textOverrides(field, value, before.lineHeight);
|
|
521
|
+
const metricsChanged = Object.entries(overrides).some(([key, value]) => key !== "color" && before[key] !== value);
|
|
522
|
+
const restyled = restyledRuns(next.paragraphs, overrides);
|
|
523
|
+
const refonted = overrides.fontFamily === undefined && overrides.fontWeight === undefined
|
|
524
|
+
? restyled
|
|
525
|
+
: withFontAssets(document, restyled, overrides.fontFamily !== undefined);
|
|
526
|
+
if (typeof refonted === "string") {
|
|
527
|
+
onError?.(field, refonted);
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
next.paragraphs = refonted;
|
|
531
|
+
if (metricsChanged)
|
|
532
|
+
textChanged = true;
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
case "componentId":
|
|
536
|
+
if (value.kind === "component" && entryOf(document.components, value.id) !== undefined)
|
|
537
|
+
next.componentId = value.id;
|
|
538
|
+
break;
|
|
539
|
+
default:
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const computed = next;
|
|
544
|
+
if (textChanged && computed.type === "text" && computed.autoResize !== "none") {
|
|
545
|
+
return { ...computed, frame: getDerivedAutoSizedTextFrame(document, computed, computed.paragraphs) };
|
|
546
|
+
}
|
|
547
|
+
return computed;
|
|
548
|
+
}
|