@floegence/floe-webapp-core 0.52.12 → 0.53.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.
@@ -1,16 +1,17 @@
1
1
  import { createComponent as Y } from "solid-js/web";
2
- import { createMemo as p, createEffect as Z, on as $, createSignal as b, useContext as ee, createContext as te, batch as F } from "solid-js";
3
- import { createStore as oe, reconcile as T, produce as M } from "solid-js/store";
2
+ import { secureRandomUUID as Z } from "../../utils/secureRandom.js";
3
+ import { createMemo as p, createEffect as $, on as ee, createSignal as b, useContext as te, createContext as oe, batch as F } from "solid-js";
4
+ import { createStore as se, reconcile as T, produce as M } from "solid-js/store";
4
5
  import { deferNonBlocking as k } from "../../utils/defer.js";
5
- import { DEFAULT_VIRTUAL_LIST_CONFIG as se } from "./types.js";
6
- const z = te();
7
- function Ce() {
8
- const n = ee(z);
6
+ import { DEFAULT_VIRTUAL_LIST_CONFIG as ne } from "./types.js";
7
+ const z = oe();
8
+ function Se() {
9
+ const n = te(z);
9
10
  if (!n)
10
11
  throw new Error("useChatContext must be used within a ChatProvider");
11
12
  return n;
12
13
  }
13
- const xe = (n) => {
14
+ const Ie = (n) => {
14
15
  const C = p(() => ({
15
16
  placeholder: "Type a message...",
16
17
  allowAttachments: !0,
@@ -19,9 +20,9 @@ const xe = (n) => {
19
20
  // 10MB
20
21
  ...n.config
21
22
  })), u = p(() => ({
22
- ...se,
23
+ ...ne,
23
24
  ...n.config?.virtualList
24
- })), [a, l] = oe(n.initialMessages || []), B = /* @__PURE__ */ new Map(), R = p(() => {
25
+ })), [a, l] = se(n.initialMessages || []), R = /* @__PURE__ */ new Map(), B = p(() => {
25
26
  const e = /* @__PURE__ */ new Map();
26
27
  for (let t = 0; t < a.length; t += 1) {
27
28
  const o = a[t]?.id;
@@ -29,19 +30,19 @@ const xe = (n) => {
29
30
  }
30
31
  return e;
31
32
  }), x = (e) => {
32
- const t = R().get(e);
33
+ const t = B().get(e);
33
34
  if (t !== void 0) return t;
34
35
  const o = a.findIndex((s) => s.id === e);
35
36
  return o >= 0 ? o : void 0;
36
37
  };
37
- Z($(() => n.initialMessages, (e) => {
38
+ $(ee(() => n.initialMessages, (e) => {
38
39
  e && e.length > 0 && l(T(e));
39
40
  }, {
40
41
  defer: !0
41
42
  }));
42
43
  const [A, H] = b(!1), [P, D] = b(!0), [L, S] = b(null), [O, I] = b(0);
43
44
  let j = 0;
44
- const g = /* @__PURE__ */ new Set(), f = [], h = /* @__PURE__ */ new Map(), q = (e) => {
45
+ const g = /* @__PURE__ */ new Set(), f = [], m = /* @__PURE__ */ new Map(), q = (e) => {
45
46
  if (!g.delete(e)) return;
46
47
  const t = f.indexOf(e);
47
48
  t >= 0 && f.splice(t, 1), I(g.size);
@@ -68,9 +69,9 @@ const xe = (n) => {
68
69
  const t = x(e);
69
70
  t !== void 0 && (l(M((o) => {
70
71
  o.splice(t, 1);
71
- })), h.delete(e));
72
+ })), m.delete(e));
72
73
  }, G = () => {
73
- l(T([])), h.clear();
74
+ l(T([])), m.clear();
74
75
  }, Q = (e) => {
75
76
  l(T(e));
76
77
  }, i = (e, t) => {
@@ -101,7 +102,7 @@ const xe = (n) => {
101
102
  }
102
103
  case "block-start": {
103
104
  i(e.messageId, (t) => {
104
- t.blocks.push(ne(e.blockType));
105
+ t.blocks.push(re(e.blockType));
105
106
  });
106
107
  break;
107
108
  }
@@ -135,7 +136,7 @@ const xe = (n) => {
135
136
  }
136
137
  }, X = {
137
138
  messages: () => a,
138
- coldMessages: B,
139
+ coldMessages: R,
139
140
  isLoadingHistory: A,
140
141
  hasMoreHistory: P,
141
142
  streamingMessageId: L,
@@ -145,9 +146,9 @@ const xe = (n) => {
145
146
  virtualListConfig: u,
146
147
  sendMessage: async (e, t = []) => {
147
148
  const o = {
148
- id: crypto.randomUUID(),
149
+ id: Z(),
149
150
  role: "user",
150
- blocks: re(e, t),
151
+ blocks: ae(e, t),
151
152
  status: "sending",
152
153
  timestamp: Date.now()
153
154
  };
@@ -164,9 +165,9 @@ const xe = (n) => {
164
165
  }
165
166
  const s = n.callbacks?.onSendMessage;
166
167
  if (!s) return;
167
- const d = N(), r = e, m = [...t];
168
+ const d = N(), r = e, h = [...t];
168
169
  k(() => {
169
- Promise.resolve().then(() => s(r, m, y)).catch((c) => {
170
+ Promise.resolve().then(() => s(r, h, y)).catch((c) => {
170
171
  console.error("Failed to send message:", c);
171
172
  }).finally(() => {
172
173
  q(d);
@@ -238,17 +239,17 @@ const xe = (n) => {
238
239
  });
239
240
  });
240
241
  },
241
- heightCache: h,
242
+ heightCache: m,
242
243
  setMessageHeight: (e, t) => {
243
- h.set(e, t);
244
+ m.set(e, t);
244
245
  },
245
- getMessageHeight: (e) => h.get(e) || u().defaultItemHeight,
246
+ getMessageHeight: (e) => m.get(e) || u().defaultItemHeight,
246
247
  toggleChecklistItem: (e, t, o) => {
247
248
  let s = null;
248
249
  i(e, (r) => {
249
- const m = r.blocks[t];
250
- if (m && m.type === "checklist") {
251
- for (const c of m.items)
250
+ const h = r.blocks[t];
251
+ if (h && h.type === "checklist") {
252
+ for (const c of h.items)
252
253
  if (c.id === o) {
253
254
  s = !c.checked, c.checked = s;
254
255
  break;
@@ -272,7 +273,7 @@ const xe = (n) => {
272
273
  }
273
274
  });
274
275
  };
275
- function ne(n) {
276
+ function re(n) {
276
277
  switch (n) {
277
278
  case "text":
278
279
  return {
@@ -349,7 +350,7 @@ function ne(n) {
349
350
  };
350
351
  }
351
352
  }
352
- function re(n, C) {
353
+ function ae(n, C) {
353
354
  const u = [];
354
355
  for (const a of C)
355
356
  a.type === "image" ? u.push({
@@ -369,6 +370,6 @@ function re(n, C) {
369
370
  }), u;
370
371
  }
371
372
  export {
372
- xe as ChatProvider,
373
- Ce as useChatContext
373
+ Ie as ChatProvider,
374
+ Se as useChatContext
374
375
  };
@@ -1,23 +1,24 @@
1
+ import { secureRandomUUID as F } from "../../../utils/secureRandom.js";
1
2
  import { createSignal as v } from "solid-js";
2
- function z(s = {}) {
3
+ function j(s = {}) {
3
4
  const {
4
5
  maxAttachments: l = 10,
5
6
  maxSize: f = 10 * 1024 * 1024,
6
7
  // 10MB
7
8
  acceptedTypes: o,
8
9
  onUpload: m
9
- } = s, [p, i] = v([]), [D, u] = v(!1), A = (t) => t.size > f ? `File "${t.name}" is too large. Maximum size is ${F(f)}.` : o && !o.split(",").map((e) => e.trim()).some((e) => e.startsWith(".") ? t.name.toLowerCase().endsWith(e.toLowerCase()) : e.endsWith("/*") ? t.type.startsWith(e.slice(0, -1)) : t.type === e) ? `File "${t.name}" is not an accepted file type.` : null, c = async (t) => {
10
- const n = [], r = p().length;
11
- r + t.length > l && (n.push(`Maximum ${l} attachments allowed.`), t = t.slice(0, l - r));
10
+ } = s, [p, i] = v([]), [D, u] = v(!1), A = (t) => t.size > f ? `File "${t.name}" is too large. Maximum size is ${L(f)}.` : o && !o.split(",").map((e) => e.trim()).some((e) => e.startsWith(".") ? t.name.toLowerCase().endsWith(e.toLowerCase()) : e.endsWith("/*") ? t.type.startsWith(e.slice(0, -1)) : t.type === e) ? `File "${t.name}" is not an accepted file type.` : null, c = async (t) => {
11
+ const r = [], n = p().length;
12
+ n + t.length > l && (r.push(`Maximum ${l} attachments allowed.`), t = t.slice(0, l - n));
12
13
  const e = [];
13
14
  for (const a of t) {
14
15
  const h = A(a);
15
16
  if (h) {
16
- n.push(h);
17
+ r.push(h);
17
18
  continue;
18
19
  }
19
20
  const g = a.type.startsWith("image/"), P = {
20
- id: crypto.randomUUID(),
21
+ id: F(),
21
22
  file: a,
22
23
  type: g ? "image" : "file",
23
24
  preview: g ? URL.createObjectURL(a) : void 0,
@@ -29,21 +30,21 @@ function z(s = {}) {
29
30
  if (e.length > 0 && (i((a) => [...a, ...e]), m))
30
31
  for (const a of e)
31
32
  w(a);
32
- return n;
33
+ return r;
33
34
  }, w = async (t) => {
34
35
  d(t.id, { status: "uploading", uploadProgress: 0 });
35
36
  try {
36
- const n = await m(t.file);
37
- d(t.id, { status: "uploaded", uploadProgress: 100, url: n });
38
- } catch (n) {
37
+ const r = await m(t.file);
38
+ d(t.id, { status: "uploaded", uploadProgress: 100, url: r });
39
+ } catch (r) {
39
40
  d(t.id, {
40
41
  status: "error",
41
- error: n instanceof Error ? n.message : "Upload failed"
42
+ error: r instanceof Error ? r.message : "Upload failed"
42
43
  });
43
44
  }
44
- }, d = (t, n) => {
45
+ }, d = (t, r) => {
45
46
  i(
46
- (r) => r.map((e) => e.id === t ? { ...e, ...n } : e)
47
+ (n) => n.map((e) => e.id === t ? { ...e, ...r } : e)
47
48
  );
48
49
  };
49
50
  return {
@@ -51,22 +52,22 @@ function z(s = {}) {
51
52
  isDragging: D,
52
53
  addFiles: c,
53
54
  removeAttachment: (t) => {
54
- i((n) => {
55
- const r = n.find((e) => e.id === t);
56
- return r?.preview && URL.revokeObjectURL(r.preview), n.filter((e) => e.id !== t);
55
+ i((r) => {
56
+ const n = r.find((e) => e.id === t);
57
+ return n?.preview && URL.revokeObjectURL(n.preview), r.filter((e) => e.id !== t);
57
58
  });
58
59
  },
59
60
  clearAttachments: () => {
60
61
  const t = p();
61
- for (const n of t)
62
- n.preview && URL.revokeObjectURL(n.preview);
62
+ for (const r of t)
63
+ r.preview && URL.revokeObjectURL(r.preview);
63
64
  i([]);
64
65
  },
65
66
  openFilePicker: () => {
66
67
  const t = document.createElement("input");
67
68
  t.type = "file", t.multiple = !0, o && (t.accept = o), t.onchange = async () => {
68
- const n = Array.from(t.files || []);
69
- await c(n);
69
+ const r = Array.from(t.files || []);
70
+ await c(r);
70
71
  }, t.click();
71
72
  },
72
73
  handleDragEnter: (t) => {
@@ -80,18 +81,18 @@ function z(s = {}) {
80
81
  },
81
82
  handleDrop: async (t) => {
82
83
  t.preventDefault(), t.stopPropagation(), u(!1);
83
- const n = Array.from(t.dataTransfer?.files || []);
84
- return c(n);
84
+ const r = Array.from(t.dataTransfer?.files || []);
85
+ return c(r);
85
86
  },
86
87
  handlePaste: async (t) => {
87
- const r = Array.from(t.clipboardData?.items || []).filter((e) => e.kind === "file").map((e) => e.getAsFile()).filter((e) => e !== null);
88
- return r.length > 0 ? (t.preventDefault(), c(r)) : [];
88
+ const n = Array.from(t.clipboardData?.items || []).filter((e) => e.kind === "file").map((e) => e.getAsFile()).filter((e) => e !== null);
89
+ return n.length > 0 ? (t.preventDefault(), c(n)) : [];
89
90
  }
90
91
  };
91
92
  }
92
- function F(s) {
93
+ function L(s) {
93
94
  return s < 1024 ? `${s} B` : s < 1024 * 1024 ? `${(s / 1024).toFixed(1)} KB` : `${(s / (1024 * 1024)).toFixed(1)} MB`;
94
95
  }
95
96
  export {
96
- z as useAttachments
97
+ j as useAttachments
97
98
  };
@@ -1,7 +1,8 @@
1
- import { computeCodeDiffModel as p } from "../diff/diffModel.js";
1
+ import { secureRandomUUID as g } from "../../../utils/secureRandom.js";
2
+ import { computeCodeDiffModel as y } from "../diff/diffModel.js";
2
3
  let n = null, a = !1, u = null;
3
- const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), g = 50;
4
- function W() {
4
+ const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), w = 50;
5
+ function R() {
5
6
  if (typeof Worker > "u") return null;
6
7
  try {
7
8
  return new Worker(new URL(
@@ -13,7 +14,7 @@ function W() {
13
14
  return null;
14
15
  }
15
16
  }
16
- function M(t) {
17
+ function S(t) {
17
18
  return n = t, a = !1, u = new Promise((r) => {
18
19
  n.onmessage = (e) => {
19
20
  if ("type" in e.data && e.data.type === "ready") {
@@ -27,27 +28,27 @@ function M(t) {
27
28
  };
28
29
  }), u;
29
30
  }
30
- function R() {
31
+ function U() {
31
32
  return !!n;
32
33
  }
33
- async function w() {
34
+ async function D() {
34
35
  return n ? a ? !0 : u ? (await u, !0) : !1 : !1;
35
36
  }
36
- function S(t, r) {
37
+ function P(t, r) {
37
38
  const e = d(t, r), o = i.get(e);
38
39
  if (o) return o;
39
- const c = p(t, r);
40
+ const c = y(t, r);
40
41
  return m(e, c), c;
41
42
  }
42
- async function U(t, r) {
43
+ async function $(t, r) {
43
44
  const e = d(t, r), o = i.get(e);
44
45
  if (o) return o;
45
- if (!await w() || !n) {
46
- const f = p(t, r);
46
+ if (!await D() || !n) {
47
+ const f = y(t, r);
47
48
  return m(e, f), f;
48
49
  }
49
50
  return new Promise((f, s) => {
50
- const h = crypto.randomUUID();
51
+ const h = g();
51
52
  l.set(h, {
52
53
  resolve: (k) => {
53
54
  m(e, k), f(k);
@@ -56,31 +57,31 @@ async function U(t, r) {
56
57
  }), n.postMessage({ id: h, oldCode: t, newCode: r });
57
58
  });
58
59
  }
59
- function P() {
60
+ function v() {
60
61
  n && (n.terminate(), n = null), a = !1, u = null, l.clear(), i.clear();
61
62
  }
62
63
  function d(t, r) {
63
- return `${t.length}:${r.length}:${y(t)}:${y(r)}`;
64
+ return `${t.length}:${r.length}:${p(t)}:${p(r)}`;
64
65
  }
65
66
  function m(t, r) {
66
- if (i.size >= g) {
67
+ if (i.size >= w) {
67
68
  const e = i.keys().next().value;
68
69
  e && i.delete(e);
69
70
  }
70
71
  i.set(t, r);
71
72
  }
72
- function y(t) {
73
+ function p(t) {
73
74
  let r = 2166136261;
74
75
  for (let e = 0; e < t.length; e += 1)
75
76
  r ^= t.charCodeAt(e), r = Math.imul(r, 16777619);
76
77
  return (r >>> 0).toString(36);
77
78
  }
78
79
  export {
79
- U as computeCodeDiff,
80
- S as computeCodeDiffSync,
81
- M as configureDiffWorker,
82
- W as createDiffWorker,
83
- R as hasDiffWorker,
84
- P as terminateDiffWorker,
85
- w as waitForDiffWorker
80
+ $ as computeCodeDiff,
81
+ P as computeCodeDiffSync,
82
+ S as configureDiffWorker,
83
+ R as createDiffWorker,
84
+ U as hasDiffWorker,
85
+ v as terminateDiffWorker,
86
+ D as waitForDiffWorker
86
87
  };
@@ -1,8 +1,9 @@
1
- import { createSignal as m } from "solid-js";
1
+ import { secureRandomUUID as m } from "../../../utils/secureRandom.js";
2
+ import { createSignal as w } from "solid-js";
2
3
  let t = null, h = !1, l = null;
3
- const f = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), w = 500;
4
+ const f = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), H = 500;
4
5
  let g = null;
5
- function M(e) {
6
+ function $(e) {
6
7
  return t = e, l = new Promise((n) => {
7
8
  t.onmessage = (r) => {
8
9
  if ("type" in r.data && r.data.type === "ready") {
@@ -16,24 +17,24 @@ function M(e) {
16
17
  };
17
18
  }), l;
18
19
  }
19
- function $(e) {
20
+ function b(e) {
20
21
  g = e;
21
22
  }
22
- async function H() {
23
+ async function S() {
23
24
  return t ? h ? !0 : l ? (await l, !0) : !1 : !1;
24
25
  }
25
- function S(e) {
26
+ function W(e) {
26
27
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
27
28
  }
28
- async function W(e, n, r = "github-dark") {
29
+ async function C(e, n, r = "github-dark") {
29
30
  const i = `${r}:${n}:${e}`, a = o.get(i);
30
31
  if (a) return a;
31
- if (await H() && t)
32
+ if (await S() && t)
32
33
  return new Promise((u, y) => {
33
- const d = crypto.randomUUID();
34
+ const d = m();
34
35
  f.set(d, {
35
36
  resolve: (p) => {
36
- if (o.size >= w) {
37
+ if (o.size >= H) {
37
38
  const k = o.keys().next().value;
38
39
  k && o.delete(k);
39
40
  }
@@ -48,15 +49,15 @@ async function W(e, n, r = "github-dark") {
48
49
  return o.set(i, u), u;
49
50
  } catch {
50
51
  }
51
- return `<pre class="shiki"><code>${S(e)}</code></pre>`;
52
+ return `<pre class="shiki"><code>${W(e)}</code></pre>`;
52
53
  }
53
- function b() {
54
- const [e, n] = m(!1);
54
+ function v() {
55
+ const [e, n] = w(!1);
55
56
  return {
56
57
  highlight: async (i, a, s) => {
57
58
  n(!0);
58
59
  try {
59
- return await W(i, a, s);
60
+ return await C(i, a, s);
60
61
  } finally {
61
62
  n(!1);
62
63
  }
@@ -64,13 +65,13 @@ function b() {
64
65
  isLoading: e
65
66
  };
66
67
  }
67
- function v() {
68
+ function E() {
68
69
  t && (t.terminate(), t = null, h = !1, l = null, f.clear()), o.clear();
69
70
  }
70
71
  export {
71
- M as configureShikiWorker,
72
- $ as configureSyncHighlighter,
73
- W as highlightCode,
74
- v as terminateShikiWorker,
75
- b as useCodeHighlight
72
+ $ as configureShikiWorker,
73
+ b as configureSyncHighlighter,
74
+ C as highlightCode,
75
+ E as terminateShikiWorker,
76
+ v as useCodeHighlight
76
77
  };
@@ -1,7 +1,8 @@
1
+ import { secureRandomUUID as w } from "../../../utils/secureRandom.js";
1
2
  import { renderMarkdownToHtml as k } from "../markdown/markdown.js";
2
3
  let n = null, l = !1, u = null;
3
- const c = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), w = 200;
4
- function y() {
4
+ const c = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), m = 200;
5
+ function h() {
5
6
  if (typeof Worker > "u") return null;
6
7
  try {
7
8
  return new Worker(new URL(
@@ -13,65 +14,65 @@ function y() {
13
14
  return null;
14
15
  }
15
16
  }
16
- function M(r) {
17
+ function W(r) {
17
18
  return n = r, l = !1, u = new Promise((t) => {
18
19
  n.onmessage = (e) => {
19
20
  if ("type" in e.data && e.data.type === "ready") {
20
21
  l = !0, t();
21
22
  return;
22
23
  }
23
- const { id: o, html: d, error: i } = e.data, s = c.get(o);
24
- s && (c.delete(o), i ? s.reject(new Error(i)) : s.resolve(d));
24
+ const { id: o, html: f, error: i } = e.data, s = c.get(o);
25
+ s && (c.delete(o), i ? s.reject(new Error(i)) : s.resolve(f));
25
26
  }, n.onerror = (e) => {
26
27
  console.error("Markdown worker error:", e);
27
28
  };
28
29
  }), u;
29
30
  }
30
- function h() {
31
+ function g() {
31
32
  return !!n;
32
33
  }
33
- async function m() {
34
+ async function p() {
34
35
  return n ? l ? !0 : u ? (await u, !0) : !1 : !1;
35
36
  }
36
- function W(r) {
37
+ function R(r) {
37
38
  const t = a.get(r);
38
39
  if (t) return t;
39
40
  const e = k(r);
40
- return f(r, e), e;
41
+ return d(r, e), e;
41
42
  }
42
- async function g(r) {
43
+ async function x(r) {
43
44
  const t = a.get(r);
44
45
  if (t) return t;
45
- if (!await m() || !n) {
46
+ if (!await p() || !n) {
46
47
  const o = k(r);
47
- return f(r, o), o;
48
+ return d(r, o), o;
48
49
  }
49
- return new Promise((o, d) => {
50
- const i = crypto.randomUUID();
50
+ return new Promise((o, f) => {
51
+ const i = w();
51
52
  c.set(i, {
52
53
  resolve: (s) => {
53
- f(r, s), o(s);
54
+ d(r, s), o(s);
54
55
  },
55
- reject: d
56
+ reject: f
56
57
  }), n.postMessage({ id: i, content: r });
57
58
  });
58
59
  }
59
- function R() {
60
+ function U() {
60
61
  n && (n.terminate(), n = null), l = !1, u = null, c.clear(), a.clear();
61
62
  }
62
- function f(r, t) {
63
- if (a.size >= w) {
63
+ function d(r, t) {
64
+ if (a.size >= m) {
64
65
  const e = a.keys().next().value;
65
66
  e && a.delete(e);
66
67
  }
67
68
  a.set(r, t);
68
69
  }
69
70
  export {
70
- M as configureMarkdownWorker,
71
- y as createMarkdownWorker,
72
- h as hasMarkdownWorker,
73
- g as renderMarkdown,
74
- W as renderMarkdownSync,
75
- R as terminateMarkdownWorker,
76
- m as waitForMarkdownWorker
71
+ W as configureMarkdownWorker,
72
+ h as createMarkdownWorker,
73
+ g as hasMarkdownWorker,
74
+ x as renderMarkdown,
75
+ R as renderMarkdownSync,
76
+ U as terminateMarkdownWorker,
77
+ p as waitForMarkdownWorker
77
78
  };
@@ -1,8 +1,9 @@
1
- import { createSignal as w } from "solid-js";
1
+ import { secureRandomUUID as w } from "../../../utils/secureRandom.js";
2
+ import { createSignal as M } from "solid-js";
2
3
  let a = null, f = !1, c = null;
3
- const l = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), M = 200;
4
- let u = null, k = 0;
5
- function E(n) {
4
+ const l = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), k = 200;
5
+ let u = null, p = 0;
6
+ function v(n) {
6
7
  return a = n, c = new Promise((o) => {
7
8
  a.onmessage = (e) => {
8
9
  if ("type" in e.data && e.data.type === "ready") {
@@ -16,21 +17,21 @@ function E(n) {
16
17
  };
17
18
  }), c;
18
19
  }
19
- function C(n) {
20
+ function I(n) {
20
21
  u = n;
21
22
  }
22
- async function p() {
23
+ async function h() {
23
24
  return a ? f ? !0 : c ? (await c, !0) : !1 : !1;
24
25
  }
25
- async function h(n, o = "default") {
26
+ async function W(n, o = "default") {
26
27
  const e = `${o}:${n}`, i = s.get(e);
27
28
  if (i) return i;
28
- if (await p() && a)
29
+ if (await h() && a)
29
30
  return new Promise((t, r) => {
30
- const m = crypto.randomUUID();
31
+ const m = w();
31
32
  l.set(m, {
32
33
  resolve: (g) => {
33
- if (s.size >= M) {
34
+ if (s.size >= k) {
34
35
  const y = s.keys().next().value;
35
36
  y && s.delete(y);
36
37
  }
@@ -41,7 +42,7 @@ async function h(n, o = "default") {
41
42
  });
42
43
  if (u)
43
44
  try {
44
- const t = `mermaid-sync-${k++}`, { svg: r } = await u.render(t, n);
45
+ const t = `mermaid-sync-${p++}`, { svg: r } = await u.render(t, n);
45
46
  return s.set(e, r), r;
46
47
  } catch (t) {
47
48
  const r = t instanceof Error ? t.message : "Failed to render diagram";
@@ -49,13 +50,13 @@ async function h(n, o = "default") {
49
50
  }
50
51
  throw new Error("Mermaid renderer not configured. Call configureMermaidWorker() or configureSyncMermaid() first.");
51
52
  }
52
- function v() {
53
- const [n, o] = w(!1);
53
+ function R() {
54
+ const [n, o] = M(!1);
54
55
  return {
55
56
  render: async (i, d) => {
56
57
  o(!0);
57
58
  try {
58
- return await h(i, d);
59
+ return await W(i, d);
59
60
  } finally {
60
61
  o(!1);
61
62
  }
@@ -63,13 +64,13 @@ function v() {
63
64
  isLoading: n
64
65
  };
65
66
  }
66
- function I() {
67
+ function S() {
67
68
  a && (a.terminate(), a = null, f = !1, c = null, l.clear()), s.clear();
68
69
  }
69
70
  export {
70
- E as configureMermaidWorker,
71
- C as configureSyncMermaid,
72
- h as renderMermaid,
73
- I as terminateMermaidWorker,
74
- v as useMermaid
71
+ v as configureMermaidWorker,
72
+ I as configureSyncMermaid,
73
+ W as renderMermaid,
74
+ S as terminateMermaidWorker,
75
+ R as useMermaid
75
76
  };