@file-viewer/renderer-text 3.1.1 → 3.2.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 +3 -50
- package/README.md +3 -50
- package/bin/copy-xml-profile-assets.mjs +59 -0
- package/dist/code.d.ts +0 -7
- package/dist/code.js +6 -138
- package/dist/html.js +2 -4
- package/dist/index.js +30 -3
- package/dist/largeText.js +39 -24
- package/dist/lrc.d.ts +2 -0
- package/dist/lrc.js +185 -0
- package/dist/lrcParser.d.ts +23 -0
- package/dist/lrcParser.js +83 -0
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +95 -31
- package/dist/markdownAnchors.d.ts +1 -0
- package/dist/markdownAnchors.js +66 -0
- package/dist/optionalCapabilities.d.ts +0 -4
- package/dist/optionalCapabilities.js +0 -4
- package/dist/patch.js +11 -4
- package/dist/prettyPrint.d.ts +0 -7
- package/dist/prettyPrint.js +0 -9
- package/dist/sanitizeHtml.d.ts +0 -1
- package/dist/sanitizeHtml.js +0 -1
- package/dist/syntaxGrammars/data.d.ts +10 -0
- package/dist/syntaxGrammars/data.js +8 -0
- package/dist/syntaxGrammars/documents.d.ts +5 -0
- package/dist/syntaxGrammars/documents.js +3 -0
- package/dist/syntaxGrammars/managed.d.ts +7 -0
- package/dist/syntaxGrammars/managed.js +5 -0
- package/dist/syntaxGrammars/native.d.ts +10 -0
- package/dist/syntaxGrammars/native.js +8 -0
- package/dist/syntaxGrammars/php.d.ts +5 -0
- package/dist/syntaxGrammars/php.js +3 -0
- package/dist/syntaxGrammars/scripting.d.ts +9 -0
- package/dist/syntaxGrammars/scripting.js +7 -0
- package/dist/syntaxGrammars/tooling.d.ts +8 -0
- package/dist/syntaxGrammars/tooling.js +6 -0
- package/dist/syntaxGrammars/web.d.ts +8 -0
- package/dist/syntaxGrammars/web.js +6 -0
- package/dist/syntaxHighlight.d.ts +5 -0
- package/dist/syntaxHighlight.js +167 -0
- package/dist/xml-profiles.d.ts +3 -0
- package/dist/xml-profiles.js +4 -0
- package/dist/xml.d.ts +10 -0
- package/dist/xml.js +169 -0
- package/dist/xmlEngines.d.ts +9 -0
- package/dist/xmlEngines.js +157 -0
- package/dist/xmlProfiles.d.ts +7 -0
- package/dist/xmlProfiles.js +145 -0
- package/dist/xmlRegistration.d.ts +8 -0
- package/dist/xmlRegistration.js +13 -0
- package/dist/xmlSafety.d.ts +18 -0
- package/dist/xmlSafety.js +143 -0
- package/dist/xmlWasmMemory.d.ts +1 -0
- package/dist/xmlWasmMemory.js +71 -0
- package/file-viewer.capability.json +1 -1
- package/licenses/xml-profiles/NOTICE.md +31 -0
- package/licenses/xml-profiles/libxml2-xsd-Copyright.txt +23 -0
- package/licenses/xml-profiles/libxml2-xslt-Copyright.txt +24 -0
- package/licenses/xml-profiles/libxslt-Copyright.txt +53 -0
- package/licenses/xml-profiles/xmllint-wasm-COPYING.txt +21 -0
- package/licenses/xml-profiles/xslt-polyfill-LICENSE.txt +28 -0
- package/licenses/xml-profiles/zlib-LICENSE.txt +22 -0
- package/package.json +104 -23
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
let mermaidLoader = null;
|
|
2
2
|
let diffToHtml = null;
|
|
3
3
|
let pakoLoader = null;
|
|
4
|
-
/**
|
|
5
|
-
* Enables embedded Mermaid blocks without making Mermaid part of the base text
|
|
6
|
-
* renderer dependency closure. Capability packs call this once at startup.
|
|
7
|
-
*/
|
|
8
4
|
export const registerFileViewerMermaidLoader = (loader) => {
|
|
9
5
|
mermaidLoader = loader;
|
|
10
6
|
};
|
package/dist/patch.js
CHANGED
|
@@ -11,9 +11,16 @@ const patchStyle = `
|
|
|
11
11
|
.patch-body .d2h-file-header{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--patch-border);background:#f8fafc;color:var(--patch-muted);font-weight:800}
|
|
12
12
|
.patch-body .d2h-file-name-wrapper{display:flex;min-width:0;align-items:center;gap:8px}
|
|
13
13
|
.patch-body .d2h-file-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
14
|
+
.patch-body .d2h-files-diff{display:flex}
|
|
15
|
+
.patch-body .d2h-file-side-diff{flex:1 1 0;min-width:0;overflow-x:auto}
|
|
14
16
|
.patch-body .d2h-diff-table{width:100%;border-collapse:collapse;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,'Liberation Mono',monospace;font-size:1em;line-height:1.58}
|
|
15
|
-
.patch-body .d2h-
|
|
16
|
-
.patch-body .d2h-code-side-
|
|
17
|
+
.patch-body .d2h-diff-table td{padding:0;vertical-align:top}
|
|
18
|
+
.patch-body td.d2h-code-side-linenumber,.patch-body td.d2h-code-linenumber{box-sizing:border-box;width:4.5em;min-width:4.5em;padding:0 8px;border-right:1px solid var(--patch-border);color:var(--patch-muted);text-align:right;white-space:nowrap;user-select:none}
|
|
19
|
+
/* Ignore template whitespace; only source spans preserve indentation. Long lines scroll without changing matched row heights. */
|
|
20
|
+
.patch-body .d2h-code-side-line,.patch-body .d2h-code-line{display:flex;min-height:1.58em;padding:0 10px;white-space:nowrap;word-break:normal;overflow-wrap:normal}
|
|
21
|
+
.patch-body .d2h-code-line-prefix{flex:0 0 1ch;white-space:pre;user-select:none}
|
|
22
|
+
.patch-body .d2h-code-line-ctn{display:block;flex:0 0 auto;white-space:pre}
|
|
23
|
+
.patch-body .d2h-emptyplaceholder{background:var(--patch-bg)}
|
|
17
24
|
.patch-body .d2h-ins{background:var(--patch-add)}
|
|
18
25
|
.patch-body .d2h-del{background:var(--patch-del)}
|
|
19
26
|
.patch-body .d2h-info{background:var(--patch-info);color:var(--patch-muted)}
|
|
@@ -54,9 +61,9 @@ const countFiles = (text) => {
|
|
|
54
61
|
return ((_a = text.match(/^---\s+/gm)) === null || _a === void 0 ? void 0 : _a.length) || 1;
|
|
55
62
|
};
|
|
56
63
|
export default async function renderPatch(buffer, target, type = 'patch', context) {
|
|
57
|
-
var _a, _b;
|
|
64
|
+
var _a, _b, _c, _d;
|
|
58
65
|
const documentRef = target.ownerDocument || document;
|
|
59
|
-
const text = decodeFileViewerTextBuffer(buffer, (_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.encoding).text;
|
|
66
|
+
const text = decodeFileViewerTextBuffer(buffer, (_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.encoding, (_d = (_c = context === null || context === void 0 ? void 0 : context.options) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.fallbackEncoding).text;
|
|
60
67
|
let zoom = 1;
|
|
61
68
|
const zoomEmitter = createZoomChangeEmitter();
|
|
62
69
|
const root = createElement(documentRef, 'div', 'patch-viewer');
|
package/dist/prettyPrint.d.ts
CHANGED
|
@@ -24,12 +24,5 @@ interface PrettierLanguageDefinition {
|
|
|
24
24
|
export type FileViewerPrettierRuntimeLoader = (definition: PrettierLanguageDefinition, source: string) => Promise<PrettierRuntime>;
|
|
25
25
|
export declare const resolveFileViewerPrettyPrintMaxBytes: (options?: FileViewerTextOptions) => number;
|
|
26
26
|
export declare const supportsFileViewerPrettyPrint: (extension: string) => boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Formats a decoded display representation without mutating the source buffer.
|
|
29
|
-
*
|
|
30
|
-
* Parser support and byte limits are resolved before the Prettier runtime or
|
|
31
|
-
* any parser plugin is imported. Failures intentionally return the original
|
|
32
|
-
* source so malformed or unsupported uploads remain previewable.
|
|
33
|
-
*/
|
|
34
27
|
export declare const formatFileViewerTextForDisplay: (source: string, extension: string, options?: FileViewerTextOptions, signal?: AbortSignal, runtimeLoader?: FileViewerPrettierRuntimeLoader) => Promise<FileViewerPrettyPrintResult>;
|
|
35
28
|
export {};
|
package/dist/prettyPrint.js
CHANGED
|
@@ -57,8 +57,6 @@ const hasWhitespaceSensitiveXml = (source) => {
|
|
|
57
57
|
}
|
|
58
58
|
const Parser = globalThis.DOMParser;
|
|
59
59
|
if (typeof Parser !== 'function') {
|
|
60
|
-
// The text renderer itself is browser-facing, but fail closed when this
|
|
61
|
-
// helper is evaluated in a non-DOM runtime.
|
|
62
60
|
return true;
|
|
63
61
|
}
|
|
64
62
|
try {
|
|
@@ -132,13 +130,6 @@ export const resolveFileViewerPrettyPrintMaxBytes = (options) => {
|
|
|
132
130
|
export const supportsFileViewerPrettyPrint = (extension) => {
|
|
133
131
|
return Boolean(prettierLanguages[extension.trim().toLowerCase()]);
|
|
134
132
|
};
|
|
135
|
-
/**
|
|
136
|
-
* Formats a decoded display representation without mutating the source buffer.
|
|
137
|
-
*
|
|
138
|
-
* Parser support and byte limits are resolved before the Prettier runtime or
|
|
139
|
-
* any parser plugin is imported. Failures intentionally return the original
|
|
140
|
-
* source so malformed or unsupported uploads remain previewable.
|
|
141
|
-
*/
|
|
142
133
|
export const formatFileViewerTextForDisplay = async (source, extension, options, signal, runtimeLoader = loadPrettierRuntime) => {
|
|
143
134
|
const maxBytes = resolveFileViewerPrettyPrintMaxBytes(options);
|
|
144
135
|
const sourceByteLength = utf8ByteLength(source);
|
package/dist/sanitizeHtml.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type FileViewerRichHtmlSanitizerOptions = {
|
|
2
|
-
/** Preserve inert SVG markup such as diff icons. Raw Markdown keeps this disabled. */
|
|
3
2
|
allowSvg?: boolean;
|
|
4
3
|
};
|
|
5
4
|
export declare const sanitizeFileViewerRichHtml: (documentRef: Document, html: string, options?: FileViewerRichHtmlSanitizerOptions) => DocumentFragment;
|
package/dist/sanitizeHtml.js
CHANGED
|
@@ -2,7 +2,6 @@ import createDOMPurify from 'dompurify';
|
|
|
2
2
|
import { sanitizeFileViewerSvgResources } from '@file-viewer/core';
|
|
3
3
|
const safeUrl = (value) => {
|
|
4
4
|
var _a, _b;
|
|
5
|
-
// eslint-disable-next-line no-control-regex -- remove URL controls before scheme validation
|
|
6
5
|
const compact = value.trim().replace(/[\u0000-\u0020\u007f-\u009f]/g, '');
|
|
7
6
|
const scheme = (_b = (_a = compact.match(/^([a-z][a-z0-9+.-]*):/i)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
8
7
|
return !scheme || ['http', 'https', 'mailto', 'tel'].includes(scheme);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
json: import("highlight.js").LanguageFn;
|
|
3
|
+
yaml: import("highlight.js").LanguageFn;
|
|
4
|
+
xml: import("highlight.js").LanguageFn;
|
|
5
|
+
http: import("highlight.js").LanguageFn;
|
|
6
|
+
protobuf: import("highlight.js").LanguageFn;
|
|
7
|
+
graphql: import("highlight.js").LanguageFn;
|
|
8
|
+
sql: import("highlight.js").LanguageFn;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import json from 'highlight.js/lib/languages/json';
|
|
2
|
+
import yaml from 'highlight.js/lib/languages/yaml';
|
|
3
|
+
import xml from 'highlight.js/lib/languages/xml';
|
|
4
|
+
import http from 'highlight.js/lib/languages/http';
|
|
5
|
+
import protobuf from 'highlight.js/lib/languages/protobuf';
|
|
6
|
+
import graphql from 'highlight.js/lib/languages/graphql';
|
|
7
|
+
import sql from 'highlight.js/lib/languages/sql';
|
|
8
|
+
export default { json, yaml, xml, http, protobuf, graphql, sql };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import java from 'highlight.js/lib/languages/java';
|
|
2
|
+
import kotlin from 'highlight.js/lib/languages/kotlin';
|
|
3
|
+
import csharp from 'highlight.js/lib/languages/csharp';
|
|
4
|
+
import vbnet from 'highlight.js/lib/languages/vbnet';
|
|
5
|
+
export default { java, kotlin, csharp, vbnet };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
c: import("highlight.js").LanguageFn;
|
|
3
|
+
cpp: import("highlight.js").LanguageFn;
|
|
4
|
+
objectivec: import("highlight.js").LanguageFn;
|
|
5
|
+
rust: import("highlight.js").LanguageFn;
|
|
6
|
+
swift: import("highlight.js").LanguageFn;
|
|
7
|
+
go: import("highlight.js").LanguageFn;
|
|
8
|
+
wasm: import("highlight.js").LanguageFn;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import c from 'highlight.js/lib/languages/c';
|
|
2
|
+
import cpp from 'highlight.js/lib/languages/cpp';
|
|
3
|
+
import go from 'highlight.js/lib/languages/go';
|
|
4
|
+
import objectivec from 'highlight.js/lib/languages/objectivec';
|
|
5
|
+
import rust from 'highlight.js/lib/languages/rust';
|
|
6
|
+
import swift from 'highlight.js/lib/languages/swift';
|
|
7
|
+
import wasm from 'highlight.js/lib/languages/wasm';
|
|
8
|
+
export default { c, cpp, objectivec, rust, swift, go, wasm };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
python: import("highlight.js").LanguageFn;
|
|
3
|
+
'python-repl': import("highlight.js").LanguageFn;
|
|
4
|
+
ruby: import("highlight.js").LanguageFn;
|
|
5
|
+
perl: import("highlight.js").LanguageFn;
|
|
6
|
+
lua: import("highlight.js").LanguageFn;
|
|
7
|
+
r: import("highlight.js").LanguageFn;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import python from 'highlight.js/lib/languages/python';
|
|
2
|
+
import pythonRepl from 'highlight.js/lib/languages/python-repl';
|
|
3
|
+
import ruby from 'highlight.js/lib/languages/ruby';
|
|
4
|
+
import perl from 'highlight.js/lib/languages/perl';
|
|
5
|
+
import lua from 'highlight.js/lib/languages/lua';
|
|
6
|
+
import r from 'highlight.js/lib/languages/r';
|
|
7
|
+
export default { python, 'python-repl': pythonRepl, ruby, perl, lua, r };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
bash: import("highlight.js").LanguageFn;
|
|
3
|
+
shell: import("highlight.js").LanguageFn;
|
|
4
|
+
makefile: import("highlight.js").LanguageFn;
|
|
5
|
+
ini: import("highlight.js").LanguageFn;
|
|
6
|
+
diff: import("highlight.js").LanguageFn;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import bash from 'highlight.js/lib/languages/bash';
|
|
2
|
+
import shell from 'highlight.js/lib/languages/shell';
|
|
3
|
+
import makefile from 'highlight.js/lib/languages/makefile';
|
|
4
|
+
import ini from 'highlight.js/lib/languages/ini';
|
|
5
|
+
import diff from 'highlight.js/lib/languages/diff';
|
|
6
|
+
export default { bash, shell, makefile, ini, diff };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
javascript: import("highlight.js").LanguageFn;
|
|
3
|
+
typescript: import("highlight.js").LanguageFn;
|
|
4
|
+
css: import("highlight.js").LanguageFn;
|
|
5
|
+
less: import("highlight.js").LanguageFn;
|
|
6
|
+
scss: import("highlight.js").LanguageFn;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import javascript from 'highlight.js/lib/languages/javascript';
|
|
2
|
+
import typescript from 'highlight.js/lib/languages/typescript';
|
|
3
|
+
import css from 'highlight.js/lib/languages/css';
|
|
4
|
+
import less from 'highlight.js/lib/languages/less';
|
|
5
|
+
import scss from 'highlight.js/lib/languages/scss';
|
|
6
|
+
export default { javascript, typescript, css, less, scss };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HLJSApi } from 'highlight.js';
|
|
2
|
+
export declare const resolveLanguage: (type: string) => string;
|
|
3
|
+
export declare const escapeHtml: (value: string) => string;
|
|
4
|
+
export declare const loadHighlighter: () => Promise<HLJSApi>;
|
|
5
|
+
export declare const registerLanguageOnce: (hljs: HLJSApi, name: string) => Promise<boolean>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const languageMap = {
|
|
2
|
+
xhtml: 'xml',
|
|
3
|
+
rss: 'xml',
|
|
4
|
+
atom: 'xml',
|
|
5
|
+
xjb: 'xml',
|
|
6
|
+
xsd: 'xml',
|
|
7
|
+
xsl: 'xml',
|
|
8
|
+
plist: 'xml',
|
|
9
|
+
wsf: 'xml',
|
|
10
|
+
svg: 'xml',
|
|
11
|
+
zsh: 'bash',
|
|
12
|
+
'c++': 'cpp',
|
|
13
|
+
'h++': 'cpp',
|
|
14
|
+
hh: 'cpp',
|
|
15
|
+
hxx: 'cpp',
|
|
16
|
+
cxx: 'cpp',
|
|
17
|
+
'c#': 'csharp',
|
|
18
|
+
mkdown: 'markdown',
|
|
19
|
+
mkd: 'markdown',
|
|
20
|
+
gemspec: 'ruby',
|
|
21
|
+
podspec: 'ruby',
|
|
22
|
+
thor: 'ruby',
|
|
23
|
+
irb: 'ruby',
|
|
24
|
+
golang: 'go',
|
|
25
|
+
jsp: 'java',
|
|
26
|
+
kts: 'kotlin',
|
|
27
|
+
ktm: 'kotlin',
|
|
28
|
+
ktx: 'kotlin',
|
|
29
|
+
pluto: 'lua',
|
|
30
|
+
mk: 'makefile',
|
|
31
|
+
mak: 'makefile',
|
|
32
|
+
make: 'makefile',
|
|
33
|
+
pl: 'perl',
|
|
34
|
+
pm: 'perl',
|
|
35
|
+
mm: 'objectivec',
|
|
36
|
+
objc: 'objectivec',
|
|
37
|
+
'obj-c': 'objectivec',
|
|
38
|
+
'obj-c++': 'objectivec',
|
|
39
|
+
'objective-c++': 'objectivec',
|
|
40
|
+
text: 'plaintext',
|
|
41
|
+
gyp: 'python',
|
|
42
|
+
ipython: 'python',
|
|
43
|
+
pycon: 'python-repl',
|
|
44
|
+
console: 'shell',
|
|
45
|
+
shellsession: 'shell',
|
|
46
|
+
mts: 'typescript',
|
|
47
|
+
cts: 'typescript',
|
|
48
|
+
vb: 'vbnet',
|
|
49
|
+
bash: 'bash',
|
|
50
|
+
c: 'c',
|
|
51
|
+
cc: 'cpp',
|
|
52
|
+
cjs: 'javascript',
|
|
53
|
+
cpp: 'cpp',
|
|
54
|
+
cs: 'csharp',
|
|
55
|
+
css: 'css',
|
|
56
|
+
diff: 'diff',
|
|
57
|
+
patch: 'diff',
|
|
58
|
+
bundle: 'plaintext',
|
|
59
|
+
bdl: 'plaintext',
|
|
60
|
+
gv: 'plaintext',
|
|
61
|
+
go: 'go',
|
|
62
|
+
graphql: 'graphql',
|
|
63
|
+
gql: 'graphql',
|
|
64
|
+
h: 'c',
|
|
65
|
+
hcl: 'plaintext',
|
|
66
|
+
hpp: 'cpp',
|
|
67
|
+
html: 'xml',
|
|
68
|
+
htm: 'xml',
|
|
69
|
+
http: 'http',
|
|
70
|
+
ini: 'ini',
|
|
71
|
+
ipynb: 'json',
|
|
72
|
+
java: 'java',
|
|
73
|
+
js: 'javascript',
|
|
74
|
+
json: 'json',
|
|
75
|
+
json5: 'json',
|
|
76
|
+
jsonc: 'json',
|
|
77
|
+
jsx: 'javascript',
|
|
78
|
+
kt: 'kotlin',
|
|
79
|
+
log: 'plaintext',
|
|
80
|
+
md: 'markdown',
|
|
81
|
+
markdown: 'markdown',
|
|
82
|
+
mjs: 'javascript',
|
|
83
|
+
php: 'php',
|
|
84
|
+
proto: 'protobuf',
|
|
85
|
+
py: 'python',
|
|
86
|
+
rb: 'ruby',
|
|
87
|
+
react: 'javascript',
|
|
88
|
+
rs: 'rust',
|
|
89
|
+
sh: 'bash',
|
|
90
|
+
sql: 'sql',
|
|
91
|
+
swift: 'swift',
|
|
92
|
+
tex: 'latex',
|
|
93
|
+
toml: 'ini',
|
|
94
|
+
ts: 'typescript',
|
|
95
|
+
tsx: 'typescript',
|
|
96
|
+
txt: 'plaintext',
|
|
97
|
+
vue: 'xml',
|
|
98
|
+
xml: 'xml',
|
|
99
|
+
yaml: 'yaml',
|
|
100
|
+
yml: 'yaml'
|
|
101
|
+
};
|
|
102
|
+
const grammarFamilies = [
|
|
103
|
+
{
|
|
104
|
+
names: ['c', 'cpp', 'objectivec', 'rust', 'swift', 'go', 'wasm'],
|
|
105
|
+
load: () => import('./syntaxGrammars/native.js')
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
names: ['java', 'kotlin', 'csharp', 'vbnet'],
|
|
109
|
+
load: () => import('./syntaxGrammars/managed.js')
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
names: ['javascript', 'typescript', 'css', 'less', 'scss'],
|
|
113
|
+
load: () => import('./syntaxGrammars/web.js')
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
names: ['python', 'python-repl', 'ruby', 'perl', 'lua', 'r'],
|
|
117
|
+
load: () => import('./syntaxGrammars/scripting.js')
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
names: ['bash', 'shell', 'makefile', 'ini', 'diff'],
|
|
121
|
+
load: () => import('./syntaxGrammars/tooling.js')
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
names: ['json', 'yaml', 'xml', 'http', 'protobuf', 'graphql', 'sql'],
|
|
125
|
+
load: () => import('./syntaxGrammars/data.js')
|
|
126
|
+
},
|
|
127
|
+
{ names: ['php', 'php-template'], load: () => import('./syntaxGrammars/php.js') },
|
|
128
|
+
{ names: ['markdown', 'latex'], load: () => import('./syntaxGrammars/documents.js') }
|
|
129
|
+
];
|
|
130
|
+
const languageLoaders = Object.fromEntries(grammarFamilies.flatMap(({ names, load }) => names.map((name) => [name, async () => ({ default: (await load()).default[name] })])));
|
|
131
|
+
let highlighterPromise = null;
|
|
132
|
+
const registeredLanguages = new Set();
|
|
133
|
+
export const resolveLanguage = (type) => {
|
|
134
|
+
const normalized = type.trim().toLowerCase();
|
|
135
|
+
return languageMap[normalized] || (languageLoaders[normalized] ? normalized : 'plaintext');
|
|
136
|
+
};
|
|
137
|
+
export const escapeHtml = (value) => {
|
|
138
|
+
return value.replace(/[&<>"']/g, (char) => {
|
|
139
|
+
const entities = {
|
|
140
|
+
'&': '&',
|
|
141
|
+
'<': '<',
|
|
142
|
+
'>': '>',
|
|
143
|
+
'"': '"',
|
|
144
|
+
"'": '''
|
|
145
|
+
};
|
|
146
|
+
return entities[char];
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
export const loadHighlighter = async () => {
|
|
150
|
+
if (!highlighterPromise) {
|
|
151
|
+
highlighterPromise = import('highlight.js/lib/core').then((module) => module.default);
|
|
152
|
+
}
|
|
153
|
+
return highlighterPromise;
|
|
154
|
+
};
|
|
155
|
+
export const registerLanguageOnce = async (hljs, name) => {
|
|
156
|
+
if (registeredLanguages.has(name)) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
const loader = languageLoaders[name];
|
|
160
|
+
if (!loader) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const { default: language } = await loader();
|
|
164
|
+
hljs.registerLanguage(name, language);
|
|
165
|
+
registeredLanguages.add(name);
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { FileViewerXmlProfile, FileViewerXmlManifest, FileViewerXmlOptions, FileViewerXmlDiagnostic, FileViewerXmlDiagnosticCode } from '@file-viewer/core';
|
|
2
|
+
export type { FileViewerXmlRenderedInstance } from './xml.js';
|
|
3
|
+
export declare function enableFileViewerXmlProfiles(): () => void;
|
package/dist/xml.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FileRenderContext, type FileViewerRenderedInstance, type FileViewerXmlDiagnostic } from '@file-viewer/core';
|
|
2
|
+
export type FileViewerXmlRenderedInstance = FileViewerRenderedInstance & {
|
|
3
|
+
xml: {
|
|
4
|
+
readonly diagnostics: readonly FileViewerXmlDiagnostic[];
|
|
5
|
+
readonly profileId: string | undefined;
|
|
6
|
+
readonly view: 'source' | 'rendered';
|
|
7
|
+
setView(view: 'source' | 'rendered'): void;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export default function renderXml(buffer: ArrayBuffer, target: HTMLDivElement, context?: FileRenderContext): Promise<FileViewerXmlRenderedInstance>;
|
package/dist/xml.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { decodeFileViewerTextBuffer, disposeFileViewerRendered } from '@file-viewer/core';
|
|
2
|
+
import renderCode from './code.js';
|
|
3
|
+
import { createHtmlPreviewDocument } from './html.js';
|
|
4
|
+
import { applyXmlProfiles } from './xmlProfiles.js';
|
|
5
|
+
import { checkXmlAbort, XmlProfileError } from './xmlSafety.js';
|
|
6
|
+
export default async function renderXml(buffer, target, context) {
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
8
|
+
const options = (_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.xml) !== null && _b !== void 0 ? _b : {};
|
|
9
|
+
const doc = target.ownerDocument;
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const signal = controller.signal;
|
|
12
|
+
const diagnostics = [];
|
|
13
|
+
const root = doc.createElement('div');
|
|
14
|
+
root.className = 'xml-profile-viewer';
|
|
15
|
+
root.dataset.xmlView = 'source';
|
|
16
|
+
const style = doc.createElement('style');
|
|
17
|
+
style.textContent = `
|
|
18
|
+
.xml-profile-viewer{height:100%;min-height:0;display:grid;grid-template-rows:auto minmax(0,1fr) auto;grid-template-columns:minmax(0,1fr)}
|
|
19
|
+
.xml-profile-controls{grid-row:1;display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:6px 10px;background:var(--file-viewer-panel,#f8fafc);color:var(--file-viewer-text,#172033);border-bottom:1px solid #dbe2e8}
|
|
20
|
+
.xml-profile-controls button{border:1px solid #94a3b8;border-radius:6px;min-height:36px;padding:4px 10px;background:transparent;color:inherit;cursor:pointer}
|
|
21
|
+
.xml-profile-controls button[aria-pressed="true"]{background:#0f766e;color:white;border-color:#0f766e}
|
|
22
|
+
.xml-profile-source,.xml-profile-rendered{grid-row:2;grid-column:1;min-height:0;height:100%;width:100%;border:0}
|
|
23
|
+
.xml-profile-source{position:relative;z-index:1;overflow:auto;background:var(--file-viewer-panel,#fff)}.xml-profile-rendered{background:white}
|
|
24
|
+
.xml-profile-diagnostics{grid-row:3;font-size:12px;max-height:140px;overflow:auto;padding:4px 10px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
25
|
+
.xml-profile-viewer [hidden]{display:none!important}
|
|
26
|
+
@media(max-width:600px){.xml-profile-controls button{min-height:44px}}
|
|
27
|
+
`;
|
|
28
|
+
const controls = doc.createElement('div');
|
|
29
|
+
controls.className = 'xml-profile-controls';
|
|
30
|
+
controls.hidden = true;
|
|
31
|
+
const sourceButton = doc.createElement('button');
|
|
32
|
+
sourceButton.type = 'button';
|
|
33
|
+
sourceButton.dataset.xmlView = 'source';
|
|
34
|
+
sourceButton.textContent = (_d = (_c = options.labels) === null || _c === void 0 ? void 0 : _c.viewSource) !== null && _d !== void 0 ? _d : 'View Source';
|
|
35
|
+
const renderedButton = doc.createElement('button');
|
|
36
|
+
renderedButton.type = 'button';
|
|
37
|
+
renderedButton.dataset.xmlView = 'rendered';
|
|
38
|
+
renderedButton.textContent = (_f = (_e = options.labels) === null || _e === void 0 ? void 0 : _e.viewRendered) !== null && _f !== void 0 ? _f : 'View Rendered';
|
|
39
|
+
controls.append(renderedButton, sourceButton);
|
|
40
|
+
const sourceTarget = doc.createElement('div');
|
|
41
|
+
sourceTarget.className = 'xml-profile-source';
|
|
42
|
+
const details = doc.createElement('details');
|
|
43
|
+
details.className = 'xml-profile-diagnostics';
|
|
44
|
+
details.hidden = true;
|
|
45
|
+
const summary = doc.createElement('summary');
|
|
46
|
+
summary.textContent = (_h = (_g = options.labels) === null || _g === void 0 ? void 0 : _g.diagnostics) !== null && _h !== void 0 ? _h : 'XML profile diagnostics';
|
|
47
|
+
const diagnosticText = doc.createElement('div');
|
|
48
|
+
details.append(summary, diagnosticText);
|
|
49
|
+
root.append(controls, sourceTarget, details);
|
|
50
|
+
target.replaceChildren(style, root);
|
|
51
|
+
let disposed = false;
|
|
52
|
+
let sourceInstance;
|
|
53
|
+
let frame;
|
|
54
|
+
let profileId;
|
|
55
|
+
let view = 'source';
|
|
56
|
+
const setView = (next) => {
|
|
57
|
+
if (disposed || !frame || !profileId)
|
|
58
|
+
return;
|
|
59
|
+
view = next;
|
|
60
|
+
root.dataset.xmlView = next;
|
|
61
|
+
frame.inert = next !== 'rendered';
|
|
62
|
+
frame.setAttribute('aria-hidden', String(next !== 'rendered'));
|
|
63
|
+
frame.style.pointerEvents = next === 'rendered' ? '' : 'none';
|
|
64
|
+
sourceTarget.hidden = next !== 'source';
|
|
65
|
+
sourceButton.setAttribute('aria-pressed', String(next === 'source'));
|
|
66
|
+
renderedButton.setAttribute('aria-pressed', String(next === 'rendered'));
|
|
67
|
+
};
|
|
68
|
+
const showSource = () => setView('source');
|
|
69
|
+
const showRendered = () => setView('rendered');
|
|
70
|
+
sourceButton.addEventListener('click', showSource);
|
|
71
|
+
renderedButton.addEventListener('click', showRendered);
|
|
72
|
+
const unmount = () => {
|
|
73
|
+
var _a;
|
|
74
|
+
if (disposed)
|
|
75
|
+
return;
|
|
76
|
+
disposed = true;
|
|
77
|
+
controller.abort(new XmlProfileError('cancelled', 'XML profile processing was cancelled.'));
|
|
78
|
+
(_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.removeEventListener('abort', unmount);
|
|
79
|
+
sourceButton.removeEventListener('click', showSource);
|
|
80
|
+
renderedButton.removeEventListener('click', showRendered);
|
|
81
|
+
void disposeFileViewerRendered(sourceInstance);
|
|
82
|
+
sourceInstance = undefined;
|
|
83
|
+
frame === null || frame === void 0 ? void 0 : frame.removeAttribute('srcdoc');
|
|
84
|
+
frame === null || frame === void 0 ? void 0 : frame.remove();
|
|
85
|
+
frame = undefined;
|
|
86
|
+
root.remove();
|
|
87
|
+
root.replaceChildren();
|
|
88
|
+
style.remove();
|
|
89
|
+
};
|
|
90
|
+
(_j = context === null || context === void 0 ? void 0 : context.signal) === null || _j === void 0 ? void 0 : _j.addEventListener('abort', unmount, { once: true });
|
|
91
|
+
if ((_k = context === null || context === void 0 ? void 0 : context.signal) === null || _k === void 0 ? void 0 : _k.aborted)
|
|
92
|
+
unmount();
|
|
93
|
+
const instance = {
|
|
94
|
+
$el: target, unmount,
|
|
95
|
+
xml: {
|
|
96
|
+
get diagnostics() { return diagnostics.map(item => ({ ...item })); },
|
|
97
|
+
get profileId() { return profileId; },
|
|
98
|
+
get view() { return view; },
|
|
99
|
+
setView
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const emit = (diagnostic) => {
|
|
103
|
+
var _a, _b, _c;
|
|
104
|
+
if (disposed)
|
|
105
|
+
return;
|
|
106
|
+
const safe = { ...diagnostic, message: diagnostic.message.slice(0, 4096) };
|
|
107
|
+
diagnostics.push(safe);
|
|
108
|
+
diagnosticText.textContent = diagnostics.map(item => `${item.code}${item.profileId ? ` (${item.profileId})` : ''}: ${item.message}`).join('\n');
|
|
109
|
+
details.hidden = false;
|
|
110
|
+
try {
|
|
111
|
+
(_a = options.onDiagnostic) === null || _a === void 0 ? void 0 : _a.call(options, { ...safe });
|
|
112
|
+
}
|
|
113
|
+
catch { }
|
|
114
|
+
try {
|
|
115
|
+
(_c = (_b = context === null || context === void 0 ? void 0 : context.options) === null || _b === void 0 ? void 0 : _b.onDiagnostic) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
116
|
+
code: `xml-profile-${safe.code}`,
|
|
117
|
+
level: ['profile-selected', 'root-mismatch', 'no-match'].includes(safe.code) ? 'info' : 'warning',
|
|
118
|
+
message: safe.message, detail: { profileId: safe.profileId }
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch { }
|
|
122
|
+
};
|
|
123
|
+
let timeout;
|
|
124
|
+
try {
|
|
125
|
+
checkXmlAbort(signal);
|
|
126
|
+
sourceInstance = await renderCode(buffer, sourceTarget, 'xml', {
|
|
127
|
+
...context, signal,
|
|
128
|
+
options: { ...context === null || context === void 0 ? void 0 : context.options, text: { ...(_l = context === null || context === void 0 ? void 0 : context.options) === null || _l === void 0 ? void 0 : _l.text, prettyPrint: false } }
|
|
129
|
+
});
|
|
130
|
+
if (disposed) {
|
|
131
|
+
void disposeFileViewerRendered(sourceInstance);
|
|
132
|
+
return instance;
|
|
133
|
+
}
|
|
134
|
+
const milliseconds = (_m = options.timeoutMs) !== null && _m !== void 0 ? _m : 15000;
|
|
135
|
+
if (!Number.isFinite(milliseconds) || milliseconds < 1)
|
|
136
|
+
throw new XmlProfileError('invalid-manifest', 'XML timeout must be a positive number.');
|
|
137
|
+
timeout = setTimeout(() => controller.abort(new XmlProfileError('timeout', 'XML profile processing timed out.')), Math.min(milliseconds, 60000));
|
|
138
|
+
const source = decodeFileViewerTextBuffer(buffer, (_p = (_o = context === null || context === void 0 ? void 0 : context.options) === null || _o === void 0 ? void 0 : _o.text) === null || _p === void 0 ? void 0 : _p.encoding, (_r = (_q = context === null || context === void 0 ? void 0 : context.options) === null || _q === void 0 ? void 0 : _q.text) === null || _r === void 0 ? void 0 : _r.fallbackEncoding).text;
|
|
139
|
+
const result = await applyXmlProfiles(source, buffer.byteLength, options, doc, signal, emit);
|
|
140
|
+
checkXmlAbort(signal);
|
|
141
|
+
if (result && !disposed) {
|
|
142
|
+
const html = createHtmlPreviewDocument(doc, result.html);
|
|
143
|
+
frame = doc.createElement('iframe');
|
|
144
|
+
frame.className = 'xml-profile-rendered';
|
|
145
|
+
frame.title = (_t = (_s = options.labels) === null || _s === void 0 ? void 0 : _s.viewRendered) !== null && _t !== void 0 ? _t : 'Rendered XML';
|
|
146
|
+
frame.setAttribute('sandbox', '');
|
|
147
|
+
frame.referrerPolicy = 'no-referrer';
|
|
148
|
+
frame.srcdoc = html;
|
|
149
|
+
root.insertBefore(frame, sourceTarget);
|
|
150
|
+
profileId = result.profileId;
|
|
151
|
+
root.dataset.xmlProfile = profileId;
|
|
152
|
+
controls.hidden = false;
|
|
153
|
+
setView((_u = options.initialView) !== null && _u !== void 0 ? _u : 'rendered');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (!disposed) {
|
|
158
|
+
const failure = signal.aborted && signal.reason instanceof XmlProfileError ? signal.reason : error;
|
|
159
|
+
emit(failure instanceof XmlProfileError
|
|
160
|
+
? { code: failure.code, message: failure.message }
|
|
161
|
+
: { code: 'resource-error', message: failure instanceof Error ? failure.message : 'XML profiles could not be loaded.' });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
if (timeout !== undefined)
|
|
166
|
+
clearTimeout(timeout);
|
|
167
|
+
}
|
|
168
|
+
return instance;
|
|
169
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface XmlEngineResult {
|
|
2
|
+
valid?: boolean;
|
|
3
|
+
html?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function validateXmlWithWasm(source: string, wasm: Uint8Array, xml: string, schema: string, signal: AbortSignal): Promise<XmlEngineResult>;
|
|
8
|
+
export declare function transformXmlWithWasm(source: string, xml: string, stylesheet: string, maxOutputBytes: number, signal: AbortSignal): Promise<XmlEngineResult>;
|
|
9
|
+
export {};
|