@open-pencil/scene-graph 0.17.0-beta.7 → 0.18.0-beta.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/dist/behaviours/index.d.ts +3 -2
- package/dist/behaviours/index.js +2 -1
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +15 -8
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/model.d.ts +2 -2
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +136 -1
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +17 -2
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +4 -0
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/behaviours/transition.d.ts +23 -0
- package/dist/behaviours/transition.d.ts.map +1 -0
- package/dist/behaviours/transition.js +36 -0
- package/dist/behaviours/transition.js.map +1 -0
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +2 -0
- package/dist/checkpoint.js.map +1 -1
- package/dist/color/index.d.ts +12 -9
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +15 -25
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +51 -23
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +154 -149
- package/dist/color/management.js.map +1 -1
- package/dist/color/okhcl.d.ts +28 -10
- package/dist/color/okhcl.d.ts.map +1 -1
- package/dist/color/okhcl.js +56 -40
- package/dist/color/okhcl.js.map +1 -1
- package/dist/color/schema.d.ts +6 -1
- package/dist/color/schema.d.ts.map +1 -1
- package/dist/color/schema.js +10 -1
- package/dist/color/schema.js.map +1 -1
- package/dist/constraints.d.ts.map +1 -1
- package/dist/constraints.js +2 -1
- package/dist/constraints.js.map +1 -1
- package/dist/copy.d.ts +7 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +22 -1
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +3 -1
- package/dist/corners.d.ts.map +1 -1
- package/dist/corners.js +3 -1
- package/dist/corners.js.map +1 -1
- package/dist/css/grid.js +1 -1
- package/dist/css/index.d.ts +3 -2
- package/dist/css/index.js +3 -2
- package/dist/css/motion.d.ts +12 -0
- package/dist/css/motion.d.ts.map +1 -0
- package/dist/css/motion.js +60 -0
- package/dist/css/motion.js.map +1 -0
- package/dist/css/shadows.d.ts +4 -3
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +8 -18
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.d.ts +6 -3
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +23 -5
- package/dist/css/values.js.map +1 -1
- package/dist/fields/index.d.ts +2 -2
- package/dist/fields/index.js +2 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +9 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/figjam/palette.js +1 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +7 -3
- package/dist/font-style.js.map +1 -1
- package/dist/generated/index.d.ts +6 -2
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +14 -4
- package/dist/generated/index.js.map +1 -1
- package/dist/geometry.d.ts +6 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +10 -2
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +29 -4
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +59 -9
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +5 -2
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +38 -8
- package/dist/group-bounds.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +19 -8
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/instances/content-size.js +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +50 -11
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/sync.js +67 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/flow.d.ts +16 -0
- package/dist/layout/flow.d.ts.map +1 -0
- package/dist/layout/flow.js +34 -0
- package/dist/layout/flow.js.map +1 -0
- package/dist/layout/index.d.ts +4 -3
- package/dist/layout/index.js +4 -3
- package/dist/layout/keywords.d.ts.map +1 -1
- package/dist/layout/keywords.js +7 -1
- package/dist/layout/keywords.js.map +1 -1
- package/dist/layout/sizing.d.ts +9 -1
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +17 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +7 -1
- package/dist/layout/spacing.d.ts.map +1 -1
- package/dist/layout/spacing.js +10 -1
- package/dist/layout/spacing.js.map +1 -1
- package/dist/mesh/geometry.d.ts +83 -0
- package/dist/mesh/geometry.d.ts.map +1 -0
- package/dist/mesh/geometry.js +441 -0
- package/dist/mesh/geometry.js.map +1 -0
- package/dist/mesh/index.d.ts +4 -0
- package/dist/mesh/index.js +4 -0
- package/dist/mesh/model.d.ts +28 -0
- package/dist/mesh/model.d.ts.map +1 -0
- package/dist/mesh/model.js +40 -0
- package/dist/mesh/model.js.map +1 -0
- package/dist/mesh/schema.d.ts +191 -0
- package/dist/mesh/schema.d.ts.map +1 -0
- package/dist/mesh/schema.js +56 -0
- package/dist/mesh/schema.js.map +1 -0
- package/dist/mutation-impact.d.ts +2 -0
- package/dist/mutation-impact.d.ts.map +1 -1
- package/dist/mutation-impact.js +18 -7
- package/dist/mutation-impact.js.map +1 -1
- package/dist/node-defaults.d.ts +3 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +22 -6
- package/dist/node-defaults.js.map +1 -1
- package/dist/paints/index.d.ts +5 -3
- package/dist/paints/index.js +5 -3
- package/dist/paints/pattern.d.ts +5 -1
- package/dist/paints/pattern.d.ts.map +1 -1
- package/dist/paints/pattern.js +33 -1
- package/dist/paints/pattern.js.map +1 -1
- package/dist/paints/shows.d.ts +4 -1
- package/dist/paints/shows.d.ts.map +1 -1
- package/dist/paints/shows.js +8 -1
- package/dist/paints/shows.js.map +1 -1
- package/dist/paints/solid.d.ts +11 -0
- package/dist/paints/solid.d.ts.map +1 -0
- package/dist/paints/solid.js +18 -0
- package/dist/paints/solid.js.map +1 -0
- package/dist/paints/stills.d.ts +74 -0
- package/dist/paints/stills.d.ts.map +1 -0
- package/dist/paints/stills.js +113 -0
- package/dist/paints/stills.js.map +1 -0
- package/dist/plugin-data/field.d.ts.map +1 -1
- package/dist/plugin-data/field.js +2 -0
- package/dist/plugin-data/field.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +67 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +12 -7
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +10 -3
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +34 -3
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +2 -2
- package/dist/scaling/index.js +2 -2
- package/dist/scaling/node.d.ts +2 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +27 -7
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/index.d.ts +2 -3
- package/dist/shaders/index.js +2 -3
- package/dist/shaders/model.d.ts +3 -11
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +13 -36
- package/dist/shaders/model.js.map +1 -1
- package/dist/shaders/schema.d.ts +1 -1
- package/dist/shaders/schema.js +1 -1
- package/dist/shaders/schema.js.map +1 -1
- package/dist/shape-with-text/document.js +276 -0
- package/dist/shape-with-text/document.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +13 -1
- package/dist/shape-with-text/geometry.d.ts.map +1 -1
- package/dist/shape-with-text/geometry.js +103 -41
- package/dist/shape-with-text/geometry.js.map +1 -1
- package/dist/shape-with-text/index.d.ts +2 -2
- package/dist/shape-with-text/index.js +2 -2
- package/dist/shared-style-index.d.ts +21 -0
- package/dist/shared-style-index.d.ts.map +1 -0
- package/dist/shared-style-index.js +72 -0
- package/dist/shared-style-index.js.map +1 -0
- package/dist/shared-styles.d.ts +3 -3
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +16 -7
- package/dist/shared-styles.js.map +1 -1
- package/dist/slides/drop.d.ts +32 -0
- package/dist/slides/drop.d.ts.map +1 -0
- package/dist/slides/drop.js +81 -0
- package/dist/slides/drop.js.map +1 -0
- package/dist/slides/index.d.ts +56 -0
- package/dist/slides/index.d.ts.map +1 -0
- package/dist/slides/index.js +134 -0
- package/dist/slides/index.js.map +1 -0
- package/dist/slides/motion.d.ts +55 -0
- package/dist/slides/motion.d.ts.map +1 -0
- package/dist/slides/motion.js +142 -0
- package/dist/slides/motion.js.map +1 -0
- package/dist/slides/playback.d.ts +59 -0
- package/dist/slides/playback.d.ts.map +1 -0
- package/dist/slides/playback.js +188 -0
- package/dist/slides/playback.js.map +1 -0
- package/dist/slides/types.d.ts +62 -0
- package/dist/slides/types.d.ts.map +1 -0
- package/dist/slides/types.js +39 -0
- package/dist/slides/types.js.map +1 -0
- package/dist/statuses/workflow.js +1 -1
- package/dist/text/direction.d.ts +6 -3
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +12 -12
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -1
- package/dist/text/index.js +3 -2
- package/dist/text/name.d.ts +22 -0
- package/dist/text/name.d.ts.map +1 -0
- package/dist/text/name.js +38 -0
- package/dist/text/name.js.map +1 -0
- package/dist/text/references.d.ts.map +1 -1
- package/dist/text/references.js +1 -2
- package/dist/text/references.js.map +1 -1
- package/dist/thumbnail.d.ts +23 -0
- package/dist/thumbnail.d.ts.map +1 -0
- package/dist/thumbnail.js +47 -0
- package/dist/thumbnail.js.map +1 -0
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +14 -3
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +6 -1
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +2 -2
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +4 -1
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +10 -1
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/history.js +2 -0
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/identity.js +18 -3
- package/dist/transfer/identity.js.map +1 -1
- package/dist/transfer/index.d.ts +2 -1
- package/dist/transfer/index.js +4 -3
- package/dist/transfer/library.d.ts +45 -0
- package/dist/transfer/library.d.ts.map +1 -0
- package/dist/transfer/library.js +102 -0
- package/dist/transfer/library.js.map +1 -0
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +9 -0
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +9 -0
- package/dist/transfer/plan.d.ts.map +1 -1
- package/dist/transfer/plan.js +51 -6
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +7 -1
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/validation.js +8 -4
- package/dist/transfer/validation.js.map +1 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +2 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +91 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +11 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +162 -38
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/easing.d.ts +48 -0
- package/dist/variables/easing.d.ts.map +1 -0
- package/dist/variables/easing.js +321 -0
- package/dist/variables/easing.js.map +1 -0
- package/dist/variables/formula/index.d.ts +4 -2
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +26 -9
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/parse.js +1 -1
- package/dist/variables/formula/schema.js +1 -1
- package/dist/variables/formula/signatures.d.ts +2 -2
- package/dist/variables/formula/signatures.d.ts.map +1 -1
- package/dist/variables/formula/signatures.js.map +1 -1
- package/dist/variables/formula/tree.d.ts +2 -2
- package/dist/variables/formula/tree.d.ts.map +1 -1
- package/dist/variables/formula/tree.js.map +1 -1
- package/dist/variables/index.d.ts +22 -5
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +67 -17
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.js +1 -1
- package/dist/variables/lookup.js.map +1 -1
- package/dist/variables/motion.d.ts +46 -0
- package/dist/variables/motion.d.ts.map +1 -0
- package/dist/variables/motion.js +107 -0
- package/dist/variables/motion.js.map +1 -0
- package/dist/variables/paints.d.ts +10 -2
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +24 -10
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +10 -9
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/schema.d.ts +59 -1
- package/dist/variables/schema.d.ts.map +1 -1
- package/dist/variables/schema.js +36 -1
- package/dist/variables/schema.js.map +1 -1
- package/dist/variables/style-bindings.d.ts +23 -0
- package/dist/variables/style-bindings.d.ts.map +1 -0
- package/dist/variables/style-bindings.js +83 -0
- package/dist/variables/style-bindings.js.map +1 -0
- package/package.json +21 -2
- package/src/behaviours/index.ts +1 -0
- package/src/behaviours/kinds.ts +5 -1
- package/src/behaviours/model.ts +2 -2
- package/src/behaviours/schema.ts +19 -2
- package/src/behaviours/spec.ts +5 -0
- package/src/behaviours/transition.ts +46 -0
- package/src/checkpoint.ts +2 -0
- package/src/color/index.ts +15 -24
- package/src/color/management.ts +144 -168
- package/src/color/okhcl.ts +62 -43
- package/src/color/schema.ts +13 -0
- package/src/constraints.ts +2 -1
- package/src/copy.ts +29 -0
- package/src/corners.ts +3 -0
- package/src/css/index.ts +2 -0
- package/src/css/motion.ts +51 -0
- package/src/css/shadows.ts +8 -23
- package/src/css/values.ts +34 -4
- package/src/fields/layout.ts +9 -0
- package/src/font-style.ts +8 -3
- package/src/generated/index.ts +15 -3
- package/src/geometry.ts +13 -1
- package/src/graph.ts +72 -9
- package/src/group-bounds.ts +54 -13
- package/src/hit-test.ts +13 -8
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +71 -12
- package/src/instances/sync.ts +93 -11
- package/src/layout/flow.ts +34 -0
- package/src/layout/index.ts +1 -0
- package/src/layout/keywords.ts +7 -1
- package/src/layout/sizing.ts +30 -0
- package/src/layout/spacing.ts +12 -0
- package/src/mesh/geometry.ts +433 -0
- package/src/mesh/index.ts +3 -0
- package/src/mesh/model.ts +50 -0
- package/src/mesh/schema.ts +81 -0
- package/src/mutation-impact.ts +23 -7
- package/src/node-defaults.ts +22 -5
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +55 -0
- package/src/paints/shows.ts +9 -0
- package/src/paints/solid.ts +10 -0
- package/src/paints/stills.ts +182 -0
- package/src/plugin-data/field.ts +3 -0
- package/src/plugin-data/fields.ts +15 -2
- package/src/resize.ts +32 -20
- package/src/scaling/index.ts +1 -1
- package/src/scaling/node.ts +43 -6
- package/src/shaders/index.ts +0 -1
- package/src/shaders/model.ts +19 -49
- package/src/shaders/schema.ts +1 -1
- package/src/shape-with-text/document.ts +175 -0
- package/src/shape-with-text/geometry.ts +99 -27
- package/src/shared-style-index.ts +106 -0
- package/src/shared-styles.ts +21 -14
- package/src/slides/drop.ts +94 -0
- package/src/slides/index.ts +125 -0
- package/src/slides/motion.ts +169 -0
- package/src/slides/playback.ts +200 -0
- package/src/slides/types.ts +94 -0
- package/src/text/direction.ts +13 -23
- package/src/text/index.ts +1 -0
- package/src/text/name.ts +39 -0
- package/src/text/references.ts +3 -3
- package/src/thumbnail.ts +52 -0
- package/src/transfer/apply.ts +16 -3
- package/src/transfer/copied.ts +7 -2
- package/src/transfer/dependencies.ts +10 -1
- package/src/transfer/history.ts +2 -0
- package/src/transfer/identity.ts +34 -2
- package/src/transfer/index.ts +6 -0
- package/src/transfer/library.ts +153 -0
- package/src/transfer/nodes.ts +20 -0
- package/src/transfer/plan.ts +96 -10
- package/src/transfer/remove.ts +6 -2
- package/src/transfer/validation.ts +15 -7
- package/src/transfer/variables.ts +8 -2
- package/src/types.ts +115 -11
- package/src/variables/bindings.ts +260 -36
- package/src/variables/easing.ts +282 -0
- package/src/variables/formula/index.ts +33 -14
- package/src/variables/formula/signatures.ts +6 -2
- package/src/variables/formula/tree.ts +3 -3
- package/src/variables/index.ts +90 -37
- package/src/variables/lookup.ts +1 -1
- package/src/variables/motion.ts +151 -0
- package/src/variables/paints.ts +29 -7
- package/src/variables/resolution.ts +11 -5
- package/src/variables/schema.ts +41 -0
- package/src/variables/style-bindings.ts +137 -0
- package/dist/shaders/still.d.ts +0 -18
- package/dist/shaders/still.d.ts.map +0 -1
- package/dist/shaders/still.js +0 -36
- package/dist/shaders/still.js.map +0 -1
- package/src/shaders/still.ts +0 -41
package/dist/shaders/model.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { TRANSPARENT } from "../constants.js";
|
|
2
|
-
import { readAllPluginData, withAllPluginData } from "../plugin-data/field.js";
|
|
3
1
|
import { OPEN_PENCIL_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
4
|
-
import {
|
|
5
|
-
import { randomHex } from "@open-pencil/std/random";
|
|
6
|
-
import { sha1 } from "@noble/hashes/legacy.js";
|
|
7
|
-
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
2
|
+
import { createStillPaint, isStillFrameCurrent, readStillPaints, stillContentKey, stillPaintOf, withStillPaints } from "../paints/stills.js";
|
|
8
3
|
//#region src/shaders/model.ts
|
|
9
4
|
/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */
|
|
10
5
|
function readShaderPaints(node) {
|
|
11
|
-
return
|
|
6
|
+
return readStillPaints(node, OPEN_PENCIL_PLUGIN_DATA.shader);
|
|
12
7
|
}
|
|
13
8
|
/**
|
|
14
9
|
* The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.
|
|
@@ -16,8 +11,7 @@ function readShaderPaints(node) {
|
|
|
16
11
|
* image it holds.
|
|
17
12
|
*/
|
|
18
13
|
function shaderOfPaint(node, paint) {
|
|
19
|
-
|
|
20
|
-
return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null;
|
|
14
|
+
return stillPaintOf(node, paint, OPEN_PENCIL_PLUGIN_DATA.shader);
|
|
21
15
|
}
|
|
22
16
|
/** Whether any paint of `node` draws a shader. */
|
|
23
17
|
function hasShaderPaint(node) {
|
|
@@ -28,45 +22,28 @@ function hasShaderPaint(node) {
|
|
|
28
22
|
* stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
|
|
29
23
|
*/
|
|
30
24
|
function withShaderPaints(node, paints, shaders = []) {
|
|
31
|
-
|
|
32
|
-
const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]));
|
|
33
|
-
for (const shader of shaders) byImage.set(shader.image, shader);
|
|
34
|
-
return withAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader, [...byImage.values()].filter((shader) => shown.has(shader.image)));
|
|
25
|
+
return withStillPaints(node, paints, OPEN_PENCIL_PLUGIN_DATA.shader, shaders);
|
|
35
26
|
}
|
|
36
|
-
/**
|
|
37
|
-
* A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet
|
|
38
|
-
* rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.
|
|
39
|
-
*/
|
|
27
|
+
/** A new paint that draws `preset`, and the shader entry it shows (`createStillPaint`). */
|
|
40
28
|
function createShaderPaint(preset) {
|
|
41
|
-
const image =
|
|
29
|
+
const { paint, image } = createStillPaint();
|
|
42
30
|
return {
|
|
43
|
-
paint
|
|
44
|
-
type: "IMAGE",
|
|
45
|
-
color: TRANSPARENT,
|
|
46
|
-
opacity: 1,
|
|
47
|
-
visible: true,
|
|
48
|
-
imageHash: image,
|
|
49
|
-
imageScaleMode: "FILL"
|
|
50
|
-
},
|
|
31
|
+
paint,
|
|
51
32
|
shader: {
|
|
52
33
|
image,
|
|
53
34
|
preset: structuredClone(preset)
|
|
54
35
|
}
|
|
55
36
|
};
|
|
56
37
|
}
|
|
57
|
-
/**
|
|
58
|
-
function shaderPresetKey(preset) {
|
|
59
|
-
return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a
|
|
63
|
-
* preset change after reopening the document does not keep a frame of the newer preset.
|
|
64
|
-
*/
|
|
38
|
+
/** Whether a shader's frame was rendered for its preset at the size `node` has now. */
|
|
65
39
|
function isShaderFrameCurrent(shader, size) {
|
|
66
40
|
const { frame } = shader;
|
|
67
|
-
return
|
|
41
|
+
return isStillFrameCurrent(frame && {
|
|
42
|
+
...frame,
|
|
43
|
+
key: frame.preset
|
|
44
|
+
}, stillContentKey(shader.preset), size);
|
|
68
45
|
}
|
|
69
46
|
//#endregion
|
|
70
|
-
export { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint,
|
|
47
|
+
export { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint, withShaderPaints };
|
|
71
48
|
|
|
72
49
|
//# sourceMappingURL=model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.ts"],"sourcesContent":["import {\n createStillPaint,\n isStillFrameCurrent,\n readStillPaints,\n stillContentKey,\n stillPaintOf,\n withStillPaints\n} from '../paints/stills'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { Fill, SceneNode } from '../types'\nimport type { ShaderPaint, ShaderPreset } 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 readStillPaints(node, OPEN_PENCIL_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 return stillPaintOf(node, paint, OPEN_PENCIL_PLUGIN_DATA.shader)\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 return withStillPaints(node, paints, OPEN_PENCIL_PLUGIN_DATA.shader, shaders)\n}\n\n/** A new paint that draws `preset`, and the shader entry it shows (`createStillPaint`). */\nexport function createShaderPaint(preset: ShaderPreset): {\n paint: Fill\n shader: ShaderPaint\n} {\n const { paint, image } = createStillPaint()\n return { paint, shader: { image, preset: structuredClone(preset) } }\n}\n\n/** Whether a shader's frame was rendered for its preset at the size `node` has now. */\nexport function isShaderFrameCurrent(\n shader: ShaderPaint,\n size: { width: number; height: number }\n): boolean {\n const { frame } = shader\n return isStillFrameCurrent(\n frame && { ...frame, key: frame.preset },\n stillContentKey(shader.preset),\n size\n )\n}\n"],"mappings":";;;;AAgBA,SAAgB,iBAAiB,MAAoD;CACnF,OAAO,gBAAgB,MAAM,wBAAwB,MAAM;AAC7D;;;;;;AAOA,SAAgB,cACd,MACA,OACoB;CACpB,OAAO,aAAa,MAAM,OAAO,wBAAwB,MAAM;AACjE;;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,OAAO,gBAAgB,MAAM,QAAQ,wBAAwB,QAAQ,OAAO;AAC9E;;AAGA,SAAgB,kBAAkB,QAGhC;CACA,MAAM,EAAE,OAAO,UAAU,iBAAiB;CAC1C,OAAO;EAAE;EAAO,QAAQ;GAAE;GAAO,QAAQ,gBAAgB,MAAM;EAAE;CAAE;AACrE;;AAGA,SAAgB,qBACd,QACA,MACS;CACT,MAAM,EAAE,UAAU;CAClB,OAAO,oBACL,SAAS;EAAE,GAAG;EAAO,KAAK,MAAM;CAAO,GACvC,gBAAgB,OAAO,MAAM,GAC7B,IACF;AACF"}
|
package/dist/shaders/schema.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare const shaderPaintSchema: v.ObjectSchema<{
|
|
|
31
31
|
readonly frame: v.OptionalSchema<v.ObjectSchema<{
|
|
32
32
|
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
33
33
|
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
34
|
-
/** The preset's key (`
|
|
34
|
+
/** The preset's key (`stillContentKey`) when the frame was rendered. */
|
|
35
35
|
readonly preset: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
36
36
|
}, undefined>, undefined>;
|
|
37
37
|
}, undefined>;
|
package/dist/shaders/schema.js
CHANGED
|
@@ -26,7 +26,7 @@ const shaderPaintSchema = v.object({
|
|
|
26
26
|
frame: v.optional(v.object({
|
|
27
27
|
width: v.pipe(v.number(), v.finite(), v.minValue(0)),
|
|
28
28
|
height: v.pipe(v.number(), v.finite(), v.minValue(0)),
|
|
29
|
-
/** The preset's key (`
|
|
29
|
+
/** The preset's key (`stillContentKey`) when the frame was rendered. */
|
|
30
30
|
preset: v.pipe(v.string(), v.nonEmpty())
|
|
31
31
|
}))
|
|
32
32
|
});
|
|
@@ -1 +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\n/**\n * A paint that draws a shader. The paint itself is an image fill of the shader's still frame, so\n * every format and renderer that reads images shows it; this entry says which image it is, the\n * preset that draws it, and the layer size and preset the frame was rendered for, which is\n * missing until it is first rendered.\n */\nexport const shaderPaintSchema = v.object({\n image: v.pipe(v.string(), v.nonEmpty()),\n preset: shaderPresetSchema,\n frame: v.optional(\n 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 /** The preset's key (`
|
|
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\n/**\n * A paint that draws a shader. The paint itself is an image fill of the shader's still frame, so\n * every format and renderer that reads images shows it; this entry says which image it is, the\n * preset that draws it, and the layer size and preset the frame was rendered for, which is\n * missing until it is first rendered.\n */\nexport const shaderPaintSchema = v.object({\n image: v.pipe(v.string(), v.nonEmpty()),\n preset: shaderPresetSchema,\n frame: v.optional(\n 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 /** The preset's key (`stillContentKey`) when the frame was rendered. */\n preset: v.pipe(v.string(), v.nonEmpty())\n })\n )\n})\n\nexport type ShaderPaint = v.InferOutput<typeof shaderPaintSchema>\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;;;;;;;AAUD,MAAa,oBAAoB,EAAE,OAAO;CACxC,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACtC,QAAQ;CACR,OAAO,EAAE,SACP,EAAE,OAAO;EACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;EACnD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;;EAEpD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACzC,CAAC,CACH;AACF,CAAC"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { pointAt, subPiece } from "../connectors/pieces.js";
|
|
2
|
+
//#region src/shape-with-text/document.ts
|
|
3
|
+
/**
|
|
4
|
+
* How far above the bottom a document's wave meets its left and right sides, and how far its
|
|
5
|
+
* crest rises, as FigJam draws it at every size. Below FigJam's least height the wave shrinks
|
|
6
|
+
* with the page.
|
|
7
|
+
*/
|
|
8
|
+
const WAVE_LEFT = 16;
|
|
9
|
+
const WAVE_RIGHT = 15;
|
|
10
|
+
const WAVE_CREST = 31;
|
|
11
|
+
const LEAST_HEIGHT = 80;
|
|
12
|
+
/** Bezier handle length for a quarter circle. */
|
|
13
|
+
const KAPPA = .5522847498;
|
|
14
|
+
/** Steps that measure a stretch of curve, and halvings that find where a length ends. */
|
|
15
|
+
const LENGTH_STEPS = 32;
|
|
16
|
+
const SEARCH_STEPS = 30;
|
|
17
|
+
const UP = {
|
|
18
|
+
x: 0,
|
|
19
|
+
y: -1
|
|
20
|
+
};
|
|
21
|
+
function piece(from, c1, c2, to) {
|
|
22
|
+
return {
|
|
23
|
+
from,
|
|
24
|
+
to,
|
|
25
|
+
handleFrom: {
|
|
26
|
+
x: c1.x - from.x,
|
|
27
|
+
y: c1.y - from.y
|
|
28
|
+
},
|
|
29
|
+
handleTo: {
|
|
30
|
+
x: c2.x - to.x,
|
|
31
|
+
y: c2.y - to.y
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function reversed(curve) {
|
|
36
|
+
return {
|
|
37
|
+
from: curve.to,
|
|
38
|
+
to: curve.from,
|
|
39
|
+
handleFrom: curve.handleTo,
|
|
40
|
+
handleTo: curve.handleFrom
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The bottom wave, right to left: up from the right side to its crest, down to its trough, up to the left side. */
|
|
44
|
+
function wave(w, h) {
|
|
45
|
+
const scale = Math.min(1, h / LEAST_HEIGHT);
|
|
46
|
+
const left = {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: h - WAVE_LEFT * scale
|
|
49
|
+
};
|
|
50
|
+
const trough = {
|
|
51
|
+
x: w * 13 / 48,
|
|
52
|
+
y: h
|
|
53
|
+
};
|
|
54
|
+
const crest = {
|
|
55
|
+
x: w * 17 / 24,
|
|
56
|
+
y: h - WAVE_CREST * scale
|
|
57
|
+
};
|
|
58
|
+
const right = {
|
|
59
|
+
x: w,
|
|
60
|
+
y: h - WAVE_RIGHT * scale
|
|
61
|
+
};
|
|
62
|
+
return [
|
|
63
|
+
piece(right, right, {
|
|
64
|
+
x: w * .854555,
|
|
65
|
+
y: crest.y
|
|
66
|
+
}, crest),
|
|
67
|
+
piece(crest, {
|
|
68
|
+
x: w * .5625,
|
|
69
|
+
y: crest.y
|
|
70
|
+
}, {
|
|
71
|
+
x: w * .413004,
|
|
72
|
+
y: h
|
|
73
|
+
}, trough),
|
|
74
|
+
piece(trough, {
|
|
75
|
+
x: w * 13 / 96,
|
|
76
|
+
y: h
|
|
77
|
+
}, left, left)
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
function unit(v) {
|
|
81
|
+
const length = Math.hypot(v.x, v.y);
|
|
82
|
+
return length > 0 ? {
|
|
83
|
+
x: v.x / length,
|
|
84
|
+
y: v.y / length
|
|
85
|
+
} : {
|
|
86
|
+
x: 0,
|
|
87
|
+
y: 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** The direction a curve leaves its start in, past handles of no length. */
|
|
91
|
+
function leaving(curve) {
|
|
92
|
+
const { from, to, handleFrom, handleTo } = curve;
|
|
93
|
+
const c1 = {
|
|
94
|
+
x: from.x + handleFrom.x,
|
|
95
|
+
y: from.y + handleFrom.y
|
|
96
|
+
};
|
|
97
|
+
const c2 = {
|
|
98
|
+
x: to.x + handleTo.x,
|
|
99
|
+
y: to.y + handleTo.y
|
|
100
|
+
};
|
|
101
|
+
for (const point of [
|
|
102
|
+
c1,
|
|
103
|
+
c2,
|
|
104
|
+
to
|
|
105
|
+
]) {
|
|
106
|
+
const direction = unit({
|
|
107
|
+
x: point.x - from.x,
|
|
108
|
+
y: point.y - from.y
|
|
109
|
+
});
|
|
110
|
+
if (direction.x !== 0 || direction.y !== 0) return direction;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
x: 0,
|
|
114
|
+
y: 0
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** The length of a curve from its start to `t`. */
|
|
118
|
+
function lengthTo(curve, t) {
|
|
119
|
+
let length = 0;
|
|
120
|
+
let last = curve.from;
|
|
121
|
+
for (let step = 1; step <= LENGTH_STEPS; step++) {
|
|
122
|
+
const point = pointAt(curve, t * step / LENGTH_STEPS);
|
|
123
|
+
length += Math.hypot(point.x - last.x, point.y - last.y);
|
|
124
|
+
last = point;
|
|
125
|
+
}
|
|
126
|
+
return length;
|
|
127
|
+
}
|
|
128
|
+
/** The parameter at `distance` along a curve from its start, by its length. */
|
|
129
|
+
function parameterAt(curve, distance) {
|
|
130
|
+
let low = 0;
|
|
131
|
+
let high = 1;
|
|
132
|
+
for (let step = 0; step < SEARCH_STEPS; step++) {
|
|
133
|
+
const middle = (low + high) / 2;
|
|
134
|
+
if (lengthTo(curve, middle) < distance) low = middle;
|
|
135
|
+
else high = middle;
|
|
136
|
+
}
|
|
137
|
+
return (low + high) / 2;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* How far a corner of `radius` trims each side of a vertex whose sides leave it along `a` and
|
|
141
|
+
* `b`, and how long its handles are. FigJam fits a circle to a blunt corner; a sharp one it trims
|
|
142
|
+
* by the radius alone, with a quarter circle's handles.
|
|
143
|
+
*/
|
|
144
|
+
function corner(a, b, radius) {
|
|
145
|
+
const angle = Math.acos(Math.max(-1, Math.min(1, a.x * b.x + a.y * b.y)));
|
|
146
|
+
if (angle <= Math.PI / 2) return {
|
|
147
|
+
trim: radius,
|
|
148
|
+
handle: radius * KAPPA
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
trim: radius / Math.tan(angle / 2),
|
|
152
|
+
handle: 4 / 3 * Math.tan((Math.PI - angle) / 4) * radius
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function curveTo(c1, c2, to) {
|
|
156
|
+
return {
|
|
157
|
+
type: "C",
|
|
158
|
+
x1: c1.x,
|
|
159
|
+
y1: c1.y,
|
|
160
|
+
x2: c2.x,
|
|
161
|
+
y2: c2.y,
|
|
162
|
+
x: to.x,
|
|
163
|
+
y: to.y
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function pieceTo(curve) {
|
|
167
|
+
const { from, to, handleFrom, handleTo } = curve;
|
|
168
|
+
return curveTo({
|
|
169
|
+
x: from.x + handleFrom.x,
|
|
170
|
+
y: from.y + handleFrom.y
|
|
171
|
+
}, {
|
|
172
|
+
x: to.x + handleTo.x,
|
|
173
|
+
y: to.y + handleTo.y
|
|
174
|
+
}, to);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A single document as FigJam draws it: a page whose bottom is a wave of fixed height, every
|
|
178
|
+
* corner rounded to `radius`, those where the wave meets the sides included.
|
|
179
|
+
*/
|
|
180
|
+
function documentOutline(w, h, radius) {
|
|
181
|
+
const [fromRight, middle, toLeft] = wave(w, h);
|
|
182
|
+
const r = Math.max(0, Math.min(radius, w / 2, h / 2));
|
|
183
|
+
const k = r * .4477152502;
|
|
184
|
+
const rightSide = fromRight.from;
|
|
185
|
+
const leftSide = toLeft.to;
|
|
186
|
+
const intoLeft = reversed(toLeft);
|
|
187
|
+
const right = corner(UP, leaving(fromRight), r);
|
|
188
|
+
const left = corner(UP, leaving(intoLeft), r);
|
|
189
|
+
const rightTrim = Math.min(right.trim, (rightSide.y - r) / 2);
|
|
190
|
+
const leftTrim = Math.min(left.trim, (leftSide.y - r) / 2);
|
|
191
|
+
const rightHandle = right.trim > 0 ? right.handle * rightTrim / right.trim : 0;
|
|
192
|
+
const leftHandle = left.trim > 0 ? left.handle * leftTrim / left.trim : 0;
|
|
193
|
+
const first = r > 0 ? subPiece(fromRight, parameterAt(fromRight, rightTrim), 1) : fromRight;
|
|
194
|
+
const last = r > 0 ? subPiece(toLeft, 0, 1 - parameterAt(intoLeft, leftTrim)) : toLeft;
|
|
195
|
+
const rightEnd = {
|
|
196
|
+
x: w,
|
|
197
|
+
y: rightSide.y - rightTrim
|
|
198
|
+
};
|
|
199
|
+
const leftEnd = {
|
|
200
|
+
x: 0,
|
|
201
|
+
y: leftSide.y - leftTrim
|
|
202
|
+
};
|
|
203
|
+
const commands = [
|
|
204
|
+
{
|
|
205
|
+
type: "M",
|
|
206
|
+
x: r,
|
|
207
|
+
y: 0
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
type: "L",
|
|
211
|
+
x: w - r,
|
|
212
|
+
y: 0
|
|
213
|
+
},
|
|
214
|
+
curveTo({
|
|
215
|
+
x: w - k,
|
|
216
|
+
y: 0
|
|
217
|
+
}, {
|
|
218
|
+
x: w,
|
|
219
|
+
y: k
|
|
220
|
+
}, {
|
|
221
|
+
x: w,
|
|
222
|
+
y: r
|
|
223
|
+
}),
|
|
224
|
+
{
|
|
225
|
+
type: "L",
|
|
226
|
+
x: rightEnd.x,
|
|
227
|
+
y: rightEnd.y
|
|
228
|
+
}
|
|
229
|
+
];
|
|
230
|
+
if (r > 0) {
|
|
231
|
+
const back = unit({
|
|
232
|
+
x: -first.handleFrom.x,
|
|
233
|
+
y: -first.handleFrom.y
|
|
234
|
+
});
|
|
235
|
+
commands.push(curveTo({
|
|
236
|
+
x: w,
|
|
237
|
+
y: rightEnd.y + rightHandle
|
|
238
|
+
}, {
|
|
239
|
+
x: first.from.x + back.x * rightHandle,
|
|
240
|
+
y: first.from.y + back.y * rightHandle
|
|
241
|
+
}, first.from));
|
|
242
|
+
}
|
|
243
|
+
commands.push(pieceTo(first), pieceTo(middle), pieceTo(last));
|
|
244
|
+
if (r > 0) {
|
|
245
|
+
const on = unit({
|
|
246
|
+
x: -last.handleTo.x,
|
|
247
|
+
y: -last.handleTo.y
|
|
248
|
+
});
|
|
249
|
+
commands.push(curveTo({
|
|
250
|
+
x: last.to.x + on.x * leftHandle,
|
|
251
|
+
y: last.to.y + on.y * leftHandle
|
|
252
|
+
}, {
|
|
253
|
+
x: 0,
|
|
254
|
+
y: leftEnd.y + leftHandle
|
|
255
|
+
}, leftEnd));
|
|
256
|
+
}
|
|
257
|
+
commands.push({
|
|
258
|
+
type: "L",
|
|
259
|
+
x: 0,
|
|
260
|
+
y: r
|
|
261
|
+
}, curveTo({
|
|
262
|
+
x: 0,
|
|
263
|
+
y: k
|
|
264
|
+
}, {
|
|
265
|
+
x: k,
|
|
266
|
+
y: 0
|
|
267
|
+
}, {
|
|
268
|
+
x: r,
|
|
269
|
+
y: 0
|
|
270
|
+
}), { type: "Z" });
|
|
271
|
+
return commands;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { documentOutline };
|
|
275
|
+
|
|
276
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","names":[],"sources":["../../src/shape-with-text/document.ts"],"sourcesContent":["import { pointAt, subPiece, type ConnectorPiece } from '../connectors/pieces'\nimport type { PolygonOutlineCommand } from '../polygon'\nimport type { Vector } from '../primitives'\n\n/**\n * How far above the bottom a document's wave meets its left and right sides, and how far its\n * crest rises, as FigJam draws it at every size. Below FigJam's least height the wave shrinks\n * with the page.\n */\nconst WAVE_LEFT = 16\nconst WAVE_RIGHT = 15\nconst WAVE_CREST = 31\nconst LEAST_HEIGHT = 80\n/** Bezier handle length for a quarter circle. */\nconst KAPPA = 0.5522847498\n/** Steps that measure a stretch of curve, and halvings that find where a length ends. */\nconst LENGTH_STEPS = 32\nconst SEARCH_STEPS = 30\nconst UP: Vector = { x: 0, y: -1 }\n\nfunction piece(from: Vector, c1: Vector, c2: Vector, to: Vector): ConnectorPiece {\n return {\n from,\n to,\n handleFrom: { x: c1.x - from.x, y: c1.y - from.y },\n handleTo: { x: c2.x - to.x, y: c2.y - to.y }\n }\n}\n\nfunction reversed(curve: ConnectorPiece): ConnectorPiece {\n return { from: curve.to, to: curve.from, handleFrom: curve.handleTo, handleTo: curve.handleFrom }\n}\n\n/** The bottom wave, right to left: up from the right side to its crest, down to its trough, up to the left side. */\nfunction wave(w: number, h: number): ConnectorPiece[] {\n const scale = Math.min(1, h / LEAST_HEIGHT)\n const left = { x: 0, y: h - WAVE_LEFT * scale }\n const trough = { x: (w * 13) / 48, y: h }\n const crest = { x: (w * 17) / 24, y: h - WAVE_CREST * scale }\n const right = { x: w, y: h - WAVE_RIGHT * scale }\n return [\n piece(right, right, { x: w * 0.854555, y: crest.y }, crest),\n piece(crest, { x: w * 0.5625, y: crest.y }, { x: w * 0.413004, y: h }, trough),\n piece(trough, { x: (w * 13) / 96, y: h }, left, left)\n ]\n}\n\nfunction unit(v: Vector): Vector {\n const length = Math.hypot(v.x, v.y)\n return length > 0 ? { x: v.x / length, y: v.y / length } : { x: 0, y: 0 }\n}\n\n/** The direction a curve leaves its start in, past handles of no length. */\nfunction leaving(curve: ConnectorPiece): Vector {\n const { from, to, handleFrom, handleTo } = curve\n const c1 = { x: from.x + handleFrom.x, y: from.y + handleFrom.y }\n const c2 = { x: to.x + handleTo.x, y: to.y + handleTo.y }\n for (const point of [c1, c2, to]) {\n const direction = unit({ x: point.x - from.x, y: point.y - from.y })\n if (direction.x !== 0 || direction.y !== 0) return direction\n }\n return { x: 0, y: 0 }\n}\n\n/** The length of a curve from its start to `t`. */\nfunction lengthTo(curve: ConnectorPiece, t: number): number {\n let length = 0\n let last = curve.from\n for (let step = 1; step <= LENGTH_STEPS; step++) {\n const point = pointAt(curve, (t * step) / LENGTH_STEPS)\n length += Math.hypot(point.x - last.x, point.y - last.y)\n last = point\n }\n return length\n}\n\n/** The parameter at `distance` along a curve from its start, by its length. */\nfunction parameterAt(curve: ConnectorPiece, distance: number): number {\n let low = 0\n let high = 1\n for (let step = 0; step < SEARCH_STEPS; step++) {\n const middle = (low + high) / 2\n if (lengthTo(curve, middle) < distance) low = middle\n else high = middle\n }\n return (low + high) / 2\n}\n\n/**\n * How far a corner of `radius` trims each side of a vertex whose sides leave it along `a` and\n * `b`, and how long its handles are. FigJam fits a circle to a blunt corner; a sharp one it trims\n * by the radius alone, with a quarter circle's handles.\n */\nfunction corner(a: Vector, b: Vector, radius: number): { trim: number; handle: number } {\n const angle = Math.acos(Math.max(-1, Math.min(1, a.x * b.x + a.y * b.y)))\n if (angle <= Math.PI / 2) return { trim: radius, handle: radius * KAPPA }\n return {\n trim: radius / Math.tan(angle / 2),\n handle: (4 / 3) * Math.tan((Math.PI - angle) / 4) * radius\n }\n}\n\nfunction curveTo(c1: Vector, c2: Vector, to: Vector): PolygonOutlineCommand {\n return { type: 'C', x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: to.x, y: to.y }\n}\n\nfunction pieceTo(curve: ConnectorPiece): PolygonOutlineCommand {\n const { from, to, handleFrom, handleTo } = curve\n return curveTo(\n { x: from.x + handleFrom.x, y: from.y + handleFrom.y },\n { x: to.x + handleTo.x, y: to.y + handleTo.y },\n to\n )\n}\n\n/**\n * A single document as FigJam draws it: a page whose bottom is a wave of fixed height, every\n * corner rounded to `radius`, those where the wave meets the sides included.\n */\nexport function documentOutline(w: number, h: number, radius: number): PolygonOutlineCommand[] {\n const [fromRight, middle, toLeft] = wave(w, h)\n const r = Math.max(0, Math.min(radius, w / 2, h / 2))\n const k = r * (1 - KAPPA)\n const rightSide = fromRight.from\n const leftSide = toLeft.to\n const intoLeft = reversed(toLeft)\n\n // Each bottom corner trims the side and the wave by the same length, the side no further than\n // its top corner.\n const right = corner(UP, leaving(fromRight), r)\n const left = corner(UP, leaving(intoLeft), r)\n const rightTrim = Math.min(right.trim, (rightSide.y - r) / 2)\n const leftTrim = Math.min(left.trim, (leftSide.y - r) / 2)\n // A corner trimmed short of its radius shortens its handles with it.\n const rightHandle = right.trim > 0 ? (right.handle * rightTrim) / right.trim : 0\n const leftHandle = left.trim > 0 ? (left.handle * leftTrim) / left.trim : 0\n const first = r > 0 ? subPiece(fromRight, parameterAt(fromRight, rightTrim), 1) : fromRight\n const last = r > 0 ? subPiece(toLeft, 0, 1 - parameterAt(intoLeft, leftTrim)) : toLeft\n const rightEnd = { x: w, y: rightSide.y - rightTrim }\n const leftEnd = { x: 0, y: leftSide.y - leftTrim }\n\n const commands: PolygonOutlineCommand[] = [\n { type: 'M', x: r, y: 0 },\n { type: 'L', x: w - r, y: 0 },\n curveTo({ x: w - k, y: 0 }, { x: w, y: k }, { x: w, y: r }),\n { type: 'L', x: rightEnd.x, y: rightEnd.y }\n ]\n if (r > 0) {\n const back = unit({ x: -first.handleFrom.x, y: -first.handleFrom.y })\n commands.push(\n curveTo(\n { x: w, y: rightEnd.y + rightHandle },\n { x: first.from.x + back.x * rightHandle, y: first.from.y + back.y * rightHandle },\n first.from\n )\n )\n }\n commands.push(pieceTo(first), pieceTo(middle), pieceTo(last))\n if (r > 0) {\n const on = unit({ x: -last.handleTo.x, y: -last.handleTo.y })\n commands.push(\n curveTo(\n { x: last.to.x + on.x * leftHandle, y: last.to.y + on.y * leftHandle },\n { x: 0, y: leftEnd.y + leftHandle },\n leftEnd\n )\n )\n }\n commands.push(\n { type: 'L', x: 0, y: r },\n curveTo({ x: 0, y: k }, { x: k, y: 0 }, { x: r, y: 0 }),\n { type: 'Z' }\n )\n return commands\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ShapeWithTextType } from "./kinds.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
2
3
|
import { PolygonOutlineCommand } from "../polygon.js";
|
|
3
4
|
//#region src/shape-with-text/geometry.d.ts
|
|
4
5
|
interface ShapeWithTextGeometry {
|
|
@@ -7,6 +8,11 @@ interface ShapeWithTextGeometry {
|
|
|
7
8
|
/** Inner lines that are stroked only, such as a database's front rim. */
|
|
8
9
|
details: PolygonOutlineCommand[];
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* The band FigJam cuts out of a shape's fill along its outline and inner lines when no stroke
|
|
13
|
+
* draws them, so a database still shows its rim: half of it insets the outline.
|
|
14
|
+
*/
|
|
15
|
+
declare const SHAPE_WITH_TEXT_LINE_GAP = 3;
|
|
10
16
|
/** How far a parallelogram's sides lean: FigJam leans them with the height, not the width. */
|
|
11
17
|
declare function parallelogramSlant(w: number, h: number): number;
|
|
12
18
|
/**
|
|
@@ -15,6 +21,12 @@ declare function parallelogramSlant(w: number, h: number): number;
|
|
|
15
21
|
* curves, such as a rounded rectangle, keep their own shape.
|
|
16
22
|
*/
|
|
17
23
|
declare function shapeWithTextGeometry(type: ShapeWithTextType, width: number, height: number, cornerRadius?: number): ShapeWithTextGeometry;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the shape's fill has its outline and inner lines cut out of it, as FigJam draws a shape
|
|
26
|
+
* with inner lines, such as a database, when no stroke draws them: it has inner lines and no
|
|
27
|
+
* visible stroke.
|
|
28
|
+
*/
|
|
29
|
+
declare function shapeWithTextCutsFill(node: Pick<SceneNode, 'type' | 'shapeWithTextType' | 'width' | 'height' | 'strokes'>): boolean;
|
|
18
30
|
//#endregion
|
|
19
|
-
export { ShapeWithTextGeometry, parallelogramSlant, shapeWithTextGeometry };
|
|
31
|
+
export { SHAPE_WITH_TEXT_LINE_GAP, ShapeWithTextGeometry, parallelogramSlant, shapeWithTextCutsFill, shapeWithTextGeometry };
|
|
20
32
|
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","names":[],"sources":["../../src/shape-with-text/geometry.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","names":[],"sources":["../../src/shape-with-text/geometry.ts"],"mappings":";;;;UAOiB;;EAEf,SAAS;;EAET,SAAS;;;;;;cAUE;;iBAyIG,mBAAmB,WAAW;;;;;;iBAmY9B,sBACd,MAAM,mBACN,eACA,gBACA,wBACC;;;;;;iBAYa,sBACd,MAAM,KAAK"}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import { drawsStroke } from "../geometry.js";
|
|
1
2
|
import { databaseCap } from "./fit.js";
|
|
3
|
+
import { documentOutline } from "./document.js";
|
|
2
4
|
//#region src/shape-with-text/geometry.ts
|
|
3
5
|
/** Bezier handle length for a quarter ellipse. */
|
|
4
6
|
const KAPPA = .5522847498;
|
|
7
|
+
/**
|
|
8
|
+
* The band FigJam cuts out of a shape's fill along its outline and inner lines when no stroke
|
|
9
|
+
* draws them, so a database still shows its rim: half of it insets the outline.
|
|
10
|
+
*/
|
|
11
|
+
const SHAPE_WITH_TEXT_LINE_GAP = 3;
|
|
12
|
+
/** A folder's tab: its height, and how far its base reaches past the middle of the box. */
|
|
13
|
+
const FOLDER_TAB_HEIGHT = 44;
|
|
14
|
+
const FOLDER_TAB_OVERHANG = 13;
|
|
15
|
+
/** How far the tab's sides lean in over its full height. */
|
|
16
|
+
const FOLDER_TAB_SLANT = 18;
|
|
17
|
+
/** How far a multiple document's front page sits right of and below its back page. */
|
|
18
|
+
const DOCUMENT_OFFSET = 16;
|
|
5
19
|
function polygon(points) {
|
|
6
20
|
const commands = points.map(([x, y], index) => ({
|
|
7
21
|
type: index === 0 ? "M" : "L",
|
|
@@ -306,16 +320,30 @@ const BUILDERS = {
|
|
|
306
320
|
}]
|
|
307
321
|
};
|
|
308
322
|
},
|
|
309
|
-
ENG_FOLDER: (w, h) => {
|
|
310
|
-
const tab = Math.min(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
[
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
323
|
+
ENG_FOLDER: (w, h, _min, radius) => {
|
|
324
|
+
const tab = Math.min(FOLDER_TAB_HEIGHT, h);
|
|
325
|
+
const base = Math.min(w / 2 + FOLDER_TAB_OVERHANG, w);
|
|
326
|
+
const slant = Math.min(FOLDER_TAB_SLANT * tab / FOLDER_TAB_HEIGHT, base / 2);
|
|
327
|
+
return {
|
|
328
|
+
outline: roundedPolygon([
|
|
329
|
+
[0, h],
|
|
330
|
+
[0, tab],
|
|
331
|
+
[slant, 0],
|
|
332
|
+
[base - slant, 0],
|
|
333
|
+
[base, tab],
|
|
334
|
+
[w, tab],
|
|
335
|
+
[w, h]
|
|
336
|
+
], [
|
|
337
|
+
radius,
|
|
338
|
+
0,
|
|
339
|
+
radius,
|
|
340
|
+
radius,
|
|
341
|
+
0,
|
|
342
|
+
radius,
|
|
343
|
+
radius
|
|
344
|
+
]),
|
|
345
|
+
details: line([0, tab], [base, tab])
|
|
346
|
+
};
|
|
319
347
|
},
|
|
320
348
|
TRAPEZOID: (w, h) => {
|
|
321
349
|
const s = Math.min(w * .2, h);
|
|
@@ -350,35 +378,43 @@ const BUILDERS = {
|
|
|
350
378
|
curve(w * .25, h * .9, 0, h * .75, 0, h * .45),
|
|
351
379
|
{ type: "Z" }
|
|
352
380
|
]),
|
|
353
|
-
DOCUMENT_SINGLE: (w, h) => plain(
|
|
354
|
-
DOCUMENT_MULTIPLE: (w, h,
|
|
355
|
-
const o = min
|
|
381
|
+
DOCUMENT_SINGLE: (w, h, _min, radius) => plain(documentOutline(w, h, radius)),
|
|
382
|
+
DOCUMENT_MULTIPLE: (w, h, _min, radius) => {
|
|
383
|
+
const o = Math.min(DOCUMENT_OFFSET, w / 4, h / 4);
|
|
384
|
+
const wave = documentPage(o, o, w - o, h - o).filter((command) => command.type === "C");
|
|
385
|
+
const base = wave.at(-1)?.y ?? h;
|
|
386
|
+
const join = Math.min(h - 2 * o, base);
|
|
387
|
+
const outline = roundedPolygon([
|
|
388
|
+
[0, 0],
|
|
389
|
+
[w - o, 0],
|
|
390
|
+
[w - o, o],
|
|
391
|
+
[w, o],
|
|
392
|
+
[w, base],
|
|
393
|
+
[o, base],
|
|
394
|
+
[o, join],
|
|
395
|
+
[0, join - o / 4]
|
|
396
|
+
], [
|
|
397
|
+
radius,
|
|
398
|
+
radius,
|
|
399
|
+
0,
|
|
400
|
+
radius,
|
|
401
|
+
0,
|
|
402
|
+
0,
|
|
403
|
+
0,
|
|
404
|
+
radius
|
|
405
|
+
]);
|
|
406
|
+
const bottom = outline.findIndex((command) => command.type === "L" && command.x === o && command.y === base);
|
|
356
407
|
return {
|
|
357
|
-
outline:
|
|
358
|
-
|
|
359
|
-
...
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
x: w - o,
|
|
368
|
-
y: h - o * 2
|
|
369
|
-
},
|
|
370
|
-
...line([o * 2, o], [o * 2, 0]),
|
|
371
|
-
{
|
|
372
|
-
type: "L",
|
|
373
|
-
x: w,
|
|
374
|
-
y: 0
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
type: "L",
|
|
378
|
-
x: w,
|
|
379
|
-
y: h - o * 3
|
|
380
|
-
}
|
|
381
|
-
]
|
|
408
|
+
outline: [
|
|
409
|
+
...outline.slice(0, bottom),
|
|
410
|
+
...wave,
|
|
411
|
+
...outline.slice(bottom + 1)
|
|
412
|
+
],
|
|
413
|
+
details: [...line([w - o, o], [o, o]), {
|
|
414
|
+
type: "L",
|
|
415
|
+
x: o,
|
|
416
|
+
y: join
|
|
417
|
+
}]
|
|
382
418
|
};
|
|
383
419
|
},
|
|
384
420
|
MANUAL_INPUT: (w, h) => plain(polygon([
|
|
@@ -498,8 +534,25 @@ function roundCorners(commands, radius) {
|
|
|
498
534
|
const points = [];
|
|
499
535
|
for (const command of commands) if (command.type !== "Z") points.push([command.x, command.y]);
|
|
500
536
|
if (points.length < 3) return commands;
|
|
537
|
+
return roundedPolygon(points, points.map(() => radius));
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* The closed polygon through `points` with the corner at each rounded to its own radius in
|
|
541
|
+
* `radii`, shortened where an edge is too short for it; a corner with radius 0 stays sharp.
|
|
542
|
+
*/
|
|
543
|
+
function roundedPolygon(points, radii) {
|
|
501
544
|
const rounded = [];
|
|
502
545
|
points.forEach((vertex, index) => {
|
|
546
|
+
const radius = radii[index] ?? 0;
|
|
547
|
+
const type = index === 0 ? "M" : "L";
|
|
548
|
+
if (radius <= 0) {
|
|
549
|
+
rounded.push({
|
|
550
|
+
type,
|
|
551
|
+
x: vertex[0],
|
|
552
|
+
y: vertex[1]
|
|
553
|
+
});
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
503
556
|
const before = points[(index + points.length - 1) % points.length];
|
|
504
557
|
const after = points[(index + 1) % points.length];
|
|
505
558
|
const toward = (to) => {
|
|
@@ -510,7 +563,7 @@ function roundCorners(commands, radius) {
|
|
|
510
563
|
const [inX, inY] = toward(before);
|
|
511
564
|
const [outX, outY] = toward(after);
|
|
512
565
|
rounded.push({
|
|
513
|
-
type
|
|
566
|
+
type,
|
|
514
567
|
x: inX,
|
|
515
568
|
y: inY
|
|
516
569
|
});
|
|
@@ -527,13 +580,22 @@ function roundCorners(commands, radius) {
|
|
|
527
580
|
function shapeWithTextGeometry(type, width, height, cornerRadius = 0) {
|
|
528
581
|
const w = Math.max(0, width);
|
|
529
582
|
const h = Math.max(0, height);
|
|
530
|
-
const geometry = BUILDERS[type](w, h, Math.min(w, h));
|
|
583
|
+
const geometry = BUILDERS[type](w, h, Math.min(w, h), cornerRadius);
|
|
531
584
|
return {
|
|
532
585
|
...geometry,
|
|
533
586
|
outline: roundCorners(geometry.outline, cornerRadius)
|
|
534
587
|
};
|
|
535
588
|
}
|
|
589
|
+
/**
|
|
590
|
+
* Whether the shape's fill has its outline and inner lines cut out of it, as FigJam draws a shape
|
|
591
|
+
* with inner lines, such as a database, when no stroke draws them: it has inner lines and no
|
|
592
|
+
* visible stroke.
|
|
593
|
+
*/
|
|
594
|
+
function shapeWithTextCutsFill(node) {
|
|
595
|
+
if (node.strokes.some((stroke) => stroke.opacity > 0 && drawsStroke(node, stroke))) return false;
|
|
596
|
+
return shapeWithTextGeometry(node.shapeWithTextType, node.width, node.height).details.length > 0;
|
|
597
|
+
}
|
|
536
598
|
//#endregion
|
|
537
|
-
export { parallelogramSlant, shapeWithTextGeometry };
|
|
599
|
+
export { SHAPE_WITH_TEXT_LINE_GAP, parallelogramSlant, shapeWithTextCutsFill, shapeWithTextGeometry };
|
|
538
600
|
|
|
539
601
|
//# sourceMappingURL=geometry.js.map
|