@open-slide/core 1.19.1 → 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 +1 -3
- package/src/app/assets/open-slide.png +0 -0
- package/src/app/components/asset-view.tsx +8 -16
- 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/image-placeholder.tsx +4 -12
- package/src/app/components/inspector/asset-picker-dialog.tsx +6 -16
- package/src/app/components/inspector/image-crop-dialog.tsx +1 -4
- package/src/app/components/inspector/inline-text-editor.tsx +798 -0
- package/src/app/components/inspector/inspect-overlay.tsx +30 -72
- package/src/app/components/inspector/inspector-panel.tsx +17 -49
- package/src/app/components/inspector/inspector-provider.tsx +53 -36
- package/src/app/components/notes-drawer.tsx +2 -5
- package/src/app/components/overview-grid.tsx +5 -4
- package/src/app/components/panel/panel-shell.tsx +1 -3
- package/src/app/components/player.tsx +5 -6
- package/src/app/components/present/control-bar.tsx +4 -4
- package/src/app/components/present/jump-input.tsx +3 -2
- package/src/app/components/present/use-presenter-channel.ts +0 -1
- package/src/app/components/sidebar/folder-item.tsx +39 -16
- package/src/app/components/sidebar/sidebar-footer.tsx +7 -1
- 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/use-design.ts +1 -28
- package/src/app/components/themes/theme-detail.tsx +4 -4
- package/src/app/components/themes/themes-gallery.tsx +11 -6
- package/src/app/components/thumbnail-rail.tsx +7 -12
- 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 +41 -52
- package/src/app/routes/presenter.tsx +10 -20
- package/src/app/routes/slide.tsx +84 -71
- package/src/app/routes/themes.tsx +7 -8
- package/src/app/styles.css +33 -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 -36
- package/src/app/components/pptx-progress-toast.tsx +0 -36
|
@@ -3,7 +3,7 @@ import { Fragment, type ReactNode, useEffect, useMemo, useRef, useState } from '
|
|
|
3
3
|
import { Link } from 'react-router-dom';
|
|
4
4
|
import { Button } from '@/components/ui/button';
|
|
5
5
|
import { format, useLocale } from '@/lib/use-locale';
|
|
6
|
-
import { cn } from '@/lib/utils';
|
|
6
|
+
import { cn, pad2 } from '@/lib/utils';
|
|
7
7
|
import { SlidePageProvider } from '../../lib/page-context';
|
|
8
8
|
import type { SlideModule } from '../../lib/sdk';
|
|
9
9
|
import { loadSlide, slidesByTheme } from '../../lib/slides';
|
|
@@ -85,7 +85,7 @@ export function ThemeDetail({ themeId, onBack }: { themeId: string; onBack: () =
|
|
|
85
85
|
</div>
|
|
86
86
|
|
|
87
87
|
<header className="flex flex-wrap items-baseline gap-3">
|
|
88
|
-
<h2 className="font-heading text-[
|
|
88
|
+
<h2 className="font-heading text-[19px] font-semibold leading-none tracking-[-0.015em] md:text-[21px]">
|
|
89
89
|
{theme.name}
|
|
90
90
|
</h2>
|
|
91
91
|
{theme.description ? (
|
|
@@ -183,7 +183,7 @@ export function ThemeDetail({ themeId, onBack }: { themeId: string; onBack: () =
|
|
|
183
183
|
<div className="flex flex-wrap items-baseline gap-3">
|
|
184
184
|
<span className="eyebrow">{t.themes.usedBy}</span>
|
|
185
185
|
{usedBySlideIds.length > 0 ? (
|
|
186
|
-
<span className="folio">{usedBySlideIds.length
|
|
186
|
+
<span className="folio">{pad2(usedBySlideIds.length)}</span>
|
|
187
187
|
) : null}
|
|
188
188
|
</div>
|
|
189
189
|
{usedBySlideIds.length === 0 ? (
|
|
@@ -231,7 +231,7 @@ function ThemeSlideCard({ id }: { id: string }) {
|
|
|
231
231
|
>
|
|
232
232
|
<div className="relative aspect-video overflow-hidden rounded-[6px] border border-hairline bg-card shadow-edge ring-1 ring-foreground/[0.04] group-hover:shadow-floating group-hover:ring-foreground/20 group-active:scale-[0.99] motion-safe:transition-[box-shadow,--tw-ring-color,scale] motion-safe:duration-200">
|
|
233
233
|
{FirstPage ? (
|
|
234
|
-
<div className="h-full w-full
|
|
234
|
+
<div className="h-full w-full">
|
|
235
235
|
<SlideCanvas flat freezeMotion design={slide?.design}>
|
|
236
236
|
<SlidePageProvider index={0} total={slide?.default.length ?? 1}>
|
|
237
237
|
<FirstPage />
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Palette } from 'lucide-react';
|
|
1
2
|
import { useEffect, useState } from 'react';
|
|
2
3
|
import { format, useLocale } from '@/lib/use-locale';
|
|
3
4
|
import { SlidePageProvider } from '../../lib/page-context';
|
|
@@ -13,8 +14,12 @@ export function ThemesGallery({ onOpen }: { onOpen: (id: string) => void }) {
|
|
|
13
14
|
|
|
14
15
|
return (
|
|
15
16
|
<ul className="grid grid-cols-[repeat(auto-fill,minmax(min(240px,100%),1fr))] gap-x-6 gap-y-9 md:grid-cols-[repeat(auto-fill,minmax(340px,1fr))]">
|
|
16
|
-
{themes.map((theme) => (
|
|
17
|
-
<li
|
|
17
|
+
{themes.map((theme, i) => (
|
|
18
|
+
<li
|
|
19
|
+
key={theme.id}
|
|
20
|
+
className="rise-in"
|
|
21
|
+
style={{ animationDelay: `${Math.min(i, 11) * 30}ms` }}
|
|
22
|
+
>
|
|
18
23
|
<ThemeCard
|
|
19
24
|
theme={theme}
|
|
20
25
|
onOpen={() => onOpen(theme.id)}
|
|
@@ -77,7 +82,7 @@ function ThemePreview({ theme }: { theme: Theme }) {
|
|
|
77
82
|
if (!FirstPage) return <NoDemoState />;
|
|
78
83
|
|
|
79
84
|
return (
|
|
80
|
-
<div className="h-full w-full
|
|
85
|
+
<div className="h-full w-full">
|
|
81
86
|
<SlideCanvas flat freezeMotion design={demo.design}>
|
|
82
87
|
<SlidePageProvider index={0} total={demo.default.length}>
|
|
83
88
|
<FirstPage />
|
|
@@ -110,10 +115,10 @@ function NoDemoState() {
|
|
|
110
115
|
function ThemesEmptyState() {
|
|
111
116
|
const t = useLocale();
|
|
112
117
|
return (
|
|
113
|
-
<div className="rounded-[
|
|
118
|
+
<div className="rounded-[8px] border border-dashed border-border px-8 py-20">
|
|
114
119
|
<div className="mx-auto flex max-w-md flex-col items-center text-center">
|
|
115
|
-
<
|
|
116
|
-
<p className="mt-
|
|
120
|
+
<Palette className="size-5 text-muted-foreground/60" aria-hidden />
|
|
121
|
+
<p className="mt-4 font-heading text-[14px] font-semibold tracking-tight">
|
|
117
122
|
{t.themes.noThemesTitle}
|
|
118
123
|
</p>
|
|
119
124
|
<p className="mt-1.5 text-[13px] leading-relaxed text-muted-foreground">
|
|
@@ -37,12 +37,13 @@ import {
|
|
|
37
37
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
|
38
38
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
39
39
|
import { format, useLocale } from '@/lib/use-locale';
|
|
40
|
-
import { cn } from '@/lib/utils';
|
|
40
|
+
import { cn, pad2 } from '@/lib/utils';
|
|
41
41
|
import type { DesignSystem } from '../lib/design';
|
|
42
42
|
import { SlidePageProvider } from '../lib/page-context';
|
|
43
43
|
import type { Page } from '../lib/sdk';
|
|
44
44
|
import { CANVAS_HEIGHT, CANVAS_WIDTH } from '../lib/sdk';
|
|
45
45
|
import type { SlideTransition } from '../lib/transition';
|
|
46
|
+
import { prefersReducedMotion } from '../lib/use-prefers-reduced-motion';
|
|
46
47
|
import { SlideCanvas } from './slide-canvas';
|
|
47
48
|
import {
|
|
48
49
|
getCenteredThumbnailScrollTop,
|
|
@@ -269,7 +270,7 @@ export function ThumbnailRail({
|
|
|
269
270
|
<div className="flex items-center justify-between gap-2">
|
|
270
271
|
<span className="eyebrow">{t.thumbnailRail.pages}</span>
|
|
271
272
|
<div className="flex items-center gap-1.5">
|
|
272
|
-
<span className="folio">{pages.length
|
|
273
|
+
<span className="folio">{pad2(pages.length)}</span>
|
|
273
274
|
{onOverview && (
|
|
274
275
|
<Tooltip>
|
|
275
276
|
<TooltipTrigger
|
|
@@ -320,7 +321,7 @@ export function ThumbnailRail({
|
|
|
320
321
|
return (
|
|
321
322
|
<TooltipProvider delay={200}>
|
|
322
323
|
<div className="relative h-full">
|
|
323
|
-
<ScrollArea className="h-full
|
|
324
|
+
<ScrollArea className="h-full bg-sidebar [&_[data-slot=scroll-area-scrollbar]]:z-20">
|
|
324
325
|
{scrollAreaContents}
|
|
325
326
|
</ScrollArea>
|
|
326
327
|
{currentPosition && (
|
|
@@ -510,7 +511,7 @@ function HorizontalVirtualThumbList({
|
|
|
510
511
|
active ? 'text-brand' : 'text-muted-foreground/70',
|
|
511
512
|
)}
|
|
512
513
|
>
|
|
513
|
-
{(i + 1)
|
|
514
|
+
{pad2(i + 1)}
|
|
514
515
|
</span>
|
|
515
516
|
<div
|
|
516
517
|
className={cn(
|
|
@@ -727,7 +728,7 @@ function getInitialVisibleRange(current: number, count: number): VisibleRange {
|
|
|
727
728
|
}
|
|
728
729
|
|
|
729
730
|
function scrollBehavior(): ScrollBehavior {
|
|
730
|
-
return
|
|
731
|
+
return prefersReducedMotion() ? 'auto' : 'smooth';
|
|
731
732
|
}
|
|
732
733
|
|
|
733
734
|
function ThumbContents({
|
|
@@ -773,7 +774,7 @@ function ThumbContents({
|
|
|
773
774
|
active ? 'text-brand' : 'text-muted-foreground/70',
|
|
774
775
|
)}
|
|
775
776
|
>
|
|
776
|
-
{(index + 1)
|
|
777
|
+
{pad2(index + 1)}
|
|
777
778
|
</span>
|
|
778
779
|
{(hasTransition || hasSteps) && (
|
|
779
780
|
<div className="flex flex-col items-end gap-0.5">
|
|
@@ -801,12 +802,6 @@ function ThumbContents({
|
|
|
801
802
|
<PageComp />
|
|
802
803
|
</SlidePageProvider>
|
|
803
804
|
</SlideCanvas>
|
|
804
|
-
{active && (
|
|
805
|
-
<span
|
|
806
|
-
aria-hidden
|
|
807
|
-
className="pointer-events-none absolute inset-y-0 left-0 w-[2px] bg-brand"
|
|
808
|
-
/>
|
|
809
|
-
)}
|
|
810
805
|
</div>
|
|
811
806
|
</>
|
|
812
807
|
);
|
package/src/app/lib/assets.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { changedSlideIds } from './slides';
|
|
3
|
+
|
|
4
|
+
export const GLOBAL_ASSET_SCOPE = '@global';
|
|
2
5
|
|
|
3
6
|
export type AssetEntry = {
|
|
4
7
|
name: string;
|
|
@@ -205,13 +208,9 @@ export function useAssets(slideId: string): UseAssetsResult {
|
|
|
205
208
|
refresh().catch(() => {});
|
|
206
209
|
}
|
|
207
210
|
};
|
|
208
|
-
const slideHandler = (data:
|
|
209
|
-
const changedIds =
|
|
210
|
-
|
|
211
|
-
: typeof data?.slideId === 'string'
|
|
212
|
-
? [data.slideId]
|
|
213
|
-
: [];
|
|
214
|
-
if (slideId === '@global' ? changedIds.length > 0 : changedIds.includes(slideId)) {
|
|
211
|
+
const slideHandler = (data: unknown) => {
|
|
212
|
+
const changedIds = changedSlideIds(data);
|
|
213
|
+
if (slideId === GLOBAL_ASSET_SCOPE ? changedIds.length > 0 : changedIds.includes(slideId)) {
|
|
215
214
|
refresh().catch(() => {});
|
|
216
215
|
}
|
|
217
216
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function sleep(ms: number): Promise<void> {
|
|
2
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function nextFrame(): Promise<void> {
|
|
6
|
+
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// rAF in real tabs; setTimeout fallback for hidden/throttled headless tabs.
|
|
10
|
+
export function nextPaint(): Promise<void> {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
let settled = false;
|
|
13
|
+
const settle = () => {
|
|
14
|
+
if (settled) return;
|
|
15
|
+
settled = true;
|
|
16
|
+
resolve();
|
|
17
|
+
};
|
|
18
|
+
requestAnimationFrame(settle);
|
|
19
|
+
setTimeout(settle, 50);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function downloadBlob(blob: Blob, filename: string): void {
|
|
24
|
+
const url = URL.createObjectURL(blob);
|
|
25
|
+
const a = document.createElement('a');
|
|
26
|
+
a.href = url;
|
|
27
|
+
a.download = filename;
|
|
28
|
+
a.rel = 'noopener';
|
|
29
|
+
document.body.appendChild(a);
|
|
30
|
+
a.click();
|
|
31
|
+
a.remove();
|
|
32
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function dragHasFiles(e: { dataTransfer: DataTransfer | null }): boolean {
|
|
36
|
+
const types = e.dataTransfer?.types;
|
|
37
|
+
if (!types) return false;
|
|
38
|
+
for (let i = 0; i < types.length; i++) {
|
|
39
|
+
if (types[i] === 'Files') return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
3
|
import { designToCssVars } from './design';
|
|
4
|
+
import { downloadBlob, nextFrame } from './dom';
|
|
4
5
|
import { SlidePageProvider } from './page-context';
|
|
5
|
-
import type
|
|
6
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from './sdk';
|
|
6
7
|
|
|
7
8
|
type AssetEntry = { name: string; bytes: Uint8Array };
|
|
8
9
|
|
|
@@ -75,8 +76,8 @@ async function renderPagesToHtml(pages: NonNullable<SlideModule['default']>): Pr
|
|
|
75
76
|
position: 'fixed',
|
|
76
77
|
left: '-99999px',
|
|
77
78
|
top: '0',
|
|
78
|
-
width:
|
|
79
|
-
height:
|
|
79
|
+
width: `${CANVAS_WIDTH}px`,
|
|
80
|
+
height: `${CANVAS_HEIGHT}px`,
|
|
80
81
|
pointerEvents: 'none',
|
|
81
82
|
});
|
|
82
83
|
document.body.appendChild(container);
|
|
@@ -87,15 +88,15 @@ async function renderPagesToHtml(pages: NonNullable<SlideModule['default']>): Pr
|
|
|
87
88
|
const Page = pages[i];
|
|
88
89
|
if (!Page) continue;
|
|
89
90
|
const host = document.createElement('div');
|
|
90
|
-
host.style.width =
|
|
91
|
-
host.style.height =
|
|
91
|
+
host.style.width = `${CANVAS_WIDTH}px`;
|
|
92
|
+
host.style.height = `${CANVAS_HEIGHT}px`;
|
|
92
93
|
container.appendChild(host);
|
|
93
94
|
const root = createRoot(host);
|
|
94
95
|
root.render(
|
|
95
96
|
createElement(SlidePageProvider, { index: i, total: pages.length }, createElement(Page)),
|
|
96
97
|
);
|
|
97
|
-
await
|
|
98
|
-
await
|
|
98
|
+
await nextFrame();
|
|
99
|
+
await nextFrame();
|
|
99
100
|
for (const video of host.querySelectorAll('video')) {
|
|
100
101
|
video.defaultMuted = video.muted;
|
|
101
102
|
}
|
|
@@ -109,10 +110,6 @@ async function renderPagesToHtml(pages: NonNullable<SlideModule['default']>): Pr
|
|
|
109
110
|
return result;
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
function nextPaint(): Promise<void> {
|
|
113
|
-
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
113
|
function collectCss(): string {
|
|
117
114
|
const chunks: string[] = [];
|
|
118
115
|
for (const sheet of Array.from(document.styleSheets)) {
|
|
@@ -263,7 +260,7 @@ ${opts.externalLinks}
|
|
|
263
260
|
<style>
|
|
264
261
|
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-family: system-ui, sans-serif; }
|
|
265
262
|
.os-stage { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
|
|
266
|
-
.os-frame { width:
|
|
263
|
+
.os-frame { width: ${CANVAS_WIDTH}px; height: ${CANVAS_HEIGHT}px; flex-shrink: 0; background: #fff; color: #000; transform-origin: center center; overflow: hidden; position: relative; }
|
|
267
264
|
.os-page { position: absolute; inset: 0; }
|
|
268
265
|
.os-page[hidden] { display: none !important; }
|
|
269
266
|
.os-counter { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); color: #fff; background: rgba(0,0,0,.5); padding: 2px 10px; border-radius: 999px; font-size: 12px; z-index: 10; font-variant-numeric: tabular-nums; }
|
|
@@ -280,7 +277,7 @@ html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-f
|
|
|
280
277
|
var frame = document.getElementById('os-frame');
|
|
281
278
|
var cur = document.getElementById('os-cur');
|
|
282
279
|
function fit() {
|
|
283
|
-
var s = Math.min(window.innerWidth /
|
|
280
|
+
var s = Math.min(window.innerWidth / ${CANVAS_WIDTH}, window.innerHeight / ${CANVAS_HEIGHT});
|
|
284
281
|
frame.style.transform = 'scale(' + s + ')';
|
|
285
282
|
}
|
|
286
283
|
function go(i) {
|
|
@@ -325,15 +322,3 @@ function escapeHtml(s: string): string {
|
|
|
325
322
|
function escapeAttr(s: string): string {
|
|
326
323
|
return s.replace(/&/g, '&').replace(/"/g, '"');
|
|
327
324
|
}
|
|
328
|
-
|
|
329
|
-
function downloadBlob(blob: Blob, filename: string): void {
|
|
330
|
-
const url = URL.createObjectURL(blob);
|
|
331
|
-
const a = document.createElement('a');
|
|
332
|
-
a.href = url;
|
|
333
|
-
a.download = filename;
|
|
334
|
-
a.rel = 'noopener';
|
|
335
|
-
document.body.appendChild(a);
|
|
336
|
-
a.click();
|
|
337
|
-
a.remove();
|
|
338
|
-
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
339
|
-
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import { createRoot, type Root } from 'react-dom/client';
|
|
3
3
|
import { designToCssVars } from './design';
|
|
4
|
+
import { nextPaint, sleep } from './dom';
|
|
4
5
|
import { SlidePageProvider } from './page-context';
|
|
5
6
|
import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from './print-ready';
|
|
6
|
-
import type
|
|
7
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from './sdk';
|
|
7
8
|
|
|
8
9
|
const PRINT_ROOT_ID = 'os-print-root';
|
|
9
10
|
const PRINT_STYLE_ID = 'os-print-style';
|
|
10
11
|
|
|
11
12
|
const PRINT_STYLES = `
|
|
12
|
-
@page { size:
|
|
13
|
+
@page { size: ${CANVAS_WIDTH}px ${CANVAS_HEIGHT}px; margin: 0; }
|
|
13
14
|
|
|
14
15
|
@media screen {
|
|
15
16
|
#${PRINT_ROOT_ID} {
|
|
@@ -36,8 +37,8 @@ const PRINT_STYLES = `
|
|
|
36
37
|
background: #fff !important;
|
|
37
38
|
}
|
|
38
39
|
#${PRINT_ROOT_ID} .os-print-frame {
|
|
39
|
-
width:
|
|
40
|
-
height:
|
|
40
|
+
width: ${CANVAS_WIDTH}px !important;
|
|
41
|
+
height: ${CANVAS_HEIGHT}px !important;
|
|
41
42
|
background: #fff;
|
|
42
43
|
color: #000;
|
|
43
44
|
overflow: hidden;
|
|
@@ -57,8 +58,8 @@ const PRINT_STYLES = `
|
|
|
57
58
|
composites it back to 1920×1080. Vector content (text, plain CSS
|
|
58
59
|
gradients, SVG) stays vector through both transforms. */
|
|
59
60
|
#${PRINT_ROOT_ID} .os-print-supersample {
|
|
60
|
-
width:
|
|
61
|
-
height:
|
|
61
|
+
width: ${CANVAS_WIDTH}px !important;
|
|
62
|
+
height: ${CANVAS_HEIGHT}px !important;
|
|
62
63
|
zoom: 2;
|
|
63
64
|
transform: scale(0.5);
|
|
64
65
|
transform-origin: top left;
|
|
@@ -130,15 +131,15 @@ export async function exportSlideAsPdf(
|
|
|
130
131
|
const host = document.createElement('div');
|
|
131
132
|
host.className = 'os-print-frame';
|
|
132
133
|
host.setAttribute('data-osd-canvas', '');
|
|
133
|
-
host.style.width =
|
|
134
|
-
host.style.height =
|
|
134
|
+
host.style.width = `${CANVAS_WIDTH}px`;
|
|
135
|
+
host.style.height = `${CANVAS_HEIGHT}px`;
|
|
135
136
|
if (designVars) {
|
|
136
137
|
for (const [k, v] of Object.entries(designVars)) host.style.setProperty(k, v);
|
|
137
138
|
}
|
|
138
139
|
const inner = document.createElement('div');
|
|
139
140
|
inner.className = 'os-print-supersample';
|
|
140
|
-
inner.style.width =
|
|
141
|
-
inner.style.height =
|
|
141
|
+
inner.style.width = `${CANVAS_WIDTH}px`;
|
|
142
|
+
inner.style.height = `${CANVAS_HEIGHT}px`;
|
|
142
143
|
host.appendChild(inner);
|
|
143
144
|
root.appendChild(host);
|
|
144
145
|
frames.push(host);
|
|
@@ -266,24 +267,6 @@ function splitBackgroundImageLayers(backgroundImage: string): string[] {
|
|
|
266
267
|
return layers;
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
function sleep(ms: number): Promise<void> {
|
|
270
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function nextPaint(): Promise<void> {
|
|
274
|
-
// rAF in real tabs; setTimeout fallback for hidden/throttled headless tabs.
|
|
275
|
-
return new Promise((resolve) => {
|
|
276
|
-
let settled = false;
|
|
277
|
-
const settle = () => {
|
|
278
|
-
if (settled) return;
|
|
279
|
-
settled = true;
|
|
280
|
-
resolve();
|
|
281
|
-
};
|
|
282
|
-
requestAnimationFrame(settle);
|
|
283
|
-
setTimeout(settle, 50);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
|
|
287
270
|
function waitForAfterPrint(timeoutMs = 60_000): Promise<void> {
|
|
288
271
|
return new Promise((resolve) => {
|
|
289
272
|
const cleanup = () => {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import { createRoot, type Root } from 'react-dom/client';
|
|
3
3
|
import { designToCssVars } from './design';
|
|
4
|
+
import { downloadBlob, nextPaint, sleep } from './dom';
|
|
4
5
|
import { SlidePageProvider } from './page-context';
|
|
5
6
|
import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from './print-ready';
|
|
6
|
-
import type
|
|
7
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from './sdk';
|
|
7
8
|
|
|
8
|
-
const SLIDE_W = 1920;
|
|
9
|
-
const SLIDE_H = 1080;
|
|
10
9
|
// 16:9 widescreen in English Metric Units (914400 EMU per inch → 13.333in × 7.5in).
|
|
11
10
|
const EMU_W = 12192000;
|
|
12
11
|
const EMU_H = 6858000;
|
|
@@ -78,8 +77,8 @@ export async function exportSlideAsImagePptx(
|
|
|
78
77
|
if (!Page) continue;
|
|
79
78
|
const host = document.createElement('div');
|
|
80
79
|
host.setAttribute('data-osd-canvas', '');
|
|
81
|
-
host.style.width = `${
|
|
82
|
-
host.style.height = `${
|
|
80
|
+
host.style.width = `${CANVAS_WIDTH}px`;
|
|
81
|
+
host.style.height = `${CANVAS_HEIGHT}px`;
|
|
83
82
|
host.style.overflow = 'hidden';
|
|
84
83
|
host.style.background = '#fff';
|
|
85
84
|
if (designVars) {
|
|
@@ -112,8 +111,8 @@ export async function exportSlideAsImagePptx(
|
|
|
112
111
|
for (let i = 0; i < frames.length; i++) {
|
|
113
112
|
freezeForCapture(frames[i]);
|
|
114
113
|
const blob = await toBlob(frames[i], {
|
|
115
|
-
width:
|
|
116
|
-
height:
|
|
114
|
+
width: CANVAS_WIDTH,
|
|
115
|
+
height: CANVAS_HEIGHT,
|
|
117
116
|
pixelRatio: CAPTURE_PIXEL_RATIO,
|
|
118
117
|
backgroundColor: '#ffffff',
|
|
119
118
|
cacheBust: true,
|
|
@@ -253,32 +252,3 @@ function slideRelsXml(idx: number): string {
|
|
|
253
252
|
function themeXml(): string {
|
|
254
253
|
return `${XML_DECL}<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:lumMod val="110000"/><a:satMod val="105000"/><a:tint val="67000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="103000"/><a:tint val="73000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="109000"/><a:tint val="81000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:satMod val="103000"/><a:lumMod val="102000"/><a:tint val="94000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:satMod val="110000"/><a:lumMod val="100000"/><a:shade val="100000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="99000"/><a:satMod val="120000"/><a:shade val="78000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"><a:tint val="95000"/><a:satMod val="170000"/></a:schemeClr></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="93000"/><a:satMod val="150000"/><a:shade val="98000"/><a:lumMod val="102000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:tint val="98000"/><a:satMod val="130000"/><a:shade val="90000"/><a:lumMod val="103000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="63000"/><a:satMod val="120000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`;
|
|
255
254
|
}
|
|
256
|
-
|
|
257
|
-
function sleep(ms: number): Promise<void> {
|
|
258
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function nextPaint(): Promise<void> {
|
|
262
|
-
return new Promise((resolve) => {
|
|
263
|
-
let settled = false;
|
|
264
|
-
const settle = () => {
|
|
265
|
-
if (settled) return;
|
|
266
|
-
settled = true;
|
|
267
|
-
resolve();
|
|
268
|
-
};
|
|
269
|
-
requestAnimationFrame(settle);
|
|
270
|
-
setTimeout(settle, 50);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function downloadBlob(blob: Blob, filename: string): void {
|
|
275
|
-
const url = URL.createObjectURL(blob);
|
|
276
|
-
const a = document.createElement('a');
|
|
277
|
-
a.href = url;
|
|
278
|
-
a.download = filename;
|
|
279
|
-
a.rel = 'noopener';
|
|
280
|
-
document.body.appendChild(a);
|
|
281
|
-
a.click();
|
|
282
|
-
a.remove();
|
|
283
|
-
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
284
|
-
}
|
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
|
+
}
|