@moondraft/import 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +34 -0
- package/README.md +36 -2
- package/SOURCE.md +169 -0
- package/dist/adapter/convert.d.ts +122 -0
- package/dist/adapter/convert.js +2302 -0
- package/dist/adapter/figma.d.ts +9 -0
- package/dist/adapter/figma.js +30 -0
- package/dist/adapter/file-components.d.ts +14 -0
- package/dist/adapter/file-components.js +262 -0
- package/dist/adapter/file-resources.d.ts +29 -0
- package/dist/adapter/file-resources.js +562 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.js +9 -0
- package/dist/adapter/link.d.ts +45 -0
- package/dist/adapter/link.js +688 -0
- package/dist/adapter/payload.d.ts +31 -0
- package/dist/adapter/payload.js +78 -0
- package/dist/adapter/shapes.d.ts +31 -0
- package/dist/adapter/shapes.js +75 -0
- package/dist/adapter/variables.d.ts +44 -0
- package/dist/adapter/variables.js +103 -0
- package/dist/figma-file.d.ts +38 -0
- package/dist/figma-file.js +97 -0
- package/dist/figma-worker.d.ts +11 -0
- package/dist/figma-worker.js +12 -0
- package/dist/figma.d.ts +26 -0
- package/dist/figma.js +96 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +49 -0
- package/dist/report.d.ts +15 -0
- package/dist/report.js +69 -0
- package/dist/svg.d.ts +33 -0
- package/dist/svg.js +44 -0
- package/dist/syntax.d.ts +8 -0
- package/dist/syntax.js +19 -0
- package/dist/taco/figma-import/clipboard.d.ts +25 -0
- package/dist/taco/figma-import/clipboard.js +87 -0
- package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
- package/dist/taco/figma-import/clipboardSize.js +107 -0
- package/dist/taco/figma-import/container/compression.d.ts +9 -0
- package/dist/taco/figma-import/container/compression.js +174 -0
- package/dist/taco/figma-import/container/error.d.ts +15 -0
- package/dist/taco/figma-import/container/error.js +19 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
- package/dist/taco/figma-import/container/limits.d.ts +22 -0
- package/dist/taco/figma-import/container/limits.js +22 -0
- package/dist/taco/figma-import/container/zip.d.ts +14 -0
- package/dist/taco/figma-import/container/zip.js +154 -0
- package/dist/taco/figma-import/figFile.d.ts +34 -0
- package/dist/taco/figma-import/figFile.js +91 -0
- package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
- package/dist/taco/figma-import/figFileDocument.js +100 -0
- package/dist/taco/figma-import/import/blobs.d.ts +10 -0
- package/dist/taco/figma-import/import/blobs.js +23 -0
- package/dist/taco/figma-import/import/carry.d.ts +11 -0
- package/dist/taco/figma-import/import/carry.js +33 -0
- package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
- package/dist/taco/figma-import/import/componentProps.js +313 -0
- package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
- package/dist/taco/figma-import/import/componentSets.js +647 -0
- package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
- package/dist/taco/figma-import/import/converters/effects.js +127 -0
- package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
- package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/frame.js +55 -0
- package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
- package/dist/taco/figma-import/import/converters/gradient.js +106 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
- package/dist/taco/figma-import/import/converters/group.js +39 -0
- package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
- package/dist/taco/figma-import/import/converters/image.js +83 -0
- package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
- package/dist/taco/figma-import/import/converters/layout.js +168 -0
- package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
- package/dist/taco/figma-import/import/converters/line.js +40 -0
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
- package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
- package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
- package/dist/taco/figma-import/import/converters/section.js +35 -0
- package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
- package/dist/taco/figma-import/import/converters/shared.js +362 -0
- package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
- package/dist/taco/figma-import/import/converters/text.js +576 -0
- package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
- package/dist/taco/figma-import/import/converters/vector.js +468 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
- package/dist/taco/figma-import/import/fields.d.ts +15 -0
- package/dist/taco/figma-import/import/fields.js +29 -0
- package/dist/taco/figma-import/import/instances.d.ts +163 -0
- package/dist/taco/figma-import/import/instances.js +1323 -0
- package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
- package/dist/taco/figma-import/import/nestingCycles.js +488 -0
- package/dist/taco/figma-import/import/slots.d.ts +56 -0
- package/dist/taco/figma-import/import/slots.js +96 -0
- package/dist/taco/figma-import/import/styles.d.ts +46 -0
- package/dist/taco/figma-import/import/styles.js +42 -0
- package/dist/taco/figma-import/import/tree.d.ts +66 -0
- package/dist/taco/figma-import/import/tree.js +194 -0
- package/dist/taco/figma-import/import/types.d.ts +232 -0
- package/dist/taco/figma-import/import/types.js +33 -0
- package/dist/taco/figma-import/import/variables.d.ts +136 -0
- package/dist/taco/figma-import/import/variables.js +762 -0
- package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
- package/dist/taco/figma-import/import/variantTrees.js +480 -0
- package/dist/taco/figma-import/import/walk.d.ts +159 -0
- package/dist/taco/figma-import/import/walk.js +1297 -0
- package/dist/taco/figma-import/index.d.ts +22 -0
- package/dist/taco/figma-import/index.js +13 -0
- package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
- package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
- package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
- package/dist/taco/figma-import/kiwi/error.js +29 -0
- package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
- package/dist/taco/figma-import/kiwi/limits.js +18 -0
- package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
- package/dist/taco/figma-import/kiwi/message.js +145 -0
- package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
- package/dist/taco/figma-import/kiwi/schema.js +206 -0
- package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
- package/dist/taco/figma-import/kiwi/types.js +18 -0
- package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
- package/dist/taco/model/agent-hidden-fields.js +29 -0
- package/dist/taco/model/asset-users.d.ts +23 -0
- package/dist/taco/model/asset-users.js +128 -0
- package/dist/taco/model/auto-layout-lines.d.ts +32 -0
- package/dist/taco/model/auto-layout-lines.js +70 -0
- package/dist/taco/model/codec.d.ts +444 -0
- package/dist/taco/model/codec.js +5635 -0
- package/dist/taco/model/color.d.ts +11 -0
- package/dist/taco/model/color.js +61 -0
- package/dist/taco/model/comment-operations.d.ts +102 -0
- package/dist/taco/model/comment-operations.js +227 -0
- package/dist/taco/model/component-evaluation.d.ts +94 -0
- package/dist/taco/model/component-evaluation.js +548 -0
- package/dist/taco/model/component-expressions.d.ts +242 -0
- package/dist/taco/model/component-expressions.js +1082 -0
- package/dist/taco/model/component-properties.d.ts +111 -0
- package/dist/taco/model/component-properties.js +339 -0
- package/dist/taco/model/component-samples.d.ts +83 -0
- package/dist/taco/model/component-samples.js +290 -0
- package/dist/taco/model/component-validity.d.ts +85 -0
- package/dist/taco/model/component-validity.js +397 -0
- package/dist/taco/model/components.d.ts +155 -0
- package/dist/taco/model/components.js +505 -0
- package/dist/taco/model/connector-ends.d.ts +20 -0
- package/dist/taco/model/connector-ends.js +188 -0
- package/dist/taco/model/connector-geometry.d.ts +74 -0
- package/dist/taco/model/connector-geometry.js +293 -0
- package/dist/taco/model/corner-radii.d.ts +26 -0
- package/dist/taco/model/corner-radii.js +47 -0
- package/dist/taco/model/derivations.d.ts +81 -0
- package/dist/taco/model/derivations.js +151 -0
- package/dist/taco/model/export-settings.d.ts +53 -0
- package/dist/taco/model/export-settings.js +156 -0
- package/dist/taco/model/expressions/ast.d.ts +153 -0
- package/dist/taco/model/expressions/ast.js +6 -0
- package/dist/taco/model/expressions/cache.d.ts +23 -0
- package/dist/taco/model/expressions/cache.js +43 -0
- package/dist/taco/model/expressions/check.d.ts +72 -0
- package/dist/taco/model/expressions/check.js +517 -0
- package/dist/taco/model/expressions/completion.d.ts +61 -0
- package/dist/taco/model/expressions/completion.js +421 -0
- package/dist/taco/model/expressions/evaluate.d.ts +32 -0
- package/dist/taco/model/expressions/evaluate.js +519 -0
- package/dist/taco/model/expressions/forms.d.ts +84 -0
- package/dist/taco/model/expressions/forms.js +200 -0
- package/dist/taco/model/expressions/index.d.ts +14 -0
- package/dist/taco/model/expressions/index.js +17 -0
- package/dist/taco/model/expressions/lexer.d.ts +42 -0
- package/dist/taco/model/expressions/lexer.js +213 -0
- package/dist/taco/model/expressions/library.d.ts +33 -0
- package/dist/taco/model/expressions/library.js +117 -0
- package/dist/taco/model/expressions/names.d.ts +43 -0
- package/dist/taco/model/expressions/names.js +99 -0
- package/dist/taco/model/expressions/parser.d.ts +15 -0
- package/dist/taco/model/expressions/parser.js +438 -0
- package/dist/taco/model/expressions/rename.d.ts +34 -0
- package/dist/taco/model/expressions/rename.js +46 -0
- package/dist/taco/model/expressions/source.d.ts +15 -0
- package/dist/taco/model/expressions/source.js +161 -0
- package/dist/taco/model/expressions/types.d.ts +119 -0
- package/dist/taco/model/expressions/types.js +102 -0
- package/dist/taco/model/expressions/values.d.ts +97 -0
- package/dist/taco/model/expressions/values.js +160 -0
- package/dist/taco/model/geometry-limits.d.ts +16 -0
- package/dist/taco/model/geometry-limits.js +67 -0
- package/dist/taco/model/geometry.d.ts +47 -0
- package/dist/taco/model/geometry.js +193 -0
- package/dist/taco/model/group-bounds.d.ts +38 -0
- package/dist/taco/model/group-bounds.js +144 -0
- package/dist/taco/model/id-table.d.ts +37 -0
- package/dist/taco/model/id-table.js +80 -0
- package/dist/taco/model/index.d.ts +25 -0
- package/dist/taco/model/index.js +27 -0
- package/dist/taco/model/instance-resolver.d.ts +372 -0
- package/dist/taco/model/instance-resolver.js +1748 -0
- package/dist/taco/model/layer-syntax.d.ts +340 -0
- package/dist/taco/model/layer-syntax.js +3506 -0
- package/dist/taco/model/layout/constraints.d.ts +84 -0
- package/dist/taco/model/layout/constraints.js +445 -0
- package/dist/taco/model/layout/frame-layout.d.ts +46 -0
- package/dist/taco/model/layout/frame-layout.js +618 -0
- package/dist/taco/model/layout/node-sizing.d.ts +163 -0
- package/dist/taco/model/layout/node-sizing.js +486 -0
- package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
- package/dist/taco/model/legacy-connector-caps.js +70 -0
- package/dist/taco/model/linear-call.d.ts +48 -0
- package/dist/taco/model/linear-call.js +58 -0
- package/dist/taco/model/new-nodes.d.ts +145 -0
- package/dist/taco/model/new-nodes.js +277 -0
- package/dist/taco/model/node-builder.d.ts +449 -0
- package/dist/taco/model/node-builder.js +2294 -0
- package/dist/taco/model/node-table-watch.d.ts +36 -0
- package/dist/taco/model/node-table-watch.js +63 -0
- package/dist/taco/model/node-transform.d.ts +39 -0
- package/dist/taco/model/node-transform.js +79 -0
- package/dist/taco/model/node-users-index.d.ts +10 -0
- package/dist/taco/model/node-users-index.js +82 -0
- package/dist/taco/model/operation-references.d.ts +80 -0
- package/dist/taco/model/operation-references.js +399 -0
- package/dist/taco/model/operations.d.ts +610 -0
- package/dist/taco/model/operations.js +2882 -0
- package/dist/taco/model/overlay-table.d.ts +71 -0
- package/dist/taco/model/overlay-table.js +171 -0
- package/dist/taco/model/override-remap.d.ts +69 -0
- package/dist/taco/model/override-remap.js +230 -0
- package/dist/taco/model/parent-table.d.ts +53 -0
- package/dist/taco/model/parent-table.js +193 -0
- package/dist/taco/model/problem-collector.d.ts +27 -0
- package/dist/taco/model/problem-collector.js +101 -0
- package/dist/taco/model/sha256.d.ts +10 -0
- package/dist/taco/model/sha256.js +74 -0
- package/dist/taco/model/shape-geometry.d.ts +96 -0
- package/dist/taco/model/shape-geometry.js +368 -0
- package/dist/taco/model/shared-node-table.d.ts +97 -0
- package/dist/taco/model/shared-node-table.js +546 -0
- package/dist/taco/model/slots.d.ts +113 -0
- package/dist/taco/model/slots.js +281 -0
- package/dist/taco/model/stroke-settings.d.ts +37 -0
- package/dist/taco/model/stroke-settings.js +90 -0
- package/dist/taco/model/svg-path-import.d.ts +89 -0
- package/dist/taco/model/svg-path-import.js +219 -0
- package/dist/taco/model/text-measurement.d.ts +142 -0
- package/dist/taco/model/text-measurement.js +846 -0
- package/dist/taco/model/text-reads.d.ts +66 -0
- package/dist/taco/model/text-reads.js +128 -0
- package/dist/taco/model/text-sizer.d.ts +358 -0
- package/dist/taco/model/text-sizer.js +996 -0
- package/dist/taco/model/theme-users.d.ts +59 -0
- package/dist/taco/model/theme-users.js +312 -0
- package/dist/taco/model/thumbnail.d.ts +15 -0
- package/dist/taco/model/thumbnail.js +34 -0
- package/dist/taco/model/types.d.ts +2347 -0
- package/dist/taco/model/types.js +366 -0
- package/dist/taco/model/unknown-property.d.ts +5 -0
- package/dist/taco/model/unknown-property.js +7 -0
- package/dist/taco/model/validated-documents.d.ts +22 -0
- package/dist/taco/model/validated-documents.js +22 -0
- package/dist/taco/model/variable-modes.d.ts +61 -0
- package/dist/taco/model/variable-modes.js +438 -0
- package/dist/taco/model/variable-references.d.ts +54 -0
- package/dist/taco/model/variable-references.js +183 -0
- package/dist/taco/model/variables.d.ts +24 -0
- package/dist/taco/model/variables.js +151 -0
- package/dist/taco/model/vector-network.d.ts +34 -0
- package/dist/taco/model/vector-network.js +411 -0
- package/dist/taco/svg-import/import-svg.d.ts +36 -0
- package/dist/taco/svg-import/import-svg.js +729 -0
- package/dist/taco/svg-import/index.d.ts +3 -0
- package/dist/taco/svg-import/index.js +3 -0
- package/dist/taco/svg-import/limits/limits.d.ts +79 -0
- package/dist/taco/svg-import/limits/limits.js +160 -0
- package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
- package/dist/taco/svg-import/paint/gradients.js +429 -0
- package/dist/taco/svg-import/paint/paint.d.ts +32 -0
- package/dist/taco/svg-import/paint/paint.js +162 -0
- package/dist/taco/svg-import/paths/paths.d.ts +58 -0
- package/dist/taco/svg-import/paths/paths.js +205 -0
- package/dist/taco/svg-import/public-types.d.ts +279 -0
- package/dist/taco/svg-import/public-types.js +56 -0
- package/dist/taco/svg-import/report/report.d.ts +44 -0
- package/dist/taco/svg-import/report/report.js +79 -0
- package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
- package/dist/taco/svg-import/reuse/reuse.js +840 -0
- package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
- package/dist/taco/svg-import/shapes/shapes.js +386 -0
- package/dist/taco/svg-import/structure/effects.d.ts +26 -0
- package/dist/taco/svg-import/structure/effects.js +618 -0
- package/dist/taco/svg-import/structure/image.d.ts +24 -0
- package/dist/taco/svg-import/structure/image.js +495 -0
- package/dist/taco/svg-import/structure/walk.d.ts +85 -0
- package/dist/taco/svg-import/structure/walk.js +544 -0
- package/dist/taco/svg-import/style/color.d.ts +40 -0
- package/dist/taco/svg-import/style/color.js +275 -0
- package/dist/taco/svg-import/style/computed.d.ts +214 -0
- package/dist/taco/svg-import/style/computed.js +1534 -0
- package/dist/taco/svg-import/style/css.d.ts +127 -0
- package/dist/taco/svg-import/style/css.js +541 -0
- package/dist/taco/svg-import/style/media.d.ts +25 -0
- package/dist/taco/svg-import/style/media.js +307 -0
- package/dist/taco/svg-import/style/properties.d.ts +43 -0
- package/dist/taco/svg-import/style/properties.js +135 -0
- package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
- package/dist/taco/svg-import/style/selector-reach.js +169 -0
- package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
- package/dist/taco/svg-import/style/selector-validity.js +307 -0
- package/dist/taco/svg-import/text/text.d.ts +29 -0
- package/dist/taco/svg-import/text/text.js +545 -0
- package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
- package/dist/taco/svg-import/transform/matrix.js +229 -0
- package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
- package/dist/taco/svg-import/tree/element-data.js +155 -0
- package/dist/taco/svg-import/tree/elements.d.ts +36 -0
- package/dist/taco/svg-import/tree/elements.js +121 -0
- package/dist/taco/svg-import/units/length.d.ts +43 -0
- package/dist/taco/svg-import/units/length.js +125 -0
- package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
- package/dist/taco/svg-import/units/viewbox.js +77 -0
- package/package.json +54 -4
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { MAX_SHAPE_POINT_COUNT, MIN_SHAPE_POINT_COUNT, vectorRegionId, vectorSegmentId, vectorVertexId, } from "./types.js";
|
|
2
|
+
/** Figma's defaults for newly drawn shapes. */
|
|
3
|
+
export const DEFAULT_POLYGON_POINT_COUNT = 3;
|
|
4
|
+
export const DEFAULT_STAR_POINT_COUNT = 5;
|
|
5
|
+
export const DEFAULT_STAR_INNER_RADIUS = 0.382;
|
|
6
|
+
export function isValidShapePointCount(value) {
|
|
7
|
+
return Number.isInteger(value) &&
|
|
8
|
+
value >= MIN_SHAPE_POINT_COUNT &&
|
|
9
|
+
value <= MAX_SHAPE_POINT_COUNT;
|
|
10
|
+
}
|
|
11
|
+
function assertPointCount(pointCount) {
|
|
12
|
+
if (!isValidShapePointCount(pointCount)) {
|
|
13
|
+
throw new RangeError(`A point count must be a whole number from ${MIN_SHAPE_POINT_COUNT} to ${MAX_SHAPE_POINT_COUNT}; got ${pointCount}.`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Maps unit-circle points into the frame so their bounding box fills it
|
|
18
|
+
* exactly. A zero-size axis collapses onto the frame edge.
|
|
19
|
+
*/
|
|
20
|
+
function fitPointsToFrame(points, width, height) {
|
|
21
|
+
const xs = points.map((point) => point.x);
|
|
22
|
+
const ys = points.map((point) => point.y);
|
|
23
|
+
const minX = Math.min(...xs);
|
|
24
|
+
const maxX = Math.max(...xs);
|
|
25
|
+
const minY = Math.min(...ys);
|
|
26
|
+
const maxY = Math.max(...ys);
|
|
27
|
+
const spanX = maxX - minX;
|
|
28
|
+
const spanY = maxY - minY;
|
|
29
|
+
return points.map((point) => ({
|
|
30
|
+
x: spanX === 0 ? 0 : (point.x - minX) / spanX * width,
|
|
31
|
+
y: spanY === 0 ? 0 : (point.y - minY) / spanY * height,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The corners of a regular polygon in frame-local coordinates, clockwise from
|
|
36
|
+
* the top center. The polygon is stretched so its bounds equal the frame.
|
|
37
|
+
* Corner $k$ of $n$ starts on the unit circle (y points down)
|
|
38
|
+
*
|
|
39
|
+
* $$
|
|
40
|
+
* \theta_k = -\frac{\pi}{2} + \frac{2\pi k}{n}, \qquad
|
|
41
|
+
* (u_k, v_k) = (\cos\theta_k, \sin\theta_k)
|
|
42
|
+
* $$
|
|
43
|
+
*
|
|
44
|
+
* and is then scaled into the frame by its bounding box:
|
|
45
|
+
* $x_k = w \cdot (u_k - u_\text{min}) / (u_\text{max} - u_\text{min})$, and
|
|
46
|
+
* likewise $y_k$ with the height (0 when the span is 0).
|
|
47
|
+
*/
|
|
48
|
+
export function polygonPoints(pointCount, width, height) {
|
|
49
|
+
assertPointCount(pointCount);
|
|
50
|
+
const unit = Array.from({ length: pointCount }, (_, index) => {
|
|
51
|
+
const angle = -Math.PI / 2 + index * 2 * Math.PI / pointCount;
|
|
52
|
+
return { x: Math.cos(angle), y: Math.sin(angle) };
|
|
53
|
+
});
|
|
54
|
+
return fitPointsToFrame(unit, width, height);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The alternating outer and inner points of a star in frame-local
|
|
58
|
+
* coordinates, clockwise from the top outer point. `innerRadius` is the inner
|
|
59
|
+
* point distance as a fraction of the outer radius. The star is stretched so
|
|
60
|
+
* the bounds of all its points equal the frame. Before stretching, point $k$
|
|
61
|
+
* of $2n$ is
|
|
62
|
+
*
|
|
63
|
+
* $$
|
|
64
|
+
* \theta_k = -\frac{\pi}{2} + \frac{\pi k}{n}, \qquad
|
|
65
|
+
* r_k = \begin{cases} 1 & k \text{ even} \\ \rho & k \text{ odd} \end{cases}, \qquad
|
|
66
|
+
* (u_k, v_k) = (r_k\cos\theta_k,\ r_k\sin\theta_k)
|
|
67
|
+
* $$
|
|
68
|
+
*
|
|
69
|
+
* with $\rho$ = `innerRadius`; the stretch is the same as `polygonPoints`.
|
|
70
|
+
*/
|
|
71
|
+
export function starPoints(pointCount, innerRadius, width, height) {
|
|
72
|
+
assertPointCount(pointCount);
|
|
73
|
+
if (!Number.isFinite(innerRadius) || innerRadius < 0 || innerRadius > 1) {
|
|
74
|
+
throw new RangeError(`A star inner radius must be from 0 to 1; got ${innerRadius}.`);
|
|
75
|
+
}
|
|
76
|
+
const unit = Array.from({ length: pointCount * 2 }, (_, index) => {
|
|
77
|
+
const radius = index % 2 === 0 ? 1 : innerRadius;
|
|
78
|
+
const angle = -Math.PI / 2 + index * Math.PI / pointCount;
|
|
79
|
+
return { x: Math.cos(angle) * radius, y: Math.sin(angle) * radius };
|
|
80
|
+
});
|
|
81
|
+
return fitPointsToFrame(unit, width, height);
|
|
82
|
+
}
|
|
83
|
+
/** A closed straight-edged network through the given points, one region. */
|
|
84
|
+
export function closedPolygonVectorNetwork(points, idPrefix = "shape") {
|
|
85
|
+
const vertices = points.map((point, index) => ({
|
|
86
|
+
id: vectorVertexId(`${idPrefix}-v${index}`),
|
|
87
|
+
x: point.x,
|
|
88
|
+
y: point.y,
|
|
89
|
+
}));
|
|
90
|
+
const segments = vertices.map((vertex, index) => ({
|
|
91
|
+
id: vectorSegmentId(`${idPrefix}-s${index}`),
|
|
92
|
+
kind: "line",
|
|
93
|
+
start: vertex.id,
|
|
94
|
+
end: vertices[(index + 1) % vertices.length].id,
|
|
95
|
+
}));
|
|
96
|
+
return {
|
|
97
|
+
vertices,
|
|
98
|
+
segments,
|
|
99
|
+
regions: [{
|
|
100
|
+
id: vectorRegionId(`${idPrefix}-region`),
|
|
101
|
+
windingRule: "nonzero",
|
|
102
|
+
loops: [{
|
|
103
|
+
segments: segments.map((segment) => ({ segmentId: segment.id, direction: "forward" })),
|
|
104
|
+
}],
|
|
105
|
+
}],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export function validateEllipseArc(arc) {
|
|
109
|
+
if (!Number.isFinite(arc.startingAngle) || !Number.isFinite(arc.endingAngle)) {
|
|
110
|
+
return "Arc angles must be finite";
|
|
111
|
+
}
|
|
112
|
+
if (Math.abs(arc.endingAngle - arc.startingAngle) > 360) {
|
|
113
|
+
return "An arc sweeps at most one full turn";
|
|
114
|
+
}
|
|
115
|
+
if (!Number.isFinite(arc.innerRadius) || arc.innerRadius < 0 || arc.innerRadius >= 1) {
|
|
116
|
+
return "An arc inner radius must be from 0 to below 1";
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The sweep in degrees, positive clockwise; at most one full turn:
|
|
122
|
+
* $\text{sweep} = \text{endingAngle} - \text{startingAngle}$.
|
|
123
|
+
*/
|
|
124
|
+
export function ellipseArcSweep(arc) {
|
|
125
|
+
return arc.endingAngle - arc.startingAngle;
|
|
126
|
+
}
|
|
127
|
+
/** True when the arc draws the plain whole ellipse. */
|
|
128
|
+
export function isWholeEllipseArc(arc) {
|
|
129
|
+
return arc === undefined ||
|
|
130
|
+
(arc.innerRadius === 0 && Math.abs(ellipseArcSweep(arc)) >= 360);
|
|
131
|
+
}
|
|
132
|
+
const FULL_TURN_EPSILON = 1e-9;
|
|
133
|
+
/**
|
|
134
|
+
* Cosine and sine of an angle in degrees, exact at multiples of 90 degrees so
|
|
135
|
+
* axis points (and every plain ellipse) carry no rounding error.
|
|
136
|
+
*/
|
|
137
|
+
function unitCircle(degrees) {
|
|
138
|
+
const quarter = degrees / 90;
|
|
139
|
+
if (Number.isInteger(quarter)) {
|
|
140
|
+
const index = ((quarter % 4) + 4) % 4;
|
|
141
|
+
return [
|
|
142
|
+
{ x: 1, y: 0 },
|
|
143
|
+
{ x: 0, y: 1 },
|
|
144
|
+
{ x: -1, y: 0 },
|
|
145
|
+
{ x: 0, y: -1 },
|
|
146
|
+
][index];
|
|
147
|
+
}
|
|
148
|
+
const radians = degrees * Math.PI / 180;
|
|
149
|
+
return { x: Math.cos(radians), y: Math.sin(radians) };
|
|
150
|
+
}
|
|
151
|
+
function addVertex(builder, prefix, point) {
|
|
152
|
+
const vertex = {
|
|
153
|
+
id: vectorVertexId(`${prefix}-v${builder.vertices.length}`),
|
|
154
|
+
x: point.x,
|
|
155
|
+
y: point.y,
|
|
156
|
+
};
|
|
157
|
+
builder.vertices.push(vertex);
|
|
158
|
+
return vertex;
|
|
159
|
+
}
|
|
160
|
+
function addLine(builder, prefix, start, end) {
|
|
161
|
+
const segment = {
|
|
162
|
+
id: vectorSegmentId(`${prefix}-s${builder.segments.length}`),
|
|
163
|
+
kind: "line",
|
|
164
|
+
start: start.id,
|
|
165
|
+
end: end.id,
|
|
166
|
+
};
|
|
167
|
+
builder.segments.push(segment);
|
|
168
|
+
return segment;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Appends elliptical-arc segments that follow the ellipse from `fromDegrees`
|
|
172
|
+
* through `sweepDegrees`, split into pieces of at most 90 degrees so no piece
|
|
173
|
+
* needs the large-arc flag. Returns the segments in path order and the final
|
|
174
|
+
* vertex. A zero radius draws straight lines instead.
|
|
175
|
+
*/
|
|
176
|
+
function addEllipticalArc(builder, prefix, center, radiusX, radiusY, from, fromDegrees, sweepDegrees, closeAt) {
|
|
177
|
+
const pieces = Math.max(1, Math.ceil(Math.abs(sweepDegrees) / 90 - 1e-9));
|
|
178
|
+
const segments = [];
|
|
179
|
+
let cursor = from;
|
|
180
|
+
for (let piece = 1; piece <= pieces; piece += 1) {
|
|
181
|
+
const last = piece === pieces;
|
|
182
|
+
const unit = unitCircle(fromDegrees + sweepDegrees * piece / pieces);
|
|
183
|
+
const end = last && closeAt !== undefined
|
|
184
|
+
? closeAt
|
|
185
|
+
: addVertex(builder, prefix, {
|
|
186
|
+
x: center.x + radiusX * unit.x,
|
|
187
|
+
y: center.y + radiusY * unit.y,
|
|
188
|
+
});
|
|
189
|
+
const segment = radiusX === 0 || radiusY === 0
|
|
190
|
+
? {
|
|
191
|
+
id: vectorSegmentId(`${prefix}-s${builder.segments.length}`),
|
|
192
|
+
kind: "line",
|
|
193
|
+
start: cursor.id,
|
|
194
|
+
end: end.id,
|
|
195
|
+
}
|
|
196
|
+
: {
|
|
197
|
+
id: vectorSegmentId(`${prefix}-s${builder.segments.length}`),
|
|
198
|
+
kind: "elliptical-arc",
|
|
199
|
+
start: cursor.id,
|
|
200
|
+
end: end.id,
|
|
201
|
+
radiusX,
|
|
202
|
+
radiusY,
|
|
203
|
+
xAxisRotation: 0,
|
|
204
|
+
largeArc: false,
|
|
205
|
+
sweep: sweepDegrees > 0,
|
|
206
|
+
};
|
|
207
|
+
builder.segments.push(segment);
|
|
208
|
+
segments.push(segment);
|
|
209
|
+
cursor = end;
|
|
210
|
+
}
|
|
211
|
+
return { segments, end: cursor };
|
|
212
|
+
}
|
|
213
|
+
function forwardLoop(segments) {
|
|
214
|
+
return {
|
|
215
|
+
segments: segments.map((segment) => ({ segmentId: segment.id, direction: "forward" })),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The network for an ellipse filling a `width` by `height` frame, cut by an
|
|
220
|
+
* optional arc: a whole ellipse, a ring (whole sweep with an inner radius), a
|
|
221
|
+
* pie (partial sweep without one), or a ring sector. A zero sweep draws
|
|
222
|
+
* nothing and returns an empty network. An angle $\phi$ in degrees (0 points
|
|
223
|
+
* right, positive turns clockwise because y points down) lands at
|
|
224
|
+
*
|
|
225
|
+
* $$
|
|
226
|
+
* \left(\frac{w}{2} + \frac{w}{2}\,t\cos\phi,\ \frac{h}{2} + \frac{h}{2}\,t\sin\phi\right)
|
|
227
|
+
* $$
|
|
228
|
+
*
|
|
229
|
+
* where $t = 1$ on the outer edge and $t$ = `innerRadius` on the inner edge.
|
|
230
|
+
*/
|
|
231
|
+
export function ellipseVectorNetwork(width, height, arc, idPrefix = "shape") {
|
|
232
|
+
if (arc !== undefined) {
|
|
233
|
+
const problem = validateEllipseArc(arc);
|
|
234
|
+
if (problem !== null)
|
|
235
|
+
throw new RangeError(problem);
|
|
236
|
+
}
|
|
237
|
+
const center = { x: width / 2, y: height / 2 };
|
|
238
|
+
const radiusX = width / 2;
|
|
239
|
+
const radiusY = height / 2;
|
|
240
|
+
const builder = { vertices: [], segments: [] };
|
|
241
|
+
const regionId = vectorRegionId(`${idPrefix}-region`);
|
|
242
|
+
const start = arc?.startingAngle ?? 0;
|
|
243
|
+
const sweep = arc === undefined ? 360 : ellipseArcSweep(arc);
|
|
244
|
+
const inner = arc?.innerRadius ?? 0;
|
|
245
|
+
if (Math.abs(sweep) < FULL_TURN_EPSILON) {
|
|
246
|
+
return { vertices: [], segments: [], regions: [] };
|
|
247
|
+
}
|
|
248
|
+
const pointAt = (degrees, scale) => {
|
|
249
|
+
const unit = unitCircle(degrees);
|
|
250
|
+
return {
|
|
251
|
+
x: center.x + radiusX * scale * unit.x,
|
|
252
|
+
y: center.y + radiusY * scale * unit.y,
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
const whole = Math.abs(sweep) >= 360 - FULL_TURN_EPSILON;
|
|
256
|
+
if (whole) {
|
|
257
|
+
// Whole turns keep the historical four quarter arcs starting at 0 degrees
|
|
258
|
+
// when there is no arc, so existing ellipses compile to the same network.
|
|
259
|
+
const outerStart = addVertex(builder, idPrefix, pointAt(start, 1));
|
|
260
|
+
const outer = addEllipticalArc(builder, idPrefix, center, radiusX, radiusY, outerStart, start, sweep, outerStart);
|
|
261
|
+
const loops = [forwardLoop(outer.segments)];
|
|
262
|
+
if (inner > 0) {
|
|
263
|
+
const innerStart = addVertex(builder, idPrefix, pointAt(start, inner));
|
|
264
|
+
const innerArc = addEllipticalArc(builder, idPrefix, center, radiusX * inner, radiusY * inner, innerStart, start, sweep, innerStart);
|
|
265
|
+
loops.push(forwardLoop(innerArc.segments));
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
vertices: builder.vertices,
|
|
269
|
+
segments: builder.segments,
|
|
270
|
+
regions: [{
|
|
271
|
+
id: regionId,
|
|
272
|
+
windingRule: inner > 0 ? "evenodd" : "nonzero",
|
|
273
|
+
loops,
|
|
274
|
+
}],
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const outerStart = addVertex(builder, idPrefix, pointAt(start, 1));
|
|
278
|
+
const outer = addEllipticalArc(builder, idPrefix, center, radiusX, radiusY, outerStart, start, sweep);
|
|
279
|
+
if (inner === 0) {
|
|
280
|
+
const middle = addVertex(builder, idPrefix, center);
|
|
281
|
+
const toCenter = addLine(builder, idPrefix, outer.end, middle);
|
|
282
|
+
const back = addLine(builder, idPrefix, middle, outerStart);
|
|
283
|
+
return {
|
|
284
|
+
vertices: builder.vertices,
|
|
285
|
+
segments: builder.segments,
|
|
286
|
+
regions: [{
|
|
287
|
+
id: regionId,
|
|
288
|
+
windingRule: "nonzero",
|
|
289
|
+
loops: [forwardLoop([...outer.segments, toCenter, back])],
|
|
290
|
+
}],
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const innerEnd = addVertex(builder, idPrefix, pointAt(start + sweep, inner));
|
|
294
|
+
const across = addLine(builder, idPrefix, outer.end, innerEnd);
|
|
295
|
+
const innerStart = pointAt(start, inner);
|
|
296
|
+
const innerStartVertex = addVertex(builder, idPrefix, innerStart);
|
|
297
|
+
const innerArc = addEllipticalArc(builder, idPrefix, center, radiusX * inner, radiusY * inner, innerEnd, start + sweep, -sweep, innerStartVertex);
|
|
298
|
+
const back = addLine(builder, idPrefix, innerStartVertex, outerStart);
|
|
299
|
+
return {
|
|
300
|
+
vertices: builder.vertices,
|
|
301
|
+
segments: builder.segments,
|
|
302
|
+
regions: [{
|
|
303
|
+
id: regionId,
|
|
304
|
+
windingRule: "nonzero",
|
|
305
|
+
loops: [forwardLoop([...outer.segments, across, ...innerArc.segments, back])],
|
|
306
|
+
}],
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The start and end points of a line in its parent's coordinates. With frame
|
|
311
|
+
* center $(c_x, c_y)$, width $w$, rotation $\theta$ (degrees converted to
|
|
312
|
+
* radians) and $s = -1$ when `flipX` is set, else $s = 1$:
|
|
313
|
+
*
|
|
314
|
+
* $$
|
|
315
|
+
* \text{start}, \text{end} = (c_x, c_y) \mp \frac{s w}{2}(\cos\theta, \sin\theta)
|
|
316
|
+
* $$
|
|
317
|
+
*/
|
|
318
|
+
export function lineEndpoints(line) {
|
|
319
|
+
const { frame } = line;
|
|
320
|
+
const radians = line.rotation * Math.PI / 180;
|
|
321
|
+
// flipX mirrors the line about its center, which swaps the two ends; flipY
|
|
322
|
+
// mirrors across the line itself, which leaves a zero-height line unchanged.
|
|
323
|
+
const direction = line.flipX === true ? -1 : 1;
|
|
324
|
+
const halfX = Math.cos(radians) * frame.width / 2 * direction;
|
|
325
|
+
const halfY = Math.sin(radians) * frame.width / 2 * direction;
|
|
326
|
+
const centerX = frame.x + frame.width / 2;
|
|
327
|
+
const centerY = frame.y + frame.height / 2;
|
|
328
|
+
return {
|
|
329
|
+
start: { x: centerX - halfX, y: centerY - halfY },
|
|
330
|
+
end: { x: centerX + halfX, y: centerY + halfY },
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* The zero-height frame and rotation of a line between two parent-space
|
|
335
|
+
* points. The rotation is in degrees within (-180, 180].
|
|
336
|
+
*/
|
|
337
|
+
export function lineFrameFromEndpoints(start, end) {
|
|
338
|
+
const dx = end.x - start.x;
|
|
339
|
+
const dy = end.y - start.y;
|
|
340
|
+
const length = Math.hypot(dx, dy);
|
|
341
|
+
const rotation = length === 0 ? 0 : Math.atan2(dy, dx) * 180 / Math.PI;
|
|
342
|
+
const centerX = (start.x + end.x) / 2;
|
|
343
|
+
const centerY = (start.y + end.y) / 2;
|
|
344
|
+
return {
|
|
345
|
+
frame: { x: centerX - length / 2, y: centerY, width: length, height: 0 },
|
|
346
|
+
rotation: rotation === -180 ? 180 : rotation,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Moves `point` so the segment from `anchor` keeps its length but turns to
|
|
351
|
+
* the nearest multiple of 45 degrees, as Shift does while drawing a line.
|
|
352
|
+
*/
|
|
353
|
+
export function constrainLineEndpoint(anchor, point) {
|
|
354
|
+
const dx = point.x - anchor.x;
|
|
355
|
+
const dy = point.y - anchor.y;
|
|
356
|
+
const length = Math.hypot(dx, dy);
|
|
357
|
+
if (length === 0)
|
|
358
|
+
return point;
|
|
359
|
+
const step = Math.PI / 4;
|
|
360
|
+
const angle = Math.round(Math.atan2(dy, dx) / step) * step;
|
|
361
|
+
const x = anchor.x + Math.cos(angle) * length;
|
|
362
|
+
const y = anchor.y + Math.sin(angle) * length;
|
|
363
|
+
// Snap exact axes so a horizontal or vertical line has no rounding drift.
|
|
364
|
+
return {
|
|
365
|
+
x: Math.abs(x - anchor.x) < 1e-9 ? anchor.x : x,
|
|
366
|
+
y: Math.abs(y - anchor.y) < 1e-9 ? anchor.y : y,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steps two tables read alongside each other may be apart, such as a
|
|
3
|
+
* laid-out view and its document (see the cost rule above).
|
|
4
|
+
*/
|
|
5
|
+
export declare const MAX_KIN_STEPS = 64;
|
|
6
|
+
/**
|
|
7
|
+
* Counts of the work the tables do, for tests that check what an edit costs.
|
|
8
|
+
* `wholeCopies`: tables copied entry by entry to start a family.
|
|
9
|
+
* `entriesWritten`: entries a draft wrote. `entriesMoved`: entries written
|
|
10
|
+
* into a family's plain object to make another table the head.
|
|
11
|
+
*/
|
|
12
|
+
export declare const sharedNodeTableStats: {
|
|
13
|
+
wholeCopies: number;
|
|
14
|
+
entriesWritten: number;
|
|
15
|
+
entriesMoved: number;
|
|
16
|
+
};
|
|
17
|
+
/** Starts calling `listed` with the entries of every pass over a whole shared table. Throws when a watch is on. */
|
|
18
|
+
export declare function watchSharedTableListings(listed: (entries: number) => void): void;
|
|
19
|
+
/** Ends `watchSharedTableListings`, taking its trap off every head that has it. */
|
|
20
|
+
export declare function unwatchSharedTableListings(): void;
|
|
21
|
+
/** Reports a pass over `entries` entries of a whole table to `watchSharedTableListings`. */
|
|
22
|
+
export declare function noteListing(entries: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* The steps between two shared tables of one family, or `limit + 1` when
|
|
25
|
+
* they are more than `limit` steps apart or not in one family. Costs at most
|
|
26
|
+
* `limit` steps.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sharedTableDistance(first: object, second: object, limit: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* A table to write into that reads as `table` until it is written: what
|
|
31
|
+
* `copyTable(table)` gives. When `table` is a shared table, the draft shares
|
|
32
|
+
* its entries and costs as much as its writes; a draft of it not sealed yet
|
|
33
|
+
* is sealed first, and is then closed to writes. Any other table is copied
|
|
34
|
+
* once, entry by entry, to start a new family (`sharedNodeTableStats.wholeCopies`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function sharedTableDraft<Value>(table: Readonly<Record<string, Value>>): Record<string, Value>;
|
|
37
|
+
/**
|
|
38
|
+
* A table to write into that reads as `table`, starting a new family with a
|
|
39
|
+
* copy of every entry (`sharedNodeTableStats.wholeCopies`): for an edit that
|
|
40
|
+
* removes entries, which a draft cannot. Entries can be removed from it until
|
|
41
|
+
* it is sealed. A draft of `table` not sealed yet is sealed first.
|
|
42
|
+
*/
|
|
43
|
+
export declare function sharedTableCopy<Value>(table: Readonly<Record<string, Value>>): Record<string, Value>;
|
|
44
|
+
/** Closes `table`, a draft from `sharedTableDraft` or a view of one, to writes. Returns it. */
|
|
45
|
+
export declare function sealSharedTable<Value>(table: Record<string, Value>): Readonly<Record<string, Value>>;
|
|
46
|
+
/** Whether `table` is a table `sharedTableDraft` made, or a view of one. */
|
|
47
|
+
export declare function isSharedNodeTable(table: object): boolean;
|
|
48
|
+
/** Whether `table` is a shared table that `sealSharedTable` has closed. */
|
|
49
|
+
export declare function isSealedSharedTable(table: object): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Makes `view`, a Proxy over `table` (a table `sharedTableDraft` made), stand
|
|
52
|
+
* for `table`: sealing it seals `table`, and a draft of it shares its entries.
|
|
53
|
+
*/
|
|
54
|
+
export declare function shareTableIdentity(view: object, table: object): void;
|
|
55
|
+
/**
|
|
56
|
+
* Makes the frozen plain table `table` stand for a sealed shared table with
|
|
57
|
+
* the same entries, copied now, so that the first draft of it shares its
|
|
58
|
+
* entries instead of copying them all (`sharedTableDraft`). `table` stays a
|
|
59
|
+
* plain frozen object, read as before. For a document opened in a store:
|
|
60
|
+
* the copy is made when it opens, not on its first edit. Does nothing for a
|
|
61
|
+
* shared table or a table that is not frozen.
|
|
62
|
+
*/
|
|
63
|
+
export declare function shareFrozenTable(table: Readonly<Record<string, unknown>>): void;
|
|
64
|
+
/**
|
|
65
|
+
* The entries in which two tables of one family may differ, each key with
|
|
66
|
+
* its entry in `previous` and in `current` (undefined where a table has
|
|
67
|
+
* none). The keys are every key written on the way from one table to the
|
|
68
|
+
* other: they hold every key whose entries differ, and may hold keys whose
|
|
69
|
+
* entries are the same again. Undefined when `previous` and `current` are not
|
|
70
|
+
* shared tables of one family.
|
|
71
|
+
*
|
|
72
|
+
* Costs the steps from each table to the head, the steps between the two
|
|
73
|
+
* tables and twice the entries written on the way, not the size of the
|
|
74
|
+
* tables: `previous` is made the head to read its entries, then `current`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function sharedTableDifferences<Value>(previous: Readonly<Record<string, Value>>, current: Readonly<Record<string, Value>>): Map<string, readonly [Value | undefined, Value | undefined]> | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* A plain frozen copy of `table` when it is a shared table, for
|
|
79
|
+
* `structuredClone`, `postMessage` and other code that copies plain objects
|
|
80
|
+
* only; `table` itself otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export declare function plainNodeTable<Value>(table: Readonly<Record<string, Value>>): Readonly<Record<string, Value>>;
|
|
83
|
+
/**
|
|
84
|
+
* The keys of `table`, as `Object.keys` lists them. For a shared table they
|
|
85
|
+
* are read from its family's plain object, at the cost of a plain table, not
|
|
86
|
+
* one entry at a time through the Proxy, which costs about three times as
|
|
87
|
+
* much.
|
|
88
|
+
*/
|
|
89
|
+
export declare function tableKeys(table: object): string[];
|
|
90
|
+
/** The values of `table`, as `Object.values` lists them (see `tableKeys`). */
|
|
91
|
+
export declare function tableValues<Value>(table: {
|
|
92
|
+
readonly [key: string]: Value;
|
|
93
|
+
}): Value[];
|
|
94
|
+
/** The entries of `table`, as `Object.entries` lists them (see `tableKeys`). */
|
|
95
|
+
export declare function tableEntries<Value>(table: {
|
|
96
|
+
readonly [key: string]: Value;
|
|
97
|
+
}): [string, Value][];
|