markstream-react 0.0.3-beta.0 → 0.0.3-beta.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.css +1 -1
- package/dist/index.js +172 -4830
- package/dist/workers/katexRenderer.worker.js +1 -45
- package/dist/workers/mermaidParser.worker.js +1 -68
- package/package.json +3 -4
|
@@ -1,45 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "katex/contrib/mhchem";
|
|
3
|
-
let n = !1;
|
|
4
|
-
globalThis.addEventListener("message", (r) => {
|
|
5
|
-
var i, l, g, u;
|
|
6
|
-
const e = r.data || {};
|
|
7
|
-
if (e.type === "init") {
|
|
8
|
-
n = !!e.debug;
|
|
9
|
-
try {
|
|
10
|
-
n && console.debug("[katexRenderer.worker] debug enabled");
|
|
11
|
-
} catch {
|
|
12
|
-
}
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const o = (i = e.id) != null ? i : "", s = (l = e.content) != null ? l : "", a = (g = e.displayMode) != null ? g : !0;
|
|
16
|
-
try {
|
|
17
|
-
n && console.debug("[katexRenderer.worker] render start", { id: o, displayMode: a, content: s });
|
|
18
|
-
const t = h.renderToString(s, {
|
|
19
|
-
throwOnError: !0,
|
|
20
|
-
displayMode: a,
|
|
21
|
-
output: "html",
|
|
22
|
-
strict: "ignore"
|
|
23
|
-
}), d = { id: o, html: t, content: s, displayMode: a };
|
|
24
|
-
try {
|
|
25
|
-
globalThis.postMessage(d), n && console.debug("[katexRenderer.worker] render success", { id: o });
|
|
26
|
-
} catch (c) {
|
|
27
|
-
console.error("[katexRenderer.worker] failed to postMessage result", c);
|
|
28
|
-
}
|
|
29
|
-
} catch (t) {
|
|
30
|
-
const d = { id: o, error: String((u = t == null ? void 0 : t.message) != null ? u : t), content: s, displayMode: a };
|
|
31
|
-
try {
|
|
32
|
-
globalThis.postMessage(d);
|
|
33
|
-
} catch (c) {
|
|
34
|
-
console.error("[katexRenderer.worker] failed to postMessage error", c);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
globalThis.addEventListener("error", (r) => {
|
|
39
|
-
var e;
|
|
40
|
-
console.error("[katexRenderer.worker] uncaught error", r.message, r.error);
|
|
41
|
-
try {
|
|
42
|
-
globalThis.postMessage({ id: "__worker_uncaught__", error: String((e = r.message) != null ? e : r.error), content: "", displayMode: !0 });
|
|
43
|
-
} catch {
|
|
44
|
-
}
|
|
45
|
-
});
|
|
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{}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(g){console.error("[katexRenderer.worker] failed to postMessage result",g)}}catch(u){const e={id:l,error:String(null!=(a=null==u?void 0:u.message)?a:u),content:i,displayMode:c};try{globalThis.postMessage(e)}catch(g){console.error("[katexRenderer.worker] failed to postMessage error",g)}}}),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{}});
|
|
@@ -1,68 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
d.initialize({ startOnLoad: !1, securityLevel: "loose" });
|
|
3
|
-
function m(r, a) {
|
|
4
|
-
const t = `%%{init: {"theme": "${a === "dark" ? "dark" : "default"}"}}%%
|
|
5
|
-
`;
|
|
6
|
-
return r.trimStart().startsWith("%%{") ? r : t + r;
|
|
7
|
-
}
|
|
8
|
-
function g(r) {
|
|
9
|
-
const a = /^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;
|
|
10
|
-
for (let e = 0; e < r.length; e++) {
|
|
11
|
-
const t = r[e].trim();
|
|
12
|
-
if (t && !t.startsWith("%%") && a.test(t))
|
|
13
|
-
return e;
|
|
14
|
-
}
|
|
15
|
-
return -1;
|
|
16
|
-
}
|
|
17
|
-
async function c(r, a) {
|
|
18
|
-
var i;
|
|
19
|
-
const e = m(r, a), t = d;
|
|
20
|
-
if (typeof t.parse == "function")
|
|
21
|
-
return await ((i = t.parse) == null ? void 0 : i.call(t, e)), !0;
|
|
22
|
-
throw new Error("mermaid.parse not available in worker");
|
|
23
|
-
}
|
|
24
|
-
async function p(r, a) {
|
|
25
|
-
const e = r.split(`
|
|
26
|
-
`), t = g(e);
|
|
27
|
-
if (t === -1)
|
|
28
|
-
return null;
|
|
29
|
-
const i = e.slice(0, t + 1);
|
|
30
|
-
await c(i.join(`
|
|
31
|
-
`), a);
|
|
32
|
-
let n = t + 1, s = e.length, l = t + 1, f = 0;
|
|
33
|
-
const u = 12;
|
|
34
|
-
for (; n <= s && f < u; ) {
|
|
35
|
-
const o = Math.floor((n + s) / 2), h = [...i, ...e.slice(t + 1, o)].join(`
|
|
36
|
-
`);
|
|
37
|
-
f++;
|
|
38
|
-
try {
|
|
39
|
-
await c(h, a), l = o, n = o + 1;
|
|
40
|
-
} catch {
|
|
41
|
-
s = o - 1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return [...i, ...e.slice(t + 1, l)].join(`
|
|
45
|
-
`);
|
|
46
|
-
}
|
|
47
|
-
self.onmessage = async (r) => {
|
|
48
|
-
var i;
|
|
49
|
-
const a = r.data, e = (n) => self.postMessage(n), t = a.id;
|
|
50
|
-
try {
|
|
51
|
-
if (a.action === "canParse") {
|
|
52
|
-
const n = await c(a.payload.code, a.payload.theme);
|
|
53
|
-
e({ id: t, ok: !0, result: n });
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (a.action === "findPrefix") {
|
|
57
|
-
const n = await p(
|
|
58
|
-
a.payload.code,
|
|
59
|
-
a.payload.theme
|
|
60
|
-
);
|
|
61
|
-
e({ id: t, ok: !0, result: n });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
e({ id: t, ok: !1, error: "Unknown action" });
|
|
65
|
-
} catch (n) {
|
|
66
|
-
e({ id: t, ok: !1, error: (i = n == null ? void 0 : n.message) != null ? i : String(n) });
|
|
67
|
-
}
|
|
68
|
-
};
|
|
1
|
+
import t from"mermaid";async function a(a,r){var n;const e=function(t,a){const r=`%%{init: {"theme": "${"dark"===a?"dark":"default"}"}}%%\n`;return t.trimStart().startsWith("%%{")?t:r+t}(a,r),i=t;if("function"==typeof i.parse)return await(null==(n=i.parse)?void 0:n.call(i,e)),!0;throw new Error("mermaid.parse not available in worker")}t.initialize({startOnLoad:!1,securityLevel:"loose"}),self.onmessage=async t=>{var r;const n=t.data,e=t=>self.postMessage(t),i=n.id;try{if("canParse"===n.action)return void e({id:i,ok:!0,result:await a(n.payload.code,n.payload.theme)});if("findPrefix"===n.action)return void e({id:i,ok:!0,result:await async function(t,r){const n=t.split("\n"),e=function(t){const a=/^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;for(let r=0;r<t.length;r++){const n=t[r].trim();if(n&&!n.startsWith("%%")&&a.test(n))return r}return-1}(n);if(-1===e)return null;const i=n.slice(0,e+1);await a(i.join("\n"),r);let o=e+1,s=n.length,l=e+1,c=0;for(;o<=s&&c<12;){const t=Math.floor((o+s)/2),d=[...i,...n.slice(e+1,t)].join("\n");c++;try{await a(d,r),l=t,o=t+1}catch{s=t-1}}return[...i,...n.slice(e+1,l)].join("\n")}(n.payload.code,n.payload.theme)});e({id:i,ok:!1,error:"Unknown action"})}catch(o){e({id:i,ok:!1,error:null!=(r=null==o?void 0:o.message)?r:String(o)})}};
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markstream-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.3-beta.
|
|
4
|
+
"version": "0.0.3-beta.2",
|
|
5
5
|
"description": "React renderer for stream-markdown based AST output used in markstream-vue.",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/index.js"
|
|
10
|
-
"require": "./dist/index.js"
|
|
9
|
+
"import": "./dist/index.js"
|
|
11
10
|
},
|
|
12
11
|
"./index.css": "./dist/index.css",
|
|
13
12
|
"./workers/katexRenderer.worker": "./dist/workers/katexRenderer.worker.js",
|
|
@@ -44,7 +43,7 @@
|
|
|
44
43
|
"dependencies": {
|
|
45
44
|
"@floating-ui/dom": "^1.7.4",
|
|
46
45
|
"clsx": "^2.1.1",
|
|
47
|
-
"stream-markdown-parser": "0.0.
|
|
46
|
+
"stream-markdown-parser": "0.0.53"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@types/react": "^18.3.27",
|