@pairdraw/scene-graph 0.0.0-stage → 0.16.1
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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/agent-notes/index.d.ts +3 -0
- package/dist/agent-notes/index.js +3 -0
- package/dist/agent-notes/model.d.ts +23 -0
- package/dist/agent-notes/model.d.ts.map +1 -0
- package/dist/agent-notes/model.js +36 -0
- package/dist/agent-notes/model.js.map +1 -0
- package/dist/agent-notes/schema.d.ts +19 -0
- package/dist/agent-notes/schema.d.ts.map +1 -0
- package/dist/agent-notes/schema.js +17 -0
- package/dist/agent-notes/schema.js.map +1 -0
- package/dist/arrow-caps.d.ts +65 -0
- package/dist/arrow-caps.d.ts.map +1 -0
- package/dist/arrow-caps.js +365 -0
- package/dist/arrow-caps.js.map +1 -0
- package/dist/asset-keys.d.ts +17 -0
- package/dist/asset-keys.d.ts.map +1 -0
- package/dist/asset-keys.js +27 -0
- package/dist/asset-keys.js.map +1 -0
- package/dist/behaviours/index.d.ts +6 -0
- package/dist/behaviours/index.js +6 -0
- package/dist/behaviours/kinds.d.ts +56 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/behaviours/kinds.js +273 -0
- package/dist/behaviours/kinds.js.map +1 -0
- package/dist/behaviours/layers.d.ts +16 -0
- package/dist/behaviours/layers.d.ts.map +1 -0
- package/dist/behaviours/layers.js +42 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +45 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +149 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +114 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +71 -0
- package/dist/behaviours/schema.js.map +1 -0
- package/dist/behaviours/spec.d.ts +26 -0
- package/dist/behaviours/spec.d.ts.map +1 -0
- package/dist/behaviours/spec.js +157 -0
- package/dist/behaviours/spec.js.map +1 -0
- package/dist/bindings.js +18 -0
- package/dist/bindings.js.map +1 -0
- package/dist/browser-node/index.d.ts +3 -0
- package/dist/browser-node/index.js +3 -0
- package/dist/browser-node/model.d.ts +18 -0
- package/dist/browser-node/model.d.ts.map +1 -0
- package/dist/browser-node/model.js +31 -0
- package/dist/browser-node/model.js.map +1 -0
- package/dist/browser-node/schema.d.ts +23 -0
- package/dist/browser-node/schema.d.ts.map +1 -0
- package/dist/browser-node/schema.js +44 -0
- package/dist/browser-node/schema.js.map +1 -0
- package/dist/buffered-events.d.ts +21 -0
- package/dist/buffered-events.d.ts.map +1 -0
- package/dist/buffered-events.js +57 -0
- package/dist/buffered-events.js.map +1 -0
- package/dist/checkpoint.d.ts +28 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +246 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/clipping.d.ts +31 -0
- package/dist/clipping.d.ts.map +1 -0
- package/dist/clipping.js +125 -0
- package/dist/clipping.js.map +1 -0
- package/dist/color/contrast.d.ts +20 -0
- package/dist/color/contrast.d.ts.map +1 -0
- package/dist/color/contrast.js +69 -0
- package/dist/color/contrast.js.map +1 -0
- package/dist/color/index.d.ts +38 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +110 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/management.d.ts +32 -0
- package/dist/color/management.d.ts.map +1 -0
- package/dist/color/management.js +187 -0
- package/dist/color/management.js.map +1 -0
- package/dist/color/normalize.d.ts +6 -0
- package/dist/color/normalize.d.ts.map +1 -0
- package/dist/color/normalize.js +15 -0
- package/dist/color/normalize.js.map +1 -0
- package/dist/color/okhcl.d.ts +33 -0
- package/dist/color/okhcl.d.ts.map +1 -0
- package/dist/color/okhcl.js +146 -0
- package/dist/color/okhcl.js.map +1 -0
- package/dist/color/schema.d.ts +11 -0
- package/dist/color/schema.d.ts.map +1 -0
- package/dist/color/schema.js +13 -0
- package/dist/color/schema.js.map +1 -0
- package/dist/comments/document.d.ts +23 -0
- package/dist/comments/document.d.ts.map +1 -0
- package/dist/comments/document.js +33 -0
- package/dist/comments/document.js.map +1 -0
- package/dist/comments/index.d.ts +6 -0
- package/dist/comments/index.js +6 -0
- package/dist/comments/list.d.ts +25 -0
- package/dist/comments/list.d.ts.map +1 -0
- package/dist/comments/list.js +33 -0
- package/dist/comments/list.js.map +1 -0
- package/dist/comments/merge.d.ts +16 -0
- package/dist/comments/merge.d.ts.map +1 -0
- package/dist/comments/merge.js +58 -0
- package/dist/comments/merge.js.map +1 -0
- package/dist/comments/schema.d.ts +8 -0
- package/dist/comments/schema.d.ts.map +1 -0
- package/dist/comments/schema.js +50 -0
- package/dist/comments/schema.js.map +1 -0
- package/dist/comments/threads.d.ts +59 -0
- package/dist/comments/threads.d.ts.map +1 -0
- package/dist/comments/threads.js +132 -0
- package/dist/comments/threads.js.map +1 -0
- package/dist/components/exposure.d.ts +24 -0
- package/dist/components/exposure.d.ts.map +1 -0
- package/dist/components/exposure.js +51 -0
- package/dist/components/exposure.js.map +1 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/library-page.d.ts +11 -0
- package/dist/components/library-page.d.ts.map +1 -0
- package/dist/components/library-page.js +21 -0
- package/dist/components/library-page.js.map +1 -0
- package/dist/components/properties.d.ts +20 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +125 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +27 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js +32 -0
- package/dist/components/variants.js.map +1 -0
- package/dist/connectors/controls.d.ts +34 -0
- package/dist/connectors/controls.d.ts.map +1 -0
- package/dist/connectors/controls.js +196 -0
- package/dist/connectors/controls.js.map +1 -0
- package/dist/connectors/create.d.ts +23 -0
- package/dist/connectors/create.d.ts.map +1 -0
- package/dist/connectors/create.js +33 -0
- package/dist/connectors/create.js.map +1 -0
- package/dist/connectors/elbow.js +191 -0
- package/dist/connectors/elbow.js.map +1 -0
- package/dist/connectors/gaps.d.ts +10 -0
- package/dist/connectors/gaps.d.ts.map +1 -0
- package/dist/connectors/gaps.js +86 -0
- package/dist/connectors/gaps.js.map +1 -0
- package/dist/connectors/hit.d.ts +11 -0
- package/dist/connectors/hit.d.ts.map +1 -0
- package/dist/connectors/hit.js +53 -0
- package/dist/connectors/hit.js.map +1 -0
- package/dist/connectors/index.d.ts +11 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/label.d.ts +32 -0
- package/dist/connectors/label.d.ts.map +1 -0
- package/dist/connectors/label.js +213 -0
- package/dist/connectors/label.js.map +1 -0
- package/dist/connectors/layout.d.ts +46 -0
- package/dist/connectors/layout.d.ts.map +1 -0
- package/dist/connectors/layout.js +234 -0
- package/dist/connectors/layout.js.map +1 -0
- package/dist/connectors/pieces.d.ts +22 -0
- package/dist/connectors/pieces.d.ts.map +1 -0
- package/dist/connectors/pieces.js +159 -0
- package/dist/connectors/pieces.js.map +1 -0
- package/dist/connectors/route.d.ts +23 -0
- package/dist/connectors/route.d.ts.map +1 -0
- package/dist/connectors/route.js +107 -0
- package/dist/connectors/route.js.map +1 -0
- package/dist/connectors/sides.d.ts +23 -0
- package/dist/connectors/sides.d.ts.map +1 -0
- package/dist/connectors/sides.js +98 -0
- package/dist/connectors/sides.js.map +1 -0
- package/dist/connectors/sublayers.d.ts +76 -0
- package/dist/connectors/sublayers.d.ts.map +1 -0
- package/dist/connectors/sublayers.js +209 -0
- package/dist/connectors/sublayers.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +31 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinate.d.ts +99 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +276 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +45 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +256 -0
- package/dist/copy.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/css/grid.js +63 -0
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +6 -0
- package/dist/css/layout.d.ts +17 -0
- package/dist/css/layout.d.ts.map +1 -0
- package/dist/css/layout.js +45 -0
- package/dist/css/layout.js.map +1 -0
- package/dist/css/shadows.d.ts +10 -0
- package/dist/css/shadows.d.ts.map +1 -0
- package/dist/css/shadows.js +64 -0
- package/dist/css/shadows.js.map +1 -0
- package/dist/css/text.d.ts +22 -0
- package/dist/css/text.d.ts.map +1 -0
- package/dist/css/text.js +76 -0
- package/dist/css/text.js.map +1 -0
- package/dist/css/values.d.ts +14 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +36 -0
- package/dist/css/values.js.map +1 -0
- package/dist/events.js +18 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +19 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +33 -0
- package/dist/export-format.js.map +1 -0
- package/dist/export-scale.d.ts +14 -0
- package/dist/export-scale.d.ts.map +1 -0
- package/dist/export-scale.js +19 -0
- package/dist/export-scale.js.map +1 -0
- package/dist/fields/appearance.d.ts +9 -0
- package/dist/fields/appearance.d.ts.map +1 -0
- package/dist/fields/appearance.js +36 -0
- package/dist/fields/appearance.js.map +1 -0
- package/dist/fields/geometry.d.ts +7 -0
- package/dist/fields/geometry.d.ts.map +1 -0
- package/dist/fields/geometry.js +14 -0
- package/dist/fields/geometry.js.map +1 -0
- package/dist/fields/index.d.ts +5 -0
- package/dist/fields/index.js +5 -0
- package/dist/fields/layout.d.ts +10 -0
- package/dist/fields/layout.d.ts.map +1 -0
- package/dist/fields/layout.js +49 -0
- package/dist/fields/layout.js.map +1 -0
- package/dist/fields/text.d.ts +11 -0
- package/dist/fields/text.d.ts.map +1 -0
- package/dist/fields/text.js +63 -0
- package/dist/fields/text.js.map +1 -0
- package/dist/fig-compression.d.ts +11 -0
- package/dist/fig-compression.d.ts.map +1 -0
- package/dist/fig-compression.js +15 -0
- package/dist/fig-compression.js.map +1 -0
- package/dist/figjam/index.d.ts +3 -0
- package/dist/figjam/index.js +3 -0
- package/dist/figjam/palette.d.ts +199 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +277 -0
- package/dist/figjam/palette.js.map +1 -0
- package/dist/figjam/text.d.ts +68 -0
- package/dist/figjam/text.d.ts.map +1 -0
- package/dist/figjam/text.js +89 -0
- package/dist/figjam/text.js.map +1 -0
- package/dist/font-style.d.ts +46 -0
- package/dist/font-style.d.ts.map +1 -0
- package/dist/font-style.js +127 -0
- package/dist/font-style.js.map +1 -0
- package/dist/generated/index.d.ts +46 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +62 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/kind.d.ts +29 -0
- package/dist/generated/kind.d.ts.map +1 -0
- package/dist/generated/shape-with-text.d.ts +38 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +119 -0
- package/dist/generated/shape-with-text.js.map +1 -0
- package/dist/generated/sticky.d.ts +128 -0
- package/dist/generated/sticky.d.ts.map +1 -0
- package/dist/generated/sticky.js +234 -0
- package/dist/generated/sticky.js.map +1 -0
- package/dist/geometry.d.ts +105 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +374 -0
- package/dist/geometry.js.map +1 -0
- package/dist/gradient.d.ts +74 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/gradient.js +211 -0
- package/dist/gradient.js.map +1 -0
- package/dist/graph.d.ts +186 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +630 -0
- package/dist/graph.js.map +1 -0
- package/dist/group-bounds.d.ts +42 -0
- package/dist/group-bounds.d.ts.map +1 -0
- package/dist/group-bounds.js +146 -0
- package/dist/group-bounds.js.map +1 -0
- package/dist/guides.d.ts +19 -0
- package/dist/guides.d.ts.map +1 -0
- package/dist/guides.js +39 -0
- package/dist/guides.js.map +1 -0
- package/dist/hit-test.d.ts +49 -0
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +315 -0
- package/dist/hit-test.js.map +1 -0
- package/dist/icons/glyph.d.ts +22 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +109 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +4 -0
- package/dist/icons/model.d.ts +29 -0
- package/dist/icons/model.d.ts.map +1 -0
- package/dist/icons/model.js +51 -0
- package/dist/icons/model.js.map +1 -0
- package/dist/icons/schema.d.ts +31 -0
- package/dist/icons/schema.d.ts.map +1 -0
- package/dist/icons/schema.js +28 -0
- package/dist/icons/schema.js.map +1 -0
- package/dist/ids.d.ts +12 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +31 -0
- package/dist/ids.js.map +1 -0
- package/dist/images.d.ts +39 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +85 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/instances/assignments.js +89 -0
- package/dist/instances/assignments.js.map +1 -0
- package/dist/instances/content-size.js +60 -0
- package/dist/instances/content-size.js.map +1 -0
- package/dist/instances/copies.js +162 -0
- package/dist/instances/copies.js.map +1 -0
- package/dist/instances/cycles.d.ts +20 -0
- package/dist/instances/cycles.d.ts.map +1 -0
- package/dist/instances/cycles.js +53 -0
- package/dist/instances/cycles.js.map +1 -0
- package/dist/instances/fields.d.ts +18 -0
- package/dist/instances/fields.d.ts.map +1 -0
- package/dist/instances/fields.js +82 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +63 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +305 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/main-component.d.ts +11 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +42 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/modes.js +26 -0
- package/dist/instances/modes.js.map +1 -0
- package/dist/instances/overrides.d.ts +63 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +164 -0
- package/dist/instances/overrides.js.map +1 -0
- package/dist/instances/placement.js +30 -0
- package/dist/instances/placement.js.map +1 -0
- package/dist/instances/replacements.d.ts +19 -0
- package/dist/instances/replacements.d.ts.map +1 -0
- package/dist/instances/replacements.js +67 -0
- package/dist/instances/replacements.js.map +1 -0
- package/dist/instances/source-walk.js +31 -0
- package/dist/instances/source-walk.js.map +1 -0
- package/dist/instances/sync.js +305 -0
- package/dist/instances/sync.js.map +1 -0
- package/dist/instances/vector-geometry.js +70 -0
- package/dist/instances/vector-geometry.js.map +1 -0
- package/dist/layout/aspect-ratio.d.ts +27 -0
- package/dist/layout/aspect-ratio.d.ts.map +1 -0
- package/dist/layout/aspect-ratio.js +45 -0
- package/dist/layout/aspect-ratio.js.map +1 -0
- package/dist/layout/guides.d.ts +25 -0
- package/dist/layout/guides.d.ts.map +1 -0
- package/dist/layout/guides.js +105 -0
- package/dist/layout/guides.js.map +1 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/keywords.d.ts +26 -0
- package/dist/layout/keywords.d.ts.map +1 -0
- package/dist/layout/keywords.js +60 -0
- package/dist/layout/keywords.js.map +1 -0
- package/dist/layout/sizing.d.ts +40 -0
- package/dist/layout/sizing.d.ts.map +1 -0
- package/dist/layout/sizing.js +122 -0
- package/dist/layout/sizing.js.map +1 -0
- package/dist/layout/writes.js +55 -0
- package/dist/layout/writes.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +120 -0
- package/dist/matrix.js.map +1 -0
- package/dist/mutation-impact.d.ts +23 -0
- package/dist/mutation-impact.d.ts.map +1 -0
- package/dist/mutation-impact.js +67 -0
- package/dist/mutation-impact.js.map +1 -0
- package/dist/naming.d.ts +9 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +16 -0
- package/dist/naming.js.map +1 -0
- package/dist/node-defaults.d.ts +19 -0
- package/dist/node-defaults.d.ts.map +1 -0
- package/dist/node-defaults.js +243 -0
- package/dist/node-defaults.js.map +1 -0
- package/dist/order-keys.d.ts +39 -0
- package/dist/order-keys.d.ts.map +1 -0
- package/dist/order-keys.js +136 -0
- package/dist/order-keys.js.map +1 -0
- package/dist/paints/index.d.ts +2 -0
- package/dist/paints/index.js +2 -0
- package/dist/paints/schema.d.ts +103 -0
- package/dist/paints/schema.d.ts.map +1 -0
- package/dist/paints/schema.js +64 -0
- package/dist/paints/schema.js.map +1 -0
- package/dist/parse-path.d.ts +36 -0
- package/dist/parse-path.d.ts.map +1 -0
- package/dist/parse-path.js +200 -0
- package/dist/parse-path.js.map +1 -0
- package/dist/plugin-data/citation.d.ts +13 -0
- package/dist/plugin-data/citation.d.ts.map +1 -0
- package/dist/plugin-data/citation.js +23 -0
- package/dist/plugin-data/citation.js.map +1 -0
- package/dist/plugin-data/field.d.ts +47 -0
- package/dist/plugin-data/field.d.ts.map +1 -0
- package/dist/plugin-data/field.js +79 -0
- package/dist/plugin-data/field.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +220 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +214 -0
- package/dist/plugin-data/fields.js.map +1 -0
- package/dist/plugin-data/index.d.ts +5 -0
- package/dist/plugin-data/index.js +5 -0
- package/dist/plugin-data/schema.d.ts +18 -0
- package/dist/plugin-data/schema.d.ts.map +1 -0
- package/dist/plugin-data/schema.js +29 -0
- package/dist/plugin-data/schema.js.map +1 -0
- package/dist/polygon.d.ts +55 -0
- package/dist/polygon.d.ts.map +1 -0
- package/dist/polygon.js +220 -0
- package/dist/polygon.js.map +1 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +63 -0
- package/dist/preview.js.map +1 -0
- package/dist/primitives/index.d.ts +43 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/schema.d.ts +18 -0
- package/dist/primitives/schema.d.ts.map +1 -0
- package/dist/primitives/schema.js +19 -0
- package/dist/primitives/schema.js.map +1 -0
- package/dist/random.d.ts +7 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +25 -0
- package/dist/random.js.map +1 -0
- package/dist/resize.d.ts +41 -0
- package/dist/resize.d.ts.map +1 -0
- package/dist/resize.js +288 -0
- package/dist/resize.js.map +1 -0
- package/dist/scaling/index.d.ts +3 -0
- package/dist/scaling/index.js +3 -0
- package/dist/scaling/node.d.ts +6 -0
- package/dist/scaling/node.d.ts.map +1 -0
- package/dist/scaling/node.js +150 -0
- package/dist/scaling/node.js.map +1 -0
- package/dist/scaling/tree.d.ts +22 -0
- package/dist/scaling/tree.d.ts.map +1 -0
- package/dist/scaling/tree.js +71 -0
- package/dist/scaling/tree.js.map +1 -0
- package/dist/script/index.d.ts +2 -0
- package/dist/script/index.js +2 -0
- package/dist/script/schema.d.ts +29 -0
- package/dist/script/schema.d.ts.map +1 -0
- package/dist/script/schema.js +51 -0
- package/dist/script/schema.js.map +1 -0
- package/dist/shaders/directives.d.ts +43 -0
- package/dist/shaders/directives.d.ts.map +1 -0
- package/dist/shaders/directives.js +293 -0
- package/dist/shaders/directives.js.map +1 -0
- package/dist/shaders/index.d.ts +5 -0
- package/dist/shaders/index.js +5 -0
- package/dist/shaders/model.d.ts +58 -0
- package/dist/shaders/model.d.ts.map +1 -0
- package/dist/shaders/model.js +109 -0
- package/dist/shaders/model.js.map +1 -0
- package/dist/shaders/schema.d.ts +86 -0
- package/dist/shaders/schema.d.ts.map +1 -0
- package/dist/shaders/schema.js +65 -0
- package/dist/shaders/schema.js.map +1 -0
- package/dist/shaders/still.d.ts +18 -0
- package/dist/shaders/still.d.ts.map +1 -0
- package/dist/shaders/still.js +36 -0
- package/dist/shaders/still.js.map +1 -0
- package/dist/shape-with-text/fit.d.ts +28 -0
- package/dist/shape-with-text/fit.d.ts.map +1 -0
- package/dist/shape-with-text/fit.js +271 -0
- package/dist/shape-with-text/fit.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +20 -0
- package/dist/shape-with-text/geometry.d.ts.map +1 -0
- package/dist/shape-with-text/geometry.js +539 -0
- package/dist/shape-with-text/geometry.js.map +1 -0
- package/dist/shape-with-text/index.d.ts +4 -0
- package/dist/shape-with-text/index.js +4 -0
- package/dist/shape-with-text/kinds.d.ts +20 -0
- package/dist/shape-with-text/kinds.d.ts.map +1 -0
- package/dist/shape-with-text/kinds.js +86 -0
- package/dist/shape-with-text/kinds.js.map +1 -0
- package/dist/shared-styles.d.ts +36 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +116 -0
- package/dist/shared-styles.js.map +1 -0
- package/dist/slots/authoring.d.ts +27 -0
- package/dist/slots/authoring.d.ts.map +1 -0
- package/dist/slots/authoring.js +74 -0
- package/dist/slots/authoring.js.map +1 -0
- package/dist/slots/content.d.ts +41 -0
- package/dist/slots/content.d.ts.map +1 -0
- package/dist/slots/content.js +103 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +38 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +113 -0
- package/dist/slots/frames.js.map +1 -0
- package/dist/slots/index.d.ts +5 -0
- package/dist/slots/index.js +5 -0
- package/dist/slots/limits.d.ts +14 -0
- package/dist/slots/limits.d.ts.map +1 -0
- package/dist/slots/limits.js +28 -0
- package/dist/slots/limits.js.map +1 -0
- package/dist/snap.d.ts +61 -0
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +264 -0
- package/dist/snap.js.map +1 -0
- package/dist/source-metadata.d.ts +6 -0
- package/dist/source-metadata.d.ts.map +1 -0
- package/dist/source-metadata.js +11 -0
- package/dist/source-metadata.js.map +1 -0
- package/dist/statuses/impact.d.ts +18 -0
- package/dist/statuses/impact.d.ts.map +1 -0
- package/dist/statuses/impact.js +33 -0
- package/dist/statuses/impact.js.map +1 -0
- package/dist/statuses/index.d.ts +5 -0
- package/dist/statuses/index.js +5 -0
- package/dist/statuses/node.d.ts +22 -0
- package/dist/statuses/node.d.ts.map +1 -0
- package/dist/statuses/node.js +47 -0
- package/dist/statuses/node.js.map +1 -0
- package/dist/statuses/schema.d.ts +59 -0
- package/dist/statuses/schema.d.ts.map +1 -0
- package/dist/statuses/schema.js +27 -0
- package/dist/statuses/schema.js.map +1 -0
- package/dist/statuses/workflow.d.ts +120 -0
- package/dist/statuses/workflow.d.ts.map +1 -0
- package/dist/statuses/workflow.js +135 -0
- package/dist/statuses/workflow.js.map +1 -0
- package/dist/text/direction.d.ts +13 -0
- package/dist/text/direction.d.ts.map +1 -0
- package/dist/text/direction.js +31 -0
- package/dist/text/direction.js.map +1 -0
- package/dist/text/index.d.ts +7 -0
- package/dist/text/index.js +7 -0
- package/dist/text/lengths.d.ts +19 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +40 -0
- package/dist/text/lengths.js.map +1 -0
- package/dist/text/lists.d.ts +44 -0
- package/dist/text/lists.d.ts.map +1 -0
- package/dist/text/lists.js +100 -0
- package/dist/text/lists.js.map +1 -0
- package/dist/text/overflow.d.ts +11 -0
- package/dist/text/overflow.d.ts.map +1 -0
- package/dist/text/overflow.js +13 -0
- package/dist/text/overflow.js.map +1 -0
- package/dist/text/paragraphs.d.ts +62 -0
- package/dist/text/paragraphs.d.ts.map +1 -0
- package/dist/text/paragraphs.js +166 -0
- package/dist/text/paragraphs.js.map +1 -0
- package/dist/text/picture.d.ts +18 -0
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +41 -0
- package/dist/text/picture.js.map +1 -0
- package/dist/text/references.d.ts +21 -0
- package/dist/text/references.d.ts.map +1 -0
- package/dist/text/references.js +43 -0
- package/dist/text/references.js.map +1 -0
- package/dist/text/schema.d.ts +10 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +11 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/transfer/apply.d.ts +9 -0
- package/dist/transfer/apply.d.ts.map +1 -0
- package/dist/transfer/apply.js +65 -0
- package/dist/transfer/apply.js.map +1 -0
- package/dist/transfer/history.d.ts +8 -0
- package/dist/transfer/history.d.ts.map +1 -0
- package/dist/transfer/history.js +32 -0
- package/dist/transfer/history.js.map +1 -0
- package/dist/transfer/identity.js +12 -0
- package/dist/transfer/identity.js.map +1 -0
- package/dist/transfer/index.d.ts +7 -0
- package/dist/transfer/index.js +7 -0
- package/dist/transfer/nodes.d.ts +14 -0
- package/dist/transfer/nodes.d.ts.map +1 -0
- package/dist/transfer/nodes.js +82 -0
- package/dist/transfer/nodes.js.map +1 -0
- package/dist/transfer/plan.d.ts +29 -0
- package/dist/transfer/plan.d.ts.map +1 -0
- package/dist/transfer/plan.js +106 -0
- package/dist/transfer/plan.js.map +1 -0
- package/dist/transfer/references.js +10 -0
- package/dist/transfer/references.js.map +1 -0
- package/dist/transfer/remove.d.ts +8 -0
- package/dist/transfer/remove.d.ts.map +1 -0
- package/dist/transfer/remove.js +34 -0
- package/dist/transfer/remove.js.map +1 -0
- package/dist/transfer/validation.js +39 -0
- package/dist/transfer/validation.js.map +1 -0
- package/dist/transfer/variables.d.ts +15 -0
- package/dist/transfer/variables.d.ts.map +1 -0
- package/dist/transfer/variables.js +52 -0
- package/dist/transfer/variables.js.map +1 -0
- package/dist/types.d.ts +910 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +89 -0
- package/dist/types.js.map +1 -0
- package/dist/undo.d.ts +93 -0
- package/dist/undo.d.ts.map +1 -0
- package/dist/undo.js +236 -0
- package/dist/undo.js.map +1 -0
- package/dist/variables/bindings.d.ts +66 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +251 -0
- package/dist/variables/bindings.js.map +1 -0
- package/dist/variables/corners.d.ts +12 -0
- package/dist/variables/corners.d.ts.map +1 -0
- package/dist/variables/corners.js +38 -0
- package/dist/variables/corners.js.map +1 -0
- package/dist/variables/fields.d.ts +30 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +89 -0
- package/dist/variables/fields.js.map +1 -0
- package/dist/variables/formula/check.d.ts +14 -0
- package/dist/variables/formula/check.d.ts.map +1 -0
- package/dist/variables/formula/check.js +73 -0
- package/dist/variables/formula/check.js.map +1 -0
- package/dist/variables/formula/evaluate.d.ts +7 -0
- package/dist/variables/formula/evaluate.d.ts.map +1 -0
- package/dist/variables/formula/evaluate.js +30 -0
- package/dist/variables/formula/evaluate.js.map +1 -0
- package/dist/variables/formula/index.d.ts +21 -0
- package/dist/variables/formula/index.d.ts.map +1 -0
- package/dist/variables/formula/index.js +77 -0
- package/dist/variables/formula/index.js.map +1 -0
- package/dist/variables/formula/parse.js +141 -0
- package/dist/variables/formula/parse.js.map +1 -0
- package/dist/variables/formula/print.d.ts +25 -0
- package/dist/variables/formula/print.d.ts.map +1 -0
- package/dist/variables/formula/print.js +105 -0
- package/dist/variables/formula/print.js.map +1 -0
- package/dist/variables/formula/schema.d.ts +7 -0
- package/dist/variables/formula/schema.d.ts.map +1 -0
- package/dist/variables/formula/schema.js +62 -0
- package/dist/variables/formula/schema.js.map +1 -0
- package/dist/variables/formula/signatures.d.ts +9 -0
- package/dist/variables/formula/signatures.d.ts.map +1 -0
- package/dist/variables/formula/signatures.js +238 -0
- package/dist/variables/formula/signatures.js.map +1 -0
- package/dist/variables/formula/tokens.d.ts +26 -0
- package/dist/variables/formula/tokens.d.ts.map +1 -0
- package/dist/variables/formula/tokens.js +82 -0
- package/dist/variables/formula/tokens.js.map +1 -0
- package/dist/variables/formula/tree.d.ts +22 -0
- package/dist/variables/formula/tree.d.ts.map +1 -0
- package/dist/variables/formula/tree.js +35 -0
- package/dist/variables/formula/tree.js.map +1 -0
- package/dist/variables/index.d.ts +41 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +246 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/resolution.d.ts +39 -0
- package/dist/variables/resolution.d.ts.map +1 -0
- package/dist/variables/resolution.js +154 -0
- package/dist/variables/resolution.js.map +1 -0
- package/dist/variables/schema.d.ts +40 -0
- package/dist/variables/schema.d.ts.map +1 -0
- package/dist/variables/schema.js +32 -0
- package/dist/variables/schema.js.map +1 -0
- package/dist/variables/text.d.ts +21 -0
- package/dist/variables/text.d.ts.map +1 -0
- package/dist/variables/text.js +58 -0
- package/dist/variables/text.js.map +1 -0
- package/dist/variables/token.d.ts +18 -0
- package/dist/variables/token.d.ts.map +1 -0
- package/dist/variables/token.js +39 -0
- package/dist/variables/token.js.map +1 -0
- package/dist/variables/units.js +19 -0
- package/dist/variables/units.js.map +1 -0
- package/dist/variables/value.d.ts +12 -0
- package/dist/variables/value.d.ts.map +1 -0
- package/dist/variables/value.js +70 -0
- package/dist/variables/value.js.map +1 -0
- package/dist/variant-name.d.ts +6 -0
- package/dist/variant-name.d.ts.map +1 -0
- package/dist/variant-name.js +17 -0
- package/dist/variant-name.js.map +1 -0
- package/dist/variant-properties.d.ts +18 -0
- package/dist/variant-properties.d.ts.map +1 -0
- package/dist/variant-properties.js +74 -0
- package/dist/variant-properties.js.map +1 -0
- package/dist/vector-network.d.ts +48 -0
- package/dist/vector-network.d.ts.map +1 -0
- package/dist/vector-network.js +352 -0
- package/dist/vector-network.js.map +1 -0
- package/package.json +364 -4
- package/src/agent-notes/index.ts +2 -0
- package/src/agent-notes/model.ts +46 -0
- package/src/agent-notes/schema.ts +28 -0
- package/src/arrow-caps.ts +364 -0
- package/src/asset-keys.ts +25 -0
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/kinds.ts +185 -0
- package/src/behaviours/layers.ts +51 -0
- package/src/behaviours/model.ts +184 -0
- package/src/behaviours/schema.ts +93 -0
- package/src/behaviours/spec.ts +178 -0
- package/src/bindings.ts +20 -0
- package/src/browser-node/index.ts +2 -0
- package/src/browser-node/model.ts +35 -0
- package/src/browser-node/schema.ts +62 -0
- package/src/buffered-events.ts +64 -0
- package/src/checkpoint.ts +325 -0
- package/src/clipping.ts +112 -0
- package/src/color/contrast.ts +71 -0
- package/src/color/index.ts +89 -0
- package/src/color/management.ts +210 -0
- package/src/color/normalize.ts +7 -0
- package/src/color/okhcl.ts +201 -0
- package/src/color/schema.ts +10 -0
- package/src/comments/document.ts +51 -0
- package/src/comments/index.ts +5 -0
- package/src/comments/list.ts +52 -0
- package/src/comments/merge.ts +63 -0
- package/src/comments/schema.ts +51 -0
- package/src/comments/threads.ts +156 -0
- package/src/components/exposure.ts +61 -0
- package/src/components/index.ts +9 -0
- package/src/components/library-page.ts +17 -0
- package/src/components/properties.ts +241 -0
- package/src/components/variants.ts +53 -0
- package/src/connectors/controls.ts +229 -0
- package/src/connectors/create.ts +48 -0
- package/src/connectors/elbow.ts +235 -0
- package/src/connectors/gaps.ts +72 -0
- package/src/connectors/hit.ts +60 -0
- package/src/connectors/index.ts +28 -0
- package/src/connectors/label.ts +238 -0
- package/src/connectors/layout.ts +280 -0
- package/src/connectors/pieces.ts +144 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +204 -0
- package/src/constants.ts +13 -0
- package/src/coordinate.ts +298 -0
- package/src/copy.ts +341 -0
- package/src/css/grid.ts +70 -0
- package/src/css/index.ts +10 -0
- package/src/css/layout.ts +53 -0
- package/src/css/shadows.ts +68 -0
- package/src/css/text.ts +84 -0
- package/src/css/values.ts +42 -0
- package/src/events.ts +21 -0
- package/src/export-format.ts +33 -0
- package/src/export-scale.ts +16 -0
- package/src/fields/appearance.ts +35 -0
- package/src/fields/geometry.ts +11 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/layout.ts +48 -0
- package/src/fields/text.ts +64 -0
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +308 -0
- package/src/figjam/text.ts +78 -0
- package/src/font-style.ts +121 -0
- package/src/generated/index.ts +81 -0
- package/src/generated/kind.ts +26 -0
- package/src/generated/shape-with-text.ts +132 -0
- package/src/generated/sticky.ts +214 -0
- package/src/geometry.ts +490 -0
- package/src/gradient.ts +275 -0
- package/src/graph.ts +842 -0
- package/src/group-bounds.ts +178 -0
- package/src/guides.ts +47 -0
- package/src/hit-test.ts +501 -0
- package/src/icons/glyph.ts +128 -0
- package/src/icons/index.ts +3 -0
- package/src/icons/model.ts +63 -0
- package/src/icons/schema.ts +34 -0
- package/src/ids.ts +34 -0
- package/src/images.ts +89 -0
- package/src/index.ts +4 -0
- package/src/instances/assignments.ts +116 -0
- package/src/instances/content-size.ts +84 -0
- package/src/instances/copies.ts +244 -0
- package/src/instances/cycles.ts +73 -0
- package/src/instances/fields.ts +90 -0
- package/src/instances/index.ts +467 -0
- package/src/instances/main-component.ts +61 -0
- package/src/instances/modes.ts +39 -0
- package/src/instances/overrides.ts +240 -0
- package/src/instances/placement.ts +29 -0
- package/src/instances/replacements.ts +80 -0
- package/src/instances/source-walk.ts +35 -0
- package/src/instances/sync.ts +556 -0
- package/src/instances/vector-geometry.ts +81 -0
- package/src/layout/aspect-ratio.ts +51 -0
- package/src/layout/guides.ts +132 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/keywords.ts +74 -0
- package/src/layout/sizing.ts +196 -0
- package/src/layout/writes.ts +59 -0
- package/src/matrix.ts +116 -0
- package/src/mutation-impact.ts +85 -0
- package/src/naming.ts +11 -0
- package/src/node-defaults.ts +260 -0
- package/src/order-keys.ts +162 -0
- package/src/paints/index.ts +1 -0
- package/src/paints/schema.ts +72 -0
- package/src/parse-path.ts +244 -0
- package/src/plugin-data/citation.ts +27 -0
- package/src/plugin-data/field.ts +140 -0
- package/src/plugin-data/fields.ts +306 -0
- package/src/plugin-data/index.ts +3 -0
- package/src/plugin-data/schema.ts +35 -0
- package/src/polygon.ts +228 -0
- package/src/preview.ts +80 -0
- package/src/primitives/index.ts +44 -0
- package/src/primitives/schema.ts +14 -0
- package/src/random.ts +28 -0
- package/src/resize.ts +415 -0
- package/src/scaling/index.ts +9 -0
- package/src/scaling/node.ts +168 -0
- package/src/scaling/tree.ts +85 -0
- package/src/script/index.ts +1 -0
- package/src/script/schema.ts +65 -0
- package/src/shaders/directives.ts +366 -0
- package/src/shaders/index.ts +4 -0
- package/src/shaders/model.ts +147 -0
- package/src/shaders/schema.ts +84 -0
- package/src/shaders/still.ts +41 -0
- package/src/shape-with-text/fit.ts +154 -0
- package/src/shape-with-text/geometry.ts +496 -0
- package/src/shape-with-text/index.ts +10 -0
- package/src/shape-with-text/kinds.ts +86 -0
- package/src/shared-styles.ts +137 -0
- package/src/slots/authoring.ts +101 -0
- package/src/slots/content.ts +127 -0
- package/src/slots/frames.ts +160 -0
- package/src/slots/index.ts +4 -0
- package/src/slots/limits.ts +49 -0
- package/src/snap.ts +349 -0
- package/src/source-metadata.ts +8 -0
- package/src/statuses/impact.ts +38 -0
- package/src/statuses/index.ts +4 -0
- package/src/statuses/node.ts +63 -0
- package/src/statuses/schema.ts +39 -0
- package/src/statuses/workflow.ts +121 -0
- package/src/text/direction.ts +55 -0
- package/src/text/index.ts +6 -0
- package/src/text/lengths.ts +34 -0
- package/src/text/lists.ts +138 -0
- package/src/text/overflow.ts +12 -0
- package/src/text/paragraphs.ts +241 -0
- package/src/text/picture.ts +57 -0
- package/src/text/references.ts +50 -0
- package/src/text/schema.ts +7 -0
- package/src/transfer/apply.ts +84 -0
- package/src/transfer/history.ts +49 -0
- package/src/transfer/identity.ts +16 -0
- package/src/transfer/index.ts +6 -0
- package/src/transfer/nodes.ts +128 -0
- package/src/transfer/plan.ts +130 -0
- package/src/transfer/references.ts +9 -0
- package/src/transfer/remove.ts +39 -0
- package/src/transfer/validation.ts +59 -0
- package/src/transfer/variables.ts +83 -0
- package/src/types.ts +1205 -0
- package/src/undo.ts +285 -0
- package/src/variables/bindings.ts +310 -0
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +109 -0
- package/src/variables/formula/check.ts +99 -0
- package/src/variables/formula/evaluate.ts +33 -0
- package/src/variables/formula/index.ts +129 -0
- package/src/variables/formula/parse.ts +160 -0
- package/src/variables/formula/print.ts +167 -0
- package/src/variables/formula/schema.ts +77 -0
- package/src/variables/formula/signatures.ts +266 -0
- package/src/variables/formula/tokens.ts +114 -0
- package/src/variables/formula/tree.ts +53 -0
- package/src/variables/index.ts +400 -0
- package/src/variables/resolution.ts +293 -0
- package/src/variables/schema.ts +31 -0
- package/src/variables/text.ts +61 -0
- package/src/variables/token.ts +40 -0
- package/src/variables/units.ts +15 -0
- package/src/variables/value.ts +92 -0
- package/src/variant-name.ts +15 -0
- package/src/variant-properties.ts +98 -0
- package/src/vector-network.ts +489 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { isEqual } from 'es-toolkit'
|
|
2
|
+
|
|
3
|
+
import type { SceneGraph } from './graph'
|
|
4
|
+
import type { InstanceOverrideState } from './instances/overrides'
|
|
5
|
+
import type { SceneNode } from './types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The document state outside its layers, copied: variables, collections, modes, the instance
|
|
9
|
+
* index, libraries, images, and document metadata, which a rollback restores in place.
|
|
10
|
+
*/
|
|
11
|
+
function captureTables(graph: SceneGraph) {
|
|
12
|
+
const variableRefs = new Map(graph.variables)
|
|
13
|
+
const collectionRefs = new Map(graph.variableCollections)
|
|
14
|
+
const snapshot = structuredClone({
|
|
15
|
+
variables: graph.variables,
|
|
16
|
+
variableCollections: graph.variableCollections,
|
|
17
|
+
activeMode: graph.activeMode,
|
|
18
|
+
instanceIndex: graph.instanceIndex,
|
|
19
|
+
enabledLibraries: graph.enabledLibraries,
|
|
20
|
+
rootId: graph.rootId,
|
|
21
|
+
figKiwiVersion: graph.figKiwiVersion,
|
|
22
|
+
figSchemaDeflated: graph.figSchemaDeflated,
|
|
23
|
+
documentColorSpace: graph.documentColorSpace
|
|
24
|
+
})
|
|
25
|
+
// Atomic property tools cannot edit assets. Retain existing buffers, not copies of every bitmap.
|
|
26
|
+
const images = new Map(graph.images)
|
|
27
|
+
|
|
28
|
+
function assertVariablesKept() {
|
|
29
|
+
for (const [id, before] of snapshot.variables) {
|
|
30
|
+
const after = graph.variables.get(id)
|
|
31
|
+
if (
|
|
32
|
+
!after ||
|
|
33
|
+
after !== variableRefs.get(id) ||
|
|
34
|
+
before.id !== after.id ||
|
|
35
|
+
before.collectionId !== after.collectionId ||
|
|
36
|
+
before.type !== after.type
|
|
37
|
+
)
|
|
38
|
+
throw new Error('Atomic tools must not change variable identity')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function assertDocumentUnchanged() {
|
|
43
|
+
if (
|
|
44
|
+
!isEqual(snapshot.variableCollections, graph.variableCollections) ||
|
|
45
|
+
!isEqual(snapshot.activeMode, graph.activeMode) ||
|
|
46
|
+
!isEqual(snapshot.instanceIndex, graph.instanceIndex) ||
|
|
47
|
+
!isEqual(snapshot.enabledLibraries, graph.enabledLibraries) ||
|
|
48
|
+
images.size !== graph.images.size ||
|
|
49
|
+
[...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||
|
|
50
|
+
graph.rootId !== snapshot.rootId ||
|
|
51
|
+
graph.documentColorSpace !== snapshot.documentColorSpace ||
|
|
52
|
+
graph.figKiwiVersion !== snapshot.figKiwiVersion ||
|
|
53
|
+
!isEqual(graph.figSchemaDeflated, snapshot.figSchemaDeflated)
|
|
54
|
+
) {
|
|
55
|
+
throw new Error('Atomic tools must not change collections, assets or document metadata')
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function restore() {
|
|
60
|
+
restoreObjects(graph.variables, snapshot.variables, variableRefs)
|
|
61
|
+
restoreObjects(graph.variableCollections, snapshot.variableCollections, collectionRefs)
|
|
62
|
+
restoreMap(graph.activeMode, structuredClone(snapshot.activeMode))
|
|
63
|
+
restoreMap(graph.instanceIndex, structuredClone(snapshot.instanceIndex))
|
|
64
|
+
restoreMap(graph.enabledLibraries, structuredClone(snapshot.enabledLibraries))
|
|
65
|
+
restoreMap(graph.images, images)
|
|
66
|
+
graph.rootId = snapshot.rootId
|
|
67
|
+
graph.figKiwiVersion = snapshot.figKiwiVersion
|
|
68
|
+
graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated)
|
|
69
|
+
graph.documentColorSpace = snapshot.documentColorSpace
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
variables: snapshot.variables,
|
|
74
|
+
variableCount: snapshot.variables.size,
|
|
75
|
+
assertVariablesKept,
|
|
76
|
+
assertDocumentUnchanged,
|
|
77
|
+
restore
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function assertSameNodes(graph: SceneGraph, refs: Map<string, SceneNode>, variableCount: number) {
|
|
82
|
+
if (refs.size !== graph.nodes.size || variableCount !== graph.variables.size)
|
|
83
|
+
throw new Error('Atomic tools must not create or remove nodes or variables')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function assertHierarchyKept(
|
|
87
|
+
graph: SceneGraph,
|
|
88
|
+
refs: Map<string, SceneNode>,
|
|
89
|
+
before: SceneNode,
|
|
90
|
+
id: string
|
|
91
|
+
) {
|
|
92
|
+
const after = graph.nodes.get(id)
|
|
93
|
+
if (
|
|
94
|
+
!after ||
|
|
95
|
+
after !== refs.get(id) ||
|
|
96
|
+
before.id !== after.id ||
|
|
97
|
+
before.type !== after.type ||
|
|
98
|
+
before.parentId !== after.parentId ||
|
|
99
|
+
before.componentId !== after.componentId ||
|
|
100
|
+
!isEqual(before.childIds, after.childIds)
|
|
101
|
+
) {
|
|
102
|
+
throw new Error('Atomic tools must not change node hierarchy or identity')
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Lets consumers know the restored hierarchy and indexes, once all of it is in place: removed
|
|
108
|
+
* layers first, then the layers put back, then `changed` ones.
|
|
109
|
+
*/
|
|
110
|
+
function announceRestore(
|
|
111
|
+
graph: SceneGraph,
|
|
112
|
+
failedNodes: Map<string, SceneNode>,
|
|
113
|
+
changed: Iterable<string>
|
|
114
|
+
) {
|
|
115
|
+
for (const [id, node] of failedNodes) {
|
|
116
|
+
if (!graph.nodes.has(id)) graph.emitter.emit('node:deleted', id, node.parentId)
|
|
117
|
+
}
|
|
118
|
+
for (const id of changed) {
|
|
119
|
+
const node = graph.nodes.get(id)
|
|
120
|
+
if (node && failedNodes.has(id)) graph.emitter.emit('node:updated', id, node)
|
|
121
|
+
}
|
|
122
|
+
for (const node of graph.nodes.values()) {
|
|
123
|
+
if (!failedNodes.has(node.id)) graph.emitter.emit('node:created', node)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Capture rollback state without changing graph or surviving object identities. */
|
|
128
|
+
export function captureGraphCheckpoint(graph: SceneGraph) {
|
|
129
|
+
const nodeRefs = new Map(graph.nodes)
|
|
130
|
+
const nodes = structuredClone(graph.nodes)
|
|
131
|
+
const tables = captureTables(graph)
|
|
132
|
+
|
|
133
|
+
function assertPropertiesOnly() {
|
|
134
|
+
assertSameNodes(graph, nodeRefs, tables.variableCount)
|
|
135
|
+
for (const [id, before] of nodes) assertHierarchyKept(graph, nodeRefs, before, id)
|
|
136
|
+
tables.assertVariablesKept()
|
|
137
|
+
tables.assertDocumentUnchanged()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function restore() {
|
|
141
|
+
const failedNodes = new Map(graph.nodes)
|
|
142
|
+
restoreObjects(graph.nodes, nodes, nodeRefs)
|
|
143
|
+
tables.restore()
|
|
144
|
+
graph.clearAbsPosCache()
|
|
145
|
+
announceRestore(graph, failedNodes, graph.nodes.keys())
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return { nodes, variables: tables.variables, assertPropertiesOnly, restore }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function copyOverrides(state: InstanceOverrideState): InstanceOverrideState {
|
|
152
|
+
return {
|
|
153
|
+
self: new Map(state.self),
|
|
154
|
+
descendants: new Map([...state.descendants].map(([id, fields]) => [id, new Map(fields)]))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A layer's fields as they are, sharing their values, with the parts the graph edits in place
|
|
160
|
+
* (child list, source metadata, override maps) copied, as undo recording copies a page.
|
|
161
|
+
*/
|
|
162
|
+
function referenceCopy(node: SceneNode): SceneNode {
|
|
163
|
+
const { source } = node
|
|
164
|
+
return {
|
|
165
|
+
...node,
|
|
166
|
+
childIds: [...node.childIds],
|
|
167
|
+
source: { ...source, fig: { ...source.fig, rawNodeFields: { ...source.fig.rawNodeFields } } },
|
|
168
|
+
instanceOverrides: copyOverrides(node.instanceOverrides)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function keyCount(value: object): number {
|
|
173
|
+
let count = 0
|
|
174
|
+
for (const key in value) if (Object.hasOwn(value, key)) count++
|
|
175
|
+
return count
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Whether `current` holds the same keys as `saved`, each with the same value, except `skip`;
|
|
180
|
+
* `savedKeys` is how many keys `saved` has, when already counted.
|
|
181
|
+
*/
|
|
182
|
+
function sameFields<T extends object>(
|
|
183
|
+
current: T,
|
|
184
|
+
saved: T,
|
|
185
|
+
skip?: ReadonlySet<string>,
|
|
186
|
+
savedKeys = keyCount(saved)
|
|
187
|
+
): boolean {
|
|
188
|
+
let currentKeys = 0
|
|
189
|
+
for (const key in current) {
|
|
190
|
+
if (!Object.hasOwn(current, key)) continue
|
|
191
|
+
currentKeys++
|
|
192
|
+
if (skip?.has(key)) continue
|
|
193
|
+
if (current[key] !== saved[key]) return false
|
|
194
|
+
}
|
|
195
|
+
return currentKeys === savedKeys
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function sameMap<K, V>(current: Map<K, V>, saved: Map<K, V>): boolean {
|
|
199
|
+
if (current.size !== saved.size) return false
|
|
200
|
+
for (const [key, value] of current) if (saved.get(key) !== value) return false
|
|
201
|
+
return true
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const COPIED_FIELDS: ReadonlySet<string> = new Set(['childIds', 'source', 'instanceOverrides'])
|
|
205
|
+
const SOURCE_FIG: ReadonlySet<string> = new Set(['fig'])
|
|
206
|
+
const FIG_RAW_FIELDS: ReadonlySet<string> = new Set(['rawNodeFields'])
|
|
207
|
+
|
|
208
|
+
/** A layer's reference copy, and how many fields it has. */
|
|
209
|
+
interface Reference {
|
|
210
|
+
node: SceneNode
|
|
211
|
+
fields: number
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Whether anything of `node` differs from its reference copy, even written in place. */
|
|
215
|
+
function differs(node: SceneNode, { node: saved, fields }: Reference): boolean {
|
|
216
|
+
const { source, instanceOverrides: overrides } = node
|
|
217
|
+
const savedOverrides = saved.instanceOverrides
|
|
218
|
+
return !(
|
|
219
|
+
sameFields(node, saved, COPIED_FIELDS, fields) &&
|
|
220
|
+
isEqual(node.childIds, saved.childIds) &&
|
|
221
|
+
sameFields(source, saved.source, SOURCE_FIG) &&
|
|
222
|
+
sameFields(source.fig, saved.source.fig, FIG_RAW_FIELDS) &&
|
|
223
|
+
sameFields(source.fig.rawNodeFields, saved.source.fig.rawNodeFields) &&
|
|
224
|
+
sameMap(overrides.self, savedOverrides.self) &&
|
|
225
|
+
overrides.descendants.size === savedOverrides.descendants.size &&
|
|
226
|
+
[...overrides.descendants].every(([id, fields]) => {
|
|
227
|
+
const savedFields = savedOverrides.descendants.get(id)
|
|
228
|
+
return savedFields !== undefined && sameMap(fields, savedFields)
|
|
229
|
+
})
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Rollback state for an edit that may only change properties, costing what the edit touches:
|
|
235
|
+
* every layer is kept by reference (its values shared, the parts the graph edits in place
|
|
236
|
+
* copied), and a layer the graph announces with `willChangeNode` is deep-copied before it
|
|
237
|
+
* changes. A layer written without that announcement is still caught and restored as long as
|
|
238
|
+
* its values were replaced rather than written into, as the graph's contract asks. The other
|
|
239
|
+
* tables are copied whole, as `captureGraphCheckpoint` does. Call `release` when done.
|
|
240
|
+
*/
|
|
241
|
+
export function captureEditCheckpoint(graph: SceneGraph) {
|
|
242
|
+
const nodeRefs = new Map(graph.nodes)
|
|
243
|
+
const references = new Map<string, Reference>()
|
|
244
|
+
for (const [id, node] of nodeRefs) {
|
|
245
|
+
const copy = referenceCopy(node)
|
|
246
|
+
references.set(id, { node: copy, fields: keyCount(copy) })
|
|
247
|
+
}
|
|
248
|
+
// Deep copies of announced layers, taken before they change.
|
|
249
|
+
const announced = new Map<string, SceneNode>()
|
|
250
|
+
const release = graph.observeNodeChanges({
|
|
251
|
+
created: () => undefined,
|
|
252
|
+
before: (node) => {
|
|
253
|
+
const saved = references.get(node.id)
|
|
254
|
+
if (saved && !announced.has(node.id)) announced.set(node.id, structuredClone(saved.node))
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
const tables = captureTables(graph)
|
|
258
|
+
|
|
259
|
+
/** Each layer the edit changed so far, as it was before: announced ones and any other. */
|
|
260
|
+
function changedNodes(): Map<string, SceneNode> {
|
|
261
|
+
const changed = new Map(announced)
|
|
262
|
+
for (const [id, node] of graph.nodes) {
|
|
263
|
+
const saved = references.get(id)
|
|
264
|
+
if (saved && !changed.has(id) && differs(node, saved)) changed.set(id, saved.node)
|
|
265
|
+
}
|
|
266
|
+
return changed
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Throws unless the edit only changed properties; returns what it changed, as `changedNodes`. */
|
|
270
|
+
function assertPropertiesOnly(): Map<string, SceneNode> {
|
|
271
|
+
assertSameNodes(graph, nodeRefs, tables.variableCount)
|
|
272
|
+
for (const [id, ref] of nodeRefs) {
|
|
273
|
+
if (graph.nodes.get(id) !== ref)
|
|
274
|
+
throw new Error('Atomic tools must not change node hierarchy or identity')
|
|
275
|
+
}
|
|
276
|
+
const changed = changedNodes()
|
|
277
|
+
for (const [id, before] of changed) assertHierarchyKept(graph, nodeRefs, before, id)
|
|
278
|
+
tables.assertVariablesKept()
|
|
279
|
+
tables.assertDocumentUnchanged()
|
|
280
|
+
return changed
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function restore() {
|
|
284
|
+
const changed = changedNodes()
|
|
285
|
+
const failedNodes = new Map(graph.nodes)
|
|
286
|
+
graph.nodes.clear()
|
|
287
|
+
for (const [id, node] of nodeRefs) graph.nodes.set(id, node)
|
|
288
|
+
for (const [id, saved] of changed) {
|
|
289
|
+
const node = nodeRefs.get(id)
|
|
290
|
+
if (!node) continue
|
|
291
|
+
for (const key of Object.keys(node) as (keyof SceneNode)[]) {
|
|
292
|
+
if (!(key in saved)) Reflect.deleteProperty(node, key)
|
|
293
|
+
}
|
|
294
|
+
// A deep copy is the checkpoint's own; a reference copy holds the values the layer had.
|
|
295
|
+
Object.assign(node, announced.has(id) ? structuredClone(saved) : saved)
|
|
296
|
+
}
|
|
297
|
+
tables.restore()
|
|
298
|
+
graph.clearAbsPosCache()
|
|
299
|
+
announceRestore(graph, failedNodes, changed.keys())
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return { variables: tables.variables, changedNodes, assertPropertiesOnly, restore, release }
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function restoreObjects<T extends object>(
|
|
306
|
+
target: Map<string, T>,
|
|
307
|
+
snapshot: Map<string, T>,
|
|
308
|
+
refs: Map<string, T>
|
|
309
|
+
) {
|
|
310
|
+
target.clear()
|
|
311
|
+
for (const [id, saved] of snapshot) {
|
|
312
|
+
const original = refs.get(id)
|
|
313
|
+
if (!original) throw new Error(`Missing checkpoint reference: ${id}`)
|
|
314
|
+
for (const key of Object.keys(original) as (keyof T)[]) {
|
|
315
|
+
if (!(key in saved)) Reflect.deleteProperty(original, key)
|
|
316
|
+
}
|
|
317
|
+
Object.assign(original, structuredClone(saved))
|
|
318
|
+
target.set(id, original)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function restoreMap<K, V>(target: Map<K, V>, saved: Map<K, V>) {
|
|
323
|
+
target.clear()
|
|
324
|
+
for (const [key, value] of saved) target.set(key, value)
|
|
325
|
+
}
|
package/src/clipping.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { computeBounds, type VisualBounds } from './geometry'
|
|
2
|
+
import type { Vector } from './primitives'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rotated-rectangle clipping: a polygon or an axis-aligned box cut by a convex polygon, such as
|
|
6
|
+
* the canvas corners of a rotated frame that clips its content.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function crossProduct(a: Vector, b: Vector, p: Vector): number {
|
|
10
|
+
return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function lineSegmentIntersect(p1: Vector, p2: Vector, p3: Vector, p4: Vector): Vector {
|
|
14
|
+
const dx1 = p2.x - p1.x
|
|
15
|
+
const dy1 = p2.y - p1.y
|
|
16
|
+
const dx2 = p4.x - p3.x
|
|
17
|
+
const dy2 = p4.y - p3.y
|
|
18
|
+
const denom = dx1 * dy2 - dy1 * dx2
|
|
19
|
+
if (denom === 0) return p1
|
|
20
|
+
const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom
|
|
21
|
+
return { x: p1.x + t * dx1, y: p1.y + t * dy1 }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function clipHalfPlane(polygon: Vector[], a: Vector, b: Vector, wantPositive: boolean): Vector[] {
|
|
25
|
+
const output: Vector[] = []
|
|
26
|
+
const isInside = (p: Vector): boolean => {
|
|
27
|
+
const cross = crossProduct(a, b, p)
|
|
28
|
+
return wantPositive ? cross >= 0 : cross <= 0
|
|
29
|
+
}
|
|
30
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
31
|
+
const curr = polygon[i]
|
|
32
|
+
const prev = polygon[i === 0 ? polygon.length - 1 : i - 1]
|
|
33
|
+
const currInside = isInside(curr)
|
|
34
|
+
const prevInside = isInside(prev)
|
|
35
|
+
if (currInside) {
|
|
36
|
+
if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b))
|
|
37
|
+
output.push(curr)
|
|
38
|
+
} else if (prevInside) {
|
|
39
|
+
output.push(lineSegmentIntersect(prev, curr, a, b))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return output
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space
|
|
47
|
+
* corners of a rotated clipping ancestor).
|
|
48
|
+
*
|
|
49
|
+
* Uses Sutherland–Hodgman polygon clipping with centroid-based interior
|
|
50
|
+
* detection, making it robust to either winding order of the clip polygon.
|
|
51
|
+
* Returns the clipped polygon, or null if the subject is fully outside the
|
|
52
|
+
* clip polygon. When `clipCorners` has fewer than 3 points the subject is
|
|
53
|
+
* returned unchanged (no clipping).
|
|
54
|
+
*
|
|
55
|
+
* Preserving the polygon (rather than collapsing to an AABB) lets callers
|
|
56
|
+
* chain multiple clips without reintroducing corners removed by an inner clip.
|
|
57
|
+
*/
|
|
58
|
+
export function clipPolygon(subject: Vector[], clipCorners: Vector[]): Vector[] | null {
|
|
59
|
+
if (clipCorners.length < 3) return subject
|
|
60
|
+
|
|
61
|
+
let cx = 0
|
|
62
|
+
let cy = 0
|
|
63
|
+
for (const c of clipCorners) {
|
|
64
|
+
cx += c.x
|
|
65
|
+
cy += c.y
|
|
66
|
+
}
|
|
67
|
+
cx /= clipCorners.length
|
|
68
|
+
cy /= clipCorners.length
|
|
69
|
+
|
|
70
|
+
let polygon: Vector[] = subject
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < clipCorners.length; i++) {
|
|
73
|
+
if (polygon.length === 0) return null
|
|
74
|
+
const a = clipCorners[i]
|
|
75
|
+
const b = clipCorners[(i + 1) % clipCorners.length]
|
|
76
|
+
const centroidCross = crossProduct(a, b, { x: cx, y: cy })
|
|
77
|
+
polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return polygon.length === 0 ? null : polygon
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Clip an axis-aligned VisualBounds rectangle against a convex polygon
|
|
85
|
+
* (e.g. the 4 canvas-space corners of a rotated clipping ancestor).
|
|
86
|
+
*
|
|
87
|
+
* Returns the AABB of the intersection, or null if the bounds are fully
|
|
88
|
+
* outside the clip polygon. Delegates to {@link clipPolygon}.
|
|
89
|
+
*
|
|
90
|
+
* For a non-rotated clip (axis-aligned corners) the result is identical
|
|
91
|
+
* to `intersectVisualBounds`.
|
|
92
|
+
*/
|
|
93
|
+
export function clipBoundsToPolygon(
|
|
94
|
+
bounds: VisualBounds,
|
|
95
|
+
clipCorners: Vector[]
|
|
96
|
+
): VisualBounds | null {
|
|
97
|
+
if (clipCorners.length < 3) return bounds
|
|
98
|
+
|
|
99
|
+
const subject: Vector[] = [
|
|
100
|
+
{ x: bounds.minX, y: bounds.minY },
|
|
101
|
+
{ x: bounds.maxX, y: bounds.minY },
|
|
102
|
+
{ x: bounds.maxX, y: bounds.maxY },
|
|
103
|
+
{ x: bounds.minX, y: bounds.maxY }
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
const polygon = clipPolygon(subject, clipCorners)
|
|
107
|
+
if (!polygon) return null
|
|
108
|
+
|
|
109
|
+
const box = computeBounds(polygon.map(({ x, y }) => ({ x, y, width: 0, height: 0 })))
|
|
110
|
+
if (box.width <= 0 || box.height <= 0) return null
|
|
111
|
+
return { minX: box.x, minY: box.y, maxX: box.x + box.width, maxY: box.y + box.height }
|
|
112
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { wcagContrast } from 'culori'
|
|
2
|
+
|
|
3
|
+
import { BLACK, WHITE } from '../constants'
|
|
4
|
+
import type { Color } from '../primitives'
|
|
5
|
+
|
|
6
|
+
/** Opaque color seen when `foreground` at `alpha` is drawn over an opaque `background`. */
|
|
7
|
+
export function compositeOver(foreground: Color, background: Color, alpha = foreground.a): Color {
|
|
8
|
+
const mix = (top: number, bottom: number) => top * alpha + bottom * (1 - alpha)
|
|
9
|
+
return {
|
|
10
|
+
r: mix(foreground.r, background.r),
|
|
11
|
+
g: mix(foreground.g, background.g),
|
|
12
|
+
b: mix(foreground.b, background.b),
|
|
13
|
+
a: 1
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** WCAG 2 contrast ratio of two colors, from 1 to 21; alpha is ignored, so composite first. */
|
|
18
|
+
export function contrastRatio(
|
|
19
|
+
a: Pick<Color, 'r' | 'g' | 'b'>,
|
|
20
|
+
b: Pick<Color, 'r' | 'g' | 'b'>
|
|
21
|
+
): number {
|
|
22
|
+
return wcagContrast(
|
|
23
|
+
{ mode: 'rgb', r: a.r, g: a.g, b: a.b },
|
|
24
|
+
{ mode: 'rgb', r: b.r, g: b.g, b: b.b }
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `background` darkened just enough for light `text` to reach `ratio` on it, by scaling its
|
|
30
|
+
* channels toward black, which keeps its hue; returned as it is when the text already does.
|
|
31
|
+
* The default is white text at WCAG AA's 4.5:1 for normal text.
|
|
32
|
+
*
|
|
33
|
+
* The check runs on 8-bit-rounded channels, since browsers round `rgb()` values and rounding
|
|
34
|
+
* can drop a result that barely passed below the target.
|
|
35
|
+
*/
|
|
36
|
+
export function darkenForContrast(
|
|
37
|
+
background: Color,
|
|
38
|
+
text: Pick<Color, 'r' | 'g' | 'b'> = WHITE,
|
|
39
|
+
ratio = 4.5
|
|
40
|
+
): Color {
|
|
41
|
+
if (contrastRatio(background, text) >= ratio) return background
|
|
42
|
+
const scaled = (factor: number): Color => ({
|
|
43
|
+
...background,
|
|
44
|
+
r: background.r * factor,
|
|
45
|
+
g: background.g * factor,
|
|
46
|
+
b: background.b * factor
|
|
47
|
+
})
|
|
48
|
+
const rounded = (factor: number): Color => {
|
|
49
|
+
const c = scaled(factor)
|
|
50
|
+
return {
|
|
51
|
+
...c,
|
|
52
|
+
r: Math.round(c.r * 255) / 255,
|
|
53
|
+
g: Math.round(c.g * 255) / 255,
|
|
54
|
+
b: Math.round(c.b * 255) / 255
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Darker always contrasts more with light text, so the smallest darkening is found by halving.
|
|
58
|
+
let enough = 0
|
|
59
|
+
let short = 1
|
|
60
|
+
for (let step = 0; step < 20; step++) {
|
|
61
|
+
const middle = (enough + short) / 2
|
|
62
|
+
if (contrastRatio(rounded(middle), text) >= ratio) enough = middle
|
|
63
|
+
else short = middle
|
|
64
|
+
}
|
|
65
|
+
return rounded(enough)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Black or white, whichever reads better on an opaque `background`. */
|
|
69
|
+
export function readableForeground(background: Pick<Color, 'r' | 'g' | 'b'>): Color {
|
|
70
|
+
return contrastRatio(background, BLACK) >= contrastRatio(background, WHITE) ? BLACK : WHITE
|
|
71
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export * from './contrast'
|
|
2
|
+
export * from './management'
|
|
3
|
+
export { normalizeColor } from './normalize'
|
|
4
|
+
export * from './okhcl'
|
|
5
|
+
|
|
6
|
+
import { parse, formatHex, formatHex8, formatRgb, converter, differenceEuclidean } from 'culori'
|
|
7
|
+
|
|
8
|
+
import { BLACK } from '../constants'
|
|
9
|
+
import type { Color } from '../primitives'
|
|
10
|
+
|
|
11
|
+
const toRGB = converter('rgb')
|
|
12
|
+
|
|
13
|
+
/** A CSS color, or null when `input` is not one. */
|
|
14
|
+
export function tryParseColor(input: string): Color | null {
|
|
15
|
+
const parsed = parse(input)
|
|
16
|
+
if (!parsed) return null
|
|
17
|
+
const rgb = toRGB(parsed)
|
|
18
|
+
return {
|
|
19
|
+
r: rgb.r,
|
|
20
|
+
g: rgb.g,
|
|
21
|
+
b: rgb.b,
|
|
22
|
+
a: parsed.alpha ?? 1
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A CSS color, or black when `input` is not one. */
|
|
27
|
+
export function parseColor(input: string): Color {
|
|
28
|
+
return tryParseColor(input) ?? { ...BLACK }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function colorToHex(color: Color): string {
|
|
32
|
+
return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function colorToHex8(color: Color, alpha?: number): string {
|
|
36
|
+
const a = alpha ?? color.a
|
|
37
|
+
if (a >= 1) return colorToHex(color)
|
|
38
|
+
return formatHex8({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: a }).toUpperCase()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function colorToHexRaw(color: Color): string {
|
|
42
|
+
return colorToHex(color).slice(1)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function colorToRgba255(color: Color) {
|
|
46
|
+
return {
|
|
47
|
+
r: Math.round(color.r * 255),
|
|
48
|
+
g: Math.round(color.g * 255),
|
|
49
|
+
b: Math.round(color.b * 255),
|
|
50
|
+
a: color.a
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function colorToCSS(color: Color): string {
|
|
55
|
+
return formatRgb({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function colorToCSSCompact(color: Color): string {
|
|
59
|
+
const { r, g, b } = colorToRgba255(color)
|
|
60
|
+
const a = Number(color.a.toFixed(3))
|
|
61
|
+
if (a >= 1) return `rgb(${r},${g},${b})`
|
|
62
|
+
return `rgba(${r},${g},${b},${a})`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {
|
|
66
|
+
return { r: r / 255, g: g / 255, b: b / 255, a }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function colorToFill(color: string | Color) {
|
|
70
|
+
const rgba = typeof color === 'string' ? parseColor(color) : color
|
|
71
|
+
return {
|
|
72
|
+
type: 'SOLID' as const,
|
|
73
|
+
color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },
|
|
74
|
+
opacity: rgba.a,
|
|
75
|
+
visible: true
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const euclideanRGB255 = differenceEuclidean('rgb')
|
|
80
|
+
|
|
81
|
+
export function colorDistance(c1: Color, c2: Color): number {
|
|
82
|
+
return (
|
|
83
|
+
euclideanRGB255(
|
|
84
|
+
{ mode: 'rgb', r: c1.r, g: c1.g, b: c1.b },
|
|
85
|
+
{ mode: 'rgb', r: c2.r, g: c2.g, b: c2.b }
|
|
86
|
+
) * 255
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
export * from './schema'
|