From 60744c3181760f723d6f14a445314a58866f63f0 Mon Sep 17 00:00:00 2001 From: Kurtis Lew Date: Fri, 10 Feb 2023 10:12:19 -0800 Subject: [PATCH] feat(docs/hold-tap): Implement hold-tap comparison Motion Canvas Project --- docs/docs/behaviors/hold-tap.md | 6 + .../animationhelpers/src/components/Key.tsx | 80 ++++++++++++ .../src/components/Output.tsx | 121 ++++++++++++++++++ .../src/hold_tap/hold_tap_comparison.meta | 3 + .../src/hold_tap/hold_tap_comparison.ts | 8 ++ docs/src/animationhelpers/src/project.ts | 8 -- .../animationhelpers/src/scenes/example.tsx | 8 -- .../scenes/hold_tap/hold_tap_comparison.tsx | 79 ++++++++++++ docs/src/animationhelpers/vite.config.ts | 2 +- 9 files changed, 298 insertions(+), 17 deletions(-) create mode 100644 docs/src/animationhelpers/src/components/Key.tsx create mode 100644 docs/src/animationhelpers/src/components/Output.tsx create mode 100644 docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.meta create mode 100644 docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.ts delete mode 100644 docs/src/animationhelpers/src/project.ts delete mode 100644 docs/src/animationhelpers/src/scenes/example.tsx create mode 100644 docs/src/animationhelpers/src/scenes/hold_tap/hold_tap_comparison.tsx diff --git a/docs/docs/behaviors/hold-tap.md b/docs/docs/behaviors/hold-tap.md index 793e350d..acf2a8a6 100644 --- a/docs/docs/behaviors/hold-tap.md +++ b/docs/docs/behaviors/hold-tap.md @@ -5,6 +5,7 @@ sidebar_label: Hold-Tap import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; +import '@motion-canvas/player' ## Summary @@ -18,6 +19,11 @@ The graph below shows how the hold-tap decides between a 'tap' and a 'hold'. ![Simple behavior](../assets/hold-tap/case1_2.svg) + + By default, the hold-tap is configured to also select the 'hold' functionality if another key is tapped while it's active: ![Hold preferred behavior](../assets/hold-tap/case_hold_preferred.svg) diff --git a/docs/src/animationhelpers/src/components/Key.tsx b/docs/src/animationhelpers/src/components/Key.tsx new file mode 100644 index 00000000..3ecbbc12 --- /dev/null +++ b/docs/src/animationhelpers/src/components/Key.tsx @@ -0,0 +1,80 @@ +import { Rect, Text, Node } from "@motion-canvas/2d/lib/components"; +import { SignalValue } from "@motion-canvas/core/lib/signals"; +import { makeRef } from "@motion-canvas/core/lib/utils"; + +const KeySize = 200; +const KeyRadius = 10; +export const KeyBorderThickness = 10; +export const KeyTravel = 40; + +export default function Key({ + refs, + binding, + params, +}: { + refs: { + group: Node; + body: Node; + fill: Rect; + duration: Rect; + shadow: Rect; + binding: Text; + params: Text; + }; + binding: SignalValue; + params: SignalValue; +}) { + return ( + + + + + + + + + + + + ); +} diff --git a/docs/src/animationhelpers/src/components/Output.tsx b/docs/src/animationhelpers/src/components/Output.tsx new file mode 100644 index 00000000..a0203af5 --- /dev/null +++ b/docs/src/animationhelpers/src/components/Output.tsx @@ -0,0 +1,121 @@ +import { Rect, Text, Node } from "@motion-canvas/2d/lib/components"; +import { makeRef } from "@motion-canvas/core/lib/utils"; +import { KeyBorderThickness } from "./Key"; + +const OutputThickness = KeyBorderThickness / 2; +const OutputFontSize = 40; +const OutputFontWeight = 600; +const ModifierRadius = 10; +const ModifierFontSize = 32; +const ModifierFontWeight = 600; +const ModifierMargin = 20; + +export default function Output({ + refs, +}: { + refs: { + group: Rect; + output: Text; + shift: Rect; + alt: Rect; + ctrl: Rect; + gui: Rect; + }; +}) { + return ( + + + + + + + "SHIFT"} + fontWeight={ModifierFontWeight} + fontSize={ModifierFontSize} + margin={ModifierMargin} + /> + + + + "ALT"} + fontWeight={ModifierFontWeight} + fontSize={ModifierFontSize} + margin={ModifierMargin} + /> + + + + "CTRL"} + fontWeight={ModifierFontWeight} + fontSize={ModifierFontSize} + margin={ModifierMargin} + /> + + + + "GUI"} + fontWeight={ModifierFontWeight} + fontSize={ModifierFontSize} + margin={ModifierMargin} + /> + + + + ); +} diff --git a/docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.meta b/docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.meta new file mode 100644 index 00000000..0e33e3fe --- /dev/null +++ b/docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.meta @@ -0,0 +1,3 @@ +{ + "version": 0 +} \ No newline at end of file diff --git a/docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.ts b/docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.ts new file mode 100644 index 00000000..496c618d --- /dev/null +++ b/docs/src/animationhelpers/src/hold_tap/hold_tap_comparison.ts @@ -0,0 +1,8 @@ +import {makeProject} from '@motion-canvas/core/lib'; + +import hold_tap_comparison from '../scenes/hold_tap/hold_tap_comparison?scene'; + +export default makeProject({ + scenes: [hold_tap_comparison], + background: '#FFFFFF', +}); diff --git a/docs/src/animationhelpers/src/project.ts b/docs/src/animationhelpers/src/project.ts deleted file mode 100644 index 017a3491..00000000 --- a/docs/src/animationhelpers/src/project.ts +++ /dev/null @@ -1,8 +0,0 @@ -import {makeProject} from '@motion-canvas/core/lib'; - -import example from './scenes/example?scene'; - -export default makeProject({ - scenes: [example], - background: '#141414', -}); diff --git a/docs/src/animationhelpers/src/scenes/example.tsx b/docs/src/animationhelpers/src/scenes/example.tsx deleted file mode 100644 index 5225bfa2..00000000 --- a/docs/src/animationhelpers/src/scenes/example.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import {makeScene2D} from '@motion-canvas/2d/lib/scenes'; -import {waitFor} from '@motion-canvas/core/lib/flow'; - -export default makeScene2D(function* (view) { - // Create your animations here - - yield* waitFor(5); -}); diff --git a/docs/src/animationhelpers/src/scenes/hold_tap/hold_tap_comparison.tsx b/docs/src/animationhelpers/src/scenes/hold_tap/hold_tap_comparison.tsx new file mode 100644 index 00000000..41c7332f --- /dev/null +++ b/docs/src/animationhelpers/src/scenes/hold_tap/hold_tap_comparison.tsx @@ -0,0 +1,79 @@ +import { makeScene2D } from "@motion-canvas/2d/lib/scenes"; +import { Text } from "@motion-canvas/2d/lib/components"; +import { createRef, makeRefs } from "@motion-canvas/core/lib/utils"; +import { 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 tap = makeRefs(); + view.add(); + tap.group.position.x(-400); + tap.group.position.y(-150); + tap.duration.fill("#D9D9D9"); + + const tap_output = makeRefs(); + view.add(); + tap_output.group.position(tap.group.position()); + tap_output.group.position.y(tap_output.group.position.y() + 300); + + const tap_label = createRef(); + view.add( + + tap + + ); + + const hold = makeRefs(); + view.add(); + hold.group.position.x(400); + hold.group.position.y(-150); + hold.duration.fill("#D9D9D9"); + + const hold_output = makeRefs(); + view.add(); + hold_output.group.position(hold.group.position()); + hold_output.group.position.y(hold_output.group.position.y() + 300); + + const hold_tap = createRef(); + view.add( + + hold + + ); + + + yield* waitFor(0.5); + yield* all( + tap.body.position.y(KeyTravel, 0.15), + hold.body.position.y(KeyTravel, 0.15) + ); + yield* all( + tap.duration.grow(0.5, 1, linear), + delay(1, tap.body.position.y(0, 0.15)), + hold.duration.grow(1, 2, linear) + ); + yield* chain( + all(tap.group.rotation(3, 0.03), hold.group.rotation(3, 0.03)), + all(tap.group.rotation(-3, 0.06), hold.group.rotation(-3, 0.06)), + all(tap.group.rotation(0, 0.03), hold.group.rotation(0, 0.03)), + all(tap_output.output.text("f", 0), hold_output.shift.fill("#969696", 0.15)) + ); + yield* waitFor(0.25); + yield* hold.body.position.y(0, 0.15); + yield* delay( + 0.5, + all(tap.duration.grow(0, 0.15), hold.duration.grow(0, 0.15)) + ); +}); diff --git a/docs/src/animationhelpers/vite.config.ts b/docs/src/animationhelpers/vite.config.ts index 4129d81e..617839f3 100644 --- a/docs/src/animationhelpers/vite.config.ts +++ b/docs/src/animationhelpers/vite.config.ts @@ -4,7 +4,7 @@ import motionCanvas from "@motion-canvas/vite-plugin"; export default defineConfig({ plugins: [ motionCanvas({ - project: ["./src/project.ts"], + project: ["./src/hold_tap/hold_tap_comparison.ts"], }), ], build: {