@lemonriver/core 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/release-notes.json +14 -0
- package/src/app/components/player.tsx +6 -1
- package/src/app/lemonriver/present/dual-screen.ts +154 -0
- package/src/app/lemonriver/present/presenter-blocked-hint.tsx +28 -0
- package/src/app/lemonriver/present/wake-lock.ts +74 -0
- package/src/app/lemonriver/text/en.ts +3 -0
- package/src/app/lemonriver/text/es.ts +3 -0
- package/src/app/lemonriver/text/ja.ts +3 -0
- package/src/app/lemonriver/text/types.ts +4 -0
- package/src/app/lemonriver/text/zh-cn.ts +3 -0
- package/src/app/lemonriver/text/zh-tw.ts +3 -0
- package/src/app/routes/presenter.tsx +2 -0
- package/src/app/routes/slide.tsx +14 -1
package/package.json
CHANGED
package/release-notes.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
+
"1.3.0": {
|
|
3
|
+
"zh-CN": [
|
|
4
|
+
"放映时屏幕不会再自动熄灭,打开演讲者视图时也一样。",
|
|
5
|
+
"接了外接显示器时,幻灯片在外接屏全屏放映,笔记本上显示演讲者视图,两边翻页同步(用 Chrome 或 Edge,第一次要允许「管理窗口」)。"
|
|
6
|
+
],
|
|
7
|
+
"zh-TW": [
|
|
8
|
+
"放映時螢幕不會再自動熄滅,開啟演講者視圖時也一樣。",
|
|
9
|
+
"接了外接顯示器時,投影片在外接螢幕全螢幕放映,筆電上顯示演講者視圖,兩邊翻頁同步(用 Chrome 或 Edge,第一次要允許「管理視窗」)。"
|
|
10
|
+
],
|
|
11
|
+
"en": [
|
|
12
|
+
"The screen no longer goes dark while you present, including in the presenter view.",
|
|
13
|
+
"With an external display connected, slides play full screen there while your laptop shows the presenter view, in sync (Chrome or Edge; allow window management the first time)."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
"1.2.0": {
|
|
3
17
|
"zh-CN": [
|
|
4
18
|
"侧栏多了「反馈」,可以填问卷或发邮件告诉我们遇到的问题和想要的功能。",
|
|
@@ -3,6 +3,9 @@ import { hasModifier, isBackwardKey, isForwardKey, isTypingTarget } from '@/lib/
|
|
|
3
3
|
import { useClickPageNavigation } from '@/lib/use-click-page-navigation';
|
|
4
4
|
import { useWheelPageNavigation } from '@/lib/use-wheel-page-navigation';
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
|
+
import { requestPresentFullscreen } from '../lemonriver/present/dual-screen';
|
|
7
|
+
import { PresenterBlockedHint } from '../lemonriver/present/presenter-blocked-hint';
|
|
8
|
+
import { useScreenWakeLock } from '../lemonriver/present/wake-lock';
|
|
6
9
|
import type { DesignSystem } from '../lib/design';
|
|
7
10
|
import type { Page } from '../lib/sdk';
|
|
8
11
|
import type { EntryDirection, StepAggregate, StepController } from '../lib/step-context';
|
|
@@ -75,6 +78,7 @@ export function Player({
|
|
|
75
78
|
}: Props) {
|
|
76
79
|
const isMobile = useIsMobile();
|
|
77
80
|
const prefersReducedMotion = usePrefersReducedMotion();
|
|
81
|
+
useScreenWakeLock(controls);
|
|
78
82
|
const fade = curtain && !prefersReducedMotion;
|
|
79
83
|
const [curtainOpaque, setCurtainOpaque] = useState(fade);
|
|
80
84
|
const exitingRef = useRef(false);
|
|
@@ -261,7 +265,7 @@ export function Player({
|
|
|
261
265
|
const el = rootRef.current;
|
|
262
266
|
if (!el) return;
|
|
263
267
|
if (document.fullscreenElement !== el) {
|
|
264
|
-
el
|
|
268
|
+
requestPresentFullscreen(el);
|
|
265
269
|
}
|
|
266
270
|
return () => {
|
|
267
271
|
if (document.fullscreenElement) document.exitFullscreen?.().catch(() => {});
|
|
@@ -538,6 +542,7 @@ export function Player({
|
|
|
538
542
|
tooltipContainer={rootEl}
|
|
539
543
|
/>
|
|
540
544
|
<PresentHelpOverlay open={helpOpen} onOpenChange={setHelpOpen} container={rootEl} />
|
|
545
|
+
{slideId && <PresenterBlockedHint slideId={slideId} />}
|
|
541
546
|
</div>
|
|
542
547
|
)}
|
|
543
548
|
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export type ScreenLike = {
|
|
2
|
+
isCurrent?: boolean;
|
|
3
|
+
left: number;
|
|
4
|
+
top: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
availLeft: number;
|
|
8
|
+
availTop: number;
|
|
9
|
+
availWidth: number;
|
|
10
|
+
availHeight: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ScreenDetailsLike = {
|
|
14
|
+
screens: ScreenLike[];
|
|
15
|
+
currentScreen: ScreenLike;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type WindowManagementApi = {
|
|
19
|
+
getScreenDetails?: () => Promise<ScreenDetailsLike>;
|
|
20
|
+
screen: ScreenLike & { isExtended?: boolean };
|
|
21
|
+
open: (url: string, name: string, features: string) => unknown;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type PresenterPopupNotice = { slideId: string; blocked: boolean };
|
|
25
|
+
|
|
26
|
+
function windowApi(): WindowManagementApi | null {
|
|
27
|
+
return typeof window === 'undefined' ? null : (window as unknown as WindowManagementApi);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function pickAudienceScreen<T extends ScreenLike>(
|
|
31
|
+
screens: readonly T[],
|
|
32
|
+
current: T | null | undefined,
|
|
33
|
+
): T | null {
|
|
34
|
+
const others = screens.filter((screen) => screen !== current && !screen.isCurrent);
|
|
35
|
+
if (others.length === 0) return null;
|
|
36
|
+
return others.reduce((largest, screen) =>
|
|
37
|
+
screen.width * screen.height > largest.width * largest.height ? screen : largest,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function supportsAudienceScreens(): boolean {
|
|
42
|
+
const win = windowApi();
|
|
43
|
+
return Boolean(win?.getScreenDetails) && win?.screen?.isExtended === true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function resolveAudienceScreen(): Promise<ScreenLike | null> {
|
|
47
|
+
const win = windowApi();
|
|
48
|
+
if (!win?.getScreenDetails) return null;
|
|
49
|
+
try {
|
|
50
|
+
const details = await win.getScreenDetails();
|
|
51
|
+
return pickAudienceScreen(details.screens, details.currentScreen);
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let audienceScreen: ScreenLike | null = null;
|
|
58
|
+
let audienceSlideId: string | null = null;
|
|
59
|
+
let presenterOpened = false;
|
|
60
|
+
|
|
61
|
+
export function clearAudiencePresentation(): void {
|
|
62
|
+
audienceScreen = null;
|
|
63
|
+
audienceSlideId = null;
|
|
64
|
+
presenterOpened = false;
|
|
65
|
+
setPopupNotice(null);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The browser only grants one user-activated action per click. Entering
|
|
69
|
+
// fullscreen has to happen first and the presenter window only once it
|
|
70
|
+
// resolved, or the popup consumes the click and fullscreen is refused.
|
|
71
|
+
export function requestPresentFullscreen(el: Element): void {
|
|
72
|
+
const options = audienceScreen
|
|
73
|
+
? ({ screen: audienceScreen } as unknown as FullscreenOptions)
|
|
74
|
+
: undefined;
|
|
75
|
+
const request = el.requestFullscreen?.(options);
|
|
76
|
+
if (!request) return;
|
|
77
|
+
request.then(
|
|
78
|
+
() => openAudiencePresenter(),
|
|
79
|
+
() => {},
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function openAudiencePresenter(): void {
|
|
84
|
+
const slideId = audienceSlideId;
|
|
85
|
+
const win = windowApi();
|
|
86
|
+
if (!audienceScreen || !slideId || presenterOpened || !win) return;
|
|
87
|
+
presenterOpened = true;
|
|
88
|
+
const blocked = !openPresenterPopup(slideId, win.screen);
|
|
89
|
+
setPopupNotice({ slideId, blocked });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function openPresenterPopup(slideId: string, current: ScreenLike): boolean {
|
|
93
|
+
const win = windowApi();
|
|
94
|
+
if (!win) return false;
|
|
95
|
+
const url = `${import.meta.env.BASE_URL}s/${encodeURIComponent(slideId)}/presenter`;
|
|
96
|
+
const left = Math.round(current.availLeft ?? current.left);
|
|
97
|
+
const top = Math.round(current.availTop ?? current.top);
|
|
98
|
+
const width = Math.round(current.availWidth || current.width);
|
|
99
|
+
const height = Math.round(current.availHeight || current.height);
|
|
100
|
+
const features = `popup,left=${left},top=${top},width=${width},height=${height}`;
|
|
101
|
+
try {
|
|
102
|
+
return win.open(url, `open-slide-presenter-${slideId}`, features) !== null;
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let popupNotice: PresenterPopupNotice | null = null;
|
|
109
|
+
const popupListeners = new Set<() => void>();
|
|
110
|
+
|
|
111
|
+
function setPopupNotice(next: PresenterPopupNotice | null) {
|
|
112
|
+
popupNotice = next;
|
|
113
|
+
for (const listener of popupListeners) listener();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function subscribePresenterPopupNotice(listener: () => void): () => void {
|
|
117
|
+
popupListeners.add(listener);
|
|
118
|
+
return () => {
|
|
119
|
+
popupListeners.delete(listener);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getPresenterPopupNotice(): PresenterPopupNotice | null {
|
|
124
|
+
return popupNotice;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function retryPresenterPopup(slideId: string): void {
|
|
128
|
+
const win = windowApi();
|
|
129
|
+
if (!win) return;
|
|
130
|
+
if (openPresenterPopup(slideId, win.screen)) setPopupNotice({ slideId, blocked: false });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function startAudiencePresentation(
|
|
134
|
+
slideId: string | undefined,
|
|
135
|
+
enter: () => void,
|
|
136
|
+
): Promise<void> {
|
|
137
|
+
audienceScreen = null;
|
|
138
|
+
audienceSlideId = null;
|
|
139
|
+
presenterOpened = false;
|
|
140
|
+
const win = windowApi();
|
|
141
|
+
if (!slideId || !win || !supportsAudienceScreens()) {
|
|
142
|
+
enter();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const audience = await resolveAudienceScreen();
|
|
146
|
+
if (!audience) {
|
|
147
|
+
enter();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
audienceScreen = audience;
|
|
151
|
+
audienceSlideId = slideId;
|
|
152
|
+
setPopupNotice({ slideId, blocked: false });
|
|
153
|
+
enter();
|
|
154
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
import { useLrText } from '../text';
|
|
3
|
+
import {
|
|
4
|
+
getPresenterPopupNotice,
|
|
5
|
+
retryPresenterPopup,
|
|
6
|
+
subscribePresenterPopupNotice,
|
|
7
|
+
} from './dual-screen';
|
|
8
|
+
|
|
9
|
+
export function PresenterBlockedHint({ slideId }: { slideId: string }) {
|
|
10
|
+
const notice = useSyncExternalStore(
|
|
11
|
+
subscribePresenterPopupNotice,
|
|
12
|
+
getPresenterPopupNotice,
|
|
13
|
+
getPresenterPopupNotice,
|
|
14
|
+
);
|
|
15
|
+
const lr = useLrText();
|
|
16
|
+
if (!notice?.blocked || notice.slideId !== slideId) return null;
|
|
17
|
+
return (
|
|
18
|
+
<div className="pointer-events-none fixed inset-x-0 top-4 z-[70] flex justify-center px-4">
|
|
19
|
+
<button
|
|
20
|
+
type="button"
|
|
21
|
+
onClick={() => retryPresenterPopup(slideId)}
|
|
22
|
+
className="pointer-events-auto rounded-[6px] border border-white/20 bg-black/80 px-4 py-2 text-[13px] text-white shadow-lg backdrop-blur hover:bg-black/90"
|
|
23
|
+
>
|
|
24
|
+
{lr.present.presenterBlocked}
|
|
25
|
+
</button>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
type WakeLockSentinel = {
|
|
4
|
+
released: boolean;
|
|
5
|
+
release: () => Promise<void>;
|
|
6
|
+
addEventListener?: (type: 'release', listener: () => void) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type WakeLockApi = {
|
|
10
|
+
request: (type: 'screen') => Promise<WakeLockSentinel>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type VisibilitySource = {
|
|
14
|
+
visibilityState: string;
|
|
15
|
+
addEventListener: (type: 'visibilitychange', listener: () => void) => void;
|
|
16
|
+
removeEventListener: (type: 'visibilitychange', listener: () => void) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type WakeLockDeps = {
|
|
20
|
+
navigator?: { wakeLock?: WakeLockApi } | null;
|
|
21
|
+
document?: VisibilitySource | null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function holdScreenWakeLock(active: boolean, deps: WakeLockDeps = {}): () => void {
|
|
25
|
+
const nav =
|
|
26
|
+
deps.navigator ??
|
|
27
|
+
(typeof navigator === 'undefined' ? null : (navigator as { wakeLock?: WakeLockApi }));
|
|
28
|
+
const doc =
|
|
29
|
+
deps.document ?? (typeof document === 'undefined' ? null : (document as VisibilitySource));
|
|
30
|
+
const wakeLock = nav?.wakeLock;
|
|
31
|
+
if (!active || !wakeLock || !doc) return () => {};
|
|
32
|
+
|
|
33
|
+
let sentinel: WakeLockSentinel | null = null;
|
|
34
|
+
let disposed = false;
|
|
35
|
+
|
|
36
|
+
const acquire = () => {
|
|
37
|
+
if (disposed || sentinel) return;
|
|
38
|
+
wakeLock.request('screen').then(
|
|
39
|
+
(next) => {
|
|
40
|
+
if (disposed || sentinel) {
|
|
41
|
+
next.release().catch(() => {});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
sentinel = next;
|
|
45
|
+
next.addEventListener?.('release', () => {
|
|
46
|
+
if (sentinel === next) sentinel = null;
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
() => {},
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const onVisibilityChange = () => {
|
|
54
|
+
if (doc.visibilityState !== 'visible') return;
|
|
55
|
+
if (sentinel && !sentinel.released) return;
|
|
56
|
+
sentinel = null;
|
|
57
|
+
acquire();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
acquire();
|
|
61
|
+
doc.addEventListener('visibilitychange', onVisibilityChange);
|
|
62
|
+
|
|
63
|
+
return () => {
|
|
64
|
+
disposed = true;
|
|
65
|
+
doc.removeEventListener('visibilitychange', onVisibilityChange);
|
|
66
|
+
const current = sentinel;
|
|
67
|
+
sentinel = null;
|
|
68
|
+
current?.release().catch(() => {});
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function useScreenWakeLock(active: boolean): void {
|
|
73
|
+
useEffect(() => holdScreenWakeLock(active), [active]);
|
|
74
|
+
}
|
|
@@ -1368,4 +1368,7 @@ export const en: LrText = {
|
|
|
1368
1368
|
executablesHint: 'Only restore it if you made this backup yourself.',
|
|
1369
1369
|
executablesConfirm: 'I made this backup myself',
|
|
1370
1370
|
},
|
|
1371
|
+
present: {
|
|
1372
|
+
presenterBlocked: 'The presenter view was blocked by your browser. Click here to open it.',
|
|
1373
|
+
},
|
|
1371
1374
|
};
|
|
@@ -711,4 +711,7 @@ export const es: LrText = {
|
|
|
711
711
|
executablesHint: 'Restáurala solo si tú mismo hiciste esta copia.',
|
|
712
712
|
executablesConfirm: 'Hice yo esta copia',
|
|
713
713
|
},
|
|
714
|
+
present: {
|
|
715
|
+
presenterBlocked: 'The presenter view was blocked by your browser. Click here to open it.',
|
|
716
|
+
},
|
|
714
717
|
};
|
|
@@ -707,4 +707,7 @@ export const ja: LrText = {
|
|
|
707
707
|
executablesHint: '自分で作ったバックアップだと確認できた場合だけ復元してください。',
|
|
708
708
|
executablesConfirm: '自分で作ったバックアップです',
|
|
709
709
|
},
|
|
710
|
+
present: {
|
|
711
|
+
presenterBlocked: 'The presenter view was blocked by your browser. Click here to open it.',
|
|
712
|
+
},
|
|
710
713
|
};
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import { PreviewStepHost } from '../components/preview-step-host';
|
|
32
32
|
import { SlideCanvas } from '../components/slide-canvas';
|
|
33
33
|
import { isDeckWarmed, markDeckWarmed, SlidePreloadLayer } from '../components/slide-preload-layer';
|
|
34
|
+
import { useScreenWakeLock } from '../lemonriver/present/wake-lock';
|
|
34
35
|
import { SlidePageProvider } from '../lib/page-context';
|
|
35
36
|
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from '../lib/sdk';
|
|
36
37
|
import { loadSlide, slideIds } from '../lib/slides';
|
|
@@ -40,6 +41,7 @@ export function Presenter() {
|
|
|
40
41
|
const { slideId = '' } = useParams();
|
|
41
42
|
const { slide, error } = useSlideModule(slideId);
|
|
42
43
|
useDocumentTitle(slide?.meta?.title);
|
|
44
|
+
useScreenWakeLock(true);
|
|
43
45
|
|
|
44
46
|
// Presenter view is a passive mirror of the projection window. It only
|
|
45
47
|
// tracks the index it last heard about; navigation buttons send commands
|
package/src/app/routes/slide.tsx
CHANGED
|
@@ -96,6 +96,10 @@ import { isDeckWarmed, markDeckWarmed, SlidePreloadLayer } from '../components/s
|
|
|
96
96
|
import { SlideTransitionLayer } from '../components/slide-transition-layer';
|
|
97
97
|
import { type ThumbnailActions, ThumbnailRail } from '../components/thumbnail-rail';
|
|
98
98
|
import { exportFailedHint } from '../lemonriver/feedback/export';
|
|
99
|
+
import {
|
|
100
|
+
clearAudiencePresentation,
|
|
101
|
+
startAudiencePresentation,
|
|
102
|
+
} from '../lemonriver/present/dual-screen';
|
|
99
103
|
import { ShareMenuEntry } from '../lemonriver/share/editor-share';
|
|
100
104
|
import { SlideExtensions } from '../lemonriver/slide-extensions';
|
|
101
105
|
import { exportSlideAsHtml } from '../lib/export-html';
|
|
@@ -171,7 +175,7 @@ export function Slide() {
|
|
|
171
175
|
},
|
|
172
176
|
[],
|
|
173
177
|
);
|
|
174
|
-
const
|
|
178
|
+
const enterPresentation = useCallback(
|
|
175
179
|
(mode: 'window' | 'fullscreen') => {
|
|
176
180
|
if (prefersReducedMotion) {
|
|
177
181
|
setPlayMode(mode);
|
|
@@ -189,7 +193,16 @@ export function Slide() {
|
|
|
189
193
|
},
|
|
190
194
|
[prefersReducedMotion],
|
|
191
195
|
);
|
|
196
|
+
const present = useCallback(
|
|
197
|
+
(mode: 'window' | 'fullscreen') => {
|
|
198
|
+
if (mode === 'fullscreen')
|
|
199
|
+
void startAudiencePresentation(slideId, () => enterPresentation('fullscreen'));
|
|
200
|
+
else enterPresentation(mode);
|
|
201
|
+
},
|
|
202
|
+
[enterPresentation, slideId],
|
|
203
|
+
);
|
|
192
204
|
const exitPresent = useCallback(() => {
|
|
205
|
+
clearAudiencePresentation();
|
|
193
206
|
setPlayMode(null);
|
|
194
207
|
if (!prefersReducedMotion) setCurtain('leaving');
|
|
195
208
|
}, [prefersReducedMotion]);
|