@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/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export * from './src/core.js';
2
+ export * from './src/basics.js';
3
+ export * from './src/controls.js';
4
+ export * from './src/forms.js';
5
+ export * from './src/data.js';
6
+ export * from './src/actions.js';
7
+ export * from './src/charts.js';
8
+ export * from './src/text.js';
9
+ export * from './src/motion.js';
10
+ export * from './src/effects.js';
11
+ export * from './src/overlays.js';
12
+ export * from './src/shell.js';
13
+ export * from './src/plugin.js';
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /* @gecko-ui-kit/vue — every Gecko UI Kit piece as a Vue 3 component (works in Nuxt: each one renders on the
2
+ server and wakes up in the browser). Import the CSS once (see README), then import components by name or
3
+ register them all with app.use(GeckoUI). */
4
+ export * from './src/core.js';
5
+ export * from './src/basics.js';
6
+ export * from './src/controls.js';
7
+ export * from './src/forms.js';
8
+ export * from './src/data.js';
9
+ export * from './src/actions.js';
10
+ export * from './src/charts.js';
11
+ export * from './src/text.js';
12
+ export * from './src/motion.js';
13
+ export * from './src/effects.js';
14
+ export * from './src/overlays.js';
15
+ export * from './src/shell.js';
16
+ export * from './src/plugin.js';
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@gecko-ui-kit/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Every Gecko UI Kit piece as a Vue 3 component (Nuxt ready): buttons, forms, pickers, data display, charts, motion, overlays and the app shell.",
5
+ "keywords": [
6
+ "vue",
7
+ "nuxt",
8
+ "ui",
9
+ "components",
10
+ "gsap"
11
+ ],
12
+ "homepage": "https://woraphondev.github.io/UI-Package/playground/",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/WoraphonDev/UI-Package.git",
16
+ "directory": "packages/vue"
17
+ },
18
+ "bugs": "https://github.com/WoraphonDev/UI-Package/issues",
19
+ "type": "module",
20
+ "license": "MIT",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./index.d.ts",
25
+ "default": "./index.js"
26
+ }
27
+ },
28
+ "types": "./index.d.ts",
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "src/",
33
+ "README.md"
34
+ ],
35
+ "dependencies": {
36
+ "@gecko-ui-kit/tokens": "^0.1.0",
37
+ "@gecko-ui-kit/icons": "^0.3.0",
38
+ "@gecko-ui-kit/motion": "^0.9.1",
39
+ "@gecko-ui-kit/components": "^0.21.1",
40
+ "@gecko-ui-kit/overlays": "^0.6.1",
41
+ "@gecko-ui-kit/shell": "^0.2.3"
42
+ },
43
+ "peerDependencies": {
44
+ "gsap": "^3.12.0",
45
+ "vue": ">=3.5"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }
@@ -0,0 +1,186 @@
1
+ import type { VNodeChild } from 'vue';
2
+ import type { GeckoComponent, ModelProps, IconLike, DefaultSlot } from './core.js';
3
+
4
+ /** 'accent' | 'good' | 'warn' | 'bad', a palette name ('rose', 'teal', 'amber'…) or any CSS colour. */
5
+ export type ActionTone = 'accent' | 'good' | 'warn' | 'bad' | 'indigo' | 'teal' | 'rose' | 'amber' | 'violet' | 'green' | 'slate' | 'sky' | (string & {});
6
+
7
+ /* ---------- LikeButton ---------- */
8
+ export interface LikeHandle {
9
+ readonly el: HTMLButtonElement;
10
+ readonly pressed: boolean;
11
+ /** The number shown (null when there is no count). */
12
+ readonly count: number | null;
13
+ /** Turn it on or off (counts ±1 like a click). silent (default true) skips onChange. */
14
+ set(pressed: boolean, options?: { silent?: boolean; animate?: boolean }): LikeHandle;
15
+ /** As if clicked: calls onChange. */
16
+ toggle(): LikeHandle;
17
+ /** Roll the number to n (for example from the server). */
18
+ setCount(n: number, animate?: boolean): LikeHandle;
19
+ }
20
+ export interface LikeButtonProps extends ModelProps<boolean> {
21
+ /** 'heart' (default) | 'star' | 'bookmark'. */
22
+ kind?: 'heart' | 'star' | 'bookmark';
23
+ /** A number shows a rolling count (leave it out for none). A new value rolls to it; v-model:count keeps yours in step. */
24
+ count?: number | null;
25
+ 'onUpdate:count'?: (count: number) => void;
26
+ /** The text (default per kind: Like / Star / Save). With iconOnly it is the aria-label. */
27
+ label?: string;
28
+ /** The text while on (bookmark: Saved). */
29
+ onLabel?: string;
30
+ /** A round icon button; the label (and count) become its aria-label. */
31
+ iconOnly?: boolean;
32
+ size?: '' | 'sm' | 'lg';
33
+ /** The "on" colour. */
34
+ tone?: ActionTone;
35
+ /** Writes the count (default toLocaleString). */
36
+ format?: (n: number) => string;
37
+ words?: { like?: string; star?: string; save?: string; saved?: string; withCount?: (label: string, count: string) => string };
38
+ /** It was clicked. Return a promise: if it fails, the button (and v-model) goes back and shakes. */
39
+ onChange?: (pressed: boolean, count: number | null, handle: LikeHandle) => unknown;
40
+ }
41
+ /** <LikeButton kind="heart" v-model="liked" :count="128" @change="(on) => api.like(id, on)" /> — template ref → LikeHandle */
42
+ export const LikeButton: GeckoComponent<LikeButtonProps>;
43
+
44
+ /* ---------- BellSwitch ---------- */
45
+ export interface BellHandle {
46
+ readonly el: HTMLButtonElement;
47
+ readonly on: boolean;
48
+ /** Switch it on or off. silent (default true) skips onChange. */
49
+ set(on: boolean, options?: { silent?: boolean; animate?: boolean }): BellHandle;
50
+ /** As if clicked: calls onChange. */
51
+ toggle(): BellHandle;
52
+ /** Ring the bell again (something new came in). */
53
+ ring(): unknown;
54
+ }
55
+ export interface BellSwitchProps extends ModelProps<boolean> {
56
+ /** The visible name (default words.label, "Notifications"), or the #label slot. With iconOnly it is the aria-label. */
57
+ label?: string;
58
+ /** Only the round bell. */
59
+ iconOnly?: boolean;
60
+ /** The "on" colour. */
61
+ tone?: ActionTone;
62
+ words?: { label?: string; on?: string; off?: string };
63
+ /** It was switched. Return a promise: if it fails, it (and v-model) switches back and shakes. */
64
+ onChange?: (on: boolean, handle: BellHandle) => unknown;
65
+ }
66
+ /** <BellSwitch v-model="alerts" label="Booking alerts" @change="save" /> — template ref → BellHandle */
67
+ export const BellSwitch: GeckoComponent<BellSwitchProps, { label?: () => VNodeChild }>;
68
+ /** The same component as BellSwitch. */
69
+ export const BellButton: typeof BellSwitch;
70
+
71
+ /* ---------- PayButton ---------- */
72
+ export interface PayHandle {
73
+ readonly el: HTMLButtonElement;
74
+ readonly state: 'idle' | 'busy' | 'done' | 'failed';
75
+ /** Start paying, as if pressed. Resolves true (paid) or false (failed). */
76
+ pay(): Promise<boolean>;
77
+ /** Back to the start. */
78
+ reset(): PayHandle;
79
+ }
80
+ export interface PayButtonProps {
81
+ /** The idle text (default words.label, "Pay now"), or the #label / default slot. */
82
+ label?: string;
83
+ /** 'dark' (default) | 'primary'. */
84
+ variant?: 'dark' | 'primary' | (string & {});
85
+ /** 'lg' (default) | '' | 'sm'. */
86
+ size?: 'lg' | '' | 'sm';
87
+ /** Fill the row. */
88
+ block?: boolean;
89
+ /** Before the label: an icon name or a component ('card' by default, '' = none). */
90
+ icon?: IconLike;
91
+ /** The card swiping through the slot (default true). */
92
+ card?: boolean;
93
+ /** Seconds "Processing" shows at least (default 1.4). */
94
+ minBusy?: number;
95
+ /** Seconds before it returns to the start after paying (default 3; 0 = stays "Paid"). */
96
+ back?: number;
97
+ words?: { label?: string; busy?: string; done?: string; retry?: string; sayBusy?: string; sayDone?: string; sayFail?: string | ((error: unknown) => string) };
98
+ /** Runs while busy: resolve = paid; throw, reject or return false = failed. */
99
+ onPay?: (handle: PayHandle) => unknown;
100
+ /** Paid: gets what onPay resolved with. */
101
+ onDone?: (result: unknown, handle: PayHandle) => void;
102
+ /** Failed: gets the error. */
103
+ onFail?: (error: unknown, handle: PayHandle) => void;
104
+ }
105
+ /** <PayButton block @pay="() => checkout(cart)">Pay <b>฿700</b></PayButton> — template ref → PayHandle */
106
+ export const PayButton: GeckoComponent<PayButtonProps, DefaultSlot & { label?: () => VNodeChild }>;
107
+
108
+ /* ---------- SpeedDial ---------- */
109
+ export interface SpeedDialAction {
110
+ id?: string;
111
+ label: string;
112
+ /** An icon name or an <svg> string. */
113
+ icon?: string;
114
+ /** Called when this action is picked (before onSelect). */
115
+ onClick?: (action: SpeedDialAction, dial: SpeedDialHandle) => void;
116
+ [key: string]: unknown;
117
+ }
118
+ export interface SpeedDialHandle {
119
+ readonly el: HTMLElement;
120
+ readonly isOpen: boolean;
121
+ readonly actions: SpeedDialAction[];
122
+ /** Fan the actions out. focus: move the focus to the nearest action. */
123
+ open(options?: { focus?: boolean }): SpeedDialHandle;
124
+ /** Fold them away. focus: give the focus back to the button. */
125
+ close(options?: { focus?: boolean }): SpeedDialHandle;
126
+ toggle(): SpeedDialHandle;
127
+ /** New actions (closes first). */
128
+ setActions(actions: SpeedDialAction[]): SpeedDialHandle;
129
+ destroy(): void;
130
+ }
131
+ export interface SpeedDialProps {
132
+ actions: SpeedDialAction[];
133
+ /** Where the actions fan out (default 'up'). */
134
+ direction?: 'up' | 'down';
135
+ /** Which edge the button sits on (default 'right'); labels point inwards. */
136
+ side?: 'right' | 'left';
137
+ /** false = icons only (default true). */
138
+ labels?: boolean;
139
+ /** Pinned to the corner of the screen (--sd-x / --sd-y set the gap). */
140
+ fixed?: boolean;
141
+ /** The main button's icon (default 'plus'; it turns into an ×). */
142
+ icon?: string;
143
+ /** label names the main button; actions names the list. */
144
+ words?: { label?: string; actions?: string };
145
+ /** An action was picked. */
146
+ onSelect?: (action: SpeedDialAction, dial: SpeedDialHandle) => void;
147
+ /** It opened or closed. */
148
+ onToggle?: (open: boolean, dial: SpeedDialHandle) => void;
149
+ }
150
+ /** <SpeedDial :actions="[{ id: 'booking', label: 'New booking', icon: 'calendar' }]" @select="(a) => …" /> — template ref → SpeedDialHandle */
151
+ export const SpeedDial: GeckoComponent<SpeedDialProps>;
152
+
153
+ /* ---------- Typing ---------- */
154
+ export interface TypingHandle {
155
+ readonly el: HTMLElement;
156
+ readonly visible: boolean;
157
+ /** The text it says now ("Pim is typing…"). */
158
+ readonly text: string;
159
+ readonly root: HTMLElement;
160
+ show(names?: string | string[]): TypingHandle;
161
+ hide(): TypingHandle;
162
+ toggle(on?: boolean): TypingHandle;
163
+ /** Change who is typing. */
164
+ set(names: string | string[]): TypingHandle;
165
+ destroy(): void;
166
+ }
167
+ export interface TypingProps {
168
+ /** Shown or hidden (default false); changes animate in place. */
169
+ visible?: boolean;
170
+ /** Who is typing: 'Pim' or ['Pim', 'Mali'] (empty = no name). */
171
+ names?: string | string[];
172
+ /** The text beside the bubble (default true; screen readers hear it either way). */
173
+ text?: boolean;
174
+ /** false: only the dots, for inside a list row or a button. */
175
+ bubble?: boolean;
176
+ size?: '' | 'sm' | 'lg';
177
+ /** Colour of the dots (default 'muted'). */
178
+ tone?: 'muted' | 'accent' | 'ink';
179
+ /** The row closes up when hidden (default true). */
180
+ collapse?: boolean;
181
+ words?: { anon?: string; one?: (name: string) => string; two?: (a: string, b: string) => string; many?: (names: string[]) => string };
182
+ }
183
+ /** <Typing :visible="typing" :names="['Pim']" /> — template ref → TypingHandle */
184
+ export const Typing: GeckoComponent<TypingProps>;
185
+
186
+ export {};
package/src/actions.js ADDED
@@ -0,0 +1,329 @@
1
+ /* Action buttons and status as Vue components: LikeButton, BellSwitch (BellButton), PayButton, SpeedDial, Typing.
2
+
3
+ LikeButton, BellSwitch and PayButton draw the same HTML as the vanilla builders (likeBtn(), bellBtn(),
4
+ payBtn()) with Vue, so they render on the server (Nuxt), then the vanilla code wires that very button for the
5
+ clicks and the little shows. The parts the vanilla code changes later (aria-pressed, the count, the
6
+ "On / Off" line…) are drawn once from the first value and never redrawn by Vue, so the two never fight;
7
+ value changes go through the handle (set(), setCount()). SpeedDial and Typing are mounted pieces. */
8
+ import { defineComponent, ref, computed, watch, onMounted, onUpdated, onBeforeUnmount, nextTick, useId, normalizeClass } from 'vue';
9
+ import * as C from '@gecko-ui-kit/components';
10
+ import * as M from '@gecko-ui-kit/motion';
11
+ import { h, B, ANY, anyProps, iconNode, Icon, mounted, changedOnly, same, snap, modelProps } from './core.js';
12
+
13
+ /* A value for expose() that stays the same object and forwards to the live vanilla handle (its methods and `el`). */
14
+ function handleOf(cur) {
15
+ return new Proxy({}, {
16
+ get(t, k) {
17
+ if (k in t) return t[k]; // Vue's own marks (__v_skip)
18
+ const x = cur.current; if (!x) return undefined;
19
+ const v = x[k]; return typeof v === 'function' ? v.bind(x) : v;
20
+ },
21
+ has(t, k) { if (k in t) return true; const x = cur.current; return !!x && k in x; },
22
+ });
23
+ }
24
+
25
+ const TONES = { accent: 'var(--accent)', good: 'var(--good)', warn: 'var(--warn)', bad: 'var(--bad)' };
26
+ const HUES = ['indigo', 'teal', 'rose', 'amber', 'violet', 'green', 'slate', 'sky'];
27
+ const toColor = (t) => (!t ? '' : TONES[t] || (HUES.includes(t) ? `var(--hue-${t})` : String(t)));
28
+ const wordsKey = (w) => JSON.stringify(snap(w) || {}); // the text words (functions are read live or ignored)
29
+ const isThenable = (r) => !!r && typeof r.then === 'function';
30
+ /* After a promise from onChange fails, the vanilla piece switches back: tell v-model about it too. */
31
+ const onFail = (r, fn) => { if (isThenable(r)) Promise.resolve(r).catch(() => Promise.resolve().then(fn)); };
32
+
33
+ /* ------------------------------------------------------------------ LikeButton */
34
+ const LK_WORDS = { like: 'Like', star: 'Star', save: 'Save', saved: 'Saved', withCount: (label, count) => `${label}, ${count}` };
35
+ const LK_KINDS = ['heart', 'star', 'bookmark'];
36
+ const lkPath = {}; // the outline of each kind, read from likeBtn() so it never drifts from the vanilla one
37
+ const lkShape = (kind) => (lkPath[kind] ??= /<path d="([^"]+)"/.exec(C.likeBtn({ kind, iconOnly: true }))?.[1] ?? '');
38
+ const lkSvg = (kind) => h('svg', { viewBox: '0 0 24 24', 'aria-hidden': 'true', focusable: 'false' }, [h('path', { d: lkShape(kind) })]);
39
+ const lkCount = (n) => Math.max(0, Math.round(+n || 0));
40
+
41
+ /**
42
+ * <LikeButton kind="heart" v-model="liked" v-model:count="likes" @change="(on) => api.like(bike.id, on)" />
43
+ * Same markup as likeBtn(options), wired by likeButton(): the heart / star pops with a burst, the bookmark fills,
44
+ * the count rolls. v-model = pressed (or default-value without v-model); v-model:count keeps your number in step.
45
+ * @change(pressed, count, handle): return a promise and the button goes back (with a shake) if it fails, and so do
46
+ * v-model and v-model:count. A new `count` rolls to it. Template ref → { pressed, count, set, toggle, setCount, el }.
47
+ */
48
+ export const LikeButton = defineComponent({
49
+ name: 'LikeButton',
50
+ props: {
51
+ ...modelProps(), kind: String, count: ANY, label: String, onLabel: String, iconOnly: B, size: { type: String, default: '' },
52
+ tone: String, format: Function, words: ANY, onChange: Function, 'onUpdate:count': Function,
53
+ },
54
+ setup(props, { expose }) {
55
+ const btn = ref(null), cur = { current: null };
56
+ const proxy = handleOf(cur);
57
+ expose(proxy);
58
+ const controlled = () => props.modelValue !== undefined;
59
+ const view = computed(() => {
60
+ const k = LK_KINDS.includes(props.kind) ? props.kind : 'heart';
61
+ const W = { ...LK_WORDS, ...snap(props.words) };
62
+ const L = props.label ?? (k === 'bookmark' ? W.save : k === 'star' ? W.star : W.like);
63
+ const OL = props.onLabel ?? (k === 'bookmark' ? W.saved : '');
64
+ const hasCount = props.count != null && props.count !== '';
65
+ const iconOnly = !!props.iconOnly;
66
+ return { k, W, L, OL, hasCount, iconOnly, swap: !iconOnly && !!OL && OL !== L, shape: JSON.stringify([k, L, OL, iconOnly, hasCount, wordsKey(props.words)]) };
67
+ });
68
+ const fmt = (n) => (props.format ? String(props.format(n)) : n.toLocaleString());
69
+
70
+ /* what Vue draws for the parts likeButton() changes later: the first value, kept until the shape changes */
71
+ let s = null;
72
+ const keep = () => {
73
+ const v = view.value;
74
+ if (s && s.shape === v.shape) return s;
75
+ const x = cur.current;
76
+ const on = controlled() ? !!props.modelValue : x ? x.pressed : !!props.defaultValue;
77
+ const n = v.hasCount ? (x?.count ?? lkCount(props.count)) : null;
78
+ return (s = { shape: v.shape, on, n, num: n == null ? '' : fmt(n), aria: n == null ? v.L : v.W.withCount(v.L, fmt(n)) });
79
+ };
80
+
81
+ /* keep the vanilla state in step with the props (also after a click the parent did not take) */
82
+ const sync = () => {
83
+ const x = cur.current; if (!x) return;
84
+ if (controlled() && x.pressed !== !!props.modelValue) x.set(!!props.modelValue, { silent: true });
85
+ };
86
+ const wire = () => {
87
+ const x = C.likeButton(btn.value, {
88
+ words: snap(props.words),
89
+ format: (n) => fmt(n),
90
+ onChange: (on, n) => {
91
+ props['onUpdate:modelValue']?.(on);
92
+ if (n != null) props['onUpdate:count']?.(n);
93
+ const r = props.onChange?.(on, n, proxy);
94
+ onFail(r, () => { // the button went back: so does v-model
95
+ if (cur.current !== x || x.pressed === on) return;
96
+ props['onUpdate:modelValue']?.(x.pressed);
97
+ if (x.count != null) props['onUpdate:count']?.(x.count);
98
+ });
99
+ // v-model that did not take the new value (the parent keeps it): show the parent's value again
100
+ if (controlled()) nextTick(() => { if (cur.current === x && controlled() && !!props.modelValue !== on && x.pressed === on) sync(); });
101
+ return r;
102
+ },
103
+ });
104
+ cur.current = x;
105
+ };
106
+ const unwire = () => { const x = cur.current; cur.current = null; x?.destroy(); };
107
+
108
+ onMounted(() => {
109
+ wire();
110
+ watch(() => [view.value.shape, props.modelValue, snap(props.count)], ([shape, , n], [pshape, , pn]) => {
111
+ if (shape !== pshape) { unwire(); wire(); }
112
+ sync();
113
+ const x = cur.current;
114
+ if (x && view.value.hasCount && !same(n, pn) && x.count !== lkCount(n)) x.setCount(lkCount(n));
115
+ }, { flush: 'post' });
116
+ });
117
+ onBeforeUnmount(unwire);
118
+
119
+ return () => {
120
+ const { k, L, OL, hasCount, iconOnly, swap, shape } = view.value;
121
+ const st = keep();
122
+ const c = toColor(props.tone);
123
+ return h('button', {
124
+ key: shape, ref: btn, type: 'button',
125
+ class: ['lk', 'lk--' + k, iconOnly && 'lk--icon', props.size && 'lk--' + props.size],
126
+ 'aria-pressed': String(st.on), 'data-kind': k, 'data-label': L, 'data-on-label': OL || undefined, 'data-count': hasCount ? st.n : undefined,
127
+ style: c ? { '--lk-c': c } : undefined,
128
+ ...(iconOnly ? { 'aria-label': st.aria } : null),
129
+ }, [
130
+ h('span', { class: 'lk__icon', 'aria-hidden': 'true' }, [
131
+ k === 'bookmark' ? null : h('span', { class: 'lk__ring' }),
132
+ h('span', { class: 'lk__bits' }, Array.from({ length: k === 'bookmark' ? 4 : 8 }, () => h('i'))),
133
+ h('span', { class: 'lk__glyph' }, [h('span', { class: 'lk__line' }, [lkSvg(k)]), h('span', { class: 'lk__solid' }, [lkSvg(k)])]),
134
+ ].filter(Boolean)),
135
+ ...(iconOnly ? [] : [
136
+ swap ? h('span', { class: 'lk__sr' }, L) : null,
137
+ h('span', { class: 'lk__label', 'aria-hidden': swap ? 'true' : undefined }, st.on && swap ? OL : L),
138
+ hasCount ? h('span', { class: 'lk__count' }, [h('span', { class: 'lk__num' }, st.num)]) : null,
139
+ ].filter(Boolean)),
140
+ ]);
141
+ };
142
+ },
143
+ });
144
+
145
+ /* ------------------------------------------------------------------ BellSwitch */
146
+ const NB_WORDS = { label: 'Notifications', on: 'On', off: 'Off' };
147
+ const nbSvg = {}; // the bell drawing from bellBtn(), on and off (library geometry, no app data)
148
+ const bellSvg = (on) => (nbSvg[on] ??= /<svg[\s\S]*<\/svg>/.exec(C.bellBtn({ on, iconOnly: true }))?.[0] ?? '');
149
+
150
+ /**
151
+ * <BellSwitch v-model="alerts" label="Booking alerts" @change="(on) => saveSetting('booking-alerts', on)" />
152
+ * Same markup as bellBtn(options), wired by bellSwitch(): on rings the bell, off draws a slash across it.
153
+ * v-model = on (or default-value). @change(on, handle): return a promise and it switches back (with a shake) if it
154
+ * fails, v-model too. label: text, or the #label slot. Template ref → { on, set, toggle, ring, el }: ring() when
155
+ * something new comes in. BellButton is the same component.
156
+ */
157
+ export const BellSwitch = defineComponent({
158
+ name: 'BellSwitch',
159
+ props: { ...modelProps(), label: String, iconOnly: B, tone: String, words: ANY, onChange: Function },
160
+ setup(props, { slots, expose }) {
161
+ const id = useId();
162
+ const btn = ref(null), cur = { current: null };
163
+ const proxy = handleOf(cur);
164
+ expose(proxy);
165
+ const controlled = () => props.modelValue !== undefined;
166
+ const W = computed(() => ({ ...NB_WORDS, ...snap(props.words) }));
167
+ const shape = computed(() => JSON.stringify([!!props.iconOnly, W.value.on, W.value.off]));
168
+
169
+ let s = null;
170
+ const keep = () => {
171
+ if (s && s.shape === shape.value) return s;
172
+ const on = controlled() ? !!props.modelValue : cur.current ? cur.current.on : !!props.defaultValue;
173
+ return (s = { shape: shape.value, on });
174
+ };
175
+ const sync = () => {
176
+ const x = cur.current;
177
+ if (x && controlled() && x.on !== !!props.modelValue) x.set(!!props.modelValue, { silent: true });
178
+ };
179
+ const wire = () => {
180
+ const x = C.bellSwitch(btn.value, {
181
+ words: snap(props.words),
182
+ onChange: (v) => {
183
+ props['onUpdate:modelValue']?.(v);
184
+ const r = props.onChange?.(v, proxy);
185
+ onFail(r, () => { if (cur.current === x && x.on !== v) props['onUpdate:modelValue']?.(x.on); });
186
+ if (controlled()) nextTick(() => { if (cur.current === x && controlled() && !!props.modelValue !== v && x.on === v) sync(); });
187
+ return r;
188
+ },
189
+ });
190
+ cur.current = x;
191
+ };
192
+ const unwire = () => { const x = cur.current; cur.current = null; x?.destroy(); };
193
+
194
+ onMounted(() => {
195
+ wire();
196
+ watch(() => [shape.value, props.modelValue], ([sh], [psh]) => {
197
+ if (sh !== psh) { unwire(); wire(); }
198
+ sync();
199
+ }, { flush: 'post' });
200
+ });
201
+ onBeforeUnmount(unwire);
202
+
203
+ return () => {
204
+ const w = W.value, st = keep(), iconOnly = !!props.iconOnly;
205
+ const c = toColor(props.tone);
206
+ const name = props.label ?? w.label;
207
+ return h('button', {
208
+ key: st.shape, ref: btn, type: 'button', role: 'switch',
209
+ class: ['nbell', iconOnly && 'nbell--icon'],
210
+ 'aria-checked': String(st.on),
211
+ ...(iconOnly ? { 'aria-label': name } : { 'aria-labelledby': id }),
212
+ 'data-on-text': w.on, 'data-off-text': w.off,
213
+ style: c ? { '--nb-c': c } : undefined,
214
+ }, [
215
+ h('span', { class: 'nbell__icon', innerHTML: bellSvg(st.on) }),
216
+ iconOnly ? null : h('span', { class: 'nbell__text' }, [
217
+ h('b', { class: 'nbell__label', id }, slots.label ? slots.label() : name),
218
+ h('small', { class: 'nbell__state', 'aria-hidden': 'true' }, [h('span', null, st.on ? w.on : w.off)]),
219
+ ]),
220
+ ].filter(Boolean));
221
+ };
222
+ },
223
+ });
224
+ /** The same component as BellSwitch, under the name of the vanilla builder bellBtn(). */
225
+ export const BellButton = BellSwitch;
226
+
227
+ /* ------------------------------------------------------------------ PayButton */
228
+ const PAY_WORDS = { label: 'Pay now', busy: 'Processing', done: 'Paid', retry: 'Try again' };
229
+ const PAY_STATES = ['is-busy', 'is-done', 'is-failed'];
230
+
231
+ /**
232
+ * <PayButton block @pay="() => checkout(cart)" @done="(receipt) => show(receipt)" @fail="(e) => …">Pay <b>฿{{ total }}</b></PayButton>
233
+ * Same markup as payBtn(options), wired by payButton(): press it and a card swipes through, "Processing", then
234
+ * "Paid" with a tick (onPay resolved) or red "Try again" (onPay threw, rejected or returned false).
235
+ * The label: the `label` text, the #label slot or the default slot. Template ref → { state, pay(), reset(), el }.
236
+ */
237
+ export const PayButton = defineComponent({
238
+ name: 'PayButton',
239
+ props: {
240
+ label: String, variant: { type: String, default: 'dark' }, size: { type: String, default: 'lg' }, block: B,
241
+ icon: { type: null, default: 'card' }, card: { type: Boolean, default: true }, minBusy: { type: Number, default: 1.4 }, back: { type: Number, default: 3 },
242
+ words: ANY, onPay: Function, onDone: Function, onFail: Function,
243
+ },
244
+ setup(props, { slots, attrs, expose }) {
245
+ const btn = ref(null), cur = { current: null };
246
+ const proxy = handleOf(cur);
247
+ expose(proxy);
248
+ const W = computed(() => ({ ...PAY_WORDS, ...snap(props.words) }));
249
+ const cls = () => normalizeClass(['btn', props.variant && 'btn--' + props.variant, props.size && 'btn--' + props.size, props.block && 'btn--block', 'pay']);
250
+
251
+ /* the vanilla code's state classes (is-busy…), put back after Vue wrote a new class list */
252
+ const states = () => {
253
+ const x = cur.current, b = btn.value; if (!x || !b) return;
254
+ PAY_STATES.forEach((c) => b.classList.toggle(c, c === 'is-' + (x.state === 'failed' ? 'failed' : x.state)));
255
+ b.classList.toggle('is-still', x.state === 'busy' && M.RM());
256
+ };
257
+ const wire = () => {
258
+ cur.current = C.payButton(btn.value, {
259
+ words: snap(props.words), card: props.card, minBusy: props.minBusy, back: props.back,
260
+ onPay: () => props.onPay?.(proxy),
261
+ onDone: (r) => props.onDone?.(r, proxy),
262
+ onFail: (e) => props.onFail?.(e, proxy),
263
+ });
264
+ };
265
+ const unwire = () => { const x = cur.current; cur.current = null; x?.destroy(); };
266
+ let lastCls = null;
267
+
268
+ onMounted(() => {
269
+ wire();
270
+ lastCls = normalizeClass([cls(), attrs.class]);
271
+ watch(() => wordsKey(props.words), () => { unwire(); wire(); states(); }, { flush: 'post' });
272
+ watch(() => [props.card, props.minBusy, props.back], ([card, minBusy, back]) => { const x = cur.current; if (x) Object.assign(x.opts, { card, minBusy, back }); });
273
+ });
274
+ onUpdated(() => {
275
+ const now = normalizeClass([cls(), attrs.class]);
276
+ if (now !== lastCls) { lastCls = now; states(); }
277
+ });
278
+ onBeforeUnmount(unwire);
279
+
280
+ return () => {
281
+ const w = W.value;
282
+ const label = slots.label ? slots.label() : slots.default ? slots.default() : props.label ?? w.label;
283
+ return h('button', { ref: btn, type: 'button', class: cls() }, [
284
+ h('span', { class: 'pay__face pay__idle' }, [iconNode(props.icon || null), h('span', { class: 'pay__label' }, label)].filter(Boolean)),
285
+ h('span', { class: 'pay__face pay__busy', 'aria-hidden': 'true' }, [h('span', null, w.busy), h('span', { class: 'pay__dots' }, [h('i'), h('i'), h('i')])]),
286
+ h('span', { class: 'pay__face pay__done', 'aria-hidden': 'true' }, [
287
+ h('svg', { class: 'pay__tick', viewBox: '0 0 24 24', 'aria-hidden': 'true', focusable: 'false' },
288
+ [h('path', { d: 'm5 12.5 4.5 4.5L19 7.5', pathLength: 1, 'stroke-dasharray': '1 2', 'stroke-dashoffset': 1 })]),
289
+ h('span', null, w.done),
290
+ ]),
291
+ h('span', { class: 'pay__face pay__fail', 'aria-hidden': 'true' }, [h(Icon, { name: 'alert' }), h('span', null, w.retry)]),
292
+ h('span', { class: 'pay__slot', 'aria-hidden': 'true' }, [h('i')]),
293
+ h('span', { class: 'pay__card', 'aria-hidden': 'true' }),
294
+ ]);
295
+ };
296
+ },
297
+ });
298
+
299
+ /* ------------------------------------------------------------------ SpeedDial */
300
+ /**
301
+ * <SpeedDial :actions="[{ id: 'booking', label: 'New booking', icon: 'calendar' }, …]" @select="(a) => go(a.id)" />
302
+ * Same as speedDial(el, options): the + turns into an × and the actions spring out. New `actions` are swapped in
303
+ * place (setActions). @select(action, handle), @toggle(open, handle).
304
+ * Template ref → { isOpen, open(), close(), toggle(), setActions(list), el }.
305
+ */
306
+ export const SpeedDial = mounted('SpeedDial', C.speedDial, {
307
+ props: { ...anyProps('actions', 'direction', 'side', 'icon', 'words'), labels: B, fixed: B, onSelect: Function, onToggle: Function },
308
+ update(d, next, prev) {
309
+ if (changedOnly(next, prev, ['actions'])) { d.setActions(next.actions || []); return true; }
310
+ return false;
311
+ },
312
+ });
313
+
314
+ /* ------------------------------------------------------------------ Typing */
315
+ /**
316
+ * <Typing :visible="othersTyping" :names="['Pim']" />
317
+ * Same as typing(el, options): three bouncing dots in a bubble with "Pim is typing…". `visible` shows / hides it
318
+ * (the row opens and closes), `names` changes who, both in place.
319
+ * Template ref → { visible, text, show(), hide(), set(), el }.
320
+ */
321
+ export const Typing = mounted('Typing', C.typing, {
322
+ props: { ...anyProps('names', 'size', 'tone', 'words'), visible: B, text: B, bubble: B, collapse: B },
323
+ update(t, next, prev) {
324
+ if (!changedOnly(next, prev, ['visible', 'names'])) return false;
325
+ if (!same(next.names, prev.names)) t.set(next.names ?? []);
326
+ if (!!next.visible !== t.visible) (next.visible ? t.show() : t.hide());
327
+ return true;
328
+ },
329
+ });