@depict-ai/utilishared 0.0.87 → 1.0.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/index.d.ts +29 -9
- package/dist/main.js +1174 -1125
- package/dist/module.js +1172 -1126
- package/package.json +4 -3
package/dist/main.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var $eYQBp$solidjs = require("solid-js");
|
|
2
|
+
|
|
1
3
|
function $parcel$exportWildcard(dest, source) {
|
|
2
4
|
Object.keys(source).forEach(function(key) {
|
|
3
5
|
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
@@ -21,6 +23,9 @@ function $parcel$interopDefault(a) {
|
|
|
21
23
|
return a && a.__esModule ? a.default : a;
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
$parcel$export(module.exports, "base64_decode_unicode", () => $ff7c981d968fe09a$export$a7e53ec3b3fdd030);
|
|
27
|
+
$parcel$export(module.exports, "base64_encode_unicode", () => $ff7c981d968fe09a$export$a1893782a2a6be0d);
|
|
28
|
+
$parcel$export(module.exports, "make_plp_recommendations_inserted_handler", () => $dba5a9c0f6fb4324$export$6f051469dd676a8b);
|
|
24
29
|
$parcel$export(module.exports, "version_info", () => $e4a18bf12ad092d9$export$60d1d0e3cfc8b9ed);
|
|
25
30
|
$parcel$export(module.exports, "add_version_query_params", () => $e4a18bf12ad092d9$export$fe609f0216e4ebef);
|
|
26
31
|
$parcel$export(module.exports, "cache_args", () => $ee1d22bd1fcdd4e1$export$6e7454c733fa1fb2);
|
|
@@ -274,7 +279,7 @@ $parcel$export(module.exports, "hsl_to_rgb", () => $d73746ee466f09ca$export$e4fd
|
|
|
274
279
|
$parcel$export(module.exports, "relative_luminance_from_rgb", () => $d73746ee466f09ca$export$98c2b3491e76c1f);
|
|
275
280
|
$parcel$export(module.exports, "version", () => $815f67c61b4c0a42$export$83d89fbfd8236492);
|
|
276
281
|
$parcel$export(module.exports, "add_to_version_info", () => $e4a18bf12ad092d9$export$2cefb7e61fcbae00);
|
|
277
|
-
const $815f67c61b4c0a42$export$83d89fbfd8236492 = "
|
|
282
|
+
const $815f67c61b4c0a42$export$83d89fbfd8236492 = "1.0.2";
|
|
278
283
|
|
|
279
284
|
|
|
280
285
|
const $7b5e577a60b81e60$export$55fe61489d2c7417 = /*@__PURE__*/ (()=>process.env.STRIP_DEBUG === "true" ? false : process.env.DEBUG === "true" || process.env.NODE_ENV === "development" || process.env.BUILD_TARGET !== "node" && (globalThis?.document?.currentScript?.dataset?.debug === "true" || globalThis?.localStorage?.getItem?.("debug") === "true"))();
|
|
@@ -317,18 +322,19 @@ function $e4a18bf12ad092d9$export$fe609f0216e4ebef(url) {
|
|
|
317
322
|
}
|
|
318
323
|
|
|
319
324
|
|
|
320
|
-
|
|
325
|
+
// Source: https://stackoverflow.com/a/30106551
|
|
321
326
|
/**
|
|
322
|
-
*
|
|
323
|
-
*/ function $
|
|
324
|
-
return function(
|
|
325
|
-
return
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
327
|
+
* Encoding UTF8 ⇢ base64
|
|
328
|
+
*/ function $ff7c981d968fe09a$export$a1893782a2a6be0d(str) {
|
|
329
|
+
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
|
|
330
|
+
return String.fromCharCode(parseInt(p1, 16));
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
function $ff7c981d968fe09a$export$a7e53ec3b3fdd030(str) {
|
|
334
|
+
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
|
|
335
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
336
|
+
}).join(""));
|
|
330
337
|
}
|
|
331
|
-
|
|
332
338
|
|
|
333
339
|
|
|
334
340
|
|
|
@@ -899,39 +905,17 @@ function $268cbd9e4ade92db$export$f18d5b0af29128b7(msg, severity, input_data = {
|
|
|
899
905
|
}
|
|
900
906
|
|
|
901
907
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
if (Array.isArray(recs)) {
|
|
910
|
-
if (min_recs == undefined) min_recs = 10;
|
|
911
|
-
if (recs.length < min_recs) {
|
|
912
|
-
(0, $e6c6e7929ea385ae$export$c2363754d4758444)("Displays provided to check_displays is too short, it contains", recs.length, "displays which is less than", min_recs);
|
|
913
|
-
return false;
|
|
914
|
-
} else return true;
|
|
915
|
-
} else (0, $e6c6e7929ea385ae$export$c2363754d4758444)(new Error("neither recs nor recs.displays are an array"));
|
|
916
|
-
} else (0, $e6c6e7929ea385ae$export$c2363754d4758444)(new Error("Non object was passed to check_displays"));
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
const $546052c2e3608435$var$elem_track_id_map = /*@__PURE__*/ new WeakMap();
|
|
922
|
-
function $546052c2e3608435$export$16d7c76794a38a4(element, event, track_id, func) {
|
|
923
|
-
const set_for_el = $546052c2e3608435$var$elem_track_id_map.get(element);
|
|
924
|
-
if (!set_for_el?.has?.(track_id)) {
|
|
925
|
-
if (!(set_for_el instanceof Set)) $546052c2e3608435$var$elem_track_id_map.set(element, new Set([
|
|
926
|
-
track_id
|
|
927
|
-
]));
|
|
928
|
-
else set_for_el.add(track_id);
|
|
929
|
-
element.addEventListener(event, func, true);
|
|
930
|
-
}
|
|
908
|
+
/**
|
|
909
|
+
* Gives a random number between min and max (potentially including min and max).
|
|
910
|
+
* @param min The minimum number.
|
|
911
|
+
* @param max The maximum number.
|
|
912
|
+
* @returns a random number
|
|
913
|
+
*/ function $3f34dc07544c5857$export$bb0a9c36cf454ea0(min, max) {
|
|
914
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
931
915
|
}
|
|
932
916
|
|
|
933
917
|
|
|
934
|
-
|
|
918
|
+
|
|
935
919
|
|
|
936
920
|
function $41f528c04cc8a8da$export$535946eb77c946dd(the_function) {
|
|
937
921
|
let busy = false;
|
|
@@ -998,1161 +982,1233 @@ class $04a37742898e4bd5$export$32ccf3a614c84258 {
|
|
|
998
982
|
}
|
|
999
983
|
|
|
1000
984
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
985
|
+
|
|
986
|
+
const $d10801050840d92b$var$ONE_MINUTE = 60000;
|
|
987
|
+
class $d10801050840d92b$export$1b28bc5c68cc4d77 extends EventTarget {
|
|
988
|
+
// WHEN MAKING CHANGES, PLEASE KEEP IN MIND THAT THIS CLASS IS ALSO USED ON THE FRONTEND
|
|
989
|
+
#ws_constructor_options;
|
|
990
|
+
#possible_events = [
|
|
991
|
+
"close",
|
|
992
|
+
"error",
|
|
993
|
+
"message",
|
|
994
|
+
"open"
|
|
995
|
+
];
|
|
996
|
+
#ons = {};
|
|
997
|
+
#try_again_in_ms = this.#initial_reconnect_delay;
|
|
998
|
+
#fails = 0;
|
|
999
|
+
#max_fails = 10;
|
|
1000
|
+
#max_backoff_ms = $d10801050840d92b$var$ONE_MINUTE;
|
|
1001
|
+
get #initial_reconnect_delay() {
|
|
1002
|
+
return (0, $3f34dc07544c5857$export$bb0a9c36cf454ea0)(1, 1000);
|
|
1014
1003
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1004
|
+
#connect() {
|
|
1005
|
+
this.current_socket = typeof window === "object" || typeof WebSocket === "function" ? new WebSocket(...this.#ws_constructor_options) : {
|
|
1006
|
+
readyState: 0,
|
|
1007
|
+
addEventListener: ()=>{},
|
|
1008
|
+
send: ()=>{}
|
|
1009
|
+
};
|
|
1010
|
+
this.#possible_events.forEach((name)=>{
|
|
1011
|
+
this.current_socket.addEventListener(name, (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)((original_event)=>{
|
|
1012
|
+
let fixed_event;
|
|
1013
|
+
if (!(original_event instanceof Event)) {
|
|
1014
|
+
// Node - the WS class uses a predecessor of EventTarget and doesn't fire actual events, which we need for dispatchEvent since we're an EventTarget
|
|
1015
|
+
fixed_event = new Event(name);
|
|
1016
|
+
delete original_event["target"];
|
|
1017
|
+
delete original_event["type"];
|
|
1018
|
+
Object.assign(fixed_event, original_event);
|
|
1019
|
+
// @ts-ignore
|
|
1020
|
+
fixed_event.data ||= original_event.data;
|
|
1021
|
+
// original_event can either be an event from the 'ws' npm package which is some custom made event for something that extends EventEmitter or an actual Event
|
|
1022
|
+
// the event will only have `.data` if it's a message or close event, but wdgaf because setting undefined = undefined is still undefined
|
|
1023
|
+
// ts-ignore because it would be very hard to teach typescript the situation
|
|
1024
|
+
} else try {
|
|
1025
|
+
// @ts-ignore
|
|
1026
|
+
fixed_event = new original_event.constructor(original_event.type, original_event); // modern browsers - clones an event as well as possible
|
|
1027
|
+
} catch (e) {
|
|
1028
|
+
// IE11 and the likes
|
|
1029
|
+
// dlog("Can't reconstruct event", e, original_event, "trying to make a CustomEvent instead");
|
|
1030
|
+
fixed_event = new CustomEvent(original_event.type, original_event);
|
|
1031
|
+
const intermediate = {};
|
|
1032
|
+
for(const key in original_event)intermediate[key] = original_event[key]; // for some reason Object.assign doesn't work because things like MessageEvent.data are not enumarable
|
|
1033
|
+
delete intermediate["target"];
|
|
1034
|
+
Object.assign(fixed_event, intermediate);
|
|
1035
|
+
}
|
|
1036
|
+
this.dispatchEvent(fixed_event);
|
|
1037
|
+
}));
|
|
1038
|
+
});
|
|
1028
1039
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
for (const [eoe, callback] of $55595fc7bb226f61$var$queued_callbacks){
|
|
1046
|
-
// put events into structure of maps and sets where they can only exist once
|
|
1047
|
-
$55595fc7bb226f61$var$queued_callbacks.delete(eoe);
|
|
1048
|
-
const { event: event_name , selector: selector , element: element } = eoe;
|
|
1049
|
-
if (!event_name) {
|
|
1050
|
-
// it's an ifexists callback, doesnt' need deduplication
|
|
1051
|
-
$55595fc7bb226f61$var$call_callback(callback, eoe);
|
|
1052
|
-
continue;
|
|
1053
|
-
}
|
|
1054
|
-
let l2_map = deduplication_map.get(event_name);
|
|
1055
|
-
if (!l2_map) {
|
|
1056
|
-
l2_map = new Map();
|
|
1057
|
-
deduplication_map.set(event_name, l2_map);
|
|
1040
|
+
#setup_dot_on_event_support() {
|
|
1041
|
+
// the idea is to make AutoReconnectingWS usable just like a normal WebSocket
|
|
1042
|
+
// so that you can do .onmessage or .addEventListener("message", handler) on an AutoReconnectingWS. It basically abstracts away connections that can close and die to one big EventTarget where you don't need to care about the underlying connection
|
|
1043
|
+
// this is how we add .onmessage, .onclose, .onopen and .onerror support to our EventTarget (this class)
|
|
1044
|
+
for (const ev of this.#possible_events){
|
|
1045
|
+
Object.defineProperty(this, "on" + ev, {
|
|
1046
|
+
configurable: false,
|
|
1047
|
+
enumerable: true,
|
|
1048
|
+
get: ()=>this.#ons[ev],
|
|
1049
|
+
set: (v)=>this.#ons[ev] = v
|
|
1050
|
+
});
|
|
1051
|
+
this.addEventListener(ev, (e)=>{
|
|
1052
|
+
// e can be MessageEvent | CloseEvent | ErrorEvent I think
|
|
1053
|
+
const on_fn = this.#ons[ev];
|
|
1054
|
+
if (typeof on_fn === "function") (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(on_fn).call(ev, e);
|
|
1055
|
+
});
|
|
1058
1056
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1057
|
+
}
|
|
1058
|
+
async #ensure_connection() {
|
|
1059
|
+
while(true){
|
|
1060
|
+
const error = await new Promise((resolve)=>{
|
|
1061
|
+
this.addEventListener("close", resolve);
|
|
1062
|
+
this.addEventListener("error", resolve);
|
|
1063
|
+
this.restart_ws = resolve;
|
|
1064
|
+
});
|
|
1065
|
+
this.removeEventListener("close", this.restart_ws);
|
|
1066
|
+
this.removeEventListener("error", this.restart_ws);
|
|
1067
|
+
// 4100 means server thinks this is a scraper bot that's ignoring robots.txt
|
|
1068
|
+
// @ts-ignore
|
|
1069
|
+
if (error?.code === 4100) {
|
|
1070
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Websocket connection rejected by server, won't reconnect", error);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Somehow the websocket died", error, "message:", // @ts-ignore
|
|
1074
|
+
error?.message, "code:", // @ts-ignore
|
|
1075
|
+
error?.code, "reason:", // @ts-ignore
|
|
1076
|
+
error?.reason, "reconnecting in", this.#try_again_in_ms);
|
|
1077
|
+
await new Promise((r)=>{
|
|
1078
|
+
// "race" the timeout and getting an https://developer.mozilla.org/en-US/docs/Web/API/Window/online_event by the browser
|
|
1079
|
+
const handler = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)((ev)=>{
|
|
1080
|
+
r();
|
|
1081
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Retrying due to 'online' event", ev);
|
|
1082
|
+
clearTimeout(timeout);
|
|
1083
|
+
});
|
|
1084
|
+
window.addEventListener("online", handler, {
|
|
1085
|
+
once: true
|
|
1086
|
+
});
|
|
1087
|
+
const timeout = setTimeout((0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(()=>{
|
|
1088
|
+
this.#try_again_in_ms *= 1.5 + Math.random();
|
|
1089
|
+
if (this.#try_again_in_ms > this.#max_backoff_ms) this.#try_again_in_ms = this.#max_backoff_ms * (1 + Math.random() / 10);
|
|
1090
|
+
r();
|
|
1091
|
+
window.removeEventListener("online", handler);
|
|
1092
|
+
}), this.#try_again_in_ms);
|
|
1093
|
+
});
|
|
1094
|
+
this.#connect();
|
|
1063
1095
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1096
|
+
}
|
|
1097
|
+
increase_fails() {
|
|
1098
|
+
this.#fails++;
|
|
1099
|
+
if (this.#fails > this.#max_fails) {
|
|
1100
|
+
this.restart_ws();
|
|
1101
|
+
this.#fails = 0;
|
|
1068
1102
|
}
|
|
1069
|
-
l4_map.set(callback, eoe);
|
|
1070
1103
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1104
|
+
async send(...args) {
|
|
1105
|
+
this.current_socket.send(...args);
|
|
1106
|
+
}
|
|
1107
|
+
constructor(url, protocols, options = {}){
|
|
1108
|
+
super();
|
|
1109
|
+
this.#ws_constructor_options = [
|
|
1110
|
+
url,
|
|
1111
|
+
protocols
|
|
1112
|
+
];
|
|
1113
|
+
const { max_backoff_ms: max_backoff_ms } = options;
|
|
1114
|
+
if (max_backoff_ms) this.#max_backoff_ms = max_backoff_ms;
|
|
1115
|
+
this.#setup_dot_on_event_support();
|
|
1116
|
+
this.#connect();
|
|
1117
|
+
this.#ensure_connection().catch((e)=>(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "error"));
|
|
1118
|
+
this.addEventListener("open", (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(()=>{
|
|
1119
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Connection opened");
|
|
1120
|
+
this.#try_again_in_ms = this.#initial_reconnect_delay; // reset exponential backoff
|
|
1121
|
+
}));
|
|
1074
1122
|
}
|
|
1075
1123
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
this.
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1124
|
+
class $d10801050840d92b$export$1d9c6fddbff3441f extends $d10801050840d92b$export$1b28bc5c68cc4d77 {
|
|
1125
|
+
// WHEN MAKING CHANGES, PLEASE KEEP IN MIND THAT THIS CLASS IS ALSO USED ON THE FRONTEND
|
|
1126
|
+
#msg_ipns = new (0, $04a37742898e4bd5$export$32ccf3a614c84258)();
|
|
1127
|
+
#initial_retry_ms = 5000;
|
|
1128
|
+
#connection_last_active = 0;
|
|
1129
|
+
#reconnect_if_dead_for_ms = 20000;
|
|
1130
|
+
#messages_queued = 0;
|
|
1131
|
+
async #wait_for_open_and_send(msg) {
|
|
1132
|
+
while(this.current_socket.readyState !== 1)await new Promise((resolve)=>{
|
|
1133
|
+
this.addEventListener("open", resolve, {
|
|
1134
|
+
once: true
|
|
1135
|
+
});
|
|
1136
|
+
});
|
|
1137
|
+
this.send(msg);
|
|
1138
|
+
}
|
|
1139
|
+
#start_reconnection_if_offline_process = (0, $41f528c04cc8a8da$export$535946eb77c946dd)(async ()=>{
|
|
1140
|
+
await new Promise((r)=>setTimeout(r, this.#reconnect_if_dead_for_ms + (0, $3f34dc07544c5857$export$bb0a9c36cf454ea0)(-2, 10)));
|
|
1141
|
+
// so if we are trying to send something and there's no activity ("error" which could mean the server is down or message or reconnection) we can safely assume that the internet connection is down. In that case we skip the exponential backoff since we want to know when we're connected again ASAP and just retry every like 20s
|
|
1142
|
+
if (this.#messages_queued === 0) return;
|
|
1143
|
+
const now = +new Date();
|
|
1144
|
+
if (now - this.#connection_last_active > this.#reconnect_if_dead_for_ms) {
|
|
1145
|
+
const reason = `No activity in ${this.#reconnect_if_dead_for_ms} ms`;
|
|
1146
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)(reason, "reconnecting ws");
|
|
1147
|
+
this.restart_ws(reason);
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
#periodic_send(msg1) {
|
|
1151
|
+
let delay_to_next_send = this.#initial_retry_ms;
|
|
1152
|
+
let quit = false;
|
|
1153
|
+
this.#messages_queued++;
|
|
1154
|
+
(async ()=>{
|
|
1155
|
+
while(!quit){
|
|
1156
|
+
this.#start_reconnection_if_offline_process();
|
|
1157
|
+
await this.#wait_for_open_and_send(msg1);
|
|
1158
|
+
const waited = await new Promise((r)=>{
|
|
1159
|
+
const handler = ()=>{
|
|
1160
|
+
r(false);
|
|
1161
|
+
clearTimeout(resend_due_to_lost_message_timeout);
|
|
1162
|
+
};
|
|
1163
|
+
// wait the correct delay
|
|
1164
|
+
const resend_due_to_lost_message_timeout = setTimeout(// this might actually never be needed and be from when Daniel didn't understand WebSockets as well
|
|
1165
|
+
(0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(()=>{
|
|
1166
|
+
r(true);
|
|
1167
|
+
this.removeEventListener("open", handler);
|
|
1168
|
+
}), delay_to_next_send);
|
|
1169
|
+
// BUT if we new websocket opens (which means the internet connection works) try again immediately (shortcut the delay)
|
|
1170
|
+
this.addEventListener("open", handler, {
|
|
1171
|
+
once: true
|
|
1172
|
+
});
|
|
1173
|
+
});
|
|
1174
|
+
if (quit) break;
|
|
1175
|
+
delay_to_next_send *= 1.5 + Math.random();
|
|
1176
|
+
if (delay_to_next_send > $d10801050840d92b$var$ONE_MINUTE) delay_to_next_send = $d10801050840d92b$var$ONE_MINUTE * (Math.random() + 1);
|
|
1177
|
+
if (waited) // don't count the fail as fail if we're trying again due to a reconnect since that could make us kill the connection if many messages suddenly retry which we don't want
|
|
1178
|
+
// this is not a proven theory and might be wrong
|
|
1179
|
+
this.increase_fails();
|
|
1180
|
+
}
|
|
1181
|
+
this.#messages_queued--;
|
|
1182
|
+
})().catch((e)=>(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "error"));
|
|
1183
|
+
return ()=>quit = true;
|
|
1184
|
+
}
|
|
1185
|
+
async ensure_sent(payload) {
|
|
1186
|
+
const json_payload = JSON.stringify(payload);
|
|
1187
|
+
const stop_sending = this.#periodic_send(json_payload);
|
|
1188
|
+
while(true){
|
|
1189
|
+
const { data: data } = await this.#msg_ipns.promise;
|
|
1190
|
+
let reply;
|
|
1191
|
+
try {
|
|
1192
|
+
reply = JSON.parse(data);
|
|
1193
|
+
} catch (e) {
|
|
1194
|
+
const msg = "Got malformed message (ignoring, might cause memory leak)";
|
|
1195
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)(msg, data, e);
|
|
1196
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
1197
|
+
e,
|
|
1198
|
+
msg
|
|
1199
|
+
], "error", {
|
|
1200
|
+
data: data
|
|
1201
|
+
});
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
if (reply.id == payload.id) {
|
|
1205
|
+
const { status: status } = reply;
|
|
1206
|
+
if (status == "ack") {
|
|
1207
|
+
stop_sending();
|
|
1208
|
+
continue;
|
|
1209
|
+
} else if (status == "not-ok") (0, $e6c6e7929ea385ae$export$c2363754d4758444)("Got reply not-ok reply from server for event!", payload, reply);
|
|
1210
|
+
else if (status == "ok") {
|
|
1211
|
+
if (process.env.BUILD_TARGET !== "node") (0, $e6c6e7929ea385ae$export$de56f1198d121036)(`Successfully sent ${payload?.event?.type} (WS)`, payload, reply);
|
|
1212
|
+
} else (0, $e6c6e7929ea385ae$export$c2363754d4758444)("Strange reply from WSS server to", payload, ":", reply);
|
|
1213
|
+
stop_sending();
|
|
1214
|
+
return [
|
|
1215
|
+
reply,
|
|
1216
|
+
data
|
|
1217
|
+
];
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
constructor(...params){
|
|
1222
|
+
super(...params);
|
|
1223
|
+
const option_retry_ms = params[2]?.initial_retry_ms;
|
|
1224
|
+
if (option_retry_ms) this.#initial_retry_ms = option_retry_ms;
|
|
1225
|
+
this.addEventListener("message", (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(this.#msg_ipns.resolve));
|
|
1226
|
+
[
|
|
1227
|
+
"open",
|
|
1228
|
+
"error",
|
|
1229
|
+
"message"
|
|
1230
|
+
].forEach((event)=>this.addEventListener(event, (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(()=>this.#connection_last_active = +new Date())));
|
|
1088
1231
|
}
|
|
1089
1232
|
}
|
|
1090
1233
|
|
|
1091
1234
|
|
|
1235
|
+
/**
|
|
1236
|
+
* Returns a random string
|
|
1237
|
+
* @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
|
|
1238
|
+
*/ function $650b64c1b384c895$export$656831b7e9c341c3() {
|
|
1239
|
+
return (Math.random() * 2e17).toString(36);
|
|
1240
|
+
}
|
|
1241
|
+
function $650b64c1b384c895$export$a6db784f019668ba() {
|
|
1242
|
+
return "x" + $650b64c1b384c895$export$656831b7e9c341c3().replaceAll(".", "");
|
|
1243
|
+
}
|
|
1092
1244
|
|
|
1093
1245
|
|
|
1094
1246
|
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
disconnector_: this.#disconnect_fn({
|
|
1141
|
-
event_: "exists",
|
|
1142
|
-
selector_: selector,
|
|
1143
|
-
callback_: callback_
|
|
1144
|
-
})
|
|
1145
|
-
}));
|
|
1146
|
-
}
|
|
1147
|
-
},
|
|
1148
|
-
wait_for_element: (selector, timeout)=>{
|
|
1149
|
-
return this.#self_proxied.wait_for_listener("exists", selector, timeout);
|
|
1150
|
-
},
|
|
1151
|
-
wait_for_listener: (listener, selector, timeout)=>{
|
|
1152
|
-
this.#check_observer_args(listener, ()=>{}, false);
|
|
1153
|
-
// console.log("waiting for listener", listener, "selector", selector, "timeout", timeout);
|
|
1154
|
-
return new Promise((0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)((r)=>{
|
|
1155
|
-
const stop_observing = this.#self_proxied["on" + listener](selector, ({ element: element , disconnector: disconnector })=>{
|
|
1156
|
-
r(element);
|
|
1157
|
-
disconnector();
|
|
1158
|
-
if (timeout) clearTimeout(obs_timeout);
|
|
1159
|
-
});
|
|
1160
|
-
if (timeout) var obs_timeout = setTimeout(()=>{
|
|
1161
|
-
stop_observing();
|
|
1162
|
-
r(undefined);
|
|
1163
|
-
}, timeout);
|
|
1164
|
-
}));
|
|
1165
|
-
}
|
|
1166
|
-
};
|
|
1167
|
-
#kickstart_observer() {
|
|
1168
|
-
if (typeof document === "undefined") return;
|
|
1169
|
-
this.#the_mutation_observer = new MutationObserver(this.#observer_callback);
|
|
1170
|
-
this.#the_mutation_observer.observe(this.#territory || document, {
|
|
1171
|
-
attributes: true,
|
|
1172
|
-
childList: true,
|
|
1173
|
-
subtree: true,
|
|
1174
|
-
attributeOldValue: true,
|
|
1175
|
-
characterData: true,
|
|
1176
|
-
characterDataOldValue: true
|
|
1177
|
-
});
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
const $4c6861fbcd3a0611$export$362abebb4b313340 = process.env.BASE_URL || "https://api.depict.ai";
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
const $0c84f8e99aac5765$var$c = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9);
|
|
1253
|
+
const $0c84f8e99aac5765$var$ws_instance = /*@__PURE__*/ $0c84f8e99aac5765$var$c(()=>new (0, $d10801050840d92b$export$1d9c6fddbff3441f)("wss://ws.depict.ai/ws/create-events"))();
|
|
1254
|
+
const $0c84f8e99aac5765$var$allowed_keys = [
|
|
1255
|
+
"tenant",
|
|
1256
|
+
"market",
|
|
1257
|
+
"type",
|
|
1258
|
+
"user_id",
|
|
1259
|
+
"session_id",
|
|
1260
|
+
"product_id",
|
|
1261
|
+
"entity_identifiers",
|
|
1262
|
+
"url",
|
|
1263
|
+
"entity_price",
|
|
1264
|
+
"currency",
|
|
1265
|
+
"document_referrer",
|
|
1266
|
+
"document_width",
|
|
1267
|
+
"attribution_id",
|
|
1268
|
+
"recommendation_id",
|
|
1269
|
+
"click_location",
|
|
1270
|
+
"ab_test_group",
|
|
1271
|
+
"variant_ids",
|
|
1272
|
+
"dsid",
|
|
1273
|
+
"transaction_id",
|
|
1274
|
+
"error_type",
|
|
1275
|
+
"detail",
|
|
1276
|
+
"recommendation_type",
|
|
1277
|
+
"search_result_id",
|
|
1278
|
+
"product_listing_result_id"
|
|
1279
|
+
];
|
|
1280
|
+
const $0c84f8e99aac5765$export$72036d950e1fae95 = /*@__PURE__*/ $0c84f8e99aac5765$var$c((payload)=>{
|
|
1281
|
+
if (process.env.DEPICT === "false") return;
|
|
1282
|
+
return payload.map((body)=>Object.fromEntries(Object.entries(body).filter(([key, value])=>$0c84f8e99aac5765$var$allowed_keys.includes(key) && value != null)));
|
|
1283
|
+
});
|
|
1284
|
+
const $0c84f8e99aac5765$export$aa26019042811d4f = /*@__PURE__*/ $0c84f8e99aac5765$var$c(async (bodies)=>{
|
|
1285
|
+
if (process.env.DEPICT === "false") return;
|
|
1286
|
+
for(let i = 0; i < bodies.length; i++){
|
|
1287
|
+
const id = (0, $650b64c1b384c895$export$656831b7e9c341c3)();
|
|
1288
|
+
$0c84f8e99aac5765$var$ws_instance?.ensure_sent({
|
|
1289
|
+
id: id,
|
|
1290
|
+
event: bodies[i]
|
|
1291
|
+
}).catch((e)=>(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "error"));
|
|
1178
1292
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const callbacks = selector_to_callback_array_map.get(selector_);
|
|
1186
|
-
callbacks?.delete(callback_);
|
|
1187
|
-
if (callbacks?.size === 0) selector_to_callback_array_map.delete(selector_);
|
|
1188
|
-
if (selector_to_callback_array_map.size === 0) delete observing[event_];
|
|
1189
|
-
if (!Object.keys(observing).length) {
|
|
1190
|
-
this.#the_mutation_observer?.disconnect();
|
|
1191
|
-
this.#the_mutation_observer = undefined;
|
|
1192
|
-
}
|
|
1193
|
-
};
|
|
1194
|
-
// If the observer callback is running, we need to queue every function that mutates this.#observing since we can't clone it for performance reasons
|
|
1195
|
-
if (this.#observer_callback_running) this.#execute_after_callback_ran.push(fn);
|
|
1196
|
-
else fn();
|
|
1197
|
-
};
|
|
1293
|
+
});
|
|
1294
|
+
const $0c84f8e99aac5765$export$608478473a3304a0 = /*@__PURE__*/ $0c84f8e99aac5765$var$c((payload, use_ws = true)=>{
|
|
1295
|
+
if (process.env.DEPICT === "false") return;
|
|
1296
|
+
if (use_ws && typeof WebSocket == "function" && typeof $0c84f8e99aac5765$var$ws_instance?.ensure_sent == "function") {
|
|
1297
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Sending to depict (ws)", payload);
|
|
1298
|
+
return $0c84f8e99aac5765$export$aa26019042811d4f(payload);
|
|
1198
1299
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1300
|
+
const url = (0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/create-events";
|
|
1301
|
+
return $0c84f8e99aac5765$export$cc3b6ddf805f6156(url, payload);
|
|
1302
|
+
});
|
|
1303
|
+
const $0c84f8e99aac5765$export$cc3b6ddf805f6156 = /*@__PURE__*/ $0c84f8e99aac5765$var$c((url, payload)=>{
|
|
1304
|
+
const payload_json = JSON.stringify(payload);
|
|
1305
|
+
let success = false;
|
|
1306
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)(`Attempting to send (beacon)`, payload);
|
|
1307
|
+
try {
|
|
1308
|
+
success = navigator.sendBeacon(url, new Blob([
|
|
1309
|
+
payload_json
|
|
1310
|
+
], {
|
|
1311
|
+
type: "application/json"
|
|
1312
|
+
}));
|
|
1313
|
+
} catch (first_error) {
|
|
1314
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Beacon has failed", first_error, "falling back to sending with wrong mime type which might work");
|
|
1201
1315
|
try {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
for(let j = 0; j < records.length; j++){
|
|
1208
|
-
const record = records[j];
|
|
1209
|
-
const { addedNodes: addedNodes , removedNodes: removedNodes , target: target } = record;
|
|
1210
|
-
const events_for_discovery = [];
|
|
1211
|
-
let nodes_to_check;
|
|
1212
|
-
// code for handling a record containing wanted elements in addedNodes or the children of added nodes and attribute changes that make an existing node match a selector, mainly for oncreation and onexists, but it will fire onchange if someone is listening if an attribute change makes an element match a selector
|
|
1213
|
-
if (!addedNodes.length && !removedNodes.length) nodes_to_check = [
|
|
1214
|
-
target
|
|
1215
|
-
];
|
|
1216
|
-
else {
|
|
1217
|
-
nodes_to_check = addedNodes;
|
|
1218
|
-
if (observing["creation"]) events_for_discovery.push("creation");
|
|
1219
|
-
}
|
|
1220
|
-
if (observing["exists"]) events_for_discovery.push("exists");
|
|
1221
|
-
if (observing["change"]) events_for_discovery.push("change");
|
|
1222
|
-
for(let n = 0; n < events_for_discovery.length; n++){
|
|
1223
|
-
const event = events_for_discovery[n];
|
|
1224
|
-
const event_is_creation_or_exists_with_tree_change = event === "creation" || event === "exists" && addedNodes.length;
|
|
1225
|
-
const selector_map = observing[event];
|
|
1226
|
-
const selectors = [
|
|
1227
|
-
...selector_map.keys()
|
|
1228
|
-
]; // we can only iterate over a MapIterator once, so we need to spread it
|
|
1229
|
-
if (event === "change" && (addedNodes.length || removedNodes.length)) {
|
|
1230
|
-
// we check the selectors first because I'm DUMB and already have come so far
|
|
1231
|
-
for(let selectors_i = 0; selectors_i < selectors.length; selectors_i++){
|
|
1232
|
-
const selector = selectors[selectors_i];
|
|
1233
|
-
// @ts-ignore
|
|
1234
|
-
if (target?.matches?.(selector)) {
|
|
1235
|
-
// we WANT change event and there are children to an element that interests us - act on it
|
|
1236
|
-
const callbacks = selector_map.get(selector);
|
|
1237
|
-
this.#call_callbacks(callbacks, (callback)=>({
|
|
1238
|
-
element_: target,
|
|
1239
|
-
// it has to be an *Element* since it has
|
|
1240
|
-
// the selector is a string since the event is change
|
|
1241
|
-
// @ts-ignore
|
|
1242
|
-
selector_: selector,
|
|
1243
|
-
event_: event,
|
|
1244
|
-
mutation_record_: record,
|
|
1245
|
-
disconnector_: this.#disconnect_fn({
|
|
1246
|
-
event_: event,
|
|
1247
|
-
selector_: selector,
|
|
1248
|
-
callback_: callback
|
|
1249
|
-
})
|
|
1250
|
-
}));
|
|
1251
|
-
selector_map.delete(selector);
|
|
1252
|
-
steps_to_restore_observing_cache.push(()=>selector_map.set(selector, callbacks));
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
break;
|
|
1256
|
-
}
|
|
1257
|
-
for(let i = 0; i < nodes_to_check.length; i++){
|
|
1258
|
-
const node = nodes_to_check[i];
|
|
1259
|
-
for(let selectors_i = 0; selectors_i < selectors.length; selectors_i++){
|
|
1260
|
-
const selector = selectors[selectors_i];
|
|
1261
|
-
const callbacks = selector_map.get(selector) || new Set();
|
|
1262
|
-
if (typeof selector !== "string") {
|
|
1263
|
-
// oncreation or onexists with node-selector
|
|
1264
|
-
if (event_is_creation_or_exists_with_tree_change) {
|
|
1265
|
-
const derefed_el = selector.deref();
|
|
1266
|
-
if (!derefed_el) {
|
|
1267
|
-
selector_map.delete(selector);
|
|
1268
|
-
continue;
|
|
1269
|
-
}
|
|
1270
|
-
if (node === derefed_el || node.contains(derefed_el)) // node is node or node is child of added node
|
|
1271
|
-
this.#call_callbacks(callbacks, (callback)=>({
|
|
1272
|
-
element_: derefed_el,
|
|
1273
|
-
selector_: derefed_el,
|
|
1274
|
-
event_: event,
|
|
1275
|
-
mutation_record_: record,
|
|
1276
|
-
disconnector_: this.#disconnect_fn({
|
|
1277
|
-
event_: event,
|
|
1278
|
-
selector_: selector,
|
|
1279
|
-
callback_: callback
|
|
1280
|
-
})
|
|
1281
|
-
}));
|
|
1282
|
-
}
|
|
1283
|
-
continue;
|
|
1284
|
-
}
|
|
1285
|
-
// @ts-ignore
|
|
1286
|
-
const matches_now = node?.matches?.(selector);
|
|
1287
|
-
let our_set;
|
|
1288
|
-
if (event == "exists") {
|
|
1289
|
-
// we want the change event to trigger to any change (exists only if it makes an element match a selector that didn't previously match)
|
|
1290
|
-
our_set = attribute_attribution_map_object[selector] ||= new WeakSet();
|
|
1291
|
-
if (record.type === "attributes" && matches_now != null) {
|
|
1292
|
-
const matched_last = our_set.has(node);
|
|
1293
|
-
if (matched_last && matches_now) continue;
|
|
1294
|
-
}
|
|
1295
|
-
if (matches_now) our_set.add(node);
|
|
1296
|
-
else our_set.delete(node);
|
|
1297
|
-
}
|
|
1298
|
-
if (matches_now) this.#call_callbacks(callbacks, (callback)=>({
|
|
1299
|
-
element_: node,
|
|
1300
|
-
selector_: selector,
|
|
1301
|
-
event_: event,
|
|
1302
|
-
mutation_record_: record,
|
|
1303
|
-
disconnector_: this.#disconnect_fn({
|
|
1304
|
-
event_: event,
|
|
1305
|
-
selector_: selector,
|
|
1306
|
-
callback_: callback
|
|
1307
|
-
})
|
|
1308
|
-
}));
|
|
1309
|
-
if ((addedNodes.length || removedNodes.length) && node.hasChildNodes() && // @ts-ignore
|
|
1310
|
-
node.querySelectorAll /* don't act on i.e. textnodes. Doing the check this way is actually faster than both `in` and instanceof */ ) {
|
|
1311
|
-
const matching_children = (0, $7599647868f98022$export$33f937d741e49339)(node, selector);
|
|
1312
|
-
for(let m = 0; m < matching_children.length; m++){
|
|
1313
|
-
// always use for loops because this can't be slow and forEach takes ages
|
|
1314
|
-
if (event == "exists") our_set.add(matching_children[m]);
|
|
1315
|
-
this.#call_callbacks(callbacks, (callback)=>({
|
|
1316
|
-
element_: matching_children[m],
|
|
1317
|
-
selector_: selector,
|
|
1318
|
-
event_: event,
|
|
1319
|
-
mutation_record_: record,
|
|
1320
|
-
disconnector_: this.#disconnect_fn({
|
|
1321
|
-
event_: event,
|
|
1322
|
-
selector_: selector,
|
|
1323
|
-
callback_: callback
|
|
1324
|
-
})
|
|
1325
|
-
}));
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
// code for handling changes to children of an observed element
|
|
1332
|
-
{
|
|
1333
|
-
const event = "change";
|
|
1334
|
-
const selector_map = observing[event];
|
|
1335
|
-
if (selector_map) {
|
|
1336
|
-
let target_el = target;
|
|
1337
|
-
while(target_el = target_el?.parentNode)// @ts-ignore
|
|
1338
|
-
if (target_el?.matches) {
|
|
1339
|
-
for (const selector of selector_map.keys())// selector is string because event is change
|
|
1340
|
-
// @ts-ignore
|
|
1341
|
-
if (target_el.matches?.(selector)) {
|
|
1342
|
-
const callbacks = selector_map.get(selector);
|
|
1343
|
-
this.#call_callbacks(callbacks, (callback)=>({
|
|
1344
|
-
element_: target_el,
|
|
1345
|
-
// @ts-ignore
|
|
1346
|
-
selector_: selector,
|
|
1347
|
-
event_: event,
|
|
1348
|
-
mutation_record_: record,
|
|
1349
|
-
disconnector_: this.#disconnect_fn({
|
|
1350
|
-
event_: event,
|
|
1351
|
-
selector_: selector,
|
|
1352
|
-
callback_: callback
|
|
1353
|
-
})
|
|
1354
|
-
}));
|
|
1355
|
-
// Since we now deduplicate
|
|
1356
|
-
steps_to_restore_observing_cache.push(()=>selector_map.set(selector, callbacks));
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
// code for observing observed elements disappearing
|
|
1362
|
-
{
|
|
1363
|
-
const event = "removed";
|
|
1364
|
-
const removed_map = observing[event];
|
|
1365
|
-
if (removed_map && removedNodes?.length) {
|
|
1366
|
-
const selectors = [
|
|
1367
|
-
...removed_map.keys()
|
|
1368
|
-
];
|
|
1369
|
-
for(let t = 0; t < removedNodes.length; t++)for(let u = 0; u < selectors.length; u++){
|
|
1370
|
-
const selector = selectors[u];
|
|
1371
|
-
const callbacks = removed_map.get(selector) || new Set();
|
|
1372
|
-
const node = removedNodes[t];
|
|
1373
|
-
if (typeof selector === "string") {
|
|
1374
|
-
const matching_nodes = [];
|
|
1375
|
-
// @ts-ignore
|
|
1376
|
-
if (node?.matches?.(selector)) matching_nodes.push(node);
|
|
1377
|
-
matching_nodes.push(...(0, $7599647868f98022$export$33f937d741e49339)(node, selector) || []);
|
|
1378
|
-
for(let v = 0; v < matching_nodes.length; v++)this.#call_callbacks(callbacks, (callback)=>({
|
|
1379
|
-
element_: matching_nodes[v],
|
|
1380
|
-
selector_: selector,
|
|
1381
|
-
event_: event,
|
|
1382
|
-
mutation_record_: record,
|
|
1383
|
-
disconnector_: this.#disconnect_fn({
|
|
1384
|
-
event_: "removed",
|
|
1385
|
-
selector_: selector,
|
|
1386
|
-
callback_: callback
|
|
1387
|
-
})
|
|
1388
|
-
}));
|
|
1389
|
-
} else {
|
|
1390
|
-
const derefed_el = selector.deref();
|
|
1391
|
-
if (derefed_el) {
|
|
1392
|
-
if (node === derefed_el || node.contains(derefed_el)) this.#call_callbacks(callbacks, (callback)=>({
|
|
1393
|
-
element_: derefed_el,
|
|
1394
|
-
mutation_record_: record,
|
|
1395
|
-
selector_: derefed_el,
|
|
1396
|
-
event_: event,
|
|
1397
|
-
disconnector_: this.#disconnect_fn({
|
|
1398
|
-
event_: event,
|
|
1399
|
-
selector_: selector,
|
|
1400
|
-
callback_: callback
|
|
1401
|
-
})
|
|
1402
|
-
}));
|
|
1403
|
-
} else // here it's also ok to mutate #observing since the WeakRef is empty
|
|
1404
|
-
removed_map.delete(selector);
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
// const end = new Date().getTime();
|
|
1411
|
-
// console.log("procesed",records.length,"in", end-start, this.#observing);
|
|
1412
|
-
} finally{
|
|
1413
|
-
// ensure that we don't leave this.#observing in a broken state if we throw
|
|
1414
|
-
while(steps_to_restore_observing_cache.length)steps_to_restore_observing_cache.pop()();
|
|
1415
|
-
const execute_after_run = this.#execute_after_callback_ran;
|
|
1416
|
-
// We need to execute these in order they were added because I'm afraid that things might rely on it
|
|
1417
|
-
for(let i = 0; i < execute_after_run.length; i++)try {
|
|
1418
|
-
execute_after_run[i]();
|
|
1419
|
-
} catch (e) {
|
|
1420
|
-
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
1421
|
-
e,
|
|
1422
|
-
"error in observer running queued function"
|
|
1423
|
-
], "error");
|
|
1424
|
-
}
|
|
1425
|
-
// Let the garbage collector empty the old array by creating a new one
|
|
1426
|
-
this.#execute_after_callback_ran = [];
|
|
1427
|
-
this.#observer_callback_running = false;
|
|
1428
|
-
}
|
|
1316
|
+
success = navigator.sendBeacon(url, new Blob([
|
|
1317
|
+
payload_json
|
|
1318
|
+
], {
|
|
1319
|
+
type: "application/x-www-form-urlencoded"
|
|
1320
|
+
}));
|
|
1429
1321
|
} catch (e) {
|
|
1430
|
-
(0, $
|
|
1431
|
-
|
|
1432
|
-
"
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
return;
|
|
1451
|
-
}
|
|
1452
|
-
the_class.#check_observer_args(selector, callback, listener != "change");
|
|
1453
|
-
if (the_class.#observer_callback_running) {
|
|
1454
|
-
// Can't mutate #observing right now, queue it for when we can
|
|
1455
|
-
the_class.#execute_after_callback_ran.push(()=>function_for_listener(selector, callback));
|
|
1456
|
-
return;
|
|
1457
|
-
}
|
|
1458
|
-
const observing = the_class.#observing;
|
|
1459
|
-
observing[listener] ||= new Map();
|
|
1460
|
-
// create map for each listener, this is because the selectors can be objects for .onremoved, .oncreation and .onexists to take explicit nodes
|
|
1461
|
-
const selector_map = observing[listener];
|
|
1462
|
-
let disconnector;
|
|
1463
|
-
if (listener === "exists") the_class.#verbs.ifexists(selector, callback);
|
|
1464
|
-
if (typeof selector === "string") {
|
|
1465
|
-
// simple code for string selectors
|
|
1466
|
-
let callback_set = selector_map.get(selector);
|
|
1467
|
-
if (!callback_set) {
|
|
1468
|
-
callback_set = new Set();
|
|
1469
|
-
selector_map.set(selector, callback_set);
|
|
1470
|
-
}
|
|
1471
|
-
callback_set.add(callback); // we make this a set since you're not supposed to be able to have the same function as listener twice, like you can't with addEventListener
|
|
1472
|
-
disconnector = the_class.#disconnect_fn({
|
|
1473
|
-
event_: listener,
|
|
1474
|
-
selector_: selector,
|
|
1475
|
-
callback_: callback
|
|
1322
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Beacon fallback has failed", e, "trying fetch");
|
|
1323
|
+
fetch(url, {
|
|
1324
|
+
"headers": {
|
|
1325
|
+
"content-type": "application/json"
|
|
1326
|
+
},
|
|
1327
|
+
"body": payload_json,
|
|
1328
|
+
"method": "POST",
|
|
1329
|
+
"mode": "cors",
|
|
1330
|
+
"credentials": "include"
|
|
1331
|
+
}).then((response)=>response.text()).then((text)=>(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Beacon fallback fallback transmission result", text)).catch((fetch_error)=>{
|
|
1332
|
+
(0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).withScope(function(scope) {
|
|
1333
|
+
scope.setExtra("stack", new Error().stack);
|
|
1334
|
+
scope.setExtra("url", url);
|
|
1335
|
+
scope.setExtra("payload", payload_json);
|
|
1336
|
+
scope.setExtra("first_error", first_error);
|
|
1337
|
+
scope.setExtra("second_error", e);
|
|
1338
|
+
scope.setTag("feature", "beacon");
|
|
1339
|
+
scope.setTag("approach", "fetch_fallback");
|
|
1340
|
+
scope.setLevel("error");
|
|
1341
|
+
this.captureMessage(fetch_error); // we can now do this - it's depict lazy sentry specific. `this` will refer to the actual hub with breadcrumbs and the scope activated
|
|
1476
1342
|
});
|
|
1477
|
-
}
|
|
1478
|
-
// for an element "selector" we don't want to keep strong references to the nodes as that would prevent them from being garbage collected
|
|
1479
|
-
let callback_set_to_add_to;
|
|
1480
|
-
for (const [stored_selector, existing_callback_set] of selector_map){
|
|
1481
|
-
// try finding an existing array of callbacks
|
|
1482
|
-
if (typeof stored_selector === "string") continue;
|
|
1483
|
-
const ref_contents = stored_selector.deref();
|
|
1484
|
-
if (!ref_contents) {
|
|
1485
|
-
// clean up listeners for selectors that have already been GC'd
|
|
1486
|
-
selector_map.delete(stored_selector);
|
|
1487
|
-
continue;
|
|
1488
|
-
}
|
|
1489
|
-
if (ref_contents === selector) {
|
|
1490
|
-
callback_set_to_add_to = existing_callback_set;
|
|
1491
|
-
disconnector = the_class.#disconnect_fn({
|
|
1492
|
-
event_: listener,
|
|
1493
|
-
selector_: stored_selector,
|
|
1494
|
-
callback_: callback
|
|
1495
|
-
});
|
|
1496
|
-
break;
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
if (!callback_set_to_add_to) {
|
|
1500
|
-
callback_set_to_add_to = new Set();
|
|
1501
|
-
const weakref = new WeakRef(selector);
|
|
1502
|
-
the_class.#cleanup_weakref_when_refd_el_gcd(listener, weakref, selector);
|
|
1503
|
-
selector_map.set(weakref, callback_set_to_add_to);
|
|
1504
|
-
disconnector = the_class.#disconnect_fn({
|
|
1505
|
-
event_: listener,
|
|
1506
|
-
selector_: weakref,
|
|
1507
|
-
callback_: callback
|
|
1508
|
-
});
|
|
1509
|
-
}
|
|
1510
|
-
callback_set_to_add_to.add(callback);
|
|
1511
|
-
}
|
|
1512
|
-
if (!the_class.#the_mutation_observer) the_class.#kickstart_observer();
|
|
1513
|
-
return disconnector;
|
|
1514
|
-
};
|
|
1515
|
-
return function_for_listener;
|
|
1516
|
-
}
|
|
1517
|
-
#cleanup_weakref_when_refd_el_gcd(listener1, weakref, element) {
|
|
1518
|
-
// we don't want to keep references to elements used as "selectors" in oncreation and onremoved
|
|
1519
|
-
if (!this.#weakref_finalization_registry) return;
|
|
1520
|
-
this.#weakref_finalization_registry.register(element, [
|
|
1521
|
-
listener1,
|
|
1522
|
-
weakref
|
|
1523
|
-
]);
|
|
1524
|
-
}
|
|
1525
|
-
#finalization_registry_callback([listener2, weak_ref]) {
|
|
1526
|
-
// element was GCd and the callbacks can never be called, remove them
|
|
1527
|
-
const observing = this.#observing;
|
|
1528
|
-
observing[listener2]?.get(weak_ref)?.clear(); // just in case something still has a reference to this set and does something with it, clear it
|
|
1529
|
-
observing[listener2]?.delete(weak_ref);
|
|
1530
|
-
if (observing[listener2]?.size === 0) delete observing[listener2];
|
|
1531
|
-
if (Object.keys(observing).length === 0) {
|
|
1532
|
-
this.#the_mutation_observer?.disconnect();
|
|
1533
|
-
this.#the_mutation_observer = undefined;
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
#call_callbacks(callbacks, make_ev_data) {
|
|
1537
|
-
for (const callback of callbacks)(0, $55595fc7bb226f61$export$2b08e30396270f0b)(callback, new (0, $e2f46d4f382caff1$export$ea60432919e69303)(make_ev_data(callback)));
|
|
1538
|
-
}
|
|
1539
|
-
#get(target, verb) {
|
|
1540
|
-
// @ts-ignore
|
|
1541
|
-
const is_listener = target.#listeners.includes(verb.slice(2));
|
|
1542
|
-
const is_verb = Object.keys(target.#verbs).includes(verb);
|
|
1543
|
-
if (is_verb) return target.#verbs[verb];
|
|
1544
|
-
else if (is_listener) return target.#add_listener(verb.slice(2));
|
|
1545
|
-
else throw new Error("Property " + verb + " is not valid. Valid listeners: " + target.#listeners.join(", ") + "; valid verbs: " + Object.keys(target.#verbs).join(", "));
|
|
1546
|
-
}
|
|
1547
|
-
constructor(options = {}){
|
|
1548
|
-
if (process.env.BUILD_TARGET !== "modern" && Proxy.toString().indexOf("[native code]") === -1) {
|
|
1549
|
-
this.#listeners.forEach((listener)=>this["on" + listener] = ()=>{}); // define listeners, needed for IE11 proxy polyfill
|
|
1550
|
-
Object.keys(this.#verbs).forEach((listener)=>this[listener] = ()=>{});
|
|
1343
|
+
});
|
|
1551
1344
|
}
|
|
1552
|
-
if (options.territory) this.#territory = options.territory;
|
|
1553
|
-
return this.#self_proxied = new Proxy(this, {
|
|
1554
|
-
get: this.#get
|
|
1555
|
-
});
|
|
1556
1345
|
}
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1346
|
+
return success;
|
|
1347
|
+
});
|
|
1348
|
+
const $0c84f8e99aac5765$export$28cacbd9b4306ffc = /*@__PURE__*/ $0c84f8e99aac5765$var$c((payload, use_ws)=>{
|
|
1349
|
+
if (process.env.DEPICT === "false") return;
|
|
1350
|
+
// filter_depict_payload will only return undefined if process.env.DEPICT === "false"
|
|
1351
|
+
return $0c84f8e99aac5765$export$608478473a3304a0($0c84f8e99aac5765$export$72036d950e1fae95(payload), use_ws);
|
|
1352
|
+
});
|
|
1561
1353
|
|
|
1562
|
-
const $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149 = /*@__PURE__*/ $2a1cbc63a04d4a2d$var$make_default_observer();
|
|
1563
|
-
function $2a1cbc63a04d4a2d$var$make_default_observer() {
|
|
1564
|
-
try {
|
|
1565
|
-
return new (0, $9043c64496e3375f$export$12e07a2a9f87578a)();
|
|
1566
|
-
} catch (error) {
|
|
1567
|
-
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
1568
|
-
error,
|
|
1569
|
-
"error starting ElementObserver"
|
|
1570
|
-
], "error");
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
1354
|
|
|
1574
1355
|
|
|
1575
1356
|
|
|
1576
1357
|
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1358
|
+
let $e0a87646d12cb987$export$6399bdb2291895e0 = ()=>{
|
|
1359
|
+
if (typeof document === "undefined") return "server";
|
|
1360
|
+
let id = "";
|
|
1361
|
+
let localstorage_error;
|
|
1362
|
+
let cookie_error;
|
|
1363
|
+
try {
|
|
1364
|
+
id = localStorage._dep_id ||= (0, $650b64c1b384c895$export$656831b7e9c341c3)();
|
|
1365
|
+
} catch (e) {
|
|
1366
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "warning");
|
|
1367
|
+
localstorage_error = e;
|
|
1587
1368
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
const anchor = event.element;
|
|
1601
|
-
if (typeof url === "string") {
|
|
1602
|
-
if (anchor.href.includes(url)) {
|
|
1603
|
-
if (!stfu) (0, $e6c6e7929ea385ae$export$de56f1198d121036)("RUNNING RELATIVIFY on", event);
|
|
1604
|
-
anchor.href = anchor.href.replaceAll(url, "/");
|
|
1605
|
-
}
|
|
1606
|
-
} else if (url.test(anchor.href)) {
|
|
1607
|
-
if (!stfu) (0, $e6c6e7929ea385ae$export$de56f1198d121036)("RUNNING RELATIVIFY on", event);
|
|
1608
|
-
anchor.href = anchor.href.replace(url, "/");
|
|
1369
|
+
if (!id) {
|
|
1370
|
+
try {
|
|
1371
|
+
const get_cookie_id = ()=>document.cookie.split(";").reduce((res, c)=>{
|
|
1372
|
+
const [key, val] = c.trim().split("=").map(decodeURIComponent);
|
|
1373
|
+
return Object.assign(res, {
|
|
1374
|
+
[key]: val
|
|
1375
|
+
});
|
|
1376
|
+
}, {})._dep_id;
|
|
1377
|
+
id = get_cookie_id();
|
|
1378
|
+
if (!id) {
|
|
1379
|
+
document.cookie = `_dep_id=${(0, $650b64c1b384c895$export$656831b7e9c341c3)()}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
|
|
1380
|
+
id = get_cookie_id();
|
|
1609
1381
|
}
|
|
1382
|
+
} catch (e) {
|
|
1383
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "warning");
|
|
1384
|
+
cookie_error = e;
|
|
1385
|
+
}
|
|
1386
|
+
(0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).withScope(function(scope) {
|
|
1387
|
+
scope.setExtra("id", id);
|
|
1388
|
+
scope.setExtra("ls_error", localstorage_error);
|
|
1389
|
+
scope.setExtra("cookie_error", cookie_error);
|
|
1390
|
+
scope.setLevel("error");
|
|
1391
|
+
this.captureMessage(`${id ? "localStorage" : "cookie and localStorage"} failed to hold a value!`);
|
|
1610
1392
|
});
|
|
1611
|
-
const link_sel = "a[href]";
|
|
1612
|
-
(0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(link_sel, relativ_callback);
|
|
1613
|
-
if (also_onchange) (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onchange(link_sel, relativ_callback);
|
|
1614
|
-
if (also_in_all_shadow_roots && typeof ShadowRoot == "function") (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists("*", (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(({ element: element })=>{
|
|
1615
|
-
if (element?.shadowRoot instanceof ShadowRoot) {
|
|
1616
|
-
const local_observer = new (0, $9043c64496e3375f$export$12e07a2a9f87578a)({
|
|
1617
|
-
territory: element.shadowRoot
|
|
1618
|
-
});
|
|
1619
|
-
local_observer.onexists(link_sel, relativ_callback);
|
|
1620
|
-
}
|
|
1621
|
-
}));
|
|
1622
1393
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
)
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1394
|
+
if (!id) id = (0, $650b64c1b384c895$export$656831b7e9c341c3)();
|
|
1395
|
+
return id;
|
|
1396
|
+
};
|
|
1397
|
+
let $e0a87646d12cb987$export$adc61a405a4cabed = $e0a87646d12cb987$export$6399bdb2291895e0;
|
|
1398
|
+
let $e0a87646d12cb987$export$61e7e1f11e96692f = ()=>undefined;
|
|
1399
|
+
const $e0a87646d12cb987$export$336e7ad40bae0652 = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)((newfn)=>$e0a87646d12cb987$export$6399bdb2291895e0 = newfn);
|
|
1400
|
+
const $e0a87646d12cb987$export$8a96793bf9f87d90 = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)((newfn)=>$e0a87646d12cb987$export$adc61a405a4cabed = newfn);
|
|
1401
|
+
const $e0a87646d12cb987$export$93ae15b1ae509334 = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)((newfn)=>$e0a87646d12cb987$export$61e7e1f11e96692f = newfn);
|
|
1402
|
+
const $e0a87646d12cb987$export$8c6f26a5b6921b95 = /*@__PURE__*/ ()=>{
|
|
1403
|
+
return {
|
|
1404
|
+
session_id: $e0a87646d12cb987$export$61e7e1f11e96692f(),
|
|
1405
|
+
user_id: $e0a87646d12cb987$export$adc61a405a4cabed(),
|
|
1406
|
+
dsid: $e0a87646d12cb987$export$6399bdb2291895e0(),
|
|
1407
|
+
url: document.location.href,
|
|
1408
|
+
document_width: window.innerWidth,
|
|
1409
|
+
document_referrer: document?.referrer
|
|
1410
|
+
};
|
|
1411
|
+
};
|
|
1412
|
+
const $e0a87646d12cb987$export$82badda1f9923310 = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)((vars, use_ws)=>{
|
|
1413
|
+
if (process.env.DEPICT === "false") return;
|
|
1414
|
+
const payload = [
|
|
1415
|
+
{
|
|
1416
|
+
...$e0a87646d12cb987$export$8c6f26a5b6921b95(),
|
|
1417
|
+
// Compatability mapping - TODO: refactor & remove
|
|
1418
|
+
tenant: vars?.TENANT,
|
|
1419
|
+
market: vars?.MARKET,
|
|
1420
|
+
entity_price: vars?.sale_price,
|
|
1421
|
+
...vars
|
|
1646
1422
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
if (
|
|
1666
|
-
|
|
1423
|
+
];
|
|
1424
|
+
return (0, $0c84f8e99aac5765$export$28cacbd9b4306ffc)(payload, use_ws);
|
|
1425
|
+
});
|
|
1426
|
+
const $e0a87646d12cb987$export$15f8a0cd5a8c0ebb = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)((vars)=>{
|
|
1427
|
+
if (process.env.DEPICT === "false") return;
|
|
1428
|
+
const beacon_retval = $e0a87646d12cb987$export$82badda1f9923310({
|
|
1429
|
+
...vars,
|
|
1430
|
+
type: "click"
|
|
1431
|
+
}, false // don't send clicks over websockets because the page might unload
|
|
1432
|
+
);
|
|
1433
|
+
$e0a87646d12cb987$export$82badda1f9923310({
|
|
1434
|
+
...vars,
|
|
1435
|
+
type: "ws_click"
|
|
1436
|
+
}, true // explicitly send `ws-click` over websockets, this is an experiment to test the hypothesis of above - does unloading the page affect if this gets sent?
|
|
1437
|
+
);
|
|
1438
|
+
return beacon_retval;
|
|
1439
|
+
});
|
|
1440
|
+
const $e0a87646d12cb987$export$9028351cb994757e = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)((vars)=>{
|
|
1441
|
+
if (process.env.DEPICT === "false") return;
|
|
1442
|
+
return $e0a87646d12cb987$export$82badda1f9923310({
|
|
1443
|
+
...vars,
|
|
1444
|
+
type: "add_to_cart"
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
function $e0a87646d12cb987$export$622991c71a1f52b3(cookie_name) {
|
|
1448
|
+
// https://stackoverflow.com/a/25490531
|
|
1449
|
+
return document.cookie.match("(^|;)\\s*" + cookie_name + "\\s*=\\s*([^;]+)")?.pop() || "";
|
|
1667
1450
|
}
|
|
1668
1451
|
|
|
1669
1452
|
|
|
1670
1453
|
|
|
1671
|
-
|
|
1454
|
+
function $13a446968e3581c0$export$c50e1901e8ed0615(callback) {
|
|
1455
|
+
// https://stackoverflow.com/a/61574326
|
|
1456
|
+
const channel = new MessageChannel();
|
|
1457
|
+
channel.port1.onmessage = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(callback);
|
|
1458
|
+
channel.port2.postMessage("");
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1672
1461
|
|
|
1673
1462
|
|
|
1463
|
+
function $dba5a9c0f6fb4324$export$6f051469dd676a8b(tenant, market, type) {
|
|
1464
|
+
let queued_sending = false;
|
|
1465
|
+
const current_displays = new Set();
|
|
1466
|
+
return function(display, info) {
|
|
1467
|
+
if (!display) return;
|
|
1468
|
+
info.set_on_index_change(()=>{
|
|
1469
|
+
current_displays.add(display);
|
|
1470
|
+
(0, $eYQBp$solidjs.onCleanup)(()=>current_displays.delete(display));
|
|
1471
|
+
if (!queued_sending) {
|
|
1472
|
+
queued_sending = true;
|
|
1473
|
+
(0, $13a446968e3581c0$export$c50e1901e8ed0615)(()=>{
|
|
1474
|
+
(0, $e0a87646d12cb987$export$82badda1f9923310)({
|
|
1475
|
+
tenant: tenant,
|
|
1476
|
+
market: market,
|
|
1477
|
+
recommendation_type: type,
|
|
1478
|
+
type: "recommendations_inserted"
|
|
1479
|
+
});
|
|
1480
|
+
queued_sending = false;
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1674
1487
|
|
|
1675
1488
|
|
|
1676
1489
|
/**
|
|
1677
|
-
*
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1490
|
+
* @deprecated this was a stupid idea, it's much easier to read if one just does a quick arrow function that provides the wanted arguments
|
|
1491
|
+
*/ function $ee1d22bd1fcdd4e1$export$6e7454c733fa1fb2(fn, ...args) {
|
|
1492
|
+
return function(...unimportant_args) {
|
|
1493
|
+
return fn.apply(this, [
|
|
1494
|
+
...args,
|
|
1495
|
+
...unimportant_args
|
|
1496
|
+
]);
|
|
1497
|
+
};
|
|
1683
1498
|
}
|
|
1684
1499
|
|
|
1685
1500
|
|
|
1686
1501
|
|
|
1687
1502
|
|
|
1503
|
+
const $eee5951374097b61$export$8582cf3716962dc2 = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)(async ({ recs: recs , min_recs: min_recs , market: market , type: type , product_id: product_id , tenant: tenant })=>{
|
|
1504
|
+
if (type == "placeholder") return;
|
|
1505
|
+
if (typeof product_id === "function") product_id = product_id();
|
|
1506
|
+
product_id = await product_id;
|
|
1507
|
+
recs = await recs;
|
|
1508
|
+
if (typeof recs === "object") {
|
|
1509
|
+
if (!Array.isArray(recs)) recs = recs?.displays;
|
|
1510
|
+
if (Array.isArray(recs)) {
|
|
1511
|
+
if (min_recs == undefined) min_recs = 10;
|
|
1512
|
+
if (recs.length < min_recs) {
|
|
1513
|
+
(0, $e6c6e7929ea385ae$export$c2363754d4758444)("Displays provided to check_displays is too short, it contains", recs.length, "displays which is less than", min_recs);
|
|
1514
|
+
return false;
|
|
1515
|
+
} else return true;
|
|
1516
|
+
} else (0, $e6c6e7929ea385ae$export$c2363754d4758444)(new Error("neither recs nor recs.displays are an array"));
|
|
1517
|
+
} else (0, $e6c6e7929ea385ae$export$c2363754d4758444)(new Error("Non object was passed to check_displays"));
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
|
|
1688
1521
|
|
|
1689
|
-
const $
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
];
|
|
1699
|
-
#ons = {};
|
|
1700
|
-
#try_again_in_ms = this.#initial_reconnect_delay;
|
|
1701
|
-
#fails = 0;
|
|
1702
|
-
#max_fails = 10;
|
|
1703
|
-
#max_backoff_ms = $d10801050840d92b$var$ONE_MINUTE;
|
|
1704
|
-
get #initial_reconnect_delay() {
|
|
1705
|
-
return (0, $3f34dc07544c5857$export$bb0a9c36cf454ea0)(1, 1000);
|
|
1522
|
+
const $546052c2e3608435$var$elem_track_id_map = /*@__PURE__*/ new WeakMap();
|
|
1523
|
+
function $546052c2e3608435$export$16d7c76794a38a4(element, event, track_id, func) {
|
|
1524
|
+
const set_for_el = $546052c2e3608435$var$elem_track_id_map.get(element);
|
|
1525
|
+
if (!set_for_el?.has?.(track_id)) {
|
|
1526
|
+
if (!(set_for_el instanceof Set)) $546052c2e3608435$var$elem_track_id_map.set(element, new Set([
|
|
1527
|
+
track_id
|
|
1528
|
+
]));
|
|
1529
|
+
else set_for_el.add(track_id);
|
|
1530
|
+
element.addEventListener(event, func, true);
|
|
1706
1531
|
}
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
// the event will only have `.data` if it's a message or close event, but wdgaf because setting undefined = undefined is still undefined
|
|
1726
|
-
// ts-ignore because it would be very hard to teach typescript the situation
|
|
1727
|
-
} else try {
|
|
1728
|
-
// @ts-ignore
|
|
1729
|
-
fixed_event = new original_event.constructor(original_event.type, original_event); // modern browsers - clones an event as well as possible
|
|
1730
|
-
} catch (e) {
|
|
1731
|
-
// IE11 and the likes
|
|
1732
|
-
// dlog("Can't reconstruct event", e, original_event, "trying to make a CustomEvent instead");
|
|
1733
|
-
fixed_event = new CustomEvent(original_event.type, original_event);
|
|
1734
|
-
const intermediate = {};
|
|
1735
|
-
for(const key in original_event)intermediate[key] = original_event[key]; // for some reason Object.assign doesn't work because things like MessageEvent.data are not enumarable
|
|
1736
|
-
delete intermediate["target"];
|
|
1737
|
-
Object.assign(fixed_event, intermediate);
|
|
1738
|
-
}
|
|
1739
|
-
this.dispatchEvent(fixed_event);
|
|
1740
|
-
}));
|
|
1741
|
-
});
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
|
|
1535
|
+
// @ts-nocheck
|
|
1536
|
+
|
|
1537
|
+
const $7599647868f98022$var$needs_patching = typeof window === "object" ? /*@__PURE__*/ $7599647868f98022$var$check_if_querySelectorAll_needs_patching() : false;
|
|
1538
|
+
function $7599647868f98022$export$33f937d741e49339(element, selector) {
|
|
1539
|
+
if (!(element instanceof Element) || !$7599647868f98022$var$needs_patching || !selector.includes("#") || !selector.includes("+")) // covers most cases, we don't need patching or don't hit the bug
|
|
1540
|
+
return element?.querySelectorAll?.(selector);
|
|
1541
|
+
const result = [];
|
|
1542
|
+
const elements_to_check = [];
|
|
1543
|
+
// intentionally not recursive since it's possible to have deeper nested elements than max stack size
|
|
1544
|
+
for(let i = element.children.length; i--;)elements_to_check.push(element.children[i]);
|
|
1545
|
+
while(elements_to_check.length){
|
|
1546
|
+
const child_element = elements_to_check.pop();
|
|
1547
|
+
if (child_element.matches(selector)) result.push(child_element);
|
|
1548
|
+
for(let i = child_element.children.length; i--;)// kudos to Karl for algorithm help
|
|
1549
|
+
elements_to_check.push(child_element.children[i]);
|
|
1742
1550
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
const on_fn = this.#ons[ev];
|
|
1757
|
-
if (typeof on_fn === "function") (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(on_fn).call(ev, e);
|
|
1758
|
-
});
|
|
1759
|
-
}
|
|
1551
|
+
return result;
|
|
1552
|
+
}
|
|
1553
|
+
function $7599647868f98022$var$check_if_querySelectorAll_needs_patching() {
|
|
1554
|
+
const id_div = document.createElement("div");
|
|
1555
|
+
const element = document.createElement("section");
|
|
1556
|
+
const selector = "#a+*";
|
|
1557
|
+
id_div.id = "a";
|
|
1558
|
+
document.documentElement.append(id_div, element);
|
|
1559
|
+
try {
|
|
1560
|
+
return element === element.querySelectorAll(selector)[0];
|
|
1561
|
+
} finally{
|
|
1562
|
+
id_div.remove();
|
|
1563
|
+
element.remove();
|
|
1760
1564
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
clearTimeout(timeout);
|
|
1786
|
-
});
|
|
1787
|
-
window.addEventListener("online", handler, {
|
|
1788
|
-
once: true
|
|
1789
|
-
});
|
|
1790
|
-
const timeout = setTimeout((0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(()=>{
|
|
1791
|
-
this.#try_again_in_ms *= 1.5 + Math.random();
|
|
1792
|
-
if (this.#try_again_in_ms > this.#max_backoff_ms) this.#try_again_in_ms = this.#max_backoff_ms * (1 + Math.random() / 10);
|
|
1793
|
-
r();
|
|
1794
|
-
window.removeEventListener("online", handler);
|
|
1795
|
-
}), this.#try_again_in_ms);
|
|
1796
|
-
});
|
|
1797
|
-
this.#connect();
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
|
|
1569
|
+
|
|
1570
|
+
let $55595fc7bb226f61$var$has_queued_microtask = false;
|
|
1571
|
+
const $55595fc7bb226f61$var$queued_callbacks = /*@__PURE__*/ new Map();
|
|
1572
|
+
const $55595fc7bb226f61$var$catchified_deduplicate_and_dispatch = /*@__PURE__*/ (0, /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9)($55595fc7bb226f61$var$deduplicate_and_dispatch, "error in observer event processing", "error");
|
|
1573
|
+
function $55595fc7bb226f61$export$2b08e30396270f0b(callback, ev) {
|
|
1574
|
+
$55595fc7bb226f61$var$queued_callbacks.set(ev, callback);
|
|
1575
|
+
if (!$55595fc7bb226f61$var$has_queued_microtask) queueMicrotask($55595fc7bb226f61$var$catchified_deduplicate_and_dispatch);
|
|
1576
|
+
}
|
|
1577
|
+
function $55595fc7bb226f61$var$deduplicate_and_dispatch() {
|
|
1578
|
+
$55595fc7bb226f61$var$has_queued_microtask = false;
|
|
1579
|
+
const deduplication_map = new Map();
|
|
1580
|
+
// event_name -> [selector -> [element -> [function, eoe]]]
|
|
1581
|
+
for (const [eoe, callback] of $55595fc7bb226f61$var$queued_callbacks){
|
|
1582
|
+
// put events into structure of maps and sets where they can only exist once
|
|
1583
|
+
$55595fc7bb226f61$var$queued_callbacks.delete(eoe);
|
|
1584
|
+
const { event: event_name , selector: selector , element: element } = eoe;
|
|
1585
|
+
if (!event_name) {
|
|
1586
|
+
// it's an ifexists callback, doesnt' need deduplication
|
|
1587
|
+
$55595fc7bb226f61$var$call_callback(callback, eoe);
|
|
1588
|
+
continue;
|
|
1798
1589
|
}
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1590
|
+
let l2_map = deduplication_map.get(event_name);
|
|
1591
|
+
if (!l2_map) {
|
|
1592
|
+
l2_map = new Map();
|
|
1593
|
+
deduplication_map.set(event_name, l2_map);
|
|
1594
|
+
}
|
|
1595
|
+
let l3_map = l2_map.get(selector);
|
|
1596
|
+
if (!l3_map) {
|
|
1597
|
+
l3_map = new Map();
|
|
1598
|
+
l2_map.set(selector, l3_map);
|
|
1599
|
+
}
|
|
1600
|
+
let l4_map = l3_map.get(element);
|
|
1601
|
+
if (!l4_map) {
|
|
1602
|
+
l4_map = new Map();
|
|
1603
|
+
l3_map.set(element, l4_map);
|
|
1805
1604
|
}
|
|
1605
|
+
l4_map.set(callback, eoe);
|
|
1806
1606
|
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1607
|
+
// go through structure and call callbacks that are left
|
|
1608
|
+
for (const [_event_name, l2_map] of deduplication_map)for (const [_selector, l3_map] of l2_map){
|
|
1609
|
+
for (const [_element, callback_set] of l3_map)for (const [callback, eoe] of callback_set)$55595fc7bb226f61$var$call_callback(callback, eoe);
|
|
1809
1610
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
this
|
|
1819
|
-
this
|
|
1820
|
-
this
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
this.#try_again_in_ms = this.#initial_reconnect_delay; // reset exponential backoff
|
|
1824
|
-
}));
|
|
1611
|
+
}
|
|
1612
|
+
function $55595fc7bb226f61$var$call_callback(callback, ev) {
|
|
1613
|
+
(0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(callback, "Error in observer callback")(ev);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
class $e2f46d4f382caff1$export$ea60432919e69303 {
|
|
1618
|
+
constructor(opts){
|
|
1619
|
+
this.element = opts.element_;
|
|
1620
|
+
this.selector = opts.selector_;
|
|
1621
|
+
this.disconnector = opts.disconnector_;
|
|
1622
|
+
opts.mutation_record_ && (this.mutation_record = opts.mutation_record_);
|
|
1623
|
+
opts.event_ && (this.event = opts.event_);
|
|
1825
1624
|
}
|
|
1826
1625
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
#
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
|
|
1629
|
+
|
|
1630
|
+
|
|
1631
|
+
class $9043c64496e3375f$export$12e07a2a9f87578a {
|
|
1632
|
+
#the_mutation_observer;
|
|
1633
|
+
#observing = {};
|
|
1634
|
+
#self_proxied;
|
|
1635
|
+
#observer_callback_running = false;
|
|
1636
|
+
#execute_after_callback_ran = [];
|
|
1637
|
+
#attribute_attribution_map_object = {};
|
|
1638
|
+
#territory;
|
|
1639
|
+
#listeners = [
|
|
1640
|
+
"exists",
|
|
1641
|
+
"creation",
|
|
1642
|
+
"removed",
|
|
1643
|
+
"change"
|
|
1644
|
+
];
|
|
1645
|
+
#weakref_finalization_registry = typeof FinalizationRegistry === "function" && new FinalizationRegistry((0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(this.#finalization_registry_callback.bind(this)));
|
|
1646
|
+
#verbs = {
|
|
1647
|
+
// add "normal" functions for the class that can be used as i.e. observer.ifexists() here
|
|
1648
|
+
ifexists: (selector, callback)=>{
|
|
1649
|
+
this.#check_observer_args(selector, callback, true);
|
|
1650
|
+
if (selector instanceof Node) {
|
|
1651
|
+
if (typeof document === "object" && (this.#territory || document.documentElement).contains(selector)) // When the selector is a node the selector and the element are the same, dunno how we could reflect that in the typing though
|
|
1652
|
+
this.#call_callbacks([
|
|
1653
|
+
callback
|
|
1654
|
+
], (callback_)=>({
|
|
1655
|
+
element_: selector,
|
|
1656
|
+
selector_: selector,
|
|
1657
|
+
// ts is being stupid here because it doesn't understand that everything in string | Text | Element | Comment that's a node is Text | Element | Comment
|
|
1658
|
+
disconnector_: this.#disconnect_fn({
|
|
1659
|
+
event_: "exists",
|
|
1660
|
+
selector_: new WeakRef(selector),
|
|
1661
|
+
callback_: callback_
|
|
1662
|
+
})
|
|
1663
|
+
}));
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
const our_set = this.#attribute_attribution_map_object[selector] ||= new WeakSet();
|
|
1667
|
+
const elements = typeof document === "undefined" ? [] : (0, $7599647868f98022$export$33f937d741e49339)(this.#territory || document, selector);
|
|
1668
|
+
for(let i = 0; i < elements.length; i++){
|
|
1669
|
+
const element = elements[i];
|
|
1670
|
+
our_set.add(element);
|
|
1671
|
+
this.#call_callbacks([
|
|
1672
|
+
callback
|
|
1673
|
+
], (callback_)=>({
|
|
1674
|
+
element_: element,
|
|
1675
|
+
selector_: selector,
|
|
1676
|
+
disconnector_: this.#disconnect_fn({
|
|
1677
|
+
event_: "exists",
|
|
1678
|
+
selector_: selector,
|
|
1679
|
+
callback_: callback_
|
|
1680
|
+
})
|
|
1681
|
+
}));
|
|
1682
|
+
}
|
|
1683
|
+
},
|
|
1684
|
+
wait_for_element: (selector, timeout)=>{
|
|
1685
|
+
return this.#self_proxied.wait_for_listener("exists", selector, timeout);
|
|
1686
|
+
},
|
|
1687
|
+
wait_for_listener: (listener, selector, timeout)=>{
|
|
1688
|
+
this.#check_observer_args(listener, ()=>{}, false);
|
|
1689
|
+
// console.log("waiting for listener", listener, "selector", selector, "timeout", timeout);
|
|
1690
|
+
return new Promise((0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)((r)=>{
|
|
1691
|
+
const stop_observing = this.#self_proxied["on" + listener](selector, ({ element: element , disconnector: disconnector })=>{
|
|
1692
|
+
r(element);
|
|
1693
|
+
disconnector();
|
|
1694
|
+
if (timeout) clearTimeout(obs_timeout);
|
|
1695
|
+
});
|
|
1696
|
+
if (timeout) var obs_timeout = setTimeout(()=>{
|
|
1697
|
+
stop_observing();
|
|
1698
|
+
r(undefined);
|
|
1699
|
+
}, timeout);
|
|
1700
|
+
}));
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
#kickstart_observer() {
|
|
1704
|
+
if (typeof document === "undefined") return;
|
|
1705
|
+
this.#the_mutation_observer = new MutationObserver(this.#observer_callback);
|
|
1706
|
+
this.#the_mutation_observer.observe(this.#territory || document, {
|
|
1707
|
+
attributes: true,
|
|
1708
|
+
childList: true,
|
|
1709
|
+
subtree: true,
|
|
1710
|
+
attributeOldValue: true,
|
|
1711
|
+
characterData: true,
|
|
1712
|
+
characterDataOldValue: true
|
|
1839
1713
|
});
|
|
1840
|
-
this.send(msg);
|
|
1841
1714
|
}
|
|
1842
|
-
#
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1715
|
+
#disconnect_fn({ event_: event_ , selector_: selector_ , callback_: callback_ }) {
|
|
1716
|
+
return ()=>{
|
|
1717
|
+
const fn = ()=>{
|
|
1718
|
+
const observing = this.#observing;
|
|
1719
|
+
const selector_to_callback_array_map = observing[event_];
|
|
1720
|
+
if (!selector_to_callback_array_map) return;
|
|
1721
|
+
const callbacks = selector_to_callback_array_map.get(selector_);
|
|
1722
|
+
callbacks?.delete(callback_);
|
|
1723
|
+
if (callbacks?.size === 0) selector_to_callback_array_map.delete(selector_);
|
|
1724
|
+
if (selector_to_callback_array_map.size === 0) delete observing[event_];
|
|
1725
|
+
if (!Object.keys(observing).length) {
|
|
1726
|
+
this.#the_mutation_observer?.disconnect();
|
|
1727
|
+
this.#the_mutation_observer = undefined;
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
// If the observer callback is running, we need to queue every function that mutates this.#observing since we can't clone it for performance reasons
|
|
1731
|
+
if (this.#observer_callback_running) this.#execute_after_callback_ran.push(fn);
|
|
1732
|
+
else fn();
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
#observer_callback = (records)=>{
|
|
1736
|
+
// this is the function which needs to be as fast as possible because it is called on EVERY mutation in the DOM
|
|
1737
|
+
try {
|
|
1738
|
+
this.#observer_callback_running = true;
|
|
1739
|
+
const steps_to_restore_observing_cache = [];
|
|
1740
|
+
try {
|
|
1741
|
+
const observing = this.#observing; // Currently observing elements. Please make sure they don't get mutated by anything except this function during the running of this function (use observer_callback_running and #execute_after_callback_ran to check for and schedule your mutations for after the run of this function). We previously cloned these on every run but that's super slow.
|
|
1742
|
+
const attribute_attribution_map_object = this.#attribute_attribution_map_object;
|
|
1743
|
+
for(let j = 0; j < records.length; j++){
|
|
1744
|
+
const record = records[j];
|
|
1745
|
+
const { addedNodes: addedNodes , removedNodes: removedNodes , target: target } = record;
|
|
1746
|
+
const events_for_discovery = [];
|
|
1747
|
+
let nodes_to_check;
|
|
1748
|
+
// code for handling a record containing wanted elements in addedNodes or the children of added nodes and attribute changes that make an existing node match a selector, mainly for oncreation and onexists, but it will fire onchange if someone is listening if an attribute change makes an element match a selector
|
|
1749
|
+
if (!addedNodes.length && !removedNodes.length) nodes_to_check = [
|
|
1750
|
+
target
|
|
1751
|
+
];
|
|
1752
|
+
else {
|
|
1753
|
+
nodes_to_check = addedNodes;
|
|
1754
|
+
if (observing["creation"]) events_for_discovery.push("creation");
|
|
1755
|
+
}
|
|
1756
|
+
if (observing["exists"]) events_for_discovery.push("exists");
|
|
1757
|
+
if (observing["change"]) events_for_discovery.push("change");
|
|
1758
|
+
for(let n = 0; n < events_for_discovery.length; n++){
|
|
1759
|
+
const event = events_for_discovery[n];
|
|
1760
|
+
const event_is_creation_or_exists_with_tree_change = event === "creation" || event === "exists" && addedNodes.length;
|
|
1761
|
+
const selector_map = observing[event];
|
|
1762
|
+
const selectors = [
|
|
1763
|
+
...selector_map.keys()
|
|
1764
|
+
]; // we can only iterate over a MapIterator once, so we need to spread it
|
|
1765
|
+
if (event === "change" && (addedNodes.length || removedNodes.length)) {
|
|
1766
|
+
// we check the selectors first because I'm DUMB and already have come so far
|
|
1767
|
+
for(let selectors_i = 0; selectors_i < selectors.length; selectors_i++){
|
|
1768
|
+
const selector = selectors[selectors_i];
|
|
1769
|
+
// @ts-ignore
|
|
1770
|
+
if (target?.matches?.(selector)) {
|
|
1771
|
+
// we WANT change event and there are children to an element that interests us - act on it
|
|
1772
|
+
const callbacks = selector_map.get(selector);
|
|
1773
|
+
this.#call_callbacks(callbacks, (callback)=>({
|
|
1774
|
+
element_: target,
|
|
1775
|
+
// it has to be an *Element* since it has
|
|
1776
|
+
// the selector is a string since the event is change
|
|
1777
|
+
// @ts-ignore
|
|
1778
|
+
selector_: selector,
|
|
1779
|
+
event_: event,
|
|
1780
|
+
mutation_record_: record,
|
|
1781
|
+
disconnector_: this.#disconnect_fn({
|
|
1782
|
+
event_: event,
|
|
1783
|
+
selector_: selector,
|
|
1784
|
+
callback_: callback
|
|
1785
|
+
})
|
|
1786
|
+
}));
|
|
1787
|
+
selector_map.delete(selector);
|
|
1788
|
+
steps_to_restore_observing_cache.push(()=>selector_map.set(selector, callbacks));
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1793
|
+
for(let i = 0; i < nodes_to_check.length; i++){
|
|
1794
|
+
const node = nodes_to_check[i];
|
|
1795
|
+
for(let selectors_i = 0; selectors_i < selectors.length; selectors_i++){
|
|
1796
|
+
const selector = selectors[selectors_i];
|
|
1797
|
+
const callbacks = selector_map.get(selector) || new Set();
|
|
1798
|
+
if (typeof selector !== "string") {
|
|
1799
|
+
// oncreation or onexists with node-selector
|
|
1800
|
+
if (event_is_creation_or_exists_with_tree_change) {
|
|
1801
|
+
const derefed_el = selector.deref();
|
|
1802
|
+
if (!derefed_el) {
|
|
1803
|
+
selector_map.delete(selector);
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
if (node === derefed_el || node.contains(derefed_el)) // node is node or node is child of added node
|
|
1807
|
+
this.#call_callbacks(callbacks, (callback)=>({
|
|
1808
|
+
element_: derefed_el,
|
|
1809
|
+
selector_: derefed_el,
|
|
1810
|
+
event_: event,
|
|
1811
|
+
mutation_record_: record,
|
|
1812
|
+
disconnector_: this.#disconnect_fn({
|
|
1813
|
+
event_: event,
|
|
1814
|
+
selector_: selector,
|
|
1815
|
+
callback_: callback
|
|
1816
|
+
})
|
|
1817
|
+
}));
|
|
1818
|
+
}
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
// @ts-ignore
|
|
1822
|
+
const matches_now = node?.matches?.(selector);
|
|
1823
|
+
let our_set;
|
|
1824
|
+
if (event == "exists") {
|
|
1825
|
+
// we want the change event to trigger to any change (exists only if it makes an element match a selector that didn't previously match)
|
|
1826
|
+
our_set = attribute_attribution_map_object[selector] ||= new WeakSet();
|
|
1827
|
+
if (record.type === "attributes" && matches_now != null) {
|
|
1828
|
+
const matched_last = our_set.has(node);
|
|
1829
|
+
if (matched_last && matches_now) continue;
|
|
1830
|
+
}
|
|
1831
|
+
if (matches_now) our_set.add(node);
|
|
1832
|
+
else our_set.delete(node);
|
|
1833
|
+
}
|
|
1834
|
+
if (matches_now) this.#call_callbacks(callbacks, (callback)=>({
|
|
1835
|
+
element_: node,
|
|
1836
|
+
selector_: selector,
|
|
1837
|
+
event_: event,
|
|
1838
|
+
mutation_record_: record,
|
|
1839
|
+
disconnector_: this.#disconnect_fn({
|
|
1840
|
+
event_: event,
|
|
1841
|
+
selector_: selector,
|
|
1842
|
+
callback_: callback
|
|
1843
|
+
})
|
|
1844
|
+
}));
|
|
1845
|
+
if ((addedNodes.length || removedNodes.length) && node.hasChildNodes() && // @ts-ignore
|
|
1846
|
+
node.querySelectorAll /* don't act on i.e. textnodes. Doing the check this way is actually faster than both `in` and instanceof */ ) {
|
|
1847
|
+
const matching_children = (0, $7599647868f98022$export$33f937d741e49339)(node, selector);
|
|
1848
|
+
for(let m = 0; m < matching_children.length; m++){
|
|
1849
|
+
// always use for loops because this can't be slow and forEach takes ages
|
|
1850
|
+
if (event == "exists") our_set.add(matching_children[m]);
|
|
1851
|
+
this.#call_callbacks(callbacks, (callback)=>({
|
|
1852
|
+
element_: matching_children[m],
|
|
1853
|
+
selector_: selector,
|
|
1854
|
+
event_: event,
|
|
1855
|
+
mutation_record_: record,
|
|
1856
|
+
disconnector_: this.#disconnect_fn({
|
|
1857
|
+
event_: event,
|
|
1858
|
+
selector_: selector,
|
|
1859
|
+
callback_: callback
|
|
1860
|
+
})
|
|
1861
|
+
}));
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
// code for handling changes to children of an observed element
|
|
1868
|
+
{
|
|
1869
|
+
const event = "change";
|
|
1870
|
+
const selector_map = observing[event];
|
|
1871
|
+
if (selector_map) {
|
|
1872
|
+
let target_el = target;
|
|
1873
|
+
while(target_el = target_el?.parentNode)// @ts-ignore
|
|
1874
|
+
if (target_el?.matches) {
|
|
1875
|
+
for (const selector of selector_map.keys())// selector is string because event is change
|
|
1876
|
+
// @ts-ignore
|
|
1877
|
+
if (target_el.matches?.(selector)) {
|
|
1878
|
+
const callbacks = selector_map.get(selector);
|
|
1879
|
+
this.#call_callbacks(callbacks, (callback)=>({
|
|
1880
|
+
element_: target_el,
|
|
1881
|
+
// @ts-ignore
|
|
1882
|
+
selector_: selector,
|
|
1883
|
+
event_: event,
|
|
1884
|
+
mutation_record_: record,
|
|
1885
|
+
disconnector_: this.#disconnect_fn({
|
|
1886
|
+
event_: event,
|
|
1887
|
+
selector_: selector,
|
|
1888
|
+
callback_: callback
|
|
1889
|
+
})
|
|
1890
|
+
}));
|
|
1891
|
+
// Since we now deduplicate
|
|
1892
|
+
steps_to_restore_observing_cache.push(()=>selector_map.set(selector, callbacks));
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
// code for observing observed elements disappearing
|
|
1898
|
+
{
|
|
1899
|
+
const event = "removed";
|
|
1900
|
+
const removed_map = observing[event];
|
|
1901
|
+
if (removed_map && removedNodes?.length) {
|
|
1902
|
+
const selectors = [
|
|
1903
|
+
...removed_map.keys()
|
|
1904
|
+
];
|
|
1905
|
+
for(let t = 0; t < removedNodes.length; t++)for(let u = 0; u < selectors.length; u++){
|
|
1906
|
+
const selector = selectors[u];
|
|
1907
|
+
const callbacks = removed_map.get(selector) || new Set();
|
|
1908
|
+
const node = removedNodes[t];
|
|
1909
|
+
if (typeof selector === "string") {
|
|
1910
|
+
const matching_nodes = [];
|
|
1911
|
+
// @ts-ignore
|
|
1912
|
+
if (node?.matches?.(selector)) matching_nodes.push(node);
|
|
1913
|
+
matching_nodes.push(...(0, $7599647868f98022$export$33f937d741e49339)(node, selector) || []);
|
|
1914
|
+
for(let v = 0; v < matching_nodes.length; v++)this.#call_callbacks(callbacks, (callback)=>({
|
|
1915
|
+
element_: matching_nodes[v],
|
|
1916
|
+
selector_: selector,
|
|
1917
|
+
event_: event,
|
|
1918
|
+
mutation_record_: record,
|
|
1919
|
+
disconnector_: this.#disconnect_fn({
|
|
1920
|
+
event_: "removed",
|
|
1921
|
+
selector_: selector,
|
|
1922
|
+
callback_: callback
|
|
1923
|
+
})
|
|
1924
|
+
}));
|
|
1925
|
+
} else {
|
|
1926
|
+
const derefed_el = selector.deref();
|
|
1927
|
+
if (derefed_el) {
|
|
1928
|
+
if (node === derefed_el || node.contains(derefed_el)) this.#call_callbacks(callbacks, (callback)=>({
|
|
1929
|
+
element_: derefed_el,
|
|
1930
|
+
mutation_record_: record,
|
|
1931
|
+
selector_: derefed_el,
|
|
1932
|
+
event_: event,
|
|
1933
|
+
disconnector_: this.#disconnect_fn({
|
|
1934
|
+
event_: event,
|
|
1935
|
+
selector_: selector,
|
|
1936
|
+
callback_: callback
|
|
1937
|
+
})
|
|
1938
|
+
}));
|
|
1939
|
+
} else // here it's also ok to mutate #observing since the WeakRef is empty
|
|
1940
|
+
removed_map.delete(selector);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
// const end = new Date().getTime();
|
|
1947
|
+
// console.log("procesed",records.length,"in", end-start, this.#observing);
|
|
1948
|
+
} finally{
|
|
1949
|
+
// ensure that we don't leave this.#observing in a broken state if we throw
|
|
1950
|
+
while(steps_to_restore_observing_cache.length)steps_to_restore_observing_cache.pop()();
|
|
1951
|
+
const execute_after_run = this.#execute_after_callback_ran;
|
|
1952
|
+
// We need to execute these in order they were added because I'm afraid that things might rely on it
|
|
1953
|
+
for(let i = 0; i < execute_after_run.length; i++)try {
|
|
1954
|
+
execute_after_run[i]();
|
|
1955
|
+
} catch (e) {
|
|
1956
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
1957
|
+
e,
|
|
1958
|
+
"error in observer running queued function"
|
|
1959
|
+
], "error");
|
|
1960
|
+
}
|
|
1961
|
+
// Let the garbage collector empty the old array by creating a new one
|
|
1962
|
+
this.#execute_after_callback_ran = [];
|
|
1963
|
+
this.#observer_callback_running = false;
|
|
1883
1964
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1965
|
+
} catch (e) {
|
|
1966
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
1967
|
+
e,
|
|
1968
|
+
"error in observer"
|
|
1969
|
+
], "error");
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
#check_observer_args(selector, callback, allow_nodes) {
|
|
1973
|
+
if (!allow_nodes && typeof selector !== "string" || allow_nodes && !(selector instanceof Node) && typeof selector !== "string") throw new Error("no or invalid selector specified");
|
|
1974
|
+
if (typeof callback !== "function") throw new Error("no callback specified");
|
|
1887
1975
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
const
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
const msg = "Got malformed message (ignoring, might cause memory leak)";
|
|
1898
|
-
(0, $e6c6e7929ea385ae$export$de56f1198d121036)(msg, data, e);
|
|
1899
|
-
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
1900
|
-
e,
|
|
1901
|
-
msg
|
|
1902
|
-
], "error", {
|
|
1903
|
-
data: data
|
|
1976
|
+
#add_listener(listener) {
|
|
1977
|
+
// called when observer.onsomethinglistener() is called, somethinglistener being something in this.#listeners
|
|
1978
|
+
const the_class = this;
|
|
1979
|
+
const function_for_listener = (selector, callback)=>{
|
|
1980
|
+
if (!listener || !selector || !callback) {
|
|
1981
|
+
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("listener, selector or callback is falsey", {
|
|
1982
|
+
listener: listener,
|
|
1983
|
+
selector: selector,
|
|
1984
|
+
callback: callback
|
|
1904
1985
|
});
|
|
1905
|
-
|
|
1986
|
+
return;
|
|
1906
1987
|
}
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
} else if (status == "not-ok") (0, $e6c6e7929ea385ae$export$c2363754d4758444)("Got reply not-ok reply from server for event!", payload, reply);
|
|
1913
|
-
else if (status == "ok") {
|
|
1914
|
-
if (process.env.BUILD_TARGET !== "node") (0, $e6c6e7929ea385ae$export$de56f1198d121036)(`Successfully sent ${payload?.event?.type} (WS)`, payload, reply);
|
|
1915
|
-
} else (0, $e6c6e7929ea385ae$export$c2363754d4758444)("Strange reply from WSS server to", payload, ":", reply);
|
|
1916
|
-
stop_sending();
|
|
1917
|
-
return [
|
|
1918
|
-
reply,
|
|
1919
|
-
data
|
|
1920
|
-
];
|
|
1988
|
+
the_class.#check_observer_args(selector, callback, listener != "change");
|
|
1989
|
+
if (the_class.#observer_callback_running) {
|
|
1990
|
+
// Can't mutate #observing right now, queue it for when we can
|
|
1991
|
+
the_class.#execute_after_callback_ran.push(()=>function_for_listener(selector, callback));
|
|
1992
|
+
return;
|
|
1921
1993
|
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
* @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
|
|
1941
|
-
*/ function $650b64c1b384c895$export$656831b7e9c341c3() {
|
|
1942
|
-
return (Math.random() * 2e17).toString(36);
|
|
1943
|
-
}
|
|
1944
|
-
function $650b64c1b384c895$export$a6db784f019668ba() {
|
|
1945
|
-
return "x" + $650b64c1b384c895$export$656831b7e9c341c3().replaceAll(".", "");
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
const $0c84f8e99aac5765$var$c = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9);
|
|
1954
|
-
const $0c84f8e99aac5765$var$ws_instance = /*@__PURE__*/ $0c84f8e99aac5765$var$c(()=>new (0, $d10801050840d92b$export$1d9c6fddbff3441f)("wss://ws.depict.ai/ws/create-events"))();
|
|
1955
|
-
const $0c84f8e99aac5765$var$allowed_keys = [
|
|
1956
|
-
"tenant",
|
|
1957
|
-
"market",
|
|
1958
|
-
"type",
|
|
1959
|
-
"user_id",
|
|
1960
|
-
"session_id",
|
|
1961
|
-
"product_id",
|
|
1962
|
-
"entity_identifiers",
|
|
1963
|
-
"url",
|
|
1964
|
-
"entity_price",
|
|
1965
|
-
"currency",
|
|
1966
|
-
"document_referrer",
|
|
1967
|
-
"document_width",
|
|
1968
|
-
"attribution_id",
|
|
1969
|
-
"recommendation_id",
|
|
1970
|
-
"click_location",
|
|
1971
|
-
"ab_test_group",
|
|
1972
|
-
"variant_ids",
|
|
1973
|
-
"dsid",
|
|
1974
|
-
"transaction_id",
|
|
1975
|
-
"error_type",
|
|
1976
|
-
"detail",
|
|
1977
|
-
"recommendation_type",
|
|
1978
|
-
"search_result_id",
|
|
1979
|
-
"product_listing_result_id"
|
|
1980
|
-
];
|
|
1981
|
-
const $0c84f8e99aac5765$export$72036d950e1fae95 = /*@__PURE__*/ $0c84f8e99aac5765$var$c((payload)=>{
|
|
1982
|
-
if (process.env.DEPICT === "false") return;
|
|
1983
|
-
return payload.map((body)=>Object.fromEntries(Object.entries(body).filter(([key, value])=>$0c84f8e99aac5765$var$allowed_keys.includes(key) && value != null)));
|
|
1984
|
-
});
|
|
1985
|
-
const $0c84f8e99aac5765$export$aa26019042811d4f = /*@__PURE__*/ $0c84f8e99aac5765$var$c(async (bodies)=>{
|
|
1986
|
-
if (process.env.DEPICT === "false") return;
|
|
1987
|
-
for(let i = 0; i < bodies.length; i++){
|
|
1988
|
-
const id = (0, $650b64c1b384c895$export$656831b7e9c341c3)();
|
|
1989
|
-
$0c84f8e99aac5765$var$ws_instance?.ensure_sent({
|
|
1990
|
-
id: id,
|
|
1991
|
-
event: bodies[i]
|
|
1992
|
-
}).catch((e)=>(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "error"));
|
|
1993
|
-
}
|
|
1994
|
-
});
|
|
1995
|
-
const $0c84f8e99aac5765$export$608478473a3304a0 = /*@__PURE__*/ $0c84f8e99aac5765$var$c((payload, use_ws = true)=>{
|
|
1996
|
-
if (process.env.DEPICT === "false") return;
|
|
1997
|
-
if (use_ws && typeof WebSocket == "function" && typeof $0c84f8e99aac5765$var$ws_instance?.ensure_sent == "function") {
|
|
1998
|
-
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Sending to depict (ws)", payload);
|
|
1999
|
-
return $0c84f8e99aac5765$export$aa26019042811d4f(payload);
|
|
2000
|
-
}
|
|
2001
|
-
const url = (0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/create-events";
|
|
2002
|
-
return $0c84f8e99aac5765$export$cc3b6ddf805f6156(url, payload);
|
|
2003
|
-
});
|
|
2004
|
-
const $0c84f8e99aac5765$export$cc3b6ddf805f6156 = /*@__PURE__*/ $0c84f8e99aac5765$var$c((url, payload)=>{
|
|
2005
|
-
const payload_json = JSON.stringify(payload);
|
|
2006
|
-
let success = false;
|
|
2007
|
-
(0, $e6c6e7929ea385ae$export$de56f1198d121036)(`Attempting to send (beacon)`, payload);
|
|
2008
|
-
try {
|
|
2009
|
-
success = navigator.sendBeacon(url, new Blob([
|
|
2010
|
-
payload_json
|
|
2011
|
-
], {
|
|
2012
|
-
type: "application/json"
|
|
2013
|
-
}));
|
|
2014
|
-
} catch (first_error) {
|
|
2015
|
-
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Beacon has failed", first_error, "falling back to sending with wrong mime type which might work");
|
|
2016
|
-
try {
|
|
2017
|
-
success = navigator.sendBeacon(url, new Blob([
|
|
2018
|
-
payload_json
|
|
2019
|
-
], {
|
|
2020
|
-
type: "application/x-www-form-urlencoded"
|
|
2021
|
-
}));
|
|
2022
|
-
} catch (e) {
|
|
2023
|
-
(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Beacon fallback has failed", e, "trying fetch");
|
|
2024
|
-
fetch(url, {
|
|
2025
|
-
"headers": {
|
|
2026
|
-
"content-type": "application/json"
|
|
2027
|
-
},
|
|
2028
|
-
"body": payload_json,
|
|
2029
|
-
"method": "POST",
|
|
2030
|
-
"mode": "cors",
|
|
2031
|
-
"credentials": "include"
|
|
2032
|
-
}).then((response)=>response.text()).then((text)=>(0, $e6c6e7929ea385ae$export$de56f1198d121036)("Beacon fallback fallback transmission result", text)).catch((fetch_error)=>{
|
|
2033
|
-
(0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).withScope(function(scope) {
|
|
2034
|
-
scope.setExtra("stack", new Error().stack);
|
|
2035
|
-
scope.setExtra("url", url);
|
|
2036
|
-
scope.setExtra("payload", payload_json);
|
|
2037
|
-
scope.setExtra("first_error", first_error);
|
|
2038
|
-
scope.setExtra("second_error", e);
|
|
2039
|
-
scope.setTag("feature", "beacon");
|
|
2040
|
-
scope.setTag("approach", "fetch_fallback");
|
|
2041
|
-
scope.setLevel("error");
|
|
2042
|
-
this.captureMessage(fetch_error); // we can now do this - it's depict lazy sentry specific. `this` will refer to the actual hub with breadcrumbs and the scope activated
|
|
1994
|
+
const observing = the_class.#observing;
|
|
1995
|
+
observing[listener] ||= new Map();
|
|
1996
|
+
// create map for each listener, this is because the selectors can be objects for .onremoved, .oncreation and .onexists to take explicit nodes
|
|
1997
|
+
const selector_map = observing[listener];
|
|
1998
|
+
let disconnector;
|
|
1999
|
+
if (listener === "exists") the_class.#verbs.ifexists(selector, callback);
|
|
2000
|
+
if (typeof selector === "string") {
|
|
2001
|
+
// simple code for string selectors
|
|
2002
|
+
let callback_set = selector_map.get(selector);
|
|
2003
|
+
if (!callback_set) {
|
|
2004
|
+
callback_set = new Set();
|
|
2005
|
+
selector_map.set(selector, callback_set);
|
|
2006
|
+
}
|
|
2007
|
+
callback_set.add(callback); // we make this a set since you're not supposed to be able to have the same function as listener twice, like you can't with addEventListener
|
|
2008
|
+
disconnector = the_class.#disconnect_fn({
|
|
2009
|
+
event_: listener,
|
|
2010
|
+
selector_: selector,
|
|
2011
|
+
callback_: callback
|
|
2043
2012
|
});
|
|
2044
|
-
}
|
|
2013
|
+
} else {
|
|
2014
|
+
// for an element "selector" we don't want to keep strong references to the nodes as that would prevent them from being garbage collected
|
|
2015
|
+
let callback_set_to_add_to;
|
|
2016
|
+
for (const [stored_selector, existing_callback_set] of selector_map){
|
|
2017
|
+
// try finding an existing array of callbacks
|
|
2018
|
+
if (typeof stored_selector === "string") continue;
|
|
2019
|
+
const ref_contents = stored_selector.deref();
|
|
2020
|
+
if (!ref_contents) {
|
|
2021
|
+
// clean up listeners for selectors that have already been GC'd
|
|
2022
|
+
selector_map.delete(stored_selector);
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
if (ref_contents === selector) {
|
|
2026
|
+
callback_set_to_add_to = existing_callback_set;
|
|
2027
|
+
disconnector = the_class.#disconnect_fn({
|
|
2028
|
+
event_: listener,
|
|
2029
|
+
selector_: stored_selector,
|
|
2030
|
+
callback_: callback
|
|
2031
|
+
});
|
|
2032
|
+
break;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (!callback_set_to_add_to) {
|
|
2036
|
+
callback_set_to_add_to = new Set();
|
|
2037
|
+
const weakref = new WeakRef(selector);
|
|
2038
|
+
the_class.#cleanup_weakref_when_refd_el_gcd(listener, weakref, selector);
|
|
2039
|
+
selector_map.set(weakref, callback_set_to_add_to);
|
|
2040
|
+
disconnector = the_class.#disconnect_fn({
|
|
2041
|
+
event_: listener,
|
|
2042
|
+
selector_: weakref,
|
|
2043
|
+
callback_: callback
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
callback_set_to_add_to.add(callback);
|
|
2047
|
+
}
|
|
2048
|
+
if (!the_class.#the_mutation_observer) the_class.#kickstart_observer();
|
|
2049
|
+
return disconnector;
|
|
2050
|
+
};
|
|
2051
|
+
return function_for_listener;
|
|
2052
|
+
}
|
|
2053
|
+
#cleanup_weakref_when_refd_el_gcd(listener1, weakref, element) {
|
|
2054
|
+
// we don't want to keep references to elements used as "selectors" in oncreation and onremoved
|
|
2055
|
+
if (!this.#weakref_finalization_registry) return;
|
|
2056
|
+
this.#weakref_finalization_registry.register(element, [
|
|
2057
|
+
listener1,
|
|
2058
|
+
weakref
|
|
2059
|
+
]);
|
|
2060
|
+
}
|
|
2061
|
+
#finalization_registry_callback([listener2, weak_ref]) {
|
|
2062
|
+
// element was GCd and the callbacks can never be called, remove them
|
|
2063
|
+
const observing = this.#observing;
|
|
2064
|
+
observing[listener2]?.get(weak_ref)?.clear(); // just in case something still has a reference to this set and does something with it, clear it
|
|
2065
|
+
observing[listener2]?.delete(weak_ref);
|
|
2066
|
+
if (observing[listener2]?.size === 0) delete observing[listener2];
|
|
2067
|
+
if (Object.keys(observing).length === 0) {
|
|
2068
|
+
this.#the_mutation_observer?.disconnect();
|
|
2069
|
+
this.#the_mutation_observer = undefined;
|
|
2045
2070
|
}
|
|
2046
2071
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2072
|
+
#call_callbacks(callbacks, make_ev_data) {
|
|
2073
|
+
for (const callback of callbacks)(0, $55595fc7bb226f61$export$2b08e30396270f0b)(callback, new (0, $e2f46d4f382caff1$export$ea60432919e69303)(make_ev_data(callback)));
|
|
2074
|
+
}
|
|
2075
|
+
#get(target, verb) {
|
|
2076
|
+
// @ts-ignore
|
|
2077
|
+
const is_listener = target.#listeners.includes(verb.slice(2));
|
|
2078
|
+
const is_verb = Object.keys(target.#verbs).includes(verb);
|
|
2079
|
+
if (is_verb) return target.#verbs[verb];
|
|
2080
|
+
else if (is_listener) return target.#add_listener(verb.slice(2));
|
|
2081
|
+
else throw new Error("Property " + verb + " is not valid. Valid listeners: " + target.#listeners.join(", ") + "; valid verbs: " + Object.keys(target.#verbs).join(", "));
|
|
2082
|
+
}
|
|
2083
|
+
constructor(options = {}){
|
|
2084
|
+
if (process.env.BUILD_TARGET !== "modern" && Proxy.toString().indexOf("[native code]") === -1) {
|
|
2085
|
+
this.#listeners.forEach((listener)=>this["on" + listener] = ()=>{}); // define listeners, needed for IE11 proxy polyfill
|
|
2086
|
+
Object.keys(this.#verbs).forEach((listener)=>this[listener] = ()=>{});
|
|
2087
|
+
}
|
|
2088
|
+
if (options.territory) this.#territory = options.territory;
|
|
2089
|
+
return this.#self_proxied = new Proxy(this, {
|
|
2090
|
+
get: this.#get
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2055
2094
|
|
|
2056
2095
|
|
|
2057
2096
|
|
|
2058
2097
|
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
let id = "";
|
|
2062
|
-
let localstorage_error;
|
|
2063
|
-
let cookie_error;
|
|
2098
|
+
const $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149 = /*@__PURE__*/ $2a1cbc63a04d4a2d$var$make_default_observer();
|
|
2099
|
+
function $2a1cbc63a04d4a2d$var$make_default_observer() {
|
|
2064
2100
|
try {
|
|
2065
|
-
|
|
2066
|
-
} catch (
|
|
2067
|
-
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(
|
|
2068
|
-
|
|
2101
|
+
return new (0, $9043c64496e3375f$export$12e07a2a9f87578a)();
|
|
2102
|
+
} catch (error) {
|
|
2103
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)([
|
|
2104
|
+
error,
|
|
2105
|
+
"error starting ElementObserver"
|
|
2106
|
+
], "error");
|
|
2069
2107
|
}
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
function $bf7f12fe044e41b2$export$925772df9b4d16e5(url, param, value) {
|
|
2114
|
+
const url_object = new URL(url), search_params = new URLSearchParams(url_object.search);
|
|
2115
|
+
search_params.set(param, value);
|
|
2116
|
+
return url_object.origin + url_object.pathname + "?" + search_params.toString();
|
|
2117
|
+
}
|
|
2118
|
+
function $bf7f12fe044e41b2$export$785f04709990c4ec(element, selector) {
|
|
2119
|
+
let result = null;
|
|
2120
|
+
while(!result && element){
|
|
2121
|
+
element = element?.parentNode;
|
|
2122
|
+
result = element?.querySelector(selector) || (element?.matches ? element.matches(selector) ? element : null : null);
|
|
2123
|
+
}
|
|
2124
|
+
return result;
|
|
2125
|
+
}
|
|
2126
|
+
function $bf7f12fe044e41b2$export$44951404cb8d0583(html) {
|
|
2127
|
+
// need to wrap the HTML into a <body> tag because the browser otherwise automatically puts <style> into head and we can't return it
|
|
2128
|
+
return new DOMParser().parseFromString(`<body>${html}</body>`, "text/html")?.body?.childNodes;
|
|
2129
|
+
}
|
|
2130
|
+
function $bf7f12fe044e41b2$export$d3e2a0560cbf4787(html) {
|
|
2131
|
+
return new DOMParser().parseFromString(`<body>${html}</body>`, "text/html")?.body?.firstElementChild;
|
|
2132
|
+
}
|
|
2133
|
+
function $bf7f12fe044e41b2$export$d4bd03f19260ef1c(url, also_onchange = false, override_dev_url = "demo.depict.ai", stfu = true, also_in_all_shadow_roots = false) {
|
|
2134
|
+
if (process.env.DEBUG === "true" && location.href.includes(override_dev_url)) {
|
|
2135
|
+
const relativ_callback = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)((event)=>{
|
|
2136
|
+
const anchor = event.element;
|
|
2137
|
+
if (typeof url === "string") {
|
|
2138
|
+
if (anchor.href.includes(url)) {
|
|
2139
|
+
if (!stfu) (0, $e6c6e7929ea385ae$export$de56f1198d121036)("RUNNING RELATIVIFY on", event);
|
|
2140
|
+
anchor.href = anchor.href.replaceAll(url, "/");
|
|
2141
|
+
}
|
|
2142
|
+
} else if (url.test(anchor.href)) {
|
|
2143
|
+
if (!stfu) (0, $e6c6e7929ea385ae$export$de56f1198d121036)("RUNNING RELATIVIFY on", event);
|
|
2144
|
+
anchor.href = anchor.href.replace(url, "/");
|
|
2082
2145
|
}
|
|
2083
|
-
} catch (e) {
|
|
2084
|
-
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(e, "warning");
|
|
2085
|
-
cookie_error = e;
|
|
2086
|
-
}
|
|
2087
|
-
(0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).withScope(function(scope) {
|
|
2088
|
-
scope.setExtra("id", id);
|
|
2089
|
-
scope.setExtra("ls_error", localstorage_error);
|
|
2090
|
-
scope.setExtra("cookie_error", cookie_error);
|
|
2091
|
-
scope.setLevel("error");
|
|
2092
|
-
this.captureMessage(`${id ? "localStorage" : "cookie and localStorage"} failed to hold a value!`);
|
|
2093
2146
|
});
|
|
2147
|
+
const link_sel = "a[href]";
|
|
2148
|
+
(0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(link_sel, relativ_callback);
|
|
2149
|
+
if (also_onchange) (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onchange(link_sel, relativ_callback);
|
|
2150
|
+
if (also_in_all_shadow_roots && typeof ShadowRoot == "function") (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists("*", (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(({ element: element })=>{
|
|
2151
|
+
if (element?.shadowRoot instanceof ShadowRoot) {
|
|
2152
|
+
const local_observer = new (0, $9043c64496e3375f$export$12e07a2a9f87578a)({
|
|
2153
|
+
territory: element.shadowRoot
|
|
2154
|
+
});
|
|
2155
|
+
local_observer.onexists(link_sel, relativ_callback);
|
|
2156
|
+
}
|
|
2157
|
+
}));
|
|
2094
2158
|
}
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
// Compatability mapping - TODO: refactor & remove
|
|
2119
|
-
tenant: vars?.TENANT,
|
|
2120
|
-
market: vars?.MARKET,
|
|
2121
|
-
entity_price: vars?.sale_price,
|
|
2122
|
-
...vars
|
|
2159
|
+
}
|
|
2160
|
+
function $bf7f12fe044e41b2$export$5e63aea0cac01fa0(elements, selector) {
|
|
2161
|
+
const matches = [];
|
|
2162
|
+
for (const element of elements){
|
|
2163
|
+
if ("querySelectorAll" in element) matches.push(...(0, $7599647868f98022$export$33f937d741e49339)(element, selector));
|
|
2164
|
+
if ("matches" in element && element.matches?.(selector)) matches.push(element);
|
|
2165
|
+
}
|
|
2166
|
+
return matches;
|
|
2167
|
+
}
|
|
2168
|
+
function $bf7f12fe044e41b2$export$cfef5d5c9ac09253(price, places_after_comma = 2, decimal_delimiter = ",", thousands_delimiter = String.fromCharCode(160) // Non-breaking space ( )
|
|
2169
|
+
) {
|
|
2170
|
+
if (!price && price !== 0) return "";
|
|
2171
|
+
if (typeof price === "string") {
|
|
2172
|
+
if (!isNaN(price)) {
|
|
2173
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(new Error("standard_price_format did not expect price as a string"), "warning", {
|
|
2174
|
+
price: price
|
|
2175
|
+
});
|
|
2176
|
+
price = parseFloat(price);
|
|
2177
|
+
} else {
|
|
2178
|
+
(0, $268cbd9e4ade92db$export$f18d5b0af29128b7)(new Error("standard_price_format cannot handle price string"), "error", {
|
|
2179
|
+
price: price
|
|
2180
|
+
});
|
|
2181
|
+
return "";
|
|
2123
2182
|
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
if (
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
);
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
);
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
if (
|
|
2143
|
-
return
|
|
2144
|
-
...vars,
|
|
2145
|
-
type: "add_to_cart"
|
|
2146
|
-
});
|
|
2147
|
-
});
|
|
2148
|
-
function $e0a87646d12cb987$export$622991c71a1f52b3(cookie_name) {
|
|
2149
|
-
// https://stackoverflow.com/a/25490531
|
|
2150
|
-
return document.cookie.match("(^|;)\\s*" + cookie_name + "\\s*=\\s*([^;]+)")?.pop() || "";
|
|
2183
|
+
}
|
|
2184
|
+
if (places_after_comma == "auto") places_after_comma = price % 1 ? 2 : 0;
|
|
2185
|
+
const fixed = places_after_comma < 0 ? price.toString().split(".") : price.toFixed(places_after_comma).split("."), [...chars] = fixed[0], reversed = chars.reverse();
|
|
2186
|
+
let j, reversed_formatted = [];
|
|
2187
|
+
for(let i = 0; i < reversed.length; i++)if (!(i % 3)) j = reversed_formatted.push([
|
|
2188
|
+
reversed[i]
|
|
2189
|
+
]) - 1;
|
|
2190
|
+
else reversed_formatted[j].push(reversed[i]);
|
|
2191
|
+
fixed[0] = reversed_formatted.map((v)=>v.reverse().join("")).reverse().join(thousands_delimiter);
|
|
2192
|
+
return fixed.join(decimal_delimiter);
|
|
2193
|
+
}
|
|
2194
|
+
function $bf7f12fe044e41b2$export$f124e3ee16e6b45d(bcp47_country_code, number, numberformat_options) {
|
|
2195
|
+
const numfmt = window?.Intl?.NumberFormat;
|
|
2196
|
+
if (numfmt) return new numfmt(bcp47_country_code, numberformat_options)?.format?.(number);
|
|
2197
|
+
return $bf7f12fe044e41b2$export$cfef5d5c9ac09253(number, "auto");
|
|
2198
|
+
}
|
|
2199
|
+
function $bf7f12fe044e41b2$export$9590700a594aef08(obj, step1, ...path) {
|
|
2200
|
+
if (typeof obj[step1] === "undefined") obj[step1] = {};
|
|
2201
|
+
if (path.length) return $bf7f12fe044e41b2$export$9590700a594aef08(obj[step1], ...path);
|
|
2202
|
+
else return obj[step1];
|
|
2151
2203
|
}
|
|
2152
2204
|
|
|
2153
2205
|
|
|
2154
2206
|
|
|
2155
2207
|
|
|
2208
|
+
|
|
2209
|
+
|
|
2210
|
+
|
|
2211
|
+
|
|
2156
2212
|
// https://stackoverflow.com/a/39941616
|
|
2157
2213
|
function $2fafbbbf345dcde0$var$invert_promise(promise) {
|
|
2158
2214
|
return new Promise((res, rej)=>promise.then(rej, res));
|
|
@@ -3335,11 +3391,12 @@ async function $94edfb6d9c42a288$export$1bc0df10745d5412(t, options, headers, ge
|
|
|
3335
3391
|
}
|
|
3336
3392
|
async function $94edfb6d9c42a288$export$d40679eb4cf32f09(t, options, headers, get_url = $94edfb6d9c42a288$var$default_get_fetch_url) {
|
|
3337
3393
|
const dsid = (0, $e0a87646d12cb987$export$6399bdb2291895e0)();
|
|
3338
|
-
const session_id = (0, $e0a87646d12cb987$export$61e7e1f11e96692f)();
|
|
3394
|
+
const session_id = options.session_id || (0, $e0a87646d12cb987$export$61e7e1f11e96692f)();
|
|
3395
|
+
const user_id = options.user_id || dsid;
|
|
3339
3396
|
const body = {
|
|
3340
3397
|
tenant: t.tenant,
|
|
3341
3398
|
market: t.market,
|
|
3342
|
-
user_id:
|
|
3399
|
+
user_id: user_id,
|
|
3343
3400
|
session_id: session_id,
|
|
3344
3401
|
dsid: dsid,
|
|
3345
3402
|
document_referrer: document.referrer,
|
|
@@ -7614,14 +7671,6 @@ async function $fac9c96b6bbe43cd$export$2dd69958012e3e49({ override_rec_renderer
|
|
|
7614
7671
|
|
|
7615
7672
|
|
|
7616
7673
|
|
|
7617
|
-
function $13a446968e3581c0$export$c50e1901e8ed0615(callback) {
|
|
7618
|
-
// https://stackoverflow.com/a/61574326
|
|
7619
|
-
const channel = new MessageChannel();
|
|
7620
|
-
channel.port1.onmessage = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9)(callback);
|
|
7621
|
-
channel.port2.postMessage("");
|
|
7622
|
-
}
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
7674
|
|
|
7626
7675
|
|
|
7627
7676
|
|