From b14de70f79e7e63a880f7c8c1846acc869c95d50 Mon Sep 17 00:00:00 2001 From: Kurtis Lew Date: Fri, 10 Feb 2023 13:31:56 -0800 Subject: [PATCH] feat(docs/hold-tap): Implement 'balanced' flavor animations --- docs/docs/behaviors/hold-tap.md | 39 ++++++++++++++ .../src/hold_tap/balanced_hold_tap_up.meta | 3 ++ .../src/hold_tap/balanced_hold_tap_up.ts | 8 +++ .../src/hold_tap/balanced_other_key_up.meta | 3 ++ .../src/hold_tap/balanced_other_key_up.ts | 8 +++ .../scenes/hold_tap/balanced_hold_tap_up.meta | 3 ++ .../scenes/hold_tap/balanced_hold_tap_up.tsx | 52 ++++++++++++++++++ .../hold_tap/balanced_other_key_up.meta | 3 ++ .../scenes/hold_tap/balanced_other_key_up.tsx | 54 +++++++++++++++++++ docs/src/animationhelpers/vite.config.ts | 2 + 10 files changed, 175 insertions(+) create mode 100644 docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.meta create mode 100644 docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.ts create mode 100644 docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.meta create mode 100644 docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.ts create mode 100644 docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.meta create mode 100644 docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.tsx create mode 100644 docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.meta create mode 100644 docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.tsx diff --git a/docs/docs/behaviors/hold-tap.md b/docs/docs/behaviors/hold-tap.md index 9699cf36..297a2d55 100644 --- a/docs/docs/behaviors/hold-tap.md +++ b/docs/docs/behaviors/hold-tap.md @@ -34,8 +34,47 @@ We call this the 'hold-preferred' flavor of hold-taps. While this flavor may wor When the hold-tap key is released and the hold behavior has not been triggered, the tap behavior will trigger. + + + + +As shown previously, the hold-tap decision is generally made after the [`tapping-term-ms`](#tapping-term-ms) has expired. + + + +Alternatively, the 'hold-preferred' flavor triggers the hold behavior when another key is pressed. + + + + + + + +The following section describes the behavior of the 'balanced' hold-tap when another key is pressed while the hold-tap is held. + +If another key is pressed while the 'balanced' hold-tap pressed, releasing the hold-tap before the interrupting keypress will invoke the tap behavior. + + + +On the other hand, if the interrupting key is released before the hold-tap, the hold behavior will be invoked. + + + + + + + ![Hold-tap comparison](../assets/hold-tap/comparison.svg) + + + ### Basic usage For basic usage, please see the [mod-tap](mod-tap.md) and [layer-tap](layers.md#layer-tap) pages. diff --git a/docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.meta b/docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.meta new file mode 100644 index 00000000..0e33e3fe --- /dev/null +++ b/docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.meta @@ -0,0 +1,3 @@ +{ + "version": 0 +} \ No newline at end of file diff --git a/docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.ts b/docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.ts new file mode 100644 index 00000000..a421a932 --- /dev/null +++ b/docs/src/animationhelpers/src/hold_tap/balanced_hold_tap_up.ts @@ -0,0 +1,8 @@ +import { makeProject } from "@motion-canvas/core/lib"; + +import balanced_hold_tap_up from "../scenes/hold_tap/balanced_hold_tap_up?scene"; + +export default makeProject({ + scenes: [balanced_hold_tap_up], + background: "#FFFFFF", +}); diff --git a/docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.meta b/docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.meta new file mode 100644 index 00000000..0e33e3fe --- /dev/null +++ b/docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.meta @@ -0,0 +1,3 @@ +{ + "version": 0 +} \ No newline at end of file diff --git a/docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.ts b/docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.ts new file mode 100644 index 00000000..b8fac9e8 --- /dev/null +++ b/docs/src/animationhelpers/src/hold_tap/balanced_other_key_up.ts @@ -0,0 +1,8 @@ +import { makeProject } from "@motion-canvas/core/lib"; + +import balanced_other_key_up from "../scenes/hold_tap/balanced_other_key_up?scene"; + +export default makeProject({ + scenes: [balanced_other_key_up], + background: "#FFFFFF", +}); diff --git a/docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.meta b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.meta new file mode 100644 index 00000000..0e33e3fe --- /dev/null +++ b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.meta @@ -0,0 +1,3 @@ +{ + "version": 0 +} \ No newline at end of file diff --git a/docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.tsx b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.tsx new file mode 100644 index 00000000..af1fe9e6 --- /dev/null +++ b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_hold_tap_up.tsx @@ -0,0 +1,52 @@ +import { makeScene2D } from "@motion-canvas/2d/lib/scenes"; +import { makeRefs } from "@motion-canvas/core/lib/utils"; +import { any, all, chain, delay, waitFor } from "@motion-canvas/core/lib/flow"; +import Key, { KeyTravel } from "../../components/Key"; +import Output from "../../components/Output"; +import { linear } from "@motion-canvas/core/lib/tweening"; + +export default makeScene2D(function* (view) { + const interrupt = makeRefs(); + view.add(); + interrupt.group.position.x(125); + interrupt.group.position.y(-150); + interrupt.duration.fill("#D9D9D9"); + + const hold = makeRefs(); + view.add(); + hold.group.position.x(-125); + hold.group.position.y(-150); + hold.duration.fill("#D9D9D9"); + + const hold_output = makeRefs(); + view.add(); + hold_output.group.position(hold.group.position().addX(125)); + hold_output.group.position.y(hold_output.group.position.y() + 300); + + yield* waitFor(0.5); + yield* any( + hold.body.position.y(KeyTravel, 0.15), + hold.duration.grow(1, 2, linear) + ); + yield* delay( + 1.2, + all( + interrupt.body.position.y(KeyTravel, 0.15), + hold.duration.fill("F21D00", 0.15) + ) + ); + yield* delay( + 1.5, + chain( + hold.body.position.y(0, 0.15), + hold.group.rotation(3, 0.03), + hold.group.rotation(-3, 0.06), + hold.group.rotation(0, 0.03), + hold.duration.grow(0, 0.15), + delay(0.05, hold_output.output.text("f", 0)), + delay(0.05, hold_output.output.text("fj", 0)) + ) + ); + yield* waitFor(0.25); + yield* interrupt.body.position.y(0, 0.15); +}); diff --git a/docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.meta b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.meta new file mode 100644 index 00000000..0e33e3fe --- /dev/null +++ b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.meta @@ -0,0 +1,3 @@ +{ + "version": 0 +} \ No newline at end of file diff --git a/docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.tsx b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.tsx new file mode 100644 index 00000000..003e676e --- /dev/null +++ b/docs/src/animationhelpers/src/scenes/hold_tap/balanced_other_key_up.tsx @@ -0,0 +1,54 @@ +import { makeScene2D } from "@motion-canvas/2d/lib/scenes"; +import { makeRefs } from "@motion-canvas/core/lib/utils"; +import { any, all, chain, delay, waitFor } from "@motion-canvas/core/lib/flow"; +import Key, { KeyTravel } from "../../components/Key"; +import Output from "../../components/Output"; +import { linear } from "@motion-canvas/core/lib/tweening"; + +export default makeScene2D(function* (view) { + const interrupt = makeRefs(); + view.add(); + interrupt.group.position.x(125); + interrupt.group.position.y(-150); + interrupt.duration.fill("#D9D9D9"); + + const hold = makeRefs(); + view.add(); + hold.group.position.x(-125); + hold.group.position.y(-150); + hold.duration.fill("#D9D9D9"); + + const hold_output = makeRefs(); + view.add(); + hold_output.group.position(hold.group.position().addX(125)); + hold_output.group.position.y(hold_output.group.position.y() + 300); + + yield* waitFor(0.5); + yield* any( + hold.body.position.y(KeyTravel, 0.15), + hold.duration.grow(1, 2, linear) + ); + yield* delay( + 1.2, + all( + interrupt.body.position.y(KeyTravel, 0.15), + hold.duration.fill("F21D00", 0.15) + ) + ); + yield* delay( + 1.5, + chain( + interrupt.body.position.y(0, 0.15), + hold.group.rotation(3, 0.03), + hold.group.rotation(-3, 0.06), + hold.group.rotation(0, 0.03), + all( + delay(0.15, hold_output.output.text("J", 0)), + hold_output.shift.fill("#969696", 0.15) + ) + ) + ); + yield* waitFor(0.25); + yield* hold.body.position.y(0, 0.15); + yield* delay(0.5, hold.duration.grow(0, 0.15)); +}); diff --git a/docs/src/animationhelpers/vite.config.ts b/docs/src/animationhelpers/vite.config.ts index 1492f79c..bdfa2d53 100644 --- a/docs/src/animationhelpers/vite.config.ts +++ b/docs/src/animationhelpers/vite.config.ts @@ -7,6 +7,8 @@ export default defineConfig({ project: [ "./src/hold_tap/hold_tap_comparison.ts", "./src/hold_tap/hold_tap_interrupted.ts", + "./src/hold_tap/balanced_other_key_up.ts", + "./src/hold_tap/balanced_hold_tap_up.ts", ], }), ],