@file-viewer/renderer-media 2.3.0 → 3.0.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/README.en.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @file-viewer/renderer-media
2
2
 
3
- Standalone audio and video renderer package for Flyfish File Viewer. It previews audio files, videos, HLS playlists, and MIDI files in the browser while loading `hls.js` and `@tonejs/midi` only for the formats that need them.
3
+ Base audio and video renderer package for Flyfish File Viewer. It provides browser-native media playback by default. HLS fallback and MIDI inspection are enabled explicitly by `@file-viewer/capability-streaming-media` and `@file-viewer/capability-midi`; neither enters the standard/full default closure.
4
4
 
5
5
  ## Usage
6
6
 
@@ -30,10 +30,10 @@ const options = {
30
30
  - The renderer inspects MP4 video tracks before playback. If the browser rejects an MPEG-4 Part 2 (`mp4v`) Simple Profile track, it starts a dedicated Worker, uses the AAC track as the playback clock, and draws software-decoded I420 frames to a Canvas. This fixes the case where audio plays over a black frame.
31
31
  - The fallback uses the Apache-2.0 AOSP PacketVideo decoder. Its WASM file is 111,379 bytes, or 34,410 bytes with gzip, and loads only after native decoding fails. The implementation contains no FFmpeg, libav, or LGPL/GPL/AGPL source.
32
32
  - Files outside the decoder's current coverage, and browsers without Worker, OffscreenCanvas, or VideoFrame support, get a codec compatibility notice. H.264/AVC still uses less CPU and works in more browsers.
33
- - HLS `.m3u8` uses native playback when available and dynamically imports `hls.js` only as a fallback.
34
- - MIDI / MID dynamically imports `@tonejs/midi` only when opened, then renders name, duration, PPQ, tracks, and note summaries.
33
+ - With the streaming-media capability installed, HLS `.m3u8` uses native playback first and loads `hls.js` only as a fallback.
34
+ - With the MIDI capability installed, MIDI / MID loads `@tonejs/midi` and renders name, duration, PPQ, tracks, and note summaries.
35
35
  - Unmount cleanup revokes object URLs, resets media elements, and destroys the HLS instance for long-lived business applications.
36
36
 
37
37
  ## Migration Note
38
38
 
39
- `@file-viewer/core` no longer bundles media renderers and no longer depends directly on `hls.js` or `@tonejs/midi`. Install this package explicitly for audio, video, HLS, or MIDI preview, or use `@file-viewer/preset-all`, which aggregates this renderer automatically.
39
+ `@file-viewer/core` does not bundle media renderers. Standard installs only this package's native media path. Opening `.m3u8`, `.midi`, or `.mid` without its capability shows the exact `npx file-viewer-cli add ...` command. `preset-all` is reserved for explicit all/debug use and registers both optional capabilities.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @file-viewer/renderer-media
2
2
 
3
- Flyfish File Viewer 的独立音视频 renderer 包。它负责音频、视频、HLS 清单和 MIDI 文件的浏览器端预览,并让 `hls.js`、`@tonejs/midi` 只在命中对应格式时加载。
3
+ Flyfish File Viewer 的基础音视频 renderer 包,默认只提供浏览器原生音频和视频播放。HLS fallback 与 MIDI 检查分别由 `@file-viewer/capability-streaming-media`、`@file-viewer/capability-midi` 显式启用,不进入 standard/full 默认闭包。
4
4
 
5
5
  ## 使用
6
6
 
@@ -30,10 +30,10 @@ const options = {
30
30
  - MP4 会读取视频轨的编码标识。浏览器无法解码 MPEG-4 Part 2(`mp4v`)Simple Profile 时,renderer 会按需启动独立 Worker,使用 AAC 音轨校时,并把软件解码的 I420 画面绘制到 Canvas,不再出现“有声音、画面全黑”。
31
31
  - MP4V 后备解码器来自 AOSP PacketVideo,许可证为 Apache-2.0。WASM 为 111,379 字节(gzip 34,410 字节),仅在原生解码失败时加载。实现不包含 FFmpeg、libav 或 LGPL/GPL/AGPL 源码。
32
32
  - 浏览器缺少 Worker、OffscreenCanvas 或 VideoFrame,或者文件超出当前解码范围时,会显示明确的兼容提示。面向更多浏览器发布时,H.264/AVC 仍是更省 CPU 的选择。
33
- - HLS `.m3u8` 优先使用浏览器原生能力,不支持时才按需加载 `hls.js`。
34
- - MIDI / MID 只在命中格式时按需加载 `@tonejs/midi`,展示曲名、时长、PPQ、轨道和音符摘要。
33
+ - 安装 streaming-media capability 后,HLS `.m3u8` 优先使用浏览器原生能力,不支持时才加载 `hls.js`。
34
+ - 安装 MIDI capability 后,MIDI / MID 才加载 `@tonejs/midi` 并展示曲名、时长、PPQ、轨道和音符摘要。
35
35
  - 所有资源在卸载时清理对象 URL、播放器状态和 HLS 实例,适合长时间运行的后台系统。
36
36
 
37
37
  ## 迁移说明
38
38
 
39
- `@file-viewer/core` 已不再内置 media renderer,也不再直接依赖 `hls.js` 和 `@tonejs/midi`。需要音频、视频、HLS 或 MIDI 预览时,请显式安装本包,或使用会自动聚合本包的 `@file-viewer/preset-all`。
39
+ `@file-viewer/core` 不内置 media renderer。standard 只装配本包的原生媒体路径;打开 `.m3u8`、`.midi` 或 `.mid` 时会给出对应的 `npx file-viewer-cli add ...` 命令。`preset-all` 仅用于显式全量/调试并注册两项可选能力。
package/dist/audio.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createFileViewerTranslator } from '@file-viewer/core';
2
+ import { getFileViewerMidiLoader } from './optionalCapabilities.js';
2
3
  const AUDIO_MIME_MAP = {
3
4
  aac: 'audio/aac',
4
5
  flac: 'audio/flac',
@@ -190,7 +191,11 @@ const renderMidiElement = (buffer, target, context) => {
190
191
  };
191
192
  void (async () => {
192
193
  try {
193
- const { Midi } = await import('@tonejs/midi');
194
+ const loadMidi = getFileViewerMidiLoader();
195
+ if (!loadMidi) {
196
+ throw new Error('MIDI support is opt-in. Run `npx file-viewer-cli add midi --write`, then `npx file-viewer-cli install --yes`.');
197
+ }
198
+ const { Midi } = await loadMidi();
194
199
  const midi = new Midi(buffer);
195
200
  if (disposed) {
196
201
  return;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { type FileRenderHandler, type FileViewerRenderedInstance, type FileViewerRendererPlugin, type RendererDefinition } from '@file-viewer/core';
2
+ export { getFileViewerHlsLoader, getFileViewerMidiLoader, registerFileViewerHlsLoader, registerFileViewerMidiLoader, } from './optionalCapabilities.js';
3
+ export type { FileViewerOptionalModuleLoader } from './optionalCapabilities.js';
2
4
  export declare const mediaRendererDefinitions: RendererDefinition[];
3
5
  export declare const renderFileViewerAudio: FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>;
4
6
  export declare const renderFileViewerVideo: FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DEFAULT_RENDERER_DEFINITIONS, } from '@file-viewer/core';
2
+ export { getFileViewerHlsLoader, getFileViewerMidiLoader, registerFileViewerHlsLoader, registerFileViewerMidiLoader, } from './optionalCapabilities.js';
2
3
  const mediaRendererIds = ['audio', 'video'];
3
4
  const mediaDefinitions = DEFAULT_RENDERER_DEFINITIONS.filter(definition => mediaRendererIds.includes(definition.id));
4
5
  if (mediaDefinitions.length !== mediaRendererIds.length) {
@@ -0,0 +1,7 @@
1
+ import type * as HlsModule from 'hls.js';
2
+ import type * as MidiModule from '@tonejs/midi';
3
+ export type FileViewerOptionalModuleLoader<T> = () => Promise<T>;
4
+ export declare const registerFileViewerHlsLoader: (loader: FileViewerOptionalModuleLoader<typeof HlsModule> | null) => void;
5
+ export declare const registerFileViewerMidiLoader: (loader: FileViewerOptionalModuleLoader<typeof MidiModule> | null) => void;
6
+ export declare const getFileViewerHlsLoader: () => FileViewerOptionalModuleLoader<typeof HlsModule> | null;
7
+ export declare const getFileViewerMidiLoader: () => FileViewerOptionalModuleLoader<typeof MidiModule> | null;
@@ -0,0 +1,10 @@
1
+ let hlsLoader = null;
2
+ let midiLoader = null;
3
+ export const registerFileViewerHlsLoader = (loader) => {
4
+ hlsLoader = loader;
5
+ };
6
+ export const registerFileViewerMidiLoader = (loader) => {
7
+ midiLoader = loader;
8
+ };
9
+ export const getFileViewerHlsLoader = () => hlsLoader;
10
+ export const getFileViewerMidiLoader = () => midiLoader;
package/dist/video.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createFileViewerTranslator } from '@file-viewer/core';
2
+ import { getFileViewerHlsLoader } from './optionalCapabilities.js';
2
3
  import { extractMp4vSoftwareTrack, inspectMp4VideoTrack } from './mp4.js';
3
4
  import { mountMp4vSoftwarePlayer } from './mp4vPlayer.js';
4
5
  const videoStyle = `
@@ -138,7 +139,11 @@ export default async function renderVideo(buffer, target, type, context) {
138
139
  await waitForVideoMetadata(video, context === null || context === void 0 ? void 0 : context.signal);
139
140
  return;
140
141
  }
141
- const { default: HlsConstructor } = await import('hls.js');
142
+ const loadHls = getFileViewerHlsLoader();
143
+ if (!loadHls) {
144
+ throw new Error('HLS fallback support is opt-in. Run `npx file-viewer-cli add streaming-media --write`, then `npx file-viewer-cli install --yes`.');
145
+ }
146
+ const { default: HlsConstructor } = await loadHls();
142
147
  if (disposed) {
143
148
  return;
144
149
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "../../../ecosystem/capability-manifest.schema.json",
3
+ "schemaVersion": 1,
4
+ "id": "media",
5
+ "packageName": "@file-viewer/renderer-media",
6
+ "rendererIds": ["video", "audio"],
7
+ "formats": ["mp4", "webm", "mp3", "mpeg", "wav", "ogg", "oga", "opus", "m4a", "aac", "flac", "weba"],
8
+ "assets": { "rendererIds": [] },
9
+ "license": { "spdx": "Apache-2.0", "policy": "permissive" },
10
+ "weight": "standard",
11
+ "profiles": ["lite", "standard", "all"]
12
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-media",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "Standalone audio and video renderer plugin for File Viewer with native media playback, HLS fallback, MIDI parsing, and offline-friendly lazy loading.",
6
+ "description": "Standalone native audio and video renderer for File Viewer; HLS fallback and MIDI inspection are explicit opt-in capabilities.",
7
7
  "keywords": [
8
8
  "file-viewer",
9
9
  "renderer",
@@ -50,25 +50,29 @@
50
50
  },
51
51
  "files": [
52
52
  "dist",
53
+ "file-viewer.capability.json",
53
54
  "README.md",
54
55
  "README.en.md",
55
56
  "LICENSE"
56
57
  ],
57
58
  "dependencies": {
58
- "@file-viewer/core": "2.3.0",
59
- "@tonejs/midi": "^2.0.28",
60
- "hls.js": "^1.6.16"
59
+ "@file-viewer/core": "3.0.0"
61
60
  },
62
61
  "devDependencies": {
62
+ "@tonejs/midi": "^2.0.28",
63
+ "hls.js": "^1.6.16",
63
64
  "typescript": "^6.0.3"
64
65
  },
66
+ "fileViewer": {
67
+ "capabilityManifest": "./file-viewer.capability.json"
68
+ },
65
69
  "license": "Apache-2.0",
66
70
  "scripts": {
67
71
  "build": "tsc -b tsconfig.json && node scripts/copy-mp4v-assets.mjs",
68
72
  "type-check": "tsc -b tsconfig.json",
69
73
  "build:mp4v-decoder": "node scripts/build-mp4v-decoder.mjs",
70
74
  "verify:mp4v-boundary": "node scripts/verify-mp4v-boundary.mjs",
71
- "verify:mp4v-demo-dist": "npm exec --yes --package playwright -- node scripts/verify-mp4v-demo-dist.mjs",
72
- "verify:mp4v-black-screen": "pnpm build && pnpm verify:mp4v-boundary && npm exec --yes --package playwright -- node scripts/verify-mp4v-black-screen.mjs"
75
+ "verify:mp4v-demo-dist": "npm exec --yes --package playwright@1.61.1 -- node scripts/verify-mp4v-demo-dist.mjs",
76
+ "verify:mp4v-black-screen": "pnpm build && pnpm verify:mp4v-boundary && npm exec --yes --package playwright@1.61.1 -- node scripts/verify-mp4v-black-screen.mjs"
73
77
  }
74
78
  }