markstream-vue2 0.0.1 → 0.0.2
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/dist/index.d.ts
CHANGED
|
@@ -784,7 +784,7 @@ declare function __VLS_template$3(): {
|
|
|
784
784
|
codeBlockContent: HTMLDivElement;
|
|
785
785
|
rendererTarget: HTMLDivElement;
|
|
786
786
|
};
|
|
787
|
-
rootEl:
|
|
787
|
+
rootEl: HTMLDivElement;
|
|
788
788
|
};
|
|
789
789
|
type __VLS_TemplateResult$3 = ReturnType<typeof __VLS_template$3>;
|
|
790
790
|
declare const __VLS_component$3: vue.DefineComponent<{
|
|
@@ -1,55 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "katex/contrib/mhchem";
|
|
3
|
-
let DEBUG = false;
|
|
4
|
-
globalThis.addEventListener("message", (ev) => {
|
|
5
|
-
var _a, _b, _c, _d;
|
|
6
|
-
const data = ev.data || {};
|
|
7
|
-
if (data.type === "init") {
|
|
8
|
-
DEBUG = !!data.debug;
|
|
9
|
-
try {
|
|
10
|
-
if (DEBUG)
|
|
11
|
-
console.debug("[katexRenderer.worker] debug enabled");
|
|
12
|
-
} catch (e) {
|
|
13
|
-
}
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const id = (_a = data.id) != null ? _a : "";
|
|
17
|
-
const content = (_b = data.content) != null ? _b : "";
|
|
18
|
-
const displayMode = (_c = data.displayMode) != null ? _c : true;
|
|
19
|
-
try {
|
|
20
|
-
if (DEBUG)
|
|
21
|
-
console.debug("[katexRenderer.worker] render start", { id, displayMode, content });
|
|
22
|
-
const html = katex.renderToString(content, {
|
|
23
|
-
throwOnError: true,
|
|
24
|
-
displayMode,
|
|
25
|
-
output: "html",
|
|
26
|
-
strict: "ignore"
|
|
27
|
-
});
|
|
28
|
-
const out = { id, html, content, displayMode };
|
|
29
|
-
try {
|
|
30
|
-
;
|
|
31
|
-
globalThis.postMessage(out);
|
|
32
|
-
if (DEBUG)
|
|
33
|
-
console.debug("[katexRenderer.worker] render success", { id });
|
|
34
|
-
} catch (postErr) {
|
|
35
|
-
console.error("[katexRenderer.worker] failed to postMessage result", postErr);
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
const out = { id, error: String((_d = err == null ? void 0 : err.message) != null ? _d : err), content, displayMode };
|
|
39
|
-
try {
|
|
40
|
-
;
|
|
41
|
-
globalThis.postMessage(out);
|
|
42
|
-
} catch (postErr) {
|
|
43
|
-
console.error("[katexRenderer.worker] failed to postMessage error", postErr);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
globalThis.addEventListener("error", (ev) => {
|
|
48
|
-
var _a;
|
|
49
|
-
console.error("[katexRenderer.worker] uncaught error", ev.message, ev.error);
|
|
50
|
-
try {
|
|
51
|
-
;
|
|
52
|
-
globalThis.postMessage({ id: "__worker_uncaught__", error: String((_a = ev.message) != null ? _a : ev.error), content: "", displayMode: true });
|
|
53
|
-
} catch (e) {
|
|
54
|
-
}
|
|
55
|
-
});
|
|
1
|
+
import e from"katex";import"katex/contrib/mhchem";let r=!1;globalThis.addEventListener("message",o=>{var t,s,n,a;const d=o.data||{};if("init"===d.type){r=!!d.debug;try{r&&console.debug("[katexRenderer.worker] debug enabled")}catch(g){}return}const l=null!=(t=d.id)?t:"",i=null!=(s=d.content)?s:"",c=null==(n=d.displayMode)||n;try{r&&console.debug("[katexRenderer.worker] render start",{id:l,displayMode:c,content:i});const o={id:l,html:e.renderToString(i,{throwOnError:!0,displayMode:c,output:"html",strict:"ignore"}),content:i,displayMode:c};try{globalThis.postMessage(o),r&&console.debug("[katexRenderer.worker] render success",{id:l})}catch(u){console.error("[katexRenderer.worker] failed to postMessage result",u)}}catch(h){const e={id:l,error:String(null!=(a=null==h?void 0:h.message)?a:h),content:i,displayMode:c};try{globalThis.postMessage(e)}catch(u){console.error("[katexRenderer.worker] failed to postMessage error",u)}}}),globalThis.addEventListener("error",e=>{var r;console.error("[katexRenderer.worker] uncaught error",e.message,e.error);try{globalThis.postMessage({id:"__worker_uncaught__",error:String(null!=(r=e.message)?r:e.error),content:"",displayMode:!0})}catch(o){}});
|
|
@@ -1,117 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
var __async = (__this, __arguments, generator) => {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
var fulfilled = (value) => {
|
|
8
|
-
try {
|
|
9
|
-
step(generator.next(value));
|
|
10
|
-
} catch (e) {
|
|
11
|
-
reject(e);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var rejected = (value) => {
|
|
15
|
-
try {
|
|
16
|
-
step(generator.throw(value));
|
|
17
|
-
} catch (e) {
|
|
18
|
-
reject(e);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
22
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
import mermaid from "mermaid";
|
|
26
|
-
var require_mermaidParser_worker = __commonJS({
|
|
27
|
-
"workers/mermaidParser.worker.js"(exports) {
|
|
28
|
-
mermaid.initialize({ startOnLoad: false, securityLevel: "loose" });
|
|
29
|
-
function applyThemeTo(code, theme) {
|
|
30
|
-
const themeValue = theme === "dark" ? "dark" : "default";
|
|
31
|
-
const themeConfig = `%%{init: {"theme": "${themeValue}"}}%%
|
|
32
|
-
`;
|
|
33
|
-
const trimmed = code.trimStart();
|
|
34
|
-
if (trimmed.startsWith("%%{"))
|
|
35
|
-
return code;
|
|
36
|
-
return themeConfig + code;
|
|
37
|
-
}
|
|
38
|
-
function findHeaderIndex(lines) {
|
|
39
|
-
const headerRe = /^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;
|
|
40
|
-
for (let i = 0; i < lines.length; i++) {
|
|
41
|
-
const l = lines[i].trim();
|
|
42
|
-
if (!l)
|
|
43
|
-
continue;
|
|
44
|
-
if (l.startsWith("%%"))
|
|
45
|
-
continue;
|
|
46
|
-
if (headerRe.test(l))
|
|
47
|
-
return i;
|
|
48
|
-
}
|
|
49
|
-
return -1;
|
|
50
|
-
}
|
|
51
|
-
function canParse(code, theme) {
|
|
52
|
-
return __async(this, null, function* () {
|
|
53
|
-
var _a;
|
|
54
|
-
const themed = applyThemeTo(code, theme);
|
|
55
|
-
const anyMermaid = mermaid;
|
|
56
|
-
if (typeof anyMermaid.parse === "function") {
|
|
57
|
-
yield (_a = anyMermaid.parse) == null ? void 0 : _a.call(anyMermaid, themed);
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
throw new Error("mermaid.parse not available in worker");
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function findLastRenderablePrefix(baseCode, theme) {
|
|
64
|
-
return __async(this, null, function* () {
|
|
65
|
-
const lines = baseCode.split("\n");
|
|
66
|
-
const headerIdx = findHeaderIndex(lines);
|
|
67
|
-
if (headerIdx === -1)
|
|
68
|
-
return null;
|
|
69
|
-
const head = lines.slice(0, headerIdx + 1);
|
|
70
|
-
yield canParse(head.join("\n"), theme);
|
|
71
|
-
let low = headerIdx + 1;
|
|
72
|
-
let high = lines.length;
|
|
73
|
-
let lastGood = headerIdx + 1;
|
|
74
|
-
let tries = 0;
|
|
75
|
-
const MAX_TRIES = 12;
|
|
76
|
-
while (low <= high && tries < MAX_TRIES) {
|
|
77
|
-
const mid = Math.floor((low + high) / 2);
|
|
78
|
-
const candidate = [...head, ...lines.slice(headerIdx + 1, mid)].join("\n");
|
|
79
|
-
tries++;
|
|
80
|
-
try {
|
|
81
|
-
yield canParse(candidate, theme);
|
|
82
|
-
lastGood = mid;
|
|
83
|
-
low = mid + 1;
|
|
84
|
-
} catch (e) {
|
|
85
|
-
high = mid - 1;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return [...head, ...lines.slice(headerIdx + 1, lastGood)].join("\n");
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
self.onmessage = (ev) => __async(exports, null, function* () {
|
|
92
|
-
var _a;
|
|
93
|
-
const msg = ev.data;
|
|
94
|
-
const send = (res) => self.postMessage(res);
|
|
95
|
-
const id = msg.id;
|
|
96
|
-
try {
|
|
97
|
-
if (msg.action === "canParse") {
|
|
98
|
-
const ok = yield canParse(msg.payload.code, msg.payload.theme);
|
|
99
|
-
send({ id, ok: true, result: ok });
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (msg.action === "findPrefix") {
|
|
103
|
-
const res = yield findLastRenderablePrefix(
|
|
104
|
-
msg.payload.code,
|
|
105
|
-
msg.payload.theme
|
|
106
|
-
);
|
|
107
|
-
send({ id, ok: true, result: res });
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
send({ id, ok: false, error: "Unknown action" });
|
|
111
|
-
} catch (e) {
|
|
112
|
-
send({ id, ok: false, error: (_a = e == null ? void 0 : e.message) != null ? _a : String(e) });
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
export default require_mermaidParser_worker();
|
|
1
|
+
var t=Object.getOwnPropertyNames,r=(t,r,e)=>new Promise((n,a)=>{var o=t=>{try{l(e.next(t))}catch(r){a(r)}},i=t=>{try{l(e.throw(t))}catch(r){a(r)}},l=t=>t.done?n(t.value):Promise.resolve(t.value).then(o,i);l((e=e.apply(t,r)).next())});import e from"mermaid";var n,a,o=(n={"workers/mermaidParser.worker.js"(t){function n(t,n){return r(this,null,function*(){var r;const a=function(t,r){const e=`%%{init: {"theme": "${"dark"===r?"dark":"default"}"}}%%\n`;return t.trimStart().startsWith("%%{")?t:e+t}(t,n),o=e;if("function"==typeof o.parse)return yield null==(r=o.parse)?void 0:r.call(o,a),!0;throw new Error("mermaid.parse not available in worker")})}e.initialize({startOnLoad:!1,securityLevel:"loose"}),self.onmessage=e=>r(t,null,function*(){var t;const a=e.data,o=t=>self.postMessage(t),i=a.id;try{if("canParse"===a.action)return void o({id:i,ok:!0,result:yield n(a.payload.code,a.payload.theme)});if("findPrefix"===a.action)return void o({id:i,ok:!0,result:yield function(t,e){return r(this,null,function*(){const r=t.split("\n"),a=function(t){const r=/^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;for(let e=0;e<t.length;e++){const n=t[e].trim();if(n&&!n.startsWith("%%")&&r.test(n))return e}return-1}(r);if(-1===a)return null;const o=r.slice(0,a+1);yield n(o.join("\n"),e);let i=a+1,l=r.length,s=a+1,c=0;for(;i<=l&&c<12;){const t=Math.floor((i+l)/2),d=[...o,...r.slice(a+1,t)].join("\n");c++;try{yield n(d,e),s=t,i=t+1}catch(u){l=t-1}}return[...o,...r.slice(a+1,s)].join("\n")})}(a.payload.code,a.payload.theme)});o({id:i,ok:!1,error:"Unknown action"})}catch(l){o({id:i,ok:!1,error:null!=(t=null==l?void 0:l.message)?t:String(l)})}})}},function(){return a||(0,n[t(n)[0]])((a={exports:{}}).exports,a),a.exports});export default o();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markstream-vue2",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "Vue 2 Markdown renderer optimized for large docs: progressive Mermaid, streaming diff code blocks, and fast real-time preview.",
|
|
6
6
|
"author": "Simon He",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,11 +24,6 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "vite build -c vite.config.ts --mode npm && pnpm run build:dts && pnpm run copy:css",
|
|
29
|
-
"build:dts": "rollup -c ./scripts/rollup.dts.config.mjs && node ./scripts/clean-dts.cjs",
|
|
30
|
-
"copy:css": "node ./scripts/copy-css.mjs"
|
|
31
|
-
},
|
|
32
27
|
"peerDependencies": {
|
|
33
28
|
"@vue/composition-api": ">=1.7.2",
|
|
34
29
|
"katex": ">=0.16.22",
|
|
@@ -75,5 +70,11 @@
|
|
|
75
70
|
"vite": "^4.5.14",
|
|
76
71
|
"vite-plugin-dts": "^4.5.4",
|
|
77
72
|
"vue-tsc": "^2.2.12"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "vite build -c vite.config.ts --mode npm && pnpm run build:dts && pnpm run copy:css",
|
|
76
|
+
"build:dts": "rollup -c ./scripts/rollup.dts.config.mjs && node ./scripts/clean-dts.cjs",
|
|
77
|
+
"copy:css": "node ./scripts/copy-css.mjs",
|
|
78
|
+
"release": "bumpp && npm publish --access public"
|
|
78
79
|
}
|
|
79
|
-
}
|
|
80
|
+
}
|