@filumo/core 0.0.0-stage → 0.1.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.
- package/LICENSE +20 -0
- package/README.md +145 -2
- package/README.zh-CN.md +137 -0
- package/dist/build-manifest.json +58 -0
- package/dist/chunks/chunk-AUUMY3MH.js +32 -0
- package/dist/controller.d.ts +15 -0
- package/dist/errors.d.ts +11 -0
- package/dist/exportOriginal.d.ts +7 -0
- package/dist/guardSource.d.ts +5 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1400 -0
- package/dist/range/BlobRangeReader.d.ts +5 -0
- package/dist/range/HttpRangeReader.d.ts +11 -0
- package/dist/range/RangeCache.d.ts +11 -0
- package/dist/range/types.d.ts +5 -0
- package/dist/session.d.ts +16 -0
- package/dist/source.d.ts +8 -0
- package/dist/sourceStream.d.ts +10 -0
- package/dist/styles.css +1 -0
- package/dist/text/TextContent.d.ts +39 -0
- package/dist/text/TextTaskClient.d.ts +22 -0
- package/dist/text/decodeText.d.ts +9 -0
- package/dist/text/detectEncoding.d.ts +16 -0
- package/dist/text/findTextMatches.d.ts +3 -0
- package/dist/text/indexLines.d.ts +8 -0
- package/dist/text/tasks.d.ts +5 -0
- package/dist/text/types.d.ts +51 -0
- package/dist/text.d.ts +8 -0
- package/dist/text.js +528 -0
- package/dist/types.d.ts +92 -0
- package/package.json +68 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gyxing
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @filumo/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p>
|
|
4
|
+
<strong>English</strong> | <a href="https://github.com/gyxing/filumo-viewer/blob/master/packages/core/README.zh-CN.md">简体中文</a> ·
|
|
5
|
+
<a href="https://gyxing.github.io/filumo-viewer/playground" target="_blank" rel="noopener noreferrer">Live demo</a> ·
|
|
6
|
+
<a href="https://gyxing.github.io/filumo-viewer/docs" target="_blank" rel="noopener noreferrer">Integration docs</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
Headless document sessions, file sources and plugin protocols for Filumo, with DOM-free text utilities.
|
|
10
|
+
|
|
11
|
+
The headless foundation for Filumo: document sources, format detection, plugin contracts, cancellation and session cleanup. Shared text utilities are available on demand from a separate subpath.
|
|
12
|
+
|
|
13
|
+
This documentation covers **0.1.1**. The commands below describe consumption after publication to npm. When using this source workspace, build the packages first as described in the integration guide.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- The core entry creates no DOM, viewer or format engine, making it suitable for custom hosts and protocol integrations.
|
|
18
|
+
- Supports local File/Blob objects, bytes, URLs and custom sources. Source leases manage range reads, budgets and cancellation.
|
|
19
|
+
- Registered text fallback is attempted only after all regular format detection fails. A parser error after a format has claimed the file is not passed to another format.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
pnpm add @filumo/core @filumo/text
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or with npm:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install @filumo/core @filumo/text
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Minimal integration
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createDocumentController } from '@filumo/core';
|
|
37
|
+
import { text } from '@filumo/text';
|
|
38
|
+
|
|
39
|
+
const controller = createDocumentController({
|
|
40
|
+
plugins: [text({ worker: 'never' }).document],
|
|
41
|
+
resourcePolicy: { maxFileBytes: 2 * 1024 * 1024 },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await controller.open(new File(['First line\nSecond line'], 'example.txt'));
|
|
46
|
+
console.log(controller.getSnapshot().status);
|
|
47
|
+
} finally {
|
|
48
|
+
await controller.destroy();
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Common options
|
|
53
|
+
|
|
54
|
+
| Option | Default | Description |
|
|
55
|
+
| ----------------------------- | -------------------- | ----------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `plugins` | Required | DocumentPlugin descriptors, available through a format factory's .document property. |
|
|
57
|
+
| `pluginId` | Automatic detection | Explicitly selects a registered plugin without implicitly installing one or switching fallback. |
|
|
58
|
+
| `baseUrl` | Unset | Base address for resolving relative URLs. |
|
|
59
|
+
| `resourcePolicy.maxFileBytes` | No universal limit | Maximum bytes read for a document. |
|
|
60
|
+
| `resourcePolicy.timeoutMs` | No universal timeout | Timeout for a single open operation. |
|
|
61
|
+
|
|
62
|
+
See the public declarations and source for complete types. Features cannot be enabled by guessing undocumented option names.
|
|
63
|
+
|
|
64
|
+
## Shared text utilities and sources
|
|
65
|
+
|
|
66
|
+
`@filumo/core/text` provides readText, decodeTextBytes, indexLines, textLineAt, findTextMatches, TextContent and a cancellable Worker task protocol without DOM dependencies. The main entry does not eagerly load all readers.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { readText } from '@filumo/core/text';
|
|
70
|
+
|
|
71
|
+
const abort = new AbortController();
|
|
72
|
+
const result = await readText(
|
|
73
|
+
new TextEncoder().encode('First line\nSecond line'),
|
|
74
|
+
{
|
|
75
|
+
signal: abort.signal,
|
|
76
|
+
encoding: 'auto',
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
if (result.kind === 'ready') {
|
|
80
|
+
console.log(result.document.lineStarts.length);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
A minimal `DocumentSource` implements readAll(signal) and dispose(), with optional readBlob, readRange and getRangeReader. Local File/Blob sources reuse the original Blob where possible. Efficient HTTP range reads require actual 206 responses and valid Content-Range headers; an existing readRange method alone does not prove efficient chunking. Full-read fallback reuses the same source cache.
|
|
85
|
+
|
|
86
|
+
FilumoError.code identifies stable error semantics; normal cancellation may produce AbortError. Input changes, timeouts and destruction cancel previous tasks. Custom sources must respect the signal and release their own resources.
|
|
87
|
+
|
|
88
|
+
## Styles and boundaries
|
|
89
|
+
|
|
90
|
+
Core has no stylesheets, UI or format engines. The example above reads session state without rendering a document. A DOM-free core does not mean every format driver runs on every Node.js version; each format package documents browser requirements. String input is a URL; use File/Blob or bytes for document content.
|
|
91
|
+
|
|
92
|
+
Use DOM or a framework adapter when you need a viewer. DocumentPlugin and ViewerPlugin, which includes loadView, serve different contracts.
|
|
93
|
+
|
|
94
|
+
## Inputs and runtime environment
|
|
95
|
+
|
|
96
|
+
String input represents a URL, not document content. Use File/Blob for inline text. Other sources include Uint8Array, URL objects with name/mimeType/request, and custom DocumentSource factories. Remote files and supporting resources must satisfy the host's networking, CORS and CSP configuration.
|
|
97
|
+
|
|
98
|
+
Packages are published as ESM with TypeScript declarations and no CommonJS require entry. Viewer mounting, image decoding and file selection run in the browser. Importing a lightweight entry does not enable server-side document rendering. Create instances in the client lifecycle and destroy them when no longer needed.
|
|
99
|
+
|
|
100
|
+
## Public entries
|
|
101
|
+
|
|
102
|
+
| Public entry | Purpose |
|
|
103
|
+
| ------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
104
|
+
| `@filumo/core` | createDocumentController, createSession, normalizeSource, FilumoError and source/plugin/session types |
|
|
105
|
+
| `@filumo/core/text` | DOM-free decoding, indexing, search and task protocols |
|
|
106
|
+
|
|
107
|
+
Unlisted internal paths are not stable public APIs. Standalone format packages do not depend on React/Vue adapters; install only the formats and adapter your host needs.
|
|
108
|
+
|
|
109
|
+
## Filumo packages
|
|
110
|
+
|
|
111
|
+
The current package is bold. Each package is published independently. Package names link to npm, and source links point to this repository.
|
|
112
|
+
|
|
113
|
+
<!-- filumo-packages:start -->
|
|
114
|
+
|
|
115
|
+
| Package (npm) | Purpose | Source documentation |
|
|
116
|
+
| ------------------------------------------------------------------ | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
117
|
+
| **[@filumo/core](https://www.npmjs.com/package/@filumo/core)** | Headless sources, plugin contracts, sessions and shared text utilities | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/core/README.md) |
|
|
118
|
+
| [@filumo/dom](https://www.npmjs.com/package/@filumo/dom) | Native DOM viewer, toolbars, source views, outlines and shared UI | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/dom/README.md) |
|
|
119
|
+
| [@filumo/viewer](https://www.npmjs.com/package/@filumo/viewer) | Standard preset and factories for ten format plugins | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/viewer/README.md) |
|
|
120
|
+
| [@filumo/office](https://www.npmjs.com/package/@filumo/office) | Word, Excel, PowerPoint and supported legacy formats | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/office/README.md) |
|
|
121
|
+
| [@filumo/pdf](https://www.npmjs.com/package/@filumo/pdf) | Continuous PDF reading, outlines, thumbnails and search | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/pdf/README.md) |
|
|
122
|
+
| [@filumo/image](https://www.npmjs.com/package/@filumo/image) | Image preview, zoom, rotation, panning and shared overlays | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/image/README.md) |
|
|
123
|
+
| [@filumo/text](https://www.npmjs.com/package/@filumo/text) | Plain text, logs, encoding detection and readable-text fallback | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/text/README.md) |
|
|
124
|
+
| [@filumo/json](https://www.npmjs.com/package/@filumo/json) | JSON / JSONC / JSONL / NDJSON source and structure views | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/json/README.md) |
|
|
125
|
+
| [@filumo/markdown](https://www.npmjs.com/package/@filumo/markdown) | Markdown reading, outlines, GFM layout and code highlighting | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/markdown/README.md) |
|
|
126
|
+
| [@filumo/csv](https://www.npmjs.com/package/@filumo/csv) | CSV / TSV read-only grids, virtual scrolling and search | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/csv/README.md) |
|
|
127
|
+
| [@filumo/xml](https://www.npmjs.com/package/@filumo/xml) | XML source, namespace-aware structure trees and node navigation | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/xml/README.md) |
|
|
128
|
+
| [@filumo/code](https://www.npmjs.com/package/@filumo/code) | Read-only highlighting for code, scripts, configuration and stylesheets | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/code/README.md) |
|
|
129
|
+
| [@filumo/react](https://www.npmjs.com/package/@filumo/react) | React 18/19 adapter | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/react/README.md) |
|
|
130
|
+
| [@filumo/vue](https://www.npmjs.com/package/@filumo/vue) | Vue 3 (>=3.3 <4) adapter | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue/README.md) |
|
|
131
|
+
| [@filumo/vue2](https://www.npmjs.com/package/@filumo/vue2) | Vue 2 (^2.6.14 or ^2.7.16) adapter | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue2/README.md) |
|
|
132
|
+
| [@filumo/archive](https://www.npmjs.com/package/@filumo/archive) | Archive directories, on-demand extraction and child previews | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/archive/README.md) |
|
|
133
|
+
|
|
134
|
+
<!-- filumo-packages:end -->
|
|
135
|
+
|
|
136
|
+
## Documentation and feedback
|
|
137
|
+
|
|
138
|
+
- [Source and complete types](https://github.com/gyxing/filumo-viewer/tree/master/packages/core/src)
|
|
139
|
+
- [Framework integration](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/preview-integration.md)
|
|
140
|
+
- [Format capabilities and limits](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/compatibility.md)
|
|
141
|
+
- [Text-based formats](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/text-formats.md)
|
|
142
|
+
- [Images and PDF deployment](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/image-pdf.md)
|
|
143
|
+
- [Standalone framework examples](https://github.com/gyxing/filumo-viewer/tree/master/examples)
|
|
144
|
+
- [Changelog](https://github.com/gyxing/filumo-viewer/blob/master/CHANGELOG.md)
|
|
145
|
+
- [Report an issue](https://github.com/gyxing/filumo-viewer/issues)
|
|
146
|
+
- [MIT license](https://github.com/gyxing/filumo-viewer/blob/master/packages/core/LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# @filumo/core
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://github.com/gyxing/filumo-viewer/blob/master/packages/core/README.md">English</a> | <strong>简体中文</strong> ·
|
|
5
|
+
<a href="https://gyxing.github.io/filumo-viewer/playground" target="_blank" rel="noopener noreferrer">在线示例</a> ·
|
|
6
|
+
<a href="https://gyxing.github.io/filumo-viewer/docs" target="_blank" rel="noopener noreferrer">对接文档</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
Filumo 的无界面基础层:统一文件来源、格式探测、插件协议、取消与会话释放;公共文本能力从独立子入口按需导入。
|
|
10
|
+
|
|
11
|
+
本文档对应 **0.1.1**。以下命令展示 npm 发布后的消费方式;从当前源码工作区使用时,请先按接入指南构建各包。
|
|
12
|
+
|
|
13
|
+
## 主要能力
|
|
14
|
+
|
|
15
|
+
- 核心入口不创建 DOM、查看器或格式引擎,适合自定义宿主和协议集成。
|
|
16
|
+
- 支持本地 File/Blob、字节、URL 和自定义来源;区间读取、配额和取消由来源租约管理。
|
|
17
|
+
- 常规格式探测全部失败后才尝试已注册插件的文本兜底;已经接管的解析错误不会改交其他格式。
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pnpm add @filumo/core @filumo/text
|
|
23
|
+
# 或使用 npm
|
|
24
|
+
npm install @filumo/core @filumo/text
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 最小接入
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { createDocumentController } from '@filumo/core';
|
|
31
|
+
import { text } from '@filumo/text';
|
|
32
|
+
|
|
33
|
+
const controller = createDocumentController({
|
|
34
|
+
plugins: [text({ worker: 'never' }).document],
|
|
35
|
+
resourcePolicy: { maxFileBytes: 2 * 1024 * 1024 },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await controller.open(new File(['第一行\n第二行'], 'example.txt'));
|
|
40
|
+
console.log(controller.getSnapshot().status);
|
|
41
|
+
} finally {
|
|
42
|
+
await controller.destroy();
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 常用配置
|
|
47
|
+
|
|
48
|
+
| 配置项 | 默认值 | 说明 |
|
|
49
|
+
| ----------------------------- | -------------- | ---------------------------------------------------------- |
|
|
50
|
+
| `plugins` | 必填 | DocumentPlugin 描述符列表;可从格式工厂的 .document 取得。 |
|
|
51
|
+
| `pluginId` | 自动探测 | 显式选择已注册插件,不隐式安装或切换兜底。 |
|
|
52
|
+
| `baseUrl` | 未设置 | 解析相对 URL 时使用的基准地址。 |
|
|
53
|
+
| `resourcePolicy.maxFileBytes` | 未设置通用上限 | 读取文件的字节限制。 |
|
|
54
|
+
| `resourcePolicy.timeoutMs` | 未设置通用超时 | 单次打开任务的超时。 |
|
|
55
|
+
|
|
56
|
+
完整类型以公开声明与源码为准;没有列出的功能不能通过猜测选项名开启。
|
|
57
|
+
|
|
58
|
+
## 公共文本与来源
|
|
59
|
+
|
|
60
|
+
`@filumo/core/text` 提供 readText、decodeTextBytes、indexLines、textLineAt、findTextMatches、TextContent 和可取消的 Worker 任务协议,不依赖 DOM;主入口不会自动加载全部读取器。
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { readText } from '@filumo/core/text';
|
|
64
|
+
|
|
65
|
+
const abort = new AbortController();
|
|
66
|
+
const result = await readText(new TextEncoder().encode('第一行\n第二行'), {
|
|
67
|
+
signal: abort.signal,
|
|
68
|
+
encoding: 'auto',
|
|
69
|
+
});
|
|
70
|
+
if (result.kind === 'ready') {
|
|
71
|
+
console.log(result.document.lineStarts.length);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`DocumentSource` 最小实现提供 readAll(signal) 和 dispose(),可选提供 readBlob、readRange、getRangeReader。本地 File/Blob 优先复用原 Blob;高效 HTTP 区间读取需要真实 206 和正确 Content-Range,旧 readRange 不能被推测为高效分块。完整读取回退继续复用同一来源缓存。
|
|
76
|
+
|
|
77
|
+
FilumoError.code 用于区分稳定错误语义,普通取消可能为 AbortError。切换输入、超时和销毁会取消旧任务;宿主自定义来源必须遵守 signal,并释放自己的资源。
|
|
78
|
+
|
|
79
|
+
## 样式与边界
|
|
80
|
+
|
|
81
|
+
Core 没有样式文件、界面或格式引擎。上面的例子只读取会话状态,不渲染文件。无 DOM 不代表全部格式驱动都能在任意 Node.js 版本运行;浏览器专用能力由对应格式包说明。字符串输入表示 URL,直接正文使用 File/Blob 或字节。
|
|
82
|
+
|
|
83
|
+
需要查看器时使用 DOM 或框架适配包;不要将 DocumentPlugin 与带 loadView 的 ViewerPlugin 混为一谈。
|
|
84
|
+
|
|
85
|
+
## 输入与运行环境
|
|
86
|
+
|
|
87
|
+
字符串输入表示 URL,不表示文件正文;直接文本内容请使用 File/Blob。支持的来源还包括 Uint8Array、带 name/mimeType/request 的 URL 对象和自定义 DocumentSource 工厂。远程文件和辅助资源需要满足宿主的网络、CORS 与 CSP 配置。
|
|
88
|
+
|
|
89
|
+
包以 ESM 发布,包含 TypeScript 声明;不提供 CommonJS require 入口。查看器挂载、图片解码和文件选择在浏览器执行;导入轻量入口不等于支持在服务端渲染文件。宿主应在客户端生命周期创建实例,并在不再使用时销毁。
|
|
90
|
+
|
|
91
|
+
## 公开入口
|
|
92
|
+
|
|
93
|
+
| 公开入口 | 用途 |
|
|
94
|
+
| ------------------- | ------------------------------------------------------------------------------------------ |
|
|
95
|
+
| `@filumo/core` | createDocumentController、createSession、normalizeSource、FilumoError 及来源/插件/会话类型 |
|
|
96
|
+
| `@filumo/core/text` | 不依赖 DOM 的解码、索引、查找和任务协议 |
|
|
97
|
+
|
|
98
|
+
未列出的包内路径不是稳定公共 API。独立格式不依赖 React/Vue 适配层,宿主只安装实际需要的格式和适配包。
|
|
99
|
+
|
|
100
|
+
## Filumo 包清单
|
|
101
|
+
|
|
102
|
+
当前包已加粗。每个包独立发布,包名链接到 npm,源码链接指向项目实际仓库。
|
|
103
|
+
|
|
104
|
+
<!-- filumo-packages:start -->
|
|
105
|
+
|
|
106
|
+
| 包(点击进入 npm) | 用途 | 源码说明 |
|
|
107
|
+
| ------------------------------------------------------------------ | -------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
108
|
+
| **[@filumo/core](https://www.npmjs.com/package/@filumo/core)** | 无 UI 的来源、插件协议、会话和公共文本处理 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/core/README.zh-CN.md) |
|
|
109
|
+
| [@filumo/dom](https://www.npmjs.com/package/@filumo/dom) | 原生 DOM 查看器、工具栏、原文、大纲和共享 UI | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/dom/README.zh-CN.md) |
|
|
110
|
+
| [@filumo/viewer](https://www.npmjs.com/package/@filumo/viewer) | 十类格式插件的标准预设与工厂聚合 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/viewer/README.zh-CN.md) |
|
|
111
|
+
| [@filumo/office](https://www.npmjs.com/package/@filumo/office) | Word、Excel、PowerPoint 与受支持的旧格式 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/office/README.zh-CN.md) |
|
|
112
|
+
| [@filumo/pdf](https://www.npmjs.com/package/@filumo/pdf) | PDF 连续阅读、大纲、缩略图和查找 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/pdf/README.zh-CN.md) |
|
|
113
|
+
| [@filumo/image](https://www.npmjs.com/package/@filumo/image) | 图片预览、缩放、旋转、拖动及共享弹层 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/image/README.zh-CN.md) |
|
|
114
|
+
| [@filumo/text](https://www.npmjs.com/package/@filumo/text) | 纯文本、日志、编码识别与可读文本兜底 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/text/README.zh-CN.md) |
|
|
115
|
+
| [@filumo/json](https://www.npmjs.com/package/@filumo/json) | JSON / JSONC / JSONL / NDJSON 原文与结构 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/json/README.zh-CN.md) |
|
|
116
|
+
| [@filumo/markdown](https://www.npmjs.com/package/@filumo/markdown) | Markdown 阅读、大纲、GFM 排版与代码高亮 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/markdown/README.zh-CN.md) |
|
|
117
|
+
| [@filumo/csv](https://www.npmjs.com/package/@filumo/csv) | CSV / TSV 只读表格、虚拟滚动和查找 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/csv/README.zh-CN.md) |
|
|
118
|
+
| [@filumo/xml](https://www.npmjs.com/package/@filumo/xml) | XML 原文、命名空间结构树和节点定位 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/xml/README.zh-CN.md) |
|
|
119
|
+
| [@filumo/code](https://www.npmjs.com/package/@filumo/code) | 代码、脚本、配置及样式源码的只读高亮 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/code/README.zh-CN.md) |
|
|
120
|
+
| [@filumo/react](https://www.npmjs.com/package/@filumo/react) | React 18/19 适配组件 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/react/README.zh-CN.md) |
|
|
121
|
+
| [@filumo/vue](https://www.npmjs.com/package/@filumo/vue) | Vue 3(>=3.3 <4)适配组件 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue/README.zh-CN.md) |
|
|
122
|
+
| [@filumo/vue2](https://www.npmjs.com/package/@filumo/vue2) | Vue 2(^2.6.14 或 ^2.7.16)适配组件 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue2/README.zh-CN.md) |
|
|
123
|
+
| [@filumo/archive](https://www.npmjs.com/package/@filumo/archive) | 压缩包目录、按需提取与包内预览 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/archive/README.zh-CN.md) |
|
|
124
|
+
|
|
125
|
+
<!-- filumo-packages:end -->
|
|
126
|
+
|
|
127
|
+
## 文档与反馈
|
|
128
|
+
|
|
129
|
+
- [本包源码与完整类型](https://github.com/gyxing/filumo-viewer/tree/master/packages/core/src)
|
|
130
|
+
- [框架接入指南](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/preview-integration.zh-CN.md)
|
|
131
|
+
- [格式能力与限制](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/compatibility.zh-CN.md)
|
|
132
|
+
- [文本类格式指南](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/text-formats.zh-CN.md)
|
|
133
|
+
- [图片与 PDF 部署](https://github.com/gyxing/filumo-viewer/blob/master/apps/docs/docs/guides/image-pdf.zh-CN.md)
|
|
134
|
+
- [独立框架示例](https://github.com/gyxing/filumo-viewer/tree/master/examples)
|
|
135
|
+
- [项目变更记录](https://github.com/gyxing/filumo-viewer/blob/master/CHANGELOG.md)
|
|
136
|
+
- [问题反馈](https://github.com/gyxing/filumo-viewer/issues)
|
|
137
|
+
- [MIT 许可证](https://github.com/gyxing/filumo-viewer/blob/master/packages/core/LICENSE)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 2,
|
|
3
|
+
"package": "@filumo/core",
|
|
4
|
+
"version": "0.1.1",
|
|
5
|
+
"outputs": [
|
|
6
|
+
{
|
|
7
|
+
"file": "index.js",
|
|
8
|
+
"entryPoint": "src/index.ts",
|
|
9
|
+
"inputs": [
|
|
10
|
+
"src/sourceStream.ts",
|
|
11
|
+
"src/guardSource.ts",
|
|
12
|
+
"src/range/BlobRangeReader.ts",
|
|
13
|
+
"src/range/RangeCache.ts",
|
|
14
|
+
"src/range/HttpRangeReader.ts",
|
|
15
|
+
"src/source.ts",
|
|
16
|
+
"src/controller.ts",
|
|
17
|
+
"src/exportOriginal.ts",
|
|
18
|
+
"src/session.ts"
|
|
19
|
+
],
|
|
20
|
+
"imports": [
|
|
21
|
+
{
|
|
22
|
+
"path": "chunks/chunk-AUUMY3MH.js",
|
|
23
|
+
"kind": "import-statement",
|
|
24
|
+
"external": false
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"file": "text.js",
|
|
30
|
+
"entryPoint": "src/text.ts",
|
|
31
|
+
"inputs": [
|
|
32
|
+
"src/text/TextTaskClient.ts",
|
|
33
|
+
"src/text/detectEncoding.ts",
|
|
34
|
+
"src/text/indexLines.ts",
|
|
35
|
+
"src/text/decodeText.ts",
|
|
36
|
+
"src/text/tasks.ts",
|
|
37
|
+
"src/text/TextContent.ts",
|
|
38
|
+
"src/text/findTextMatches.ts"
|
|
39
|
+
],
|
|
40
|
+
"imports": [
|
|
41
|
+
{
|
|
42
|
+
"path": "chunks/chunk-AUUMY3MH.js",
|
|
43
|
+
"kind": "import-statement",
|
|
44
|
+
"external": false
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"file": "chunks/chunk-AUUMY3MH.js",
|
|
50
|
+
"inputs": [
|
|
51
|
+
"src/errors.ts"
|
|
52
|
+
],
|
|
53
|
+
"imports": []
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"roles": {},
|
|
57
|
+
"styleCount": 0
|
|
58
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// packages/core/src/errors.ts
|
|
2
|
+
var FilumoError = class extends Error {
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = "FilumoError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function abortError() {
|
|
10
|
+
const error = new Error("\u6587\u6863\u52A0\u8F7D\u5DF2\u53D6\u6D88");
|
|
11
|
+
error.name = "AbortError";
|
|
12
|
+
return error;
|
|
13
|
+
}
|
|
14
|
+
function throwIfAborted(signal) {
|
|
15
|
+
if (signal.aborted)
|
|
16
|
+
throw signal.reason ?? abortError();
|
|
17
|
+
}
|
|
18
|
+
function notify(listeners) {
|
|
19
|
+
for (const listener of listeners) {
|
|
20
|
+
try {
|
|
21
|
+
listener();
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
FilumoError,
|
|
29
|
+
abortError,
|
|
30
|
+
throwIfAborted,
|
|
31
|
+
notify
|
|
32
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ControllerSnapshot, DocumentInput, DocumentOpenOptions, DocumentPlugin, ResourcePolicy } from './types';
|
|
2
|
+
export interface ControllerOptions {
|
|
3
|
+
plugins: readonly DocumentPlugin[];
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
pluginId?: string;
|
|
6
|
+
resourcePolicy?: ResourcePolicy;
|
|
7
|
+
}
|
|
8
|
+
/** 管理单实例加载代次,保证旧异步结果不能覆盖新文档。 */
|
|
9
|
+
export declare function createDocumentController(options: ControllerOptions): {
|
|
10
|
+
getSnapshot: () => ControllerSnapshot;
|
|
11
|
+
subscribe(listener: () => void): () => void;
|
|
12
|
+
open(input: DocumentInput, selection?: DocumentOpenOptions): Promise<void>;
|
|
13
|
+
destroy(): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
export type DocumentController = ReturnType<typeof createDocumentController>;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** 为宿主提供稳定错误码,避免通过中文提示判断错误类型。 */
|
|
2
|
+
export declare class FilumoError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code: string, message: string);
|
|
5
|
+
}
|
|
6
|
+
/** 统一被替换或取消的加载任务,返回标准取消错误。 */
|
|
7
|
+
export declare function abortError(): Error;
|
|
8
|
+
/** 在不可取消的读取完成后也检查信号,避免迟到结果继续渲染。 */
|
|
9
|
+
export declare function throwIfAborted(signal: AbortSignal): void;
|
|
10
|
+
/** 观察者的异常不能中断其他订阅者或资源清理。 */
|
|
11
|
+
export declare function notify(listeners: ReadonlySet<() => void>): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DocumentSource, ResourcePolicy } from './types';
|
|
2
|
+
/** 对不遵守取消的第三方读取器也停止等待,并移除监听,迟到结果由 Promise 消费。 */
|
|
3
|
+
export declare function waitForSource<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
4
|
+
/** 来源工厂每次取得独立租约,统一限额与取消;共享对象仅在最后一个租约释放时销毁。 */
|
|
5
|
+
export declare function guardSource(raw: DocumentSource, policy?: ResourcePolicy): DocumentSource;
|
package/dist/index.d.ts
ADDED