@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,290 @@
|
|
|
1
|
+
import { deserializeDocument } from "./codec.js";
|
|
2
|
+
import { CURRENT_DOCUMENT_SCHEMA_VERSION, codeStyleId, componentId, documentId, nodeId, pageId, textStyleId, variableCollectionId, variableId, variableModeId, } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The IDs the component sample documents use, so tests can refer to them by
|
|
5
|
+
* name. Layer paths for overrides are built from the node IDs, for example
|
|
6
|
+
* `layerPathKey([componentSampleIds.cardButton, componentSampleIds.buttonLabel])`.
|
|
7
|
+
* @since 0.23.0
|
|
8
|
+
*/
|
|
9
|
+
export const componentSampleIds = {
|
|
10
|
+
document: documentId("component-samples"),
|
|
11
|
+
page: pageId("page-one"),
|
|
12
|
+
pageRoot: nodeId("root-one"),
|
|
13
|
+
textStyle: textStyleId("body"),
|
|
14
|
+
/** A "Button" component: a horizontal auto layout root that hugs a label and an icon. */
|
|
15
|
+
button: componentId("button"),
|
|
16
|
+
buttonRoot: nodeId("button-root"),
|
|
17
|
+
buttonLabel: nodeId("button-label"),
|
|
18
|
+
buttonIcon: nodeId("button-icon"),
|
|
19
|
+
/** A "Card" component: a vertical auto layout root with a title and a nested Button instance. */
|
|
20
|
+
card: componentId("card"),
|
|
21
|
+
cardRoot: nodeId("card-root"),
|
|
22
|
+
cardTitle: nodeId("card-title"),
|
|
23
|
+
cardButton: nodeId("card-button"),
|
|
24
|
+
/** An "Icon button" component: a fixed-size root with only an icon. */
|
|
25
|
+
iconButton: componentId("icon-button"),
|
|
26
|
+
iconButtonRoot: nodeId("icon-button-root"),
|
|
27
|
+
iconButtonIcon: nodeId("icon-button-icon"),
|
|
28
|
+
/** Instances on the page. */
|
|
29
|
+
buttonInstance: nodeId("button-1"),
|
|
30
|
+
secondButtonInstance: nodeId("button-2"),
|
|
31
|
+
cardInstance: nodeId("card-1"),
|
|
32
|
+
/** Variables of the variable-bound sample. */
|
|
33
|
+
colors: variableCollectionId("colors"),
|
|
34
|
+
lightMode: variableModeId("light"),
|
|
35
|
+
primary: variableId("primary"),
|
|
36
|
+
danger: variableId("danger"),
|
|
37
|
+
};
|
|
38
|
+
const ids = componentSampleIds;
|
|
39
|
+
const framed = (id, name, frame) => ({
|
|
40
|
+
id,
|
|
41
|
+
name,
|
|
42
|
+
visible: true,
|
|
43
|
+
locked: false,
|
|
44
|
+
opacity: 1,
|
|
45
|
+
frame,
|
|
46
|
+
rotation: 0,
|
|
47
|
+
});
|
|
48
|
+
const text = (id, name, characters, frame) => ({
|
|
49
|
+
...framed(id, name, frame),
|
|
50
|
+
type: "text",
|
|
51
|
+
paragraphs: [{ runs: [{ text: characters }] }],
|
|
52
|
+
verticalAlign: "top",
|
|
53
|
+
overflow: "visible",
|
|
54
|
+
autoResize: "width-and-height",
|
|
55
|
+
wrap: "none",
|
|
56
|
+
});
|
|
57
|
+
const rectangle = (id, name, frame, color) => ({
|
|
58
|
+
...framed(id, name, frame),
|
|
59
|
+
type: "shape",
|
|
60
|
+
shape: "rectangle",
|
|
61
|
+
style: { fills: [{ kind: "solid", color }], cornerRadius: 4 },
|
|
62
|
+
});
|
|
63
|
+
const hugRoot = (id, name, kind, children, size, fill) => ({
|
|
64
|
+
...framed(id, name, { x: 0, y: 0, ...size }),
|
|
65
|
+
type: "frame",
|
|
66
|
+
children,
|
|
67
|
+
layout: {
|
|
68
|
+
kind,
|
|
69
|
+
widthSizing: "hug",
|
|
70
|
+
heightSizing: "hug",
|
|
71
|
+
gap: 8,
|
|
72
|
+
padding: { top: 8, right: 12, bottom: 8, left: 12 },
|
|
73
|
+
align: "center",
|
|
74
|
+
justify: "start",
|
|
75
|
+
},
|
|
76
|
+
style: { fills: [{ kind: "solid", color: fill }], cornerRadius: 6 },
|
|
77
|
+
clipContent: false,
|
|
78
|
+
});
|
|
79
|
+
const instance = (id, name, of, frame, overrides) => ({
|
|
80
|
+
...framed(id, name, frame),
|
|
81
|
+
type: "instance",
|
|
82
|
+
componentId: of,
|
|
83
|
+
...(overrides === undefined ? {} : { overrides }),
|
|
84
|
+
});
|
|
85
|
+
const buttonComponent = {
|
|
86
|
+
id: ids.button,
|
|
87
|
+
key: "6f1d2b8e-7c1a-4e4f-9c1d-0b7a2f3e4d51",
|
|
88
|
+
name: "Button",
|
|
89
|
+
description: "A label with an icon",
|
|
90
|
+
rootId: ids.buttonRoot,
|
|
91
|
+
};
|
|
92
|
+
const buttonNodes = () => ({
|
|
93
|
+
[ids.buttonRoot]: hugRoot(ids.buttonRoot, "Button", "horizontal", [ids.buttonLabel, ids.buttonIcon], { width: 96, height: 40 }, "#0d9488"),
|
|
94
|
+
[ids.buttonLabel]: text(ids.buttonLabel, "Label", "Button", { x: 12, y: 8, width: 48, height: 24 }),
|
|
95
|
+
[ids.buttonIcon]: rectangle(ids.buttonIcon, "Icon", { x: 68, y: 12, width: 16, height: 16 }, "#ffffff"),
|
|
96
|
+
});
|
|
97
|
+
const cardComponent = {
|
|
98
|
+
id: ids.card,
|
|
99
|
+
key: "2a9c4e7b-3d5f-4a1b-8e6c-9f0d1a2b3c44",
|
|
100
|
+
name: "Card",
|
|
101
|
+
rootId: ids.cardRoot,
|
|
102
|
+
};
|
|
103
|
+
const cardNodes = () => ({
|
|
104
|
+
[ids.cardRoot]: hugRoot(ids.cardRoot, "Card", "vertical", [ids.cardTitle, ids.cardButton], { width: 200, height: 96 }, "#ffffff"),
|
|
105
|
+
[ids.cardTitle]: text(ids.cardTitle, "Title", "Card title", { x: 12, y: 8, width: 176, height: 24 }),
|
|
106
|
+
[ids.cardButton]: instance(ids.cardButton, "Button", ids.button, { x: 12, y: 40, width: 96, height: 40 }),
|
|
107
|
+
});
|
|
108
|
+
const iconButtonComponent = {
|
|
109
|
+
id: ids.iconButton,
|
|
110
|
+
key: "c3b2a1d0-5e6f-4789-a0b1-c2d3e4f5a677",
|
|
111
|
+
name: "Icon button",
|
|
112
|
+
rootId: ids.iconButtonRoot,
|
|
113
|
+
};
|
|
114
|
+
const iconButtonNodes = () => ({
|
|
115
|
+
[ids.iconButtonRoot]: {
|
|
116
|
+
...hugRoot(ids.iconButtonRoot, "Icon button", "horizontal", [ids.iconButtonIcon], { width: 40, height: 40 }, "#0d9488"),
|
|
117
|
+
layout: {
|
|
118
|
+
kind: "horizontal",
|
|
119
|
+
widthSizing: "fixed",
|
|
120
|
+
heightSizing: "fixed",
|
|
121
|
+
gap: 0,
|
|
122
|
+
padding: { top: 12, right: 12, bottom: 12, left: 12 },
|
|
123
|
+
align: "center",
|
|
124
|
+
justify: "center",
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
[ids.iconButtonIcon]: rectangle(ids.iconButtonIcon, "Icon", { x: 12, y: 12, width: 16, height: 16 }, "#ffffff"),
|
|
128
|
+
});
|
|
129
|
+
const pageRoot = (children) => ({
|
|
130
|
+
...framed(ids.pageRoot, "Page 1", { x: 0, y: 0, width: 800, height: 600 }),
|
|
131
|
+
type: "frame",
|
|
132
|
+
children,
|
|
133
|
+
layout: { kind: "absolute" },
|
|
134
|
+
});
|
|
135
|
+
const baseDocument = (nodes, components, theme) => deserializeDocument({
|
|
136
|
+
schemaVersion: CURRENT_DOCUMENT_SCHEMA_VERSION,
|
|
137
|
+
commentThreads: [],
|
|
138
|
+
id: ids.document,
|
|
139
|
+
title: "Component samples",
|
|
140
|
+
pageOrder: [ids.page],
|
|
141
|
+
pages: { [ids.page]: { id: ids.page, name: "Page 1", rootId: ids.pageRoot } },
|
|
142
|
+
nodes,
|
|
143
|
+
assets: {},
|
|
144
|
+
theme: {
|
|
145
|
+
defaultTextStyleId: ids.textStyle,
|
|
146
|
+
defaultCodeStyleId: codeStyleId("code"),
|
|
147
|
+
colors: {},
|
|
148
|
+
nodeStyles: {},
|
|
149
|
+
textStyles: {
|
|
150
|
+
[ids.textStyle]: {
|
|
151
|
+
name: "Body",
|
|
152
|
+
fontFamily: "Inter",
|
|
153
|
+
fontSize: 16,
|
|
154
|
+
fontWeight: 500,
|
|
155
|
+
lineHeight: 1.5,
|
|
156
|
+
color: "#111111",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
codeStyles: {
|
|
160
|
+
code: {
|
|
161
|
+
name: "Code",
|
|
162
|
+
fontFamily: "JetBrains Mono",
|
|
163
|
+
fontSize: 14,
|
|
164
|
+
lineHeight: 1.4,
|
|
165
|
+
background: "#111111",
|
|
166
|
+
foreground: "#f5f5f5",
|
|
167
|
+
syntax: {},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
...theme,
|
|
171
|
+
},
|
|
172
|
+
components,
|
|
173
|
+
});
|
|
174
|
+
/**
|
|
175
|
+
* One Button component and one instance of it on the page, with no
|
|
176
|
+
* overrides. The instance is at the component's natural size.
|
|
177
|
+
* @since 0.23.0
|
|
178
|
+
*/
|
|
179
|
+
export function plainInstanceSample() {
|
|
180
|
+
return baseDocument({
|
|
181
|
+
[ids.pageRoot]: pageRoot([ids.buttonInstance]),
|
|
182
|
+
...buttonNodes(),
|
|
183
|
+
[ids.buttonInstance]: instance(ids.buttonInstance, "Button", ids.button, { x: 40, y: 40, width: 96, height: 40 }),
|
|
184
|
+
}, { [ids.button]: buttonComponent });
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A Card component whose tree holds an instance of Button, and one Card
|
|
188
|
+
* instance on the page. The nesting graph has the edge Card → Button.
|
|
189
|
+
* @since 0.23.0
|
|
190
|
+
*/
|
|
191
|
+
export function nestedInstanceSample() {
|
|
192
|
+
return baseDocument({
|
|
193
|
+
[ids.pageRoot]: pageRoot([ids.cardInstance]),
|
|
194
|
+
...buttonNodes(),
|
|
195
|
+
...cardNodes(),
|
|
196
|
+
[ids.cardInstance]: instance(ids.cardInstance, "Card", ids.card, { x: 40, y: 40, width: 200, height: 96 }),
|
|
197
|
+
}, { [ids.button]: buttonComponent, [ids.card]: cardComponent });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Two Button instances with text overrides: `button-1` changes the label's
|
|
201
|
+
* characters only, and `button-2` stores styled paragraphs because part of
|
|
202
|
+
* its label is bold. Both keep the component's font.
|
|
203
|
+
* @since 0.23.0
|
|
204
|
+
*/
|
|
205
|
+
export function textOverrideSample() {
|
|
206
|
+
return baseDocument({
|
|
207
|
+
[ids.pageRoot]: pageRoot([ids.buttonInstance, ids.secondButtonInstance]),
|
|
208
|
+
...buttonNodes(),
|
|
209
|
+
[ids.buttonInstance]: instance(ids.buttonInstance, "Buy button", ids.button, { x: 40, y: 40, width: 108, height: 40 }, { [ids.buttonLabel]: { characters: "Buy now" } }),
|
|
210
|
+
[ids.secondButtonInstance]: instance(ids.secondButtonInstance, "Styled button", ids.button, { x: 40, y: 100, width: 120, height: 40 }, {
|
|
211
|
+
[ids.buttonLabel]: {
|
|
212
|
+
paragraphs: [{
|
|
213
|
+
runs: [
|
|
214
|
+
{ text: "Save " },
|
|
215
|
+
{ text: "20%", overrides: { fontWeight: 700 } },
|
|
216
|
+
],
|
|
217
|
+
}],
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
}, { [ids.button]: buttonComponent });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The Button label's colour is bound to the `primary` variable in the
|
|
224
|
+
* component. The instance rebinds it to `danger` for the label, and for the
|
|
225
|
+
* root it overrides the fills with a plain colour while removing the
|
|
226
|
+
* component's `fillColor` binding, so the plain override cannot be repainted
|
|
227
|
+
* by the variable.
|
|
228
|
+
* @since 0.23.0
|
|
229
|
+
*/
|
|
230
|
+
export function variableBoundOverrideSample() {
|
|
231
|
+
const button = buttonNodes();
|
|
232
|
+
const label = button[ids.buttonLabel];
|
|
233
|
+
const root = button[ids.buttonRoot];
|
|
234
|
+
return baseDocument({
|
|
235
|
+
[ids.pageRoot]: pageRoot([ids.buttonInstance]),
|
|
236
|
+
...button,
|
|
237
|
+
[ids.buttonLabel]: { ...label, variableBindings: { textColor: ids.primary } },
|
|
238
|
+
[ids.buttonRoot]: { ...root, variableBindings: { fillColor: ids.primary } },
|
|
239
|
+
[ids.buttonInstance]: instance(ids.buttonInstance, "Danger button", ids.button, { x: 40, y: 40, width: 96, height: 40 }, {
|
|
240
|
+
[ids.buttonLabel]: { variableBindings: { textColor: ids.danger } },
|
|
241
|
+
[ids.buttonRoot]: {
|
|
242
|
+
fills: [{ kind: "solid", color: "#fee2e2" }],
|
|
243
|
+
variableBindings: { fillColor: null },
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
}, { [ids.button]: buttonComponent }, {
|
|
247
|
+
variableCollections: {
|
|
248
|
+
[ids.colors]: {
|
|
249
|
+
name: "Colors",
|
|
250
|
+
defaultModeId: ids.lightMode,
|
|
251
|
+
modeOrder: [ids.lightMode],
|
|
252
|
+
modes: { [ids.lightMode]: { name: "Light" } },
|
|
253
|
+
variables: {
|
|
254
|
+
[ids.primary]: { name: "primary", type: "color", values: { [ids.lightMode]: "#0d9488" } },
|
|
255
|
+
[ids.danger]: { name: "danger", type: "color", values: { [ids.lightMode]: "#dc2626" } },
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The nested sample plus an Icon button component. The Card instance swaps
|
|
263
|
+
* its nested Button to Icon button, and keeps a characters override under
|
|
264
|
+
* the old label's path, which Icon button does not have: the entry is
|
|
265
|
+
* allowed and has no effect.
|
|
266
|
+
* @since 0.23.0
|
|
267
|
+
*/
|
|
268
|
+
export function swappedNestedInstanceSample() {
|
|
269
|
+
return baseDocument({
|
|
270
|
+
[ids.pageRoot]: pageRoot([ids.cardInstance]),
|
|
271
|
+
...buttonNodes(),
|
|
272
|
+
...cardNodes(),
|
|
273
|
+
...iconButtonNodes(),
|
|
274
|
+
[ids.cardInstance]: instance(ids.cardInstance, "Card", ids.card, { x: 40, y: 40, width: 200, height: 96 }, {
|
|
275
|
+
[ids.cardButton]: { componentId: ids.iconButton },
|
|
276
|
+
[`${ids.cardButton};${ids.buttonLabel}`]: { characters: "Gone" },
|
|
277
|
+
}),
|
|
278
|
+
}, { [ids.button]: buttonComponent, [ids.card]: cardComponent, [ids.iconButton]: iconButtonComponent });
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Every component sample by name, for tests that run over all of them.
|
|
282
|
+
* @since 0.23.0
|
|
283
|
+
*/
|
|
284
|
+
export const componentSampleDocuments = {
|
|
285
|
+
plain: plainInstanceSample,
|
|
286
|
+
nested: nestedInstanceSample,
|
|
287
|
+
textOverride: textOverrideSample,
|
|
288
|
+
variableBoundOverride: variableBoundOverrideSample,
|
|
289
|
+
swappedNested: swappedNestedInstanceSample,
|
|
290
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type ExpressionCheckResult, type ExpressionEnvironment } from "./expressions/check.ts";
|
|
2
|
+
import type { ComponentDefinition, ComponentPropertyValue, ComponentPropertyValues } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The most steps one search for a valid combination may take (one step is
|
|
5
|
+
* one property given one value). Above it the search throws a `ModelError`
|
|
6
|
+
* naming the component: its validity expression is too costly to search.
|
|
7
|
+
* @since 0.35.0
|
|
8
|
+
*/
|
|
9
|
+
export declare const VARIANT_SEARCH_STEP_LIMIT = 100000;
|
|
10
|
+
/**
|
|
11
|
+
* What these functions read of a component: its ID and name (for messages),
|
|
12
|
+
* its properties and its validity expression.
|
|
13
|
+
* @since 0.35.0
|
|
14
|
+
*/
|
|
15
|
+
export type ValidityComponent = Pick<ComponentDefinition, "id" | "name" | "properties" | "validity">;
|
|
16
|
+
/**
|
|
17
|
+
* The checking environment of a component's validity expression: its enum
|
|
18
|
+
* and boolean properties by name, and nothing else (no other property, no
|
|
19
|
+
* variable, no `stored`).
|
|
20
|
+
* @since 0.35.0
|
|
21
|
+
*/
|
|
22
|
+
export declare function componentValidityEnvironment(component: ValidityComponent): ExpressionEnvironment;
|
|
23
|
+
/**
|
|
24
|
+
* Checks `source` (the component's own validity expression by default) as a
|
|
25
|
+
* validity expression of `component`: it must parse, be a boolean, and read
|
|
26
|
+
* only the component's enum and boolean properties. Undefined when there is
|
|
27
|
+
* no expression to check.
|
|
28
|
+
* @since 0.35.0
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkComponentValidity(component: ValidityComponent, source?: string | undefined): ExpressionCheckResult | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* True when `values` (an instance's values by property ID; a missing value
|
|
33
|
+
* or one that does not fit reads as the default) form a valid combination
|
|
34
|
+
* of `component`. Always true for a component without a validity
|
|
35
|
+
* expression. Only enum and boolean values matter.
|
|
36
|
+
* @since 0.35.0
|
|
37
|
+
*/
|
|
38
|
+
export declare function isValidVariantCombination(component: ValidityComponent, values?: ComponentPropertyValues): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* For each enum and boolean property of `component`, by property ID, the
|
|
41
|
+
* values to offer with the others as in `values`: an option is offered
|
|
42
|
+
* when at least one valid combination has it (choosing it may change other
|
|
43
|
+
* properties, see `nearestValidCombination`). Enum values are option IDs in
|
|
44
|
+
* option order; booleans are `false`, then `true`. Every value is offered
|
|
45
|
+
* without a validity expression. Throws a `ModelError` when the search
|
|
46
|
+
* passes `VARIANT_SEARCH_STEP_LIMIT` steps.
|
|
47
|
+
* @since 0.35.0
|
|
48
|
+
*/
|
|
49
|
+
export declare function offeredVariantValues(component: ValidityComponent, values?: ComponentPropertyValues): Readonly<Record<string, readonly ComponentPropertyValue[]>>;
|
|
50
|
+
/** A valid combination `nearestValidCombination` found. */
|
|
51
|
+
export interface VariantCombinationChange {
|
|
52
|
+
/** Every enum and boolean property's value, by property ID. */
|
|
53
|
+
readonly values: Readonly<Record<string, ComponentPropertyValue>>;
|
|
54
|
+
/** The properties whose value differs from the one `values` gave before, in property order. */
|
|
55
|
+
readonly changed: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The valid combination nearest to `values` that keeps `propertyId` at
|
|
59
|
+
* `value` (or, with no property given, the valid combination nearest to
|
|
60
|
+
* `values`): the fewest other properties changed; among as near ones, the
|
|
61
|
+
* first in the search order, which takes the properties in the component's
|
|
62
|
+
* order and each one's values in option order (a boolean `false` before
|
|
63
|
+
* `true`), so an earlier property's earlier option wins. Undefined when no
|
|
64
|
+
* valid combination has that value. `values` itself when it is valid.
|
|
65
|
+
* Throws a `ModelError` when the search passes `VARIANT_SEARCH_STEP_LIMIT`
|
|
66
|
+
* steps, and when `propertyId` is not an enum or boolean property or
|
|
67
|
+
* `value` does not fit it.
|
|
68
|
+
* @since 0.35.0
|
|
69
|
+
*/
|
|
70
|
+
export declare function nearestValidCombination(component: ValidityComponent, values?: ComponentPropertyValues, propertyId?: string, value?: ComponentPropertyValue): VariantCombinationChange | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Why `values` are not a valid combination of `component`, naming the valid
|
|
73
|
+
* combinations nearest to them (each keeps one property and changes as few
|
|
74
|
+
* others as it can); undefined when they are valid.
|
|
75
|
+
* @since 0.35.0
|
|
76
|
+
*/
|
|
77
|
+
export declare function invalidCombinationProblem(component: ValidityComponent, values?: ComponentPropertyValues): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* `values` with the enum and boolean values moved to the nearest valid
|
|
80
|
+
* combination when they are not one (see `nearestValidCombination`; no
|
|
81
|
+
* property is held), writing only the values that change. `values` itself
|
|
82
|
+
* when it is valid or none is near.
|
|
83
|
+
* @since 0.35.0
|
|
84
|
+
*/
|
|
85
|
+
export declare function withValidVariantValues(component: ValidityComponent, values: ComponentPropertyValues): ComponentPropertyValues;
|