@open-press/core 1.1.4 → 1.2.1

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.
Files changed (51) hide show
  1. package/engine/cli.mjs +3 -3
  2. package/engine/commands/_shared.mjs +89 -13
  3. package/engine/commands/deploy.mjs +19 -4
  4. package/engine/commands/image.mjs +9 -3
  5. package/engine/commands/pdf.mjs +4 -1
  6. package/engine/output/chrome-pdf.mjs +102 -0
  7. package/engine/output/static-server.mjs +64 -17
  8. package/engine/react/document-export.mjs +22 -0
  9. package/package.json +1 -1
  10. package/src/openpress/app/OpenPressApp.tsx +5 -1
  11. package/src/openpress/app/OpenPressRuntime.tsx +85 -6
  12. package/src/openpress/reader/PageThumbnailsPanel.tsx +28 -5
  13. package/src/openpress/reader/PublicReaderPage.tsx +163 -74
  14. package/src/openpress/reader/SlidePresentationPage.tsx +37 -15
  15. package/src/openpress/reader/SlidePublicPage.tsx +332 -0
  16. package/src/openpress/reader/index.ts +1 -0
  17. package/src/openpress/reader/pageViewportScaleModel.ts +5 -3
  18. package/src/openpress/reader/usePageViewportScale.ts +9 -5
  19. package/src/openpress/reader/usePanelState.ts +14 -5
  20. package/src/openpress/shared/index.ts +1 -0
  21. package/src/openpress/shared/staticSearch.ts +174 -0
  22. package/src/openpress/workbench/Workbench.tsx +61 -176
  23. package/src/openpress/workbench/actions/DeploymentControl.tsx +1 -1
  24. package/src/openpress/workbench/actions/ExportControl.tsx +267 -0
  25. package/src/openpress/workbench/actions/SearchControl.tsx +32 -43
  26. package/src/openpress/workbench/actions/index.ts +1 -1
  27. package/src/openpress/workbench/actions/useDeploymentWorkbench.ts +21 -5
  28. package/src/openpress/workbench/hooks/useWorkbenchNavigation.ts +42 -0
  29. package/src/openpress/workbench/inspector/useInspectorComments.ts +6 -6
  30. package/src/openpress/workbench/project/ProjectEntryPanel.tsx +2 -278
  31. package/src/openpress/workbench/shell/WorkbenchShell.tsx +44 -18
  32. package/src/openpress/workbench/shell/WorkbenchToolbarActions.tsx +206 -0
  33. package/src/styles/openpress/app-shell.css +0 -83
  34. package/src/styles/openpress/print-route.css +1 -3
  35. package/src/styles/openpress/project-preview-panel.css +5 -783
  36. package/src/styles/openpress/public-viewer.css +7 -249
  37. package/src/styles/openpress/reader-runtime.css +0 -274
  38. package/src/styles/openpress/slide-presenter.css +150 -0
  39. package/src/styles/openpress/slide-public-viewer.css +222 -0
  40. package/src/styles/openpress/workbench-dialog.css +267 -0
  41. package/src/styles/openpress/workbench-export.css +154 -0
  42. package/src/styles/openpress/workbench-inline-editor.css +128 -0
  43. package/src/styles/openpress/workbench-panels.css +0 -88
  44. package/src/styles/openpress/workbench-search.css +257 -0
  45. package/src/styles/openpress/workbench-toolbar.css +422 -0
  46. package/src/styles/openpress/workbench.css +34 -1263
  47. package/src/styles/openpress/workspace-gallery.css +0 -5
  48. package/src/styles/openpress.css +7 -1
  49. package/vite.config.ts +66 -17
  50. package/src/openpress/workbench/actions/ExportImageControl.tsx +0 -96
  51. package/src/styles/openpress/media-workspace.css +0 -230
@@ -1,43 +1,15 @@
1
1
  import { useCallback, useEffect, useId, useMemo, useRef, useState, type FormEvent } from "react";
2
2
  import { FileText, Loader2, Search } from "lucide-react";
3
3
  import type { SourceBlock } from "../../document-model";
4
+ import type { SearchReport, SearchScope } from "../../shared";
4
5
  import { WorkbenchDialog } from "../dialog";
5
6
 
