@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.3
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/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +211 -10
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +18 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +66 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -16
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +4 -2
- package/dist/css/index.js +4 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -1
- package/dist/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +37 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +80 -137
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +125 -27
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -38
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +291 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +112 -39
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +2 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +21 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +38 -15
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +16 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +69 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +6 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +16 -19
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +73 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +37 -11
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +122 -74
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +7 -7
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +57 -26
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +14 -1
- package/src/arrow-caps.ts +2 -5
- package/src/asset-keys.ts +20 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +319 -17
- package/src/components/properties.ts +101 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +18 -19
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +18 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +97 -206
- package/src/graph.ts +155 -45
- package/src/group-bounds.ts +84 -17
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +93 -64
- package/src/images.ts +71 -3
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +62 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +456 -0
- package/src/instances/sync.ts +176 -50
- package/src/node-defaults.ts +3 -1
- package/src/order-keys.ts +6 -0
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +21 -2
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +90 -1
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +6 -1
- package/src/slots/frames.ts +9 -7
- package/src/text/direction.ts +5 -0
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +17 -31
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +83 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +152 -88
- package/src/variables/fields.ts +46 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +90 -39
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
|
@@ -23,7 +23,10 @@ declare function behaviourOwner(graph: SceneGraph, node: SceneNode): SceneNode |
|
|
|
23
23
|
declare function readBehaviour(owner: SceneNode): Behaviour | null;
|
|
24
24
|
/** The owner's plugin data with the behaviour set, or removed when null. */
|
|
25
25
|
declare function withBehaviour(owner: SceneNode, behaviour: Behaviour | null): SceneNode['pluginData'];
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Component properties the behaviour can bind to: the owner's, with a set's variant values and
|
|
28
|
+
* defaults read from its variants, and a set's variants' own.
|
|
29
|
+
*/
|
|
27
30
|
declare function behaviourProperties(graph: SceneGraph, owner: SceneNode): ComponentPropertyDefinition[];
|
|
28
31
|
/**
|
|
29
32
|
* Required values and parts that are unbound, or bound to a property the component no longer
|
|
@@ -31,10 +34,10 @@ declare function behaviourProperties(graph: SceneGraph, owner: SceneNode): Compo
|
|
|
31
34
|
*/
|
|
32
35
|
declare function missingBindings(graph: SceneGraph, owner: SceneNode, behaviour: Behaviour): string[];
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
35
|
-
* as `Hover` or `Pressed`; states without such a value are left unset.
|
|
37
|
+
* A kind of control's interaction states for a variant property, each mapped to the value whose
|
|
38
|
+
* name means it, such as `Hover` or `Pressed`; states without such a value are left unset.
|
|
36
39
|
*/
|
|
37
|
-
declare function guessInteractionStates(propertyId: string, values: readonly string[]): BehaviourInteractionStates;
|
|
40
|
+
declare function guessInteractionStates(kind: BehaviourKind, propertyId: string, values: readonly string[]): BehaviourInteractionStates;
|
|
38
41
|
/**
|
|
39
42
|
* The behaviour with every component property id it binds renamed by `rename`, for formats that
|
|
40
43
|
* give properties new ids on write, such as `.fig` with its GUIDs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/behaviours/model.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/behaviours/model.ts"],"mappings":";;;;;cAoBa,yBAAyB;;iBAQtB,eACd,WAAW,WACX,kBACC;;iBAKa,YAAY,WAAW,WAAW;;iBAKlC,YAAY,WAAW,WAAW;;iBAKlC,eACd,WAAW,WACX,kBACC;;iBAKa,eAAe,MAAM,gBAAgB;;;;;iBAcrC,eAAe,OAAO,YAAY,MAAM,YAAY;;iBAQpD,cAAc,OAAO,YAAY;;iBAKjC,cACd,OAAO,WACP,WAAW,mBACV;;;;;iBAQa,oBACd,OAAO,YACP,OAAO,YACN;;;;;iBAsBa,gBACd,OAAO,YACP,OAAO,WACP,WAAW;;;;;iBAyCG,uBACd,MAAM,eACN,oBACA,4BACC;;;;;iBAaa,0BACd,WAAW,WACX,SAAS,gCACR"}
|
package/dist/behaviours/model.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
2
|
-
import {
|
|
2
|
+
import { behaviourContract, interactionStatesOf } from "./kinds.js";
|
|
3
3
|
import { OPEN_PENCIL_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
4
|
+
import { resolvedVariantDefinition } from "../components/variants.js";
|
|
4
5
|
import { mapValues } from "es-toolkit";
|
|
5
6
|
//#region src/behaviours/model.ts
|
|
6
7
|
const DEFAULT_NUMBER_SETTINGS = {
|
|
@@ -54,11 +55,16 @@ function readBehaviour(owner) {
|
|
|
54
55
|
function withBehaviour(owner, behaviour) {
|
|
55
56
|
return withPluginData(owner.pluginData, OPEN_PENCIL_PLUGIN_DATA.behaviour, behaviour ?? void 0);
|
|
56
57
|
}
|
|
57
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Component properties the behaviour can bind to: the owner's, with a set's variant values and
|
|
60
|
+
* defaults read from its variants, and a set's variants' own.
|
|
61
|
+
*/
|
|
58
62
|
function behaviourProperties(graph, owner) {
|
|
59
|
-
const
|
|
63
|
+
const isSet = owner.type === "COMPONENT_SET";
|
|
64
|
+
const own = isSet ? owner.componentPropertyDefinitions.map((definition) => resolvedVariantDefinition(graph, owner, definition)) : owner.componentPropertyDefinitions;
|
|
65
|
+
const variants = isSet ? owner.childIds.flatMap((id) => graph.getNode(id)?.componentPropertyDefinitions ?? []) : [];
|
|
60
66
|
const seen = /* @__PURE__ */ new Set();
|
|
61
|
-
return [...
|
|
67
|
+
return [...own, ...variants].filter((definition) => {
|
|
62
68
|
if (seen.has(definition.id)) return false;
|
|
63
69
|
seen.add(definition.id);
|
|
64
70
|
return true;
|
|
@@ -110,15 +116,16 @@ const STATE_NAMES = {
|
|
|
110
116
|
"focus visible",
|
|
111
117
|
"focus-visible"
|
|
112
118
|
],
|
|
113
|
-
disabled: ["disabled", "inactive"]
|
|
119
|
+
disabled: ["disabled", "inactive"],
|
|
120
|
+
invalid: ["invalid", "error"]
|
|
114
121
|
};
|
|
115
122
|
/**
|
|
116
|
-
*
|
|
117
|
-
* as `Hover` or `Pressed`; states without such a value are left unset.
|
|
123
|
+
* A kind of control's interaction states for a variant property, each mapped to the value whose
|
|
124
|
+
* name means it, such as `Hover` or `Pressed`; states without such a value are left unset.
|
|
118
125
|
*/
|
|
119
|
-
function guessInteractionStates(propertyId, values) {
|
|
126
|
+
function guessInteractionStates(kind, propertyId, values) {
|
|
120
127
|
const states = { propertyId };
|
|
121
|
-
for (const state of
|
|
128
|
+
for (const state of interactionStatesOf(kind)) {
|
|
122
129
|
const match = values.find((value) => STATE_NAMES[state].includes(value.trim().toLowerCase()));
|
|
123
130
|
if (match) states[state] = match;
|
|
124
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/behaviours/model.ts"],"sourcesContent":["import { mapValues } from 'es-toolkit'\n\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\nimport {\n behaviourContract,\n INTERACTION_STATES,\n type BehaviourKind,\n type InteractionState\n} from './kinds'\nimport type {\n Behaviour,\n BehaviourBooleanBinding,\n BehaviourInteractionStates,\n BehaviourNumberSettings\n} from './schema'\n\nexport const DEFAULT_NUMBER_SETTINGS: BehaviourNumberSettings = {\n min: 0,\n max: 100,\n step: 1,\n default: 50\n}\n\n/** A boolean value's binding, if the behaviour has one. */\nexport function booleanBinding(\n behaviour: Behaviour,\n valueId: string\n): BehaviourBooleanBinding | undefined {\n return Object.hasOwn(behaviour.booleans, valueId) ? behaviour.booleans[valueId] : undefined\n}\n\n/** The slot property a part is bound to, if any. */\nexport function partBinding(behaviour: Behaviour, partId: string): string | undefined {\n return Object.hasOwn(behaviour.parts, partId) ? behaviour.parts[partId] : undefined\n}\n\n/** The text property a text value is bound to, if any. */\nexport function textBinding(behaviour: Behaviour, valueId: string): string | undefined {\n return Object.hasOwn(behaviour.texts, valueId) ? behaviour.texts[valueId].propertyId : undefined\n}\n\n/** A number value's range, if the behaviour has one. */\nexport function numberSettings(\n behaviour: Behaviour,\n valueId: string\n): BehaviourNumberSettings | undefined {\n return Object.hasOwn(behaviour.numbers, valueId) ? behaviour.numbers[valueId] : undefined\n}\n\n/** A new behaviour of a kind, its number values at their defaults and nothing bound. */\nexport function emptyBehaviour(kind: BehaviourKind): Behaviour {\n const contract = behaviourContract(kind)\n const numbers = Object.fromEntries(\n contract.values\n .filter((value) => value.type === 'number')\n .map((value) => [value.id, { ...DEFAULT_NUMBER_SETTINGS }])\n )\n return { kind, booleans: {}, texts: {}, numbers, parts: {} }\n}\n\n/**\n * The node that keeps the behaviour: a component set for its variants, otherwise the main\n * component itself.\n */\nexport function behaviourOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n if (node.type === 'COMPONENT_SET') return node\n if (node.type !== 'COMPONENT') return undefined\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent : node\n}\n\n/** The behaviour a component or component set keeps, or null when it has none or it is unreadable. */\nexport function readBehaviour(owner: SceneNode): Behaviour | null {\n return readPluginData(owner.pluginData, OPEN_PENCIL_PLUGIN_DATA.behaviour) ?? null\n}\n\n/** The owner's plugin data with the behaviour set, or removed when null. */\nexport function withBehaviour(\n owner: SceneNode,\n behaviour: Behaviour | null\n): SceneNode['pluginData'] {\n return withPluginData(owner.pluginData, OPEN_PENCIL_PLUGIN_DATA.behaviour, behaviour ?? undefined)\n}\n\n/** Component properties the behaviour can bind to: the owner's, and a set's variants' own. */\nexport function behaviourProperties(\n graph: SceneGraph,\n owner: SceneNode\n): ComponentPropertyDefinition[] {\n const variants =\n owner.type === 'COMPONENT_SET'\n ? owner.childIds.flatMap((id) => graph.getNode(id)?.componentPropertyDefinitions ?? [])\n : []\n const seen = new Set<string>()\n return [...owner.componentPropertyDefinitions, ...variants].filter((definition) => {\n if (seen.has(definition.id)) return false\n seen.add(definition.id)\n return true\n })\n}\n\n/**\n * Required values and parts that are unbound, or bound to a property the component no longer\n * has, by value or part id; `states` when the interaction states lost their variant property.\n */\nexport function missingBindings(\n graph: SceneGraph,\n owner: SceneNode,\n behaviour: Behaviour\n): string[] {\n const contract = behaviourContract(behaviour.kind)\n const properties = new Map(\n behaviourProperties(graph, owner).map((definition) => [definition.id, definition])\n )\n const bound = (propertyId: string | undefined, type: ComponentPropertyDefinition['type'][]) => {\n const definition = propertyId ? properties.get(propertyId) : undefined\n return !!definition && type.includes(definition.type)\n }\n const values = contract.values\n .filter((value) => value.required)\n .filter((value) =>\n value.type === 'text'\n ? !bound(textBinding(behaviour, value.id), ['TEXT'])\n : value.type === 'boolean' &&\n !bound(booleanBinding(behaviour, value.id)?.propertyId, ['VARIANT', 'BOOLEAN'])\n )\n .map((value) => value.id)\n const parts = contract.parts\n .filter((part) => part.required && !bound(partBinding(behaviour, part.id), ['SLOT']))\n .map((part) => part.id)\n const states =\n behaviour.states && !bound(behaviour.states.propertyId, ['VARIANT']) ? ['states'] : []\n return [...values, ...parts, ...states]\n}\n\n/** Variant value names that usually mean each interaction state, compared case-insensitively. */\nconst STATE_NAMES: Record<InteractionState, readonly string[]> = {\n rest: ['default', 'rest', 'idle', 'normal', 'enabled'],\n hover: ['hover', 'hovered', 'hovering'],\n pressed: ['pressed', 'active', 'down', 'pressing'],\n focus: ['focus', 'focused', 'focus visible', 'focus-visible'],\n disabled: ['disabled', 'inactive']\n}\n\n/**\n * Interaction states for a variant property, each mapped to the value whose name means it, such\n * as `Hover` or `Pressed`; states without such a value are left unset.\n */\nexport function guessInteractionStates(\n propertyId: string,\n values: readonly string[]\n): BehaviourInteractionStates {\n const states: BehaviourInteractionStates = { propertyId }\n for (const state of INTERACTION_STATES) {\n const match = values.find((value) => STATE_NAMES[state].includes(value.trim().toLowerCase()))\n if (match) states[state] = match\n }\n return states\n}\n\n/**\n * The behaviour with every component property id it binds renamed by `rename`, for formats that\n * give properties new ids on write, such as `.fig` with its GUIDs.\n */\nexport function renameBehaviourProperties(\n behaviour: Behaviour,\n rename: (propertyId: string) => string\n): Behaviour {\n return {\n ...behaviour,\n booleans: mapValues(behaviour.booleans, (binding) => ({\n ...binding,\n propertyId: rename(binding.propertyId)\n })),\n texts: mapValues(behaviour.texts, (binding) => ({ propertyId: rename(binding.propertyId) })),\n parts: mapValues(behaviour.parts, rename),\n ...(behaviour.states\n ? { states: { ...behaviour.states, propertyId: rename(behaviour.states.propertyId) } }\n : {})\n }\n}\n"],"mappings":";;;;;AAmBA,MAAa,0BAAmD;CAC9D,KAAK;CACL,KAAK;CACL,MAAM;CACN,SAAS;AACX;;AAGA,SAAgB,eACd,WACA,SACqC;CACrC,OAAO,OAAO,OAAO,UAAU,UAAU,OAAO,IAAI,UAAU,SAAS,WAAW,KAAA;AACpF;;AAGA,SAAgB,YAAY,WAAsB,QAAoC;CACpF,OAAO,OAAO,OAAO,UAAU,OAAO,MAAM,IAAI,UAAU,MAAM,UAAU,KAAA;AAC5E;;AAGA,SAAgB,YAAY,WAAsB,SAAqC;CACrF,OAAO,OAAO,OAAO,UAAU,OAAO,OAAO,IAAI,UAAU,MAAM,QAAQ,CAAC,aAAa,KAAA;AAC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W;CACxD,KAAK,MAAM,SAAS,oBAAoB;EACtC,MAAM,QAAQ,OAAO,MAAM,UAAU,YAAY,MAAM,CAAC,SAAS,MAAM,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC;EAC5F,IAAI,OAAO,OAAO,SAAS;CAC7B;CACA,OAAO;AACT;;;;;AAMA,SAAgB,0BACd,WACA,QACW;CACX,OAAO;EACL,GAAG;EACH,UAAU,UAAU,UAAU,WAAW,aAAa;GACpD,GAAG;GACH,YAAY,OAAO,QAAQ,UAAU;EACvC,EAAE;EACF,OAAO,UAAU,UAAU,QAAQ,aAAa,EAAE,YAAY,OAAO,QAAQ,UAAU,EAAE,EAAE;EAC3F,OAAO,UAAU,UAAU,OAAO,MAAM;EACxC,GAAI,UAAU,SACV,EAAE,QAAQ;GAAE,GAAG,UAAU;GAAQ,YAAY,OAAO,UAAU,OAAO,UAAU;EAAE,EAAE,IACnF,CAAC;CACP;AACF"}
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/behaviours/model.ts"],"sourcesContent":["import { mapValues } from 'es-toolkit'\n\nimport { resolvedVariantDefinition } from '../components/variants'\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\nimport {\n behaviourContract,\n interactionStatesOf,\n type BehaviourKind,\n type InteractionState\n} from './kinds'\nimport type {\n Behaviour,\n BehaviourBooleanBinding,\n BehaviourInteractionStates,\n BehaviourNumberSettings\n} from './schema'\n\nexport const DEFAULT_NUMBER_SETTINGS: BehaviourNumberSettings = {\n min: 0,\n max: 100,\n step: 1,\n default: 50\n}\n\n/** A boolean value's binding, if the behaviour has one. */\nexport function booleanBinding(\n behaviour: Behaviour,\n valueId: string\n): BehaviourBooleanBinding | undefined {\n return Object.hasOwn(behaviour.booleans, valueId) ? behaviour.booleans[valueId] : undefined\n}\n\n/** The slot property a part is bound to, if any. */\nexport function partBinding(behaviour: Behaviour, partId: string): string | undefined {\n return Object.hasOwn(behaviour.parts, partId) ? behaviour.parts[partId] : undefined\n}\n\n/** The text property a text value is bound to, if any. */\nexport function textBinding(behaviour: Behaviour, valueId: string): string | undefined {\n return Object.hasOwn(behaviour.texts, valueId) ? behaviour.texts[valueId].propertyId : undefined\n}\n\n/** A number value's range, if the behaviour has one. */\nexport function numberSettings(\n behaviour: Behaviour,\n valueId: string\n): BehaviourNumberSettings | undefined {\n return Object.hasOwn(behaviour.numbers, valueId) ? behaviour.numbers[valueId] : undefined\n}\n\n/** A new behaviour of a kind, its number values at their defaults and nothing bound. */\nexport function emptyBehaviour(kind: BehaviourKind): Behaviour {\n const contract = behaviourContract(kind)\n const numbers = Object.fromEntries(\n contract.values\n .filter((value) => value.type === 'number')\n .map((value) => [value.id, { ...DEFAULT_NUMBER_SETTINGS }])\n )\n return { kind, booleans: {}, texts: {}, numbers, parts: {} }\n}\n\n/**\n * The node that keeps the behaviour: a component set for its variants, otherwise the main\n * component itself.\n */\nexport function behaviourOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n if (node.type === 'COMPONENT_SET') return node\n if (node.type !== 'COMPONENT') return undefined\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent : node\n}\n\n/** The behaviour a component or component set keeps, or null when it has none or it is unreadable. */\nexport function readBehaviour(owner: SceneNode): Behaviour | null {\n return readPluginData(owner.pluginData, OPEN_PENCIL_PLUGIN_DATA.behaviour) ?? null\n}\n\n/** The owner's plugin data with the behaviour set, or removed when null. */\nexport function withBehaviour(\n owner: SceneNode,\n behaviour: Behaviour | null\n): SceneNode['pluginData'] {\n return withPluginData(owner.pluginData, OPEN_PENCIL_PLUGIN_DATA.behaviour, behaviour ?? undefined)\n}\n\n/**\n * Component properties the behaviour can bind to: the owner's, with a set's variant values and\n * defaults read from its variants, and a set's variants' own.\n */\nexport function behaviourProperties(\n graph: SceneGraph,\n owner: SceneNode\n): ComponentPropertyDefinition[] {\n const isSet = owner.type === 'COMPONENT_SET'\n const own = isSet\n ? owner.componentPropertyDefinitions.map((definition) =>\n resolvedVariantDefinition(graph, owner, definition)\n )\n : owner.componentPropertyDefinitions\n const variants = isSet\n ? owner.childIds.flatMap((id) => graph.getNode(id)?.componentPropertyDefinitions ?? [])\n : []\n const seen = new Set<string>()\n return [...own, ...variants].filter((definition) => {\n if (seen.has(definition.id)) return false\n seen.add(definition.id)\n return true\n })\n}\n\n/**\n * Required values and parts that are unbound, or bound to a property the component no longer\n * has, by value or part id; `states` when the interaction states lost their variant property.\n */\nexport function missingBindings(\n graph: SceneGraph,\n owner: SceneNode,\n behaviour: Behaviour\n): string[] {\n const contract = behaviourContract(behaviour.kind)\n const properties = new Map(\n behaviourProperties(graph, owner).map((definition) => [definition.id, definition])\n )\n const bound = (propertyId: string | undefined, type: ComponentPropertyDefinition['type'][]) => {\n const definition = propertyId ? properties.get(propertyId) : undefined\n return !!definition && type.includes(definition.type)\n }\n const values = contract.values\n .filter((value) => value.required)\n .filter((value) =>\n value.type === 'text'\n ? !bound(textBinding(behaviour, value.id), ['TEXT'])\n : value.type === 'boolean' &&\n !bound(booleanBinding(behaviour, value.id)?.propertyId, ['VARIANT', 'BOOLEAN'])\n )\n .map((value) => value.id)\n const parts = contract.parts\n .filter((part) => part.required && !bound(partBinding(behaviour, part.id), ['SLOT']))\n .map((part) => part.id)\n const states =\n behaviour.states && !bound(behaviour.states.propertyId, ['VARIANT']) ? ['states'] : []\n return [...values, ...parts, ...states]\n}\n\n/** Variant value names that usually mean each interaction state, compared case-insensitively. */\nconst STATE_NAMES: Record<InteractionState, readonly string[]> = {\n rest: ['default', 'rest', 'idle', 'normal', 'enabled'],\n hover: ['hover', 'hovered', 'hovering'],\n pressed: ['pressed', 'active', 'down', 'pressing'],\n focus: ['focus', 'focused', 'focus visible', 'focus-visible'],\n disabled: ['disabled', 'inactive'],\n invalid: ['invalid', 'error']\n}\n\n/**\n * A kind of control's interaction states for a variant property, each mapped to the value whose\n * name means it, such as `Hover` or `Pressed`; states without such a value are left unset.\n */\nexport function guessInteractionStates(\n kind: BehaviourKind,\n propertyId: string,\n values: readonly string[]\n): BehaviourInteractionStates {\n const states: BehaviourInteractionStates = { propertyId }\n for (const state of interactionStatesOf(kind)) {\n const match = values.find((value) => STATE_NAMES[state].includes(value.trim().toLowerCase()))\n if (match) states[state] = match\n }\n return states\n}\n\n/**\n * The behaviour with every component property id it binds renamed by `rename`, for formats that\n * give properties new ids on write, such as `.fig` with its GUIDs.\n */\nexport function renameBehaviourProperties(\n behaviour: Behaviour,\n rename: (propertyId: string) => string\n): Behaviour {\n return {\n ...behaviour,\n booleans: mapValues(behaviour.booleans, (binding) => ({\n ...binding,\n propertyId: rename(binding.propertyId)\n })),\n texts: mapValues(behaviour.texts, (binding) => ({ propertyId: rename(binding.propertyId) })),\n parts: mapValues(behaviour.parts, rename),\n ...(behaviour.states\n ? { states: { ...behaviour.states, propertyId: rename(behaviour.states.propertyId) } }\n : {})\n }\n}\n"],"mappings":";;;;;;AAoBA,MAAa,0BAAmD;CAC9D,KAAK;CACL,KAAK;CACL,MAAM;CACN,SAAS;AACX;;AAGA,SAAgB,eACd,WACA,SACqC;CACrC,OAAO,OAAO,OAAO,UAAU,UAAU,OAAO,IAAI,UAAU,SAAS,WAAW,KAAA;AACpF;;AAGA,SAAgB,YAAY,WAAsB,QAAoC;CACpF,OAAO,OAAO,OAAO,UAAU,OAAO,MAAM,IAAI,UAAU,MAAM,UAAU,KAAA;AAC5E;;AAGA,SAAgB,YAAY,WAAsB,SAAqC;CACrF,OAAO,OAAO,OAAO,UAAU,OAAO,OAAO,IAAI,UAAU,MAAM,QAAQ,CAAC,aAAa,KAAA;AACzF;;AAGA,SAAgB,eACd,WACA,SACqC;CACrC,OAAO,OAAO,OAAO,UAAU,SAAS,OAAO,IAAI,UAAU,QAAQ,WAAW,KAAA;AAClF;;AAGA,SAAgB,eAAe,MAAgC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AAW;CACxD,KAAK,MAAM,SAAS,oBAAoB,IAAI,GAAG;EAC7C,MAAM,QAAQ,OAAO,MAAM,UAAU,YAAY,MAAM,CAAC,SAAS,MAAM,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC;EAC5F,IAAI,OAAO,OAAO,SAAS;CAC7B;CACA,OAAO;AACT;;;;;AAMA,SAAgB,0BACd,WACA,QACW;CACX,OAAO;EACL,GAAG;EACH,UAAU,UAAU,UAAU,WAAW,aAAa;GACpD,GAAG;GACH,YAAY,OAAO,QAAQ,UAAU;EACvC,EAAE;EACF,OAAO,UAAU,UAAU,QAAQ,aAAa,EAAE,YAAY,OAAO,QAAQ,UAAU,EAAE,EAAE;EAC3F,OAAO,UAAU,UAAU,OAAO,MAAM;EACxC,GAAI,UAAU,SACV,EAAE,QAAQ;GAAE,GAAG,UAAU;GAAQ,YAAY,OAAO,UAAU,OAAO,UAAU;EAAE,EAAE,IACnF,CAAC;CACP;AACF"}
|
|
@@ -30,6 +30,7 @@ declare const interactionStateValues: {
|
|
|
30
30
|
pressed: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
31
31
|
focus: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
32
32
|
disabled: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
33
|
+
invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
33
34
|
};
|
|
34
35
|
declare const interactionStatesSchema: v.ObjectSchema<{
|
|
35
36
|
readonly rest: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -37,10 +38,11 @@ declare const interactionStatesSchema: v.ObjectSchema<{
|
|
|
37
38
|
readonly pressed: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
38
39
|
readonly focus: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
39
40
|
readonly disabled: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
41
|
+
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
40
42
|
readonly propertyId: v.StringSchema<undefined>;
|
|
41
43
|
}, undefined>;
|
|
42
|
-
declare const
|
|
43
|
-
readonly kind: v.PicklistSchema<readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "collapsible", "accordion"], undefined>;
|
|
44
|
+
declare const storedBehaviourSchema: v.ObjectSchema<{
|
|
45
|
+
readonly kind: v.PicklistSchema<readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "tab", "collapsible", "accordion"], undefined>;
|
|
44
46
|
/** Boolean values, by value id, bound to component properties. */
|
|
45
47
|
readonly booleans: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
46
48
|
readonly propertyId: v.StringSchema<undefined>;
|
|
@@ -72,11 +74,122 @@ declare const behaviourSchema: v.ObjectSchema<{
|
|
|
72
74
|
readonly pressed: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
73
75
|
readonly focus: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
74
76
|
readonly disabled: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
77
|
+
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
75
78
|
readonly propertyId: v.StringSchema<undefined>;
|
|
76
79
|
}, undefined>, undefined>;
|
|
77
80
|
}, undefined>;
|
|
81
|
+
type StoredBehaviour = v.InferOutput<typeof storedBehaviourSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* A stored behaviour. An invalid state on a kind of control that has none, such as a button,
|
|
84
|
+
* is dropped as it is read, so nothing draws or exports it; the rest of the behaviour stays.
|
|
85
|
+
*/
|
|
86
|
+
declare const behaviourSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
87
|
+
readonly kind: v.PicklistSchema<readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "tab", "collapsible", "accordion"], undefined>;
|
|
88
|
+
/** Boolean values, by value id, bound to component properties. */
|
|
89
|
+
readonly booleans: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
90
|
+
readonly propertyId: v.StringSchema<undefined>;
|
|
91
|
+
/** For a variant property: the values that mean on and off. */
|
|
92
|
+
readonly on: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
93
|
+
readonly off: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
94
|
+
}, undefined>, undefined>;
|
|
95
|
+
/** Text values, by value id, bound to text properties. */
|
|
96
|
+
readonly texts: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
97
|
+
readonly propertyId: v.StringSchema<undefined>;
|
|
98
|
+
}, undefined>, undefined>, {}>;
|
|
99
|
+
/** Number values, by value id: the range the behaviour keeps itself. */
|
|
100
|
+
readonly numbers: v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
101
|
+
readonly min: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
102
|
+
readonly max: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
103
|
+
readonly step: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
104
|
+
readonly default: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
105
|
+
}, undefined>, v.CheckAction<{
|
|
106
|
+
min: number;
|
|
107
|
+
max: number;
|
|
108
|
+
step: number;
|
|
109
|
+
default: number;
|
|
110
|
+
}, "A number value needs max above min and a positive step">]>, undefined>;
|
|
111
|
+
/** Parts, by part id, bound to slot properties. */
|
|
112
|
+
readonly parts: v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>;
|
|
113
|
+
readonly states: v.OptionalSchema<v.ObjectSchema<{
|
|
114
|
+
readonly rest: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
115
|
+
readonly hover: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
116
|
+
readonly pressed: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
117
|
+
readonly focus: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
118
|
+
readonly disabled: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
119
|
+
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
120
|
+
readonly propertyId: v.StringSchema<undefined>;
|
|
121
|
+
}, undefined>, undefined>;
|
|
122
|
+
}, undefined>, v.TransformAction<{
|
|
123
|
+
kind: "button" | "textField" | "textarea" | "numberField" | "toggle" | "switch" | "checkbox" | "radio" | "radioGroup" | "toggleGroup" | "slider" | "progress" | "tabs" | "tab" | "collapsible" | "accordion";
|
|
124
|
+
booleans: {
|
|
125
|
+
[x: string]: {
|
|
126
|
+
propertyId: string;
|
|
127
|
+
on?: string | undefined;
|
|
128
|
+
off?: string | undefined;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
texts: {
|
|
132
|
+
[x: string]: {
|
|
133
|
+
propertyId: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
numbers: {
|
|
137
|
+
[x: string]: {
|
|
138
|
+
min: number;
|
|
139
|
+
max: number;
|
|
140
|
+
step: number;
|
|
141
|
+
default: number;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
parts: {
|
|
145
|
+
[x: string]: string;
|
|
146
|
+
};
|
|
147
|
+
states?: {
|
|
148
|
+
rest?: string | undefined;
|
|
149
|
+
hover?: string | undefined;
|
|
150
|
+
pressed?: string | undefined;
|
|
151
|
+
focus?: string | undefined;
|
|
152
|
+
disabled?: string | undefined;
|
|
153
|
+
invalid?: string | undefined;
|
|
154
|
+
propertyId: string;
|
|
155
|
+
} | undefined;
|
|
156
|
+
}, {
|
|
157
|
+
kind: "button" | "textField" | "textarea" | "numberField" | "toggle" | "switch" | "checkbox" | "radio" | "radioGroup" | "toggleGroup" | "slider" | "progress" | "tabs" | "tab" | "collapsible" | "accordion";
|
|
158
|
+
booleans: {
|
|
159
|
+
[x: string]: {
|
|
160
|
+
propertyId: string;
|
|
161
|
+
on?: string | undefined;
|
|
162
|
+
off?: string | undefined;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
texts: {
|
|
166
|
+
[x: string]: {
|
|
167
|
+
propertyId: string;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
numbers: {
|
|
171
|
+
[x: string]: {
|
|
172
|
+
min: number;
|
|
173
|
+
max: number;
|
|
174
|
+
step: number;
|
|
175
|
+
default: number;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
parts: {
|
|
179
|
+
[x: string]: string;
|
|
180
|
+
};
|
|
181
|
+
states?: {
|
|
182
|
+
rest?: string | undefined;
|
|
183
|
+
hover?: string | undefined;
|
|
184
|
+
pressed?: string | undefined;
|
|
185
|
+
focus?: string | undefined;
|
|
186
|
+
disabled?: string | undefined;
|
|
187
|
+
invalid?: string | undefined;
|
|
188
|
+
propertyId: string;
|
|
189
|
+
} | undefined;
|
|
190
|
+
}>]>;
|
|
78
191
|
/** How a main component behaves as a control, as kept in its plugin data. */
|
|
79
|
-
type Behaviour =
|
|
192
|
+
type Behaviour = StoredBehaviour;
|
|
80
193
|
type BehaviourBooleanBinding = v.InferOutput<typeof booleanBindingSchema>;
|
|
81
194
|
type BehaviourNumberSettings = v.InferOutput<typeof numberSettingsSchema>;
|
|
82
195
|
type BehaviourInteractionStates = v.InferOutput<typeof interactionStatesSchema>;
|
|
@@ -86,7 +199,7 @@ type BehaviourInteractionStates = v.InferOutput<typeof interactionStatesSchema>;
|
|
|
86
199
|
* number field's own range.
|
|
87
200
|
*/
|
|
88
201
|
declare const behaviourSpecSchema: v.ObjectSchema<{
|
|
89
|
-
readonly kind: v.PicklistSchema<readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "collapsible", "accordion"], undefined>;
|
|
202
|
+
readonly kind: v.PicklistSchema<readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "tab", "collapsible", "accordion"], undefined>;
|
|
90
203
|
readonly values: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.ObjectSchema<{
|
|
91
204
|
readonly property: v.StringSchema<undefined>;
|
|
92
205
|
readonly on: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -105,6 +218,7 @@ declare const behaviourSpecSchema: v.ObjectSchema<{
|
|
|
105
218
|
readonly pressed: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
106
219
|
readonly focus: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
107
220
|
readonly disabled: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
221
|
+
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
108
222
|
readonly property: v.StringSchema<undefined>;
|
|
109
223
|
}, undefined>], undefined>, undefined>;
|
|
110
224
|
}, undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/behaviours/schema.ts"],"mappings":";;cAIM,sBAAoB,EAAA;;;;;;;iBAQV,cAAc;EAAY;EAAa;EAAa;;cAI9D,sBAAoB,EAAA,yBAAA,EAAA;;;;;;;;;;;;cAcb
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/behaviours/schema.ts"],"mappings":";;cAIM,sBAAoB,EAAA;;;;;;;iBAQV,cAAc;EAAY;EAAa;EAAa;;cAI9D,sBAAoB,EAAA,yBAAA,EAAA;;;;;;;;;;;;cAcb;;;;;;;;cASP,yBAAuB,EAAA;;;;;;;;;cAEvB,uBAAqB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAatB,kBAAkB,EAAE,mBAAmB;;;;;cAa/B,iBAAe,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAGhB,YAAY;KACZ,0BAA0B,EAAE,mBAAmB;KAC/C,0BAA0B,EAAE,mBAAmB;KAC/C,6BAA6B,EAAE,mBAAmB;;;;;;cAOjD,qBAAmB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;KA4BpB,gBAAgB,EAAE,mBAAmB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BEHAVIOUR_KINDS } from "./kinds.js";
|
|
1
|
+
import { BEHAVIOUR_KINDS, hasInvalidState } from "./kinds.js";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
//#region src/behaviours/schema.ts
|
|
4
4
|
const booleanBindingSchema = v.object({
|
|
@@ -23,13 +23,14 @@ const interactionStateValues = {
|
|
|
23
23
|
hover: v.optional(v.string()),
|
|
24
24
|
pressed: v.optional(v.string()),
|
|
25
25
|
focus: v.optional(v.string()),
|
|
26
|
-
disabled: v.optional(v.string())
|
|
26
|
+
disabled: v.optional(v.string()),
|
|
27
|
+
invalid: v.optional(v.string())
|
|
27
28
|
};
|
|
28
29
|
const interactionStatesSchema = v.object({
|
|
29
30
|
propertyId: v.string(),
|
|
30
31
|
...interactionStateValues
|
|
31
32
|
});
|
|
32
|
-
const
|
|
33
|
+
const storedBehaviourSchema = v.object({
|
|
33
34
|
kind: v.picklist(BEHAVIOUR_KINDS),
|
|
34
35
|
/** Boolean values, by value id, bound to component properties. */
|
|
35
36
|
booleans: v.record(v.string(), booleanBindingSchema),
|
|
@@ -41,6 +42,20 @@ const behaviourSchema = v.object({
|
|
|
41
42
|
parts: v.record(v.string(), v.string()),
|
|
42
43
|
states: v.optional(interactionStatesSchema)
|
|
43
44
|
});
|
|
45
|
+
/** The behaviour without an invalid state when its kind of control has none. */
|
|
46
|
+
function withoutUnsupportedStates(behaviour) {
|
|
47
|
+
if (behaviour.states?.invalid === void 0 || hasInvalidState(behaviour.kind)) return behaviour;
|
|
48
|
+
const { invalid: _invalid, ...states } = behaviour.states;
|
|
49
|
+
return {
|
|
50
|
+
...behaviour,
|
|
51
|
+
states
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A stored behaviour. An invalid state on a kind of control that has none, such as a button,
|
|
56
|
+
* is dropped as it is read, so nothing draws or exports it; the rest of the behaviour stays.
|
|
57
|
+
*/
|
|
58
|
+
const behaviourSchema = v.pipe(storedBehaviourSchema, v.transform(withoutUnsupportedStates));
|
|
44
59
|
/**
|
|
45
60
|
* A behaviour as scripts, tools, and JSX write it: component properties and slots by name, not
|
|
46
61
|
* by id. Values are boolean or text values by their contract id; numbers are a slider's or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/behaviours/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { BEHAVIOUR_KINDS, type InteractionState } from './kinds'\n\nconst booleanBindingSchema = v.object({\n propertyId: v.string(),\n /** For a variant property: the values that mean on and off. */\n on: v.optional(v.string()),\n off: v.optional(v.string())\n})\n\n/** Whether a number value's range can be stepped through: `max` above `min`, a positive step. */\nexport function isNumberRange(settings: { min: number; max: number; step: number }): boolean {\n return settings.max > settings.min && settings.step > 0\n}\n\nconst numberSettingsSchema = v.pipe(\n v.object({\n min: v.pipe(v.number(), v.finite()),\n max: v.pipe(v.number(), v.finite()),\n step: v.pipe(v.number(), v.finite()),\n default: v.pipe(v.number(), v.finite())\n }),\n v.check(\n (settings) => isNumberRange(settings),\n 'A number value needs max above min and a positive step'\n )\n)\n\n/** Each interaction state's variant value, by state; a state left out shows the rest value. */\nexport const interactionStateValues = {\n rest: v.optional(v.string()),\n hover: v.optional(v.string()),\n pressed: v.optional(v.string()),\n focus: v.optional(v.string()),\n disabled: v.optional(v.string())\n} satisfies Record<InteractionState, unknown>\n\nconst interactionStatesSchema = v.object({ propertyId: v.string(), ...interactionStateValues })\n\
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/behaviours/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { BEHAVIOUR_KINDS, hasInvalidState, type InteractionState } from './kinds'\n\nconst booleanBindingSchema = v.object({\n propertyId: v.string(),\n /** For a variant property: the values that mean on and off. */\n on: v.optional(v.string()),\n off: v.optional(v.string())\n})\n\n/** Whether a number value's range can be stepped through: `max` above `min`, a positive step. */\nexport function isNumberRange(settings: { min: number; max: number; step: number }): boolean {\n return settings.max > settings.min && settings.step > 0\n}\n\nconst numberSettingsSchema = v.pipe(\n v.object({\n min: v.pipe(v.number(), v.finite()),\n max: v.pipe(v.number(), v.finite()),\n step: v.pipe(v.number(), v.finite()),\n default: v.pipe(v.number(), v.finite())\n }),\n v.check(\n (settings) => isNumberRange(settings),\n 'A number value needs max above min and a positive step'\n )\n)\n\n/** Each interaction state's variant value, by state; a state left out shows the rest value. */\nexport const interactionStateValues = {\n rest: v.optional(v.string()),\n hover: v.optional(v.string()),\n pressed: v.optional(v.string()),\n focus: v.optional(v.string()),\n disabled: v.optional(v.string()),\n invalid: v.optional(v.string())\n} satisfies Record<InteractionState, unknown>\n\nconst interactionStatesSchema = v.object({ propertyId: v.string(), ...interactionStateValues })\n\nconst storedBehaviourSchema = v.object({\n kind: v.picklist(BEHAVIOUR_KINDS),\n /** Boolean values, by value id, bound to component properties. */\n booleans: v.record(v.string(), booleanBindingSchema),\n /** Text values, by value id, bound to text properties. */\n texts: v.optional(v.record(v.string(), v.object({ propertyId: v.string() })), {}),\n /** Number values, by value id: the range the behaviour keeps itself. */\n numbers: v.record(v.string(), numberSettingsSchema),\n /** Parts, by part id, bound to slot properties. */\n parts: v.record(v.string(), v.string()),\n states: v.optional(interactionStatesSchema)\n})\n\ntype StoredBehaviour = v.InferOutput<typeof storedBehaviourSchema>\n\n/** The behaviour without an invalid state when its kind of control has none. */\nfunction withoutUnsupportedStates(behaviour: StoredBehaviour): StoredBehaviour {\n if (behaviour.states?.invalid === undefined || hasInvalidState(behaviour.kind)) return behaviour\n const { invalid: _invalid, ...states } = behaviour.states\n return { ...behaviour, states }\n}\n\n/**\n * A stored behaviour. An invalid state on a kind of control that has none, such as a button,\n * is dropped as it is read, so nothing draws or exports it; the rest of the behaviour stays.\n */\nexport const behaviourSchema = v.pipe(storedBehaviourSchema, v.transform(withoutUnsupportedStates))\n\n/** How a main component behaves as a control, as kept in its plugin data. */\nexport type Behaviour = StoredBehaviour\nexport type BehaviourBooleanBinding = v.InferOutput<typeof booleanBindingSchema>\nexport type BehaviourNumberSettings = v.InferOutput<typeof numberSettingsSchema>\nexport type BehaviourInteractionStates = v.InferOutput<typeof interactionStatesSchema>\n\n/**\n * A behaviour as scripts, tools, and JSX write it: component properties and slots by name, not\n * by id. Values are boolean or text values by their contract id; numbers are a slider's or\n * number field's own range.\n */\nexport const behaviourSpecSchema = v.object({\n kind: v.picklist(BEHAVIOUR_KINDS),\n values: v.optional(\n v.record(\n v.string(),\n v.union([\n v.string(),\n v.object({ property: v.string(), on: v.optional(v.string()), off: v.optional(v.string()) })\n ])\n )\n ),\n numbers: v.optional(\n v.record(\n v.string(),\n v.object({\n min: v.optional(v.number()),\n max: v.optional(v.number()),\n step: v.optional(v.number()),\n default: v.optional(v.number())\n })\n )\n ),\n parts: v.optional(v.record(v.string(), v.string())),\n states: v.optional(\n v.union([v.string(), v.object({ property: v.string(), ...interactionStateValues })])\n )\n})\n\nexport type BehaviourSpec = v.InferOutput<typeof behaviourSpecSchema>\n"],"mappings":";;;AAIA,MAAM,uBAAuB,EAAE,OAAO;CACpC,YAAY,EAAE,OAAO;;CAErB,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;CACzB,KAA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;;;;
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../src/behaviours/spec.ts"],"mappings":";;;;;;;;iBAoBgB,WACd,4BACA;EAAY;EAAa;;EACtB;EAAa;;;;;;;iBAyFF,kBACd,OAAO,YACP,OAAO,WACP,MAAM,gBACL;;iBAgCa,gBACd,OAAO,YACP,OAAO,WACP,WAAW,YACV"}
|
package/dist/behaviours/spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { behaviourContract } from "./kinds.js";
|
|
1
|
+
import { behaviourContract, hasInvalidState } from "./kinds.js";
|
|
2
2
|
import { isNumberRange } from "./schema.js";
|
|
3
3
|
import { behaviourProperties, emptyBehaviour, guessInteractionStates, textBinding } from "./model.js";
|
|
4
4
|
import { omitBy } from "es-toolkit/object";
|
|
@@ -72,12 +72,13 @@ function resolveValue(behaviour, properties, valueId, binding) {
|
|
|
72
72
|
}
|
|
73
73
|
function resolveStates(behaviour, properties, states) {
|
|
74
74
|
const definition = findProperty(properties, typeof states === "string" ? states : states.property, ["VARIANT"], "states");
|
|
75
|
-
const guessed = guessInteractionStates(definition.id, definition.variantOptions ?? []);
|
|
75
|
+
const guessed = guessInteractionStates(behaviour.kind, definition.id, definition.variantOptions ?? []);
|
|
76
76
|
if (typeof states === "string") {
|
|
77
77
|
behaviour.states = guessed;
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
const { property: _property, ...values } = states;
|
|
81
|
+
if (values.invalid !== void 0 && !hasInvalidState(behaviour.kind)) throw new Error(`A ${behaviour.kind} has no invalid state`);
|
|
81
82
|
behaviour.states = {
|
|
82
83
|
...guessed,
|
|
83
84
|
...stripUndefined(values)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.js","names":[],"sources":["../../src/behaviours/spec.ts"],"sourcesContent":["import { omitBy } from 'es-toolkit/object'\n\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\nimport { behaviourContract } from './kinds'\nimport { behaviourProperties, emptyBehaviour, guessInteractionStates, textBinding } from './model'\nimport { isNumberRange, type Behaviour, type BehaviourSpec } from './schema'\n\n/** Variant values that usually mean on, compared case-insensitively. */\nconst ON_NAMES = ['on', 'true', 'yes', 'checked', 'pressed', 'open', 'selected', 'active']\nconst OFF_NAMES = ['off', 'false', 'no', 'unchecked', 'closed', 'default', 'inactive']\n\nfunction named(names: readonly string[], options: readonly string[]): string | undefined {\n return options.find((option) => names.includes(option.trim().toLowerCase()))\n}\n\n/**\n * The variant values that likely mean on and off: names such as On, True, or Checked first,\n * then the values in order.\n */\nexport function guessOnOff(\n options: readonly string[],\n explicit: { on?: string; off?: string } = {}\n): { on?: string; off?: string } {\n const on = explicit.on ?? named(ON_NAMES, options) ?? options[0]\n const off = explicit.off ?? named(OFF_NAMES, options) ?? options.find((option) => option !== on)\n return { on, off }\n}\n\nfunction findProperty(\n properties: readonly ComponentPropertyDefinition[],\n name: string,\n types: readonly ComponentPropertyDefinition['type'][],\n what: string\n): ComponentPropertyDefinition {\n const found = properties.find((item) => item.name === name && types.includes(item.type))\n if (found) return found\n const available = properties.filter((item) => types.includes(item.type)).map((item) => item.name)\n throw new Error(\n `${what} needs a ${types.join(' or ')} property named \"${name}\"; the component has ${\n available.length ? available.map((item) => `\"${item}\"`).join(', ') : 'none'\n }`\n )\n}\n\ntype ValueBinding = NonNullable<BehaviourSpec['values']>[string]\ntype StatesSpec = NonNullable<BehaviourSpec['states']>\n\nfunction listed(items: readonly { id: string }[]): string {\n return items.map((item) => `\"${item.id}\"`).join(', ')\n}\n\n/** Bind a boolean or text value to the property named in its binding. */\nfunction resolveValue(\n behaviour: Behaviour,\n properties: readonly ComponentPropertyDefinition[],\n valueId: string,\n binding: ValueBinding\n): void {\n const contract = behaviourContract(behaviour.kind)\n const bindable = contract.values.filter((item) => item.type === 'boolean' || item.type === 'text')\n const value = bindable.find((item) => item.id === valueId)\n if (!value)\n throw new Error(\n `A ${behaviour.kind} has no boolean or text value \"${valueId}\"; it has ${listed(bindable)}`\n )\n const name = typeof binding === 'string' ? binding : binding.property\n if (value.type === 'text') {\n behaviour.texts[valueId] = { propertyId: findProperty(properties, name, ['TEXT'], valueId).id }\n return\n }\n const definition = findProperty(properties, name, ['VARIANT', 'BOOLEAN'], valueId)\n if (definition.type === 'BOOLEAN') {\n behaviour.booleans[valueId] = { propertyId: definition.id }\n return\n }\n const options = definition.variantOptions ?? []\n const explicit: { on?: string; off?: string } = typeof binding === 'string' ? {} : binding\n const { on, off } = guessOnOff(options, explicit)\n for (const choice of [on, off])\n if (choice !== undefined && !options.includes(choice))\n throw new Error(`\"${definition.name}\" has no value \"${choice}\"; it has ${options.join(', ')}`)\n behaviour.booleans[valueId] = { propertyId: definition.id, on, off }\n}\n\nfunction resolveStates(\n behaviour: Behaviour,\n properties: readonly ComponentPropertyDefinition[],\n states: StatesSpec\n): void {\n const name = typeof states === 'string' ? states : states.property\n const definition = findProperty(properties, name, ['VARIANT'], 'states')\n const guessed = guessInteractionStates(definition.id, definition.variantOptions ?? [])\n if (typeof states === 'string') {\n behaviour.states = guessed\n return\n }\n const { property: _property, ...values } = states\n behaviour.states = { ...guessed, ...stripUndefined(values) }\n}\n\n/**\n * The stored behaviour for a spec, with names resolved to the owner's property and slot ids. A\n * name the component lacks, a value the kind does not have, or a variant value the property\n * does not offer fails with a message naming what exists.\n */\nexport function behaviourFromSpec(\n graph: SceneGraph,\n owner: SceneNode,\n spec: BehaviourSpec\n): Behaviour {\n const contract = behaviourContract(spec.kind)\n const properties = behaviourProperties(graph, owner)\n const behaviour = emptyBehaviour(spec.kind)\n for (const [valueId, binding] of Object.entries(spec.values ?? {}))\n resolveValue(behaviour, properties, valueId, binding)\n const numbers = contract.values.filter((item) => item.type === 'number')\n for (const [valueId, settings] of Object.entries(spec.numbers ?? {})) {\n if (!numbers.some((item) => item.id === valueId))\n throw new Error(`A ${spec.kind} has no number value \"${valueId}\"; it has ${listed(numbers)}`)\n const range = { ...behaviour.numbers[valueId], ...stripUndefined(settings) }\n if (!isNumberRange(range))\n throw new Error(`\"${valueId}\" needs max above min and a positive step`)\n behaviour.numbers[valueId] = range\n }\n for (const [partId, slotName] of Object.entries(spec.parts ?? {})) {\n if (!contract.parts.some((item) => item.id === partId))\n throw new Error(`A ${spec.kind} has no part \"${partId}\"; it has ${listed(contract.parts)}`)\n const id = findProperty(properties, slotName, ['SLOT'], partId).id\n const taken = Object.entries(behaviour.parts).find(([, slot]) => slot === id)?.[0]\n if (taken) throw new Error(`\"${slotName}\" is already the ${taken}; a slot draws one part`)\n behaviour.parts[partId] = id\n }\n if (spec.states !== undefined) resolveStates(behaviour, properties, spec.states)\n return behaviour\n}\n\nfunction stripUndefined<T extends Record<string, unknown>>(record: T): Partial<T> {\n return omitBy(record, (value) => value === undefined)\n}\n\n/** The spec a stored behaviour reads as, with ids back to names; unresolved bindings are left out. */\nexport function behaviourToSpec(\n graph: SceneGraph,\n owner: SceneNode,\n behaviour: Behaviour\n): BehaviourSpec {\n const properties = behaviourProperties(graph, owner)\n const nameOf = (id: string | undefined) => properties.find((item) => item.id === id)?.name\n const values: NonNullable<BehaviourSpec['values']> = {}\n for (const [valueId, binding] of Object.entries(behaviour.booleans)) {\n const name = nameOf(binding.propertyId)\n if (name)\n values[valueId] =\n binding.on || binding.off ? { property: name, on: binding.on, off: binding.off } : name\n }\n for (const valueId of Object.keys(behaviour.texts)) {\n const name = nameOf(textBinding(behaviour, valueId))\n if (name) values[valueId] = name\n }\n const parts = Object.fromEntries(\n Object.entries(behaviour.parts).flatMap(([partId, id]) => {\n const name = nameOf(id)\n return name ? [[partId, name]] : []\n })\n )\n const statesName = nameOf(behaviour.states?.propertyId)\n const spec: BehaviourSpec = { kind: behaviour.kind }\n if (Object.keys(values).length) spec.values = values\n if (Object.keys(behaviour.numbers).length) spec.numbers = structuredClone(behaviour.numbers)\n if (Object.keys(parts).length) spec.parts = parts\n if (behaviour.states && statesName)\n spec.states = {\n ...stripUndefined({ ...behaviour.states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ACZ,GAAG,eAAe;GAAE,GAAG,UAAU;GAAQ,YAAY,KAAA;EAAU,CAAC;EAChE,UAAU;CACZ;CACF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"spec.js","names":[],"sources":["../../src/behaviours/spec.ts"],"sourcesContent":["import { omitBy } from 'es-toolkit/object'\n\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\nimport { behaviourContract, hasInvalidState } from './kinds'\nimport { behaviourProperties, emptyBehaviour, guessInteractionStates, textBinding } from './model'\nimport { isNumberRange, type Behaviour, type BehaviourSpec } from './schema'\n\n/** Variant values that usually mean on, compared case-insensitively. */\nconst ON_NAMES = ['on', 'true', 'yes', 'checked', 'pressed', 'open', 'selected', 'active']\nconst OFF_NAMES = ['off', 'false', 'no', 'unchecked', 'closed', 'default', 'inactive']\n\nfunction named(names: readonly string[], options: readonly string[]): string | undefined {\n return options.find((option) => names.includes(option.trim().toLowerCase()))\n}\n\n/**\n * The variant values that likely mean on and off: names such as On, True, or Checked first,\n * then the values in order.\n */\nexport function guessOnOff(\n options: readonly string[],\n explicit: { on?: string; off?: string } = {}\n): { on?: string; off?: string } {\n const on = explicit.on ?? named(ON_NAMES, options) ?? options[0]\n const off = explicit.off ?? named(OFF_NAMES, options) ?? options.find((option) => option !== on)\n return { on, off }\n}\n\nfunction findProperty(\n properties: readonly ComponentPropertyDefinition[],\n name: string,\n types: readonly ComponentPropertyDefinition['type'][],\n what: string\n): ComponentPropertyDefinition {\n const found = properties.find((item) => item.name === name && types.includes(item.type))\n if (found) return found\n const available = properties.filter((item) => types.includes(item.type)).map((item) => item.name)\n throw new Error(\n `${what} needs a ${types.join(' or ')} property named \"${name}\"; the component has ${\n available.length ? available.map((item) => `\"${item}\"`).join(', ') : 'none'\n }`\n )\n}\n\ntype ValueBinding = NonNullable<BehaviourSpec['values']>[string]\ntype StatesSpec = NonNullable<BehaviourSpec['states']>\n\nfunction listed(items: readonly { id: string }[]): string {\n return items.map((item) => `\"${item.id}\"`).join(', ')\n}\n\n/** Bind a boolean or text value to the property named in its binding. */\nfunction resolveValue(\n behaviour: Behaviour,\n properties: readonly ComponentPropertyDefinition[],\n valueId: string,\n binding: ValueBinding\n): void {\n const contract = behaviourContract(behaviour.kind)\n const bindable = contract.values.filter((item) => item.type === 'boolean' || item.type === 'text')\n const value = bindable.find((item) => item.id === valueId)\n if (!value)\n throw new Error(\n `A ${behaviour.kind} has no boolean or text value \"${valueId}\"; it has ${listed(bindable)}`\n )\n const name = typeof binding === 'string' ? binding : binding.property\n if (value.type === 'text') {\n behaviour.texts[valueId] = { propertyId: findProperty(properties, name, ['TEXT'], valueId).id }\n return\n }\n const definition = findProperty(properties, name, ['VARIANT', 'BOOLEAN'], valueId)\n if (definition.type === 'BOOLEAN') {\n behaviour.booleans[valueId] = { propertyId: definition.id }\n return\n }\n const options = definition.variantOptions ?? []\n const explicit: { on?: string; off?: string } = typeof binding === 'string' ? {} : binding\n const { on, off } = guessOnOff(options, explicit)\n for (const choice of [on, off])\n if (choice !== undefined && !options.includes(choice))\n throw new Error(`\"${definition.name}\" has no value \"${choice}\"; it has ${options.join(', ')}`)\n behaviour.booleans[valueId] = { propertyId: definition.id, on, off }\n}\n\nfunction resolveStates(\n behaviour: Behaviour,\n properties: readonly ComponentPropertyDefinition[],\n states: StatesSpec\n): void {\n const name = typeof states === 'string' ? states : states.property\n const definition = findProperty(properties, name, ['VARIANT'], 'states')\n const guessed = guessInteractionStates(\n behaviour.kind,\n definition.id,\n definition.variantOptions ?? []\n )\n if (typeof states === 'string') {\n behaviour.states = guessed\n return\n }\n const { property: _property, ...values } = states\n if (values.invalid !== undefined && !hasInvalidState(behaviour.kind))\n throw new Error(`A ${behaviour.kind} has no invalid state`)\n behaviour.states = { ...guessed, ...stripUndefined(values) }\n}\n\n/**\n * The stored behaviour for a spec, with names resolved to the owner's property and slot ids. A\n * name the component lacks, a value the kind does not have, or a variant value the property\n * does not offer fails with a message naming what exists.\n */\nexport function behaviourFromSpec(\n graph: SceneGraph,\n owner: SceneNode,\n spec: BehaviourSpec\n): Behaviour {\n const contract = behaviourContract(spec.kind)\n const properties = behaviourProperties(graph, owner)\n const behaviour = emptyBehaviour(spec.kind)\n for (const [valueId, binding] of Object.entries(spec.values ?? {}))\n resolveValue(behaviour, properties, valueId, binding)\n const numbers = contract.values.filter((item) => item.type === 'number')\n for (const [valueId, settings] of Object.entries(spec.numbers ?? {})) {\n if (!numbers.some((item) => item.id === valueId))\n throw new Error(`A ${spec.kind} has no number value \"${valueId}\"; it has ${listed(numbers)}`)\n const range = { ...behaviour.numbers[valueId], ...stripUndefined(settings) }\n if (!isNumberRange(range))\n throw new Error(`\"${valueId}\" needs max above min and a positive step`)\n behaviour.numbers[valueId] = range\n }\n for (const [partId, slotName] of Object.entries(spec.parts ?? {})) {\n if (!contract.parts.some((item) => item.id === partId))\n throw new Error(`A ${spec.kind} has no part \"${partId}\"; it has ${listed(contract.parts)}`)\n const id = findProperty(properties, slotName, ['SLOT'], partId).id\n const taken = Object.entries(behaviour.parts).find(([, slot]) => slot === id)?.[0]\n if (taken) throw new Error(`\"${slotName}\" is already the ${taken}; a slot draws one part`)\n behaviour.parts[partId] = id\n }\n if (spec.states !== undefined) resolveStates(behaviour, properties, spec.states)\n return behaviour\n}\n\nfunction stripUndefined<T extends Record<string, unknown>>(record: T): Partial<T> {\n return omitBy(record, (value) => value === undefined)\n}\n\n/** The spec a stored behaviour reads as, with ids back to names; unresolved bindings are left out. */\nexport function behaviourToSpec(\n graph: SceneGraph,\n owner: SceneNode,\n behaviour: Behaviour\n): BehaviourSpec {\n const properties = behaviourProperties(graph, owner)\n const nameOf = (id: string | undefined) => properties.find((item) => item.id === id)?.name\n const values: NonNullable<BehaviourSpec['values']> = {}\n for (const [valueId, binding] of Object.entries(behaviour.booleans)) {\n const name = nameOf(binding.propertyId)\n if (name)\n values[valueId] =\n binding.on || binding.off ? { property: name, on: binding.on, off: binding.off } : name\n }\n for (const valueId of Object.keys(behaviour.texts)) {\n const name = nameOf(textBinding(behaviour, valueId))\n if (name) values[valueId] = name\n }\n const parts = Object.fromEntries(\n Object.entries(behaviour.parts).flatMap(([partId, id]) => {\n const name = nameOf(id)\n return name ? [[partId, name]] : []\n })\n )\n const statesName = nameOf(behaviour.states?.propertyId)\n const spec: BehaviourSpec = { kind: behaviour.kind }\n if (Object.keys(values).length) spec.values = values\n if (Object.keys(behaviour.numbers).length) spec.numbers = structuredClone(behaviour.numbers)\n if (Object.keys(parts).length) spec.parts = parts\n if (behaviour.states && statesName)\n spec.states = {\n ...stripUndefined({ ...behaviour.states, propertyId: undefined }),\n property: statesName\n }\n return spec\n}\n"],"mappings":";;;;;;AASA,MAAM,WAAW;CAAC;CAAM;CAAQ;CAAO;CAAW;CAAW;CAAQ;CAAY;AAAQ;AACzF,MAAM,YAAY;CAAC;CAAO;CAAS;CAAM;CAAa;CAAU;CAAW;AAAU;AAErF,SAAS,MAAM,OAA0B,SAAgD;CACvF,OAAO,QAAQ,MAAM,WAAW,MAAM,SAAS,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC;AAC7E;;;;;AAMA,SAAgB,WACd,SACA,WAA0C,CAAC,GACZ;CAC/B,MAAM,KAAK,SAAS,MAAM,MAAM,UAAU,OAAO,KAAK,QAAQ;CAE9D,OAAO;EAAE;EAAI,KADD,SAAS,OAAO,MAAM,WAAW,OAAO,KAAK,QAAQ,MAAM,WAAW,WAAW,EAAE;CAC9E;AACnB;AAEA,SAAS,aACP,YACA,MACA,OACA,MAC6B;CAC7B,MAAM,QAAQ,WAAW,MAAM,SAAS,KAAK,SAAS,QAAQ,MAAM,SAAS,KAAK,IAAI,CAAC;CACvF,IAAI,OAAO,OAAO;CAClB,MAAM,YAAY,WAAW,QAAQ,SAAS,MAAM,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,KAAK,IAAI;CAChG,MAAM,IAAI,MACR,GAAG,KAAK,WAAW,MAAM,KAAK,MAAM,EAAE,m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K,CAAC,CAAC,SAAS,CAAC,QAAQ,QAAQ;EACxD,MAAM,OAAO,OAAO,EAAE;EACtB,OAAO,OAAO,CAAC,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC;CACpC,CAAC,CACH;CACA,MAAM,aAAa,OAAO,UAAU,QAAQ,UAAU;CACtD,MAAM,OAAsB,EAAE,MAAM,UAAU,KAAK;CACnD,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,QAAQ,KAAK,SAAS;CAC9C,IAAI,OAAO,KAAK,UAAU,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,gBAAgB,UAAU,OAAO;CAC3F,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,KAAK,QAAQ;CAC5C,IAAI,UAAU,UAAU,YACtB,KAAK,SAAS;EACZ,GAAG,eAAe;GAAE,GAAG,UAAU;GAAQ,YAAY,KAAA;EAAU,CAAC;EAChE,UAAU;CACZ;CACF,OAAO;AACT"}
|
package/dist/bindings.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { effectBindableProperties, effectBindingTarget } from "./variables/fields.js";
|
|
1
2
|
import { omit } from "es-toolkit/object";
|
|
2
3
|
//#region src/bindings.ts
|
|
4
|
+
/** Whether an effect binding names a property its effect still has: a blur binds only radius. */
|
|
5
|
+
function bindsEffectProperty(node, key) {
|
|
6
|
+
const target = effectBindingTarget(key);
|
|
7
|
+
const effect = target && node.effects.at(target.index);
|
|
8
|
+
return !effect || effectBindableProperties(effect.type).includes(target.property);
|
|
9
|
+
}
|
|
3
10
|
function removeStaleBindings(node, field, changes) {
|
|
4
11
|
const length = node[field].length;
|
|
5
12
|
const stale = Object.keys(node.boundVariables).filter((key) => {
|
|
6
13
|
if (key === field) return true;
|
|
7
14
|
if (!key.startsWith(`${field}/`)) return false;
|
|
8
15
|
const index = Number.parseInt(key.split("/")[1] ?? "", 10);
|
|
9
|
-
|
|
16
|
+
if (Number.isNaN(index) || index < 0 || index >= length) return true;
|
|
17
|
+
return field === "effects" && !bindsEffectProperty(node, key);
|
|
10
18
|
});
|
|
11
19
|
if (stale.length === 0) return;
|
|
12
20
|
node.boundVariables = omit(node.boundVariables, stale);
|
package/dist/bindings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindings.js","names":[],"sources":["../src/bindings.ts"],"sourcesContent":["import { omit } from 'es-toolkit/object'\n\nimport type { SceneNode } from './types'\n\nexport function removeStaleBindings(\n node: SceneNode,\n field: 'fills' | 'strokes',\n changes: Partial<SceneNode>\n): void {\n const length = node[field].length\n const stale = Object.keys(node.boundVariables).filter((key) => {\n if (key === field) return true\n if (!key.startsWith(`${field}/`)) return false\n const index = Number.parseInt(key.split('/')[1] ?? '', 10)\n
|
|
1
|
+
{"version":3,"file":"bindings.js","names":[],"sources":["../src/bindings.ts"],"sourcesContent":["import { omit } from 'es-toolkit/object'\n\nimport type { SceneNode } from './types'\nimport { effectBindableProperties, effectBindingTarget } from './variables/fields'\n\n/** Whether an effect binding names a property its effect still has: a blur binds only radius. */\nfunction bindsEffectProperty(node: SceneNode, key: string): boolean {\n const target = effectBindingTarget(key)\n const effect = target && node.effects.at(target.index)\n return !effect || effectBindableProperties(effect.type).includes(target.property)\n}\n\nexport function removeStaleBindings(\n node: SceneNode,\n field: 'fills' | 'strokes' | 'effects',\n changes: Partial<SceneNode>\n): void {\n const length = node[field].length\n const stale = Object.keys(node.boundVariables).filter((key) => {\n if (key === field) return true\n if (!key.startsWith(`${field}/`)) return false\n const index = Number.parseInt(key.split('/')[1] ?? '', 10)\n if (Number.isNaN(index) || index < 0 || index >= length) return true\n return field === 'effects' && !bindsEffectProperty(node, key)\n })\n if (stale.length === 0) return\n node.boundVariables = omit(node.boundVariables, stale)\n changes.boundVariables = { ...node.boundVariables }\n}\n"],"mappings":";;;;AAMA,SAAS,oBAAoB,MAAiB,KAAsB;CAClE,MAAM,SAAS,oBAAoB,GAAG;CACtC,MAAM,SAAS,UAAU,KAAK,QAAQ,GAAG,OAAO,KAAK;CACrD,OAAO,CAAC,UAAU,yBAAyB,OAAO,IAAI,CAAC,CAAC,SAAS,OAAO,QAAQ;AAClF;AAEA,SAAgB,oBACd,MACA,OACA,SACM;CACN,MAAM,SAAS,KAAK,MAAM,CAAC;CAC3B,MAAM,QAAQ,OAAO,KAAK,KAAK,cAAc,CAAC,CAAC,QAAQ,QAAQ;EAC7D,IAAI,QAAQ,OAAO,OAAO;EAC1B,IAAI,CAAC,IAAI,WAAW,GAAG,MAAM,EAAE,GAAG,OAAO;EACzC,MAAM,QAAQ,OAAO,SAAS,IAAI,MAAM,GAAG,CAAC,CAAC,MAAM,IAAI,EAAE;EACzD,IAAI,OAAO,MAAM,KAAK,KAAK,QAAQ,KAAK,SAAS,QAAQ,OAAO;EAChE,OAAO,UAAU,aAAa,CAAC,oBAAoB,MAAM,GAAG;CAC9D,CAAC;CACD,IAAI,MAAM,WAAW,GAAG;CACxB,KAAK,iBAAiB,KAAK,KAAK,gBAAgB,KAAK;CACrD,QAAQ,iBAAiB,EAAE,GAAG,KAAK,eAAe;AACpD"}
|
package/dist/checkpoint.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SceneGraph } from "./graph.js";
|
|
2
|
-
import { SceneNode, Variable } from "./types.js";
|
|
2
|
+
import { SceneNode, Variable, VariableCollection } from "./types.js";
|
|
3
3
|
//#region src/checkpoint.d.ts
|
|
4
4
|
/** Capture rollback state without changing graph or surviving object identities. */
|
|
5
5
|
declare function captureGraphCheckpoint(graph: SceneGraph): {
|
|
@@ -8,6 +8,35 @@ declare function captureGraphCheckpoint(graph: SceneGraph): {
|
|
|
8
8
|
assertPropertiesOnly: () => void;
|
|
9
9
|
restore: () => void;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Rollback state for an edit that may only change properties, which costs what the edit touches
|
|
13
|
+
* rather than a copy of the document: a node is copied the first time the graph reports it about
|
|
14
|
+
* to change (`SceneGraph.observeNodeChanges`), together with its ancestors below the page, which
|
|
15
|
+
* keep instance override maps the graph writes into in place.
|
|
16
|
+
*/
|
|
17
|
+
interface TouchedCheckpoint {
|
|
18
|
+
/** Copies of the reported nodes and their ancestors below the page, as they were before. */
|
|
19
|
+
readonly nodes: ReadonlyMap<string, SceneNode>;
|
|
20
|
+
/** Nodes the graph reported changing or creating. */
|
|
21
|
+
readonly reported: ReadonlySet<string>;
|
|
22
|
+
/** Copies of the variables reported changing (`SceneGraph.willChangeVariable`), as they were. */
|
|
23
|
+
readonly variables: ReadonlyMap<string, Variable | null>;
|
|
24
|
+
readonly variableCollections: ReadonlyMap<string, VariableCollection | null>;
|
|
25
|
+
/** Throws unless the edit only changed properties of existing nodes and variables. */
|
|
26
|
+
assertPropertiesOnly(): void;
|
|
27
|
+
/** Stops observing and puts back everything the edit changed, keeping object identities. */
|
|
28
|
+
restore(): void;
|
|
29
|
+
/** Stops observing the graph. */
|
|
30
|
+
stop(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Starts observing `graph` for an edit that may only change properties. Node identities are
|
|
34
|
+
* kept as pointers, so replacing, adding, or removing a node anywhere is found; a node's fields
|
|
35
|
+
* are compared and restored only where the graph reported it, so code that writes into a node
|
|
36
|
+
* directly calls `SceneGraph.willChangeNode` first, and a node event without such a report fails
|
|
37
|
+
* the edit.
|
|
38
|
+
*/
|
|
39
|
+
declare function captureTouchedCheckpoint(graph: SceneGraph): TouchedCheckpoint;
|
|
11
40
|
//#endregion
|
|
12
|
-
export { captureGraphCheckpoint };
|
|
41
|
+
export { TouchedCheckpoint, captureGraphCheckpoint, captureTouchedCheckpoint };
|
|
13
42
|
//# sourceMappingURL=checkpoint.d.ts.map
|
package/dist/checkpoint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.d.ts","names":[],"sources":["../src/checkpoint.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","names":[],"sources":["../src/checkpoint.ts"],"mappings":";;;;iBA+BgB,uBAAuB,OAAO;;;;;;;;;;;;UAqJ7B;;WAEN,OAAO,oBAAoB;;WAE3B,UAAU;;WAEV,WAAW,oBAAoB;WAC/B,qBAAqB,oBAAoB;;EAElD;;EAEA;;EAEA;;;;;;;;;iBAUc,yBAAyB,OAAO,aAAa"}
|