@gecko-ui-kit/motion 0.0.0-stage → 0.8.0
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/LICENSE +21 -0
- package/README.md +73 -2
- package/index.js +25 -0
- package/motion.css +137 -0
- package/package.json +38 -4
- package/src/bin.js +96 -0
- package/src/burger.js +123 -0
- package/src/charts.js +37 -0
- package/src/confetti.js +166 -0
- package/src/core.js +26 -0
- package/src/count.js +21 -0
- package/src/drag.js +71 -0
- package/src/edge.js +127 -0
- package/src/enter.js +24 -0
- package/src/feedback.js +25 -0
- package/src/fly.js +88 -0
- package/src/hold.js +169 -0
- package/src/hover.js +26 -0
- package/src/indicator.js +57 -0
- package/src/liquid.js +130 -0
- package/src/odometer.js +169 -0
- package/src/overlay.js +12 -0
- package/src/search.js +134 -0
- package/src/swap.js +24 -0
- package/src/text.js +28 -0
- package/src/theme.js +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WoraphonDev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gecko-ui-kit/motion
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Every animation helper, built on GSAP 3 (peer dependency). All of them respect
|
|
4
|
+
`prefers-reduced-motion`.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install gsap @gecko-ui-kit/motion
|
|
8
|
+
```
|
|
9
|
+
```js
|
|
10
|
+
import '@gecko-ui-kit/motion/motion.css'
|
|
11
|
+
import { indicator, rise, title, count, swap, drag, theme } from '@gecko-ui-kit/motion'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Helper | What it does |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `indicator(pill, target, opts)` / `trackIndicator` | Stretchy highlight: leading edge first, trailing edge follows |
|
|
17
|
+
| `swap(view, dir, render)` | Old page leaves, new page slides in from the direction of travel |
|
|
18
|
+
| `title(el)` / `retitle(el, text)` | Split a heading into letters that roll up |
|
|
19
|
+
| `rise`, `slide`, `deal`, `reveal` | Staggered entrances |
|
|
20
|
+
| `count(el, to, fmt)` / `countAll(root)` | Numbers that count up (`[data-count]`) |
|
|
21
|
+
| `bars`, `meter`, `ring`, `steps`, `growX`, `growY` | Data motion |
|
|
22
|
+
| `magnetic(root)` / `lift(root)` | `.magnetic` buttons follow the cursor, `[data-lift]` floats on hover |
|
|
23
|
+
| `pop`, `shake`, `flash`, `tick`, `wiggle` | Feedback |
|
|
24
|
+
| `drag(el, e, opts)`, `landFrom(el, rect)`, `sortable(root)` | Drag & drop with elastic landing |
|
|
25
|
+
| `theme(next, button)` / `toggleTheme` | Light/dark with a circle reveal from the button |
|
|
26
|
+
| `popIn`, `popOut`, `zoomFrom`, `fadeIn` | Overlay motions |
|
|
27
|
+
| `liquidTabs(el, opts)` / `liquidBar(items, opts)` | Liquid phone tab bar: the bubble over the active tab sinks and rises (or glides) to the new tab, melting into the bar |
|
|
28
|
+
| `expandSearch(el, opts)` / `searchField(opts)` | Search icon that opens into a field: it stretches out, the magnifier swings, the hint types itself in and a close × draws itself |
|
|
29
|
+
| `edgeProgress(button, opts)` | Download button: the outline fills round the edge as progress (or chases when the size is unknown), then the button fills and a tick draws |
|
|
30
|
+
| `holdConfirm(button, opts)` | Hold to confirm: colour floods the button (or a ring fills round it) while held, drains with a reminder if let go early, bursts into a tick when done |
|
|
31
|
+
| `binEat(button, opts)` / `binEat.reset` | Delete button: the bin opens its lid and eats the word letter by letter, then “Deleted” rises in |
|
|
32
|
+
| `sendOff(button, opts)` / `sendOff.reset` | Send button: the plane flies off (climb, straight or loop) with a dotted trail, then “Sent” and a drawn tick roll in |
|
|
33
|
+
| `speed(x)`, `reduceMotion(bool)` | Global speed / force reduced motion |
|
|
34
|
+
|
|
35
|
+
## Odometer
|
|
36
|
+
Numbers roll digit by digit, like the meter in a car: every digit is a reel that spins to its new digit, the reels
|
|
37
|
+
start one after the other from the right, and digits that stay the same don't move. When the number gets longer or
|
|
38
|
+
shorter the width glides; commas, currency signs and suffixes stay put. Screen readers get only the final text.
|
|
39
|
+
```js
|
|
40
|
+
import { odometer } from '@gecko-ui-kit/motion'
|
|
41
|
+
|
|
42
|
+
odometer(price, 29, { format: { style: 'currency', currency: 'USD', minimumFractionDigits: 0, maximumFractionDigits: 0 } })
|
|
43
|
+
odometer(price, 23) // later: rolls down to $23 (format is remembered)
|
|
44
|
+
odometer(orders, 1284, { from: 0, duration: 1.2, stagger: 0.08, direction: 'up' })
|
|
45
|
+
```
|
|
46
|
+
Options: `format` (Intl options or a function), `locale`, `duration` (0.9), `stagger` (0.06), `direction` (`'auto'|'up'|'down'`),
|
|
47
|
+
`ease`, `from`. Returns the GSAP timeline. Row height: `--odo-lh`. With reduced motion the number just changes.
|
|
48
|
+
|
|
49
|
+
## Confetti
|
|
50
|
+
A burst of paper shoots up from a button (or any point), slows in the air and flutters down over the page, each piece
|
|
51
|
+
spinning, swaying and turning over before it fades. It draws on one fixed canvas that ignores the mouse; the canvas and
|
|
52
|
+
its animation frame are removed when the last piece lands. Colours come from the theme (`--accent` and the hues).
|
|
53
|
+
```js
|
|
54
|
+
import { confetti } from '@gecko-ui-kit/motion'
|
|
55
|
+
|
|
56
|
+
button.addEventListener('click', () => confetti(button))
|
|
57
|
+
const party = confetti({ x: innerWidth / 2, y: innerHeight }, { count: 200, spread: 70, shapes: ['rect', 'star'] })
|
|
58
|
+
await party // resolves when the last piece is gone; party.stop() clears it now, confetti.clear() clears all
|
|
59
|
+
```
|
|
60
|
+
Options: `count` (120), `spread` (100°), `angle` (90 = up), `velocity`, `colors`, `shapes` (`rect circle strip star`),
|
|
61
|
+
`gravity`, `duration` (3 s), `zIndex` (9999), `reduced` (`'sparkle'` = a few soft twinkles at the origin, or `'none'`).
|
|
62
|
+
|
|
63
|
+
## Burger icon
|
|
64
|
+
Three lines that turn into an ✕: the outer lines slide to the middle while the middle one shrinks away, then they turn
|
|
65
|
+
and meet with a small springy settle; closing plays it backwards. `aria-expanded` and the button label follow.
|
|
66
|
+
```js
|
|
67
|
+
import { burgerIcon, burger, bindBurger } from '@gecko-ui-kit/motion'
|
|
68
|
+
|
|
69
|
+
menuButton.innerHTML = burgerIcon()
|
|
70
|
+
const menu = bindBurger(menuButton, { controls: 'main-menu', onToggle: (open) => { nav.hidden = !open } })
|
|
71
|
+
burger(otherButton, true) // just the morph: ✕ (and aria-expanded="true")
|
|
72
|
+
```
|
|
73
|
+
`bindBurger` options: `onToggle`, `open`, `duration` (0.45), `words: { open, close }` (the label), `controls`, `escape`
|
|
74
|
+
(Escape closes and refocuses). Size with `--burger-w`, `--burger-h`, `--burger-t`, `--burger-r`, or `burger--sm` / `burger--lg`.
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* @gecko-ui-kit/motion — every animation helper. Needs GSAP 3 (peer dependency). */
|
|
2
|
+
export { g, gsap, RM, D, $$, esc, fine, ready, reduceMotion, speed } from './src/core.js';
|
|
3
|
+
export { split, title, retitle } from './src/text.js';
|
|
4
|
+
export { rise, slide, deal, reveal } from './src/enter.js';
|
|
5
|
+
export { flash, tick, pop, shake, wiggle } from './src/feedback.js';
|
|
6
|
+
export { count, countAll } from './src/count.js';
|
|
7
|
+
export { magnetic, lift } from './src/hover.js';
|
|
8
|
+
export { indicator, trackIndicator, indicatorTiming } from './src/indicator.js';
|
|
9
|
+
export { meter, growX, growY, bars, ring, steps, switchKnob } from './src/charts.js';
|
|
10
|
+
export { landFrom, drag, sortable } from './src/drag.js';
|
|
11
|
+
export { theme, toggleTheme, getTheme, restoreTheme } from './src/theme.js';
|
|
12
|
+
export { swap, swapTiming } from './src/swap.js';
|
|
13
|
+
export { popIn, popOut, zoomFrom, fadeIn } from './src/overlay.js';
|
|
14
|
+
export { sendOff } from './src/fly.js';
|
|
15
|
+
export { binEat, binIcon } from './src/bin.js';
|
|
16
|
+
export { edgeProgress, downloadIcon } from './src/edge.js';
|
|
17
|
+
export { expandSearch, searchField } from './src/search.js';
|
|
18
|
+
export { liquidTabs, liquidBar } from './src/liquid.js';
|
|
19
|
+
export { holdConfirm } from './src/hold.js';
|
|
20
|
+
/** Odometer: numbers roll digit by digit (one reel per digit, staggered from the right; width glides when the length changes). See src/odometer.js. */
|
|
21
|
+
export { odometer } from './src/odometer.js';
|
|
22
|
+
/** Confetti: a paper burst from an element or point on one shared fixed canvas, removed when the last piece lands; returns a promise with stop(). See src/confetti.js. */
|
|
23
|
+
export { confetti } from './src/confetti.js';
|
|
24
|
+
/** Burger icon: three lines that morph to ✕ and back (burger), with click/Escape wiring and aria-expanded (bindBurger). See src/burger.js. */
|
|
25
|
+
export { burgerIcon, burger, bindBurger } from './src/burger.js';
|
package/motion.css
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/* @gecko-ui-kit/motion/motion.css — CSS the motion helpers rely on */
|
|
2
|
+
/* title(): words mask the rising characters */
|
|
3
|
+
.word { display: inline-block; overflow: hidden; padding-bottom: .08em; margin-bottom: -.08em; vertical-align: bottom; }
|
|
4
|
+
.ch { display: inline-block; will-change: transform; }
|
|
5
|
+
/* flash() / tick() */
|
|
6
|
+
@keyframes t-flash { 0% { color: var(--accent); } 100% { color: inherit; } }
|
|
7
|
+
@keyframes t-tick-up { 0% { color: var(--up, #16a36a); } 100% { color: inherit; } }
|
|
8
|
+
@keyframes t-tick-down { 0% { color: var(--down, #e0464c); } 100% { color: inherit; } }
|
|
9
|
+
.is-flash { animation: t-flash 1s var(--ease, ease); display: inline-block; }
|
|
10
|
+
.tick-up { animation: t-tick-up 1.1s var(--ease, ease); }
|
|
11
|
+
.tick-down { animation: t-tick-down 1.1s var(--ease, ease); }
|
|
12
|
+
/* .live — breathing status dot */
|
|
13
|
+
@keyframes t-breathe { 0%, 100% { opacity: .1; transform: scale(1); } 50% { opacity: .45; transform: scale(1.25); } }
|
|
14
|
+
.live { position: relative; }
|
|
15
|
+
.live::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; background: var(--good, #16a36a); opacity: .25; animation: t-breathe 2s ease-in-out infinite; }
|
|
16
|
+
/* drag() */
|
|
17
|
+
.is-drag { position: relative; z-index: 50; cursor: grabbing !important; box-shadow: var(--shadow-3) !important; }
|
|
18
|
+
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
|
|
19
|
+
.is-target { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft) !important; }
|
|
20
|
+
/* theme(): let the circle reveal do the work */
|
|
21
|
+
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
|
|
22
|
+
@media (prefers-reduced-motion: reduce) { .live::after { animation: none; } }
|
|
23
|
+
/* sendOff(): the plane may fly outside the button */
|
|
24
|
+
.fly { position: relative; overflow: visible !important; }
|
|
25
|
+
.fly > svg { position: relative; z-index: 2; will-change: transform; }
|
|
26
|
+
.fly__done { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; opacity: 0; pointer-events: none; font-weight: inherit; }
|
|
27
|
+
.fly__done b { font-weight: inherit; }
|
|
28
|
+
.fly__done path { stroke-dasharray: 22; stroke-dashoffset: 22; }
|
|
29
|
+
.fly.is-sent { background: var(--good, #16a36a) !important; border-color: transparent !important; color: #fff !important; transition: background .35s, color .35s, border-color .35s; }
|
|
30
|
+
.fly__dot { position: absolute; z-index: 1; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: var(--accent, #5b4cf0); pointer-events: none; }
|
|
31
|
+
.btn--primary.fly .fly__dot, .btn--dark.fly .fly__dot { background: color-mix(in srgb, var(--accent, #5b4cf0) 70%, var(--ink, #14161c)); }
|
|
32
|
+
/* binEat(): letters hop into the bin */
|
|
33
|
+
.bin-eat { overflow: visible !important; }
|
|
34
|
+
.bin__ch { display: inline-block; will-change: transform; }
|
|
35
|
+
.bin-eat > .bin { overflow: visible; }
|
|
36
|
+
.btn--danger.is-eaten { background: color-mix(in srgb, var(--bad, #e0464c) 78%, #000); }
|
|
37
|
+
.bin-eat:not(.btn--danger).is-eaten { color: var(--bad, #e0464c); }
|
|
38
|
+
/* edgeProgress(): the outline is the progress bar */
|
|
39
|
+
.edge { position: relative; font-variant-numeric: tabular-nums; }
|
|
40
|
+
.edge > svg.edge__ring { position: absolute; inset: -1px; width: calc(100% + 2px); height: calc(100% + 2px); overflow: visible; pointer-events: none; fill: none; stroke-linecap: round; }
|
|
41
|
+
.edge__track { stroke: color-mix(in srgb, currentColor 18%, transparent); }
|
|
42
|
+
.edge__line { stroke: var(--accent, #5b4cf0); filter: drop-shadow(0 0 3px color-mix(in srgb, var(--accent, #5b4cf0) 55%, transparent)); }
|
|
43
|
+
.btn--primary.edge .edge__line, .btn--dark.edge .edge__line { stroke: #fff; filter: drop-shadow(0 0 3px rgba(255, 255, 255, .6)); }
|
|
44
|
+
.edge.is-done { background: var(--good, #16a36a) !important; border-color: transparent !important; color: #fff !important; transition: background .35s, color .35s; }
|
|
45
|
+
.edge.is-failed .edge__line { stroke: var(--bad, #e0464c); filter: none; }
|
|
46
|
+
.edge.is-failed { color: var(--bad, #e0464c); }
|
|
47
|
+
.btn--primary.edge.is-failed, .btn--dark.edge.is-failed { color: #fff; background: var(--bad, #e0464c); }
|
|
48
|
+
.btn--primary.edge.is-failed .edge__line, .btn--dark.edge.is-failed .edge__line { stroke: rgba(255, 255, 255, .7); }
|
|
49
|
+
.edge__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
50
|
+
.dl .dl__tick { stroke-width: 2.4; }
|
|
51
|
+
/* expandSearch(): a round search button that opens into a field */
|
|
52
|
+
.xs { --xs-h: 44px; position: relative; display: inline-flex; align-items: center; flex: 0 1 auto; min-width: var(--xs-h); height: var(--xs-h); width: var(--xs-h); max-width: 100%; border-radius: 999px; background: var(--card, #fff); border: 1px solid var(--line-2, #d5d9e0); color: var(--ink, #14161c); box-shadow: var(--shadow-1, none); overflow: hidden; transition: background .25s, border-color .25s, box-shadow .25s; }
|
|
53
|
+
.xs--sm { --xs-h: 36px; }
|
|
54
|
+
.xs.is-open:focus-within { border-color: var(--accent, #5b4cf0); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent, #5b4cf0) 16%, transparent); }
|
|
55
|
+
.xs--quiet:not(.is-open) { background: transparent; border-color: transparent; box-shadow: none; }
|
|
56
|
+
.xs__btn { flex: none; display: grid; place-items: center; width: calc(var(--xs-h) - 2px); height: calc(var(--xs-h) - 2px); border-radius: 50%; color: inherit; transition: background .2s; }
|
|
57
|
+
.xs:not(.is-open) .xs__btn:hover { background: var(--card-2, #f7f8fa); }
|
|
58
|
+
.xs__btn:focus-visible, .xs__close:focus-visible { outline: 2px solid var(--accent, #5b4cf0); outline-offset: -4px; }
|
|
59
|
+
.xs__ic { width: 18px; height: 18px; overflow: visible; }
|
|
60
|
+
.xs--sm .xs__ic { width: 16px; height: 16px; }
|
|
61
|
+
.xs__input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: inherit; font: inherit; font-size: 14px; padding: 0 4px 0 0; visibility: hidden; }
|
|
62
|
+
.xs__input::placeholder { color: var(--faint, #9aa1ad); }
|
|
63
|
+
.xs__input::-webkit-search-cancel-button, .xs__input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
|
|
64
|
+
.xs__close { flex: none; display: grid; place-items: center; width: calc(var(--xs-h) - 14px); height: calc(var(--xs-h) - 14px); margin-right: 5px; border-radius: 50%; color: var(--muted, #6b7280); visibility: hidden; transition: background .2s, color .2s; }
|
|
65
|
+
.xs__close:hover { background: var(--card-2, #f7f8fa); color: var(--ink, #14161c); }
|
|
66
|
+
.xs__close svg { width: 16px; height: 16px; }
|
|
67
|
+
.xs.is-open .xs__input, .xs.is-open .xs__close { visibility: visible; }
|
|
68
|
+
/* liquidTabs(): a tab bar where the bar and the bubble over the active tab are one liquid.
|
|
69
|
+
Set --lq-h --lq-bub --lq-dot --lq-lift --lq-bg --lq-ink --lq-on --lq-on-ink --lq-edge --lq-shadow on the bar or any parent. */
|
|
70
|
+
.lq { --lq-auto-bg: var(--card, #fff); --lq-auto-edge: var(--line-2, #d5d9e0); --lq-auto-shadow: rgba(16, 18, 24, .14);
|
|
71
|
+
position: relative; isolation: isolate; display: flex; align-items: stretch; height: var(--lq-h, 64px); padding: 0 6px; }
|
|
72
|
+
[data-theme="dark"] .lq { --lq-auto-bg: var(--card-2, #1d2027); --lq-auto-edge: #454b5a; --lq-auto-shadow: rgba(0, 0, 0, .55); } /* lift the bar off a dark page */
|
|
73
|
+
.lq__defs { position: absolute; width: 0; height: 0; overflow: hidden; }
|
|
74
|
+
.lq__goo { position: absolute; inset: 0; z-index: -1; pointer-events: none; filter: var(--lq-goo,) drop-shadow(0 0 1px var(--lq-edge, var(--lq-auto-edge))) drop-shadow(0 10px 18px var(--lq-shadow, var(--lq-auto-shadow))); }
|
|
75
|
+
.lq--plain .lq__goo { filter: drop-shadow(0 0 1px var(--lq-edge, var(--lq-auto-edge))) drop-shadow(0 10px 18px var(--lq-shadow, var(--lq-auto-shadow))); }
|
|
76
|
+
.lq__body, .lq__bub, .lq__drop { position: absolute; background: var(--lq-bg, var(--lq-auto-bg)); }
|
|
77
|
+
.lq__body { inset: 0; border-radius: 24px; }
|
|
78
|
+
.lq__bub { left: 0; top: calc(-1 * var(--lq-lift, 22px)); width: var(--lq-bub, 56px); height: var(--lq-bub, 56px); border-radius: 50%; }
|
|
79
|
+
.lq__drop { left: 0; top: -6px; width: 18px; height: 18px; border-radius: 50%; transform: scale(0); }
|
|
80
|
+
.lq__dot { position: absolute; left: 0; top: calc((var(--lq-bub, 56px) - var(--lq-dot, 42px)) / 2 - var(--lq-lift, 22px)); width: var(--lq-dot, 42px); height: var(--lq-dot, 42px); border-radius: 50%; background: var(--lq-on, var(--accent, #5b4cf0)); box-shadow: 0 8px 16px -8px var(--lq-on, var(--accent, #5b4cf0)); pointer-events: none; }
|
|
81
|
+
.lq__tab { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--lq-ink, var(--muted, #6b7280)); font-size: 10.5px; font-weight: 650; -webkit-tap-highlight-color: transparent; transition: color .25s; }
|
|
82
|
+
.lq__tab[aria-current] { color: var(--lq-on, var(--accent, #5b4cf0)); }
|
|
83
|
+
.lq__ic { display: grid; place-items: center; width: 24px; height: 24px; transition: color .2s; }
|
|
84
|
+
.lq__ic svg { width: 22px; height: 22px; }
|
|
85
|
+
.lq__tab.is-on .lq__ic { color: var(--lq-on-ink, #fff); }
|
|
86
|
+
.lq__lb { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
87
|
+
.lq--icons .lq__lb { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
88
|
+
.lq__tab:focus-visible { outline: none; }
|
|
89
|
+
.lq__tab:focus-visible .lq__lb, .lq--icons .lq__tab:focus-visible .lq__ic { outline: 2px solid var(--accent, #5b4cf0); outline-offset: 3px; border-radius: 6px; }
|
|
90
|
+
|
|
91
|
+
/* ---------- hold to confirm (holdConfirm) ----------
|
|
92
|
+
Colour: --hold-c (set by the tone class) on the button or any parent. */
|
|
93
|
+
.hold { position: relative; isolation: isolate; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; font-variant-numeric: tabular-nums; }
|
|
94
|
+
.hold--bad { --hold-c: var(--bad, #e0464c); }
|
|
95
|
+
.hold--accent { --hold-c: var(--accent, #5b4cf0); }
|
|
96
|
+
.hold--good { --hold-c: var(--good, #16a36a); }
|
|
97
|
+
.hold--warn { --hold-c: var(--warn, #d97706); }
|
|
98
|
+
.hold__fill { position: absolute; inset: -1px; z-index: 1; border-radius: inherit; overflow: hidden; background: var(--hold-c); color: #fff; clip-path: inset(0 100% 0 0); pointer-events: none; }
|
|
99
|
+
.hold__face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: inherit; padding: inherit; }
|
|
100
|
+
.hold__face > svg { flex: none; }
|
|
101
|
+
.hold.is-done { background: var(--hold-c) !important; border-color: transparent !important; color: #fff !important; }
|
|
102
|
+
.hold > svg.hold__ring { position: absolute; inset: -6px; width: calc(100% + 12px) !important; height: calc(100% + 12px) !important; /* !important: page rules like 'button svg { width: 20px }' must not shrink the ring */
|
|
103
|
+
transform: rotate(-90deg); overflow: visible; pointer-events: none; fill: none; stroke-width: 4; stroke-linecap: round; }
|
|
104
|
+
.hold__track { stroke: color-mix(in srgb, var(--hold-c) 16%, transparent); }
|
|
105
|
+
.hold__arc { stroke: var(--hold-c); }
|
|
106
|
+
.hold--ring.is-done > svg.hold__ring { opacity: 0; transition: opacity .3s; }
|
|
107
|
+
.hold__burst { position: absolute; inset: -1px; z-index: -1; border-radius: inherit; background: var(--hold-c); pointer-events: none; }
|
|
108
|
+
.hold__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
109
|
+
|
|
110
|
+
/* ---------- odometer (odometer) ----------
|
|
111
|
+
Each digit is a clipped column holding a reel of 0–9 (three times over, so it can roll past 9).
|
|
112
|
+
Height of a row: --odo-lh (unitless line-height, default 1.15). */
|
|
113
|
+
.odo { position: relative; display: inline-block; white-space: nowrap; line-height: var(--odo-lh, 1.15); font-variant-numeric: tabular-nums; }
|
|
114
|
+
.odo__vis { white-space: nowrap; }
|
|
115
|
+
.odo__cell { display: inline-block; vertical-align: top; }
|
|
116
|
+
.odo__ch { overflow-x: clip; } /* clips only sideways while it grows or shrinks, so Thai marks above / below are never cut */
|
|
117
|
+
.odo__col { height: calc(var(--odo-lh, 1.15) * 1em); overflow: hidden; text-align: center;
|
|
118
|
+
-webkit-mask-image: linear-gradient(transparent, #000 .14em, #000 calc(100% - .14em), transparent);
|
|
119
|
+
mask-image: linear-gradient(transparent, #000 .14em, #000 calc(100% - .14em), transparent); }
|
|
120
|
+
.odo__reel { display: block; will-change: transform; }
|
|
121
|
+
.odo__reel > span { display: block; height: calc(var(--odo-lh, 1.15) * 1em); }
|
|
122
|
+
.odo__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
|
|
123
|
+
|
|
124
|
+
/* ---------- confetti (confetti) ----------
|
|
125
|
+
The canvas confetti() lays over the page while pieces are in the air (removed afterwards).
|
|
126
|
+
The script also sets these inline, so it works without this file; z-index comes from the zIndex option. */
|
|
127
|
+
.confetti-layer { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
|
|
128
|
+
|
|
129
|
+
/* ---------- burger icon (burgerIcon / burger / bindBurger) ----------
|
|
130
|
+
Three lines in currentColor. Size: --burger-w × --burger-h, line thickness --burger-t. */
|
|
131
|
+
.burger { --burger-w: 20px; --burger-h: 14px; --burger-t: 2px; position: relative; display: inline-block; flex: none; width: var(--burger-w); height: var(--burger-h); vertical-align: middle; }
|
|
132
|
+
.burger > i { position: absolute; left: 0; width: 100%; height: var(--burger-t); border-radius: var(--burger-r, 2px); background: currentColor; transform-origin: 50% 50%; }
|
|
133
|
+
.burger > i:nth-child(1) { top: 0; }
|
|
134
|
+
.burger > i:nth-child(2) { top: calc(50% - var(--burger-t) / 2); }
|
|
135
|
+
.burger > i:nth-child(3) { top: calc(100% - var(--burger-t)); }
|
|
136
|
+
.burger--lg { --burger-w: 24px; --burger-h: 17px; --burger-t: 2.5px; }
|
|
137
|
+
.burger--sm { --burger-w: 16px; --burger-h: 11px; --burger-t: 1.75px; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gecko-ui-kit/motion",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Animation helpers: stretchy indicator, page swap, text reveal, count-up, odometer, confetti, burger morph, drag & drop, theme reveal and more.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vanilla-js",
|
|
7
|
+
"ui",
|
|
8
|
+
"animation",
|
|
9
|
+
"gsap",
|
|
10
|
+
"motion"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://woraphondev.github.io/UI-Package/playground/",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/WoraphonDev/UI-Package.git",
|
|
16
|
+
"directory": "packages/motion"
|
|
17
|
+
},
|
|
18
|
+
"bugs": "https://github.com/WoraphonDev/UI-Package/issues",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"*.css"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./index.js",
|
|
26
|
+
"./motion.css": "./motion.css"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"*.js",
|
|
30
|
+
"*.css",
|
|
31
|
+
"src/",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"gsap": "^3.12.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/bin.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* Delete: the bin on the button opens its lid and eats its own label. Each letter hops in an
|
|
2
|
+
arc into the bin, the bin gulps as it lands, the lid snaps shut with a bounce, the bin chews,
|
|
3
|
+
and the new label ("Deleted") rises in. After a moment the word comes back. */
|
|
4
|
+
import { g, RM, $$ } from './core.js';
|
|
5
|
+
|
|
6
|
+
/* A bin drawn in two parts so the lid can open on its left hinge. */
|
|
7
|
+
const BIN = `<svg class="bin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
8
|
+
<g class="bin__lid"><path d="M3 6.5h18"/><path d="M9 6.5V5a1.6 1.6 0 0 1 1.6-1.6h2.8A1.6 1.6 0 0 1 15 5v1.5"/></g>
|
|
9
|
+
<g class="bin__body"><path d="M5.6 6.5l.95 12.6A1.9 1.9 0 0 0 8.45 21h7.1a1.9 1.9 0 0 0 1.9-1.9l.95-12.6"/><path d="M10 10.5v6.2M14 10.5v6.2"/></g></svg>`;
|
|
10
|
+
/** The bin icon binEat() animates (lid and body as separate groups). Use it in your own buttons. */
|
|
11
|
+
export const binIcon = BIN;
|
|
12
|
+
|
|
13
|
+
const parts = (btn) => {
|
|
14
|
+
let svg = btn.querySelector(':scope > svg');
|
|
15
|
+
if (!svg?.querySelector('.bin__lid')) { // swap any icon for the two-part bin
|
|
16
|
+
const t = document.createElement('template'); t.innerHTML = BIN.trim();
|
|
17
|
+
const fresh = t.content.firstElementChild;
|
|
18
|
+
svg ? svg.replaceWith(fresh) : btn.prepend(fresh); svg = fresh;
|
|
19
|
+
}
|
|
20
|
+
return { svg, lid: svg.querySelector('.bin__lid'), body: svg.querySelector('.bin__body'), label: btn.querySelector(':scope > span:not(.bin__sr)') };
|
|
21
|
+
};
|
|
22
|
+
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
23
|
+
|
|
24
|
+
/** Width change without a jump: run fn (which changes the text), then tween from the old width to the new. */
|
|
25
|
+
const keepWidth = (btn, fn, duration = 0.4) => {
|
|
26
|
+
const w0 = btn.offsetWidth; fn(); const w1 = btn.offsetWidth;
|
|
27
|
+
if (!RM() && Math.abs(w1 - w0) > 1) g.fromTo(btn, { width: w0 }, { width: w1, duration, ease: 'power3.out', clearProps: 'width' });
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* binEat(button, { done: 'Deleted', order: 'first'|'last', chew: true, back: 2.4, onDone })
|
|
32
|
+
* The button needs a <span> label; its icon is swapped for the two-part bin.
|
|
33
|
+
* order: which letter jumps first ('first' = the one next to the bin).
|
|
34
|
+
* back: seconds before the word comes back (0 = stay; call binEat.reset(button) yourself).
|
|
35
|
+
*/
|
|
36
|
+
export const binEat = (btn, { done = 'Deleted', order = 'first', chew = true, back = 2.4, onDone } = {}) => {
|
|
37
|
+
btn = $$(btn)[0];
|
|
38
|
+
if (!btn || btn.__eating) return g.timeline();
|
|
39
|
+
const { svg, lid, body, label } = parts(btn);
|
|
40
|
+
if (!label) return g.timeline();
|
|
41
|
+
btn.__eating = true; btn.__binText ??= label.textContent; btn.classList.add('bin-eat');
|
|
42
|
+
btn.setAttribute('aria-disabled', 'true');
|
|
43
|
+
const word = btn.__binText;
|
|
44
|
+
const finish = () => { btn.classList.add('is-eaten'); onDone?.(btn); if (back > 0) g.delayedCall(back, () => reset(btn)); };
|
|
45
|
+
const showDone = () => keepWidth(btn, () => { label.textContent = done; });
|
|
46
|
+
|
|
47
|
+
if (RM()) { showDone(); finish(); return g.timeline(); }
|
|
48
|
+
|
|
49
|
+
// split the word into letters that can fly
|
|
50
|
+
label.setAttribute('aria-label', word);
|
|
51
|
+
label.innerHTML = [...word].map((c) => `<span class="bin__ch" aria-hidden="true">${c === ' ' ? ' ' : esc(c)}</span>`).join('');
|
|
52
|
+
let chs = [...label.children];
|
|
53
|
+
if (order === 'last') chs = chs.reverse();
|
|
54
|
+
const bin = svg.getBoundingClientRect();
|
|
55
|
+
const mouthX = bin.left + bin.width * 0.55, mouthY = bin.top + bin.height * 0.32;
|
|
56
|
+
|
|
57
|
+
const tl = g.timeline({ onComplete: finish });
|
|
58
|
+
tl.to(btn, { scale: 0.96, duration: 0.1, ease: 'power2.out' })
|
|
59
|
+
.to(btn, { scale: 1, duration: 0.5, ease: 'back.out(3)' })
|
|
60
|
+
.to(lid, { rotation: -38, svgOrigin: '3.5 6.5', y: -1.5, duration: 0.28, ease: 'back.out(2.5)' }, 0.05);
|
|
61
|
+
const start = 0.25, gap = Math.min(0.09, 0.6 / chs.length);
|
|
62
|
+
chs.forEach((ch, k) => {
|
|
63
|
+
const r = ch.getBoundingClientRect(), dx = mouthX - (r.left + r.width / 2), dy = mouthY - (r.top + r.height / 2);
|
|
64
|
+
const at = start + k * gap, hop = 0.42;
|
|
65
|
+
tl.to(ch, {
|
|
66
|
+
keyframes: { '0%': { x: 0, y: 0, rotation: 0, scale: 1 }, '45%': { x: dx * 0.5, y: Math.min(dy, 0) - 11, rotation: -25 }, '100%': { x: dx, y: dy, rotation: -70, scale: 0.25, opacity: 0 }, easeEach: 'sine.inOut' },
|
|
67
|
+
duration: hop, ease: 'power1.in',
|
|
68
|
+
}, at)
|
|
69
|
+
// the bin gulps as each letter lands
|
|
70
|
+
.fromTo(body, { scaleY: 0.86, scaleX: 1.06 }, { scaleY: 1, scaleX: 1, svgOrigin: '12 21', duration: 0.3, ease: 'back.out(3)', immediateRender: false }, at + hop - 0.02);
|
|
71
|
+
});
|
|
72
|
+
const shut = start + (chs.length - 1) * gap + 0.42;
|
|
73
|
+
tl.to(lid, { rotation: 0, y: 0, svgOrigin: '3.5 6.5', duration: 0.4, ease: 'back.out(3.2)' }, shut)
|
|
74
|
+
.fromTo(svg, { y: 0 }, { keyframes: { y: [0, 2, 0] }, duration: 0.25, ease: 'power2.out' }, shut);
|
|
75
|
+
if (chew) tl.to(svg, { keyframes: { rotation: [0, -9, 8, -6, 4, 0] }, transformOrigin: '50% 100%', duration: 0.6, ease: 'power1.inOut' }, shut + 0.2);
|
|
76
|
+
tl.add(() => {
|
|
77
|
+
showDone();
|
|
78
|
+
g.fromTo(label, { y: 10, opacity: 0 }, { y: 0, opacity: 1, duration: 0.45, ease: 'back.out(2)', clearProps: 'transform,opacity' });
|
|
79
|
+
}, chew ? shut + 0.5 : shut + 0.15);
|
|
80
|
+
return tl;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Bring the word back: the lid pops, and the original label drops in. */
|
|
84
|
+
export const reset = (btn) => {
|
|
85
|
+
btn = $$(btn)[0]; if (!btn || !btn.__binText) return g.timeline();
|
|
86
|
+
const { svg, lid, label } = parts(btn);
|
|
87
|
+
g.killTweensOf([btn, svg, lid, label]);
|
|
88
|
+
const end = () => { btn.__eating = false; btn.classList.remove('is-eaten'); btn.removeAttribute('aria-disabled'); label.removeAttribute('aria-label'); };
|
|
89
|
+
if (RM()) { keepWidth(btn, () => { label.textContent = btn.__binText; }); end(); return g.timeline(); }
|
|
90
|
+
return g.timeline({ onComplete: end })
|
|
91
|
+
.to(label, { y: -8, opacity: 0, duration: 0.2, ease: 'power2.in' })
|
|
92
|
+
.add(() => { btn.classList.remove('is-eaten'); keepWidth(btn, () => { label.textContent = btn.__binText; }); })
|
|
93
|
+
.to(lid, { keyframes: { rotation: [0, -30, 0] }, svgOrigin: '3.5 6.5', duration: 0.45, ease: 'power2.out' })
|
|
94
|
+
.fromTo(label, { y: 8, opacity: 0 }, { y: 0, opacity: 1, duration: 0.4, ease: 'power3.out', clearProps: 'transform,opacity' }, '<');
|
|
95
|
+
};
|
|
96
|
+
binEat.reset = reset;
|
package/src/burger.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/* Burger icon: three lines that turn into an ✕. Opening, the top and bottom lines first slide to
|
|
2
|
+
the middle (the middle line shrinks away from both ends at the same time), then they turn in
|
|
3
|
+
opposite directions and meet as a cross with a small springy settle. Closing plays the same
|
|
4
|
+
story backwards: the cross unturns, then the lines spread apart and the middle one grows back.
|
|
5
|
+
The button's aria-expanded (and its label, if you give words) follow. With reduced motion the
|
|
6
|
+
icon swaps at once. */
|
|
7
|
+
import { g, RM, $$ } from './core.js';
|
|
8
|
+
|
|
9
|
+
const WORDS = { open: 'Open menu', close: 'Close menu' };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* burgerIcon({ cls }) → '<span class="burger">…three lines…</span>'
|
|
13
|
+
* Put it inside a button (for example an .iconbtn). The lines use currentColor; size with
|
|
14
|
+
* --burger-w, --burger-h and --burger-t (line thickness) on the icon or any parent.
|
|
15
|
+
*/
|
|
16
|
+
export const burgerIcon = ({ cls = '' } = {}) => `<span class="burger${cls ? ' ' + cls : ''}" aria-hidden="true"><i></i><i></i><i></i></span>`;
|
|
17
|
+
|
|
18
|
+
const linesOf = (btn) => [...(btn.querySelector('.burger') || btn).querySelectorAll(':scope > i')].slice(0, 3);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* burger(button, open, { duration: 0.45, words: { open: 'Open menu', close: 'Close menu' } })
|
|
22
|
+
* Morph the icon in button to ✕ (open = true) or back to ☰ (false); leave open out to toggle.
|
|
23
|
+
* Sets aria-expanded, and aria-label when words are given (or were given to bindBurger).
|
|
24
|
+
* Returns the GSAP timeline.
|
|
25
|
+
*/
|
|
26
|
+
export const burger = (btn, open, opts = {}) => {
|
|
27
|
+
btn = $$(btn)[0];
|
|
28
|
+
if (!btn) return g.timeline();
|
|
29
|
+
const st = btn.__burger || (btn.__burger = { open: btn.getAttribute('aria-expanded') === 'true', words: null, tl: null });
|
|
30
|
+
if (opts.words) st.words = { ...WORDS, ...opts.words };
|
|
31
|
+
if (open === undefined || open === null) open = !st.open;
|
|
32
|
+
open = !!open;
|
|
33
|
+
const duration = opts.duration ?? st.duration ?? 0.45;
|
|
34
|
+
st.open = open;
|
|
35
|
+
btn.setAttribute('aria-expanded', String(open));
|
|
36
|
+
if (st.words) btn.setAttribute('aria-label', open ? st.words.close : st.words.open);
|
|
37
|
+
btn.classList.toggle('is-open', open);
|
|
38
|
+
|
|
39
|
+
const [top, mid, bot] = linesOf(btn);
|
|
40
|
+
st.tl?.kill();
|
|
41
|
+
const tl = g.timeline();
|
|
42
|
+
st.tl = tl;
|
|
43
|
+
if (!top || !bot) return tl;
|
|
44
|
+
// how far the outer lines travel to reach the middle one
|
|
45
|
+
const gap = mid ? mid.offsetTop - top.offsetTop : (bot.offsetTop - top.offsetTop) / 2;
|
|
46
|
+
const outer = [top, bot];
|
|
47
|
+
if (RM() || !duration) {
|
|
48
|
+
g.set(top, { y: open ? gap : 0, rotation: open ? 45 : 0 });
|
|
49
|
+
g.set(bot, { y: open ? -gap : 0, rotation: open ? -45 : 0 });
|
|
50
|
+
if (mid) g.set(mid, { scaleX: open ? 0 : 1, opacity: open ? 0 : 1 });
|
|
51
|
+
return tl;
|
|
52
|
+
}
|
|
53
|
+
const a = duration * 0.4, b = duration * 0.6;
|
|
54
|
+
if (open) {
|
|
55
|
+
tl.to(top, { y: gap, rotation: 0, duration: a, ease: 'power2.in' }, 0)
|
|
56
|
+
.to(bot, { y: -gap, rotation: 0, duration: a, ease: 'power2.in' }, 0)
|
|
57
|
+
.to(top, { rotation: 45, duration: b, ease: 'back.out(2.2)' }, a)
|
|
58
|
+
.to(bot, { rotation: -45, duration: b, ease: 'back.out(2.2)' }, a);
|
|
59
|
+
if (mid) tl.to(mid, { scaleX: 0, opacity: 0, duration: a, ease: 'power2.in' }, 0);
|
|
60
|
+
} else {
|
|
61
|
+
tl.to(outer, { rotation: 0, duration: a, ease: 'power2.inOut' }, 0)
|
|
62
|
+
.to(top, { y: 0, duration: b, ease: 'back.out(2)' }, a)
|
|
63
|
+
.to(bot, { y: 0, duration: b, ease: 'back.out(2)' }, a);
|
|
64
|
+
if (mid) tl.to(mid, { scaleX: 1, opacity: 1, duration: b, ease: 'power3.out' }, a);
|
|
65
|
+
}
|
|
66
|
+
return tl;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* const menu = bindBurger(button, {
|
|
71
|
+
* onToggle(open, button) {}, // show / hide your menu here
|
|
72
|
+
* open: false, // start open?
|
|
73
|
+
* duration: 0.45,
|
|
74
|
+
* words: { open: 'Open menu', close: 'Close menu' }, // the button's label; false = leave it alone
|
|
75
|
+
* controls: 'main-menu', // id of the menu: sets aria-controls
|
|
76
|
+
* escape: true, // Escape closes it and puts focus back on the button
|
|
77
|
+
* })
|
|
78
|
+
* menu.open · menu.set(open) · menu.toggle() · menu.destroy()
|
|
79
|
+
*/
|
|
80
|
+
export const bindBurger = (btn, opts = {}) => {
|
|
81
|
+
btn = $$(btn)[0];
|
|
82
|
+
if (!btn) return null;
|
|
83
|
+
btn.__burgerApi?.destroy();
|
|
84
|
+
const o = { onToggle: null, open: false, duration: 0.45, words: WORDS, controls: '', escape: true, ...opts };
|
|
85
|
+
if (o.words === undefined || o.words === true) o.words = WORDS;
|
|
86
|
+
const ac = new AbortController(), on = (t, ev, fn, x) => t.addEventListener(ev, fn, { signal: ac.signal, ...x });
|
|
87
|
+
const label0 = btn.getAttribute('aria-label');
|
|
88
|
+
btn.__burger = { open: !!o.open, words: o.words ? { ...WORDS, ...o.words } : null, tl: null, duration: o.duration };
|
|
89
|
+
const added = !btn.querySelector('.burger');
|
|
90
|
+
if (added) btn.insertAdjacentHTML('afterbegin', burgerIcon());
|
|
91
|
+
if (o.controls) btn.setAttribute('aria-controls', o.controls);
|
|
92
|
+
burger(btn, !!o.open, { duration: 0 });
|
|
93
|
+
|
|
94
|
+
const api = {
|
|
95
|
+
el: btn,
|
|
96
|
+
get open() { return !!btn.__burger?.open; },
|
|
97
|
+
set(open, { silent = false } = {}) {
|
|
98
|
+
open = !!open;
|
|
99
|
+
if (open === api.open) return api;
|
|
100
|
+
burger(btn, open);
|
|
101
|
+
if (!silent) o.onToggle?.(open, btn);
|
|
102
|
+
return api;
|
|
103
|
+
},
|
|
104
|
+
toggle() { return api.set(!api.open); },
|
|
105
|
+
destroy() {
|
|
106
|
+
ac.abort(); btn.__burger?.tl?.kill();
|
|
107
|
+
g.set(linesOf(btn), { clearProps: 'all' });
|
|
108
|
+
if (added) btn.querySelector('.burger')?.remove();
|
|
109
|
+
btn.classList.remove('is-open');
|
|
110
|
+
if (o.words) { if (label0 === null) btn.removeAttribute('aria-label'); else btn.setAttribute('aria-label', label0); }
|
|
111
|
+
delete btn.__burger; delete btn.__burgerApi;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
on(btn, 'click', () => api.toggle());
|
|
115
|
+
if (o.escape) {
|
|
116
|
+
on(document, 'keydown', (e) => {
|
|
117
|
+
if (e.key !== 'Escape' || !api.open || e.defaultPrevented) return;
|
|
118
|
+
api.set(false); btn.focus();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
btn.__burgerApi = api;
|
|
122
|
+
return api;
|
|
123
|
+
};
|
package/src/charts.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* Data motion: meters, bars, rings, steps, switch knob */
|
|
2
|
+
import { g, D, RM, $$ } from './core.js';
|
|
3
|
+
|
|
4
|
+
export const meter = (bar, f, delay = 0.15) => g.fromTo(bar, { scaleX: 0 }, { scaleX: Math.max(0, Math.min(1, f)), duration: D(1), ease: 'expo.out', delay: D(delay), transformOrigin: '0 50%' });
|
|
5
|
+
|
|
6
|
+
export const growX = (els, { stagger = 0.05, delay = 0.2, duration = 0.9, to } = {}) => {
|
|
7
|
+
els = $$(els); if (!els.length) return;
|
|
8
|
+
return g.fromTo(els, { scaleX: 0 }, { scaleX: to ?? 1, duration: D(duration), ease: 'expo.out', stagger: D(stagger), delay: D(delay), transformOrigin: '0 50%', ...(to === undefined ? { clearProps: 'transform' } : {}) });
|
|
9
|
+
};
|
|
10
|
+
export const growY = (els, { stagger = 0.008, delay = 0.1, ease = 'back.out(2)', duration = 0.5 } = {}) => {
|
|
11
|
+
els = $$(els); if (!els.length) return;
|
|
12
|
+
return g.fromTo(els, { scaleY: 0 }, { scaleY: 1, duration: D(duration), ease, stagger: D(stagger), delay: D(delay), transformOrigin: '50% 100%', clearProps: 'transform' });
|
|
13
|
+
};
|
|
14
|
+
/** bars(els, [3,5,2], 5) grows each bar to value/max. Call again with { first:false } to morph. */
|
|
15
|
+
export const bars = (els, values, max, { first = true } = {}) => {
|
|
16
|
+
$$(els).forEach((e, i) => {
|
|
17
|
+
const f = (values[i] ?? 0) / (max || 1);
|
|
18
|
+
first ? g.fromTo(e, { scaleY: 0 }, { scaleY: f, duration: D(1), delay: D(0.15 + i * 0.04), ease: 'expo.out', transformOrigin: '50% 100%' })
|
|
19
|
+
: g.to(e, { scaleY: f, duration: D(0.75), delay: D(i * 0.02), ease: 'expo.inOut', transformOrigin: '50% 100%' });
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
/** ring(circle, 0.72) — circle needs data-len (its circumference) and stroke-dasharray. */
|
|
23
|
+
export const ring = (circle, f, { delay = 0.2, from = 0 } = {}) => {
|
|
24
|
+
if (!circle) return;
|
|
25
|
+
const len = +circle.getAttribute('data-len'); const st = { v: from };
|
|
26
|
+
if (RM()) { circle.setAttribute('stroke-dashoffset', len * (1 - f)); return; }
|
|
27
|
+
return g.to(st, { v: f, duration: 1.1, ease: 'expo.out', delay, onUpdate: () => circle.setAttribute('stroke-dashoffset', String(len * (1 - st.v))) });
|
|
28
|
+
};
|
|
29
|
+
/** steps(ol.steps, now, prev) — fills the bars up to step `now`, pops the new dot. */
|
|
30
|
+
export const steps = (root, now, prev) => {
|
|
31
|
+
$$('.steps__fill', root).forEach((e, n) => g.to(e, { scaleX: +(n < now), duration: D(prev === now ? 0.9 : 0.6), delay: D(prev === now ? 0.2 + n * 0.12 : 0), ease: 'expo.out' }));
|
|
32
|
+
if (prev !== now) { const dots = $$('.steps__dot', root); const d = dots[Math.min(now, dots.length - 1)]; d && g.fromTo(d, { scale: 0.5 }, { scale: 1, duration: D(0.6), ease: 'back.out(3)', clearProps: 'transform' }); }
|
|
33
|
+
};
|
|
34
|
+
export const switchKnob = (btn, on, animate = true) => {
|
|
35
|
+
const i = btn.querySelector('i'); const x = on ? (btn.offsetWidth ? btn.offsetWidth - i.offsetWidth - 6 : 18) : 0;
|
|
36
|
+
animate ? g.to(i, { x, duration: D(0.45), ease: 'back.out(2.2)' }) : g.set(i, { x });
|
|
37
|
+
};
|