@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, BehaviourContract, BehaviourKind, BehaviourPartContract, BehaviourValueContract, BehaviourValueType, INTERACTION_STATES, InteractionState, behaviourContract, hasInvalidState, interactionStatesOf } from "./kinds.js";
|
|
2
2
|
import { findLayerByPath, hasBehaviour, layerPath } from "./layers.js";
|
|
3
|
-
import { Behaviour, BehaviourBooleanBinding, BehaviourInteractionStates, BehaviourNumberSettings, BehaviourSpec, behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange } from "./schema.js";
|
|
3
|
+
import { Behaviour, BehaviourBooleanBinding, BehaviourInteractionStates, BehaviourNumberSettings, BehaviourSpec, BehaviourTransition, behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange } from "./schema.js";
|
|
4
4
|
import { DEFAULT_NUMBER_SETTINGS, behaviourOwner, behaviourProperties, booleanBinding, emptyBehaviour, guessInteractionStates, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour } from "./model.js";
|
|
5
5
|
import { behaviourFromSpec, behaviourToSpec, guessOnOff } from "./spec.js";
|
|
6
|
-
|
|
6
|
+
import { ResolvedTransition, defaultTransition, mapTransitionVariables, resolveTransition, transitionVariableIds } from "./transition.js";
|
|
7
|
+
export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, Behaviour, BehaviourBooleanBinding, BehaviourContract, BehaviourInteractionStates, BehaviourKind, BehaviourNumberSettings, BehaviourPartContract, BehaviourSpec, BehaviourTransition, BehaviourValueContract, BehaviourValueType, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, InteractionState, ResolvedTransition, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, defaultTransition, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, hasInvalidState, interactionStateValues, interactionStatesOf, isNumberRange, layerPath, mapTransitionVariables, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, resolveTransition, textBinding, transitionVariableIds, withBehaviour };
|
package/dist/behaviours/index.js
CHANGED
|
@@ -2,5 +2,6 @@ import { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, INTERACTION_STATES, behaviourCont
|
|
|
2
2
|
import { behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange } from "./schema.js";
|
|
3
3
|
import { DEFAULT_NUMBER_SETTINGS, behaviourOwner, behaviourProperties, booleanBinding, emptyBehaviour, guessInteractionStates, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour } from "./model.js";
|
|
4
4
|
import { findLayerByPath, hasBehaviour, layerPath } from "./layers.js";
|
|
5
|
+
import { defaultTransition, mapTransitionVariables, resolveTransition, transitionVariableIds } from "./transition.js";
|
|
5
6
|
import { behaviourFromSpec, behaviourToSpec, guessOnOff } from "./spec.js";
|
|
6
|
-
export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, hasInvalidState, interactionStateValues, interactionStatesOf, isNumberRange, layerPath, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour };
|
|
7
|
+
export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, defaultTransition, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, hasInvalidState, interactionStateValues, interactionStatesOf, isNumberRange, layerPath, mapTransitionVariables, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, resolveTransition, textBinding, transitionVariableIds, withBehaviour };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.d.ts","names":[],"sources":["../../src/behaviours/kinds.ts"],"mappings":";;cACa;KAmBD,wBAAwB;;;;;;cAOvB;KASD,2BAA2B;;;;;;;KAQ3B;;UAGK;EACf;EACA,MAAM;;EAEN;;;;;;UAOe;EACf;EACA;;;;;;EAMA;;;;;EAKA;;UAGe;EACf,QAAQ;EACR,OAAO;;;;;;;cA2BI,qBAAqB,SAAS,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","names":[],"sources":["../../src/behaviours/kinds.ts"],"mappings":";;cACa;KAmBD,wBAAwB;;;;;;cAOvB;KASD,2BAA2B;;;;;;;KAQ3B;;UAGK;EACf;EACA,MAAM;;EAEN;;;;;;UAOe;EACf;EACA;;;;;;EAMA;;;;;EAKA;;UAGe;EACf,QAAQ;EACR,OAAO;;;;;;;cA2BI,qBAAqB,SAAS,OAAO,eAAe;iBA0FjD,kBAAkB,MAAM,gBAAgB;;iBAKxC,gBAAgB,MAAM;;iBAKtB,oBAAoB,MAAM,gBAAgB"}
|
package/dist/behaviours/kinds.js
CHANGED
|
@@ -227,7 +227,7 @@ const BEHAVIOUR_CONTRACTS = {
|
|
|
227
227
|
}],
|
|
228
228
|
parts: [{
|
|
229
229
|
id: "track",
|
|
230
|
-
required:
|
|
230
|
+
required: false
|
|
231
231
|
}, {
|
|
232
232
|
id: "indicator",
|
|
233
233
|
required: true
|
|
@@ -239,13 +239,20 @@ const BEHAVIOUR_CONTRACTS = {
|
|
|
239
239
|
type: "boolean",
|
|
240
240
|
required: false
|
|
241
241
|
}, DISABLED],
|
|
242
|
-
parts: [
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
242
|
+
parts: [
|
|
243
|
+
{
|
|
244
|
+
id: "header",
|
|
245
|
+
required: false
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: "trigger",
|
|
249
|
+
required: true
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
id: "content",
|
|
253
|
+
required: true
|
|
254
|
+
}
|
|
255
|
+
]
|
|
249
256
|
},
|
|
250
257
|
accordion: {
|
|
251
258
|
values: [DISABLED],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.js","names":[],"sources":["../../src/behaviours/kinds.ts"],"sourcesContent":["/** The controls a main component can behave as, in the order the picker lists them. */\nexport const BEHAVIOUR_KINDS = [\n 'button',\n 'textField',\n 'textarea',\n 'numberField',\n 'toggle',\n 'switch',\n 'checkbox',\n 'radio',\n 'radioGroup',\n 'toggleGroup',\n 'slider',\n 'progress',\n 'tabs',\n 'tab',\n 'collapsible',\n 'accordion'\n] as const\n\nexport type BehaviourKind = (typeof BEHAVIOUR_KINDS)[number]\n\n/**\n * The interaction states a control can show, each drawn as a value of one variant property:\n * at rest, under the pointer, while pressed, focused from the keyboard, disabled, and invalid. Only\n * a form control has an invalid state (`hasInvalidState`), shown while its value fails validation.\n */\nexport const INTERACTION_STATES = [\n 'rest',\n 'hover',\n 'pressed',\n 'focus',\n 'disabled',\n 'invalid'\n] as const\n\nexport type InteractionState = (typeof INTERACTION_STATES)[number]\n\n/**\n * How a behaviour value is held. A boolean is a variant or boolean property of the component,\n * and text is a text property. Figma has no number property, so a number is the behaviour's\n * own (min, max, step, default); a choice is which item of a slot is active, the first by\n * default.\n */\nexport type BehaviourValueType = 'boolean' | 'text' | 'number' | 'choice'\n\n/** A value of the control: its state, which preview reads and changes. */\nexport interface BehaviourValueContract {\n id: string\n type: BehaviourValueType\n /** Whether a boolean or text value must be bound before the behaviour is complete. */\n required: boolean\n}\n\n/**\n * A Reka UI subcomponent of the control, which is a slot of the component: the behaviour binds\n * it to one of the component's slot properties, never to a layer found by name.\n */\nexport interface BehaviourPartContract {\n id: string\n required: boolean\n /**\n * Whether the slot holds the control's items, each an instance with its own behaviour (a\n * radio, a toggle, a collapsible, a tab), which the control turns on and off. A tab list's\n * triggers may also be plain layers, which have no state of their own.\n */\n items?: boolean\n /**\n * The Reka UI part each child of the slot is, when the slot holds repeated parts: a tab list's\n * triggers, the tabs' content panels, or a group's items.\n */\n children?: string\n}\n\nexport interface BehaviourContract {\n values: BehaviourValueContract[]\n parts: BehaviourPartContract[]\n}\n\nconst DISABLED: BehaviourValueContract = { id: 'disabled', type: 'boolean', required: false }\n\n/** Whether a form control's value fails validation, which code marks with `aria-invalid`. */\nconst INVALID: BehaviourValueContract = { id: 'invalid', type: 'boolean', required: false }\n\n/**\n * A text field or textarea: its text is a text property, and `filled`, when bound, draws the\n * empty field with its placeholder.\n */\nconst TEXT_INPUT: BehaviourContract = {\n values: [\n { id: 'value', type: 'text', required: true },\n { id: 'filled', type: 'boolean', required: false },\n DISABLED,\n INVALID\n ],\n parts: []\n}\n\n/**\n * The behaviours OpenPencil knows, after Reka UI's primitives. Their states are drawn as the\n * component's variants and properties; their subcomponents (thumb, range, trigger, …) are the\n * component's slots, and the component itself is the control's root.\n */\nexport const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContract>> = {\n button: {\n values: [DISABLED],\n parts: []\n },\n textField: TEXT_INPUT,\n textarea: TEXT_INPUT,\n numberField: {\n values: [\n { id: 'value', type: 'number', required: false },\n { id: 'text', type: 'text', required: true },\n DISABLED,\n INVALID\n ],\n parts: [\n { id: 'increment', required: false },\n { id: 'decrement', required: false }\n ]\n },\n toggle: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED],\n parts: []\n },\n switch: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'thumb', required: false }]\n },\n checkbox: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'indicator', required: false }]\n },\n radio: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'indicator', required: false }]\n },\n radioGroup: {\n values: [DISABLED, INVALID],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n toggleGroup: {\n values: [DISABLED],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n slider: {\n values: [{ id: 'value', type: 'number', required: false }, DISABLED],\n parts: [\n { id: 'track', required: true },\n { id: 'range', required: false },\n { id: 'thumb', required: true }\n ]\n },\n tabs: {\n values: [{ id: 'value', type: 'choice', required: false }],\n parts: [\n { id: 'list', required: true, items: true, children: 'trigger' },\n { id: 'panels', required: false, children: 'content' }\n ]\n },\n // A tab list's trigger, after Reka's TabsTrigger: on while its tab is the chosen one.\n tab: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: []\n },\n progress: {\n values: [{ id: 'value', type: 'number', required: false }],\n parts: [\n { id: 'track', required:
|
|
1
|
+
{"version":3,"file":"kinds.js","names":[],"sources":["../../src/behaviours/kinds.ts"],"sourcesContent":["/** The controls a main component can behave as, in the order the picker lists them. */\nexport const BEHAVIOUR_KINDS = [\n 'button',\n 'textField',\n 'textarea',\n 'numberField',\n 'toggle',\n 'switch',\n 'checkbox',\n 'radio',\n 'radioGroup',\n 'toggleGroup',\n 'slider',\n 'progress',\n 'tabs',\n 'tab',\n 'collapsible',\n 'accordion'\n] as const\n\nexport type BehaviourKind = (typeof BEHAVIOUR_KINDS)[number]\n\n/**\n * The interaction states a control can show, each drawn as a value of one variant property:\n * at rest, under the pointer, while pressed, focused from the keyboard, disabled, and invalid. Only\n * a form control has an invalid state (`hasInvalidState`), shown while its value fails validation.\n */\nexport const INTERACTION_STATES = [\n 'rest',\n 'hover',\n 'pressed',\n 'focus',\n 'disabled',\n 'invalid'\n] as const\n\nexport type InteractionState = (typeof INTERACTION_STATES)[number]\n\n/**\n * How a behaviour value is held. A boolean is a variant or boolean property of the component,\n * and text is a text property. Figma has no number property, so a number is the behaviour's\n * own (min, max, step, default); a choice is which item of a slot is active, the first by\n * default.\n */\nexport type BehaviourValueType = 'boolean' | 'text' | 'number' | 'choice'\n\n/** A value of the control: its state, which preview reads and changes. */\nexport interface BehaviourValueContract {\n id: string\n type: BehaviourValueType\n /** Whether a boolean or text value must be bound before the behaviour is complete. */\n required: boolean\n}\n\n/**\n * A Reka UI subcomponent of the control, which is a slot of the component: the behaviour binds\n * it to one of the component's slot properties, never to a layer found by name.\n */\nexport interface BehaviourPartContract {\n id: string\n required: boolean\n /**\n * Whether the slot holds the control's items, each an instance with its own behaviour (a\n * radio, a toggle, a collapsible, a tab), which the control turns on and off. A tab list's\n * triggers may also be plain layers, which have no state of their own.\n */\n items?: boolean\n /**\n * The Reka UI part each child of the slot is, when the slot holds repeated parts: a tab list's\n * triggers, the tabs' content panels, or a group's items.\n */\n children?: string\n}\n\nexport interface BehaviourContract {\n values: BehaviourValueContract[]\n parts: BehaviourPartContract[]\n}\n\nconst DISABLED: BehaviourValueContract = { id: 'disabled', type: 'boolean', required: false }\n\n/** Whether a form control's value fails validation, which code marks with `aria-invalid`. */\nconst INVALID: BehaviourValueContract = { id: 'invalid', type: 'boolean', required: false }\n\n/**\n * A text field or textarea: its text is a text property, and `filled`, when bound, draws the\n * empty field with its placeholder.\n */\nconst TEXT_INPUT: BehaviourContract = {\n values: [\n { id: 'value', type: 'text', required: true },\n { id: 'filled', type: 'boolean', required: false },\n DISABLED,\n INVALID\n ],\n parts: []\n}\n\n/**\n * The behaviours OpenPencil knows, after Reka UI's primitives. Their states are drawn as the\n * component's variants and properties; their subcomponents (thumb, range, trigger, …) are the\n * component's slots, and the component itself is the control's root.\n */\nexport const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContract>> = {\n button: {\n values: [DISABLED],\n parts: []\n },\n textField: TEXT_INPUT,\n textarea: TEXT_INPUT,\n numberField: {\n values: [\n { id: 'value', type: 'number', required: false },\n { id: 'text', type: 'text', required: true },\n DISABLED,\n INVALID\n ],\n parts: [\n { id: 'increment', required: false },\n { id: 'decrement', required: false }\n ]\n },\n toggle: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED],\n parts: []\n },\n switch: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'thumb', required: false }]\n },\n checkbox: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'indicator', required: false }]\n },\n radio: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'indicator', required: false }]\n },\n radioGroup: {\n values: [DISABLED, INVALID],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n toggleGroup: {\n values: [DISABLED],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n slider: {\n values: [{ id: 'value', type: 'number', required: false }, DISABLED],\n parts: [\n { id: 'track', required: true },\n { id: 'range', required: false },\n { id: 'thumb', required: true }\n ]\n },\n tabs: {\n values: [{ id: 'value', type: 'choice', required: false }],\n parts: [\n { id: 'list', required: true, items: true, children: 'trigger' },\n { id: 'panels', required: false, children: 'content' }\n ]\n },\n // A tab list's trigger, after Reka's TabsTrigger: on while its tab is the chosen one.\n tab: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: []\n },\n // Reka's and Radix's progress root is its track; a design may still draw one of its own.\n progress: {\n values: [{ id: 'value', type: 'number', required: false }],\n parts: [\n { id: 'track', required: false },\n { id: 'indicator', required: true }\n ]\n },\n // An accordion item's header is the heading its trigger is in; without one, the trigger is\n // put in a heading of its own.\n collapsible: {\n values: [{ id: 'open', type: 'boolean', required: false }, DISABLED],\n parts: [\n { id: 'header', required: false },\n { id: 'trigger', required: true },\n { id: 'content', required: true }\n ]\n },\n accordion: {\n values: [DISABLED],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n }\n}\n\nexport function behaviourContract(kind: BehaviourKind): BehaviourContract {\n return BEHAVIOUR_CONTRACTS[kind]\n}\n\n/** Whether a kind of control can be invalid: a form control, whose contract has `invalid`. */\nexport function hasInvalidState(kind: BehaviourKind): boolean {\n return BEHAVIOUR_CONTRACTS[kind].values.some((value) => value.id === 'invalid')\n}\n\n/** The interaction states a kind of control can show. */\nexport function interactionStatesOf(kind: BehaviourKind): InteractionState[] {\n return INTERACTION_STATES.filter((state) => state !== 'invalid' || hasInvalidState(kind))\n}\n"],"mappings":";;AACA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA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AW,UAAU;GAAK;GAChC;IAAE,IAAI;IAAW,UAAU;GAAK;EAClC;CACF;CACA,WAAW;EACT,QAAQ,CAAC,QAAQ;EACjB,OAAO,CAAC;GAAE,IAAI;GAAS,UAAU;GAAM,OAAO;GAAM,UAAU;EAAO,CAAC;CACxE;AACF;AAEA,SAAgB,kBAAkB,MAAwC;CACxE,OAAO,oBAAoB;AAC7B;;AAGA,SAAgB,gBAAgB,MAA8B;CAC5D,OAAO,oBAAoB,KAAK,CAAC,OAAO,MAAM,UAAU,MAAM,OAAO,SAAS;AAChF;;AAGA,SAAgB,oBAAoB,MAAyC;CAC3E,OAAO,mBAAmB,QAAQ,UAAU,UAAU,aAAa,gBAAgB,IAAI,CAAC;AAC1F"}
|
|
@@ -20,9 +20,9 @@ declare function emptyBehaviour(kind: BehaviourKind): Behaviour;
|
|
|
20
20
|
*/
|
|
21
21
|
declare function behaviourOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined;
|
|
22
22
|
/** The behaviour a component or component set keeps, or null when it has none or it is unreadable. */
|
|
23
|
-
declare function readBehaviour(owner: SceneNode): Behaviour | null;
|
|
23
|
+
declare function readBehaviour(owner: Pick<SceneNode, 'pluginData'>): Behaviour | null;
|
|
24
24
|
/** The owner's plugin data with the behaviour set, or removed when null. */
|
|
25
|
-
declare function withBehaviour(owner: SceneNode, behaviour: Behaviour | null): SceneNode['pluginData'];
|
|
25
|
+
declare function withBehaviour(owner: Pick<SceneNode, 'pluginData'>, behaviour: Behaviour | null): SceneNode['pluginData'];
|
|
26
26
|
/**
|
|
27
27
|
* Component properties the behaviour can bind to: the owner's, with a set's variant values and
|
|
28
28
|
* defaults read from its variants, and a set's variants' own.
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,KAAK,2BAA2B;;iBAKrD,cACd,OAAO,KAAK,0BACZ,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"}
|
|
@@ -1 +1 @@
|
|
|
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;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CACjC,SAAS,CAAC,WAAW,OAAO;AAC9B;;;;;AAMA,SAAgB,uBACd,MACA,YACA,QAC4B;CAC5B,MAAM,SAAqC,EAAE,WAAW;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"}
|
|
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: Pick<SceneNode, 'pluginData'>): 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: Pick<SceneNode, 'pluginData'>,\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,a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W;EAAiB;CAAe;CAC5D,UAAU,CAAC,YAAY,UAAU;CACjC,SAAS,CAAC,WAAW,OAAO;AAC9B;;;;;AAMA,SAAgB,uBACd,MACA,YACA,QAC4B;CAC5B,MAAM,SAAqC,EAAE,WAAW;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"}
|
|
@@ -41,6 +41,32 @@ declare const interactionStatesSchema: v.ObjectSchema<{
|
|
|
41
41
|
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
42
42
|
readonly propertyId: v.StringSchema<undefined>;
|
|
43
43
|
}, undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* How a control moves between its states: a duration in seconds and an easing, each its own value
|
|
46
|
+
* or, while the variable exists, a TIMING or EASING variable's, as Figma keeps a transition's
|
|
47
|
+
* duration and easing beside the variables they follow.
|
|
48
|
+
*/
|
|
49
|
+
declare const transitionSchema: v.ObjectSchema<{
|
|
50
|
+
readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
51
|
+
readonly easing: v.ObjectSchema<{
|
|
52
|
+
readonly easing: v.PicklistSchema<readonly ["IN_CUBIC", "OUT_CUBIC", "INOUT_CUBIC", "LINEAR", "IN_BACK_CUBIC", "OUT_BACK_CUBIC", "INOUT_BACK_CUBIC", "CUSTOM_CUBIC", "SPRING", "GENTLE_SPRING", "CUSTOM_SPRING", "SPRING_PRESET_ONE", "SPRING_PRESET_TWO", "SPRING_PRESET_THREE", "HOLD", "EASE_IN"], undefined>;
|
|
53
|
+
readonly bezier: v.OptionalSchema<v.ObjectSchema<{
|
|
54
|
+
readonly x1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
55
|
+
readonly y1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
56
|
+
readonly x2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
57
|
+
readonly y2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
58
|
+
}, undefined>, undefined>;
|
|
59
|
+
readonly spring: v.OptionalSchema<v.ObjectSchema<{
|
|
60
|
+
readonly stiffness: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
61
|
+
readonly damping: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
62
|
+
readonly mass: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.GtValueAction<number, 0, undefined>]>;
|
|
63
|
+
readonly type: v.OptionalSchema<v.PicklistSchema<["NORMALIZED", "PHYSICAL"], undefined>, undefined>;
|
|
64
|
+
readonly platform: v.OptionalSchema<v.PicklistSchema<["IOS_WEB", "ANDROID"], undefined>, undefined>;
|
|
65
|
+
}, undefined>, undefined>;
|
|
66
|
+
}, undefined>;
|
|
67
|
+
readonly durationVariableId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
68
|
+
readonly easingVariableId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
69
|
+
}, undefined>;
|
|
44
70
|
declare const storedBehaviourSchema: v.ObjectSchema<{
|
|
45
71
|
readonly kind: v.PicklistSchema<readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "tab", "collapsible", "accordion"], undefined>;
|
|
46
72
|
/** Boolean values, by value id, bound to component properties. */
|
|
@@ -77,6 +103,27 @@ declare const storedBehaviourSchema: v.ObjectSchema<{
|
|
|
77
103
|
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
78
104
|
readonly propertyId: v.StringSchema<undefined>;
|
|
79
105
|
}, undefined>, undefined>;
|
|
106
|
+
readonly transition: v.OptionalSchema<v.ObjectSchema<{
|
|
107
|
+
readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
108
|
+
readonly easing: v.ObjectSchema<{
|
|
109
|
+
readonly easing: v.PicklistSchema<readonly ["IN_CUBIC", "OUT_CUBIC", "INOUT_CUBIC", "LINEAR", "IN_BACK_CUBIC", "OUT_BACK_CUBIC", "INOUT_BACK_CUBIC", "CUSTOM_CUBIC", "SPRING", "GENTLE_SPRING", "CUSTOM_SPRING", "SPRING_PRESET_ONE", "SPRING_PRESET_TWO", "SPRING_PRESET_THREE", "HOLD", "EASE_IN"], undefined>;
|
|
110
|
+
readonly bezier: v.OptionalSchema<v.ObjectSchema<{
|
|
111
|
+
readonly x1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
112
|
+
readonly y1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
113
|
+
readonly x2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
114
|
+
readonly y2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
115
|
+
}, undefined>, undefined>;
|
|
116
|
+
readonly spring: v.OptionalSchema<v.ObjectSchema<{
|
|
117
|
+
readonly stiffness: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
118
|
+
readonly damping: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
119
|
+
readonly mass: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.GtValueAction<number, 0, undefined>]>;
|
|
120
|
+
readonly type: v.OptionalSchema<v.PicklistSchema<["NORMALIZED", "PHYSICAL"], undefined>, undefined>;
|
|
121
|
+
readonly platform: v.OptionalSchema<v.PicklistSchema<["IOS_WEB", "ANDROID"], undefined>, undefined>;
|
|
122
|
+
}, undefined>, undefined>;
|
|
123
|
+
}, undefined>;
|
|
124
|
+
readonly durationVariableId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
125
|
+
readonly easingVariableId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
126
|
+
}, undefined>, undefined>;
|
|
80
127
|
}, undefined>;
|
|
81
128
|
type StoredBehaviour = v.InferOutput<typeof storedBehaviourSchema>;
|
|
82
129
|
/**
|
|
@@ -119,6 +166,27 @@ declare const behaviourSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
119
166
|
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
120
167
|
readonly propertyId: v.StringSchema<undefined>;
|
|
121
168
|
}, undefined>, undefined>;
|
|
169
|
+
readonly transition: v.OptionalSchema<v.ObjectSchema<{
|
|
170
|
+
readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
171
|
+
readonly easing: v.ObjectSchema<{
|
|
172
|
+
readonly easing: v.PicklistSchema<readonly ["IN_CUBIC", "OUT_CUBIC", "INOUT_CUBIC", "LINEAR", "IN_BACK_CUBIC", "OUT_BACK_CUBIC", "INOUT_BACK_CUBIC", "CUSTOM_CUBIC", "SPRING", "GENTLE_SPRING", "CUSTOM_SPRING", "SPRING_PRESET_ONE", "SPRING_PRESET_TWO", "SPRING_PRESET_THREE", "HOLD", "EASE_IN"], undefined>;
|
|
173
|
+
readonly bezier: v.OptionalSchema<v.ObjectSchema<{
|
|
174
|
+
readonly x1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
175
|
+
readonly y1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
176
|
+
readonly x2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
177
|
+
readonly y2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
178
|
+
}, undefined>, undefined>;
|
|
179
|
+
readonly spring: v.OptionalSchema<v.ObjectSchema<{
|
|
180
|
+
readonly stiffness: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
181
|
+
readonly damping: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
182
|
+
readonly mass: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.GtValueAction<number, 0, undefined>]>;
|
|
183
|
+
readonly type: v.OptionalSchema<v.PicklistSchema<["NORMALIZED", "PHYSICAL"], undefined>, undefined>;
|
|
184
|
+
readonly platform: v.OptionalSchema<v.PicklistSchema<["IOS_WEB", "ANDROID"], undefined>, undefined>;
|
|
185
|
+
}, undefined>, undefined>;
|
|
186
|
+
}, undefined>;
|
|
187
|
+
readonly durationVariableId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
188
|
+
readonly easingVariableId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
189
|
+
}, undefined>, undefined>;
|
|
122
190
|
}, undefined>, v.TransformAction<{
|
|
123
191
|
kind: "button" | "textField" | "textarea" | "numberField" | "toggle" | "switch" | "checkbox" | "radio" | "radioGroup" | "toggleGroup" | "slider" | "progress" | "tabs" | "tab" | "collapsible" | "accordion";
|
|
124
192
|
booleans: {
|
|
@@ -153,6 +221,27 @@ declare const behaviourSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
153
221
|
invalid?: string | undefined;
|
|
154
222
|
propertyId: string;
|
|
155
223
|
} | undefined;
|
|
224
|
+
transition?: {
|
|
225
|
+
duration: number;
|
|
226
|
+
easing: {
|
|
227
|
+
easing: "IN_CUBIC" | "OUT_CUBIC" | "INOUT_CUBIC" | "LINEAR" | "IN_BACK_CUBIC" | "OUT_BACK_CUBIC" | "INOUT_BACK_CUBIC" | "CUSTOM_CUBIC" | "SPRING" | "GENTLE_SPRING" | "CUSTOM_SPRING" | "SPRING_PRESET_ONE" | "SPRING_PRESET_TWO" | "SPRING_PRESET_THREE" | "HOLD" | "EASE_IN";
|
|
228
|
+
bezier?: {
|
|
229
|
+
x1: number;
|
|
230
|
+
y1: number;
|
|
231
|
+
x2: number;
|
|
232
|
+
y2: number;
|
|
233
|
+
} | undefined;
|
|
234
|
+
spring?: {
|
|
235
|
+
stiffness: number;
|
|
236
|
+
damping: number;
|
|
237
|
+
mass: number;
|
|
238
|
+
type?: "NORMALIZED" | "PHYSICAL" | undefined;
|
|
239
|
+
platform?: "ANDROID" | "IOS_WEB" | undefined;
|
|
240
|
+
} | undefined;
|
|
241
|
+
};
|
|
242
|
+
durationVariableId?: string | undefined;
|
|
243
|
+
easingVariableId?: string | undefined;
|
|
244
|
+
} | undefined;
|
|
156
245
|
}, {
|
|
157
246
|
kind: "button" | "textField" | "textarea" | "numberField" | "toggle" | "switch" | "checkbox" | "radio" | "radioGroup" | "toggleGroup" | "slider" | "progress" | "tabs" | "tab" | "collapsible" | "accordion";
|
|
158
247
|
booleans: {
|
|
@@ -187,12 +276,34 @@ declare const behaviourSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
187
276
|
invalid?: string | undefined;
|
|
188
277
|
propertyId: string;
|
|
189
278
|
} | undefined;
|
|
279
|
+
transition?: {
|
|
280
|
+
duration: number;
|
|
281
|
+
easing: {
|
|
282
|
+
easing: "IN_CUBIC" | "OUT_CUBIC" | "INOUT_CUBIC" | "LINEAR" | "IN_BACK_CUBIC" | "OUT_BACK_CUBIC" | "INOUT_BACK_CUBIC" | "CUSTOM_CUBIC" | "SPRING" | "GENTLE_SPRING" | "CUSTOM_SPRING" | "SPRING_PRESET_ONE" | "SPRING_PRESET_TWO" | "SPRING_PRESET_THREE" | "HOLD" | "EASE_IN";
|
|
283
|
+
bezier?: {
|
|
284
|
+
x1: number;
|
|
285
|
+
y1: number;
|
|
286
|
+
x2: number;
|
|
287
|
+
y2: number;
|
|
288
|
+
} | undefined;
|
|
289
|
+
spring?: {
|
|
290
|
+
stiffness: number;
|
|
291
|
+
damping: number;
|
|
292
|
+
mass: number;
|
|
293
|
+
type?: "NORMALIZED" | "PHYSICAL" | undefined;
|
|
294
|
+
platform?: "ANDROID" | "IOS_WEB" | undefined;
|
|
295
|
+
} | undefined;
|
|
296
|
+
};
|
|
297
|
+
durationVariableId?: string | undefined;
|
|
298
|
+
easingVariableId?: string | undefined;
|
|
299
|
+
} | undefined;
|
|
190
300
|
}>]>;
|
|
191
301
|
/** How a main component behaves as a control, as kept in its plugin data. */
|
|
192
302
|
type Behaviour = StoredBehaviour;
|
|
193
303
|
type BehaviourBooleanBinding = v.InferOutput<typeof booleanBindingSchema>;
|
|
194
304
|
type BehaviourNumberSettings = v.InferOutput<typeof numberSettingsSchema>;
|
|
195
305
|
type BehaviourInteractionStates = v.InferOutput<typeof interactionStatesSchema>;
|
|
306
|
+
type BehaviourTransition = v.InferOutput<typeof transitionSchema>;
|
|
196
307
|
/**
|
|
197
308
|
* A behaviour as scripts, tools, and JSX write it: component properties and slots by name, not
|
|
198
309
|
* by id. Values are boolean or text values by their contract id; numbers are a slider's or
|
|
@@ -221,8 +332,32 @@ declare const behaviourSpecSchema: v.ObjectSchema<{
|
|
|
221
332
|
readonly invalid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
222
333
|
readonly property: v.StringSchema<undefined>;
|
|
223
334
|
}, undefined>], undefined>, undefined>;
|
|
335
|
+
/** How the control moves between states, as `motionSpecSchema` writes it. */
|
|
336
|
+
readonly transition: v.OptionalSchema<v.ObjectSchema<{
|
|
337
|
+
readonly duration: v.OptionalSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.ObjectSchema<{
|
|
338
|
+
readonly variable: v.StringSchema<undefined>;
|
|
339
|
+
}, undefined>], undefined>, undefined>;
|
|
340
|
+
readonly easing: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.ObjectSchema<{
|
|
341
|
+
readonly variable: v.StringSchema<undefined>;
|
|
342
|
+
}, undefined>, v.ObjectSchema<{
|
|
343
|
+
readonly easing: v.PicklistSchema<readonly ["IN_CUBIC", "OUT_CUBIC", "INOUT_CUBIC", "LINEAR", "IN_BACK_CUBIC", "OUT_BACK_CUBIC", "INOUT_BACK_CUBIC", "CUSTOM_CUBIC", "SPRING", "GENTLE_SPRING", "CUSTOM_SPRING", "SPRING_PRESET_ONE", "SPRING_PRESET_TWO", "SPRING_PRESET_THREE", "HOLD", "EASE_IN"], undefined>;
|
|
344
|
+
readonly bezier: v.OptionalSchema<v.ObjectSchema<{
|
|
345
|
+
readonly x1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
346
|
+
readonly y1: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
347
|
+
readonly x2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
348
|
+
readonly y2: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
349
|
+
}, undefined>, undefined>;
|
|
350
|
+
readonly spring: v.OptionalSchema<v.ObjectSchema<{
|
|
351
|
+
readonly stiffness: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
352
|
+
readonly damping: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>]>;
|
|
353
|
+
readonly mass: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, v.GtValueAction<number, 0, undefined>]>;
|
|
354
|
+
readonly type: v.OptionalSchema<v.PicklistSchema<["NORMALIZED", "PHYSICAL"], undefined>, undefined>;
|
|
355
|
+
readonly platform: v.OptionalSchema<v.PicklistSchema<["IOS_WEB", "ANDROID"], undefined>, undefined>;
|
|
356
|
+
}, undefined>, undefined>;
|
|
357
|
+
}, undefined>], undefined>, undefined>;
|
|
358
|
+
}, undefined>, undefined>;
|
|
224
359
|
}, undefined>;
|
|
225
360
|
type BehaviourSpec = v.InferOutput<typeof behaviourSpecSchema>;
|
|
226
361
|
//#endregion
|
|
227
|
-
export { Behaviour, BehaviourBooleanBinding, BehaviourInteractionStates, BehaviourNumberSettings, BehaviourSpec, behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange };
|
|
362
|
+
export { Behaviour, BehaviourBooleanBinding, BehaviourInteractionStates, BehaviourNumberSettings, BehaviourSpec, BehaviourTransition, behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange };
|
|
228
363
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/behaviours/schema.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/behaviours/schema.ts"],"mappings":";;cAKM,sBAAoB,EAAA;;;;;;;iBAQV,cAAc;EAAY;EAAa;EAAa;;cAI9D,sBAAoB,EAAA,yBAAA,EAAA;;;;;;;;;;;;cAcb;;;;;;;;cASP,yBAAuB,EAAA;;;;;;;;;;;;;;cAOvB,kBAAgB,EAAA;;;;;;;;;;;;;;;;;;;;;cAOhB,uBAAqB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KActB,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;KAClD,sBAAsB,EAAE,mBAAmB;;;;;;cAO1C,qBAAmB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BpB,gBAAgB,EAAE,mBAAmB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { easingSchema, motionSpecSchema } from "../variables/schema.js";
|
|
1
2
|
import { BEHAVIOUR_KINDS, hasInvalidState } from "./kinds.js";
|
|
2
3
|
import * as v from "valibot";
|
|
3
4
|
//#region src/behaviours/schema.ts
|
|
@@ -30,6 +31,17 @@ const interactionStatesSchema = v.object({
|
|
|
30
31
|
propertyId: v.string(),
|
|
31
32
|
...interactionStateValues
|
|
32
33
|
});
|
|
34
|
+
/**
|
|
35
|
+
* How a control moves between its states: a duration in seconds and an easing, each its own value
|
|
36
|
+
* or, while the variable exists, a TIMING or EASING variable's, as Figma keeps a transition's
|
|
37
|
+
* duration and easing beside the variables they follow.
|
|
38
|
+
*/
|
|
39
|
+
const transitionSchema = v.object({
|
|
40
|
+
duration: v.pipe(v.number(), v.finite(), v.minValue(0)),
|
|
41
|
+
easing: easingSchema,
|
|
42
|
+
durationVariableId: v.optional(v.string()),
|
|
43
|
+
easingVariableId: v.optional(v.string())
|
|
44
|
+
});
|
|
33
45
|
const storedBehaviourSchema = v.object({
|
|
34
46
|
kind: v.picklist(BEHAVIOUR_KINDS),
|
|
35
47
|
/** Boolean values, by value id, bound to component properties. */
|
|
@@ -40,7 +52,8 @@ const storedBehaviourSchema = v.object({
|
|
|
40
52
|
numbers: v.record(v.string(), numberSettingsSchema),
|
|
41
53
|
/** Parts, by part id, bound to slot properties. */
|
|
42
54
|
parts: v.record(v.string(), v.string()),
|
|
43
|
-
states: v.optional(interactionStatesSchema)
|
|
55
|
+
states: v.optional(interactionStatesSchema),
|
|
56
|
+
transition: v.optional(transitionSchema)
|
|
44
57
|
});
|
|
45
58
|
/** The behaviour without an invalid state when its kind of control has none. */
|
|
46
59
|
function withoutUnsupportedStates(behaviour) {
|
|
@@ -78,7 +91,9 @@ const behaviourSpecSchema = v.object({
|
|
|
78
91
|
states: v.optional(v.union([v.string(), v.object({
|
|
79
92
|
property: v.string(),
|
|
80
93
|
...interactionStateValues
|
|
81
|
-
})]))
|
|
94
|
+
})])),
|
|
95
|
+
/** How the control moves between states, as `motionSpecSchema` writes it. */
|
|
96
|
+
transition: v.optional(motionSpecSchema)
|
|
82
97
|
});
|
|
83
98
|
//#endregion
|
|
84
99
|
export { behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange };
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/behaviours/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { easingSchema, motionSpecSchema } from '../variables/schema'\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\n/**\n * How a control moves between its states: a duration in seconds and an easing, each its own value\n * or, while the variable exists, a TIMING or EASING variable's, as Figma keeps a transition's\n * duration and easing beside the variables they follow.\n */\nconst transitionSchema = v.object({\n duration: v.pipe(v.number(), v.finite(), v.minValue(0)),\n easing: easingSchema,\n durationVariableId: v.optional(v.string()),\n easingVariableId: v.optional(v.string())\n})\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 transition: v.optional(transitionSchema)\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>\nexport type BehaviourTransition = v.InferOutput<typeof transitionSchema>\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 /** How the control moves between states, as `motionSpecSchema` writes it. */\n transition: v.optional(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O,CAAC;EAC3B,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC;CAChC,CAAC,CACH,CACF;CACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;CAClD,QAAQ,EAAE,SACR,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO;EAAE,UAAU,EAAE,OAAO;EAAG,GAAG;CAAuB,CAAC,CAAC,CAAC,CACrF;;CAEA,YAAY,EAAE,SAAS,gBAAgB;AACzC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../src/behaviours/spec.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../src/behaviours/spec.ts"],"mappings":";;;;;;;;iBAsBgB,WACd,4BACA;EAAY;EAAa;;EACtB;EAAa;;;;;;;iBAyFF,kBACd,OAAO,YACP,OAAO,WACP,MAAM,gBACL;;iBAkCa,gBACd,OAAO,YACP,OAAO,WACP,WAAW,YACV"}
|
package/dist/behaviours/spec.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { behaviourContract, hasInvalidState } from "./kinds.js";
|
|
2
2
|
import { isNumberRange } from "./schema.js";
|
|
3
|
+
import { motionFromSpec, motionToSpec } from "../variables/motion.js";
|
|
3
4
|
import { behaviourProperties, emptyBehaviour, guessInteractionStates, textBinding } from "./model.js";
|
|
5
|
+
import { defaultTransition } from "./transition.js";
|
|
4
6
|
import { omitBy } from "es-toolkit/object";
|
|
5
7
|
//#region src/behaviours/spec.ts
|
|
6
8
|
/** Variant values that usually mean on, compared case-insensitively. */
|
|
@@ -112,6 +114,7 @@ function behaviourFromSpec(graph, owner, spec) {
|
|
|
112
114
|
behaviour.parts[partId] = id;
|
|
113
115
|
}
|
|
114
116
|
if (spec.states !== void 0) resolveStates(behaviour, properties, spec.states);
|
|
117
|
+
if (spec.transition) behaviour.transition = motionFromSpec(graph, spec.transition, defaultTransition());
|
|
115
118
|
return behaviour;
|
|
116
119
|
}
|
|
117
120
|
function stripUndefined(record) {
|
|
@@ -150,6 +153,7 @@ function behaviourToSpec(graph, owner, behaviour) {
|
|
|
150
153
|
}),
|
|
151
154
|
property: statesName
|
|
152
155
|
};
|
|
156
|
+
if (behaviour.transition) spec.transition = motionToSpec(graph, behaviour.transition);
|
|
153
157
|
return spec;
|
|
154
158
|
}
|
|
155
159
|
//#endregion
|
|
@@ -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, 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,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,QAAQ;EAAI,IAAI;CACzF;CACA,KAAK,MAAM,WAAW,OAAO,KAAK,UAAU,KAAK,GAAG;EAClD,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,CAAC;EACnD,IAAI,MAAM,OAAO,WAAW;CAC9B;CACA,MAAM,QAAQ,OAAO,YACnB,OAAO,QAAQ,UAAU,KAAK,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"}
|
|
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 { motionFromSpec, motionToSpec } from '../variables/motion'\nimport { behaviourContract, hasInvalidState } from './kinds'\nimport { behaviourProperties, emptyBehaviour, guessInteractionStates, textBinding } from './model'\nimport { isNumberRange, type Behaviour, type BehaviourSpec } from './schema'\nimport { defaultTransition } from './transition'\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 if (spec.transition)\n behaviour.transition = motionFromSpec(graph, spec.transition, defaultTransition())\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 if (behaviour.transition)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AS;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,IAAI,UAAU,YAAY,KAAK,aAAa,aAAa,OAAO,UAAU,UAAU;CACpF,OAAO;AACT"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { Behaviour, BehaviourTransition } from "./schema.js";
|
|
3
|
+
import { ResolvedMotion } from "../variables/motion.js";
|
|
4
|
+
//#region src/behaviours/transition.d.ts
|
|
5
|
+
/** What a control's state change plays: a duration in seconds and an easing. */
|
|
6
|
+
type ResolvedTransition = ResolvedMotion;
|
|
7
|
+
/** The transition a behaviour starts with when one is added: Figma's Smart animate default. */
|
|
8
|
+
declare function defaultTransition(): BehaviourTransition;
|
|
9
|
+
/**
|
|
10
|
+
* The transition `node` plays, an instance of the behaviour's component: each variable read in the
|
|
11
|
+
* modes the node is in, and the behaviour's own value where the variable is gone or gives nothing.
|
|
12
|
+
*/
|
|
13
|
+
declare function resolveTransition(graph: SceneGraph, behaviour: Behaviour, nodeId: string): ResolvedTransition | undefined;
|
|
14
|
+
/** The variables a behaviour's transition follows. */
|
|
15
|
+
declare function transitionVariableIds(behaviour: Behaviour): string[];
|
|
16
|
+
/**
|
|
17
|
+
* The behaviour with its transition following other variables, as a copy into another document
|
|
18
|
+
* or a file's own IDs name them; a variable `map` gives nothing for is let go, keeping the value.
|
|
19
|
+
*/
|
|
20
|
+
declare function mapTransitionVariables(behaviour: Behaviour, map: (variableId: string) => string | undefined): Behaviour;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ResolvedTransition, defaultTransition, mapTransitionVariables, resolveTransition, transitionVariableIds };
|
|
23
|
+
//# sourceMappingURL=transition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transition.d.ts","names":[],"sources":["../../src/behaviours/transition.ts"],"mappings":";;;;;KAWY,qBAAqB;;iBAGjB,qBAAqB;;;;;iBAQrB,kBACd,OAAO,YACP,WAAW,WACX,iBACC;;iBAKa,sBAAsB,WAAW;;;;;iBAQjC,uBACd,WAAW,WACX,MAAM,4CACL"}
|