markstream-angular 0.0.1-alpha.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.md +94 -0
- package/dist/index.css +1 -0
- package/dist/index.js +7967 -0
- package/dist/types/components/AdmonitionNode/AdmonitionNode.component.d.ts +11 -0
- package/dist/types/components/BlockquoteNode/BlockquoteNode.component.d.ts +9 -0
- package/dist/types/components/CheckboxNode/CheckboxNode.component.d.ts +5 -0
- package/dist/types/components/CodeBlockNode/CodeBlockNode.component.d.ts +84 -0
- package/dist/types/components/CodeBlockNode/HtmlPreviewFrame.component.d.ts +9 -0
- package/dist/types/components/D2BlockNode/D2BlockNode.component.d.ts +44 -0
- package/dist/types/components/DefinitionListNode/DefinitionListNode.component.d.ts +11 -0
- package/dist/types/components/DynamicNodeHost/DynamicNodeHost.component.d.ts +16 -0
- package/dist/types/components/EmojiNode/EmojiNode.component.d.ts +5 -0
- package/dist/types/components/EmphasisNode/EmphasisNode.component.d.ts +8 -0
- package/dist/types/components/FallbackComponent/FallbackComponent.component.d.ts +14 -0
- package/dist/types/components/FootnoteAnchorNode/FootnoteAnchorNode.component.d.ts +7 -0
- package/dist/types/components/FootnoteNode/FootnoteNode.component.d.ts +9 -0
- package/dist/types/components/FootnoteReferenceNode/FootnoteReferenceNode.component.d.ts +6 -0
- package/dist/types/components/HardBreakNode/HardBreakNode.component.d.ts +2 -0
- package/dist/types/components/HeadingNode/HeadingNode.component.d.ts +10 -0
- package/dist/types/components/HighlightNode/HighlightNode.component.d.ts +8 -0
- package/dist/types/components/HtmlBlockNode/HtmlBlockNode.component.d.ts +10 -0
- package/dist/types/components/HtmlInlineNode/HtmlInlineNode.component.d.ts +10 -0
- package/dist/types/components/ImageNode/ImageNode.component.d.ts +8 -0
- package/dist/types/components/InfographicBlockNode/InfographicBlockNode.component.d.ts +58 -0
- package/dist/types/components/InlineCodeNode/InlineCodeNode.component.d.ts +5 -0
- package/dist/types/components/InsertNode/InsertNode.component.d.ts +8 -0
- package/dist/types/components/LinkNode/LinkNode.component.d.ts +24 -0
- package/dist/types/components/ListItemNode/ListItemNode.component.d.ts +9 -0
- package/dist/types/components/ListNode/ListNode.component.d.ts +11 -0
- package/dist/types/components/MathBlockNode/MathBlockNode.component.d.ts +17 -0
- package/dist/types/components/MathInlineNode/MathInlineNode.component.d.ts +18 -0
- package/dist/types/components/MermaidBlockNode/MermaidBlockNode.component.d.ts +67 -0
- package/dist/types/components/NestedRenderer/NestedRenderer.component.d.ts +33 -0
- package/dist/types/components/NodeOutlet/NodeOutlet.component.d.ts +15 -0
- package/dist/types/components/NodeRenderer/NodeRenderer.component.d.ts +120 -0
- package/dist/types/components/ParagraphNode/ParagraphNode.component.d.ts +20 -0
- package/dist/types/components/PreCodeNode/PreCodeNode.component.d.ts +9 -0
- package/dist/types/components/ReferenceNode/ReferenceNode.component.d.ts +5 -0
- package/dist/types/components/StrikethroughNode/StrikethroughNode.component.d.ts +8 -0
- package/dist/types/components/StrongNode/StrongNode.component.d.ts +8 -0
- package/dist/types/components/SubscriptNode/SubscriptNode.component.d.ts +8 -0
- package/dist/types/components/SuperscriptNode/SuperscriptNode.component.d.ts +8 -0
- package/dist/types/components/TableNode/TableNode.component.d.ts +14 -0
- package/dist/types/components/TextNode/TextNode.component.d.ts +6 -0
- package/dist/types/components/ThematicBreakNode/ThematicBreakNode.component.d.ts +2 -0
- package/dist/types/components/VmrContainerNode/VmrContainerNode.component.d.ts +8 -0
- package/dist/types/components/shared/node-helpers.d.ts +99 -0
- package/dist/types/components/shared/node-outlet-helpers.d.ts +7 -0
- package/dist/types/components/shared/render-window.d.ts +18 -0
- package/dist/types/components/shared/rich-block-helpers.d.ts +6 -0
- package/dist/types/components/shared/safe-attrs.directive.d.ts +11 -0
- package/dist/types/customComponents.d.ts +9 -0
- package/dist/types/enhanceRenderedHtml.d.ts +20 -0
- package/dist/types/hydrateCustomTagContent.d.ts +2 -0
- package/dist/types/i18n/useSafeI18n.d.ts +4 -0
- package/dist/types/index.d.ts +71 -0
- package/dist/types/markstream-angular.component.d.ts +2 -0
- package/dist/types/optional/d2.d.ts +6 -0
- package/dist/types/optional/infographic.d.ts +1 -0
- package/dist/types/optional/katex.d.ts +6 -0
- package/dist/types/optional/mermaid.d.ts +6 -0
- package/dist/types/optional/monaco.d.ts +1 -0
- package/dist/types/parseNestedMarkdownToNodes.d.ts +14 -0
- package/dist/types/renderMarkdownHtml.d.ts +28 -0
- package/dist/types/sanitizeHtmlContent.d.ts +1 -0
- package/dist/types/sanitizeSvg.d.ts +2 -0
- package/dist/types/tooltip/singletonTooltip.d.ts +3 -0
- package/dist/types/utils/languageIcon.d.ts +6 -0
- package/dist/types/workers/katexCdnWorker.d.ts +20 -0
- package/dist/types/workers/katexRenderer.worker.d.ts +0 -0
- package/dist/types/workers/katexWorkerClient.d.ts +35 -0
- package/dist/types/workers/mermaidCdnWorker.d.ts +15 -0
- package/dist/types/workers/mermaidParser.worker.d.ts +1 -0
- package/dist/types/workers/mermaidWorkerClient.d.ts +15 -0
- package/dist/workers/katexRenderer.worker.js +45 -0
- package/dist/workers/mermaidParser.worker.js +69 -0
- package/package.json +86 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare function setKaTeXWorker(nextWorker: Worker): void;
|
|
2
|
+
export declare function clearKaTeXWorker(): void;
|
|
3
|
+
export declare function setKaTeXWorkerDebug(enabled: boolean): void;
|
|
4
|
+
export declare function renderKaTeXInWorker(content: string, displayMode?: boolean, timeout?: number, signal?: AbortSignal): Promise<string>;
|
|
5
|
+
export declare function setKaTeXCache(content: string, displayMode: boolean, html: string): void;
|
|
6
|
+
export declare function getKaTeXWorkerLoad(): {
|
|
7
|
+
inFlight: number;
|
|
8
|
+
max: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function setKaTeXWorkerMaxConcurrency(value: number): void;
|
|
11
|
+
export declare const WORKER_BUSY_CODE = "WORKER_BUSY";
|
|
12
|
+
export declare function isKaTeXWorkerBusy(): boolean;
|
|
13
|
+
export declare function waitForKaTeXWorkerSlot(timeout?: number, signal?: AbortSignal): Promise<void>;
|
|
14
|
+
export interface BackpressureOptions {
|
|
15
|
+
timeout?: number;
|
|
16
|
+
waitTimeout?: number;
|
|
17
|
+
backoffMs?: number;
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
declare const defaultBackpressure: {
|
|
22
|
+
timeout: number;
|
|
23
|
+
waitTimeout: number;
|
|
24
|
+
backoffMs: number;
|
|
25
|
+
maxRetries: number;
|
|
26
|
+
};
|
|
27
|
+
export declare function setKaTeXBackpressureDefaults(options: Partial<typeof defaultBackpressure>): void;
|
|
28
|
+
export declare function getKaTeXBackpressureDefaults(): {
|
|
29
|
+
timeout: number;
|
|
30
|
+
waitTimeout: number;
|
|
31
|
+
backoffMs: number;
|
|
32
|
+
maxRetries: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function renderKaTeXWithBackpressure(content: string, displayMode?: boolean, options?: BackpressureOptions): Promise<string>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type MermaidCDNWorkerMode = 'classic' | 'module';
|
|
2
|
+
export interface MermaidCDNWorkerOptions {
|
|
3
|
+
mermaidUrl: string;
|
|
4
|
+
mode?: MermaidCDNWorkerMode;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
workerOptions?: WorkerOptions;
|
|
7
|
+
initializeOptions?: Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
export interface MermaidCDNWorkerHandle {
|
|
10
|
+
worker: Worker | null;
|
|
11
|
+
dispose: () => void;
|
|
12
|
+
source: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function buildMermaidCDNWorkerSource(options: MermaidCDNWorkerOptions): string;
|
|
15
|
+
export declare function createMermaidWorkerFromCDN(options: MermaidCDNWorkerOptions): MermaidCDNWorkerHandle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Theme = 'light' | 'dark';
|
|
2
|
+
export declare function setMermaidWorkerClientDebug(enabled: boolean): void;
|
|
3
|
+
export declare function setMermaidWorkerMaxConcurrency(value: number): void;
|
|
4
|
+
export declare function getMermaidWorkerLoad(): {
|
|
5
|
+
inFlight: number;
|
|
6
|
+
max: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const MERMAID_WORKER_BUSY_CODE = "WORKER_BUSY";
|
|
9
|
+
export declare const MERMAID_DISABLED_CODE = "MERMAID_DISABLED";
|
|
10
|
+
export declare function setMermaidWorker(nextWorker: Worker): void;
|
|
11
|
+
export declare function clearMermaidWorker(): void;
|
|
12
|
+
export declare function canParseOffthread(code: string, theme: Theme, timeout?: number): Promise<boolean>;
|
|
13
|
+
export declare function findPrefixOffthread(code: string, theme: Theme, timeout?: number): Promise<string>;
|
|
14
|
+
export declare function terminateWorker(): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import d from "katex";
|
|
2
|
+
import "katex/dist/contrib/mhchem";
|
|
3
|
+
let i = !1;
|
|
4
|
+
globalThis.addEventListener("message", (r) => {
|
|
5
|
+
const e = r.data || {};
|
|
6
|
+
if (e.type === "init") {
|
|
7
|
+
i = !!e.debug;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const a = e.id ?? "", t = e.content ?? "", o = e.displayMode ?? !0;
|
|
11
|
+
try {
|
|
12
|
+
i && console.debug("[markstream-angular:katexRenderer.worker] render start", { id: a, displayMode: o, content: t });
|
|
13
|
+
const s = d.renderToString(t, {
|
|
14
|
+
throwOnError: !0,
|
|
15
|
+
displayMode: o,
|
|
16
|
+
output: "html",
|
|
17
|
+
strict: "ignore"
|
|
18
|
+
}), n = {
|
|
19
|
+
id: a,
|
|
20
|
+
html: s,
|
|
21
|
+
content: t,
|
|
22
|
+
displayMode: o
|
|
23
|
+
};
|
|
24
|
+
globalThis.postMessage(n);
|
|
25
|
+
} catch (s) {
|
|
26
|
+
const n = {
|
|
27
|
+
id: a,
|
|
28
|
+
error: String(s?.message ?? s),
|
|
29
|
+
content: t,
|
|
30
|
+
displayMode: o
|
|
31
|
+
};
|
|
32
|
+
globalThis.postMessage(n);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
globalThis.addEventListener("error", (r) => {
|
|
36
|
+
try {
|
|
37
|
+
globalThis.postMessage({
|
|
38
|
+
id: "__worker_uncaught__",
|
|
39
|
+
error: String(r.message ?? r.error),
|
|
40
|
+
content: "",
|
|
41
|
+
displayMode: !0
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import f from "mermaid";
|
|
2
|
+
f.initialize({ startOnLoad: !1, securityLevel: "loose" });
|
|
3
|
+
function h(r, t) {
|
|
4
|
+
const e = `%%{init: {"theme": "${t === "dark" ? "dark" : "default"}"}}%%
|
|
5
|
+
`;
|
|
6
|
+
return r.trimStart().startsWith("%%{") ? r : e + r;
|
|
7
|
+
}
|
|
8
|
+
function g(r) {
|
|
9
|
+
const t = /^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;
|
|
10
|
+
for (let a = 0; a < r.length; a += 1) {
|
|
11
|
+
const e = r[a].trim();
|
|
12
|
+
if (!(!e || e.startsWith("%%")) && t.test(e))
|
|
13
|
+
return a;
|
|
14
|
+
}
|
|
15
|
+
return -1;
|
|
16
|
+
}
|
|
17
|
+
async function l(r, t) {
|
|
18
|
+
const a = h(r, t), e = f;
|
|
19
|
+
if (typeof e.parse == "function")
|
|
20
|
+
return await e.parse(a), !0;
|
|
21
|
+
throw new Error("mermaid.parse not available in worker");
|
|
22
|
+
}
|
|
23
|
+
async function p(r, t) {
|
|
24
|
+
const a = r.split(`
|
|
25
|
+
`), e = g(a);
|
|
26
|
+
if (e === -1)
|
|
27
|
+
return null;
|
|
28
|
+
const n = a.slice(0, e + 1);
|
|
29
|
+
await l(n.join(`
|
|
30
|
+
`), t);
|
|
31
|
+
let o = e + 1, s = a.length, c = e + 1, d = 0;
|
|
32
|
+
const m = 12;
|
|
33
|
+
for (; o <= s && d < m; ) {
|
|
34
|
+
const i = Math.floor((o + s) / 2), u = [...n, ...a.slice(e + 1, i)].join(`
|
|
35
|
+
`);
|
|
36
|
+
d += 1;
|
|
37
|
+
try {
|
|
38
|
+
await l(u, t), c = i, o = i + 1;
|
|
39
|
+
} catch {
|
|
40
|
+
s = i - 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [...n, ...a.slice(e + 1, c)].join(`
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
self.onmessage = async (r) => {
|
|
47
|
+
const t = r.data, a = (e) => self.postMessage(e);
|
|
48
|
+
try {
|
|
49
|
+
if (t.action === "canParse") {
|
|
50
|
+
a({
|
|
51
|
+
id: t.id,
|
|
52
|
+
ok: !0,
|
|
53
|
+
result: await l(t.payload.code, t.payload.theme)
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (t.action === "findPrefix") {
|
|
58
|
+
a({
|
|
59
|
+
id: t.id,
|
|
60
|
+
ok: !0,
|
|
61
|
+
result: await p(t.payload.code, t.payload.theme)
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
a({ id: t.id, ok: !1, error: "Unknown action" });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
a({ id: t.id, ok: !1, error: e?.message ?? String(e) });
|
|
68
|
+
}
|
|
69
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markstream-angular",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1-alpha.0",
|
|
5
|
+
"description": "Experimental Angular Markdown renderer for Markstream, built on stream-markdown AST and a stable HTML baseline renderer.",
|
|
6
|
+
"author": "Simon He",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/Simon-He95/markstream-vue#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Simon-He95/markstream-vue.git",
|
|
12
|
+
"directory": "packages/markstream-angular"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Simon-He95/markstream-vue/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"angular",
|
|
19
|
+
"markdown",
|
|
20
|
+
"markdown-renderer",
|
|
21
|
+
"streaming-markdown",
|
|
22
|
+
"markstream",
|
|
23
|
+
"markstream-angular"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./index.css": "./dist/index.css",
|
|
34
|
+
"./workers/katexRenderer.worker": "./dist/workers/katexRenderer.worker.js",
|
|
35
|
+
"./workers/mermaidParser.worker": "./dist/workers/mermaidParser.worker.js"
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@antv/infographic": "^0.2.3",
|
|
45
|
+
"@angular/common": ">=20",
|
|
46
|
+
"@angular/core": ">=20",
|
|
47
|
+
"@terrastruct/d2": ">=0.1.33",
|
|
48
|
+
"katex": ">=0.16.22",
|
|
49
|
+
"mermaid": ">=11",
|
|
50
|
+
"stream-monaco": ">=0.0.18"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"@antv/infographic": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@terrastruct/d2": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"katex": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"mermaid": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"stream-monaco": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@floating-ui/dom": "^1.7.6",
|
|
71
|
+
"stream-markdown-parser": "0.0.69"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@types/node": "^18.19.130",
|
|
75
|
+
"rollup": "^3.30.0",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"vite": "^7.3.1",
|
|
78
|
+
"vite-plugin-dts": "^4.5.4"
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"build": "vite build --mode npm",
|
|
82
|
+
"dev": "vite dev",
|
|
83
|
+
"preview": "vite preview",
|
|
84
|
+
"typecheck": "tsc --noEmit"
|
|
85
|
+
}
|
|
86
|
+
}
|