@epam/ai-dial-quotations 1.2.0-dev.3 → 1.2.0-dev.300

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/index.js CHANGED
@@ -1,154 +1,305 @@
1
1
  import { MIMEType as e, MarkdownRenderer as t, buildCssVars as n, isAnnotationSelector as r, mergeClasses as i, normalizePersistedHtmlTagAttachmentType as a, normalizeRawAnnotations as o } from "@epam/ai-dial-chat-shared";
2
- import { DIAL_KIT_ICON_STROKE as s, ElementSize as c, EllipsisTooltip as l, GhostIconButton as u, NeutralButton as d, PrimaryButton as f, Tooltip as p } from "@epam/ai-dial-ui-kit";
3
- import { IconChevronLeft as m, IconChevronRight as h } from "@tabler/icons-react";
4
- import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
5
- import { createContext as y, useCallback as b, useContext as x, useMemo as S, useState as C } from "react";
6
- var w = {
2
+ import { DIAL_KIT_ICON_STROKE as s, DialItemType as c, Dropdown as l, ElementSize as u, EllipsisTooltip as d, FileIcon as f, GhostIconButton as p, LinkButton as m, NeutralButton as h, PrimaryButton as g } from "@epam/ai-dial-ui-kit";
3
+ import { IconChevronLeft as _, IconChevronRight as v } from "@tabler/icons-react";
4
+ import { createContext as y, useCallback as b, useContext as x, useEffect as S, useId as ee, useLayoutEffect as C, useMemo as w, useRef as T, useState as E } from "react";
5
+ import { Fragment as D, jsx as O, jsxs as k } from "react/jsx-runtime";
6
+ //#region src/constants/public-class-names.ts
7
+ var A = {
8
+ citationCard: "dial-quotations-citation-card",
9
+ citationDropdown: "dial-quotations-citation-dropdown",
10
+ citationMarker: "dial-quotations-citation-marker"
11
+ }, j = (e) => {
12
+ try {
13
+ return decodeURIComponent(e);
14
+ } catch {
15
+ return e;
16
+ }
17
+ }, M = (e) => {
18
+ try {
19
+ let t = new URL(e);
20
+ return t.pathname.split("/").map((e) => j(e)).filter(Boolean).at(-1) ?? t.hostname;
21
+ } catch {
22
+ return e.split("/").map((e) => j(e)).filter(Boolean).at(-1) ?? e;
23
+ }
24
+ }, N = /\.([a-z0-9]{1,10})$/i, P = (e) => {
25
+ let t = e == null ? null : N.exec(e.trim());
26
+ return t == null ? void 0 : `.${t[1].toLowerCase()}`;
27
+ }, te = (e) => {
28
+ let t = e.body?.source?.attachment, n = t?.url;
29
+ return (n == null ? void 0 : P(M(n))) ?? P(t?.title);
30
+ }, F = (e, t) => e.body?.source?.attachment?.title ?? M(t), I = (e) => {
31
+ let t = e.target?.selector;
32
+ return t?.type === "html_tag" ? t : void 0;
33
+ }, L = (e) => I(e) != null, R = (e) => {
34
+ let t = /* @__PURE__ */ new Map();
35
+ for (let n of e) {
36
+ if (L(n)) continue;
37
+ let e = n.body?.source?.attachment?.url;
38
+ if (e == null) continue;
39
+ let r = t.get(e);
40
+ r ? r.annotations.push(n) : t.set(e, {
41
+ groupKey: e,
42
+ sourceUrl: e,
43
+ sourceName: F(n, e),
44
+ annotations: [n],
45
+ primaryAnnotation: n
46
+ });
47
+ }
48
+ return Array.from(t.values());
49
+ }, z = (e) => {
50
+ let t = /* @__PURE__ */ new Map();
51
+ for (let n of e) {
52
+ let e = I(n)?.id;
53
+ if (e == null) continue;
54
+ let r = n.body?.source?.attachment?.url;
55
+ if (r == null) continue;
56
+ let i = t.get(e);
57
+ i ? i.annotations.push(n) : t.set(e, {
58
+ groupKey: `cit:${e}`,
59
+ sourceUrl: r,
60
+ sourceName: F(n, r),
61
+ annotations: [n],
62
+ primaryAnnotation: n
63
+ });
64
+ }
65
+ return Array.from(t.values());
66
+ }, B = (e) => [...z(e), ...R(e)], V = (e, t) => {
67
+ let n = e.body?.source?.attachment?.url;
68
+ return n == null || !t.includes(e) ? [e] : t.filter((e) => e.body?.source?.attachment?.url === n);
69
+ }, H = {
7
70
  card: "_card_1kph1_1",
8
71
  quote: "_quote_1kph1_5",
9
72
  title: "_title_1kph1_9",
10
73
  switcher: "_switcher_1kph1_13",
11
74
  sourceName: "_sourceName_1kph1_17"
12
- }, T = ({ group: r, activeIndex: a, onIndexChange: o, onPreview: d, onOpenInBrowser: p, headerIcon: g, labels: y, typography: b, colors: x }) => {
13
- let S = r.annotations.length, C = r.annotations[a] ?? r.primaryAnnotation, T = S > 1, E = r.primaryAnnotation.body?.source?.attachment?.type, D = d == null || E === e.HTML || E === e.XHTML, O = b?.sourceNameClassName ?? "dial-tiny-text", k = b?.titleClassName ?? "dial-body-semi-text", A = b?.quoteClassName ?? "dial-small-text", j = b?.quoteStrongClassName ?? "dial-small-semi-text", M = b?.switcherClassName ?? "dial-tiny-text", N = n({
14
- "--cc-card-bg": x?.cardBackground,
15
- "--cc-quote-text": x?.quoteText,
16
- "--cc-title-text": x?.titleText,
17
- "--cc-switcher-text": x?.switcherText,
18
- "--cc-source-name-text": x?.sourceNameText
19
- });
20
- return /* @__PURE__ */ v("div", {
75
+ }, U = ({ group: r, activeIndex: a, onIndexChange: o, onPreview: l, onOpenInBrowser: h, isDownloadEnabled: y = !0, headerIcon: b, labels: x, typography: w, colors: D }) => {
76
+ let j = r.annotations.length, M = r.annotations[a] ?? r.primaryAnnotation, N = j > 1, P = M.body?.source?.attachment?.type, F = l == null || P === e.HTML || P === e.XHTML, I = F ? void 0 : te(M), L = I ?? r.sourceName, R = b ?? (I == null ? void 0 : /* @__PURE__ */ O(f, {
77
+ type: c.File,
78
+ name: I,
79
+ fileExtension: I,
80
+ size: 16,
81
+ decorative: !0,
82
+ className: "shrink-0"
83
+ })), z = w?.sourceNameClassName ?? "dial-tiny-text", B = w?.titleClassName ?? "dial-body-semi-text", V = w?.quoteClassName ?? "dial-small-text", U = w?.quoteStrongClassName ?? "dial-small-semi-text", W = w?.switcherClassName ?? "dial-tiny-text", G = n({
84
+ "--cc-card-bg": D?.cardBackground,
85
+ "--cc-quote-text": D?.quoteText,
86
+ "--cc-title-text": D?.titleText,
87
+ "--cc-switcher-text": D?.switcherText,
88
+ "--cc-source-name-text": D?.sourceNameText
89
+ }), K = M.body?.quote, q = ee(), J = T(null), [Y, X] = E(!1), [ne, re] = E(!1);
90
+ return S(() => {
91
+ X(!1);
92
+ }, [a, K]), C(() => {
93
+ let e = J.current;
94
+ if (!e || Y) return;
95
+ let t = () => re(e.scrollHeight > e.clientHeight + 1);
96
+ t();
97
+ let n = new ResizeObserver(t);
98
+ return n.observe(e), () => n.disconnect();
99
+ }, [K, Y]), /* @__PURE__ */ k("div", {
21
100
  role: "dialog",
22
101
  "aria-modal": "true",
23
- "aria-label": y.ariaLabel,
24
- style: N,
25
- className: i("flex w-[400px] flex-col gap-3 rounded-lg p-4 shadow-lg", w.card),
102
+ "aria-label": x.ariaLabel,
103
+ style: G,
104
+ className: i("flex w-[400px] max-w-full flex-col gap-3 rounded-lg p-4 shadow-lg", H.card, A.citationCard),
26
105
  children: [
27
- /* @__PURE__ */ v("div", {
106
+ /* @__PURE__ */ k("div", {
28
107
  className: "flex items-center justify-between gap-2",
29
- children: [/* @__PURE__ */ v("div", {
108
+ children: [/* @__PURE__ */ k("div", {
30
109
  className: "flex min-w-0 items-center gap-1",
31
- children: [g, /* @__PURE__ */ _(l, {
32
- text: r.sourceName,
33
- className: i(O, "min-w-0", w.sourceName)
110
+ children: [R, /* @__PURE__ */ O(d, {
111
+ text: L,
112
+ className: i(z, "min-w-0", H.sourceName)
34
113
  })]
35
- }), T && /* @__PURE__ */ v("div", {
114
+ }), N && /* @__PURE__ */ k("div", {
36
115
  className: "flex shrink-0 items-center gap-1",
37
116
  children: [
38
- /* @__PURE__ */ _(u, {
39
- icon: /* @__PURE__ */ _(m, {
117
+ /* @__PURE__ */ O(p, {
118
+ icon: /* @__PURE__ */ O(_, {
40
119
  size: 14,
41
120
  className: "rtl:scale-x-[-1]",
42
121
  stroke: s
43
122
  }),
44
- size: c.Small,
45
- "aria-label": y.previousCitation,
46
- onClick: () => o((a - 1 + S) % S)
123
+ size: u.Small,
124
+ "aria-label": x.previousCitation,
125
+ onClick: () => o((a - 1 + j) % j)
47
126
  }),
48
- /* @__PURE__ */ _("span", {
49
- className: i(M, w.switcher),
50
- children: y.formatSwitcherText(a + 1, S)
127
+ /* @__PURE__ */ O("span", {
128
+ className: i(W, H.switcher),
129
+ children: x.formatSwitcherText(a + 1, j)
51
130
  }),
52
- /* @__PURE__ */ _(u, {
53
- icon: /* @__PURE__ */ _(h, {
131
+ /* @__PURE__ */ O(p, {
132
+ icon: /* @__PURE__ */ O(v, {
54
133
  size: 14,
55
134
  className: "rtl:scale-x-[-1]",
56
135
  stroke: s
57
136
  }),
58
- size: c.Small,
59
- "aria-label": y.nextCitation,
60
- onClick: () => o((a + 1) % S)
137
+ size: u.Small,
138
+ "aria-label": x.nextCitation,
139
+ onClick: () => o((a + 1) % j)
61
140
  })
62
141
  ]
63
142
  })]
64
143
  }),
65
- (C.body?.title || C.body?.quote || T) && /* @__PURE__ */ v("div", {
144
+ (M.body?.title || M.body?.quote || N) && /* @__PURE__ */ k("div", {
66
145
  className: "flex flex-col gap-3",
67
- children: [C.body?.title && /* @__PURE__ */ _("p", {
68
- className: i(k, w.title, "break-words"),
69
- children: C.body.title
70
- }), (C.body?.quote || T) && /* @__PURE__ */ _("div", {
71
- className: i(A, w.quote, "line-clamp-6 break-words", T && "min-h-[3lh]"),
72
- children: C.body?.quote && /* @__PURE__ */ _(t, {
73
- content: C.body.quote,
74
- classNames: {
75
- p: i(A, w.quote),
76
- ul: i(A, "ps-3"),
77
- ol: i(A, "ps-3"),
78
- strong: j
79
- }
80
- })
146
+ children: [M.body?.title && /* @__PURE__ */ O("p", {
147
+ className: i(B, H.title, "break-words"),
148
+ children: M.body.title
149
+ }), (K || N) && /* @__PURE__ */ k("div", {
150
+ className: "flex flex-col items-start gap-1",
151
+ children: [/* @__PURE__ */ O("div", {
152
+ ref: J,
153
+ id: q,
154
+ tabIndex: Y ? 0 : void 0,
155
+ className: i(V, H.quote, "w-full break-words", Y ? "max-h-[min(20rem,50vh)] overflow-y-auto" : "line-clamp-6"),
156
+ children: K && /* @__PURE__ */ O(t, {
157
+ content: K,
158
+ classNames: {
159
+ p: i(V, H.quote),
160
+ ul: i(V, "ps-[1.5em]"),
161
+ ol: V,
162
+ strong: U
163
+ },
164
+ codeBlockCopyLabel: x.codeBlockCopyLabel,
165
+ codeBlockCopiedLabel: x.codeBlockCopiedLabel,
166
+ codeBlockDownloadLabel: x.codeBlockDownloadLabel,
167
+ tableScrollRegionAriaLabel: x.tableScrollRegionAriaLabel,
168
+ mathScrollRegionAriaLabel: x.mathScrollRegionAriaLabel
169
+ })
170
+ }), ne && /* @__PURE__ */ O(m, {
171
+ label: Y ? x.showLess : x.showMore,
172
+ size: u.Small,
173
+ "aria-expanded": Y,
174
+ "aria-controls": q,
175
+ onClick: () => X((e) => !e)
176
+ })]
81
177
  })]
82
178
  }),
83
- /* @__PURE__ */ v("div", {
179
+ /* @__PURE__ */ k("div", {
84
180
  className: "flex justify-start gap-2",
85
- children: [d && /* @__PURE__ */ _(f, {
86
- label: y.preview,
87
- size: c.Small,
88
- onClick: () => d(C)
89
- }), /* @__PURE__ */ _(f, {
90
- label: D ? y.openInBrowser : y.download,
91
- size: c.Small,
92
- onClick: () => p(C)
181
+ children: [l && /* @__PURE__ */ O(g, {
182
+ label: x.preview,
183
+ size: u.Small,
184
+ onClick: () => l(M)
185
+ }), (F || y) && /* @__PURE__ */ O(g, {
186
+ label: F ? x.openInBrowser : x.download,
187
+ size: u.Small,
188
+ onClick: () => h(M)
93
189
  })]
94
190
  })
95
191
  ]
96
192
  });
97
- }, E = ({ annotationCount: e, onOpen: t, icon: n, labels: r, labelClassName: i = "dial-caption-text" }) => {
98
- let a = /* @__PURE__ */ v("span", {
99
- className: "flex items-center gap-1",
100
- children: [n, /* @__PURE__ */ _("span", {
101
- className: i,
102
- children: e > 1 ? r.labelWithOverflow : r.label
103
- })]
104
- });
105
- return /* @__PURE__ */ _(d, {
106
- size: c.Small,
107
- label: a,
108
- "aria-label": r.ariaLabel,
109
- onClick: t
110
- });
111
- }, D = y(null), O = D.Provider, k = () => {
112
- let e = x(D);
193
+ }, W = ({ annotationCount: e, onOpen: t, icon: n, labels: r, labelClassName: a = "dial-caption-text" }) => /* @__PURE__ */ O(h, {
194
+ size: u.Small,
195
+ className: i("max-w-[240px]", A.citationMarker),
196
+ textClassName: "min-w-0 truncate",
197
+ iconBefore: n,
198
+ label: /* @__PURE__ */ O("span", {
199
+ className: a,
200
+ children: e > 1 ? r.labelWithOverflow : r.label
201
+ }),
202
+ "aria-label": r.ariaLabel,
203
+ onClick: t
204
+ }), G = y(null), K = G.Provider, q = () => {
205
+ let e = x(G);
113
206
  if (e == null) throw Error("useCitationCardContext must be used within a CitationCardProvider");
114
207
  return e;
115
- }, A = { content: "_content_xzs0h_1" }, j = ({ group: e, onPreview: t, onOpenInBrowser: n, icon: r, headerIcon: a, cardLabels: o, markerLabels: s, cardTypography: c, markerLabelClassName: l }) => {
116
- let u = k(), d = u.isOpen(e.groupKey), f = u.getActiveIndex(e.groupKey), m = b((e) => {
117
- e || u.closePopup();
118
- }, [u]), h = S(() => t ? (e) => {
119
- t(e), u.closePopup();
120
- } : void 0, [t, u]);
121
- return /* @__PURE__ */ _(p, {
122
- open: d,
123
- onOpenChange: m,
124
- triggerClassName: "ms-1 inline-flex align-middle",
125
- contentClassName: i("!p-0 !bg-transparent !border-0 !shadow-none !max-w-none !rounded-none", A.content),
126
- tooltip: /* @__PURE__ */ _(T, {
127
- group: e,
128
- activeIndex: f,
129
- onIndexChange: (t) => u.setActiveIndex(e.groupKey, t),
130
- onPreview: h,
131
- onOpenInBrowser: n,
132
- headerIcon: a,
133
- labels: o,
134
- typography: c
135
- }),
136
- children: /* @__PURE__ */ _(E, {
208
+ }, J = { trigger: "_trigger_1ud83_1" }, Y = ({ group: e, onPreview: t, isPreviewable: n, onOpenInBrowser: r, isDownloadEnabled: a = !0, isPreviewOpen: o = !1, icon: s, headerIcon: c, cardLabels: u, markerLabels: d, cardTypography: f, markerLabelClassName: p }) => {
209
+ let m = q(), h = ee(), g = m.isOpen(h), _ = m.getActiveIndex(e.groupKey), v = e.annotations[_] ?? e.primaryAnnotation, y = n?.(v) ?? !0, x = b((e) => {
210
+ e || m.closePopup(h);
211
+ }, [m, h]), S = w(() => t && y ? (e) => {
212
+ t(e), m.closePopup(h);
213
+ } : void 0, [
214
+ t,
215
+ y,
216
+ m,
217
+ h
218
+ ]), C = b(() => {
219
+ if (o && S) {
220
+ S(v);
221
+ return;
222
+ }
223
+ m.openPopup(h);
224
+ }, [
225
+ o,
226
+ S,
227
+ v,
228
+ m,
229
+ h
230
+ ]), T = b(() => /* @__PURE__ */ O(U, {
231
+ group: e,
232
+ activeIndex: _,
233
+ onIndexChange: (t) => m.setActiveIndex(e.groupKey, t),
234
+ onPreview: S,
235
+ onOpenInBrowser: r,
236
+ isDownloadEnabled: a,
237
+ headerIcon: c,
238
+ labels: u,
239
+ typography: f
240
+ }), [
241
+ e,
242
+ _,
243
+ m,
244
+ S,
245
+ r,
246
+ a,
247
+ c,
248
+ u,
249
+ f
250
+ ]);
251
+ return /* @__PURE__ */ O(l, {
252
+ open: g,
253
+ onOpenChange: x,
254
+ trigger: [],
255
+ placement: "bottom-end",
256
+ matchReferenceWidth: !1,
257
+ className: i("ms-1 inline-flex align-middle", J.trigger),
258
+ listClassName: i("!p-0 !bg-transparent !shadow-none !rounded-none", A.citationDropdown),
259
+ renderOverlay: T,
260
+ children: /* @__PURE__ */ O(W, {
137
261
  sourceName: e.sourceName,
138
262
  annotationCount: e.annotations.length,
139
- onOpen: () => u.openPopup(e.groupKey),
140
- icon: r,
141
- labels: s,
142
- labelClassName: l
263
+ onOpen: C,
264
+ icon: s,
265
+ labels: d,
266
+ labelClassName: p
143
267
  })
144
268
  });
145
- }, M = {
269
+ }, X = (e) => {
270
+ let t = e.trim();
271
+ if (!t.startsWith("|") || !t.endsWith("|") || /[\r\n]/.test(t)) return;
272
+ let n = [], r = "";
273
+ for (let e = 1; e < t.length; e += 1) {
274
+ let i = t[e], a = t[e + 1];
275
+ i === "\\" && a != null && /[!-/:-@[-`{-~]/.test(a) ? (r += a, e += 1) : i === "|" ? (n.push(r.trim()), r = "") : r += i;
276
+ }
277
+ if (!(r !== "" || n.length < 2 || n.every((e) => e === "" || /^:?-{3,}:?$/.test(e)))) return n;
278
+ }, ne = (e) => {
279
+ if (e.type !== "docx_text_anchor" && e.type !== "pptx_text_anchor") return;
280
+ let { text: t, occurrence: n, slide: r } = e;
281
+ if (typeof t != "string" || typeof n != "number" || !Number.isSafeInteger(n) || n < 1) return;
282
+ let i = X(t);
283
+ if (i != null) {
284
+ if (e.type === "docx_text_anchor") return {
285
+ type: "docx_text_anchor",
286
+ cells: i,
287
+ occurrence: n
288
+ };
289
+ if (!(typeof r != "number" || !Number.isSafeInteger(r) || r < 1)) return {
290
+ type: "pptx_text_anchor",
291
+ cells: i,
292
+ occurrence: n,
293
+ slide: r
294
+ };
295
+ }
296
+ }, re = {
146
297
  backgroundColor: "transparent",
147
298
  borderColor: "var(--stroke-accent, #1D4ED8)",
148
299
  borderWidth: "2px",
149
300
  opacity: .5,
150
301
  hoverOpacity: .5
151
- }, N = (e) => {
302
+ }, ie = (e) => {
152
303
  if (typeof e != "object" || !e) return;
153
304
  let t = e, { lt: n, wh: r } = t;
154
305
  if (Array.isArray(n) && Array.isArray(r) && n.length >= 2 && r.length >= 2) {
@@ -167,7 +318,7 @@ var w = {
167
318
  x2: i + o,
168
319
  y2: a + s
169
320
  };
170
- }, P = (e) => {
321
+ }, Z = (e) => {
171
322
  if (!r(e)) return;
172
323
  let t = e, n;
173
324
  if (t.type === "pdf_bbox") {
@@ -178,7 +329,7 @@ var w = {
178
329
  x2: i,
179
330
  y2: a
180
331
  });
181
- } else t.type === "pdf_region" && (n = N(t.bbox));
332
+ } else t.type === "pdf_region" && (n = ie(t.bbox));
182
333
  if (n == null) return;
183
334
  let i = t.page;
184
335
  if (!(typeof i != "number" || !Number.isInteger(i) || i < 1) && [
@@ -193,48 +344,85 @@ var w = {
193
344
  x2: n.x2,
194
345
  y2: n.y2
195
346
  };
196
- }, ee = (e) => e.flatMap((e, t) => {
197
- let n = e.body?.selector;
198
- if (n == null) return [];
199
- let i = (Array.isArray(n) ? n : [n]).flatMap((e) => {
200
- if (!r(e)) return [];
201
- let t = P(e);
347
+ }, ae = (e) => {
348
+ if (!r(e)) return;
349
+ let t = e;
350
+ if (t.type !== "pdf_bbox" && t.type !== "pdf_region") return;
351
+ let n = t.page;
352
+ return typeof n == "number" && Number.isInteger(n) && n >= 1 ? n : void 0;
353
+ }, Q = (e) => typeof e != "object" || !e ? String(e) : Array.isArray(e) ? `[${e.map(Q).join(",")}]` : `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${e}=${Q(t)}`).join(",")}}`, oe = (e) => {
354
+ let t = 5381;
355
+ for (let n = 0; n < e.length; n += 1) t = t * 33 + e.charCodeAt(n) | 0;
356
+ return (t >>> 0).toString(36);
357
+ }, se = (e) => {
358
+ let t = e.body?.selector;
359
+ if (t == null) return;
360
+ let n = (Array.isArray(t) ? t : [t]).flatMap((e) => {
361
+ let t = Z(e);
202
362
  return t == null ? [] : [t];
363
+ }), r = xe(e);
364
+ if (!(n.length === 0 && r.length === 0)) return Q([n, r]);
365
+ }, ce = (e) => {
366
+ let t = e.target?.selector, n = t?.type === "html_tag" ? t.id : void 0, r = typeof n == "string" ? n : void 0, i = se(e);
367
+ if (!(r == null && i == null)) return oe(`${r ?? ""}|${i ?? ""}`);
368
+ }, le = (e) => {
369
+ let t = de(e);
370
+ return e.flatMap((e, n) => {
371
+ let i = e.body?.selector;
372
+ if (i == null) return [];
373
+ let a = (Array.isArray(i) ? i : [i]).flatMap((e) => {
374
+ if (!r(e)) return [];
375
+ let t = Z(e);
376
+ return t == null ? [] : [t];
377
+ });
378
+ return a.length === 0 ? [] : [{
379
+ id: t[n],
380
+ bboxes: a,
381
+ style: re
382
+ }];
203
383
  });
204
- return i.length === 0 ? [] : [{
205
- id: String(e.index ?? t),
206
- bboxes: i,
207
- style: M
208
- }];
209
- }), te = (e, t) => String(e.index ?? t), ne = (e) => {
384
+ }, ue = (e, t) => e.index == null ? ce(e) ?? String(t) : String(e.index), de = (e) => {
385
+ let t = e.map((e, t) => ue(e, t)), n = new Set(t), r = /* @__PURE__ */ new Set();
386
+ return t.map((e) => {
387
+ if (!r.has(e)) return r.add(e), e;
388
+ let t = 1;
389
+ for (; n.has(`${e}-${t}`);) t += 1;
390
+ let i = `${e}-${t}`;
391
+ return n.add(i), r.add(i), i;
392
+ });
393
+ }, fe = (e) => {
210
394
  let t = e.body?.selector;
211
395
  if (t == null) return;
212
396
  let n = Array.isArray(t) ? t : [t];
213
397
  for (let e of n) {
214
398
  if (!r(e)) continue;
215
- let t = P(e);
399
+ let t = Z(e);
216
400
  if (t != null) return t.page;
217
401
  }
218
- }, F = (e) => {
402
+ for (let e of n) {
403
+ let t = ae(e);
404
+ if (t != null) return t;
405
+ }
406
+ }, pe = (e) => {
219
407
  let t = e.custom_content?.annotations;
220
408
  if (t?.length) return t.filter((e) => e != null && e.body?.source?.attachment?.url != null).map(a);
221
409
  let n = e.custom_fields;
222
410
  if (typeof n != "object" || !n) return [];
223
411
  let r = n.annotations;
224
412
  return !Array.isArray(r) || r.length === 0 ? [] : o(r, e.custom_content?.attachments ?? []).map(a);
225
- }, I = (e) => {
413
+ }, me = (e) => {
226
414
  if (e.type !== "docx_text_range") return !1;
227
415
  let t = e;
228
416
  return typeof t.story == "string" && Array.isArray(t.path) && t.path.every((e) => typeof e == "number") && typeof t.start == "number" && typeof t.end == "number" && typeof t.text == "string";
229
- }, L = (e) => {
417
+ }, he = (e) => {
230
418
  if (e.type !== "pptx_text_range") return !1;
231
419
  let t = e;
232
420
  return typeof t.slide == "number" && typeof t.shape_id == "string" && typeof t.start == "number" && typeof t.end == "number" && typeof t.text == "string";
233
- }, R = (e) => typeof e == "object" && !!e && typeof e.row == "number" && typeof e.col == "number", z = (e) => {
421
+ }, ge = (e) => typeof e == "object" && !!e && typeof e.row == "number" && typeof e.col == "number", _e = (e) => {
234
422
  if (e.type !== "excel_rc_range") return !1;
235
423
  let t = e;
236
- return typeof t.sheet == "string" && R(t.start) && (t.end === void 0 || t.end === null || R(t.end));
237
- }, re = (e) => {
424
+ return typeof t.sheet == "string" && ge(t.start) && (t.end === void 0 || t.end === null || ge(t.end));
425
+ }, ve = (e) => {
238
426
  let { story: t, path: n, start: r, end: i, text: a } = e;
239
427
  if (!(!n.every((e) => Number.isInteger(e)) || !Number.isInteger(r) || !Number.isInteger(i) || r < 0 || i < r)) return {
240
428
  type: "docx_text_range",
@@ -244,7 +432,7 @@ var w = {
244
432
  endExclusive: i,
245
433
  text: a
246
434
  };
247
- }, ie = (e) => {
435
+ }, ye = (e) => {
248
436
  let { slide: t, shape_id: n, start: r, end: i, text: a } = e;
249
437
  if (!(!Number.isInteger(t) || t < 1 || !Number.isInteger(r) || !Number.isInteger(i) || r < 0 || i < r)) return {
250
438
  type: "pptx_text_range",
@@ -254,7 +442,7 @@ var w = {
254
442
  endExclusive: i,
255
443
  text: a
256
444
  };
257
- }, ae = (e) => {
445
+ }, be = (e) => {
258
446
  let { sheet: t, start: n, end: r } = e;
259
447
  if (!(t.length === 0 || !Number.isInteger(n.row) || !Number.isInteger(n.col) || n.row < 1 || n.col < 1)) {
260
448
  if (r == null) return {
@@ -269,38 +457,39 @@ var w = {
269
457
  end: r
270
458
  };
271
459
  }
272
- }, oe = (e) => {
460
+ }, xe = (e) => {
273
461
  let t = e.body?.selector;
274
462
  return t == null ? [] : (Array.isArray(t) ? t : [t]).flatMap((e) => {
275
463
  if (!r(e)) return [];
276
- if (I(e)) {
277
- let t = re(e);
464
+ if (me(e)) {
465
+ let t = ve(e);
278
466
  return t ? [t] : [];
279
467
  }
280
- if (L(e)) {
281
- let t = ie(e);
468
+ if (he(e)) {
469
+ let t = ye(e);
282
470
  return t ? [t] : [];
283
471
  }
284
- if (z(e)) {
285
- let t = ae(e);
472
+ if (_e(e)) {
473
+ let t = be(e);
286
474
  return t ? [t] : [];
287
475
  }
288
- return [];
476
+ let t = ne(e);
477
+ return t ? [t] : [];
289
478
  });
290
- }, se = (e, t) => S(() => t ? [] : F(e), [t, e]), ce = {
291
- openGroupKey: null,
479
+ }, Se = (e, t) => w(() => t ? [] : pe(e), [t, e]), Ce = {
480
+ openOwnerKey: null,
292
481
  activeIndexByGroup: {}
293
- }, le = () => {
294
- let [e, t] = C(ce), n = b((e) => {
482
+ }, we = () => {
483
+ let [e, t] = E(Ce), n = b((e) => {
295
484
  t((t) => ({
296
485
  ...t,
297
- openGroupKey: e
298
- }));
299
- }, []), r = b(() => {
300
- t((e) => ({
301
- ...e,
302
- openGroupKey: null
486
+ openOwnerKey: e
303
487
  }));
488
+ }, []), r = b((e) => {
489
+ t((t) => t.openOwnerKey === e ? {
490
+ ...t,
491
+ openOwnerKey: null
492
+ } : t);
304
493
  }, []), i = b((e, n) => {
305
494
  t((t) => ({
306
495
  ...t,
@@ -310,11 +499,11 @@ var w = {
310
499
  }
311
500
  }));
312
501
  }, []);
313
- return S(() => ({
502
+ return w(() => ({
314
503
  openPopup: n,
315
504
  closePopup: r,
316
505
  setActiveIndex: i,
317
- isOpen: (t) => e.openGroupKey === t,
506
+ isOpen: (t) => e.openOwnerKey === t,
318
507
  getActiveIndex: (t) => e.activeIndexByGroup[t] ?? 0
319
508
  }), [
320
509
  n,
@@ -322,7 +511,7 @@ var w = {
322
511
  i,
323
512
  e
324
513
  ]);
325
- }, ue = /⟦C(\d+)⟧/g, B = (e, t) => {
514
+ }, Te = /⟦C(\d+)⟧/g, Ee = (e, t) => {
326
515
  let n = t.map((e, t) => ({
327
516
  g: e,
328
517
  idx: t
@@ -335,9 +524,9 @@ var w = {
335
524
  }).sort((e, t) => t.pos - e.pos), r = e;
336
525
  for (let { idx: e, pos: t } of n) r = `${r.slice(0, t)}⟦C${e}⟧${r.slice(t)}`;
337
526
  return r;
338
- }, V = /<cit\s+data-id=(?:"[^"]+"|'[^']+')\s*>\s*<\/cit>/g, H = /^<cit\s+data-id=(?:"[^"]+"|'[^']+')\s*>\s*<\/cit>$/, de = /<cit\s+data-id=(?:"[^"]+"|'[^']+')\s*>\s*<\/cit>|<\/?cit\b[^>]*>|<\/?cit\b[^>]*$/gi, fe = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), U = (e) => e.replace(de, (e) => H.test(e) ? e : fe(e)), W = (e) => U(e).replace(V, ""), G = (e, t) => {
527
+ }, De = /<cit\s+data-id=(?:"[^"]+"|'[^']+')\s*>\s*<\/cit>/g, Oe = /^<cit\s+data-id=(?:"[^"]+"|'[^']+')\s*>\s*<\/cit>$/, ke = /<cit\s+data-id=(?:"[^"]+"|'[^']+')\s*>\s*<\/cit>|<\/?cit\b[^>]*>|<\/?cit\b[^>]*$/gi, Ae = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), je = (e) => e.replace(ke, (e) => Oe.test(e) ? e : Ae(e)), Me = (e) => je(e).replace(De, ""), $ = (e, t) => {
339
528
  if (typeof e == "string") {
340
- let n = e.split(ue);
529
+ let n = e.split(Te);
341
530
  if (n.length === 1) return e;
342
531
  let r = [];
343
532
  return n.forEach((e, n) => {
@@ -345,57 +534,64 @@ var w = {
345
534
  }), r;
346
535
  }
347
536
  return Array.isArray(e) ? e.flatMap((e) => {
348
- let n = G(e, t);
537
+ let n = $(e, t);
349
538
  return Array.isArray(n) ? n : [n];
350
539
  }) : e;
351
- }, pe = (e) => {
540
+ }, Ne = {}, Pe = [], Fe = (e) => {
352
541
  let t = e.primaryAnnotation.target?.selector;
353
542
  return t?.type === "html_tag" ? t.id : void 0;
354
- }, me = (e, t) => /* @__PURE__ */ v(g, { children: [
543
+ }, Ie = (e, t) => /* @__PURE__ */ k(D, { children: [
355
544
  e == null ? "<cit>" : `<cit data-id="${e}">`,
356
545
  t,
357
546
  "</cit>"
358
- ] }), he = (e, t, n, r = !1, a = !1) => {
359
- let { onPreview: o, onOpenInBrowser: s, buildLabels: c } = n, l = S(() => r ? W(e) : U(t.length > 0 ? B(e, t) : e), [
547
+ ] }), Le = (e, t, n, r = !1, a = !1, o = Pe) => {
548
+ let { onPreview: s, isPreviewable: c, onOpenInBrowser: l, isDownloadEnabled: u = !0, isPreviewOpen: d = !1, buildLabels: f } = n, p = w(() => r ? Me(e) : je(t.length > 0 ? Ee(e, t) : e), [
360
549
  e,
361
550
  t,
362
551
  r
363
- ]), u = l.includes("<cit");
552
+ ]), m = p.includes("<cit");
364
553
  return {
365
- processedContent: l,
366
- markdownComponents: S(() => {
554
+ processedContent: p,
555
+ markdownComponents: w(() => {
367
556
  let e = /* @__PURE__ */ new Map();
557
+ for (let t of o) {
558
+ let n = Fe(t);
559
+ n != null && e.set(n, t);
560
+ }
368
561
  for (let n of t) {
369
- let t = pe(n);
562
+ let t = Fe(n);
370
563
  t != null && e.set(t, n);
371
564
  }
372
565
  let n = (e) => {
373
- let { cardLabels: t, markerLabels: n } = c(e);
374
- return /* @__PURE__ */ _(j, {
566
+ let { cardLabels: t, markerLabels: n } = f(e);
567
+ return /* @__PURE__ */ O(Y, {
375
568
  group: e,
376
- onPreview: (t) => o(t, e),
377
- onOpenInBrowser: s,
569
+ onPreview: (t) => s(t, e),
570
+ isPreviewable: c,
571
+ onOpenInBrowser: l,
572
+ isDownloadEnabled: u,
573
+ isPreviewOpen: d,
378
574
  cardLabels: t,
379
575
  markerLabels: n
380
576
  }, `citation-${e.groupKey}`);
381
577
  }, r = (e) => {
382
578
  let r = t[e];
383
579
  return r ? n(r) : null;
384
- }, l = { cit: (t) => {
580
+ }, p = { cit: (t) => {
385
581
  let r = t["data-id"] == null ? void 0 : e.get(t["data-id"]);
386
- return r ? n(r) : me(t["data-id"], t.children);
582
+ return r ? n(r) : Ie(t["data-id"], t.children);
387
583
  } };
388
- return t.length === 0 ? u ? l : {} : {
389
- ...l,
390
- p: ({ children: e, ...t }) => /* @__PURE__ */ _("p", {
584
+ return t.length === 0 && o.length === 0 ? m ? p : Ne : {
585
+ ...p,
586
+ p: ({ children: e, ...t }) => /* @__PURE__ */ O("p", {
391
587
  ...t,
392
588
  className: i(a ? "dial-small-paragraph-text" : "dial-body-paragraph-text", "mb-3 [overflow-wrap:anywhere] [text-wrap:pretty] last:mb-0"),
393
- children: G(e, r)
589
+ children: $(e, r)
394
590
  }),
395
- li: ({ children: e, ...t }) => /* @__PURE__ */ _("li", {
591
+ li: ({ children: e, ...t }) => /* @__PURE__ */ O("li", {
396
592
  ...t,
397
593
  className: "mb-1.5 last:mb-0",
398
- children: G(e, r)
594
+ children: $(e, r)
399
595
  })
400
596
  };
401
597
  }, [
@@ -403,70 +599,22 @@ var w = {
403
599
  o,
404
600
  s,
405
601
  c,
602
+ l,
603
+ u,
604
+ d,
605
+ f,
406
606
  a,
407
- u
607
+ m
408
608
  ])
409
609
  };
410
- }, K = (e) => {
411
- try {
412
- return decodeURIComponent(e);
413
- } catch {
414
- return e;
415
- }
416
- }, ge = (e) => {
417
- try {
418
- let t = new URL(e);
419
- return t.pathname.split("/").map((e) => K(e)).filter(Boolean).at(-1) ?? t.hostname;
420
- } catch {
421
- return e.split("/").map((e) => K(e)).filter(Boolean).at(-1) ?? e;
422
- }
423
- }, q = (e, t) => e.body?.source?.attachment?.title ?? ge(t), J = (e) => {
424
- let t = e.target?.selector;
425
- return t?.type === "html_tag" ? t : void 0;
426
- }, _e = (e) => J(e) != null, Y = (e) => {
427
- let t = /* @__PURE__ */ new Map();
428
- for (let n of e) {
429
- if (_e(n)) continue;
430
- let e = n.body?.source?.attachment?.url;
431
- if (e == null) continue;
432
- let r = t.get(e);
433
- r ? r.annotations.push(n) : t.set(e, {
434
- groupKey: e,
435
- sourceUrl: e,
436
- sourceName: q(n, e),
437
- annotations: [n],
438
- primaryAnnotation: n
439
- });
440
- }
441
- return Array.from(t.values());
442
- }, X = (e) => {
443
- let t = /* @__PURE__ */ new Map();
444
- for (let n of e) {
445
- let e = J(n)?.id;
446
- if (e == null) continue;
447
- let r = n.body?.source?.attachment?.url;
448
- if (r == null) continue;
449
- let i = t.get(e);
450
- i ? i.annotations.push(n) : t.set(e, {
451
- groupKey: `cit:${e}`,
452
- sourceUrl: r,
453
- sourceName: q(n, r),
454
- annotations: [n],
455
- primaryAnnotation: n
456
- });
457
- }
458
- return Array.from(t.values());
459
- }, ve = (e) => [...X(e), ...Y(e)], Z = (e, t) => {
460
- let n = e.body?.source?.attachment?.url;
461
- return n == null || !t.includes(e) ? [e] : t.filter((e) => e.body?.source?.attachment?.url === n);
462
- }, Q = (e) => e.url == null && e.reference_url != null, ye = /^(.*\.pdf)(?:#page=(\d+))?$/i, $ = (e) => {
463
- let t = ye.exec(e);
610
+ }, Re = (e) => e.url == null && e.reference_url != null, ze = /^(.*\.pdf)(?:#page=(\d+))?$/i, Be = (e) => {
611
+ let t = ze.exec(e);
464
612
  return t ? {
465
613
  baseUrl: t[1],
466
614
  page: t[2] == null ? null : Number(t[2])
467
615
  } : null;
468
- }, be = (t) => Y((t ?? []).filter(Q).map((t) => {
469
- let n = t.reference_url, r = $(n) != null;
616
+ }, Ve = (t) => R((t ?? []).filter(Re).map((t) => {
617
+ let n = t.reference_url, r = Be(n) != null;
470
618
  return { body: {
471
619
  quote: t.data,
472
620
  source: {
@@ -480,4 +628,4 @@ var w = {
480
628
  } };
481
629
  }));
482
630
  //#endregion
483
- export { T as CitationCard, O as CitationCardProvider, j as CitationDropdown, E as CitationMarker, te as annotationHighlightId, oe as annotationToOfficeHighlightLocations, ee as annotationsToPdfHighlights, Z as gatherSameSourceAnnotations, ne as getAnnotationPdfPage, be as getReferenceAttachmentGroups, ve as groupAnnotations, X as groupAnnotationsByCitId, Y as groupAnnotationsBySource, B as injectCitationSentinels, I as isDocxRangeSelector, z as isExcelRcRangeSelector, L as isPptxRangeSelector, Q as isReferenceOnlyAttachment, $ as parsePdfPageReference, G as replaceSentinelsInChildren, F as resolveMessageAnnotations, W as stripCitTagsWhileStreaming, se as useAnnotations, le as useCitationCard, k as useCitationCardContext, he as useCitationMarkdownComponents };
631
+ export { U as CitationCard, K as CitationCardProvider, Y as CitationDropdown, W as CitationMarker, A as QUOTATIONS_CLASS, ue as annotationHighlightId, de as annotationHighlightIds, xe as annotationToOfficeHighlightLocations, le as annotationsToPdfHighlights, V as gatherSameSourceAnnotations, fe as getAnnotationPdfPage, Ve as getReferenceAttachmentGroups, B as groupAnnotations, z as groupAnnotationsByCitId, R as groupAnnotationsBySource, Ee as injectCitationSentinels, me as isDocxRangeSelector, _e as isExcelRcRangeSelector, he as isPptxRangeSelector, Re as isReferenceOnlyAttachment, Be as parsePdfPageReference, $ as replaceSentinelsInChildren, pe as resolveMessageAnnotations, Me as stripCitTagsWhileStreaming, Se as useAnnotations, we as useCitationCard, q as useCitationCardContext, Le as useCitationMarkdownComponents };