@moondraft/import 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/LICENSE +34 -0
- package/README.md +36 -2
- package/SOURCE.md +394 -0
- package/dist/adapter/convert.d.ts +144 -0
- package/dist/adapter/convert.js +2811 -0
- package/dist/adapter/figma-descriptions.d.ts +7 -0
- package/dist/adapter/figma-descriptions.js +34 -0
- package/dist/adapter/figma-grids.d.ts +12 -0
- package/dist/adapter/figma-grids.js +175 -0
- package/dist/adapter/figma-handoff.d.ts +12 -0
- package/dist/adapter/figma-handoff.js +167 -0
- package/dist/adapter/figma-hyperlinks.d.ts +13 -0
- package/dist/adapter/figma-hyperlinks.js +77 -0
- package/dist/adapter/figma.d.ts +12 -0
- package/dist/adapter/figma.js +40 -0
- package/dist/adapter/file-components.d.ts +20 -0
- package/dist/adapter/file-components.js +352 -0
- package/dist/adapter/file-resources.d.ts +29 -0
- package/dist/adapter/file-resources.js +851 -0
- package/dist/adapter/image-crop.d.ts +18 -0
- package/dist/adapter/image-crop.js +30 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.js +9 -0
- package/dist/adapter/link.d.ts +49 -0
- package/dist/adapter/link.js +892 -0
- package/dist/adapter/payload.d.ts +31 -0
- package/dist/adapter/payload.js +78 -0
- package/dist/adapter/shapes.d.ts +31 -0
- package/dist/adapter/shapes.js +75 -0
- package/dist/adapter/variables.d.ts +45 -0
- package/dist/adapter/variables.js +106 -0
- package/dist/figma-file.d.ts +38 -0
- package/dist/figma-file.js +97 -0
- package/dist/figma-worker.d.ts +11 -0
- package/dist/figma-worker.js +12 -0
- package/dist/figma.d.ts +26 -0
- package/dist/figma.js +230 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +50 -0
- package/dist/report.d.ts +42 -0
- package/dist/report.js +142 -0
- package/dist/serialize.d.ts +7 -0
- package/dist/serialize.js +79 -0
- package/dist/svg.d.ts +33 -0
- package/dist/svg.js +44 -0
- package/dist/syntax.d.ts +8 -0
- package/dist/syntax.js +19 -0
- package/dist/taco/figma-import/clipboard.d.ts +25 -0
- package/dist/taco/figma-import/clipboard.js +87 -0
- package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
- package/dist/taco/figma-import/clipboardSize.js +107 -0
- package/dist/taco/figma-import/container/compression.d.ts +9 -0
- package/dist/taco/figma-import/container/compression.js +174 -0
- package/dist/taco/figma-import/container/error.d.ts +15 -0
- package/dist/taco/figma-import/container/error.js +19 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
- package/dist/taco/figma-import/container/limits.d.ts +22 -0
- package/dist/taco/figma-import/container/limits.js +22 -0
- package/dist/taco/figma-import/container/zip.d.ts +14 -0
- package/dist/taco/figma-import/container/zip.js +154 -0
- package/dist/taco/figma-import/figFile.d.ts +34 -0
- package/dist/taco/figma-import/figFile.js +91 -0
- package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
- package/dist/taco/figma-import/figFileDocument.js +100 -0
- package/dist/taco/figma-import/import/blobs.d.ts +10 -0
- package/dist/taco/figma-import/import/blobs.js +23 -0
- package/dist/taco/figma-import/import/carry.d.ts +24 -0
- package/dist/taco/figma-import/import/carry.js +66 -0
- package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
- package/dist/taco/figma-import/import/componentProps.js +329 -0
- package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
- package/dist/taco/figma-import/import/componentSets.js +647 -0
- package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
- package/dist/taco/figma-import/import/converters/effects.js +127 -0
- package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
- package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
- package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
- package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/frame.js +63 -0
- package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
- package/dist/taco/figma-import/import/converters/gradient.js +108 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
- package/dist/taco/figma-import/import/converters/group.js +30 -0
- package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
- package/dist/taco/figma-import/import/converters/image.js +94 -0
- package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
- package/dist/taco/figma-import/import/converters/layout.js +187 -0
- package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
- package/dist/taco/figma-import/import/converters/line.js +40 -0
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
- package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
- package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
- package/dist/taco/figma-import/import/converters/section.js +29 -0
- package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
- package/dist/taco/figma-import/import/converters/shared.js +372 -0
- package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
- package/dist/taco/figma-import/import/converters/text.js +707 -0
- package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
- package/dist/taco/figma-import/import/converters/vector.js +609 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
- package/dist/taco/figma-import/import/fields.d.ts +15 -0
- package/dist/taco/figma-import/import/fields.js +29 -0
- package/dist/taco/figma-import/import/instances.d.ts +184 -0
- package/dist/taco/figma-import/import/instances.js +1530 -0
- package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
- package/dist/taco/figma-import/import/nestingCycles.js +488 -0
- package/dist/taco/figma-import/import/slots.d.ts +56 -0
- package/dist/taco/figma-import/import/slots.js +96 -0
- package/dist/taco/figma-import/import/styles.d.ts +48 -0
- package/dist/taco/figma-import/import/styles.js +48 -0
- package/dist/taco/figma-import/import/tree.d.ts +66 -0
- package/dist/taco/figma-import/import/tree.js +194 -0
- package/dist/taco/figma-import/import/types.d.ts +232 -0
- package/dist/taco/figma-import/import/types.js +33 -0
- package/dist/taco/figma-import/import/variables.d.ts +137 -0
- package/dist/taco/figma-import/import/variables.js +769 -0
- package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
- package/dist/taco/figma-import/import/variantTrees.js +520 -0
- package/dist/taco/figma-import/import/walk.d.ts +207 -0
- package/dist/taco/figma-import/import/walk.js +1464 -0
- package/dist/taco/figma-import/index.d.ts +22 -0
- package/dist/taco/figma-import/index.js +13 -0
- package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
- package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
- package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
- package/dist/taco/figma-import/kiwi/error.js +29 -0
- package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
- package/dist/taco/figma-import/kiwi/limits.js +18 -0
- package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
- package/dist/taco/figma-import/kiwi/message.js +147 -0
- package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
- package/dist/taco/figma-import/kiwi/schema.js +206 -0
- package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
- package/dist/taco/figma-import/kiwi/types.js +18 -0
- package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
- package/dist/taco/model/agent-hidden-fields.js +29 -0
- package/dist/taco/model/asset-users.d.ts +23 -0
- package/dist/taco/model/asset-users.js +128 -0
- package/dist/taco/model/auto-layout-lines.d.ts +32 -0
- package/dist/taco/model/auto-layout-lines.js +70 -0
- package/dist/taco/model/codec.d.ts +444 -0
- package/dist/taco/model/codec.js +5665 -0
- package/dist/taco/model/color.d.ts +11 -0
- package/dist/taco/model/color.js +61 -0
- package/dist/taco/model/comment-operations.d.ts +102 -0
- package/dist/taco/model/comment-operations.js +227 -0
- package/dist/taco/model/component-evaluation.d.ts +96 -0
- package/dist/taco/model/component-evaluation.js +555 -0
- package/dist/taco/model/component-expressions.d.ts +242 -0
- package/dist/taco/model/component-expressions.js +1082 -0
- package/dist/taco/model/component-properties.d.ts +111 -0
- package/dist/taco/model/component-properties.js +339 -0
- package/dist/taco/model/component-samples.d.ts +83 -0
- package/dist/taco/model/component-samples.js +290 -0
- package/dist/taco/model/component-validity.d.ts +85 -0
- package/dist/taco/model/component-validity.js +397 -0
- package/dist/taco/model/components.d.ts +155 -0
- package/dist/taco/model/components.js +505 -0
- package/dist/taco/model/connector-ends.d.ts +20 -0
- package/dist/taco/model/connector-ends.js +188 -0
- package/dist/taco/model/connector-geometry.d.ts +74 -0
- package/dist/taco/model/connector-geometry.js +293 -0
- package/dist/taco/model/corner-radii.d.ts +26 -0
- package/dist/taco/model/corner-radii.js +47 -0
- package/dist/taco/model/derivations.d.ts +81 -0
- package/dist/taco/model/derivations.js +151 -0
- package/dist/taco/model/export-settings.d.ts +53 -0
- package/dist/taco/model/export-settings.js +156 -0
- package/dist/taco/model/expressions/ast.d.ts +153 -0
- package/dist/taco/model/expressions/ast.js +6 -0
- package/dist/taco/model/expressions/cache.d.ts +23 -0
- package/dist/taco/model/expressions/cache.js +43 -0
- package/dist/taco/model/expressions/check.d.ts +72 -0
- package/dist/taco/model/expressions/check.js +517 -0
- package/dist/taco/model/expressions/completion.d.ts +61 -0
- package/dist/taco/model/expressions/completion.js +421 -0
- package/dist/taco/model/expressions/evaluate.d.ts +32 -0
- package/dist/taco/model/expressions/evaluate.js +519 -0
- package/dist/taco/model/expressions/forms.d.ts +84 -0
- package/dist/taco/model/expressions/forms.js +200 -0
- package/dist/taco/model/expressions/index.d.ts +14 -0
- package/dist/taco/model/expressions/index.js +17 -0
- package/dist/taco/model/expressions/lexer.d.ts +42 -0
- package/dist/taco/model/expressions/lexer.js +213 -0
- package/dist/taco/model/expressions/library.d.ts +33 -0
- package/dist/taco/model/expressions/library.js +117 -0
- package/dist/taco/model/expressions/names.d.ts +43 -0
- package/dist/taco/model/expressions/names.js +99 -0
- package/dist/taco/model/expressions/parser.d.ts +15 -0
- package/dist/taco/model/expressions/parser.js +438 -0
- package/dist/taco/model/expressions/rename.d.ts +34 -0
- package/dist/taco/model/expressions/rename.js +46 -0
- package/dist/taco/model/expressions/source.d.ts +15 -0
- package/dist/taco/model/expressions/source.js +161 -0
- package/dist/taco/model/expressions/types.d.ts +119 -0
- package/dist/taco/model/expressions/types.js +102 -0
- package/dist/taco/model/expressions/values.d.ts +97 -0
- package/dist/taco/model/expressions/values.js +160 -0
- package/dist/taco/model/geometry-limits.d.ts +16 -0
- package/dist/taco/model/geometry-limits.js +67 -0
- package/dist/taco/model/geometry.d.ts +47 -0
- package/dist/taco/model/geometry.js +193 -0
- package/dist/taco/model/group-bounds.d.ts +38 -0
- package/dist/taco/model/group-bounds.js +144 -0
- package/dist/taco/model/id-table.d.ts +37 -0
- package/dist/taco/model/id-table.js +80 -0
- package/dist/taco/model/index.d.ts +25 -0
- package/dist/taco/model/index.js +27 -0
- package/dist/taco/model/instance-resolver.d.ts +376 -0
- package/dist/taco/model/instance-resolver.js +1778 -0
- package/dist/taco/model/layer-syntax.d.ts +340 -0
- package/dist/taco/model/layer-syntax.js +3506 -0
- package/dist/taco/model/layout/constraints.d.ts +84 -0
- package/dist/taco/model/layout/constraints.js +445 -0
- package/dist/taco/model/layout/frame-layout.d.ts +46 -0
- package/dist/taco/model/layout/frame-layout.js +618 -0
- package/dist/taco/model/layout/node-sizing.d.ts +163 -0
- package/dist/taco/model/layout/node-sizing.js +486 -0
- package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
- package/dist/taco/model/legacy-connector-caps.js +70 -0
- package/dist/taco/model/linear-call.d.ts +48 -0
- package/dist/taco/model/linear-call.js +58 -0
- package/dist/taco/model/new-nodes.d.ts +145 -0
- package/dist/taco/model/new-nodes.js +277 -0
- package/dist/taco/model/node-builder.d.ts +449 -0
- package/dist/taco/model/node-builder.js +2294 -0
- package/dist/taco/model/node-table-watch.d.ts +36 -0
- package/dist/taco/model/node-table-watch.js +63 -0
- package/dist/taco/model/node-transform.d.ts +39 -0
- package/dist/taco/model/node-transform.js +79 -0
- package/dist/taco/model/node-users-index.d.ts +10 -0
- package/dist/taco/model/node-users-index.js +82 -0
- package/dist/taco/model/operation-references.d.ts +80 -0
- package/dist/taco/model/operation-references.js +399 -0
- package/dist/taco/model/operations.d.ts +610 -0
- package/dist/taco/model/operations.js +2882 -0
- package/dist/taco/model/overlay-table.d.ts +71 -0
- package/dist/taco/model/overlay-table.js +171 -0
- package/dist/taco/model/override-remap.d.ts +69 -0
- package/dist/taco/model/override-remap.js +230 -0
- package/dist/taco/model/parent-table.d.ts +53 -0
- package/dist/taco/model/parent-table.js +193 -0
- package/dist/taco/model/problem-collector.d.ts +27 -0
- package/dist/taco/model/problem-collector.js +101 -0
- package/dist/taco/model/sha256.d.ts +10 -0
- package/dist/taco/model/sha256.js +79 -0
- package/dist/taco/model/shape-geometry.d.ts +96 -0
- package/dist/taco/model/shape-geometry.js +368 -0
- package/dist/taco/model/shared-node-table.d.ts +97 -0
- package/dist/taco/model/shared-node-table.js +546 -0
- package/dist/taco/model/slots.d.ts +113 -0
- package/dist/taco/model/slots.js +281 -0
- package/dist/taco/model/stroke-settings.d.ts +37 -0
- package/dist/taco/model/stroke-settings.js +90 -0
- package/dist/taco/model/svg-path-import.d.ts +89 -0
- package/dist/taco/model/svg-path-import.js +219 -0
- package/dist/taco/model/text-measurement.d.ts +142 -0
- package/dist/taco/model/text-measurement.js +846 -0
- package/dist/taco/model/text-reads.d.ts +66 -0
- package/dist/taco/model/text-reads.js +128 -0
- package/dist/taco/model/text-sizer.d.ts +358 -0
- package/dist/taco/model/text-sizer.js +996 -0
- package/dist/taco/model/theme-users.d.ts +59 -0
- package/dist/taco/model/theme-users.js +312 -0
- package/dist/taco/model/thumbnail.d.ts +15 -0
- package/dist/taco/model/thumbnail.js +34 -0
- package/dist/taco/model/types.d.ts +2369 -0
- package/dist/taco/model/types.js +366 -0
- package/dist/taco/model/unknown-property.d.ts +5 -0
- package/dist/taco/model/unknown-property.js +7 -0
- package/dist/taco/model/validated-documents.d.ts +22 -0
- package/dist/taco/model/validated-documents.js +22 -0
- package/dist/taco/model/variable-modes.d.ts +61 -0
- package/dist/taco/model/variable-modes.js +438 -0
- package/dist/taco/model/variable-references.d.ts +54 -0
- package/dist/taco/model/variable-references.js +183 -0
- package/dist/taco/model/variables.d.ts +24 -0
- package/dist/taco/model/variables.js +151 -0
- package/dist/taco/model/vector-network.d.ts +34 -0
- package/dist/taco/model/vector-network.js +411 -0
- package/dist/taco/svg-import/import-svg.d.ts +36 -0
- package/dist/taco/svg-import/import-svg.js +729 -0
- package/dist/taco/svg-import/index.d.ts +3 -0
- package/dist/taco/svg-import/index.js +3 -0
- package/dist/taco/svg-import/limits/limits.d.ts +79 -0
- package/dist/taco/svg-import/limits/limits.js +160 -0
- package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
- package/dist/taco/svg-import/paint/gradients.js +429 -0
- package/dist/taco/svg-import/paint/paint.d.ts +32 -0
- package/dist/taco/svg-import/paint/paint.js +162 -0
- package/dist/taco/svg-import/paths/paths.d.ts +58 -0
- package/dist/taco/svg-import/paths/paths.js +205 -0
- package/dist/taco/svg-import/public-types.d.ts +279 -0
- package/dist/taco/svg-import/public-types.js +56 -0
- package/dist/taco/svg-import/report/report.d.ts +44 -0
- package/dist/taco/svg-import/report/report.js +79 -0
- package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
- package/dist/taco/svg-import/reuse/reuse.js +840 -0
- package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
- package/dist/taco/svg-import/shapes/shapes.js +386 -0
- package/dist/taco/svg-import/structure/effects.d.ts +26 -0
- package/dist/taco/svg-import/structure/effects.js +618 -0
- package/dist/taco/svg-import/structure/image.d.ts +24 -0
- package/dist/taco/svg-import/structure/image.js +495 -0
- package/dist/taco/svg-import/structure/walk.d.ts +85 -0
- package/dist/taco/svg-import/structure/walk.js +544 -0
- package/dist/taco/svg-import/style/color.d.ts +40 -0
- package/dist/taco/svg-import/style/color.js +275 -0
- package/dist/taco/svg-import/style/computed.d.ts +214 -0
- package/dist/taco/svg-import/style/computed.js +1534 -0
- package/dist/taco/svg-import/style/css.d.ts +127 -0
- package/dist/taco/svg-import/style/css.js +541 -0
- package/dist/taco/svg-import/style/media.d.ts +25 -0
- package/dist/taco/svg-import/style/media.js +307 -0
- package/dist/taco/svg-import/style/properties.d.ts +43 -0
- package/dist/taco/svg-import/style/properties.js +135 -0
- package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
- package/dist/taco/svg-import/style/selector-reach.js +169 -0
- package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
- package/dist/taco/svg-import/style/selector-validity.js +307 -0
- package/dist/taco/svg-import/text/text.d.ts +29 -0
- package/dist/taco/svg-import/text/text.js +545 -0
- package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
- package/dist/taco/svg-import/transform/matrix.js +229 -0
- package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
- package/dist/taco/svg-import/tree/element-data.js +155 -0
- package/dist/taco/svg-import/tree/elements.d.ts +36 -0
- package/dist/taco/svg-import/tree/elements.js +121 -0
- package/dist/taco/svg-import/units/length.d.ts +43 -0
- package/dist/taco/svg-import/units/length.js +125 -0
- package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
- package/dist/taco/svg-import/units/viewbox.js +77 -0
- package/package.json +55 -4
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { BLEND_MODES, } from "../../../model/index.js";
|
|
2
|
+
import { field, isObject } from "../fields.js";
|
|
3
|
+
import { imagePaint } from "./image.js";
|
|
4
|
+
import { moveMark } from "../carry.js";
|
|
5
|
+
import { gradientShape, onBox } from "./gradient.js";
|
|
6
|
+
import { styleBackedList } from "../styles.js";
|
|
7
|
+
import { sizeLimitsOf } from "./layout.js";
|
|
8
|
+
import { exportSettingsOf } from "./exportSettings.js";
|
|
9
|
+
/**
|
|
10
|
+
* A Figma blend mode enum name as a Taco blend mode: `undefined` for
|
|
11
|
+
* `NORMAL` and `PASS_THROUGH` (Taco's default), `null` when Taco has no such
|
|
12
|
+
* mode (`LINEAR_BURN`, `LINEAR_DODGE`).
|
|
13
|
+
*/
|
|
14
|
+
export function blendModeOf(value) {
|
|
15
|
+
if (value === "NORMAL" || value === "PASS_THROUGH")
|
|
16
|
+
return undefined;
|
|
17
|
+
const name = value.toLowerCase().replace(/_/g, "-");
|
|
18
|
+
return BLEND_MODES.includes(name) ? name : null;
|
|
19
|
+
}
|
|
20
|
+
export function readNumbers(object, keys, where) {
|
|
21
|
+
const out = {};
|
|
22
|
+
for (const key of keys) {
|
|
23
|
+
const value = field(object, key, "number", where);
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return null;
|
|
26
|
+
out[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/** `#rrggbb`, or `#rrggbbaa` when alpha is below 1, from Figma's 0..1 channels. */
|
|
31
|
+
export function hexColor(color) {
|
|
32
|
+
const byte = (value) => Math.round(Math.min(1, Math.max(0, value)) * 255).toString(16).padStart(2, "0");
|
|
33
|
+
const alpha = color.a < 1 ? byte(color.a) : "";
|
|
34
|
+
return `#${byte(color.r)}${byte(color.g)}${byte(color.b)}${alpha}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The fields every Taco layer shares (id, name, visibility, lock, opacity and
|
|
38
|
+
* blend mode, the mask flag, the aspect ratio lock and resize constraints, see `constraintsOf`).
|
|
39
|
+
* Reports a blend mode Taco lacks, a mask that is not an alpha mask and, unless the
|
|
40
|
+
* caller imports them (`effectsImported`), effects, which are not imported yet.
|
|
41
|
+
*/
|
|
42
|
+
export function layerBase(node, walk, defaultName, effectsImported = false) {
|
|
43
|
+
const where = `node ${node.id}`;
|
|
44
|
+
const blend = field(node.change, "blendMode", "string", where);
|
|
45
|
+
const blendMode = blend === undefined ? undefined : blendModeOf(blend);
|
|
46
|
+
if (blendMode === null)
|
|
47
|
+
walk.report("property-left-out", `blend mode ${String(blend)} has no Taco equivalent`);
|
|
48
|
+
const mask = field(node.change, "mask", "boolean", where) === true;
|
|
49
|
+
let outline = false;
|
|
50
|
+
if (mask) {
|
|
51
|
+
// As grida reads Kiwi masks (packages/grida-canvas-io-figma/lib.ts:4066): maskType defaults to ALPHA,
|
|
52
|
+
// and maskIsOutline (older files) defaults to maskType OUTLINE. Taco masks by alpha only.
|
|
53
|
+
const maskType = field(node.change, "maskType", "string", where) ?? "ALPHA";
|
|
54
|
+
outline = field(node.change, "maskIsOutline", "boolean", where) ?? maskType === "OUTLINE";
|
|
55
|
+
// Moondraft patch (../carry.ts): an outline mask is carried as a vector mask, so it is not reported.
|
|
56
|
+
if (!outline && maskType !== "ALPHA") {
|
|
57
|
+
walk.report("approximated", `the ${maskType.toLowerCase()} mask is imported as an alpha mask`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!effectsImported && (field(node.change, "effects", "list", where)?.length ?? 0) > 0)
|
|
61
|
+
walk.report("property-left-out", "effects are not imported yet");
|
|
62
|
+
const constraints = constraintsOf(node.change, walk.report);
|
|
63
|
+
// Figma sets `targetAspectRatio` (width and height) when a layer's aspect ratio is locked; auto layout then keeps
|
|
64
|
+
// that ratio, whatever the layer's stored size.
|
|
65
|
+
const aspectRatio = aspectRatioOf(node.change, where);
|
|
66
|
+
const exportSettings = exportSettingsOf(node.change["exportSettings"], walk.report);
|
|
67
|
+
return {
|
|
68
|
+
id: walk.newId(),
|
|
69
|
+
name: node.name === "" ? defaultName : node.name,
|
|
70
|
+
visible: field(node.change, "visible", "boolean", where) ?? true,
|
|
71
|
+
locked: field(node.change, "locked", "boolean", where) ?? false,
|
|
72
|
+
opacity: field(node.change, "opacity", "number", where) ?? 1,
|
|
73
|
+
...(blendMode ? { blendMode } : {}),
|
|
74
|
+
...(mask ? { mask } : {}),
|
|
75
|
+
...(constraints ? { constraints } : {}),
|
|
76
|
+
...(aspectRatio === undefined ? {} : { aspectRatioLocked: true, aspectRatio }),
|
|
77
|
+
...(exportSettings === undefined ? {} : { exportSettings }),
|
|
78
|
+
...(outline ? { metadata: { figma: { maskType: "vector" } } } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Figma's locked aspect ratio (`targetAspectRatio`) as width over height, or `undefined` when unlocked or unusable. */
|
|
82
|
+
function aspectRatioOf(change, where) {
|
|
83
|
+
const target = field(change, "targetAspectRatio", "object", where);
|
|
84
|
+
const value = target === undefined ? undefined : field(target, "value", "object", `${where} targetAspectRatio`);
|
|
85
|
+
const sides = value === undefined ? null : readNumbers(value, ["x", "y"], `${where} targetAspectRatio`);
|
|
86
|
+
if (!sides || !(sides.x > 0) || !(sides.y > 0))
|
|
87
|
+
return undefined;
|
|
88
|
+
const ratio = sides.x / sides.y;
|
|
89
|
+
return Number.isFinite(ratio) ? ratio : undefined;
|
|
90
|
+
}
|
|
91
|
+
const HORIZONTAL = { MIN: "left", MAX: "right", STRETCH: "left-right", CENTER: "center", SCALE: "scale" };
|
|
92
|
+
const VERTICAL = { MIN: "top", MAX: "bottom", STRETCH: "top-bottom", CENTER: "center", SCALE: "scale" };
|
|
93
|
+
/**
|
|
94
|
+
* Figma's `horizontalConstraint` and `verticalConstraint` as Taco
|
|
95
|
+
* `constraints`, or `undefined` when both are MIN (or absent), Taco's
|
|
96
|
+
* default. A value Taco has no match for (such as FIXED_MIN) is reported and
|
|
97
|
+
* read as MIN. They are taken off again where they do not apply: from a
|
|
98
|
+
* group (carried in its metadata) by `convertGroup`, from a child in an auto layout flow by
|
|
99
|
+
* `stackChildFields`, and from a layer in a section (directly or through
|
|
100
|
+
* groups) by the walk, as Figma applies none when a section is resized.
|
|
101
|
+
*/
|
|
102
|
+
export function constraintsOf(change, report) {
|
|
103
|
+
const read = (name, table) => {
|
|
104
|
+
const value = change[name];
|
|
105
|
+
if (value === undefined)
|
|
106
|
+
return table["MIN"];
|
|
107
|
+
if (typeof value === "string" && Object.hasOwn(table, value))
|
|
108
|
+
return table[value];
|
|
109
|
+
report("property-left-out", `${name} ${String(value)} has no Taco equivalent; the layer keeps its MIN position on that axis`);
|
|
110
|
+
return table["MIN"];
|
|
111
|
+
};
|
|
112
|
+
const constraints = { horizontal: read("horizontalConstraint", HORIZONTAL), vertical: read("verticalConstraint", VERTICAL) };
|
|
113
|
+
return constraints.horizontal === "left" && constraints.vertical === "top" ? undefined : constraints;
|
|
114
|
+
}
|
|
115
|
+
/** A node's size and transform numbers, or `null` when either is incomplete, so `framedBase` leaves the node out. */
|
|
116
|
+
export function frameGeometry(node) {
|
|
117
|
+
const where = `node ${node.id}`;
|
|
118
|
+
const size = field(node.change, "size", "object", where);
|
|
119
|
+
const transform = field(node.change, "transform", "object", where);
|
|
120
|
+
const sides = size && readNumbers(size, ["x", "y"], `${where} size`);
|
|
121
|
+
const m = transform && readNumbers(transform, ["m00", "m01", "m02", "m10", "m11", "m12"], `${where} transform`);
|
|
122
|
+
return sides && m ? { sides, m } : null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The fields every framed Taco node shares, or `null` after reporting why
|
|
126
|
+
* the node is left out. Figma's `transform` maps the node's local space to
|
|
127
|
+
* its parent's (x' = m00 x + m01 y + m02, y' = m10 x + m11 y + m12); Taco
|
|
128
|
+
* keeps the unrotated frame plus a rotation about its center, clockwise in
|
|
129
|
+
* degrees, and a horizontal flip when the matrix mirrors.
|
|
130
|
+
*/
|
|
131
|
+
export function framedBase(node, walk, defaultName, effectsImported = false) {
|
|
132
|
+
const geometry = frameGeometry(node);
|
|
133
|
+
if (geometry === null) {
|
|
134
|
+
walk.report("node-left-out", "the node has no complete size or transform");
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const { sides, m } = geometry;
|
|
138
|
+
const { x: width, y: height } = sides;
|
|
139
|
+
const flipX = m.m00 * m.m11 - m.m01 * m.m10 < 0;
|
|
140
|
+
// With a flip the matrix is R·diag(-1, 1), so R's first column is minus the matrix's.
|
|
141
|
+
const radians = flipX ? Math.atan2(-m.m10, -m.m00) : Math.atan2(m.m10, m.m00);
|
|
142
|
+
const degrees = radians * 180 / Math.PI;
|
|
143
|
+
const rotation = degrees === -180 ? 180 : degrees + 0;
|
|
144
|
+
const tolerance = 1e-4;
|
|
145
|
+
if (Math.abs(m.m00 ** 2 + m.m10 ** 2 - 1) > tolerance || Math.abs(m.m01 ** 2 + m.m11 ** 2 - 1) > tolerance
|
|
146
|
+
|| Math.abs(m.m00 * m.m01 + m.m10 * m.m11) > tolerance) {
|
|
147
|
+
walk.report("approximated", "the transform scales or skews; only its position, rotation and flip are kept");
|
|
148
|
+
}
|
|
149
|
+
const centerX = m.m00 * width / 2 + m.m01 * height / 2 + m.m02;
|
|
150
|
+
const centerY = m.m10 * width / 2 + m.m11 * height / 2 + m.m12;
|
|
151
|
+
const base = layerBase(node, walk, defaultName, effectsImported);
|
|
152
|
+
const limits = sizeLimitsOf(node.change);
|
|
153
|
+
return {
|
|
154
|
+
...base,
|
|
155
|
+
frame: { x: centerX - width / 2, y: centerY - height / 2, width, height },
|
|
156
|
+
rotation,
|
|
157
|
+
...(flipX ? { flipX } : {}),
|
|
158
|
+
...(Object.keys(limits).length > 0 ? { resizing: limits } : {}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The colour that the variable bound to stop `index` of gradient `paint` (its `stopsVar` entry) gives in the modes the
|
|
163
|
+
* node is shown in, or `undefined` when the stop is not bound or the binding gives no colour. Figma stores the stops
|
|
164
|
+
* in the modes of the node's own place, so a layer of a component shown by an instance in other modes needs this.
|
|
165
|
+
*/
|
|
166
|
+
function boundStopColor(walk, paint, index, at) {
|
|
167
|
+
const bound = (field(paint, "stopsVar", "list", at) ?? [])[index];
|
|
168
|
+
if (walk.variableColor === undefined || !isObject(bound) || bound["colorVar"] === undefined)
|
|
169
|
+
return undefined;
|
|
170
|
+
const hex = walk.variableColor(bound["colorVar"]);
|
|
171
|
+
if (hex === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
const channel = (from) => parseInt(hex.slice(from, from + 2), 16) / 255;
|
|
174
|
+
return { r: channel(1), g: channel(3), b: channel(5), a: hex.length === 9 ? channel(7) : 1 };
|
|
175
|
+
}
|
|
176
|
+
/** A Figma gradient paint as a Taco paint, or a reason it is left out. */
|
|
177
|
+
function gradientPaint(node, walk, paint, type, at, box) {
|
|
178
|
+
const where = `node ${node.id}`;
|
|
179
|
+
const size = field(node.change, "size", "object", where);
|
|
180
|
+
const sides = size && readNumbers(size, ["x", "y"], `${where} size`);
|
|
181
|
+
const transform = field(paint, "transform", "object", at);
|
|
182
|
+
const m = transform && readNumbers(transform, ["m00", "m01", "m02", "m10", "m11", "m12"], `${at} transform`);
|
|
183
|
+
const stops = [];
|
|
184
|
+
for (const [index, stop] of (field(paint, "stops", "list", at) ?? []).entries()) {
|
|
185
|
+
const colorObject = isObject(stop) ? field(stop, "color", "object", `${at} stops[${String(index)}]`) : undefined;
|
|
186
|
+
const color = colorObject && readNumbers(colorObject, ["r", "g", "b", "a"], `${at} stops[${String(index)}] color`);
|
|
187
|
+
const position = isObject(stop) ? field(stop, "position", "number", `${at} stops[${String(index)}]`) : undefined;
|
|
188
|
+
if (!color || position === undefined)
|
|
189
|
+
return "a gradient stop has no colour or position";
|
|
190
|
+
stops.push({ color: boundStopColor(walk, paint, index, at) ?? color, position });
|
|
191
|
+
}
|
|
192
|
+
const result = !sides || !m ? null
|
|
193
|
+
: box ? gradientShape(type, stops, onBox(m, sides.x, sides.y, box), box.width, box.height)
|
|
194
|
+
: gradientShape(type, stops, m, sides.x, sides.y);
|
|
195
|
+
if (!result)
|
|
196
|
+
return "the gradient has no stops, no complete transform or a flat transform";
|
|
197
|
+
const { shape } = result;
|
|
198
|
+
const paintOut = shape.kind === "solid"
|
|
199
|
+
? { kind: "solid", color: hexColor(shape.color) }
|
|
200
|
+
: { ...shape, stops: shape.stops.map((stop) => ({ offset: stop.position, color: hexColor(stop.color) })) };
|
|
201
|
+
return { paint: paintOut, ...(result.approximated ? { approximated: result.approximated } : {}) };
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The solid, gradient and image paints of the node's `fillPaints` or `strokePaints`
|
|
205
|
+
* list, named `fill` or `stroke` in report entries; other paint types are
|
|
206
|
+
* reported and left out. A node that names a fill or stroke style takes the
|
|
207
|
+
* style's paints (`styleBackedList`). `node` may also be a style override entry, with `id`
|
|
208
|
+
* saying where it is; its `change` must then carry the node's `size` for gradients.
|
|
209
|
+
* Figma places a gradient on the node's box (`size`); `box`, in node pixels,
|
|
210
|
+
* is the box the renderer places it on instead when that differs, such as a
|
|
211
|
+
* vector region's bounds.
|
|
212
|
+
*/
|
|
213
|
+
export function nodePaints(node, walk, list, box, source = styleBackedList(node.change, list, walk.styleList, `node ${node.id}`, walk.report) ?? []) {
|
|
214
|
+
const where = `node ${node.id}`;
|
|
215
|
+
const what = list === "fillPaints" ? "fill" : "stroke";
|
|
216
|
+
const paints = [];
|
|
217
|
+
const indices = walk.paintIndices ? [] : undefined;
|
|
218
|
+
source.forEach((paint, index) => {
|
|
219
|
+
const at = `${where} ${list}[${String(index)}]`;
|
|
220
|
+
const label = `${what} ${String(index + 1)}`;
|
|
221
|
+
if (!isObject(paint))
|
|
222
|
+
return walk.report("property-left-out", `${label} is not a paint object`);
|
|
223
|
+
const type = field(paint, "type", "string", at);
|
|
224
|
+
let base;
|
|
225
|
+
if (type?.startsWith("GRADIENT_")) {
|
|
226
|
+
const gradient = gradientPaint(node, walk, paint, type, at, typeof box === "function" ? box() : box);
|
|
227
|
+
if (typeof gradient === "string")
|
|
228
|
+
return walk.report("property-left-out", `${label} (${type}) is left out: ${gradient}`);
|
|
229
|
+
if (gradient.approximated)
|
|
230
|
+
walk.report("approximated", `${label}: ${gradient.approximated}`);
|
|
231
|
+
base = gradient.paint;
|
|
232
|
+
}
|
|
233
|
+
else if (type === "IMAGE") {
|
|
234
|
+
const image = imagePaint(paint, at, label, walk, list === "fillPaints");
|
|
235
|
+
if (image === null)
|
|
236
|
+
return;
|
|
237
|
+
if (typeof image === "string")
|
|
238
|
+
return walk.report("property-left-out", `${label} (IMAGE) is left out: ${image}`);
|
|
239
|
+
base = image;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const colorObject = field(paint, "color", "object", at);
|
|
243
|
+
const color = colorObject && readNumbers(colorObject, ["r", "g", "b", "a"], `${at} color`);
|
|
244
|
+
if (type !== "SOLID" || !color) {
|
|
245
|
+
return walk.report("property-left-out", `${label} (${type ?? "no type"}) is left out: only solid paints with a colour, gradient paints and image paints are imported`);
|
|
246
|
+
}
|
|
247
|
+
base = { kind: "solid", color: hexColor(color) };
|
|
248
|
+
}
|
|
249
|
+
let opacity = field(paint, "opacity", "number", at) ?? 1;
|
|
250
|
+
if (type === "SOLID" && base.kind === "solid" && opacity !== 1 && paint["colorVar"] && walk.copiedPaintAlpha?.(paint, opacity)) {
|
|
251
|
+
const color = walk.variableColor?.(paint["colorVar"]);
|
|
252
|
+
if (color !== undefined) {
|
|
253
|
+
base = { ...base, color };
|
|
254
|
+
opacity = 1;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const visible = field(paint, "visible", "boolean", at) ?? true;
|
|
258
|
+
const blend = field(paint, "blendMode", "string", at);
|
|
259
|
+
const blendMode = blend === undefined ? undefined : blendModeOf(blend);
|
|
260
|
+
if (blendMode === null)
|
|
261
|
+
walk.report("property-left-out", `${label} blend mode ${String(blend)} has no Taco equivalent`);
|
|
262
|
+
const placed = {
|
|
263
|
+
...base,
|
|
264
|
+
...(opacity !== 1 ? { opacity } : {}),
|
|
265
|
+
...(visible ? {} : { visible }),
|
|
266
|
+
...(blendMode ? { blendMode } : {}),
|
|
267
|
+
};
|
|
268
|
+
moveMark(base, placed); // Moondraft patch (../carry.ts)
|
|
269
|
+
paints.push(placed);
|
|
270
|
+
indices?.push(index);
|
|
271
|
+
});
|
|
272
|
+
if (indices)
|
|
273
|
+
walk.paintIndices(source, indices);
|
|
274
|
+
return paints;
|
|
275
|
+
}
|
|
276
|
+
const STROKE_POSITIONS = { CENTER: "center", INSIDE: "inside", OUTSIDE: "outside" };
|
|
277
|
+
const STROKE_JOINS = { MITER: "miter", BEVEL: "bevel", ROUND: "round" };
|
|
278
|
+
/** The most dash lengths a stroke can carry; the renderer rejects longer patterns (`WIRE_LIMITS.strokeDashIntervals`). */
|
|
279
|
+
const MAX_DASH_LENGTHS = 64;
|
|
280
|
+
/** Figma's `strokeCap` names Taco has, as path ends and dash ends alike. */
|
|
281
|
+
export const STROKE_CAPS = { NONE: "none", ROUND: "round", SQUARE: "square" };
|
|
282
|
+
const END_CAPS = {
|
|
283
|
+
...STROKE_CAPS, ARROW_LINES: "line-arrow", ARROW_EQUILATERAL: "triangle-arrow",
|
|
284
|
+
TRIANGLE_FILLED: "reversed-triangle", CIRCLE_FILLED: "circle-arrow", DIAMOND_FILLED: "diamond-arrow",
|
|
285
|
+
};
|
|
286
|
+
/** Figma's vector endpoint styles, including heads that dashes cannot use. */
|
|
287
|
+
export function endCapOf(value) {
|
|
288
|
+
return typeof value === "string" && Object.hasOwn(END_CAPS, value) ? END_CAPS[value] : undefined;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Figma's separate side weights as Taco side widths, or `undefined` when the
|
|
292
|
+
* node uses one weight. With `borderStrokeWeightsIndependent` Kiwi leaves out
|
|
293
|
+
* a side of weight 0, so an absent side is 0.
|
|
294
|
+
*/
|
|
295
|
+
function strokeSides(node, where) {
|
|
296
|
+
if (field(node.change, "borderStrokeWeightsIndependent", "boolean", where) !== true)
|
|
297
|
+
return undefined;
|
|
298
|
+
const side = (name) => Math.max(0, field(node.change, name, "number", where) ?? 0);
|
|
299
|
+
return { top: side("borderTopWeight"), right: side("borderRightWeight"), bottom: side("borderBottomWeight"), left: side("borderLeftWeight") };
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Stroke paints with the node's weight, alignment, join, miter limit and
|
|
303
|
+
* dashes, gradients placed on `box` (the node's box when left out). Kiwi
|
|
304
|
+
* leaves out an enum field at its first value, so an absent `strokeAlign` is
|
|
305
|
+
* CENTER, an absent `strokeJoin` MITER and an absent `strokeCap` NONE.
|
|
306
|
+
* `sides` reads Figma's separate side weights, which only rectangles and
|
|
307
|
+
* frames have. A dashed stroke's dash ends follow `strokeCap`, as in Figma.
|
|
308
|
+
*/
|
|
309
|
+
export function nodeStrokes(node, walk, box, sides = false) {
|
|
310
|
+
const where = `node ${node.id}`;
|
|
311
|
+
const paints = nodePaints(node, walk, "strokePaints", box);
|
|
312
|
+
if (paints.length === 0)
|
|
313
|
+
return [];
|
|
314
|
+
const sideWidths = sides ? strokeSides(node, where) : undefined;
|
|
315
|
+
const width = sideWidths ? Math.max(sideWidths.top, sideWidths.right, sideWidths.bottom, sideWidths.left)
|
|
316
|
+
: field(node.change, "strokeWeight", "number", where);
|
|
317
|
+
if (width === undefined) {
|
|
318
|
+
walk.report("property-left-out", "strokes are left out: the node has stroke paints but no strokeWeight");
|
|
319
|
+
return [];
|
|
320
|
+
}
|
|
321
|
+
const align = field(node.change, "strokeAlign", "string", where) ?? "CENTER";
|
|
322
|
+
const position = Object.hasOwn(STROKE_POSITIONS, align) ? STROKE_POSITIONS[align] : "center";
|
|
323
|
+
if (!Object.hasOwn(STROKE_POSITIONS, align))
|
|
324
|
+
walk.report("approximated", `stroke alignment ${align} has no Taco equivalent; the strokes are centered`);
|
|
325
|
+
const joinName = field(node.change, "strokeJoin", "string", where) ?? "MITER";
|
|
326
|
+
const join = Object.hasOwn(STROKE_JOINS, joinName) ? STROKE_JOINS[joinName] : "miter";
|
|
327
|
+
if (!Object.hasOwn(STROKE_JOINS, joinName))
|
|
328
|
+
walk.report("approximated", `stroke join ${joinName} has no Taco equivalent; miter is used`);
|
|
329
|
+
// Figma's miter limit is a length ratio; Taco keeps the angle where a miter bevels: limit = 1 / sin(angle / 2).
|
|
330
|
+
const limit = field(node.change, "miterLimit", "number", where);
|
|
331
|
+
const miterAngle = limit === undefined ? undefined : limit > 1 ? 2 * Math.asin(1 / limit) * 180 / Math.PI : 180;
|
|
332
|
+
if (limit !== undefined && !(limit >= 1))
|
|
333
|
+
walk.report("approximated", `miter limit ${String(limit)} is below 1; every miter corner is beveled`);
|
|
334
|
+
const pattern = field(node.change, "dashPattern", "list", where) ?? [];
|
|
335
|
+
const dashProblem = !pattern.every((length) => typeof length === "number" && Number.isFinite(length) && length >= 0)
|
|
336
|
+
? "the dash pattern has a length that is not a number of 0 or more"
|
|
337
|
+
: pattern.length > MAX_DASH_LENGTHS ? `the dash pattern has more than ${MAX_DASH_LENGTHS} lengths`
|
|
338
|
+
: pattern.length > 0 && pattern.every((length) => length === 0) ? "every length in the dash pattern is 0"
|
|
339
|
+
: undefined;
|
|
340
|
+
const dash = dashProblem === undefined ? pattern : [];
|
|
341
|
+
if (dashProblem !== undefined)
|
|
342
|
+
walk.report("property-left-out", `dashes are left out: ${dashProblem}`);
|
|
343
|
+
const capName = field(node.change, "strokeCap", "string", where) ?? "NONE";
|
|
344
|
+
const dashCap = Object.hasOwn(STROKE_CAPS, capName) ? STROKE_CAPS[capName] : "none";
|
|
345
|
+
if (dash.length > 0 && !Object.hasOwn(STROKE_CAPS, capName))
|
|
346
|
+
walk.report("approximated", `stroke cap ${capName} has no Taco dash end; the dashes end flat`);
|
|
347
|
+
const boundWidth = walk.paintIndices && node.change["variableConsumptionMap"]
|
|
348
|
+
?.entries?.some(e => e.variableField === "STROKE_WEIGHT" || /^BORDER_(TOP|RIGHT|BOTTOM|LEFT)_WEIGHT$/.test(e.variableField));
|
|
349
|
+
return paints.map((paint) => ({
|
|
350
|
+
paint, width, position, join, ...(boundWidth && { fileBoundWidth: true }),
|
|
351
|
+
...(sideWidths ? { sides: sideWidths } : {}),
|
|
352
|
+
...(miterAngle !== undefined ? { miterAngle } : {}),
|
|
353
|
+
...(dash.length > 0 ? { dash, dashCap } : {}),
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
/** Solid, gradient and image fills and strokes and corners as a Taco style; other paint types are reported and left out. */
|
|
357
|
+
export function visualStyle(node, walk) {
|
|
358
|
+
const where = `node ${node.id}`;
|
|
359
|
+
const fills = nodePaints(node, walk, "fillPaints");
|
|
360
|
+
const strokes = nodeStrokes(node, walk, undefined, true);
|
|
361
|
+
const radius = field(node.change, "cornerRadius", "number", where) ?? 0;
|
|
362
|
+
const smoothing = field(node.change, "cornerSmoothing", "number", where) ?? 0;
|
|
363
|
+
const corner = (name) => field(node.change, name, "number", where) ?? 0;
|
|
364
|
+
// As grida reads it (packages/grida-canvas-io-figma/lib.ts:4150): per-corner fields only when independent.
|
|
365
|
+
const corners = field(node.change, "rectangleCornerRadiiIndependent", "boolean", where) === true
|
|
366
|
+
? { cornerRadii: {
|
|
367
|
+
topLeft: corner("rectangleTopLeftCornerRadius"), topRight: corner("rectangleTopRightCornerRadius"),
|
|
368
|
+
bottomRight: corner("rectangleBottomRightCornerRadius"), bottomLeft: corner("rectangleBottomLeftCornerRadius"),
|
|
369
|
+
} }
|
|
370
|
+
: radius > 0 ? { cornerRadius: radius } : {};
|
|
371
|
+
return { ...(fills.length > 0 ? { fills } : {}), ...(strokes.length > 0 ? { strokes } : {}), ...corners, ...(smoothing > 0 ? { cornerSmoothing: smoothing } : {}) };
|
|
372
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { TextRun, TextStyle } from "../../../model/index.ts";
|
|
2
|
+
import { type FigmaObject } from "../fields.ts";
|
|
3
|
+
import type { FigmaNodeConverter, NodeWalk } from "../walk.ts";
|
|
4
|
+
/** The weight a Figma font style name such as "Semi Bold Italic" names (undefined when it names no known weight), and whether it is italic. */
|
|
5
|
+
export declare function fontStyleWeight(styleName: string): {
|
|
6
|
+
readonly fontWeight: number | undefined;
|
|
7
|
+
readonly italic: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A field the importer adds to a text layer's Figma fields, never one Figma writes: the line height in pixels Figma laid
|
|
11
|
+
* out every line of this layer at in an instance (its stored `derivedTextData`), which replaces the line height the
|
|
12
|
+
* layer's runs would take from their text style or variable. The runs stay linked to their style, with this line height
|
|
13
|
+
* as an override.
|
|
14
|
+
*/
|
|
15
|
+
export declare const KEPT_LINE_HEIGHT_FIELD = "tacoKeptLineHeight";
|
|
16
|
+
/**
|
|
17
|
+
* A Figma TEXT node as a Taco text node. `textData.characters` is split into
|
|
18
|
+
* paragraphs at each newline, and each paragraph into runs where the style id
|
|
19
|
+
* changes. `textData.characterStyleIDs` holds one id per code point and may
|
|
20
|
+
* be shorter than the text: missing ids are 0. Id 0 is the node's own style;
|
|
21
|
+
* every other id names an entry of `textData.styleOverrideTable` whose fields
|
|
22
|
+
* replace the node's. Fonts are named by family, weight and italic only;
|
|
23
|
+
* `fontAssetId` is left for the host to bind. A node or override entry that
|
|
24
|
+
* names a Figma text style (`styleIdForText`) takes the style's typography
|
|
25
|
+
* over the node's stored copies (an override entry's own fields still win, and
|
|
26
|
+
* the colour stays the node's), and its runs link to the shared style the walk made
|
|
27
|
+
* for it (`NodeWalk.textStyle`), with only the fields that differ as overrides.
|
|
28
|
+
* A line height bound to a variable (`LINE_HEIGHT`) is the variable's value in
|
|
29
|
+
* the mode the node uses (`NodeWalk.variableNumber`), as a fixed multiple of the
|
|
30
|
+
* font size, read from the same place as the line height itself (`runBinding`).
|
|
31
|
+
*/
|
|
32
|
+
export declare const convertText: FigmaNodeConverter;
|
|
33
|
+
/** Figma stores the deviations from its feature defaults in separate on and off lists. */
|
|
34
|
+
export declare const OPEN_TYPE_TOGGLES: readonly ["toggledOnOTFeatures", "toggledOffOTFeatures"];
|
|
35
|
+
/** Figma fields that specify OpenType features on a layer, range or instance override. */
|
|
36
|
+
export declare const OPEN_TYPE_FIELDS: string[];
|
|
37
|
+
/** Keeps omitted toggle lists inherited, except for tags explicitly toggled the other way. */
|
|
38
|
+
export declare function inheritOpenTypeToggles(base: FigmaObject | undefined, own: FigmaObject): FigmaObject;
|
|
39
|
+
/** An empty range hyperlink explicitly clears the layer's hyperlink. */
|
|
40
|
+
export declare function hyperlinkOf(value: unknown, report: NodeWalk["report"]): TextRun["hyperlink"];
|
|
41
|
+
/**
|
|
42
|
+
* A Figma text style node (`styleType` TEXT) as a Taco text style, read as a
|
|
43
|
+
* run of a node without overrides is; a value it lacks is Figma's default.
|
|
44
|
+
* An auto line height is the font's own from the style node's font metadata,
|
|
45
|
+
* else from the first of `layers`, the text layers that name the style, that has it.
|
|
46
|
+
* A line height bound to a variable is the number `variableNumber` gives for it; the
|
|
47
|
+
* layers that use the style report it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function figmaTextStyle(change: FigmaObject, name: string, report: NodeWalk["report"], where: string, layers?: readonly FigmaObject[], variableNumber?: NodeWalk["variableNumber"]): TextStyle;
|
|
50
|
+
/** The top visible solid fill as a colour with the paint's opacity in its alpha; other fills are reported. */
|
|
51
|
+
export declare function textColor(paints: readonly unknown[], report?: NodeWalk["report"], where?: string): {
|
|
52
|
+
value: string;
|
|
53
|
+
paint: FigmaObject | undefined;
|
|
54
|
+
};
|