@gecko-ui-kit/vue 0.0.0-stage → 0.1.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/src/shell.js ADDED
@@ -0,0 +1,716 @@
1
+ /* App shell: AppShell and its parts (Sidebar, Topbar, PageHeader, MobileTabbar) as Vue components.
2
+
3
+ The vanilla createShell() owns everything: it draws the frame, runs a hash router and renders pages from
4
+ HTML strings. In a Nuxt / vue-router app the router is yours and the pages are Vue, so these components draw
5
+ the same markup themselves (the same CSS styles it, it renders on the server) and only borrow the motion:
6
+ the stretchy pill, the sub-menu accordion, the rail collapse with FLIP, the hover flyout, the split-letter
7
+ title, the tab underline, the bell wiggle, the theme reveal, the intro and the page slide.
8
+
9
+ Routing: pass the current path (`:path="route.path"`) and `@navigate` (router.push / navigateTo). Every link is
10
+ a real <a href> (or your `link` component, e.g. NuxtLink or RouterLink, given `to`); a plain click calls
11
+ onNavigate(href) instead of loading the page. Without @navigate a `link` component navigates by itself.
12
+ An item's address is item.href, else `${base}/${id}`; a sub-page's is `${itemHref}/${subId}` (or its own href). */
13
+ import { defineComponent, ref, reactive, computed, watch, nextTick, provide, inject, onMounted, onUpdated, onBeforeUnmount, Teleport } from 'vue';
14
+ import * as M from '@gecko-ui-kit/motion';
15
+ import * as O from '@gecko-ui-kit/overlays';
16
+ import { esc } from '@gecko-ui-kit/components';
17
+ import { h, ANY, Icon, iconNode, useModel, modelProps } from './core.js';
18
+
19
+ const { g, D, RM, $$ } = M;
20
+
21
+ const WORDS = {
22
+ sidebar: 'Sidebar', main: 'Main', collapse: 'Collapse sidebar', expand: 'Expand sidebar', collapseTip: 'Collapse [', expandTip: 'Expand [',
23
+ account: 'account', open: 'Open', menu: 'Open menu', breadcrumb: 'Breadcrumb', search: 'Search', searchPlaceholder: 'Search…', searchKey: '⌘K',
24
+ theme: 'Switch theme', themeTip: 'Theme', bell: 'Notifications', primary: 'New', tabs: 'Tabs', more: 'More', sections: 'Sections',
25
+ shortcuts: 'Keyboard shortcuts', replay: 'Replay intro', searchPages: 'Search pages…', goTo: 'Go to', toggleRail: 'Collapse / expand sidebar',
26
+ thisList: 'This list', close: 'Close',
27
+ };
28
+ const wordsOf = (w) => (w ? { ...WORDS, ...w } : WORDS);
29
+
30
+ /* ---------------- routes from nav + path ---------------- */
31
+ const clean = (p) => (String(p ?? '/').replace(/[?#].*$/, '').replace(/\/+$/, '') || '/');
32
+ const normSub = (s) => (Array.isArray(s) ? { id: String(s[0]), label: s[1] ?? s[0], href: s[2] } : { ...s, id: String(s.id) });
33
+
34
+ /** nav + end → everything the parts need to know about the menu and where we are. */
35
+ function model({ nav = [], end = [], base = '', path, home }) {
36
+ const all = [...(nav || []).flatMap((grp) => grp.items || []), ...(end || [])];
37
+ const hrefOf = (it, subId) => {
38
+ const ih = it.href ?? `${base || ''}/${it.id}`;
39
+ if (!subId) return ih;
40
+ const s = (it.subs || []).map(normSub).find((x) => x.id === subId);
41
+ return s?.href ?? `${ih === '/' ? '' : ih}/${subId}`;
42
+ };
43
+ const subsOf = (it) => (it?.subs?.length ? it.subs.map(normSub).map((s) => ({ ...s, href: hrefOf(it, s.id) })) : null);
44
+ const p = clean(path);
45
+ let item = null, score = -1;
46
+ for (const it of all) {
47
+ const ih = clean(hrefOf(it));
48
+ if ((p === ih || (ih !== '/' && p.startsWith(ih + '/'))) && ih.length > score) { item = it; score = ih.length; }
49
+ }
50
+ if (!item && home && path == null) item = all.find((it) => it.id === home) || null;
51
+ let sub = '';
52
+ const subs = subsOf(item);
53
+ if (subs) sub = subs.find((s) => { const sh = clean(s.href); return p === sh || p.startsWith(sh + '/'); })?.id ?? '';
54
+ const order = all.map((it) => it.id);
55
+ const rank = item ? order.indexOf(item.id) * 100 + Math.max(0, subs?.findIndex((s) => s.id === sub) ?? 0) : -1;
56
+ return { all, hrefOf, subsOf, item, page: item?.id ?? null, sub, rank, itemOf: (id) => all.find((it) => it.id === id) };
57
+ }
58
+ const countOf = (it) => (typeof it.count === 'function' ? it.count() : it.count) ?? 0;
59
+ const modelOf = (props) => computed(() => model({ nav: props.nav, end: props.end, base: props.base, path: props.path, home: props.home }));
60
+
61
+ /* The props every part shares (see ShellNavProps in shell.d.ts). */
62
+ const navProps = () => ({
63
+ nav: { type: Array, default: () => [] }, end: Array, path: String, base: String, home: String,
64
+ onNavigate: Function, link: ANY, words: Object,
65
+ });
66
+
67
+ /* ---------------- navigation ---------------- */
68
+ const go = (onNavigate, href) => { if (onNavigate) onNavigate(href); else location.assign(href); };
69
+ /**
70
+ * A real link; a plain left click calls onNavigate(href) instead of loading the page.
71
+ * With a `link` component (NuxtLink, RouterLink) it gets `to` and our click runs first (capture), so when
72
+ * onNavigate is given the link sees the click as handled and does not navigate a second time.
73
+ */
74
+ function navLink({ onNavigate, link }, { href, onClick, ...rest }, kids) {
75
+ const click = (e) => {
76
+ onClick?.(e);
77
+ if (e.defaultPrevented || !onNavigate || e.button || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || rest.target) return;
78
+ e.preventDefault(); onNavigate(href);
79
+ };
80
+ return link && link !== 'a'
81
+ ? h(link, { to: href, ...rest, onClickCapture: click }, { default: () => kids })
82
+ : h('a', { href, ...rest, onClick: click }, kids);
83
+ }
84
+
85
+ /* html.is-sideopen: the sidebar shown as a drawer on phones. Every part hears about it through one event. */
86
+ const SIDE_EVENT = 'gecko:sideopen';
87
+ const setSideOpen = (open) => {
88
+ const root = document.documentElement;
89
+ if (root.classList.contains('is-sideopen') === !!open) return;
90
+ root.classList.toggle('is-sideopen', !!open);
91
+ window.dispatchEvent(new CustomEvent(SIDE_EVENT, { detail: !!open }));
92
+ };
93
+
94
+ /* menu items for O.menu: '-' · { section } heading · { icon, label, kbd, danger, run } */
95
+ const toMenu = (items) => (items || []).filter((it) => it != null && it !== false).map((it) => {
96
+ if (it === '-' || it.sep) return '-';
97
+ if (it.section != null) return { label: String(it.section) };
98
+ return { icon: typeof it.icon === 'string' ? it.icon : undefined, label: String(it.label ?? ''), kbd: it.kbd ? esc(it.kbd) : '', danger: !!it.danger, run: (a) => it.run?.(a) };
99
+ });
100
+
101
+ const SHELL = Symbol('gecko-shell');
102
+ /**
103
+ * Inside <AppShell> (call it in setup()): a reactive object
104
+ * { route: { page, sub }, path, navigate(href), palette(), shortcuts(), intro(), setRail(b), isRail() }
105
+ * route and path follow the current path. Outside: null.
106
+ * const shell = useShell(); → {{ shell?.route.page }} · shell.navigate('/bikes')
107
+ */
108
+ export const useShell = () => inject(SHELL, null)?.api ?? null;
109
+
110
+ /* ======================================================================= */
111
+ /* Sidebar */
112
+ /* ======================================================================= */
113
+ /* FLIP targets and the parts that fade while the sidebar collapses / expands (same as the vanilla shell) */
114
+ const FLIP = [['.side__head .brand', '.mark'], ['.side__head .collapse', ''], ['.snav__item', '.ico'], ['.side__me', ':scope > .av']];
115
+ const FADE = '.brand__text, .side__group, .snav__label, .snav__chev, .snav__count, .snav__subs, .side__me .cell__text, .side__me > .ico';
116
+ const RISE = ':scope > .card, :scope > .grid > .card, :scope > .kpis > .kpi, :scope > .stack > .card, [data-rise]';
117
+
118
+ const initials = (name = '') => String(name).split(/\s+/).filter(Boolean).slice(0, 2).map((w) => w[0]).join('').toUpperCase();
119
+ /* the same markup as av(person, '', online) */
120
+ const avatar = (person, online) => h('span', { class: `av av--${person.tone || 'indigo'}`, title: person.name }, [person.ini ?? initials(person.name), online ? h('i', { class: 'av__on' }) : null]);
121
+
122
+ /**
123
+ * <Sidebar :brand="{ name: 'MotoRent', sub: 'Chiang Mai', icon: 'logo' }" :nav="nav" :end="end" :user="me"
124
+ * :path="route.path" @navigate="(href) => router.push(href)" />
125
+ * The main menu: a pill stretches to the current item, the open section unfolds its sub-pages (click it to fold),
126
+ * numbers flash when they change, it collapses to a rail of icons (with a flyout on hover) and saves that choice.
127
+ * On phones it is a drawer opened by the Topbar's menu button.
128
+ * Template ref → { setRail(b), isRail(), el }.
129
+ */
130
+ export const Sidebar = defineComponent({
131
+ name: 'Sidebar',
132
+ inheritAttrs: false,
133
+ props: {
134
+ ...navProps(), brand: { type: Object, default: () => ({ name: 'App' }) }, user: Object,
135
+ storageKey: { type: String, default: 'gecko' }, railBreakpoint: { type: Number, default: 1280 }, mobile: { type: Number, default: 760 },
136
+ },
137
+ setup(props, { attrs, expose }) {
138
+ const m = modelOf(props);
139
+ const W = computed(() => wordsOf(props.words));
140
+ const L = () => ({ onNavigate: props.onNavigate, link: props.link });
141
+ const side = ref(null), pill = ref(null), flyEl = ref(null);
142
+ const rail = ref(false);
143
+ const phone = ref(false); // on phones the sidebar is a full drawer, even when saved as a rail
144
+ let railTl = null, flyTimer = null, stopTrack = null, mq = null;
145
+ const subs = reactive({ page: m.value.page, shut: false, hidden: false });
146
+ watch(() => m.value.page, (p) => { if (subs.page !== p) Object.assign(subs, { page: p, shut: false, hidden: false }); }, { flush: 'pre' });
147
+ const fly = ref(null); // { id, left, y, out }
148
+ const isMobile = () => innerWidth <= props.mobile;
149
+
150
+ /* ----- rail ----- */
151
+ const setRail = (r) => {
152
+ railTl?.progress(1);
153
+ if (rail.value === r) return;
154
+ closeFly(true);
155
+ const root = document.documentElement, sideEl = side.value, main = document.querySelector('.t-main');
156
+ const apply = () => {
157
+ root.classList.toggle('is-rail', r);
158
+ try { if (innerWidth >= props.railBreakpoint) localStorage.setItem(`${props.storageKey}:pinned`, r ? '0' : '1'); } catch {}
159
+ rail.value = r;
160
+ };
161
+ if (RM() || isMobile() || !sideEl) { apply(); return; }
162
+ const collect = () => FLIP.flatMap(([s, rf]) => $$(s, sideEl).map((el) => ({ el, ref: (rf ? el.querySelector(rf) : el) ?? el, key: s + (el.dataset?.id ?? '') })));
163
+ const els = collect();
164
+ const w0 = sideEl.offsetWidth, m0 = main?.getBoundingClientRect().left ?? 0;
165
+ root.classList.toggle('is-rail', r); const w1 = sideEl.offsetWidth, m1 = main?.getBoundingClientRect().left ?? 0; root.classList.toggle('is-rail', !r);
166
+ const clip = (x) => `inset(0 ${x}px 0 0 round 22px)`;
167
+ // measure, switch, then (once Vue has drawn the new state, before the next paint) slide every icon from where
168
+ // it was: those tweens go into the rail timeline at `at` (room is kept for them there, so it does not end first)
169
+ let tl = null;
170
+ const flipIcons = (dur, ease, at) => {
171
+ const before = new Map(els.map((x) => [x.key, x.ref.getBoundingClientRect()]));
172
+ apply();
173
+ nextTick(() => {
174
+ if (!tl || railTl !== tl || !side.value) return;
175
+ const sub = g.timeline();
176
+ collect().forEach((x) => {
177
+ const b = before.get(x.key); if (!b) return;
178
+ const a = x.ref.getBoundingClientRect(), dx = b.left - a.left, dy = b.top - a.top;
179
+ if (Math.abs(dx) + Math.abs(dy) < 0.5) return;
180
+ sub.fromTo(x.el, { x: dx, y: dy }, { x: 0, y: 0, duration: dur, ease }, 0);
181
+ if (x.el.matches('.snav__item[aria-current="page"]')) sub.fromTo(pill.value, { x: dx, y: dy }, { x: 0, y: 0, duration: dur, ease }, 0);
182
+ });
183
+ tl.add(sub, at);
184
+ });
185
+ };
186
+ const cleanup = () => {
187
+ g.set(sideEl, { clearProps: 'clipPath' }); if (main) g.set(main, { clearProps: 'marginLeft' });
188
+ g.set([...$$(FADE, sideEl), ...$$('.snav__item, .brand, .collapse, .side__me', sideEl)], { clearProps: 'opacity,transform' });
189
+ g.set(pill.value, { clearProps: 'transform' }); railTl = null;
190
+ };
191
+ tl = railTl = g.timeline({ onComplete: cleanup });
192
+ if (r) {
193
+ tl.to($$(FADE, sideEl), { opacity: 0, x: -6, duration: 0.16, ease: 'power2.in', stagger: 0.004 }, 0);
194
+ tl.fromTo(sideEl, { clipPath: clip(0) }, { clipPath: clip(w0 - w1), duration: 0.42, ease: 'power3.inOut' }, 0.05);
195
+ if (main) tl.fromTo(main, { marginLeft: m0 }, { marginLeft: m1, duration: 0.42, ease: 'power3.inOut' }, 0.05);
196
+ const at = tl.duration();
197
+ tl.add(() => { g.set(sideEl, { clipPath: clip(0) }); flipIcons(0.36, 'power3.out', at); }, at);
198
+ tl.add(() => {}, at + 0.36);
199
+ } else {
200
+ flipIcons(0.45, 'power3.out', 0);
201
+ tl.fromTo(sideEl, { clipPath: clip(w1 - w0) }, { clipPath: clip(0), duration: 0.5, ease: 'expo.out' }, 0);
202
+ if (main) tl.fromTo(main, { marginLeft: m0 }, { marginLeft: m1, duration: 0.5, ease: 'expo.out' }, 0);
203
+ tl.fromTo($$(FADE, sideEl), { opacity: 0, x: -8 }, { opacity: 1, x: 0, duration: 0.4, ease: 'power3.out', stagger: 0.01 }, 0.12);
204
+ }
205
+ };
206
+ expose({ setRail: (r) => setRail(!!r), isRail: () => rail.value, get el() { return side.value; } });
207
+
208
+ /* ----- pill, sub-pages, counts ----- */
209
+ let counts = {}, shown = null;
210
+ const placePill = () => {
211
+ const el = side.value; if (!el) return;
212
+ const moved = !!shown && shown.page !== m.value.page && shown.rail === rail.value && shown.phone === phone.value; // a new page, not a boot / rail change
213
+ shown = { page: m.value.page, rail: rail.value, phone: phone.value };
214
+ M.indicator(pill.value, el.querySelector('.snav__item[aria-current="page"]'), { animate: moved && !railTl, radius: 14 });
215
+ const list = el.querySelector('.snav__subs');
216
+ if (moved && list && !list.hidden && !RM() && !railTl) {
217
+ g.fromTo(list, { height: 0, opacity: 0 }, { height: 'auto', opacity: 1, duration: 0.45, ease: 'power3.out', clearProps: 'height,opacity' });
218
+ g.fromTo(list.children, { opacity: 0, x: -8 }, { opacity: 1, x: 0, duration: 0.35, ease: 'power3.out', stagger: 0.03, delay: 0.06, clearProps: 'transform,opacity' });
219
+ }
220
+ };
221
+ const readCounts = () => { const now = {}; m.value.all.forEach((it) => { if (it.count !== undefined) now[it.id] = countOf(it); }); return now; };
222
+
223
+ // the saved choice (or a narrow window) starts it as a rail; the classes go when the sidebar does
224
+ onMounted(() => {
225
+ const root = document.documentElement;
226
+ let r = root.classList.contains('is-rail');
227
+ try { const p = localStorage.getItem(`${props.storageKey}:pinned`); if (p === '0' || (p === null && innerWidth < props.railBreakpoint)) r = true; } catch {}
228
+ root.classList.toggle('is-rail', r); rail.value = r;
229
+ O.initTips();
230
+ mq = matchMedia(`(max-width: ${props.mobile}px)`); onMq(); mq.addEventListener('change', onMq);
231
+ stopTrack = M.trackIndicator(pill.value, () => side.value?.querySelector('.snav__item[aria-current="page"]'), { radius: 14 });
232
+ counts = readCounts();
233
+ nextTick(() => {
234
+ placePill();
235
+ watch(() => `${m.value.page}\u0001${rail.value}\u0001${phone.value}`, placePill, { flush: 'post' });
236
+ });
237
+ // moving somewhere closes the phone drawer and the flyout
238
+ watch(() => props.path, () => { setSideOpen(false); closeFly(true); });
239
+ });
240
+ const onMq = () => { phone.value = !!mq?.matches; };
241
+ // numbers flash when they change
242
+ onUpdated(() => {
243
+ const now = readCounts();
244
+ for (const id in now) if (now[id] !== counts[id] && now[id] > 0) {
245
+ const c = side.value?.querySelector(`.snav__item[data-id="${CSS.escape(id)}"] .snav__count`); if (c) M.flash(c);
246
+ }
247
+ counts = now;
248
+ });
249
+ onBeforeUnmount(() => {
250
+ stopTrack?.(); stopTrack = null; mq?.removeEventListener('change', onMq); railTl?.kill(); railTl = null; flyTimer?.kill(); flyTimer = null;
251
+ if (flyEl.value) g.killTweensOf(flyEl.value);
252
+ document.documentElement.classList.remove('is-rail', 'is-sideopen');
253
+ });
254
+
255
+ const toggleSubs = () => {
256
+ const list = side.value?.querySelector('.snav__subs'); if (!list) return;
257
+ const open = subs.shut;
258
+ g.killTweensOf([list, ...list.children]);
259
+ if (open) {
260
+ subs.shut = false; subs.hidden = false;
261
+ nextTick(() => {
262
+ if (RM() || !list.isConnected) return;
263
+ g.fromTo(list, { height: 0, opacity: 0 }, { height: 'auto', opacity: 1, duration: 0.4, ease: 'power3.out', clearProps: 'height,opacity' });
264
+ g.fromTo(list.children, { opacity: 0, x: -8 }, { opacity: 1, x: 0, duration: 0.3, ease: 'power3.out', stagger: 0.03, delay: 0.05, clearProps: 'transform,opacity' });
265
+ });
266
+ } else if (RM()) { subs.shut = true; subs.hidden = true; }
267
+ else {
268
+ subs.shut = true;
269
+ g.to(list, { height: 0, opacity: 0, duration: 0.28, ease: 'power3.inOut', onComplete: () => { if (subs.shut) subs.hidden = true; nextTick(() => g.set(list, { clearProps: 'height,opacity' })); } });
270
+ }
271
+ };
272
+
273
+ /* ----- rail flyout ----- */
274
+ const openFly = (item, a) => {
275
+ if (!rail.value || isMobile()) return;
276
+ flyTimer?.kill();
277
+ if (fly.value?.id === item.id && !fly.value.out) return;
278
+ const r = a.getBoundingClientRect();
279
+ fly.value = { id: item.id, left: side.value.getBoundingClientRect().right + 10, y: r.top + r.height / 2 - 30 };
280
+ };
281
+ function closeFly(now = false) {
282
+ flyTimer?.kill();
283
+ const el = flyEl.value;
284
+ if (now || RM() || !el) { fly.value = null; return; }
285
+ if (fly.value) fly.value = { ...fly.value, out: true };
286
+ g.to(el, { opacity: 0, x: -6, duration: 0.14, ease: 'power2.in', onComplete: () => { if (fly.value?.out) fly.value = null; } });
287
+ }
288
+ const closeFlySoon = () => { flyTimer?.kill(); flyTimer = g.delayedCall(0.18, () => closeFly()); };
289
+ watch(() => `${fly.value?.id ?? ''}\u0001${!!fly.value?.out}`, () => {
290
+ const el = flyEl.value; if (!el || fly.value?.out) return;
291
+ el.style.top = Math.max(8, Math.min(fly.value.y, innerHeight - el.offsetHeight - 8)) + 'px';
292
+ if (!RM()) {
293
+ g.fromTo(el, { opacity: 0, x: -10, scale: 0.97 }, { opacity: 1, x: 0, scale: 1, duration: 0.34, ease: 'back.out(1.6)', transformOrigin: '0 30px', clearProps: 'transform,opacity', overwrite: true });
294
+ g.fromTo(el.querySelectorAll('a'), { opacity: 0, x: -6 }, { opacity: 1, x: 0, duration: 0.3, ease: 'power3.out', stagger: 0.03, delay: 0.05, clearProps: 'transform,opacity' });
295
+ }
296
+ }, { flush: 'post' });
297
+
298
+ /* ----- account menu ----- */
299
+ const openMe = (e) => {
300
+ O.bindEscape();
301
+ O.menu(e.currentTarget, toMenu([{ section: props.user.name }, ...(props.user.menu || [])]));
302
+ };
303
+
304
+ /* ----- markup ----- */
305
+ return () => {
306
+ const mm = m.value, w = W.value, l = L(), isRail = rail.value, user = props.user, brand = props.brand || { name: 'App' };
307
+ const navItem = (n) => {
308
+ const on = n.id === mm.page, c = countOf(n), list = mm.subsOf(n), open = on && !!list && (!isRail || phone.value);
309
+ return h('div', { class: 'snav__wrap', key: n.id }, [
310
+ navLink(l, {
311
+ class: 'snav__item', 'data-id': n.id, href: mm.hrefOf(n), 'aria-current': on ? 'page' : undefined,
312
+ 'aria-expanded': open ? !subs.shut : undefined, 'aria-controls': open ? `snav-subs-${n.id}` : undefined, 'aria-label': n.label,
313
+ onClick: open ? (e) => { e.preventDefault(); toggleSubs(); } : undefined,
314
+ onPointerenter: (e) => { if (M.fine.matches) openFly(n, e.currentTarget); }, onPointerleave: closeFlySoon,
315
+ onFocus: (e) => openFly(n, e.currentTarget), onBlur: closeFlySoon,
316
+ }, [iconNode(n.icon), h('span', { class: 'snav__label' }, n.label), c > 0 ? h('span', { class: 'snav__count' }, c) : null,
317
+ list && !c ? h(Icon, { name: 'chevR', class: 'snav__chev' }) : null]),
318
+ open ? h('div', { class: 'snav__subs', id: `snav-subs-${n.id}`, hidden: subs.hidden },
319
+ list.map((s) => navLink(l, { key: s.id, href: s.href, 'aria-current': s.id === mm.sub ? 'page' : undefined }, [s.label]))) : null,
320
+ ]);
321
+ };
322
+ const f = fly.value, flyItem = f && mm.itemOf(f.id);
323
+ const flyList = flyItem && mm.subsOf(flyItem), flyCount = flyItem ? countOf(flyItem) : 0;
324
+ const homeItem = mm.itemOf(props.home);
325
+ return [
326
+ h('aside', { ...attrs, class: ['side', attrs.class], id: 't-side', 'aria-label': w.sidebar, ref: side }, [
327
+ h('div', { class: 'side__head' }, [
328
+ navLink(l, { class: 'brand', href: brand.href ?? (homeItem ? mm.hrefOf(homeItem) : mm.all[0] ? mm.hrefOf(mm.all[0]) : '/'), 'aria-label': brand.name }, [
329
+ h('span', { class: 'mark' }, [iconNode(brand.icon || 'logo')]),
330
+ h('span', { class: 'brand__text' }, [h('b', null, brand.name), brand.sub ? h('small', null, brand.sub) : null]),
331
+ ]),
332
+ h('button', {
333
+ type: 'button', class: 'collapse', 'aria-label': isRail ? w.expand : w.collapse, 'data-tip': isRail ? w.expandTip : w.collapseTip,
334
+ 'data-tip-side': isRail ? 'right' : undefined, onClick: (e) => { M.pop(e.currentTarget); setRail(!rail.value); },
335
+ }, [h(Icon, { name: 'panel' })]),
336
+ ]),
337
+ h('nav', { class: 'snav', 'aria-label': w.main }, [
338
+ h('span', { class: 'snav__pill', ref: pill }),
339
+ ...(props.nav || []).map((grp, i) => h('div', { class: 'snav__group', key: i }, [grp.label ? h('span', { class: 'side__group' }, grp.label) : null, ...(grp.items || []).map(navItem)])),
340
+ props.end?.length ? h('div', { class: 'snav__group snav__group--end', key: 'end' }, props.end.map(navItem)) : null,
341
+ ]),
342
+ user ? h('div', { class: 'side__foot' }, [
343
+ h('button', { type: 'button', class: 'side__me', 'aria-label': `${user.name} — ${w.account}`, 'data-tip': isRail ? user.name : undefined, 'data-tip-side': isRail ? 'right' : undefined, onClick: openMe }, [
344
+ avatar(user, user.online ?? true),
345
+ h('span', { class: 'cell__text' }, [h('b', null, user.name), user.role ? h('small', null, user.role) : null]),
346
+ h(Icon, { name: 'sort' }),
347
+ ]),
348
+ ]) : null,
349
+ ]),
350
+ h('div', { class: 'side__scrim', onClick: () => setSideOpen(false) }),
351
+ f && flyItem ? h(Teleport, { to: 'body' }, [h('div', {
352
+ ref: flyEl, class: 'flyout', 'data-id': flyItem.id, role: 'menu', style: { left: f.left + 'px', top: f.y + 'px' },
353
+ onPointerenter: () => flyTimer?.kill(), onPointerleave: closeFlySoon,
354
+ onClick: (e) => { if (e.target.closest('a')) closeFly(); },
355
+ }, [
356
+ h('div', { class: 'flyout__head' }, [h('b', null, [flyItem.label, flyCount ? h('span', { class: 'snav__count' }, flyCount) : null]), flyItem.blurb ? h('small', null, flyItem.blurb) : null]),
357
+ ...(flyList
358
+ ? flyList.map((s) => navLink(l, { key: s.id, role: 'menuitem', href: s.href, 'aria-current': mm.page === flyItem.id && mm.sub === s.id ? 'page' : undefined }, [h(Icon, { name: 'chevR' }), s.label]))
359
+ : [navLink(l, { role: 'menuitem', href: mm.hrefOf(flyItem), 'aria-current': mm.page === flyItem.id ? 'page' : undefined }, [h(Icon, { name: 'arrowR' }), `${w.open} ${String(flyItem.label).toLowerCase()}`])]),
360
+ ])]) : null,
361
+ ];
362
+ };
363
+ },
364
+ });
365
+
366
+ /* ======================================================================= */
367
+ /* Topbar */
368
+ /* ======================================================================= */
369
+ /**
370
+ * <Topbar :nav="nav" :path="route.path" @navigate="router.push" crumbs-root="MotoRent"
371
+ * :search="{ placeholder: 'Search bikes…', onOpen: openSearch }" :bell="{ count: unread, onClick: openInbox }"
372
+ * :primary="{ label: 'New booking', icon: 'plus', run: newBooking }">…extra buttons…</Topbar>
373
+ * The bar above the page: menu button (phones), breadcrumbs from the route, a search button, your own
374
+ * buttons (default slot), a theme switch that spreads from the button, a bell whose badge pops when the number
375
+ * goes up, and one main action. It frosts over the page once you scroll. Template ref: .$el is the <header>.
376
+ */
377
+ export const Topbar = defineComponent({
378
+ name: 'Topbar',
379
+ props: {
380
+ ...navProps(), crumbsRoot: { type: String, default: '' }, search: ANY, theme: { type: Boolean, default: true }, bell: Object, primary: Object,
381
+ onSearch: Function, storageKey: { type: String, default: 'gecko' },
382
+ },
383
+ setup(props, { slots }) {
384
+ const m = modelOf(props);
385
+ const W = computed(() => wordsOf(props.words));
386
+ const top = ref(null), menuBtn = ref(null), bellBtn = ref(null), crumbs = ref(null);
387
+ const stuck = ref(false);
388
+ const count = computed(() => props.bell?.count ?? 0);
389
+ let burgerApi = null, mag = null;
390
+ const onScroll = () => { stuck.value = scrollY > 4; };
391
+ const sync = (e) => burgerApi?.set(e.detail, { silent: true });
392
+ onMounted(() => {
393
+ if (props.theme !== false) M.restoreTheme(`${props.storageKey}:theme`);
394
+ onScroll();
395
+ addEventListener('scroll', onScroll, { passive: true });
396
+ burgerApi = M.bindBurger(menuBtn.value, { controls: 't-side', escape: false, onToggle: (open) => setSideOpen(open) });
397
+ addEventListener(SIDE_EVENT, sync);
398
+ mag = M.magnetic(top.value);
399
+ // breadcrumbs slide in after a move
400
+ watch(() => `${m.value.page}\u0001${m.value.sub}`, () => { if (crumbs.value) M.slide(crumbs.value.children, { x: -6, y: 0, stagger: 0.02 }); }, { flush: 'post' });
401
+ // the bell wiggles and its badge pops when the number goes up
402
+ watch(count, (now, was) => {
403
+ if (now <= was || RM() || !bellBtn.value) return;
404
+ M.wiggle(bellBtn.value.querySelector('svg'));
405
+ g.fromTo(bellBtn.value.querySelector('.bell__n'), { scale: 0.4 }, { scale: 1, duration: 0.6, ease: 'back.out(3)' });
406
+ }, { flush: 'post' });
407
+ });
408
+ onBeforeUnmount(() => {
409
+ removeEventListener('scroll', onScroll); removeEventListener(SIDE_EVENT, sync);
410
+ burgerApi?.destroy(); burgerApi = null; mag?.destroy(); mag = null;
411
+ if (bellBtn.value) g.killTweensOf([bellBtn.value.querySelector('svg'), bellBtn.value.querySelector('.bell__n')]);
412
+ });
413
+
414
+ return () => {
415
+ const mm = m.value, w = W.value, l = { onNavigate: props.onNavigate, link: props.link };
416
+ const subLabel = mm.sub && mm.subsOf(mm.item)?.find((s) => s.id === mm.sub)?.label;
417
+ const s = props.search === false ? null : props.search || {};
418
+ const bell = props.bell, primary = props.primary;
419
+ return h('header', { class: ['top', stuck.value && 'is-stuck'], ref: top }, [
420
+ h('div', { class: 'top__in' }, [
421
+ h('button', { type: 'button', class: 'iconbtn top__menu', 'aria-label': w.menu, ref: menuBtn }, [h('span', { class: 'burger', 'aria-hidden': 'true' }, [h('i'), h('i'), h('i')])]),
422
+ h('nav', { class: 'crumbs', 'aria-label': w.breadcrumb, ref: crumbs }, [
423
+ ...(props.crumbsRoot ? [h('span', null, props.crumbsRoot), h(Icon, { name: 'chevR' })] : []),
424
+ mm.item ? navLink(l, { href: mm.hrefOf(mm.item) }, [mm.item.label]) : null,
425
+ ...(subLabel ? [h(Icon, { name: 'chevR' }), h('b', null, subLabel)] : []),
426
+ ]),
427
+ s ? h('button', { type: 'button', class: 'search', 'aria-label': w.search, onClick: () => (s.onOpen ? s.onOpen() : props.onSearch?.()) }, [
428
+ h(Icon, { name: 'search' }), h('span', null, s.placeholder || w.searchPlaceholder), h('kbd', null, w.searchKey)]) : null,
429
+ ...(slots.default?.() ?? []),
430
+ props.theme !== false ? h('button', {
431
+ type: 'button', class: 'iconbtn top__theme', 'aria-label': w.theme, 'data-tip': w.themeTip,
432
+ onClick: (e) => { M.pop(e.currentTarget); M.toggleTheme(e.currentTarget, { storageKey: `${props.storageKey}:theme` }); },
433
+ }, [h(Icon, { name: 'moon', class: 'i-moon' }), h(Icon, { name: 'sun', class: 'i-sun' })]) : null,
434
+ bell ? h('button', { type: 'button', class: 'iconbtn top__bell', 'aria-label': w.bell, 'data-tip': w.bell, ref: bellBtn, onClick: (e) => bell.onClick?.(e.currentTarget) }, [
435
+ h(Icon, { name: 'bell' }), h('span', { class: 'bell__n', hidden: !count.value }, count.value)]) : null,
436
+ primary ? h('button', { type: 'button', class: 'btn btn--primary top__new magnetic', 'data-tip': primary.tip || '', onClick: (e) => primary.run?.(e.currentTarget) }, [
437
+ iconNode(primary.icon || 'plus'), h('span', null, primary.label || w.primary)]) : null,
438
+ ]),
439
+ ]);
440
+ };
441
+ },
442
+ });
443
+
444
+ /* ======================================================================= */
445
+ /* Mobile tab bar */
446
+ /* ======================================================================= */
447
+ /**
448
+ * <MobileTabbar :nav="nav" :end="end" :path="route.path" @navigate="router.push" :tabbar="['today', 'bikes', 'bookings', 'riders']" />
449
+ * On phones (CSS: 760px and below) a tab bar sits at the bottom with your main sections; a soft highlight
450
+ * stretches to the current one and “More” lists the rest. Hidden on wider screens. Template ref: .$el is the <nav>.
451
+ */
452
+ export const MobileTabbar = defineComponent({
453
+ name: 'MobileTabbar',
454
+ props: { ...navProps(), tabbar: Array },
455
+ setup(props) {
456
+ const m = modelOf(props);
457
+ const el = ref(null), line = ref(null);
458
+ const target = () => el.value?.querySelector('a[aria-current]') || el.value?.querySelector('[data-more]');
459
+ let stopTrack = null;
460
+ onMounted(() => {
461
+ stopTrack = M.trackIndicator(line.value, target, { radius: 14 });
462
+ watch(() => m.value.page, () => { M.indicator(line.value, target(), { radius: 14 }); }, { flush: 'post', immediate: true });
463
+ });
464
+ onBeforeUnmount(() => { stopTrack?.(); stopTrack = null; });
465
+ return () => {
466
+ const mm = m.value, w = wordsOf(props.words), l = { onNavigate: props.onNavigate, link: props.link };
467
+ const ids = props.tabbar || mm.all.slice(0, 4).map((it) => it.id);
468
+ const rest = mm.all.filter((it) => !ids.includes(it.id));
469
+ return h('nav', { class: 'tabbar', 'aria-label': w.tabs, ref: el }, [
470
+ h('span', { class: 'tabbar__line', ref: line }),
471
+ ...ids.map((id) => { const it = mm.itemOf(id); return it ? navLink(l, { key: id, href: mm.hrefOf(it), 'data-id': id, 'aria-current': mm.page === id ? 'page' : undefined }, [iconNode(it.icon), h('small', null, it.label)]) : null; }),
472
+ rest.length ? h('button', {
473
+ type: 'button', 'data-more': '',
474
+ onClick: (e) => { O.bindEscape(); O.menu(e.currentTarget, toMenu(rest.map((it) => ({ icon: it.icon, label: it.label, run: () => go(props.onNavigate, mm.hrefOf(it)) }))), { align: 'end' }); },
475
+ }, [h(Icon, { name: 'menu' }), h('small', null, w.more)]) : null,
476
+ ]);
477
+ };
478
+ },
479
+ });
480
+
481
+ /* ======================================================================= */
482
+ /* Page header */
483
+ /* ======================================================================= */
484
+ /* the same markup split() from @gecko-ui-kit/motion makes, so title() animates it without touching it.
485
+ Letters are grapheme clusters, so Thai vowels and tone marks stay on their letter. */
486
+ const seg = typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function' ? new Intl.Segmenter(undefined, { granularity: 'grapheme' }) : null;
487
+ const chars = (w) => (seg ? [...seg.segment(w)].map((x) => x.segment) : [...w]);
488
+ const splitTitle = (t) => String(t).trim().split(' ').flatMap((w, i) => [
489
+ i ? ' ' : null,
490
+ h('span', { class: 'word', 'aria-hidden': 'true', key: 'w' + i }, chars(w).map((c, j) => h('span', { class: 'ch', key: j }, c))),
491
+ ]).filter((x) => x !== null);
492
+ const normTab = (t) => (Array.isArray(t) ? { id: String(t[0]), label: t[1] ?? t[0], count: t[2], href: t[3] } : { ...t, id: String(t.id) });
493
+ const filled = (x) => x != null && x !== false && x !== '';
494
+
495
+ /**
496
+ * <PageHeader eyebrow="Monday 7 December" title="Bookings" sub="Who rides what, day by day." :counts="{ requests: 3 }">
497
+ * <template #actions><Button variant="primary" icon="plus">New booking</Button></template>
498
+ * </PageHeader>
499
+ * The top of a page: an eyebrow, a big title whose letters roll up (again when it changes), a line of text,
500
+ * buttons on the right (#actions) and tabs with an underline that stretches to the chosen one.
501
+ * Inside <AppShell>, an item with sub-pages gets its sub-pages as link tabs by itself (:tabs="false" hides them).
502
+ * Or pass tabs: [{ id, label, count, href }] (or [id, label, count, href]) — with href they are links,
503
+ * without they are buttons: v-model (the chosen tab's id) + @tab-change(id).
504
+ * eyebrow / sub: text props or #eyebrow / #sub slots. Template ref → { el } (the <header>).
505
+ */
506
+ export const PageHeader = defineComponent({
507
+ name: 'PageHeader',
508
+ inheritAttrs: false,
509
+ props: { ...modelProps(), title: { type: String, default: '' }, eyebrow: ANY, sub: ANY, actions: ANY, tabs: ANY, onTabChange: Function, counts: Object, words: Object },
510
+ setup(props, { slots, attrs, expose }) {
511
+ const ctx = inject(SHELL, null);
512
+ const [chosen, choose] = useModel(props, { event: 'onTabChange' });
513
+ const el = ref(null), h1 = ref(null), line = ref(null), tabsEl = ref(null);
514
+ expose({ get el() { return el.value; } });
515
+
516
+ const tabsOf = () => {
517
+ let list = null, current = chosen.value, links = false, L = {};
518
+ if (Array.isArray(props.tabs)) { list = props.tabs.map(normTab); links = list.some((t) => t.href != null); if (ctx) L = ctx.linkProps(); }
519
+ else if (props.tabs !== false && ctx) {
520
+ const r = ctx.model.value, it = r.item, subs = r.subsOf(it);
521
+ if (subs && (it.tabs ?? ctx.tabs()) !== false) { list = subs.map((s) => ({ id: s.id, label: s.label, href: s.href })); current = r.sub; links = true; L = ctx.linkProps(); }
522
+ }
523
+ if (list && props.counts) list = list.map((t) => (props.counts[t.id] != null ? { ...t, count: props.counts[t.id] } : t));
524
+ return { list, current, links, L };
525
+ };
526
+ const state = computed(tabsOf);
527
+ const cur = () => tabsEl.value?.querySelector('[aria-current="page"], [aria-selected="true"]');
528
+
529
+ let stopTrack = null;
530
+ const track = (on) => { stopTrack?.(); stopTrack = on && line.value ? M.trackIndicator(line.value, cur, { radius: 2, line: true }) : null; };
531
+ onMounted(() => {
532
+ M.title(h1.value);
533
+ M.slide(el.value.querySelectorAll('.phead__eyebrow, .phead p, .phead__actions > *'), { y: 10, stagger: 0.05, delay: 0.12 });
534
+ if (line.value) M.indicator(line.value, cur(), { animate: false, radius: 2, line: true });
535
+ track(!!state.value.list);
536
+ watch(() => props.title, () => M.title(h1.value), { flush: 'post' });
537
+ watch(() => (typeof props.sub === 'string' ? props.sub : null), () => { const p = el.value?.querySelector('.phead p'); if (p) M.slide([p], { y: 6 }); }, { flush: 'post' });
538
+ watch(() => `${state.value.current}\u0001${!!state.value.list}`, () => { if (line.value) M.indicator(line.value, cur(), { animate: true, radius: 2, line: true }); }, { flush: 'post' });
539
+ watch(() => !!state.value.list, track, { flush: 'post' });
540
+ });
541
+ onBeforeUnmount(() => { stopTrack?.(); stopTrack = null; });
542
+
543
+ const badge = (n) => (n ? h('span', { class: 'badge' }, n) : null);
544
+ return () => {
545
+ const w = wordsOf(props.words), title = String(props.title ?? '');
546
+ const { list, current, links, L } = state.value;
547
+ const eyebrow = slots.eyebrow ? slots.eyebrow() : props.eyebrow;
548
+ const sub = slots.sub ? slots.sub() : props.sub;
549
+ const actions = slots.actions ? slots.actions() : props.actions;
550
+ return [
551
+ h('header', { ...attrs, class: ['phead', attrs.class], ref: el }, [
552
+ h('div', { class: 'phead__text' }, [
553
+ filled(eyebrow) ? h('span', { class: 'phead__eyebrow' }, eyebrow) : null,
554
+ h('h1', { ref: h1, 'data-text': title, 'data-split': title, 'aria-label': title }, splitTitle(title)),
555
+ filled(sub) ? h('p', null, sub) : null,
556
+ ]),
557
+ filled(actions) ? h('div', { class: 'phead__actions' }, actions) : null,
558
+ ]),
559
+ list ? (links
560
+ ? h('nav', { class: 'tabs', 'aria-label': w.sections, ref: tabsEl }, [h('span', { class: 'tabs__line', ref: line }),
561
+ ...list.map((t) => navLink(L, { key: t.id, href: t.href ?? '#', 'aria-current': t.id === current ? 'page' : undefined }, [t.label, badge(t.count)]))])
562
+ : h('div', { class: 'tabs', role: 'tablist', ref: tabsEl }, [h('span', { class: 'tabs__line', ref: line }),
563
+ ...list.map((t) => h('button', {
564
+ key: t.id, type: 'button', role: 'tab', 'data-v': t.id, 'aria-selected': t.id === current,
565
+ onClick: () => { if (t.id !== current) choose(t.id); },
566
+ }, [t.label, badge(t.count)]))])) : null,
567
+ ];
568
+ };
569
+ },
570
+ });
571
+
572
+ /* ======================================================================= */
573
+ /* AppShell */
574
+ /* ======================================================================= */
575
+ /**
576
+ * A script for <head> that puts the saved theme and rail on <html> before the first paint (no jump).
577
+ * Nuxt: useHead({ script: [{ innerHTML: shellBootScript({ storageKey: 'motorent' }), tagPriority: 'critical' }] })
578
+ */
579
+ export const shellBootScript = ({ storageKey = 'gecko', railBreakpoint = 1280 } = {}) =>
580
+ `try{var d=document.documentElement,k=${JSON.stringify(String(storageKey)).replace(/</g, '\\u003c')},t=localStorage.getItem(k+':theme');if(t)d.dataset.theme=t;var p=localStorage.getItem(k+':pinned');if(p==='0'||(p===null&&innerWidth<${Number(railBreakpoint) || 1280}))d.classList.add('is-rail')}catch(e){}`;
581
+
582
+ /**
583
+ * <AppShell :brand="brand" :nav="nav" :end="end" :user="me" :path="route.path" @navigate="(href) => router.push(href)"
584
+ * :link="NuxtLink" :top="{ search: { placeholder: 'Search…' }, bell: { count, onClick }, primary: { label: 'New', run } }">
585
+ * <NuxtPage />
586
+ * <template #extra>…buttons before the theme switch…</template>
587
+ * </AppShell>
588
+ * The whole frame: Sidebar (rail, flyout), Topbar, your page in <main class="view">, the phone tab bar,
589
+ * the ⌘K palette (pages + your search(q) groups), keyboard shortcuts (⌘K / search, [ rail, ? list, Esc close,
590
+ * your keys) and the intro. When the path changes the new page slides in from the direction of travel.
591
+ * Use <PageHeader> at the top of each page. useShell() inside gives { route, navigate, palette, setRail… }.
592
+ */
593
+ export const AppShell = defineComponent({
594
+ name: 'AppShell',
595
+ props: {
596
+ ...navProps(), brand: Object, user: Object, top: { type: Object, default: () => ({}) }, crumbsRoot: String, tabbar: Array,
597
+ tabs: { type: Boolean, default: true }, intro: { type: Boolean, default: true }, shortcuts: { type: Boolean, default: true },
598
+ keys: Array, search: Function, storageKey: { type: String, default: 'gecko' }, railBreakpoint: { type: Number, default: 1280 }, mobile: { type: Number, default: 760 },
599
+ },
600
+ setup(props, { slots }) {
601
+ const m = modelOf(props);
602
+ const W = computed(() => wordsOf(props.words));
603
+ const sideRef = ref(null), view = ref(null), root = ref(null);
604
+ let pal = null, introTl = null, onKey = null;
605
+ const navigate = (href) => go(props.onNavigate, href);
606
+
607
+ const palette = () => {
608
+ const mm = m.value, w = W.value, extra = props.search, t = props.top || {};
609
+ const pages = mm.all.flatMap((n) => {
610
+ const list = mm.subsOf(n), ic = typeof n.icon === 'string' ? n.icon : undefined;
611
+ return list ? list.map((s) => ({ title: String(s.label), sub: String(n.label), icon: ic, run: () => navigate(s.href) }))
612
+ : [{ title: String(n.label), sub: n.blurb || '', icon: ic, run: () => navigate(mm.hrefOf(n)) }];
613
+ });
614
+ O.bindEscape();
615
+ const l = O.palette({
616
+ placeholder: t.search?.placeholder || w.searchPages,
617
+ search: (q) => [
618
+ ...(extra?.(q) || []).map((gr) => ({ label: gr.label ?? '', items: (gr.items || []).map(({ html, ...it }) => it) })),
619
+ { label: w.goTo, items: pages.filter((p) => !q || (p.title + ' ' + p.sub).toLowerCase().includes(q)).slice(0, q ? 12 : 8) },
620
+ ],
621
+ });
622
+ if (l) pal = l;
623
+ };
624
+ const openSearch = () => { const s = props.top?.search; if (s === false) return; if (s?.onOpen) s.onOpen(); else palette(); };
625
+ const showShortcuts = () => {
626
+ const w = W.value, k = props.keys;
627
+ const list = [['⌘ K or /', w.search], ['[', w.toggleRail], ['?', w.thisList], ['Esc', w.close], ...(k || []).map((x) => [x.key, x.label])];
628
+ O.bindEscape();
629
+ O.modal({
630
+ title: esc(w.shortcuts), size: 'sm',
631
+ body: `<dl class="keys">${list.map(([kk, v]) => `<dt>${String(kk).split(' ').map((x) => (x === 'or' || x === 'then' ? `<em>${x}</em>` : `<kbd>${esc(x)}</kbd>`)).join(' ')}</dt><dd>${esc(v)}</dd>`).join('')}</dl>`,
632
+ onMount: (el) => M.slide(el.querySelectorAll('dt, dd'), { y: 6, stagger: 0.015 }),
633
+ });
634
+ };
635
+ const playIntro = () => {
636
+ const el = root.value; if (!el) return null;
637
+ introTl?.progress(1);
638
+ const side = el.querySelector('.side'), pill = el.querySelector('.snav__pill'), phone = innerWidth <= props.mobile;
639
+ M.ready.v = false;
640
+ const tl = g.timeline({ onComplete: () => { M.ready.v = true; } });
641
+ if (!phone && side) {
642
+ tl.fromTo(side, { x: -30, opacity: 0 }, { x: 0, opacity: 1, duration: D(0.7), ease: 'expo.out', clearProps: 'transform,opacity' });
643
+ tl.fromTo($$('.side__head > *, .side__group, .snav__item, .snav__subs > a, .side__foot > *', side), { opacity: 0, x: -10 }, { opacity: 1, x: 0, duration: D(0.5), ease: 'power3.out', stagger: D(0.025), clearProps: 'transform,opacity' }, D(0.1));
644
+ tl.fromTo(pill, { scale: 0.4, opacity: 0 }, { scale: 1, opacity: 1, duration: D(0.6), ease: 'back.out(2)', transformOrigin: '50% 50%', clearProps: 'transform' }, D(0.45));
645
+ }
646
+ const bits = el.querySelectorAll('.top__in > *');
647
+ if (bits.length) tl.fromTo(bits, { y: -12, opacity: 0 }, { y: 0, opacity: 1, duration: D(0.6), ease: 'expo.out', stagger: D(0.05), clearProps: 'transform,opacity' }, D(0.15));
648
+ const tb = el.querySelector('.tabbar');
649
+ if (phone && tb) tl.fromTo(tb, { y: 90 }, { y: 0, duration: D(0.7), ease: 'expo.out', clearProps: 'transform' }, D(0.2));
650
+ if (RM()) M.ready.v = true;
651
+ introTl = tl;
652
+ return tl;
653
+ };
654
+
655
+ const api = reactive({
656
+ route: computed(() => ({ page: m.value.page, sub: m.value.sub })),
657
+ path: computed(() => props.path),
658
+ navigate, palette: openSearch, shortcuts: showShortcuts, intro: () => { playIntro(); },
659
+ setRail: (r) => sideRef.value?.setRail(r), isRail: () => !!sideRef.value?.isRail(),
660
+ });
661
+ provide(SHELL, { api, model: m, tabs: () => props.tabs, linkProps: () => ({ onNavigate: props.onNavigate, link: props.link }) });
662
+
663
+ // boot: overlay width, intro, keys
664
+ onMounted(() => {
665
+ O.config.mobile = props.mobile;
666
+ if (props.intro) playIntro();
667
+ onKey = (e) => {
668
+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); openSearch(); return; }
669
+ if (e.key === 'Escape') {
670
+ if (e.defaultPrevented) return;
671
+ if (O.closeTop()) { e.preventDefault(); return; }
672
+ if (document.documentElement.classList.contains('is-sideopen')) { setSideOpen(false); root.value?.querySelector('.top__menu')?.focus(); }
673
+ return;
674
+ }
675
+ if (!props.shortcuts || e.target.closest?.('input, textarea, select, [contenteditable]') || e.metaKey || e.ctrlKey || e.altKey || O.stack.length) return;
676
+ if (e.key === '/') { e.preventDefault(); openSearch(); }
677
+ else if (e.key === '?') showShortcuts();
678
+ else if (e.key === '[') sideRef.value?.setRail(!sideRef.value.isRail());
679
+ else (props.keys || []).find((k) => String(k.key).toLowerCase() === e.key.toLowerCase())?.run?.(api);
680
+ };
681
+ addEventListener('keydown', onKey);
682
+ // a new page slides in from the direction of travel; popovers and tours close
683
+ let was = { page: m.value.page, sub: m.value.sub, rank: m.value.rank };
684
+ watch(() => `${m.value.page}\u0001${m.value.sub}`, () => {
685
+ const now = m.value, before = was; was = { page: now.page, sub: now.sub, rank: now.rank };
686
+ O.closeAll('pop'); O.closeAll('tour');
687
+ const v = view.value; if (!v || RM()) return;
688
+ const dir = now.rank >= before.rank ? 1 : -1;
689
+ g.fromTo(v, { x: dir * M.swapTiming.enter }, { x: 0, duration: M.swapTiming.in, ease: 'expo.out', overwrite: true, clearProps: 'transform' });
690
+ M.rise(v.querySelectorAll(RISE), { stagger: 0.05 });
691
+ }, { flush: 'post' });
692
+ });
693
+ onBeforeUnmount(() => {
694
+ if (onKey) removeEventListener('keydown', onKey); onKey = null;
695
+ introTl?.kill(); introTl = null; M.ready.v = true;
696
+ if (view.value) g.killTweensOf(view.value);
697
+ if (pal && !pal.closing) pal.close(); pal = null;
698
+ });
699
+
700
+ return () => {
701
+ const w = W.value, user = props.user, top = props.top || {};
702
+ const me = user ? { ...user, menu: [...(user.menu || []), ...(props.shortcuts || props.intro ? ['-'] : []),
703
+ ...(props.shortcuts ? [{ icon: 'help', label: w.shortcuts, kbd: '?', run: showShortcuts }] : []),
704
+ ...(props.intro ? [{ icon: 'refresh', label: w.replay, run: () => playIntro() }] : [])] } : null;
705
+ const bag = { nav: props.nav, end: props.end, path: props.path, base: props.base, home: props.home, onNavigate: props.onNavigate, link: props.link, words: props.words };
706
+ return h('div', { class: 't-app', ref: root }, [
707
+ h(Sidebar, { ...bag, ref: sideRef, brand: props.brand, user: me, storageKey: props.storageKey, railBreakpoint: props.railBreakpoint, mobile: props.mobile }),
708
+ h('div', { class: 't-main' }, [
709
+ h(Topbar, { ...bag, crumbsRoot: props.crumbsRoot, search: top.search, theme: top.theme, bell: top.bell, primary: top.primary, onSearch: palette, storageKey: props.storageKey }, slots.extra ? { default: () => slots.extra() } : undefined),
710
+ h('main', { class: 'view', tabindex: -1, ref: view }, slots.default?.()),
711
+ ]),
712
+ h(MobileTabbar, { ...bag, tabbar: props.tabbar }),
713
+ ]);
714
+ };
715
+ },
716
+ });