@vettvangur/ai-sdk 0.13.0 → 0.15.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.
package/dist/index.js CHANGED
@@ -1,34 +1,4 @@
1
1
  import { a as isSafeLinkUrl, n as createSafeImage, r as createSafeLink, t as createPart } from "./dom.js";
2
- import { A as MAX_ANSWER_CARD_URL_LENGTH, C as MAX_ANSWER_CARD_TABLES, D as MAX_ANSWER_CARD_TOTAL_STRUCTURAL_ITEMS, E as MAX_ANSWER_CARD_TEXT_LENGTH, M as isAnswerCard, N as renderAnswerCard, O as MAX_ANSWER_CARD_TOTAL_TABLE_CELLS, S as MAX_ANSWER_CARD_SECTIONS, T as MAX_ANSWER_CARD_TABLE_ROWS, _ as renderActions, a as createAiChatRegistry, b as MAX_ANSWER_CARD_FACTS, c as closeHandoverCard, d as createChatSession, f as readEventStream, g as CARD_LIST_CLASS, h as ACTIONS_CLASS, i as bindChat, j as assertAnswerCardContract, k as MAX_ANSWER_CARD_TOTAL_TEXT_CHARACTERS, l as isHandoverPayload, m as parseStreamEvent, n as bindLauncherTeaser, o as HANDOVER_TOOL, p as AI_CHAT_PROTOCOL_VERSION, r as CHAT_CLASS, s as LIVE_CHAT_ACTION, t as bindChatWindow, u as renderHandoverCard, v as renderCardList, w as MAX_ANSWER_CARD_TABLE_CELLS, x as MAX_ANSWER_CARD_LINKS, y as ANSWER_CARD_CLASS } from "./window.js";
3
- import { n as createTemplateItemSurface, t as createSingleSurface } from "./surfaces.js";
4
- //#region src/form-context.ts
5
- /**
6
- * Tells the AI what the visitor entered into a form embedded in the thread. Whenever `element`
7
- * changes and holds `options.form`, its filled-in `fields` are summarised as `label: value` and
8
- * sent with every later question through `binding.setFormContext`, framed as context rather than
9
- * something the visitor said. Returns a function that stops watching.
10
- */
11
- function watchFormContext(binding, element, options) {
12
- const record = () => {
13
- const form = element.querySelector(options.form);
14
- if (!form) return;
15
- const values = new FormData(form);
16
- const parts = options.fields.map(([field, label]) => {
17
- const raw = String(values.get(field) ?? "").trim();
18
- const value = options.values?.[raw] ?? raw;
19
- return value ? `${label}: ${value}` : "";
20
- }).filter(Boolean);
21
- if (!parts.length) return;
22
- const note = options.note ? ` ${options.note}` : "";
23
- binding.setFormContext(options.name, `Context, not a message from the visitor: they filled in ${options.title} with ${parts.join(", ")}.${note}`, options.followUp);
24
- };
25
- const observer = new MutationObserver(record);
26
- observer.observe(element, {
27
- childList: true,
28
- subtree: true
29
- });
30
- record();
31
- return () => observer.disconnect();
32
- }
33
- //#endregion
34
- export { ACTIONS_CLASS, AI_CHAT_PROTOCOL_VERSION, ANSWER_CARD_CLASS, CARD_LIST_CLASS, CHAT_CLASS, HANDOVER_TOOL, LIVE_CHAT_ACTION, MAX_ANSWER_CARD_FACTS, MAX_ANSWER_CARD_LINKS, MAX_ANSWER_CARD_SECTIONS, MAX_ANSWER_CARD_TABLES, MAX_ANSWER_CARD_TABLE_CELLS, MAX_ANSWER_CARD_TABLE_ROWS, MAX_ANSWER_CARD_TEXT_LENGTH, MAX_ANSWER_CARD_TOTAL_STRUCTURAL_ITEMS, MAX_ANSWER_CARD_TOTAL_TABLE_CELLS, MAX_ANSWER_CARD_TOTAL_TEXT_CHARACTERS, MAX_ANSWER_CARD_URL_LENGTH, assertAnswerCardContract, bindChat, bindChatWindow, bindLauncherTeaser, closeHandoverCard, createAiChatRegistry, createChatSession, createPart, createSafeImage, createSafeLink, createSingleSurface, createTemplateItemSurface, isAnswerCard, isHandoverPayload, isSafeLinkUrl, parseStreamEvent, readEventStream, renderActions, renderAnswerCard, renderCardList, renderHandoverCard, watchFormContext };
2
+ import { t as readServerEvents } from "./events.js";
3
+ import { r as renderMarkdown, t as MAX_MARKDOWN_CHARACTERS } from "./markdown.js";
4
+ export { MAX_MARKDOWN_CHARACTERS, createPart, createSafeImage, createSafeLink, isSafeLinkUrl, readServerEvents, renderMarkdown };
@@ -1,5 +1,5 @@
1
1
  import { l as AiLiveChatSurveyField, o as AiLiveChatProvider } from "../provider.js";
