@gecko-ui-kit/components 0.20.0 → 0.21.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/README.md +192 -0
- package/index.js +27 -0
- package/package.json +3 -3
- package/src/activity.js +218 -0
- package/src/beforeafter.js +141 -0
- package/src/bell.js +137 -0
- package/src/like.js +208 -0
- package/src/pay.js +162 -0
- package/src/pricing.js +189 -0
- package/src/radiocards.js +101 -0
- package/src/speeddial.js +128 -0
- package/src/subscribe.js +173 -0
- package/src/typing.js +93 -0
- package/style.css +331 -0
package/README.md
CHANGED
|
@@ -711,3 +711,195 @@ button.querySelector('svg').outerHTML = spinner({ size: '1.15em', tone: 'current
|
|
|
711
711
|
Options: `size` (28), `tone` (`accent ink muted good warn bad current`), `speed` (s per lap), `track`, `label`, `stack`,
|
|
712
712
|
`words: { loading }` (the hidden text when there is no label), `decorative`, `cls`. CSS: `--orb-c`, `--orb-track`,
|
|
713
713
|
`--orb-w`, `--orb-head`, `--orb-speed`. It has `role="status"`, so the label (or a hidden "Loading…") is read out.
|
|
714
|
+
|
|
715
|
+
## Radio cards
|
|
716
|
+
Pick one of a few choices drawn as cards: title, short description, a price on the right, an icon and a badge.
|
|
717
|
+
The picked card rings and tints, its round mark fills and a tick pops in with a little overshoot. They are real
|
|
718
|
+
radios in a `<fieldset>`, so arrow keys, Tab, forms and screen readers work like any radio group.
|
|
719
|
+
```js
|
|
720
|
+
import { radioCards } from '@gecko-ui-kit/components'
|
|
721
|
+
|
|
722
|
+
const delivery = radioCards(document.querySelector('#delivery'), {
|
|
723
|
+
label: 'Delivery', name: 'delivery',
|
|
724
|
+
options: [
|
|
725
|
+
{ value: 'standard', title: 'Standard', desc: '3–5 working days', price: 'Free' },
|
|
726
|
+
{ value: 'express', title: 'Express', desc: 'Arrives tomorrow', price: '$9', icon: 'zap', badge: 'Popular' },
|
|
727
|
+
{ value: 'pickup', title: 'Pick up in store', desc: 'Ready in 2 hours', price: 'Free', disabled: true },
|
|
728
|
+
],
|
|
729
|
+
value: 'standard',
|
|
730
|
+
layout: 'list', // or 'grid' (side by side, min: 160 = narrowest card in px)
|
|
731
|
+
onChange: (value, option) => updateTotal(option),
|
|
732
|
+
})
|
|
733
|
+
delivery.value; delivery.set('express'); delivery.focus(); delivery.destroy()
|
|
734
|
+
```
|
|
735
|
+
Also `hideLabel`, `required`, `disabled`, `words: { group }` (the name read out when there is no label). `--rc-c` sets the picked colour.
|
|
736
|
+
|
|
737
|
+
## Pricing toggle
|
|
738
|
+
Plan cards under a billing-period switch. Picking another period slides the switch’s thumb and every price rolls
|
|
739
|
+
digit by digit to its new number (`odometer` from motion; `motion: 'count'` counts instead), the first period’s
|
|
740
|
+
price shows crossed out, the note under the price slides to its new words and the period’s badge pops.
|
|
741
|
+
Needs `@gecko-ui-kit/motion/motion.css` for the rolling digits.
|
|
742
|
+
```js
|
|
743
|
+
import { pricingToggle } from '@gecko-ui-kit/components'
|
|
744
|
+
|
|
745
|
+
const prices = pricingToggle(document.querySelector('#prices'), {
|
|
746
|
+
periods: [
|
|
747
|
+
{ id: 'month', label: 'Monthly', per: '/mo' },
|
|
748
|
+
{ id: 'year', label: 'Yearly', per: '/mo', badge: 'Save 20%' },
|
|
749
|
+
],
|
|
750
|
+
plans: [
|
|
751
|
+
{ id: 'starter', name: 'Starter', price: { month: 12, year: 9 }, note: { month: 'Billed monthly', year: '$108 billed yearly' },
|
|
752
|
+
features: ['1 location', 'Email support'], action: 'Choose Starter' },
|
|
753
|
+
{ id: 'pro', name: 'Pro', price: { month: 29, year: 23 }, featured: true, tag: 'Popular', action: 'Start free trial' },
|
|
754
|
+
],
|
|
755
|
+
format: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }, // or (value, periodId, plan) => text
|
|
756
|
+
strike: true,
|
|
757
|
+
words: { label: 'Billing period', showing: (period) => `Showing ${period} prices`, was: 'Was' },
|
|
758
|
+
onSelect: (plan, period) => startCheckout(plan.id, period),
|
|
759
|
+
})
|
|
760
|
+
prices.period; prices.set('year'); prices.destroy()
|
|
761
|
+
```
|
|
762
|
+
A price can be text (`'Custom'`); a note can be `(periodId, plan) => text`. `--pr-min` is the narrowest plan card.
|
|
763
|
+
|
|
764
|
+
## Email subscribe
|
|
765
|
+
An email field and a button for a newsletter or waitlist. The label floats up, a tick draws once the address looks
|
|
766
|
+
complete, a wrong one turns red and shakes, a good one makes the button busy while `onSubmit` runs, then the button
|
|
767
|
+
grows across the row into the thank-you message. Status changes are read out by a polite live region.
|
|
768
|
+
```js
|
|
769
|
+
import { subscribeForm } from '@gecko-ui-kit/components'
|
|
770
|
+
|
|
771
|
+
const signup = subscribeForm(document.querySelector('#signup'), {
|
|
772
|
+
icon: 'mail', // optional icon inside the field
|
|
773
|
+
layout: 'row', // or 'stack' (button under the field)
|
|
774
|
+
validate: (email) => '', // your own extra check: return a message to refuse it
|
|
775
|
+
resetAfter: 0, // ms until an empty field comes back (0 = stay thanked)
|
|
776
|
+
words: { label: 'Email address', button: 'Subscribe', hint: 'One email a month. No spam.', done: 'You’re subscribed!' },
|
|
777
|
+
onSubmit: async (email) => { // reject / throw to show the message in red
|
|
778
|
+
const res = await fetch('/api/subscribe', { method: 'POST', body: JSON.stringify({ email }) })
|
|
779
|
+
if (!res.ok) throw new Error(await res.text())
|
|
780
|
+
},
|
|
781
|
+
})
|
|
782
|
+
signup.value; signup.state; signup.setError('…'); signup.reset(); signup.destroy()
|
|
783
|
+
```
|
|
784
|
+
All words: `label, button, hint, missing, bad, busy, done, doneText, failed`.
|
|
785
|
+
|
|
786
|
+
## Activity timeline
|
|
787
|
+
Who did what, and when, newest at the top. When it first shows, the line draws down from mark to mark and each
|
|
788
|
+
event rises in after it; `add()` pushes the others down and pops the new event in at the top. Times read
|
|
789
|
+
“5 min ago” in any language and keep themselves up to date. New events are announced politely.
|
|
790
|
+
```js
|
|
791
|
+
import { activity } from '@gecko-ui-kit/components'
|
|
792
|
+
|
|
793
|
+
const feed = activity(document.querySelector('#activity'), {
|
|
794
|
+
items: [
|
|
795
|
+
{ id: 'e1', who: { name: 'Pim Wong', ini: 'PW', tone: 'indigo' }, what: 'approved the refund', detail: '฿180 back to the card',
|
|
796
|
+
icon: 'check', tone: 'good', time: '2026-12-04T09:41' },
|
|
797
|
+
{ id: 'e2', title: 'Order placed', detail: 'Flat white × 2', time: '2026-12-04T09:12' }, // bold title, no person
|
|
798
|
+
],
|
|
799
|
+
marks: 'auto', // 'icon' | 'avatar' | 'dot'
|
|
800
|
+
max: 0, latest: true, intro: 'view', locale: 'th',
|
|
801
|
+
})
|
|
802
|
+
feed.add({ who: 'Online shop', what: 'received order #1043', icon: 'box', time: new Date() })
|
|
803
|
+
// feed.remove(id) · feed.set(items) · feed.play() · feed.items · feed.destroy()
|
|
804
|
+
```
|
|
805
|
+
Options: `format(date)` (your own time text), `refresh` (seconds, 30), `label`, `words: { label, now, added, more }`.
|
|
806
|
+
CSS: `--act-mark`, `--act-gap`, `--act-line`, `--act-bg`.
|
|
807
|
+
|
|
808
|
+
## Typing indicator
|
|
809
|
+
Three dots that bounce one after another in a chat bubble, with optional “Pim is typing…” text. `show()` pops it
|
|
810
|
+
up from its tail corner, `hide()` shrinks it away and the row closes up. The dots bounce with CSS; a polite
|
|
811
|
+
`role="status"` says the text once. With reduced motion the dots fade in turn and show / hide is a fade.
|
|
812
|
+
```js
|
|
813
|
+
import { typing } from '@gecko-ui-kit/components'
|
|
814
|
+
|
|
815
|
+
const dots = typing(document.querySelector('#chat-typing'), { names: 'Pim' })
|
|
816
|
+
dots.show() // or dots.show(['Pim', 'Mali']) → “Pim and Mali are typing…”
|
|
817
|
+
dots.hide()
|
|
818
|
+
```
|
|
819
|
+
Options: `text`, `bubble`, `size` (`sm` / `lg`), `tone` (`muted` / `accent` / `ink`), `collapse`, `visible`,
|
|
820
|
+
`words: { anon, one, two, many }`. CSS: `--typing-c`, `--typing-bg`, `--typing-dot`, `--typing-speed`.
|
|
821
|
+
|
|
822
|
+
## Before / after
|
|
823
|
+
Two pictures (or any two pieces of content) with a divider you drag to wipe between them. Mouse, touch and pen
|
|
824
|
+
drag (a vertical swipe still scrolls); the handle is an ARIA slider (← →, Shift, Page Up / Down, Home / End).
|
|
825
|
+
```js
|
|
826
|
+
import { beforeAfter } from '@gecko-ui-kit/components'
|
|
827
|
+
|
|
828
|
+
const ba = beforeAfter(document.querySelector('#shop'), {
|
|
829
|
+
before: '<img src="before.jpg" alt="The shop before">', // or leave out and put two children in #shop
|
|
830
|
+
after: '<img src="after.jpg" alt="The shop after">',
|
|
831
|
+
start: 50, hover: false, hint: true, ratio: '4/3',
|
|
832
|
+
onChange: (v) => console.log(v),
|
|
833
|
+
})
|
|
834
|
+
ba.set(30) // ba.value · ba.destroy()
|
|
835
|
+
```
|
|
836
|
+
Options: `labels`, `step`, `words: { before, after, label, value }`. CSS: `--ba-line`, `--ba-knob`.
|
|
837
|
+
|
|
838
|
+
## Like & bookmark
|
|
839
|
+
On / off icon buttons that celebrate when they turn on: the heart (or star) pops with a ring and a burst of dots,
|
|
840
|
+
the bookmark fills from the top, dips and throws a few sparks. An optional count rolls up, or down when the like is
|
|
841
|
+
taken back. Real `<button aria-pressed>`; `bindAll(root)` wires every `.lk` button inside root.
|
|
842
|
+
```js
|
|
843
|
+
import { likeBtn, likeButton, bindAll } from '@gecko-ui-kit/components'
|
|
844
|
+
|
|
845
|
+
bar.innerHTML = likeBtn({ kind: 'heart', count: 128 }) + likeBtn({ kind: 'bookmark' }) // bookmark: Save → Saved
|
|
846
|
+
bindAll(bar)
|
|
847
|
+
|
|
848
|
+
const like = likeButton(bar.querySelector('.lk--heart'), {
|
|
849
|
+
onChange: (on, count) => api.react(postId, on), // return the promise: if it fails, the button goes back and shakes
|
|
850
|
+
})
|
|
851
|
+
like.pressed; like.count; like.set(true); like.setCount(200); like.destroy()
|
|
852
|
+
```
|
|
853
|
+
Options: `kind` (`heart` `star` `bookmark`), `pressed`, `count` (leave out for none), `label`, `onLabel`, `iconOnly`,
|
|
854
|
+
`size` (`sm` `lg`), `tone`, `format`, `words: { like, star, save, saved, withCount }`. CSS: `--lk-c`, `--lk-c2`, `--lk-s`.
|
|
855
|
+
|
|
856
|
+
## Notification bell
|
|
857
|
+
A `role="switch"` for notifications: turning it on rings the bell (the clapper a beat behind, two little sound
|
|
858
|
+
waves), turning it off draws a slash across it. The “On / Off” line under the label comes from `words`.
|
|
859
|
+
```js
|
|
860
|
+
import { bellBtn, bellSwitch } from '@gecko-ui-kit/components'
|
|
861
|
+
|
|
862
|
+
box.innerHTML = bellBtn({ label: 'Booking alerts', on: true }) // bindAll(box) wires it too
|
|
863
|
+
const bell = bellSwitch(box.querySelector('.nbell'), {
|
|
864
|
+
words: { on: 'เปิดอยู่', off: 'ปิดอยู่' },
|
|
865
|
+
onChange: (on) => saveSetting('booking-alerts', on), // a failed promise switches it back
|
|
866
|
+
})
|
|
867
|
+
bell.ring() // ring again when something new arrives
|
|
868
|
+
```
|
|
869
|
+
Options: `on`, `label`, `iconOnly`, `tone`, `words: { label, on, off }`. CSS: `--nb-c`, `--nb-bg`.
|
|
870
|
+
|
|
871
|
+
## Pay button
|
|
872
|
+
The busy-state button for checkout, built on `.btn`: a card swipes through a little reader slot, “Processing”
|
|
873
|
+
slides in, then the button turns green and “Paid” springs in with a drawn tick — or turns red, shakes and offers
|
|
874
|
+
“Try again”. A polite live region reads each step; while busy it is `aria-busy` / `aria-disabled` (the focus stays).
|
|
875
|
+
```js
|
|
876
|
+
import { payBtn, payButton } from '@gecko-ui-kit/components'
|
|
877
|
+
|
|
878
|
+
box.innerHTML = payBtn({ label: 'Pay ฿700', variant: 'dark', block: true })
|
|
879
|
+
const pay = payButton(box.querySelector('.pay'), {
|
|
880
|
+
onPay: async () => { const r = await fetch('/api/checkout', { method: 'POST' }); if (!r.ok) throw new Error('Declined'); return r.json() },
|
|
881
|
+
back: 3, // seconds before it returns to the start after paying (0 = stays "Paid")
|
|
882
|
+
minBusy: 1.4, // the shortest busy time, so the swipe is seen
|
|
883
|
+
onDone: (receipt) => showReceipt(receipt),
|
|
884
|
+
})
|
|
885
|
+
pay.state; pay.pay(); pay.reset(); pay.setLabel('Pay ฿850')
|
|
886
|
+
```
|
|
887
|
+
Options: `card` (the swipe), `variant`, `size`, `block`, `icon`, `words: { label, busy, done, retry, sayBusy, sayDone, sayFail(error) }`,
|
|
888
|
+
`onFail(error, pay)`. CSS: `--pay-card`, `.pay.is-done`, `.pay.is-failed`.
|
|
889
|
+
|
|
890
|
+
## Speed dial
|
|
891
|
+
A round floating + button that fans out a few labelled actions, nearest first; the + turns into an ×. Escape, a
|
|
892
|
+
click outside or tabbing away closes it; opened from the keyboard the focus goes to the nearest action and the arrow
|
|
893
|
+
keys walk along them. `aria-expanded` + `aria-controls`; the closed list is `hidden`.
|
|
894
|
+
```js
|
|
895
|
+
import { speedDial } from '@gecko-ui-kit/components'
|
|
896
|
+
|
|
897
|
+
const dial = speedDial(document.querySelector('#create'), {
|
|
898
|
+
actions: [{ id: 'booking', label: 'New booking', icon: 'calendar' }, { id: 'photo', label: 'Photo', icon: 'image' }],
|
|
899
|
+
direction: 'up', side: 'right', // 'down' for a button near the top, 'left' for the left edge
|
|
900
|
+
fixed: false, // true = pinned to the screen corner (--sd-x / --sd-y)
|
|
901
|
+
onSelect: (action) => openEditor(action.id),
|
|
902
|
+
})
|
|
903
|
+
dial.open({ focus: true }); dial.close(); dial.setActions(list); dial.destroy()
|
|
904
|
+
```
|
|
905
|
+
Options: `labels` (false = icons only), `icon` (`'plus'`), `words: { label, actions }`, `onToggle(open, dial)`. CSS: `--sd-c`.
|
package/index.js
CHANGED
|
@@ -196,3 +196,30 @@ export { leaderboard } from './src/leaderboard.js';
|
|
|
196
196
|
/** Code field (one-time code / PIN). See src/otp.js. */
|
|
197
197
|
export { otp, bindOtp, otpState, otpClear, otpValue } from './src/otp.js';
|
|
198
198
|
import { bindOtp as _bindOtp } from './src/otp.js';
|
|
199
|
+
/** Radio cards: a radio group drawn as cards (title, description, price, icon, badge); the picked one rings and its tick pops in; arrow keys like native radios. See src/radiocards.js. */
|
|
200
|
+
export { radioCards } from './src/radiocards.js';
|
|
201
|
+
/** Pricing toggle: plan cards under a billing-period switch; prices roll (odometer) or count to the new period, old price crossed out, “Save 20%” badge. See src/pricing.js. */
|
|
202
|
+
export { pricingToggle } from './src/pricing.js';
|
|
203
|
+
/** Email subscribe: floating-label email field + button; checks as you type, shakes when wrong, busy spinner, then the button grows into the thank-you message. See src/subscribe.js. */
|
|
204
|
+
export { subscribeForm } from './src/subscribe.js';
|
|
205
|
+
|
|
206
|
+
/** Activity timeline: events on a line that draws down, rows rise in; add() pushes a new one in at the top. See src/activity.js. */
|
|
207
|
+
export { activity } from './src/activity.js';
|
|
208
|
+
|
|
209
|
+
/** Typing indicator: three bouncing dots in a bubble with optional “Name is typing…”, soft pop in and out. See src/typing.js. */
|
|
210
|
+
export { typing } from './src/typing.js';
|
|
211
|
+
|
|
212
|
+
/** Before / after: two pictures with a divider you drag (or move with the keys) to wipe between them. See src/beforeafter.js. */
|
|
213
|
+
export { beforeAfter } from './src/beforeafter.js';
|
|
214
|
+
/** Like & bookmark: an aria-pressed icon button (heart, star or bookmark) that pops and bursts when it turns on, with a rolling count; bindAll wires .lk buttons. See src/like.js. */
|
|
215
|
+
export { likeBtn, likeButton, bindLikes } from './src/like.js';
|
|
216
|
+
/** Notification bell: a role="switch" that rings the bell when turned on and draws a slash across it when off. See src/bell.js. */
|
|
217
|
+
export { bellBtn, bellSwitch, bindBells } from './src/bell.js';
|
|
218
|
+
/** Pay button: the busy-state button for checkout — a card swipes through, "Processing", then "Paid" with a tick (or "Try again"), announced. See src/pay.js. */
|
|
219
|
+
export { payBtn, payButton } from './src/pay.js';
|
|
220
|
+
/** Speed dial: a floating + button that fans out labelled actions (aria-expanded, Escape / outside click, arrow keys). See src/speeddial.js. */
|
|
221
|
+
export { speedDial } from './src/speeddial.js';
|
|
222
|
+
import { bindLikes as _bindLikes } from './src/like.js';
|
|
223
|
+
import { bindBells as _bindBells } from './src/bell.js';
|
|
224
|
+
enhance(_bindLikes);
|
|
225
|
+
enhance(_bindBells);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gecko-ui-kit/components",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Buttons, inputs, password strength, sign in / sign up, combobox, tags input, range slider, file drop, segmented, switch, tabs, pagination, breadcrumbs, tags, avatars, cards, tables, data grid, virtual list, tree view, calendar, heatmap, leaderboard, line, donut and gauge charts, code field, sliders, colour swatches, meters, rings, steps, wizard, skeleton, spinner, alerts.",
|
|
3
|
+
"version": "0.21.0",
|
|
4
|
+
"description": "Buttons, like & bookmark, notification bell, pay button, speed dial, radio cards, pricing toggle, email subscribe, activity timeline, before / after, typing indicator, inputs, password strength, sign in / sign up, combobox, tags input, range slider, file drop, segmented, switch, tabs, pagination, breadcrumbs, tags, avatars, cards, tables, data grid, virtual list, tree view, calendar, heatmap, leaderboard, line, donut and gauge charts, code field, sliders, colour swatches, meters, rings, steps, wizard, skeleton, spinner, alerts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vanilla-js",
|
|
7
7
|
"ui",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@gecko-ui-kit/icons": "^0.3.0",
|
|
36
|
-
"@gecko-ui-kit/motion": "^0.
|
|
36
|
+
"@gecko-ui-kit/motion": "^0.9.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"gsap": "^3.12.0"
|
package/src/activity.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* Activity timeline: a vertical list of things that happened — who did what, and when — newest at
|
|
2
|
+
the top. Each event has a round mark on a thin line: an icon in a tinted circle, the person's
|
|
3
|
+
avatar, or a small dot. How it moves: when the list first shows (by default when it scrolls into
|
|
4
|
+
view) the line draws down from mark to mark and each event rises in just after the line reaches
|
|
5
|
+
it. add() puts a new event at the top: the others slide down to make room (measured before and
|
|
6
|
+
after, then glided with GSAP), the new one pops in and its line grows down to the next mark.
|
|
7
|
+
The newest event's mark wears a soft halo. Times read “5 min ago” and keep themselves up to date
|
|
8
|
+
(Intl.RelativeTimeFormat, any language), or write your own with format(). New events are read
|
|
9
|
+
out politely. With reduced motion everything is simply there, with no movement. */
|
|
10
|
+
import * as M from '@gecko-ui-kit/motion';
|
|
11
|
+
import { icon } from '@gecko-ui-kit/icons';
|
|
12
|
+
import { esc, av } from '../index.js';
|
|
13
|
+
|
|
14
|
+
const { g, RM, $$ } = M;
|
|
15
|
+
const WORDS = {
|
|
16
|
+
label: 'Activity',
|
|
17
|
+
now: 'Just now',
|
|
18
|
+
added: (text) => `New: ${text}`, // read out after add()
|
|
19
|
+
more: (n) => `and ${n} more`, // when add() brings several at once
|
|
20
|
+
};
|
|
21
|
+
const TONES = ['accent', 'good', 'warn', 'bad', 'plain', 'indigo', 'teal', 'rose', 'amber', 'violet', 'green', 'slate', 'sky'];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* const feed = activity(el, {
|
|
25
|
+
* items: [{
|
|
26
|
+
* id, time, // Date | ms | ISO string (default: now)
|
|
27
|
+
* who: 'Pim' | { name, ini, tone }, // shown in bold before the text; an object also gives an avatar
|
|
28
|
+
* what: 'approved the order', // plain text
|
|
29
|
+
* title: 'Delivered', // bold text instead of the name (for status events with no person)
|
|
30
|
+
* detail: 'Order #1042 · ฿450', // optional second line
|
|
31
|
+
* icon: 'check', tone: 'good', // the mark: an icon in a tinted circle (tone: accent good warn bad plain indigo teal…)
|
|
32
|
+
* html, // trusted markup instead of who + what
|
|
33
|
+
* }],
|
|
34
|
+
* marks: 'auto' | 'icon' | 'avatar' | 'dot', // auto: icon if it has one, else the avatar, else a dot
|
|
35
|
+
* latest: true, // halo on the newest mark
|
|
36
|
+
* max: 0, // keep at most this many (0 = all); the oldest fade out at the bottom
|
|
37
|
+
* intro: 'view' | true | false, // draw the line + rise in: when it scrolls into view, at once, or not at all
|
|
38
|
+
* locale: undefined, // for the relative times ('th', 'en-GB'…)
|
|
39
|
+
* format: (date) => string, // your own time text instead
|
|
40
|
+
* refresh: 30, // seconds between time updates (0 = never)
|
|
41
|
+
* label: '', // name for screen readers (default words.label)
|
|
42
|
+
* words: { label, now, added, more },
|
|
43
|
+
* })
|
|
44
|
+
* feed.add(item | items) // at the top, with a smooth push-down
|
|
45
|
+
* feed.remove(id) · feed.set(items) · feed.play() (draw it again) · feed.items · feed.root · feed.destroy()
|
|
46
|
+
*/
|
|
47
|
+
export const activity = (el, opts = {}) => {
|
|
48
|
+
el = $$(el)[0];
|
|
49
|
+
if (!el) return null;
|
|
50
|
+
const o = { items: [], marks: 'auto', latest: true, max: 0, intro: 'view', locale: undefined, format: null, refresh: 30, label: '', words: null, ...opts };
|
|
51
|
+
const W = { ...WORDS, ...o.words };
|
|
52
|
+
const max = +o.max > 0 ? Math.round(+o.max) : Infinity;
|
|
53
|
+
let seq = 0, list = [], dead = false, io = null, timer = 0;
|
|
54
|
+
|
|
55
|
+
el.innerHTML = `<div class="act${o.latest ? ' act--latest' : ''}"><ol class="act__list" role="list" aria-label="${esc(o.label || W.label)}"></ol>`
|
|
56
|
+
+ '<span class="act__sr" role="status" aria-live="polite"></span></div>';
|
|
57
|
+
const root = el.firstElementChild, ol = root.querySelector('.act__list'), live = root.querySelector('.act__sr');
|
|
58
|
+
const say = (t) => { live.textContent = ''; if (t) requestAnimationFrame(() => { if (!dead) live.textContent = t; }); };
|
|
59
|
+
|
|
60
|
+
/* ---------- time ---------- */
|
|
61
|
+
const toMs = (t) => (t == null ? Date.now() : t instanceof Date ? t.getTime() : typeof t === 'number' ? t : (Date.parse(t) || Date.now()));
|
|
62
|
+
const when = (ms) => {
|
|
63
|
+
if (o.format) return String(o.format(new Date(ms)));
|
|
64
|
+
const s = Math.max(0, (Date.now() - ms) / 1000), L = o.locale;
|
|
65
|
+
const rtf = new Intl.RelativeTimeFormat(L, { numeric: 'auto', style: 'short' });
|
|
66
|
+
if (s < 45) return W.now;
|
|
67
|
+
if (s < 3600) return rtf.format(-Math.max(1, Math.round(s / 60)), 'minute');
|
|
68
|
+
if (s < 86400) return rtf.format(-Math.round(s / 3600), 'hour');
|
|
69
|
+
if (s < 86400 * 7) return rtf.format(-Math.round(s / 86400), 'day');
|
|
70
|
+
return new Intl.DateTimeFormat(L, { day: 'numeric', month: 'short' }).format(ms);
|
|
71
|
+
};
|
|
72
|
+
const stamp = (it, li) => {
|
|
73
|
+
const t = li.querySelector('.act__time'), d = new Date(it.ms);
|
|
74
|
+
t.textContent = when(it.ms); t.dateTime = d.toISOString();
|
|
75
|
+
t.title = new Intl.DateTimeFormat(o.locale, { dateStyle: 'medium', timeStyle: 'short' }).format(d);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/* ---------- rows ---------- */
|
|
79
|
+
const norm = (it) => ({ ...it, id: it.id != null ? String(it.id) : `a${++seq}`, ms: toMs(it.time) });
|
|
80
|
+
const pub = (it) => { const { ms, li, ...rest } = it; return rest; };
|
|
81
|
+
const tone = (t) => (TONES.includes(t) ? t : 'accent');
|
|
82
|
+
const whoName = (it) => (it.title != null ? String(it.title) : it.who == null ? '' : typeof it.who === 'string' ? it.who : it.who.name || '');
|
|
83
|
+
const plain = (it) => {
|
|
84
|
+
if (it.html != null) { const d = document.createElement('div'); d.innerHTML = it.html; return d.textContent.trim(); }
|
|
85
|
+
return `${whoName(it)} ${it.what ?? ''}`.trim();
|
|
86
|
+
};
|
|
87
|
+
const mark = (it) => {
|
|
88
|
+
const kind = o.marks === 'auto' ? (it.icon ? 'icon' : it.who && typeof it.who === 'object' ? 'avatar' : 'dot') : o.marks;
|
|
89
|
+
if (kind === 'avatar' && it.who && typeof it.who === 'object') return `<span class="act__mark act__mark--av">${av(it.who, 'sm')}</span>`;
|
|
90
|
+
if (kind === 'icon' || (kind === 'avatar' && it.icon)) return `<span class="act__mark act__tone--${tone(it.tone)}">${icon(it.icon || 'check')}</span>`;
|
|
91
|
+
return `<span class="act__mark act__mark--dot act__tone--${tone(it.tone)}"></span>`;
|
|
92
|
+
};
|
|
93
|
+
const make = (it) => {
|
|
94
|
+
const li = document.createElement('li');
|
|
95
|
+
li.className = 'act__row'; li.dataset.id = it.id;
|
|
96
|
+
const text = it.html != null ? it.html : `${whoName(it) ? `<b>${esc(whoName(it))}</b> ` : ''}${esc(it.what ?? '')}`;
|
|
97
|
+
li.innerHTML = `<span class="act__rail" aria-hidden="true">${mark(it)}<i class="act__seg"></i></span>`
|
|
98
|
+
+ `<div class="act__body"><div class="act__head"><p class="act__text">${text}</p><time class="act__time"></time></div>`
|
|
99
|
+
+ `${it.detail ? `<p class="act__detail">${esc(it.detail)}</p>` : ''}</div>`;
|
|
100
|
+
stamp(it, li);
|
|
101
|
+
it.li = li;
|
|
102
|
+
return li;
|
|
103
|
+
};
|
|
104
|
+
const markLatest = () => list.forEach((it, i) => it.li.classList.toggle('is-latest', i === 0));
|
|
105
|
+
const parts = (li) => ({ seg: li.querySelector('.act__seg'), mk: li.querySelector('.act__mark'), body: li.querySelector('.act__body') });
|
|
106
|
+
|
|
107
|
+
/* ---------- the intro: line draws down, events rise in after it ---------- */
|
|
108
|
+
let introTl = null;
|
|
109
|
+
const play = () => {
|
|
110
|
+
introTl?.kill();
|
|
111
|
+
const rows = list.map((it) => it.li);
|
|
112
|
+
g.killTweensOf(rows.flatMap((li) => Object.values(parts(li))));
|
|
113
|
+
if (RM() || !rows.length) { rows.forEach((li) => g.set(Object.values(parts(li)), { clearProps: 'all' })); return null; }
|
|
114
|
+
const tl = g.timeline({ onComplete: () => rows.forEach((li) => g.set(Object.values(parts(li)), { clearProps: 'all' })) });
|
|
115
|
+
rows.forEach((li, i) => {
|
|
116
|
+
const { seg, mk, body } = parts(li), at = i * 0.16;
|
|
117
|
+
tl.fromTo(mk, { scale: 0, opacity: 0 }, { scale: 1, opacity: 1, duration: 0.45, ease: 'back.out(2.6)' }, at)
|
|
118
|
+
.fromTo(body, { opacity: 0, y: 10, x: -6 }, { opacity: 1, y: 0, x: 0, duration: 0.5, ease: 'power3.out' }, at + 0.04)
|
|
119
|
+
.fromTo(seg, { scaleY: 0 }, { scaleY: 1, duration: 0.2, ease: 'none' }, at + 0.06);
|
|
120
|
+
});
|
|
121
|
+
introTl = tl;
|
|
122
|
+
return tl;
|
|
123
|
+
};
|
|
124
|
+
const hideAll = () => list.forEach((it) => { const { seg, mk, body } = parts(it.li); g.set(mk, { scale: 0, opacity: 0 }); g.set(body, { opacity: 0 }); g.set(seg, { scaleY: 0 }); });
|
|
125
|
+
|
|
126
|
+
/* ---------- trim to max ---------- */
|
|
127
|
+
const trim = (animate) => {
|
|
128
|
+
while (list.length > max) {
|
|
129
|
+
const it = list.pop(), li = it.li;
|
|
130
|
+
g.killTweensOf([li, ...Object.values(parts(li))]);
|
|
131
|
+
if (!animate) { li.remove(); continue; }
|
|
132
|
+
li.classList.add('is-leaving'); li.setAttribute('aria-hidden', 'true');
|
|
133
|
+
g.to(li, { opacity: 0, y: 8, height: 0, paddingBottom: 0, duration: 0.4, ease: 'power2.inOut', onComplete: () => li.remove() });
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/* ---------- add at the top ---------- */
|
|
138
|
+
const add = (items) => {
|
|
139
|
+
if (dead) return api;
|
|
140
|
+
const fresh = (Array.isArray(items) ? items : [items]).filter(Boolean).map(norm).sort((a, b) => b.ms - a.ms);
|
|
141
|
+
if (!fresh.length) return api;
|
|
142
|
+
introTl?.progress(1);
|
|
143
|
+
const animate = !RM();
|
|
144
|
+
const before = new Map(list.map((it) => [it.id, it.li.getBoundingClientRect().top]));
|
|
145
|
+
const h0 = ol.offsetHeight;
|
|
146
|
+
// the same id again replaces the old row
|
|
147
|
+
fresh.forEach((it) => { const k = list.findIndex((x) => x.id === it.id); if (k > -1) { list[k].li.remove(); list.splice(k, 1); } });
|
|
148
|
+
for (let i = fresh.length - 1; i >= 0; i--) { list.unshift(fresh[i]); ol.prepend(make(fresh[i])); }
|
|
149
|
+
markLatest();
|
|
150
|
+
trim(animate);
|
|
151
|
+
say(`${W.added(plain(fresh[0]))}${fresh.length > 1 ? ` ${W.more(fresh.length - 1)}` : ''}`);
|
|
152
|
+
if (!animate) return api;
|
|
153
|
+
const h1 = ol.offsetHeight;
|
|
154
|
+
if (h1 !== h0) g.fromTo(ol, { height: h0 }, { height: h1, duration: 0.55, ease: 'power3.inOut', clearProps: 'height' });
|
|
155
|
+
// the rows that were there glide down
|
|
156
|
+
list.forEach((it) => {
|
|
157
|
+
if (!before.has(it.id)) return;
|
|
158
|
+
const dy = before.get(it.id) - it.li.getBoundingClientRect().top;
|
|
159
|
+
if (Math.abs(dy) > 0.5) g.fromTo(it.li, { y: dy }, { y: 0, duration: 0.6, ease: 'power3.inOut', clearProps: 'transform' });
|
|
160
|
+
});
|
|
161
|
+
// the new ones pop in, their line grows down to the next mark
|
|
162
|
+
fresh.forEach((it, i) => {
|
|
163
|
+
if (!it.li.isConnected) return;
|
|
164
|
+
const { seg, mk, body } = parts(it.li), at = 0.18 + i * 0.1;
|
|
165
|
+
g.fromTo(mk, { scale: 0 }, { scale: 1, duration: 0.55, delay: at, ease: 'back.out(2.8)', clearProps: 'transform' });
|
|
166
|
+
g.fromTo(body, { opacity: 0, x: -10 }, { opacity: 1, x: 0, duration: 0.5, delay: at + 0.05, ease: 'power3.out', clearProps: 'opacity,transform' });
|
|
167
|
+
g.fromTo(seg, { scaleY: 0 }, { scaleY: 1, duration: 0.45, delay: at + 0.2, ease: 'power2.out', clearProps: 'transform' });
|
|
168
|
+
});
|
|
169
|
+
return api;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const set = (items) => {
|
|
173
|
+
introTl?.kill();
|
|
174
|
+
list.forEach((it) => g.killTweensOf([it.li, ...Object.values(parts(it.li))]));
|
|
175
|
+
ol.innerHTML = '';
|
|
176
|
+
list = (items || []).filter(Boolean).map(norm).sort((a, b) => b.ms - a.ms);
|
|
177
|
+
list.forEach((it) => ol.append(make(it)));
|
|
178
|
+
markLatest();
|
|
179
|
+
trim(false);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/* ---------- start ---------- */
|
|
183
|
+
set(o.items);
|
|
184
|
+
if (o.intro && !RM() && list.length) {
|
|
185
|
+
if (o.intro === 'view' && typeof IntersectionObserver === 'function') {
|
|
186
|
+
hideAll();
|
|
187
|
+
io = new IntersectionObserver((ents) => { if (ents.some((e) => e.isIntersecting)) { io.disconnect(); io = null; play(); } }, { threshold: 0.2 });
|
|
188
|
+
io.observe(root);
|
|
189
|
+
} else play();
|
|
190
|
+
}
|
|
191
|
+
if (+o.refresh > 0) timer = setInterval(() => list.forEach((it) => stamp(it, it.li)), +o.refresh * 1000);
|
|
192
|
+
|
|
193
|
+
const api = {
|
|
194
|
+
root,
|
|
195
|
+
/** The events, newest first. */
|
|
196
|
+
get items() { return list.map(pub); },
|
|
197
|
+
add,
|
|
198
|
+
remove(id) {
|
|
199
|
+
const k = list.findIndex((x) => x.id === String(id));
|
|
200
|
+
if (k < 0) return api;
|
|
201
|
+
const [it] = list.splice(k, 1), li = it.li;
|
|
202
|
+
markLatest();
|
|
203
|
+
if (RM()) { li.remove(); return api; }
|
|
204
|
+
g.killTweensOf([li, ...Object.values(parts(li))]);
|
|
205
|
+
li.setAttribute('aria-hidden', 'true');
|
|
206
|
+
g.to(li, { opacity: 0, x: -12, height: 0, paddingBottom: 0, duration: 0.4, ease: 'power2.inOut', onComplete: () => li.remove() });
|
|
207
|
+
return api;
|
|
208
|
+
},
|
|
209
|
+
set(items) { set(items); return api; },
|
|
210
|
+
play() { io?.disconnect(); io = null; play(); return api; },
|
|
211
|
+
destroy() {
|
|
212
|
+
dead = true; io?.disconnect(); clearInterval(timer); introTl?.kill();
|
|
213
|
+
g.killTweensOf([ol, ...root.querySelectorAll('*')]);
|
|
214
|
+
el.innerHTML = '';
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
return api;
|
|
218
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* Before / after: two pictures (or any two pieces of content) laid on top of each other, with a
|
|
2
|
+
divider you drag sideways to wipe from one to the other — a renovation, a photo edit, a redesign,
|
|
3
|
+
light and dark. Drag anywhere on it with a mouse, finger or pen (an up-and-down swipe still
|
|
4
|
+
scrolls the page), click to jump there, or Tab to the handle and use ← → (Shift for bigger steps),
|
|
5
|
+
Page Up / Page Down, Home and End: the handle is an ARIA slider. With hover: true the divider
|
|
6
|
+
follows a mouse without pressing. Clicks and keys glide the divider, drags follow the finger, the
|
|
7
|
+
handle squeezes a little while held, and the “Before” / “After” tags step aside when the divider
|
|
8
|
+
comes close. With hint: true it sweeps once to each side when it first scrolls into view, so
|
|
9
|
+
people see it can move. With reduced motion the divider jumps and there is no sweep. */
|
|
10
|
+
import * as M from '@gecko-ui-kit/motion';
|
|
11
|
+
import { icon } from '@gecko-ui-kit/icons';
|
|
12
|
+
import { esc } from '../index.js';
|
|
13
|
+
|
|
14
|
+
const { g, RM, $$, fine } = M;
|
|
15
|
+
const WORDS = {
|
|
16
|
+
before: 'Before', after: 'After',
|
|
17
|
+
label: 'Before and after divider', // the slider's name
|
|
18
|
+
value: (n) => `${n}% before`, // read out as it moves
|
|
19
|
+
};
|
|
20
|
+
const clamp = (v) => Math.max(0, Math.min(100, v));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* const ba = beforeAfter(el, {
|
|
24
|
+
* before: '<img src="old.jpg" alt="The shop before">', // HTML string or an element
|
|
25
|
+
* after: '<img src="new.jpg" alt="The shop after">', // (leave both out to use el's first two children)
|
|
26
|
+
* start: 50, // where the divider starts, 0–100 (% of the before side shown)
|
|
27
|
+
* hover: false, // the divider follows the mouse without pressing (mouse / trackpad only)
|
|
28
|
+
* hint: false, // sweep once when it first scrolls into view
|
|
29
|
+
* labels: true, // the “Before” / “After” tags
|
|
30
|
+
* ratio: '4/3', // aspect ratio of the frame ('' = as tall as the content)
|
|
31
|
+
* step: 5, // arrow-key step in %, Shift × 4
|
|
32
|
+
* words: { before, after, label, value },
|
|
33
|
+
* onChange: (value, ba) => {}, // 0–100, while it moves
|
|
34
|
+
* })
|
|
35
|
+
* ba.set(70) · ba.set(70, false) (jump) · ba.value · ba.root · ba.destroy()
|
|
36
|
+
*/
|
|
37
|
+
export const beforeAfter = (el, opts = {}) => {
|
|
38
|
+
el = $$(el)[0];
|
|
39
|
+
if (!el) return null;
|
|
40
|
+
const o = { before: null, after: null, start: 50, hover: false, hint: false, labels: true, ratio: '4/3', step: 5, words: null, onChange: null, ...opts };
|
|
41
|
+
const W = { ...WORDS, ...o.words };
|
|
42
|
+
const ac = new AbortController(), on = (t, ev, fn, x) => t.addEventListener(ev, fn, { signal: ac.signal, ...x });
|
|
43
|
+
const own = [...el.children];
|
|
44
|
+
const take = (v, i) => (v == null ? own[i] || null : v);
|
|
45
|
+
const parts = [take(o.before, 0), take(o.after, 1)];
|
|
46
|
+
|
|
47
|
+
el.innerHTML = `<div class="ba${o.ratio ? '' : ' ba--auto'}"${o.ratio ? ` style="aspect-ratio:${esc(String(o.ratio).replace(/[^\d./ ]/g, ''))}"` : ''}>`
|
|
48
|
+
+ '<div class="ba__pane ba__after"></div><div class="ba__pane ba__before"></div>'
|
|
49
|
+
+ (o.labels ? `<span class="ba__tag ba__tag--before" aria-hidden="true">${esc(W.before)}</span><span class="ba__tag ba__tag--after" aria-hidden="true">${esc(W.after)}</span>` : '')
|
|
50
|
+
+ `<div class="ba__handle" role="slider" tabindex="0" aria-label="${esc(W.label)}" aria-orientation="horizontal" aria-valuemin="0" aria-valuemax="100">`
|
|
51
|
+
+ `<span class="ba__knob">${icon('chevL')}${icon('chevR')}</span></div></div>`;
|
|
52
|
+
const root = el.firstElementChild, handle = root.querySelector('.ba__handle'), knob = root.querySelector('.ba__knob');
|
|
53
|
+
const tagB = root.querySelector('.ba__tag--before'), tagA = root.querySelector('.ba__tag--after');
|
|
54
|
+
const fillPane = (pane, v) => { if (v == null) return; if (typeof v === 'string') pane.innerHTML = v; else pane.append(v); };
|
|
55
|
+
fillPane(root.querySelector('.ba__before'), parts[0]);
|
|
56
|
+
fillPane(root.querySelector('.ba__after'), parts[1]);
|
|
57
|
+
|
|
58
|
+
/* ---------- the value ---------- */
|
|
59
|
+
const st = { v: clamp(+o.start || 0) };
|
|
60
|
+
let shown = -1, ready = false;
|
|
61
|
+
const paint = () => {
|
|
62
|
+
const v = clamp(st.v);
|
|
63
|
+
root.style.setProperty('--ba-pos', `${v}%`);
|
|
64
|
+
const n = Math.round(v);
|
|
65
|
+
if (n !== shown) {
|
|
66
|
+
shown = n;
|
|
67
|
+
handle.setAttribute('aria-valuenow', String(n));
|
|
68
|
+
handle.setAttribute('aria-valuetext', W.value(n));
|
|
69
|
+
if (ready) o.onChange?.(n, api);
|
|
70
|
+
}
|
|
71
|
+
if (tagB) tagB.classList.toggle('is-away', v < 22);
|
|
72
|
+
if (tagA) tagA.classList.toggle('is-away', v > 78);
|
|
73
|
+
};
|
|
74
|
+
const glide = (to, duration = 0.45) => {
|
|
75
|
+
g.killTweensOf(st);
|
|
76
|
+
if (RM() || !duration) { st.v = clamp(to); paint(); return; }
|
|
77
|
+
g.to(st, { v: clamp(to), duration, ease: 'power3.out', onUpdate: paint });
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/* ---------- pointer ---------- */
|
|
81
|
+
const at = (e) => { const r = root.getBoundingClientRect(); return r.width ? ((e.clientX - r.left) / r.width) * 100 : st.v; };
|
|
82
|
+
let drag = null;
|
|
83
|
+
const stopHint = () => { hintTl?.kill(); hintTl = null; };
|
|
84
|
+
on(root, 'pointerdown', (e) => {
|
|
85
|
+
if (e.button !== 0) return;
|
|
86
|
+
stopHint();
|
|
87
|
+
drag = e.pointerId;
|
|
88
|
+
try { root.setPointerCapture(e.pointerId); } catch {}
|
|
89
|
+
root.classList.add('is-drag');
|
|
90
|
+
if (!RM()) g.to(knob, { scale: 0.9, duration: 0.2, ease: 'power2.out' });
|
|
91
|
+
glide(at(e), 0.25);
|
|
92
|
+
handle.focus({ preventScroll: true });
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
});
|
|
95
|
+
on(root, 'pointermove', (e) => {
|
|
96
|
+
if (drag === e.pointerId) { g.killTweensOf(st); st.v = clamp(at(e)); paint(); return; }
|
|
97
|
+
if (o.hover && e.pointerType === 'mouse' && fine.matches && drag == null) { stopHint(); glide(at(e), 0.35); }
|
|
98
|
+
});
|
|
99
|
+
const up = (e) => {
|
|
100
|
+
if (drag !== e.pointerId) return;
|
|
101
|
+
drag = null;
|
|
102
|
+
root.classList.remove('is-drag');
|
|
103
|
+
if (!RM()) g.to(knob, { scale: 1, duration: 0.5, ease: 'back.out(3)' }); else g.set(knob, { scale: 1 });
|
|
104
|
+
};
|
|
105
|
+
on(root, 'pointerup', up);
|
|
106
|
+
on(root, 'pointercancel', up);
|
|
107
|
+
|
|
108
|
+
/* ---------- keyboard ---------- */
|
|
109
|
+
on(handle, 'keydown', (e) => {
|
|
110
|
+
const s = (+o.step || 5) * (e.shiftKey ? 4 : 1);
|
|
111
|
+
const to = { ArrowLeft: st.v - s, ArrowDown: st.v - s, ArrowRight: st.v + s, ArrowUp: st.v + s, PageDown: st.v - 20, PageUp: st.v + 20, Home: 0, End: 100 }[e.key];
|
|
112
|
+
if (to === undefined) return;
|
|
113
|
+
e.preventDefault(); stopHint();
|
|
114
|
+
glide(Math.round(to), 0.3);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/* ---------- the hint sweep ---------- */
|
|
118
|
+
let hintTl = null, io = null;
|
|
119
|
+
const hint = () => {
|
|
120
|
+
if (RM()) return;
|
|
121
|
+
const from = st.v;
|
|
122
|
+
hintTl = g.timeline({ delay: 0.2, onUpdate: paint })
|
|
123
|
+
.to(st, { v: Math.max(12, from - 22), duration: 0.7, ease: 'power2.inOut' })
|
|
124
|
+
.to(st, { v: Math.min(88, from + 22), duration: 0.9, ease: 'power2.inOut' })
|
|
125
|
+
.to(st, { v: from, duration: 0.7, ease: 'power3.out' });
|
|
126
|
+
};
|
|
127
|
+
if (o.hint && typeof IntersectionObserver === 'function') {
|
|
128
|
+
io = new IntersectionObserver((ents) => { if (ents.some((x) => x.isIntersecting)) { io.disconnect(); io = null; hint(); } }, { threshold: 0.5 });
|
|
129
|
+
io.observe(root);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const api = {
|
|
133
|
+
root,
|
|
134
|
+
get value() { return Math.round(clamp(st.v)); },
|
|
135
|
+
set(v, animate = true) { stopHint(); glide(+v || 0, animate ? 0.45 : 0); return api; },
|
|
136
|
+
destroy() { ac.abort(); io?.disconnect(); stopHint(); g.killTweensOf([st, knob]); el.innerHTML = ''; },
|
|
137
|
+
};
|
|
138
|
+
paint();
|
|
139
|
+
ready = true;
|
|
140
|
+
return api;
|
|
141
|
+
};
|