markstream-angular 0.0.1-alpha.2 → 0.0.1-alpha.4

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.
@@ -1,45 +1 @@
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
- });
1
+ import e from"katex";import"katex/dist/contrib/mhchem";let t=!1;globalThis.addEventListener(`message`,n=>{let r=n.data||{};if(r.type===`init`){t=!!r.debug;return}let i=r.id??``,a=r.content??``,o=r.displayMode??!0;try{t&&console.debug(`[markstream-angular:katexRenderer.worker] render start`,{id:i,displayMode:o,content:a});let n={id:i,html:e.renderToString(a,{throwOnError:!0,displayMode:o,output:`html`,strict:`ignore`}),content:a,displayMode:o};globalThis.postMessage(n)}catch(e){let t={id:i,error:String(e?.message??e),content:a,displayMode:o};globalThis.postMessage(t)}}),globalThis.addEventListener(`error`,e=>{try{globalThis.postMessage({id:`__worker_uncaught__`,error:String(e.message??e.error),content:``,displayMode:!0})}catch{}});
@@ -1,69 +1,5 @@
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
- };
1
+ import e from"mermaid";e.initialize({startOnLoad:!1,securityLevel:`loose`});function t(e,t){let n=`%%{init: {"theme": "${t===`dark`?`dark`:`default`}"}}%%\n`;return e.trimStart().startsWith(`%%{`)?e:n+e}function n(e){let t=/^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;for(let n=0;n<e.length;n+=1){let r=e[n].trim();if(!(!r||r.startsWith(`%%`))&&t.test(r))return n}return-1}async function r(n,r){let i=t(n,r),a=e;if(typeof a.parse==`function`)return await a.parse(i),!0;throw Error(`mermaid.parse not available in worker`)}async function i(e,t){let i=e.split(`
2
+ `),a=n(i);if(a===-1)return null;let o=i.slice(0,a+1);await r(o.join(`
3
+ `),t);let s=a+1,c=i.length,l=a+1,u=0;for(;s<=c&&u<12;){let e=Math.floor((s+c)/2),n=[...o,...i.slice(a+1,e)].join(`
4
+ `);u+=1;try{await r(n,t),l=e,s=e+1}catch{c=e-1}}return[...o,...i.slice(a+1,l)].join(`
5
+ `)}self.onmessage=async e=>{let t=e.data,n=e=>self.postMessage(e);try{if(t.action===`canParse`){n({id:t.id,ok:!0,result:await r(t.payload.code,t.payload.theme)});return}if(t.action===`findPrefix`){n({id:t.id,ok:!0,result:await i(t.payload.code,t.payload.theme)});return}n({id:t.id,ok:!1,error:`Unknown action`})}catch(e){n({id:t.id,ok:!1,error:e?.message??String(e)})}};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "markstream-angular",
3
3
  "type": "module",
4
- "version": "0.0.1-alpha.2",
4
+ "version": "0.0.1-alpha.4",
5
5
  "description": "Experimental Angular Markdown renderer for Markstream, built on stream-markdown AST and a stable HTML baseline renderer.",
6
6
  "author": "Simon He",
7
7
  "license": "MIT",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "dependencies": {
70
70
  "@floating-ui/dom": "^1.7.6",
71
- "stream-markdown-parser": "0.0.70"
71
+ "stream-markdown-parser": "0.0.73"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/node": "^18.19.130",