From bc1491bed526b4f9361b661e3fd971041663ea23 Mon Sep 17 00:00:00 2001 From: yiling Date: Sat, 18 Jul 2026 10:32:38 +0800 Subject: [PATCH] feat(transcode): add PDF preview, sprite generation, and annotation support --- Dockerfile | 1 + README.md | 10 +- README_CN.md | 10 +- bun.lock | 55 +++- docs/using-shumai/agent-tools.mdx | 16 +- package.json | 3 +- packages/core/src/asset/asset.ts | 1 + packages/core/src/transcode/transcode.ts | 133 +++++++++ packages/core/src/upload/upload.ts | 11 +- packages/dtos/src/asset.ts | 1 + .../src/activities/transcode.test.ts | 17 +- .../transcode/src/activities/transcode.ts | 47 +++- packages/transcode/src/transcoder.ts | 38 +++ .../transcode/src/workflows/transcode.test.ts | 83 ++++++ .../components/file-browser/file-preview.tsx | 24 +- .../webui/components/viewers/pdf/index.tsx | 14 + .../viewers/pdf/pdf-control-bar.tsx | 91 +++++++ .../components/viewers/pdf/pdf-viewer.tsx | 257 ++++++++++++++++++ packages/webui/components/viewers/registry.ts | 3 +- packages/webui/css.d.ts | 5 + packages/webui/messages/en.json | 3 + packages/webui/messages/zh.json | 5 +- packages/webui/paraglide/messages/_index.d.ts | 3 + packages/webui/paraglide/messages/_index.js | 3 + packages/webui/paraglide/messages/fit.js | 2 +- .../webui/paraglide/messages/next_page.d.ts | 16 ++ .../webui/paraglide/messages/next_page.js | 29 ++ .../paraglide/messages/page_of_pages.d.ts | 19 ++ .../webui/paraglide/messages/page_of_pages.js | 29 ++ .../paraglide/messages/previous_page.d.ts | 16 ++ .../webui/paraglide/messages/previous_page.js | 29 ++ 31 files changed, 928 insertions(+), 46 deletions(-) create mode 100644 packages/webui/components/viewers/pdf/index.tsx create mode 100644 packages/webui/components/viewers/pdf/pdf-control-bar.tsx create mode 100644 packages/webui/components/viewers/pdf/pdf-viewer.tsx create mode 100644 packages/webui/paraglide/messages/next_page.d.ts create mode 100644 packages/webui/paraglide/messages/next_page.js create mode 100644 packages/webui/paraglide/messages/page_of_pages.d.ts create mode 100644 packages/webui/paraglide/messages/page_of_pages.js create mode 100644 packages/webui/paraglide/messages/previous_page.d.ts create mode 100644 packages/webui/paraglide/messages/previous_page.js diff --git a/Dockerfile b/Dockerfile index 33d401a0..5e0a8fb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ bubblewrap \ gosu \ + poppler-utils \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index 93486001..41501479 100644 --- a/README.md +++ b/README.md @@ -125,23 +125,24 @@ mkdir shumai && cd shumai Shumai requires the following system packages on Linux: - **`ffmpeg`** – Used for media transcoding and metadata extraction. +- **`poppler`** (`poppler-utils`) – Used for PDF page image extraction and PDF sprite preview generation (`pdftoppm`). - **`bubblewrap`**, **`socat`**, and **`ripgrep`** – Required by the AI agent sandbox (`anthropic-experimental/sandbox-runtime`) for process isolation, networking, and workspace search. Install all required packages with one command: > Ubuntu/Debian ```bash -sudo apt install -y ffmpeg bubblewrap socat ripgrep +sudo apt install -y ffmpeg poppler-utils bubblewrap socat ripgrep ``` > Fedora ```bash -sudo dnf install -y ffmpeg bubblewrap socat ripgrep +sudo dnf install -y ffmpeg poppler-utils bubblewrap socat ripgrep ``` > Arch Linux ```bash -sudo pacman -S --noconfirm ffmpeg bubblewrap socat ripgrep +sudo pacman -S --noconfirm ffmpeg poppler bubblewrap socat ripgrep ``` > [!NOTE] @@ -162,12 +163,13 @@ sudo pacman -S --noconfirm ffmpeg bubblewrap socat ripgrep Shumai requires: - **`ffmpeg`** – Used for media transcoding and metadata extraction. +- **`poppler`** – Used for PDF page image extraction and PDF sprite preview generation (`pdftoppm`). - **`ripgrep`** – Required by the AI agent sandbox (`anthropic-experimental/sandbox-runtime`). Install the required packages with Homebrew: ```bash -brew install ffmpeg ripgrep +brew install ffmpeg poppler ripgrep ``` --- diff --git a/README_CN.md b/README_CN.md index 2200f7dc..7bc8f77e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -139,23 +139,24 @@ mkdir shumai && cd shumai 在 Linux 上运行 Shumai 需要安装以下系统依赖: - **`ffmpeg`** —— 用于媒体转码和元数据提取。 +- **`poppler`** (`poppler-utils`) —— 用于 PDF 页面图像提取和 PDF 雪碧图预览生成 (`pdftoppm`)。 - **`bubblewrap`**、**`socat`** 和 **`ripgrep`** —— AI Agent 沙箱(`anthropic-experimental/sandbox-runtime`)所需,用于进程隔离、网络通信和工作区搜索。 可以使用以下命令一次性安装所有依赖: > Ubuntu/Debian ```bash -sudo apt install -y ffmpeg bubblewrap socat ripgrep +sudo apt install -y ffmpeg poppler-utils bubblewrap socat ripgrep ``` > Fedora ```bash -sudo dnf install -y ffmpeg bubblewrap socat ripgrep +sudo dnf install -y ffmpeg poppler-utils bubblewrap socat ripgrep ``` > Arch Linux ```bash -sudo pacman -S --noconfirm ffmpeg bubblewrap socat ripgrep +sudo pacman -S --noconfirm ffmpeg poppler bubblewrap socat ripgrep ``` > [!NOTE] @@ -176,12 +177,13 @@ sudo pacman -S --noconfirm ffmpeg bubblewrap socat ripgrep 在 macOS 上运行 Shumai 需要: - **`ffmpeg`** —— 用于媒体转码和元数据提取。 +- **`poppler`** —— 用于 PDF 页面图像提取和 PDF 雪碧图预览生成 (`pdftoppm`)。 - **`ripgrep`** —— AI Agent 沙箱(`anthropic-experimental/sandbox-runtime`)所需。 使用 Homebrew 安装所需依赖: ```bash -brew install ffmpeg ripgrep +brew install ffmpeg poppler ripgrep ``` --- diff --git a/bun.lock b/bun.lock index 65d4b2ed..d8c560eb 100644 --- a/bun.lock +++ b/bun.lock @@ -7,6 +7,7 @@ "dependencies": { "@tanstack/react-virtual": "3.14.2", "jittered-fractional-indexing": "1.0.1", + "pdfjs-dist": "6.1.200", }, "devDependencies": { "@eslint/js": "10.0.1", @@ -37,7 +38,7 @@ }, "apps/agent": { "name": "@shumai/agent-app", - "version": "0.1.9", + "version": "0.1.10", "bin": { "shumai-agent": "./src/index.ts", }, @@ -49,7 +50,7 @@ }, "apps/cli": { "name": "@shumai/cli", - "version": "0.1.9", + "version": "0.1.10", "bin": { "shumai-cli": "./src/index.ts", }, @@ -64,7 +65,7 @@ }, "apps/transcode": { "name": "@shumai/transcode-app", - "version": "0.1.9", + "version": "0.1.10", "bin": { "shumai-transcode": "./src/index.ts", }, @@ -76,7 +77,7 @@ }, "apps/web": { "name": "@shumai/web-app", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@shumai/agent": "workspace:*", "@shumai/api": "workspace:*", @@ -96,7 +97,7 @@ }, "packages/agent": { "name": "@shumai/agent", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@anthropic-ai/sandbox-runtime": "0.0.52", "@earendil-works/pi-agent-core": "0.78.0", @@ -120,7 +121,7 @@ }, "packages/api": { "name": "@shumai/api", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@hono/zod-validator": "0.7.6", "@shumai/core": "workspace:*", @@ -134,7 +135,7 @@ }, "packages/core": { "name": "@shumai/core", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@earendil-works/pi-agent-core": "0.78.0", "@shumai/db": "workspace:*", @@ -162,7 +163,7 @@ }, "packages/db": { "name": "@shumai/db", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@earendil-works/pi-agent-core": "0.78.0", "@prisma/adapter-pg": "7.8.0", @@ -178,7 +179,7 @@ }, "packages/dtos": { "name": "@shumai/dtos", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@earendil-works/pi-agent-core": "0.78.0", "zod": "4.4.3", @@ -186,7 +187,7 @@ }, "packages/e2e": { "name": "@shumai/e2e", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@earendil-works/pi-agent-core": "0.78.0", "@google/genai": "1.52.0", @@ -200,11 +201,11 @@ }, "packages/tableprinter": { "name": "@shumai/tableprinter", - "version": "0.1.9", + "version": "0.1.10", }, "packages/transcode": { "name": "@shumai/transcode", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@shumai/core": "workspace:*", "@shumai/db": "workspace:*", @@ -218,7 +219,7 @@ }, "packages/webui": { "name": "@shumai/webui", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@base-ui/react": "1.5.0", "@dnd-kit/abstract": "0.4.0", @@ -315,7 +316,7 @@ }, "packages/workflow-core": { "name": "@shumai/workflow-core", - "version": "0.1.9", + "version": "0.1.10", "dependencies": { "@shumai/core": "workspace:*", "@shumai/db": "workspace:*", @@ -732,6 +733,30 @@ "@mistralai/mistralai": ["@mistralai/mistralai@2.2.1", "", { "dependencies": { "ws": "^8.18.0", "zod": "^3.25.0 || ^4.0.0", "zod-to-json-schema": "^3.25.0" } }, "sha512-uKU8CZmL2RzYKmplsU01hii4p3pe4HqJefpWNRWXm1Tcm0Sm4xXfwSLIy4k7ZCPlbETCGcp69E7hZs+WOJ5itQ=="], + "@napi-rs/canvas": ["@napi-rs/canvas@1.0.2", "", { "optionalDependencies": { "@napi-rs/canvas-android-arm64": "1.0.2", "@napi-rs/canvas-darwin-arm64": "1.0.2", "@napi-rs/canvas-darwin-x64": "1.0.2", "@napi-rs/canvas-linux-arm-gnueabihf": "1.0.2", "@napi-rs/canvas-linux-arm64-gnu": "1.0.2", "@napi-rs/canvas-linux-arm64-musl": "1.0.2", "@napi-rs/canvas-linux-riscv64-gnu": "1.0.2", "@napi-rs/canvas-linux-x64-gnu": "1.0.2", "@napi-rs/canvas-linux-x64-musl": "1.0.2", "@napi-rs/canvas-win32-arm64-msvc": "1.0.2", "@napi-rs/canvas-win32-x64-msvc": "1.0.2" } }, "sha512-EYEqlMYaCbpZDz+IgDH5xp9MTd3ui4dmGqbQYryhMLnSRxrhHKq5KQWHHKxFUcEP4Hp8/BWgvqXocX4j7iSbOQ=="], + + "@napi-rs/canvas-android-arm64": ["@napi-rs/canvas-android-arm64@1.0.2", "", { "os": "android", "cpu": "arm64" }, "sha512-IMXKVQod0ol4vt3gmClUfXz4JAgHYESGPCUqmH3lQxBoL0K/2greJaQE1HVBVxWWFKfLc4OLZVdxg7kXVyXv+g=="], + + "@napi-rs/canvas-darwin-arm64": ["@napi-rs/canvas-darwin-arm64@1.0.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Sc8tPi6cF+5lqOzCCKFALJHhDiRwyMzTPYm3bbhdXsOunU0lQO5f05ucyOzN2r55I23Hg5bsjH63uSCvWp3EgQ=="], + + "@napi-rs/canvas-darwin-x64": ["@napi-rs/canvas-darwin-x64@1.0.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-niDXZ9LhKB1zLrUdYB64RHQFDGz9rr0eGx061qtJJU3U20EMMIx28ADF5fVYbhtOgkWQrBjFicfaye1yM0U62A=="], + + "@napi-rs/canvas-linux-arm-gnueabihf": ["@napi-rs/canvas-linux-arm-gnueabihf@1.0.2", "", { "os": "linux", "cpu": "arm" }, "sha512-sgatQL9JxGRH/Amzcvu0P3t8Am3duou74CisfuJ41Dwt8cWy723z/9KZ8LlgmxfypEwEZxSTNFJtU8d281lmhQ=="], + + "@napi-rs/canvas-linux-arm64-gnu": ["@napi-rs/canvas-linux-arm64-gnu@1.0.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-dgKuX0peF3xwY6ZF5QxGS4wbfDqpoFAJYXiLSp+guZKARQUKMkRqZSDrXKj7nfrec3UCMzC0PFCPte0ES98AiA=="], + + "@napi-rs/canvas-linux-arm64-musl": ["@napi-rs/canvas-linux-arm64-musl@1.0.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-qwROoDIC9upfvDoRLuPn2aNg9CGW1x0Ygr4k2Or+8paA9d0qBLwk87U+g8KQpoOviKoPoiwl97kvBYuYD7qZoA=="], + + "@napi-rs/canvas-linux-riscv64-gnu": ["@napi-rs/canvas-linux-riscv64-gnu@1.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-fXRjnPihdnbO6qy1QQOgxAonb68A0TCEG7rj1x7v7rxNElsE8EVIKIEUTvyDtU+sthYSbX+8e7g3oZiLGnOmxw=="], + + "@napi-rs/canvas-linux-x64-gnu": ["@napi-rs/canvas-linux-x64-gnu@1.0.2", "", { "os": "linux", "cpu": "x64" }, "sha512-nPR97DXhbWIAy7yazF3jc06kEPMqYMLmPzFOVNlwKPfIoSChnI+x7dc0hTLaihz3jxrjL6j4BbA7earxfx4X3g=="], + + "@napi-rs/canvas-linux-x64-musl": ["@napi-rs/canvas-linux-x64-musl@1.0.2", "", { "os": "linux", "cpu": "x64" }, "sha512-l7zZY5+jL5qnBZtDz7CoBtY6p7EkHu422g/0zWwrOrzIwWyWxZFRfZZORY1UG7YApymPLx+UbOkN206xXn/c1Q=="], + + "@napi-rs/canvas-win32-arm64-msvc": ["@napi-rs/canvas-win32-arm64-msvc@1.0.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-yE0koHCFF4PIbMc2o2SEALhnipz7WBISh5glLvQiomtIoCcW0np3H4Lw93ceJAfJttTTeIIWFbwH84F7EVzjMQ=="], + + "@napi-rs/canvas-win32-x64-msvc": ["@napi-rs/canvas-win32-x64-msvc@1.0.2", "", { "os": "win32", "cpu": "x64" }, "sha512-okU8/t2foV6C31n0GtvEMbfD5rOFc70+/6xUNME9Guld29sgSOIGUEDScAWFlcP3k5TYQRl9TNkwJEEjh15w8A=="], + "@noble/ciphers": ["@noble/ciphers@2.2.0", "", {}, "sha512-Z6pjIZ/8IJcCGzb2S/0Px5J81yij85xASuk1teLNeg75bfT07MV3a/O2Mtn1I2se43k3lkVEcFaR10N4cgQcZA=="], "@noble/hashes": ["@noble/hashes@2.2.0", "", {}, "sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg=="], @@ -2242,6 +2267,8 @@ "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], + "pdfjs-dist": ["pdfjs-dist@6.1.200", "", { "optionalDependencies": { "@napi-rs/canvas": "^1.0.0" } }, "sha512-o8MolyzirkkLrcdsae/HEOiIcXWI7DS5zGpvqW8xTC2YUsW30rltFw2bDGvw/fskUdEMrQm2br68jzDS5BH2vw=="], + "pend": ["pend@1.2.0", "", {}, "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg=="], "perfect-debounce": ["perfect-debounce@2.1.0", "", {}, "sha512-LjgdTytVFXeUgtHZr9WYViYSM/g8MkcTPYDlPa3cDqMirHjKiSZPYd6DoL7pK8AJQr+uWkQvCjHNdiMqsrJs+g=="], diff --git a/docs/using-shumai/agent-tools.mdx b/docs/using-shumai/agent-tools.mdx index e5d58e57..b50baf4a 100644 --- a/docs/using-shumai/agent-tools.mdx +++ b/docs/using-shumai/agent-tools.mdx @@ -3,12 +3,15 @@ title: Agent Tools description: Configure the tools and capabilities permitted for each agent. --- -Shumai agents are equipped with built-in tools that allow them to interact with the file system, view files, extract video frames, and execute commands. +Shumai agents are equipped with built-in tools that allow them to interact with the file system, view files, extract video frames, and execute commands. By default, **all tools are enabled** for new agents. Team Owners can deny specific tools to restrict agent capabilities. -**Caution:** Disabling tools can cause agents or skills to fail. For example, disabling the **Sandboxed Terminal** tool will break almost all custom skills that rely on executing commands or script environments. Disable tools only when you have a specific security policy or isolation requirement. + **Caution:** Disabling tools can cause agents or skills to fail. For example, disabling the + **Sandboxed Terminal** tool will break almost all custom skills that rely on executing commands or + script environments. Disable tools only when you have a specific security policy or isolation + requirement. --- @@ -18,34 +21,42 @@ By default, **all tools are enabled** for new agents. Team Owners can deny speci The following tools can be individually toggled in the agent configuration dialog: ### 1. Sandboxed Terminal (`bash`) + - **Description:** Allows the agent to run terminal/shell commands in a highly isolated environment. - **Why it matters:** Essential for running custom scripts, processing files on disk, or using standard Unix utilities. If disabled, the agent won't be able to run command-line code. ### 2. Read Skills (`read_skill`) + - **Description:** Allows the agent to load and read skill definitions to perform specialized actions. - **Why it matters:** Enables the agent to inspect the instructions/configurations of custom skills registered in your workspace before executing them. ### 3. Analyze Image (`analyze_image`) + - **Description:** Allows the agent to view and analyze the visual contents of an image file. - **Why it matters:** Enables multimodal agents to "see" image assets uploaded to Shumai, allowing them to answer comments or write metadata about images. ### 4. Video Frame Extraction (`screenshot`) + - **Description:** Allows the agent to extract still image frames from video files for analysis. - **Why it matters:** Enables the agent to perform frame-by-frame analysis on videos (e.g. for comments, annotation, or search). ### 5. Browse Shumai (`list_assets`) + - **Description:** Allows the agent to list folders and browse files in Shumai. - **Why it matters:** Gives the agent visual mapping of the project structure so it can search for other files or locate related assets. ### 6. Create Folder (`create_folder`) + - **Description:** Allows the agent to create new folders in Shumai. - **Why it matters:** Needed if the agent organizes outputs or places files in custom subdirectory folders. ### 7. Create File (`create_file`) + - **Description:** Allows the agent to create and upload new files to Shumai. - **Why it matters:** Allows the agent to generate new assets (e.g. text logs, transcoded clips, reports) and save them directly back into your project. ### 8. Create Version (`create_version`) + - **Description:** Allows the agent to upload and stack a new version of an existing file in Shumai. - **Why it matters:** Allows the agent to update files in a clean, non-destructive way by stacking revisions rather than creating duplicate files. @@ -54,6 +65,7 @@ The following tools can be individually toggled in the agent configuration dialo ## Restricting Tools To change which tools an agent can use: + 1. Navigate to **Team Settings** > **Agents** (Note: Only Team Owners can view and modify these settings). 2. Click on the agent you want to edit. 3. Scroll down below the **Skills** section to find the **Tools** configuration panel. diff --git a/package.json b/package.json index ece6f4a6..1c1b4bde 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ }, "dependencies": { "@tanstack/react-virtual": "3.14.2", - "jittered-fractional-indexing": "1.0.1" + "jittered-fractional-indexing": "1.0.1", + "pdfjs-dist": "6.1.200" } } diff --git a/packages/core/src/asset/asset.ts b/packages/core/src/asset/asset.ts index ca7ccc6d..40e5bd37 100644 --- a/packages/core/src/asset/asset.ts +++ b/packages/core/src/asset/asset.ts @@ -2021,6 +2021,7 @@ export class AssetService { originalWidth: asset.media.metadata?.originalWidth, spriteUrl, duration: asset.media.metadata?.duration, + pageCount: asset.media.metadata?.totalFrames, } } diff --git a/packages/core/src/transcode/transcode.ts b/packages/core/src/transcode/transcode.ts index baba2a68..0d8823eb 100644 --- a/packages/core/src/transcode/transcode.ts +++ b/packages/core/src/transcode/transcode.ts @@ -287,6 +287,139 @@ export class TranscodeService { await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args]) } + async generatePdfSprite( + inputFile: string, + outputSprite: string, + outputPoster: string, + ): Promise<{ pageCount: number; originalWidth: number; originalHeight: number }> { + const tmpDir = this.createTempDir('pdf-sprite-') + try { + const pagePrefix = path.join(tmpDir, 'page') + try { + await execFileAsync('pdftoppm', ['-png', '-f', '1', '-l', '100', inputFile, pagePrefix]) + } catch (err) { + const msg = err instanceof Error ? err.message : String(err) + if (msg.includes('pdftoppm') || msg.includes('ENOENT') || msg.includes('not found')) { + throw new Error( + `pdftoppm executable not found in $PATH. Please install poppler-utils / poppler. (${msg})`, + { cause: err }, + ) + } + throw err + } + + const files = fs.readdirSync(tmpDir).filter((f) => f.endsWith('.png')) + if (files.length === 0) { + throw new Error('pdftoppm produced no image outputs') + } + + files.sort((a, b) => { + const numA = parseInt(a.replace(/[^0-9]/g, ''), 10) + const numB = parseInt(b.replace(/[^0-9]/g, ''), 10) + return numA - numB + }) + + const extractedCount = files.length + const firstPagePath = path.join(tmpDir, files[0]) + const firstMeta = await sharp(firstPagePath, { limitInputPixels: false }).metadata() + const originalWidth = firstMeta.width || 800 + const originalHeight = firstMeta.height || 1000 + + for (let f = 1; f <= 100; f++) { + const pageIdx = Math.min(extractedCount - 1, Math.floor(((f - 1) * extractedCount) / 100)) + const srcPath = path.join(tmpDir, files[pageIdx]) + const destPath = path.join(tmpDir, `frame_${f}.png`) + if (srcPath !== destPath) { + fs.copyFileSync(srcPath, destPath) + } + } + + const spriteArgs = [ + '-i', + path.join(tmpDir, 'frame_%d.png'), + '-filter_complex', + 'scale=w=480:h=-2,tile=10x10', + '-frames:v', + '1', + '-c:v', + 'libwebp', + '-q:v', + '75', + outputSprite, + ] + await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...spriteArgs]) + + await sharp(firstPagePath, { limitInputPixels: false }) + .resize(480, null, { withoutEnlargement: true, fit: 'inside' }) + .webp({ quality: 75 }) + .toFile(outputPoster) + + let totalPages = extractedCount + try { + const { stdout } = await execFileAsync('pdfinfo', [inputFile]) + const match = stdout.match(/Pages:\s+(\d+)/) + if (match) { + totalPages = parseInt(match[1], 10) + } + } catch { + // Fallback to extracted count if pdfinfo is unavailable + } + + return { + pageCount: totalPages, + originalWidth, + originalHeight, + } + } finally { + this.removeDir(tmpDir) + } + } + + async getPdfInfo(inputFile: string): Promise { + const tmpDir = this.createTempDir('pdf-info-') + let originalWidth = 800 + let originalHeight = 1000 + let pageCount = 1 + + try { + const pagePrefix = path.join(tmpDir, 'page') + await execFileAsync('pdftoppm', ['-png', '-f', '1', '-l', '1', inputFile, pagePrefix]) + const files = fs.readdirSync(tmpDir).filter((f) => f.endsWith('.png')) + if (files.length > 0) { + const meta = await sharp(path.join(tmpDir, files[0]), { + limitInputPixels: false, + }).metadata() + originalWidth = meta.width || 800 + originalHeight = meta.height || 1000 + } + } catch (err) { + console.warn('pdftoppm not available for PDF dimensions extraction:', err) + } + + try { + const { stdout } = await execFileAsync('pdfinfo', [inputFile]) + const match = stdout.match(/Pages:\s+(\d+)/) + if (match) { + pageCount = parseInt(match[1], 10) + } + } catch { + // Fallback + } finally { + this.removeDir(tmpDir) + } + + return { + originalWidth, + originalHeight, + duration: 0, + bitRate: 0, + frameRate: 0, + totalFrames: pageCount, + hasAudio: false, + mimeType: 'application/pdf', + } + } + async extractAudio(inputFile: string, outputFile: string, bitrate: string): Promise { const args = ['-i', inputFile, '-vn', '-acodec', 'libmp3lame', '-b:a', bitrate, outputFile] await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args]) diff --git a/packages/core/src/upload/upload.ts b/packages/core/src/upload/upload.ts index 68f83e09..000eaa00 100644 --- a/packages/core/src/upload/upload.ts +++ b/packages/core/src/upload/upload.ts @@ -18,7 +18,7 @@ import { PresignedUrl, TaskInfo, } from '@shumai/dtos' -import { ImageTranscoder, VideoTranscoder } from '@shumai/transcode' +import { ImageTranscoder, PdfTranscoder, VideoTranscoder } from '@shumai/transcode' import { generateKeyBetween } from 'jittered-fractional-indexing' import { ulid } from 'ulid' import { sanitizeFilename } from '@shumai/core/src/utils/filename' @@ -303,6 +303,7 @@ export class UploadService { const isVideo = asset.mediaType?.startsWith('video/') const isImage = asset.mediaType?.startsWith('image/') const isAudio = asset.mediaType?.startsWith('audio/') + const isPdf = asset.mediaType === 'application/pdf' || asset.name.toLowerCase().endsWith('.pdf') if (autofillAgent && (isVideo || isImage)) { await tx.workflowTask.create({ @@ -320,7 +321,7 @@ export class UploadService { }) } - if (!isVideo && !isImage && !isAudio) { + if (!isVideo && !isImage && !isAudio && !isPdf) { await tx.asset.update({ where: { id: asset.id }, data: { status: AssetStatus.processed }, @@ -341,6 +342,12 @@ export class UploadService { } else if (isImage) { // eslint-disable-next-line @typescript-eslint/no-explicit-any await new ImageTranscoder(tx as any, asset.id, team.id, projectId).withThumbnail().submit() + } else if (isPdf) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + await new PdfTranscoder(tx as any, asset.id, team.id, projectId) + .withSprite() + .withPoster() + .submit() } } } diff --git a/packages/dtos/src/asset.ts b/packages/dtos/src/asset.ts index 6513674b..f368cbfd 100644 --- a/packages/dtos/src/asset.ts +++ b/packages/dtos/src/asset.ts @@ -14,6 +14,7 @@ export const previewInfoSchema = z.object({ originalWidth: z.number().optional(), spriteUrl: z.string().optional(), duration: z.number().optional(), + pageCount: z.number().optional(), }) export type PreviewInfo = z.infer diff --git a/packages/transcode/src/activities/transcode.test.ts b/packages/transcode/src/activities/transcode.test.ts index 5bfb7305..a95a9368 100644 --- a/packages/transcode/src/activities/transcode.test.ts +++ b/packages/transcode/src/activities/transcode.test.ts @@ -3,7 +3,7 @@ import { s3Service } from '@shumai/core/src/s3/s3' import { prisma } from '@shumai/db' import { setupTestDbHooks } from '@shumai/db/test' import { beforeEach, describe, expect, it, vi } from 'vitest' -import { transcodeService } from '@shumai/core' +import { transcodeService } from '@shumai/core/src/transcode/transcode' import * as child_process from 'child_process' vi.mock('child_process', () => ({ @@ -39,10 +39,25 @@ vi.mock('@shumai/core/src/transcode/transcode', () => ({ getVideoInfo: vi.fn(), getAudioInfo: vi.fn(), getImageInfo: vi.fn(), + getPdfInfo: vi.fn().mockResolvedValue({ + originalWidth: 800, + originalHeight: 1000, + duration: 0, + bitRate: 0, + frameRate: 0, + totalFrames: 10, + hasAudio: false, + mimeType: 'application/pdf', + }), transcodeVideo: vi.fn(), transcodeAudio: vi.fn(), transcodeImage: vi.fn(), generateSprite: vi.fn(), + generatePdfSprite: vi.fn().mockResolvedValue({ + pageCount: 10, + originalWidth: 800, + originalHeight: 1000, + }), createTempDir: vi.fn().mockReturnValue('/tmp'), removeDir: vi.fn(), takeScreenshots: vi.fn(), diff --git a/packages/transcode/src/activities/transcode.ts b/packages/transcode/src/activities/transcode.ts index d601fb71..c3c1aa6d 100644 --- a/packages/transcode/src/activities/transcode.ts +++ b/packages/transcode/src/activities/transcode.ts @@ -1,6 +1,6 @@ import { prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db' import { s3Service } from '@shumai/core/src/s3/s3' -import { transcodeService } from '@shumai/core' +import { transcodeService } from '@shumai/core/src/transcode/transcode' import { metadataService } from '@shumai/core/src/metadata/metadata' import { stemFromKey } from '@shumai/core/src/utils/filename' import { ApplicationFailure } from '@temporalio/activity' @@ -163,6 +163,25 @@ export async function getMediaInfoActivity(params: { { key: 'resolution_width', value: info.originalWidth }, { key: 'resolution_height', value: info.originalHeight }, ) + } else if (params.mediaType === 'application/pdf') { + const info = await transcodeService.getPdfInfo(params.filePath) + mediaInfo.frames = info.totalFrames + mediaInfo.metadata = { + originalWidth: info.originalWidth, + originalHeight: info.originalHeight, + duration: 0, + bitRate: 0, + frameRate: 0, + totalFrames: info.totalFrames, + startTimecode: '00:00:00:00', + hasAudio: false, + format: {}, + } + metadataUpdates.push( + { key: 'resolution_width', value: info.originalWidth }, + { key: 'resolution_height', value: info.originalHeight }, + { key: 'total_pages', value: info.totalFrames }, + ) } await metadataService.updateAssetMetadata(params.assetId, metadataUpdates, true) @@ -401,12 +420,26 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam const posterFile = path.join(tmpDir, 'poster.webp') try { - await transcodeService.generateSprite( - params.filePath, - spriteFile, - posterFile, - params.mediaInfo.duration, - ) + if (params.mediaInfo.mimeType === 'application/pdf') { + const pdfRes = await transcodeService.generatePdfSprite( + params.filePath, + spriteFile, + posterFile, + ) + if (params.mediaInfo && params.mediaInfo.metadata) { + params.mediaInfo.metadata.totalFrames = pdfRes.pageCount + params.mediaInfo.metadata.originalWidth = pdfRes.originalWidth + params.mediaInfo.metadata.originalHeight = pdfRes.originalHeight + params.mediaInfo.frames = pdfRes.pageCount + } + } else { + await transcodeService.generateSprite( + params.filePath, + spriteFile, + posterFile, + params.mediaInfo.duration, + ) + } const spriteBuffer = fs.readFileSync(spriteFile) await s3Service.putObject( diff --git a/packages/transcode/src/transcoder.ts b/packages/transcode/src/transcoder.ts index 525d0602..29edb84a 100644 --- a/packages/transcode/src/transcoder.ts +++ b/packages/transcode/src/transcoder.ts @@ -82,3 +82,41 @@ export class ImageTranscoder { return task.id } } + +export class PdfTranscoder { + private spec: PrismaJson.TaskSpec = {} + + constructor( + private readonly db: TransactionClient, + private readonly assetId: string, + private readonly teamId: string, + private readonly projectId: string, + ) {} + + withSprite(): this { + this.spec.sprite = true + return this + } + + withPoster(): this { + this.spec.poster = true + return this + } + + async submit(): Promise { + const task = await this.db.workflowTask.create({ + data: { + assetId: this.assetId, + teamId: this.teamId, + projectId: this.projectId, + type: WorkflowTaskType.transcode, + status: WorkflowTaskStatus.pending, + payload: { + projectId: this.projectId, + transcode: this.spec, + }, + }, + }) + return task.id + } +} diff --git a/packages/transcode/src/workflows/transcode.test.ts b/packages/transcode/src/workflows/transcode.test.ts index 4287349a..2e031c94 100644 --- a/packages/transcode/src/workflows/transcode.test.ts +++ b/packages/transcode/src/workflows/transcode.test.ts @@ -245,6 +245,89 @@ describe('Transcode Workflow', () => { }) }) + it('should process pdf transcode and sprite generation successfully', async () => { + const task: WorkflowTask = { + id: 'task-pdf', + assetId: 'asset-pdf', + type: WorkflowTaskType.transcode, + status: WorkflowTaskStatus.pending, + sessionId: null, + output: null, + payload: { + projectId: 'proj-1', + transcode: { + sprite: true, + poster: true, + }, + }, + createdAt: new Date(), + updatedAt: new Date(), + heartbeat: null, + teamId: 'team-1', + projectId: 'proj-1', + uid: 'task-uid-pdf', + model: null, + inputTokens: 0, + outputTokens: 0, + } + + mockActivities.getAssetActivity.mockResolvedValue({ + id: 'asset-pdf', + storageKey: { key: 'document.pdf' }, + mediaType: 'application/pdf', + }) + + mockActivities.getMediaInfoActivity.mockResolvedValue({ + mimeType: 'application/pdf', + metadata: { + originalWidth: 800, + originalHeight: 1000, + duration: 0, + frameRate: 0, + totalFrames: 12, + startTimecode: '00:00:00:00', + bitRate: 0, + hasAudio: false, + format: {}, + }, + videoTranscodes: [], + imageTranscodes: [], + }) + + mockActivities.generateSpriteActivity.mockResolvedValue({ + sprite: { key: 'sprite.webp', frames: 100, tileX: 10, tileY: 10 }, + poster: { key: 'poster.webp' }, + }) + + await transcodeMedia(task) + + expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({ + assetId: 'asset-pdf', + status: AssetStatus.processing, + }) + + expect(mockActivities.generateSpriteActivity).toHaveBeenCalledWith({ + assetKey: 'document.pdf', + filePath: '/tmp/video.mp4', + spriteSpec: expect.objectContaining({ key: 'sprite.webp' }), + posterSpec: expect.objectContaining({ key: 'poster.webp' }), + mediaInfo: expect.objectContaining({ mimeType: 'application/pdf' }), + }) + + expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({ + assetId: 'asset-pdf', + mediaInfo: expect.objectContaining({ + sprite: { key: 'sprite.webp', frames: 100, tileX: 10, tileY: 10 }, + poster: { key: 'poster.webp' }, + }), + }) + + expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({ + assetId: 'asset-pdf', + status: AssetStatus.processed, + }) + }) + it('should handle failures and update task status with error', async () => { const task: WorkflowTask = { id: 'task-fail', diff --git a/packages/webui/components/file-browser/file-preview.tsx b/packages/webui/components/file-browser/file-preview.tsx index 362bc20a..0344944e 100644 --- a/packages/webui/components/file-browser/file-preview.tsx +++ b/packages/webui/components/file-browser/file-preview.tsx @@ -11,6 +11,7 @@ type FilePreviewItem = { originalWidth?: number originalHeight?: number duration?: number + pageCount?: number } | null } @@ -22,23 +23,30 @@ interface FilePreviewProps { export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) => { const isVideo = item.preview?.mediaType?.startsWith('video/') const isAudio = item.preview?.mediaType?.startsWith('audio/') + const isPdf = item.preview?.mediaType === 'application/pdf' const hasDuration = isVideo || isAudio const duration = item.preview?.duration - const durationOverlay = + const pageCount = item.preview?.pageCount + + const overlay = showDuration && hasDuration && typeof duration === 'number' && duration > 0 ? ( - + {formatTime(duration)} + ) : showDuration && isPdf && typeof pageCount === 'number' && pageCount > 0 ? ( + + {pageCount} P + ) : null - const isVideoWithSprite = - isVideo && + const isMediaWithSprite = + (isVideo || isPdf) && item.preview?.spriteUrl && item.preview.thumbnailUrl && item.preview.originalWidth && item.preview.originalHeight - if (isVideoWithSprite && item.preview) { + if (isMediaWithSprite && item.preview) { return ( <> videoWidth={item.preview.originalWidth!} videoHeight={item.preview.originalHeight!} /> - {durationOverlay} + {overlay} ) } @@ -60,7 +68,7 @@ export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) => alt="Preview" className="w-full h-full object-contain bg-black" /> - {durationOverlay} + {overlay} ) } @@ -71,7 +79,7 @@ export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) =>
- {durationOverlay} + {overlay} ) } diff --git a/packages/webui/components/viewers/pdf/index.tsx b/packages/webui/components/viewers/pdf/index.tsx new file mode 100644 index 00000000..c1dc8f35 --- /dev/null +++ b/packages/webui/components/viewers/pdf/index.tsx @@ -0,0 +1,14 @@ +import { FileTypeDefinition } from '../types' +import PdfViewer from './pdf-viewer' + +export const pdfTypeDefinition: FileTypeDefinition = { + id: 'pdf', + name: 'PDF', + match: (file) => file.mediaType === 'application/pdf' || file.name.toLowerCase().endsWith('.pdf'), + viewer: PdfViewer, + commentsConfig: { + hasTimestamp: false, + hasAnnotations: true, + hasAiBots: true, + }, +} diff --git a/packages/webui/components/viewers/pdf/pdf-control-bar.tsx b/packages/webui/components/viewers/pdf/pdf-control-bar.tsx new file mode 100644 index 00000000..356c291a --- /dev/null +++ b/packages/webui/components/viewers/pdf/pdf-control-bar.tsx @@ -0,0 +1,91 @@ +import { ChevronLeft, ChevronRight, Download, Minus, Plus } from 'lucide-react' +import { m } from '@/ui/paraglide/messages.js' + +export interface PdfControlBarProps { + currentPage: number + totalPages: number + onPageChange: (newPage: number) => void + zoom: number + onZoomIn: () => void + onZoomOut: () => void + onFit: () => void + onDownload: () => void + canDownload: boolean +} + +export function PdfControlBar({ + currentPage, + totalPages, + onPageChange, + zoom, + onZoomIn, + onZoomOut, + onFit, + onDownload, + canDownload, +}: PdfControlBarProps) { + return ( +
+ {/* Page Navigation */} +
+ + + {m.page_of_pages({ current: currentPage, total: totalPages || 1 })} + + +
+ + {/* Zoom & Action Controls */} +
+
+ + + {Math.round(zoom * 100)}% + + +
+ + +
+
+ ) +} diff --git a/packages/webui/components/viewers/pdf/pdf-viewer.tsx b/packages/webui/components/viewers/pdf/pdf-viewer.tsx new file mode 100644 index 00000000..cfcd9eb7 --- /dev/null +++ b/packages/webui/components/viewers/pdf/pdf-viewer.tsx @@ -0,0 +1,257 @@ +import { client } from '@/ui/api/client' +import DrawingCanvas from '@/ui/components/drawing-canvas' +import { useAnnotationStore } from '@/ui/stores/annotation-store' +import * as pdfjsLib from 'pdfjs-dist' +import React, { useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react' +import { FileViewerProps, MediaController } from '../types' +import { PdfControlBar } from './pdf-control-bar' + +if (typeof window !== 'undefined' && pdfjsLib.GlobalWorkerOptions) { + pdfjsLib.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjsLib.version}/build/pdf.worker.min.mjs` +} + +export const PdfViewer = React.forwardRef( + ({ file, annotations, shareId, children }, ref) => { + useImperativeHandle(ref, () => ({ + play: () => {}, + pause: () => {}, + seekTo: () => {}, + })) + + const { + isDrawing, + currentTool, + currentColor, + addAnnotation, + annotations: draftAnnotations, + } = useAnnotationStore() + + const [pdfDoc, setPdfDoc] = useState(null) + const [currentPage, setCurrentPage] = useState(1) + const [totalPages, setTotalPages] = useState(1) + const [pageImageUrl, setPageImageUrl] = useState('') + const [pageDimensions, setPageDimensions] = useState({ width: 800, height: 1000 }) + const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) + + const [containerSize, setContainerSize] = useState({ width: 0, height: 0 }) + const [zoom, setZoom] = useState(1) + const [pan, setPan] = useState({ x: 0, y: 0 }) + + const observerRef = useRef(null) + + const containerRef = useCallback((node: HTMLDivElement | null) => { + if (observerRef.current) { + observerRef.current.disconnect() + observerRef.current = null + } + + if (node !== null) { + const observer = new ResizeObserver((entries) => { + const entry = entries[0] + if (entry) { + setContainerSize({ + width: entry.contentRect.width, + height: entry.contentRect.height, + }) + } + }) + observer.observe(node) + observerRef.current = observer + } + }, []) + + const fileUrl = file.media?.original?.downloadUrl + + // Load PDF Document + useEffect(() => { + if (!fileUrl) { + setError('No PDF URL available') + setLoading(false) + return + } + + let active = true + setLoading(true) + setError(null) + + const loadingTask = pdfjsLib.getDocument({ url: fileUrl }) + loadingTask.promise + .then((doc) => { + if (!active) return + setPdfDoc(doc) + setTotalPages(doc.numPages) + setCurrentPage(1) + setLoading(false) + }) + .catch((err) => { + if (!active) return + console.error('Failed to load PDF:', err) + setError('Failed to load PDF document') + setLoading(false) + }) + + return () => { + active = false + } + }, [fileUrl]) + + // Render active PDF page into image + useEffect(() => { + if (!pdfDoc) return + + let active = true + pdfDoc + .getPage(currentPage) + .then((page) => { + if (!active) return + const unscaledViewport = page.getViewport({ scale: 1.0 }) + const renderScale = 2.0 + const viewport = page.getViewport({ scale: renderScale }) + + const canvas = document.createElement('canvas') + canvas.width = viewport.width + canvas.height = viewport.height + const ctx = canvas.getContext('2d') + + if (!ctx) return + + page + .render({ canvasContext: ctx, viewport, canvas }) + .promise.then(() => { + if (!active) return + setPageImageUrl(canvas.toDataURL('image/png')) + setPageDimensions({ + width: unscaledViewport.width, + height: unscaledViewport.height, + }) + }) + .catch((err) => { + console.error('Failed to render page:', err) + }) + }) + .catch((err) => { + console.error('Failed to get page:', err) + }) + + return () => { + active = false + } + }, [pdfDoc, currentPage]) + + const conW = containerSize.width + const conH = containerSize.height + const pdfW = pageDimensions.width + const pdfH = pageDimensions.height + + let baseScale = 1 + if (conW > 0 && conH > 0 && pdfW > 0 && pdfH > 0) { + baseScale = Math.min(conW / pdfW, conH / pdfH) + } + + useEffect(() => { + if (conW > 0 && conH > 0 && pdfW > 0 && pdfH > 0) { + setZoom(baseScale) + const x = (conW - pdfW * baseScale) / 2 + const y = (conH - pdfH * baseScale) / 2 + setPan({ x, y }) + } + }, [file.id, currentPage, conW, conH, baseScale, pdfW, pdfH]) + + const handleZoom = (factor: number) => { + const cx = conW / 2 + const cy = conH / 2 + + const newZoom = zoom * factor + if (newZoom < 0.01 || newZoom > 50) return + + const newPanX = cx - (cx - pan.x) * (newZoom / zoom) + const newPanY = cy - (cy - pan.y) * (newZoom / zoom) + + setZoom(newZoom) + setPan({ x: newPanX, y: newPanY }) + } + + const handleFit = () => { + setZoom(baseScale) + const x = (conW - pdfW * baseScale) / 2 + const y = (conH - pdfH * baseScale) / 2 + setPan({ x, y }) + } + + const handleDownload = async () => { + const key = file.media?.original?.key + if (!key || !file.id) return + try { + const res = shareId + ? await client.api.shares[':shareId'].files[':fileId']['download-url'].$post({ + param: { shareId, fileId: file.id }, + json: { key }, + }) + : await client.api.files['download-url'].$post({ + json: { key, assetId: file.id }, + }) + if (!res.ok) return + const { url } = await res.json() + const link = document.createElement('a') + link.href = url + link.download = file.name || 'document.pdf' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + } catch { + // fail silently + } + } + + const displayAnnotations = [...(annotations || []), ...draftAnnotations] + + return ( +
+
+ {children} +
+ {loading ? ( +
+
+
+ ) : error ? ( +
+ {error} +
+ ) : ( + + )} +
+
+ handleZoom(1.2)} + onZoomOut={() => handleZoom(0.8)} + onFit={handleFit} + onDownload={handleDownload} + canDownload={!!file.media?.original?.key} + /> +
+ ) + }, +) + +export default PdfViewer diff --git a/packages/webui/components/viewers/registry.ts b/packages/webui/components/viewers/registry.ts index 5302d2c7..3ca2f1f7 100644 --- a/packages/webui/components/viewers/registry.ts +++ b/packages/webui/components/viewers/registry.ts @@ -2,9 +2,10 @@ import type { AssetInfo } from '@shumai/dtos' import { FileTypeDefinition } from './types' import { videoTypeDefinition } from './video' import { imageTypeDefinition } from './image' +import { pdfTypeDefinition } from './pdf' import { defaultTypeDefinition } from './default' -const registry: FileTypeDefinition[] = [videoTypeDefinition, imageTypeDefinition] +const registry: FileTypeDefinition[] = [pdfTypeDefinition, videoTypeDefinition, imageTypeDefinition] export function getViewerForFile(file: AssetInfo | null | undefined): FileTypeDefinition { if (!file) return defaultTypeDefinition diff --git a/packages/webui/css.d.ts b/packages/webui/css.d.ts index 5238bedf..a3bdb298 100644 --- a/packages/webui/css.d.ts +++ b/packages/webui/css.d.ts @@ -2,3 +2,8 @@ declare module '*.css' { const content: { [className: string]: string } export default content } + +declare module '*?url' { + const content: string + export default content +} diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index d4301139..d863150e 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -475,6 +475,9 @@ "zoom_out": "Zoom Out", "zoom_in": "Zoom In", "fit": "Fit", + "previous_page": "Previous Page", + "next_page": "Next Page", + "page_of_pages": "Page {current} of {total}", "copy_image_to_clipboard": "Copy optimized image to clipboard", "download_original_image": "Download original image", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index a5477a22..c9385898 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -474,7 +474,10 @@ "download_original_file": "下载原始文件", "zoom_out": "缩小", "zoom_in": "放大", - "fit": "适应", + "fit": "适应窗口", + "previous_page": "上一页", + "next_page": "下一页", + "page_of_pages": "第 {current} / {total} 页", "copy_image_to_clipboard": "复制优化图片到剪贴板", "download_original_image": "下载原始图片", diff --git a/packages/webui/paraglide/messages/_index.d.ts b/packages/webui/paraglide/messages/_index.d.ts index 7e877239..d7805ac4 100644 --- a/packages/webui/paraglide/messages/_index.d.ts +++ b/packages/webui/paraglide/messages/_index.d.ts @@ -451,6 +451,9 @@ export * from "./download_original_file.js"; export * from "./zoom_out.js"; export * from "./zoom_in.js"; export * from "./fit.js"; +export * from "./previous_page.js"; +export * from "./next_page.js"; +export * from "./page_of_pages.js"; export * from "./copy_image_to_clipboard.js"; export * from "./download_original_image.js"; export * from "./no_item_selected.js"; diff --git a/packages/webui/paraglide/messages/_index.js b/packages/webui/paraglide/messages/_index.js index cec75af6..504d6ccc 100644 --- a/packages/webui/paraglide/messages/_index.js +++ b/packages/webui/paraglide/messages/_index.js @@ -453,6 +453,9 @@ export * from './download_original_file.js' export * from './zoom_out.js' export * from './zoom_in.js' export * from './fit.js' +export * from './previous_page.js' +export * from './next_page.js' +export * from './page_of_pages.js' export * from './copy_image_to_clipboard.js' export * from './download_original_image.js' export * from './no_item_selected.js' diff --git a/packages/webui/paraglide/messages/fit.js b/packages/webui/paraglide/messages/fit.js index 20826400..a0820240 100644 --- a/packages/webui/paraglide/messages/fit.js +++ b/packages/webui/paraglide/messages/fit.js @@ -10,7 +10,7 @@ const en_fit = /** @type {(inputs: FitInputs) => LocalizedString} */ () => { }; const zh_fit = /** @type {(inputs: FitInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`适应`) + return /** @type {LocalizedString} */ (`适应窗口`) }; /** diff --git a/packages/webui/paraglide/messages/next_page.d.ts b/packages/webui/paraglide/messages/next_page.d.ts new file mode 100644 index 00000000..84f0f5a6 --- /dev/null +++ b/packages/webui/paraglide/messages/next_page.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Next Page" | +* +* @param {Next_PageInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const next_page: ((inputs?: Next_PageInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Next_PageInputs = {}; diff --git a/packages/webui/paraglide/messages/next_page.js b/packages/webui/paraglide/messages/next_page.js new file mode 100644 index 00000000..345ba476 --- /dev/null +++ b/packages/webui/paraglide/messages/next_page.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Next_PageInputs */ + +const en_next_page = /** @type {(inputs: Next_PageInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Next Page`) +}; + +const zh_next_page = /** @type {(inputs: Next_PageInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`下一页`) +}; + +/** +* | output | +* | --- | +* | "Next Page" | +* +* @param {Next_PageInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const next_page = /** @type {((inputs?: Next_PageInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_next_page(inputs) + return zh_next_page(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/page_of_pages.d.ts b/packages/webui/paraglide/messages/page_of_pages.d.ts new file mode 100644 index 00000000..48f1df2e --- /dev/null +++ b/packages/webui/paraglide/messages/page_of_pages.d.ts @@ -0,0 +1,19 @@ +/** +* | output | +* | --- | +* | "Page {current} of {total}" | +* +* @param {Page_Of_PagesInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const page_of_pages: ((inputs: Page_Of_PagesInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Page_Of_PagesInputs = { + current: NonNullable; + total: NonNullable; +}; diff --git a/packages/webui/paraglide/messages/page_of_pages.js b/packages/webui/paraglide/messages/page_of_pages.js new file mode 100644 index 00000000..70da54a3 --- /dev/null +++ b/packages/webui/paraglide/messages/page_of_pages.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{ current: NonNullable, total: NonNullable }} Page_Of_PagesInputs */ + +const en_page_of_pages = /** @type {(inputs: Page_Of_PagesInputs) => LocalizedString} */ (i) => { + return /** @type {LocalizedString} */ (`Page ${i?.current} of ${i?.total}`) +}; + +const zh_page_of_pages = /** @type {(inputs: Page_Of_PagesInputs) => LocalizedString} */ (i) => { + return /** @type {LocalizedString} */ (`第 ${i?.current} / ${i?.total} 页`) +}; + +/** +* | output | +* | --- | +* | "Page {current} of {total}" | +* +* @param {Page_Of_PagesInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const page_of_pages = /** @type {((inputs: Page_Of_PagesInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_page_of_pages(inputs) + return zh_page_of_pages(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/previous_page.d.ts b/packages/webui/paraglide/messages/previous_page.d.ts new file mode 100644 index 00000000..1e614a57 --- /dev/null +++ b/packages/webui/paraglide/messages/previous_page.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Previous Page" | +* +* @param {Previous_PageInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const previous_page: ((inputs?: Previous_PageInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Previous_PageInputs = {}; diff --git a/packages/webui/paraglide/messages/previous_page.js b/packages/webui/paraglide/messages/previous_page.js new file mode 100644 index 00000000..6bc78a3d --- /dev/null +++ b/packages/webui/paraglide/messages/previous_page.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Previous_PageInputs */ + +const en_previous_page = /** @type {(inputs: Previous_PageInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Previous Page`) +}; + +const zh_previous_page = /** @type {(inputs: Previous_PageInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`上一页`) +}; + +/** +* | output | +* | --- | +* | "Previous Page" | +* +* @param {Previous_PageInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const previous_page = /** @type {((inputs?: Previous_PageInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_previous_page(inputs) + return zh_previous_page(inputs) +}); \ No newline at end of file