@gecko-ui-kit/vue 0.0.0-stage → 0.3.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 +2052 -2
- package/index.d.ts +13 -0
- package/index.js +16 -0
- package/package.json +48 -4
- package/src/actions.d.ts +186 -0
- package/src/actions.js +329 -0
- package/src/basics.d.ts +315 -0
- package/src/basics.js +475 -0
- package/src/charts.d.ts +219 -0
- package/src/charts.js +93 -0
- package/src/controls.d.ts +149 -0
- package/src/controls.js +354 -0
- package/src/core.d.ts +109 -0
- package/src/core.js +414 -0
- package/src/data.d.ts +754 -0
- package/src/data.js +718 -0
- package/src/effects.d.ts +407 -0
- package/src/effects.js +699 -0
- package/src/forms.d.ts +757 -0
- package/src/forms.js +481 -0
- package/src/motion.d.ts +127 -0
- package/src/motion.js +216 -0
- package/src/overlays.d.ts +467 -0
- package/src/overlays.js +710 -0
- package/src/plugin.d.ts +6 -0
- package/src/plugin.js +27 -0
- package/src/shell.d.ts +210 -0
- package/src/shell.js +716 -0
- package/src/text.d.ts +309 -0
- package/src/text.js +383 -0
package/src/text.js
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/* Text motion from @gecko-ui-kit/motion as Vue components: TextReveal, Typewriter, Rotator, Shine, Highlighter,
|
|
2
|
+
ScrollReveal, BlurIn, ScrollProgress, Odometer, CountUp.
|
|
3
|
+
|
|
4
|
+
Pieces that rewrite their own text (letters, typed text, rolling words and digits) draw their first state on the
|
|
5
|
+
server, then hand the inside of their element to the vanilla code: Vue never touches that inside again, and new
|
|
6
|
+
props (or a new slot text) reach the piece through its own handle (retitle, set, go, odometer(el, value)…), so
|
|
7
|
+
the two never fight. Pieces that split your slot content into words or mark it (Highlighter, ScrollReveal words,
|
|
8
|
+
BlurIn) undo their changes before Vue patches a new text in, and run again after it. Classes the vanilla code
|
|
9
|
+
adds to the element (is-typing, is-armed…) survive a class change. */
|
|
10
|
+
import { defineComponent, ref, watch, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, normalizeClass, isVNode, toRaw, unref, Comment } from 'vue';
|
|
11
|
+
import * as M from '@gecko-ui-kit/motion';
|
|
12
|
+
import { h, B, ANY, anyProps, same, stop, changedOnly, enhancer, vnodeKey } from './core.js';
|
|
13
|
+
|
|
14
|
+
/* ---------------- small helpers ---------------- */
|
|
15
|
+
|
|
16
|
+
/** Options with every function swapped for a stable caller of the latest prop. */
|
|
17
|
+
const live = (o, latest) => {
|
|
18
|
+
const out = {};
|
|
19
|
+
for (const k in o) { const v = o[k]; out[k] = typeof v === 'function' ? (...a) => latest.current[k]?.(...a) : v; }
|
|
20
|
+
return out;
|
|
21
|
+
};
|
|
22
|
+
/** A plain copy of a prop (arrays and plain objects copied, read through Vue so changes inside are noticed). */
|
|
23
|
+
const read = (v) => {
|
|
24
|
+
if (Array.isArray(v)) return v.map(read);
|
|
25
|
+
if (v && typeof v === 'object' && !('$el' in v) && Object.getPrototypeOf(toRaw(v)) === Object.prototype) { const o = {}; for (const k in v) o[k] = read(v[k]); return o; }
|
|
26
|
+
return toRaw(unref(v));
|
|
27
|
+
};
|
|
28
|
+
/** An element from an element, a template ref, a component or a selector. */
|
|
29
|
+
const deref = (x) => { x = unref(x); return x && typeof x === 'object' && '$el' in x ? x.$el : x ?? null; };
|
|
30
|
+
/** The text of slot content made of text ('Hello', 'Hi {{ name }}'). */
|
|
31
|
+
const textOf = (v) => (v == null || typeof v === 'boolean' ? '' : Array.isArray(v) ? v.map(textOf).join('')
|
|
32
|
+
: isVNode(v) ? (v.type === Comment ? '' : typeof v.children === 'string' ? v.children : Array.isArray(v.children) ? textOf(v.children) : '')
|
|
33
|
+
: String(v));
|
|
34
|
+
/** "a, b and c" (what screen readers hear for a list). The vanilla code writes its own on mount. */
|
|
35
|
+
const listText = (items, locale) => {
|
|
36
|
+
if (items.length < 2) return items[0] ?? '';
|
|
37
|
+
try { return new Intl.ListFormat(locale, { type: 'conjunction' }).format(items); } catch { return items.join(', '); }
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A component whose vanilla motion owns the inside of its element.
|
|
42
|
+
* props option props (anything else goes on the element)
|
|
43
|
+
* cls(o) classes the element always has (so the server HTML already looks right)
|
|
44
|
+
* kids(o) the first content, drawn on the server and kept as it is (Vue never redraws it)
|
|
45
|
+
* run(el, o) → handle · end(handle, el) clean up (default: stop) · update(handle, next, prev, el) → true when applied
|
|
46
|
+
* fromSlot(o, nodes) read options from the default slot (e.g. the text); the slot itself is not rendered
|
|
47
|
+
* handle true: a template ref gets the vanilla handle's methods and values plus `el`
|
|
48
|
+
*/
|
|
49
|
+
function owned(name, spec) {
|
|
50
|
+
const { tag = 'span', props: decl, defaults = {}, cls, kids, run, end = stop, update, handle: asHandle = false, fromSlot, rootAttrs } = spec;
|
|
51
|
+
return defineComponent({
|
|
52
|
+
name,
|
|
53
|
+
inheritAttrs: false,
|
|
54
|
+
props: { ...decl, as: { type: String, default: undefined } },
|
|
55
|
+
setup(props, { slots, attrs, expose }) {
|
|
56
|
+
const el = ref(null);
|
|
57
|
+
const latest = { current: {} };
|
|
58
|
+
let cur = null, first = null, firstTag = null, lastOwn = null, kept = null;
|
|
59
|
+
if (asHandle) {
|
|
60
|
+
expose(new Proxy({}, {
|
|
61
|
+
get(t, k) {
|
|
62
|
+
if (k in t) return t[k];
|
|
63
|
+
if (k === 'el') return el.value;
|
|
64
|
+
const x = cur?.handle; if (x == null || typeof x !== 'object') return undefined;
|
|
65
|
+
const v = x[k]; return typeof v === 'function' ? v.bind(x) : v;
|
|
66
|
+
},
|
|
67
|
+
has(t, k) { return k in t || k === 'el' || (cur?.handle != null && k in Object(cur.handle)); },
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
const start = () => { const o = latest.current, node = el.value; cur = { el: node, opts: o, handle: run(node, live(o, latest)) ?? null }; };
|
|
71
|
+
const finish = () => { const c = cur; cur = null; if (c) end(c.handle, c.el); };
|
|
72
|
+
const sync = () => {
|
|
73
|
+
const c = cur; if (!c) return;
|
|
74
|
+
if (c.el !== el.value) { finish(); start(); return; } // a new element (`as` changed)
|
|
75
|
+
const next = latest.current, prev = c.opts;
|
|
76
|
+
if (same(next, prev)) return;
|
|
77
|
+
if (update && update(c.handle, next, prev, c.el) === true) { c.opts = next; return; }
|
|
78
|
+
finish(); start();
|
|
79
|
+
};
|
|
80
|
+
onMounted(start);
|
|
81
|
+
onUpdated(() => {
|
|
82
|
+
if (kept && el.value) el.value.classList.add(...kept);
|
|
83
|
+
kept = null;
|
|
84
|
+
sync();
|
|
85
|
+
});
|
|
86
|
+
onBeforeUnmount(finish);
|
|
87
|
+
return () => {
|
|
88
|
+
const o = { ...defaults };
|
|
89
|
+
for (const k in decl) { const v = read(props[k]); if (v !== undefined) o[k] = v; }
|
|
90
|
+
fromSlot?.(o, slots.default?.());
|
|
91
|
+
latest.current = o;
|
|
92
|
+
const t = props.as || tag;
|
|
93
|
+
const own = normalizeClass([cls?.(o), attrs.class]);
|
|
94
|
+
if (firstTag !== t) { first = kids(o); firstTag = t; kept = null; }
|
|
95
|
+
else if (lastOwn !== null && own !== lastOwn && el.value) {
|
|
96
|
+
// Vue writes the whole class attribute: keep the classes the vanilla code added (is-typing…)
|
|
97
|
+
const was = new Set(lastOwn.split(/\s+/));
|
|
98
|
+
kept = [...el.value.classList].filter((c) => !was.has(c));
|
|
99
|
+
}
|
|
100
|
+
lastOwn = own;
|
|
101
|
+
return h(t, { ...attrs, ...rootAttrs?.(o), ref: el, class: own || undefined }, first);
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* ---------------- TextReveal ---------------- */
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* <TextReveal as="h1" :stagger="0.022" :tilt="6">Bikes for every trip</TextReveal>
|
|
111
|
+
* Same as title(el, { delay, stagger, tilt, duration }): the letters roll up out of a mask. The slot is the text
|
|
112
|
+
* (or the `text` prop); a new text plays again in place (retitle), new options replay it. Screen readers hear the
|
|
113
|
+
* whole text.
|
|
114
|
+
*/
|
|
115
|
+
export const TextReveal = owned('TextReveal', {
|
|
116
|
+
props: { text: { type: String, default: undefined }, ...anyProps('delay', 'stagger', 'tilt', 'duration') },
|
|
117
|
+
fromSlot: (o, nodes) => { if (o.text === undefined) o.text = textOf(nodes); },
|
|
118
|
+
kids: (o) => o.text,
|
|
119
|
+
run: (el, o) => ({ tw: M.title(el, o) }),
|
|
120
|
+
end: (x) => x?.tw?.kill(),
|
|
121
|
+
update(x, next, prev, el) {
|
|
122
|
+
x.tw?.kill();
|
|
123
|
+
x.tw = next.text !== prev.text ? M.retitle(el, next.text, next) : M.title(el, next);
|
|
124
|
+
return true;
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/* ---------------- Typewriter ---------------- */
|
|
129
|
+
|
|
130
|
+
const CARETS = ['bar', 'block', 'underscore'];
|
|
131
|
+
const caretOf = (c) => (c === undefined ? 'bar' : CARETS.includes(c) ? c : 'none');
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* <Typewriter :phrases="['scooters', 'city bikes', 'e-bikes']" caret="bar" erase="select" />
|
|
135
|
+
* <Typewriter as="p" :loop="false">Booked!</Typewriter>
|
|
136
|
+
* Same as typewriter(el, options). New `phrases` (or a new slot text) delete the current one and type the new
|
|
137
|
+
* list (tw.set). `paused` stops and resumes it. @phrase(i, text).
|
|
138
|
+
* Template ref → { phrase, play(), pause(), restart(), set(list), el }.
|
|
139
|
+
*/
|
|
140
|
+
export const Typewriter = owned('Typewriter', {
|
|
141
|
+
props: { ...anyProps('phrases', 'speed', 'jitter', 'eraseSpeed', 'erase', 'hold', 'gap', 'delay', 'caret', 'locale', 'label'), loop: B, whenVisible: B, paused: B, onPhrase: Function },
|
|
142
|
+
handle: true,
|
|
143
|
+
fromSlot: (o, nodes) => { if (!o.phrases) { const t = textOf(nodes); o.phrases = t ? [t] : []; } },
|
|
144
|
+
cls: (o) => ['gk-tw', 'gk-tw--' + caretOf(o.caret)],
|
|
145
|
+
kids: (o) => [
|
|
146
|
+
h('span', { class: 'gk-tw__sr', 'data-allow-mismatch': 'text' }, o.label ?? listText(o.phrases, o.locale)),
|
|
147
|
+
h('span', { class: 'gk-tw__vis', 'aria-hidden': 'true' }, [h('span', { class: 'gk-tw__text' }), h('i', { class: 'gk-tw__caret' })]),
|
|
148
|
+
],
|
|
149
|
+
run: (el, { paused, ...o }) => { const t = M.typewriter(el, o); if (paused) t?.pause(); return t; },
|
|
150
|
+
update(t, next, prev) {
|
|
151
|
+
if (!t || !changedOnly(next, prev, ['phrases', 'paused'])) return false;
|
|
152
|
+
if (!same(next.phrases, prev.phrases)) t.set(next.phrases);
|
|
153
|
+
if (!!next.paused !== !!prev.paused) (next.paused ? t.pause() : t.play());
|
|
154
|
+
return true;
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/* ---------------- Rotator ---------------- */
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* <h2>Rent a <Rotator :words="['scooter', 'city bike', 'e-bike']" effect="roll" pill /> by the hour</h2>
|
|
162
|
+
* Same as rotator(el, options): one word keeps changing while its slot glides to the new width.
|
|
163
|
+
* New `words` start again from the first (r.set); `index` shows that word (r.go); `paused` stops it.
|
|
164
|
+
* @change(i, word). Template ref → { index, next(), go(i), play(), pause(), set(words), el }.
|
|
165
|
+
*/
|
|
166
|
+
export const Rotator = owned('Rotator', {
|
|
167
|
+
props: { ...anyProps('words', 'every', 'effect', 'duration', 'ease', 'stagger', 'locale', 'label', 'index'), auto: B, whenVisible: B, paused: B, pill: B, onChange: Function },
|
|
168
|
+
defaults: { words: [] },
|
|
169
|
+
handle: true,
|
|
170
|
+
cls: (o) => ['gk-rot', o.pill && 'gk-rot--pill'],
|
|
171
|
+
kids: (o) => {
|
|
172
|
+
const w = o.words[o.index ?? 0] ?? o.words[0] ?? '';
|
|
173
|
+
return [
|
|
174
|
+
h('span', { class: 'gk-rot__sr', 'data-allow-mismatch': 'text' }, o.label ?? listText(o.words, o.locale)),
|
|
175
|
+
h('span', { class: 'gk-rot__box', 'aria-hidden': 'true' }, [h('span', { class: 'gk-rot__sizer' }, w), h('span', { class: 'gk-rot__w' }, w)]),
|
|
176
|
+
];
|
|
177
|
+
},
|
|
178
|
+
run: (el, { index, paused, pill, ...o }) => {
|
|
179
|
+
const r = M.rotator(el, o);
|
|
180
|
+
if (r && index) r.go(index);
|
|
181
|
+
if (r && paused) r.pause();
|
|
182
|
+
return r;
|
|
183
|
+
},
|
|
184
|
+
update(r, next, prev) {
|
|
185
|
+
if (!r || !changedOnly(next, prev, ['words', 'index', 'paused', 'pill'])) return false;
|
|
186
|
+
if (!same(next.words, prev.words)) r.set(next.words);
|
|
187
|
+
if (next.index != null && next.index !== r.index) r.go(next.index);
|
|
188
|
+
if (!!next.paused !== !!prev.paused) (next.paused ? r.pause() : r.play());
|
|
189
|
+
return true;
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/* ---------------- Shine ---------------- */
|
|
194
|
+
|
|
195
|
+
const SHINE_LOOKS = ['gradient', 'ink', 'color'];
|
|
196
|
+
const SHINE_PROPS = anyProps('look', 'trigger', 'duration', 'repeatDelay', 'delay', 'ease', 'angle', 'width', 'color');
|
|
197
|
+
const ShineMotion = enhancer('ShineMotion', (el, o) => M.shine(el, o), { tag: 'span', props: SHINE_PROPS });
|
|
198
|
+
/**
|
|
199
|
+
* <Shine as="h2" look="gradient" trigger="loop">Ride the river path</Shine>
|
|
200
|
+
* Same as shine(el, options): a slanted band of light sweeps across the letters. The slot is any text or markup.
|
|
201
|
+
*/
|
|
202
|
+
export const Shine = defineComponent({
|
|
203
|
+
name: 'Shine',
|
|
204
|
+
props: { ...SHINE_PROPS, as: { type: String, default: undefined } },
|
|
205
|
+
setup(props, { slots }) {
|
|
206
|
+
return () => {
|
|
207
|
+
const look = SHINE_LOOKS.includes(props.look) ? props.look : 'gradient';
|
|
208
|
+
return h(ShineMotion, { ...props, class: ['gk-shine', 'gk-shine--' + look] }, { default: () => slots.default?.() });
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
/* ---------------- Highlighter ---------------- */
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* <Highlighter as="p" tone="amber">Helmets are <mark>free with every rental</mark>.</Highlighter>
|
|
217
|
+
* Same as highlighter(el, options): the <mark> words inside get a marker stroke when they scroll into view.
|
|
218
|
+
* With trigger="manual", `active` draws the strokes (true) or clears them (false). A new slot content is marked again.
|
|
219
|
+
*/
|
|
220
|
+
export const Highlighter = enhancer('Highlighter', (el, { active, ...o }) => {
|
|
221
|
+
const hl = M.highlighter(el, o);
|
|
222
|
+
if (hl && active && o.trigger === 'manual') hl.play();
|
|
223
|
+
return hl;
|
|
224
|
+
}, {
|
|
225
|
+
tag: 'p', rerunOnChildren: true,
|
|
226
|
+
props: { ...anyProps('selector', 'look', 'tone', 'color', 'trigger', 'threshold', 'duration', 'stagger', 'delay', 'ease'), once: B, active: B },
|
|
227
|
+
update(hl, next, prev) {
|
|
228
|
+
if (!hl || !changedOnly(next, prev, ['active'])) return false;
|
|
229
|
+
if (next.active) hl.play(); else hl.reset();
|
|
230
|
+
return true;
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/* ---------------- ScrollReveal ---------------- */
|
|
235
|
+
|
|
236
|
+
const SR_PROPS = { ...anyProps('effect', 'y', 'x', 'scale', 'blur', 'duration', 'stagger', 'wordStagger', 'delay', 'ease', 'threshold', 'rootMargin', 'root'), words: B, once: B, onEnter: Function, onLeave: Function };
|
|
237
|
+
/**
|
|
238
|
+
* <ScrollReveal effect="rise">…one block…</ScrollReveal>
|
|
239
|
+
* <ScrollReveal items=":scope > article" effect="slide" :x="-40" :once="false"><article v-for="s in steps">…</article></ScrollReveal>
|
|
240
|
+
* <ScrollReveal as="p" words effect="blur">Slow mornings and a bike at the door.</ScrollReveal>
|
|
241
|
+
* Same as scrollReveal(targets, options). Without `items` the element itself is revealed (hidden until then, also
|
|
242
|
+
* in the server HTML); with `items` (a selector inside) each match is, top to bottom. New items are revealed as
|
|
243
|
+
* they arrive. With `words` the text is split into words; a new text is joined back before Vue draws it, then split
|
|
244
|
+
* and revealed again. root: the scrolling box (element, template ref or selector; default the page).
|
|
245
|
+
* @enter(el), @leave(el).
|
|
246
|
+
*/
|
|
247
|
+
export const ScrollReveal = defineComponent({
|
|
248
|
+
name: 'ScrollReveal',
|
|
249
|
+
props: { ...SR_PROPS, as: { type: String, default: undefined }, items: { type: String, default: undefined } },
|
|
250
|
+
setup(props, { slots, attrs }) {
|
|
251
|
+
const el = ref(null);
|
|
252
|
+
const latest = { current: {} };
|
|
253
|
+
let st = null, kidsKey = '', again = false, lastClass = normalizeClass(attrs.class), kept = null;
|
|
254
|
+
const arm = () => {
|
|
255
|
+
const s = st, node = el.value; if (!s || !node) return;
|
|
256
|
+
const targets = props.items ? [...node.querySelectorAll(props.items)] : [node];
|
|
257
|
+
const fresh = targets.filter((t) => !s.armed.has(t)); if (!fresh.length) return;
|
|
258
|
+
fresh.forEach((t) => s.armed.add(t));
|
|
259
|
+
const o = live(latest.current, latest);
|
|
260
|
+
s.handles.push(M.scrollReveal(fresh, { ...o, root: deref(o.root) }));
|
|
261
|
+
};
|
|
262
|
+
const halt = () => { st?.handles.forEach((x) => x.destroy()); st = null; };
|
|
263
|
+
const reset = () => { halt(); st = { handles: [], armed: new WeakSet(), opts: latest.current, items: props.items }; };
|
|
264
|
+
onMounted(() => { reset(); arm(); });
|
|
265
|
+
// Vue rewrites the whole class attribute when `class` changes: keep is-armed / is-shown
|
|
266
|
+
onBeforeUpdate(() => {
|
|
267
|
+
const nc = normalizeClass(attrs.class);
|
|
268
|
+
if (nc !== lastClass && el.value) {
|
|
269
|
+
const was = new Set(String(lastClass || '').split(/\s+/));
|
|
270
|
+
kept = [...el.value.classList].filter((c) => !was.has(c));
|
|
271
|
+
}
|
|
272
|
+
lastClass = nc;
|
|
273
|
+
});
|
|
274
|
+
onUpdated(() => {
|
|
275
|
+
if (kept) { el.value?.classList.add(...kept); kept = null; }
|
|
276
|
+
if (again || !st || !same(latest.current, st.opts) || st.items !== props.items) { again = false; reset(); arm(); } // new text or options: arm again
|
|
277
|
+
else arm(); // new items: arm them
|
|
278
|
+
});
|
|
279
|
+
onBeforeUnmount(halt);
|
|
280
|
+
return () => {
|
|
281
|
+
const o = {};
|
|
282
|
+
for (const k in SR_PROPS) { const v = read(props[k]); if (v !== undefined) o[k] = v; }
|
|
283
|
+
latest.current = o;
|
|
284
|
+
const kids = slots.default?.();
|
|
285
|
+
if (o.words) {
|
|
286
|
+
const k = vnodeKey(kids);
|
|
287
|
+
// the text changed: join the words back now (render runs before the patch), split again after it
|
|
288
|
+
if (st && k !== kidsKey) { halt(); again = true; }
|
|
289
|
+
kidsKey = k;
|
|
290
|
+
}
|
|
291
|
+
return h(props.as || 'div', { ref: el, 'data-reveal': props.items ? undefined : '' }, kids);
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
/* ---------------- BlurIn ---------------- */
|
|
297
|
+
|
|
298
|
+
const BLUR_PROPS = anyProps('blur', 'y', 'duration', 'stagger', 'delay', 'ease');
|
|
299
|
+
const BlurInMotion = enhancer('BlurInMotion', (el, o) => {
|
|
300
|
+
el.removeAttribute('data-reveal'); // it was hiding the text until now
|
|
301
|
+
const tw = M.blurIn(el, o);
|
|
302
|
+
return () => { tw.kill(); M.blurIn.clear(el); };
|
|
303
|
+
}, { tag: 'p', props: BLUR_PROPS, rerunOnChildren: true });
|
|
304
|
+
/**
|
|
305
|
+
* <BlurIn as="p" :blur="12" :stagger="0.05">Slow mornings, fresh coffee and a bike waiting at the door.</BlurIn>
|
|
306
|
+
* Same as blurIn(el, options): the words come into focus one after another, right away. A new text (or new options)
|
|
307
|
+
* plays again. Hidden in the server HTML until it plays.
|
|
308
|
+
*/
|
|
309
|
+
export const BlurIn = defineComponent({
|
|
310
|
+
name: 'BlurIn',
|
|
311
|
+
props: { ...BLUR_PROPS, as: { type: String, default: undefined } },
|
|
312
|
+
setup(props, { slots }) {
|
|
313
|
+
return () => h(BlurInMotion, { ...props, 'data-reveal': '' }, { default: () => slots.default?.() });
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
/* ---------------- ScrollProgress ---------------- */
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* <ScrollProgress /> or <ScrollProgress :root="panel" @change="(p) => (read = p)" />
|
|
321
|
+
* Same as scrollProgress(bar, { root, onChange }): a thin line on .gk-scroll-progress that fills as the page (or the
|
|
322
|
+
* scrolling box root: element, template ref or selector) is read. @change(progress 0…1).
|
|
323
|
+
*/
|
|
324
|
+
export const ScrollProgress = defineComponent({
|
|
325
|
+
name: 'ScrollProgress',
|
|
326
|
+
props: { root: ANY, onChange: Function },
|
|
327
|
+
setup(props) {
|
|
328
|
+
const el = ref(null);
|
|
329
|
+
let p = null;
|
|
330
|
+
const go = () => { p?.destroy(); p = M.scrollProgress(el.value, { root: deref(props.root), onChange: (v) => props.onChange?.(v) }); };
|
|
331
|
+
onMounted(() => { go(); watch(() => deref(props.root), go, { flush: 'post' }); });
|
|
332
|
+
onBeforeUnmount(() => { p?.destroy(); p = null; });
|
|
333
|
+
return () => h('div', { ref: el, 'aria-hidden': 'true', class: 'gk-scroll-progress' });
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
/* ---------------- Odometer ---------------- */
|
|
338
|
+
|
|
339
|
+
const odoText = (v, o) => {
|
|
340
|
+
if (typeof v === 'string') return v;
|
|
341
|
+
if (typeof o.format === 'function') return String(o.format(v));
|
|
342
|
+
try { return new Intl.NumberFormat(o.locale, o.format || undefined).format(v); } catch { return String(v); }
|
|
343
|
+
};
|
|
344
|
+
const ODO_PROPS = anyProps('value', 'format', 'locale', 'duration', 'stagger', 'direction', 'ease', 'from');
|
|
345
|
+
/**
|
|
346
|
+
* <Odometer :value="price" :format="{ style: 'currency', currency: 'THB', maximumFractionDigits: 0 }" locale="th-TH" />
|
|
347
|
+
* Same as odometer(el, value, options): when `value` changes the digits roll in place, one reel each.
|
|
348
|
+
* from: roll in from this value on mount. value may also be a ready-made string.
|
|
349
|
+
*/
|
|
350
|
+
export const Odometer = owned('Odometer', {
|
|
351
|
+
props: ODO_PROPS,
|
|
352
|
+
defaults: { value: 0 },
|
|
353
|
+
cls: () => 'gk-odo',
|
|
354
|
+
// without a locale the number is written in the reader's language, which the server may not share
|
|
355
|
+
rootAttrs: (o) => (o.locale == null ? { 'data-allow-mismatch': 'text' } : null),
|
|
356
|
+
kids: (o) => odoText(o.from ?? o.value, o),
|
|
357
|
+
run: (el, { value, ...o }) => { M.odometer(el, value, o); return null; },
|
|
358
|
+
end: (_, el) => M.odometer.clear(el),
|
|
359
|
+
update: (_, { value, ...o }, prev, el) => { M.odometer(el, value, o); return true; },
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
/* ---------------- CountUp ---------------- */
|
|
363
|
+
|
|
364
|
+
const countFormat = (o) => (typeof o.format === 'function' ? (v) => o.format(v)
|
|
365
|
+
: (v) => (o.prefix ?? '') + Number(v).toLocaleString(o.locale ?? 'en-US', { minimumFractionDigits: o.decimals ?? 0, maximumFractionDigits: o.decimals ?? 0 }) + (o.suffix ?? ''));
|
|
366
|
+
const COUNT_PROPS = { ...anyProps('value', 'from', 'duration', 'delay', 'prefix', 'suffix', 'decimals', 'locale'), format: Function, tick: B };
|
|
367
|
+
/**
|
|
368
|
+
* <CountUp :value="48250" prefix="฿" /> <CountUp :value="4.8" :decimals="1" suffix=" / 5" tick />
|
|
369
|
+
* Same as num() + count(): the number counts up from `from` (0) on mount, and from the number on screen to the
|
|
370
|
+
* new one when `value` changes (tick: tints it green going up, red going down).
|
|
371
|
+
*/
|
|
372
|
+
export const CountUp = owned('CountUp', {
|
|
373
|
+
props: COUNT_PROPS,
|
|
374
|
+
defaults: { value: 0 },
|
|
375
|
+
kids: (o) => countFormat(o)(o.from ?? 0),
|
|
376
|
+
run: (el, o) => ({ tw: M.count(el, o.value, countFormat(o), { duration: o.duration, delay: o.delay, from: o.from ?? 0 }) }),
|
|
377
|
+
end: (x) => x?.tw?.kill(),
|
|
378
|
+
update(x, next, prev, el) {
|
|
379
|
+
x.tw = M.count(el, next.value, countFormat(next), { duration: next.duration });
|
|
380
|
+
if (next.tick && next.value !== prev.value) M.tick(el, next.value > prev.value);
|
|
381
|
+
return true;
|
|
382
|
+
},
|
|
383
|
+
});
|