-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create gsap like wrapper prototype
- Loading branch information
1 parent
f530809
commit 2ebaf5b
Showing
11 changed files
with
417 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="x-ua-compatible" content="IE=Edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> | ||
<title>interpol</title> | ||
</head> | ||
<body> | ||
<div id="root"> | ||
<div class="App"> | ||
<div class="Controls"> | ||
<button class="play">play</button> | ||
<button class="reverse">reverse</button> | ||
<button class="pause">pause</button> | ||
<button class="resume">resume</button> | ||
<button class="stop">stop</button> | ||
<button class="refresh">refresh</button> | ||
<button class="seek-0">seek 0</button> | ||
<button class="seek-05">seek .5</button> | ||
<button class="seek-1">seek 1</button> | ||
<input class="progress" value="0" type="number" /> | ||
<input class="slider" type="range" min="0" max="100" value="0" /> | ||
</div> | ||
<div class="wrapper"> | ||
<div class="ball"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="module" src="src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "interpol-psap", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"dev": "vite --host" | ||
}, | ||
"dependencies": { | ||
"@wbe/interpol": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"less": "^4.2.0", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
:root { | ||
--color-gray: #454545; | ||
--color-black-1: #313131; | ||
--color-black: #171717; | ||
--color-blue: #646cff; | ||
--color-white: #fff; | ||
} | ||
|
||
html { | ||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif; | ||
font-weight: 400; | ||
color-scheme: dark; | ||
font-synthesis: none; | ||
text-rendering: optimizeLegibility; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
-webkit-text-size-adjust: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
font-size: 16px; | ||
min-width: 100vw; | ||
min-height: 100vh; | ||
overflow: hidden; | ||
position: fixed; | ||
} | ||
|
||
.ball { | ||
position: absolute; | ||
width: 50px; | ||
height: 50px; | ||
border-radius: 50%; | ||
background-color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Interpol } from "@wbe/interpol" | ||
import type { InterpolConstruct, PropsValues } from "@wbe/interpol" | ||
import "./index.less" | ||
|
||
/** | ||
* Query | ||
*/ | ||
const $element = document.querySelector<HTMLElement>(".ball")! | ||
|
||
const seek0 = document.querySelector<HTMLButtonElement>(".seek-0") | ||
const seek05 = document.querySelector<HTMLButtonElement>(".seek-05") | ||
const seek1 = document.querySelector<HTMLButtonElement>(".seek-1") | ||
|
||
const inputProgress = document.querySelector<HTMLInputElement>(".progress") | ||
const inputSlider = document.querySelector<HTMLInputElement>(".slider") | ||
|
||
/** | ||
* Events | ||
*/ | ||
;["play", "reverse", "pause", "stop", "refresh", "resume"].forEach( | ||
(name: any) => | ||
(document.querySelector<HTMLButtonElement>(`.${name}`)!.onclick = () => { | ||
// @ts-ignore | ||
itp[name]() | ||
}), | ||
) | ||
|
||
seek0!.onclick = () => itp.seek(0, false) | ||
seek05!.onclick = () => itp.seek(0.5, false) | ||
seek1!.onclick = () => itp.seek(1, false) | ||
inputProgress!.onchange = () => itp.seek(parseFloat(inputProgress!.value) / 100, false) | ||
inputSlider!.oninput = () => itp.seek(parseFloat(inputSlider!.value) / 100, false) | ||
|
||
|
||
/** | ||
* PSAP type | ||
*/ | ||
type InterpolKeys = keyof InterpolConstruct<any>; | ||
type CustomPropsValues = Omit<PropsValues, InterpolKeys>; | ||
|
||
const psap = ( | ||
el: HTMLElement | HTMLElement[], | ||
options: InterpolConstruct<any> & { [x:string]: CustomPropsValues } | ||
) => { | ||
|
||
const OptionsWithoutProps = { | ||
duration: options?.duration ?? 1000, | ||
ease: options?.ease ?? "linear", | ||
reverseEase: options?.reverseEase ?? "linear", | ||
paused: options?.paused ?? false, | ||
immediateRender: options?.immediateRender ?? false, | ||
delay: options?.delay ?? 0, | ||
debug: options?.debug ?? false, | ||
beforeStart: options?.beforeStart ?? (()=> {}), | ||
onUpdate: options?.onUpdate ?? (()=> {}), | ||
onComplete: options?.onComplete ?? (()=> {}), | ||
} | ||
|
||
// in options, get all keys that are not in OptionsWithoutProps | ||
const props = Object.keys(options).reduce((acc, key) => { | ||
if (!Object.keys(OptionsWithoutProps).includes(key)) acc[key] = options[key] | ||
return acc | ||
}, {} as Record<string, PropsValues>) | ||
|
||
|
||
return new Interpol({ el, props, ...OptionsWithoutProps }) | ||
} | ||
|
||
/** | ||
* Use a simple psap | ||
*/ | ||
const itp = psap($element, { | ||
x: [0, 100, "px"], | ||
y: { from: 0, to: 100, unit:"px", ease: "power1.in"}, | ||
ease: "power3.out", | ||
paused: true, | ||
onComplete: ({x}, time, props, instance) => { | ||
|
||
} | ||
}) | ||
|
||
itp.play() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
|
||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": false, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
|
||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.