6
- type SearchScope = "content" | "all";
7
7
  type SearchStatus = "idle" | "loading" | "success" | "error";
8
8
  const SEARCH_SCOPE: SearchScope = "all";
9
9
  const LIVE_SEARCH_DEBOUNCE_MS = 280;
10
10
 
11
- type SearchFile = {
12
- scope: string;
13
- file: string;
14
- path: string;
15
- matchCount: number;
16
- };
17
-
18
- type SearchMatch = {
19
- id: string;
20
- scope: string;
21
- file: string;
22
- path: string;
23
- line: number;
24
- column: number;
25
- index: number;
26
- text: string;
27
- preview: string;
28
- };
29
-
30
- type SearchReport = {
31
- ok?: boolean;
32
- kind: "search";
33
- query: string;
34
- scope: SearchScope;
35
- caseSensitive: boolean;
36
- matchCount: number;
37
- files: Array<SearchFile>;
38
- matches: Array<SearchMatch>;
39
- message?: string;
40
- };
11
+ type SearchFile = SearchReport["files"][number];
12
+ type SearchMatch = SearchReport["matches"][number];
41
13
 
42
14
  type SearchJumpTarget = {
43
15
  blockId: string;
@@ -45,12 +17,37 @@ type SearchJumpTarget = {
45
17
  pageNumber: number;
46
18
  };
47
19
 
20
+ export interface SearchControlSearcherArgs {
21
+ query: string;
22
+ scope: SearchScope;
23
+ signal: AbortSignal;
24
+ }
25
+
26
+ export type SearchControlSearcher = (args: SearchControlSearcherArgs) => Promise<SearchReport>;
27
+
28
+ // Default searcher: hits the dev-only /__openpress/search endpoint.
29
+ // Public deploys override this via the `searcher` prop with a static
30
+ // in-browser searcher backed by /openpress/search-corpus.json.
31
+ async function liveSearcher({ query, scope, signal }: SearchControlSearcherArgs): Promise<SearchReport> {
32
+ const params = new URLSearchParams();
33
+ params.set("q", query);
34
+ params.set("scope", scope);
35
+ const response = await fetch(`/__openpress/search?${params.toString()}`, { cache: "no-store", signal });
36
+ const data = (await response.json().catch(() => null)) as (Partial<SearchReport> & { message?: string }) | null;
37
+ if (!response.ok || data?.ok === false || !isSearchReport(data)) {
38
+ throw new Error(data?.message ?? "搜尋失敗。");
39
+ }
40
+ return data;
41
+ }
42
+
48
43
  export function SearchControl({
49
44
  sourceBlocksByPath = {},
50
45
  onSelectPage,
46
+ searcher = liveSearcher,
51
47
  }: {
52
48
  sourceBlocksByPath?: Record<string, SourceBlock[]>;
53
49
  onSelectPage?: (pageIndex: number, options?: { behavior?: ScrollBehavior }) => void;
50
+ searcher?: SearchControlSearcher;
54
51
  }) {
55
52
  const titleId = useId();
56
53
  const [open, setOpen] = useState(false);
@@ -98,26 +95,18 @@ export function SearchControl({
98
95
  setError("");
99
96
 
100
97
  try {
101
- const params = new URLSearchParams();
102
- params.set("q", trimmedQuery);
103
- params.set("scope", SEARCH_SCOPE);
104
- const response = await fetch(`/__openpress/search?${params.toString()}`, {
105
- cache: "no-store",
106
- signal: controller.signal,
107
- });
108
- const data = await response.json().catch(() => null) as (Partial<SearchReport> & { message?: string }) | null;
98
+ const data = await searcher({ query: trimmedQuery, scope: SEARCH_SCOPE, signal: controller.signal });
109
99
  if (controller.signal.aborted || requestId !== searchRequestIdRef.current) return;
110
- if (!response.ok || data?.ok === false || !isSearchReport(data)) {
111
- throw new Error(data?.message ?? "搜尋失敗。");
112
- }
100
+ if (!isSearchReport(data)) throw new Error("搜尋失敗。");
113
101
  setReport(data);
114
102
  setStatus("success");
115
103
  } catch (searchError) {
116
104
  if (controller.signal.aborted || requestId !== searchRequestIdRef.current) return;
105
+ if (searchError instanceof DOMException && searchError.name === "AbortError") return;
117
106
  setError(searchError instanceof Error ? searchError.message : String(searchError));
118
107
  setStatus("error");
119
108
  }
120
- }, []);
109
+ }, [searcher]);
121
110
 
