@open-slide/core 1.19.0 → 2.0.0-beta.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/dist/{build-CaV_vhIw.js → build-CfAxF6Dm.js} +2 -5
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +139 -13
- package/dist/{config-CDHB8Oow.d.ts → config-AtA2Bqtn.d.ts} +4 -4
- package/dist/{config-GA6NMgs_.js → config-C_VI2EpT.js} +545 -776
- package/dist/{design-cpzS8aud.js → design-Cpqx7SJs.js} +1 -2
- package/dist/{dev-D57ui2yV.js → dev-BChELmc-.js} +4 -7
- package/dist/index.d.ts +7 -37
- package/dist/index.js +51 -54
- package/dist/locale/index.d.ts +2 -8
- package/dist/locale/index.js +13 -3
- package/dist/{preview-D40Zw_o0.js → preview-CcCQa268.js} +3 -7
- package/dist/{types-8HghULIe.d.ts → types-BzPSOxe-.d.ts} +5 -9
- package/dist/vite/index.d.ts +1 -4
- package/dist/vite/index.js +2 -4
- package/dist/{format-74A3B6zu.js → zh-tw-BxZ_pYqe.js} +13 -49
- package/package.json +12 -12
- package/skills/create-slide/SKILL.md +4 -1
- package/skills/slide-authoring/SKILL.md +25 -2
- package/src/app/app.tsx +18 -15
- package/src/app/assets/open-slide.png +0 -0
- package/src/app/components/asset-view.tsx +46 -39
- package/src/app/components/command/command-menu.tsx +5 -1
- package/src/app/components/command/command.tsx +4 -2
- package/src/app/components/command/home-command-menu.tsx +6 -6
- package/src/app/components/export-progress-toast.tsx +80 -0
- package/src/app/components/history-provider.tsx +1 -5
- package/src/app/components/icon-tooltip.tsx +24 -15
- package/src/app/components/image-placeholder.tsx +4 -12
- package/src/app/components/inspector/asset-picker-dialog.tsx +24 -32
- package/src/app/components/inspector/comment-widget.tsx +33 -7
- package/src/app/components/inspector/image-crop-dialog.tsx +9 -6
- package/src/app/components/inspector/inline-text-editor.tsx +798 -0
- package/src/app/components/inspector/inspect-overlay.tsx +35 -76
- package/src/app/components/inspector/inspector-panel.tsx +31 -53
- package/src/app/components/inspector/inspector-provider.tsx +53 -36
- package/src/app/components/language-toggle.tsx +2 -3
- package/src/app/components/notes-drawer.tsx +4 -7
- package/src/app/components/overview-grid.tsx +15 -8
- package/src/app/components/panel/panel-shell.tsx +1 -3
- package/src/app/components/panel/save-card.tsx +12 -3
- package/src/app/components/player.tsx +5 -6
- package/src/app/components/present/blackout-overlay.tsx +16 -3
- package/src/app/components/present/control-bar.tsx +21 -13
- package/src/app/components/present/jump-input.tsx +27 -5
- package/src/app/components/present/laser-pointer.tsx +34 -11
- package/src/app/components/present/progress-bar.tsx +1 -1
- package/src/app/components/present/use-presenter-channel.ts +0 -1
- package/src/app/components/present/use-touch-swipe.ts +9 -2
- package/src/app/components/sidebar/folder-item.tsx +48 -21
- package/src/app/components/sidebar/icon-picker.tsx +1 -1
- package/src/app/components/sidebar/sidebar-footer.tsx +20 -7
- package/src/app/components/sidebar/sidebar.tsx +91 -64
- package/src/app/components/slide-canvas.tsx +2 -6
- package/src/app/components/slide-transition-layer.tsx +48 -76
- package/src/app/components/style-panel/design-provider.tsx +1 -14
- package/src/app/components/style-panel/style-panel.tsx +16 -12
- package/src/app/components/style-panel/use-design.ts +1 -28
- package/src/app/components/theme-toggle.tsx +4 -5
- package/src/app/components/themes/theme-detail.tsx +11 -8
- package/src/app/components/themes/themes-gallery.tsx +13 -8
- package/src/app/components/thumbnail-rail.tsx +14 -15
- package/src/app/index.html +21 -0
- package/src/app/lib/assets.ts +6 -7
- package/src/app/lib/dom.ts +42 -0
- package/src/app/lib/export-html.ts +10 -25
- package/src/app/lib/export-pdf.ts +11 -28
- package/src/app/lib/export-pptx.ts +6 -36
- package/src/app/lib/folders.ts +51 -46
- package/src/app/lib/inspector/inline-text.ts +31 -0
- package/src/app/lib/inspector/pick-target.ts +38 -0
- package/src/app/lib/inspector/use-comments.ts +1 -1
- package/src/app/lib/keys.ts +18 -0
- package/src/app/lib/last-home-location.ts +18 -0
- package/src/app/lib/print-ready.ts +2 -4
- package/src/app/lib/slides.ts +7 -4
- package/src/app/lib/text-diff.ts +19 -0
- package/src/app/lib/use-click-page-navigation.ts +2 -6
- package/src/app/lib/use-is-mobile.ts +2 -14
- package/src/app/lib/use-media-query.ts +20 -0
- package/src/app/lib/use-prefers-reduced-motion.ts +5 -13
- package/src/app/lib/use-slide-module.ts +1 -1
- package/src/app/lib/use-wheel-page-navigation.ts +1 -1
- package/src/app/lib/utils.test.ts +25 -1
- package/src/app/lib/utils.ts +8 -0
- package/src/app/routes/home-shell.tsx +71 -64
- package/src/app/routes/home.tsx +50 -58
- package/src/app/routes/presenter.tsx +14 -23
- package/src/app/routes/slide.tsx +90 -77
- package/src/app/routes/themes.tsx +7 -8
- package/src/app/styles.css +40 -44
- package/src/locale/en.ts +2 -7
- package/src/locale/ja.ts +2 -7
- package/src/locale/types.ts +2 -7
- package/src/locale/zh-cn.ts +2 -7
- package/src/locale/zh-tw.ts +2 -7
- package/dist/sync-BCJDRIqo.js +0 -139
- package/dist/sync-j9_QPovT.js +0 -3
- package/src/app/components/pdf-progress-toast.tsx +0 -32
- package/src/app/components/pptx-progress-toast.tsx +0 -32
package/src/app/lib/folders.ts
CHANGED
|
@@ -24,77 +24,84 @@ async function getManifest(): Promise<FoldersManifest> {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
async function send(method: string, path: string, body?: unknown): Promise<Response> {
|
|
28
|
+
const init: RequestInit = { method };
|
|
29
|
+
if (body !== undefined) {
|
|
30
|
+
init.headers = { 'content-type': 'application/json' };
|
|
31
|
+
init.body = JSON.stringify(body);
|
|
32
|
+
}
|
|
33
|
+
const res = await fetch(path, init);
|
|
34
|
+
if (!res.ok) throw new Error(`${method} ${path} ${res.status}`);
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function request(method: string, path: string, body?: unknown): Promise<void> {
|
|
39
|
+
await send(method, path, body);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function requestJson<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
43
|
+
const res = await send(method, path, body);
|
|
44
|
+
return (await res.json()) as T;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isFolderIcon(value: unknown): value is FolderIcon {
|
|
48
|
+
if (!value || typeof value !== 'object') return false;
|
|
49
|
+
const icon = value as { type?: unknown; value?: unknown };
|
|
50
|
+
return (icon.type === 'emoji' || icon.type === 'color') && typeof icon.value === 'string';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function asFolder(value: unknown): Folder {
|
|
54
|
+
const folder = value as Partial<Folder> | null;
|
|
55
|
+
if (
|
|
56
|
+
!folder ||
|
|
57
|
+
typeof folder.id !== 'string' ||
|
|
58
|
+
typeof folder.name !== 'string' ||
|
|
59
|
+
!isFolderIcon(folder.icon)
|
|
60
|
+
) {
|
|
61
|
+
throw new Error('malformed folder response');
|
|
62
|
+
}
|
|
63
|
+
return folder as Folder;
|
|
64
|
+
}
|
|
65
|
+
|
|
27
66
|
async function patchSlideName(slideId: string, name: string): Promise<void> {
|
|
28
|
-
|
|
29
|
-
method: 'PATCH',
|
|
30
|
-
headers: { 'content-type': 'application/json' },
|
|
31
|
-
body: JSON.stringify({ name }),
|
|
32
|
-
});
|
|
33
|
-
if (!res.ok) throw new Error(`PATCH /__slides/${slideId} ${res.status}`);
|
|
67
|
+
await request('PATCH', `/__slides/${slideId}`, { name });
|
|
34
68
|
}
|
|
35
69
|
|
|
36
70
|
async function duplicateSlideReq(slideId: string, newId?: string): Promise<string> {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const res = await fetch(`/__slides/${slideId}/duplicate`, init);
|
|
43
|
-
if (!res.ok) throw new Error(`POST /__slides/${slideId}/duplicate ${res.status}`);
|
|
44
|
-
const body = (await res.json()) as { slideId?: unknown };
|
|
71
|
+
const body = await requestJson<{ slideId?: unknown }>(
|
|
72
|
+
'POST',
|
|
73
|
+
`/__slides/${slideId}/duplicate`,
|
|
74
|
+
newId === undefined ? undefined : { newId },
|
|
75
|
+
);
|
|
45
76
|
if (typeof body.slideId !== 'string') throw new Error('duplicate response missing slideId');
|
|
46
77
|
return body.slideId;
|
|
47
78
|
}
|
|
48
79
|
|
|
49
80
|
async function deleteSlideReq(slideId: string): Promise<void> {
|
|
50
|
-
|
|
51
|
-
if (!res.ok) throw new Error(`DELETE /__slides/${slideId} ${res.status}`);
|
|
81
|
+
await request('DELETE', `/__slides/${slideId}`);
|
|
52
82
|
}
|
|
53
83
|
|
|
54
84
|
async function postFolder(name: string, icon: FolderIcon): Promise<Folder> {
|
|
55
|
-
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: { 'content-type': 'application/json' },
|
|
58
|
-
body: JSON.stringify({ name, icon }),
|
|
59
|
-
});
|
|
60
|
-
if (!res.ok) throw new Error(`POST /__folders ${res.status}`);
|
|
61
|
-
return (await res.json()) as Folder;
|
|
85
|
+
return asFolder(await requestJson('POST', '/__folders', { name, icon }));
|
|
62
86
|
}
|
|
63
87
|
|
|
64
88
|
async function patchFolder(
|
|
65
89
|
id: string,
|
|
66
90
|
patch: { name?: string; icon?: FolderIcon },
|
|
67
91
|
): Promise<Folder> {
|
|
68
|
-
|
|
69
|
-
method: 'PATCH',
|
|
70
|
-
headers: { 'content-type': 'application/json' },
|
|
71
|
-
body: JSON.stringify(patch),
|
|
72
|
-
});
|
|
73
|
-
if (!res.ok) throw new Error(`PATCH /__folders/${id} ${res.status}`);
|
|
74
|
-
return (await res.json()) as Folder;
|
|
92
|
+
return asFolder(await requestJson('PATCH', `/__folders/${id}`, patch));
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
async function deleteFolder(id: string): Promise<void> {
|
|
78
|
-
|
|
79
|
-
if (!res.ok) throw new Error(`DELETE /__folders/${id} ${res.status}`);
|
|
96
|
+
await request('DELETE', `/__folders/${id}`);
|
|
80
97
|
}
|
|
81
98
|
|
|
82
99
|
async function putAssign(slideId: string, folderId: string | null): Promise<void> {
|
|
83
|
-
|
|
84
|
-
method: 'PUT',
|
|
85
|
-
headers: { 'content-type': 'application/json' },
|
|
86
|
-
body: JSON.stringify({ slideId, folderId }),
|
|
87
|
-
});
|
|
88
|
-
if (!res.ok) throw new Error(`PUT /__folders/assign ${res.status}`);
|
|
100
|
+
await request('PUT', '/__folders/assign', { slideId, folderId });
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
async function putReorder(ids: string[]): Promise<void> {
|
|
92
|
-
|
|
93
|
-
method: 'PUT',
|
|
94
|
-
headers: { 'content-type': 'application/json' },
|
|
95
|
-
body: JSON.stringify({ ids }),
|
|
96
|
-
});
|
|
97
|
-
if (!res.ok) throw new Error(`PUT /__folders/reorder ${res.status}`);
|
|
104
|
+
await request('PUT', '/__folders/reorder', { ids });
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
export type UseFoldersResult = {
|
|
@@ -108,7 +115,6 @@ export type UseFoldersResult = {
|
|
|
108
115
|
renameSlide: (slideId: string, name: string) => Promise<void>;
|
|
109
116
|
duplicateSlide: (slideId: string, newId?: string) => Promise<string>;
|
|
110
117
|
deleteSlide: (slideId: string) => Promise<void>;
|
|
111
|
-
refresh: () => Promise<void>;
|
|
112
118
|
};
|
|
113
119
|
|
|
114
120
|
export function useFolders(): UseFoldersResult {
|
|
@@ -234,6 +240,5 @@ export function useFolders(): UseFoldersResult {
|
|
|
234
240
|
renameSlide,
|
|
235
241
|
duplicateSlide,
|
|
236
242
|
deleteSlide,
|
|
237
|
-
refresh,
|
|
238
243
|
};
|
|
239
244
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Tags the inspector treats as part of a text run rather than as a container
|
|
2
|
+
// of their own, so `<p>a <strong>b</strong></p>` stays one editable target.
|
|
3
|
+
export const INLINE_TEXT_TAGS = new Set([
|
|
4
|
+
'B',
|
|
5
|
+
'CODE',
|
|
6
|
+
'DEL',
|
|
7
|
+
'EM',
|
|
8
|
+
'I',
|
|
9
|
+
'INS',
|
|
10
|
+
'MARK',
|
|
11
|
+
'S',
|
|
12
|
+
'SMALL',
|
|
13
|
+
'SPAN',
|
|
14
|
+
'STRONG',
|
|
15
|
+
'SUB',
|
|
16
|
+
'SUP',
|
|
17
|
+
'U',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export function hasOnlyInlineTextChildren(el: HTMLElement): boolean {
|
|
21
|
+
for (const child of Array.from(el.childNodes)) {
|
|
22
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
23
|
+
continue;
|
|
24
|
+
} else if (child instanceof HTMLElement) {
|
|
25
|
+
if (child.tagName === 'BR') continue;
|
|
26
|
+
if (INLINE_TEXT_TAGS.has(child.tagName) && hasOnlyInlineTextChildren(child)) continue;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { hasOnlyInlineTextChildren, INLINE_TEXT_TAGS } from '@/lib/inspector/inline-text';
|
|
2
|
+
|
|
3
|
+
// Only handle events that originate inside the slide root. Portaled UI
|
|
4
|
+
// (dialogs, tooltips, toasts) mounts on `document.body`, outside the root;
|
|
5
|
+
// without this guard capture-phase window listeners swallow clicks meant
|
|
6
|
+
// for a dialog and hit the slide element behind it instead.
|
|
7
|
+
export function isInspectableEventTarget(target: EventTarget | null): boolean {
|
|
8
|
+
if (!(target instanceof Element)) return false;
|
|
9
|
+
if (target.closest('[data-inspector-ui]')) return false;
|
|
10
|
+
return !!target.closest('[data-inspector-root]');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function pickElement(x: number, y: number): HTMLElement | null {
|
|
14
|
+
const stack = document.elementsFromPoint(x, y);
|
|
15
|
+
for (const el of stack) {
|
|
16
|
+
if (!(el instanceof HTMLElement)) continue;
|
|
17
|
+
if (el.closest('[data-inspector-ui]')) continue;
|
|
18
|
+
if (!el.closest('[data-inspector-root]')) continue;
|
|
19
|
+
return el;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function pickInspectorTarget(el: HTMLElement | null): HTMLElement | null {
|
|
25
|
+
if (!el) return null;
|
|
26
|
+
const root = el.closest('[data-inspector-root]');
|
|
27
|
+
const startedOnInlineText = INLINE_TEXT_TAGS.has(el.tagName);
|
|
28
|
+
for (let cur: HTMLElement | null = el; cur && root?.contains(cur); cur = cur.parentElement) {
|
|
29
|
+
if (startedOnInlineText && INLINE_TEXT_TAGS.has(cur.tagName)) continue;
|
|
30
|
+
if (isEditableTextContainer(cur)) return cur;
|
|
31
|
+
}
|
|
32
|
+
return el;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isEditableTextContainer(el: HTMLElement): boolean {
|
|
36
|
+
if (!el.textContent?.trim()) return false;
|
|
37
|
+
return hasOnlyInlineTextChildren(el);
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function isTypingTarget(target: EventTarget | null): boolean {
|
|
2
|
+
return (
|
|
3
|
+
target instanceof HTMLElement && (target.isContentEditable || target.matches('input, textarea'))
|
|
4
|
+
);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Single-letter shortcuts bail on this so browser combos (⌘P, ⌘F…) still work.
|
|
8
|
+
export function hasModifier(e: KeyboardEvent): boolean {
|
|
9
|
+
return e.altKey || e.ctrlKey || e.metaKey;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isForwardKey(e: KeyboardEvent): boolean {
|
|
13
|
+
return e.key === 'ArrowRight' || e.key === 'ArrowDown' || e.key === ' ' || e.key === 'PageDown';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isBackwardKey(e: KeyboardEvent): boolean {
|
|
17
|
+
return e.key === 'ArrowLeft' || e.key === 'ArrowUp' || e.key === 'PageUp';
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const LAST_HOME_LOCATION_KEY = 'open-slide:last-home-location';
|
|
2
|
+
|
|
3
|
+
export function rememberHomeLocation(pathname: string, search: string): void {
|
|
4
|
+
try {
|
|
5
|
+
sessionStorage.setItem(LAST_HOME_LOCATION_KEY, pathname + search);
|
|
6
|
+
} catch {
|
|
7
|
+
// sessionStorage can be unavailable (private browsing, quota); falling
|
|
8
|
+
// back to the default home route is fine.
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function readLastHomeLocation(): string {
|
|
13
|
+
try {
|
|
14
|
+
return sessionStorage.getItem(LAST_HOME_LOCATION_KEY) ?? '/';
|
|
15
|
+
} catch {
|
|
16
|
+
return '/';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { nextFrame } from './dom';
|
|
2
|
+
|
|
1
3
|
const DEFAULT_WAITFOR_TIMEOUT_MS = 10_000;
|
|
2
4
|
|
|
3
5
|
// `document.fonts.ready` already waits for every in-flight face. Never call
|
|
@@ -45,7 +47,3 @@ export function isFrameAnimationSettled(frame: Element): boolean {
|
|
|
45
47
|
}
|
|
46
48
|
return true;
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
function nextFrame(): Promise<void> {
|
|
50
|
-
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
51
|
-
}
|
package/src/app/lib/slides.ts
CHANGED
|
@@ -18,9 +18,12 @@ export async function loadSlide(id: string): Promise<SlideModule> {
|
|
|
18
18
|
return load(id);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export function changedSlideIds(data: unknown): string[] {
|
|
22
|
+
if (!data || typeof data !== 'object') return [];
|
|
23
|
+
const ids = (data as { slideIds?: unknown }).slideIds;
|
|
24
|
+
return Array.isArray(ids) ? (ids as string[]) : [];
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
export function slideChangeIncludes(data: unknown, slideId: string): boolean {
|
|
22
|
-
|
|
23
|
-
const payload = data as { slideId?: unknown; slideIds?: unknown };
|
|
24
|
-
if (payload.slideId === slideId) return true;
|
|
25
|
-
return Array.isArray(payload.slideIds) && payload.slideIds.includes(slideId);
|
|
28
|
+
return changedSlideIds(data).includes(slideId);
|
|
26
29
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function textDiff(prevText: string, nextText: string) {
|
|
2
|
+
let start = 0;
|
|
3
|
+
while (
|
|
4
|
+
start < prevText.length &&
|
|
5
|
+
start < nextText.length &&
|
|
6
|
+
prevText[start] === nextText[start]
|
|
7
|
+
) {
|
|
8
|
+
start += 1;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let prevEnd = prevText.length;
|
|
12
|
+
let nextEnd = nextText.length;
|
|
13
|
+
while (prevEnd > start && nextEnd > start && prevText[prevEnd - 1] === nextText[nextEnd - 1]) {
|
|
14
|
+
prevEnd -= 1;
|
|
15
|
+
nextEnd -= 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return { start, end: prevEnd, value: nextText.slice(start, nextEnd) };
|
|
19
|
+
}
|
|
@@ -7,7 +7,7 @@ const NAV_PASSTHROUGH =
|
|
|
7
7
|
'a, button, input, textarea, select, label, summary, iframe, video, audio, embed, object, [role="button"], [role="link"], [contenteditable="true"], [data-osd-interactive], [data-osd-chrome]';
|
|
8
8
|
|
|
9
9
|
type UseClickPageNavigationOptions<T extends HTMLElement> = {
|
|
10
|
-
ref: RefObject<T>;
|
|
10
|
+
ref: RefObject<T | null>;
|
|
11
11
|
enabled?: boolean;
|
|
12
12
|
/** Fraction of the width on each side that navigates; the center is inert. */
|
|
13
13
|
edgeRatio?: number;
|
|
@@ -15,7 +15,6 @@ type UseClickPageNavigationOptions<T extends HTMLElement> = {
|
|
|
15
15
|
canNext: boolean;
|
|
16
16
|
onPrev: () => void;
|
|
17
17
|
onNext: () => void;
|
|
18
|
-
onCenterClick?: () => void;
|
|
19
18
|
onViewportClick?: (point: { x: number; y: number }) => void;
|
|
20
19
|
};
|
|
21
20
|
|
|
@@ -27,7 +26,6 @@ export function useClickPageNavigation<T extends HTMLElement>({
|
|
|
27
26
|
canNext,
|
|
28
27
|
onPrev,
|
|
29
28
|
onNext,
|
|
30
|
-
onCenterClick,
|
|
31
29
|
onViewportClick,
|
|
32
30
|
}: UseClickPageNavigationOptions<T>) {
|
|
33
31
|
useEffect(() => {
|
|
@@ -49,12 +47,10 @@ export function useClickPageNavigation<T extends HTMLElement>({
|
|
|
49
47
|
if (canPrev) onPrev();
|
|
50
48
|
} else if (x > 1 - edgeRatio) {
|
|
51
49
|
if (canNext) onNext();
|
|
52
|
-
} else {
|
|
53
|
-
onCenterClick?.();
|
|
54
50
|
}
|
|
55
51
|
};
|
|
56
52
|
|
|
57
53
|
el.addEventListener('click', onClick);
|
|
58
54
|
return () => el.removeEventListener('click', onClick);
|
|
59
|
-
}, [ref, enabled, edgeRatio, canPrev, canNext, onPrev, onNext,
|
|
55
|
+
}, [ref, enabled, edgeRatio, canPrev, canNext, onPrev, onNext, onViewportClick]);
|
|
60
56
|
}
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMediaQuery } from './use-media-query';
|
|
2
2
|
|
|
3
3
|
// Matches Tailwind's `md` breakpoint — below it the slide viewer hides desktop
|
|
4
4
|
// navigation chrome and relies on tap-to-navigate instead.
|
|
5
5
|
const QUERY = '(max-width: 767.98px)';
|
|
6
6
|
|
|
7
7
|
export function useIsMobile(): boolean {
|
|
8
|
-
|
|
9
|
-
if (typeof window === 'undefined') return false;
|
|
10
|
-
return window.matchMedia(QUERY).matches;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
const mql = window.matchMedia(QUERY);
|
|
15
|
-
const onChange = (e: MediaQueryListEvent) => setMobile(e.matches);
|
|
16
|
-
mql.addEventListener('change', onChange);
|
|
17
|
-
return () => mql.removeEventListener('change', onChange);
|
|
18
|
-
}, []);
|
|
19
|
-
|
|
20
|
-
return mobile;
|
|
8
|
+
return useMediaQuery(QUERY);
|
|
21
9
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function matchesMediaQuery(query: string): boolean {
|
|
4
|
+
if (typeof window === 'undefined') return false;
|
|
5
|
+
return window.matchMedia(query).matches;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useMediaQuery(query: string): boolean {
|
|
9
|
+
const [matches, setMatches] = useState(() => matchesMediaQuery(query));
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const mql = window.matchMedia(query);
|
|
13
|
+
setMatches(mql.matches);
|
|
14
|
+
const onChange = (e: MediaQueryListEvent) => setMatches(e.matches);
|
|
15
|
+
mql.addEventListener('change', onChange);
|
|
16
|
+
return () => mql.removeEventListener('change', onChange);
|
|
17
|
+
}, [query]);
|
|
18
|
+
|
|
19
|
+
return matches;
|
|
20
|
+
}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matchesMediaQuery, useMediaQuery } from './use-media-query';
|
|
2
2
|
|
|
3
3
|
const QUERY = '(prefers-reduced-motion: reduce)';
|
|
4
4
|
|
|
5
5
|
export function usePrefersReducedMotion(): boolean {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return window.matchMedia(QUERY).matches;
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const mql = window.matchMedia(QUERY);
|
|
13
|
-
const onChange = (e: MediaQueryListEvent) => setReduce(e.matches);
|
|
14
|
-
mql.addEventListener('change', onChange);
|
|
15
|
-
return () => mql.removeEventListener('change', onChange);
|
|
16
|
-
}, []);
|
|
6
|
+
return useMediaQuery(QUERY);
|
|
7
|
+
}
|
|
17
8
|
|
|
18
|
-
|
|
9
|
+
export function prefersReducedMotion(): boolean {
|
|
10
|
+
return matchesMediaQuery(QUERY);
|
|
19
11
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { cn } from './utils.ts';
|
|
2
|
+
import { cn, pad2, round2 } from './utils.ts';
|
|
3
3
|
|
|
4
4
|
describe('cn', () => {
|
|
5
5
|
it('joins multiple class names', () => {
|
|
@@ -23,3 +23,27 @@ describe('cn', () => {
|
|
|
23
23
|
expect(cn('p-2', 'm-4')).toBe('p-2 m-4');
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
+
|
|
27
|
+
describe('pad2', () => {
|
|
28
|
+
it('pads single digits to two', () => {
|
|
29
|
+
expect(pad2(0)).toBe('00');
|
|
30
|
+
expect(pad2(7)).toBe('07');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('leaves two or more digits alone', () => {
|
|
34
|
+
expect(pad2(12)).toBe('12');
|
|
35
|
+
expect(pad2(340)).toBe('340');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('round2', () => {
|
|
40
|
+
it('rounds to two decimal places', () => {
|
|
41
|
+
expect(round2(1.005)).toBe(1);
|
|
42
|
+
expect(round2(1.2345)).toBe(1.23);
|
|
43
|
+
expect(round2(1.2355)).toBe(1.24);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('leaves whole numbers alone', () => {
|
|
47
|
+
expect(round2(42)).toBe(42);
|
|
48
|
+
});
|
|
49
|
+
});
|
package/src/app/lib/utils.ts
CHANGED
|
@@ -4,3 +4,11 @@ import { twMerge } from 'tailwind-merge';
|
|
|
4
4
|
export function cn(...inputs: ClassValue[]) {
|
|
5
5
|
return twMerge(clsx(inputs));
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
export function round2(n: number): number {
|
|
9
|
+
return Math.round(n * 100) / 100;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function pad2(n: number): string {
|
|
13
|
+
return n.toString().padStart(2, '0');
|
|
14
|
+
}
|