@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,31 @@
|
|
|
1
|
+
import type { VisualStyle } from "../../../model/index.ts";
|
|
2
|
+
import type { FigmaTreeNode } from "../tree.ts";
|
|
3
|
+
import type { NodeWalk } from "../walk.ts";
|
|
4
|
+
/**
|
|
5
|
+
* True when the renderer draws a node with `style` as a plain rectangle, the
|
|
6
|
+
* only shape whose drop shadow it shrinks for a negative spread
|
|
7
|
+
* (`drawShadowedRect` in packages/render-core/cpp/skia/skia_adapter.cc); every
|
|
8
|
+
* other shape's drop shadow ignores a negative spread (`buildPreparedShadows`).
|
|
9
|
+
* Frames are drawn so when their corners are square; rectangles also need at
|
|
10
|
+
* most one plain solid fill or a stroke with unequal per-side weights, or they are drawn as a path
|
|
11
|
+
* (`compileRectangle` and `needsRegionFillPaints` in packages/render-core/src/page-compiler.ts).
|
|
12
|
+
*/
|
|
13
|
+
export declare function drawnAsPlainRectangle(style: VisualStyle, isFrame: boolean): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The node's Figma `effects` as Taco shadows, layer blur and background blur,
|
|
16
|
+
* shadows in Figma's order; a node with an effect style takes the style's
|
|
17
|
+
* effects (`styleBackedList`). Figma's blur radius is twice the Gaussian sigma:
|
|
18
|
+
* its shadow radius is the CSS box-shadow blur radius (sigma = radius / 2, CSS
|
|
19
|
+
* Backgrounds 3 §7.1.1, https://bjango.com/articles/blurradiuscomparison/),
|
|
20
|
+
* and Figma halves a blur radius for CSS `blur()`, whose argument is the sigma
|
|
21
|
+
* (https://forum.figma.com/t/background-blur-is-different-in-dev-mode/81631).
|
|
22
|
+
* Taco's renderer also blurs at a sigma of half the radius, so radii carry
|
|
23
|
+
* over unchanged. Kiwi leaves out an enum field at its first value, so an
|
|
24
|
+
* absent `type` is INNER_SHADOW. As fig2sketch reads effects
|
|
25
|
+
* (src/converter/style.py, `convert_effects`), absent offset, radius and
|
|
26
|
+
* spread are 0. Taco has no hidden shadow or blur, one layer blur and one
|
|
27
|
+
* background blur, and at most 16 shadows; what does not fit is reported.
|
|
28
|
+
* A drop shadow keeps a negative spread only when `plainRectangle` is true
|
|
29
|
+
* (see `drawnAsPlainRectangle`); elsewhere it is drawn with spread 0 and reported.
|
|
30
|
+
*/
|
|
31
|
+
export declare function nodeEffects(node: FigmaTreeNode, walk: NodeWalk, plainRectangle?: boolean): Pick<VisualStyle, "shadows" | "layerBlur" | "backgroundBlur">;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { field, isObject } from "../fields.js";
|
|
2
|
+
import { styleBackedList } from "../styles.js";
|
|
3
|
+
import { blendModeOf, hexColor, readNumbers } from "./shared.js";
|
|
4
|
+
import { markShadowBehind } from "../carry.js";
|
|
5
|
+
/** The renderer refuses a node with more shadows than this (`WIRE_LIMITS.shadows` in packages/render-core/src/protocol.ts). */
|
|
6
|
+
const MAX_SHADOWS = 16;
|
|
7
|
+
// Prototype-free, so an effect type such as "constructor" finds no entry.
|
|
8
|
+
const SHADOW_KINDS = Object.assign(Object.create(null), { DROP_SHADOW: "drop", INNER_SHADOW: "inner" });
|
|
9
|
+
const BLUR_KINDS = Object.assign(Object.create(null), { FOREGROUND_BLUR: "layerBlur", BACKGROUND_BLUR: "backgroundBlur" });
|
|
10
|
+
/**
|
|
11
|
+
* True when the renderer draws a node with `style` as a plain rectangle, the
|
|
12
|
+
* only shape whose drop shadow it shrinks for a negative spread
|
|
13
|
+
* (`drawShadowedRect` in packages/render-core/cpp/skia/skia_adapter.cc); every
|
|
14
|
+
* other shape's drop shadow ignores a negative spread (`buildPreparedShadows`).
|
|
15
|
+
* Frames are drawn so when their corners are square; rectangles also need at
|
|
16
|
+
* most one plain solid fill or a stroke with unequal per-side weights, or they are drawn as a path
|
|
17
|
+
* (`compileRectangle` and `needsRegionFillPaints` in packages/render-core/src/page-compiler.ts).
|
|
18
|
+
*/
|
|
19
|
+
export function drawnAsPlainRectangle(style, isFrame) {
|
|
20
|
+
const square = (style.cornerRadius ?? 0) === 0 && Object.values(style.cornerRadii ?? {}).every((radius) => radius === 0);
|
|
21
|
+
if (!square || isFrame)
|
|
22
|
+
return square;
|
|
23
|
+
// A stroke with unequal per-side weights makes the rectangle a container, whatever its fills (`hasSidedStroke`).
|
|
24
|
+
const sidedStroke = style.strokes?.some(({ sides }) => sides !== undefined
|
|
25
|
+
&& !(sides.right === sides.top && sides.bottom === sides.top && sides.left === sides.top)) ?? false;
|
|
26
|
+
if (sidedStroke)
|
|
27
|
+
return true;
|
|
28
|
+
const fills = style.fills ?? [];
|
|
29
|
+
return fills.length <= 1 && fills.every((paint) => paint.kind === "solid" && paint.visible !== false && (paint.blendMode ?? "normal") === "normal");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The node's Figma `effects` as Taco shadows, layer blur and background blur,
|
|
33
|
+
* shadows in Figma's order; a node with an effect style takes the style's
|
|
34
|
+
* effects (`styleBackedList`). Figma's blur radius is twice the Gaussian sigma:
|
|
35
|
+
* its shadow radius is the CSS box-shadow blur radius (sigma = radius / 2, CSS
|
|
36
|
+
* Backgrounds 3 §7.1.1, https://bjango.com/articles/blurradiuscomparison/),
|
|
37
|
+
* and Figma halves a blur radius for CSS `blur()`, whose argument is the sigma
|
|
38
|
+
* (https://forum.figma.com/t/background-blur-is-different-in-dev-mode/81631).
|
|
39
|
+
* Taco's renderer also blurs at a sigma of half the radius, so radii carry
|
|
40
|
+
* over unchanged. Kiwi leaves out an enum field at its first value, so an
|
|
41
|
+
* absent `type` is INNER_SHADOW. As fig2sketch reads effects
|
|
42
|
+
* (src/converter/style.py, `convert_effects`), absent offset, radius and
|
|
43
|
+
* spread are 0. Taco has no hidden shadow or blur, one layer blur and one
|
|
44
|
+
* background blur, and at most 16 shadows; what does not fit is reported.
|
|
45
|
+
* A drop shadow keeps a negative spread only when `plainRectangle` is true
|
|
46
|
+
* (see `drawnAsPlainRectangle`); elsewhere it is drawn with spread 0 and reported.
|
|
47
|
+
*/
|
|
48
|
+
export function nodeEffects(node, walk, plainRectangle = false) {
|
|
49
|
+
const where = `node ${node.id}`;
|
|
50
|
+
const shadows = [];
|
|
51
|
+
const boundZeroBlurs = new Map();
|
|
52
|
+
const blurs = {};
|
|
53
|
+
(styleBackedList(node.change, "effects", walk.styleList, where, walk.report) ?? []).forEach((effect, index) => {
|
|
54
|
+
const at = `${where} effects[${String(index)}]`;
|
|
55
|
+
const label = `effect ${String(index + 1)}`;
|
|
56
|
+
if (!isObject(effect))
|
|
57
|
+
return walk.report("property-left-out", `${label} is not an effect object`);
|
|
58
|
+
const type = field(effect, "type", "string", at) ?? "INNER_SHADOW";
|
|
59
|
+
const shadowKind = SHADOW_KINDS[type];
|
|
60
|
+
const blurKind = BLUR_KINDS[type];
|
|
61
|
+
if (!shadowKind && !blurKind)
|
|
62
|
+
return walk.report("property-left-out", `${label} (${type}) is left out: only shadows and blurs are imported`);
|
|
63
|
+
if (field(effect, "visible", "boolean", at) === false) {
|
|
64
|
+
return walk.report("property-left-out", `${label} (${type}) is hidden and left out: Taco effects cannot be hidden`);
|
|
65
|
+
}
|
|
66
|
+
let radius = field(effect, "radius", "number", at) ?? 0;
|
|
67
|
+
if (radius < 0) {
|
|
68
|
+
walk.report("approximated", `${label} (${type}) radius ${String(radius)} is below 0; 0 is used`);
|
|
69
|
+
radius = 0;
|
|
70
|
+
}
|
|
71
|
+
const blend = field(effect, "blendMode", "string", at);
|
|
72
|
+
if (blend !== undefined && blendModeOf(blend) !== undefined) {
|
|
73
|
+
walk.report("approximated", `${label} (${type}) blend mode ${blend} is not imported; the effect blends normally`);
|
|
74
|
+
}
|
|
75
|
+
if (blurKind) {
|
|
76
|
+
if (field(effect, "blurOpType", "string", at) === "PROGRESSIVE") {
|
|
77
|
+
walk.report("approximated", `${label} (${type}) is a progressive blur; Taco blurs evenly at radius ${String(radius)}`);
|
|
78
|
+
}
|
|
79
|
+
// A blur of radius 0 draws nothing, so it leaves the slot for a later blur of the same kind.
|
|
80
|
+
if (radius === 0) {
|
|
81
|
+
if (walk.effectField && effect["radiusVar"] && !boundZeroBlurs.has(blurKind))
|
|
82
|
+
boundZeroBlurs.set(blurKind, effect);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (blurs[blurKind] !== undefined)
|
|
86
|
+
return walk.report("property-left-out", `${label} (${type}) is left out: Taco keeps one ${type === "FOREGROUND_BLUR" ? "layer" : "background"} blur`);
|
|
87
|
+
walk.effectField?.(effect, "look." + blurKind);
|
|
88
|
+
blurs[blurKind] = radius;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const offset = field(effect, "offset", "object", at) ?? {};
|
|
92
|
+
const x = field(offset, "x", "number", `${at} offset`) ?? 0;
|
|
93
|
+
const y = field(offset, "y", "number", `${at} offset`) ?? 0;
|
|
94
|
+
let spread = field(effect, "spread", "number", at) ?? 0;
|
|
95
|
+
const colorObject = field(effect, "color", "object", at);
|
|
96
|
+
const color = colorObject && readNumbers(colorObject, ["r", "g", "b", "a"], `${at} color`);
|
|
97
|
+
if (!color)
|
|
98
|
+
return walk.report("property-left-out", `${label} (${type}) is left out: it has no complete colour`);
|
|
99
|
+
if (shadows.length === MAX_SHADOWS)
|
|
100
|
+
return walk.report("property-left-out", `${label} (${type}) is left out: Taco draws at most ${String(MAX_SHADOWS)} shadows`);
|
|
101
|
+
// Moondraft patch (../carry.ts): Moondraft knocks a drop shadow out under the node's fill, as Figma does unless
|
|
102
|
+
// showShadowBehindNode is set; such a shadow is marked, and the see-through fill is no longer reported.
|
|
103
|
+
const behind = shadowKind === "drop" && field(effect, "showShadowBehindNode", "boolean", at) === true;
|
|
104
|
+
if (shadowKind === "inner" && spread < 0) {
|
|
105
|
+
// The renderer grows an inner shadow only inward and treats a negative spread as 0.
|
|
106
|
+
walk.report("approximated", `${label} (${type}) spread ${String(spread)} is below 0; Taco draws inner shadows with spread 0`);
|
|
107
|
+
spread = 0;
|
|
108
|
+
}
|
|
109
|
+
if (shadowKind === "drop" && spread < 0 && !plainRectangle) {
|
|
110
|
+
walk.report("approximated", `${label} (${type}) spread ${String(spread)} is below 0; Taco shrinks drop shadows only on square-cornered rectangles and frames, so spread 0 is used`);
|
|
111
|
+
spread = 0;
|
|
112
|
+
}
|
|
113
|
+
const shadow = { kind: shadowKind, x, y, blur: radius, spread, color: hexColor(color) };
|
|
114
|
+
if (behind)
|
|
115
|
+
markShadowBehind(shadow);
|
|
116
|
+
walk.effectField?.(effect, "look.shadows." + String(shadows.length));
|
|
117
|
+
shadows.push(shadow);
|
|
118
|
+
});
|
|
119
|
+
for (const [kind, effect] of boundZeroBlurs)
|
|
120
|
+
if (blurs[kind] === undefined)
|
|
121
|
+
walk.effectField(effect, "look." + kind);
|
|
122
|
+
return {
|
|
123
|
+
...(shadows.length > 0 ? { shadows } : {}),
|
|
124
|
+
...(blurs.layerBlur ? { layerBlur: blurs.layerBlur } : {}),
|
|
125
|
+
...(blurs.backgroundBlur ? { backgroundBlur: blurs.backgroundBlur } : {}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FigmaNodeConverter } from "../walk.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A Figma ELLIPSE as a Taco ellipse. Figma's `arcData` (radians, clockwise
|
|
4
|
+
* from the x axis, inner radius as a fraction of the outer one) maps to
|
|
5
|
+
* Taco's `arc` in degrees; a whole ellipse leaves `arc` out.
|
|
6
|
+
*/
|
|
7
|
+
export declare const convertEllipse: FigmaNodeConverter;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isWholeEllipseArc } from "../../../model/index.js";
|
|
2
|
+
import { field, isObject } from "../fields.js";
|
|
3
|
+
import { nodeEffects } from "./effects.js";
|
|
4
|
+
import { framedBase, nodePaints, nodeStrokes } from "./shared.js";
|
|
5
|
+
/** Largest inner radius Taco accepts; its arcs need an inner radius below 1. */
|
|
6
|
+
const MAX_INNER_RADIUS = 0.999;
|
|
7
|
+
/** Figma stores angles as 32-bit floats; a full turn can read a little over or under 360 degrees. */
|
|
8
|
+
const FULL_TURN_TOLERANCE = 1e-3;
|
|
9
|
+
/** Radians to degrees, rounded to 1e-4 degree to drop 32-bit float noise. */
|
|
10
|
+
const degreesOf = (radians) => Math.round(radians * 180 / Math.PI * 1e4) / 1e4 + 0;
|
|
11
|
+
/**
|
|
12
|
+
* A Figma ELLIPSE as a Taco ellipse. Figma's `arcData` (radians, clockwise
|
|
13
|
+
* from the x axis, inner radius as a fraction of the outer one) maps to
|
|
14
|
+
* Taco's `arc` in degrees; a whole ellipse leaves `arc` out.
|
|
15
|
+
*/
|
|
16
|
+
export const convertEllipse = (node, walk) => {
|
|
17
|
+
const base = framedBase(node, walk, "Ellipse", true);
|
|
18
|
+
if (base === null)
|
|
19
|
+
return null;
|
|
20
|
+
const fills = nodePaints(node, walk, "fillPaints");
|
|
21
|
+
// Per-side weights only apply to rectangles and frames; an ellipse's strokes use the node's one strokeWeight.
|
|
22
|
+
const strokes = nodeStrokes(node, walk);
|
|
23
|
+
const arc = arcOf(node, walk);
|
|
24
|
+
const ellipse = {
|
|
25
|
+
...base, type: "shape", shape: "ellipse",
|
|
26
|
+
style: { ...(fills.length > 0 ? { fills } : {}), ...(strokes.length > 0 ? { strokes } : {}), ...nodeEffects(node, walk) }, ...(arc ? { arc } : {}),
|
|
27
|
+
};
|
|
28
|
+
return ellipse;
|
|
29
|
+
};
|
|
30
|
+
/** The node's arc, or `undefined` for a whole ellipse; out-of-range values are clamped and reported. */
|
|
31
|
+
function arcOf(node, walk) {
|
|
32
|
+
const where = `node ${node.id}`;
|
|
33
|
+
const data = field(node.change, "arcData", "object", where);
|
|
34
|
+
if (data === undefined || !isObject(data))
|
|
35
|
+
return undefined;
|
|
36
|
+
const at = `${where} arcData`;
|
|
37
|
+
const startingAngle = degreesOf(field(data, "startingAngle", "number", at) ?? 0);
|
|
38
|
+
let endingAngle = degreesOf(field(data, "endingAngle", "number", at) ?? 2 * Math.PI);
|
|
39
|
+
const sweep = endingAngle - startingAngle;
|
|
40
|
+
// A full turn can read a little under or over 360 after float32 storage and rounding.
|
|
41
|
+
if (Math.abs(sweep) > 360 - FULL_TURN_TOLERANCE) {
|
|
42
|
+
if (Math.abs(sweep) - 360 > FULL_TURN_TOLERANCE)
|
|
43
|
+
walk.report("approximated", "the arc sweeps more than one full turn; one full turn is kept");
|
|
44
|
+
endingAngle = startingAngle + Math.sign(sweep) * 360;
|
|
45
|
+
}
|
|
46
|
+
// Rounded to 1e-6 to drop 32-bit float noise (0.8 reads as 0.800000011920929).
|
|
47
|
+
const rawInner = Math.round((field(data, "innerRadius", "number", at) ?? 0) * 1e6) / 1e6;
|
|
48
|
+
const innerRadius = Math.min(Math.max(rawInner, 0), MAX_INNER_RADIUS);
|
|
49
|
+
if (innerRadius !== rawInner) {
|
|
50
|
+
walk.report("approximated", `the arc inner radius ${String(rawInner)} is outside 0 to below 1; ${String(innerRadius)} is kept`);
|
|
51
|
+
}
|
|
52
|
+
const arc = { startingAngle, endingAngle, innerRadius };
|
|
53
|
+
return isWholeEllipseArc(arc) ? undefined : arc;
|
|
54
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExportSetting } from "../../../model/types.ts";
|
|
2
|
+
import type { NodeWalk } from "../walk.ts";
|
|
3
|
+
/** Reads the export rows stored by a layer or by an instance's root override. */
|
|
4
|
+
export declare function exportSettingsOf(value: unknown, report: NodeWalk["report"]): ExportSetting[] | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defaultExportQuality, exportConstraintProblem, exportSuffixProblem, MAX_EXPORT_SETTINGS } from "../../../model/export-settings.js";
|
|
2
|
+
import { isObject } from "../fields.js";
|
|
3
|
+
/** Reads the export rows stored by a layer or by an instance's root override. */
|
|
4
|
+
export function exportSettingsOf(value, report) {
|
|
5
|
+
if (value === undefined)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (!Array.isArray(value)) {
|
|
8
|
+
report("property-left-out", "the export settings are not a list");
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const settings = [];
|
|
12
|
+
for (const row of value) {
|
|
13
|
+
if (!isObject(row)) {
|
|
14
|
+
report("property-left-out", "an invalid export setting is left out");
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const format = typeof row["imageType"] === "string" ? row["imageType"].toLowerCase() : undefined;
|
|
18
|
+
if (format !== "png" && format !== "jpeg" && format !== "svg" && format !== "pdf") {
|
|
19
|
+
report("property-left-out", `an export setting with format ${String(format)} is left out`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const size = row["constraint"];
|
|
23
|
+
const type = isObject(size) ? size["type"] : undefined;
|
|
24
|
+
const unit = type === "CONTENT_WIDTH" ? "width" : type === "CONTENT_HEIGHT" ? "height"
|
|
25
|
+
: type === "CONTENT_SCALE" || size === undefined ? "scale" : undefined;
|
|
26
|
+
const amount = size === undefined ? 1 : isObject(size) ? size["value"] : undefined;
|
|
27
|
+
if (unit === undefined || typeof amount !== "number" || exportConstraintProblem({ type: unit, value: amount }) !== null) {
|
|
28
|
+
report("property-left-out", "an export setting with an invalid size is left out");
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const suffix = row["suffix"] ?? "";
|
|
32
|
+
if (typeof suffix !== "string" || exportSuffixProblem(suffix) !== null) {
|
|
33
|
+
report("property-left-out", "an export setting with an invalid suffix is left out");
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (settings.length === MAX_EXPORT_SETTINGS) {
|
|
37
|
+
report("property-left-out", "an export setting beyond the reader's list limit is left out");
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
settings.push({
|
|
41
|
+
format, constraint: { type: unit, value: amount }, suffix,
|
|
42
|
+
quality: defaultExportQuality(format),
|
|
43
|
+
resampling: "detailed",
|
|
44
|
+
ignoreOverlappingLayers: row["contentsOnly"] !== false,
|
|
45
|
+
includeIdAttribute: row["svgIDMode"] === "ALWAYS",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return settings.length === 0 ? undefined : settings;
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type FigmaObject } from "../fields.ts";
|
|
2
|
+
import type { FigmaNodeConverter } from "../walk.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A Figma FRAME as a Taco frame, with its HORIZONTAL or VERTICAL auto layout
|
|
5
|
+
* as a stack (see `stackLayoutOf`) and free layout otherwise. Frames clip unless
|
|
6
|
+
* `frameMaskDisabled` is true (grida, packages/grida-canvas-io-figma/lib.ts:4246).
|
|
7
|
+
* Figma stores a group as a FRAME. `resizeToFit` alone does not prove it, so a
|
|
8
|
+
* FRAME counts as a group only when it also clips (`frameMaskDisabled` is
|
|
9
|
+
* false), has no fill, stroke or background paints (grida,
|
|
10
|
+
* packages/grida-canvas-io-figma/lib.ts:4567) and has no auto layout
|
|
11
|
+
* (fig2sketch, src/converter/tree.py:169). A group is converted by
|
|
12
|
+
* `convertGroup`. Only a FRAME is checked: a SYMBOL or INSTANCE with the same
|
|
13
|
+
* fields is still a component or an instance, so it imports as a frame.
|
|
14
|
+
*/
|
|
15
|
+
export declare const convertFrame: FigmaNodeConverter;
|
|
16
|
+
/**
|
|
17
|
+
* Whether a FRAME's fields mark it as a Figma group (see `convertFrame`).
|
|
18
|
+
* It never throws: a field of the wrong type makes it "not a group", and the
|
|
19
|
+
* converter then refuses that field itself.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isFigmaGroup(change: FigmaObject): boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { carry } from "../carry.js";
|
|
2
|
+
import { field } from "../fields.js";
|
|
3
|
+
import { gridStyleReference } from "../styles.js";
|
|
4
|
+
import { drawnAsPlainRectangle, nodeEffects } from "./effects.js";
|
|
5
|
+
import { stackLayoutOf } from "./layout.js";
|
|
6
|
+
import { convertGroup } from "./group.js";
|
|
7
|
+
import { framedBase, visualStyle } from "./shared.js";
|
|
8
|
+
/**
|
|
9
|
+
* A Figma FRAME as a Taco frame, with its HORIZONTAL or VERTICAL auto layout
|
|
10
|
+
* as a stack (see `stackLayoutOf`) and free layout otherwise. Frames clip unless
|
|
11
|
+
* `frameMaskDisabled` is true (grida, packages/grida-canvas-io-figma/lib.ts:4246).
|
|
12
|
+
* Figma stores a group as a FRAME. `resizeToFit` alone does not prove it, so a
|
|
13
|
+
* FRAME counts as a group only when it also clips (`frameMaskDisabled` is
|
|
14
|
+
* false), has no fill, stroke or background paints (grida,
|
|
15
|
+
* packages/grida-canvas-io-figma/lib.ts:4567) and has no auto layout
|
|
16
|
+
* (fig2sketch, src/converter/tree.py:169). A group is converted by
|
|
17
|
+
* `convertGroup`. Only a FRAME is checked: a SYMBOL or INSTANCE with the same
|
|
18
|
+
* fields is still a component or an instance, so it imports as a frame.
|
|
19
|
+
*/
|
|
20
|
+
export const convertFrame = (node, walk) => {
|
|
21
|
+
const stackMode = field(node.change, "stackMode", "string", `node ${node.id}`);
|
|
22
|
+
// The paint lists are checked here, so a malformed list is refused rather than read as "not a group".
|
|
23
|
+
for (const name of ["fillPaints", "strokePaints", "backgroundPaints"])
|
|
24
|
+
field(node.change, name, "list", `node ${node.id}`);
|
|
25
|
+
if (node.type === "FRAME" && isFigmaGroup(node.change))
|
|
26
|
+
return convertGroup(node, walk);
|
|
27
|
+
const base = framedBase(node, walk, "Frame", true);
|
|
28
|
+
if (base === null)
|
|
29
|
+
return null;
|
|
30
|
+
const visual = visualStyle(node, walk);
|
|
31
|
+
const style = { ...visual, ...nodeEffects(node, walk, drawnAsPlainRectangle(visual, true)) };
|
|
32
|
+
const frame = {
|
|
33
|
+
...base,
|
|
34
|
+
type: "frame",
|
|
35
|
+
children: walk.convertChildren(),
|
|
36
|
+
layout: stackLayoutOf(node.change, walk.report) ?? { kind: "absolute" },
|
|
37
|
+
clipContent: node.change["frameMaskDisabled"] !== true,
|
|
38
|
+
...(Object.keys(style).length > 0 ? { style } : {}),
|
|
39
|
+
};
|
|
40
|
+
if ((frame.layout.kind === "horizontal" || frame.layout.kind === "vertical") && node.change["bordersTakeSpace"] === true) {
|
|
41
|
+
carry(frame, { strokesIncluded: true });
|
|
42
|
+
}
|
|
43
|
+
return frame;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Whether a FRAME's fields mark it as a Figma group (see `convertFrame`).
|
|
47
|
+
* It never throws: a field of the wrong type makes it "not a group", and the
|
|
48
|
+
* converter then refuses that field itself.
|
|
49
|
+
*/
|
|
50
|
+
export function isFigmaGroup(change) {
|
|
51
|
+
if (change["resizeToFit"] !== true || change["frameMaskDisabled"] !== false)
|
|
52
|
+
return false;
|
|
53
|
+
const grids = change["layoutGrids"];
|
|
54
|
+
if ((Array.isArray(grids) && grids.length > 0) || gridStyleReference(change) !== undefined)
|
|
55
|
+
return false;
|
|
56
|
+
const stackMode = change["stackMode"];
|
|
57
|
+
if (stackMode !== undefined && stackMode !== "NONE")
|
|
58
|
+
return false;
|
|
59
|
+
return ["fillPaints", "strokePaints", "backgroundPaints"].every((name) => {
|
|
60
|
+
const paints = change[name];
|
|
61
|
+
return paints === undefined || (Array.isArray(paints) && paints.length === 0);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Figma gradient paints as Taco gradient geometry.
|
|
3
|
+
*
|
|
4
|
+
* A Figma gradient paint's `transform` maps the node's unit box (0..1 on
|
|
5
|
+
* each axis, scaled to the node's size) into gradient space, so it is the
|
|
6
|
+
* inverse of the mapping that places the gradient's handles. In gradient
|
|
7
|
+
* space a linear gradient runs from (0, 0.5) to (1, 0.5); radial, diamond
|
|
8
|
+
* and angular gradients are centred on (0.5, 0.5) with radius 0.5, and an
|
|
9
|
+
* angular gradient starts along +x. fig2sketch's `convert_gradient`
|
|
10
|
+
* (src/converter/style.py) reads the paint the same way.
|
|
11
|
+
*/
|
|
12
|
+
/** A colour as Figma stores it: channels from 0 to 1. */
|
|
13
|
+
export interface Rgba {
|
|
14
|
+
readonly r: number;
|
|
15
|
+
readonly g: number;
|
|
16
|
+
readonly b: number;
|
|
17
|
+
readonly a: number;
|
|
18
|
+
}
|
|
19
|
+
/** A gradient stop; `position` is Figma's, or a Taco offset once mapped. */
|
|
20
|
+
export interface ColorStop {
|
|
21
|
+
readonly position: number;
|
|
22
|
+
readonly color: Rgba;
|
|
23
|
+
}
|
|
24
|
+
export type FigmaMatrix = Record<"m00" | "m01" | "m02" | "m10" | "m11" | "m12", number>;
|
|
25
|
+
export type GradientShape = {
|
|
26
|
+
readonly kind: "linear-gradient";
|
|
27
|
+
readonly from: Point;
|
|
28
|
+
readonly to: Point;
|
|
29
|
+
readonly stops: readonly ColorStop[];
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: "radial-gradient";
|
|
32
|
+
readonly center: Point;
|
|
33
|
+
readonly radius: Point;
|
|
34
|
+
readonly stops: readonly ColorStop[];
|
|
35
|
+
} | {
|
|
36
|
+
readonly kind: "angular-gradient";
|
|
37
|
+
readonly center: Point;
|
|
38
|
+
readonly angle: number;
|
|
39
|
+
readonly stops: readonly ColorStop[];
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: "solid";
|
|
42
|
+
readonly color: Rgba;
|
|
43
|
+
};
|
|
44
|
+
interface Point {
|
|
45
|
+
readonly x: number;
|
|
46
|
+
readonly y: number;
|
|
47
|
+
}
|
|
48
|
+
/** A box in the node's own pixels. */
|
|
49
|
+
export interface Box {
|
|
50
|
+
readonly x: number;
|
|
51
|
+
readonly y: number;
|
|
52
|
+
readonly width: number;
|
|
53
|
+
readonly height: number;
|
|
54
|
+
}
|
|
55
|
+
/** A vector computes its paint bounds on the first gradient that needs them. */
|
|
56
|
+
export type PaintBounds = Box | (() => Box | undefined);
|
|
57
|
+
/**
|
|
58
|
+
* The paint transform `m` of a `width` by `height` node re-expressed on
|
|
59
|
+
* `box`'s unit box, so the gradient stays where it is in node pixels when it
|
|
60
|
+
* is placed on `box`: unit point (u, v) of `box` is node unit point
|
|
61
|
+
* ((box.x + u box.width) / width, (box.y + v box.height) / height). An axis
|
|
62
|
+
* of size 0 has no unit position, so the gradient does not vary along it.
|
|
63
|
+
*/
|
|
64
|
+
export declare function onBox(m: FigmaMatrix, width: number, height: number, box: Box): FigmaMatrix;
|
|
65
|
+
/**
|
|
66
|
+
* The Taco geometry of a Figma gradient of `type` on a `width` by `height`
|
|
67
|
+
* node, plus why it is only approximated, or `null` when the transform is
|
|
68
|
+
* flat or there are no stops.
|
|
69
|
+
*/
|
|
70
|
+
export declare function gradientShape(type: string, stops: readonly ColorStop[], m: FigmaMatrix, width: number, height: number): {
|
|
71
|
+
shape: GradientShape;
|
|
72
|
+
approximated?: string;
|
|
73
|
+
} | null;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Figma gradient paints as Taco gradient geometry.
|
|
3
|
+
*
|
|
4
|
+
* A Figma gradient paint's `transform` maps the node's unit box (0..1 on
|
|
5
|
+
* each axis, scaled to the node's size) into gradient space, so it is the
|
|
6
|
+
* inverse of the mapping that places the gradient's handles. In gradient
|
|
7
|
+
* space a linear gradient runs from (0, 0.5) to (1, 0.5); radial, diamond
|
|
8
|
+
* and angular gradients are centred on (0.5, 0.5) with radius 0.5, and an
|
|
9
|
+
* angular gradient starts along +x. fig2sketch's `convert_gradient`
|
|
10
|
+
* (src/converter/style.py) reads the paint the same way.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The paint transform `m` of a `width` by `height` node re-expressed on
|
|
14
|
+
* `box`'s unit box, so the gradient stays where it is in node pixels when it
|
|
15
|
+
* is placed on `box`: unit point (u, v) of `box` is node unit point
|
|
16
|
+
* ((box.x + u box.width) / width, (box.y + v box.height) / height). An axis
|
|
17
|
+
* of size 0 has no unit position, so the gradient does not vary along it.
|
|
18
|
+
*/
|
|
19
|
+
export function onBox(m, width, height, box) {
|
|
20
|
+
const fx = width > 0 ? 1 / width : 0;
|
|
21
|
+
const fy = height > 0 ? 1 / height : 0;
|
|
22
|
+
return {
|
|
23
|
+
m00: m.m00 * box.width * fx, m01: m.m01 * box.height * fy, m02: m.m00 * box.x * fx + m.m01 * box.y * fy + m.m02,
|
|
24
|
+
m10: m.m10 * box.width * fx, m11: m.m11 * box.height * fy, m12: m.m10 * box.x * fx + m.m11 * box.y * fy + m.m12,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** The colour at `t`: the end colours outside the stops, interpolated between them. */
|
|
28
|
+
function sample(stops, t) {
|
|
29
|
+
const first = stops[0];
|
|
30
|
+
const last = stops[stops.length - 1];
|
|
31
|
+
if (t <= first.position)
|
|
32
|
+
return first.color;
|
|
33
|
+
if (t >= last.position)
|
|
34
|
+
return last.color;
|
|
35
|
+
const after = stops.findIndex((stop) => stop.position > t);
|
|
36
|
+
const a = stops[after - 1];
|
|
37
|
+
const b = stops[after];
|
|
38
|
+
const k = (t - a.position) / (b.position - a.position);
|
|
39
|
+
const mix = (key) => a.color[key] + (b.color[key] - a.color[key]) * k;
|
|
40
|
+
return { r: mix("r"), g: mix("g"), b: mix("b"), a: mix("a") };
|
|
41
|
+
}
|
|
42
|
+
/** Stops cut to 0..1, with the colours sampled at the cut ends; at least two stops. */
|
|
43
|
+
function clipStops(stops) {
|
|
44
|
+
const out = [];
|
|
45
|
+
if (stops[0].position < 0)
|
|
46
|
+
out.push({ position: 0, color: sample(stops, 0) });
|
|
47
|
+
for (const stop of stops)
|
|
48
|
+
if (stop.position >= 0 && stop.position <= 1)
|
|
49
|
+
out.push(stop);
|
|
50
|
+
if (stops[stops.length - 1].position > 1)
|
|
51
|
+
out.push({ position: 1, color: sample(stops, 1) });
|
|
52
|
+
return out.length === 1 ? [{ position: 0, color: out[0].color }, { position: 1, color: out[0].color }] : out;
|
|
53
|
+
}
|
|
54
|
+
const DEGREES = 180 / Math.PI;
|
|
55
|
+
const normalizeDegrees = (degrees) => ((degrees % 360) + 360) % 360 + 0;
|
|
56
|
+
/**
|
|
57
|
+
* The Taco geometry of a Figma gradient of `type` on a `width` by `height`
|
|
58
|
+
* node, plus why it is only approximated, or `null` when the transform is
|
|
59
|
+
* flat or there are no stops.
|
|
60
|
+
*/
|
|
61
|
+
export function gradientShape(type, stops, m, width, height) {
|
|
62
|
+
if (stops.length === 0)
|
|
63
|
+
return null;
|
|
64
|
+
const sorted = [...stops].sort((a, b) => a.position - b.position);
|
|
65
|
+
if (type === "GRADIENT_LINEAR") {
|
|
66
|
+
// Gradient position t = m00 u + m01 v + m02 at unit point (u, v) = (x / width, y / height),
|
|
67
|
+
// so t grows along (m00 / width, m01 / height) in node pixels.
|
|
68
|
+
const gx = width > 0 ? m.m00 / width : 0;
|
|
69
|
+
const gy = height > 0 ? m.m01 / height : 0;
|
|
70
|
+
const perPixel = Math.hypot(gx, gy);
|
|
71
|
+
const atCenter = (m.m00 + m.m01) / 2 + m.m02;
|
|
72
|
+
if (perPixel < 1e-12)
|
|
73
|
+
return { shape: { kind: "solid", color: sample(sorted, atCenter) } };
|
|
74
|
+
const step = { x: width ? (gx / perPixel) / (perPixel * width) : 0, y: height ? (gy / perPixel) / (perPixel * height) : 0 };
|
|
75
|
+
// Anchor the axis on Figma's first handle. A shear transforms the lines of equal colour
|
|
76
|
+
// by the inverse transpose, so the step follows their normal in local pixels.
|
|
77
|
+
const det = m.m00 * m.m11 - m.m01 * m.m10;
|
|
78
|
+
const from = det
|
|
79
|
+
? { x: (-m.m02 * m.m11 - (0.5 - m.m12) * m.m01) / det || 0,
|
|
80
|
+
y: ((0.5 - m.m12) * m.m00 + m.m02 * m.m10) / det || 0 }
|
|
81
|
+
: { x: 0.5 - atCenter * step.x, y: 0.5 - atCenter * step.y };
|
|
82
|
+
return { shape: { kind: "linear-gradient", from, to: { x: from.x + step.x, y: from.y + step.y }, stops: clipStops(sorted) } };
|
|
83
|
+
}
|
|
84
|
+
const determinant = m.m00 * m.m11 - m.m01 * m.m10;
|
|
85
|
+
if (Math.abs(determinant) < 1e-12)
|
|
86
|
+
return null;
|
|
87
|
+
// The inverse's linear part, then the centre (0.5, 0.5) of gradient space in the unit box.
|
|
88
|
+
const a = m.m11 / determinant, b = -m.m01 / determinant, c = -m.m10 / determinant, d = m.m00 / determinant;
|
|
89
|
+
const center = { x: a * (0.5 - m.m02) + b * (0.5 - m.m12), y: c * (0.5 - m.m02) + d * (0.5 - m.m12) };
|
|
90
|
+
const clipped = clipStops(sorted);
|
|
91
|
+
if (type === "GRADIENT_RADIAL" || type === "GRADIENT_DIAMOND") {
|
|
92
|
+
// The circle of radius 0.5 maps to an ellipse whose bounding half-extents these are; Taco's ellipse is upright.
|
|
93
|
+
const radius = { x: 0.5 * Math.hypot(a, b), y: 0.5 * Math.hypot(c, d) };
|
|
94
|
+
const tilted = Math.abs(a * c + b * d) > 1e-4 * Math.hypot(a, b) * Math.hypot(c, d);
|
|
95
|
+
const approximated = type === "GRADIENT_DIAMOND" ? "a diamond gradient is drawn as a radial gradient"
|
|
96
|
+
: tilted ? "a rotated or skewed radial gradient is drawn as an upright ellipse" : undefined;
|
|
97
|
+
return { shape: { kind: "radial-gradient", center, radius, stops: clipped }, ...(approximated ? { approximated } : {}) };
|
|
98
|
+
}
|
|
99
|
+
if (type === "GRADIENT_ANGULAR") {
|
|
100
|
+
// Gradient space's +x in node pixels; the sweep is even only when the map is a turn and a uniform scale.
|
|
101
|
+
const p = { a: a * width, b: b * width, c: c * height, d: d * height };
|
|
102
|
+
const scale = Math.hypot(p.a, p.c);
|
|
103
|
+
const even = determinant > 0 && Math.abs(p.a - p.d) <= 1e-4 * scale && Math.abs(p.b + p.c) <= 1e-4 * scale;
|
|
104
|
+
const shape = { kind: "angular-gradient", center, angle: normalizeDegrees(Math.atan2(p.c, p.a) * DEGREES), stops: clipped };
|
|
105
|
+
return even ? { shape } : { shape, approximated: "a stretched or mirrored angular gradient is drawn as an even sweep" };
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FigmaNodeConverter } from "../walk.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A Figma group (a FRAME that `convertFrame` finds to be a group) as a Taco
|
|
4
|
+
* group. Figma stores each child's transform in the group's own space, with
|
|
5
|
+
* the group's top-left at the origin; a Taco group places its children the
|
|
6
|
+
* same way, relative to its frame, rotated and flipped about its middle
|
|
7
|
+
* (`nodeLocalTransform`). So the group's transform converts as a frame's
|
|
8
|
+
* does, and every child keeps its place on the page. A Taco group's frame is
|
|
9
|
+
* always the union of its children's bounds; Figma's size can differ (a mask
|
|
10
|
+
* group is as large as its mask), so the walk fits every imported group to
|
|
11
|
+
* its children afterwards, which moves nothing on the page. A group never
|
|
12
|
+
* clips, as in grida (packages/grida-canvas-io-figma/lib.ts:4605 sets
|
|
13
|
+
* `clipsContent: false`) and fig2sketch (src/converter/group.py:12 builds a
|
|
14
|
+
* plain Sketch group).
|
|
15
|
+
*
|
|
16
|
+
* A Taco group follows its layers' constraints (see `NodeBase.constraints`).
|
|
17
|
+
* The adapter reads the group's own constraints from its Figma metadata.
|
|
18
|
+
*/
|
|
19
|
+
export declare const convertGroup: FigmaNodeConverter;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { carry } from "../carry.js";
|
|
2
|
+
import { framedBase } from "./shared.js";
|
|
3
|
+
/**
|
|
4
|
+
* A Figma group (a FRAME that `convertFrame` finds to be a group) as a Taco
|
|
5
|
+
* group. Figma stores each child's transform in the group's own space, with
|
|
6
|
+
* the group's top-left at the origin; a Taco group places its children the
|
|
7
|
+
* same way, relative to its frame, rotated and flipped about its middle
|
|
8
|
+
* (`nodeLocalTransform`). So the group's transform converts as a frame's
|
|
9
|
+
* does, and every child keeps its place on the page. A Taco group's frame is
|
|
10
|
+
* always the union of its children's bounds; Figma's size can differ (a mask
|
|
11
|
+
* group is as large as its mask), so the walk fits every imported group to
|
|
12
|
+
* its children afterwards, which moves nothing on the page. A group never
|
|
13
|
+
* clips, as in grida (packages/grida-canvas-io-figma/lib.ts:4605 sets
|
|
14
|
+
* `clipsContent: false`) and fig2sketch (src/converter/group.py:12 builds a
|
|
15
|
+
* plain Sketch group).
|
|
16
|
+
*
|
|
17
|
+
* A Taco group follows its layers' constraints (see `NodeBase.constraints`).
|
|
18
|
+
* The adapter reads the group's own constraints from its Figma metadata.
|
|
19
|
+
*/
|
|
20
|
+
export const convertGroup = (node, walk) => {
|
|
21
|
+
const base = framedBase(node, walk, "Group");
|
|
22
|
+
if (base === null)
|
|
23
|
+
return null;
|
|
24
|
+
// `framedBase` sets no variable bindings; a group's type allows no width or height binding.
|
|
25
|
+
const { variableBindings: _none, constraints, ...fields } = base;
|
|
26
|
+
const group = { ...fields, type: "group", children: walk.convertChildren() };
|
|
27
|
+
if (constraints !== undefined)
|
|
28
|
+
carry(group, { groupConstraints: { ...constraints } });
|
|
29
|
+
return group;
|
|
30
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Paint } from "../../../model/index.ts";
|
|
2
|
+
import { type FigmaObject } from "../fields.ts";
|
|
3
|
+
import type { NodeWalk } from "../walk.ts";
|
|
4
|
+
/** The MIME type of PNG, JPEG, GIF and WebP bytes, read from their first bytes; `undefined` for anything else. */
|
|
5
|
+
export declare function sniffImageMimeType(bytes: Uint8Array): string | undefined;
|
|
6
|
+
export declare function hexText(bytes: Uint8Array): string;
|
|
7
|
+
/**
|
|
8
|
+
* A Figma IMAGE paint as a Taco image paint whose asset the host supplied
|
|
9
|
+
* (`FigmaImportOptions.images`), or a reason it is left out. `null` means it
|
|
10
|
+
* is left out for a reason already reported for the same image. Rotation
|
|
11
|
+
* and image adjustments (`paintFilter`, `filterColorAdjust`) are reported, not kept.
|
|
12
|
+
*/
|
|
13
|
+
export declare function imagePaint(paint: FigmaObject, at: string, label: string, walk: NodeWalk, fill: boolean): Paint | string | null;
|