122
111
  useEffect(() => {
123
112
  if (!open) return undefined;
@@ -1,6 +1,6 @@
1
1
  export * from "./deploymentStatusModel";
2
2
  export * from "./DeploymentControl";
3
- export * from "./ExportImageControl";
3
+ export * from "./ExportControl";
4
4
  export * from "./PageZoomControl";
5
5
  export * from "./SearchControl";
6
6
  export * from "./useDeploymentWorkbench";
@@ -6,6 +6,12 @@ import { parseDeployError, workbenchPdfButtonText, workbenchPdfStatusMessage } f
6
6
 
7
7
  export interface UseDeploymentWorkbenchOptions {
8
8
  deploymentInfo: DeploymentInfo;
9
+ // Active Press slug — when present the local PDF export endpoint
10
+ // tells the CLI to export this Press (open-press pdf . --press <slug>)
11
+ // instead of defaulting to the first Press. Empty / null means the
12
+ // workspace has only one Press, or the workbench is at the gallery
13
+ // root, and the CLI default is correct.
14
+ pressSlug?: string | null;
9
15
  }
10
16
 
11
17
  export interface DeploymentWorkbench {
@@ -22,7 +28,7 @@ export interface DeploymentWorkbench {
22
28
  handleOpenWorkbenchPdf: () => void;
23
29
  }
24
30
 
25
- export function useDeploymentWorkbench({ deploymentInfo }: UseDeploymentWorkbenchOptions): DeploymentWorkbench {
31
+ export function useDeploymentWorkbench({ deploymentInfo, pressSlug = null }: UseDeploymentWorkbenchOptions): DeploymentWorkbench {
26
32
  const [status, setStatus] = useState<DeployStatus>("idle");
27
33
  const [pdfActionStatus, setPdfActionStatus] = useState<PdfActionStatus>("idle");
28
34
  const [currentDeploymentInfo, setCurrentDeploymentInfo] = useState(deploymentInfo);
@@ -48,7 +54,12 @@ export function useDeploymentWorkbench({ deploymentInfo }: UseDeploymentWorkbenc
48
54
  }
49
55
  setStatus("deploying");
50
56
  try {
51
- const response = await fetch("/__openpress/deploy", { method: "POST" });
57
+ const requestBody = pressSlug ? { press: pressSlug } : {};
58
+ const response = await fetch("/__openpress/deploy", {
59
+ method: "POST",
60
+ headers: { "Content-Type": "application/json" },
61
+ body: JSON.stringify(requestBody),
62
+ });
52
63
  if (response.status === 404 || response.status === 405) {
53
64
  setStatus("unavailable");
54
65
  return;
@@ -90,13 +101,18 @@ export function useDeploymentWorkbench({ deploymentInfo }: UseDeploymentWorkbenc
90
101
  console.error("OpenPress deploy unavailable", error);
91
102
  setStatus("unavailable");
92
103
  }
93
- }, [status, currentDeploymentInfo.configured]);
104
+ }, [status, currentDeploymentInfo.configured, pressSlug]);
94
105
 
95
106
  const handleOpenLatestLocalPdf = useCallback(async () => {
96
107
  if (pdfActionStatus === "generating") return;
97
108
  setPdfActionStatus("generating");
98
109
  try {
99
- const response = await fetch("/__openpress/local-pdf-export", { method: "POST" });
110
+ const requestBody = pressSlug ? { press: pressSlug } : {};
111
+ const response = await fetch("/__openpress/local-pdf-export", {
112
+ method: "POST",
113
+ headers: { "Content-Type": "application/json" },
114
+ body: JSON.stringify(requestBody),
115
+ });
100
116
  if (!response.ok) {
101
117
  const text = await response.text().catch(() => "");
102
118
  throw new Error(text || `Local PDF export failed with status ${response.status}`);
@@ -109,7 +125,7 @@ export function useDeploymentWorkbench({ deploymentInfo }: UseDeploymentWorkbenc
109
125
  console.error("OpenPress local PDF export failed", error);
110
126
  setPdfActionStatus("failed");
111
127
  }
112
- }, [pdfActionStatus]);
128
+ }, [pdfActionStatus, pressSlug]);
113
129
 
114
130
  const handleOpenWorkbenchPdf = useCallback(() => {
115
131
  if (localDeployEnabled) {
@@ -0,0 +1,42 @@
1
+ import { useCallback } from "react";
2
+ import { resolveAnchorPageIndex } from "../../document-model";
3
+ import { PUBLIC_DRAWER_BREAKPOINT, type DisplayPage } from "../../reader";
4
+
5
+ type SetPage = (pageIndex: number, options?: { behavior?: ScrollBehavior }) => void;
6
+
7
+ export function useWorkbenchNavigation({
8
+ anchorPageMap,
9
+ pages,
10
+ rightPanelOpen,
11
+ setPage,
12
+ toggleRightPanel,
13
+ }: {
14
+ anchorPageMap: Map<string, number>;
15
+ pages: DisplayPage[];
16
+ rightPanelOpen: boolean;
17
+ setPage: SetPage;
18
+ toggleRightPanel: () => void;
19
+ }) {
20
+ const selectWorkspacePage = useCallback((pageIndex: number, options?: { behavior?: ScrollBehavior }) => {
21
+ setPage(pageIndex, options);
22
+ if (
23
+ typeof window !== "undefined"
24
+ && window.innerWidth < PUBLIC_DRAWER_BREAKPOINT
25
+ && rightPanelOpen
26
+ ) {
27
+ toggleRightPanel();
28
+ }
29
+ }, [rightPanelOpen, setPage, toggleRightPanel]);
30
+
31
+ const selectWorkspaceAnchor = useCallback((anchorId: string, pageIndex?: number) => {
32
+ const targetPageIndex = resolveAnchorPageIndex(anchorPageMap, pages.length, anchorId, pageIndex);
33
+ if (targetPageIndex === null) return false;
34
+ selectWorkspacePage(targetPageIndex, { behavior: "smooth" });
35
+ return true;
36
+ }, [anchorPageMap, pages.length, selectWorkspacePage]);
37
+
38
+ return {
39
+ selectWorkspaceAnchor,
40
+ selectWorkspacePage,
41
+ };
42
+ }
@@ -8,7 +8,7 @@ import type { InspectorState, PendingComment } from "./inspectorModel";
8
8
  import { getInlineSavedCommentForTarget, resolveInlineSavedComment } from "./inlineCommentModel";
9
9
 
10
10
  export interface UseInspectorCommentsOptions {
11
- devMode: boolean;
11
+ workspaceMode: boolean;
12
12
  inspector: InspectorState;
13
13
  sourceBlockMap: Record<string, SourceBlock>;
14
14
  sourceBlocksByPath: Record<string, SourceBlock[]>;
@@ -36,7 +36,7 @@ export interface InspectorComments {
36
36
  }
37
37
 
38
38
  export function useInspectorComments({
39
- devMode,
39
+ workspaceMode,
40
40
  inspector,
41
41
  sourceBlockMap,
42
42
  sourceBlocksByPath,
@@ -76,7 +76,7 @@ export function useInspectorComments({
76
76
  );
77
77
 
78
78
  const refreshPendingComments = useCallback(async () => {
79
- if (!devMode) return;
79
+ if (!workspaceMode) return;
80
80
  setCommentsStatus("loading");
81
81
  setCommentsError("");
82
82
  try {
@@ -87,7 +87,7 @@ export function useInspectorComments({
87
87
  setCommentsStatus("failed");
88
88
  setCommentsError(error instanceof Error ? error.message : String(error));
89
89
  }
90
- }, [devMode]);
90
+ }, [workspaceMode]);
91
91
 
92
92
  const clearPendingComment = useCallback(async (id: string) => {
93
93
  setCommentsStatus("clearing");
@@ -225,9 +225,9 @@ export function useInspectorComments({
225
225
 
226
226
  // Initial + dev-mode refresh of pending comments.
227
227
  useEffect(() => {
228
- if (!devMode) return;
228
+ if (!workspaceMode) return;
229
229
  void refreshPendingComments();
230
- }, [devMode, refreshPendingComments]);
230
+ }, [workspaceMode, refreshPendingComments]);
231
231
 
232
232
  return {
233
233
  pendingComments,
@@ -1,7 +1,6 @@
1
- import { memo, useState, type CSSProperties } from "react";
2
- import { Component as ComponentIcon, Images, Palette, type LucideIcon } from "lucide-react";
1
+ import { memo, useState } from "react";
2
+ import { Component as ComponentIcon } from "lucide-react";
3
3
  import type { BookmarkItem, BookmarkSubItem, MediaAssetItem } from "../../document-model";
4
- import { projectSourceDirectoryPath, PROJECT_SOURCES } from "./projectSourceModel";
5
4
  import type { BlockSource } from "../../document-model";
6
5
  import type { DisplayPage } from "../../reader";
7
6
  import { Panel } from "../panels/Panel";
@@ -15,10 +14,6 @@ import {
15
14
  export { createProjectObjectEntityId } from "./projectPreviewTypes";
16
15
  export type { ProjectMentionItem, ProjectPanelPreview } from "./projectPreviewTypes";
17
16
 
18
- export const PROJECT_VISUAL_SYSTEM_KEY = "visual-system";
19
- export const PROJECT_IMAGE_GALLERY_KEY = "image-gallery";
20
- export const PROJECT_COMPONENT_LIBRARY_KEY = "component-library";
21
-
22
17
  export type ProjectComponentUsage = {
23
18
  count: number;
24
19
  pageIndexes: number[];
@@ -167,264 +162,6 @@ function ProjectEntryPanelImpl({
167
162
  export const ProjectEntryPanel = memo(ProjectEntryPanelImpl);
168
163
  ProjectEntryPanel.displayName = "ProjectEntryPanel";
169
164
 
170
- export function ProjectPreviewPanel({
171
- mediaAssets,
172
- componentUsages,
173
- selectedKey,
174
- }: {
175
- mediaAssets: MediaAssetItem[];
176
- componentUsages: Map<string, ProjectComponentUsage>;
177
- selectedKey: string | null;
178
- }) {
179
- if (!selectedKey || selectedKey === PROJECT_VISUAL_SYSTEM_KEY) {
180
- return <ProjectVisualSystem />;
181
- }
182
-
183
- if (selectedKey === PROJECT_IMAGE_GALLERY_KEY) {
184
- return <ProjectImageGallery mediaAssets={mediaAssets} />;
185
- }
186
-
187
- if (selectedKey === PROJECT_COMPONENT_LIBRARY_KEY) {
188
- return <ProjectComponentLibrary usages={componentUsages} />;
189
- }
190
-
191
- return <ProjectVisualSystem />;
192
- }
193
-
194
- function ProjectPanelButton({
195
- icon: Icon,
196
- label,
197
- meta,
198
- active,
199
- onClick,
200
- }: {
201
- icon: LucideIcon;
202
- label: string;
203
- meta: string;
204
- active: boolean;
205
- onClick: () => void;
206
- }) {
207
- return (
208
- <button
209
- type="button"
210
- className={`bookmark-item bookmark-h2 openpress-project-entry${active ? " is-active" : ""}`}
211
- aria-pressed={active}
212
- onClick={onClick}
213
- >
214
- <span className="bookmark-index openpress-project-entry-icon"><Icon aria-hidden="true" /></span>
215
- <span className="bookmark-title">
216
- <span>{label}</span>
217
- <small>{meta}</small>
218
- </span>
219
- </button>
220
- );
221
- }
222
-
223
- function ProjectVisualSystem() {
224
- return (
225
- <section className="openpress-project-preview-panel" aria-label="專案">
226
- <article className="openpress-project-visual-system" aria-label="Visual System">
227
- <ProjectSectionHeader title="Visual System" minimal />
228
-
229
- <div className="openpress-project-visual-grid">
230
- <section className="openpress-project-visual-card openpress-project-visual-card--typography" aria-label="Typography">
231
- <header>
232
- <span>Typography</span>
233
- <strong>閱讀層級</strong>
234
- </header>
235
- <div className="openpress-project-type-specimen">
236
- <p className="openpress-project-type-kicker">Course Notes</p>
237
- <h2>Data Structures</h2>
238
- <h3>Linked List 與 Tree Traversal</h3>
239
- <h4>Pointer / Node / Recursive Thinking</h4>
240
- <p>以 C/C++ 實作資料結構,整理概念、表示法與操作流程。</p>
241
- <code>struct Node *next = head;</code>
242
- </div>
243
- </section>
244
-
245
- <section className="openpress-project-visual-card" aria-label="Color Palette">
246
- <header>
247
- <span>Palette</span>
248
- <strong>色票配置</strong>
249
- </header>
250
- <div className="openpress-project-swatch-grid">
251
- {PROJECT_COLOR_SWATCHES.map((item) => (
252
- <div className="openpress-project-swatch" key={item.token}>
253
- <span
254
- className="openpress-project-swatch-chip"
255
- style={{ "--openpress-project-swatch": `var(${item.token})` } as CSSProperties}
256
- aria-hidden="true"
257
- />
258
- <strong>{item.label}</strong>
259
- <code>{item.token.replace("--openpress-", "")}</code>
260
- </div>
261
- ))}
262
- </div>
263
- </section>
264
-
265
- <section className="openpress-project-visual-card openpress-project-visual-card--surfaces" aria-label="Surfaces">
266
- <header>
267
- <span>Surfaces</span>
268
- <strong>區塊背景</strong>
269
- </header>
270
- <div className="openpress-project-surface-preview">
271
- <div className="openpress-project-surface-paper">
272
- <span>Page paper</span>
273
- </div>
274
- <div className="openpress-project-surface-block">
275
- <span>Figure / Code block</span>
276
- </div>
277
- </div>
278
- </section>
279
- </div>
280
- </article>
281
- </section>
282
- );
283
- }
284
-
285
- function ProjectComponentLibrary({
286
- usages,
287
- }: {
288
- usages: Map<string, ProjectComponentUsage>;
289
- }) {
290
- const previewItems = createComponentPreviewItems(usages);
291
- return (
292
- <section className="openpress-project-preview-panel" aria-label="專案">
293
- <article className="openpress-project-component-viewer" aria-label={PROJECT_SOURCES.components.label}>
294
- <ProjectSectionHeader
295
- title="Rendered Components"
296
- description="文件目前實際渲染出的 component、圖表與示意圖狀態。"
297
- stats={[
298
- ["Kinds", String(usages.size)],
299
- ["Renders", String(previewItems.length)],
300
- ]}
301
- />
302
- {previewItems.length > 0 ? (
303
- <div className="openpress-project-component-list" aria-label="rendered content block list">
304
- {previewItems.map((item) => (
305
- <figure className="openpress-project-component-preview-row" key={`${item.name}-${item.index}`}>
306
- <figcaption>
307
- <span>{item.name}</span>
308
- <small>P{String(item.preview.pageIndex + 1).padStart(2, "0")}</small>
309
- </figcaption>
310
- <div
311
- className="openpress-project-component-preview"
312
- dangerouslySetInnerHTML={{ __html: item.preview.html }}
313
- />
314
- </figure>
315
- ))}
316
- </div>
317
- ) : (
318
- <p className="openpress-project-empty">目前文件尚未渲染任何內容區塊。</p>
319
- )}
320
- </article>
321
- </section>
322
- );
323
- }
324
-
325
- function ProjectImageGallery({
326
- mediaAssets,
327
- }: {
328
- mediaAssets: MediaAssetItem[];
329
- }) {
330
- const usedCount = mediaAssets.filter((item) => item.usageCount > 0).length;
331
- const unreferencedAssets = mediaAssets.filter((item) => item.usageCount === 0);
332
- const referencedAssets = mediaAssets.filter((item) => item.usageCount > 0);
333
- return (
334
- <section className="openpress-project-preview-panel" aria-label="專案">
335
- <article className="openpress-project-gallery-viewer" aria-label="Image Gallery">
336
- <ProjectSectionHeader
337
- title="Media Library"
338
- description={projectSourceDirectoryPath("media")}
339
- stats={[
340
- ["Files", String(mediaAssets.length)],
341
- ["Used", String(usedCount)],
342
- ]}
343
- />
344
- {mediaAssets.length > 0 ? (
345
- <div className="openpress-project-media-sections" aria-label="media gallery">
346
- <ProjectMediaSection title="未引用" assets={unreferencedAssets} />
347
- <ProjectMediaSection title="已引用" assets={referencedAssets} />
348
- </div>
349
- ) : (
350
- <p className="openpress-project-empty">{projectSourceDirectoryPath("media")} 尚未有可預覽素材。</p>
351
- )}
352
- </article>
353
- </section>
354
- );
355
- }
356
-
357
- function ProjectSectionHeader({
358
- title,
359
- description,
360
- stats,
361
- minimal = false,
362
- }: {
363
- title: string;
364
- description?: string;
365
- stats?: Array<[string, string]>;
366
- minimal?: boolean;
367
- }) {
368
- return (
369
- <header className={`openpress-project-section-header${minimal ? " openpress-project-section-header--minimal" : ""}`}>
370
- <div>
371
- <h2>{title}</h2>
372
- {description ? <span>{description}</span> : null}
373
- </div>
374
- {!minimal && stats?.length ? (
375
- <dl>
376
- {stats.map(([label, value]) => (
377
- <div key={label}>
378
- <dt>{label}</dt>
379
- <dd>{value}</dd>
380
- </div>
381
- ))}
382
- </dl>
383
- ) : null}
384
- </header>
385
- );
386
- }
387
-
388
- function ProjectMediaSection({
389
- title,
390
- assets,
391
- }: {
392
- title: string;
393
- assets: MediaAssetItem[];
394
- }) {
395
- return (
396
- <section className="openpress-project-media-section" aria-label={title}>
397
- <header className="openpress-project-media-section-header">
398
- <h3>{title}</h3>
399
- </header>
400
- {assets.length > 0 ? (
401
- <div className="openpress-project-media-gallery">
402
- {assets.map((item) => (
403
- <figure className="openpress-project-media-card" data-unused={item.usageCount === 0 ? "true" : "false"} key={item.id}>
404
- <img src={item.src} alt="" loading="lazy" />
405
- <figcaption>
406
- <strong>{item.fileName}</strong>
407
- </figcaption>
408
- </figure>
409
- ))}
410
- </div>
411
- ) : (
412
- <p className="openpress-project-media-section-empty">沒有{title}圖片。</p>
413
- )}
414
- </section>
415
- );
416
- }
417
-
418
- function createComponentPreviewItems(usages: Map<string, ProjectComponentUsage>) {
419
- return Array.from(usages.entries())
420
- .flatMap(([name, usage]) => usage.previews.map((preview, index) => ({ name, preview, index })))
421
- .filter((item) => Boolean(item.preview.html))
422
- .sort((a, b) => {
423
- const pageDelta = a.preview.pageIndex - b.preview.pageIndex;
424
- return pageDelta || a.name.localeCompare(b.name, "zh-Hant") || a.index - b.index;
425
- });
426
- }
427
-
428
165
  function extractRenderedComponentBlocks(html: string) {
429
166
  const blocks: Array<{ name: string; html: string }> = [];
430
167
  const openTagPattern = /<(figure|section|article|div)\b[^>]*data-openpress-component="([^"]+)"[^>]*>/g;
@@ -510,16 +247,3 @@ const PROJECT_SKILL_MENTIONS: ProjectMentionItem[] = [
510
247
  { trigger: "/", value: "/apply-style", label: "apply-style", meta: "skill", kind: "skill" },
511
248
  { trigger: "/", value: "/fix-code", label: "fix-code", meta: "skill", kind: "skill" },
512
249
  ];
513
-
514
- const PROJECT_COLOR_SWATCHES = [
515
- { label: "Document", token: "--openpress-color-document" },
516
- { label: "Paper", token: "--openpress-color-paper" },
517
- { label: "Ink", token: "--openpress-color-ink" },
518
- { label: "Body", token: "--openpress-color-body" },
519
- { label: "Muted", token: "--openpress-color-muted" },
520
- { label: "Subtle", token: "--openpress-color-subtle" },
521
- { label: "Line", token: "--openpress-color-line" },
522
- { label: "Block", token: "--openpress-color-block" },
523
- { label: "Info", token: "--openpress-color-info" },
524
- { label: "Green", token: "--openpress-color-green" },
525
- ];