@brainfish-ai/widgets-initiator 1.12.0 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/utils/brainfishQueue.d.ts +1 -0
- package/dist/types/web.d.ts +2 -2
- package/dist/web.cjs.js +1 -169
- package/dist/web.es.js +2023 -0
- package/dist/web.js +1 -974
- package/package.json +5 -4
- package/dist/index.cjs.js +0 -2
- package/dist/index.js +0 -13
- package/dist/types/utils/isIOS14OrBelow.d.ts +0 -1
- package/dist/types/utils/isIOS14OrBelow.test.d.ts +0 -1
package/dist/web.es.js
ADDED
|
@@ -0,0 +1,2023 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
;
|
|
5
|
+
!function() {
|
|
6
|
+
try {
|
|
7
|
+
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
|
|
8
|
+
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "13ff9fe0-f844-427a-8e83-9c170fcd5721", e._sentryDebugIdIdentifier = "sentry-dbid-13ff9fe0-f844-427a-8e83-9c170fcd5721");
|
|
9
|
+
} catch (e2) {
|
|
10
|
+
}
|
|
11
|
+
}();
|
|
12
|
+
class InvalidTokenError extends Error {
|
|
13
|
+
}
|
|
14
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
15
|
+
function b64DecodeUnicode(str) {
|
|
16
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
17
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
18
|
+
if (code.length < 2) {
|
|
19
|
+
code = "0" + code;
|
|
20
|
+
}
|
|
21
|
+
return "%" + code;
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function base64UrlDecode(str) {
|
|
25
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
26
|
+
switch (output.length % 4) {
|
|
27
|
+
case 0:
|
|
28
|
+
break;
|
|
29
|
+
case 2:
|
|
30
|
+
output += "==";
|
|
31
|
+
break;
|
|
32
|
+
case 3:
|
|
33
|
+
output += "=";
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
throw new Error("base64 string is not of the correct length");
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return b64DecodeUnicode(output);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
return atob(output);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function jwtDecode(token, options) {
|
|
45
|
+
if (typeof token !== "string") {
|
|
46
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
47
|
+
}
|
|
48
|
+
options || (options = {});
|
|
49
|
+
const pos = options.header === true ? 0 : 1;
|
|
50
|
+
const part = token.split(".")[pos];
|
|
51
|
+
if (typeof part !== "string") {
|
|
52
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
53
|
+
}
|
|
54
|
+
let decoded;
|
|
55
|
+
try {
|
|
56
|
+
decoded = base64UrlDecode(part);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(decoded);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : {};
|
|
67
|
+
_global.SENTRY_RELEASE = { id: "38135ed0031eaede9a94159dc2d9a3e6df84467d" };
|
|
68
|
+
var WidgetType;
|
|
69
|
+
(function(WidgetType2) {
|
|
70
|
+
WidgetType2["Sidebar"] = "sidebar";
|
|
71
|
+
WidgetType2["Searchbar"] = "searchbar";
|
|
72
|
+
WidgetType2["Popup"] = "popup";
|
|
73
|
+
})(WidgetType || (WidgetType = {}));
|
|
74
|
+
({
|
|
75
|
+
[WidgetType.Sidebar]: "brainfish-sidebar-widget",
|
|
76
|
+
[WidgetType.Searchbar]: "brainfish-searchbar-widget",
|
|
77
|
+
[WidgetType.Popup]: "brainfish-popup-widget"
|
|
78
|
+
});
|
|
79
|
+
class BrainfishWidgetError extends Error {
|
|
80
|
+
constructor(message, options) {
|
|
81
|
+
super(message, options);
|
|
82
|
+
__publicField(this, "cause");
|
|
83
|
+
this.name = "BrainfishWidgetError";
|
|
84
|
+
this.cause = options?.cause;
|
|
85
|
+
if (Error.captureStackTrace) {
|
|
86
|
+
Error.captureStackTrace(this, BrainfishWidgetError);
|
|
87
|
+
}
|
|
88
|
+
if (this.cause instanceof Error && this.cause.stack) {
|
|
89
|
+
this.stack = this.stack + "\nCaused by: " + this.cause.stack;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
toJSON() {
|
|
93
|
+
return {
|
|
94
|
+
name: this.name,
|
|
95
|
+
message: this.message,
|
|
96
|
+
stack: this.stack,
|
|
97
|
+
cause: this.cause instanceof Error ? {
|
|
98
|
+
name: this.cause.name,
|
|
99
|
+
message: this.cause.message,
|
|
100
|
+
stack: this.cause.stack
|
|
101
|
+
} : this.cause
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
var ActionType;
|
|
106
|
+
(function(ActionType2) {
|
|
107
|
+
ActionType2["LINK"] = "link";
|
|
108
|
+
ActionType2["CALLBACK"] = "callback";
|
|
109
|
+
ActionType2["EMAIL"] = "email";
|
|
110
|
+
ActionType2["PHONE"] = "phone";
|
|
111
|
+
})(ActionType || (ActionType = {}));
|
|
112
|
+
const sendErrors = (apiHost, error, widgetKey) => {
|
|
113
|
+
if (!navigator || navigator.userAgent.toLowerCase().includes("headless")) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const errorData = error.toJSON();
|
|
117
|
+
const API_HOST = apiHost || "https://app.brainfi.sh";
|
|
118
|
+
fetch(`${API_HOST}/api/trackError.widget.create`, {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
"api-key": widgetKey
|
|
123
|
+
},
|
|
124
|
+
body: JSON.stringify({
|
|
125
|
+
error: `WebWidgetVersion: ${"1.13.2"}. ${error.message}`,
|
|
126
|
+
stack: error.stack,
|
|
127
|
+
cause: {
|
|
128
|
+
message: errorData.message,
|
|
129
|
+
stack: errorData.stack,
|
|
130
|
+
cause: errorData.cause
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const sendBrainfishWidgetError = (apiHost, error, message, widgetKey) => {
|
|
136
|
+
let errorMessage = message;
|
|
137
|
+
let errorDetails = {};
|
|
138
|
+
if (error instanceof Error) {
|
|
139
|
+
try {
|
|
140
|
+
errorDetails = JSON.parse(error.message);
|
|
141
|
+
errorMessage += ` - ${errorDetails.message || error.message}`;
|
|
142
|
+
} catch {
|
|
143
|
+
errorMessage += ` - ${error.message}`;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
errorMessage += ` - ${String(error)}`;
|
|
147
|
+
}
|
|
148
|
+
const err = new BrainfishWidgetError(errorMessage, {
|
|
149
|
+
cause: errorDetails
|
|
150
|
+
});
|
|
151
|
+
sendErrors(apiHost, err, widgetKey);
|
|
152
|
+
};
|
|
153
|
+
async function fetchWithErrorHandling(apiHost, endpoint, widgetKey) {
|
|
154
|
+
const maxRetries = 3;
|
|
155
|
+
const delay = 500;
|
|
156
|
+
let attempt = 0;
|
|
157
|
+
let lastError;
|
|
158
|
+
while (attempt < maxRetries) {
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetch(`${apiHost}${endpoint}`, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: {
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
"api-key": widgetKey
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
throw new Error(`API call failed with status: ${response.status}`);
|
|
169
|
+
}
|
|
170
|
+
const data = await response.json();
|
|
171
|
+
if (!data) {
|
|
172
|
+
throw new Error("Error loading config: empty response");
|
|
173
|
+
}
|
|
174
|
+
return data;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
lastError = error;
|
|
177
|
+
attempt++;
|
|
178
|
+
if (attempt >= maxRetries) {
|
|
179
|
+
sendBrainfishWidgetError(
|
|
180
|
+
apiHost,
|
|
181
|
+
error,
|
|
182
|
+
"Error fetching config",
|
|
183
|
+
widgetKey
|
|
184
|
+
);
|
|
185
|
+
throw lastError;
|
|
186
|
+
}
|
|
187
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const getConfigByKey = async ({
|
|
192
|
+
widgetKey,
|
|
193
|
+
apiHost
|
|
194
|
+
}) => {
|
|
195
|
+
const endpoint = `/api/searchWidgets.getConfigByKey`;
|
|
196
|
+
return fetchWithErrorHandling(apiHost, endpoint, widgetKey);
|
|
197
|
+
};
|
|
198
|
+
const mapActionButtons = (actionButtons) => actionButtons.map(
|
|
199
|
+
(action) => action.type === ActionType.CALLBACK && action.value ? { ...action, value: new Function(`return ${action.value}`)() } : action
|
|
200
|
+
);
|
|
201
|
+
const updateActions = (configActions = [], overrideActions) => {
|
|
202
|
+
const actionMap = new Map(
|
|
203
|
+
configActions.map((action) => [action.label, action])
|
|
204
|
+
);
|
|
205
|
+
overrideActions.forEach((action) => actionMap.set(action.label, action));
|
|
206
|
+
return Array.from(actionMap.values());
|
|
207
|
+
};
|
|
208
|
+
const transformConfig = ({
|
|
209
|
+
config,
|
|
210
|
+
apiKey,
|
|
211
|
+
apiHost
|
|
212
|
+
}) => {
|
|
213
|
+
const settings = config.settings || {};
|
|
214
|
+
["bodyActionButtons", "footerActionButtons", "nextBestActions"].forEach((key) => {
|
|
215
|
+
if (settings[key]) {
|
|
216
|
+
settings[key] = mapActionButtons(
|
|
217
|
+
settings[key]
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
...config,
|
|
223
|
+
settings,
|
|
224
|
+
apiHost,
|
|
225
|
+
widgetMode: config.widgetType,
|
|
226
|
+
apiKey
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const getApiHost = (overrides) => {
|
|
230
|
+
return overrides?.apiHost || "https://app.brainfi.sh";
|
|
231
|
+
};
|
|
232
|
+
const getWidgetHost = (overrides) => {
|
|
233
|
+
return overrides?.widgetHost || "https://agent.brainfi.sh";
|
|
234
|
+
};
|
|
235
|
+
const getAnalyticsApiHost = (overrides) => {
|
|
236
|
+
return overrides?.analyticsApiHost || "";
|
|
237
|
+
};
|
|
238
|
+
const loadSearchWidgetScript = async (url) => {
|
|
239
|
+
if (document.getElementById("brainfish-widget")) {
|
|
240
|
+
return window.Brainfish;
|
|
241
|
+
}
|
|
242
|
+
return new Promise((resolve, reject) => {
|
|
243
|
+
const script = document.createElement("script");
|
|
244
|
+
script.id = "brainfish-widget";
|
|
245
|
+
script.src = url;
|
|
246
|
+
script.type = "module";
|
|
247
|
+
script.async = true;
|
|
248
|
+
script.crossOrigin = "anonymous";
|
|
249
|
+
script.onload = () => {
|
|
250
|
+
setTimeout(() => {
|
|
251
|
+
const module = window.Brainfish;
|
|
252
|
+
module ? resolve(module) : reject(new Error("Failed to load Brainfish module"));
|
|
253
|
+
}, 200);
|
|
254
|
+
};
|
|
255
|
+
script.onerror = (event) => {
|
|
256
|
+
const errorEvent = event;
|
|
257
|
+
const errorDetails = {
|
|
258
|
+
message: `Failed to load script: ${url}`,
|
|
259
|
+
type: errorEvent.type,
|
|
260
|
+
fileName: errorEvent.filename,
|
|
261
|
+
lineNumber: errorEvent.lineno,
|
|
262
|
+
columnNumber: errorEvent.colno,
|
|
263
|
+
error: errorEvent.error ? errorEvent.error.toString() : "Unknown error"
|
|
264
|
+
};
|
|
265
|
+
reject(new Error(JSON.stringify(errorDetails)));
|
|
266
|
+
};
|
|
267
|
+
document.head.appendChild(script);
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
const init = async ({
|
|
271
|
+
apiHost,
|
|
272
|
+
widgetKey,
|
|
273
|
+
version
|
|
274
|
+
}) => {
|
|
275
|
+
try {
|
|
276
|
+
const url = `https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${version}/dist/web.js`;
|
|
277
|
+
const widget = await loadSearchWidgetScript(url);
|
|
278
|
+
return { widget };
|
|
279
|
+
} catch (error) {
|
|
280
|
+
sendBrainfishWidgetError(
|
|
281
|
+
apiHost,
|
|
282
|
+
error,
|
|
283
|
+
error.message,
|
|
284
|
+
widgetKey
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
function initializeWidget(widget, config) {
|
|
289
|
+
if (config.widgetType === WidgetType.Searchbar || config.widgetType === "Search") {
|
|
290
|
+
widget.SearchWidget.initStandard(config);
|
|
291
|
+
} else {
|
|
292
|
+
widget.HelpWidget.initPopup(config);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const initializedWidgets$1 = /* @__PURE__ */ new Set();
|
|
296
|
+
const initSearchWidget = async (options, config) => {
|
|
297
|
+
const apiHost = getApiHost(options.overrides);
|
|
298
|
+
try {
|
|
299
|
+
if (initializedWidgets$1.has(options.widgetKey)) {
|
|
300
|
+
return void 0;
|
|
301
|
+
}
|
|
302
|
+
const result = await init({
|
|
303
|
+
apiHost,
|
|
304
|
+
widgetKey: options.widgetKey,
|
|
305
|
+
version: config.version || "latest"
|
|
306
|
+
});
|
|
307
|
+
if (result) {
|
|
308
|
+
const { widget } = result;
|
|
309
|
+
const transformedConfig = transformConfig({
|
|
310
|
+
config,
|
|
311
|
+
apiKey: options.widgetKey,
|
|
312
|
+
apiHost
|
|
313
|
+
});
|
|
314
|
+
if (options.overrides && config.settings) {
|
|
315
|
+
Object.entries(options.overrides).forEach(([key, value]) => {
|
|
316
|
+
if (config.settings && key in config.settings) {
|
|
317
|
+
config.settings[key] = updateActions(
|
|
318
|
+
config.settings[key],
|
|
319
|
+
value
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
initializeWidget(widget, transformedConfig);
|
|
325
|
+
initializedWidgets$1.add(options.widgetKey);
|
|
326
|
+
return widget;
|
|
327
|
+
}
|
|
328
|
+
} catch (error) {
|
|
329
|
+
sendBrainfishWidgetError(
|
|
330
|
+
apiHost,
|
|
331
|
+
error,
|
|
332
|
+
error.message,
|
|
333
|
+
options.widgetKey
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
return void 0;
|
|
337
|
+
};
|
|
338
|
+
const ANALYTICS_API_HOST = "";
|
|
339
|
+
let isTrackerInitialized = false;
|
|
340
|
+
const loadTrackerScript = async (apiHost, widgetKey) => {
|
|
341
|
+
if (document.getElementById("brainfish-analytics")) {
|
|
342
|
+
return window.BrainfishAnalytics;
|
|
343
|
+
}
|
|
344
|
+
const script = document.createElement("script");
|
|
345
|
+
script.id = "brainfish-analytics";
|
|
346
|
+
script.src = `https://cdn.jsdelivr.net/npm/@brainfish-ai/web-tracker@latest/dist/tracker.js`;
|
|
347
|
+
script.type = "module";
|
|
348
|
+
script.async = true;
|
|
349
|
+
script.crossOrigin = "anonymous";
|
|
350
|
+
script.onerror = () => {
|
|
351
|
+
sendBrainfishWidgetError(
|
|
352
|
+
apiHost,
|
|
353
|
+
new Error(`Failed to load script: ${script.src}`),
|
|
354
|
+
`Failed to load script: ${script.src}`,
|
|
355
|
+
widgetKey
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
document.head.appendChild(script);
|
|
359
|
+
};
|
|
360
|
+
const isDoNotTrackEnabled = () => {
|
|
361
|
+
if (typeof window === "undefined" || typeof navigator === "undefined") {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
const dntEnabledValues = ["1", "yes", "true"];
|
|
365
|
+
const nav = navigator;
|
|
366
|
+
const win = window;
|
|
367
|
+
const dnt = (nav.doNotTrack || // Standard
|
|
368
|
+
win.doNotTrack || // IE11, Edge
|
|
369
|
+
nav.msDoNotTrack || // IE9, IE10
|
|
370
|
+
"0").toString().toLowerCase();
|
|
371
|
+
return dntEnabledValues.includes(dnt);
|
|
372
|
+
};
|
|
373
|
+
const initBrainfishAnalytics = async (widgetKey, accessKey, apiHost, analyticsApiHost = ANALYTICS_API_HOST, enableRecording = false, recordingBlocklist = [], _allowLocalhostRecording, _allowScreenRecording) => {
|
|
374
|
+
if (!accessKey) {
|
|
375
|
+
sendBrainfishWidgetError(
|
|
376
|
+
apiHost,
|
|
377
|
+
new Error("Access key is required"),
|
|
378
|
+
"Access key is required",
|
|
379
|
+
widgetKey
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
if (isTrackerInitialized) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
const isDNTEnabled = isDoNotTrackEnabled();
|
|
387
|
+
window.BrainfishAnalytics("init", {
|
|
388
|
+
apiUrl: analyticsApiHost,
|
|
389
|
+
accessKey,
|
|
390
|
+
trackScreenViews: true,
|
|
391
|
+
trackAttributes: !isDNTEnabled,
|
|
392
|
+
trackOutgoingLinks: !isDNTEnabled,
|
|
393
|
+
enableRecording: !isDNTEnabled && enableRecording,
|
|
394
|
+
recordingBlocklist,
|
|
395
|
+
_allowLocalhostRecording,
|
|
396
|
+
_allowScreenRecording
|
|
397
|
+
});
|
|
398
|
+
isTrackerInitialized = true;
|
|
399
|
+
await loadTrackerScript(apiHost, widgetKey);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
sendBrainfishWidgetError(
|
|
402
|
+
apiHost,
|
|
403
|
+
error,
|
|
404
|
+
"Failed to initialize BrainfishAnalytics",
|
|
405
|
+
widgetKey
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
function createBrainfishQueue() {
|
|
410
|
+
let queue = [];
|
|
411
|
+
let realBrainfish = null;
|
|
412
|
+
function queueOrExecute(method, args) {
|
|
413
|
+
if (realBrainfish) {
|
|
414
|
+
const parts = method.split(".");
|
|
415
|
+
let obj = realBrainfish;
|
|
416
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
417
|
+
obj = obj[parts[i]];
|
|
418
|
+
}
|
|
419
|
+
const fn = obj[parts[parts.length - 1]];
|
|
420
|
+
if (typeof fn === "function") {
|
|
421
|
+
return fn.apply(obj, args);
|
|
422
|
+
}
|
|
423
|
+
} else {
|
|
424
|
+
queue.push([method, args]);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const brainfishQueue = {
|
|
428
|
+
Widgets: {
|
|
429
|
+
init: (...args) => queueOrExecute("Widgets.init", args),
|
|
430
|
+
identify: (...args) => queueOrExecute("Widgets.identify", args),
|
|
431
|
+
setSignedAttributes: (...args) => queueOrExecute("Widgets.setSignedAttributes", args),
|
|
432
|
+
open: () => queueOrExecute("Widgets.open", []),
|
|
433
|
+
close: () => queueOrExecute("Widgets.close", []),
|
|
434
|
+
isReady: false
|
|
435
|
+
},
|
|
436
|
+
SearchWidget: {
|
|
437
|
+
initStandard: (...args) => queueOrExecute("SearchWidget.initStandard", args)
|
|
438
|
+
},
|
|
439
|
+
HelpWidget: {
|
|
440
|
+
initPopup: (...args) => queueOrExecute("HelpWidget.initPopup", args),
|
|
441
|
+
close: (...args) => queueOrExecute("HelpWidget.close", args),
|
|
442
|
+
open: (...args) => queueOrExecute("HelpWidget.open", args),
|
|
443
|
+
toggle: (...args) => queueOrExecute("HelpWidget.toggle", args)
|
|
444
|
+
},
|
|
445
|
+
_setRealBrainfish: function(bf) {
|
|
446
|
+
realBrainfish = bf;
|
|
447
|
+
while (queue.length > 0) {
|
|
448
|
+
const [method, args] = queue.shift();
|
|
449
|
+
queueOrExecute(method, args);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
return brainfishQueue;
|
|
454
|
+
}
|
|
455
|
+
const createQueues = () => {
|
|
456
|
+
if (window) {
|
|
457
|
+
window.BrainfishAnalytics = window.BrainfishAnalytics || function(...args) {
|
|
458
|
+
(window.BrainfishAnalytics.q = window.BrainfishAnalytics.q || []).push(
|
|
459
|
+
args
|
|
460
|
+
);
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
function createElementWithClass(tagName, className, attributes = {}) {
|
|
465
|
+
const element = document.createElement(tagName);
|
|
466
|
+
element.className = className;
|
|
467
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
468
|
+
element.setAttribute(key, value);
|
|
469
|
+
});
|
|
470
|
+
return element;
|
|
471
|
+
}
|
|
472
|
+
const IFRAME_CONTAINER_CLASS = "bf-iframe-container";
|
|
473
|
+
const TRIGGER_BUTTON_CLASS = "bf-trigger-button";
|
|
474
|
+
function createTriggerButton(widgetKey, triggerButtonIcon) {
|
|
475
|
+
const button = createElementWithClass("button", TRIGGER_BUTTON_CLASS, {
|
|
476
|
+
id: `trigger-button-${widgetKey}`,
|
|
477
|
+
"aria-controls": IFRAME_CONTAINER_CLASS,
|
|
478
|
+
"aria-expanded": "false",
|
|
479
|
+
"data-name": TRIGGER_BUTTON_CLASS
|
|
480
|
+
});
|
|
481
|
+
const icon = createElementWithClass("div", "trigger-button-icon", {
|
|
482
|
+
"aria-hidden": "true"
|
|
483
|
+
});
|
|
484
|
+
if (!triggerButtonIcon) {
|
|
485
|
+
icon.innerHTML = `
|
|
486
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 256 256" class="close-icon">
|
|
487
|
+
<path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z"></path>
|
|
488
|
+
</svg>
|
|
489
|
+
<svg width="24" height="14" viewBox="0 0 24 14" fill="none" xmlns="http://www.w3.org/2000/svg" class="fish-icon visible">
|
|
490
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.71844 10.3882L4.60606 6.98384L1.71844 3.58375C1.4014 3.21362 1.44424 2.65841 1.81269 2.33993C1.97978 2.1979 2.65242 1.98701 3.04657 2.43461L5.78425 5.65824C6.14281 5.29523 6.51693 4.95924 6.90479 4.65114C8.88976 3.07437 11.2345 2.22803 13.6931 2.22803C16.9492 2.22803 20.0039 3.71718 22.2917 6.41142C22.5702 6.74282 22.5702 7.22916 22.2917 7.56056C20.0039 10.2591 16.9492 11.744 13.6931 11.744C11.2348 11.744 8.89035 10.8948 6.90554 9.31995C6.51741 9.01199 6.14304 8.67628 5.78425 8.31374L3.04657 11.5374C2.72953 11.9075 2.18114 11.9505 1.81269 11.632C1.44852 11.3179 1.40568 10.7584 1.71844 10.3882ZM5.93026 10.4683C8.17161 12.2599 10.8546 13.25 13.6931 13.25C17.4881 13.25 21.019 11.4034 23.4447 8.52942C24.1873 7.64571 24.1843 6.31801 23.4397 5.43663C20.8944 2.43919 17.4337 0.722025 13.6931 0.722025C10.8555 0.722025 8.17194 1.70845 5.92952 3.50276L4.17682 1.43933C3.57943 0.760929 2.79325 0.630009 2.25286 0.662947C1.98116 0.679506 1.73125 0.736852 1.51895 0.811846C1.26839 0.900352 1.03017 1.02718 0.827835 1.20058C-0.165283 2.05903 -0.283916 3.561 0.574656 4.56345L2.63075 6.98445L0.568104 9.41623C-0.272133 10.4106 -0.166523 11.9125 0.827835 12.7714C1.81372 13.6243 3.34308 13.5062 4.19036 12.5171L5.93026 10.4683Z" fill="currentColor"/>
|
|
491
|
+
</svg>
|
|
492
|
+
`;
|
|
493
|
+
} else {
|
|
494
|
+
icon.innerHTML = `
|
|
495
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 256 256" class="close-icon">
|
|
496
|
+
<path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z"></path>
|
|
497
|
+
</svg>
|
|
498
|
+
<img src="${triggerButtonIcon}" class="fish-icon visible" alt="Trigger button icon" height="32" width="32" aria-hidden="true" aria-label="help button icon" />
|
|
499
|
+
`;
|
|
500
|
+
}
|
|
501
|
+
button.setAttribute("aria-label", "Open Brainfish widget");
|
|
502
|
+
button.appendChild(icon);
|
|
503
|
+
return { button, icon };
|
|
504
|
+
}
|
|
505
|
+
function createIframeContainer(widgetUrl) {
|
|
506
|
+
const iframeContainer = createElementWithClass(
|
|
507
|
+
"div",
|
|
508
|
+
IFRAME_CONTAINER_CLASS,
|
|
509
|
+
{
|
|
510
|
+
id: IFRAME_CONTAINER_CLASS,
|
|
511
|
+
"aria-live": "polite",
|
|
512
|
+
"aria-hidden": "true"
|
|
513
|
+
}
|
|
514
|
+
);
|
|
515
|
+
const loadingIndicator = createElementWithClass("div", "iframe-loading-indicator");
|
|
516
|
+
const spinner = createElementWithClass("div", "spinner");
|
|
517
|
+
loadingIndicator.setAttribute("aria-label", "Loading content");
|
|
518
|
+
loadingIndicator.setAttribute("role", "status");
|
|
519
|
+
loadingIndicator.appendChild(spinner);
|
|
520
|
+
iframeContainer.appendChild(loadingIndicator);
|
|
521
|
+
const iframe = createElementWithClass("iframe", "trigger-iframe", {
|
|
522
|
+
src: widgetUrl,
|
|
523
|
+
sandbox: "allow-scripts allow-same-origin allow-popups allow-forms",
|
|
524
|
+
allow: "clipboard-write",
|
|
525
|
+
role: "dialog"
|
|
526
|
+
});
|
|
527
|
+
iframe.style.opacity = "0";
|
|
528
|
+
iframe.addEventListener("load", () => {
|
|
529
|
+
loadingIndicator.style.display = "none";
|
|
530
|
+
iframe.style.opacity = "1";
|
|
531
|
+
});
|
|
532
|
+
iframe.addEventListener("error", (error) => {
|
|
533
|
+
console.error("Error loading iframe:", error);
|
|
534
|
+
loadingIndicator.innerHTML = "";
|
|
535
|
+
const errorIcon = createElementWithClass("div", "loading-error");
|
|
536
|
+
loadingIndicator.appendChild(errorIcon);
|
|
537
|
+
loadingIndicator.setAttribute("aria-label", "Failed to load content");
|
|
538
|
+
});
|
|
539
|
+
iframeContainer.appendChild(iframe);
|
|
540
|
+
return { iframeContainer, iframe };
|
|
541
|
+
}
|
|
542
|
+
function toggleIframeSize() {
|
|
543
|
+
const iframeContainer = document.querySelector(
|
|
544
|
+
`.${IFRAME_CONTAINER_CLASS}`
|
|
545
|
+
);
|
|
546
|
+
if (iframeContainer.classList.contains("expanded")) {
|
|
547
|
+
iframeContainer.classList.remove("expanded");
|
|
548
|
+
} else {
|
|
549
|
+
iframeContainer.classList.add("expanded");
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const MOBILE_BREAKPOINT = 576;
|
|
553
|
+
class IframeStateManager {
|
|
554
|
+
static get isWidgetOpen() {
|
|
555
|
+
return this.isOpen;
|
|
556
|
+
}
|
|
557
|
+
static initialize({
|
|
558
|
+
button,
|
|
559
|
+
icon,
|
|
560
|
+
isButtonHidden
|
|
561
|
+
}) {
|
|
562
|
+
this.button = button || null;
|
|
563
|
+
this.icon = icon || null;
|
|
564
|
+
this.isButtonHidden = isButtonHidden || false;
|
|
565
|
+
if (button) {
|
|
566
|
+
button.addEventListener("click", () => this.toggleIframeVisibility());
|
|
567
|
+
}
|
|
568
|
+
if (window.Brainfish?.HelpWidget) {
|
|
569
|
+
window.Brainfish.HelpWidget.close = () => this.closeWidget();
|
|
570
|
+
window.Brainfish.HelpWidget.open = () => this.openWidget();
|
|
571
|
+
}
|
|
572
|
+
if (window.Brainfish?.Widgets) {
|
|
573
|
+
window.Brainfish.Widgets.open = () => this.openWidget();
|
|
574
|
+
window.Brainfish.Widgets.close = () => this.closeWidget();
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
static toggleIframeVisibility() {
|
|
578
|
+
this.isOpen = !this.isOpen;
|
|
579
|
+
if (this.isOpen) {
|
|
580
|
+
this.openWidget();
|
|
581
|
+
} else {
|
|
582
|
+
this.closeWidget();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// Open the widget programmatically
|
|
586
|
+
static openWidget() {
|
|
587
|
+
this.isOpen = true;
|
|
588
|
+
const iframeContainer = document.querySelector(".bf-iframe-container");
|
|
589
|
+
const iframe = iframeContainer?.querySelector("iframe");
|
|
590
|
+
iframeContainer?.classList.add("open");
|
|
591
|
+
iframeContainer?.setAttribute("aria-hidden", "false");
|
|
592
|
+
iframe?.contentWindow?.postMessage({ type: "FOCUS_SEARCH_FIELD" }, "*");
|
|
593
|
+
if (this.button && this.icon) {
|
|
594
|
+
const fishIconSVG = this.icon.querySelector(".fish-icon");
|
|
595
|
+
const closeIconSVG = this.icon.querySelector(".close-icon");
|
|
596
|
+
this.button.setAttribute("aria-expanded", "true");
|
|
597
|
+
fishIconSVG.classList.remove("visible");
|
|
598
|
+
closeIconSVG.classList.add("visible");
|
|
599
|
+
if (document.body.clientWidth <= MOBILE_BREAKPOINT) {
|
|
600
|
+
this.hideTriggerButton();
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
window.dispatchEvent(new Event("onBrainfishWidgetOpen"));
|
|
604
|
+
window.BrainfishAnalytics("track", "Open Widget");
|
|
605
|
+
}
|
|
606
|
+
// Close the widget programmatically
|
|
607
|
+
static closeWidget() {
|
|
608
|
+
this.isOpen = false;
|
|
609
|
+
const iframeContainer = document.querySelector(".bf-iframe-container");
|
|
610
|
+
iframeContainer?.classList.remove("open");
|
|
611
|
+
iframeContainer?.setAttribute("aria-hidden", "true");
|
|
612
|
+
if (this.button && this.icon) {
|
|
613
|
+
this.button.setAttribute("aria-expanded", "false");
|
|
614
|
+
const fishIconSVG = this.icon.querySelector(".fish-icon");
|
|
615
|
+
const closeIconSVG = this.icon.querySelector(".close-icon");
|
|
616
|
+
fishIconSVG.classList.add("visible");
|
|
617
|
+
closeIconSVG.classList.remove("visible");
|
|
618
|
+
if (document.body.clientWidth <= MOBILE_BREAKPOINT) {
|
|
619
|
+
this.showTriggerButton();
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
window.dispatchEvent(new Event("onBrainfishWidgetClose"));
|
|
623
|
+
window.BrainfishAnalytics("track", "Close Widget");
|
|
624
|
+
}
|
|
625
|
+
static showTriggerButton() {
|
|
626
|
+
this.button?.classList.remove("hidden");
|
|
627
|
+
}
|
|
628
|
+
static hideTriggerButton() {
|
|
629
|
+
this.button?.classList.add("hidden");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
__publicField(IframeStateManager, "isOpen", false);
|
|
633
|
+
__publicField(IframeStateManager, "button", null);
|
|
634
|
+
__publicField(IframeStateManager, "icon", null);
|
|
635
|
+
__publicField(IframeStateManager, "isButtonHidden", false);
|
|
636
|
+
function initMessageListener({
|
|
637
|
+
widgetHost,
|
|
638
|
+
apiHost,
|
|
639
|
+
widgetKey,
|
|
640
|
+
signal
|
|
641
|
+
}) {
|
|
642
|
+
const messageHandler = (event) => {
|
|
643
|
+
if (event.origin !== widgetHost) return;
|
|
644
|
+
const { type } = event.data;
|
|
645
|
+
if (type === "TOGGLE_WIDGET_SIZE") {
|
|
646
|
+
toggleIframeSize();
|
|
647
|
+
}
|
|
648
|
+
if (type === "TRACK_EVENT") {
|
|
649
|
+
if (!window.BrainfishAnalytics) return;
|
|
650
|
+
const { eventName, data } = event.data;
|
|
651
|
+
window.BrainfishAnalytics("track", eventName, data);
|
|
652
|
+
}
|
|
653
|
+
if (type === "CLOSE_WIDGET") {
|
|
654
|
+
window.BrainfishAnalytics("track", "Close Widget");
|
|
655
|
+
IframeStateManager.toggleIframeVisibility();
|
|
656
|
+
}
|
|
657
|
+
if (type === "NEXT_BEST_ACTION_CLICKED") {
|
|
658
|
+
const { action, searchQueryId, query, answer } = event.data;
|
|
659
|
+
const context = { action, searchQueryId };
|
|
660
|
+
if (!["function", "callback"].includes(action.type)) {
|
|
661
|
+
console.error("Invalid action type", action);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
window.__bfCallbacks = window.__bfCallbacks || {};
|
|
665
|
+
if (window.__bfCallbacks[action.id]) {
|
|
666
|
+
window.__bfCallbacks[action.id](query, answer, context);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const scriptUrl = `${apiHost}/api/searchWidgets.callback.codeblocks?apiKey=${widgetKey}&codeblockId=${action.id}`;
|
|
670
|
+
const script = document.createElement("script");
|
|
671
|
+
script.src = scriptUrl;
|
|
672
|
+
document.head.appendChild(script);
|
|
673
|
+
script.onload = () => {
|
|
674
|
+
window.__bfCallbacks[action.id](query, answer, context);
|
|
675
|
+
setTimeout(() => {
|
|
676
|
+
document.head.removeChild(script);
|
|
677
|
+
}, 300);
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
window.addEventListener("message", messageHandler, { signal });
|
|
682
|
+
}
|
|
683
|
+
const styles = '.bf-trigger-button{position:fixed;bottom:16px;right:16px;width:36px;height:36px;border-radius:50%;border:none;box-shadow:0 1px 6px #0000000f,0 2px 32px #00000029;transition:transform 167ms cubic-bezier(.33,0,0,1);box-sizing:content-box;display:flex;align-items:center;justify-content:center;cursor:pointer;z-index:1000;padding:12px;gap:10px;overflow:hidden}.bf-trigger-button.hidden{display:none}.trigger-button-icon{display:flex;align-items:center;justify-content:center;width:36px;height:36px;position:relative}.trigger-button-icon svg{width:100%;height:100%;position:absolute;inset:0}.trigger-button-icon>svg>path{transition:transform .3s ease,opacity .3s ease;transform:scale(.5);transform-origin:center;opacity:0}.trigger-button-icon .fish-icon{display:none}.trigger-button-icon .fish-icon.visible{display:block}.trigger-button-icon svg.visible{display:block}.trigger-button-icon>svg.visible>path{opacity:1;transform:scale(1)}.trigger-iframe{position:relative;width:100%;height:100%;border:none;outline:none;transform:translateZ(0)}.bf-iframe-container{display:none;position:fixed;z-index:2147483000000;background-color:#fff;bottom:0;right:0;width:100vw;height:100vh;border:none;overflow:hidden;opacity:0;pointer-events:none;transform:translateY(20px);transition:opacity .3s ease,transform .3s ease,width .2s ease-in-out,height .2s ease-in-out}.bf-iframe-container.open{display:block;opacity:1;transform:translateY(0);pointer-events:auto;top:0;left:0}@media (min-width: 576px){.bf-iframe-container{bottom:80px;right:24px;width:448px;height:min(750px,calc(100vh - 80px));border-radius:8px;border:1px solid var(--Dark-300, #D4D4D4);box-shadow:0 20px 25px -5px #1212171a,0 10px 10px -5px #1212170a}.bf-iframe-container.open{top:unset;left:unset}.bf-iframe-container.expanded{width:min(calc(448px * 1.35),calc(100vw - 16px));height:min(calc(750px * 1.35),calc(100vh - 80px))}}.iframe-loading-indicator{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);display:flex;align-items:center;justify-content:center;z-index:10}.spinner{width:24px;height:24px;border:2px solid rgba(0,0,0,.1);border-radius:50%;border-top-color:#3498db;animation:spin 1s ease-in-out infinite}@keyframes spin{to{transform:rotate(360deg)}}.loading-error{width:24px;height:24px;position:relative;display:flex;align-items:center;justify-content:center}.loading-error:before,.loading-error:after{content:"";position:absolute;width:16px;height:2px;background-color:#e74c3c;border-radius:2px}.loading-error:before{transform:rotate(45deg)}.loading-error:after{transform:rotate(-45deg)}';
|
|
684
|
+
function getDefaultExportFromCjs(x) {
|
|
685
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
686
|
+
}
|
|
687
|
+
var getLuminance$1 = { exports: {} };
|
|
688
|
+
var parseToRgb = { exports: {} };
|
|
689
|
+
var _hslToRgb = { exports: {} };
|
|
690
|
+
var hasRequired_hslToRgb;
|
|
691
|
+
function require_hslToRgb() {
|
|
692
|
+
if (hasRequired_hslToRgb) return _hslToRgb.exports;
|
|
693
|
+
hasRequired_hslToRgb = 1;
|
|
694
|
+
(function(module, exports) {
|
|
695
|
+
exports.__esModule = true;
|
|
696
|
+
exports["default"] = void 0;
|
|
697
|
+
function colorToInt(color) {
|
|
698
|
+
return Math.round(color * 255);
|
|
699
|
+
}
|
|
700
|
+
function convertToInt(red, green, blue) {
|
|
701
|
+
return colorToInt(red) + "," + colorToInt(green) + "," + colorToInt(blue);
|
|
702
|
+
}
|
|
703
|
+
function hslToRgb(hue, saturation, lightness, convert) {
|
|
704
|
+
if (convert === void 0) {
|
|
705
|
+
convert = convertToInt;
|
|
706
|
+
}
|
|
707
|
+
if (saturation === 0) {
|
|
708
|
+
return convert(lightness, lightness, lightness);
|
|
709
|
+
}
|
|
710
|
+
var huePrime = (hue % 360 + 360) % 360 / 60;
|
|
711
|
+
var chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
712
|
+
var secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1));
|
|
713
|
+
var red = 0;
|
|
714
|
+
var green = 0;
|
|
715
|
+
var blue = 0;
|
|
716
|
+
if (huePrime >= 0 && huePrime < 1) {
|
|
717
|
+
red = chroma;
|
|
718
|
+
green = secondComponent;
|
|
719
|
+
} else if (huePrime >= 1 && huePrime < 2) {
|
|
720
|
+
red = secondComponent;
|
|
721
|
+
green = chroma;
|
|
722
|
+
} else if (huePrime >= 2 && huePrime < 3) {
|
|
723
|
+
green = chroma;
|
|
724
|
+
blue = secondComponent;
|
|
725
|
+
} else if (huePrime >= 3 && huePrime < 4) {
|
|
726
|
+
green = secondComponent;
|
|
727
|
+
blue = chroma;
|
|
728
|
+
} else if (huePrime >= 4 && huePrime < 5) {
|
|
729
|
+
red = secondComponent;
|
|
730
|
+
blue = chroma;
|
|
731
|
+
} else if (huePrime >= 5 && huePrime < 6) {
|
|
732
|
+
red = chroma;
|
|
733
|
+
blue = secondComponent;
|
|
734
|
+
}
|
|
735
|
+
var lightnessModification = lightness - chroma / 2;
|
|
736
|
+
var finalRed = red + lightnessModification;
|
|
737
|
+
var finalGreen = green + lightnessModification;
|
|
738
|
+
var finalBlue = blue + lightnessModification;
|
|
739
|
+
return convert(finalRed, finalGreen, finalBlue);
|
|
740
|
+
}
|
|
741
|
+
exports["default"] = hslToRgb;
|
|
742
|
+
module.exports = exports.default;
|
|
743
|
+
})(_hslToRgb, _hslToRgb.exports);
|
|
744
|
+
return _hslToRgb.exports;
|
|
745
|
+
}
|
|
746
|
+
var _nameToHex = { exports: {} };
|
|
747
|
+
var hasRequired_nameToHex;
|
|
748
|
+
function require_nameToHex() {
|
|
749
|
+
if (hasRequired_nameToHex) return _nameToHex.exports;
|
|
750
|
+
hasRequired_nameToHex = 1;
|
|
751
|
+
(function(module, exports) {
|
|
752
|
+
exports.__esModule = true;
|
|
753
|
+
exports["default"] = void 0;
|
|
754
|
+
var namedColorMap = {
|
|
755
|
+
aliceblue: "f0f8ff",
|
|
756
|
+
antiquewhite: "faebd7",
|
|
757
|
+
aqua: "00ffff",
|
|
758
|
+
aquamarine: "7fffd4",
|
|
759
|
+
azure: "f0ffff",
|
|
760
|
+
beige: "f5f5dc",
|
|
761
|
+
bisque: "ffe4c4",
|
|
762
|
+
black: "000",
|
|
763
|
+
blanchedalmond: "ffebcd",
|
|
764
|
+
blue: "0000ff",
|
|
765
|
+
blueviolet: "8a2be2",
|
|
766
|
+
brown: "a52a2a",
|
|
767
|
+
burlywood: "deb887",
|
|
768
|
+
cadetblue: "5f9ea0",
|
|
769
|
+
chartreuse: "7fff00",
|
|
770
|
+
chocolate: "d2691e",
|
|
771
|
+
coral: "ff7f50",
|
|
772
|
+
cornflowerblue: "6495ed",
|
|
773
|
+
cornsilk: "fff8dc",
|
|
774
|
+
crimson: "dc143c",
|
|
775
|
+
cyan: "00ffff",
|
|
776
|
+
darkblue: "00008b",
|
|
777
|
+
darkcyan: "008b8b",
|
|
778
|
+
darkgoldenrod: "b8860b",
|
|
779
|
+
darkgray: "a9a9a9",
|
|
780
|
+
darkgreen: "006400",
|
|
781
|
+
darkgrey: "a9a9a9",
|
|
782
|
+
darkkhaki: "bdb76b",
|
|
783
|
+
darkmagenta: "8b008b",
|
|
784
|
+
darkolivegreen: "556b2f",
|
|
785
|
+
darkorange: "ff8c00",
|
|
786
|
+
darkorchid: "9932cc",
|
|
787
|
+
darkred: "8b0000",
|
|
788
|
+
darksalmon: "e9967a",
|
|
789
|
+
darkseagreen: "8fbc8f",
|
|
790
|
+
darkslateblue: "483d8b",
|
|
791
|
+
darkslategray: "2f4f4f",
|
|
792
|
+
darkslategrey: "2f4f4f",
|
|
793
|
+
darkturquoise: "00ced1",
|
|
794
|
+
darkviolet: "9400d3",
|
|
795
|
+
deeppink: "ff1493",
|
|
796
|
+
deepskyblue: "00bfff",
|
|
797
|
+
dimgray: "696969",
|
|
798
|
+
dimgrey: "696969",
|
|
799
|
+
dodgerblue: "1e90ff",
|
|
800
|
+
firebrick: "b22222",
|
|
801
|
+
floralwhite: "fffaf0",
|
|
802
|
+
forestgreen: "228b22",
|
|
803
|
+
fuchsia: "ff00ff",
|
|
804
|
+
gainsboro: "dcdcdc",
|
|
805
|
+
ghostwhite: "f8f8ff",
|
|
806
|
+
gold: "ffd700",
|
|
807
|
+
goldenrod: "daa520",
|
|
808
|
+
gray: "808080",
|
|
809
|
+
green: "008000",
|
|
810
|
+
greenyellow: "adff2f",
|
|
811
|
+
grey: "808080",
|
|
812
|
+
honeydew: "f0fff0",
|
|
813
|
+
hotpink: "ff69b4",
|
|
814
|
+
indianred: "cd5c5c",
|
|
815
|
+
indigo: "4b0082",
|
|
816
|
+
ivory: "fffff0",
|
|
817
|
+
khaki: "f0e68c",
|
|
818
|
+
lavender: "e6e6fa",
|
|
819
|
+
lavenderblush: "fff0f5",
|
|
820
|
+
lawngreen: "7cfc00",
|
|
821
|
+
lemonchiffon: "fffacd",
|
|
822
|
+
lightblue: "add8e6",
|
|
823
|
+
lightcoral: "f08080",
|
|
824
|
+
lightcyan: "e0ffff",
|
|
825
|
+
lightgoldenrodyellow: "fafad2",
|
|
826
|
+
lightgray: "d3d3d3",
|
|
827
|
+
lightgreen: "90ee90",
|
|
828
|
+
lightgrey: "d3d3d3",
|
|
829
|
+
lightpink: "ffb6c1",
|
|
830
|
+
lightsalmon: "ffa07a",
|
|
831
|
+
lightseagreen: "20b2aa",
|
|
832
|
+
lightskyblue: "87cefa",
|
|
833
|
+
lightslategray: "789",
|
|
834
|
+
lightslategrey: "789",
|
|
835
|
+
lightsteelblue: "b0c4de",
|
|
836
|
+
lightyellow: "ffffe0",
|
|
837
|
+
lime: "0f0",
|
|
838
|
+
limegreen: "32cd32",
|
|
839
|
+
linen: "faf0e6",
|
|
840
|
+
magenta: "f0f",
|
|
841
|
+
maroon: "800000",
|
|
842
|
+
mediumaquamarine: "66cdaa",
|
|
843
|
+
mediumblue: "0000cd",
|
|
844
|
+
mediumorchid: "ba55d3",
|
|
845
|
+
mediumpurple: "9370db",
|
|
846
|
+
mediumseagreen: "3cb371",
|
|
847
|
+
mediumslateblue: "7b68ee",
|
|
848
|
+
mediumspringgreen: "00fa9a",
|
|
849
|
+
mediumturquoise: "48d1cc",
|
|
850
|
+
mediumvioletred: "c71585",
|
|
851
|
+
midnightblue: "191970",
|
|
852
|
+
mintcream: "f5fffa",
|
|
853
|
+
mistyrose: "ffe4e1",
|
|
854
|
+
moccasin: "ffe4b5",
|
|
855
|
+
navajowhite: "ffdead",
|
|
856
|
+
navy: "000080",
|
|
857
|
+
oldlace: "fdf5e6",
|
|
858
|
+
olive: "808000",
|
|
859
|
+
olivedrab: "6b8e23",
|
|
860
|
+
orange: "ffa500",
|
|
861
|
+
orangered: "ff4500",
|
|
862
|
+
orchid: "da70d6",
|
|
863
|
+
palegoldenrod: "eee8aa",
|
|
864
|
+
palegreen: "98fb98",
|
|
865
|
+
paleturquoise: "afeeee",
|
|
866
|
+
palevioletred: "db7093",
|
|
867
|
+
papayawhip: "ffefd5",
|
|
868
|
+
peachpuff: "ffdab9",
|
|
869
|
+
peru: "cd853f",
|
|
870
|
+
pink: "ffc0cb",
|
|
871
|
+
plum: "dda0dd",
|
|
872
|
+
powderblue: "b0e0e6",
|
|
873
|
+
purple: "800080",
|
|
874
|
+
rebeccapurple: "639",
|
|
875
|
+
red: "f00",
|
|
876
|
+
rosybrown: "bc8f8f",
|
|
877
|
+
royalblue: "4169e1",
|
|
878
|
+
saddlebrown: "8b4513",
|
|
879
|
+
salmon: "fa8072",
|
|
880
|
+
sandybrown: "f4a460",
|
|
881
|
+
seagreen: "2e8b57",
|
|
882
|
+
seashell: "fff5ee",
|
|
883
|
+
sienna: "a0522d",
|
|
884
|
+
silver: "c0c0c0",
|
|
885
|
+
skyblue: "87ceeb",
|
|
886
|
+
slateblue: "6a5acd",
|
|
887
|
+
slategray: "708090",
|
|
888
|
+
slategrey: "708090",
|
|
889
|
+
snow: "fffafa",
|
|
890
|
+
springgreen: "00ff7f",
|
|
891
|
+
steelblue: "4682b4",
|
|
892
|
+
tan: "d2b48c",
|
|
893
|
+
teal: "008080",
|
|
894
|
+
thistle: "d8bfd8",
|
|
895
|
+
tomato: "ff6347",
|
|
896
|
+
turquoise: "40e0d0",
|
|
897
|
+
violet: "ee82ee",
|
|
898
|
+
wheat: "f5deb3",
|
|
899
|
+
white: "fff",
|
|
900
|
+
whitesmoke: "f5f5f5",
|
|
901
|
+
yellow: "ff0",
|
|
902
|
+
yellowgreen: "9acd32"
|
|
903
|
+
};
|
|
904
|
+
function nameToHex(color) {
|
|
905
|
+
if (typeof color !== "string") return color;
|
|
906
|
+
var normalizedColorName = color.toLowerCase();
|
|
907
|
+
return namedColorMap[normalizedColorName] ? "#" + namedColorMap[normalizedColorName] : color;
|
|
908
|
+
}
|
|
909
|
+
exports["default"] = nameToHex;
|
|
910
|
+
module.exports = exports.default;
|
|
911
|
+
})(_nameToHex, _nameToHex.exports);
|
|
912
|
+
return _nameToHex.exports;
|
|
913
|
+
}
|
|
914
|
+
var _errors = { exports: {} };
|
|
915
|
+
var hasRequired_errors;
|
|
916
|
+
function require_errors() {
|
|
917
|
+
if (hasRequired_errors) return _errors.exports;
|
|
918
|
+
hasRequired_errors = 1;
|
|
919
|
+
(function(module, exports) {
|
|
920
|
+
exports.__esModule = true;
|
|
921
|
+
exports["default"] = void 0;
|
|
922
|
+
function _assertThisInitialized(self2) {
|
|
923
|
+
if (self2 === void 0) {
|
|
924
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
925
|
+
}
|
|
926
|
+
return self2;
|
|
927
|
+
}
|
|
928
|
+
function _inheritsLoose(subClass, superClass) {
|
|
929
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
930
|
+
subClass.prototype.constructor = subClass;
|
|
931
|
+
_setPrototypeOf(subClass, superClass);
|
|
932
|
+
}
|
|
933
|
+
function _wrapNativeSuper(Class) {
|
|
934
|
+
var _cache = typeof Map === "function" ? /* @__PURE__ */ new Map() : void 0;
|
|
935
|
+
_wrapNativeSuper = function _wrapNativeSuper2(Class2) {
|
|
936
|
+
if (Class2 === null || !_isNativeFunction(Class2)) return Class2;
|
|
937
|
+
if (typeof Class2 !== "function") {
|
|
938
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
939
|
+
}
|
|
940
|
+
if (typeof _cache !== "undefined") {
|
|
941
|
+
if (_cache.has(Class2)) return _cache.get(Class2);
|
|
942
|
+
_cache.set(Class2, Wrapper);
|
|
943
|
+
}
|
|
944
|
+
function Wrapper() {
|
|
945
|
+
return _construct(Class2, arguments, _getPrototypeOf(this).constructor);
|
|
946
|
+
}
|
|
947
|
+
Wrapper.prototype = Object.create(Class2.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });
|
|
948
|
+
return _setPrototypeOf(Wrapper, Class2);
|
|
949
|
+
};
|
|
950
|
+
return _wrapNativeSuper(Class);
|
|
951
|
+
}
|
|
952
|
+
function _construct(t, e, r) {
|
|
953
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
954
|
+
var o = [null];
|
|
955
|
+
o.push.apply(o, e);
|
|
956
|
+
var p = new (t.bind.apply(t, o))();
|
|
957
|
+
return r && _setPrototypeOf(p, r.prototype), p;
|
|
958
|
+
}
|
|
959
|
+
function _isNativeReflectConstruct() {
|
|
960
|
+
try {
|
|
961
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
|
|
962
|
+
}));
|
|
963
|
+
} catch (t2) {
|
|
964
|
+
}
|
|
965
|
+
return (_isNativeReflectConstruct = function _isNativeReflectConstruct2() {
|
|
966
|
+
return !!t;
|
|
967
|
+
})();
|
|
968
|
+
}
|
|
969
|
+
function _isNativeFunction(fn) {
|
|
970
|
+
try {
|
|
971
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
972
|
+
} catch (e) {
|
|
973
|
+
return typeof fn === "function";
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
function _setPrototypeOf(o, p) {
|
|
977
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) {
|
|
978
|
+
o2.__proto__ = p2;
|
|
979
|
+
return o2;
|
|
980
|
+
};
|
|
981
|
+
return _setPrototypeOf(o, p);
|
|
982
|
+
}
|
|
983
|
+
function _getPrototypeOf(o) {
|
|
984
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) {
|
|
985
|
+
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
986
|
+
};
|
|
987
|
+
return _getPrototypeOf(o);
|
|
988
|
+
}
|
|
989
|
+
var ERRORS = {
|
|
990
|
+
"1": "Passed invalid arguments to hsl, please pass multiple numbers e.g. hsl(360, 0.75, 0.4) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75 }).\n\n",
|
|
991
|
+
"2": "Passed invalid arguments to hsla, please pass multiple numbers e.g. hsla(360, 0.75, 0.4, 0.7) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75, alpha: 0.7 }).\n\n",
|
|
992
|
+
"3": "Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n",
|
|
993
|
+
"4": "Couldn't generate valid rgb string from %s, it returned %s.\n\n",
|
|
994
|
+
"5": "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n",
|
|
995
|
+
"6": "Passed invalid arguments to rgb, please pass multiple numbers e.g. rgb(255, 205, 100) or an object e.g. rgb({ red: 255, green: 205, blue: 100 }).\n\n",
|
|
996
|
+
"7": "Passed invalid arguments to rgba, please pass multiple numbers e.g. rgb(255, 205, 100, 0.75) or an object e.g. rgb({ red: 255, green: 205, blue: 100, alpha: 0.75 }).\n\n",
|
|
997
|
+
"8": "Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n",
|
|
998
|
+
"9": "Please provide a number of steps to the modularScale helper.\n\n",
|
|
999
|
+
"10": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
|
|
1000
|
+
"11": 'Invalid value passed as base to modularScale, expected number or em string but got "%s"\n\n',
|
|
1001
|
+
"12": 'Expected a string ending in "px" or a number passed as the first argument to %s(), got "%s" instead.\n\n',
|
|
1002
|
+
"13": 'Expected a string ending in "px" or a number passed as the second argument to %s(), got "%s" instead.\n\n',
|
|
1003
|
+
"14": 'Passed invalid pixel value ("%s") to %s(), please pass a value like "12px" or 12.\n\n',
|
|
1004
|
+
"15": 'Passed invalid base value ("%s") to %s(), please pass a value like "12px" or 12.\n\n',
|
|
1005
|
+
"16": "You must provide a template to this method.\n\n",
|
|
1006
|
+
"17": "You passed an unsupported selector state to this method.\n\n",
|
|
1007
|
+
"18": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
|
|
1008
|
+
"19": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
|
|
1009
|
+
"20": "expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
|
|
1010
|
+
"21": "expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
|
|
1011
|
+
"22": "expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
|
|
1012
|
+
"23": "fontFace expects a name of a font-family.\n\n",
|
|
1013
|
+
"24": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
|
|
1014
|
+
"25": "fontFace expects localFonts to be an array.\n\n",
|
|
1015
|
+
"26": "fontFace expects fileFormats to be an array.\n\n",
|
|
1016
|
+
"27": "radialGradient requries at least 2 color-stops to properly render.\n\n",
|
|
1017
|
+
"28": "Please supply a filename to retinaImage() as the first argument.\n\n",
|
|
1018
|
+
"29": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
|
|
1019
|
+
"30": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
|
|
1020
|
+
"31": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n",
|
|
1021
|
+
"32": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s')\n\n",
|
|
1022
|
+
"33": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n",
|
|
1023
|
+
"34": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
|
|
1024
|
+
"35": 'borderRadius expects one of "top", "bottom", "left" or "right" as the first argument.\n\n',
|
|
1025
|
+
"36": "Property must be a string value.\n\n",
|
|
1026
|
+
"37": "Syntax Error at %s.\n\n",
|
|
1027
|
+
"38": "Formula contains a function that needs parentheses at %s.\n\n",
|
|
1028
|
+
"39": "Formula is missing closing parenthesis at %s.\n\n",
|
|
1029
|
+
"40": "Formula has too many closing parentheses at %s.\n\n",
|
|
1030
|
+
"41": "All values in a formula must have the same unit or be unitless.\n\n",
|
|
1031
|
+
"42": "Please provide a number of steps to the modularScale helper.\n\n",
|
|
1032
|
+
"43": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
|
|
1033
|
+
"44": "Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n",
|
|
1034
|
+
"45": "Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n",
|
|
1035
|
+
"46": "Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n",
|
|
1036
|
+
"47": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
|
|
1037
|
+
"48": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
|
|
1038
|
+
"49": "Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
|
|
1039
|
+
"50": "Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n",
|
|
1040
|
+
"51": "Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n",
|
|
1041
|
+
"52": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
|
|
1042
|
+
"53": "fontFace expects localFonts to be an array.\n\n",
|
|
1043
|
+
"54": "fontFace expects fileFormats to be an array.\n\n",
|
|
1044
|
+
"55": "fontFace expects a name of a font-family.\n\n",
|
|
1045
|
+
"56": "linearGradient requries at least 2 color-stops to properly render.\n\n",
|
|
1046
|
+
"57": "radialGradient requries at least 2 color-stops to properly render.\n\n",
|
|
1047
|
+
"58": "Please supply a filename to retinaImage() as the first argument.\n\n",
|
|
1048
|
+
"59": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
|
|
1049
|
+
"60": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
|
|
1050
|
+
"61": "Property must be a string value.\n\n",
|
|
1051
|
+
"62": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
|
|
1052
|
+
"63": 'borderRadius expects one of "top", "bottom", "left" or "right" as the first argument.\n\n',
|
|
1053
|
+
"64": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n",
|
|
1054
|
+
"65": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s').\n\n",
|
|
1055
|
+
"66": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n",
|
|
1056
|
+
"67": "You must provide a template to this method.\n\n",
|
|
1057
|
+
"68": "You passed an unsupported selector state to this method.\n\n",
|
|
1058
|
+
"69": 'Expected a string ending in "px" or a number passed as the first argument to %s(), got %s instead.\n\n',
|
|
1059
|
+
"70": 'Expected a string ending in "px" or a number passed as the second argument to %s(), got %s instead.\n\n',
|
|
1060
|
+
"71": 'Passed invalid pixel value %s to %s(), please pass a value like "12px" or 12.\n\n',
|
|
1061
|
+
"72": 'Passed invalid base value %s to %s(), please pass a value like "12px" or 12.\n\n',
|
|
1062
|
+
"73": "Please provide a valid CSS variable.\n\n",
|
|
1063
|
+
"74": "CSS variable not found and no default was provided.\n\n",
|
|
1064
|
+
"75": "important requires a valid style object, got a %s instead.\n\n",
|
|
1065
|
+
"76": "fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n",
|
|
1066
|
+
"77": 'remToPx expects a value in "rem" but you provided it in "%s".\n\n',
|
|
1067
|
+
"78": 'base must be set in "px" or "%" but you set it in "%s".\n'
|
|
1068
|
+
};
|
|
1069
|
+
function format() {
|
|
1070
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1071
|
+
args[_key] = arguments[_key];
|
|
1072
|
+
}
|
|
1073
|
+
var a = args[0];
|
|
1074
|
+
var b = [];
|
|
1075
|
+
var c;
|
|
1076
|
+
for (c = 1; c < args.length; c += 1) {
|
|
1077
|
+
b.push(args[c]);
|
|
1078
|
+
}
|
|
1079
|
+
b.forEach(function(d) {
|
|
1080
|
+
a = a.replace(/%[a-z]/, d);
|
|
1081
|
+
});
|
|
1082
|
+
return a;
|
|
1083
|
+
}
|
|
1084
|
+
exports["default"] = /* @__PURE__ */ function(_Error) {
|
|
1085
|
+
_inheritsLoose(PolishedError, _Error);
|
|
1086
|
+
function PolishedError(code) {
|
|
1087
|
+
var _this;
|
|
1088
|
+
if (process.env.NODE_ENV === "production") {
|
|
1089
|
+
_this = _Error.call(this, "An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#" + code + " for more information.") || this;
|
|
1090
|
+
} else {
|
|
1091
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1092
|
+
args[_key2 - 1] = arguments[_key2];
|
|
1093
|
+
}
|
|
1094
|
+
_this = _Error.call(this, format.apply(void 0, [ERRORS[code]].concat(args))) || this;
|
|
1095
|
+
}
|
|
1096
|
+
return _assertThisInitialized(_this);
|
|
1097
|
+
}
|
|
1098
|
+
return PolishedError;
|
|
1099
|
+
}(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
1100
|
+
module.exports = exports.default;
|
|
1101
|
+
})(_errors, _errors.exports);
|
|
1102
|
+
return _errors.exports;
|
|
1103
|
+
}
|
|
1104
|
+
var hasRequiredParseToRgb;
|
|
1105
|
+
function requireParseToRgb() {
|
|
1106
|
+
if (hasRequiredParseToRgb) return parseToRgb.exports;
|
|
1107
|
+
hasRequiredParseToRgb = 1;
|
|
1108
|
+
(function(module, exports) {
|
|
1109
|
+
exports.__esModule = true;
|
|
1110
|
+
exports["default"] = parseToRgb2;
|
|
1111
|
+
var _hslToRgb2 = _interopRequireDefault(/* @__PURE__ */ require_hslToRgb());
|
|
1112
|
+
var _nameToHex2 = _interopRequireDefault(/* @__PURE__ */ require_nameToHex());
|
|
1113
|
+
var _errors2 = _interopRequireDefault(/* @__PURE__ */ require_errors());
|
|
1114
|
+
function _interopRequireDefault(obj) {
|
|
1115
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1116
|
+
}
|
|
1117
|
+
var hexRegex = /^#[a-fA-F0-9]{6}$/;
|
|
1118
|
+
var hexRgbaRegex = /^#[a-fA-F0-9]{8}$/;
|
|
1119
|
+
var reducedHexRegex = /^#[a-fA-F0-9]{3}$/;
|
|
1120
|
+
var reducedRgbaHexRegex = /^#[a-fA-F0-9]{4}$/;
|
|
1121
|
+
var rgbRegex = /^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i;
|
|
1122
|
+
var rgbaRegex = /^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i;
|
|
1123
|
+
var hslRegex = /^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i;
|
|
1124
|
+
var hslaRegex = /^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i;
|
|
1125
|
+
function parseToRgb2(color) {
|
|
1126
|
+
if (typeof color !== "string") {
|
|
1127
|
+
throw new _errors2["default"](3);
|
|
1128
|
+
}
|
|
1129
|
+
var normalizedColor = (0, _nameToHex2["default"])(color);
|
|
1130
|
+
if (normalizedColor.match(hexRegex)) {
|
|
1131
|
+
return {
|
|
1132
|
+
red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16),
|
|
1133
|
+
green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16),
|
|
1134
|
+
blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16)
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
if (normalizedColor.match(hexRgbaRegex)) {
|
|
1138
|
+
var alpha = parseFloat((parseInt("" + normalizedColor[7] + normalizedColor[8], 16) / 255).toFixed(2));
|
|
1139
|
+
return {
|
|
1140
|
+
red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16),
|
|
1141
|
+
green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16),
|
|
1142
|
+
blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16),
|
|
1143
|
+
alpha
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
if (normalizedColor.match(reducedHexRegex)) {
|
|
1147
|
+
return {
|
|
1148
|
+
red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16),
|
|
1149
|
+
green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16),
|
|
1150
|
+
blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16)
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
if (normalizedColor.match(reducedRgbaHexRegex)) {
|
|
1154
|
+
var _alpha = parseFloat((parseInt("" + normalizedColor[4] + normalizedColor[4], 16) / 255).toFixed(2));
|
|
1155
|
+
return {
|
|
1156
|
+
red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16),
|
|
1157
|
+
green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16),
|
|
1158
|
+
blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16),
|
|
1159
|
+
alpha: _alpha
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
var rgbMatched = rgbRegex.exec(normalizedColor);
|
|
1163
|
+
if (rgbMatched) {
|
|
1164
|
+
return {
|
|
1165
|
+
red: parseInt("" + rgbMatched[1], 10),
|
|
1166
|
+
green: parseInt("" + rgbMatched[2], 10),
|
|
1167
|
+
blue: parseInt("" + rgbMatched[3], 10)
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
var rgbaMatched = rgbaRegex.exec(normalizedColor.substring(0, 50));
|
|
1171
|
+
if (rgbaMatched) {
|
|
1172
|
+
return {
|
|
1173
|
+
red: parseInt("" + rgbaMatched[1], 10),
|
|
1174
|
+
green: parseInt("" + rgbaMatched[2], 10),
|
|
1175
|
+
blue: parseInt("" + rgbaMatched[3], 10),
|
|
1176
|
+
alpha: parseFloat("" + rgbaMatched[4]) > 1 ? parseFloat("" + rgbaMatched[4]) / 100 : parseFloat("" + rgbaMatched[4])
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
var hslMatched = hslRegex.exec(normalizedColor);
|
|
1180
|
+
if (hslMatched) {
|
|
1181
|
+
var hue = parseInt("" + hslMatched[1], 10);
|
|
1182
|
+
var saturation = parseInt("" + hslMatched[2], 10) / 100;
|
|
1183
|
+
var lightness = parseInt("" + hslMatched[3], 10) / 100;
|
|
1184
|
+
var rgbColorString = "rgb(" + (0, _hslToRgb2["default"])(hue, saturation, lightness) + ")";
|
|
1185
|
+
var hslRgbMatched = rgbRegex.exec(rgbColorString);
|
|
1186
|
+
if (!hslRgbMatched) {
|
|
1187
|
+
throw new _errors2["default"](4, normalizedColor, rgbColorString);
|
|
1188
|
+
}
|
|
1189
|
+
return {
|
|
1190
|
+
red: parseInt("" + hslRgbMatched[1], 10),
|
|
1191
|
+
green: parseInt("" + hslRgbMatched[2], 10),
|
|
1192
|
+
blue: parseInt("" + hslRgbMatched[3], 10)
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
var hslaMatched = hslaRegex.exec(normalizedColor.substring(0, 50));
|
|
1196
|
+
if (hslaMatched) {
|
|
1197
|
+
var _hue = parseInt("" + hslaMatched[1], 10);
|
|
1198
|
+
var _saturation = parseInt("" + hslaMatched[2], 10) / 100;
|
|
1199
|
+
var _lightness = parseInt("" + hslaMatched[3], 10) / 100;
|
|
1200
|
+
var _rgbColorString = "rgb(" + (0, _hslToRgb2["default"])(_hue, _saturation, _lightness) + ")";
|
|
1201
|
+
var _hslRgbMatched = rgbRegex.exec(_rgbColorString);
|
|
1202
|
+
if (!_hslRgbMatched) {
|
|
1203
|
+
throw new _errors2["default"](4, normalizedColor, _rgbColorString);
|
|
1204
|
+
}
|
|
1205
|
+
return {
|
|
1206
|
+
red: parseInt("" + _hslRgbMatched[1], 10),
|
|
1207
|
+
green: parseInt("" + _hslRgbMatched[2], 10),
|
|
1208
|
+
blue: parseInt("" + _hslRgbMatched[3], 10),
|
|
1209
|
+
alpha: parseFloat("" + hslaMatched[4]) > 1 ? parseFloat("" + hslaMatched[4]) / 100 : parseFloat("" + hslaMatched[4])
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
throw new _errors2["default"](5);
|
|
1213
|
+
}
|
|
1214
|
+
module.exports = exports.default;
|
|
1215
|
+
})(parseToRgb, parseToRgb.exports);
|
|
1216
|
+
return parseToRgb.exports;
|
|
1217
|
+
}
|
|
1218
|
+
var hasRequiredGetLuminance;
|
|
1219
|
+
function requireGetLuminance() {
|
|
1220
|
+
if (hasRequiredGetLuminance) return getLuminance$1.exports;
|
|
1221
|
+
hasRequiredGetLuminance = 1;
|
|
1222
|
+
(function(module, exports) {
|
|
1223
|
+
exports.__esModule = true;
|
|
1224
|
+
exports["default"] = getLuminance2;
|
|
1225
|
+
var _parseToRgb = _interopRequireDefault(/* @__PURE__ */ requireParseToRgb());
|
|
1226
|
+
function _interopRequireDefault(obj) {
|
|
1227
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1228
|
+
}
|
|
1229
|
+
function getLuminance2(color) {
|
|
1230
|
+
if (color === "transparent") return 0;
|
|
1231
|
+
var rgbColor = (0, _parseToRgb["default"])(color);
|
|
1232
|
+
var _Object$keys$map = Object.keys(rgbColor).map(function(key) {
|
|
1233
|
+
var channel = rgbColor[key] / 255;
|
|
1234
|
+
return channel <= 0.03928 ? channel / 12.92 : Math.pow((channel + 0.055) / 1.055, 2.4);
|
|
1235
|
+
}), r = _Object$keys$map[0], g = _Object$keys$map[1], b = _Object$keys$map[2];
|
|
1236
|
+
return parseFloat((0.2126 * r + 0.7152 * g + 0.0722 * b).toFixed(3));
|
|
1237
|
+
}
|
|
1238
|
+
module.exports = exports.default;
|
|
1239
|
+
})(getLuminance$1, getLuminance$1.exports);
|
|
1240
|
+
return getLuminance$1.exports;
|
|
1241
|
+
}
|
|
1242
|
+
var getLuminanceExports = /* @__PURE__ */ requireGetLuminance();
|
|
1243
|
+
const getLuminance = /* @__PURE__ */ getDefaultExportFromCjs(getLuminanceExports);
|
|
1244
|
+
var darken$1 = { exports: {} };
|
|
1245
|
+
var _curry = { exports: {} };
|
|
1246
|
+
var hasRequired_curry;
|
|
1247
|
+
function require_curry() {
|
|
1248
|
+
if (hasRequired_curry) return _curry.exports;
|
|
1249
|
+
hasRequired_curry = 1;
|
|
1250
|
+
(function(module, exports) {
|
|
1251
|
+
exports.__esModule = true;
|
|
1252
|
+
exports["default"] = curry;
|
|
1253
|
+
function curried(f, length, acc) {
|
|
1254
|
+
return function fn() {
|
|
1255
|
+
var combined = acc.concat(Array.prototype.slice.call(arguments));
|
|
1256
|
+
return combined.length >= length ? f.apply(this, combined) : curried(f, length, combined);
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
function curry(f) {
|
|
1260
|
+
return curried(f, f.length, []);
|
|
1261
|
+
}
|
|
1262
|
+
module.exports = exports.default;
|
|
1263
|
+
})(_curry, _curry.exports);
|
|
1264
|
+
return _curry.exports;
|
|
1265
|
+
}
|
|
1266
|
+
var _guard = { exports: {} };
|
|
1267
|
+
var hasRequired_guard;
|
|
1268
|
+
function require_guard() {
|
|
1269
|
+
if (hasRequired_guard) return _guard.exports;
|
|
1270
|
+
hasRequired_guard = 1;
|
|
1271
|
+
(function(module, exports) {
|
|
1272
|
+
exports.__esModule = true;
|
|
1273
|
+
exports["default"] = void 0;
|
|
1274
|
+
function guard(lowerBoundary, upperBoundary, value) {
|
|
1275
|
+
return Math.max(lowerBoundary, Math.min(upperBoundary, value));
|
|
1276
|
+
}
|
|
1277
|
+
exports["default"] = guard;
|
|
1278
|
+
module.exports = exports.default;
|
|
1279
|
+
})(_guard, _guard.exports);
|
|
1280
|
+
return _guard.exports;
|
|
1281
|
+
}
|
|
1282
|
+
var parseToHsl = { exports: {} };
|
|
1283
|
+
var _rgbToHsl = { exports: {} };
|
|
1284
|
+
var hasRequired_rgbToHsl;
|
|
1285
|
+
function require_rgbToHsl() {
|
|
1286
|
+
if (hasRequired_rgbToHsl) return _rgbToHsl.exports;
|
|
1287
|
+
hasRequired_rgbToHsl = 1;
|
|
1288
|
+
(function(module, exports) {
|
|
1289
|
+
exports.__esModule = true;
|
|
1290
|
+
exports["default"] = void 0;
|
|
1291
|
+
function rgbToHsl(color) {
|
|
1292
|
+
var red = color.red / 255;
|
|
1293
|
+
var green = color.green / 255;
|
|
1294
|
+
var blue = color.blue / 255;
|
|
1295
|
+
var max = Math.max(red, green, blue);
|
|
1296
|
+
var min = Math.min(red, green, blue);
|
|
1297
|
+
var lightness = (max + min) / 2;
|
|
1298
|
+
if (max === min) {
|
|
1299
|
+
if (color.alpha !== void 0) {
|
|
1300
|
+
return {
|
|
1301
|
+
hue: 0,
|
|
1302
|
+
saturation: 0,
|
|
1303
|
+
lightness,
|
|
1304
|
+
alpha: color.alpha
|
|
1305
|
+
};
|
|
1306
|
+
} else {
|
|
1307
|
+
return {
|
|
1308
|
+
hue: 0,
|
|
1309
|
+
saturation: 0,
|
|
1310
|
+
lightness
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
var hue;
|
|
1315
|
+
var delta = max - min;
|
|
1316
|
+
var saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
|
1317
|
+
switch (max) {
|
|
1318
|
+
case red:
|
|
1319
|
+
hue = (green - blue) / delta + (green < blue ? 6 : 0);
|
|
1320
|
+
break;
|
|
1321
|
+
case green:
|
|
1322
|
+
hue = (blue - red) / delta + 2;
|
|
1323
|
+
break;
|
|
1324
|
+
default:
|
|
1325
|
+
hue = (red - green) / delta + 4;
|
|
1326
|
+
break;
|
|
1327
|
+
}
|
|
1328
|
+
hue *= 60;
|
|
1329
|
+
if (color.alpha !== void 0) {
|
|
1330
|
+
return {
|
|
1331
|
+
hue,
|
|
1332
|
+
saturation,
|
|
1333
|
+
lightness,
|
|
1334
|
+
alpha: color.alpha
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
return {
|
|
1338
|
+
hue,
|
|
1339
|
+
saturation,
|
|
1340
|
+
lightness
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
exports["default"] = rgbToHsl;
|
|
1344
|
+
module.exports = exports.default;
|
|
1345
|
+
})(_rgbToHsl, _rgbToHsl.exports);
|
|
1346
|
+
return _rgbToHsl.exports;
|
|
1347
|
+
}
|
|
1348
|
+
var hasRequiredParseToHsl;
|
|
1349
|
+
function requireParseToHsl() {
|
|
1350
|
+
if (hasRequiredParseToHsl) return parseToHsl.exports;
|
|
1351
|
+
hasRequiredParseToHsl = 1;
|
|
1352
|
+
(function(module, exports) {
|
|
1353
|
+
exports.__esModule = true;
|
|
1354
|
+
exports["default"] = parseToHsl2;
|
|
1355
|
+
var _parseToRgb = _interopRequireDefault(/* @__PURE__ */ requireParseToRgb());
|
|
1356
|
+
var _rgbToHsl2 = _interopRequireDefault(/* @__PURE__ */ require_rgbToHsl());
|
|
1357
|
+
function _interopRequireDefault(obj) {
|
|
1358
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1359
|
+
}
|
|
1360
|
+
function parseToHsl2(color) {
|
|
1361
|
+
return (0, _rgbToHsl2["default"])((0, _parseToRgb["default"])(color));
|
|
1362
|
+
}
|
|
1363
|
+
module.exports = exports.default;
|
|
1364
|
+
})(parseToHsl, parseToHsl.exports);
|
|
1365
|
+
return parseToHsl.exports;
|
|
1366
|
+
}
|
|
1367
|
+
var toColorString = { exports: {} };
|
|
1368
|
+
var hsl = { exports: {} };
|
|
1369
|
+
var _hslToHex = { exports: {} };
|
|
1370
|
+
var _reduceHexValue = { exports: {} };
|
|
1371
|
+
var hasRequired_reduceHexValue;
|
|
1372
|
+
function require_reduceHexValue() {
|
|
1373
|
+
if (hasRequired_reduceHexValue) return _reduceHexValue.exports;
|
|
1374
|
+
hasRequired_reduceHexValue = 1;
|
|
1375
|
+
(function(module, exports) {
|
|
1376
|
+
exports.__esModule = true;
|
|
1377
|
+
exports["default"] = void 0;
|
|
1378
|
+
var reduceHexValue = function reduceHexValue2(value) {
|
|
1379
|
+
if (value.length === 7 && value[1] === value[2] && value[3] === value[4] && value[5] === value[6]) {
|
|
1380
|
+
return "#" + value[1] + value[3] + value[5];
|
|
1381
|
+
}
|
|
1382
|
+
return value;
|
|
1383
|
+
};
|
|
1384
|
+
exports["default"] = reduceHexValue;
|
|
1385
|
+
module.exports = exports.default;
|
|
1386
|
+
})(_reduceHexValue, _reduceHexValue.exports);
|
|
1387
|
+
return _reduceHexValue.exports;
|
|
1388
|
+
}
|
|
1389
|
+
var _numberToHex = { exports: {} };
|
|
1390
|
+
var hasRequired_numberToHex;
|
|
1391
|
+
function require_numberToHex() {
|
|
1392
|
+
if (hasRequired_numberToHex) return _numberToHex.exports;
|
|
1393
|
+
hasRequired_numberToHex = 1;
|
|
1394
|
+
(function(module, exports) {
|
|
1395
|
+
exports.__esModule = true;
|
|
1396
|
+
exports["default"] = void 0;
|
|
1397
|
+
function numberToHex(value) {
|
|
1398
|
+
var hex = value.toString(16);
|
|
1399
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
1400
|
+
}
|
|
1401
|
+
exports["default"] = numberToHex;
|
|
1402
|
+
module.exports = exports.default;
|
|
1403
|
+
})(_numberToHex, _numberToHex.exports);
|
|
1404
|
+
return _numberToHex.exports;
|
|
1405
|
+
}
|
|
1406
|
+
var hasRequired_hslToHex;
|
|
1407
|
+
function require_hslToHex() {
|
|
1408
|
+
if (hasRequired_hslToHex) return _hslToHex.exports;
|
|
1409
|
+
hasRequired_hslToHex = 1;
|
|
1410
|
+
(function(module, exports) {
|
|
1411
|
+
exports.__esModule = true;
|
|
1412
|
+
exports["default"] = void 0;
|
|
1413
|
+
var _hslToRgb2 = _interopRequireDefault(/* @__PURE__ */ require_hslToRgb());
|
|
1414
|
+
var _reduceHexValue2 = _interopRequireDefault(/* @__PURE__ */ require_reduceHexValue());
|
|
1415
|
+
var _numberToHex2 = _interopRequireDefault(/* @__PURE__ */ require_numberToHex());
|
|
1416
|
+
function _interopRequireDefault(obj) {
|
|
1417
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1418
|
+
}
|
|
1419
|
+
function colorToHex(color) {
|
|
1420
|
+
return (0, _numberToHex2["default"])(Math.round(color * 255));
|
|
1421
|
+
}
|
|
1422
|
+
function convertToHex(red, green, blue) {
|
|
1423
|
+
return (0, _reduceHexValue2["default"])("#" + colorToHex(red) + colorToHex(green) + colorToHex(blue));
|
|
1424
|
+
}
|
|
1425
|
+
function hslToHex(hue, saturation, lightness) {
|
|
1426
|
+
return (0, _hslToRgb2["default"])(hue, saturation, lightness, convertToHex);
|
|
1427
|
+
}
|
|
1428
|
+
exports["default"] = hslToHex;
|
|
1429
|
+
module.exports = exports.default;
|
|
1430
|
+
})(_hslToHex, _hslToHex.exports);
|
|
1431
|
+
return _hslToHex.exports;
|
|
1432
|
+
}
|
|
1433
|
+
var hasRequiredHsl;
|
|
1434
|
+
function requireHsl() {
|
|
1435
|
+
if (hasRequiredHsl) return hsl.exports;
|
|
1436
|
+
hasRequiredHsl = 1;
|
|
1437
|
+
(function(module, exports) {
|
|
1438
|
+
exports.__esModule = true;
|
|
1439
|
+
exports["default"] = hsl2;
|
|
1440
|
+
var _hslToHex2 = _interopRequireDefault(/* @__PURE__ */ require_hslToHex());
|
|
1441
|
+
var _errors2 = _interopRequireDefault(/* @__PURE__ */ require_errors());
|
|
1442
|
+
function _interopRequireDefault(obj) {
|
|
1443
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1444
|
+
}
|
|
1445
|
+
function hsl2(value, saturation, lightness) {
|
|
1446
|
+
if (typeof value === "number" && typeof saturation === "number" && typeof lightness === "number") {
|
|
1447
|
+
return (0, _hslToHex2["default"])(value, saturation, lightness);
|
|
1448
|
+
} else if (typeof value === "object" && saturation === void 0 && lightness === void 0) {
|
|
1449
|
+
return (0, _hslToHex2["default"])(value.hue, value.saturation, value.lightness);
|
|
1450
|
+
}
|
|
1451
|
+
throw new _errors2["default"](1);
|
|
1452
|
+
}
|
|
1453
|
+
module.exports = exports.default;
|
|
1454
|
+
})(hsl, hsl.exports);
|
|
1455
|
+
return hsl.exports;
|
|
1456
|
+
}
|
|
1457
|
+
var hsla = { exports: {} };
|
|
1458
|
+
var hasRequiredHsla;
|
|
1459
|
+
function requireHsla() {
|
|
1460
|
+
if (hasRequiredHsla) return hsla.exports;
|
|
1461
|
+
hasRequiredHsla = 1;
|
|
1462
|
+
(function(module, exports) {
|
|
1463
|
+
exports.__esModule = true;
|
|
1464
|
+
exports["default"] = hsla2;
|
|
1465
|
+
var _hslToHex2 = _interopRequireDefault(/* @__PURE__ */ require_hslToHex());
|
|
1466
|
+
var _hslToRgb2 = _interopRequireDefault(/* @__PURE__ */ require_hslToRgb());
|
|
1467
|
+
var _errors2 = _interopRequireDefault(/* @__PURE__ */ require_errors());
|
|
1468
|
+
function _interopRequireDefault(obj) {
|
|
1469
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1470
|
+
}
|
|
1471
|
+
function hsla2(value, saturation, lightness, alpha) {
|
|
1472
|
+
if (typeof value === "number" && typeof saturation === "number" && typeof lightness === "number" && typeof alpha === "number") {
|
|
1473
|
+
return alpha >= 1 ? (0, _hslToHex2["default"])(value, saturation, lightness) : "rgba(" + (0, _hslToRgb2["default"])(value, saturation, lightness) + "," + alpha + ")";
|
|
1474
|
+
} else if (typeof value === "object" && saturation === void 0 && lightness === void 0 && alpha === void 0) {
|
|
1475
|
+
return value.alpha >= 1 ? (0, _hslToHex2["default"])(value.hue, value.saturation, value.lightness) : "rgba(" + (0, _hslToRgb2["default"])(value.hue, value.saturation, value.lightness) + "," + value.alpha + ")";
|
|
1476
|
+
}
|
|
1477
|
+
throw new _errors2["default"](2);
|
|
1478
|
+
}
|
|
1479
|
+
module.exports = exports.default;
|
|
1480
|
+
})(hsla, hsla.exports);
|
|
1481
|
+
return hsla.exports;
|
|
1482
|
+
}
|
|
1483
|
+
var rgb = { exports: {} };
|
|
1484
|
+
var hasRequiredRgb;
|
|
1485
|
+
function requireRgb() {
|
|
1486
|
+
if (hasRequiredRgb) return rgb.exports;
|
|
1487
|
+
hasRequiredRgb = 1;
|
|
1488
|
+
(function(module, exports) {
|
|
1489
|
+
exports.__esModule = true;
|
|
1490
|
+
exports["default"] = rgb2;
|
|
1491
|
+
var _reduceHexValue2 = _interopRequireDefault(/* @__PURE__ */ require_reduceHexValue());
|
|
1492
|
+
var _numberToHex2 = _interopRequireDefault(/* @__PURE__ */ require_numberToHex());
|
|
1493
|
+
var _errors2 = _interopRequireDefault(/* @__PURE__ */ require_errors());
|
|
1494
|
+
function _interopRequireDefault(obj) {
|
|
1495
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1496
|
+
}
|
|
1497
|
+
function rgb2(value, green, blue) {
|
|
1498
|
+
if (typeof value === "number" && typeof green === "number" && typeof blue === "number") {
|
|
1499
|
+
return (0, _reduceHexValue2["default"])("#" + (0, _numberToHex2["default"])(value) + (0, _numberToHex2["default"])(green) + (0, _numberToHex2["default"])(blue));
|
|
1500
|
+
} else if (typeof value === "object" && green === void 0 && blue === void 0) {
|
|
1501
|
+
return (0, _reduceHexValue2["default"])("#" + (0, _numberToHex2["default"])(value.red) + (0, _numberToHex2["default"])(value.green) + (0, _numberToHex2["default"])(value.blue));
|
|
1502
|
+
}
|
|
1503
|
+
throw new _errors2["default"](6);
|
|
1504
|
+
}
|
|
1505
|
+
module.exports = exports.default;
|
|
1506
|
+
})(rgb, rgb.exports);
|
|
1507
|
+
return rgb.exports;
|
|
1508
|
+
}
|
|
1509
|
+
var rgba = { exports: {} };
|
|
1510
|
+
var hasRequiredRgba;
|
|
1511
|
+
function requireRgba() {
|
|
1512
|
+
if (hasRequiredRgba) return rgba.exports;
|
|
1513
|
+
hasRequiredRgba = 1;
|
|
1514
|
+
(function(module, exports) {
|
|
1515
|
+
exports.__esModule = true;
|
|
1516
|
+
exports["default"] = rgba2;
|
|
1517
|
+
var _parseToRgb = _interopRequireDefault(/* @__PURE__ */ requireParseToRgb());
|
|
1518
|
+
var _rgb = _interopRequireDefault(/* @__PURE__ */ requireRgb());
|
|
1519
|
+
var _errors2 = _interopRequireDefault(/* @__PURE__ */ require_errors());
|
|
1520
|
+
function _interopRequireDefault(obj) {
|
|
1521
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1522
|
+
}
|
|
1523
|
+
function rgba2(firstValue, secondValue, thirdValue, fourthValue) {
|
|
1524
|
+
if (typeof firstValue === "string" && typeof secondValue === "number") {
|
|
1525
|
+
var rgbValue = (0, _parseToRgb["default"])(firstValue);
|
|
1526
|
+
return "rgba(" + rgbValue.red + "," + rgbValue.green + "," + rgbValue.blue + "," + secondValue + ")";
|
|
1527
|
+
} else if (typeof firstValue === "number" && typeof secondValue === "number" && typeof thirdValue === "number" && typeof fourthValue === "number") {
|
|
1528
|
+
return fourthValue >= 1 ? (0, _rgb["default"])(firstValue, secondValue, thirdValue) : "rgba(" + firstValue + "," + secondValue + "," + thirdValue + "," + fourthValue + ")";
|
|
1529
|
+
} else if (typeof firstValue === "object" && secondValue === void 0 && thirdValue === void 0 && fourthValue === void 0) {
|
|
1530
|
+
return firstValue.alpha >= 1 ? (0, _rgb["default"])(firstValue.red, firstValue.green, firstValue.blue) : "rgba(" + firstValue.red + "," + firstValue.green + "," + firstValue.blue + "," + firstValue.alpha + ")";
|
|
1531
|
+
}
|
|
1532
|
+
throw new _errors2["default"](7);
|
|
1533
|
+
}
|
|
1534
|
+
module.exports = exports.default;
|
|
1535
|
+
})(rgba, rgba.exports);
|
|
1536
|
+
return rgba.exports;
|
|
1537
|
+
}
|
|
1538
|
+
var hasRequiredToColorString;
|
|
1539
|
+
function requireToColorString() {
|
|
1540
|
+
if (hasRequiredToColorString) return toColorString.exports;
|
|
1541
|
+
hasRequiredToColorString = 1;
|
|
1542
|
+
(function(module, exports) {
|
|
1543
|
+
exports.__esModule = true;
|
|
1544
|
+
exports["default"] = toColorString2;
|
|
1545
|
+
var _hsl = _interopRequireDefault(/* @__PURE__ */ requireHsl());
|
|
1546
|
+
var _hsla = _interopRequireDefault(/* @__PURE__ */ requireHsla());
|
|
1547
|
+
var _rgb = _interopRequireDefault(/* @__PURE__ */ requireRgb());
|
|
1548
|
+
var _rgba = _interopRequireDefault(/* @__PURE__ */ requireRgba());
|
|
1549
|
+
var _errors2 = _interopRequireDefault(/* @__PURE__ */ require_errors());
|
|
1550
|
+
function _interopRequireDefault(obj) {
|
|
1551
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1552
|
+
}
|
|
1553
|
+
var isRgb = function isRgb2(color) {
|
|
1554
|
+
return typeof color.red === "number" && typeof color.green === "number" && typeof color.blue === "number" && (typeof color.alpha !== "number" || typeof color.alpha === "undefined");
|
|
1555
|
+
};
|
|
1556
|
+
var isRgba = function isRgba2(color) {
|
|
1557
|
+
return typeof color.red === "number" && typeof color.green === "number" && typeof color.blue === "number" && typeof color.alpha === "number";
|
|
1558
|
+
};
|
|
1559
|
+
var isHsl = function isHsl2(color) {
|
|
1560
|
+
return typeof color.hue === "number" && typeof color.saturation === "number" && typeof color.lightness === "number" && (typeof color.alpha !== "number" || typeof color.alpha === "undefined");
|
|
1561
|
+
};
|
|
1562
|
+
var isHsla = function isHsla2(color) {
|
|
1563
|
+
return typeof color.hue === "number" && typeof color.saturation === "number" && typeof color.lightness === "number" && typeof color.alpha === "number";
|
|
1564
|
+
};
|
|
1565
|
+
function toColorString2(color) {
|
|
1566
|
+
if (typeof color !== "object") throw new _errors2["default"](8);
|
|
1567
|
+
if (isRgba(color)) return (0, _rgba["default"])(color);
|
|
1568
|
+
if (isRgb(color)) return (0, _rgb["default"])(color);
|
|
1569
|
+
if (isHsla(color)) return (0, _hsla["default"])(color);
|
|
1570
|
+
if (isHsl(color)) return (0, _hsl["default"])(color);
|
|
1571
|
+
throw new _errors2["default"](8);
|
|
1572
|
+
}
|
|
1573
|
+
module.exports = exports.default;
|
|
1574
|
+
})(toColorString, toColorString.exports);
|
|
1575
|
+
return toColorString.exports;
|
|
1576
|
+
}
|
|
1577
|
+
var hasRequiredDarken;
|
|
1578
|
+
function requireDarken() {
|
|
1579
|
+
if (hasRequiredDarken) return darken$1.exports;
|
|
1580
|
+
hasRequiredDarken = 1;
|
|
1581
|
+
(function(module, exports) {
|
|
1582
|
+
exports.__esModule = true;
|
|
1583
|
+
exports["default"] = void 0;
|
|
1584
|
+
var _curry2 = _interopRequireDefault(/* @__PURE__ */ require_curry());
|
|
1585
|
+
var _guard2 = _interopRequireDefault(/* @__PURE__ */ require_guard());
|
|
1586
|
+
var _parseToHsl = _interopRequireDefault(/* @__PURE__ */ requireParseToHsl());
|
|
1587
|
+
var _toColorString = _interopRequireDefault(/* @__PURE__ */ requireToColorString());
|
|
1588
|
+
function _interopRequireDefault(obj) {
|
|
1589
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1590
|
+
}
|
|
1591
|
+
function _extends() {
|
|
1592
|
+
_extends = Object.assign ? Object.assign.bind() : function(target) {
|
|
1593
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1594
|
+
var source = arguments[i];
|
|
1595
|
+
for (var key in source) {
|
|
1596
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1597
|
+
target[key] = source[key];
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return target;
|
|
1602
|
+
};
|
|
1603
|
+
return _extends.apply(this, arguments);
|
|
1604
|
+
}
|
|
1605
|
+
function darken2(amount, color) {
|
|
1606
|
+
if (color === "transparent") return color;
|
|
1607
|
+
var hslColor = (0, _parseToHsl["default"])(color);
|
|
1608
|
+
return (0, _toColorString["default"])(_extends({}, hslColor, {
|
|
1609
|
+
lightness: (0, _guard2["default"])(0, 1, hslColor.lightness - parseFloat(amount))
|
|
1610
|
+
}));
|
|
1611
|
+
}
|
|
1612
|
+
var curriedDarken = (0, _curry2["default"])(darken2);
|
|
1613
|
+
exports["default"] = curriedDarken;
|
|
1614
|
+
module.exports = exports.default;
|
|
1615
|
+
})(darken$1, darken$1.exports);
|
|
1616
|
+
return darken$1.exports;
|
|
1617
|
+
}
|
|
1618
|
+
var darkenExports = /* @__PURE__ */ requireDarken();
|
|
1619
|
+
const darken = /* @__PURE__ */ getDefaultExportFromCjs(darkenExports);
|
|
1620
|
+
var lighten$1 = { exports: {} };
|
|
1621
|
+
var hasRequiredLighten;
|
|
1622
|
+
function requireLighten() {
|
|
1623
|
+
if (hasRequiredLighten) return lighten$1.exports;
|
|
1624
|
+
hasRequiredLighten = 1;
|
|
1625
|
+
(function(module, exports) {
|
|
1626
|
+
exports.__esModule = true;
|
|
1627
|
+
exports["default"] = void 0;
|
|
1628
|
+
var _curry2 = _interopRequireDefault(/* @__PURE__ */ require_curry());
|
|
1629
|
+
var _guard2 = _interopRequireDefault(/* @__PURE__ */ require_guard());
|
|
1630
|
+
var _parseToHsl = _interopRequireDefault(/* @__PURE__ */ requireParseToHsl());
|
|
1631
|
+
var _toColorString = _interopRequireDefault(/* @__PURE__ */ requireToColorString());
|
|
1632
|
+
function _interopRequireDefault(obj) {
|
|
1633
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
1634
|
+
}
|
|
1635
|
+
function _extends() {
|
|
1636
|
+
_extends = Object.assign ? Object.assign.bind() : function(target) {
|
|
1637
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1638
|
+
var source = arguments[i];
|
|
1639
|
+
for (var key in source) {
|
|
1640
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1641
|
+
target[key] = source[key];
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
return target;
|
|
1646
|
+
};
|
|
1647
|
+
return _extends.apply(this, arguments);
|
|
1648
|
+
}
|
|
1649
|
+
function lighten2(amount, color) {
|
|
1650
|
+
if (color === "transparent") return color;
|
|
1651
|
+
var hslColor = (0, _parseToHsl["default"])(color);
|
|
1652
|
+
return (0, _toColorString["default"])(_extends({}, hslColor, {
|
|
1653
|
+
lightness: (0, _guard2["default"])(0, 1, hslColor.lightness + parseFloat(amount))
|
|
1654
|
+
}));
|
|
1655
|
+
}
|
|
1656
|
+
var curriedLighten = (0, _curry2["default"])(lighten2);
|
|
1657
|
+
exports["default"] = curriedLighten;
|
|
1658
|
+
module.exports = exports.default;
|
|
1659
|
+
})(lighten$1, lighten$1.exports);
|
|
1660
|
+
return lighten$1.exports;
|
|
1661
|
+
}
|
|
1662
|
+
var lightenExports = /* @__PURE__ */ requireLighten();
|
|
1663
|
+
const lighten = /* @__PURE__ */ getDefaultExportFromCjs(lightenExports);
|
|
1664
|
+
function insertStyles(primaryColor = "#000", foreground = "FFF") {
|
|
1665
|
+
const style = document.createElement("style");
|
|
1666
|
+
style.attributes.setNamedItem(document.createAttribute("data-widget-styles"));
|
|
1667
|
+
const isLightButtonColor = getLuminance(primaryColor) > 0.5;
|
|
1668
|
+
style.textContent = `
|
|
1669
|
+
${styles}
|
|
1670
|
+
.${TRIGGER_BUTTON_CLASS} { background: ${primaryColor}; }
|
|
1671
|
+
.${TRIGGER_BUTTON_CLASS}:hover {
|
|
1672
|
+
background: ${isLightButtonColor ? darken(0.05, primaryColor) : lighten(0.05, primaryColor)};
|
|
1673
|
+
}
|
|
1674
|
+
.trigger-button-icon { color: ${foreground}; }
|
|
1675
|
+
`;
|
|
1676
|
+
document.head.appendChild(style);
|
|
1677
|
+
}
|
|
1678
|
+
function insertStylesIfNeeded(config) {
|
|
1679
|
+
if (!document.querySelector("style[data-widget-styles]")) {
|
|
1680
|
+
const buttonColor = config?.theme?.inputButtonBgColor || "#007bff";
|
|
1681
|
+
const iconColor = config?.theme?.textBaseColor || "#ffffff";
|
|
1682
|
+
insertStyles(buttonColor, iconColor);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function initColorSchemeListener(iframe, signal) {
|
|
1686
|
+
const updateIframeBodyClass = (isDarkMode) => {
|
|
1687
|
+
iframe.contentWindow?.postMessage(
|
|
1688
|
+
{ type: "UPDATE_BODY_CLASS", isDarkMode },
|
|
1689
|
+
"*"
|
|
1690
|
+
);
|
|
1691
|
+
};
|
|
1692
|
+
const checkAndUpdateDarkMode = () => {
|
|
1693
|
+
const isDarkMode = document.body.classList.contains("dark");
|
|
1694
|
+
updateIframeBodyClass(isDarkMode);
|
|
1695
|
+
};
|
|
1696
|
+
const observeBodyClassChanges = () => {
|
|
1697
|
+
const observer = new MutationObserver(checkAndUpdateDarkMode);
|
|
1698
|
+
observer.observe(document.body, {
|
|
1699
|
+
attributes: true,
|
|
1700
|
+
attributeFilter: ["class"]
|
|
1701
|
+
});
|
|
1702
|
+
signal.addEventListener("abort", () => observer.disconnect());
|
|
1703
|
+
};
|
|
1704
|
+
checkAndUpdateDarkMode();
|
|
1705
|
+
observeBodyClassChanges();
|
|
1706
|
+
}
|
|
1707
|
+
function observeColorSchemeChanges(iframe, signal) {
|
|
1708
|
+
const updateIframeBodyClass = (isMobile) => {
|
|
1709
|
+
const message = { type: "UPDATE_BODY_CLASS", isMobile };
|
|
1710
|
+
iframe.contentWindow?.postMessage(message, "*");
|
|
1711
|
+
if (isMobile) {
|
|
1712
|
+
if (IframeStateManager.isWidgetOpen) {
|
|
1713
|
+
IframeStateManager.hideTriggerButton();
|
|
1714
|
+
} else {
|
|
1715
|
+
IframeStateManager.showTriggerButton();
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
let resizeTimeout;
|
|
1720
|
+
const checkAndUpdateIsMobile = () => {
|
|
1721
|
+
const isMobile = document.body.clientWidth <= MOBILE_BREAKPOINT;
|
|
1722
|
+
updateIframeBodyClass(isMobile);
|
|
1723
|
+
};
|
|
1724
|
+
const debouncedCheckAndUpdateIsMobile = () => {
|
|
1725
|
+
if (resizeTimeout) {
|
|
1726
|
+
clearTimeout(resizeTimeout);
|
|
1727
|
+
}
|
|
1728
|
+
resizeTimeout = window.setTimeout(checkAndUpdateIsMobile, 300);
|
|
1729
|
+
};
|
|
1730
|
+
const observeBodyResize = () => {
|
|
1731
|
+
const resizeObserver = new ResizeObserver(debouncedCheckAndUpdateIsMobile);
|
|
1732
|
+
resizeObserver.observe(document.body);
|
|
1733
|
+
signal.addEventListener("abort", () => resizeObserver.disconnect());
|
|
1734
|
+
};
|
|
1735
|
+
checkAndUpdateIsMobile();
|
|
1736
|
+
observeBodyResize();
|
|
1737
|
+
}
|
|
1738
|
+
function base64Encode(text) {
|
|
1739
|
+
const encoder = new TextEncoder();
|
|
1740
|
+
const uint8Array = encoder.encode(text);
|
|
1741
|
+
if (typeof window !== "undefined" && typeof window.btoa === "function") {
|
|
1742
|
+
const binaryString = Array.from(
|
|
1743
|
+
uint8Array,
|
|
1744
|
+
(byte) => String.fromCharCode(byte)
|
|
1745
|
+
).join("");
|
|
1746
|
+
return btoa(binaryString);
|
|
1747
|
+
}
|
|
1748
|
+
if (typeof Buffer !== "undefined") {
|
|
1749
|
+
return Buffer.from(uint8Array).toString("base64");
|
|
1750
|
+
}
|
|
1751
|
+
throw new Error("[utils.base64Encode]: Unsupported environment");
|
|
1752
|
+
}
|
|
1753
|
+
const base64Decode = (text) => {
|
|
1754
|
+
if (typeof window !== "undefined" && typeof window.atob === "function") {
|
|
1755
|
+
const binaryString = atob(text);
|
|
1756
|
+
const len = binaryString.length;
|
|
1757
|
+
const bytes = new Uint8Array(len);
|
|
1758
|
+
for (let i = 0; i < len; i++) {
|
|
1759
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
1760
|
+
}
|
|
1761
|
+
const decoder = new TextDecoder();
|
|
1762
|
+
return decoder.decode(bytes);
|
|
1763
|
+
}
|
|
1764
|
+
if (typeof Buffer !== "undefined") {
|
|
1765
|
+
return Buffer.from(text, "base64").toString("utf-8");
|
|
1766
|
+
}
|
|
1767
|
+
throw new Error("[utils.base64Decode]: Unsupported environment");
|
|
1768
|
+
};
|
|
1769
|
+
const initializedWidgets = /* @__PURE__ */ new Set();
|
|
1770
|
+
function isWidgetInitialized(widgetKey) {
|
|
1771
|
+
return initializedWidgets.has(widgetKey);
|
|
1772
|
+
}
|
|
1773
|
+
function isButtonExisting(widgetKey) {
|
|
1774
|
+
return !!document.getElementById(`trigger-button-${widgetKey}`);
|
|
1775
|
+
}
|
|
1776
|
+
function createWidgetWithButton(widgetKey, widgetUrl, {
|
|
1777
|
+
isButtonHidden,
|
|
1778
|
+
triggerButtonIcon
|
|
1779
|
+
}) {
|
|
1780
|
+
const fragment = document.createDocumentFragment();
|
|
1781
|
+
if (!isButtonHidden) {
|
|
1782
|
+
const { button, icon } = createTriggerButton(widgetKey, triggerButtonIcon);
|
|
1783
|
+
fragment.appendChild(button);
|
|
1784
|
+
IframeStateManager.initialize({ button, icon });
|
|
1785
|
+
} else {
|
|
1786
|
+
IframeStateManager.initialize({ isButtonHidden });
|
|
1787
|
+
}
|
|
1788
|
+
const { iframeContainer, iframe } = createIframeContainer(widgetUrl);
|
|
1789
|
+
fragment.appendChild(iframeContainer);
|
|
1790
|
+
return { fragment, iframe };
|
|
1791
|
+
}
|
|
1792
|
+
function handleInitializationError(apiHost, error, widgetKey) {
|
|
1793
|
+
sendBrainfishWidgetError(apiHost, error, error.message, widgetKey);
|
|
1794
|
+
}
|
|
1795
|
+
const initIframeTrigger = (options, config) => {
|
|
1796
|
+
const apiHost = getApiHost(options.overrides);
|
|
1797
|
+
const widgetHost = getWidgetHost(options.overrides);
|
|
1798
|
+
const { theme, settings } = config;
|
|
1799
|
+
const encodedRules = base64Encode(
|
|
1800
|
+
JSON.stringify(options.overrides?.redirectRules)
|
|
1801
|
+
);
|
|
1802
|
+
const widgetUrl = `${widgetHost}/?widgetKey=${options.widgetKey}#${new URLSearchParams({
|
|
1803
|
+
theme: base64Encode(JSON.stringify(theme)),
|
|
1804
|
+
settings: base64Encode(JSON.stringify(settings)),
|
|
1805
|
+
redirectRules: encodedRules
|
|
1806
|
+
}).toString()}`;
|
|
1807
|
+
const isButtonHidden = settings?.hideTriggerButton;
|
|
1808
|
+
const triggerButtonIcon = settings?.triggerButtonIcon;
|
|
1809
|
+
try {
|
|
1810
|
+
if (isWidgetInitialized(options.widgetKey)) return void 0;
|
|
1811
|
+
if (isButtonExisting(options.widgetKey)) return void 0;
|
|
1812
|
+
insertStylesIfNeeded(config);
|
|
1813
|
+
const { fragment, iframe } = createWidgetWithButton(
|
|
1814
|
+
options.widgetKey,
|
|
1815
|
+
widgetUrl,
|
|
1816
|
+
{
|
|
1817
|
+
isButtonHidden: isButtonHidden || false,
|
|
1818
|
+
triggerButtonIcon: triggerButtonIcon || ""
|
|
1819
|
+
}
|
|
1820
|
+
);
|
|
1821
|
+
const controller = new AbortController();
|
|
1822
|
+
const { signal } = controller;
|
|
1823
|
+
iframe.onload = () => {
|
|
1824
|
+
setTimeout(() => {
|
|
1825
|
+
initColorSchemeListener(iframe, signal);
|
|
1826
|
+
initMessageListener({
|
|
1827
|
+
widgetHost,
|
|
1828
|
+
apiHost,
|
|
1829
|
+
widgetKey: options.widgetKey,
|
|
1830
|
+
signal
|
|
1831
|
+
});
|
|
1832
|
+
observeColorSchemeChanges(iframe, signal);
|
|
1833
|
+
}, 0);
|
|
1834
|
+
};
|
|
1835
|
+
document.body.appendChild(fragment);
|
|
1836
|
+
initializedWidgets.add(options.widgetKey);
|
|
1837
|
+
const cleanup = () => {
|
|
1838
|
+
controller.abort();
|
|
1839
|
+
window.removeEventListener("beforeunload", cleanup);
|
|
1840
|
+
};
|
|
1841
|
+
window.addEventListener("beforeunload", cleanup);
|
|
1842
|
+
return void 0;
|
|
1843
|
+
} catch (error) {
|
|
1844
|
+
handleInitializationError(apiHost, error, options.widgetKey);
|
|
1845
|
+
}
|
|
1846
|
+
return void 0;
|
|
1847
|
+
};
|
|
1848
|
+
var HandOffType = /* @__PURE__ */ ((HandOffType2) => {
|
|
1849
|
+
HandOffType2["FRESHCHAT"] = "freshchat";
|
|
1850
|
+
HandOffType2["INTERCOM"] = "intercom";
|
|
1851
|
+
HandOffType2["ZENDESK"] = "zendesk";
|
|
1852
|
+
HandOffType2["HELPSCOUT"] = "helpscout";
|
|
1853
|
+
return HandOffType2;
|
|
1854
|
+
})(HandOffType || {});
|
|
1855
|
+
const detectHandoff = (config) => {
|
|
1856
|
+
const usesFreshChat = !!window.fcWidget;
|
|
1857
|
+
if (usesFreshChat) {
|
|
1858
|
+
return HandOffType.FRESHCHAT;
|
|
1859
|
+
}
|
|
1860
|
+
return null;
|
|
1861
|
+
};
|
|
1862
|
+
const initFreshChat = async () => {
|
|
1863
|
+
if (!window.fcWidget) {
|
|
1864
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1865
|
+
}
|
|
1866
|
+
window.fcWidget.hide();
|
|
1867
|
+
window.fcWidget.on("widget:closed", () => {
|
|
1868
|
+
window.fcWidget.hide();
|
|
1869
|
+
});
|
|
1870
|
+
};
|
|
1871
|
+
const initHandOffs = async (config) => {
|
|
1872
|
+
if (config.widgetType === WidgetType.Popup) {
|
|
1873
|
+
const handoffType = detectHandoff();
|
|
1874
|
+
if (handoffType && handoffType === HandOffType.FRESHCHAT) {
|
|
1875
|
+
await initFreshChat();
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
const scriptElementId = "brainfish-nudges";
|
|
1880
|
+
const loadNudgeWidgetScript = async (apiHost, widgetKey) => {
|
|
1881
|
+
if (document.getElementById(scriptElementId)) {
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
const script = document.createElement("script");
|
|
1885
|
+
script.id = scriptElementId;
|
|
1886
|
+
script.src = `https://cdn.jsdelivr.net/npm/@brainfish-ai/nudge-widget@latest/dist/index.js`;
|
|
1887
|
+
script.type = "module";
|
|
1888
|
+
script.async = true;
|
|
1889
|
+
script.crossOrigin = "anonymous";
|
|
1890
|
+
script.onerror = () => {
|
|
1891
|
+
sendBrainfishWidgetError(
|
|
1892
|
+
apiHost,
|
|
1893
|
+
new Error(`Failed to load script: ${script.src}`),
|
|
1894
|
+
`Failed to load script: ${script.src}`,
|
|
1895
|
+
widgetKey
|
|
1896
|
+
);
|
|
1897
|
+
};
|
|
1898
|
+
document.head.appendChild(script);
|
|
1899
|
+
};
|
|
1900
|
+
const initNudgeWidget = async (apiHost, widgetKey) => {
|
|
1901
|
+
try {
|
|
1902
|
+
await loadNudgeWidgetScript(apiHost, widgetKey);
|
|
1903
|
+
} catch (error) {
|
|
1904
|
+
sendBrainfishWidgetError(
|
|
1905
|
+
apiHost,
|
|
1906
|
+
error,
|
|
1907
|
+
"Failed to initialize Nudge widget",
|
|
1908
|
+
widgetKey
|
|
1909
|
+
);
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
let globalBrainfish = null;
|
|
1913
|
+
function getBrainfishInstance() {
|
|
1914
|
+
if (typeof window !== "undefined" && window.Brainfish) {
|
|
1915
|
+
return window.Brainfish;
|
|
1916
|
+
}
|
|
1917
|
+
if (!globalBrainfish) {
|
|
1918
|
+
globalBrainfish = createBrainfishQueue();
|
|
1919
|
+
if (typeof window !== "undefined") {
|
|
1920
|
+
window.Brainfish = globalBrainfish;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return globalBrainfish;
|
|
1924
|
+
}
|
|
1925
|
+
const Brainfish = getBrainfishInstance();
|
|
1926
|
+
let initializationPromise = null;
|
|
1927
|
+
async function initializeBrainfish(options, config, apiHost, analyticsApiHost) {
|
|
1928
|
+
const enableRecording = options.overrides?.enableRecording || config?.settings?.enableRecording || false;
|
|
1929
|
+
const requestedVersion = options.overrides?.version || config?.version;
|
|
1930
|
+
const initPromises = [];
|
|
1931
|
+
if (requestedVersion?.startsWith("2.")) {
|
|
1932
|
+
initIframeTrigger(options, config);
|
|
1933
|
+
} else {
|
|
1934
|
+
initPromises.push(initSearchWidget(options, config));
|
|
1935
|
+
}
|
|
1936
|
+
initPromises.push(
|
|
1937
|
+
initBrainfishAnalytics(
|
|
1938
|
+
options.widgetKey,
|
|
1939
|
+
config.trackingToken || "",
|
|
1940
|
+
apiHost,
|
|
1941
|
+
analyticsApiHost,
|
|
1942
|
+
enableRecording,
|
|
1943
|
+
config?.settings?.recordingBlocklist || [],
|
|
1944
|
+
config?.settings?._allowLocalhostRecording,
|
|
1945
|
+
config?.settings?._allowScreenRecording
|
|
1946
|
+
)
|
|
1947
|
+
// Even if this fails, it won't block the widget
|
|
1948
|
+
);
|
|
1949
|
+
initPromises.push(initNudgeWidget(apiHost, options.widgetKey));
|
|
1950
|
+
const [widgetPromise] = await Promise.allSettled(initPromises);
|
|
1951
|
+
if (widgetPromise && widgetPromise.status === "fulfilled" && widgetPromise.value) {
|
|
1952
|
+
Brainfish._setRealBrainfish(widgetPromise.value);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
Brainfish.Widgets.isReady = false;
|
|
1956
|
+
Brainfish.Widgets.identify = (userData) => {
|
|
1957
|
+
window.BrainfishAnalytics("identify", userData);
|
|
1958
|
+
};
|
|
1959
|
+
Brainfish.Widgets.setSignedAttributes = (jwt) => {
|
|
1960
|
+
try {
|
|
1961
|
+
jwtDecode(jwt);
|
|
1962
|
+
} catch (error) {
|
|
1963
|
+
console.error("[Brainfish] Invalid JWT provided to setSignedAttributes:", error);
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
const iframe = document.querySelector(
|
|
1967
|
+
"#bf-iframe-container .trigger-iframe"
|
|
1968
|
+
);
|
|
1969
|
+
if (iframe) {
|
|
1970
|
+
const sendMessage = () => {
|
|
1971
|
+
if (iframe.contentWindow) {
|
|
1972
|
+
iframe.contentWindow.postMessage(
|
|
1973
|
+
{
|
|
1974
|
+
type: "SET_SIGNED_ATTRIBUTES",
|
|
1975
|
+
jwt
|
|
1976
|
+
},
|
|
1977
|
+
"*"
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
if (iframe.contentWindow) {
|
|
1982
|
+
sendMessage();
|
|
1983
|
+
}
|
|
1984
|
+
iframe.addEventListener("load", sendMessage);
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
Brainfish.Widgets.init = async (options) => {
|
|
1988
|
+
createQueues();
|
|
1989
|
+
const apiHost = getApiHost(options.overrides);
|
|
1990
|
+
const analyticsApiHost = getAnalyticsApiHost(options.overrides);
|
|
1991
|
+
let config;
|
|
1992
|
+
if (options.config) {
|
|
1993
|
+
config = JSON.parse(base64Decode(options.config));
|
|
1994
|
+
} else {
|
|
1995
|
+
const { config: fetchedConfig } = await getConfigByKey({
|
|
1996
|
+
widgetKey: options.widgetKey,
|
|
1997
|
+
apiHost
|
|
1998
|
+
});
|
|
1999
|
+
config = fetchedConfig;
|
|
2000
|
+
}
|
|
2001
|
+
if (!initializationPromise) {
|
|
2002
|
+
initializationPromise = initializeBrainfish(
|
|
2003
|
+
options,
|
|
2004
|
+
config,
|
|
2005
|
+
apiHost,
|
|
2006
|
+
analyticsApiHost
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
await initializationPromise;
|
|
2010
|
+
await initHandOffs(config);
|
|
2011
|
+
Brainfish.Widgets.isReady = true;
|
|
2012
|
+
window.dispatchEvent(new Event("onBrainfishReady"));
|
|
2013
|
+
};
|
|
2014
|
+
const BrainfishAnalytics = (...args) => {
|
|
2015
|
+
if (typeof window !== "undefined" && window.BrainfishAnalytics) {
|
|
2016
|
+
window.BrainfishAnalytics(...args);
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
export {
|
|
2020
|
+
BrainfishAnalytics,
|
|
2021
|
+
Brainfish as default
|
|
2022
|
+
};
|
|
2023
|
+
//# sourceMappingURL=web.es.js.map
|