@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
package/dist/clipping.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { computeBounds } from "./geometry.js";
|
|
2
|
+
//#region src/clipping.ts
|
|
3
|
+
/**
|
|
4
|
+
* Rotated-rectangle clipping: a polygon or an axis-aligned box cut by a convex polygon, such as
|
|
5
|
+
* the canvas corners of a rotated frame that clips its content.
|
|
6
|
+
*/
|
|
7
|
+
function crossProduct(a, b, p) {
|
|
8
|
+
return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);
|
|
9
|
+
}
|
|
10
|
+
function lineSegmentIntersect(p1, p2, p3, p4) {
|
|
11
|
+
const dx1 = p2.x - p1.x;
|
|
12
|
+
const dy1 = p2.y - p1.y;
|
|
13
|
+
const dx2 = p4.x - p3.x;
|
|
14
|
+
const dy2 = p4.y - p3.y;
|
|
15
|
+
const denom = dx1 * dy2 - dy1 * dx2;
|
|
16
|
+
if (denom === 0) return p1;
|
|
17
|
+
const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom;
|
|
18
|
+
return {
|
|
19
|
+
x: p1.x + t * dx1,
|
|
20
|
+
y: p1.y + t * dy1
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function clipHalfPlane(polygon, a, b, wantPositive) {
|
|
24
|
+
const output = [];
|
|
25
|
+
const isInside = (p) => {
|
|
26
|
+
const cross = crossProduct(a, b, p);
|
|
27
|
+
return wantPositive ? cross >= 0 : cross <= 0;
|
|
28
|
+
};
|
|
29
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
30
|
+
const curr = polygon[i];
|
|
31
|
+
const prev = polygon[i === 0 ? polygon.length - 1 : i - 1];
|
|
32
|
+
const currInside = isInside(curr);
|
|
33
|
+
const prevInside = isInside(prev);
|
|
34
|
+
if (currInside) {
|
|
35
|
+
if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b));
|
|
36
|
+
output.push(curr);
|
|
37
|
+
} else if (prevInside) output.push(lineSegmentIntersect(prev, curr, a, b));
|
|
38
|
+
}
|
|
39
|
+
return output;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space
|
|
43
|
+
* corners of a rotated clipping ancestor).
|
|
44
|
+
*
|
|
45
|
+
* Uses Sutherland–Hodgman polygon clipping with centroid-based interior
|
|
46
|
+
* detection, making it robust to either winding order of the clip polygon.
|
|
47
|
+
* Returns the clipped polygon, or null if the subject is fully outside the
|
|
48
|
+
* clip polygon. When `clipCorners` has fewer than 3 points the subject is
|
|
49
|
+
* returned unchanged (no clipping).
|
|
50
|
+
*
|
|
51
|
+
* Preserving the polygon (rather than collapsing to an AABB) lets callers
|
|
52
|
+
* chain multiple clips without reintroducing corners removed by an inner clip.
|
|
53
|
+
*/
|
|
54
|
+
function clipPolygon(subject, clipCorners) {
|
|
55
|
+
if (clipCorners.length < 3) return subject;
|
|
56
|
+
let cx = 0;
|
|
57
|
+
let cy = 0;
|
|
58
|
+
for (const c of clipCorners) {
|
|
59
|
+
cx += c.x;
|
|
60
|
+
cy += c.y;
|
|
61
|
+
}
|
|
62
|
+
cx /= clipCorners.length;
|
|
63
|
+
cy /= clipCorners.length;
|
|
64
|
+
let polygon = subject;
|
|
65
|
+
for (let i = 0; i < clipCorners.length; i++) {
|
|
66
|
+
if (polygon.length === 0) return null;
|
|
67
|
+
const a = clipCorners[i];
|
|
68
|
+
const b = clipCorners[(i + 1) % clipCorners.length];
|
|
69
|
+
const centroidCross = crossProduct(a, b, {
|
|
70
|
+
x: cx,
|
|
71
|
+
y: cy
|
|
72
|
+
});
|
|
73
|
+
polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0);
|
|
74
|
+
}
|
|
75
|
+
return polygon.length === 0 ? null : polygon;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Clip an axis-aligned VisualBounds rectangle against a convex polygon
|
|
79
|
+
* (e.g. the 4 canvas-space corners of a rotated clipping ancestor).
|
|
80
|
+
*
|
|
81
|
+
* Returns the AABB of the intersection, or null if the bounds are fully
|
|
82
|
+
* outside the clip polygon. Delegates to {@link clipPolygon}.
|
|
83
|
+
*
|
|
84
|
+
* For a non-rotated clip (axis-aligned corners) the result is identical
|
|
85
|
+
* to `intersectVisualBounds`.
|
|
86
|
+
*/
|
|
87
|
+
function clipBoundsToPolygon(bounds, clipCorners) {
|
|
88
|
+
if (clipCorners.length < 3) return bounds;
|
|
89
|
+
const polygon = clipPolygon([
|
|
90
|
+
{
|
|
91
|
+
x: bounds.minX,
|
|
92
|
+
y: bounds.minY
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
x: bounds.maxX,
|
|
96
|
+
y: bounds.minY
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
x: bounds.maxX,
|
|
100
|
+
y: bounds.maxY
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
x: bounds.minX,
|
|
104
|
+
y: bounds.maxY
|
|
105
|
+
}
|
|
106
|
+
], clipCorners);
|
|
107
|
+
if (!polygon) return null;
|
|
108
|
+
const box = computeBounds(polygon.map(({ x, y }) => ({
|
|
109
|
+
x,
|
|
110
|
+
y,
|
|
111
|
+
width: 0,
|
|
112
|
+
height: 0
|
|
113
|
+
})));
|
|
114
|
+
if (box.width <= 0 || box.height <= 0) return null;
|
|
115
|
+
return {
|
|
116
|
+
minX: box.x,
|
|
117
|
+
minY: box.y,
|
|
118
|
+
maxX: box.x + box.width,
|
|
119
|
+
maxY: box.y + box.height
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { clipBoundsToPolygon, clipPolygon };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=clipping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipping.js","names":[],"sources":["../src/clipping.ts"],"sourcesContent":["import { computeBounds, type VisualBounds } from './geometry'\nimport type { Vector } from './primitives'\n\n/**\n * Rotated-rectangle clipping: a polygon or an axis-aligned box cut by a convex polygon, such as\n * the canvas corners of a rotated frame that clips its content.\n */\n\nfunction crossProduct(a: Vector, b: Vector, p: Vector): number {\n return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x)\n}\n\nfunction lineSegmentIntersect(p1: Vector, p2: Vector, p3: Vector, p4: Vector): Vector {\n const dx1 = p2.x - p1.x\n const dy1 = p2.y - p1.y\n const dx2 = p4.x - p3.x\n const dy2 = p4.y - p3.y\n const denom = dx1 * dy2 - dy1 * dx2\n if (denom === 0) return p1\n const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom\n return { x: p1.x + t * dx1, y: p1.y + t * dy1 }\n}\n\nfunction clipHalfPlane(polygon: Vector[], a: Vector, b: Vector, wantPositive: boolean): Vector[] {\n const output: Vector[] = []\n const isInside = (p: Vector): boolean => {\n const cross = crossProduct(a, b, p)\n return wantPositive ? cross >= 0 : cross <= 0\n }\n for (let i = 0; i < polygon.length; i++) {\n const curr = polygon[i]\n const prev = polygon[i === 0 ? polygon.length - 1 : i - 1]\n const currInside = isInside(curr)\n const prevInside = isInside(prev)\n if (currInside) {\n if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b))\n output.push(curr)\n } else if (prevInside) {\n output.push(lineSegmentIntersect(prev, curr, a, b))\n }\n }\n return output\n}\n\n/**\n * Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space\n * corners of a rotated clipping ancestor).\n *\n * Uses Sutherland–Hodgman polygon clipping with centroid-based interior\n * detection, making it robust to either winding order of the clip polygon.\n * Returns the clipped polygon, or null if the subject is fully outside the\n * clip polygon. When `clipCorners` has fewer than 3 points the subject is\n * returned unchanged (no clipping).\n *\n * Preserving the polygon (rather than collapsing to an AABB) lets callers\n * chain multiple clips without reintroducing corners removed by an inner clip.\n */\nexport function clipPolygon(subject: Vector[], clipCorners: Vector[]): Vector[] | null {\n if (clipCorners.length < 3) return subject\n\n let cx = 0\n let cy = 0\n for (const c of clipCorners) {\n cx += c.x\n cy += c.y\n }\n cx /= clipCorners.length\n cy /= clipCorners.length\n\n let polygon: Vector[] = subject\n\n for (let i = 0; i < clipCorners.length; i++) {\n if (polygon.length === 0) return null\n const a = clipCorners[i]\n const b = clipCorners[(i + 1) % clipCorners.length]\n const centroidCross = crossProduct(a, b, { x: cx, y: cy })\n polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0)\n }\n\n return polygon.length === 0 ? null : polygon\n}\n\n/**\n * Clip an axis-aligned VisualBounds rectangle against a convex polygon\n * (e.g. the 4 canvas-space corners of a rotated clipping ancestor).\n *\n * Returns the AABB of the intersection, or null if the bounds are fully\n * outside the clip polygon. Delegates to {@link clipPolygon}.\n *\n * For a non-rotated clip (axis-aligned corners) the result is identical\n * to `intersectVisualBounds`.\n */\nexport function clipBoundsToPolygon(\n bounds: VisualBounds,\n clipCorners: Vector[]\n): VisualBounds | null {\n if (clipCorners.length < 3) return bounds\n\n const subject: Vector[] = [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n { x: bounds.minX, y: bounds.maxY }\n ]\n\n const polygon = clipPolygon(subject, clipCorners)\n if (!polygon) return null\n\n const box = computeBounds(polygon.map(({ x, y }) => ({ x, y, width: 0, height: 0 })))\n if (box.width <= 0 || box.height <= 0) return null\n return { minX: box.x, minY: box.y, maxX: box.x + box.width, maxY: box.y + box.height }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Color } from "../primitives/index.js";
|
|
2
|
+
//#region src/color/contrast.d.ts
|
|
3
|
+
/** Opaque color seen when `foreground` at `alpha` is drawn over an opaque `background`. */
|
|
4
|
+
declare function compositeOver(foreground: Color, background: Color, alpha?: number): Color;
|
|
5
|
+
/** WCAG 2 contrast ratio of two colors, from 1 to 21; alpha is ignored, so composite first. */
|
|
6
|
+
declare function contrastRatio(a: Pick<Color, 'r' | 'g' | 'b'>, b: Pick<Color, 'r' | 'g' | 'b'>): number;
|
|
7
|
+
/**
|
|
8
|
+
* `background` darkened just enough for light `text` to reach `ratio` on it, by scaling its
|
|
9
|
+
* channels toward black, which keeps its hue; returned as it is when the text already does.
|
|
10
|
+
* The default is white text at WCAG AA's 4.5:1 for normal text.
|
|
11
|
+
*
|
|
12
|
+
* The check runs on 8-bit-rounded channels, since browsers round `rgb()` values and rounding
|
|
13
|
+
* can drop a result that barely passed below the target.
|
|
14
|
+
*/
|
|
15
|
+
declare function darkenForContrast(background: Color, text?: Pick<Color, 'r' | 'g' | 'b'>, ratio?: number): Color;
|
|
16
|
+
/** Black or white, whichever reads better on an opaque `background`. */
|
|
17
|
+
declare function readableForeground(background: Pick<Color, 'r' | 'g' | 'b'>): Color;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { compositeOver, contrastRatio, darkenForContrast, readableForeground };
|
|
20
|
+
//# sourceMappingURL=contrast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contrast.d.ts","names":[],"sources":["../../src/color/contrast.ts"],"mappings":";;;iBAMgB,cAAc,YAAY,OAAO,YAAY,OAAO,iBAAuB;;iBAW3E,cACd,GAAG,KAAK,yBACR,GAAG,KAAK;;;;;;;;;iBAgBM,kBACd,YAAY,OACZ,OAAM,KAAK,yBACX,iBACC;;iBA6Ba,mBAAmB,YAAY,KAAK,0BAA0B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BLACK, WHITE } from "../constants.js";
|
|
2
|
+
import { wcagContrast } from "culori";
|
|
3
|
+
//#region src/color/contrast.ts
|
|
4
|
+
/** Opaque color seen when `foreground` at `alpha` is drawn over an opaque `background`. */
|
|
5
|
+
function compositeOver(foreground, background, alpha = foreground.a) {
|
|
6
|
+
const mix = (top, bottom) => top * alpha + bottom * (1 - alpha);
|
|
7
|
+
return {
|
|
8
|
+
r: mix(foreground.r, background.r),
|
|
9
|
+
g: mix(foreground.g, background.g),
|
|
10
|
+
b: mix(foreground.b, background.b),
|
|
11
|
+
a: 1
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** WCAG 2 contrast ratio of two colors, from 1 to 21; alpha is ignored, so composite first. */
|
|
15
|
+
function contrastRatio(a, b) {
|
|
16
|
+
return wcagContrast({
|
|
17
|
+
mode: "rgb",
|
|
18
|
+
r: a.r,
|
|
19
|
+
g: a.g,
|
|
20
|
+
b: a.b
|
|
21
|
+
}, {
|
|
22
|
+
mode: "rgb",
|
|
23
|
+
r: b.r,
|
|
24
|
+
g: b.g,
|
|
25
|
+
b: b.b
|
|
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
|
+
function darkenForContrast(background, text = WHITE, ratio = 4.5) {
|
|
37
|
+
if (contrastRatio(background, text) >= ratio) return background;
|
|
38
|
+
const scaled = (factor) => ({
|
|
39
|
+
...background,
|
|
40
|
+
r: background.r * factor,
|
|
41
|
+
g: background.g * factor,
|
|
42
|
+
b: background.b * factor
|
|
43
|
+
});
|
|
44
|
+
const rounded = (factor) => {
|
|
45
|
+
const c = scaled(factor);
|
|
46
|
+
return {
|
|
47
|
+
...c,
|
|
48
|
+
r: Math.round(c.r * 255) / 255,
|
|
49
|
+
g: Math.round(c.g * 255) / 255,
|
|
50
|
+
b: Math.round(c.b * 255) / 255
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
let enough = 0;
|
|
54
|
+
let short = 1;
|
|
55
|
+
for (let step = 0; step < 20; step++) {
|
|
56
|
+
const middle = (enough + short) / 2;
|
|
57
|
+
if (contrastRatio(rounded(middle), text) >= ratio) enough = middle;
|
|
58
|
+
else short = middle;
|
|
59
|
+
}
|
|
60
|
+
return rounded(enough);
|
|
61
|
+
}
|
|
62
|
+
/** Black or white, whichever reads better on an opaque `background`. */
|
|
63
|
+
function readableForeground(background) {
|
|
64
|
+
return contrastRatio(background, BLACK) >= contrastRatio(background, WHITE) ? BLACK : WHITE;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { compositeOver, contrastRatio, darkenForContrast, readableForeground };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=contrast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contrast.js","names":[],"sources":["../../src/color/contrast.ts"],"sourcesContent":["import { wcagContrast } from 'culori'\n\nimport { BLACK, WHITE } from '../constants'\nimport type { Color } from '../primitives'\n\n/** Opaque color seen when `foreground` at `alpha` is drawn over an opaque `background`. */\nexport function compositeOver(foreground: Color, background: Color, alpha = foreground.a): Color {\n const mix = (top: number, bottom: number) => top * alpha + bottom * (1 - alpha)\n return {\n r: mix(foreground.r, background.r),\n g: mix(foreground.g, background.g),\n b: mix(foreground.b, background.b),\n a: 1\n }\n}\n\n/** WCAG 2 contrast ratio of two colors, from 1 to 21; alpha is ignored, so composite first. */\nexport function contrastRatio(\n a: Pick<Color, 'r' | 'g' | 'b'>,\n b: Pick<Color, 'r' | 'g' | 'b'>\n): number {\n return wcagContrast(\n { mode: 'rgb', r: a.r, g: a.g, b: a.b },\n { mode: 'rgb', r: b.r, g: b.g, b: b.b }\n )\n}\n\n/**\n * `background` darkened just enough for light `text` to reach `ratio` on it, by scaling its\n * channels toward black, which keeps its hue; returned as it is when the text already does.\n * The default is white text at WCAG AA's 4.5:1 for normal text.\n *\n * The check runs on 8-bit-rounded channels, since browsers round `rgb()` values and rounding\n * can drop a result that barely passed below the target.\n */\nexport function darkenForContrast(\n background: Color,\n text: Pick<Color, 'r' | 'g' | 'b'> = WHITE,\n ratio = 4.5\n): Color {\n if (contrastRatio(background, text) >= ratio) return background\n const scaled = (factor: number): Color => ({\n ...background,\n r: background.r * factor,\n g: background.g * factor,\n b: background.b * factor\n })\n const rounded = (factor: number): Color => {\n const c = scaled(factor)\n return {\n ...c,\n r: Math.round(c.r * 255) / 255,\n g: Math.round(c.g * 255) / 255,\n b: Math.round(c.b * 255) / 255\n }\n }\n // Darker always contrasts more with light text, so the smallest darkening is found by halving.\n let enough = 0\n let short = 1\n for (let step = 0; step < 20; step++) {\n const middle = (enough + short) / 2\n if (contrastRatio(rounded(middle), text) >= ratio) enough = middle\n else short = middle\n }\n return rounded(enough)\n}\n\n/** Black or white, whichever reads better on an opaque `background`. */\nexport function readableForeground(background: Pick<Color, 'r' | 'g' | 'b'>): Color {\n return contrastRatio(background, BLACK) >= contrastRatio(background, WHITE) ? BLACK : WHITE\n}\n"],"mappings":";;;;AAMA,SAAgB,cAAc,YAAmB,YAAmB,QAAQ,WAAW,GAAU;CAC/F,MAAM,OAAO,KAAa,WAAmB,MAAM,QAAQ,UAAU,IAAI;CACzE,OAAO;EACL,GAAG,IAAI,WAAW,GAAG,WAAW,CAAC;EACjC,GAAG,IAAI,WAAW,GAAG,WAAW,CAAC;EACjC,GAAG,IAAI,WAAW,GAAG,WAAW,CAAC;EACjC,GAAG;CACL;AACF;;AAGA,SAAgB,cACd,GACA,GACQ;CACR,OAAO,aACL;EAAE,MAAM;EAAO,GAAG,EAAE;EAAG,GAAG,EAAE;EAAG,GAAG,EAAE;CAAE,GACtC;EAAE,MAAM;EAAO,GAAG,EAAE;EAAG,GAAG,EAAE;EAAG,GAAG,EAAE;CAAE,CACxC;AACF;;;;;;;;;AAUA,SAAgB,kBACd,YACA,OAAqC,OACrC,QAAQ,KACD;CACP,IAAI,cAAc,YAAY,IAAI,KAAK,OAAO,OAAO;CACrD,MAAM,UAAU,YAA2B;EACzC,GAAG;EACH,GAAG,WAAW,IAAI;EAClB,GAAG,WAAW,IAAI;EAClB,GAAG,WAAW,IAAI;CACpB;CACA,MAAM,WAAW,WAA0B;EACzC,MAAM,IAAI,OAAO,MAAM;EACvB,OAAO;GACL,GAAG;GACH,GAAG,KAAK,MAAM,EAAE,IAAI,GAAG,IAAI;GAC3B,GAAG,KAAK,MAAM,EAAE,IAAI,GAAG,IAAI;GAC3B,GAAG,KAAK,MAAM,EAAE,IAAI,GAAG,IAAI;EAC7B;CACF;CAEA,IAAI,SAAS;CACb,IAAI,QAAQ;CACZ,KAAK,IAAI,OAAO,GAAG,OAAO,IAAI,QAAQ;EACpC,MAAM,UAAU,SAAS,SAAS;EAClC,IAAI,cAAc,QAAQ,MAAM,GAAG,IAAI,KAAK,OAAO,SAAS;OACvD,QAAQ;CACf;CACA,OAAO,QAAQ,MAAM;AACvB;;AAGA,SAAgB,mBAAmB,YAAiD;CAClF,OAAO,cAAc,YAAY,KAAK,KAAK,cAAc,YAAY,KAAK,IAAI,QAAQ;AACxF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Color } from "../primitives/index.js";
|
|
2
|
+
import { compositeOver, contrastRatio, darkenForContrast, readableForeground } from "./contrast.js";
|
|
3
|
+
import { OkHCLColor, OkHCLColorSpace, OkHCLPayload, clearNodeFillOkHCL, clearNodeStrokeOkHCL, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, okhclToRGBA, parseOkHCLPayload, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL } from "./okhcl.js";
|
|
4
|
+
import { ColorIntentSpace, ColorPreviewOptions, RenderColorSpace, ResolvedRenderColor, colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview } from "./management.js";
|
|
5
|
+
import { normalizeColor } from "./normalize.js";
|
|
6
|
+
import { colorSchema } from "./schema.js";
|
|
7
|
+
//#region src/color/index.d.ts
|
|
8
|
+
/** A CSS color, or null when `input` is not one. */
|
|
9
|
+
declare function tryParseColor(input: string): Color | null;
|
|
10
|
+
/** A CSS color, or black when `input` is not one. */
|
|
11
|
+
declare function parseColor(input: string): Color;
|
|
12
|
+
declare function colorToHex(color: Color): string;
|
|
13
|
+
declare function colorToHex8(color: Color, alpha?: number): string;
|
|
14
|
+
declare function colorToHexRaw(color: Color): string;
|
|
15
|
+
declare function colorToRgba255(color: Color): {
|
|
16
|
+
r: number;
|
|
17
|
+
g: number;
|
|
18
|
+
b: number;
|
|
19
|
+
a: number;
|
|
20
|
+
};
|
|
21
|
+
declare function colorToCSS(color: Color): string;
|
|
22
|
+
declare function colorToCSSCompact(color: Color): string;
|
|
23
|
+
declare function rgba255ToColor(r: number, g: number, b: number, a?: number): Color;
|
|
24
|
+
declare function colorToFill(color: string | Color): {
|
|
25
|
+
type: "SOLID";
|
|
26
|
+
color: {
|
|
27
|
+
r: number;
|
|
28
|
+
g: number;
|
|
29
|
+
b: number;
|
|
30
|
+
a: number;
|
|
31
|
+
};
|
|
32
|
+
opacity: number;
|
|
33
|
+
visible: boolean;
|
|
34
|
+
};
|
|
35
|
+
declare function colorDistance(c1: Color, c2: Color): number;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ColorIntentSpace, ColorPreviewOptions, OkHCLColor, OkHCLColorSpace, OkHCLPayload, RenderColorSpace, ResolvedRenderColor, clearNodeFillOkHCL, clearNodeStrokeOkHCL, colorDistance, colorSchema, colorToCSS, colorToCSSCompact, colorToDisplayCSS, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToRgba255, compositeOver, contrastRatio, darkenForContrast, getDefaultRenderColorSpace, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, normalizeColor, okhclToRGBA, parseColor, parseDisplayableColor, parseOkHCLPayload, readableForeground, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview, rgba255ToColor, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL, tryParseColor };
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/color/index.ts"],"mappings":";;;;;;;;iBAagB,cAAc,gBAAgB;;iBAa9B,WAAW,gBAAgB;iBAI3B,WAAW,OAAO;iBAIlB,YAAY,OAAO,OAAO;iBAM1B,cAAc,OAAO;iBAIrB,eAAe,OAAO;;;;;;iBAStB,WAAW,OAAO;iBAIlB,kBAAkB,OAAO;iBAOzB,eAAe,WAAW,WAAW,WAAW,aAAQ;iBAIxD,YAAY,gBAAgB;;;;;;;;;;;iBAY5B,cAAc,IAAI,OAAO,IAAI"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { BLACK } from "../constants.js";
|
|
2
|
+
import { colorSchema } from "./schema.js";
|
|
3
|
+
import { compositeOver, contrastRatio, darkenForContrast, readableForeground } from "./contrast.js";
|
|
4
|
+
import { normalizeColor } from "./normalize.js";
|
|
5
|
+
import { clearNodeFillOkHCL, clearNodeStrokeOkHCL, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, okhclToRGBA, parseOkHCLPayload, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL } from "./okhcl.js";
|
|
6
|
+
import { colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview } from "./management.js";
|
|
7
|
+
import { converter, differenceEuclidean, formatHex, formatHex8, formatRgb, parse } from "culori";
|
|
8
|
+
//#region src/color/index.ts
|
|
9
|
+
const toRGB = converter("rgb");
|
|
10
|
+
/** A CSS color, or null when `input` is not one. */
|
|
11
|
+
function tryParseColor(input) {
|
|
12
|
+
const parsed = parse(input);
|
|
13
|
+
if (!parsed) return null;
|
|
14
|
+
const rgb = toRGB(parsed);
|
|
15
|
+
return {
|
|
16
|
+
r: rgb.r,
|
|
17
|
+
g: rgb.g,
|
|
18
|
+
b: rgb.b,
|
|
19
|
+
a: parsed.alpha ?? 1
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** A CSS color, or black when `input` is not one. */
|
|
23
|
+
function parseColor(input) {
|
|
24
|
+
return tryParseColor(input) ?? { ...BLACK };
|
|
25
|
+
}
|
|
26
|
+
function colorToHex(color) {
|
|
27
|
+
return formatHex({
|
|
28
|
+
mode: "rgb",
|
|
29
|
+
r: color.r,
|
|
30
|
+
g: color.g,
|
|
31
|
+
b: color.b
|
|
32
|
+
}).toUpperCase();
|
|
33
|
+
}
|
|
34
|
+
function colorToHex8(color, alpha) {
|
|
35
|
+
const a = alpha ?? color.a;
|
|
36
|
+
if (a >= 1) return colorToHex(color);
|
|
37
|
+
return formatHex8({
|
|
38
|
+
mode: "rgb",
|
|
39
|
+
r: color.r,
|
|
40
|
+
g: color.g,
|
|
41
|
+
b: color.b,
|
|
42
|
+
alpha: a
|
|
43
|
+
}).toUpperCase();
|
|
44
|
+
}
|
|
45
|
+
function colorToHexRaw(color) {
|
|
46
|
+
return colorToHex(color).slice(1);
|
|
47
|
+
}
|
|
48
|
+
function colorToRgba255(color) {
|
|
49
|
+
return {
|
|
50
|
+
r: Math.round(color.r * 255),
|
|
51
|
+
g: Math.round(color.g * 255),
|
|
52
|
+
b: Math.round(color.b * 255),
|
|
53
|
+
a: color.a
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function colorToCSS(color) {
|
|
57
|
+
return formatRgb({
|
|
58
|
+
mode: "rgb",
|
|
59
|
+
r: color.r,
|
|
60
|
+
g: color.g,
|
|
61
|
+
b: color.b,
|
|
62
|
+
alpha: color.a
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function colorToCSSCompact(color) {
|
|
66
|
+
const { r, g, b } = colorToRgba255(color);
|
|
67
|
+
const a = Number(color.a.toFixed(3));
|
|
68
|
+
if (a >= 1) return `rgb(${r},${g},${b})`;
|
|
69
|
+
return `rgba(${r},${g},${b},${a})`;
|
|
70
|
+
}
|
|
71
|
+
function rgba255ToColor(r, g, b, a = 1) {
|
|
72
|
+
return {
|
|
73
|
+
r: r / 255,
|
|
74
|
+
g: g / 255,
|
|
75
|
+
b: b / 255,
|
|
76
|
+
a
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function colorToFill(color) {
|
|
80
|
+
const rgba = typeof color === "string" ? parseColor(color) : color;
|
|
81
|
+
return {
|
|
82
|
+
type: "SOLID",
|
|
83
|
+
color: {
|
|
84
|
+
r: rgba.r,
|
|
85
|
+
g: rgba.g,
|
|
86
|
+
b: rgba.b,
|
|
87
|
+
a: rgba.a
|
|
88
|
+
},
|
|
89
|
+
opacity: rgba.a,
|
|
90
|
+
visible: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const euclideanRGB255 = differenceEuclidean("rgb");
|
|
94
|
+
function colorDistance(c1, c2) {
|
|
95
|
+
return euclideanRGB255({
|
|
96
|
+
mode: "rgb",
|
|
97
|
+
r: c1.r,
|
|
98
|
+
g: c1.g,
|
|
99
|
+
b: c1.b
|
|
100
|
+
}, {
|
|
101
|
+
mode: "rgb",
|
|
102
|
+
r: c2.r,
|
|
103
|
+
g: c2.g,
|
|
104
|
+
b: c2.b
|
|
105
|
+
}) * 255;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { clearNodeFillOkHCL, clearNodeStrokeOkHCL, colorDistance, colorSchema, colorToCSS, colorToCSSCompact, colorToDisplayCSS, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToRgba255, compositeOver, contrastRatio, darkenForContrast, getDefaultRenderColorSpace, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, normalizeColor, okhclToRGBA, parseColor, parseDisplayableColor, parseOkHCLPayload, readableForeground, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview, rgba255ToColor, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL, tryParseColor };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/color/index.ts"],"sourcesContent":["export * from './contrast'\nexport * from './management'\nexport { normalizeColor } from './normalize'\nexport * from './okhcl'\n\nimport { parse, formatHex, formatHex8, formatRgb, converter, differenceEuclidean } from 'culori'\n\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\n\nconst toRGB = converter('rgb')\n\n/** A CSS color, or null when `input` is not one. */\nexport function tryParseColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n const rgb = toRGB(parsed)\n return {\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: parsed.alpha ?? 1\n }\n}\n\n/** A CSS color, or black when `input` is not one. */\nexport function parseColor(input: string): Color {\n return tryParseColor(input) ?? { ...BLACK }\n}\n\nexport function colorToHex(color: Color): string {\n return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()\n}\n\nexport function colorToHex8(color: Color, alpha?: number): string {\n const a = alpha ?? color.a\n if (a >= 1) return colorToHex(color)\n return formatHex8({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: a }).toUpperCase()\n}\n\nexport function colorToHexRaw(color: Color): string {\n return colorToHex(color).slice(1)\n}\n\nexport function colorToRgba255(color: Color) {\n return {\n r: Math.round(color.r * 255),\n g: Math.round(color.g * 255),\n b: Math.round(color.b * 255),\n a: color.a\n }\n}\n\nexport function colorToCSS(color: Color): string {\n return formatRgb({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nexport function colorToCSSCompact(color: Color): string {\n const { r, g, b } = colorToRgba255(color)\n const a = Number(color.a.toFixed(3))\n if (a >= 1) return `rgb(${r},${g},${b})`\n return `rgba(${r},${g},${b},${a})`\n}\n\nexport function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {\n return { r: r / 255, g: g / 255, b: b / 255, a }\n}\n\nexport function colorToFill(color: string | Color) {\n const rgba = typeof color === 'string' ? parseColor(color) : color\n return {\n type: 'SOLID' as const,\n color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },\n opacity: rgba.a,\n visible: true\n }\n}\n\nconst euclideanRGB255 = differenceEuclidean('rgb')\n\nexport function colorDistance(c1: Color, c2: Color): number {\n return (\n euclideanRGB255(\n { mode: 'rgb', r: c1.r, g: c1.g, b: c1.b },\n { mode: 'rgb', r: c2.r, g: c2.g, b: c2.b }\n ) * 255\n )\n}\nexport * from './schema'\n"],"mappings":";;;;;;;;AAUA,MAAM,QAAQ,UAAU,KAAK;;AAG7B,SAAgB,cAAc,OAA6B;CACzD,MAAM,SAAS,MAAM,KAAK;CAC1B,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,MAAM,MAAM,MAAM;CACxB,OAAO;EACL,GAAG,IAAI;EACP,GAAG,IAAI;EACP,GAAG,IAAI;EACP,GAAG,OAAO,SAAS;CACrB;AACF;;AAGA,SAAgB,WAAW,OAAsB;CAC/C,OAAO,cAAc,KAAK,KAAK,EAAE,GAAG,MAAM;AAC5C;AAEA,SAAgB,WAAW,OAAsB;CAC/C,OAAO,UAAU;EAAE,MAAM;EAAO,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;CAAE,CAAC,CAAC,CAAC,YAAY;AACpF;AAEA,SAAgB,YAAY,OAAc,OAAwB;CAChE,MAAM,IAAI,SAAS,MAAM;CACzB,IAAI,KAAK,GAAG,OAAO,WAAW,KAAK;CACnC,OAAO,WAAW;EAAE,MAAM;EAAO,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,OAAO;CAAE,CAAC,CAAC,CAAC,YAAY;AAC/F;AAEA,SAAgB,cAAc,OAAsB;CAClD,OAAO,WAAW,KAAK,CAAC,CAAC,MAAM,CAAC;AAClC;AAEA,SAAgB,eAAe,OAAc;CAC3C,OAAO;EACL,GAAG,KAAK,MAAM,MAAM,IAAI,GAAG;EAC3B,GAAG,KAAK,MAAM,MAAM,IAAI,GAAG;EAC3B,GAAG,KAAK,MAAM,MAAM,IAAI,GAAG;EAC3B,GAAG,MAAM;CACX;AACF;AAEA,SAAgB,WAAW,OAAsB;CAC/C,OAAO,UAAU;EAAE,MAAM;EAAO,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,OAAO,MAAM;CAAE,CAAC;AACtF;AAEA,SAAgB,kBAAkB,OAAsB;CACtD,MAAM,EAAE,GAAG,GAAG,MAAM,eAAe,KAAK;CACxC,MAAM,IAAI,OAAO,MAAM,EAAE,QAAQ,CAAC,CAAC;CACnC,IAAI,KAAK,GAAG,OAAO,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE;CACtC,OAAO,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAClC;AAEA,SAAgB,eAAe,GAAW,GAAW,GAAW,IAAI,GAAU;CAC5E,OAAO;EAAE,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK;CAAE;AACjD;AAEA,SAAgB,YAAY,OAAuB;CACjD,MAAM,OAAO,OAAO,UAAU,WAAW,WAAW,KAAK,IAAI;CAC7D,OAAO;EACL,MAAM;EACN,OAAO;GAAE,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;EAAE;EACpD,SAAS,KAAK;EACd,SAAS;CACX;AACF;AAEA,MAAM,kBAAkB,oBAAoB,KAAK;AAEjD,SAAgB,cAAc,IAAW,IAAmB;CAC1D,OACE,gBACE;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,GACzC;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,CAC3C,IAAI;AAER"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Color } from "../primitives/index.js";
|
|
2
|
+
import { DocumentColorSpace, Fill, SceneNode, Stroke } from "../types.js";
|
|
3
|
+
import { OkHCLColor } from "./okhcl.js";
|
|
4
|
+
//#region src/color/management.d.ts
|
|
5
|
+
type RenderColorSpace = 'srgb' | 'display-p3';
|
|
6
|
+
type ColorIntentSpace = 'oklch' | 'srgb';
|
|
7
|
+
interface ColorPreviewOptions {
|
|
8
|
+
colorSpace?: RenderColorSpace;
|
|
9
|
+
documentColorSpace?: DocumentColorSpace;
|
|
10
|
+
}
|
|
11
|
+
interface ResolvedRenderColor {
|
|
12
|
+
color: Color;
|
|
13
|
+
cssColor: string;
|
|
14
|
+
sourceSpace: ColorIntentSpace;
|
|
15
|
+
targetSpace: RenderColorSpace;
|
|
16
|
+
clipped: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare function resolveOkHCLForPreview(color: OkHCLColor, options?: ColorPreviewOptions): ResolvedRenderColor;
|
|
19
|
+
/**
|
|
20
|
+
* A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing
|
|
21
|
+
* chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing
|
|
22
|
+
* (`none`) component reads as zero. Null when `input` is not a color.
|
|
23
|
+
*/
|
|
24
|
+
declare function parseDisplayableColor(input: string): Color | null;
|
|
25
|
+
declare function resolveRGBAForPreview(color: Color, options?: ColorPreviewOptions): ResolvedRenderColor;
|
|
26
|
+
declare function resolveNodeFillColor(fill: Fill, fillIndex: number, node: SceneNode, options?: ColorPreviewOptions): ResolvedRenderColor;
|
|
27
|
+
declare function resolveNodeStrokeColor(stroke: Stroke, strokeIndex: number, node: SceneNode, options?: ColorPreviewOptions): ResolvedRenderColor;
|
|
28
|
+
declare function colorToDisplayCSS(color: Color, options?: ColorPreviewOptions): string;
|
|
29
|
+
declare function getDefaultRenderColorSpace(): RenderColorSpace;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ColorIntentSpace, ColorPreviewOptions, RenderColorSpace, ResolvedRenderColor, colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview };
|
|
32
|
+
//# sourceMappingURL=management.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"management.d.ts","names":[],"sources":["../../src/color/management.ts"],"mappings":";;;;KAOY;KACA;UAEK;EACf,aAAa;EACb,qBAAqB;;UAGN;EACf,OAAO;EACP;EACA,aAAa;EACb,aAAa;EACb;;iBA0Ec,uBACd,OAAO,YACP,UAAU,sBACT;;;;;;iBA2Da,sBAAsB,gBAAgB;iBAStC,sBACd,OAAO,OACP,UAAU,sBACT;iBAaa,qBACd,MAAM,MACN,mBACA,MAAM,WACN,UAAU,sBACT;iBAMa,uBACd,QAAQ,QACR,qBACA,MAAM,WACN,UAAU,sBACT;iBAMa,kBAAkB,OAAO,OAAO,UAAU;iBAI1C,8BAA8B"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { normalizeColor } from "./normalize.js";
|
|
2
|
+
import { getFillOkHCL, getStrokeOkHCL } from "./okhcl.js";
|
|
3
|
+
import { converter, formatCss, formatRgb, inGamut, parse, toGamut } from "culori";
|
|
4
|
+
//#region src/color/management.ts
|
|
5
|
+
const DEFAULT_COLOR_SPACE = "srgb";
|
|
6
|
+
const toRGB = converter("rgb");
|
|
7
|
+
const toP3 = converter("p3");
|
|
8
|
+
const toDisplayableRGB = toGamut("rgb", "oklch");
|
|
9
|
+
const toDisplayableP3 = toGamut("p3", "oklch");
|
|
10
|
+
const isDisplayableRGB = inGamut("rgb");
|
|
11
|
+
const isDisplayableP3 = inGamut("p3");
|
|
12
|
+
function normalizeOkLCH(color) {
|
|
13
|
+
const hue = color.h % 360;
|
|
14
|
+
return {
|
|
15
|
+
mode: "oklch",
|
|
16
|
+
l: Math.max(0, Math.min(1, color.l)),
|
|
17
|
+
c: Math.max(0, color.c),
|
|
18
|
+
h: hue < 0 ? hue + 360 : hue,
|
|
19
|
+
alpha: Math.max(0, Math.min(1, color.a ?? 1))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Numbers are stored in the document's profile, so painting into a surface with a different
|
|
24
|
+
* profile has to convert them. Same profile means no work, which is the common case.
|
|
25
|
+
*/
|
|
26
|
+
function convertComponents(color, from, to) {
|
|
27
|
+
if (from === to) return color;
|
|
28
|
+
const source = from === "display-p3" ? {
|
|
29
|
+
mode: "p3",
|
|
30
|
+
r: color.r,
|
|
31
|
+
g: color.g,
|
|
32
|
+
b: color.b,
|
|
33
|
+
alpha: color.a
|
|
34
|
+
} : {
|
|
35
|
+
mode: "rgb",
|
|
36
|
+
r: color.r,
|
|
37
|
+
g: color.g,
|
|
38
|
+
b: color.b,
|
|
39
|
+
alpha: color.a
|
|
40
|
+
};
|
|
41
|
+
const converted = to === "display-p3" ? toP3(source) : toRGB(source);
|
|
42
|
+
return normalizeColor({
|
|
43
|
+
r: converted.r,
|
|
44
|
+
g: converted.g,
|
|
45
|
+
b: converted.b,
|
|
46
|
+
a: converted.alpha ?? color.a
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function isOutsideGamut(color, space) {
|
|
50
|
+
if (space === "display-p3") return !isDisplayableP3({
|
|
51
|
+
mode: "p3",
|
|
52
|
+
r: color.r,
|
|
53
|
+
g: color.g,
|
|
54
|
+
b: color.b,
|
|
55
|
+
alpha: color.a
|
|
56
|
+
});
|
|
57
|
+
return !isDisplayableRGB({
|
|
58
|
+
mode: "rgb",
|
|
59
|
+
r: color.r,
|
|
60
|
+
g: color.g,
|
|
61
|
+
b: color.b,
|
|
62
|
+
alpha: color.a
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function resolveTargetSpace(options) {
|
|
66
|
+
return options?.colorSpace ?? options?.documentColorSpace ?? DEFAULT_COLOR_SPACE;
|
|
67
|
+
}
|
|
68
|
+
function formatCSSForTarget(color, targetSpace) {
|
|
69
|
+
if (targetSpace === "display-p3") {
|
|
70
|
+
const p3 = toP3({
|
|
71
|
+
mode: "rgb",
|
|
72
|
+
r: color.r,
|
|
73
|
+
g: color.g,
|
|
74
|
+
b: color.b,
|
|
75
|
+
alpha: color.a
|
|
76
|
+
});
|
|
77
|
+
return formatCss({
|
|
78
|
+
mode: "p3",
|
|
79
|
+
r: p3.r,
|
|
80
|
+
g: p3.g,
|
|
81
|
+
b: p3.b,
|
|
82
|
+
alpha: p3.alpha ?? color.a
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return formatRgb({
|
|
86
|
+
mode: "rgb",
|
|
87
|
+
r: color.r,
|
|
88
|
+
g: color.g,
|
|
89
|
+
b: color.b,
|
|
90
|
+
alpha: color.a
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function resolveOkHCLForPreview(color, options) {
|
|
94
|
+
const oklch = normalizeOkLCH(color);
|
|
95
|
+
const targetSpace = resolveTargetSpace(options);
|
|
96
|
+
if (targetSpace === "display-p3") {
|
|
97
|
+
const clipped = !isDisplayableP3(oklch);
|
|
98
|
+
const p3 = toP3(toDisplayableP3(oklch));
|
|
99
|
+
return {
|
|
100
|
+
color: normalizeColor({
|
|
101
|
+
r: p3.r,
|
|
102
|
+
g: p3.g,
|
|
103
|
+
b: p3.b,
|
|
104
|
+
a: p3.alpha ?? oklch.alpha
|
|
105
|
+
}),
|
|
106
|
+
cssColor: formatCss({
|
|
107
|
+
mode: "p3",
|
|
108
|
+
r: p3.r,
|
|
109
|
+
g: p3.g,
|
|
110
|
+
b: p3.b,
|
|
111
|
+
alpha: p3.alpha ?? oklch.alpha
|
|
112
|
+
}),
|
|
113
|
+
sourceSpace: "oklch",
|
|
114
|
+
targetSpace,
|
|
115
|
+
clipped
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const clipped = !isDisplayableRGB(oklch);
|
|
119
|
+
const rgb = toRGB(toDisplayableRGB(oklch));
|
|
120
|
+
const resolved = normalizeColor({
|
|
121
|
+
r: rgb.r,
|
|
122
|
+
g: rgb.g,
|
|
123
|
+
b: rgb.b,
|
|
124
|
+
a: rgb.alpha ?? oklch.alpha
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
color: resolved,
|
|
128
|
+
cssColor: formatRgb({
|
|
129
|
+
mode: "rgb",
|
|
130
|
+
r: resolved.r,
|
|
131
|
+
g: resolved.g,
|
|
132
|
+
b: resolved.b,
|
|
133
|
+
alpha: resolved.a
|
|
134
|
+
}),
|
|
135
|
+
sourceSpace: "oklch",
|
|
136
|
+
targetSpace,
|
|
137
|
+
clipped
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing
|
|
142
|
+
* chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing
|
|
143
|
+
* (`none`) component reads as zero. Null when `input` is not a color.
|
|
144
|
+
*/
|
|
145
|
+
function parseDisplayableColor(input) {
|
|
146
|
+
const parsed = parse(input);
|
|
147
|
+
if (!parsed) return null;
|
|
148
|
+
const rgb = isDisplayableRGB(parsed) ? toRGB(parsed) : toDisplayableRGB(parsed);
|
|
149
|
+
return normalizeColor({
|
|
150
|
+
r: rgb.r,
|
|
151
|
+
g: rgb.g,
|
|
152
|
+
b: rgb.b,
|
|
153
|
+
a: parsed.alpha
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function resolveRGBAForPreview(color, options) {
|
|
157
|
+
const documentColorSpace = options?.documentColorSpace ?? DEFAULT_COLOR_SPACE;
|
|
158
|
+
const targetSpace = options?.colorSpace ?? documentColorSpace;
|
|
159
|
+
const resolved = convertComponents(normalizeColor(color), documentColorSpace, targetSpace);
|
|
160
|
+
return {
|
|
161
|
+
color: resolved,
|
|
162
|
+
cssColor: formatCSSForTarget(resolved, targetSpace),
|
|
163
|
+
sourceSpace: "srgb",
|
|
164
|
+
targetSpace,
|
|
165
|
+
clipped: targetSpace !== documentColorSpace && isOutsideGamut(resolved, targetSpace)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function resolveNodeFillColor(fill, fillIndex, node, options) {
|
|
169
|
+
const okhcl = getFillOkHCL(node, fillIndex)?.color;
|
|
170
|
+
if (okhcl) return resolveOkHCLForPreview(okhcl, options);
|
|
171
|
+
return resolveRGBAForPreview(fill.color, options);
|
|
172
|
+
}
|
|
173
|
+
function resolveNodeStrokeColor(stroke, strokeIndex, node, options) {
|
|
174
|
+
const okhcl = getStrokeOkHCL(node, strokeIndex)?.color;
|
|
175
|
+
if (okhcl) return resolveOkHCLForPreview(okhcl, options);
|
|
176
|
+
return resolveRGBAForPreview(stroke.color, options);
|
|
177
|
+
}
|
|
178
|
+
function colorToDisplayCSS(color, options) {
|
|
179
|
+
return resolveRGBAForPreview(color, options).cssColor;
|
|
180
|
+
}
|
|
181
|
+
function getDefaultRenderColorSpace() {
|
|
182
|
+
return DEFAULT_COLOR_SPACE;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview };
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=management.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"management.js","names":[],"sources":["../../src/color/management.ts"],"sourcesContent":["import { converter, formatCss, formatRgb, inGamut, parse, toGamut } from 'culori'\n\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace, Fill, SceneNode, Stroke } from '../types'\nimport { normalizeColor } from './normalize'\nimport { getFillOkHCL, getStrokeOkHCL, type OkHCLColor } from './okhcl'\n\nexport type RenderColorSpace = 'srgb' | 'display-p3'\nexport type ColorIntentSpace = 'oklch' | 'srgb'\n\nexport interface ColorPreviewOptions {\n colorSpace?: RenderColorSpace\n documentColorSpace?: DocumentColorSpace\n}\n\nexport interface ResolvedRenderColor {\n color: Color\n cssColor: string\n sourceSpace: ColorIntentSpace\n targetSpace: RenderColorSpace\n clipped: boolean\n}\n\nconst DEFAULT_COLOR_SPACE: RenderColorSpace = 'srgb'\n\nconst toRGB = converter('rgb')\nconst toP3 = converter('p3')\nconst toDisplayableRGB = toGamut('rgb', 'oklch')\nconst toDisplayableP3 = toGamut('p3', 'oklch')\nconst isDisplayableRGB = inGamut('rgb')\nconst isDisplayableP3 = inGamut('p3')\n\nfunction normalizeOkLCH(color: OkHCLColor) {\n const hue = color.h % 360\n return {\n mode: 'oklch' as const,\n l: Math.max(0, Math.min(1, color.l)),\n c: Math.max(0, color.c),\n h: hue < 0 ? hue + 360 : hue,\n alpha: Math.max(0, Math.min(1, color.a ?? 1))\n }\n}\n\n/**\n * Numbers are stored in the document's profile, so painting into a surface with a different\n * profile has to convert them. Same profile means no work, which is the common case.\n */\nfunction convertComponents(color: Color, from: RenderColorSpace, to: RenderColorSpace): Color {\n if (from === to) return color\n const source =\n from === 'display-p3'\n ? { mode: 'p3' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }\n : { mode: 'rgb' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }\n const converted = to === 'display-p3' ? toP3(source) : toRGB(source)\n return normalizeColor({\n r: converted.r,\n g: converted.g,\n b: converted.b,\n a: converted.alpha ?? color.a\n })\n}\n\nfunction isOutsideGamut(color: Color, space: RenderColorSpace): boolean {\n if (space === 'display-p3') {\n return !isDisplayableP3({ mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a })\n }\n return !isDisplayableRGB({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nfunction resolveTargetSpace(options?: ColorPreviewOptions): RenderColorSpace {\n return options?.colorSpace ?? options?.documentColorSpace ?? DEFAULT_COLOR_SPACE\n}\n\nfunction formatCSSForTarget(color: Color, targetSpace: RenderColorSpace): string {\n if (targetSpace === 'display-p3') {\n const p3 = toP3({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n return formatCss({\n mode: 'p3',\n r: p3.r,\n g: p3.g,\n b: p3.b,\n alpha: p3.alpha ?? color.a\n })\n }\n\n return formatRgb({\n mode: 'rgb',\n r: color.r,\n g: color.g,\n b: color.b,\n alpha: color.a\n })\n}\n\nexport function resolveOkHCLForPreview(\n color: OkHCLColor,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const oklch = normalizeOkLCH(color)\n const targetSpace = resolveTargetSpace(options)\n\n if (targetSpace === 'display-p3') {\n const clipped = !isDisplayableP3(oklch)\n const p3 = toP3(toDisplayableP3(oklch))\n // P3 coordinates, because the caller asked for a P3 target.\n const resolved = normalizeColor({\n r: p3.r,\n g: p3.g,\n b: p3.b,\n a: p3.alpha ?? oklch.alpha\n })\n\n return {\n color: resolved,\n cssColor: formatCss({\n mode: 'p3',\n r: p3.r,\n g: p3.g,\n b: p3.b,\n alpha: p3.alpha ?? oklch.alpha\n }),\n sourceSpace: 'oklch',\n targetSpace,\n clipped\n }\n }\n\n const clipped = !isDisplayableRGB(oklch)\n const rgb = toRGB(toDisplayableRGB(oklch))\n const resolved = normalizeColor({\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: rgb.alpha ?? oklch.alpha\n })\n\n return {\n color: resolved,\n cssColor: formatRgb({\n mode: 'rgb',\n r: resolved.r,\n g: resolved.g,\n b: resolved.b,\n alpha: resolved.a\n }),\n sourceSpace: 'oklch',\n targetSpace,\n clipped\n }\n}\n\n/**\n * A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing\n * chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing\n * (`none`) component reads as zero. Null when `input` is not a color.\n */\nexport function parseDisplayableColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n // Mapping through OKLCH shifts colors already in sRGB by float noise, so only map the rest.\n const rgb = isDisplayableRGB(parsed) ? toRGB(parsed) : toDisplayableRGB(parsed)\n // culori leaves a `none` channel out, which normalizing reads as zero.\n return normalizeColor({ r: rgb.r, g: rgb.g, b: rgb.b, a: parsed.alpha })\n}\n\nexport function resolveRGBAForPreview(\n color: Color,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const documentColorSpace = options?.documentColorSpace ?? DEFAULT_COLOR_SPACE\n const targetSpace = options?.colorSpace ?? documentColorSpace\n const resolved = convertComponents(normalizeColor(color), documentColorSpace, targetSpace)\n return {\n color: resolved,\n cssColor: formatCSSForTarget(resolved, targetSpace),\n sourceSpace: 'srgb',\n targetSpace,\n clipped: targetSpace !== documentColorSpace && isOutsideGamut(resolved, targetSpace)\n }\n}\n\nexport function resolveNodeFillColor(\n fill: Fill,\n fillIndex: number,\n node: SceneNode,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const okhcl = getFillOkHCL(node, fillIndex)?.color\n if (okhcl) return resolveOkHCLForPreview(okhcl, options)\n return resolveRGBAForPreview(fill.color, options)\n}\n\nexport function resolveNodeStrokeColor(\n stroke: Stroke,\n strokeIndex: number,\n node: SceneNode,\n options?: ColorPreviewOptions\n): ResolvedRenderColor {\n const okhcl = getStrokeOkHCL(node, strokeIndex)?.color\n if (okhcl) return resolveOkHCLForPreview(okhcl, options)\n return resolveRGBAForPreview(stroke.color, options)\n}\n\nexport function colorToDisplayCSS(color: Color, options?: ColorPreviewOptions): string {\n return resolveRGBAForPreview(color, options).cssColor\n}\n\nexport function getDefaultRenderColorSpace(): RenderColorSpace {\n return DEFAULT_COLOR_SPACE\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","names":[],"sources":["../../src/color/normalize.ts"],"mappings":";;iBAGgB,eAAe,QAAQ,QAAQ,SAAS"}
|