@file-viewer/renderer-text 3.3.4 → 3.3.6

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/text/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/text/README.zh-CN.md)
4
4
 
5
- Base code, text, and Markdown renderer package for Flyfish File Viewer. Mermaid, side-by-side patch diff, and Git bundle inspection live in `@file-viewer/capability-mermaid` and `@file-viewer/capability-text-tools`; they are excluded from the standard/full default closure.
5
+ Base code, text, and Markdown renderer package for Flyfish File Viewer. Mermaid, side-by-side patch diff, and Git bundle inspection live in `@file-viewer/capability-mermaid` and `@file-viewer/capability-text-tools`. The standard preset omits them; `preset-all` and Full packages include them.
6
6
 
7
7
  ## Usage
8
8
 
@@ -37,6 +37,7 @@ const options = {
37
37
  ## Capabilities
38
38
 
39
39
  - Code and text preview uses `highlight.js` core with per-language dynamic imports instead of registering every language up front.
40
+ - Code/text and Markdown expose their existing zoom providers through the shared capabilities. Viewer toolbar actions follow the active provider's minimum, maximum, and reset state without renderer overrides.
40
41
  - Code, text, and virtualized Markdown source views show their file type, indexing status, and line-count metadata bar by default. Set `options.text.toolbar: false` to hide this renderer-local bar without hiding the viewer-level download, search, or zoom toolbar.
41
42
  - Regular code and text previews can show a line-number gutter with `options.text.lineNumbers: true`. The gutter is excluded from copied source, search matches, and assistive reading. Virtual large-text views keep their existing gutter unless it is explicitly set to `false`.
42
43
  - `options.text.wrapLongLines: true` changes layout only and never inserts source newlines. Regular previews keep one gutter entry per logical line; large files remain bounded in the virtual window while wrapping to the available width.
@@ -54,7 +55,7 @@ const options = {
54
55
 
55
56
  ## Migration Note
56
57
 
57
- Standard/full includes base code, text, and Markdown without installing `diff2html`, `pako`, or Mermaid. Optional uploads show `npx file-viewer-cli add text-tools --write` or `add mermaid-markdown --write`; `preset-all` is only for explicit all/debug use.
58
+ The base text renderer and standard preset provide code, text, and Markdown without installing `diff2html`, `pako`, or Mermaid. Add `text-tools` or `mermaid-markdown` with the CLI when composing a lightweight integration. `preset-all` and Full packages already include those capabilities.
58
59
 
59
60
  ## Optional XML Profiles
60
61
 
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/text/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/text/README.zh-CN.md)
4
4
 
5
- Base code, text, and Markdown renderer package for Flyfish File Viewer. Mermaid, side-by-side patch diff, and Git bundle inspection live in `@file-viewer/capability-mermaid` and `@file-viewer/capability-text-tools`; they are excluded from the standard/full default closure.
5
+ Base code, text, and Markdown renderer package for Flyfish File Viewer. Mermaid, side-by-side patch diff, and Git bundle inspection live in `@file-viewer/capability-mermaid` and `@file-viewer/capability-text-tools`. The standard preset omits them; `preset-all` and Full packages include them.
6
6
 
7
7
  ## Usage
8
8
 
@@ -37,6 +37,7 @@ const options = {
37
37
  ## Capabilities
38
38
 
39
39
  - Code and text preview uses `highlight.js` core with per-language dynamic imports instead of registering every language up front.
40
+ - Code/text and Markdown expose their existing zoom providers through the shared capabilities. Viewer toolbar actions follow the active provider's minimum, maximum, and reset state without renderer overrides.
40
41
  - Code, text, and virtualized Markdown source views show their file type, indexing status, and line-count metadata bar by default. Set `options.text.toolbar: false` to hide this renderer-local bar without hiding the viewer-level download, search, or zoom toolbar.
41
42
  - Regular code and text previews can show a line-number gutter with `options.text.lineNumbers: true`. The gutter is excluded from copied source, search matches, and assistive reading. Virtual large-text views keep their existing gutter unless it is explicitly set to `false`.
42
43
  - `options.text.wrapLongLines: true` changes layout only and never inserts source newlines. Regular previews keep one gutter entry per logical line; large files remain bounded in the virtual window while wrapping to the available width.
@@ -54,7 +55,7 @@ const options = {
54
55
 
55
56
  ## Migration Note
56
57
 
57
- Standard/full includes base code, text, and Markdown without installing `diff2html`, `pako`, or Mermaid. Optional uploads show `npx file-viewer-cli add text-tools --write` or `add mermaid-markdown --write`; `preset-all` is only for explicit all/debug use.
58
+ The base text renderer and standard preset provide code, text, and Markdown without installing `diff2html`, `pako`, or Mermaid. Add `text-tools` or `mermaid-markdown` with the CLI when composing a lightweight integration. `preset-all` and Full packages already include those capabilities.
58
59
 
59
60
  ## Optional XML Profiles
60
61
 
package/README.zh-CN.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Markdown 中标明受支持语言的围栏代码块默认自动高亮,Shadow DOM 内同样可用,无需调用 `highlightAll()`。语言模块按需从本地加载;未知语言以及超过每份文档 512 KiB 高亮预算的代码保持原文显示。通过 `options.text.markdownHighlight: false` 可以关闭。
6
6
 
7
- Flyfish File Viewer 的基础代码、文本和 Markdown renderer 包。Mermaid、patch 左右比对和 Git bundle 检查已拆到 `@file-viewer/capability-mermaid` 与 `@file-viewer/capability-text-tools`,不进入 standard/full 默认闭包。
7
+ Flyfish File Viewer 的基础代码、文本和 Markdown renderer 包。Mermaid、patch 左右比对和 Git bundle 检查位于 `@file-viewer/capability-mermaid` 与 `@file-viewer/capability-text-tools`。standard 预设不包含这些能力,`preset-all` 和 Full 包已包含。
8
8
 
9
9
  ## 用法
10
10
 
@@ -39,6 +39,7 @@ const options = {
39
39
  ## 能力边界
40
40
 
41
41
  - 代码和文本使用 `highlight.js` core + 按语言动态加载,避免一次性注册全部语言。
42
+ - 代码、文本和 Markdown 通过共享能力声明启用已有缩放 provider。Viewer 工具栏遵循当前 provider 的最小、最大和重置状态,无需覆盖 renderer 定义。
42
43
  - 代码、文本和超大 Markdown 源码视图默认显示文件类型、索引状态和行数元信息栏;传入 `options.text.toolbar: false` 可隐藏该 renderer 内部栏,不影响 Viewer 的下载、搜索、缩放等全局工具栏。
43
44
  - 普通代码和文本可通过 `options.text.lineNumbers: true` 显示行号;行号不会进入复制内容、搜索结果或无障碍朗读。超大文本保留原有的虚拟行号栏,可显式传 `false` 隐藏。
44
45
  - `options.text.wrapLongLines: true` 仅改变布局,不向源码插入换行。普通预览会按逻辑行维护行号,超大文本仍使用有界虚拟窗口并按可用宽度换行。
@@ -55,7 +56,7 @@ const options = {
55
56
 
56
57
  ## 迁移说明
57
58
 
58
- standard/full 默认包含基础代码、文本和 Markdown,不安装 `diff2html`、`pako` 或 Mermaid。打开可选格式时会提示运行 `npx file-viewer-cli add text-tools --write` 或 `add mermaid-markdown --write`;`preset-all` 仅用于显式全量/调试。
59
+ 基础 text renderer 和 standard 预设提供代码、文本和 Markdown,不安装 `diff2html`、`pako` 或 Mermaid。轻量接入可通过 CLI 加入 `text-tools` 或 `mermaid-markdown`;`preset-all` 和 Full 包已包含这些能力。
59
60
 
60
61
  ## 可选 XML Profiles
61
62
 
@@ -10,7 +10,7 @@ const require = createRequire(import.meta.url)
10
10
  const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
11
11
  const engines = [
12
12
  { name: 'xmllint-wasm', version: '5.3.0', files: ['xmllint-browser.mjs', 'xmllint.wasm'] },
13
- { name: 'xslt-polyfill', version: '1.0.33', files: ['dist/xslt-wasm.js'] }
13
+ { name: 'xslt-polyfill', version: '1.0.37', files: ['dist/xslt-wasm.js'] }
14
14
  ]
15
15
 
16
16
  /** Copy pinned optional runtimes and notices; never download or install packages. */
@@ -19,7 +19,7 @@ export async function copyXmlProfileAssets(destination = 'public/file-viewer/xml
19
19
  for (const engine of engines) {
20
20
  let manifest
21
21
  try { manifest = require.resolve(`${engine.name}/package.json`) } catch {
22
- throw new Error(`Install the optional XML engines first: pnpm add xmllint-wasm@5.3.0 xslt-polyfill@1.0.33 (missing ${engine.name}).`)
22
+ throw new Error(`Install the optional XML engines first: pnpm add xmllint-wasm@5.3.0 xslt-polyfill@1.0.37 (missing ${engine.name}).`)
23
23
  }
24
24
  const metadata = JSON.parse(await readFile(manifest, 'utf8'))
25
25
  if (metadata.version !== engine.version) throw new Error(`Expected ${engine.name}@${engine.version}; found ${metadata.version}.`)
@@ -47,7 +47,7 @@ let entryPoint = false
47
47
  try { entryPoint = !!process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url) } catch { /* Imported helper. */ }
48
48
  if (entryPoint) {
49
49
  if (process.argv.includes('--help')) {
50
- console.log('Usage: file-viewer-xml-assets [destination-directory]\nDefault: public/file-viewer/xml\nRequires xmllint-wasm@5.3.0 and xslt-polyfill@1.0.33 installed by the host.')
50
+ console.log('Usage: file-viewer-xml-assets [destination-directory]\nDefault: public/file-viewer/xml\nRequires xmllint-wasm@5.3.0 and xslt-polyfill@1.0.37 installed by the host.')
51
51
  } else if (process.argv.length > 3 || process.argv[2]?.startsWith('-')) {
52
52
  console.error('Expected one destination directory.'); process.exitCode = 1
53
53
  } else {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_RENDERER_DEFINITIONS, } from '@file-viewer/core';
1
+ import { DEFAULT_RENDERER_DEFINITIONS, renderWithFileViewerDocumentInspection, } from '@file-viewer/core';
2
2
  import { getXmlProfilesLoader } from './xmlRegistration.js';
3
3
  export { getFileViewerMermaidLoader, getFileViewerDiffToHtml, getFileViewerPakoLoader, registerFileViewerDiffToHtml, registerFileViewerMermaidLoader, registerFileViewerPakoLoader, } from './optionalCapabilities.js';
4
4
  export { sanitizeFileViewerRichHtml } from './sanitizeHtml.js';
@@ -8,7 +8,7 @@ if (textDefinitions.length !== textRendererIds.length) {
8
8
  throw new Error('@file-viewer/renderer-text could not locate the shared code/markdown format definitions.');
9
9
  }
10
10
  export const textRendererDefinitions = textDefinitions;
11
- export const renderFileViewerCode = async (buffer, target, type, context) => {
11
+ const renderCodePreview = async (buffer, target, type, context) => {
12
12
  var _a, _b, _c, _d, _e;
13
13
  if ((type === null || type === void 0 ? void 0 : type.trim().toLowerCase()) === 'lrc') {
14
14
  const { default: renderLrc } = await import('./lrc.js');
@@ -37,6 +37,7 @@ export const renderFileViewerCode = async (buffer, target, type, context) => {
37
37
  const { default: renderCode } = await import('./code.js');
38
38
  return renderCode(buffer, target, type, context);
39
39
  };
40
+ export const renderFileViewerCode = (buffer, target, type, context) => renderWithFileViewerDocumentInspection(buffer, target, type || '', context, () => renderCodePreview(buffer, target, type, context));
40
41
  export const renderFileViewerMarkdown = (buffer, target, type, context) => import('./largeText.js').then(async ({ default: renderLargeText, shouldVirtualizeMarkdownBuffer }) => {
41
42
  if (shouldVirtualizeMarkdownBuffer(buffer, context)) {
42
43
  return renderLargeText(buffer, target, type || 'md', context);
@@ -12,6 +12,9 @@ function runXsltWorker() {
12
12
  }
13
13
  };
14
14
  let networkAttempt = false;
15
+ let engineError = false;
16
+ const reportEngineError = () => { engineError = true; };
17
+ console.error = reportEngineError;
15
18
  const deny = () => { networkAttempt = true; throw new Error('External XML resources are disabled.'); };
16
19
  Object.defineProperty(globalThis, 'fetch', { value: async () => deny(), writable: false, configurable: false });
17
20
  for (const name of ['XMLHttpRequest', 'WebSocket', 'EventSource', 'importScripts']) {
@@ -21,7 +24,7 @@ function runXsltWorker() {
21
24
  let engine;
22
25
  const pointers = [];
23
26
  try {
24
- engine = await createXSLTTransformModule({ print: () => undefined, printErr: () => undefined });
27
+ engine = await createXSLTTransformModule({ print: () => undefined, printErr: reportEngineError });
25
28
  const encoder = new TextEncoder();
26
29
  const allocate = (bytes) => {
27
30
  const pointer = engine._malloc(bytes.length + 1);
@@ -46,6 +49,8 @@ function runXsltWorker() {
46
49
  pointers.push(result);
47
50
  if (networkAttempt)
48
51
  throw new Error('The XSLT engine attempted to read a blocked external resource.');
52
+ if (engineError)
53
+ throw new Error('The XSLT engine reported an error while transforming this document.');
49
54
  const heap = new Uint8Array(engine.wasmMemory.buffer);
50
55
  let end = result;
51
56
  const bound = Math.min(heap.length, result + data.maxOutputBytes + 1);
@@ -8,7 +8,7 @@ the engine's instructions or data, nor install the automatic page polyfill.
8
8
 
9
9
  | Component | Verified upstream notice | Included notice |
10
10
  | --- | --- | --- |
11
- | xslt-polyfill 1.0.33 | [BSD-3-Clause](https://github.com/mfreed7/xslt_polyfill/blob/4c0603c4dc84c17a511816c703c7ce3b936aa56f/LICENSE) | xslt-polyfill-LICENSE.txt |
11
+ | xslt-polyfill 1.0.37 | [BSD-3-Clause](https://github.com/mfreed7/xslt_polyfill/blob/ba5175c41412b7193b4f40e5175fd9e5cc18b379/LICENSE) | xslt-polyfill-LICENSE.txt |
12
12
  | xmllint-wasm 5.3.0 | [MIT](https://github.com/noppa/xmllint-wasm/blob/master/COPYING) | xmllint-wasm-COPYING.txt |
13
13
  | XSLT libxml2 submodule | [Copyright at c34742f](https://github.com/GNOME/libxml2/blob/c34742f3017f6d39f3e4ccae4f70172238160ef8/Copyright) | libxml2-xslt-Copyright.txt |
14
14
  | XSD libxml2 submodule | [Copyright at eb0a2f2](https://github.com/GNOME/libxml2/blob/eb0a2f2b91566384f378d870ffcd69c0a24162cc/Copyright) | libxml2-xsd-Copyright.txt |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-text",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone code, text, and Markdown renderer for File Viewer; Mermaid, patch diff, and Git bundle tools are explicit opt-in capabilities.",
@@ -134,17 +134,17 @@
134
134
  "README.zh-CN.md"
135
135
  ],
136
136
  "dependencies": {
137
- "@file-viewer/core": "3.3.4",
137
+ "@file-viewer/core": "3.3.6",
138
138
  "@types/pako": "^2.0.4",
139
139
  "@prettier/plugin-xml": "3.4.2",
140
- "dompurify": "3.4.17",
140
+ "dompurify": "3.4.18",
141
141
  "highlight.js": "^11.11.1",
142
- "marked": "^18.1.2",
143
- "prettier": "3.9.10"
142
+ "marked": "^18.2.1",
143
+ "prettier": "3.10.1"
144
144
  },
145
145
  "peerDependencies": {
146
146
  "xmllint-wasm": "5.3.0",
147
- "xslt-polyfill": "1.0.33"
147
+ "xslt-polyfill": "1.0.37"
148
148
  },
149
149
  "peerDependenciesMeta": {
150
150
  "xmllint-wasm": {