@theonexai/blockspark-chat-widget 1.0.17
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/README.md +270 -0
- package/dist/ChatWidget-BM2lXfeE.cjs +2 -0
- package/dist/ChatWidget-BM2lXfeE.cjs.map +1 -0
- package/dist/ChatWidget-Cljd-Tfm.js +1356 -0
- package/dist/ChatWidget-Cljd-Tfm.js.map +1 -0
- package/dist/adapters/vue/index.d.ts +7 -0
- package/dist/adapters/vue/index.d.ts.map +1 -0
- package/dist/adapters/vue/useChatMode.d.ts +21 -0
- package/dist/adapters/vue/useChatMode.d.ts.map +1 -0
- package/dist/components/ChatWidget.d.ts +39 -0
- package/dist/components/ChatWidget.d.ts.map +1 -0
- package/dist/composables/useChatWidget.d.ts +35 -0
- package/dist/composables/useChatWidget.d.ts.map +1 -0
- package/dist/core/stateManager.d.ts +136 -0
- package/dist/core/stateManager.d.ts.map +1 -0
- package/dist/core/types.d.ts +64 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/entry/next.d.ts +9 -0
- package/dist/entry/next.d.ts.map +1 -0
- package/dist/entry/nuxt.d.ts +12 -0
- package/dist/entry/nuxt.d.ts.map +1 -0
- package/dist/entry/react.d.ts +10 -0
- package/dist/entry/react.d.ts.map +1 -0
- package/dist/entry/vanilla.d.ts +33 -0
- package/dist/entry/vanilla.d.ts.map +1 -0
- package/dist/entry/vite.d.ts +11 -0
- package/dist/entry/vite.d.ts.map +1 -0
- package/dist/entry/vue.d.ts +12 -0
- package/dist/entry/vue.d.ts.map +1 -0
- package/dist/hooks/useChatMode.d.ts +17 -0
- package/dist/hooks/useChatMode.d.ts.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +1383 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/nuxt.cjs.js +2 -0
- package/dist/nuxt.cjs.js.map +1 -0
- package/dist/nuxt.esm.js +9 -0
- package/dist/nuxt.esm.js.map +1 -0
- package/dist/sanitize-C8MB41vY.cjs +4 -0
- package/dist/sanitize-C8MB41vY.cjs.map +1 -0
- package/dist/sanitize-Cm1kskSD.js +1842 -0
- package/dist/sanitize-Cm1kskSD.js.map +1 -0
- package/dist/services/chatService.d.ts +144 -0
- package/dist/services/chatService.d.ts.map +1 -0
- package/dist/services/dialogflowBackendService.d.ts +36 -0
- package/dist/services/dialogflowBackendService.d.ts.map +1 -0
- package/dist/services/dialogflowClient.d.ts +36 -0
- package/dist/services/dialogflowClient.d.ts.map +1 -0
- package/dist/services/sessionManager.d.ts +13 -0
- package/dist/services/sessionManager.d.ts.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/dialogflowHandler.d.ts +31 -0
- package/dist/utils/dialogflowHandler.d.ts.map +1 -0
- package/dist/utils/frameworkDetector.d.ts +17 -0
- package/dist/utils/frameworkDetector.d.ts.map +1 -0
- package/dist/utils/sanitize.d.ts +25 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/ssr.d.ts +35 -0
- package/dist/utils/ssr.d.ts.map +1 -0
- package/dist/vue.cjs.js +2 -0
- package/dist/vue.cjs.js.map +1 -0
- package/dist/vue.esm.js +9 -0
- package/dist/vue.esm.js.map +1 -0
- package/package.json +114 -0
|
@@ -0,0 +1,1842 @@
|
|
|
1
|
+
const DEFAULT_BASE_URL$1 = typeof process !== "undefined" && process.env?.REACT_APP_BACKEND_BASE_URL || "http://localhost:8012";
|
|
2
|
+
async function createDialogflowSession(config, existingSessionId) {
|
|
3
|
+
try {
|
|
4
|
+
const backendBaseUrl = config.backendBaseUrl || DEFAULT_BASE_URL$1;
|
|
5
|
+
const requestBody = {
|
|
6
|
+
dfProjectId: config.dfProjectId,
|
|
7
|
+
dfLocation: config.dfLocation || "us-central1",
|
|
8
|
+
dfAgentId: config.dfAgentId,
|
|
9
|
+
languageCode: config.languageCode || "en"
|
|
10
|
+
};
|
|
11
|
+
if (existingSessionId) {
|
|
12
|
+
requestBody.sessionId = existingSessionId;
|
|
13
|
+
}
|
|
14
|
+
const response = await fetch(`${backendBaseUrl}/api/dialogflow/session/create`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json"
|
|
18
|
+
// Don't send X-Session-ID header for Dialogflow-only operations
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify(requestBody)
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const contentType2 = response.headers.get("content-type");
|
|
24
|
+
let error = {};
|
|
25
|
+
if (contentType2 && contentType2.includes("application/json")) {
|
|
26
|
+
try {
|
|
27
|
+
error = await response.json();
|
|
28
|
+
} catch {
|
|
29
|
+
error = {};
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
const text2 = await response.text();
|
|
33
|
+
throw new Error(
|
|
34
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. Response preview: ${text2.substring(0, 200)}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${backendBaseUrl}/api/dialogflow/session/create`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (response.status === 400) {
|
|
38
|
+
throw new Error(error.message || "Bad request. Please check your Dialogflow configuration.");
|
|
39
|
+
} else if (response.status === 401) {
|
|
40
|
+
throw new Error(error.message || "Authentication failed. Please check your backend configuration.");
|
|
41
|
+
} else if (response.status === 403) {
|
|
42
|
+
throw new Error(error.message || "Access forbidden. Please check your permissions.");
|
|
43
|
+
} else if (response.status === 404) {
|
|
44
|
+
throw new Error(error.message || "Dialogflow agent not found. Please check your project ID, location, and agent ID.");
|
|
45
|
+
} else if (response.status === 500) {
|
|
46
|
+
throw new Error(error.message || "Internal server error. Please try again later.");
|
|
47
|
+
}
|
|
48
|
+
throw new Error(error.message || `HTTP error! status: ${response.status}`);
|
|
49
|
+
}
|
|
50
|
+
const contentType = response.headers.get("content-type");
|
|
51
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
52
|
+
const clonedResponse = response.clone();
|
|
53
|
+
const text2 = await clonedResponse.text();
|
|
54
|
+
throw new Error(
|
|
55
|
+
`API endpoint returned non-JSON response. Status: ${response.status}. Content-Type: ${contentType || "unknown"}. Response body: ${text2.substring(0, 200)}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${backendBaseUrl}/api/dialogflow/session/create`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
if (data.status !== "success") {
|
|
60
|
+
throw new Error(data.message || "Failed to create session. Backend returned unsuccessful status.");
|
|
61
|
+
}
|
|
62
|
+
const responseData = data.data || data;
|
|
63
|
+
return {
|
|
64
|
+
session_id: responseData.session_id || data.session_id,
|
|
65
|
+
message: responseData.message || "Hello! How can I help you today?",
|
|
66
|
+
...responseData.richContent && { richContent: responseData.richContent }
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error("Error creating Dialogflow session:", error);
|
|
70
|
+
if (error.message?.includes("Failed to fetch") || error.message?.includes("CORS")) {
|
|
71
|
+
throw new Error("Network error. Unable to connect to backend. Please check your network connection and CORS settings.");
|
|
72
|
+
}
|
|
73
|
+
if (error.message && !error.message.includes("HTTP error")) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
throw new Error(error.message || "Failed to create Dialogflow session");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function sendDialogflowMessage(message, sessionId, config) {
|
|
80
|
+
try {
|
|
81
|
+
const backendBaseUrl = config.backendBaseUrl || DEFAULT_BASE_URL$1;
|
|
82
|
+
const requestBody = {
|
|
83
|
+
message: message.trim(),
|
|
84
|
+
dfProjectId: config.dfProjectId,
|
|
85
|
+
dfLocation: config.dfLocation || "us-central1",
|
|
86
|
+
dfAgentId: config.dfAgentId,
|
|
87
|
+
languageCode: config.languageCode || "en"
|
|
88
|
+
};
|
|
89
|
+
const response = await fetch(
|
|
90
|
+
`${backendBaseUrl}/api/dialogflow/session/${encodeURIComponent(sessionId)}/message`,
|
|
91
|
+
{
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "application/json"
|
|
95
|
+
// Don't send X-Session-ID header for Dialogflow-only operations
|
|
96
|
+
},
|
|
97
|
+
body: JSON.stringify(requestBody)
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
const contentType2 = response.headers.get("content-type");
|
|
102
|
+
let error = {};
|
|
103
|
+
if (contentType2 && contentType2.includes("application/json")) {
|
|
104
|
+
try {
|
|
105
|
+
error = await response.json();
|
|
106
|
+
} catch {
|
|
107
|
+
error = {};
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const text2 = await response.text();
|
|
111
|
+
throw new Error(
|
|
112
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. Response preview: ${text2.substring(0, 200)}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${backendBaseUrl}/api/dialogflow/session/${encodeURIComponent(sessionId)}/message`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (response.status === 400) {
|
|
116
|
+
throw new Error(error.message || "Bad request. Please check your message and configuration.");
|
|
117
|
+
} else if (response.status === 401) {
|
|
118
|
+
throw new Error(error.message || "Authentication failed. Please check your backend configuration.");
|
|
119
|
+
} else if (response.status === 403) {
|
|
120
|
+
throw new Error(error.message || "Access forbidden. Please check your permissions.");
|
|
121
|
+
} else if (response.status === 404) {
|
|
122
|
+
throw new Error(error.message || "Dialogflow session not found. Please check your session ID.");
|
|
123
|
+
} else if (response.status === 500) {
|
|
124
|
+
throw new Error(error.message || "Internal server error. Please try again later.");
|
|
125
|
+
}
|
|
126
|
+
throw new Error(error.message || `HTTP error! status: ${response.status}`);
|
|
127
|
+
}
|
|
128
|
+
const contentType = response.headers.get("content-type");
|
|
129
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
130
|
+
const clonedResponse = response.clone();
|
|
131
|
+
const text2 = await clonedResponse.text();
|
|
132
|
+
throw new Error(
|
|
133
|
+
`API endpoint returned non-JSON response. Status: ${response.status}. Content-Type: ${contentType || "unknown"}. Response body: ${text2.substring(0, 200)}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${backendBaseUrl}/api/dialogflow/session/${encodeURIComponent(sessionId)}/message`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
if (data.status !== "success") {
|
|
138
|
+
throw new Error(data.message || "Failed to send message. Backend returned unsuccessful status.");
|
|
139
|
+
}
|
|
140
|
+
const responseData = data.data || data;
|
|
141
|
+
return {
|
|
142
|
+
response: responseData.response || responseData.message || "I'm sorry, I didn't understand that. Could you please rephrase?",
|
|
143
|
+
session_id: responseData.session_id || data.session_id || sessionId,
|
|
144
|
+
source: responseData.source || "dialogflow",
|
|
145
|
+
timestamp: responseData.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
146
|
+
...responseData.richContent && { richContent: responseData.richContent },
|
|
147
|
+
...responseData.handoff !== void 0 && { handoff: responseData.handoff }
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Error sending message to Dialogflow:", error);
|
|
151
|
+
if (error.message?.includes("Failed to fetch") || error.message?.includes("CORS")) {
|
|
152
|
+
throw new Error("Network error. Unable to connect to backend. Please check your network connection and CORS settings.");
|
|
153
|
+
}
|
|
154
|
+
if (error.message && !error.message.includes("HTTP error")) {
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
throw new Error(error.message || "Failed to send message to Dialogflow");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const SESSION_KEY = "chat_session_id";
|
|
161
|
+
class ChatSessionManager {
|
|
162
|
+
constructor() {
|
|
163
|
+
this.sessionId = null;
|
|
164
|
+
this.sessionId = this.loadSessionId();
|
|
165
|
+
}
|
|
166
|
+
loadSessionId() {
|
|
167
|
+
if (typeof localStorage !== "undefined") {
|
|
168
|
+
return localStorage.getItem(SESSION_KEY);
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
saveSessionId(sessionId) {
|
|
173
|
+
this.sessionId = sessionId;
|
|
174
|
+
if (typeof localStorage !== "undefined") {
|
|
175
|
+
if (sessionId) {
|
|
176
|
+
localStorage.setItem(SESSION_KEY, sessionId);
|
|
177
|
+
} else {
|
|
178
|
+
localStorage.removeItem(SESSION_KEY);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
updateSessionFromResponse(responseData) {
|
|
183
|
+
const sid = responseData?.data?.session_id || responseData?.session_id;
|
|
184
|
+
if (sid && typeof sid === "string") {
|
|
185
|
+
this.saveSessionId(sid);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
getSessionId() {
|
|
189
|
+
return this.sessionId || "";
|
|
190
|
+
}
|
|
191
|
+
getSessionHeader() {
|
|
192
|
+
return {
|
|
193
|
+
"X-Session-ID": this.getSessionId()
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
let sessionManagerInstance = null;
|
|
198
|
+
function getSessionManager() {
|
|
199
|
+
if (!sessionManagerInstance) {
|
|
200
|
+
sessionManagerInstance = new ChatSessionManager();
|
|
201
|
+
}
|
|
202
|
+
return sessionManagerInstance;
|
|
203
|
+
}
|
|
204
|
+
class ChatResolvedError extends Error {
|
|
205
|
+
constructor(message = "chat_resolved") {
|
|
206
|
+
super(message);
|
|
207
|
+
this.reason = "chat_resolved";
|
|
208
|
+
this.name = "ChatResolvedError";
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const DEFAULT_BASE_URL = typeof process !== "undefined" && process.env?.REACT_APP_BACKEND_BASE_URL;
|
|
212
|
+
const DEFAULT_WS_URL = typeof process !== "undefined" && process.env?.REACT_APP_BACKEND_WS_URL;
|
|
213
|
+
class ChatService {
|
|
214
|
+
constructor(config = {}) {
|
|
215
|
+
this.ws = null;
|
|
216
|
+
this.wsReconnectAttempts = 0;
|
|
217
|
+
this.maxReconnectAttempts = 5;
|
|
218
|
+
this.reconnectTimeout = null;
|
|
219
|
+
this.pingInterval = null;
|
|
220
|
+
this.currentChatId = null;
|
|
221
|
+
this.currentSessionId = null;
|
|
222
|
+
this.messageHandlers = /* @__PURE__ */ new Set();
|
|
223
|
+
this.connectionHandlers = /* @__PURE__ */ new Set();
|
|
224
|
+
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
225
|
+
this.wsUrl = config.wsUrl || DEFAULT_WS_URL;
|
|
226
|
+
this.debug = config.debug || false;
|
|
227
|
+
this.sessionManager = getSessionManager();
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Start a new support chat session
|
|
231
|
+
* @param dialogflowSessionId - Optional: Dialogflow session ID
|
|
232
|
+
* @param customerName - Optional: Customer name
|
|
233
|
+
* @param customerEmail - Optional: Customer email
|
|
234
|
+
* @param customerMobile - Optional: Customer mobile number
|
|
235
|
+
*/
|
|
236
|
+
async startSupportChat(dialogflowSessionId, customerName, customerEmail, customerMobile) {
|
|
237
|
+
try {
|
|
238
|
+
const headers = {
|
|
239
|
+
"Content-Type": "application/json",
|
|
240
|
+
...this.sessionManager.getSessionHeader()
|
|
241
|
+
};
|
|
242
|
+
if (dialogflowSessionId) {
|
|
243
|
+
headers["X-Session-ID"] = dialogflowSessionId;
|
|
244
|
+
}
|
|
245
|
+
const body = {};
|
|
246
|
+
if (customerName) body.name = customerName;
|
|
247
|
+
if (customerEmail) body.email = customerEmail;
|
|
248
|
+
if (customerMobile) body.mobile = customerMobile;
|
|
249
|
+
const response = await fetch(`${this.baseUrl}/api/support/chat/start`, {
|
|
250
|
+
method: "POST",
|
|
251
|
+
headers,
|
|
252
|
+
body: JSON.stringify(body)
|
|
253
|
+
});
|
|
254
|
+
if (!response.ok) {
|
|
255
|
+
const contentType2 = response.headers.get("content-type");
|
|
256
|
+
let error = {};
|
|
257
|
+
if (contentType2 && contentType2.includes("application/json")) {
|
|
258
|
+
try {
|
|
259
|
+
error = await response.json();
|
|
260
|
+
} catch {
|
|
261
|
+
error = {};
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
const text2 = await response.text();
|
|
265
|
+
throw new Error(
|
|
266
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/start`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
throw new Error(
|
|
270
|
+
error.message || `HTTP error! status: ${response.status}`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const contentType = response.headers.get("content-type");
|
|
274
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
275
|
+
const text2 = await response.text();
|
|
276
|
+
throw new Error(
|
|
277
|
+
`API endpoint returned non-JSON response. Status: ${response.status}. Content-Type: ${contentType || "unknown"}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/start`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const data = await response.json();
|
|
281
|
+
this.sessionManager.updateSessionFromResponse(data);
|
|
282
|
+
if (data.status && data.data) {
|
|
283
|
+
return {
|
|
284
|
+
chat_id: data.data.chat_id,
|
|
285
|
+
session_id: data.data.session_id
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (data.chat_id && data.session_id) {
|
|
289
|
+
return {
|
|
290
|
+
chat_id: data.chat_id,
|
|
291
|
+
session_id: data.session_id
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
throw new Error("Invalid response format from chat start endpoint");
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.error("Error starting support chat:", error);
|
|
297
|
+
throw new Error(
|
|
298
|
+
error.message || "Failed to start support chat session"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Request handoff to human agent
|
|
304
|
+
* @param chatId - Chat ID (must be valid, not undefined)
|
|
305
|
+
* @param sessionId - Session ID
|
|
306
|
+
* @param reason - Optional: Reason for handoff
|
|
307
|
+
* @param dialogflowSessionId - Optional: Dialogflow session ID
|
|
308
|
+
* @param customerName - Optional: Customer name
|
|
309
|
+
* @param customerEmail - Optional: Customer email
|
|
310
|
+
* @param customerMobile - Optional: Customer mobile number
|
|
311
|
+
*/
|
|
312
|
+
async requestHandoff(chatId, sessionId, reason, dialogflowSessionId, customerName, customerEmail, customerMobile) {
|
|
313
|
+
if (!chatId || chatId === "undefined" || chatId === "null") {
|
|
314
|
+
throw new Error("Invalid chat_id. Chat must be initialized first.");
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
const headers = {
|
|
318
|
+
"Content-Type": "application/json",
|
|
319
|
+
...this.sessionManager.getSessionHeader()
|
|
320
|
+
};
|
|
321
|
+
if (sessionId) {
|
|
322
|
+
headers["X-Session-ID"] = sessionId;
|
|
323
|
+
} else if (dialogflowSessionId) {
|
|
324
|
+
headers["X-Session-ID"] = dialogflowSessionId;
|
|
325
|
+
}
|
|
326
|
+
const body = {};
|
|
327
|
+
if (reason) body.reason = reason;
|
|
328
|
+
if (customerName) body.name = customerName;
|
|
329
|
+
if (customerEmail) body.email = customerEmail;
|
|
330
|
+
if (customerMobile) body.mobile = customerMobile;
|
|
331
|
+
const response = await fetch(
|
|
332
|
+
`${this.baseUrl}/api/support/chat/${chatId}/handoff`,
|
|
333
|
+
{
|
|
334
|
+
method: "POST",
|
|
335
|
+
headers,
|
|
336
|
+
body: JSON.stringify(body)
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
const contentType = response.headers.get("content-type");
|
|
340
|
+
if (response.status === 400 || response.status === 404) {
|
|
341
|
+
let error = {};
|
|
342
|
+
if (contentType && contentType.includes("application/json")) {
|
|
343
|
+
try {
|
|
344
|
+
error = await response.json();
|
|
345
|
+
} catch {
|
|
346
|
+
error = {};
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
const text2 = await response.text();
|
|
350
|
+
throw new Error(
|
|
351
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the chat_id is invalid or the endpoint doesn't exist. URL: ${this.baseUrl}/api/support/chat/${chatId}/handoff`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
throw new Error(
|
|
355
|
+
error.message || "Invalid chat_id. Chat may have expired."
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
if (!response.ok) {
|
|
359
|
+
let error = {};
|
|
360
|
+
if (contentType && contentType.includes("application/json")) {
|
|
361
|
+
try {
|
|
362
|
+
error = await response.json();
|
|
363
|
+
} catch {
|
|
364
|
+
error = {};
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
const text2 = await response.text();
|
|
368
|
+
throw new Error(
|
|
369
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/${chatId}/handoff`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
throw new Error(
|
|
373
|
+
error.message || `HTTP error! status: ${response.status}`
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
377
|
+
const text2 = await response.text();
|
|
378
|
+
throw new Error(
|
|
379
|
+
`API endpoint returned non-JSON response. Status: ${response.status}. Content-Type: ${contentType || "unknown"}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/${chatId}/handoff`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
const data = await response.json();
|
|
383
|
+
this.sessionManager.updateSessionFromResponse(data);
|
|
384
|
+
if (data.status) {
|
|
385
|
+
return {
|
|
386
|
+
success: true,
|
|
387
|
+
message: data.message || data.data?.message
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
success: true,
|
|
392
|
+
message: data.message
|
|
393
|
+
};
|
|
394
|
+
} catch (error) {
|
|
395
|
+
console.error("Error requesting handoff:", error);
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Send message to agent via REST API
|
|
401
|
+
*/
|
|
402
|
+
async sendMessageToAgent(chatId, sessionId, message) {
|
|
403
|
+
try {
|
|
404
|
+
const headers = {
|
|
405
|
+
"Content-Type": "application/json",
|
|
406
|
+
...this.sessionManager.getSessionHeader()
|
|
407
|
+
};
|
|
408
|
+
if (sessionId) {
|
|
409
|
+
headers["X-Session-ID"] = sessionId;
|
|
410
|
+
}
|
|
411
|
+
const response = await fetch(
|
|
412
|
+
`${this.baseUrl}/api/support/chat/${chatId}/message`,
|
|
413
|
+
{
|
|
414
|
+
method: "POST",
|
|
415
|
+
headers,
|
|
416
|
+
body: JSON.stringify({
|
|
417
|
+
content: message
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
);
|
|
421
|
+
const contentType = response.headers.get("content-type");
|
|
422
|
+
if (response.status === 401 || response.status === 404) {
|
|
423
|
+
let error = {};
|
|
424
|
+
if (contentType && contentType.includes("application/json")) {
|
|
425
|
+
try {
|
|
426
|
+
error = await response.json();
|
|
427
|
+
} catch {
|
|
428
|
+
error = {};
|
|
429
|
+
}
|
|
430
|
+
} else {
|
|
431
|
+
const text2 = await response.text();
|
|
432
|
+
throw new Error(
|
|
433
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the chat_id is invalid or the endpoint doesn't exist. URL: ${this.baseUrl}/api/support/chat/${chatId}/message`
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
throw new Error(
|
|
437
|
+
error.message || "Chat not found or unauthorized"
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
if (!response.ok) {
|
|
441
|
+
let error = {};
|
|
442
|
+
if (contentType && contentType.includes("application/json")) {
|
|
443
|
+
try {
|
|
444
|
+
error = await response.json();
|
|
445
|
+
} catch {
|
|
446
|
+
error = {};
|
|
447
|
+
}
|
|
448
|
+
} else {
|
|
449
|
+
const text2 = await response.text();
|
|
450
|
+
throw new Error(
|
|
451
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/${chatId}/message`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
throw new Error(
|
|
455
|
+
error.message || `HTTP error! status: ${response.status}`
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
459
|
+
const text2 = await response.text();
|
|
460
|
+
throw new Error(
|
|
461
|
+
`API endpoint returned non-JSON response. Status: ${response.status}. Content-Type: ${contentType || "unknown"}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/${chatId}/message`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
const data = await response.json();
|
|
465
|
+
this.sessionManager.updateSessionFromResponse(data);
|
|
466
|
+
if (data?.ignored === true && data?.reason === "chat_resolved") {
|
|
467
|
+
throw new ChatResolvedError();
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
id: data.id,
|
|
471
|
+
sender_type: "customer",
|
|
472
|
+
content: message,
|
|
473
|
+
timestamp: data.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
474
|
+
};
|
|
475
|
+
} catch (error) {
|
|
476
|
+
if (error instanceof ChatResolvedError || error?.name === "ChatResolvedError") {
|
|
477
|
+
throw error;
|
|
478
|
+
}
|
|
479
|
+
console.error("Error sending message to agent:", error);
|
|
480
|
+
throw new Error(error.message || "Failed to send message to agent");
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Ensure chat is initialized - helper method
|
|
485
|
+
* Returns existing chat_id if valid, otherwise initializes new chat
|
|
486
|
+
* @param existingChatId - Existing chat ID to validate
|
|
487
|
+
* @param existingSessionId - Existing session ID
|
|
488
|
+
* @param dialogflowSessionId - Optional: Dialogflow session ID
|
|
489
|
+
* @param customerName - Optional: Customer name
|
|
490
|
+
* @param customerEmail - Optional: Customer email
|
|
491
|
+
* @param customerMobile - Optional: Customer mobile number
|
|
492
|
+
* @returns Promise with chat_id and session_id
|
|
493
|
+
*/
|
|
494
|
+
async ensureChatInitialized(existingChatId, existingSessionId, dialogflowSessionId, customerName, customerEmail, customerMobile) {
|
|
495
|
+
if (existingChatId && existingChatId !== "undefined" && existingChatId !== "null" && existingSessionId) {
|
|
496
|
+
return {
|
|
497
|
+
chat_id: existingChatId,
|
|
498
|
+
session_id: existingSessionId
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
return await this.startSupportChat(
|
|
502
|
+
dialogflowSessionId || null,
|
|
503
|
+
customerName || null,
|
|
504
|
+
customerEmail || null,
|
|
505
|
+
customerMobile || null
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Load message history
|
|
510
|
+
*/
|
|
511
|
+
async loadMessageHistory(chatId, sessionId) {
|
|
512
|
+
try {
|
|
513
|
+
const headers = {
|
|
514
|
+
...this.sessionManager.getSessionHeader()
|
|
515
|
+
};
|
|
516
|
+
if (sessionId) {
|
|
517
|
+
headers["X-Session-ID"] = sessionId;
|
|
518
|
+
}
|
|
519
|
+
const response = await fetch(
|
|
520
|
+
`${this.baseUrl}/api/support/chat/${chatId}/messages`,
|
|
521
|
+
{
|
|
522
|
+
method: "GET",
|
|
523
|
+
headers
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
const contentType = response.headers.get("content-type");
|
|
527
|
+
if (response.status === 401 || response.status === 404) {
|
|
528
|
+
let error = {};
|
|
529
|
+
if (contentType && contentType.includes("application/json")) {
|
|
530
|
+
try {
|
|
531
|
+
error = await response.json();
|
|
532
|
+
} catch {
|
|
533
|
+
error = {};
|
|
534
|
+
}
|
|
535
|
+
} else {
|
|
536
|
+
const text2 = await response.text();
|
|
537
|
+
throw new Error(
|
|
538
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the chat_id is invalid or the endpoint doesn't exist. URL: ${this.baseUrl}/api/support/chat/${chatId}/messages`
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
throw new Error(
|
|
542
|
+
error.message || "Chat not found or unauthorized"
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
if (!response.ok) {
|
|
546
|
+
let error = {};
|
|
547
|
+
if (contentType && contentType.includes("application/json")) {
|
|
548
|
+
try {
|
|
549
|
+
error = await response.json();
|
|
550
|
+
} catch {
|
|
551
|
+
error = {};
|
|
552
|
+
}
|
|
553
|
+
} else {
|
|
554
|
+
const text2 = await response.text();
|
|
555
|
+
throw new Error(
|
|
556
|
+
`API endpoint returned HTML instead of JSON. Status: ${response.status}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/${chatId}/messages`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
throw new Error(
|
|
560
|
+
error.message || `HTTP error! status: ${response.status}`
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
564
|
+
const text2 = await response.text();
|
|
565
|
+
throw new Error(
|
|
566
|
+
`API endpoint returned non-JSON response. Status: ${response.status}. Content-Type: ${contentType || "unknown"}. This usually means the endpoint doesn't exist or the server is misconfigured. URL: ${this.baseUrl}/api/support/chat/${chatId}/messages`
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
const data = await response.json();
|
|
570
|
+
this.sessionManager.updateSessionFromResponse(data);
|
|
571
|
+
return data.messages || [];
|
|
572
|
+
} catch (error) {
|
|
573
|
+
console.error("Error loading message history:", error);
|
|
574
|
+
throw new Error(error.message || "Failed to load message history");
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Connect to WebSocket
|
|
579
|
+
*/
|
|
580
|
+
connectWebSocket(chatId, sessionId, onMessage, onConnectionChange, onClose) {
|
|
581
|
+
if (this.reconnectTimeout) {
|
|
582
|
+
clearTimeout(this.reconnectTimeout);
|
|
583
|
+
this.reconnectTimeout = null;
|
|
584
|
+
}
|
|
585
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
586
|
+
if (this.debug) {
|
|
587
|
+
console.log("WebSocket already connected");
|
|
588
|
+
}
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
this.currentChatId = chatId;
|
|
592
|
+
this.currentSessionId = sessionId;
|
|
593
|
+
if (onMessage) {
|
|
594
|
+
this.messageHandlers.add(onMessage);
|
|
595
|
+
}
|
|
596
|
+
if (onConnectionChange) {
|
|
597
|
+
this.connectionHandlers.add(onConnectionChange);
|
|
598
|
+
}
|
|
599
|
+
const sessionIdToUse = sessionId || this.sessionManager.getSessionId() || "";
|
|
600
|
+
const wsUrl = `${this.wsUrl}/ws/support/${chatId}?X-Session-ID=${encodeURIComponent(sessionIdToUse)}`;
|
|
601
|
+
try {
|
|
602
|
+
this.ws = new WebSocket(wsUrl);
|
|
603
|
+
this.ws.onopen = () => {
|
|
604
|
+
if (this.debug) {
|
|
605
|
+
console.log("WebSocket connected to:", wsUrl);
|
|
606
|
+
}
|
|
607
|
+
console.log("✅ Customer WebSocket connected:", { chatId, sessionId, wsUrl });
|
|
608
|
+
this.wsReconnectAttempts = 0;
|
|
609
|
+
this.connectionHandlers.forEach((handler) => handler(true));
|
|
610
|
+
this.startPingInterval();
|
|
611
|
+
};
|
|
612
|
+
this.ws.onmessage = (event) => {
|
|
613
|
+
try {
|
|
614
|
+
const message = JSON.parse(event.data);
|
|
615
|
+
if (this.debug) {
|
|
616
|
+
console.log("WebSocket raw message received:", event.data);
|
|
617
|
+
console.log("WebSocket parsed message:", message);
|
|
618
|
+
}
|
|
619
|
+
if (message.session_id) {
|
|
620
|
+
this.sessionManager.updateSessionFromResponse({ session_id: message.session_id });
|
|
621
|
+
}
|
|
622
|
+
if (message.type === "agent_accepted" || message.type === "chat_resolved" || message.type === "chat_ended") {
|
|
623
|
+
console.log("🔔 Received notification message:", {
|
|
624
|
+
type: message.type,
|
|
625
|
+
chat_id: message.chat_id,
|
|
626
|
+
timestamp: message.timestamp,
|
|
627
|
+
to_agent: message.to_agent,
|
|
628
|
+
to_agent_id: message.to_agent_id
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
if (message.type === "pong") {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (this.debug && message.type === "message") {
|
|
635
|
+
console.log("Processing message type:", {
|
|
636
|
+
type: message.type,
|
|
637
|
+
sender_type: message.sender_type,
|
|
638
|
+
content: message.content?.substring(0, 50) + "...",
|
|
639
|
+
id: message.id
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
this.messageHandlers.forEach((handler) => handler(message));
|
|
643
|
+
} catch (error) {
|
|
644
|
+
console.error("Error parsing WebSocket message:", error);
|
|
645
|
+
if (this.debug) {
|
|
646
|
+
console.error("Raw message data:", event.data);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
this.ws.onerror = (error) => {
|
|
651
|
+
console.error("❌ WebSocket error:", error);
|
|
652
|
+
this.connectionHandlers.forEach((handler) => handler(false));
|
|
653
|
+
};
|
|
654
|
+
this.ws.onclose = (event) => {
|
|
655
|
+
if (this.debug) {
|
|
656
|
+
console.log("WebSocket closed:", event.code, event.reason);
|
|
657
|
+
}
|
|
658
|
+
console.log("🔌 Customer WebSocket closed:", { code: event.code, reason: event.reason, chatId });
|
|
659
|
+
this.stopPingInterval();
|
|
660
|
+
this.connectionHandlers.forEach((handler) => handler(false));
|
|
661
|
+
this.ws = null;
|
|
662
|
+
onClose?.(event);
|
|
663
|
+
if (event.code === 4e3) {
|
|
664
|
+
this.wsReconnectAttempts = this.maxReconnectAttempts;
|
|
665
|
+
this.currentChatId = null;
|
|
666
|
+
this.currentSessionId = null;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (this.wsReconnectAttempts < this.maxReconnectAttempts && this.currentChatId && this.currentSessionId) {
|
|
670
|
+
this.wsReconnectAttempts++;
|
|
671
|
+
const delay = Math.min(1e3 * Math.pow(2, this.wsReconnectAttempts), 3e4);
|
|
672
|
+
if (this.debug) {
|
|
673
|
+
console.log(`Reconnecting in ${delay}ms (attempt ${this.wsReconnectAttempts}/${this.maxReconnectAttempts})`);
|
|
674
|
+
}
|
|
675
|
+
this.reconnectTimeout = setTimeout(() => {
|
|
676
|
+
if (this.currentChatId && this.currentSessionId) {
|
|
677
|
+
this.connectWebSocket(this.currentChatId, this.currentSessionId, onMessage, onConnectionChange, onClose);
|
|
678
|
+
}
|
|
679
|
+
}, delay);
|
|
680
|
+
} else if (this.debug) {
|
|
681
|
+
console.error("Max reconnection attempts reached");
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
} catch (error) {
|
|
685
|
+
console.error("Error creating WebSocket connection:", error);
|
|
686
|
+
this.connectionHandlers.forEach((handler) => handler(false));
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Send message via WebSocket
|
|
691
|
+
*/
|
|
692
|
+
sendMessageViaWebSocket(message) {
|
|
693
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
try {
|
|
697
|
+
this.ws.send(
|
|
698
|
+
JSON.stringify({
|
|
699
|
+
type: "message",
|
|
700
|
+
content: message
|
|
701
|
+
})
|
|
702
|
+
);
|
|
703
|
+
return true;
|
|
704
|
+
} catch (error) {
|
|
705
|
+
console.error("Error sending message via WebSocket:", error);
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Send typing indicator via WebSocket
|
|
711
|
+
*/
|
|
712
|
+
sendTypingIndicator(type) {
|
|
713
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
try {
|
|
717
|
+
this.ws.send(
|
|
718
|
+
JSON.stringify({
|
|
719
|
+
type
|
|
720
|
+
})
|
|
721
|
+
);
|
|
722
|
+
return true;
|
|
723
|
+
} catch (error) {
|
|
724
|
+
console.error(`Error sending ${type} via WebSocket:`, error);
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Start ping interval to keep connection alive
|
|
730
|
+
*/
|
|
731
|
+
startPingInterval() {
|
|
732
|
+
this.stopPingInterval();
|
|
733
|
+
this.pingInterval = setInterval(() => {
|
|
734
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
735
|
+
try {
|
|
736
|
+
this.ws.send(JSON.stringify({ type: "ping" }));
|
|
737
|
+
} catch (error) {
|
|
738
|
+
console.error("Error sending ping:", error);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}, 3e4);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Stop ping interval
|
|
745
|
+
*/
|
|
746
|
+
stopPingInterval() {
|
|
747
|
+
if (this.pingInterval) {
|
|
748
|
+
clearInterval(this.pingInterval);
|
|
749
|
+
this.pingInterval = null;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Disconnect WebSocket
|
|
754
|
+
*/
|
|
755
|
+
disconnectWebSocket() {
|
|
756
|
+
if (this.reconnectTimeout) {
|
|
757
|
+
clearTimeout(this.reconnectTimeout);
|
|
758
|
+
this.reconnectTimeout = null;
|
|
759
|
+
}
|
|
760
|
+
this.stopPingInterval();
|
|
761
|
+
if (this.ws) {
|
|
762
|
+
this.ws.close();
|
|
763
|
+
this.ws = null;
|
|
764
|
+
}
|
|
765
|
+
this.messageHandlers.clear();
|
|
766
|
+
this.connectionHandlers.clear();
|
|
767
|
+
this.wsReconnectAttempts = 0;
|
|
768
|
+
this.currentChatId = null;
|
|
769
|
+
this.currentSessionId = null;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Check if WebSocket is connected
|
|
773
|
+
*/
|
|
774
|
+
isWebSocketConnected() {
|
|
775
|
+
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Remove message handler
|
|
779
|
+
*/
|
|
780
|
+
removeMessageHandler(handler) {
|
|
781
|
+
this.messageHandlers.delete(handler);
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Remove connection handler
|
|
785
|
+
*/
|
|
786
|
+
removeConnectionHandler(handler) {
|
|
787
|
+
this.connectionHandlers.delete(handler);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function createChatService(config) {
|
|
791
|
+
return new ChatService(config);
|
|
792
|
+
}
|
|
793
|
+
/*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
|
|
794
|
+
const {
|
|
795
|
+
entries,
|
|
796
|
+
setPrototypeOf,
|
|
797
|
+
isFrozen,
|
|
798
|
+
getPrototypeOf,
|
|
799
|
+
getOwnPropertyDescriptor
|
|
800
|
+
} = Object;
|
|
801
|
+
let {
|
|
802
|
+
freeze,
|
|
803
|
+
seal,
|
|
804
|
+
create
|
|
805
|
+
} = Object;
|
|
806
|
+
let {
|
|
807
|
+
apply,
|
|
808
|
+
construct
|
|
809
|
+
} = typeof Reflect !== "undefined" && Reflect;
|
|
810
|
+
if (!freeze) {
|
|
811
|
+
freeze = function freeze2(x) {
|
|
812
|
+
return x;
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
if (!seal) {
|
|
816
|
+
seal = function seal2(x) {
|
|
817
|
+
return x;
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
if (!apply) {
|
|
821
|
+
apply = function apply2(func, thisArg) {
|
|
822
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
823
|
+
args[_key - 2] = arguments[_key];
|
|
824
|
+
}
|
|
825
|
+
return func.apply(thisArg, args);
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
if (!construct) {
|
|
829
|
+
construct = function construct2(Func) {
|
|
830
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
831
|
+
args[_key2 - 1] = arguments[_key2];
|
|
832
|
+
}
|
|
833
|
+
return new Func(...args);
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
const arrayForEach = unapply(Array.prototype.forEach);
|
|
837
|
+
const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
838
|
+
const arrayPop = unapply(Array.prototype.pop);
|
|
839
|
+
const arrayPush = unapply(Array.prototype.push);
|
|
840
|
+
const arraySplice = unapply(Array.prototype.splice);
|
|
841
|
+
const stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
842
|
+
const stringToString = unapply(String.prototype.toString);
|
|
843
|
+
const stringMatch = unapply(String.prototype.match);
|
|
844
|
+
const stringReplace = unapply(String.prototype.replace);
|
|
845
|
+
const stringIndexOf = unapply(String.prototype.indexOf);
|
|
846
|
+
const stringTrim = unapply(String.prototype.trim);
|
|
847
|
+
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
848
|
+
const regExpTest = unapply(RegExp.prototype.test);
|
|
849
|
+
const typeErrorCreate = unconstruct(TypeError);
|
|
850
|
+
function unapply(func) {
|
|
851
|
+
return function(thisArg) {
|
|
852
|
+
if (thisArg instanceof RegExp) {
|
|
853
|
+
thisArg.lastIndex = 0;
|
|
854
|
+
}
|
|
855
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
856
|
+
args[_key3 - 1] = arguments[_key3];
|
|
857
|
+
}
|
|
858
|
+
return apply(func, thisArg, args);
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
function unconstruct(Func) {
|
|
862
|
+
return function() {
|
|
863
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
864
|
+
args[_key4] = arguments[_key4];
|
|
865
|
+
}
|
|
866
|
+
return construct(Func, args);
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function addToSet(set, array) {
|
|
870
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
871
|
+
if (setPrototypeOf) {
|
|
872
|
+
setPrototypeOf(set, null);
|
|
873
|
+
}
|
|
874
|
+
let l = array.length;
|
|
875
|
+
while (l--) {
|
|
876
|
+
let element = array[l];
|
|
877
|
+
if (typeof element === "string") {
|
|
878
|
+
const lcElement = transformCaseFunc(element);
|
|
879
|
+
if (lcElement !== element) {
|
|
880
|
+
if (!isFrozen(array)) {
|
|
881
|
+
array[l] = lcElement;
|
|
882
|
+
}
|
|
883
|
+
element = lcElement;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
set[element] = true;
|
|
887
|
+
}
|
|
888
|
+
return set;
|
|
889
|
+
}
|
|
890
|
+
function cleanArray(array) {
|
|
891
|
+
for (let index = 0; index < array.length; index++) {
|
|
892
|
+
const isPropertyExist = objectHasOwnProperty(array, index);
|
|
893
|
+
if (!isPropertyExist) {
|
|
894
|
+
array[index] = null;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return array;
|
|
898
|
+
}
|
|
899
|
+
function clone(object) {
|
|
900
|
+
const newObject = create(null);
|
|
901
|
+
for (const [property, value] of entries(object)) {
|
|
902
|
+
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
903
|
+
if (isPropertyExist) {
|
|
904
|
+
if (Array.isArray(value)) {
|
|
905
|
+
newObject[property] = cleanArray(value);
|
|
906
|
+
} else if (value && typeof value === "object" && value.constructor === Object) {
|
|
907
|
+
newObject[property] = clone(value);
|
|
908
|
+
} else {
|
|
909
|
+
newObject[property] = value;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
return newObject;
|
|
914
|
+
}
|
|
915
|
+
function lookupGetter(object, prop) {
|
|
916
|
+
while (object !== null) {
|
|
917
|
+
const desc = getOwnPropertyDescriptor(object, prop);
|
|
918
|
+
if (desc) {
|
|
919
|
+
if (desc.get) {
|
|
920
|
+
return unapply(desc.get);
|
|
921
|
+
}
|
|
922
|
+
if (typeof desc.value === "function") {
|
|
923
|
+
return unapply(desc.value);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
object = getPrototypeOf(object);
|
|
927
|
+
}
|
|
928
|
+
function fallbackValue() {
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
return fallbackValue;
|
|
932
|
+
}
|
|
933
|
+
const html$1 = freeze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]);
|
|
934
|
+
const svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
|
|
935
|
+
const svgFilters = freeze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]);
|
|
936
|
+
const svgDisallowed = freeze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]);
|
|
937
|
+
const mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
|
|
938
|
+
const mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
|
939
|
+
const text = freeze(["#text"]);
|
|
940
|
+
const html = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
|
|
941
|
+
const svg = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "mask-type", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
|
|
942
|
+
const mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
|
|
943
|
+
const xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
|
944
|
+
const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
|
945
|
+
const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
946
|
+
const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm);
|
|
947
|
+
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
948
|
+
const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
949
|
+
const IS_ALLOWED_URI = seal(
|
|
950
|
+
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
951
|
+
// eslint-disable-line no-useless-escape
|
|
952
|
+
);
|
|
953
|
+
const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
954
|
+
const ATTR_WHITESPACE = seal(
|
|
955
|
+
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
956
|
+
// eslint-disable-line no-control-regex
|
|
957
|
+
);
|
|
958
|
+
const DOCTYPE_NAME = seal(/^html$/i);
|
|
959
|
+
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
960
|
+
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
|
961
|
+
__proto__: null,
|
|
962
|
+
ARIA_ATTR,
|
|
963
|
+
ATTR_WHITESPACE,
|
|
964
|
+
CUSTOM_ELEMENT,
|
|
965
|
+
DATA_ATTR,
|
|
966
|
+
DOCTYPE_NAME,
|
|
967
|
+
ERB_EXPR,
|
|
968
|
+
IS_ALLOWED_URI,
|
|
969
|
+
IS_SCRIPT_OR_DATA,
|
|
970
|
+
MUSTACHE_EXPR,
|
|
971
|
+
TMPLIT_EXPR
|
|
972
|
+
});
|
|
973
|
+
const NODE_TYPE = {
|
|
974
|
+
element: 1,
|
|
975
|
+
text: 3,
|
|
976
|
+
// Deprecated
|
|
977
|
+
progressingInstruction: 7,
|
|
978
|
+
comment: 8,
|
|
979
|
+
document: 9
|
|
980
|
+
};
|
|
981
|
+
const getGlobal = function getGlobal2() {
|
|
982
|
+
return typeof window === "undefined" ? null : window;
|
|
983
|
+
};
|
|
984
|
+
const _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
|
|
985
|
+
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
let suffix = null;
|
|
989
|
+
const ATTR_NAME = "data-tt-policy-suffix";
|
|
990
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
|
991
|
+
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
992
|
+
}
|
|
993
|
+
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
994
|
+
try {
|
|
995
|
+
return trustedTypes.createPolicy(policyName, {
|
|
996
|
+
createHTML(html2) {
|
|
997
|
+
return html2;
|
|
998
|
+
},
|
|
999
|
+
createScriptURL(scriptUrl) {
|
|
1000
|
+
return scriptUrl;
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
} catch (_) {
|
|
1004
|
+
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
const _createHooksMap = function _createHooksMap2() {
|
|
1009
|
+
return {
|
|
1010
|
+
afterSanitizeAttributes: [],
|
|
1011
|
+
afterSanitizeElements: [],
|
|
1012
|
+
afterSanitizeShadowDOM: [],
|
|
1013
|
+
beforeSanitizeAttributes: [],
|
|
1014
|
+
beforeSanitizeElements: [],
|
|
1015
|
+
beforeSanitizeShadowDOM: [],
|
|
1016
|
+
uponSanitizeAttribute: [],
|
|
1017
|
+
uponSanitizeElement: [],
|
|
1018
|
+
uponSanitizeShadowNode: []
|
|
1019
|
+
};
|
|
1020
|
+
};
|
|
1021
|
+
function createDOMPurify() {
|
|
1022
|
+
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
1023
|
+
const DOMPurify = (root) => createDOMPurify(root);
|
|
1024
|
+
DOMPurify.version = "3.3.1";
|
|
1025
|
+
DOMPurify.removed = [];
|
|
1026
|
+
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
|
|
1027
|
+
DOMPurify.isSupported = false;
|
|
1028
|
+
return DOMPurify;
|
|
1029
|
+
}
|
|
1030
|
+
let {
|
|
1031
|
+
document
|
|
1032
|
+
} = window2;
|
|
1033
|
+
const originalDocument = document;
|
|
1034
|
+
const currentScript = originalDocument.currentScript;
|
|
1035
|
+
const {
|
|
1036
|
+
DocumentFragment,
|
|
1037
|
+
HTMLTemplateElement,
|
|
1038
|
+
Node,
|
|
1039
|
+
Element,
|
|
1040
|
+
NodeFilter,
|
|
1041
|
+
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
|
1042
|
+
HTMLFormElement,
|
|
1043
|
+
DOMParser,
|
|
1044
|
+
trustedTypes
|
|
1045
|
+
} = window2;
|
|
1046
|
+
const ElementPrototype = Element.prototype;
|
|
1047
|
+
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
1048
|
+
const remove = lookupGetter(ElementPrototype, "remove");
|
|
1049
|
+
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
1050
|
+
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
1051
|
+
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
1052
|
+
if (typeof HTMLTemplateElement === "function") {
|
|
1053
|
+
const template = document.createElement("template");
|
|
1054
|
+
if (template.content && template.content.ownerDocument) {
|
|
1055
|
+
document = template.content.ownerDocument;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
let trustedTypesPolicy;
|
|
1059
|
+
let emptyHTML = "";
|
|
1060
|
+
const {
|
|
1061
|
+
implementation,
|
|
1062
|
+
createNodeIterator,
|
|
1063
|
+
createDocumentFragment,
|
|
1064
|
+
getElementsByTagName
|
|
1065
|
+
} = document;
|
|
1066
|
+
const {
|
|
1067
|
+
importNode
|
|
1068
|
+
} = originalDocument;
|
|
1069
|
+
let hooks = _createHooksMap();
|
|
1070
|
+
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
1071
|
+
const {
|
|
1072
|
+
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
|
1073
|
+
ERB_EXPR: ERB_EXPR2,
|
|
1074
|
+
TMPLIT_EXPR: TMPLIT_EXPR2,
|
|
1075
|
+
DATA_ATTR: DATA_ATTR2,
|
|
1076
|
+
ARIA_ATTR: ARIA_ATTR2,
|
|
1077
|
+
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
|
1078
|
+
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
|
1079
|
+
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
|
1080
|
+
} = EXPRESSIONS;
|
|
1081
|
+
let {
|
|
1082
|
+
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
1083
|
+
} = EXPRESSIONS;
|
|
1084
|
+
let ALLOWED_TAGS = null;
|
|
1085
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
1086
|
+
let ALLOWED_ATTR = null;
|
|
1087
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
1088
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
1089
|
+
tagNameCheck: {
|
|
1090
|
+
writable: true,
|
|
1091
|
+
configurable: false,
|
|
1092
|
+
enumerable: true,
|
|
1093
|
+
value: null
|
|
1094
|
+
},
|
|
1095
|
+
attributeNameCheck: {
|
|
1096
|
+
writable: true,
|
|
1097
|
+
configurable: false,
|
|
1098
|
+
enumerable: true,
|
|
1099
|
+
value: null
|
|
1100
|
+
},
|
|
1101
|
+
allowCustomizedBuiltInElements: {
|
|
1102
|
+
writable: true,
|
|
1103
|
+
configurable: false,
|
|
1104
|
+
enumerable: true,
|
|
1105
|
+
value: false
|
|
1106
|
+
}
|
|
1107
|
+
}));
|
|
1108
|
+
let FORBID_TAGS = null;
|
|
1109
|
+
let FORBID_ATTR = null;
|
|
1110
|
+
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
1111
|
+
tagCheck: {
|
|
1112
|
+
writable: true,
|
|
1113
|
+
configurable: false,
|
|
1114
|
+
enumerable: true,
|
|
1115
|
+
value: null
|
|
1116
|
+
},
|
|
1117
|
+
attributeCheck: {
|
|
1118
|
+
writable: true,
|
|
1119
|
+
configurable: false,
|
|
1120
|
+
enumerable: true,
|
|
1121
|
+
value: null
|
|
1122
|
+
}
|
|
1123
|
+
}));
|
|
1124
|
+
let ALLOW_ARIA_ATTR = true;
|
|
1125
|
+
let ALLOW_DATA_ATTR = true;
|
|
1126
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
1127
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
1128
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
1129
|
+
let SAFE_FOR_XML = true;
|
|
1130
|
+
let WHOLE_DOCUMENT = false;
|
|
1131
|
+
let SET_CONFIG = false;
|
|
1132
|
+
let FORCE_BODY = false;
|
|
1133
|
+
let RETURN_DOM = false;
|
|
1134
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
1135
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
1136
|
+
let SANITIZE_DOM = true;
|
|
1137
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
1138
|
+
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
1139
|
+
let KEEP_CONTENT = true;
|
|
1140
|
+
let IN_PLACE = false;
|
|
1141
|
+
let USE_PROFILES = {};
|
|
1142
|
+
let FORBID_CONTENTS = null;
|
|
1143
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]);
|
|
1144
|
+
let DATA_URI_TAGS = null;
|
|
1145
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
1146
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
1147
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
|
1148
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
1149
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
1150
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
1151
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
1152
|
+
let IS_EMPTY_INPUT = false;
|
|
1153
|
+
let ALLOWED_NAMESPACES = null;
|
|
1154
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
1155
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
|
1156
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
|
1157
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
|
1158
|
+
let PARSER_MEDIA_TYPE = null;
|
|
1159
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
1160
|
+
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
1161
|
+
let transformCaseFunc = null;
|
|
1162
|
+
let CONFIG = null;
|
|
1163
|
+
const formElement = document.createElement("form");
|
|
1164
|
+
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
|
1165
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
1166
|
+
};
|
|
1167
|
+
const _parseConfig = function _parseConfig2() {
|
|
1168
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1169
|
+
if (CONFIG && CONFIG === cfg) {
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if (!cfg || typeof cfg !== "object") {
|
|
1173
|
+
cfg = {};
|
|
1174
|
+
}
|
|
1175
|
+
cfg = clone(cfg);
|
|
1176
|
+
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
|
1177
|
+
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
1178
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
1179
|
+
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
1180
|
+
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
1181
|
+
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
1182
|
+
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, "ADD_URI_SAFE_ATTR") ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
|
1183
|
+
DATA_URI_TAGS = objectHasOwnProperty(cfg, "ADD_DATA_URI_TAGS") ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
|
|
1184
|
+
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
1185
|
+
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
|
|
1186
|
+
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
|
|
1187
|
+
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
|
1188
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
1189
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
1190
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
1191
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
1192
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
1193
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
1194
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
1195
|
+
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
1196
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
1197
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
1198
|
+
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
1199
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
1200
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
1201
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
1202
|
+
IN_PLACE = cfg.IN_PLACE || false;
|
|
1203
|
+
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
1204
|
+
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
1205
|
+
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
|
1206
|
+
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
|
1207
|
+
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
1208
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
1209
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
1210
|
+
}
|
|
1211
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
1212
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
1213
|
+
}
|
|
1214
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
|
1215
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
1216
|
+
}
|
|
1217
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1218
|
+
ALLOW_DATA_ATTR = false;
|
|
1219
|
+
}
|
|
1220
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
1221
|
+
RETURN_DOM = true;
|
|
1222
|
+
}
|
|
1223
|
+
if (USE_PROFILES) {
|
|
1224
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
1225
|
+
ALLOWED_ATTR = [];
|
|
1226
|
+
if (USE_PROFILES.html === true) {
|
|
1227
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
1228
|
+
addToSet(ALLOWED_ATTR, html);
|
|
1229
|
+
}
|
|
1230
|
+
if (USE_PROFILES.svg === true) {
|
|
1231
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
1232
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
1233
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1234
|
+
}
|
|
1235
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
1236
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
1237
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
1238
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1239
|
+
}
|
|
1240
|
+
if (USE_PROFILES.mathMl === true) {
|
|
1241
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
1242
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
1243
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
if (cfg.ADD_TAGS) {
|
|
1247
|
+
if (typeof cfg.ADD_TAGS === "function") {
|
|
1248
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
1249
|
+
} else {
|
|
1250
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
1251
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
1252
|
+
}
|
|
1253
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
if (cfg.ADD_ATTR) {
|
|
1257
|
+
if (typeof cfg.ADD_ATTR === "function") {
|
|
1258
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
1259
|
+
} else {
|
|
1260
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
1261
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
1262
|
+
}
|
|
1263
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
1267
|
+
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
1268
|
+
}
|
|
1269
|
+
if (cfg.FORBID_CONTENTS) {
|
|
1270
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
1271
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1272
|
+
}
|
|
1273
|
+
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
1274
|
+
}
|
|
1275
|
+
if (cfg.ADD_FORBID_CONTENTS) {
|
|
1276
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
1277
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1278
|
+
}
|
|
1279
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
1280
|
+
}
|
|
1281
|
+
if (KEEP_CONTENT) {
|
|
1282
|
+
ALLOWED_TAGS["#text"] = true;
|
|
1283
|
+
}
|
|
1284
|
+
if (WHOLE_DOCUMENT) {
|
|
1285
|
+
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
|
1286
|
+
}
|
|
1287
|
+
if (ALLOWED_TAGS.table) {
|
|
1288
|
+
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
1289
|
+
delete FORBID_TAGS.tbody;
|
|
1290
|
+
}
|
|
1291
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
1292
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
|
1293
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
1294
|
+
}
|
|
1295
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
|
1296
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
1297
|
+
}
|
|
1298
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
1299
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
1300
|
+
} else {
|
|
1301
|
+
if (trustedTypesPolicy === void 0) {
|
|
1302
|
+
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
1303
|
+
}
|
|
1304
|
+
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
|
1305
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
if (freeze) {
|
|
1309
|
+
freeze(cfg);
|
|
1310
|
+
}
|
|
1311
|
+
CONFIG = cfg;
|
|
1312
|
+
};
|
|
1313
|
+
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
1314
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
1315
|
+
const _checkValidNamespace = function _checkValidNamespace2(element) {
|
|
1316
|
+
let parent = getParentNode(element);
|
|
1317
|
+
if (!parent || !parent.tagName) {
|
|
1318
|
+
parent = {
|
|
1319
|
+
namespaceURI: NAMESPACE,
|
|
1320
|
+
tagName: "template"
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
const tagName = stringToLowerCase(element.tagName);
|
|
1324
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
1325
|
+
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
1326
|
+
return false;
|
|
1327
|
+
}
|
|
1328
|
+
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
1329
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
1330
|
+
return tagName === "svg";
|
|
1331
|
+
}
|
|
1332
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
1333
|
+
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
1334
|
+
}
|
|
1335
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
1336
|
+
}
|
|
1337
|
+
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
1338
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
1339
|
+
return tagName === "math";
|
|
1340
|
+
}
|
|
1341
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
1342
|
+
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
1343
|
+
}
|
|
1344
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
1345
|
+
}
|
|
1346
|
+
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
1347
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
1348
|
+
return false;
|
|
1349
|
+
}
|
|
1350
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
1351
|
+
return false;
|
|
1352
|
+
}
|
|
1353
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
1354
|
+
}
|
|
1355
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
1356
|
+
return true;
|
|
1357
|
+
}
|
|
1358
|
+
return false;
|
|
1359
|
+
};
|
|
1360
|
+
const _forceRemove = function _forceRemove2(node) {
|
|
1361
|
+
arrayPush(DOMPurify.removed, {
|
|
1362
|
+
element: node
|
|
1363
|
+
});
|
|
1364
|
+
try {
|
|
1365
|
+
getParentNode(node).removeChild(node);
|
|
1366
|
+
} catch (_) {
|
|
1367
|
+
remove(node);
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
const _removeAttribute = function _removeAttribute2(name, element) {
|
|
1371
|
+
try {
|
|
1372
|
+
arrayPush(DOMPurify.removed, {
|
|
1373
|
+
attribute: element.getAttributeNode(name),
|
|
1374
|
+
from: element
|
|
1375
|
+
});
|
|
1376
|
+
} catch (_) {
|
|
1377
|
+
arrayPush(DOMPurify.removed, {
|
|
1378
|
+
attribute: null,
|
|
1379
|
+
from: element
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
element.removeAttribute(name);
|
|
1383
|
+
if (name === "is") {
|
|
1384
|
+
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
1385
|
+
try {
|
|
1386
|
+
_forceRemove(element);
|
|
1387
|
+
} catch (_) {
|
|
1388
|
+
}
|
|
1389
|
+
} else {
|
|
1390
|
+
try {
|
|
1391
|
+
element.setAttribute(name, "");
|
|
1392
|
+
} catch (_) {
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
const _initDocument = function _initDocument2(dirty) {
|
|
1398
|
+
let doc = null;
|
|
1399
|
+
let leadingWhitespace = null;
|
|
1400
|
+
if (FORCE_BODY) {
|
|
1401
|
+
dirty = "<remove></remove>" + dirty;
|
|
1402
|
+
} else {
|
|
1403
|
+
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
1404
|
+
leadingWhitespace = matches && matches[0];
|
|
1405
|
+
}
|
|
1406
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
|
1407
|
+
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
|
|
1408
|
+
}
|
|
1409
|
+
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
1410
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
1411
|
+
try {
|
|
1412
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
1413
|
+
} catch (_) {
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
if (!doc || !doc.documentElement) {
|
|
1417
|
+
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
1418
|
+
try {
|
|
1419
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
1420
|
+
} catch (_) {
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
const body = doc.body || doc.documentElement;
|
|
1424
|
+
if (dirty && leadingWhitespace) {
|
|
1425
|
+
body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
1426
|
+
}
|
|
1427
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
1428
|
+
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
1429
|
+
}
|
|
1430
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
1431
|
+
};
|
|
1432
|
+
const _createNodeIterator = function _createNodeIterator2(root) {
|
|
1433
|
+
return createNodeIterator.call(
|
|
1434
|
+
root.ownerDocument || root,
|
|
1435
|
+
root,
|
|
1436
|
+
// eslint-disable-next-line no-bitwise
|
|
1437
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
|
1438
|
+
null
|
|
1439
|
+
);
|
|
1440
|
+
};
|
|
1441
|
+
const _isClobbered = function _isClobbered2(element) {
|
|
1442
|
+
return element instanceof HTMLFormElement && (typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function");
|
|
1443
|
+
};
|
|
1444
|
+
const _isNode = function _isNode2(value) {
|
|
1445
|
+
return typeof Node === "function" && value instanceof Node;
|
|
1446
|
+
};
|
|
1447
|
+
function _executeHooks(hooks2, currentNode, data) {
|
|
1448
|
+
arrayForEach(hooks2, (hook) => {
|
|
1449
|
+
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
const _sanitizeElements = function _sanitizeElements2(currentNode) {
|
|
1453
|
+
let content = null;
|
|
1454
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
1455
|
+
if (_isClobbered(currentNode)) {
|
|
1456
|
+
_forceRemove(currentNode);
|
|
1457
|
+
return true;
|
|
1458
|
+
}
|
|
1459
|
+
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
1460
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
1461
|
+
tagName,
|
|
1462
|
+
allowedTags: ALLOWED_TAGS
|
|
1463
|
+
});
|
|
1464
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
|
|
1465
|
+
_forceRemove(currentNode);
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
1469
|
+
_forceRemove(currentNode);
|
|
1470
|
+
return true;
|
|
1471
|
+
}
|
|
1472
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
1473
|
+
_forceRemove(currentNode);
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1476
|
+
if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
|
|
1477
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
1478
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
1482
|
+
return false;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
1486
|
+
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
1487
|
+
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
1488
|
+
if (childNodes && parentNode) {
|
|
1489
|
+
const childCount = childNodes.length;
|
|
1490
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
1491
|
+
const childClone = cloneNode(childNodes[i], true);
|
|
1492
|
+
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
1493
|
+
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
_forceRemove(currentNode);
|
|
1498
|
+
return true;
|
|
1499
|
+
}
|
|
1500
|
+
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
1501
|
+
_forceRemove(currentNode);
|
|
1502
|
+
return true;
|
|
1503
|
+
}
|
|
1504
|
+
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
1505
|
+
_forceRemove(currentNode);
|
|
1506
|
+
return true;
|
|
1507
|
+
}
|
|
1508
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
1509
|
+
content = currentNode.textContent;
|
|
1510
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
1511
|
+
content = stringReplace(content, expr, " ");
|
|
1512
|
+
});
|
|
1513
|
+
if (currentNode.textContent !== content) {
|
|
1514
|
+
arrayPush(DOMPurify.removed, {
|
|
1515
|
+
element: currentNode.cloneNode()
|
|
1516
|
+
});
|
|
1517
|
+
currentNode.textContent = content;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
1521
|
+
return false;
|
|
1522
|
+
};
|
|
1523
|
+
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
|
1524
|
+
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document || value in formElement)) {
|
|
1525
|
+
return false;
|
|
1526
|
+
}
|
|
1527
|
+
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
|
1528
|
+
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
|
1529
|
+
else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ;
|
|
1530
|
+
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
1531
|
+
if (
|
|
1532
|
+
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
1533
|
+
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1534
|
+
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
1535
|
+
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
1536
|
+
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1537
|
+
lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))
|
|
1538
|
+
) ;
|
|
1539
|
+
else {
|
|
1540
|
+
return false;
|
|
1541
|
+
}
|
|
1542
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
|
1543
|
+
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
1544
|
+
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
|
1545
|
+
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
1546
|
+
else if (value) {
|
|
1547
|
+
return false;
|
|
1548
|
+
} else ;
|
|
1549
|
+
return true;
|
|
1550
|
+
};
|
|
1551
|
+
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
|
1552
|
+
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
|
1553
|
+
};
|
|
1554
|
+
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
|
1555
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
1556
|
+
const {
|
|
1557
|
+
attributes
|
|
1558
|
+
} = currentNode;
|
|
1559
|
+
if (!attributes || _isClobbered(currentNode)) {
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
const hookEvent = {
|
|
1563
|
+
attrName: "",
|
|
1564
|
+
attrValue: "",
|
|
1565
|
+
keepAttr: true,
|
|
1566
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
1567
|
+
forceKeepAttr: void 0
|
|
1568
|
+
};
|
|
1569
|
+
let l = attributes.length;
|
|
1570
|
+
while (l--) {
|
|
1571
|
+
const attr = attributes[l];
|
|
1572
|
+
const {
|
|
1573
|
+
name,
|
|
1574
|
+
namespaceURI,
|
|
1575
|
+
value: attrValue
|
|
1576
|
+
} = attr;
|
|
1577
|
+
const lcName = transformCaseFunc(name);
|
|
1578
|
+
const initValue = attrValue;
|
|
1579
|
+
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
1580
|
+
hookEvent.attrName = lcName;
|
|
1581
|
+
hookEvent.attrValue = value;
|
|
1582
|
+
hookEvent.keepAttr = true;
|
|
1583
|
+
hookEvent.forceKeepAttr = void 0;
|
|
1584
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
1585
|
+
value = hookEvent.attrValue;
|
|
1586
|
+
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
|
1587
|
+
_removeAttribute(name, currentNode);
|
|
1588
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1589
|
+
}
|
|
1590
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
|
|
1591
|
+
_removeAttribute(name, currentNode);
|
|
1592
|
+
continue;
|
|
1593
|
+
}
|
|
1594
|
+
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
1595
|
+
_removeAttribute(name, currentNode);
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1598
|
+
if (hookEvent.forceKeepAttr) {
|
|
1599
|
+
continue;
|
|
1600
|
+
}
|
|
1601
|
+
if (!hookEvent.keepAttr) {
|
|
1602
|
+
_removeAttribute(name, currentNode);
|
|
1603
|
+
continue;
|
|
1604
|
+
}
|
|
1605
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
1606
|
+
_removeAttribute(name, currentNode);
|
|
1607
|
+
continue;
|
|
1608
|
+
}
|
|
1609
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1610
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
1611
|
+
value = stringReplace(value, expr, " ");
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
1615
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
1616
|
+
_removeAttribute(name, currentNode);
|
|
1617
|
+
continue;
|
|
1618
|
+
}
|
|
1619
|
+
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
|
1620
|
+
if (namespaceURI) ;
|
|
1621
|
+
else {
|
|
1622
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
1623
|
+
case "TrustedHTML": {
|
|
1624
|
+
value = trustedTypesPolicy.createHTML(value);
|
|
1625
|
+
break;
|
|
1626
|
+
}
|
|
1627
|
+
case "TrustedScriptURL": {
|
|
1628
|
+
value = trustedTypesPolicy.createScriptURL(value);
|
|
1629
|
+
break;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (value !== initValue) {
|
|
1635
|
+
try {
|
|
1636
|
+
if (namespaceURI) {
|
|
1637
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
1638
|
+
} else {
|
|
1639
|
+
currentNode.setAttribute(name, value);
|
|
1640
|
+
}
|
|
1641
|
+
if (_isClobbered(currentNode)) {
|
|
1642
|
+
_forceRemove(currentNode);
|
|
1643
|
+
} else {
|
|
1644
|
+
arrayPop(DOMPurify.removed);
|
|
1645
|
+
}
|
|
1646
|
+
} catch (_) {
|
|
1647
|
+
_removeAttribute(name, currentNode);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
1652
|
+
};
|
|
1653
|
+
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
|
1654
|
+
let shadowNode = null;
|
|
1655
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
1656
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
1657
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
1658
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
1659
|
+
_sanitizeElements(shadowNode);
|
|
1660
|
+
_sanitizeAttributes(shadowNode);
|
|
1661
|
+
if (shadowNode.content instanceof DocumentFragment) {
|
|
1662
|
+
_sanitizeShadowDOM2(shadowNode.content);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
1666
|
+
};
|
|
1667
|
+
DOMPurify.sanitize = function(dirty) {
|
|
1668
|
+
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1669
|
+
let body = null;
|
|
1670
|
+
let importedNode = null;
|
|
1671
|
+
let currentNode = null;
|
|
1672
|
+
let returnNode = null;
|
|
1673
|
+
IS_EMPTY_INPUT = !dirty;
|
|
1674
|
+
if (IS_EMPTY_INPUT) {
|
|
1675
|
+
dirty = "<!-->";
|
|
1676
|
+
}
|
|
1677
|
+
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
|
1678
|
+
if (typeof dirty.toString === "function") {
|
|
1679
|
+
dirty = dirty.toString();
|
|
1680
|
+
if (typeof dirty !== "string") {
|
|
1681
|
+
throw typeErrorCreate("dirty is not a string, aborting");
|
|
1682
|
+
}
|
|
1683
|
+
} else {
|
|
1684
|
+
throw typeErrorCreate("toString is not a function");
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
if (!DOMPurify.isSupported) {
|
|
1688
|
+
return dirty;
|
|
1689
|
+
}
|
|
1690
|
+
if (!SET_CONFIG) {
|
|
1691
|
+
_parseConfig(cfg);
|
|
1692
|
+
}
|
|
1693
|
+
DOMPurify.removed = [];
|
|
1694
|
+
if (typeof dirty === "string") {
|
|
1695
|
+
IN_PLACE = false;
|
|
1696
|
+
}
|
|
1697
|
+
if (IN_PLACE) {
|
|
1698
|
+
if (dirty.nodeName) {
|
|
1699
|
+
const tagName = transformCaseFunc(dirty.nodeName);
|
|
1700
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
1701
|
+
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
} else if (dirty instanceof Node) {
|
|
1705
|
+
body = _initDocument("<!---->");
|
|
1706
|
+
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
1707
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
|
1708
|
+
body = importedNode;
|
|
1709
|
+
} else if (importedNode.nodeName === "HTML") {
|
|
1710
|
+
body = importedNode;
|
|
1711
|
+
} else {
|
|
1712
|
+
body.appendChild(importedNode);
|
|
1713
|
+
}
|
|
1714
|
+
} else {
|
|
1715
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
|
1716
|
+
dirty.indexOf("<") === -1) {
|
|
1717
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
1718
|
+
}
|
|
1719
|
+
body = _initDocument(dirty);
|
|
1720
|
+
if (!body) {
|
|
1721
|
+
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
if (body && FORCE_BODY) {
|
|
1725
|
+
_forceRemove(body.firstChild);
|
|
1726
|
+
}
|
|
1727
|
+
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
1728
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
1729
|
+
_sanitizeElements(currentNode);
|
|
1730
|
+
_sanitizeAttributes(currentNode);
|
|
1731
|
+
if (currentNode.content instanceof DocumentFragment) {
|
|
1732
|
+
_sanitizeShadowDOM(currentNode.content);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
if (IN_PLACE) {
|
|
1736
|
+
return dirty;
|
|
1737
|
+
}
|
|
1738
|
+
if (RETURN_DOM) {
|
|
1739
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
1740
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
1741
|
+
while (body.firstChild) {
|
|
1742
|
+
returnNode.appendChild(body.firstChild);
|
|
1743
|
+
}
|
|
1744
|
+
} else {
|
|
1745
|
+
returnNode = body;
|
|
1746
|
+
}
|
|
1747
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
1748
|
+
returnNode = importNode.call(originalDocument, returnNode, true);
|
|
1749
|
+
}
|
|
1750
|
+
return returnNode;
|
|
1751
|
+
}
|
|
1752
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
1753
|
+
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
1754
|
+
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
1755
|
+
}
|
|
1756
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1757
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
1758
|
+
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
1762
|
+
};
|
|
1763
|
+
DOMPurify.setConfig = function() {
|
|
1764
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1765
|
+
_parseConfig(cfg);
|
|
1766
|
+
SET_CONFIG = true;
|
|
1767
|
+
};
|
|
1768
|
+
DOMPurify.clearConfig = function() {
|
|
1769
|
+
CONFIG = null;
|
|
1770
|
+
SET_CONFIG = false;
|
|
1771
|
+
};
|
|
1772
|
+
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
1773
|
+
if (!CONFIG) {
|
|
1774
|
+
_parseConfig({});
|
|
1775
|
+
}
|
|
1776
|
+
const lcTag = transformCaseFunc(tag);
|
|
1777
|
+
const lcName = transformCaseFunc(attr);
|
|
1778
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
1779
|
+
};
|
|
1780
|
+
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
1781
|
+
if (typeof hookFunction !== "function") {
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
1785
|
+
};
|
|
1786
|
+
DOMPurify.removeHook = function(entryPoint, hookFunction) {
|
|
1787
|
+
if (hookFunction !== void 0) {
|
|
1788
|
+
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
1789
|
+
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
1790
|
+
}
|
|
1791
|
+
return arrayPop(hooks[entryPoint]);
|
|
1792
|
+
};
|
|
1793
|
+
DOMPurify.removeHooks = function(entryPoint) {
|
|
1794
|
+
hooks[entryPoint] = [];
|
|
1795
|
+
};
|
|
1796
|
+
DOMPurify.removeAllHooks = function() {
|
|
1797
|
+
hooks = _createHooksMap();
|
|
1798
|
+
};
|
|
1799
|
+
return DOMPurify;
|
|
1800
|
+
}
|
|
1801
|
+
var purify = createDOMPurify();
|
|
1802
|
+
function sanitizeHtml(html2, options) {
|
|
1803
|
+
const defaultOptions = {
|
|
1804
|
+
ALLOWED_TAGS: ["a", "b", "strong", "i", "em", "u", "br", "p", "span"],
|
|
1805
|
+
ALLOWED_ATTR: ["href", "target", "rel"],
|
|
1806
|
+
ALLOW_DATA_ATTR: false
|
|
1807
|
+
};
|
|
1808
|
+
const config = {
|
|
1809
|
+
...defaultOptions,
|
|
1810
|
+
...options?.allowedTags && { ALLOWED_TAGS: options.allowedTags },
|
|
1811
|
+
...options?.allowedAttributes && {
|
|
1812
|
+
ALLOWED_ATTR: Object.keys(options.allowedAttributes).flatMap(
|
|
1813
|
+
(key) => options.allowedAttributes[key]
|
|
1814
|
+
)
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
const result = purify.sanitize(html2, config);
|
|
1818
|
+
return typeof result === "string" ? result : String(result);
|
|
1819
|
+
}
|
|
1820
|
+
function linkifyText(text2) {
|
|
1821
|
+
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
|
1822
|
+
const linked = text2.replace(
|
|
1823
|
+
urlRegex,
|
|
1824
|
+
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'
|
|
1825
|
+
);
|
|
1826
|
+
return sanitizeHtml(linked, {
|
|
1827
|
+
allowedTags: ["a"],
|
|
1828
|
+
allowedAttributes: { a: ["href", "target", "rel"] }
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
function safeLinkifyText(text2) {
|
|
1832
|
+
return linkifyText(text2);
|
|
1833
|
+
}
|
|
1834
|
+
export {
|
|
1835
|
+
ChatResolvedError as C,
|
|
1836
|
+
createDialogflowSession as a,
|
|
1837
|
+
safeLinkifyText as b,
|
|
1838
|
+
createChatService as c,
|
|
1839
|
+
linkifyText as l,
|
|
1840
|
+
sendDialogflowMessage as s
|
|
1841
|
+
};
|
|
1842
|
+
//# sourceMappingURL=sanitize-Cm1kskSD.js.map
|