@file-viewer/core 2.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/LICENSE +160 -0
- package/README.en.md +78 -0
- package/README.md +83 -0
- package/dist/assets.d.ts +62 -0
- package/dist/assets.js +260 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +1 -0
- package/dist/capabilities.d.ts +24 -0
- package/dist/capabilities.js +95 -0
- package/dist/document.d.ts +9 -0
- package/dist/document.js +86 -0
- package/dist/documentDom/anchors.d.ts +7 -0
- package/dist/documentDom/anchors.js +196 -0
- package/dist/documentDom/index.d.ts +5 -0
- package/dist/documentDom/index.js +3 -0
- package/dist/documentDom/providers.d.ts +13 -0
- package/dist/documentDom/providers.js +52 -0
- package/dist/documentDom/scroll.d.ts +12 -0
- package/dist/documentDom/scroll.js +42 -0
- package/dist/documentDom.d.ts +5 -0
- package/dist/documentDom.js +3 -0
- package/dist/documentEvents.d.ts +73 -0
- package/dist/documentEvents.js +150 -0
- package/dist/documentSearch.d.ts +50 -0
- package/dist/documentSearch.js +459 -0
- package/dist/documentZoom.d.ts +47 -0
- package/dist/documentZoom.js +184 -0
- package/dist/export.d.ts +26 -0
- package/dist/export.js +466 -0
- package/dist/formats.d.ts +305 -0
- package/dist/formats.js +207 -0
- package/dist/headless.d.ts +25 -0
- package/dist/headless.js +14 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +118 -0
- package/dist/lifecycleFacade.d.ts +46 -0
- package/dist/lifecycleFacade.js +68 -0
- package/dist/loading.d.ts +59 -0
- package/dist/loading.js +489 -0
- package/dist/operations.d.ts +287 -0
- package/dist/operations.js +485 -0
- package/dist/options.d.ts +16 -0
- package/dist/options.js +92 -0
- package/dist/presentation.d.ts +14 -0
- package/dist/presentation.js +16 -0
- package/dist/printLayout.d.ts +19 -0
- package/dist/printLayout.js +83 -0
- package/dist/registry.d.ts +2 -0
- package/dist/registry.js +63 -0
- package/dist/rendererDispatcher.d.ts +21 -0
- package/dist/rendererDispatcher.js +42 -0
- package/dist/rendererHandler.d.ts +165 -0
- package/dist/rendererHandler.js +354 -0
- package/dist/renderers/archive.d.ts +2 -0
- package/dist/renderers/archive.js +547 -0
- package/dist/renderers/archiveCache.d.ts +10 -0
- package/dist/renderers/archiveCache.js +96 -0
- package/dist/renderers/archiveFallback.d.ts +7 -0
- package/dist/renderers/archiveFallback.js +166 -0
- package/dist/renderers/archiveShared.d.ts +23 -0
- package/dist/renderers/archiveShared.js +71 -0
- package/dist/renderers/audio.d.ts +8 -0
- package/dist/renderers/audio.js +219 -0
- package/dist/renderers/cad.d.ts +2 -0
- package/dist/renderers/cad.js +445 -0
- package/dist/renderers/code.d.ts +11 -0
- package/dist/renderers/code.js +233 -0
- package/dist/renderers/data.d.ts +7 -0
- package/dist/renderers/data.js +370 -0
- package/dist/renderers/drawing.d.ts +10 -0
- package/dist/renderers/drawing.js +537 -0
- package/dist/renderers/eda.d.ts +2 -0
- package/dist/renderers/eda.js +434 -0
- package/dist/renderers/edaParser.d.ts +77 -0
- package/dist/renderers/edaParser.js +569 -0
- package/dist/renderers/email.d.ts +2 -0
- package/dist/renderers/email.js +463 -0
- package/dist/renderers/epub.d.ts +2 -0
- package/dist/renderers/epub.js +330 -0
- package/dist/renderers/geo.d.ts +2 -0
- package/dist/renderers/geo.js +284 -0
- package/dist/renderers/image.d.ts +2 -0
- package/dist/renderers/image.js +179 -0
- package/dist/renderers/index.d.ts +21 -0
- package/dist/renderers/index.js +207 -0
- package/dist/renderers/markdown.d.ts +2 -0
- package/dist/renderers/markdown.js +83 -0
- package/dist/renderers/model.d.ts +2 -0
- package/dist/renderers/model.js +566 -0
- package/dist/renderers/ofd.d.ts +2 -0
- package/dist/renderers/ofd.js +255 -0
- package/dist/renderers/openDocument.d.ts +2 -0
- package/dist/renderers/openDocument.js +122 -0
- package/dist/renderers/pdf.d.ts +3 -0
- package/dist/renderers/pdf.js +846 -0
- package/dist/renderers/pdfStyles.d.ts +1 -0
- package/dist/renderers/pdfStyles.js +1 -0
- package/dist/renderers/pptx.d.ts +2 -0
- package/dist/renderers/pptx.js +202 -0
- package/dist/renderers/spreadsheet/state.d.ts +80 -0
- package/dist/renderers/spreadsheet/state.js +96 -0
- package/dist/renderers/spreadsheet/view.d.ts +25 -0
- package/dist/renderers/spreadsheet/view.js +833 -0
- package/dist/renderers/spreadsheet/worker/index.d.ts +2 -0
- package/dist/renderers/spreadsheet/worker/index.js +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +73 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.js +623 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/color.d.ts +2 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/color.js +73 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/index.d.ts +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/index.js +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/parser.d.ts +18 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/parser.js +106 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.d.ts +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.js +11 -0
- package/dist/renderers/spreadsheet/worker/type.d.ts +57 -0
- package/dist/renderers/spreadsheet/worker/type.js +1 -0
- package/dist/renderers/spreadsheet.d.ts +3 -0
- package/dist/renderers/spreadsheet.js +929 -0
- package/dist/renderers/typst.d.ts +8 -0
- package/dist/renderers/typst.js +415 -0
- package/dist/renderers/umd/parser.d.ts +30 -0
- package/dist/renderers/umd/parser.js +408 -0
- package/dist/renderers/umd.d.ts +2 -0
- package/dist/renderers/umd.js +297 -0
- package/dist/renderers/video.d.ts +8 -0
- package/dist/renderers/video.js +108 -0
- package/dist/renderers/wordDoc.d.ts +5 -0
- package/dist/renderers/wordDoc.js +284 -0
- package/dist/renderers/wordDocx.d.ts +5 -0
- package/dist/renderers/wordDocx.js +501 -0
- package/dist/renderers/wordDocx.worker.d.ts +1 -0
- package/dist/renderers/wordDocx.worker.js +96 -0
- package/dist/source.d.ts +18 -0
- package/dist/source.js +152 -0
- package/dist/sourceLoading.d.ts +566 -0
- package/dist/sourceLoading.js +918 -0
- package/dist/state.d.ts +16 -0
- package/dist/state.js +81 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.js +1 -0
- package/dist/viewer.d.ts +8 -0
- package/dist/viewer.js +285 -0
- package/dist/viewerOperations.d.ts +88 -0
- package/dist/viewerOperations.js +242 -0
- package/dist/watermark.d.ts +15 -0
- package/dist/watermark.js +81 -0
- package/dist/worker.d.ts +34 -0
- package/dist/worker.js +101 -0
- package/package.json +109 -0
- package/vendor/ofd/dltech/jbig2/arithmetic_decoder.js +183 -0
- package/vendor/ofd/dltech/jbig2/ccitt.js +1070 -0
- package/vendor/ofd/dltech/jbig2/compatibility.js +12 -0
- package/vendor/ofd/dltech/jbig2/core_utils.js +180 -0
- package/vendor/ofd/dltech/jbig2/is_node.js +27 -0
- package/vendor/ofd/dltech/jbig2/jbig2.js +2589 -0
- package/vendor/ofd/dltech/jbig2/jbig2_stream.js +81 -0
- package/vendor/ofd/dltech/jbig2/primitives.js +387 -0
- package/vendor/ofd/dltech/jbig2/stream.js +1348 -0
- package/vendor/ofd/dltech/jbig2/util.js +972 -0
- package/vendor/ofd/dltech/ofd/ofd.d.ts +11 -0
- package/vendor/ofd/dltech/ofd/ofd.js +100 -0
- package/vendor/ofd/dltech/ofd/ofd_parser.js +395 -0
- package/vendor/ofd/dltech/ofd/ofd_render.js +473 -0
- package/vendor/ofd/dltech/ofd/ofd_util.js +350 -0
- package/vendor/ofd/dltech/ofd/pipeline.js +26 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const escapeXml = (value) => value
|
|
2
|
+
.replace(/&/g, '&')
|
|
3
|
+
.replace(/"/g, '"')
|
|
4
|
+
.replace(/</g, '<')
|
|
5
|
+
.replace(/>/g, '>');
|
|
6
|
+
const encodeSvgDataUrl = (svg) => {
|
|
7
|
+
return `url("data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}")`;
|
|
8
|
+
};
|
|
9
|
+
const clampNumber = (value, fallback, min, max) => {
|
|
10
|
+
const next = typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
11
|
+
return Math.min(max, Math.max(min, next));
|
|
12
|
+
};
|
|
13
|
+
export const normalizeFileViewerWatermark = (watermark) => {
|
|
14
|
+
if (!watermark) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (watermark === true) {
|
|
18
|
+
return {
|
|
19
|
+
enabled: true,
|
|
20
|
+
text: 'Flyfish Viewer',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (watermark.enabled === false) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (!watermark.text && !watermark.image) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
enabled: true,
|
|
31
|
+
...watermark,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export const buildFileViewerWatermarkSvg = (watermark) => {
|
|
35
|
+
const gapX = clampNumber(watermark.gapX, 260, 96, 800);
|
|
36
|
+
const gapY = clampNumber(watermark.gapY, 180, 80, 800);
|
|
37
|
+
const width = clampNumber(watermark.width, watermark.image ? 160 : 220, 32, gapX);
|
|
38
|
+
const height = clampNumber(watermark.height, watermark.image ? 72 : 72, 24, gapY);
|
|
39
|
+
const rotate = clampNumber(watermark.rotate, -24, -75, 75);
|
|
40
|
+
const opacity = clampNumber(watermark.opacity, 0.18, 0.02, 0.8);
|
|
41
|
+
const x = (gapX - width) / 2;
|
|
42
|
+
const y = (gapY - height) / 2;
|
|
43
|
+
const cx = gapX / 2;
|
|
44
|
+
const cy = gapY / 2;
|
|
45
|
+
if (watermark.image) {
|
|
46
|
+
const href = escapeXml(watermark.image);
|
|
47
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${gapX}" height="${gapY}" viewBox="0 0 ${gapX} ${gapY}"><g opacity="${opacity}" transform="rotate(${rotate} ${cx} ${cy})"><image href="${href}" x="${x}" y="${y}" width="${width}" height="${height}" preserveAspectRatio="xMidYMid meet"/></g></svg>`;
|
|
48
|
+
}
|
|
49
|
+
const text = escapeXml(watermark.text || 'Flyfish Viewer');
|
|
50
|
+
const fontSize = clampNumber(watermark.fontSize, 20, 10, 72);
|
|
51
|
+
const color = escapeXml(watermark.color || '#355070');
|
|
52
|
+
const fontFamily = escapeXml(watermark.fontFamily || "Aptos, 'Segoe UI', sans-serif");
|
|
53
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${gapX}" height="${gapY}" viewBox="0 0 ${gapX} ${gapY}"><g opacity="${opacity}" transform="rotate(${rotate} ${cx} ${cy})"><text x="${cx}" y="${cy}" text-anchor="middle" dominant-baseline="middle" fill="${color}" font-family="${fontFamily}" font-size="${fontSize}" font-weight="700">${text}</text></g></svg>`;
|
|
54
|
+
};
|
|
55
|
+
export const buildFileViewerWatermarkBackgroundImage = (watermark) => {
|
|
56
|
+
const normalized = normalizeFileViewerWatermark(watermark);
|
|
57
|
+
return normalized ? encodeSvgDataUrl(buildFileViewerWatermarkSvg(normalized)) : '';
|
|
58
|
+
};
|
|
59
|
+
export const buildFileViewerWatermarkStyle = (watermark) => {
|
|
60
|
+
const backgroundImage = buildFileViewerWatermarkBackgroundImage(watermark);
|
|
61
|
+
return backgroundImage ? { backgroundImage } : undefined;
|
|
62
|
+
};
|
|
63
|
+
export const buildFileViewerWatermarkInlineStyle = (watermark) => {
|
|
64
|
+
const backgroundImage = buildFileViewerWatermarkBackgroundImage(watermark);
|
|
65
|
+
return backgroundImage
|
|
66
|
+
? `position:absolute;inset:0;pointer-events:none;background-image:${backgroundImage};background-repeat:repeat;z-index:20;`
|
|
67
|
+
: '';
|
|
68
|
+
};
|
|
69
|
+
export const resolveFileViewerWatermarkPresentationState = (watermark) => {
|
|
70
|
+
const normalizedWatermark = normalizeFileViewerWatermark(watermark);
|
|
71
|
+
const backgroundImage = normalizedWatermark
|
|
72
|
+
? encodeSvgDataUrl(buildFileViewerWatermarkSvg(normalizedWatermark))
|
|
73
|
+
: '';
|
|
74
|
+
return {
|
|
75
|
+
normalizedWatermark,
|
|
76
|
+
watermarkStyle: backgroundImage ? { backgroundImage } : undefined,
|
|
77
|
+
watermarkInlineStyle: backgroundImage
|
|
78
|
+
? `position:absolute;inset:0;pointer-events:none;background-image:${backgroundImage};background-repeat:repeat;z-index:20;`
|
|
79
|
+
: '',
|
|
80
|
+
};
|
|
81
|
+
};
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type WorkerProvider = () => Worker;
|
|
2
|
+
export type FileViewerWorkerFactory = () => Worker | undefined;
|
|
3
|
+
export type FileViewerWorkerEventHandler = (payload: any) => void;
|
|
4
|
+
export type FileViewerWorkerMessageHook = (event: MessageEvent) => void;
|
|
5
|
+
export type FileViewerWorkerErrorHook = (event: ErrorEvent) => void;
|
|
6
|
+
export interface FileViewerWorkerContext {
|
|
7
|
+
emit(type: string, payload: any): void;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateFileViewerWorkerControllerOptions {
|
|
10
|
+
logErrors?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface FileViewerWorkerController {
|
|
13
|
+
readonly instance: Worker | undefined;
|
|
14
|
+
readonly worker: FileViewerWorkerContext;
|
|
15
|
+
emit(type: string, payload: any): void;
|
|
16
|
+
onWorkerMessage(hook: FileViewerWorkerMessageHook): () => void;
|
|
17
|
+
onWorkerError(hook: FileViewerWorkerErrorHook): () => void;
|
|
18
|
+
onWorkerEvent(type: string, hook: FileViewerWorkerEventHandler): () => void;
|
|
19
|
+
mapEvents(mappings: Array<string> | Record<string, string>): Record<string, (payload: any) => void>;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface WorkerRef {
|
|
23
|
+
name: string;
|
|
24
|
+
worker: Worker | null;
|
|
25
|
+
defaults(provider: WorkerProvider): Worker;
|
|
26
|
+
}
|
|
27
|
+
export declare class WorkerRefImpl implements WorkerRef {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
worker: Worker | null;
|
|
30
|
+
constructor(nameOrWorker: string | Worker | null, worker?: Worker | null);
|
|
31
|
+
defaults(provider: WorkerProvider): Worker;
|
|
32
|
+
}
|
|
33
|
+
export declare const refWorker: (name: string, _module?: boolean) => WorkerRef;
|
|
34
|
+
export declare const createFileViewerWorkerController: (factory: FileViewerWorkerFactory, options?: CreateFileViewerWorkerControllerOptions) => FileViewerWorkerController;
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export class WorkerRefImpl {
|
|
2
|
+
constructor(nameOrWorker, worker = null) {
|
|
3
|
+
if (typeof nameOrWorker === 'string') {
|
|
4
|
+
this.name = nameOrWorker;
|
|
5
|
+
this.worker = worker;
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
this.name = '';
|
|
9
|
+
this.worker = nameOrWorker;
|
|
10
|
+
}
|
|
11
|
+
defaults(provider) {
|
|
12
|
+
if (!this.worker) {
|
|
13
|
+
this.worker = provider();
|
|
14
|
+
}
|
|
15
|
+
return this.worker;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const refWorker = (name, _module = false) => {
|
|
19
|
+
return new WorkerRefImpl(name, null);
|
|
20
|
+
};
|
|
21
|
+
export const createFileViewerWorkerController = (factory, options = {}) => {
|
|
22
|
+
const instance = factory();
|
|
23
|
+
const eventHandlers = new Map();
|
|
24
|
+
const messageHooks = new Set();
|
|
25
|
+
const errorHooks = new Set();
|
|
26
|
+
const emit = (type, payload) => {
|
|
27
|
+
instance === null || instance === void 0 ? void 0 : instance.postMessage({
|
|
28
|
+
type,
|
|
29
|
+
payload,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const handleMessage = (event) => {
|
|
33
|
+
const { type, payload } = event.data || {};
|
|
34
|
+
const handlers = eventHandlers.get(type);
|
|
35
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.forEach(handler => handler(payload));
|
|
36
|
+
messageHooks.forEach(hook => hook(event));
|
|
37
|
+
};
|
|
38
|
+
const handleError = (event) => {
|
|
39
|
+
if (options.logErrors !== false) {
|
|
40
|
+
console.error(event);
|
|
41
|
+
}
|
|
42
|
+
errorHooks.forEach(hook => hook(event));
|
|
43
|
+
};
|
|
44
|
+
instance === null || instance === void 0 ? void 0 : instance.addEventListener('message', handleMessage);
|
|
45
|
+
instance === null || instance === void 0 ? void 0 : instance.addEventListener('error', handleError);
|
|
46
|
+
const worker = {
|
|
47
|
+
emit,
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
instance,
|
|
51
|
+
worker,
|
|
52
|
+
emit,
|
|
53
|
+
onWorkerMessage(hook) {
|
|
54
|
+
messageHooks.add(hook);
|
|
55
|
+
return () => {
|
|
56
|
+
messageHooks.delete(hook);
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
onWorkerError(hook) {
|
|
60
|
+
errorHooks.add(hook);
|
|
61
|
+
return () => {
|
|
62
|
+
errorHooks.delete(hook);
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
onWorkerEvent(type, hook) {
|
|
66
|
+
let handlers = eventHandlers.get(type);
|
|
67
|
+
if (!handlers) {
|
|
68
|
+
handlers = new Set();
|
|
69
|
+
eventHandlers.set(type, handlers);
|
|
70
|
+
}
|
|
71
|
+
handlers.add(hook);
|
|
72
|
+
return () => {
|
|
73
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.delete(hook);
|
|
74
|
+
if ((handlers === null || handlers === void 0 ? void 0 : handlers.size) === 0) {
|
|
75
|
+
eventHandlers.delete(type);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
mapEvents(mappings) {
|
|
80
|
+
if (Array.isArray(mappings)) {
|
|
81
|
+
return mappings.reduce((result, key) => {
|
|
82
|
+
result[key] = (payload) => emit(key, payload);
|
|
83
|
+
return result;
|
|
84
|
+
}, {});
|
|
85
|
+
}
|
|
86
|
+
return Object.keys(mappings).reduce((result, key) => {
|
|
87
|
+
const name = mappings[key];
|
|
88
|
+
result[name] = (payload) => emit(key, payload);
|
|
89
|
+
return result;
|
|
90
|
+
}, {});
|
|
91
|
+
},
|
|
92
|
+
destroy() {
|
|
93
|
+
instance === null || instance === void 0 ? void 0 : instance.removeEventListener('message', handleMessage);
|
|
94
|
+
instance === null || instance === void 0 ? void 0 : instance.removeEventListener('error', handleError);
|
|
95
|
+
instance === null || instance === void 0 ? void 0 : instance.terminate();
|
|
96
|
+
eventHandlers.clear();
|
|
97
|
+
messageHooks.clear();
|
|
98
|
+
errorHooks.clear();
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@file-viewer/core",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Framework-neutral TypeScript core for Flyfish File Viewer",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"file-viewer",
|
|
9
|
+
"document-preview",
|
|
10
|
+
"typescript",
|
|
11
|
+
"core"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org/"
|
|
16
|
+
},
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Wangyu",
|
|
19
|
+
"email": "wybaby168@gmail.com"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/flyfish-dev/file-viewer-core.git",
|
|
24
|
+
"directory": "packages/core"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://doc.flyfish-viewer.app/",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./assets": {
|
|
37
|
+
"types": "./dist/assets.d.ts",
|
|
38
|
+
"import": "./dist/assets.js",
|
|
39
|
+
"default": "./dist/assets.js"
|
|
40
|
+
},
|
|
41
|
+
"./headless": {
|
|
42
|
+
"types": "./dist/headless.d.ts",
|
|
43
|
+
"import": "./dist/headless.js",
|
|
44
|
+
"default": "./dist/headless.js"
|
|
45
|
+
},
|
|
46
|
+
"./browser": {
|
|
47
|
+
"types": "./dist/browser.d.ts",
|
|
48
|
+
"import": "./dist/browser.js",
|
|
49
|
+
"default": "./dist/browser.js"
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"vendor",
|
|
56
|
+
"README.md",
|
|
57
|
+
"README.en.md",
|
|
58
|
+
"LICENSE"
|
|
59
|
+
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@aiden0z/pptx-renderer": "^1.2.0",
|
|
62
|
+
"@flyfish-dev/cad-viewer": "^0.6.4",
|
|
63
|
+
"@excalidraw/excalidraw": "^0.18.1",
|
|
64
|
+
"@kenjiuno/msgreader": "^1.28.0",
|
|
65
|
+
"@myriaddreamin/typst.ts": "0.7.0",
|
|
66
|
+
"@myriaddreamin/typst-ts-renderer": "0.7.0",
|
|
67
|
+
"@myriaddreamin/typst-ts-web-compiler": "0.7.0",
|
|
68
|
+
"@tmcw/togeojson": "^7.1.2",
|
|
69
|
+
"@tonejs/midi": "^2.0.28",
|
|
70
|
+
"@xmldom/xmldom": "^0.9.10",
|
|
71
|
+
"ag-psd": "^30.1.1",
|
|
72
|
+
"avsc": "^5.7.9",
|
|
73
|
+
"cfb": "^1.2.2",
|
|
74
|
+
"docx-preview": "^0.3.7",
|
|
75
|
+
"e-virt-table": "^1.3.26",
|
|
76
|
+
"epubjs": "^0.3.93",
|
|
77
|
+
"heic2any": "^0.0.4",
|
|
78
|
+
"highlight.js": "^11.11.1",
|
|
79
|
+
"hls.js": "^1.6.16",
|
|
80
|
+
"hyparquet": "^1.26.0",
|
|
81
|
+
"jszip": "^3.10.1",
|
|
82
|
+
"libarchive.js": "^2.0.2",
|
|
83
|
+
"linkedom": "^0.18.12",
|
|
84
|
+
"marked": "^18.0.5",
|
|
85
|
+
"msdoc-viewer": "^0.2.0",
|
|
86
|
+
"ofd-xml-parser": "^0.0.6",
|
|
87
|
+
"pako": "^2.1.0",
|
|
88
|
+
"pdfjs-dist": "^6.0.227",
|
|
89
|
+
"postal-mime": "^2.7.4",
|
|
90
|
+
"roughjs": "^4.6.6",
|
|
91
|
+
"rtf.js": "^3.0.9",
|
|
92
|
+
"shpjs": "^6.2.0",
|
|
93
|
+
"sql.js": "^1.14.1",
|
|
94
|
+
"styled-exceljs": "0.21.1",
|
|
95
|
+
"three": "^0.184.0",
|
|
96
|
+
"tinycolor2": "^1.6.0"
|
|
97
|
+
},
|
|
98
|
+
"devDependencies": {
|
|
99
|
+
"@types/tinycolor2": "^1.4.6",
|
|
100
|
+
"@types/three": "^0.184.1",
|
|
101
|
+
"typescript": "^6.0.3",
|
|
102
|
+
"@types/pako": "^2.0.4"
|
|
103
|
+
},
|
|
104
|
+
"license": "Apache-2.0",
|
|
105
|
+
"scripts": {
|
|
106
|
+
"build": "node scripts/clean-dist.mjs && tsc -b tsconfig.json --force && node scripts/fix-core-esm-extensions.mjs",
|
|
107
|
+
"type-check": "tsc -b tsconfig.json"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* Copyright 2012 Mozilla Foundation
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
/* eslint no-var: error */
|
|
16
|
+
|
|
17
|
+
// Table C-2
|
|
18
|
+
const QeTable = [
|
|
19
|
+
{ qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1 },
|
|
20
|
+
{ qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0 },
|
|
21
|
+
{ qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0 },
|
|
22
|
+
{ qe: 0x0ac1, nmps: 4, nlps: 12, switchFlag: 0 },
|
|
23
|
+
{ qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0 },
|
|
24
|
+
{ qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0 },
|
|
25
|
+
{ qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1 },
|
|
26
|
+
{ qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0 },
|
|
27
|
+
{ qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0 },
|
|
28
|
+
{ qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0 },
|
|
29
|
+
{ qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0 },
|
|
30
|
+
{ qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0 },
|
|
31
|
+
{ qe: 0x1c01, nmps: 13, nlps: 20, switchFlag: 0 },
|
|
32
|
+
{ qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0 },
|
|
33
|
+
{ qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1 },
|
|
34
|
+
{ qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0 },
|
|
35
|
+
{ qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0 },
|
|
36
|
+
{ qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0 },
|
|
37
|
+
{ qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0 },
|
|
38
|
+
{ qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0 },
|
|
39
|
+
{ qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0 },
|
|
40
|
+
{ qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0 },
|
|
41
|
+
{ qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0 },
|
|
42
|
+
{ qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0 },
|
|
43
|
+
{ qe: 0x1c01, nmps: 25, nlps: 22, switchFlag: 0 },
|
|
44
|
+
{ qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0 },
|
|
45
|
+
{ qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0 },
|
|
46
|
+
{ qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0 },
|
|
47
|
+
{ qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0 },
|
|
48
|
+
{ qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0 },
|
|
49
|
+
{ qe: 0x0ac1, nmps: 31, nlps: 28, switchFlag: 0 },
|
|
50
|
+
{ qe: 0x09c1, nmps: 32, nlps: 29, switchFlag: 0 },
|
|
51
|
+
{ qe: 0x08a1, nmps: 33, nlps: 30, switchFlag: 0 },
|
|
52
|
+
{ qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0 },
|
|
53
|
+
{ qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0 },
|
|
54
|
+
{ qe: 0x02a1, nmps: 36, nlps: 33, switchFlag: 0 },
|
|
55
|
+
{ qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0 },
|
|
56
|
+
{ qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0 },
|
|
57
|
+
{ qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0 },
|
|
58
|
+
{ qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0 },
|
|
59
|
+
{ qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0 },
|
|
60
|
+
{ qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0 },
|
|
61
|
+
{ qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0 },
|
|
62
|
+
{ qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0 },
|
|
63
|
+
{ qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0 },
|
|
64
|
+
{ qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0 },
|
|
65
|
+
{ qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0 },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* This class implements the QM Coder decoding as defined in
|
|
70
|
+
* JPEG 2000 Part I Final Committee Draft Version 1.0
|
|
71
|
+
* Annex C.3 Arithmetic decoding procedure
|
|
72
|
+
* available at http://www.jpeg.org/public/fcd15444-1.pdf
|
|
73
|
+
*
|
|
74
|
+
* The arithmetic decoder is used in conjunction with context models to decode
|
|
75
|
+
* JPEG2000 and JBIG2 streams.
|
|
76
|
+
*/
|
|
77
|
+
class ArithmeticDecoder {
|
|
78
|
+
// C.3.5 Initialisation of the decoder (INITDEC)
|
|
79
|
+
constructor(data, start, end) {
|
|
80
|
+
this.data = data;
|
|
81
|
+
this.bp = start;
|
|
82
|
+
this.dataEnd = end;
|
|
83
|
+
|
|
84
|
+
this.chigh = data[start];
|
|
85
|
+
this.clow = 0;
|
|
86
|
+
|
|
87
|
+
this.byteIn();
|
|
88
|
+
|
|
89
|
+
this.chigh = ((this.chigh << 7) & 0xffff) | ((this.clow >> 9) & 0x7f);
|
|
90
|
+
this.clow = (this.clow << 7) & 0xffff;
|
|
91
|
+
this.ct -= 7;
|
|
92
|
+
this.a = 0x8000;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// C.3.4 Compressed data input (BYTEIN)
|
|
96
|
+
byteIn() {
|
|
97
|
+
const data = this.data;
|
|
98
|
+
let bp = this.bp;
|
|
99
|
+
|
|
100
|
+
if (data[bp] === 0xff) {
|
|
101
|
+
if (data[bp + 1] > 0x8f) {
|
|
102
|
+
this.clow += 0xff00;
|
|
103
|
+
this.ct = 8;
|
|
104
|
+
} else {
|
|
105
|
+
bp++;
|
|
106
|
+
this.clow += data[bp] << 9;
|
|
107
|
+
this.ct = 7;
|
|
108
|
+
this.bp = bp;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
bp++;
|
|
112
|
+
this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xff00;
|
|
113
|
+
this.ct = 8;
|
|
114
|
+
this.bp = bp;
|
|
115
|
+
}
|
|
116
|
+
if (this.clow > 0xffff) {
|
|
117
|
+
this.chigh += this.clow >> 16;
|
|
118
|
+
this.clow &= 0xffff;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// C.3.2 Decoding a decision (DECODE)
|
|
123
|
+
readBit(contexts, pos) {
|
|
124
|
+
// Contexts are packed into 1 byte:
|
|
125
|
+
// highest 7 bits carry cx.index, lowest bit carries cx.mps
|
|
126
|
+
let cx_index = contexts[pos] >> 1,
|
|
127
|
+
cx_mps = contexts[pos] & 1;
|
|
128
|
+
const qeTableIcx = QeTable[cx_index];
|
|
129
|
+
const qeIcx = qeTableIcx.qe;
|
|
130
|
+
let d;
|
|
131
|
+
let a = this.a - qeIcx;
|
|
132
|
+
|
|
133
|
+
if (this.chigh < qeIcx) {
|
|
134
|
+
// exchangeLps
|
|
135
|
+
if (a < qeIcx) {
|
|
136
|
+
a = qeIcx;
|
|
137
|
+
d = cx_mps;
|
|
138
|
+
cx_index = qeTableIcx.nmps;
|
|
139
|
+
} else {
|
|
140
|
+
a = qeIcx;
|
|
141
|
+
d = 1 ^ cx_mps;
|
|
142
|
+
if (qeTableIcx.switchFlag === 1) {
|
|
143
|
+
cx_mps = d;
|
|
144
|
+
}
|
|
145
|
+
cx_index = qeTableIcx.nlps;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
this.chigh -= qeIcx;
|
|
149
|
+
if ((a & 0x8000) !== 0) {
|
|
150
|
+
this.a = a;
|
|
151
|
+
return cx_mps;
|
|
152
|
+
}
|
|
153
|
+
// exchangeMps
|
|
154
|
+
if (a < qeIcx) {
|
|
155
|
+
d = 1 ^ cx_mps;
|
|
156
|
+
if (qeTableIcx.switchFlag === 1) {
|
|
157
|
+
cx_mps = d;
|
|
158
|
+
}
|
|
159
|
+
cx_index = qeTableIcx.nlps;
|
|
160
|
+
} else {
|
|
161
|
+
d = cx_mps;
|
|
162
|
+
cx_index = qeTableIcx.nmps;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// C.3.3 renormD;
|
|
166
|
+
do {
|
|
167
|
+
if (this.ct === 0) {
|
|
168
|
+
this.byteIn();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
a <<= 1;
|
|
172
|
+
this.chigh = ((this.chigh << 1) & 0xffff) | ((this.clow >> 15) & 1);
|
|
173
|
+
this.clow = (this.clow << 1) & 0xffff;
|
|
174
|
+
this.ct--;
|
|
175
|
+
} while ((a & 0x8000) === 0);
|
|
176
|
+
this.a = a;
|
|
177
|
+
|
|
178
|
+
contexts[pos] = (cx_index << 1) | cx_mps;
|
|
179
|
+
return d;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export { ArithmeticDecoder };
|