@pairdraw/scene-graph 0.0.0-stage → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +13 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +78 -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 +352 -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 +123 -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,109 @@
|
|
|
1
|
+
import { TRANSPARENT } from "../constants.js";
|
|
2
|
+
import { randomHex } from "../random.js";
|
|
3
|
+
import { readAllPluginData, withAllPluginData } from "../plugin-data/field.js";
|
|
4
|
+
import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
5
|
+
import { sha1 } from "@noble/hashes/legacy.js";
|
|
6
|
+
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
7
|
+
//#region src/shaders/model.ts
|
|
8
|
+
/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */
|
|
9
|
+
function readShaderPaints(node) {
|
|
10
|
+
return readAllPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.shader);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.
|
|
14
|
+
* Null for any other paint, including one whose image was replaced, which then draws as the
|
|
15
|
+
* image it holds.
|
|
16
|
+
*/
|
|
17
|
+
function shaderOfPaint(node, paint) {
|
|
18
|
+
if (paint.type !== "IMAGE" || !paint.imageHash) return null;
|
|
19
|
+
return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null;
|
|
20
|
+
}
|
|
21
|
+
/** Whether any paint of `node` draws a shader. */
|
|
22
|
+
function hasShaderPaint(node) {
|
|
23
|
+
return [...node.fills, ...node.strokes].some((paint) => shaderOfPaint(node, paint) !== null);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The node's plugin data with `shaders` set by their image, keeping only shaders a fill or
|
|
27
|
+
* stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
|
|
28
|
+
*/
|
|
29
|
+
function withShaderPaints(node, paints, shaders = []) {
|
|
30
|
+
const shown = new Set(paints.flatMap((paint) => paint.type === "IMAGE" && paint.imageHash ? [paint.imageHash] : []));
|
|
31
|
+
const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]));
|
|
32
|
+
for (const shader of shaders) byImage.set(shader.image, shader);
|
|
33
|
+
return withAllPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.shader, [...byImage.values()].filter((shader) => shown.has(shader.image)));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet
|
|
37
|
+
* rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.
|
|
38
|
+
*/
|
|
39
|
+
function createShaderPaint(preset) {
|
|
40
|
+
const image = randomHex(20);
|
|
41
|
+
return {
|
|
42
|
+
paint: {
|
|
43
|
+
type: "IMAGE",
|
|
44
|
+
color: TRANSPARENT,
|
|
45
|
+
opacity: 1,
|
|
46
|
+
visible: true,
|
|
47
|
+
imageHash: image,
|
|
48
|
+
imageScaleMode: "FILL"
|
|
49
|
+
},
|
|
50
|
+
shader: {
|
|
51
|
+
image,
|
|
52
|
+
preset: structuredClone(preset)
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A new paint that draws shader `source`, and the shader entry it shows. It starts as a shader
|
|
58
|
+
* paint of the same image, so replacing a preset keeps the layer's paint and frame. A caller
|
|
59
|
+
* reading one back from a file passes the `image` it recorded, so reading it again keeps it.
|
|
60
|
+
*/
|
|
61
|
+
function createShaderSourcePaint(source, image = randomHex(20)) {
|
|
62
|
+
return {
|
|
63
|
+
paint: {
|
|
64
|
+
type: "IMAGE",
|
|
65
|
+
color: TRANSPARENT,
|
|
66
|
+
opacity: 1,
|
|
67
|
+
visible: true,
|
|
68
|
+
imageHash: image,
|
|
69
|
+
imageScaleMode: "FILL"
|
|
70
|
+
},
|
|
71
|
+
shader: {
|
|
72
|
+
image,
|
|
73
|
+
source,
|
|
74
|
+
uniforms: {}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** A short key that tells one preset from another, which a rendered frame records. */
|
|
79
|
+
function shaderPresetKey(preset) {
|
|
80
|
+
return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))));
|
|
81
|
+
}
|
|
82
|
+
/** A short key that tells one shader source from another, which a rendered frame records. */
|
|
83
|
+
function shaderSourceKey(source) {
|
|
84
|
+
return bytesToHex(sha1(utf8ToBytes(source)));
|
|
85
|
+
}
|
|
86
|
+
/** Whether the shader draws a library preset, so `preset` is present. */
|
|
87
|
+
function isShaderPresetPaint(shader) {
|
|
88
|
+
return "preset" in shader;
|
|
89
|
+
}
|
|
90
|
+
/** Whether the shader draws code the user wrote, so `source` is present. */
|
|
91
|
+
function isShaderSourcePaint(shader) {
|
|
92
|
+
return "source" in shader;
|
|
93
|
+
}
|
|
94
|
+
/** The key of what a shader draws, which its still frame records. */
|
|
95
|
+
function shaderFrameKey(shader) {
|
|
96
|
+
return isShaderSourcePaint(shader) ? shaderSourceKey(shader.source) : shaderPresetKey(shader.preset);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a
|
|
100
|
+
* preset change after reopening the document does not keep a frame of the newer preset.
|
|
101
|
+
*/
|
|
102
|
+
function isShaderFrameCurrent(shader, size) {
|
|
103
|
+
const { frame } = shader;
|
|
104
|
+
return frame !== void 0 && frame.preset === shaderFrameKey(shader) && Math.round(frame.width) === Math.round(size.width) && Math.round(frame.height) === Math.round(size.height);
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, readShaderPaints, shaderFrameKey, shaderOfPaint, shaderPresetKey, shaderSourceKey, withShaderPaints };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\nimport { TRANSPARENT } from '../constants'\nimport { readAllPluginData, withAllPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport { randomHex } from '../random'\nimport type { Fill, SceneNode } from '../types'\nimport type { ShaderPaint, ShaderPreset, ShaderPresetPaint, ShaderSourcePaint } from './schema'\n\n/** What shader paints read of a node. */\ntype ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>\n\n/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */\nexport function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[] {\n return readAllPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.shader)\n}\n\n/**\n * The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.\n * Null for any other paint, including one whose image was replaced, which then draws as the\n * image it holds.\n */\nexport function shaderOfPaint(\n node: Pick<SceneNode, 'pluginData'>,\n paint: Fill\n): ShaderPaint | null {\n if (paint.type !== 'IMAGE' || !paint.imageHash) return null\n return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null\n}\n\n/** Whether any paint of `node` draws a shader. */\nexport function hasShaderPaint(node: ShaderNode): boolean {\n return [...node.fills, ...node.strokes].some((paint) => shaderOfPaint(node, paint) !== null)\n}\n\n/**\n * The node's plugin data with `shaders` set by their image, keeping only shaders a fill or\n * stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.\n */\nexport function withShaderPaints(\n node: Pick<SceneNode, 'pluginData'>,\n paints: readonly Fill[],\n shaders: readonly ShaderPaint[] = []\n): SceneNode['pluginData'] {\n const shown = new Set(\n paints.flatMap((paint) => (paint.type === 'IMAGE' && paint.imageHash ? [paint.imageHash] : []))\n )\n const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]))\n for (const shader of shaders) byImage.set(shader.image, shader)\n return withAllPluginData(\n node.pluginData,\n PAIRDRAW_PLUGIN_DATA.shader,\n [...byImage.values()].filter((shader) => shown.has(shader.image))\n )\n}\n\n/**\n * A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet\n * rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.\n */\nexport function createShaderPaint(preset: ShaderPreset): {\n paint: Fill\n shader: ShaderPaint\n} {\n const image = randomHex(20)\n return {\n paint: {\n type: 'IMAGE',\n color: TRANSPARENT,\n opacity: 1,\n visible: true,\n imageHash: image,\n imageScaleMode: 'FILL'\n },\n shader: { image, preset: structuredClone(preset) }\n }\n}\n\n/**\n * A new paint that draws shader `source`, and the shader entry it shows. It starts as a shader\n * paint of the same image, so replacing a preset keeps the layer's paint and frame. A caller\n * reading one back from a file passes the `image` it recorded, so reading it again keeps it.\n */\nexport function createShaderSourcePaint(\n source: string,\n image: string = randomHex(20)\n): {\n paint: Fill\n shader: ShaderSourcePaint\n} {\n return {\n paint: {\n type: 'IMAGE',\n color: TRANSPARENT,\n opacity: 1,\n visible: true,\n imageHash: image,\n imageScaleMode: 'FILL'\n },\n shader: { image, source, uniforms: {} }\n }\n}\n\n/** A short key that tells one preset from another, which a rendered frame records. */\nexport function shaderPresetKey(preset: ShaderPreset): string {\n return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))))\n}\n\n/** A short key that tells one shader source from another, which a rendered frame records. */\nexport function shaderSourceKey(source: string): string {\n return bytesToHex(sha1(utf8ToBytes(source)))\n}\n\n/** Whether the shader draws a library preset, so `preset` is present. */\nexport function isShaderPresetPaint(shader: ShaderPaint): shader is ShaderPresetPaint {\n return 'preset' in shader\n}\n\n/** Whether the shader draws code the user wrote, so `source` is present. */\nexport function isShaderSourcePaint(shader: ShaderPaint): shader is ShaderSourcePaint {\n return 'source' in shader\n}\n\n/** The key of what a shader draws, which its still frame records. */\nexport function shaderFrameKey(shader: ShaderPaint): string {\n return isShaderSourcePaint(shader)\n ? shaderSourceKey(shader.source)\n : shaderPresetKey(shader.preset)\n}\n\n/**\n * Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a\n * preset change after reopening the document does not keep a frame of the newer preset.\n */\nexport function isShaderFrameCurrent(\n shader: ShaderPaint,\n size: { width: number; height: number }\n): boolean {\n const { frame } = shader\n return (\n frame !== undefined &&\n frame.preset === shaderFrameKey(shader) &&\n Math.round(frame.width) === Math.round(size.width) &&\n Math.round(frame.height) === Math.round(size.height)\n )\n}\n"],"mappings":";;;;;;;;AAcA,SAAgB,iBAAiB,MAAoD;CACnF,OAAO,kBAAkB,KAAK,YAAY,qBAAqB,MAAM;AACvE;;;;;;AAOA,SAAgB,cACd,MACA,OACoB;CACpB,IAAI,MAAM,SAAS,WAAW,CAAC,MAAM,WAAW,OAAO;CACvD,OAAO,iBAAiB,IAAI,CAAC,CAAC,MAAM,WAAW,OAAO,UAAU,MAAM,SAAS,KAAK;AACtF;;AAGA,SAAgB,eAAe,MAA2B;CACxD,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG,KAAK,OAAO,CAAC,CAAC,MAAM,UAAU,cAAc,MAAM,KAAK,MAAM,IAAI;AAC7F;;;;;AAMA,SAAgB,iBACd,MACA,QACA,UAAkC,CAAC,GACV;CACzB,MAAM,QAAQ,IAAI,IAChB,OAAO,SAAS,UAAW,MAAM,SAAS,WAAW,MAAM,YAAY,CAAC,MAAM,SAAS,IAAI,CAAC,CAAE,CAChG;CACA,MAAM,UAAU,IAAI,IAAI,iBAAiB,IAAI,CAAC,CAAC,KAAK,WAAW,CAAC,OAAO,OAAO,MAAM,CAAC,CAAC;CACtF,KAAK,MAAM,UAAU,SAAS,QAAQ,IAAI,OAAO,OAAO,MAAM;CAC9D,OAAO,kBACL,KAAK,YACL,qBAAqB,QACrB,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC,QAAQ,WAAW,MAAM,IAAI,OAAO,KAAK,CAAC,CAClE;AACF;;;;;AAMA,SAAgB,kBAAkB,QAGhC;CACA,MAAM,QAAQ,UAAU,EAAE;CAC1B,OAAO;EACL,OAAO;GACL,MAAM;GACN,OAAO;GACP,SAAS;GACT,SAAS;GACT,WAAW;GACX,gBAAgB;EAClB;EACA,QAAQ;GAAE;GAAO,QAAQ,gBAAgB,MAAM;EAAE;CACnD;AACF;;;;;;AAOA,SAAgB,wBACd,QACA,QAAgB,UAAU,EAAE,GAI5B;CACA,OAAO;EACL,OAAO;GACL,MAAM;GACN,OAAO;GACP,SAAS;GACT,SAAS;GACT,WAAW;GACX,gBAAgB;EAClB;EACA,QAAQ;GAAE;GAAO;GAAQ,UAAU,CAAC;EAAE;CACxC;AACF;;AAGA,SAAgB,gBAAgB,QAA8B;CAC5D,OAAO,WAAW,KAAK,YAAY,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC;AAC7D;;AAGA,SAAgB,gBAAgB,QAAwB;CACtD,OAAO,WAAW,KAAK,YAAY,MAAM,CAAC,CAAC;AAC7C;;AAGA,SAAgB,oBAAoB,QAAkD;CACpF,OAAO,YAAY;AACrB;;AAGA,SAAgB,oBAAoB,QAAkD;CACpF,OAAO,YAAY;AACrB;;AAGA,SAAgB,eAAe,QAA6B;CAC1D,OAAO,oBAAoB,MAAM,IAC7B,gBAAgB,OAAO,MAAM,IAC7B,gBAAgB,OAAO,MAAM;AACnC;;;;;AAMA,SAAgB,qBACd,QACA,MACS;CACT,MAAM,EAAE,UAAU;CAClB,OACE,UAAU,KAAA,KACV,MAAM,WAAW,eAAe,MAAM,KACtC,KAAK,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,KAAK,KACjD,KAAK,MAAM,MAAM,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM;AAEvD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/shaders/schema.d.ts
|
|
3
|
+
/** One effect of a shader preset, as the `shaders` library names it, with the effects it holds. */
|
|
4
|
+
interface ShaderComponent {
|
|
5
|
+
type: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
props?: Record<string, unknown>;
|
|
8
|
+
children?: ShaderComponent[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A shader as the `shaders` library describes it and shaders.com exports it: a tree of effects,
|
|
12
|
+
* drawn first to last.
|
|
13
|
+
*/
|
|
14
|
+
declare const shaderPresetSchema: v.ObjectSchema<{
|
|
15
|
+
readonly components: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, ShaderComponent>, undefined>, v.MinLengthAction<ShaderComponent[], 1, undefined>]>;
|
|
16
|
+
readonly structureVersion: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
17
|
+
}, undefined>;
|
|
18
|
+
type ShaderPreset = v.InferOutput<typeof shaderPresetSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* A value a shader uniform holds in the document: a number, a boolean, a hex color, or 2–4
|
|
21
|
+
* numbers. A uniform bound to a variable resolves to the same shape.
|
|
22
|
+
*/
|
|
23
|
+
declare const shaderUniformValueSchema: v.UnionSchema<[v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.StringSchema<undefined>, v.ArraySchema<v.NumberSchema<undefined>, undefined>], undefined>;
|
|
24
|
+
type ShaderUniformValue = v.InferOutput<typeof shaderUniformValueSchema>;
|
|
25
|
+
/** A paint that draws a shader preset as an image fill of its still frame. */
|
|
26
|
+
declare const shaderPresetPaintSchema: v.ObjectSchema<{
|
|
27
|
+
readonly image: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
28
|
+
readonly preset: v.ObjectSchema<{
|
|
29
|
+
readonly components: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, ShaderComponent>, undefined>, v.MinLengthAction<ShaderComponent[], 1, undefined>]>;
|
|
30
|
+
readonly structureVersion: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
31
|
+
}, undefined>;
|
|
32
|
+
readonly frame: v.OptionalSchema<v.ObjectSchema<{
|
|
33
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
34
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
35
|
+
readonly preset: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
36
|
+
}, undefined>, undefined>;
|
|
37
|
+
}, undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* A paint that draws shader code the user wrote. The renderer compiles it live; the uniform
|
|
40
|
+
* values are stored by name, and `uniformBindings` names the variables some of them follow.
|
|
41
|
+
*/
|
|
42
|
+
declare const shaderSourcePaintSchema: v.ObjectSchema<{
|
|
43
|
+
readonly image: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
44
|
+
readonly source: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
45
|
+
readonly uniforms: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.StringSchema<undefined>, v.ArraySchema<v.NumberSchema<undefined>, undefined>], undefined>, undefined>, undefined>;
|
|
46
|
+
readonly uniformBindings: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
47
|
+
readonly frame: v.OptionalSchema<v.ObjectSchema<{
|
|
48
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
49
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
50
|
+
readonly preset: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
51
|
+
}, undefined>, undefined>;
|
|
52
|
+
}, undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* A paint that draws a shader, either a library preset or shader code the user wrote. The paint
|
|
55
|
+
* itself is an image fill, so every format and renderer that reads images shows a shader's still
|
|
56
|
+
* frame; a source shader draws live where the canvas can compile it, and its still frame, which
|
|
57
|
+
* optional renderers may draw, keeps it visible everywhere else.
|
|
58
|
+
*/
|
|
59
|
+
declare const shaderPaintSchema: v.UnionSchema<[v.ObjectSchema<{
|
|
60
|
+
readonly image: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
61
|
+
readonly source: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
62
|
+
readonly uniforms: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.StringSchema<undefined>, v.ArraySchema<v.NumberSchema<undefined>, undefined>], undefined>, undefined>, undefined>;
|
|
63
|
+
readonly uniformBindings: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
64
|
+
readonly frame: v.OptionalSchema<v.ObjectSchema<{
|
|
65
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
66
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
67
|
+
readonly preset: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
68
|
+
}, undefined>, undefined>;
|
|
69
|
+
}, undefined>, v.ObjectSchema<{
|
|
70
|
+
readonly image: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
71
|
+
readonly preset: v.ObjectSchema<{
|
|
72
|
+
readonly components: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, ShaderComponent>, undefined>, v.MinLengthAction<ShaderComponent[], 1, undefined>]>;
|
|
73
|
+
readonly structureVersion: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
74
|
+
}, undefined>;
|
|
75
|
+
readonly frame: v.OptionalSchema<v.ObjectSchema<{
|
|
76
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
77
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
78
|
+
readonly preset: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
79
|
+
}, undefined>, undefined>;
|
|
80
|
+
}, undefined>], undefined>;
|
|
81
|
+
type ShaderPaint = v.InferOutput<typeof shaderPaintSchema>;
|
|
82
|
+
type ShaderPresetPaint = v.InferOutput<typeof shaderPresetPaintSchema>;
|
|
83
|
+
type ShaderSourcePaint = v.InferOutput<typeof shaderSourcePaintSchema>;
|
|
84
|
+
//#endregion
|
|
85
|
+
export { ShaderComponent, ShaderPaint, ShaderPreset, ShaderPresetPaint, ShaderSourcePaint, ShaderUniformValue, shaderPaintSchema, shaderPresetPaintSchema, shaderPresetSchema, shaderSourcePaintSchema, shaderUniformValueSchema };
|
|
86
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/shaders/schema.ts"],"mappings":";;;UAGiB;EACf;EACA;EACA,QAAQ;EACR,WAAW;;;;;;cAcA,oBAAkB,EAAA;;;;KAKnB,eAAe,EAAE,mBAAmB;;;;;cAmBnC,0BAAwB,EAAA,aAAA,EAAA,yBAAA,EAAA,0BAAA,EAAA,yBAAA,EAAA,YAAA,EAAA;KAOzB,qBAAqB,EAAE,mBAAmB;;cAGzC,yBAAuB,EAAA;;;;;;;;;;;;;;;;cAUvB,yBAAuB,EAAA;;;;;;;;;;;;;;;;;cAcvB,mBAAiB,EAAA,aAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;KAElB,cAAc,EAAE,mBAAmB;KACnC,oBAAoB,EAAE,mBAAmB;KACzC,oBAAoB,EAAE,mBAAmB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/shaders/schema.ts
|
|
3
|
+
const shaderComponentSchema = v.object({
|
|
4
|
+
type: v.pipe(v.string(), v.nonEmpty(), v.maxLength(100)),
|
|
5
|
+
id: v.optional(v.string()),
|
|
6
|
+
props: v.optional(v.record(v.string(), v.unknown())),
|
|
7
|
+
children: v.optional(v.array(v.lazy(() => shaderComponentSchema)))
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* A shader as the `shaders` library describes it and shaders.com exports it: a tree of effects,
|
|
11
|
+
* drawn first to last.
|
|
12
|
+
*/
|
|
13
|
+
const shaderPresetSchema = v.object({
|
|
14
|
+
components: v.pipe(v.array(shaderComponentSchema), v.minLength(1)),
|
|
15
|
+
structureVersion: v.optional(v.number())
|
|
16
|
+
});
|
|
17
|
+
const shaderImageSchema = v.pipe(v.string(), v.nonEmpty());
|
|
18
|
+
/**
|
|
19
|
+
* The layer size a still frame was rendered for, and the key of what it was rendered from
|
|
20
|
+
* (`shaderPresetKey` for a preset, `shaderSourceKey` for user code), which is missing until the
|
|
21
|
+
* frame is first rendered.
|
|
22
|
+
*/
|
|
23
|
+
const shaderFrameSchema = v.object({
|
|
24
|
+
width: v.pipe(v.number(), v.finite(), v.minValue(0)),
|
|
25
|
+
height: v.pipe(v.number(), v.finite(), v.minValue(0)),
|
|
26
|
+
preset: v.pipe(v.string(), v.nonEmpty())
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* A value a shader uniform holds in the document: a number, a boolean, a hex color, or 2–4
|
|
30
|
+
* numbers. A uniform bound to a variable resolves to the same shape.
|
|
31
|
+
*/
|
|
32
|
+
const shaderUniformValueSchema = v.union([
|
|
33
|
+
v.number(),
|
|
34
|
+
v.boolean(),
|
|
35
|
+
v.string(),
|
|
36
|
+
v.array(v.number())
|
|
37
|
+
]);
|
|
38
|
+
/** A paint that draws a shader preset as an image fill of its still frame. */
|
|
39
|
+
const shaderPresetPaintSchema = v.object({
|
|
40
|
+
image: shaderImageSchema,
|
|
41
|
+
preset: shaderPresetSchema,
|
|
42
|
+
frame: v.optional(shaderFrameSchema)
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* A paint that draws shader code the user wrote. The renderer compiles it live; the uniform
|
|
46
|
+
* values are stored by name, and `uniformBindings` names the variables some of them follow.
|
|
47
|
+
*/
|
|
48
|
+
const shaderSourcePaintSchema = v.object({
|
|
49
|
+
image: shaderImageSchema,
|
|
50
|
+
source: v.pipe(v.string(), v.nonEmpty()),
|
|
51
|
+
uniforms: v.optional(v.record(v.string(), shaderUniformValueSchema)),
|
|
52
|
+
uniformBindings: v.optional(v.record(v.string(), v.string())),
|
|
53
|
+
frame: v.optional(shaderFrameSchema)
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* A paint that draws a shader, either a library preset or shader code the user wrote. The paint
|
|
57
|
+
* itself is an image fill, so every format and renderer that reads images shows a shader's still
|
|
58
|
+
* frame; a source shader draws live where the canvas can compile it, and its still frame, which
|
|
59
|
+
* optional renderers may draw, keeps it visible everywhere else.
|
|
60
|
+
*/
|
|
61
|
+
const shaderPaintSchema = v.union([shaderSourcePaintSchema, shaderPresetPaintSchema]);
|
|
62
|
+
//#endregion
|
|
63
|
+
export { shaderPaintSchema, shaderPresetPaintSchema, shaderPresetSchema, shaderSourcePaintSchema, shaderUniformValueSchema };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/shaders/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\n/** One effect of a shader preset, as the `shaders` library names it, with the effects it holds. */\nexport interface ShaderComponent {\n type: string\n id?: string\n props?: Record<string, unknown>\n children?: ShaderComponent[]\n}\n\nconst shaderComponentSchema: v.GenericSchema<unknown, ShaderComponent> = v.object({\n type: v.pipe(v.string(), v.nonEmpty(), v.maxLength(100)),\n id: v.optional(v.string()),\n props: v.optional(v.record(v.string(), v.unknown())),\n children: v.optional(v.array(v.lazy(() => shaderComponentSchema)))\n})\n\n/**\n * A shader as the `shaders` library describes it and shaders.com exports it: a tree of effects,\n * drawn first to last.\n */\nexport const shaderPresetSchema = v.object({\n components: v.pipe(v.array(shaderComponentSchema), v.minLength(1)),\n structureVersion: v.optional(v.number())\n})\n\nexport type ShaderPreset = v.InferOutput<typeof shaderPresetSchema>\n\nconst shaderImageSchema = v.pipe(v.string(), v.nonEmpty())\n\n/**\n * The layer size a still frame was rendered for, and the key of what it was rendered from\n * (`shaderPresetKey` for a preset, `shaderSourceKey` for user code), which is missing until the\n * frame is first rendered.\n */\nconst shaderFrameSchema = v.object({\n width: v.pipe(v.number(), v.finite(), v.minValue(0)),\n height: v.pipe(v.number(), v.finite(), v.minValue(0)),\n preset: v.pipe(v.string(), v.nonEmpty())\n})\n\n/**\n * A value a shader uniform holds in the document: a number, a boolean, a hex color, or 2–4\n * numbers. A uniform bound to a variable resolves to the same shape.\n */\nexport const shaderUniformValueSchema = v.union([\n v.number(),\n v.boolean(),\n v.string(),\n v.array(v.number())\n])\n\nexport type ShaderUniformValue = v.InferOutput<typeof shaderUniformValueSchema>\n\n/** A paint that draws a shader preset as an image fill of its still frame. */\nexport const shaderPresetPaintSchema = v.object({\n image: shaderImageSchema,\n preset: shaderPresetSchema,\n frame: v.optional(shaderFrameSchema)\n})\n\n/**\n * A paint that draws shader code the user wrote. The renderer compiles it live; the uniform\n * values are stored by name, and `uniformBindings` names the variables some of them follow.\n */\nexport const shaderSourcePaintSchema = v.object({\n image: shaderImageSchema,\n source: v.pipe(v.string(), v.nonEmpty()),\n uniforms: v.optional(v.record(v.string(), shaderUniformValueSchema)),\n uniformBindings: v.optional(v.record(v.string(), v.string())),\n frame: v.optional(shaderFrameSchema)\n})\n\n/**\n * A paint that draws a shader, either a library preset or shader code the user wrote. The paint\n * itself is an image fill, so every format and renderer that reads images shows a shader's still\n * frame; a source shader draws live where the canvas can compile it, and its still frame, which\n * optional renderers may draw, keeps it visible everywhere else.\n */\nexport const shaderPaintSchema = v.union([shaderSourcePaintSchema, shaderPresetPaintSchema])\n\nexport type ShaderPaint = v.InferOutput<typeof shaderPaintSchema>\nexport type ShaderPresetPaint = v.InferOutput<typeof shaderPresetPaintSchema>\nexport type ShaderSourcePaint = v.InferOutput<typeof shaderSourcePaintSchema>\n"],"mappings":";;AAUA,MAAM,wBAAmE,EAAE,OAAO;CAChF,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,GAAG,EAAE,UAAU,GAAG,CAAC;CACvD,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;CACzB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;CACnD,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,qBAAqB,CAAC,CAAC;AACnE,CAAC;;;;;AAMD,MAAa,qBAAqB,EAAE,OAAO;CACzC,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,GAAG,EAAE,UAAU,CAAC,CAAC;CACjE,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;AACzC,CAAC;AAID,MAAM,oBAAoB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;;;;;;AAOzD,MAAM,oBAAoB,EAAE,OAAO;CACjC,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;CACnD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;CACpD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;AACzC,CAAC;;;;;AAMD,MAAa,2BAA2B,EAAE,MAAM;CAC9C,EAAE,OAAO;CACT,EAAE,QAAQ;CACV,EAAE,OAAO;CACT,EAAE,MAAM,EAAE,OAAO,CAAC;AACpB,CAAC;;AAKD,MAAa,0BAA0B,EAAE,OAAO;CAC9C,OAAO;CACP,QAAQ;CACR,OAAO,EAAE,SAAS,iBAAiB;AACrC,CAAC;;;;;AAMD,MAAa,0BAA0B,EAAE,OAAO;CAC9C,OAAO;CACP,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACvC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,wBAAwB,CAAC;CACnE,iBAAiB,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;CAC5D,OAAO,EAAE,SAAS,iBAAiB;AACrC,CAAC;;;;;;;AAQD,MAAa,oBAAoB,EAAE,MAAM,CAAC,yBAAyB,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Size } from "../primitives/index.js";
|
|
2
|
+
//#region src/shaders/still.d.ts
|
|
3
|
+
/** The pixels a frame for a layer of `size` is drawn at. */
|
|
4
|
+
declare function shaderFramePixels(size: Size): Size;
|
|
5
|
+
interface ShaderFrameEncoding {
|
|
6
|
+
type: 'image/jpeg' | 'image/png';
|
|
7
|
+
/** For `canvas.toBlob` and `toDataURL`; PNG takes none. */
|
|
8
|
+
quality?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which
|
|
12
|
+
* is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind
|
|
13
|
+
* show through, which JPEG cannot keep.
|
|
14
|
+
*/
|
|
15
|
+
declare function shaderFrameEncoding(rgba: ArrayLike<number>): ShaderFrameEncoding;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ShaderFrameEncoding, shaderFrameEncoding, shaderFramePixels };
|
|
18
|
+
//# sourceMappingURL=still.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"still.d.ts","names":[],"sources":["../../src/shaders/still.ts"],"mappings":";;;iBAgBgB,kBAAkB,MAAM,OAAO;UAQ9B;EACf;;EAEA;;;;;;;iBAQc,oBAAoB,MAAM,oBAAoB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/shaders/still.ts
|
|
2
|
+
/**
|
|
3
|
+
* How a shader paint's still frame is drawn and stored, for every renderer that draws one: the
|
|
4
|
+
* editor's canvas and the tools that prebuild documents. The frame is an image fill in `.fig`
|
|
5
|
+
* files, so Figma must be able to read it, which rules out WebP.
|
|
6
|
+
*/
|
|
7
|
+
/** Frames are drawn at twice the layer's size, for sharp high-density displays. */
|
|
8
|
+
const FRAME_SCALE = 2;
|
|
9
|
+
/** The longest side a frame is drawn at, however large the layer. */
|
|
10
|
+
const MAX_FRAME_EDGE = 2048;
|
|
11
|
+
/** JPEG quality for opaque frames: no visible difference from PNG at a fraction of the size. */
|
|
12
|
+
const JPEG_QUALITY = .9;
|
|
13
|
+
/** The pixels a frame for a layer of `size` is drawn at. */
|
|
14
|
+
function shaderFramePixels(size) {
|
|
15
|
+
const scale = Math.min(FRAME_SCALE, MAX_FRAME_EDGE / Math.max(size.width, size.height, 1));
|
|
16
|
+
return {
|
|
17
|
+
width: Math.max(1, Math.round(size.width * scale)),
|
|
18
|
+
height: Math.max(1, Math.round(size.height * scale))
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which
|
|
23
|
+
* is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind
|
|
24
|
+
* show through, which JPEG cannot keep.
|
|
25
|
+
*/
|
|
26
|
+
function shaderFrameEncoding(rgba) {
|
|
27
|
+
for (let alpha = 3; alpha < rgba.length; alpha += 4) if (rgba[alpha] !== 255) return { type: "image/png" };
|
|
28
|
+
return {
|
|
29
|
+
type: "image/jpeg",
|
|
30
|
+
quality: JPEG_QUALITY
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { shaderFrameEncoding, shaderFramePixels };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=still.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"still.js","names":[],"sources":["../../src/shaders/still.ts"],"sourcesContent":["import type { Size } from '../primitives'\n\n/**\n * How a shader paint's still frame is drawn and stored, for every renderer that draws one: the\n * editor's canvas and the tools that prebuild documents. The frame is an image fill in `.fig`\n * files, so Figma must be able to read it, which rules out WebP.\n */\n\n/** Frames are drawn at twice the layer's size, for sharp high-density displays. */\nconst FRAME_SCALE = 2\n/** The longest side a frame is drawn at, however large the layer. */\nconst MAX_FRAME_EDGE = 2048\n/** JPEG quality for opaque frames: no visible difference from PNG at a fraction of the size. */\nconst JPEG_QUALITY = 0.9\n\n/** The pixels a frame for a layer of `size` is drawn at. */\nexport function shaderFramePixels(size: Size): Size {\n const scale = Math.min(FRAME_SCALE, MAX_FRAME_EDGE / Math.max(size.width, size.height, 1))\n return {\n width: Math.max(1, Math.round(size.width * scale)),\n height: Math.max(1, Math.round(size.height * scale))\n }\n}\n\nexport interface ShaderFrameEncoding {\n type: 'image/jpeg' | 'image/png'\n /** For `canvas.toBlob` and `toDataURL`; PNG takes none. */\n quality?: number\n}\n\n/**\n * The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which\n * is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind\n * show through, which JPEG cannot keep.\n */\nexport function shaderFrameEncoding(rgba: ArrayLike<number>): ShaderFrameEncoding {\n for (let alpha = 3; alpha < rgba.length; alpha += 4) {\n if (rgba[alpha] !== 255) return { type: 'image/png' }\n }\n return { type: 'image/jpeg', quality: JPEG_QUALITY }\n}\n"],"mappings":";;;;;;;AASA,MAAM,cAAc;;AAEpB,MAAM,iBAAiB;;AAEvB,MAAM,eAAe;;AAGrB,SAAgB,kBAAkB,MAAkB;CAClD,MAAM,QAAQ,KAAK,IAAI,aAAa,iBAAiB,KAAK,IAAI,KAAK,OAAO,KAAK,QAAQ,CAAC,CAAC;CACzF,OAAO;EACL,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,QAAQ,KAAK,CAAC;EACjD,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,SAAS,KAAK,CAAC;CACrD;AACF;;;;;;AAaA,SAAgB,oBAAoB,MAA8C;CAChF,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAChD,IAAI,KAAK,WAAW,KAAK,OAAO,EAAE,MAAM,YAAY;CAEtD,OAAO;EAAE,MAAM;EAAc,SAAS;CAAa;AACrD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ShapeWithTextType } from "./kinds.js";
|
|
2
|
+
//#region src/shape-with-text/fit.d.ts
|
|
3
|
+
/** The height of a database's elliptical cap: FigJam keeps it 24 px tall at any size. */
|
|
4
|
+
declare function databaseCap(w: number, h: number): number;
|
|
5
|
+
interface LabelBox {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
/** Where a shape's label sits inside its `width` × `height` box. */
|
|
12
|
+
declare function shapeWithTextLabelBox(type: ShapeWithTextType, width: number, height: number): LabelBox;
|
|
13
|
+
/** Measures a label wrapped at `maxWidth`; its height is what the wrapped lines take. */
|
|
14
|
+
type LabelMeasure = (maxWidth: number) => {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
};
|
|
18
|
+
/** Whether a kind grows for its label; FigJam keeps summing junctions and ors round. */
|
|
19
|
+
declare function shapeWithTextGrows(type: ShapeWithTextType): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The height a `width`-wide shape of `type` takes for its label, as FigJam fits it: the height it
|
|
22
|
+
* was given while the label fits its label box, else the smallest whole height whose label box
|
|
23
|
+
* holds the label. FigJam never widens a shape for its label; a word too long for it breaks.
|
|
24
|
+
*/
|
|
25
|
+
declare function fitShapeWithTextHeight(type: ShapeWithTextType, width: number, height: number, measure: LabelMeasure): number;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { LabelBox, LabelMeasure, databaseCap, fitShapeWithTextHeight, shapeWithTextGrows, shapeWithTextLabelBox };
|
|
28
|
+
//# sourceMappingURL=fit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit.d.ts","names":[],"sources":["../../src/shape-with-text/fit.ts"],"mappings":";;;iBAGgB,YAAY,WAAW;UAItB;EACf;EACA;EACA;EACA;;;iBAgFc,sBACd,MAAM,mBACN,eACA,iBACC;;KAkBS,gBAAgB;EAAuB;EAAe;;;iBAKlD,mBAAmB,MAAM;;;;;;iBASzB,uBACd,MAAM,mBACN,eACA,gBACA,SAAS"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
//#region src/shape-with-text/fit.ts
|
|
2
|
+
/** The height of a database's elliptical cap: FigJam keeps it 24 px tall at any size. */
|
|
3
|
+
function databaseCap(w, h) {
|
|
4
|
+
return Math.min(24, h * .25, w * .25);
|
|
5
|
+
}
|
|
6
|
+
/** The 16 px FigJam leaves around a label, 8 px on a shape less than 100 px on a side. */
|
|
7
|
+
function labelPadding(width, height) {
|
|
8
|
+
return Math.min(width, height) < 100 ? 8 : 16;
|
|
9
|
+
}
|
|
10
|
+
/** FigJam doubles some kinds' insets on a shape 300 px wide or more. */
|
|
11
|
+
function wide(width) {
|
|
12
|
+
return width >= 300;
|
|
13
|
+
}
|
|
14
|
+
/** A triangle's label sits under its middle, 4 px in from its sides; returns its top and bottom. */
|
|
15
|
+
function triangleInsets(width, height) {
|
|
16
|
+
const lean = 4 * height / width;
|
|
17
|
+
return [height / 2 + lean, 8 + lean];
|
|
18
|
+
}
|
|
19
|
+
/** The rectangle inscribed in an ellipse, its width rounded to a whole pixel. */
|
|
20
|
+
const ellipseInsets = (width, height) => {
|
|
21
|
+
const label = Math.round(width / Math.SQRT2);
|
|
22
|
+
const x = (width - label) / 2;
|
|
23
|
+
const y = (height - height * Math.sqrt(1 - (label / width) ** 2)) / 2;
|
|
24
|
+
return [
|
|
25
|
+
x,
|
|
26
|
+
y,
|
|
27
|
+
x,
|
|
28
|
+
y
|
|
29
|
+
];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The px FigJam leaves free on each side of a label in each kind, measured from its saved label
|
|
33
|
+
* layouts. Insets that scale do so with the side they lie along.
|
|
34
|
+
*/
|
|
35
|
+
const LABEL_INSETS = {
|
|
36
|
+
SQUARE: (_w, _h, p) => [
|
|
37
|
+
p,
|
|
38
|
+
p,
|
|
39
|
+
p,
|
|
40
|
+
p
|
|
41
|
+
],
|
|
42
|
+
ROUNDED_RECTANGLE: (w, _h, p) => {
|
|
43
|
+
const inset = wide(w) ? p * 2 : p;
|
|
44
|
+
return [
|
|
45
|
+
inset,
|
|
46
|
+
inset,
|
|
47
|
+
inset,
|
|
48
|
+
inset
|
|
49
|
+
];
|
|
50
|
+
},
|
|
51
|
+
ELLIPSE: ellipseInsets,
|
|
52
|
+
SUMMING_JUNCTION: ellipseInsets,
|
|
53
|
+
OR: ellipseInsets,
|
|
54
|
+
DIAMOND: (w, h) => [
|
|
55
|
+
w / 4 + 4,
|
|
56
|
+
h / 4 + 4,
|
|
57
|
+
w / 4 + 4,
|
|
58
|
+
h / 4 + 4
|
|
59
|
+
],
|
|
60
|
+
TRIANGLE_UP: (w, h) => {
|
|
61
|
+
const [apex, base] = triangleInsets(w, h);
|
|
62
|
+
return [
|
|
63
|
+
w / 4,
|
|
64
|
+
apex,
|
|
65
|
+
w / 4,
|
|
66
|
+
base
|
|
67
|
+
];
|
|
68
|
+
},
|
|
69
|
+
TRIANGLE_DOWN: (w, h) => {
|
|
70
|
+
const [apex, base] = triangleInsets(w, h);
|
|
71
|
+
return [
|
|
72
|
+
w / 4,
|
|
73
|
+
base,
|
|
74
|
+
w / 4,
|
|
75
|
+
apex
|
|
76
|
+
];
|
|
77
|
+
},
|
|
78
|
+
PARALLELOGRAM_RIGHT: (w, _h, p) => [
|
|
79
|
+
13 * w / 62 + 6,
|
|
80
|
+
p,
|
|
81
|
+
13 * w / 62 + 6,
|
|
82
|
+
p
|
|
83
|
+
],
|
|
84
|
+
PARALLELOGRAM_LEFT: (w, _h, p) => [
|
|
85
|
+
13 * w / 62 + 6,
|
|
86
|
+
p,
|
|
87
|
+
13 * w / 62 + 6,
|
|
88
|
+
p
|
|
89
|
+
],
|
|
90
|
+
ENG_DATABASE: (w, h, p) => [
|
|
91
|
+
p,
|
|
92
|
+
databaseCap(w, h) * 2 + p,
|
|
93
|
+
p,
|
|
94
|
+
databaseCap(w, h)
|
|
95
|
+
],
|
|
96
|
+
ENG_QUEUE: (_w, _h, p) => [
|
|
97
|
+
24,
|
|
98
|
+
p,
|
|
99
|
+
64,
|
|
100
|
+
p
|
|
101
|
+
],
|
|
102
|
+
ENG_FILE: (_w, _h, p) => [
|
|
103
|
+
p,
|
|
104
|
+
64,
|
|
105
|
+
p,
|
|
106
|
+
64
|
|
107
|
+
],
|
|
108
|
+
ENG_FOLDER: (_w, _h, p) => [
|
|
109
|
+
p,
|
|
110
|
+
60,
|
|
111
|
+
p,
|
|
112
|
+
p
|
|
113
|
+
],
|
|
114
|
+
TRAPEZOID: (w, _h, p) => [
|
|
115
|
+
16 * w / 121,
|
|
116
|
+
p,
|
|
117
|
+
16 * w / 121,
|
|
118
|
+
p
|
|
119
|
+
],
|
|
120
|
+
HEXAGON: (w, _h, p) => [
|
|
121
|
+
8 * w / 121,
|
|
122
|
+
p,
|
|
123
|
+
8 * w / 121,
|
|
124
|
+
p
|
|
125
|
+
],
|
|
126
|
+
PREDEFINED_PROCESS: (w) => wide(w) ? [
|
|
127
|
+
48,
|
|
128
|
+
24,
|
|
129
|
+
48,
|
|
130
|
+
24
|
|
131
|
+
] : [
|
|
132
|
+
32,
|
|
133
|
+
16,
|
|
134
|
+
32,
|
|
135
|
+
16
|
|
136
|
+
],
|
|
137
|
+
INTERNAL_STORAGE: (w) => wide(w) ? [
|
|
138
|
+
40,
|
|
139
|
+
40,
|
|
140
|
+
24,
|
|
141
|
+
24
|
|
142
|
+
] : [
|
|
143
|
+
24,
|
|
144
|
+
24,
|
|
145
|
+
16,
|
|
146
|
+
16
|
|
147
|
+
],
|
|
148
|
+
SHIELD: (_w, h, p) => [
|
|
149
|
+
p,
|
|
150
|
+
h * .075,
|
|
151
|
+
p,
|
|
152
|
+
h * .1977
|
|
153
|
+
],
|
|
154
|
+
DOCUMENT_SINGLE: (_w, _h, p) => [
|
|
155
|
+
p,
|
|
156
|
+
p,
|
|
157
|
+
p,
|
|
158
|
+
28
|
|
159
|
+
],
|
|
160
|
+
DOCUMENT_MULTIPLE: (_w, _h, p) => [
|
|
161
|
+
32,
|
|
162
|
+
p,
|
|
163
|
+
p,
|
|
164
|
+
28
|
|
165
|
+
],
|
|
166
|
+
MANUAL_INPUT: (_w, _h, p) => [
|
|
167
|
+
p,
|
|
168
|
+
24,
|
|
169
|
+
p,
|
|
170
|
+
p
|
|
171
|
+
],
|
|
172
|
+
CHEVRON: (_w, _h, p) => [
|
|
173
|
+
43,
|
|
174
|
+
p,
|
|
175
|
+
43,
|
|
176
|
+
p
|
|
177
|
+
],
|
|
178
|
+
PENTAGON: (w, h) => [
|
|
179
|
+
w * .115,
|
|
180
|
+
h * .27403,
|
|
181
|
+
w * .115,
|
|
182
|
+
h * .08454
|
|
183
|
+
],
|
|
184
|
+
OCTAGON: (w, h) => [
|
|
185
|
+
w * .11466,
|
|
186
|
+
h * .1193,
|
|
187
|
+
w * .11466,
|
|
188
|
+
h * .1193
|
|
189
|
+
],
|
|
190
|
+
STAR: (w, h) => [
|
|
191
|
+
w * .19531,
|
|
192
|
+
h * .3028,
|
|
193
|
+
w * .19531,
|
|
194
|
+
h * .109
|
|
195
|
+
],
|
|
196
|
+
PLUS: (_w, h, p) => [
|
|
197
|
+
p,
|
|
198
|
+
h * 5 / 18,
|
|
199
|
+
p,
|
|
200
|
+
h * 5 / 18
|
|
201
|
+
],
|
|
202
|
+
ARROW_LEFT: (_w, h, p) => [
|
|
203
|
+
54,
|
|
204
|
+
h * .25465,
|
|
205
|
+
p,
|
|
206
|
+
h * .25465
|
|
207
|
+
],
|
|
208
|
+
ARROW_RIGHT: (_w, h, p) => [
|
|
209
|
+
p,
|
|
210
|
+
h * .25465,
|
|
211
|
+
54,
|
|
212
|
+
h * .25465
|
|
213
|
+
],
|
|
214
|
+
SPEECH_BUBBLE: (w, h, p) => [
|
|
215
|
+
p,
|
|
216
|
+
p,
|
|
217
|
+
p,
|
|
218
|
+
p + Math.min(32, Math.min(w, h) / 8)
|
|
219
|
+
]
|
|
220
|
+
};
|
|
221
|
+
/** Where a shape's label sits inside its `width` × `height` box. */
|
|
222
|
+
function shapeWithTextLabelBox(type, width, height) {
|
|
223
|
+
const [left, top, right, bottom] = LABEL_INSETS[type](width, height, labelPadding(width, height));
|
|
224
|
+
const x = insetWithin(left, right, width);
|
|
225
|
+
const y = insetWithin(top, bottom, height);
|
|
226
|
+
return {
|
|
227
|
+
x,
|
|
228
|
+
y,
|
|
229
|
+
width: Math.max(0, width - x - right),
|
|
230
|
+
height: Math.max(0, height - y - bottom)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/** The inset before a label, its share of `size` when both insets do not fit in it. */
|
|
234
|
+
function insetWithin(before, after, size) {
|
|
235
|
+
return before + after <= size ? before : size * before / (before + after);
|
|
236
|
+
}
|
|
237
|
+
const LARGEST = 1e5;
|
|
238
|
+
/** Whether a kind grows for its label; FigJam keeps summing junctions and ors round. */
|
|
239
|
+
function shapeWithTextGrows(type) {
|
|
240
|
+
return type !== "SUMMING_JUNCTION" && type !== "OR";
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The height a `width`-wide shape of `type` takes for its label, as FigJam fits it: the height it
|
|
244
|
+
* was given while the label fits its label box, else the smallest whole height whose label box
|
|
245
|
+
* holds the label. FigJam never widens a shape for its label; a word too long for it breaks.
|
|
246
|
+
*/
|
|
247
|
+
function fitShapeWithTextHeight(type, width, height, measure) {
|
|
248
|
+
const fits = (h) => {
|
|
249
|
+
const box = shapeWithTextLabelBox(type, width, h);
|
|
250
|
+
return measure(box.width).height <= box.height;
|
|
251
|
+
};
|
|
252
|
+
if (width <= 0 || height <= 0 || !shapeWithTextGrows(type) || fits(height)) return height;
|
|
253
|
+
let low = height;
|
|
254
|
+
let high = Math.max(height * 2, height + 16);
|
|
255
|
+
while (!fits(high)) {
|
|
256
|
+
low = high;
|
|
257
|
+
high *= 2;
|
|
258
|
+
if (high > LARGEST) return LARGEST;
|
|
259
|
+
}
|
|
260
|
+
low = Math.floor(low);
|
|
261
|
+
while (high - low > 1) {
|
|
262
|
+
const middle = Math.floor((low + high) / 2);
|
|
263
|
+
if (fits(middle)) high = middle;
|
|
264
|
+
else low = middle;
|
|
265
|
+
}
|
|
266
|
+
return Math.ceil(high);
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
export { databaseCap, fitShapeWithTextHeight, shapeWithTextGrows, shapeWithTextLabelBox };
|
|
270
|
+
|
|
271
|
+
//# sourceMappingURL=fit.js.map
|