2
- import { M as AiLiveChatFactoryContext } from "../contracts.js";
2
+ import { j as AiLiveChatFactoryContext } from "../contracts.js";
3
3
  //#region src/live-chat/aichat.d.ts
4
4
  type AiChatLiveConfig = {
5
5
  /** The prefix the site maps the chat under with `MapAiChat`, such as `/webapi/aichat`. */
package/dist/livechat.js CHANGED
@@ -345,7 +345,9 @@ function createLiveChatProvider(config) {
345
345
  function load() {
346
346
  if (connection) return connection;
347
347
  const pending = (async () => {
348
- const sdk = (await import("@livechat/customer-sdk")).init({
348
+ const sdk = (await import("@livechat/customer-sdk").catch((error) => {
349
+ throw new Error("LiveChat needs @livechat/customer-sdk installed.", { cause: error });
350
+ })).init({
349
351
  organizationId: config.organizationId,
350
352
  clientId: config.clientId,
351
353
  ...config.groupId === void 0 ? {} : { groupId: config.groupId }
@@ -0,0 +1,230 @@
1
+ import { a as isSafeLinkUrl, r as createSafeLink } from "./dom.js";
2
+ //#region src/markdown.ts
3
+ const MAX_MARKDOWN_CHARACTERS = 8e3;
4
+ function isWordCharacter(character) {
5
+ return character !== void 0 && /[\p{L}\p{N}]/u.test(character);
6
+ }
7
+ function delimitedToken(source, start, marker, type) {
8
+ if (!source.startsWith(marker, start)) return null;
9
+ const contentStart = start + marker.length;
10
+ const closing = source.indexOf(marker, contentStart);
11
+ if (closing === -1 || closing === contentStart) return null;
12
+ return {
13
+ type,
14
+ content: source.slice(contentStart, closing),
15
+ end: closing + marker.length
16
+ };
17
+ }
18
+ function linkToken(source, start) {
19
+ if (source[start] !== "[") return null;
20
+ let labelEnd = start + 1;
21
+ while (labelEnd < source.length) {
22
+ if (source[labelEnd] === "[") return null;
23
+ if (source[labelEnd] === "]" && source[labelEnd + 1] === "(") break;
24
+ labelEnd += 1;
25
+ }
26
+ if (labelEnd === source.length) return {
27
+ type: "text",
28
+ content: source.slice(start),
29
+ end: source.length
30
+ };
31
+ if (labelEnd === start + 1) return null;
32
+ let depth = 1;
33
+ let end = labelEnd + 2;
34
+ while (end < source.length && depth > 0) {
35
+ if (source[end] === "(") depth += 1;
36
+ else if (source[end] === ")") depth -= 1;
37
+ end += 1;
38
+ }
39
+ if (depth !== 0) return {
40
+ type: "text",
41
+ content: source.slice(start),
42
+ end: source.length
43
+ };
44
+ const url = source.slice(labelEnd + 2, end - 1);
45
+ if (!isSafeLinkUrl(url)) return {
46
+ type: "text",
47
+ content: source.slice(start, end),
48
+ end
49
+ };
50
+ return {
51
+ type: "link",
52
+ label: source.slice(start + 1, labelEnd),
53
+ url,
54
+ end
55
+ };
56
+ }
57
+ function inlineToken(source, start) {
58
+ const link = linkToken(source, start);
59
+ if (link) return link;
60
+ const code = delimitedToken(source, start, "`", "code");
61
+ if (code) return code;
62
+ const bold = delimitedToken(source, start, "**", "bold") ?? delimitedToken(source, start, "__", "bold");
63
+ if (bold) return bold;
64
+ const marker = source[start];
65
+ if ((marker === "*" || marker === "_") && !isWordCharacter(source[start - 1])) return delimitedToken(source, start, marker, "italic");
66
+ return null;
67
+ }
68
+ function inlineStructuralItemCount(source) {
69
+ let count = 0;
70
+ let index = 0;
71
+ while (index < source.length) {
72
+ const token = inlineToken(source, index);
73
+ if (!token) {
74
+ index += 1;
75
+ continue;
76
+ }
77
+ switch (token.type) {
78
+ case "bold":
79
+ case "italic":
80
+ count += 1 + inlineStructuralItemCount(token.content);
81
+ break;
82
+ case "code":
83
+ case "link": count += 1;
84
+ }
85
+ index = token.end;
86
+ }
87
+ return count;
88
+ }
89
+ function appendInlineMarkdown(document, parent, source) {
90
+ let textStart = 0;
91
+ let index = 0;
92
+ while (index < source.length) {
93
+ const token = inlineToken(source, index);
94
+ if (!token) {
95
+ index += 1;
96
+ continue;
97
+ }
98
+ if (textStart < index) parent.append(document.createTextNode(source.slice(textStart, index)));
99
+ switch (token.type) {
100
+ case "code": {
101
+ const code = document.createElement("code");
102
+ code.append(document.createTextNode(token.content));
103
+ parent.append(code);
104
+ break;
105
+ }
106
+ case "bold": {
107
+ const strong = document.createElement("strong");
108
+ appendInlineMarkdown(document, strong, token.content);
109
+ parent.append(strong);
110
+ break;
111
+ }
112
+ case "italic": {
113
+ const emphasis = document.createElement("em");
114
+ appendInlineMarkdown(document, emphasis, token.content);
115
+ parent.append(emphasis);
116
+ break;
117
+ }
118
+ case "link": {
119
+ const link = createSafeLink(document, token.label, token.url);
120
+ if (link) parent.append(link);
121
+ else parent.append(document.createTextNode(source.slice(index, token.end)));
122
+ break;
123
+ }
124
+ case "text": parent.append(document.createTextNode(token.content));
125
+ }
126
+ index = token.end;
127
+ textStart = index;
128
+ }
129
+ if (textStart < source.length) parent.append(document.createTextNode(source.slice(textStart)));
130
+ }
131
+ function unorderedListItem(line) {
132
+ return /^\s*[-+*]\s+(.+)$/.exec(line)?.[1] ?? null;
133
+ }
134
+ function orderedListItem(line) {
135
+ return /^\s*\d+[.)]\s+(.+)$/.exec(line)?.[1] ?? null;
136
+ }
137
+ function heading(line) {
138
+ return /^\s{0,3}#{1,6}\s+(.+?)\s*#*\s*$/.exec(line)?.[1] ?? null;
139
+ }
140
+ function countMarkdownStructuralItems(source) {
141
+ const lines = source.slice(0, MAX_MARKDOWN_CHARACTERS).split(/\r\n?|\n/);
142
+ let count = 0;
143
+ let index = 0;
144
+ while (index < lines.length) {
145
+ const line = lines[index];
146
+ if (line.trim().length === 0) {
147
+ index += 1;
148
+ continue;
149
+ }
150
+ const headingText = heading(line);
151
+ if (headingText !== null) {
152
+ count += 2 + inlineStructuralItemCount(headingText);
153
+ index += 1;
154
+ continue;
155
+ }
156
+ const unorderedItem = unorderedListItem(line);
157
+ const orderedItem = orderedListItem(line);
158
+ if (unorderedItem !== null || orderedItem !== null) {
159
+ const itemForLine = unorderedItem === null ? orderedListItem : unorderedListItem;
160
+ count += 1;
161
+ while (index < lines.length) {
162
+ const item = itemForLine(lines[index]);
163
+ if (item === null) break;
164
+ count += 1 + inlineStructuralItemCount(item);
165
+ index += 1;
166
+ }
167
+ continue;
168
+ }
169
+ const paragraphLines = [];
170
+ while (index < lines.length) {
171
+ const paragraphLine = lines[index];
172
+ if (paragraphLine.trim().length === 0 || heading(paragraphLine) !== null || unorderedListItem(paragraphLine) !== null || orderedListItem(paragraphLine) !== null) break;
173
+ paragraphLines.push(paragraphLine);
174
+ index += 1;
175
+ }
176
+ count += 1 + inlineStructuralItemCount(paragraphLines.join(" "));
177
+ }
178
+ return count;
179
+ }
180
+ function renderMarkdown(document, source) {
181
+ const fragment = document.createDocumentFragment();
182
+ const lines = source.slice(0, MAX_MARKDOWN_CHARACTERS).split(/\r\n?|\n/);
183
+ let index = 0;
184
+ while (index < lines.length) {
185
+ const line = lines[index];
186
+ if (line.trim().length === 0) {
187
+ index += 1;
188
+ continue;
189
+ }
190
+ const headingText = heading(line);
191
+ if (headingText !== null) {
192
+ const paragraph = document.createElement("p");
193
+ const strong = document.createElement("strong");
194
+ appendInlineMarkdown(document, strong, headingText);
195
+ paragraph.append(strong);
196
+ fragment.append(paragraph);
197
+ index += 1;
198
+ continue;
199
+ }
200
+ const unorderedItem = unorderedListItem(line);
201
+ const orderedItem = orderedListItem(line);
202
+ if (unorderedItem !== null || orderedItem !== null) {
203
+ const list = document.createElement(unorderedItem === null ? "ol" : "ul");
204
+ const itemForLine = unorderedItem === null ? orderedListItem : unorderedListItem;
205
+ while (index < lines.length) {
206
+ const item = itemForLine(lines[index]);
207
+ if (item === null) break;
208
+ const listItem = document.createElement("li");
209
+ appendInlineMarkdown(document, listItem, item);
210
+ list.append(listItem);
211
+ index += 1;
212
+ }
213
+ fragment.append(list);
214
+ continue;
215
+ }
216
+ const paragraphLines = [];
217
+ while (index < lines.length) {
218
+ const paragraphLine = lines[index];
219
+ if (paragraphLine.trim().length === 0 || heading(paragraphLine) !== null || unorderedListItem(paragraphLine) !== null || orderedListItem(paragraphLine) !== null) break;
220
+ paragraphLines.push(paragraphLine);
221
+ index += 1;
222
+ }
223
+ const paragraph = document.createElement("p");
224
+ appendInlineMarkdown(document, paragraph, paragraphLines.join(" "));
225
+ fragment.append(paragraph);
226
+ }
227
+ return fragment;
228
+ }
229
+ //#endregion
230
+ export { countMarkdownStructuralItems as n, renderMarkdown as r, MAX_MARKDOWN_CHARACTERS as t };
package/dist/mount.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { o as AiLiveChatProvider } from "./provider.js";
2
- import { M as AiLiveChatFactoryContext, d as AiChatBindings, u as AiChatBinding } from "./contracts.js";
2
+ import { j as AiLiveChatFactoryContext, l as AiChatBinding, u as AiChatBindings } from "./contracts.js";
3
3
  //#region src/mount.d.ts
4
4
  /**
5
5
  * The provider a person answers through, chosen by the root's attributes: Omnichannel when
@@ -171,7 +171,9 @@ function createOmnichannelProvider(config) {
171
171
  function load() {
172
172
  if (chat) return chat;
173
173
  const pending = (async () => {
174
- const module = await import("@microsoft/omnichannel-chat-sdk");
174
+ const module = await import("@microsoft/omnichannel-chat-sdk").catch((error) => {
175
+ throw new Error("Omnichannel needs @microsoft/omnichannel-chat-sdk installed.", { cause: error });
176
+ });
175
177
  const sdk = new module.OmnichannelChatSDK({
176
178
  orgId: config.orgId,
177
179
  orgUrl: config.orgUrl,
package/dist/styles.css CHANGED
@@ -54,10 +54,13 @@
54
54
  --vv-ai-chat-window-header: var(--vv-ai-color-accent);
55
55
  --vv-ai-chat-window-header-agent: var(--vv-ai-color-accent-hover);
56
56
  --vv-ai-chat-window-header-text: var(--vv-ai-color-on-accent);
57
- --vv-ai-chat-window-header-muted: rgb(255 255 255 / 0.85);
58
- --vv-ai-chat-window-header-hover: rgb(255 255 255 / 0.15);
57
+ --vv-ai-chat-window-header-muted: color-mix(in srgb, var(--vv-ai-chat-window-header-text) 85%, transparent);
58
+ --vv-ai-chat-window-header-hover: color-mix(in srgb, var(--vv-ai-chat-window-header-text) 15%, transparent);
59
59
  /* An image in the circle beside each of the assistant's bubbles in the window. */
60
60
  --vv-ai-chat-assistant-avatar: none;
61
+ /* Buttons and fields in the window's thread, the host's own included. */
62
+ --vv-ai-chat-window-control-height: 2.25rem;
63
+ --vv-ai-chat-window-control-font-size: 0.875rem;
61
64
  --vv-ai-launcher-shadow: 0 0.375rem 1.25rem rgb(16 40 80 / 0.25);
62
65
  --vv-ai-launcher-teaser-shadow: 0 0.5rem 1.5rem rgb(16 40 80 / 0.15);
63
66
  --vv-ai-menu-shadow: 0 0.5rem 1.5rem rgb(16 40 80 / 0.18);
@@ -1007,7 +1010,7 @@ body:has(.vv-ai-chat:not(.vv-ai-chat--window)) {
1007
1010
  }
1008
1011
 
1009
1012
  .vv-ai-chat--window .vv-ai-chat__avatar {
1010
- background: rgb(255 255 255 / 0.18);
1013
+ background: color-mix(in srgb, var(--vv-ai-chat-window-header-text) 18%, transparent);
1011
1014
  }
1012
1015
 
1013
1016
  .vv-ai-chat--window .vv-ai-chat__name {
@@ -1385,6 +1388,42 @@ body:has(.vv-ai-chat:not(.vv-ai-chat--window)) {
1385
1388
  line-height: 1.4;
1386
1389
  }
1387
1390
 
1391
+ /*
1392
+ * Buttons and fields in the window's thread stay small. A component the host embeds there brings
1393
+ * the site's buttons and fields, sized for a page, so the common button classes are caught here as
1394
+ * well as the package's own. The composer below the thread keeps its own.
1395
+ */
1396
+ .vv-ai-chat--window .vv-ai-chat__thread-inner :is(
1397
+ .button, [class^="button-"], [class*=" button-"],
1398
+ .btn, [class^="btn-"], [class*=" btn-"],
1399
+ .bttn, [class^="bttn-"], [class*=" bttn-"],
1400
+ .vv-ai-actions__action,
1401
+ .vv-ai-survey__submit
1402
+ ) {
1403
+ min-height: var(--vv-ai-chat-window-control-height);
1404
+ padding-block: 0.375rem;
1405
+ padding-inline: 1rem;
1406
+ font-size: var(--vv-ai-chat-window-control-font-size);
1407
+ line-height: 1.5;
1408
+ }
1409
+
1410
+ .vv-ai-chat--window .vv-ai-chat__thread-inner :is(
1411
+ input:not([type="checkbox"], [type="radio"], [type="range"], [type="hidden"], [type="file"]),
1412
+ select
1413
+ ) {
1414
+ box-sizing: border-box;
1415
+ height: var(--vv-ai-chat-window-control-height);
1416
+ padding-block: 0.5rem;
1417
+ font-size: var(--vv-ai-chat-window-control-font-size);
1418
+ line-height: 1.2;
1419
+ }
1420
+
1421
+ .vv-ai-chat--window .vv-ai-chat__thread-inner textarea {
1422
+ padding-block: 0.5rem;
1423
+ font-size: var(--vv-ai-chat-window-control-font-size);
1424
+ line-height: 1.4;
1425
+ }
1426
+
1388
1427
  .vv-ai-chat--window .vv-ai-chat__composer-inner {
1389
1428
  max-width: none;
1390
1429
  padding: 0.75rem 0.75rem 0.5rem;
package/dist/survey.js CHANGED
@@ -1,232 +1,5 @@
1
- import { a as isSafeLinkUrl, r as createSafeLink, t as createPart } from "./dom.js";
2
- //#region src/markdown.ts
3
- const MAX_MARKDOWN_CHARACTERS = 8e3;
4
- function isWordCharacter(character) {
5
- return character !== void 0 && /[\p{L}\p{N}]/u.test(character);
6
- }
7
- function delimitedToken(source, start, marker, type) {
8
- if (!source.startsWith(marker, start)) return null;
9
- const contentStart = start + marker.length;
10
- const closing = source.indexOf(marker, contentStart);
11
- if (closing === -1 || closing === contentStart) return null;
12
- return {
13
- type,
14
- content: source.slice(contentStart, closing),
15
- end: closing + marker.length
16
- };
17
- }
18
- function linkToken(source, start) {
19
- if (source[start] !== "[") return null;
20
- let labelEnd = start + 1;
21
- while (labelEnd < source.length) {
22
- if (source[labelEnd] === "[") return null;
23
- if (source[labelEnd] === "]" && source[labelEnd + 1] === "(") break;
24
- labelEnd += 1;
25
- }
26
- if (labelEnd === source.length) return {
27
- type: "text",
28
- content: source.slice(start),
29
- end: source.length
30
- };
31
- if (labelEnd === start + 1) return null;
32
- let depth = 1;
33
- let end = labelEnd + 2;
34
- while (end < source.length && depth > 0) {
35
- if (source[end] === "(") depth += 1;
36
- else if (source[end] === ")") depth -= 1;
37
- end += 1;
38
- }
39
- if (depth !== 0) return {
40
- type: "text",
41
- content: source.slice(start),
42
- end: source.length
43
- };
44
- const url = source.slice(labelEnd + 2, end - 1);
45
- if (!isSafeLinkUrl(url)) return {
46
- type: "text",
47
- content: source.slice(start, end),
48
- end
49
- };
50
- return {
51
- type: "link",
52
- label: source.slice(start + 1, labelEnd),
53
- url,
54
- end
55
- };
56
- }
57
- function inlineToken(source, start) {
58
- const link = linkToken(source, start);
59
- if (link) return link;
60
- const code = delimitedToken(source, start, "`", "code");
61
- if (code) return code;
62
- const bold = delimitedToken(source, start, "**", "bold") ?? delimitedToken(source, start, "__", "bold");
63
- if (bold) return bold;
64
- const marker = source[start];
65
- if ((marker === "*" || marker === "_") && !isWordCharacter(source[start - 1])) return delimitedToken(source, start, marker, "italic");
66
- return null;
67
- }
68
- function inlineStructuralItemCount(source) {
69
- let count = 0;
70
- let index = 0;
71
- while (index < source.length) {
72
- const token = inlineToken(source, index);
73
- if (!token) {
74
- index += 1;
75
- continue;
76
- }
77
- switch (token.type) {
78
- case "bold":
79
- case "italic":
80
- count += 1 + inlineStructuralItemCount(token.content);
81
- break;
82
- case "code":
83
- case "link": count += 1;
84
- }
85
- index = token.end;
86
- }
87
- return count;
88
- }
89
- function appendInlineMarkdown(document, parent, source) {
90
- let textStart = 0;
91
- let index = 0;
92
- while (index < source.length) {
93
- const token = inlineToken(source, index);
94
- if (!token) {
95
- index += 1;
96
- continue;
97
- }
98
- if (textStart < index) parent.append(document.createTextNode(source.slice(textStart, index)));
99
- switch (token.type) {
100
- case "code": {
101
- const code = document.createElement("code");
102
- code.append(document.createTextNode(token.content));
103
- parent.append(code);
104
- break;
105
- }
106
- case "bold": {
107
- const strong = document.createElement("strong");
108
- appendInlineMarkdown(document, strong, token.content);
109
- parent.append(strong);
110
- break;
111
- }
112
- case "italic": {
113
- const emphasis = document.createElement("em");
114
- appendInlineMarkdown(document, emphasis, token.content);
115
- parent.append(emphasis);
116
- break;
117
- }
118
- case "link": {
119
- const link = createSafeLink(document, token.label, token.url);
120
- if (link) parent.append(link);
121
- else parent.append(document.createTextNode(source.slice(index, token.end)));
122
- break;
123
- }
124
- case "text": parent.append(document.createTextNode(token.content));
125
- }
126
- index = token.end;
127
- textStart = index;
128
- }
129
- if (textStart < source.length) parent.append(document.createTextNode(source.slice(textStart)));
130
- }
131
- function unorderedListItem(line) {
132
- return /^\s*[-+*]\s+(.+)$/.exec(line)?.[1] ?? null;
133
- }
134
- function orderedListItem(line) {
135
- return /^\s*\d+[.)]\s+(.+)$/.exec(line)?.[1] ?? null;
136
- }
137
- function heading(line) {
138
- return /^\s{0,3}#{1,6}\s+(.+?)\s*#*\s*$/.exec(line)?.[1] ?? null;
139
- }
140
- function countMarkdownStructuralItems(source) {
141
- const lines = source.slice(0, MAX_MARKDOWN_CHARACTERS).split(/\r\n?|\n/);
142
- let count = 0;
143
- let index = 0;
144
- while (index < lines.length) {
145
- const line = lines[index];
146
- if (line.trim().length === 0) {
147
- index += 1;
148
- continue;
149
- }
150
- const headingText = heading(line);
151
- if (headingText !== null) {
152
- count += 2 + inlineStructuralItemCount(headingText);
153
- index += 1;
154
- continue;
155
- }
156
- const unorderedItem = unorderedListItem(line);
157
- const orderedItem = orderedListItem(line);
158
- if (unorderedItem !== null || orderedItem !== null) {
159
- const itemForLine = unorderedItem === null ? orderedListItem : unorderedListItem;
160
- count += 1;
161
- while (index < lines.length) {
162
- const item = itemForLine(lines[index]);
163
- if (item === null) break;
164
- count += 1 + inlineStructuralItemCount(item);
165
- index += 1;
166
- }
167
- continue;
168
- }
169
- const paragraphLines = [];
170
- while (index < lines.length) {
171
- const paragraphLine = lines[index];
172
- if (paragraphLine.trim().length === 0 || heading(paragraphLine) !== null || unorderedListItem(paragraphLine) !== null || orderedListItem(paragraphLine) !== null) break;
173
- paragraphLines.push(paragraphLine);
174
- index += 1;
175
- }
176
- count += 1 + inlineStructuralItemCount(paragraphLines.join(" "));
177
- }
178
- return count;
179
- }
180
- function renderMarkdown(document, source) {
181
- const fragment = document.createDocumentFragment();
182
- const lines = source.slice(0, MAX_MARKDOWN_CHARACTERS).split(/\r\n?|\n/);
183
- let index = 0;
184
- while (index < lines.length) {
185
- const line = lines[index];
186
- if (line.trim().length === 0) {
187
- index += 1;
188
- continue;
189
- }
190
- const headingText = heading(line);
191
- if (headingText !== null) {
192
- const paragraph = document.createElement("p");
193
- const strong = document.createElement("strong");
194
- appendInlineMarkdown(document, strong, headingText);
195
- paragraph.append(strong);
196
- fragment.append(paragraph);
197
- index += 1;
198
- continue;
199
- }
200
- const unorderedItem = unorderedListItem(line);
201
- const orderedItem = orderedListItem(line);
202
- if (unorderedItem !== null || orderedItem !== null) {
203
- const list = document.createElement(unorderedItem === null ? "ol" : "ul");
204
- const itemForLine = unorderedItem === null ? orderedListItem : unorderedListItem;
205
- while (index < lines.length) {
206
- const item = itemForLine(lines[index]);
207
- if (item === null) break;
208
- const listItem = document.createElement("li");
209
- appendInlineMarkdown(document, listItem, item);
210
- list.append(listItem);
211
- index += 1;
212
- }
213
- fragment.append(list);
214
- continue;
215
- }
216
- const paragraphLines = [];
217
- while (index < lines.length) {
218
- const paragraphLine = lines[index];
219
- if (paragraphLine.trim().length === 0 || heading(paragraphLine) !== null || unorderedListItem(paragraphLine) !== null || orderedListItem(paragraphLine) !== null) break;
220
- paragraphLines.push(paragraphLine);
221
- index += 1;
222
- }
223
- const paragraph = document.createElement("p");
224
- appendInlineMarkdown(document, paragraph, paragraphLines.join(" "));
225
- fragment.append(paragraph);
226
- }
227
- return fragment;
228
- }
229
- //#endregion
1
+ import { t as createPart } from "./dom.js";
2
+ import { r as renderMarkdown } from "./markdown.js";
230
3
  //#region src/live-chat/survey.ts
231
4
  /** Every element of the survey form carries a class under this block. */
232
5
  const SURVEY_CLASS = "vv-ai-survey";
@@ -389,4 +162,4 @@ function renderSurveyForm(document, fields, options) {
389
162
  };
390
163
  }
391
164
  //#endregion
392
- export { renderMarkdown as i, renderSurveyForm as n, countMarkdownStructuralItems as r, SURVEY_CLASS as t };
165
+ export { renderSurveyForm as n, SURVEY_CLASS as t };