@depict-ai/utilishared 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/latest/index.cjs CHANGED
@@ -1,20 +1,6 @@
1
1
  var $z0IcO$solidjs = require("solid-js");
2
2
  var $z0IcO$solidjsweb = require("solid-js/web");
3
3
  require("../multi_import_deduplicator.cjs").register_es_version("utilishared", "latest");
4
- function $parcel$exportWildcard(dest, source) {
5
- Object.keys(source).forEach(function (key) {
6
- if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
7
- return;
8
- }
9
- Object.defineProperty(dest, key, {
10
- enumerable: true,
11
- get: function get() {
12
- return source[key];
13
- }
14
- });
15
- });
16
- return dest;
17
- }
18
4
  function $parcel$export(e, n, v, s) {
19
5
  Object.defineProperty(e, n, {
20
6
  get: v,
@@ -37,21 +23,10 @@ $parcel$export(module.exports, "cache_args", () => $ee1d22bd1fcdd4e1$export$6e74
37
23
  $parcel$export(module.exports, "check_displays", () => $eee5951374097b61$export$8582cf3716962dc2);
38
24
  $parcel$export(module.exports, "err", () => $548fd58b14b25a52$export$8048b892d651b310);
39
25
  $parcel$export(module.exports, "require_event_listener", () => $546052c2e3608435$export$16d7c76794a38a4);
40
- $parcel$export(module.exports, "Auto_GWVM", () => $d1ef5fbddf08305d$export$41de2959a8dd405d);
41
- $parcel$export(module.exports, "GWVM_Renderer", () => $e5479d0db39d328b$export$c83d8da642b5104a);
42
26
  $parcel$export(module.exports, "infinite_promise_creator", () => $7198207999c01453$export$55621c1ce3cd536b);
43
27
  $parcel$export(module.exports, "infinite_promise_no_skip", () => $04a37742898e4bd5$export$32ccf3a614c84258);
44
- $parcel$export(module.exports, "infinite_renderer", () => $55dae85e9309db86$export$c0a4d29bc45a38c6);
45
- $parcel$export(module.exports, "deprecated_insert_styling", () => $8686e45614d71607$export$9eae832ae57fbf);
46
28
  $parcel$export(module.exports, "placeholder", () => $807b852d8decb547$export$c7187bbd1a7a9244);
47
- $parcel$export(module.exports, "Pro_Slider", () => $3cb558cec98ba1a7$export$cab8bc58c64c2013);
48
- $parcel$export(module.exports, "simplified_template_tool", () => $52d3be7ce5146924$export$2e2bcd8739ae039);
49
29
  $parcel$export(module.exports, "insert_styling_into_slider", () => $e090b20cef3f0516$export$f1b8b9fd75ddcab1);
50
- $parcel$export(module.exports, "RR_Slider", () => $7af744346f17bf99$export$cd12721587f4f16d);
51
- $parcel$export(module.exports, "Depict", () => $0b6a8303b64cced1$export$1a8782481a9af507);
52
- $parcel$export(module.exports, "get_recs_with_template", () => $66a2a93dfa520bc6$export$30933c637c977eef);
53
- $parcel$export(module.exports, "default_post_processor", () => $66a2a93dfa520bc6$export$c410ce1205e5118a);
54
- $parcel$export(module.exports, "default_pre_processor", () => $66a2a93dfa520bc6$export$4f39078bdc72ecd0);
55
30
  $parcel$export(module.exports, "wpff", () => $c413c7798924612a$export$2e2bcd8739ae039);
56
31
  $parcel$export(module.exports, "ElementObserver", () => $9043c64496e3375f$export$12e07a2a9f87578a);
57
32
  $parcel$export(module.exports, "observer", () => $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149);
@@ -76,28 +51,11 @@ $parcel$export(module.exports, "test_array_proxy_support", () => $1da560af170fb8
76
51
  $parcel$export(module.exports, "Amazing_Slider", () => $1683d0164abd7c1d$export$692b27c28639e5b9);
77
52
  $parcel$export(module.exports, "colorize_elements", () => $f3f05d97149aec76$export$16501883f477737a);
78
53
  $parcel$export(module.exports, "should_colorizeLogics", () => $f3f05d97149aec76$export$deca40f48c0569f8);
79
- $parcel$export(module.exports, "default_rr", () => $92bde32714bb1e07$export$50ce83ace0cdd87e);
80
- $parcel$export(module.exports, "fetch_recs", () => $94edfb6d9c42a288$export$1bc0df10745d5412);
81
- $parcel$export(module.exports, "fetch_recs_whole_response", () => $94edfb6d9c42a288$export$d40679eb4cf32f09);
82
- $parcel$export(module.exports, "clone_deep", () => $558ccd2de887e6d9$export$c42139a43c877ecd);
83
- $parcel$export(module.exports, "regex_templating", () => $558ccd2de887e6d9$export$e0009e7da572f99b);
84
- $parcel$export(module.exports, "Rec_Renderer", () => $558ccd2de887e6d9$export$a9fc160c5ed83bd7);
85
54
  $parcel$export(module.exports, "n_col_styling_with_dist", () => $1cc2444a0f1b992e$export$17c3166a7ebd4688);
86
55
  $parcel$export(module.exports, "Layout", () => $1cc2444a0f1b992e$export$c84671f46d6a1ca);
87
56
  $parcel$export(module.exports, "layout_get_visible_recs_without_partial_rows", () => $1cc2444a0f1b992e$export$483bdd1f1186de13);
88
57
  $parcel$export(module.exports, "layout_get_total_rec_amount_for_row", () => $1cc2444a0f1b992e$export$3dc5e2383c924ebf);
89
58
  $parcel$export(module.exports, "layout_media_query_header", () => $1cc2444a0f1b992e$export$717f13d9ba00ca19);
90
- $parcel$export(module.exports, "RecommendationGrid", () => $a7315720bf2a1638$export$b0a773486c1c2312);
91
- $parcel$export(module.exports, "RecommendationSlider", () => $79804e8d76404ae4$export$82cfdc85a4d15688);
92
- $parcel$export(module.exports, "default_click_tracking", () => $04d2f7d9126af667$export$6830ae1fbe21e589);
93
- $parcel$export(module.exports, "default_view_tracking", () => $04d2f7d9126af667$export$f37c58ab3d3e3b75);
94
- $parcel$export(module.exports, "ga_click", () => $04d2f7d9126af667$export$dd32cb565eae0a1f);
95
- $parcel$export(module.exports, "gtag_click_post_processor", () => $04d2f7d9126af667$export$8d72437623fef90c);
96
- $parcel$export(module.exports, "gtag_view_post_processor", () => $04d2f7d9126af667$export$1bffac19f9f0d6fc);
97
- $parcel$export(module.exports, "depict_click_tracking_post_processor", () => $04d2f7d9126af667$export$e9106d6e723510d2);
98
- $parcel$export(module.exports, "recs_inserted_tracking", () => $04d2f7d9126af667$export$fb9afe9f540ae069);
99
- $parcel$export(module.exports, "add_to_localstorage", () => $04d2f7d9126af667$export$32eb5dd18e963410);
100
- $parcel$export(module.exports, "depict_page_view", () => $04d2f7d9126af667$export$9e1caada6901f552);
101
59
  $parcel$export(module.exports, "slider_autoscroll_factory", () => $535c6ee2337e2717$export$8cbd8aa1c70f9a13);
102
60
  $parcel$export(module.exports, "make_button1", () => $a8a0385b88626561$export$80039a49055269fb);
103
61
  $parcel$export(module.exports, "make_button2", () => $edc9fe0b09e00df6$export$af88b4929c2dc86);
@@ -111,12 +69,9 @@ $parcel$export(module.exports, "slider_snap_css", () => $6af20338fcad1911$export
111
69
  $parcel$export(module.exports, "can_use_snapping_and_still_scroll", () => $6af20338fcad1911$export$49b950309ab787ad);
112
70
  $parcel$export(module.exports, "slider_snapping_factory", () => $379066823f8eeb0b$export$dac64fd35a4805a4);
113
71
  $parcel$export(module.exports, "Amazing_Lazy_Slider", () => $a69a5236b5814082$export$68babfc5be0de5da);
114
- $parcel$export(module.exports, "slider_wraparound_factory", () => $3d8df0a23b9bebac$export$53306504b987cbf7);
115
72
  $parcel$export(module.exports, "sizes_to_surface", () => $bf76a92ec2055e1a$export$419f84efad7d9fe);
116
73
  $parcel$export(module.exports, "surface_mixer", () => $bf76a92ec2055e1a$export$417ef0ab13d8b984);
117
74
  $parcel$export(module.exports, "promise_until_next_navigation", () => $bf76a92ec2055e1a$export$be95cb0e8cfd099e);
118
- $parcel$export(module.exports, "AIO", () => $fbb09973782881cb$export$29a6094e0bd8bc5f);
119
- $parcel$export(module.exports, "paint_red", () => $fbb09973782881cb$export$6ebd242c09192cec);
120
75
  $parcel$export(module.exports, "bind_to_a2c_button", () => $c8263a2185830bf1$export$2c34560c3749dc63);
121
76
  $parcel$export(module.exports, "bind_tracking_to_link", () => $c8263a2185830bf1$export$82a685f2da2fb027);
122
77
  $parcel$export(module.exports, "depict_click", () => $e0a87646d12cb987$export$15f8a0cd5a8c0ebb);
@@ -133,15 +88,6 @@ $parcel$export(module.exports, "send_depict_unfiltered", () => $0c84f8e99aac5765
133
88
  $parcel$export(module.exports, "send_websocket", () => $0c84f8e99aac5765$export$aa26019042811d4f);
134
89
  $parcel$export(module.exports, "create_ga_queue", () => $c18ce8dadd041cdd$export$674d8cd8b6868154);
135
90
  $parcel$export(module.exports, "make_tracker_send_to_depict", () => $c18ce8dadd041cdd$export$edfedd0557ca5a2d);
136
- $parcel$export(module.exports, "ga_to_transaction_api", () => $5a44db2d2c8361b9$export$1ff14fec60ed5697);
137
- $parcel$export(module.exports, "send_ga", () => $d3d8549954e0318e$export$f75172d2e289cd02);
138
- $parcel$export(module.exports, "setup_ga", () => $d3d8549954e0318e$export$ac7296527cb52311);
139
- $parcel$export(module.exports, "setup_gtag", () => $d3d8549954e0318e$export$d031e55ccd4c52dc);
140
- $parcel$export(module.exports, "gtag_click", () => $d3d8549954e0318e$export$f522672c9379e339);
141
- $parcel$export(module.exports, "ga_purchase_click", () => $d3d8549954e0318e$export$bf205937e5e012cb);
142
- $parcel$export(module.exports, "ga_rec_click", () => $d3d8549954e0318e$export$127751e82111fcf);
143
- $parcel$export(module.exports, "gtag_view", () => $d3d8549954e0318e$export$7babcd5d4056b2ca);
144
- $parcel$export(module.exports, "load_gtag", () => $d3d8549954e0318e$export$f3354ec2ce95ebd9);
145
91
  $parcel$export(module.exports, "send_impression_event", () => $dd025eb6f77f8f8b$export$4205dc6835bc0d9f);
146
92
  $parcel$export(module.exports, "impression_track_element", () => $8e19f8200d357fe7$export$37125ccc5dd98050);
147
93
  $parcel$export(module.exports, "impression_tracking_post_processor", () => $11ff7b46c1fb674c$export$d0efd8ed14f5c33);
@@ -151,15 +97,6 @@ $parcel$export(module.exports, "has_to_be_intersecting_for", () => $dd025eb6f77f
151
97
  $parcel$export(module.exports, "add_new_tab_listener", () => $44909e19109bf973$export$58c56fe2313fdbe3);
152
98
  $parcel$export(module.exports, "broadcast_product_id", () => $44909e19109bf973$export$836f70a28c317905);
153
99
  $parcel$export(module.exports, "contextmenu_callback", () => $44909e19109bf973$export$8f66c4c7fb96eda2);
154
- $parcel$export(module.exports, "optanon_get_cookie_ipns", () => $2026711c6c2d6204$export$7e4427e80d5fc619);
155
- $parcel$export(module.exports, "init_optanon_tracking", () => $2026711c6c2d6204$export$f0f6c846d96fdbec);
156
- $parcel$export(module.exports, "optanon_get_consent", () => $2026711c6c2d6204$export$1dd9ce50e201eff1);
157
- $parcel$export(module.exports, "optanon_wait_for_consent", () => $2026711c6c2d6204$export$7a6d436e0782c6ed);
158
- $parcel$export(module.exports, "send_transaction_id_to_depict", () => $0c9d834f187cc4ff$export$1ac466d53a6636ac);
159
- $parcel$export(module.exports, "datalayer_interceptor", () => $0c9d834f187cc4ff$export$9ed4fbc47d558f94);
160
- $parcel$export(module.exports, "datalayer_transaction_id_extractor", () => $0c9d834f187cc4ff$export$b11248fa13a8a86c);
161
- $parcel$export(module.exports, "orderpage_transaction_id_extractor", () => $0c9d834f187cc4ff$export$3ebd86018b39d9d2);
162
- $parcel$export(module.exports, "url_transaction_id_extractor", () => $0c9d834f187cc4ff$export$ff8673d5dea82bd4);
163
100
  $parcel$export(module.exports, "send_page_view_if_needed", () => $72ee205b59322497$export$eee4c4d924348b05);
164
101
  $parcel$export(module.exports, "send_page_view_on_navigation", () => $72ee205b59322497$export$f7cb1bd47199ec38);
165
102
  $parcel$export(module.exports, "DepictAPIWS", () => $d10801050840d92b$export$1d9c6fddbff3441f);
@@ -187,7 +124,6 @@ $parcel$export(module.exports, "intercept", () => $23d6393391c08860$export$ab0f8
187
124
  $parcel$export(module.exports, "fetch_replacer", () => $7ccebf01cfe4f824$export$85be83e1935d93c2);
188
125
  $parcel$export(module.exports, "FakeResponse", () => $7ccebf01cfe4f824$export$f8da66bc4f1d059e);
189
126
  $parcel$export(module.exports, "fetch_retry", () => $d2fc3fb450961938$export$bcd70d5ed1cf6313);
190
- $parcel$export(module.exports, "get_optimize_variant", () => $40f3ad8d5c440ce9$export$b404e20f3c4a490e);
191
127
  $parcel$export(module.exports, "stateless_href_change_ipns", () => $69f7524c8bdd85b4$export$20e9533e68ee72e7);
192
128
  $parcel$export(module.exports, "href_change_ipns", () => $69f7524c8bdd85b4$export$a9d39e43ae273d26);
193
129
  $parcel$export(module.exports, "history_replacer", () => $69f7524c8bdd85b4$export$baccefee4a395d8f);
@@ -209,12 +145,8 @@ $parcel$export(module.exports, "insert_styling", () => $e4bebbfa0f0b1454$export$
209
145
  $parcel$export(module.exports, "depict_init", () => $e4bebbfa0f0b1454$export$692b606677218a16);
210
146
  $parcel$export(module.exports, "depict_init_with_market_logic", () => $e4bebbfa0f0b1454$export$328e81c44cddf3c0);
211
147
  $parcel$export(module.exports, "normal_get_product_id", () => $e4bebbfa0f0b1454$export$a4f97b27a0592e6c);
212
- $parcel$export(module.exports, "track_a2c", () => $e4bebbfa0f0b1454$export$a96c18473f2af463);
213
148
  $parcel$export(module.exports, "javascript_media_query", () => $93c499898a1702c7$export$515c3ea4d599b05a);
214
149
  $parcel$export(module.exports, "patched_querySelectorAll", () => $7599647868f98022$export$33f937d741e49339);
215
- $parcel$export(module.exports, "placeholder_svg", () => $fac9c96b6bbe43cd$export$a4eccf92efefa04d);
216
- $parcel$export(module.exports, "make_placeholder_rr", () => $fac9c96b6bbe43cd$export$2dd69958012e3e49);
217
- $parcel$export(module.exports, "random_text_placeholder", () => $fac9c96b6bbe43cd$export$3b75288f46cadd96);
218
150
  $parcel$export(module.exports, "Promise_Any", () => $2fafbbbf345dcde0$export$947a20746936143d);
219
151
  $parcel$export(module.exports, "queueMacroTask", () => $13a446968e3581c0$export$c50e1901e8ed0615);
220
152
  $parcel$export(module.exports, "rand", () => $3f34dc07544c5857$export$bb0a9c36cf454ea0);
@@ -232,7 +164,6 @@ $parcel$export(module.exports, "serialize_object", () => $45e05ec4fd7f1ee7$expor
232
164
  $parcel$export(module.exports, "sort_obj", () => $24daf6f6e6529b9f$export$12b4c6cbc6b8b4e4);
233
165
  $parcel$export(module.exports, "standard_get_market", () => $02a3425594231893$export$a422d714c8cb1a5d);
234
166
  $parcel$export(module.exports, "listenToLocalStorage", () => $05802e6cb0fdbdcd$export$3427ec8268623f1);
235
- $parcel$export(module.exports, "Tenant", () => $16f3a26cfac77a4c$export$8d42ce4827f43582);
236
167
  $parcel$export(module.exports, "timeout_promise", () => $9ed7c4b0fbf9ccd8$export$cd1adfb8059b5fcd);
237
168
  $parcel$export(module.exports, "variable_setter_to_ipns", () => $e6d67ef355abb2dc$export$79f910a98828378d);
238
169
  $parcel$export(module.exports, "find_descriptor", () => $e6d67ef355abb2dc$export$d5062f468a0454f3);
@@ -273,7 +204,7 @@ $parcel$export(module.exports, "version", () => $815f67c61b4c0a42$export$83d89fb
273
204
  $parcel$export(module.exports, "add_to_version_info", () => $e4a18bf12ad092d9$export$2cefb7e61fcbae00);
274
205
  $parcel$export(module.exports, "sync_el_content_with_accessor", () => $35303d72263038db$export$c3f56a35e076f139);
275
206
  $parcel$export(module.exports, "use_href_accessor", () => $da35c7e27be2a442$export$e35115e6d0715f77);
276
- const $815f67c61b4c0a42$export$83d89fbfd8236492 = "2.2.0";
207
+ const $815f67c61b4c0a42$export$83d89fbfd8236492 = "2.3.0";
277
208
  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"))();
278
209
  const $e6c6e7929ea385ae$var$browser_prefix_styling = "color: #fff;";
279
210
  let $e6c6e7929ea385ae$var$browser_prefix = "[Depict]";
@@ -1394,39 +1325,85 @@ function $546052c2e3608435$export$16d7c76794a38a4(element, event, track_id, func
1394
1325
  }
1395
1326
  }
1396
1327
 
1397
- // @ts-nocheck
1398
-
1399
- const $7599647868f98022$var$needs_patching = typeof window === "object" ? /*@__PURE__*/$7599647868f98022$var$check_if_querySelectorAll_needs_patching() : false;
1400
- function $7599647868f98022$export$33f937d741e49339(element, selector) {
1401
- if (!(element instanceof Element) || !$7599647868f98022$var$needs_patching || !selector.includes("#") || !selector.includes("+"))
1402
- // covers most cases, we don't need patching or don't hit the bug
1403
- return element?.querySelectorAll?.(selector);
1404
- const result = [];
1405
- const elements_to_check = [];
1406
- // intentionally not recursive since it's possible to have deeper nested elements than max stack size
1407
- for (let i = element.children.length; i--;) elements_to_check.push(element.children[i]);
1408
- while (elements_to_check.length) {
1409
- const child_element = elements_to_check.pop();
1410
- if (child_element.matches(selector)) result.push(child_element);
1411
- for (let i = child_element.children.length; i--;)
1412
- // kudos to Karl for algorithm help
1413
- elements_to_check.push(child_element.children[i]);
1414
- }
1415
- return result;
1328
+ /**
1329
+ * @deprecated use async_iterable_ipns instead. This can skip values which yields unexpected results.
1330
+ */
1331
+ function $7198207999c01453$export$55621c1ce3cd536b() {
1332
+ // the idea is to have a new promise available immediately before one resolves, so to say an infinite promise
1333
+ let internal_resolve; // copy and pasted from iconbeauty
1334
+ const cart_promise_object = {
1335
+ // I feel like Anton is not going to like this extremely awesome approach
1336
+ promise: new Promise(r => internal_resolve = r),
1337
+ // which is why I'm reluctant with making it a library
1338
+ internal_resolve: internal_resolve,
1339
+ // Edit from later on: I have realised that this is actually very useful, it just has a steep learning curve.
1340
+ resolve: argument => {
1341
+ // it allows both not having to call functions in a loop and instead just awaiting the promise from multiple places
1342
+ const oldresolve = cart_promise_object.internal_resolve; // and to effortlessly ensure a process is never running twice with 100% reliability
1343
+ cart_promise_object.promise = new Promise(r => cart_promise_object.internal_resolve = r); // it could be made a class, but I already know this works, so I'll leave it as is
1344
+ oldresolve(argument);
1345
+ }
1346
+ };
1347
+ return cart_promise_object;
1416
1348
  }
1417
- function $7599647868f98022$var$check_if_querySelectorAll_needs_patching() {
1418
- const id_div = document.createElement("div");
1419
- const element = document.createElement("section");
1420
- const selector = "#a+*";
1421
- id_div.id = "a";
1422
- document.documentElement.append(id_div, element);
1423
- try {
1424
- return element === element.querySelectorAll(selector)[0];
1425
- } finally {
1426
- id_div.remove();
1427
- element.remove();
1349
+ function $807b852d8decb547$export$c7187bbd1a7a9244(...args) {
1350
+ $807b852d8decb547$var$placeholder_worker(...args).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
1351
+ return args[0];
1352
+ }
1353
+ async function $807b852d8decb547$var$placeholder_worker(placeholder_elements, final_elements, switching_trigger) {
1354
+ let state = false;
1355
+ let has_sanitized_elements = false;
1356
+ const sanit_el_if_needed = async () => {
1357
+ if (!has_sanitized_elements) {
1358
+ has_sanitized_elements = true;
1359
+ placeholder_elements = await $807b852d8decb547$var$convert_to_node_array(placeholder_elements);
1360
+ final_elements = await $807b852d8decb547$var$convert_to_node_array(final_elements);
1361
+ }
1362
+ };
1363
+ if (switching_trigger instanceof (0, $04a37742898e4bd5$export$32ccf3a614c84258)) while (true) {
1364
+ const new_state = await switching_trigger.promise;
1365
+ if (new_state != state) {
1366
+ await sanit_el_if_needed();
1367
+ await $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, new_state);
1368
+ state = new_state;
1369
+ }
1370
+ } else if (switching_trigger instanceof Promise) {
1371
+ const new_state = await switching_trigger;
1372
+ if (state != new_state) {
1373
+ await sanit_el_if_needed();
1374
+ await $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, new_state);
1375
+ state = new_state;
1376
+ }
1377
+ } else {
1378
+ await sanit_el_if_needed();
1379
+ placeholder_elements[0].addEventListener("placeholder_switch", $41f528c04cc8a8da$export$535946eb77c946dd(async e => {
1380
+ const new_state = e.detail.state;
1381
+ if (state != new_state) {
1382
+ await sanit_el_if_needed();
1383
+ await $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, new_state);
1384
+ state = new_state;
1385
+ }
1386
+ }));
1428
1387
  }
1429
1388
  }
1389
+ async function $807b852d8decb547$var$convert_to_node_array(elements) {
1390
+ if (typeof elements == "function") elements = elements();
1391
+ elements = await elements;
1392
+ if (typeof elements[Symbol.iterator] != "function") elements = [elements];
1393
+ return elements;
1394
+ }
1395
+ async function $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, switch_to_final) {
1396
+ if (switch_to_final) $807b852d8decb547$var$switch_elements(placeholder_elements, final_elements);else $807b852d8decb547$var$switch_elements(final_elements, placeholder_elements);
1397
+ }
1398
+ function $807b852d8decb547$var$switch_elements(from, to) {
1399
+ if (!from.length || !to.length) $e6c6e7929ea385ae$export$c2363754d4758444("Cannot switch elements as from or to is empty", from, to);
1400
+ from[0].replaceWith(...to);
1401
+ for (let i = 1; i < from.length; i++) from[i].remove();
1402
+ }
1403
+
1404
+ // @ts-ignore
1405
+ var $1c4a3b6d660e3905$exports = {};
1406
+ $1c4a3b6d660e3905$exports = ".depict .rec_outer.noautospacing {\n width: 6cm;\n max-width: 46vw;\n margin-left: 1%;\n margin-right: 1%;\n}\n\n.depict .rec_outer.noautospacing:nth-child(1) {\n margin-left: 0;\n}\n\n.depict .rec_outer.noautospacing:nth-last-child(1) {\n margin-right: 0;\n}\n\n.depict-slider .slider_snap {\n scroll-snap-type: x mandatory;\n}\n\n.depict-slider {\n width: 100%;\n position: relative;\n}\n\n.depict-slider .sliding::-webkit-scrollbar {\n display: none;\n}\n\n.depict-slider .sliding {\n scroll-behavior: smooth;\n -ms-overflow-style: none;\n scrollbar-width: none;\n flex-flow: row;\n margin-top: -1%;\n margin-bottom: -2%;\n padding-top: 1%;\n padding-bottom: 2%;\n display: flex;\n overflow-x: scroll;\n}\n\n.depict-slider .sliding > * {\n box-sizing: border-box;\n flex: none;\n}\n\n.depict-slider button.right {\n right: 0;\n}\n\n.depict-slider button.left, .depict-slider button.right {\n z-index: 2;\n touch-action: manipulation;\n width: 1cm;\n height: 1cm;\n cursor: pointer;\n background: #fff;\n border: none;\n padding: .5%;\n transition-duration: .2s;\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n}\n\n.depict-slider button.left.hidden, .depict-slider button.right.hidden {\n opacity: 0;\n cursor: default;\n}\n\n.depict-slider button.left {\n left: 0;\n transform: translateY(-50%)rotate(180deg);\n}\n\n.depict-slider button.left img, .depict-slider button.right img {\n width: 100%;\n height: 100%;\n}\n\n.depict-slider .rec_outer {\n margin-top: 0 !important;\n}\n\n";
1430
1407
  let $55595fc7bb226f61$var$has_queued_microtask = false;
1431
1408
  const $55595fc7bb226f61$var$queued_callbacks = /*@__PURE__*/new Map();
1432
1409
  const $55595fc7bb226f61$var$catchified_deduplicate_and_dispatch = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9($55595fc7bb226f61$var$deduplicate_and_dispatch, "error in observer event processing", "error");
@@ -1485,6 +1462,37 @@ class $e2f46d4f382caff1$export$ea60432919e69303 {
1485
1462
  opts.event_ && (this.event = opts.event_);
1486
1463
  }
1487
1464
  }
1465
+ const $7599647868f98022$var$needs_patching = typeof window === "object" ? /*@__PURE__*/$7599647868f98022$var$check_if_querySelectorAll_needs_patching() : false;
1466
+ function $7599647868f98022$export$33f937d741e49339(element, selector) {
1467
+ if (!(element instanceof Element) || !$7599647868f98022$var$needs_patching || !selector.includes("#") || !selector.includes("+"))
1468
+ // covers most cases, we don't need patching or don't hit the bug
1469
+ return element?.querySelectorAll?.(selector);
1470
+ const result = [];
1471
+ const elements_to_check = [];
1472
+ // intentionally not recursive since it's possible to have deeper nested elements than max stack size
1473
+ for (let i = element.children.length; i--;) elements_to_check.push(element.children[i]);
1474
+ while (elements_to_check.length) {
1475
+ const child_element = elements_to_check.pop();
1476
+ if (child_element.matches(selector)) result.push(child_element);
1477
+ for (let i = child_element.children.length; i--;)
1478
+ // kudos to Karl for algorithm help
1479
+ elements_to_check.push(child_element.children[i]);
1480
+ }
1481
+ return result;
1482
+ }
1483
+ function $7599647868f98022$var$check_if_querySelectorAll_needs_patching() {
1484
+ const id_div = document.createElement("div");
1485
+ const element = document.createElement("section");
1486
+ const selector = "#a+*";
1487
+ id_div.id = "a";
1488
+ document.documentElement.append(id_div, element);
1489
+ try {
1490
+ return element === element.querySelectorAll(selector)[0];
1491
+ } finally {
1492
+ id_div.remove();
1493
+ element.remove();
1494
+ }
1495
+ }
1488
1496
  class $9043c64496e3375f$export$12e07a2a9f87578a {
1489
1497
  #the_mutation_observer;
1490
1498
  #observing = {};
@@ -1982,6 +1990,21 @@ function $2a1cbc63a04d4a2d$var$make_default_observer() {
1982
1990
  $268cbd9e4ade92db$export$f18d5b0af29128b7([error, "error starting ElementObserver"], "error");
1983
1991
  }
1984
1992
  }
1993
+
1994
+ /**
1995
+ * Useful for the `thresholds` option of IntersectionObserver - if you want to be notified at a 10% change, call this and set num_steps to 10. Pls see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds
1996
+ * @param numSteps How many steps (notifications) there should be between 0 and 100% intersection
1997
+ * @return Stuff to give to IntersectionObserver
1998
+ */
1999
+ function $0da0cad4f39e8f32$export$f8ea2e7b15b5d129(numSteps) {
2000
+ const thresholds = [];
2001
+ for (let i = 1.0; i <= numSteps; i++) {
2002
+ const ratio = i / numSteps;
2003
+ thresholds.push(ratio);
2004
+ }
2005
+ thresholds.push(0);
2006
+ return thresholds;
2007
+ }
1985
2008
  function $bf7f12fe044e41b2$export$925772df9b4d16e5(url, param, value) {
1986
2009
  const url_object = new URL(url),
1987
2010
  search_params = new URLSearchParams(url_object.search);
@@ -2078,1794 +2101,97 @@ function $bf7f12fe044e41b2$export$9590700a594aef08(obj, step1, ...path) {
2078
2101
  if (typeof obj[step1] === "undefined") obj[step1] = {};
2079
2102
  if (path.length) return $bf7f12fe044e41b2$export$9590700a594aef08(obj[step1], ...path);else return obj[step1];
2080
2103
  }
2081
-
2082
- // https://stackoverflow.com/a/39941616
2083
- function $2fafbbbf345dcde0$var$invert_promise(promise) {
2084
- return new Promise((res, rej) => promise.then(rej, res));
2085
- }
2086
- function $2fafbbbf345dcde0$export$947a20746936143d(promises) {
2087
- return Promise?.any?.(promises) ?? $2fafbbbf345dcde0$var$invert_promise(Promise.all([...promises].map($2fafbbbf345dcde0$var$invert_promise)));
2088
- }
2089
- async function $44909e19109bf973$export$836f70a28c317905(product_id) {
2090
- if (typeof BroadcastChannel != "function") return;
2091
- const bc = new BroadcastChannel("right_click_attribution");
2092
- $e6c6e7929ea385ae$export$de56f1198d121036("Broadcasting", product_id, "to", bc);
2093
- bc.postMessage(product_id);
2094
- bc.close();
2095
- }
2096
- function $44909e19109bf973$export$58c56fe2313fdbe3(elements, display, info, get_event_listener_remover) {
2097
- if (typeof BroadcastChannel != "function") return elements;
2098
- const disconnectors = [];
2099
- const handler = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => $44909e19109bf973$export$8f66c4c7fb96eda2(e, ("variant_index" in display ? display.variant_displays[display.variant_index] : display).product_id));
2100
- const auxclick_handler = e => e.button === 1 && handler(e);
2101
- for (let i = 0; i < elements?.length; i++) {
2102
- const element = elements[i];
2103
- element.addEventListener("contextmenu", handler);
2104
- element.addEventListener("auxclick", auxclick_handler); // actual wheel click - some mouses / OS:es also dispatch auxclick on rightclick
2105
- if (get_event_listener_remover) disconnectors.push(() => {
2106
- element.removeEventListener("contextmenu", handler);
2107
- element.removeEventListener("auxclick", auxclick_handler);
2108
- });
2109
- }
2110
- get_event_listener_remover?.(() => disconnectors.forEach(disconnector => disconnector()));
2111
- return elements;
2112
- }
2113
- async function $44909e19109bf973$export$8f66c4c7fb96eda2(e, product_id) {
2114
- $e6c6e7929ea385ae$export$de56f1198d121036("Contextmenu was invoked", e);
2115
- const element = e.currentTarget || e.target;
2116
- const bc = new BroadcastChannel("right_click_attribution");
2117
- const got_wanted_event = await $2fafbbbf345dcde0$export$947a20746936143d([new Promise(resolve => {
2118
- bc.addEventListener("message", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(msg => {
2119
- const {
2120
- data: data
2121
- } = msg;
2122
- $e6c6e7929ea385ae$export$de56f1198d121036("Recieved broadcast channel event", data, msg);
2123
- if (data == product_id) resolve(true);
2124
- }));
2125
- }), new Promise(r => setTimeout(r, 60000, false))]);
2126
- if (got_wanted_event) {
2127
- const click = new MouseEvent("click", {
2128
- view: window,
2129
- bubbles: true,
2130
- cancelable: true,
2131
- metaKey: true
2132
- });
2133
- $e6c6e7929ea385ae$export$de56f1198d121036("Someone broadcasted our product_id! Simulating a click event on the element that was contextmenu'd", element, click);
2134
- element.addEventListener("click", e => (e.preventDefault(), false), {
2135
- once: true
2136
- });
2137
- element.dispatchEvent(click);
2138
- } else $e6c6e7929ea385ae$export$de56f1198d121036("Our product_id did not get broadcasted, closing channel");
2139
- bc.close();
2140
- }
2141
-
2142
- /**
2143
- * Useful for the `thresholds` option of IntersectionObserver - if you want to be notified at a 10% change, call this and set num_steps to 10. Pls see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds
2144
- * @param numSteps How many steps (notifications) there should be between 0 and 100% intersection
2145
- * @return Stuff to give to IntersectionObserver
2146
- */
2147
- function $0da0cad4f39e8f32$export$f8ea2e7b15b5d129(numSteps) {
2148
- const thresholds = [];
2149
- for (let i = 1.0; i <= numSteps; i++) {
2150
- const ratio = i / numSteps;
2151
- thresholds.push(ratio);
2152
- }
2153
- thresholds.push(0);
2154
- return thresholds;
2155
- }
2156
-
2157
- /**
2158
- * Elements currently intersecting with the viewport.
2159
- * If they are intersecting for the `has_to_be_intersecting_for` duration, we count it as an impression, and call the callback.
2160
- */
2161
- const $72ed530554068e4f$var$current_intersections = /*@__PURE__*/new WeakMap();
2162
- /**
2163
- * Currently watched elements by the intersection observer with their respective callback
2164
- * */
2165
- const $72ed530554068e4f$var$watched_elements = /*@__PURE__*/new WeakMap();
2166
- const $72ed530554068e4f$var$unwatch_element = element => {
2167
- $72ed530554068e4f$var$intersection_observer?.unobserve(element);
2168
- $72ed530554068e4f$var$watched_elements.delete(element);
2169
- $72ed530554068e4f$var$current_intersections.delete(element);
2170
- };
2171
- const $72ed530554068e4f$export$4c51576248bcdf31 = (element, callback) => {
2172
- if ($72ed530554068e4f$var$watched_elements.has(element)) {
2173
- $e6c6e7929ea385ae$export$de56f1198d121036("Not watching", element, "as it's already being watched");
2174
- return () => {};
2175
- }
2176
- $72ed530554068e4f$var$intersection_observer?.observe(element);
2177
- /** Calls the given callback and makes sure to stop watching the element */
2178
- const wrapped_callback = element => {
2179
- callback(element);
2180
- $72ed530554068e4f$var$unwatch_element(element);
2181
- };
2182
- $72ed530554068e4f$var$watched_elements.set(element, wrapped_callback);
2183
- const disconnect_observer = (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onremoved(element, () => {
2184
- // Sometimes it has already rapidly been reinserted. The observer events lag by one tick.
2185
- // For that case, make sure we're really out of the DOM
2186
- if (document.documentElement.contains(element)) return;
2187
- $72ed530554068e4f$var$unwatch_element(element);
2188
- });
2189
- return () => {
2190
- disconnect_observer();
2191
- $72ed530554068e4f$var$unwatch_element(element);
2192
- };
2193
- };
2194
- const $72ed530554068e4f$var$intersection_observer_callback = entries => {
2195
- for (const record of entries) {
2196
- const {
2197
- target: target
2198
- } = record;
2199
- const callback = $72ed530554068e4f$var$watched_elements.get(target);
2200
- // Skip the element if it's no longer being watched.
2201
- if (!callback) {
2202
- $72ed530554068e4f$var$intersection_observer?.unobserve(target);
2203
- continue;
2204
- }
2205
- const currently_intersecting = $72ed530554068e4f$var$current_intersections.has(target);
2206
- if (!currently_intersecting && record.intersectionRatio >= (0, $dd025eb6f77f8f8b$export$135da44d0ba958bc)[0]) {
2207
- // we're intersecting enough and not already in the process of "measuring"
2208
- const started_intersecting_at_ = +new Date(); // save start time
2209
- // Schedule the callback function to be called after the element has been intersecting for the required duration
2210
- const callback_timeout_ = setTimeout(callback, (0, $dd025eb6f77f8f8b$export$ca8321ea61dc2544), target);
2211
- $72ed530554068e4f$var$current_intersections.set(target, {
2212
- started_intersecting_at_: started_intersecting_at_,
2213
- callback_timeout_: callback_timeout_
2214
- });
2215
- } else if (currently_intersecting && record.intersectionRatio < (0, $dd025eb6f77f8f8b$export$135da44d0ba958bc)[1]) {
2216
- // we are in the process of "measuring" and went below the threshold
2217
- const {
2218
- started_intersecting_at_: started_intersecting_at_,
2219
- callback_timeout_: callback_timeout_
2220
- } = $72ed530554068e4f$var$current_intersections.get(target);
2221
- const time_elapsed = +new Date() - started_intersecting_at_;
2222
- // If we stopped intersecting too early we want to abort our timeout.
2223
- // if we did not we also want to abort the timeout since it's been lagging and just instantly send the event
2224
- // (the browser can delay setTimeout timers)
2225
- clearTimeout(callback_timeout_);
2226
- if (time_elapsed <= (0, $dd025eb6f77f8f8b$export$ca8321ea61dc2544)) $72ed530554068e4f$var$current_intersections.delete(target);else {
2227
- // we intersected long enough
2228
- $e6c6e7929ea385ae$export$de56f1198d121036("intersection_observer: setTimeout lagged", time_elapsed, (0, $dd025eb6f77f8f8b$export$ca8321ea61dc2544), "ms", target);
2229
- callback(target);
2230
- }
2231
- }
2232
- }
2233
- };
2234
- /**
2235
- * Global IntersectionObserver used for all impression tracking.
2236
- * It's faster to use one observer for all elements than to create a new one for each element.
2237
- */
2238
- const $72ed530554068e4f$var$intersection_observer = typeof window === "object" ? /*@__PURE__*/new IntersectionObserver( /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9($72ed530554068e4f$var$intersection_observer_callback), {
2239
- threshold: /*@__PURE__*/$0da0cad4f39e8f32$export$f8ea2e7b15b5d129(8)
2240
- }) : undefined;
2241
- const $11ff7b46c1fb674c$export$d0efd8ed14f5c33 = (items, display, info) => {
2242
- if (!items?.length) return items;
2243
- const node_array = Array.isArray(items) ? items : [...items]; // if it's a NodeList convert it to an array
2244
- const first_watchable_el = node_array.find(el => el instanceof Element);
2245
- if (!first_watchable_el) {
2246
- $e6c6e7929ea385ae$export$de56f1198d121036("Impression tracking: Can't observe", items, display);
2247
- return items;
2248
- }
2249
- if (!info.t) {
2250
- $e6c6e7929ea385ae$export$de56f1198d121036("Impression tracking: No tenant instance, can't track", items, display);
2251
- return items;
2252
- }
2253
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(first_watchable_el, ({
2254
- element: element
2255
- }) => {
2256
- $72ed530554068e4f$export$4c51576248bcdf31(element, () => {
2257
- const {
2258
- recommendation_id: recommendation_id,
2259
- search_result_id: search_result_id,
2260
- product_listing_result_id: product_listing_result_id,
2261
- suggestions_result_id: suggestions_result_id
2262
- } = display;
2263
- $dd025eb6f77f8f8b$export$4205dc6835bc0d9f({
2264
- ...$e0a87646d12cb987$export$8c6f26a5b6921b95(),
2265
- recommendation_type: info.rendering_options.type,
2266
- entity_price: display.sale_price,
2267
- market: info.t.market,
2268
- tenant: info.t.tenant,
2269
- product_id: display.product_id,
2270
- recommendation_id: recommendation_id,
2271
- search_result_id: search_result_id,
2272
- product_listing_result_id: product_listing_result_id,
2273
- suggestions_result_id: suggestions_result_id
2274
- });
2275
- });
2276
- });
2277
- return items;
2278
- };
2279
- const $8e19f8200d357fe7$export$37125ccc5dd98050 = ({
2280
- element: element,
2281
- data: data,
2282
- wait_for_dom_insertion = true
2283
- }) => {
2284
- const disconnectors = [];
2285
- const impression_track = () => {
2286
- const disconnector = $72ed530554068e4f$export$4c51576248bcdf31(element, () => {
2287
- $dd025eb6f77f8f8b$export$4205dc6835bc0d9f({
2288
- ...$e0a87646d12cb987$export$8c6f26a5b6921b95(),
2289
- ...data
2290
- });
2291
- });
2292
- disconnectors.push(disconnector);
2293
- };
2294
- if (wait_for_dom_insertion) disconnectors.push((0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(element, impression_track));else impression_track();
2295
- return () => disconnectors.forEach(disconnector => disconnector());
2296
- };
2297
- let $dd025eb6f77f8f8b$export$135da44d0ba958bc = [0.6, 0.5];
2298
- const $dd025eb6f77f8f8b$export$c543ee4cdb0d0964 = (start, end) => $dd025eb6f77f8f8b$export$135da44d0ba958bc = [start, end];
2299
- const $dd025eb6f77f8f8b$export$ca8321ea61dc2544 = 500;
2300
- const $dd025eb6f77f8f8b$export$4205dc6835bc0d9f = data => {
2301
- data.type = "element_visible"; // Set the type to element_visible as this is optional to pass here.
2302
- $0c84f8e99aac5765$export$28cacbd9b4306ffc([data], true);
2303
- };
2304
- function $c8263a2185830bf1$export$82a685f2da2fb027(a_element, product_id, recommendation_id, additional_listener) {
2305
- if (!a_element ||
2306
- // @ts-ignore
2307
- !a_element.depict_tracked ||
2308
- // @ts-ignore
2309
- a_element?.depict_tracked?.recommendation_id != recommendation_id ||
2310
- // @ts-ignore
2311
- a_element?.depict_tracked?.product_id != product_id) {
2312
- const listener = e => {
2313
- localStorage.setItem(`depict_attribution_${product_id}`, recommendation_id);
2314
- if (additional_listener) additional_listener(e, product_id, recommendation_id);
2315
- };
2316
- // @ts-ignore
2317
- if (a_element.depict_tracked)
2318
- // @ts-ignore
2319
- a_element.removeEventListener("click", a_element.depict_tracked?.listener);
2320
- // @ts-ignore
2321
- a_element.depict_tracked = {
2322
- product_id: product_id,
2323
- recommendation_id: recommendation_id,
2324
- listener: listener
2325
- };
2326
- a_element.addEventListener("click", listener);
2327
- return listener;
2328
- }
2329
- }
2330
- async function $c8263a2185830bf1$export$2c34560c3749dc63(button, get_product_id, tracking_fn, unmatching_tracking, event) {
2331
- // @ts-ignore
2332
- if (!button || button.depict_tracked) return;
2333
- button.addEventListener(event ? event : "click", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async e => {
2334
- if (!e.isTrusted) {
2335
- $e6c6e7929ea385ae$export$de56f1198d121036("ignoring event", e, "because it's not user generated");
2336
- return;
2337
- }
2338
- const product_id = await get_product_id(undefined, e);
2339
- if (product_id) {
2340
- const item_name = `depict_attribution_${product_id}`;
2341
- const recommendation_id = localStorage.getItem(item_name);
2342
- if (recommendation_id) {
2343
- localStorage.removeItem(item_name);
2344
- tracking_fn(product_id, recommendation_id, false, e);
2345
- } else if (unmatching_tracking) tracking_fn(product_id, recommendation_id, true, e);
2346
- }
2347
- }));
2348
- // @ts-ignore
2349
- button.depict_tracked = true;
2350
- }
2351
- const $69f7524c8bdd85b4$export$20e9533e68ee72e7 = /*@__PURE__*/$9a42a570de51ea3d$export$e806c6c1615a59ae(false);
2352
- const $69f7524c8bdd85b4$export$a9d39e43ae273d26 = /*@__PURE__*/$9a42a570de51ea3d$export$e806c6c1615a59ae();
2353
- const $69f7524c8bdd85b4$export$7500cdfd37aafd43 = /*@__PURE__*/new Set();
2354
- let $69f7524c8bdd85b4$var$old_url;
2355
- const $69f7524c8bdd85b4$var$maybe_navigation = (what_happened, args) => {
2356
- if (typeof location === "undefined") return;
2357
- const new_url = location.href;
2358
- if ($69f7524c8bdd85b4$var$old_url !== new_url) {
2359
- $69f7524c8bdd85b4$export$a9d39e43ae273d26(new_url);
2360
- if ($69f7524c8bdd85b4$var$old_url !== undefined)
2361
- // don't resolve stateless href change ipns with the initial value - it's not a navigation
2362
- $69f7524c8bdd85b4$export$20e9533e68ee72e7(new_url);
2363
- $69f7524c8bdd85b4$var$old_url = new_url;
2364
- }
2365
- for (const fn of $69f7524c8bdd85b4$export$7500cdfd37aafd43) fn(what_happened, args);
2366
- };
2367
- $69f7524c8bdd85b4$export$baccefee4a395d8f((args, what_happened) => $69f7524c8bdd85b4$var$maybe_navigation(what_happened, args));
2368
- $69f7524c8bdd85b4$var$maybe_navigation();
2369
- globalThis?.window?.addEventListener("popstate", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => $69f7524c8bdd85b4$var$maybe_navigation("popstate", e)));
2370
- async function $69f7524c8bdd85b4$export$1cd22bab0d2c3b0b(callback) {
2371
- const catchified_callback = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(callback);
2372
- for await (const href of $69f7524c8bdd85b4$export$20e9533e68ee72e7) {
2373
- catchified_callback(href);
2374
- break;
2375
- }
2376
- }
2377
- async function $69f7524c8bdd85b4$export$baccefee4a395d8f(after_navigation, replace_replaceState = true) {
2378
- if (typeof History === "undefined") return;
2379
- const {
2380
- prototype: prototype
2381
- } = History;
2382
- const instance = history;
2383
- const polyfill_dance = the_thing => {
2384
- const proxy_the_thing = obj => {
2385
- const orig_pushState = obj[the_thing];
2386
- obj[the_thing] = new Proxy(orig_pushState, {
2387
- apply: (target, this_arg, arguments_list) => {
2388
- const nav_result = Reflect.apply(target, this_arg, arguments_list);
2389
- try {
2390
- after_navigation(arguments_list, the_thing);
2391
- } catch (e) {
2392
- $548fd58b14b25a52$export$8048b892d651b310(e);
2393
- }
2394
- return nav_result;
2395
- }
2396
- });
2397
- };
2398
- proxy_the_thing(prototype);
2399
- if (Object.getOwnPropertyNames(instance).includes(the_thing))
2400
- // we don't want to just change the instance because that's not the way to do it, but we don't want to not work because someone else did it wrong
2401
- proxy_the_thing(instance);
2402
- };
2403
- polyfill_dance("pushState");
2404
- if (replace_replaceState) polyfill_dance("replaceState");
2405
- }
2406
- let $72ee205b59322497$var$last_page_pageview_sent_for;
2407
- async function $72ee205b59322497$export$eee4c4d924348b05(data) {
2408
- // Send page view to depict if needed
2409
- try {
2410
- const {
2411
- href: href
2412
- } = location;
2413
- if ($72ee205b59322497$var$last_page_pageview_sent_for !== href) {
2414
- $72ee205b59322497$var$last_page_pageview_sent_for = href;
2415
- $e0a87646d12cb987$export$82badda1f9923310({
2416
- ...data,
2417
- type: "page_view"
2418
- });
2419
- if (data.product_id) await $44909e19109bf973$export$836f70a28c317905(data.product_id); // this takes care of right click click attribution - broadcasts the URL of the current page
2420
- }
2421
- } catch (error) {
2422
- $268cbd9e4ade92db$export$f18d5b0af29128b7([error, "Sending page view failed"], "warning");
2423
- }
2424
- }
2425
- let $72ee205b59322497$var$sending_on_navigation = false;
2426
- async function $72ee205b59322497$export$f7cb1bd47199ec38(data) {
2427
- if (!$72ee205b59322497$var$sending_on_navigation) {
2428
- $72ee205b59322497$var$sending_on_navigation = true;
2429
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async () => {
2430
- for await (const _href of (0, $69f7524c8bdd85b4$export$a9d39e43ae273d26)) $72ee205b59322497$export$eee4c4d924348b05({
2431
- tenant: data.tenant,
2432
- market: data.market,
2433
- product_id: await data.get_product_id(_href)
2434
- });
2435
- })();
2436
- }
2437
- }
2438
- function $c18ce8dadd041cdd$export$edfedd0557ca5a2d(ga_tracker, append_to_url) {
2439
- if (!ga_tracker) return;
2440
- // Docs for analytics.js Tasks:
2441
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks
2442
- const sendHitTask = "sendHitTask";
2443
- const originalSendHitTask = ga_tracker.get(sendHitTask);
2444
- ga_tracker.set(sendHitTask, model => {
2445
- originalSendHitTask(model);
2446
- // console.log('Sent original hit, now sending to depict');
2447
- try {
2448
- const payLoad = model.get("hitPayload");
2449
- const path = (0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/collect-ga";
2450
- let url = path + "?" + payLoad;
2451
- if (append_to_url) url += append_to_url;
2452
- const n = navigator;
2453
- const sb = "sendBeacon";
2454
- if (n[sb])
2455
- // this is actually smaller, I tested
2456
- n[sb](url);else {
2457
- const xhttp = new XMLHttpRequest();
2458
- xhttp.open("GET", url);
2459
- xhttp.send();
2460
- }
2461
- } catch (e) {
2462
- // console.log('Could not send beacon to /collect-ga', e);
2463
- }
2464
- });
2465
- }
2466
- function $c18ce8dadd041cdd$export$674d8cd8b6868154() {
2467
- // Snippet to load GA async
2468
- const w = window;
2469
- // @ts-ignore
2470
- w.ga ||= function () {
2471
- (w.ga.q ||= []).push(arguments);
2472
- };
2473
- w.ga.l = +new Date();
2474
- }
2475
- var $28e42b0009d694b2$exports = {};
2476
- $parcel$export($28e42b0009d694b2$exports, "cookiebot_get_consent", () => $28e42b0009d694b2$export$fce59460a1699957);
2477
- $parcel$export($28e42b0009d694b2$exports, "cookiebot_wait_for_consent", () => $28e42b0009d694b2$export$56c2e8be65fb14ae);
2478
- $parcel$export($28e42b0009d694b2$exports, "cookiebot_get_cookie_ipns", () => $28e42b0009d694b2$export$8827362e5e938d26);
2479
- $parcel$export($28e42b0009d694b2$exports, "init_cookiebot_tracking", () => $28e42b0009d694b2$export$abec7fd9f0b9cc22);
2480
- const $28e42b0009d694b2$var$required_consent_level = process.env.DEPICT_TRACKING_CONSENT_LEVEL;
2481
- function $28e42b0009d694b2$var$consent_from_cookie() {
2482
- const cookie = $e0a87646d12cb987$export$622991c71a1f52b3("CookieConsent");
2483
- if (!cookie) return;
2484
- const consent_json = cookie.replace(/%2C/g, ",").replace(/%27/g, "'").replace(/'/g, '"').replace(/([{[,])\s*([\w]+?):/g, '$1"$2":');
2485
- try {
2486
- return JSON.parse(consent_json);
2487
- } catch ({
2488
- message: message
2489
- }) {
2490
- $e6c6e7929ea385ae$export$de56f1198d121036("Error parsing cookie json", consent_json, message);
2491
- return;
2492
- }
2493
- }
2494
- let $28e42b0009d694b2$var$cookie_ipns;
2495
- let $28e42b0009d694b2$var$has_consent = /*@__PURE__*/(() => $28e42b0009d694b2$var$required_consent_level ? $28e42b0009d694b2$var$consent_from_cookie()?.[$28e42b0009d694b2$var$required_consent_level] || false : true)();
2496
- const $28e42b0009d694b2$export$fce59460a1699957 = () => $28e42b0009d694b2$var$has_consent;
2497
- async function $28e42b0009d694b2$export$56c2e8be65fb14ae() {
2498
- for await (const consent_obj of $28e42b0009d694b2$export$8827362e5e938d26()) return consent_obj[process.env.DEPICT_TRACKING_CONSENT_LEVEL];
2499
- // Impossible
2500
- return false;
2501
- }
2502
- function $28e42b0009d694b2$export$8827362e5e938d26() {
2503
- if ($28e42b0009d694b2$var$cookie_ipns) return $28e42b0009d694b2$var$cookie_ipns;
2504
- $28e42b0009d694b2$var$cookie_ipns = $9a42a570de51ea3d$export$e806c6c1615a59ae();
2505
- const existing_consent = $28e42b0009d694b2$var$consent_from_cookie();
2506
- if (existing_consent) $28e42b0009d694b2$var$cookie_ipns(existing_consent);
2507
- const consent_maybe_changed = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
2508
- const {
2509
- consent: {
2510
- marketing: marketing,
2511
- necessary: necessary,
2512
- preferences: preferences,
2513
- statistics: statistics
2514
- }
2515
- } = window.Cookiebot;
2516
- const new_consent_obj = {
2517
- marketing: marketing,
2518
- necessary: necessary,
2519
- preferences: preferences,
2520
- statistics: statistics
2521
- };
2522
- if (!Object.keys(new_consent_obj).every(k => $28e42b0009d694b2$var$cookie_ipns.latest_call_value?.[k] === new_consent_obj[k])) {
2523
- $e6c6e7929ea385ae$export$de56f1198d121036("Consent changed", new_consent_obj);
2524
- $28e42b0009d694b2$var$cookie_ipns(new_consent_obj);
2525
- }
2526
- }, "extracting consent failed");
2527
- $e6d67ef355abb2dc$export$2fc1a072736ae2f6(window, "Cookiebot", "consent").then(consent_maybe_changed);
2528
- ["CookiebotOnAccept", "CookiebotOnDecline"].forEach(e => window.addEventListener(e, consent_maybe_changed, false));
2529
- return $28e42b0009d694b2$var$cookie_ipns;
2530
- }
2531
- const $28e42b0009d694b2$export$abec7fd9f0b9cc22 = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async (anon_id = "anonymous") => {
2532
- $e6c6e7929ea385ae$export$de56f1198d121036("Initializing Cookiebot tracking");
2533
- if (!$28e42b0009d694b2$var$required_consent_level) return $e6c6e7929ea385ae$export$de56f1198d121036("No consent level set for Depict tracking. Ignoring consent and tracking everything.");
2534
- const original_get_session_id = (0, $e0a87646d12cb987$export$61e7e1f11e96692f);
2535
- $e0a87646d12cb987$export$93ae15b1ae509334(() => $28e42b0009d694b2$var$has_consent ? original_get_session_id() : anon_id);
2536
- for await (const consent_obj of $28e42b0009d694b2$export$8827362e5e938d26()) {
2537
- // Changing this will change the return value of function given to set_depict_id_fn above
2538
- $28e42b0009d694b2$var$has_consent = consent_obj[$28e42b0009d694b2$var$required_consent_level];
2539
- if (!$28e42b0009d694b2$var$has_consent) $e6c6e7929ea385ae$export$de56f1198d121036(`dsid will be set to, "${anon_id}", until Cookiebot has consent for "${$28e42b0009d694b2$var$required_consent_level}"`);else $e6c6e7929ea385ae$export$de56f1198d121036(`Cookiebot obtained consent for "${$28e42b0009d694b2$var$required_consent_level}", will use true dsid/session_id`);
2540
- }
2541
- });
2542
- const $2026711c6c2d6204$var$required_consent_level = process.env.DEPICT_TRACKING_CONSENT_LEVEL;
2543
- /*
2544
- The Optanon cookie format can vary slightly between integrations. To figure out the key values used for a particular customer,
2545
- visit their web, finish the consent dialog, then run
2546
- new URLSearchParams(document.cookie.match("(^|;)\\s*OptanonConsent\\s*=\\s*([^;]+)")?.pop()).get("groups")
2547
- in the console. You should see something like
2548
- 'NECES:1,ANALY:1,PERON:1,MARKE:1'
2549
- Which tells you what the key values for each consent level is. Enter them in the correct order, comma separated,
2550
- as OPTANON_KEYS in the tenants .env file. For the cookie output above, the .env entry would be
2551
- OPTANON_KEYS="NECES,ANALY,PERON,MARKE"
2552
- If it's not obvious which consent level each key represents, open the consent dialog again and start de-selecting consent options,
2553
- then check the cookie value again.
2554
- */
2555
- const $2026711c6c2d6204$var$KEY_ORDER = ["necessary", "statistics", "preferences", "marketing"];
2556
- const $2026711c6c2d6204$var$OPTANON_TO_COOKIEBOT = Object.fromEntries((process.env.OPTANON_KEYS || "").split(",").filter(k => k).map((k, i) => [k, $2026711c6c2d6204$var$KEY_ORDER[i]]));
2557
- function $2026711c6c2d6204$var$consent_from_cookie() {
2558
- const cookie = $e0a87646d12cb987$export$622991c71a1f52b3("OptanonConsent");
2559
- if (!cookie) return;
2560
- const groups = new URLSearchParams(cookie).get("groups") || "";
2561
- const matches = groups.matchAll(/(\w+):(\d)/g);
2562
- const consent = {};
2563
- for (const match of matches) consent[$2026711c6c2d6204$var$OPTANON_TO_COOKIEBOT[match[1]]] = match[2] == "1";
2564
- return consent;
2565
- }
2566
- let $2026711c6c2d6204$var$cookie_ipns;
2567
- let $2026711c6c2d6204$var$has_consent = /*@__PURE__*/(() => $2026711c6c2d6204$var$required_consent_level ? $2026711c6c2d6204$var$consent_from_cookie()?.[$2026711c6c2d6204$var$required_consent_level] || false : true)();
2568
- const $2026711c6c2d6204$export$1dd9ce50e201eff1 = () => $2026711c6c2d6204$var$has_consent;
2569
- async function $2026711c6c2d6204$export$7a6d436e0782c6ed() {
2570
- for await (const consent_obj of $2026711c6c2d6204$export$7e4427e80d5fc619()) return consent_obj[process.env.DEPICT_TRACKING_CONSENT_LEVEL];
2571
- // Impossible
2572
- return false;
2573
- }
2574
- function $2026711c6c2d6204$export$7e4427e80d5fc619() {
2575
- if ($2026711c6c2d6204$var$cookie_ipns) return $2026711c6c2d6204$var$cookie_ipns;
2576
- $2026711c6c2d6204$var$cookie_ipns = $9a42a570de51ea3d$export$e806c6c1615a59ae();
2577
- const existing_consent = $2026711c6c2d6204$var$consent_from_cookie();
2578
- if (existing_consent?.necessary)
2579
- // If "necessary" isn't set, user hasn't actually given/withold consent yet.
2580
- $2026711c6c2d6204$var$cookie_ipns(existing_consent);
2581
- window.addEventListener("consent.onetrust", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(evt => {
2582
- const c = evt;
2583
- // Cast because TS doesn't know about the forEach coming up
2584
- const consent_obj = {};
2585
- Object.keys($2026711c6c2d6204$var$OPTANON_TO_COOKIEBOT).forEach(k => {
2586
- consent_obj[$2026711c6c2d6204$var$OPTANON_TO_COOKIEBOT[k]] = c.detail.includes(k);
2587
- });
2588
- if (!consent_obj.necessary)
2589
- // If "necessary" isn't set, user hasn't actually given/withold consent yet.
2590
- return;
2591
- if (!Object.keys(consent_obj).every(k => $2026711c6c2d6204$var$cookie_ipns.latest_call_value?.[k] === consent_obj[k])) $2026711c6c2d6204$var$cookie_ipns(consent_obj);
2592
- }));
2593
- return $2026711c6c2d6204$var$cookie_ipns;
2594
- }
2595
- const $2026711c6c2d6204$export$f0f6c846d96fdbec = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async (anon_id = "anonymous") => {
2596
- $e6c6e7929ea385ae$export$de56f1198d121036("Initializing OptAnon tracking");
2597
- if (!$2026711c6c2d6204$var$required_consent_level) return $e6c6e7929ea385ae$export$de56f1198d121036("No consent level set for Depict tracking. Ignoring consent and tracking everything.");
2598
- const original_get_session_id = (0, $e0a87646d12cb987$export$61e7e1f11e96692f);
2599
- $e0a87646d12cb987$export$93ae15b1ae509334(() => $2026711c6c2d6204$var$has_consent ? original_get_session_id() : anon_id);
2600
- for await (const consent_obj of $2026711c6c2d6204$export$7e4427e80d5fc619()) {
2601
- // Changing this will change the return value of function given to set_depict_id_fn above
2602
- $2026711c6c2d6204$var$has_consent = consent_obj[$2026711c6c2d6204$var$required_consent_level];
2603
- if (!$2026711c6c2d6204$var$has_consent) $e6c6e7929ea385ae$export$de56f1198d121036(`dsid/session_id will be set to, "${anon_id}", until Optanon has consent for "${$2026711c6c2d6204$var$required_consent_level}"`);else $e6c6e7929ea385ae$export$de56f1198d121036(`Optanon obtained consent for "${$2026711c6c2d6204$var$required_consent_level}", will use true dsid/session_id`);
2604
- }
2605
- });
2606
- const $d3d8549954e0318e$var$g = typeof globalThis == "object" && globalThis || window;
2607
- const $d3d8549954e0318e$export$f3354ec2ce95ebd9 = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async (GA_ID, strict) => {
2608
- if (process.env.GTAG === "false") return;
2609
- if (!GA_ID) {
2610
- $e6c6e7929ea385ae$export$c2363754d4758444("Couldn't load gtag, GA_ID not specified", GA_ID);
2611
- return;
2612
- }
2613
- const required_consent_level = process.env.GTAG_LOADING_CONSENT_LEVEL;
2614
- if (required_consent_level !== undefined) {
2615
- $e6c6e7929ea385ae$export$de56f1198d121036(`GTag loading waiting for consent level ${required_consent_level}`);
2616
- const ipns = process.env.CONSENT_FRAMEWORK == "optanon" ? $2026711c6c2d6204$export$7e4427e80d5fc619() : $28e42b0009d694b2$export$8827362e5e938d26();
2617
- for await (const consent_status of ipns) {
2618
- const status_for_level = consent_status[required_consent_level];
2619
- if (status_for_level) {
2620
- $e6c6e7929ea385ae$export$de56f1198d121036("got consent for", required_consent_level, "loading gtag");
2621
- break;
2622
- }
2623
- }
2624
- }
2625
- // delay loading of script because it's huge and slow according to nordiska galleriet
2626
- // @ts-ignore
2627
- const page_hasnt_loaded = $d3d8549954e0318e$var$g?.performance?.getEntriesByType?.("navigation")?.every?.(e => e?.loadEventEnd) === false;
2628
- // Source: comment on https://stackoverflow.com/a/53525488
2629
- // don't use readyState, source: personal experience and comment on https://stackoverflow.com/a/28093606
2630
- $e6c6e7929ea385ae$export$de56f1198d121036("Loading gtag after " + (page_hasnt_loaded ? "pageload and " : "") + "3s" + (strict ? "" : ", but setting up queues already"));
2631
- if (!strict) $d3d8549954e0318e$export$d031e55ccd4c52dc(GA_ID);
2632
- if (page_hasnt_loaded) {
2633
- const load_event = await new Promise(r => window.addEventListener("load", r, {
2634
- once: true
2635
- }));
2636
- $e6c6e7929ea385ae$export$de56f1198d121036("page has loaded", load_event);
2637
- }
2638
- await new Promise(r => setTimeout(r, 3000));
2639
- const script = document.createElement("script"),
2640
- head = document.head;
2641
- script.async = true;
2642
- script.src = "https://www.googletagmanager.com/gtag/js?id=" + GA_ID;
2643
- head.appendChild(script);
2644
- $e6c6e7929ea385ae$export$de56f1198d121036("Loading gtag now", script);
2645
- });
2646
- const $d3d8549954e0318e$export$d031e55ccd4c52dc = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(GA_ID => {
2647
- if (process.env.GTAG === "false") return;
2648
- $d3d8549954e0318e$var$g.dataLayer ||= [];
2649
- function gtag() {
2650
- $d3d8549954e0318e$var$g.dataLayer.push(arguments);
2651
- }
2652
- $d3d8549954e0318e$var$g.gtag = gtag;
2653
- $d3d8549954e0318e$var$g.gtag("js", new Date());
2654
- $d3d8549954e0318e$var$g.gtag("config", GA_ID, {
2655
- "send_page_view": false
2656
- });
2657
- $e6c6e7929ea385ae$export$de56f1198d121036("configuring gtag with", GA_ID);
2658
- });
2659
- const $d3d8549954e0318e$export$7babcd5d4056b2ca = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async (raw_displays, get_product_id, more) => {
2660
- const displays = raw_displays; // gtag tracking is "obsolete" and we don't expect any customers using something else than LegacyDisplay to use it
2661
- if (process.env.GTAG === "false") return;
2662
- if (process.env.GTAG_VIEW === "false") return;
2663
- if (process.env.GTAG_EVENT_CONSENT_LEVEL !== undefined && !(await $d3d8549954e0318e$var$can_send_gtag_events(displays, get_product_id, more))) return;
2664
- if (typeof $d3d8549954e0318e$var$g.gtag == "function") {
2665
- const make_item = (display, index, id) => ({
2666
- id: id,
2667
- "list_name": "depict",
2668
- "list_position": display?.index || index + 1,
2669
- ...(typeof more === "function" ? more(display) : more)
2670
- });
2671
- const gtag_items = [
2672
- // spread works around safari 11 bug where Array returned by Promise.all is not an instance of the global Array
2673
- // https://sentry.io/organizations/depictai-0o/issues/2794688692/?project=5476183
2674
- ...(await Promise.all(displays.map(async (display, index) => display.ga_product_ids ? display.ga_product_ids.map(id => make_item(display, index, id)) : make_item(display, index, display.ga_product_id || display.product_id || (await get_product_id(display.page_url)) || (await get_product_id(display)) // the last statement is this row allows for special product_id getter functions that not only use the page_url. They need to check the typeof their argument tho and ignore the first calls
2675
- ))))].flat();
2676
- const max_products_per_request = 100;
2677
- for (let i = 0; i < gtag_items.length; i += max_products_per_request) {
2678
- const gtag_args = ["event", "view_item_list", {
2679
- "items": gtag_items.slice(i, i + max_products_per_request)
2680
- }];
2681
- $e6c6e7929ea385ae$export$de56f1198d121036("Sending product view to gtag", gtag_args);
2682
- $d3d8549954e0318e$var$g.gtag(...gtag_args);
2683
- }
2684
- } else $e6c6e7929ea385ae$export$c2363754d4758444("not sending gtag tracking as there is no gtag");
2685
- });
2686
- const $d3d8549954e0318e$export$f522672c9379e339 = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async (product_id, index, more) => {
2687
- if (process.env.GTAG === "false") return;
2688
- if (process.env.GTAG_EVENT_CONSENT_LEVEL !== undefined && !(await $d3d8549954e0318e$var$can_send_gtag_events(product_id, index, more))) return;
2689
- if (typeof $d3d8549954e0318e$var$g.gtag == "function") {
2690
- const gtag_args = ["event", "select_content", {
2691
- "content_type": "product",
2692
- "items": [{
2693
- "id": product_id,
2694
- "list_name": "depict",
2695
- "list_position": index + 1,
2696
- ...more
2697
- }]
2698
- }];
2699
- $e6c6e7929ea385ae$export$de56f1198d121036("calling gtag with arguments", gtag_args);
2700
- return $d3d8549954e0318e$var$g.gtag(...gtag_args);
2701
- } else $e6c6e7929ea385ae$export$c2363754d4758444("not sending gtag tracking as there is no gtag");
2702
- });
2703
- const $d3d8549954e0318e$export$f75172d2e289cd02 = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(action => {
2704
- if (process.env.GA === "false") return;
2705
- if (typeof $d3d8549954e0318e$var$g.ga != "function") {
2706
- $e6c6e7929ea385ae$export$c2363754d4758444("Not sending to ga as there is no ga");
2707
- return;
2708
- }
2709
- $e6c6e7929ea385ae$export$de56f1198d121036("sending", action, "to GA");
2710
- return $d3d8549954e0318e$var$g.ga("depict.send", {
2711
- hitType: "event",
2712
- eventCategory: "Depict",
2713
- eventAction: action,
2714
- eventLabel: "rec-bar-tracking",
2715
- nonInteraction: 1
2716
- });
2717
- });
2718
- const $d3d8549954e0318e$export$ac7296527cb52311 = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(GAID => {
2719
- if (process.env.GA === "false") return;
2720
- if (!GAID) {
2721
- $e6c6e7929ea385ae$export$c2363754d4758444(new Error("No GAID specified"));
2722
- return;
2723
- }
2724
- if (typeof $d3d8549954e0318e$var$g.ga != "function") {
2725
- $e6c6e7929ea385ae$export$de56f1198d121036("Creating GA queue");
2726
- $c18ce8dadd041cdd$export$674d8cd8b6868154();
2727
- }
2728
- $e6c6e7929ea385ae$export$de56f1198d121036("Creating ga with GA-ID", GAID);
2729
- $d3d8549954e0318e$var$g.ga("create", GAID, "auto", "depict");
2730
- $d3d8549954e0318e$export$f3354ec2ce95ebd9(GAID, false);
2731
- });
2732
- const $d3d8549954e0318e$export$127751e82111fcf = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => $d3d8549954e0318e$export$f75172d2e289cd02("rec_bar_click"));
2733
- const $d3d8549954e0318e$export$bf205937e5e012cb = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => $d3d8549954e0318e$export$f75172d2e289cd02("add_to_cart_after_rec_bar_click"));
2734
- async function $d3d8549954e0318e$var$can_send_gtag_events(...stuff_to_log) {
2735
- const required_consent_level = process.env.GTAG_LOADING_CONSENT_LEVEL;
2736
- if (required_consent_level !== undefined) return true; // just in case
2737
- const ipns = process.env.CONSENT_FRAMEWORK == "optanon" ? $2026711c6c2d6204$export$7e4427e80d5fc619() : $28e42b0009d694b2$export$8827362e5e938d26();
2738
- for await (const consent_obj of ipns) {
2739
- const can_send = consent_obj[required_consent_level];
2740
- if (!can_send) $e6c6e7929ea385ae$export$de56f1198d121036("Got no consent for", required_consent_level, "not sending gtag event for", ...stuff_to_log);
2741
- return can_send;
2742
- }
2743
- }
2744
- let $e4bebbfa0f0b1454$var$existing_style_tag;
2745
- let $e4bebbfa0f0b1454$var$reactions_in_last_s = 0;
2746
- const $e4bebbfa0f0b1454$export$59ba1eb2c083f0cd = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async css => {
2747
- const style_tag = await ($e4bebbfa0f0b1454$var$existing_style_tag ||= (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element("head").then(head => {
2748
- const tag = document.createElement("style");
2749
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onremoved(
2750
- // reinsertion for next.js's "portable" <head>
2751
- tag, eoe => {
2752
- if (document.head.contains(tag))
2753
- // just make sure to not freak out if it's already been added again
2754
- return;
2755
- if ($e4bebbfa0f0b1454$var$reactions_in_last_s >= 10) {
2756
- $268cbd9e4ade92db$export$f18d5b0af29128b7(new Error("Someone removed our styling but insists on it (10 removals in previous second). Giving up \uD83D\uDE2B"), "error");
2757
- return;
2758
- }
2759
- $e6c6e7929ea385ae$export$de56f1198d121036("Someone removed our styling \uD83D\uDE24, reinserting", eoe);
2760
- $e4bebbfa0f0b1454$var$reactions_in_last_s++;
2761
- setTimeout(() => $e4bebbfa0f0b1454$var$reactions_in_last_s--, 1000);
2762
- document.head.append(tag); // we're sure that head exists now since we inserted it there previously
2763
- });
2764
-
2765
- $e6c6e7929ea385ae$export$de56f1198d121036("inserting", tag, "into", head);
2766
- return head.appendChild(tag);
2767
- }));
2768
- style_tag.append(css);
2769
- });
2770
- const $e4bebbfa0f0b1454$export$a96c18473f2af463 = (tenant, selector, validator) => {
2771
- return (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(selector, ({
2772
- element: element
2773
- }) => $c8263a2185830bf1$export$2c34560c3749dc63(element, tenant.get_product_id, (p_id, r_id, was_unmatching, event) => {
2774
- if (typeof validator === "function" && !validator(event)) return;
2775
- if (!was_unmatching) $d3d8549954e0318e$export$bf205937e5e012cb();
2776
- $e0a87646d12cb987$export$9028351cb994757e({
2777
- ...tenant,
2778
- product_id: p_id,
2779
- ...(was_unmatching ? {
2780
- attribution_id: "recommendation"
2781
- } : {
2782
- recommendation_id: r_id
2783
- })
2784
- });
2785
- }, true));
2786
- };
2787
- const $e4bebbfa0f0b1454$export$a4f97b27a0592e6c = url => (url ? new URL(url, window.location.origin) : window.location).pathname.split("/").filter(a => a).pop()?.replace(/\.html?$/i, "") || "";
2788
- const $e4bebbfa0f0b1454$export$692b606677218a16 = callback => {
2789
- if (document.depictwashere) {
2790
- if (process.env.BUILD_TARGET === "dev") {
2791
- $e6c6e7929ea385ae$export$de56f1198d121036("HMR tried to rerun us, reloading page");
2792
- /* eslint-disable no-self-assign */
2793
- location.href = location.href;
2794
- }
2795
- $e6c6e7929ea385ae$export$de56f1198d121036("Script has already ran", document.currentScript, "is exiting");
2796
- return;
2797
- }
2798
- if (process.env.BUILD_TARGET === "dev") /* eslint-disable no-console */console.clear = new Proxy(console.clear, {
2799
- apply(target, this_arg, arg_list) {
2800
- if (new Error().stack?.split("\n").filter(Boolean).some(s => s.includes("http://localhost:1234/depict-ai.js"))) {
2801
- /* eslint-disable no-console */console.log("CSS change detected through hack, reloading");
2802
- location.reload();
2803
- }
2804
- return target.apply(this_arg, arg_list);
2805
- }
2806
- });
2807
- document.depictwashere = true;
2808
- callback().catch((0, $548fd58b14b25a52$export$8048b892d651b310));
2809
- };
2810
- function $e4bebbfa0f0b1454$export$328e81c44cddf3c0(callback, get_market, supported_markets, unsupported_markets, preferred_demo_market) {
2811
- $e4bebbfa0f0b1454$export$692b606677218a16(async () => {
2812
- // Handle override for debug scripts (could be used on demo pages too)
2813
- if (process.env.DEBUG === "true") {
2814
- let localstorage_override;
2815
- const query_param_override = new URLSearchParams(location.search).get("depict-override-market");
2816
- if (query_param_override !== null) {
2817
- $e6c6e7929ea385ae$export$de56f1198d121036(`Found ?depict-override-market=${query_param_override}. Using that as the market`);
2818
- get_market = () => query_param_override;
2819
- localStorage.setItem("depict-override-market", query_param_override);
2820
- } else if ((localstorage_override = localStorage.getItem("depict-override-market")) !== null) {
2821
- $e6c6e7929ea385ae$export$de56f1198d121036(`Found depict-override-market="${localstorage_override}" in localStorage. Using that as the market`);
2822
- get_market = () => localstorage_override;
2823
- }
2824
- }
2825
- const market = await get_market();
2826
- if (supported_markets.includes(market)) {
2827
- $e6c6e7929ea385ae$export$de56f1198d121036(`Initializing with market: ${market}`);
2828
- return callback(market).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
2829
- } else if (unsupported_markets.includes(market)) {
2830
- $e6c6e7929ea385ae$export$de56f1198d121036(`Unsupported market: ${market}. Exiting...`);
2831
- return;
2832
- } else if (process.env.DEBUG === "true" && location.host.endsWith(".demo.depict.ai") && preferred_demo_market) {
2833
- $e6c6e7929ea385ae$export$de56f1198d121036(`On demosite with default market override. Setting market to ${preferred_demo_market}`);
2834
- return callback(preferred_demo_market).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
2835
- } else {
2836
- $548fd58b14b25a52$export$8048b892d651b310(new Error(`Unknown market: "${market}". Exiting...`));
2837
- return;
2838
- }
2839
- });
2840
- }
2841
- class $16f3a26cfac77a4c$export$8d42ce4827f43582 {
2842
- constructor(options) {
2843
- this.dataset = {
2844
- ...((options.current_script_override || document.currentScript || {}).dataset || {})
2845
- };
2846
- this.modify = this.dataset.modify === "true";
2847
- this.is_debug = (0, $7b5e577a60b81e60$export$55fe61489d2c7417);
2848
- this.dlog = (0, $e6c6e7929ea385ae$export$de56f1198d121036);
2849
- this.TENANT = options.TENANT || process.env.TENANT || "sandbox";
2850
- this.MARKET = options.MARKET;
2851
- this.Sentry = (0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5);
2852
- this.GA_ID = options.GA_ID ?? "";
2853
- this.TYPE = options.TYPE || "normal";
2854
- this.catchify = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9);
2855
- this.err = (0, $548fd58b14b25a52$export$8048b892d651b310);
2856
- if (this.GA_ID) $d3d8549954e0318e$export$ac7296527cb52311(this.GA_ID);
2857
- // https://gitlab.com/depict-ai/depict.ai/-/merge_requests/2318#note_927887712
2858
- this.get_product_id = $268cbd9e4ade92db$export$b3bbfd758f11cfa9((...args) => {
2859
- const id = options.get_product_id(...args);
2860
- if (id instanceof Promise) return id.then(id => id || "");
2861
- return id || "";
2862
- });
2863
- this.product_id = this.get_product_id; // template tool compatible alias
2864
- this.tenant = this.TENANT;
2865
- this.market = this.MARKET;
2866
- this.gaid = this.GA_ID; // template tool compatible alias
2867
- this.type = this.TYPE;
2868
- this.catchify = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9);
2869
- this.err = (0, $548fd58b14b25a52$export$8048b892d651b310);
2870
- if (localStorage.getItem("highlight-depict") === "true") $e4bebbfa0f0b1454$export$59ba1eb2c083f0cd(".depict { background: #f00a !important; }");
2871
- if (options.pageview_tracking ?? true) (async () => {
2872
- $72ee205b59322497$export$f7cb1bd47199ec38({
2873
- market: this.market,
2874
- tenant: this.tenant,
2875
- get_product_id: this.get_product_id
2876
- });
2877
- })();
2878
- }
2879
- } /**
2880
- * This is a list of alpha-2 country codes plus some two letter combinations commonly used to describe markets
2881
- */ // albania
2882
-
2883
- const $fbb09973782881cb$var$default_get_rec_id = elem => elem?.dataset?.depict_recommendation_id || elem?.dataset?.recommendationId;
2884
- const $fbb09973782881cb$var$default_get_prod_id = elem => elem?.dataset?.depict_product_id || elem?.dataset?.productId;
2885
- const $fbb09973782881cb$var$default_get_ga_prod_id = elem => elem?.dataset?.ga_ids;
2886
- const $fbb09973782881cb$var$get_index_in_children_of_el = el => [...(el?.parentElement?.children || [])].indexOf(el);
2887
- const $fbb09973782881cb$export$29a6094e0bd8bc5f = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async (options, gtag_options) => {
2888
- const {
2889
- product_selector: product_selector,
2890
- a2c_selector: a2c_selector,
2891
- rec_a2c_selector: rec_a2c_selector,
2892
- rec_a2c_unbubbled: rec_a2c_unbubbled,
2893
- get_product_id = options.t?.get_product_id,
2894
- get_rec_id = $fbb09973782881cb$var$default_get_rec_id,
2895
- get_prod_id = $fbb09973782881cb$var$default_get_prod_id,
2896
- get_ga_prod_id = $fbb09973782881cb$var$default_get_ga_prod_id,
2897
- get_display: get_display,
2898
- impression_tracking: impression_tracking,
2899
- a2c_elements: a2c_elements,
2900
- product_elements: product_elements,
2901
- t: t,
2902
- click_location_prefix = elem => elem?.parentElement?.dataset?.type + "_"
2903
- } = options;
2904
- const get_display_data = async elem => {
2905
- const data = {};
2906
- if (get_prod_id) data.product_id = (await get_prod_id(elem)) || (get_product_id ? await get_product_id(elem.querySelector("a")?.href || elem?.href) : undefined);
2907
- if (get_ga_prod_id) data.ga_product_id = await get_ga_prod_id(elem);
2908
- if (get_rec_id) data.recommendation_id = get_rec_id(elem);
2909
- if (get_display) Object.assign(data, get_display(elem));
2910
- return data;
2911
- };
2912
- const impression_tracked_els = new WeakSet();
2913
- const view_tracked_els = new WeakSet();
2914
- const a2c_tracked_els = new WeakSet();
2915
- const click_tracked_els = new WeakSet();
2916
- const gtag_view_product_ids = {};
2917
- // Page view
2918
- if (t instanceof (0, $16f3a26cfac77a4c$export$8d42ce4827f43582)) (async () => {
2919
- $72ee205b59322497$export$eee4c4d924348b05({
2920
- tenant: t.tenant,
2921
- market: t.market,
2922
- product_id: await t.get_product_id()
2923
- });
2924
- })();
2925
- // Product card
2926
- const add_tracking_to_product_card = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async ({
2927
- element: elem
2928
- }) => {
2929
- const index = $fbb09973782881cb$var$get_index_in_children_of_el(elem);
2930
- const data = await get_display_data(elem);
2931
- const prefix = typeof click_location_prefix === "function" && click_location_prefix(elem) || "depict_";
2932
- const gtag_list_name = "depict_" + (prefix[prefix.length - 1] == "_" ? prefix.substr(0, prefix.length - 1) : prefix);
2933
- // Impression tracking
2934
- if (impression_tracking && !impression_tracked_els.has(elem)) {
2935
- impression_tracked_els.add(elem);
2936
- $8e19f8200d357fe7$export$37125ccc5dd98050({
2937
- element: elem,
2938
- data: {
2939
- recommendation_id: data.recommendation_id,
2940
- product_id: data.product_id,
2941
- tenant: t.tenant,
2942
- recommendation_type: prefix.slice(-1) === "_" ? prefix.slice(0, -1) : prefix,
2943
- entity_price: data.entity_price,
2944
- market: t.market
2945
- },
2946
- wait_for_dom_insertion: false
2947
- });
2948
- }
2949
- // Gtag view tracking
2950
- if (data.product_id && options.attempt_gtag_view_tracking && !view_tracked_els.has(elem)) {
2951
- view_tracked_els.add(elem);
2952
- const gtag_view_product_ids_for_product = gtag_view_product_ids[gtag_list_name] ||= [];
2953
- gtag_view_product_ids_for_product.push({
2954
- product_id: data.ga_product_id || data.product_id,
2955
- index: index
2956
- });
2957
- if (data.ga_product_ids) gtag_view_product_ids_for_product.push(...data.ga_product_ids.map(product_id => ({
2958
- product_id: product_id,
2959
- index: index
2960
- })));
2961
- try {
2962
- const ga_ids = elem?.dataset?.ga_ids;
2963
- if (ga_ids) gtag_view_product_ids_for_product.push(...ga_ids.split(",").map(id => ({
2964
- product_id: id,
2965
- index: index
2966
- })));
2967
- } catch (e) {
2968
- $e6c6e7929ea385ae$export$c2363754d4758444("Something went wrong on a product with multiple ga_ids", e);
2969
- }
2970
- }
2971
- if (typeof BroadcastChannel == "function") {
2972
- // right click and mouse wheel click tracking
2973
- const handler = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => $44909e19109bf973$export$8f66c4c7fb96eda2(e, data.product_id));
2974
- elem.addEventListener("contextmenu", handler);
2975
- elem.addEventListener("auxclick", e => e.button === 1 && handler(e)); // actual wheel click - some mouses / OS:es also dispatch auxclick on rightclick
2976
- }
2977
-
2978
- click_tracking: {
2979
- if (click_tracked_els.has(elem)) break click_tracking;
2980
- click_tracked_els.add(elem);
2981
- elem.addEventListener("click", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
2982
- const product_id = data.product_id || "DNT";
2983
- const recommendation_id = data.recommendation_id || "not_depict";
2984
- localStorage.setItem(`depict_attribution_${product_id}`, recommendation_id);
2985
- const index = $fbb09973782881cb$var$get_index_in_children_of_el(elem);
2986
- const click_location = prefix + (index + 1);
2987
- $d3d8549954e0318e$export$127751e82111fcf();
2988
- $e0a87646d12cb987$export$15f8a0cd5a8c0ebb({
2989
- ...(options.t || {}),
2990
- ...options,
2991
- ...data,
2992
- ...(data.recommendation_id ? {} : {
2993
- attribution_id: "recommendation"
2994
- }),
2995
- click_location: click_location
2996
- });
2997
- if (!options.no_gtag) {
2998
- const gtag_options_with_click_location = {
2999
- list_name: gtag_list_name,
3000
- ...gtag_options
3001
- };
3002
- $d3d8549954e0318e$export$f522672c9379e339(data.product_id, index, gtag_options_with_click_location);
3003
- try {
3004
- const to_iterate = [];
3005
- if (data.ga_product_id) to_iterate.push(...(data.ga_product_id.toString?.().split(",") ?? []));
3006
- to_iterate.push(...(data.ga_product_ids || []));
3007
- to_iterate.forEach(id => $d3d8549954e0318e$export$f522672c9379e339(id, index, gtag_options_with_click_location));
3008
- } catch (e) {
3009
- $e6c6e7929ea385ae$export$c2363754d4758444("Something went wrong when sending gtag click tracking on a product with multiple ga_ids");
3010
- $268cbd9e4ade92db$export$f18d5b0af29128b7(e, "error");
3011
- }
3012
- }
3013
- }), {
3014
- once: true
3015
- });
3016
- }
3017
- // Product card A2C button tracking
3018
- if (rec_a2c_selector && !a2c_tracked_els.has(elem)) {
3019
- const track_rec_a2c = async element => {
3020
- const rec_a2c_button = element.querySelector(rec_a2c_selector);
3021
- if (!rec_a2c_button) return;
3022
- const data = await get_display_data(element);
3023
- rec_a2c_button.addEventListener("click", () => {
3024
- if (rec_a2c_unbubbled) {
3025
- // If their script cancels the event before it reaches the rec card,
3026
- // we will only attribute an a2c but not a click. This is inconsistent with what we usually do.
3027
- // Create a fake click event on the main rec card,
3028
- // so our click_tracking above can send tracking for a click as well.
3029
- const click = new MouseEvent("click", {
3030
- view: window,
3031
- bubbles: true,
3032
- cancelable: true,
3033
- metaKey: true
3034
- });
3035
- element.addEventListener("click", e => (e.preventDefault(), false), {
3036
- once: true
3037
- });
3038
- element.dispatchEvent(click);
3039
- }
3040
- $d3d8549954e0318e$export$bf205937e5e012cb();
3041
- $e0a87646d12cb987$export$9028351cb994757e({
3042
- ...(options.t || {}),
3043
- ...options,
3044
- ...data
3045
- });
3046
- });
3047
- a2c_tracked_els.add(elem);
3048
- };
3049
- track_rec_a2c(elem);
3050
- }
3051
- if (options.shade) $fbb09973782881cb$export$6ebd242c09192cec(elem);
3052
- if (options.attempt_gtag_view_tracking && Object.keys(gtag_view_product_ids)?.length)
3053
- // setTimeout to batch the requests / put it all into one gtag view event
3054
- setTimeout($268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
3055
- for (const key in gtag_view_product_ids) {
3056
- const product_ids = gtag_view_product_ids[key];
3057
- if (product_ids?.length) {
3058
- $d3d8549954e0318e$export$7babcd5d4056b2ca(product_ids, () => "", {
3059
- list_name: key,
3060
- ...gtag_options
3061
- });
3062
- delete gtag_view_product_ids[key];
3063
- }
3064
- }
3065
- }));
3066
- });
3067
- if (typeof product_selector == "string") (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(product_selector, add_tracking_to_product_card);else if (product_elements && typeof product_elements?.[Symbol.iterator] == "function") for (const element of product_elements) add_tracking_to_product_card({
3068
- element: element
3069
- });else $e6c6e7929ea385ae$export$c2363754d4758444(new Error("AIO can't find elements, try adding a selector or els")); // don't throw so that a2c tracking keeps working
3070
- // Page A2C button tracking
3071
- const a2c_handler = ({
3072
- element: element
3073
- }) => {
3074
- $c8263a2185830bf1$export$2c34560c3749dc63(element, get_product_id, (product_id, recommendation_id, was_unmatching) => {
3075
- if (!was_unmatching) $d3d8549954e0318e$export$bf205937e5e012cb();
3076
- $e0a87646d12cb987$export$9028351cb994757e({
3077
- ...(options.t || {}),
3078
- ...options,
3079
- product_id: product_id,
3080
- ...(recommendation_id == "not_depict" || was_unmatching ? {
3081
- attribution_id: "recommendation"
3082
- } : {
3083
- recommendation_id: recommendation_id
3084
- })
3085
- });
3086
- }, options.always_track_a2c);
3087
- if (options.shade) $fbb09973782881cb$export$6ebd242c09192cec(element);
3088
- };
3089
- if (typeof a2c_selector == "string") (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(a2c_selector, a2c_handler);else if (a2c_elements && typeof a2c_elements?.[Symbol.iterator] == "function") for (const element of a2c_elements) a2c_handler({
3090
- element: element
3091
- });else $e6c6e7929ea385ae$export$c2363754d4758444(new Error("Can't find a2c button, try adding a selector or els"));
3092
- return {
3093
- add_a2c_element: element => a2c_handler({
3094
- element: element
3095
- }),
3096
- add_product_element: element => add_tracking_to_product_card({
3097
- element: element
3098
- })
3099
- };
3100
- });
3101
- const $fbb09973782881cb$export$6ebd242c09192cec = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(element => {
3102
- element.style.boxShadow = "rgba(255,0,0,0.5) 10px 10px 30px 40px";
3103
- element.style.background = "rgba(255,0,0,0.5)";
3104
- element.style.color = "white";
3105
- });
3106
-
3107
- // not ideal but can help when debugging via sentry
3108
- /**
3109
- * A function that attempts to "serialize" an object to a text representation that helps with debugging when using sentry
3110
- * @param anything Something to try to serialize - this function is crappy and your mileage may vary
3111
- * @param depth How deep to go when recursing
3112
- * @return An object that is somehow closer to text (better serializable by sentry) or text
3113
- */
3114
- function $45e05ec4fd7f1ee7$export$39d526a1194b6499(anything, depth) {
3115
- depth ??= 0;
3116
- depth++;
3117
- if (depth > 30) return anything;
3118
- const output = {};
3119
- for (const key in anything) {
3120
- const value = anything[key];
3121
- let serialized_value;
3122
- if (value instanceof Element) serialized_value = value.cloneNode(false).outerHTML;else if (value instanceof Headers) serialized_value = Object.fromEntries(value.entries());else if (typeof value == "object" && value != null && (typeof value[Symbol.iterator] === "function" || value instanceof Response)) serialized_value = $45e05ec4fd7f1ee7$export$39d526a1194b6499(value, depth);else serialized_value = value?.toString?.();
3123
- output[key] = serialized_value;
3124
- }
3125
- return output;
3126
- }
3127
- const $55769f63ea4d8da4$export$5c069c93d2b7493f = delay => new Promise(resolve => setTimeout(resolve, delay));
3128
- async function $d2fc3fb450961938$export$bcd70d5ed1cf6313(url, options, max_retries = 10, useFetch = fetch) {
3129
- const ONE_MINUTE = 60000;
3130
- const max_backoff_ms = ONE_MINUTE;
3131
- const {
3132
- stack: stack
3133
- } = new Error();
3134
- const calculate_retry = delay => {
3135
- delay *= 2 + Math.random();
3136
- if (delay > max_backoff_ms) delay = max_backoff_ms * (1 + Math.random() / 10);
3137
- return delay;
3138
- };
3139
- let try_again_in_ms = 100;
3140
- let has_succeeded = false;
3141
- let result = false;
3142
- while (max_retries && !has_succeeded) try {
3143
- const response = await useFetch(url, options);
3144
- const {
3145
- status: status,
3146
- ok: ok
3147
- } = response;
3148
- if (!response || !ok || status !== 200) {
3149
- if (status >= 400 && status < 500) {
3150
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9($d2fc3fb450961938$var$send_sentry_4xx)(response, options?.body || {}, stack);
3151
- has_succeeded = true;
3152
- } else if (status === 404) has_succeeded = true;
3153
- $e6c6e7929ea385ae$export$de56f1198d121036("Response not ok", response);
3154
- } else has_succeeded = true;
3155
- result = response;
3156
- } catch (error) {
3157
- $e6c6e7929ea385ae$export$de56f1198d121036("Error while fetching: ", error, url, options);
3158
- // Don't retry CORS
3159
- if (error.message.includes("CORS") && error.name.includes("CORS")) has_succeeded = true;
3160
- } finally {
3161
- if (!has_succeeded) await $55769f63ea4d8da4$export$5c069c93d2b7493f(try_again_in_ms);
3162
- try_again_in_ms = calculate_retry(try_again_in_ms);
3163
- max_retries -= 1;
3164
- }
3165
- return result;
3166
- }
3167
- async function $d2fc3fb450961938$var$send_sentry_4xx(response, body, stack) {
3168
- if (process.env.TENANT === "shopify-config" && response.status === 403)
3169
- // Don't send requests in the shopify admin that say we need to re-authorize to sentry
3170
- return;
3171
- const msg = `Validation error: got 4XX from API`;
3172
- const text = await response.clone().text();
3173
- $e6c6e7929ea385ae$export$de56f1198d121036(msg, "body", body, "response", response, "text", text, "stack", stack);
3174
- (0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).withScope(function (scope) {
3175
- scope.setExtra("stack", stack);
3176
- scope.setExtra("request_body", body);
3177
- scope.setExtra("response", response);
3178
- scope.setExtra("serialized_response", $45e05ec4fd7f1ee7$export$39d526a1194b6499(response));
3179
- scope.setExtra("response_text", text);
3180
- scope.setLevel("error");
3181
- this.captureException(new Error(msg));
3182
- });
3183
- }
3184
- async function $94edfb6d9c42a288$export$1bc0df10745d5412(t, options, headers, get_url = $94edfb6d9c42a288$var$default_get_fetch_url) {
3185
- const res = await $94edfb6d9c42a288$export$d40679eb4cf32f09(t, options, headers, get_url);
3186
- return res?.displays || [];
3187
- }
3188
- async function $94edfb6d9c42a288$export$d40679eb4cf32f09(t, options, headers, get_url = $94edfb6d9c42a288$var$default_get_fetch_url) {
3189
- const session_id = options.session_id || $e0a87646d12cb987$export$61e7e1f11e96692f();
3190
- const body = {
3191
- tenant: t.tenant,
3192
- market: t.market,
3193
- session_id: session_id,
3194
- document_referrer: document.referrer,
3195
- ...options
3196
- };
3197
- const endpoint = $94edfb6d9c42a288$var$get_fetch_endpoint_from_options(options);
3198
- return await $d2fc3fb450961938$export$bcd70d5ed1cf6313(get_url(endpoint), {
3199
- body: JSON.stringify(body),
3200
- ...(headers ? {
3201
- headers: headers
3202
- } : {}),
3203
- method: "POST"
3204
- }) // @ts-ignore
3205
- .then(r => r.json()).catch(e => $e6c6e7929ea385ae$export$de56f1198d121036("fetch_retry threw", e));
3206
- }
3207
- function $94edfb6d9c42a288$var$default_get_fetch_url(type) {
3208
- return $e4a18bf12ad092d9$export$fe609f0216e4ebef(`${(0, $4c6861fbcd3a0611$export$362abebb4b313340)}/v2/recommend/products/${type}`);
3209
- }
3210
- function $94edfb6d9c42a288$var$get_fetch_endpoint_from_options(options) {
3211
- if (options["category_id"] !== undefined) return "category";else if (options["product_id"] !== undefined) return "product";else if (options["product_ids"] !== undefined) return "products";
3212
- return "general";
3213
- }
3214
- async function $558ccd2de887e6d9$export$a9fc160c5ed83bd7(t, rendering_options) {
3215
- // clone options to prevent nasty bugs where changes of options change the options somewhere else too
3216
- rendering_options = $558ccd2de887e6d9$export$c42139a43c877ecd(rendering_options);
3217
- const {
3218
- type: type
3219
- } = rendering_options;
3220
- const displays = await $558ccd2de887e6d9$var$make_sure_we_have_displays(t, rendering_options);
3221
- if (!displays?.length) {
3222
- $e6c6e7929ea385ae$export$de56f1198d121036("RR: Got no displays for type " + type + ", can't recover.", t, rendering_options);
3223
- return {};
3224
- }
3225
- // return if too few displays
3226
- const {
3227
- min_items_to_run: min_items_to_run
3228
- } = rendering_options;
3229
- const good_displays = await $558ccd2de887e6d9$var$check_displays(displays, min_items_to_run).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
3230
- if (!good_displays) return {};
3231
- const processed_displays = await $558ccd2de887e6d9$export$c22e610107c5a15a(t, rendering_options, displays);
3232
- if (!processed_displays.length) {
3233
- $e6c6e7929ea385ae$export$de56f1198d121036("RR: No displays left after preprocessing");
3234
- return {};
3235
- }
3236
- const {
3237
- template: template,
3238
- post_processors = []
3239
- } = rendering_options;
3240
- const caught_post_processing_functions = post_processors.map(post_pro => $268cbd9e4ade92db$export$b3bbfd758f11cfa9(post_pro));
3241
- let a;
3242
- const caught_html2elems = $268cbd9e4ade92db$export$b3bbfd758f11cfa9((0, $bf7f12fe044e41b2$export$44951404cb8d0583));
3243
- let output_elements;
3244
- if (typeof template === "function") {
3245
- const caught_template = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(template);
3246
- output_elements = (await Promise.allSettled(processed_displays.map(async (display, index) => {
3247
- const event_listeners = [];
3248
- let keep = true;
3249
- const info = new $558ccd2de887e6d9$export$da854280fb61cd32(t, rendering_options, displays, index, () => keep = false, event_listeners);
3250
- const template_result = await caught_template(display, info);
3251
- if (!keep) throw keep;
3252
- const elements = (typeof template_result == "string" ? caught_html2elems(template_result) : template_result) || [];
3253
- const post_processed_elements = await $558ccd2de887e6d9$export$cf7cbc6b76039101(t, rendering_options, processed_displays, index, caught_post_processing_functions, elements, event_listeners);
3254
- return Array.from(post_processed_elements);
3255
- }))).filter(p => p.status === "fulfilled").map(p => p.value).flat();
3256
- // I don't want to use anything using spread since spread is a nice form of apply and
3257
- // there's a - browser engine dependant - limit of arguments that can be applied to a function
3258
- // we don't know how this will be used and want it to be robust
3259
- } else output_elements = (await Promise.all(processed_displays.map(async (display, index) => {
3260
- const html = $558ccd2de887e6d9$export$e0009e7da572f99b(template, display);
3261
- const elements = caught_html2elems(html) || [];
3262
- const post_processed_elements = await $558ccd2de887e6d9$export$cf7cbc6b76039101(t, rendering_options, processed_displays, index, caught_post_processing_functions, elements);
3263
- return Array.from(post_processed_elements);
3264
- }))).flat();
3265
- if (!output_elements.length) {
3266
- $e6c6e7929ea385ae$export$de56f1198d121036("RR: No displays left after postprocessing/rendering");
3267
- return {};
3268
- }
3269
- return {
3270
- elements: output_elements,
3271
- displays: processed_displays
3272
- };
3273
- }
3274
- function $558ccd2de887e6d9$export$e0009e7da572f99b(template, display = {}) {
3275
- const discount_matcher = /{DISCOUNT{([\s\S]+?)}}/g;
3276
- const no_discount_matcher = /{NODISCOUNT{([\s\S]+?)}}/g;
3277
- if ("variant_index" in display) throw new Error("Modern display in ancient templating");
3278
- const {
3279
- sale_price: sale_price,
3280
- original_price: original_price
3281
- } = display;
3282
- if (sale_price !== original_price) template = template.replaceAll(discount_matcher, "$1").replaceAll(no_discount_matcher, "");else template = template.replaceAll(discount_matcher, "").replaceAll(no_discount_matcher, "$1");
3283
- // Conditional statements
3284
- // {if VAR_NAME}
3285
- // print this if true
3286
- // {else}
3287
- // print this if false
3288
- // {end}
3289
- // Note: these can't be nested. Else statement is optional
3290
- template = template.replace(/{if\s+(.+?)}([\S\s]*?)(?:{else}([\S\s]*?))?{end}/g, (_, variable, if_yes, if_no) => {
3291
- if (typeof if_no !== "string")
3292
- // if_no is a number if there's no {else} statement
3293
- if_no = "";
3294
- return display[variable] ? if_yes : if_no;
3295
- });
3296
- return template.replace(/\${(.*?)}/g, (_, g) => display[g] ?? "");
3297
- // this is copied from here, I hope I'm not breaking any licenses. Need it to transpile for IE11 compatiblity:
3298
- // https://github.com/mikemaccana/dynamic-template/blob/master/index.js
3299
- }
3300
-
3301
- function $558ccd2de887e6d9$export$c42139a43c877ecd(obj) {
3302
- if (obj && typeof obj === "object" && !(obj instanceof Promise)) {
3303
- // @ts-ignore (I don't know how to type this)
3304
- const new_obj = Object.assign(new obj.constructor(), obj);
3305
- for (const key in new_obj) if (typeof new_obj[key] === "object") new_obj[key] = $558ccd2de887e6d9$export$c42139a43c877ecd(new_obj[key]);
3306
- return new_obj;
3307
- }
3308
- return obj;
3309
- }
3310
- async function $558ccd2de887e6d9$export$cf7cbc6b76039101(t, rendering_options, displays, index, functions, elements, event_listeners = []) {
3311
- let keep = true;
3312
- const info = new $558ccd2de887e6d9$export$da854280fb61cd32(t, rendering_options, displays, index, () => keep = false, event_listeners);
3313
- for (let i = 0; i < functions.length; i++) {
3314
- const result = await functions[i](elements, displays[index], info);
3315
- if (result) elements = result;
3316
- if (!keep) break;
3317
- }
3318
- if (keep) {
3319
- for (let i = 0; i < event_listeners.length; i++) for (let j = 0; j < elements.length; j++) elements[j].addEventListener(...event_listeners[i]);
3320
- }
3321
- return keep ? elements : [];
3322
- }
3323
- async function $558ccd2de887e6d9$export$c22e610107c5a15a(t, rendering_options, displays) {
3324
- const {
3325
- max_items: max_items,
3326
- pre_processors = []
3327
- } = rendering_options;
3328
- const caught_pre_processors = pre_processors.map(pre_pro => $268cbd9e4ade92db$export$b3bbfd758f11cfa9(pre_pro));
3329
- const processed_displays = [];
3330
- for (let i = 0; i < displays.length; i++) {
3331
- // classic for loop is both fast and can be stopped with break
3332
- let keep = true;
3333
- const info_for_pre_pro = new $558ccd2de887e6d9$export$da854280fb61cd32(t, rendering_options, displays, i, () => keep = false);
3334
- let display = displays[i];
3335
- for (let j = 0; j < caught_pre_processors.length; j++) {
3336
- const pre_processor = caught_pre_processors[j];
3337
- const result = await pre_processor(display, info_for_pre_pro);
3338
- if (result) display = result; // Don't understand why this cast is needed
3339
- if (!keep) break;
3340
- }
3341
- if (keep) processed_displays.push(display);
3342
- if (processed_displays.length >= max_items) break;
3343
- }
3344
- return processed_displays;
3345
- }
3346
- class $558ccd2de887e6d9$export$da854280fb61cd32 {
3347
- constructor(t, rendering_options, displays, index, remove_display, event_listeners) {
3348
- // @ts-ignore Support for no-tenant recommendation rendering for js-ui/react-ui
3349
- this.t = t;
3350
- this.rendering_options = rendering_options;
3351
- this.displays = displays;
3352
- if (index != null) this.index = index;
3353
- if (remove_display) this.remove_display = remove_display;
3354
- if (event_listeners) {
3355
- this.event_listeners = event_listeners;
3356
- this.register_event_listener = (...args) => this.event_listeners.push(args);
3357
- }
3358
- }
3359
- }
3360
- async function $558ccd2de887e6d9$var$check_displays(displays, min_items_to_run) {
3361
- // don't run if too few recs
3362
- if (min_items_to_run && displays.length < min_items_to_run) {
3363
- $e6c6e7929ea385ae$export$de56f1198d121036("RR: Got too few displays, exiting");
3364
- return false;
3365
- }
3366
- return true;
3367
- }
3368
- async function $558ccd2de887e6d9$var$make_sure_we_have_displays(t, rendering_options) {
3369
- const recs = await rendering_options.recs;
3370
- if (Array.isArray(recs)) return $558ccd2de887e6d9$export$c42139a43c877ecd(recs);
3371
- if (!t)
3372
- // No recs and no tenant, so we can't get any. Should never happen.
3373
- return [];
3374
- // get displays with get_displays if none are provided
3375
- const get_displays_options = {
3376
- type: rendering_options.type,
3377
- ...(rendering_options.extra_api_options || {})
3378
- };
3379
- for (const key of ["product_ids", "category_id", "product_id"]) if (key in rendering_options) get_displays_options[key] = rendering_options[key];
3380
- return await $94edfb6d9c42a288$export$1bc0df10745d5412(t, get_displays_options, rendering_options.headers || {}).catch(t.err);
3381
- }
3382
- async function $e5479d0db39d328b$export$c83d8da642b5104a(t, options, GWVM_opts) {
3383
- const {
3384
- catchify: catchify,
3385
- dlog: dlog,
3386
- is_debug: is_debug
3387
- } = t;
3388
- const {
3389
- container_selector = ".grid",
3390
- container_template: container_template,
3391
- start_rows = 1,
3392
- rows_per_click = 1,
3393
- override_rec_renderer: override_rec_renderer,
3394
- button: button,
3395
- title: title,
3396
- title_selector: title_selector,
3397
- only_full_rows = false,
3398
- should_preload = true
3399
- } = GWVM_opts;
3400
- const outer_els = typeof container_template === "string" ? [...$bf7f12fe044e41b2$export$44951404cb8d0583(container_template)] : container_template;
3401
- const [root] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(outer_els, container_selector);
3402
- const cut_off_promise_obj = /*@__PURE__*/new (0, $04a37742898e4bd5$export$32ccf3a614c84258)();
3403
- const i_observer = new IntersectionObserver(catchify($e5479d0db39d328b$var$observer_callback));
3404
- let cut_off_point = 0;
3405
- const recs_per_row = () => typeof GWVM_opts.recs_per_row === "function" ? GWVM_opts.recs_per_row(cut_off_point) : GWVM_opts.recs_per_row ?? 6;
3406
- cut_off_point = recs_per_row() * start_rows;
3407
- const get_show_next_num = () => recs_per_row() * rows_per_click;
3408
- const preload_next_row = catchify(() => {
3409
- const preload_these = [...rendering_results.displays].slice(cut_off_point, cut_off_point + get_show_next_num());
3410
- for (const elem of preload_these) {
3411
- const img = new Image();
3412
- img.src = elem.image_url;
3413
- // Element should be garbage collected, and the image source put in cache
3414
- // https://stackoverflow.com/questions/3646036/preloading-images-with-javascript
3415
- }
3416
- });
3417
-
3418
- const load_more = catchify(num => {
3419
- const adds = typeof num == "number" ? num : get_show_next_num();
3420
- cut_off_point += adds;
3421
- cut_off_promise_obj.resolve(cut_off_point);
3422
- if ((only_full_rows ? cut_off_point + adds : cut_off_point) >= displays.length)
3423
- // TODO: make it remove/add back the button depending on viewport
3424
- load_more_cont.remove();
3425
- if (adds > 0 && should_preload) preload_next_row();
3426
- });
3427
- const our_post_pro = (elements, display, info) => $e5479d0db39d328b$var$post_processor(elements, display, info, cut_off_point, i_observer, cut_off_promise_obj, load_more);
3428
- const rendering_results = await (override_rec_renderer || (0, $558ccd2de887e6d9$export$a9fc160c5ed83bd7))(t, {
3429
- ...options,
3430
- post_processors: [our_post_pro, ...(options.post_processors || [])]
3431
- });
3432
- const {
3433
- elements: rendered_elements,
3434
- displays: displays
3435
- } = rendering_results;
3436
- if (!rendered_elements) {
3437
- dlog("Grid with view more is stopping because it got no elements");
3438
- return rendering_results;
3439
- }
3440
- root.append(...rendered_elements);
3441
- const load_more_cont = $bf7f12fe044e41b2$export$d3e2a0560cbf4787(`<div class="load-more-container"></div>`);
3442
- const button_element = button instanceof Element ? button : $bf7f12fe044e41b2$export$d3e2a0560cbf4787(`<button class="load_more">${button || "Visa mer"}</button>`);
3443
- button_element.addEventListener("click", load_more);
3444
- load_more_cont.append(button_element);
3445
- root.after(load_more_cont);
3446
- if (should_preload) {
3447
- const load_more_intersection = async (entries, intersection_observer) => {
3448
- // Multiple observe calls could potentially (?) be batched into one fn call, so check everything
3449
- let intersected = false;
3450
- for (let i = 0; i < entries.length; i++) if (entries[i].isIntersecting) {
3451
- intersected = true;
3452
- break;
3453
- }
3454
- if (!intersected) return;
3455
- preload_next_row();
3456
- intersection_observer.disconnect(); // The load_more button has its own preload call, so this only needs to happen the first time.
3457
- };
3458
-
3459
- const load_more_observer = new IntersectionObserver(catchify(load_more_intersection));
3460
- load_more_observer.observe(load_more_cont);
3461
- }
3462
- if (title) {
3463
- const [title_el] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(outer_els, title_selector || "h1.title");
3464
- if (title_el) {
3465
- if (title instanceof Element) title_el.replaceWith(title);else title_el.innerText = title;
3466
- } else if (is_debug) {
3467
- console.error("GWVM: Title set but couldn't find title element. Please specify title_selector", () => {});
3468
- console.trace();
3469
- }
3470
- }
3471
- return {
3472
- ...rendering_results,
3473
- elements: outer_els,
3474
- load_more: load_more
3475
- };
3476
- }
3477
- function $e5479d0db39d328b$var$observer_callback(entries) {
3478
- for (let i = 0; i < entries.length; i++) if (entries[i].isIntersecting) {
3479
- const target = entries[i].target;
3480
- if (!target.src?.length && target.dataset?.src?.length) {
3481
- target.src = target.dataset.src;
3482
- target.removeAttribute("data-src");
3483
- }
3484
- }
3485
- }
3486
- function $e5479d0db39d328b$var$post_processor(elements, _,
3487
- //display: display,
3488
- info, cut_off_point, i_observer, cut_off_promise_obj, load_more) {
3489
- const {
3490
- catchify: catchify,
3491
- err: err,
3492
- dlog: dlog
3493
- } = info.t;
3494
- const {
3495
- index: index
3496
- } = info;
3497
- const elements_arr = [...elements];
3498
- const [an_element_node] = elements_arr.filter(node => node.nodeType == Node.ELEMENT_NODE);
3499
- const is_initially_hidden = index + 1 > cut_off_point;
3500
- const extras = info.extras ||= {};
3501
- extras.load_more ||= load_more;
3502
- extras.load_more_ipo ||= cut_off_promise_obj;
3503
- $bf7f12fe044e41b2$export$5e63aea0cac01fa0(elements_arr, "img:not(.filler):not(.ngl):not(.nolazy)").forEach(image => {
3504
- // "img" also selects "image" in IE11 which can be an SVG element which doesn't have a src property, therefore optional chaining
3505
- if ((image?.src?.length || image?.dataset?.src) && image?.src?.substr?.(0, 6) != "data:") {
3506
- if (is_initially_hidden && !image?.dataset.src) {
3507
- image.dataset.src = image.src;
3508
- image.removeAttribute("src");
3509
- }
3510
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element(an_element_node).then(catchify(el => {
3511
- if (el?.offsetParent !== null) image.src ||= image.dataset.src;else i_observer.observe(image);
3512
- }));
3513
- }
3514
- });
3515
- (async function () {
3516
- if (is_initially_hidden) for (let i = 0; i < elements_arr.length; i++) {
3517
- // HTMLElement is a lie, but TS is too dumb to understand that we check for it being a Node the line below this
3518
- const {
3519
- style: style
3520
- } = elements_arr[i];
3521
- if (style) style.display = "none";
3522
- }
3523
- while (true) {
3524
- cut_off_point = await cut_off_promise_obj.promise;
3525
- extras.load_more_currently_showing = cut_off_point;
3526
- if (index + 1 <= cut_off_point) {
3527
- for (let i = 0; i < elements_arr.length; i++) {
3528
- const {
3529
- style: style
3530
- } = elements_arr[i];
3531
- if (style) style.display = "";
3532
- }
3533
- break;
3534
- }
3535
- }
3536
- })().catch(err);
3537
- return elements;
3538
- }
3539
- async function $d1ef5fbddf08305d$export$41de2959a8dd405d(t, options, GWVM_opts, {
3540
- rec_selector = ".rec_outer"
3541
- } = {}) {
3542
- const {
3543
- start_rows: wished_start_rows = 1
3544
- } = GWVM_opts;
3545
- const {
3546
- dlog: dlog,
3547
- err: err,
3548
- catchify: catchify
3549
- } = t;
3550
- let result;
3551
- let rec;
3552
- let first = true;
3553
- const modified_GWVM_opts = {
3554
- ...GWVM_opts,
3555
- start_rows: 1 / 6,
3556
- recs_per_row(num) {
3557
- try {
3558
- if (result?.elements && rec) {
3559
- let {
3560
- parentElement: parentElement
3561
- } = rec;
3562
- if (!parentElement) {
3563
- // first rec was removed
3564
- [rec] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(result?.elements || [], rec_selector);
3565
- parentElement = rec?.parentElement;
3566
- if (!parentElement) throw new Error("Could not find element matching " + rec_selector + "to calculate width");
3567
- }
3568
- const recs_fitting_in_row = Math.floor(parentElement.getBoundingClientRect().width / Math.floor(rec.getBoundingClientRect().width));
3569
- // this is not entirely accurate because of margins but seems to work 100% of the time for our use case
3570
- if (recs_fitting_in_row != Infinity) {
3571
- dlog("We think there are currently", recs_fitting_in_row, "columns");
3572
- const {
3573
- children: children
3574
- } = parentElement;
3575
- const last_visible = $d1ef5fbddf08305d$var$find_last_visible(children);
3576
- if (!last_visible) {
3577
- dlog("It seems like no elements are visible, not loading any");
3578
- return 0;
3579
- }
3580
- if (num % recs_fitting_in_row !== 0) {
3581
- // X % 0 is NaN, prevent this from happening
3582
- const fill_last_row = recs_fitting_in_row === 0 ? 0 : recs_fitting_in_row - num % recs_fitting_in_row;
3583
- result.load_more?.(fill_last_row + recs_fitting_in_row * (wished_start_rows - 1));
3584
- }
3585
- // Special case for when it's the first "load more" (which is automatically triggered)
3586
- if (num === 1 && first) {
3587
- first = false;
3588
- return 0;
3589
- }
3590
- return recs_fitting_in_row;
3591
- }
3592
- }
3593
- } catch (e) {
3594
- err(e);
3595
- }
3596
- return 6;
3597
- }
3598
- };
3599
- // @ts-ignore
3600
- result = await $e5479d0db39d328b$export$c83d8da642b5104a(t, options, modified_GWVM_opts);
3601
- if (!result?.elements)
3602
- // no chance in finding any elements, API didn't return recs
3603
- return result;
3604
- if (typeof result?.load_more == "function") (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element(rec_selector).then(() => {
3605
- // we load 1 card to be able to determine the width
3606
- // in this situation recs_per_row will not return actual recs per row but recs_to_complete_row, so we add one card to get actual recs per row
3607
- // then we remove the one card again from total calculation
3608
- result.load_more?.();
3609
- });else err("Could not find recommendation to calculate recs per row. rec_selector: " + rec_selector);
3610
- return result;
3611
- }
3612
- function $d1ef5fbddf08305d$var$find_last_visible(items) {
3613
- for (let i = items.length - 1; i > -1; i--) {
3614
- // @ts-ignore
3615
- if (items[i]?.offsetParent !== null) return items[i];
3616
- }
3617
- }
3618
-
3619
- /**
3620
- * @deprecated use async_iterable_ipns instead. This can skip values which yields unexpected results.
3621
- */
3622
- function $7198207999c01453$export$55621c1ce3cd536b() {
3623
- // the idea is to have a new promise available immediately before one resolves, so to say an infinite promise
3624
- let internal_resolve; // copy and pasted from iconbeauty
3625
- const cart_promise_object = {
3626
- // I feel like Anton is not going to like this extremely awesome approach
3627
- promise: new Promise(r => internal_resolve = r),
3628
- // which is why I'm reluctant with making it a library
3629
- internal_resolve: internal_resolve,
3630
- // Edit from later on: I have realised that this is actually very useful, it just has a steep learning curve.
3631
- resolve: argument => {
3632
- // it allows both not having to call functions in a loop and instead just awaiting the promise from multiple places
3633
- const oldresolve = cart_promise_object.internal_resolve; // and to effortlessly ensure a process is never running twice with 100% reliability
3634
- cart_promise_object.promise = new Promise(r => cart_promise_object.internal_resolve = r); // it could be made a class, but I already know this works, so I'll leave it as is
3635
- oldresolve(argument);
3636
- }
3637
- };
3638
- return cart_promise_object;
3639
- }
3640
-
3641
- // import { buildThresholdList } from "../../helpers/build_threshold_list";
3642
-
3643
- async function $55dae85e9309db86$export$c0a4d29bc45a38c6(t, options, GWVM_opts, {
3644
- rec_selector = ".rec_outer"
3645
- } = {}) {
3646
- const options_for_auto_gwvm = {
3647
- ...GWVM_opts,
3648
- start_rows: 1
3649
- };
3650
- let all_rendered_elements = [];
3651
- options.post_processors = [...(options.post_processors || []), (elements, display, info) => {
3652
- all_rendered_elements.push(elements);
3653
- if (!info.index)
3654
- // the plan:
3655
- // observe first element - after dom insertion, count the visible elements and observe the last one thereof
3656
- // once it enters the view port, unobserve it
3657
- // once new elements have been loaded, count the visible elements - only once tho, in response of the first one being visible
3658
- // then attach to last element again and repeat
3659
- $55dae85e9309db86$var$observe_first_el_after_dominsertion(all_rendered_elements, elements, info.extras.load_more);
3660
- return elements;
3661
- }];
3662
- return await $d1ef5fbddf08305d$export$41de2959a8dd405d(t, options, options_for_auto_gwvm, {
3663
- rec_selector: rec_selector
3664
- });
3665
- }
3666
- function $55dae85e9309db86$var$observe_first_el_after_dominsertion(all_rendered_elements, elements, load_more) {
3667
- const element = $55dae85e9309db86$var$find_html_element(elements);
3668
- if (!element) {
3669
- $e6c6e7929ea385ae$export$de56f1198d121036("Infinite scroll won't work, couldn't find element to observe", elements);
3670
- return;
3671
- }
3672
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element(element).then($268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
3673
- $55dae85e9309db86$var$find_last_el_and_observe(all_rendered_elements, load_more);
3674
- }));
3675
- }
3676
- function $55dae85e9309db86$var$find_last_el_and_observe(all_rendered_elements, load_more) {
3677
- const last_visible_el = $55dae85e9309db86$var$find_last_visible(all_rendered_elements);
3678
- if (!last_visible_el) return;
3679
- const i_o = new IntersectionObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(records => {
3680
- for (const record of records) if (record.isIntersecting) {
3681
- $e6c6e7929ea385ae$export$de56f1198d121036("loading more because of", record);
3682
- load_more();
3683
- setTimeout($268cbd9e4ade92db$export$b3bbfd758f11cfa9($55dae85e9309db86$var$find_last_el_and_observe), 0, all_rendered_elements, load_more);
3684
- i_o.disconnect();
3685
- }
3686
- }));
3687
- i_o.observe(last_visible_el);
3688
- }
3689
- function $55dae85e9309db86$var$find_html_element(elements) {
3690
- // intersection observers don't work on text nodes
3691
- let element;
3692
- for (let i = 0; !((element = elements[i++]) instanceof HTMLElement) && element;);
3693
- return element;
3694
- }
3695
- function $55dae85e9309db86$var$find_last_visible(bunch_of_elements) {
3696
- const considered_elements = bunch_of_elements.map(els => $55dae85e9309db86$var$find_html_element(els));
3697
- // this is a potentially dangerous assumption - that the visibility status of the first element is the same as all other elements, but it should be true 100% of the time right now since GWVM sets display: none uniformally and why tf would you want it differently?
3698
- for (let i = 0; i < considered_elements.length; i++) {
3699
- const respected_element = considered_elements[i];
3700
- if (!respected_element) {
3701
- $e6c6e7929ea385ae$export$de56f1198d121036("Infinite scroll error: couldn't find last visible element", bunch_of_elements);
3702
- return;
3703
- }
3704
- if (respected_element.offsetParent === null) {
3705
- if (!i) {
3706
- // if index is 0 and we are not visible don't return the element at index -1 from the array - shit will hit the fan. Return the first one and everything should work out fine
3707
- $e6c6e7929ea385ae$export$de56f1198d121036("Inf scroll: No elements visible, ", considered_elements, "will attach to first el", respected_element);
3708
- return considered_elements[i];
3709
- }
3710
- return considered_elements[i - 1];
3711
- }
3712
- }
3713
- $e6c6e7929ea385ae$export$de56f1198d121036("Seems like all elements are loaded");
3714
- }
3715
- async function $8686e45614d71607$export$9eae832ae57fbf(t, css, extra_html) {
3716
- const head = await (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element("head"),
3717
- {
3718
- dlog: dlog
3719
- } = t,
3720
- elems = $bf7f12fe044e41b2$export$44951404cb8d0583(`<style type="text/css">${css}</style>` + (extra_html ? extra_html : ""));
3721
- dlog("inserting", ...elems, "into", head);
3722
- head.append(...elems);
3723
- }
3724
- function $807b852d8decb547$export$c7187bbd1a7a9244(...args) {
3725
- $807b852d8decb547$var$placeholder_worker(...args).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
3726
- return args[0];
3727
- }
3728
- async function $807b852d8decb547$var$placeholder_worker(placeholder_elements, final_elements, switching_trigger) {
3729
- let state = false;
3730
- let has_sanitized_elements = false;
3731
- const sanit_el_if_needed = async () => {
3732
- if (!has_sanitized_elements) {
3733
- has_sanitized_elements = true;
3734
- placeholder_elements = await $807b852d8decb547$var$convert_to_node_array(placeholder_elements);
3735
- final_elements = await $807b852d8decb547$var$convert_to_node_array(final_elements);
3736
- }
3737
- };
3738
- if (switching_trigger instanceof (0, $04a37742898e4bd5$export$32ccf3a614c84258)) while (true) {
3739
- const new_state = await switching_trigger.promise;
3740
- if (new_state != state) {
3741
- await sanit_el_if_needed();
3742
- await $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, new_state);
3743
- state = new_state;
3744
- }
3745
- } else if (switching_trigger instanceof Promise) {
3746
- const new_state = await switching_trigger;
3747
- if (state != new_state) {
3748
- await sanit_el_if_needed();
3749
- await $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, new_state);
3750
- state = new_state;
3751
- }
3752
- } else {
3753
- await sanit_el_if_needed();
3754
- placeholder_elements[0].addEventListener("placeholder_switch", $41f528c04cc8a8da$export$535946eb77c946dd(async e => {
3755
- const new_state = e.detail.state;
3756
- if (state != new_state) {
3757
- await sanit_el_if_needed();
3758
- await $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, new_state);
3759
- state = new_state;
3760
- }
3761
- }));
3762
- }
3763
- }
3764
- async function $807b852d8decb547$var$convert_to_node_array(elements) {
3765
- if (typeof elements == "function") elements = elements();
3766
- elements = await elements;
3767
- if (typeof elements[Symbol.iterator] != "function") elements = [elements];
3768
- return elements;
3769
- }
3770
- async function $807b852d8decb547$var$decide_direction_and_switch(placeholder_elements, final_elements, switch_to_final) {
3771
- if (switch_to_final) $807b852d8decb547$var$switch_elements(placeholder_elements, final_elements);else $807b852d8decb547$var$switch_elements(final_elements, placeholder_elements);
3772
- }
3773
- function $807b852d8decb547$var$switch_elements(from, to) {
3774
- if (!from.length || !to.length) $e6c6e7929ea385ae$export$c2363754d4758444("Cannot switch elements as from or to is empty", from, to);
3775
- from[0].replaceWith(...to);
3776
- for (let i = 1; i < from.length; i++) from[i].remove();
3777
- }
3778
- class $1da560af170fb839$export$3be7054c61590ee3 {
3779
- #verbose = false;
3780
- #images_on_first_page = [];
3781
- #default_lazyfinder = (() => {
3782
- const class_this = this;
3783
- return {
3784
- unload(image) {
3785
- for (const element of [image, ...$1da560af170fb839$export$e4741190ccada479(image, "source")]) for (const attr of ["src", "srcset"]) {
3786
- // I spent 30 minutes on debugging and it turns out IE11 always returns undefined for HTMLImageElementWithLoaded.srcset
3787
- const attribute_value = element.getAttribute(attr);
3788
- if (attribute_value?.length) {
3789
- element.dataset[attr] = attribute_value;
3790
- element.removeAttribute(attr);
3791
- }
3792
- }
3793
- },
3794
- load: $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async image => {
3795
- for (const element of [...$1da560af170fb839$export$e4741190ccada479(image, "source"), image]) {
3796
- if ("loaded" in element) {
3797
- if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036(element, "is already loading, not loading again");
3798
- continue;
3799
- }
3800
- if (document?.body?.contains?.(image) === false) {
3801
- if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036(element, "has been removed from the DOM, can't load");
3802
- const {
3803
- elements: elements
3804
- } = class_this.lazyfinder;
3805
- const index = elements.indexOf(image);
3806
- if (index >= 0) elements.splice(index, 1);
3807
- continue;
3808
- }
3809
- const has_src = element.dataset?.src?.length;
3810
- const has_srcset = element.dataset?.srcset?.length;
3811
- if (has_src || has_srcset) {
3812
- if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036("Loading", element);
3813
- element.loaded = false;
3814
- // here it's of importance that we give the browser the srcset first, otherwise it (safari) might start loading the fallback src at first
3815
- if (has_srcset) {
3816
- // in Safari for some reason sometimes the .sizes attribute isn't set yet, like in https://www.notion.so/depictai/Pictures-in-recommendations-are-not-displayed-88e30e0f98de421e94b9eb273aea21dc. In that case, wait up to one event loop execution for it
3817
- if (!element.sizes) await new Promise(resolve => {
3818
- const mo = new MutationObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(_records => {
3819
- if (element.sizes) {
3820
- resolve();
3821
- mo.disconnect();
3822
- }
3823
- }));
3824
- mo.observe(element, {
3825
- attributes: true,
3826
- attributeFilter: ["sizes"]
3827
- });
3828
- setTimeout($268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
3829
- resolve(); // in case ResizeObserver doesn't set .sizes or something
3830
- mo.disconnect();
3831
- }));
3832
- });
3833
- element.setAttribute("srcset", element.dataset.srcset);
3834
- element.removeAttribute("data-srcset");
3835
- }
3836
- if (has_src) {
3837
- element.src = element.dataset.src;
3838
- element.removeAttribute("data-src");
3839
- }
3840
- class_this.intersection_observer.unobserve(element);
3841
- } else {
3842
- if (element.src?.startsWith?.("data:")) continue;
3843
- // This happens quite often for reasons unknown. One day we will figure out why, or replace this lazyloader with a new one/native.
3844
- if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036("Cannot load", element, "as it doesn't have a data-src or data-srcset attribute");
3845
- }
3846
- }
3847
- }),
3848
- get elements() {
3849
- // define ourselves away with an array containing all elements we find. Said array is "listening" and calling unload and add_load_event_listener on every pushed element
3850
- const lazyfinder_this = this;
3851
- const currently_existing = [];
3852
- Object.defineProperty(lazyfinder_this, "elements", {
3853
- value: currently_existing
3854
- });
3855
- class_this.start_observing_for_new_children_();
3856
- return currently_existing;
3857
- }
3858
- };
3859
- })();
3860
- #initiate_new_image(image) {
3861
- if (image.loaded === true || image.loaded === false) {
3862
- if (this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036("Not lazyloading", image, "because it was loaded before or is loading");
3863
- return;
3864
- }
3865
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9(this.lazyfinder.unload)(image);
3866
- this.#add_load_event_listener(image);
3867
- this.intersection_observer?.observe?.(image); // observe if observer already exists, otherwise it won't and start_observer will do it
3868
- }
2104
+ class $1da560af170fb839$export$3be7054c61590ee3 {
2105
+ #verbose = false;
2106
+ #images_on_first_page = [];
2107
+ #default_lazyfinder = (() => {
2108
+ const class_this = this;
2109
+ return {
2110
+ unload(image) {
2111
+ for (const element of [image, ...$1da560af170fb839$export$e4741190ccada479(image, "source")]) for (const attr of ["src", "srcset"]) {
2112
+ // I spent 30 minutes on debugging and it turns out IE11 always returns undefined for HTMLImageElementWithLoaded.srcset
2113
+ const attribute_value = element.getAttribute(attr);
2114
+ if (attribute_value?.length) {
2115
+ element.dataset[attr] = attribute_value;
2116
+ element.removeAttribute(attr);
2117
+ }
2118
+ }
2119
+ },
2120
+ load: $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async image => {
2121
+ for (const element of [...$1da560af170fb839$export$e4741190ccada479(image, "source"), image]) {
2122
+ if ("loaded" in element) {
2123
+ if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036(element, "is already loading, not loading again");
2124
+ continue;
2125
+ }
2126
+ if (document?.body?.contains?.(image) === false) {
2127
+ if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036(element, "has been removed from the DOM, can't load");
2128
+ const {
2129
+ elements: elements
2130
+ } = class_this.lazyfinder;
2131
+ const index = elements.indexOf(image);
2132
+ if (index >= 0) elements.splice(index, 1);
2133
+ continue;
2134
+ }
2135
+ const has_src = element.dataset?.src?.length;
2136
+ const has_srcset = element.dataset?.srcset?.length;
2137
+ if (has_src || has_srcset) {
2138
+ if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036("Loading", element);
2139
+ element.loaded = false;
2140
+ // here it's of importance that we give the browser the srcset first, otherwise it (safari) might start loading the fallback src at first
2141
+ if (has_srcset) {
2142
+ // in Safari for some reason sometimes the .sizes attribute isn't set yet, like in https://www.notion.so/depictai/Pictures-in-recommendations-are-not-displayed-88e30e0f98de421e94b9eb273aea21dc. In that case, wait up to one event loop execution for it
2143
+ if (!element.sizes) await new Promise(resolve => {
2144
+ const mo = new MutationObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(_records => {
2145
+ if (element.sizes) {
2146
+ resolve();
2147
+ mo.disconnect();
2148
+ }
2149
+ }));
2150
+ mo.observe(element, {
2151
+ attributes: true,
2152
+ attributeFilter: ["sizes"]
2153
+ });
2154
+ setTimeout($268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
2155
+ resolve(); // in case ResizeObserver doesn't set .sizes or something
2156
+ mo.disconnect();
2157
+ }));
2158
+ });
2159
+ element.setAttribute("srcset", element.dataset.srcset);
2160
+ element.removeAttribute("data-srcset");
2161
+ }
2162
+ if (has_src) {
2163
+ element.src = element.dataset.src;
2164
+ element.removeAttribute("data-src");
2165
+ }
2166
+ class_this.intersection_observer.unobserve(element);
2167
+ } else {
2168
+ if (element.src?.startsWith?.("data:")) continue;
2169
+ // This happens quite often for reasons unknown. One day we will figure out why, or replace this lazyloader with a new one/native.
2170
+ if (class_this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036("Cannot load", element, "as it doesn't have a data-src or data-srcset attribute");
2171
+ }
2172
+ }
2173
+ }),
2174
+ get elements() {
2175
+ // define ourselves away with an array containing all elements we find. Said array is "listening" and calling unload and add_load_event_listener on every pushed element
2176
+ const lazyfinder_this = this;
2177
+ const currently_existing = [];
2178
+ Object.defineProperty(lazyfinder_this, "elements", {
2179
+ value: currently_existing
2180
+ });
2181
+ class_this.start_observing_for_new_children_();
2182
+ return currently_existing;
2183
+ }
2184
+ };
2185
+ })();
2186
+ #initiate_new_image(image) {
2187
+ if (image.loaded === true || image.loaded === false) {
2188
+ if (this.#verbose) $e6c6e7929ea385ae$export$de56f1198d121036("Not lazyloading", image, "because it was loaded before or is loading");
2189
+ return;
2190
+ }
2191
+ $268cbd9e4ade92db$export$b3bbfd758f11cfa9(this.lazyfinder.unload)(image);
2192
+ this.#add_load_event_listener(image);
2193
+ this.intersection_observer?.observe?.(image); // observe if observer already exists, otherwise it won't and start_observer will do it
2194
+ }
3869
2195
 
3870
2196
  start_observing_for_new_children_(override_container) {
3871
2197
  // should ONLY run on our "stock" elements array and is therefore called if "elements" is get in it - which means it's being used
@@ -4388,535 +2714,57 @@ class $1683d0164abd7c1d$export$692b27c28639e5b9 {
4388
2714
  autoinvalidate_cache: autoinvalidate_cache
4389
2715
  }) {
4390
2716
  dist_to_hide_left && (this.dist_to_hide_left = dist_to_hide_left);
4391
- dist_to_hide_right && (this.dist_to_hide_right = dist_to_hide_right);
4392
- stepstoslide && (this.stepstoslide = stepstoslide);
4393
- center_target && (this.center_target = true);
4394
- mutation_plugins && (this.#mutation_plugins = mutation_plugins);
4395
- correct_bs_targets == false && (this.correct_bs_targets = correct_bs_targets);
4396
- if (button_elems) {
4397
- this.#elements.right_ = button_elems.right;
4398
- this.#elements.left_ = button_elems.left;
4399
- }
4400
- if (button_contents?.right) this.#elements.right_.append(...button_contents.right);
4401
- if (button_contents?.left) this.#elements.left_.append(...button_contents.left);
4402
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9(this.#create_element_structure).call(this, autoinvalidate_cache);
4403
- // @ts-ignore
4404
- this.#elements.sliding_el_.slider = this; // dunno if this is dumb? So far nordicagolf/kondomvaruhuset depend on it
4405
- // plugin functionality i.e. for dots
4406
- const constructor_args = arguments;
4407
- constructor_plugins?.forEach?.(mplugin => {
4408
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9(mplugin).call(this, constructor_args);
4409
- });
4410
- }
4411
- }
4412
- class $a69a5236b5814082$export$68babfc5be0de5da extends (0, $1683d0164abd7c1d$export$692b27c28639e5b9) {
4413
- constructor(options, lazyfier_options) {
4414
- super(options);
4415
- const lazy_promise = new Promise(r => {
4416
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(this.insert_here, ({
4417
- element: element,
4418
- disconnector: disconnector
4419
- }) => {
4420
- const i_o = new IntersectionObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(records => {
4421
- for (const record of records) if (record.intersectionRatio > 0) {
4422
- r(true);
4423
- i_o.disconnect();
4424
- disconnector();
4425
- return;
4426
- }
4427
- }),
4428
- // Fixes https://gitlab.com/depict-ai/depict.ai/-/merge_requests/5816/diffs, don't understand why
4429
- {
4430
- threshold: $0da0cad4f39e8f32$export$f8ea2e7b15b5d129(10)
4431
- });
4432
- i_o.observe(element);
4433
- });
4434
- });
4435
- this.lazyfier = new (0, $1da560af170fb839$export$3be7054c61590ee3)({
4436
- container: this.insert_here,
4437
- wait_for_dominsertion: lazy_promise,
4438
- ...(lazyfier_options || {})
4439
- });
4440
- }
4441
- }
4442
- const $04d2f7d9126af667$export$f37c58ab3d3e3b75 = [$04d2f7d9126af667$export$9e1caada6901f552, (0, $11ff7b46c1fb674c$export$d0efd8ed14f5c33), $04d2f7d9126af667$export$fb9afe9f540ae069, ...(process.env.GTAG_VIEW === "true" ? [$04d2f7d9126af667$export$1bffac19f9f0d6fc] : [])];
4443
- const $04d2f7d9126af667$export$6830ae1fbe21e589 = [$04d2f7d9126af667$export$e9106d6e723510d2, $04d2f7d9126af667$export$32eb5dd18e963410, (0, $44909e19109bf973$export$58c56fe2313fdbe3), ...(process.env.GTAG === "true" ? [$04d2f7d9126af667$export$8d72437623fef90c] : [])];
4444
- const $04d2f7d9126af667$export$ed8a68dacd075983 = /*@__PURE__*/new Map();
4445
- const $04d2f7d9126af667$export$4b50a4de9c6bbe09 = /*@__PURE__*/new WeakSet();
4446
- function $04d2f7d9126af667$export$fb9afe9f540ae069(elements, _display, info) {
4447
- if (!elements?.length) return elements;
4448
- if (!info.t) return elements;
4449
- const elements_as_array = [...elements];
4450
- const handler = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async () => {
4451
- const {
4452
- rendering_options: rendering_options,
4453
- t: t
4454
- } = info;
4455
- if (!$04d2f7d9126af667$export$4b50a4de9c6bbe09.has(rendering_options) && elements_as_array.some(e => document.documentElement.contains(e)) // check, just in case
4456
- ) {
4457
- $04d2f7d9126af667$export$4b50a4de9c6bbe09.add(rendering_options);
4458
- $e0a87646d12cb987$export$82badda1f9923310({
4459
- ...t,
4460
- product_id: await t.get_product_id(),
4461
- recommendation_type: info.rendering_options.type,
4462
- type: "recommendations_inserted"
4463
- });
4464
- }
4465
- });
4466
- $04d2f7d9126af667$var$push_function($04d2f7d9126af667$export$fb9afe9f540ae069, handler);
4467
- const first_el = elements_as_array?.[0];
4468
- if (first_el instanceof Node) (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element(first_el).then(handler);
4469
- return elements;
4470
- }
4471
- const $04d2f7d9126af667$export$3777a14dd8c2363d = /*@__PURE__*/new WeakSet();
4472
- function $04d2f7d9126af667$export$1bffac19f9f0d6fc(elements, _display, info) {
4473
- if (!elements?.length)
4474
- // don't make it hurt even more that rendering failed
4475
- return elements;
4476
- if (!info.t)
4477
- // GTAG tracking is deprecated, if we're doing no-tenant recommendation rendering it's SDK anyway.
4478
- return elements;
4479
- const [first_element] = elements;
4480
- const handler = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
4481
- const {
4482
- rendering_options: rendering_options,
4483
- displays: displays
4484
- } = info;
4485
- if (!$04d2f7d9126af667$export$3777a14dd8c2363d.has(displays)) {
4486
- $04d2f7d9126af667$export$3777a14dd8c2363d.add(displays);
4487
- const {
4488
- get_product_id: get_product_id
4489
- } = info.t;
4490
- const {
4491
- type: type
4492
- } = rendering_options;
4493
- $d3d8549954e0318e$export$7babcd5d4056b2ca(displays, get_product_id /* yes this might create errors if there's no page_url in the display but don't have time to fix, sorry */, {
4494
- list_name: "depict_" + type
4495
- });
4496
- }
4497
- });
4498
- $04d2f7d9126af667$var$push_function($04d2f7d9126af667$export$1bffac19f9f0d6fc, handler);
4499
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(first_element, handler);
4500
- return elements;
4501
- }
4502
- function $04d2f7d9126af667$export$9e1caada6901f552(elements, _display, info) {
4503
- const {
4504
- t: t
4505
- } = info;
4506
- if (!t) return elements;
4507
- (async () => {
4508
- $72ee205b59322497$export$eee4c4d924348b05({
4509
- tenant: t.tenant,
4510
- market: t.market,
4511
- product_id: await t.get_product_id()
4512
- }).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
4513
- })();
4514
- return elements;
4515
- }
4516
- function $04d2f7d9126af667$export$8d72437623fef90c(elements, display, info) {
4517
- const handler = () => {
4518
- const {
4519
- ga_product_ids: ga_product_ids,
4520
- ga_product_id: ga_product_id,
4521
- product_id: product_id
4522
- } = display;
4523
- if (Array.isArray(ga_product_ids)) for (let i = 0; i < ga_product_ids.length; i++) $d3d8549954e0318e$export$f522672c9379e339(ga_product_ids[i], info.index, {
4524
- list_name: "depict_" + info.rendering_options.type
4525
- });else $d3d8549954e0318e$export$f522672c9379e339(ga_product_id || product_id, info.index, {
4526
- list_name: "depict_" + info.rendering_options.type
4527
- });
4528
- };
4529
- $04d2f7d9126af667$var$push_function($04d2f7d9126af667$export$8d72437623fef90c, handler);
4530
- info.register_event_listener("click", handler, {
4531
- once: true
4532
- });
4533
- return elements;
4534
- }
4535
- function $04d2f7d9126af667$export$e9106d6e723510d2(elements, display, info) {
4536
- const handler = () => {
4537
- const {
4538
- t: t,
4539
- index: index,
4540
- rendering_options: rendering_options
4541
- } = info;
4542
- return $e0a87646d12cb987$export$15f8a0cd5a8c0ebb({
4543
- ...t,
4544
- ...rendering_options,
4545
- ...display,
4546
- click_location: rendering_options.type + "_" + (index + 1),
4547
- recommendation_type: rendering_options.type,
4548
- product_id: "variant_index" in display ? display.variant_displays[display.variant_index].product_id : display.product_id
4549
- });
4550
- };
4551
- $04d2f7d9126af667$var$push_function($04d2f7d9126af667$export$e9106d6e723510d2, handler);
4552
- info.register_event_listener("click", handler, {
4553
- once: true
4554
- });
4555
- return elements;
4556
- }
4557
- function $04d2f7d9126af667$export$32eb5dd18e963410(elements, display, info) {
4558
- const {
4559
- search_result_id: search_result_id
4560
- } = display;
4561
- const {
4562
- product_id: product_id,
4563
- recommendation_id: recommendation_id
4564
- } = "variant_index" in display ? display.variant_displays[display.variant_index] : display;
4565
- if (!elements?.length) return elements;
4566
- for (const element of elements) {
4567
- const handler = $c8263a2185830bf1$export$82a685f2da2fb027(element, product_id, recommendation_id || search_result_id);
4568
- if (handler) $04d2f7d9126af667$var$push_function($04d2f7d9126af667$export$32eb5dd18e963410, handler);
4569
- }
4570
- return elements;
4571
- }
4572
- function $04d2f7d9126af667$export$dd32cb565eae0a1f(elements, display, info) {
4573
- const handler = () => {
4574
- $d3d8549954e0318e$export$127751e82111fcf();
4575
- };
4576
- $04d2f7d9126af667$var$push_function($04d2f7d9126af667$export$dd32cb565eae0a1f, handler);
4577
- info.register_event_listener("click", handler, {
4578
- once: true
4579
- });
4580
- return elements;
4581
- }
4582
- function $04d2f7d9126af667$var$push_function(fn1, handler) {
4583
- const fn_array = $04d2f7d9126af667$export$ed8a68dacd075983.get(fn1) || [];
4584
- fn_array.push(new WeakRef(handler));
4585
- $04d2f7d9126af667$export$ed8a68dacd075983.set(fn1, fn_array);
4586
- }
4587
- const $f3f05d97149aec76$export$deca40f48c0569f8 = typeof window === "undefined" ? false : /*@__PURE__*/localStorage.getItem("colorize-logics") === "true";
4588
- function $f3f05d97149aec76$export$16501883f477737a(elements, display) {
4589
- elements.forEach(elem => {
4590
- if (elem.nodeType !== Node.TEXT_NODE) {
4591
- // calc a hash for given string
4592
- const hc = (str = "") => {
4593
- let hash = 0;
4594
- if (str.length === 0) return hash;
4595
- for (let i = 0; i < str.length; i++) {
4596
- const chr = str.charCodeAt(i);
4597
- hash = (hash << 5) - hash + chr;
4598
- hash |= 0;
4599
- }
4600
- return hash;
4601
- };
4602
- const hash = hc(display.logic);
4603
- // Change hue based on hash
4604
- const color = "hsl(" + hash % 360 + ",100%,75%)";
4605
- if ("style" in elem) elem.style.background = color;
4606
- // @ts-ignore
4607
- elem?.setAttribute?.("data-logic", display.logic);
4608
- // @ts-ignore
4609
- elem?.setAttribute?.("title", "Logic: " + display.logic);
4610
- }
4611
- });
4612
- return elements;
4613
- }
4614
- var $92bde32714bb1e07$export$2e2bcd8739ae039 = $92bde32714bb1e07$export$50ce83ace0cdd87e;
4615
- async function $92bde32714bb1e07$export$50ce83ace0cdd87e(t, rendering_options) {
4616
- const {
4617
- view_tracking: view_tracking,
4618
- click_tracking: click_tracking
4619
- } = rendering_options;
4620
- return await $558ccd2de887e6d9$export$a9fc160c5ed83bd7(t, {
4621
- ...rendering_options,
4622
- headers: {
4623
- ...((0, $f3f05d97149aec76$export$deca40f48c0569f8) ? {
4624
- "x-debug": "true"
4625
- } : {}),
4626
- ...(rendering_options.headers || {})
4627
- },
4628
- pre_processors: [...(rendering_options.pre_processors || [])],
4629
- post_processors: [...(Array.isArray(view_tracking) ? view_tracking : (0, $04d2f7d9126af667$export$f37c58ab3d3e3b75)), ...(Array.isArray(click_tracking) ? click_tracking : (0, $04d2f7d9126af667$export$6830ae1fbe21e589)), ...((0, $f3f05d97149aec76$export$deca40f48c0569f8) ? [(0, $f3f05d97149aec76$export$16501883f477737a)] : []), ...(rendering_options.post_processors || [])]
4630
- });
4631
- }
4632
- async function $3cb558cec98ba1a7$export$cab8bc58c64c2013(t, rendering_options, options_for_us, slider_options) {
4633
- options_for_us ||= {};
4634
- const {
4635
- root_selector: root_selector,
4636
- override_rec_renderer: local_rr = (0, $92bde32714bb1e07$export$2e2bcd8739ae039),
4637
- insertion_verb = "replaceWith",
4638
- lazyfier_options: lazyfier_options
4639
- } = options_for_us;
4640
- let {
4641
- container: container
4642
- } = options_for_us;
4643
- if (typeof container == "string") container = [...$bf7f12fe044e41b2$export$44951404cb8d0583(container)];
4644
- if (container && !Array.isArray(container)) container = [...container];
4645
- const slider = new (0, $a69a5236b5814082$export$68babfc5be0de5da)({
4646
- dist_to_hide_left: 10,
4647
- dist_to_hide_right: 10,
4648
- ...slider_options
4649
- }, lazyfier_options);
4650
- const recs = await local_rr(t, {
4651
- ...rendering_options,
4652
- post_processors: [(elements, display) => {
4653
- $bf7f12fe044e41b2$export$5e63aea0cac01fa0(elements, ".rec_outer").forEach(ro => ro.classList.add("noautospacing"));
4654
- return elements;
4655
- }, ...(rendering_options.post_processors || [])]
4656
- });
4657
- if (!recs.elements) {
4658
- $e6c6e7929ea385ae$export$de56f1198d121036("Pro_Slider says bye bye cuz no recs");
4659
- return {};
4660
- }
4661
- slider.insert_here.append(...recs.elements);
4662
- if (container) {
4663
- const [root] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(container, root_selector || ".grid");
4664
- root[insertion_verb](slider.container);
4665
- }
4666
- return {
4667
- ...recs,
4668
- displays: recs.displays,
4669
- elements: container ? container : [slider.container]
4670
- };
4671
- }
4672
- const $0b6a8303b64cced1$var$discountMatcher = /{DISCOUNT{([\s\S]+?)}}/g;
4673
- const $0b6a8303b64cced1$var$noDiscountMatcher = /{NODISCOUNT{([\s\S]+?)}}/g;
4674
- let $0b6a8303b64cced1$var$pageview_sent = false;
4675
- class $0b6a8303b64cced1$export$1a8782481a9af507 {
4676
- constructor(settings) {
4677
- this.settings = settings;
4678
- }
4679
- #dispatched_recs_inserted = false;
4680
- init(callback, existingDisplays) {
4681
- if (!this.settings.DNT) this.trackPageView();
4682
- if (!existingDisplays) this.loadRecommendations(callback);else {
4683
- this.data = existingDisplays;
4684
- callback();
4685
- }
4686
- }
4687
- loadRecommendations(callback) {
4688
- const {
4689
- tenant: tenant,
4690
- product_id: product_id,
4691
- type: type,
4692
- market: market
4693
- } = this.settings;
4694
- $94edfb6d9c42a288$export$1bc0df10745d5412(
4695
- // @ts-ignore - Quick workaround, as we don't have a tenant object here
4696
- {
4697
- tenant: tenant,
4698
- market: market
4699
- }, {
4700
- type: type,
4701
- product_id: product_id()
4702
- }).then(recs => {
4703
- this.data = recs;
4704
- $eee5951374097b61$export$8582cf3716962dc2({
4705
- ...this.settings,
4706
- recs: this.data,
4707
- min_recs: this.settings.min_items || this.settings.max_items
4708
- });
4709
- }).catch(e => {
4710
- if (this.settings.debug) console.warn("template-tool: error fetching: ", e);
4711
- }).finally(() => callback());
4712
- }
4713
- trackGAEvent(action, index, product_id, ga_product_ids) {
4714
- if (this.settings.sendGa === false) return;
4715
- // @ts-ignore
4716
- if (typeof ga !== "function") {
4717
- console.log("Could not send", action, "to GA. analytics.js not loaded.");
4718
- return;
4719
- }
4720
- if (!action || action instanceof Event) action = "rec_bar_click";
4721
- if (action == "rec_bar_click" && typeof index != "undefined" && product_id) {
4722
- if (Array.isArray(ga_product_ids)) for (const id of ga_product_ids) $d3d8549954e0318e$export$f522672c9379e339(id, index, {
4723
- list_name: "depict_" + this.settings.type
4724
- });else $d3d8549954e0318e$export$f522672c9379e339(product_id, index, {
4725
- list_name: "depict_" + this.settings.type
4726
- });
4727
- }
4728
- if (this.tracker === undefined)
4729
- // @ts-ignore
4730
- this.tracker = ga("create", this.settings.gaid, "auto", "depict");
4731
- $d3d8549954e0318e$export$f75172d2e289cd02(action);
4732
- }
4733
- trackPageView() {
4734
- if ($0b6a8303b64cced1$var$pageview_sent) {
4735
- if (this.settings.debug) console.log("template-tool: not sending page view tracking to depict as it has already been sent");
4736
- return;
2717
+ dist_to_hide_right && (this.dist_to_hide_right = dist_to_hide_right);
2718
+ stepstoslide && (this.stepstoslide = stepstoslide);
2719
+ center_target && (this.center_target = true);
2720
+ mutation_plugins && (this.#mutation_plugins = mutation_plugins);
2721
+ correct_bs_targets == false && (this.correct_bs_targets = correct_bs_targets);
2722
+ if (button_elems) {
2723
+ this.#elements.right_ = button_elems.right;
2724
+ this.#elements.left_ = button_elems.left;
4737
2725
  }
4738
- $0b6a8303b64cced1$var$pageview_sent = true;
4739
- const {
4740
- product_id: product_id
4741
- } = this.settings;
4742
- $72ee205b59322497$export$eee4c4d924348b05(typeof product_id === "function" ? product_id() : product_id);
4743
- }
4744
- trackClick(index) {
4745
- const item = this.data[index];
4746
- if (item === undefined) return;
4747
- return $e0a87646d12cb987$export$15f8a0cd5a8c0ebb({
4748
- ...this.settings,
4749
- ...item,
4750
- click_location: `${this.settings.type}_${index + 1}`,
4751
- product_id: item.product_id || this.settings.product_id(item.page_url)
4752
- });
4753
- }
4754
- trackAddToCart(pId) {
4755
- return $e0a87646d12cb987$export$9028351cb994757e({
4756
- ...this.settings,
4757
- product_id: pId && !(pId instanceof Event) ? pId : this.settings.product_id()
2726
+ if (button_contents?.right) this.#elements.right_.append(...button_contents.right);
2727
+ if (button_contents?.left) this.#elements.left_.append(...button_contents.left);
2728
+ $268cbd9e4ade92db$export$b3bbfd758f11cfa9(this.#create_element_structure).call(this, autoinvalidate_cache);
2729
+ // @ts-ignore
2730
+ this.#elements.sliding_el_.slider = this; // dunno if this is dumb? So far nordicagolf/kondomvaruhuset depend on it
2731
+ // plugin functionality i.e. for dots
2732
+ const constructor_args = arguments;
2733
+ constructor_plugins?.forEach?.(mplugin => {
2734
+ $268cbd9e4ade92db$export$b3bbfd758f11cfa9(mplugin).call(this, constructor_args);
4758
2735
  });
4759
2736
  }
4760
- createContainer(root, container, prepend = false) {
4761
- function htmlToElements(html) {
4762
- const template = document.createElement("template");
4763
- template.innerHTML = html;
4764
- return template.content.childNodes;
4765
- }
4766
- const elements = Array.from(htmlToElements(container));
4767
- if (prepend) {
4768
- elements.reverse();
4769
- for (const el of elements) root.prepend(el);
4770
- } else for (const el of elements) root.appendChild(el);
4771
- }
4772
- renderTemplate({
4773
- prep: prep,
4774
- root: root,
4775
- template: template,
4776
- itemPreprocessor: itemPreprocessor,
4777
- itemPostprocessor: itemPostprocessor
4778
- } = this.settings) {
4779
- if (document._depict_modify !== true) {
4780
- if (this.settings.debug) console.warn("Template-tool: not running because document._depict_modify is false!", this);
4781
- return;
4782
- }
4783
- if (!this.data) return;
4784
- const product_id_at_rendering = this.settings.product_id();
4785
- if (typeof prep === "function") prep();
4786
- const interpolator = t => {
4787
- return function (item) {
4788
- // Conditional statements
4789
- // {if VAR_NAME}
4790
- // print this if true
4791
- // {else}
4792
- // print this if false
4793
- // {end}
4794
- // Note: these can't be nested
4795
- t = t.replace(/{if\s+(.+?)}([\S\s]*?)(?:{else}([\S\s]*?))?{end}/g, (_, variable, if_yes, if_no) => {
4796
- if (typeof if_no !== "string")
4797
- // if_no is a number if there's no {else} statement
4798
- if_no = "";
4799
- return item[variable] ? if_yes : if_no;
4800
- });
4801
- return t.replace(/\${(.*?)}/g, (_, g) => item[g]); // this is copied from here, I hope I'm not breaking any licenses. Need it to transpile for IE11 compatiblity: https://github.com/mikemaccana/dynamic-template/blob/master/index.js
4802
- // if you need variables that go over multiple lines:
4803
- // const matcher = /\${([^}]+)}/g;
4804
- };
4805
- };
4806
-
4807
- const elementsFromHTML = html => new DOMParser().parseFromString(html, "text/html").body.children;
4808
- const getContent = () => {
4809
- const recsArray = [];
4810
- const resultingElements = [];
4811
- this.data.forEach((item, rec_index) => {
4812
- if (typeof itemPreprocessor === "function") {
4813
- item = itemPreprocessor(item, rec_index);
4814
- if (!Object.keys(item).length) {
4815
- if (this.settings.debug) console.info("template-tool: discarding display", item, "because it is empty");
2737
+ }
2738
+ class $a69a5236b5814082$export$68babfc5be0de5da extends (0, $1683d0164abd7c1d$export$692b27c28639e5b9) {
2739
+ constructor(options, lazyfier_options) {
2740
+ super(options);
2741
+ const lazy_promise = new Promise(r => {
2742
+ (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(this.insert_here, ({
2743
+ element: element,
2744
+ disconnector: disconnector
2745
+ }) => {
2746
+ const i_o = new IntersectionObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(records => {
2747
+ for (const record of records) if (record.intersectionRatio > 0) {
2748
+ r(true);
2749
+ i_o.disconnect();
2750
+ disconnector();
4816
2751
  return;
4817
2752
  }
4818
- }
4819
- if (recsArray.length >= this.settings.max_items) return;
4820
- recsArray.push(item);
4821
- let itemTemplate;
4822
- if (item.sale_price !== item.original_price) {
4823
- itemTemplate = template.replaceAll($0b6a8303b64cced1$var$discountMatcher, "$1").replaceAll($0b6a8303b64cced1$var$noDiscountMatcher, "");
4824
- item.discount = `\u{2013}${Math.round(100 * (1 - item.sale_price / item.original_price))}%`;
4825
- } else {
4826
- itemTemplate = template.replaceAll($0b6a8303b64cced1$var$discountMatcher, "").replaceAll($0b6a8303b64cced1$var$noDiscountMatcher, "$1");
4827
- item.discount = "";
4828
- }
4829
- const resultHTML = interpolator(itemTemplate)(item);
4830
- let elements = elementsFromHTML(resultHTML);
4831
- if (!this.settings.DNT) for (const element of elements) {
4832
- // recommendations_inserted event
4833
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).oncreation(element, () => {
4834
- if (!this.#dispatched_recs_inserted) {
4835
- this.#dispatched_recs_inserted = true;
4836
- $e0a87646d12cb987$export$82badda1f9923310({
4837
- ...this.settings,
4838
- product_id: product_id_at_rendering,
4839
- recommendation_type: this.settings.type,
4840
- type: "recommendations_inserted"
4841
- });
4842
- }
4843
- });
4844
- const listener = e => {
4845
- this.trackClick(rec_index);
4846
- this.trackGAEvent("rec_bar_click", rec_index, item.ga_product_id || item.product_id || this.settings.product_id(item.page_url), item.ga_product_ids);
4847
- };
4848
- element.addEventListener("click", listener);
4849
- $c8263a2185830bf1$export$82a685f2da2fb027(element, item.product_id, item.recommendation_id);
4850
- if (this.settings.shade) $fbb09973782881cb$export$6ebd242c09192cec(element);
4851
- // @ts-ignore
4852
- if (!element.depict_event_listeners)
4853
- // @ts-ignore
4854
- element.depict_event_listeners = [];
4855
- // @ts-ignore
4856
- element.depict_event_listeners.push(listener);
4857
- }
4858
- if (typeof itemPostprocessor === "function") elements = itemPostprocessor(elements, item);
4859
- resultingElements.push(...elements);
4860
- });
4861
- this.data = recsArray;
4862
- if (!this.settings.DNT) $d3d8549954e0318e$export$7babcd5d4056b2ca(recsArray, this.settings.product_id, {
4863
- list_name: "depict_" + this.settings.type
2753
+ }),
2754
+ // Fixes https://gitlab.com/depict-ai/depict.ai/-/merge_requests/5816/diffs, don't understand why
2755
+ {
2756
+ threshold: $0da0cad4f39e8f32$export$f8ea2e7b15b5d129(10)
2757
+ });
2758
+ i_o.observe(element);
4864
2759
  });
4865
- return resultingElements;
4866
- };
4867
- const renderedContent = getContent();
4868
- if (typeof root === "function") {
4869
- if (this.settings.loadHack === true) {
4870
- const SLEEP_TIME_MS = 50;
4871
- let MAX_RETRY = Math.round(10000 / SLEEP_TIME_MS);
4872
- const tick = setInterval(() => {
4873
- const r = root();
4874
- if (MAX_RETRY === 0) clearInterval(tick);
4875
- MAX_RETRY--;
4876
- if (r !== null) {
4877
- r.append(...renderedContent);
4878
- clearInterval(tick);
4879
- }
4880
- }, SLEEP_TIME_MS);
4881
- } else if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => {
4882
- const r = root();
4883
- r.append(...renderedContent);
4884
- }, {
4885
- once: true
4886
- });else {
4887
- const r = root();
4888
- r.append(...renderedContent);
4889
- }
4890
- return;
4891
- }
4892
- root.append(...renderedContent);
2760
+ });
2761
+ this.lazyfier = new (0, $1da560af170fb839$export$3be7054c61590ee3)({
2762
+ container: this.insert_here,
2763
+ wait_for_dominsertion: lazy_promise,
2764
+ ...(lazyfier_options || {})
2765
+ });
4893
2766
  }
4894
2767
  }
4895
- var
4896
- /**
4897
- * @deprecated Please use RecommendationRenderer instead
4898
- */
4899
- $52d3be7ce5146924$export$2e2bcd8739ae039 = async options => {
4900
- const depict = new (0, $0b6a8303b64cced1$export$1a8782481a9af507)(options.options),
4901
- done = new Promise(itsdone => {
4902
- document._depict_modify = true;
4903
- depict.init(() => {
4904
- depict.renderTemplate({
4905
- itemPostprocessor: options.postProcessor,
4906
- itemPreprocessor: options.preProcessor,
4907
- root: options.root,
4908
- template: options.template
4909
- });
4910
- itsdone();
4911
- }, options.recs);
4912
- });
4913
- await done;
4914
- return depict;
4915
- };
4916
-
4917
- // @ts-ignore
4918
- var $1c4a3b6d660e3905$exports = {};
4919
- $1c4a3b6d660e3905$exports = ".depict .rec_outer.noautospacing {\n width: 6cm;\n max-width: 46vw;\n margin-left: 1%;\n margin-right: 1%;\n}\n\n.depict .rec_outer.noautospacing:nth-child(1) {\n margin-left: 0;\n}\n\n.depict .rec_outer.noautospacing:nth-last-child(1) {\n margin-right: 0;\n}\n\n.depict-slider .slider_snap {\n scroll-snap-type: x mandatory;\n}\n\n.depict-slider {\n width: 100%;\n position: relative;\n}\n\n.depict-slider .sliding::-webkit-scrollbar {\n display: none;\n}\n\n.depict-slider .sliding {\n scroll-behavior: smooth;\n -ms-overflow-style: none;\n scrollbar-width: none;\n flex-flow: row;\n margin-top: -1%;\n margin-bottom: -2%;\n padding-top: 1%;\n padding-bottom: 2%;\n display: flex;\n overflow-x: scroll;\n}\n\n.depict-slider .sliding > * {\n box-sizing: border-box;\n flex: none;\n}\n\n.depict-slider button.right {\n right: 0;\n}\n\n.depict-slider button.left, .depict-slider button.right {\n z-index: 2;\n touch-action: manipulation;\n width: 1cm;\n height: 1cm;\n cursor: pointer;\n background: #fff;\n border: none;\n padding: .5%;\n transition-duration: .2s;\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n}\n\n.depict-slider button.left.hidden, .depict-slider button.right.hidden {\n opacity: 0;\n cursor: default;\n}\n\n.depict-slider button.left {\n left: 0;\n transform: translateY(-50%)rotate(180deg);\n}\n\n.depict-slider button.left img, .depict-slider button.right img {\n width: 100%;\n height: 100%;\n}\n\n.depict-slider .rec_outer {\n margin-top: 0 !important;\n}\n\n";
4920
2768
  const $e090b20cef3f0516$var$default_image_src = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMy4wLjYsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAxNiAxNiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTYgMTY7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwb2x5Z29uIHBvaW50cz0iOSwyLjYgOC4zLDMuNCAxMi40LDcuNSAxLjYsNy41IDEuNiw4LjUgMTIuNCw4LjUgOC4zLDEyLjYgOSwxMy40IDE0LjQsOCAiLz4NCjwvc3ZnPg0K";
4921
2769
  class $e090b20cef3f0516$export$4d41c6499d53639c extends (0, $a69a5236b5814082$export$68babfc5be0de5da) {
4922
2770
  constructor(static_options, override_lazyfier_options) {
@@ -4950,229 +2798,26 @@ function $e090b20cef3f0516$export$f1b8b9fd75ddcab1(slider) {
4950
2798
  style_elem.append((0, /*@__PURE__*/$parcel$interopDefault($1c4a3b6d660e3905$exports)));
4951
2799
  slider.container.appendChild(style_elem);
4952
2800
  }
4953
- async function $7af744346f17bf99$export$cd12721587f4f16d(t, rendering_options, options_for_us, slider_options, override_lazyfier_options) {
4954
- options_for_us ||= {};
4955
- const {
4956
- dlog: dlog,
4957
- catchify: catchify
4958
- } = t;
4959
- const {
4960
- root_selector: root_selector,
4961
- Rec_Renderer: local_rr = (0, $92bde32714bb1e07$export$2e2bcd8739ae039),
4962
- insertion_verb = "replaceWith"
4963
- } = options_for_us;
4964
- let {
4965
- container: container
4966
- } = options_for_us;
4967
- if (typeof container == "string") container = [...$bf7f12fe044e41b2$export$44951404cb8d0583(container)];
4968
- if (container && !Array.isArray(container)) container = [...container];
4969
- const slider = new (0, $e090b20cef3f0516$export$4d41c6499d53639c)({
4970
- dlog: dlog,
4971
- catchify: catchify,
4972
- dist_to_hide_left: 6,
4973
- dist_to_hide_right: 6,
4974
- ...slider_options
4975
- }, override_lazyfier_options);
4976
- const recs = await local_rr(t, {
4977
- ...rendering_options,
4978
- post_processors: [(elements, display) => {
4979
- $bf7f12fe044e41b2$export$5e63aea0cac01fa0(elements, "a.rec_outer").forEach(ro => ro.classList.add("noautospacing"));
4980
- return elements;
4981
- }, ...(rendering_options.post_processors || [])]
4982
- });
4983
- if (!recs.elements) {
4984
- dlog("RR_Slider says bye bye cuz no recs");
4985
- return {};
4986
- }
4987
- slider.insert_here.append(...recs.elements);
4988
- if (container) {
4989
- const [root] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(container, root_selector || ".grid");
4990
- root[insertion_verb](slider.container);
4991
- }
4992
- return {
4993
- ...recs,
4994
- displays: recs.displays,
4995
- elements: container ? container : [slider.container]
4996
- };
4997
- }
4998
- var $66a2a93dfa520bc6$var$_tmpl$ = /*#__PURE__*/$z0IcO$solidjsweb.template(`<button class=load_more>`);
4999
- async function $66a2a93dfa520bc6$export$30933c637c977eef({
5000
- t: t,
5001
- recs: recs,
5002
- title: title,
5003
- infinite_scroll = false,
5004
- with_slider = false,
5005
- with_loadmore = false,
5006
- template_tool_options: template_tool_options,
5007
- slider_options = {},
5008
- pre_processors = [],
5009
- post_processors = [],
5010
- container_template: container_template,
5011
- template:
5012
- // container template
5013
- template,
5014
- // recommendation template
5015
- chunk_size_for_load_more = 4,
5016
- insertion_promise: insertion_promise,
5017
- view_more_text: view_more_text
5018
- }) {
5019
- const {
5020
- catchify: catchify,
5021
- dlog: dlog
5022
- } = t,
5023
- container = [...$bf7f12fe044e41b2$export$44951404cb8d0583(container_template)],
5024
- root = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(container, ".grid")[0],
5025
- internal_pre_processors = [...pre_processors],
5026
- // copy arrays so we don't unintentionally modify an array of a script calling us when doing auto postprocessor for slider if insertion_promise is defined
5027
- internal_post_processors = [...post_processors];
5028
- if (with_slider) var slider = catchify(() => new (0, $e090b20cef3f0516$export$4d41c6499d53639c)({
5029
- ...t,
5030
- arrow_image: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJkaXNwbGF5OiBpbmxpbmUtYmxvY2s7IHZlcnRpY2FsLWFsaWduOiBtaWRkbGU7IiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4IiB2aWV3Qm94PSIwIDAgOCAxNSI+PHBhdGggc3R5bGU9ImZpbGw6IHJnYigwLCAwLCAwKTsiIGQ9Ik0uNjI5LjAwMWMuMTUuMDA4LjI5My4wNzIuMzk4LjE4bDYuNzkyIDYuODlhLjYwMS42MDEgMCAwIDEgMCAuODZsLTYuNzkyIDYuODg4YS41ODYuNTg2IDAgMCAxLS44NDYgMCAuNjAxLjYwMSAwIDAgMSAwLS44Nkw2LjU1NCA3LjUuMjExIDEuMDAxYS42MDEuNjAxIDAgMCAxIDAtLjg2Yy4xMTUtLjEuMjY2LS4xNS40MTgtLjE0Ij48L3BhdGg+PC9zdmc+",
5031
- ...slider_options
5032
- }))();
5033
- if (slider) {
5034
- root.replaceWith(slider.container);
5035
- if (insertion_promise) internal_post_processors.push((t, items, d) => {
5036
- for (const item of items) insertion_promise.then(() => {
5037
- $8e19f8200d357fe7$export$37125ccc5dd98050({
5038
- element: item,
5039
- data: {
5040
- tenant: t.tenant,
5041
- entity_price: d.entity_price,
5042
- recommendation_id: d.recommendation_id,
5043
- market: t.market,
5044
- product_id: d.product_id,
5045
- recommendation_type: d.recommendation_type
5046
- },
5047
- wait_for_dom_insertion: false
5048
- });
5049
- });
5050
- return items;
5051
- });
5052
- }
5053
- if (!slider || !insertion_promise) internal_post_processors.push((t, items, d) => {
5054
- for (const item of items) $8e19f8200d357fe7$export$37125ccc5dd98050({
5055
- element: item,
5056
- data: {
5057
- tenant: t.tenant,
5058
- entity_price: d.entity_price,
5059
- recommendation_id: d.recommendation_id,
5060
- market: t.market,
5061
- product_id: d.product_id,
5062
- recommendation_type: d.recommendation_type
5063
- },
5064
- wait_for_dom_insertion: false
5065
- });
5066
- return items;
5067
- });
5068
- const template_tool = await $52d3be7ce5146924$export$2e2bcd8739ae039({
5069
- options: {
5070
- ...t,
5071
- ...(template_tool_options || {})
5072
- },
5073
- root: slider ? slider.insert_here : root,
5074
- recs: recs,
5075
- template: template,
5076
- preProcessor: (d, i) => {
5077
- return internal_pre_processors.reduce((accumulator, currentValue) => {
5078
- // basic pre processor pipeline
5079
- return catchify(currentValue)(t, accumulator, i, with_loadmore, with_slider, infinite_scroll) || accumulator;
5080
- }, d);
5081
- },
5082
- postProcessor: (items, d) => {
5083
- return internal_post_processors.reduce((accumulator, currentValue) => {
5084
- // basic post processor pipeline
5085
- return catchify(currentValue)(t, accumulator, d, slider) || accumulator;
5086
- }, items);
5087
- }
5088
- });
5089
- if (with_loadmore) catchify($66a2a93dfa520bc6$var$setup_load_more)(t, root, chunk_size_for_load_more, view_more_text);
5090
- if (infinite_scroll) catchify($66a2a93dfa520bc6$var$setup_infinite_scroll)(t, root);
5091
- if (title) {
5092
- const [title_element] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(container, "h1.title, h2.title, h3.title, h4.title, h5.title, h6.title");
5093
- if (title_element) {
5094
- if (typeof title == "string") title_element.innerText = title;else title_element.replaceWith(...title);
5095
- }
5096
- }
5097
- if (template_tool?.data?.length) return container;else dlog("Didn't get recs from API", template_tool);
5098
- }
5099
- function $66a2a93dfa520bc6$var$setup_infinite_scroll(t, root) {
5100
- const {
5101
- dlog: dlog,
5102
- catchify: catchify
5103
- } = t,
5104
- get_last_visible_el = () => [...root.querySelectorAll("a.rec_outer:not(.not_visible)")].slice(-1)[0],
5105
- last_visible_el = get_last_visible_el();
5106
- if (!last_visible_el) {
5107
- dlog("not setting up infinite scroll as there are no elements");
5108
- return;
5109
- }
5110
- const intersection_observer = new IntersectionObserver(catchify(records => {
5111
- dlog("Intersection observer for", last_visible_el, "has records", records);
5112
- records.forEach(record => {
5113
- if (record.isIntersecting && record.target == get_last_visible_el()) {
5114
- dlog("Loading more recs because of", record);
5115
- if ($66a2a93dfa520bc6$var$load_more_elements(root)) $66a2a93dfa520bc6$var$setup_infinite_scroll(t, root);
5116
- }
5117
- });
5118
- }));
5119
- dlog("starting to intersection observe", last_visible_el, "for infinite scroll");
5120
- intersection_observer.observe(last_visible_el);
5121
- }
5122
- function $66a2a93dfa520bc6$var$load_more_elements(root, chunk_size = 4) {
5123
- const hidden_elements = root.querySelectorAll("a.rec_outer.not_visible");
5124
- let i = 0;
5125
- for (; i < Math.min(hidden_elements.length, chunk_size); i++) {
5126
- // @ts-ignore
5127
- hidden_elements[i].load_image();
5128
- hidden_elements[i].classList.remove("not_visible");
5129
- }
5130
- const has_more = i >= chunk_size && hidden_elements.length > chunk_size;
5131
- return has_more;
5132
- }
5133
- function $66a2a93dfa520bc6$var$setup_load_more(t, root, chunk_size, view_more_text = "Visa mer") {
5134
- const {
5135
- catchify: catchify
5136
- } = t,
5137
- load_more_cont = $bf7f12fe044e41b2$export$d3e2a0560cbf4787(`<div class="load-more-container"></div>`),
5138
- load_button = load_more_cont.appendChild((() => {
5139
- var _el$ = $z0IcO$solidjsweb.getNextElement($66a2a93dfa520bc6$var$_tmpl$);
5140
- $z0IcO$solidjsweb.insert(_el$, view_more_text);
5141
- return _el$;
5142
- })());
5143
- load_button.addEventListener("click", catchify(load_more_recs_and_hide_button_if_needed));
5144
- root.after(load_more_cont);
5145
- load_more_recs_and_hide_button_if_needed();
5146
- function load_more_recs_and_hide_button_if_needed() {
5147
- if (!$66a2a93dfa520bc6$var$load_more_elements(root, chunk_size))
5148
- // there aren't any recs left to display
5149
- load_button.classList.add("not_visible");
5150
- }
5151
- }
5152
- function $66a2a93dfa520bc6$export$4f39078bdc72ecd0(_t, d, i, with_loadmore, with_slider, infinite_scroll) {
5153
- d.class ||= "";
5154
- if (infinite_scroll) d.class = i >= 4 ? "not_visible" : ""; // this will make it hold image loading until .load_image is called on .rec_outer
5155
- if (with_loadmore) d.class = "not_visible";
5156
- d.percentage_off = Math.round(100 - d.sale_price / d.original_price * 100);
5157
- if (!d.percentage_off || d.percentage_off < 10) d.percentage_off = "";
5158
- return d;
5159
- }
5160
- function $66a2a93dfa520bc6$export$c410ce1205e5118a(_t, itms, d, slider) {
5161
- for (const item of itms) {
5162
- const {
5163
- image_url: image_url
5164
- } = d,
5165
- img = item.querySelector("img.image"),
5166
- load_image = () => {
5167
- img.src = image_url;
5168
- slider?.observe?.(img);
5169
- };
5170
- if (item.classList.contains("not_visible") || slider)
5171
- // @ts-ignore
5172
- item.load_image = load_image;else load_image();
5173
- if (slider) item.classList.add("noautospacing");
2801
+
2802
+ // not ideal but can help when debugging via sentry
2803
+ /**
2804
+ * A function that attempts to "serialize" an object to a text representation that helps with debugging when using sentry
2805
+ * @param anything Something to try to serialize - this function is crappy and your mileage may vary
2806
+ * @param depth How deep to go when recursing
2807
+ * @return An object that is somehow closer to text (better serializable by sentry) or text
2808
+ */
2809
+ function $45e05ec4fd7f1ee7$export$39d526a1194b6499(anything, depth) {
2810
+ depth ??= 0;
2811
+ depth++;
2812
+ if (depth > 30) return anything;
2813
+ const output = {};
2814
+ for (const key in anything) {
2815
+ const value = anything[key];
2816
+ let serialized_value;
2817
+ if (value instanceof Element) serialized_value = value.cloneNode(false).outerHTML;else if (value instanceof Headers) serialized_value = Object.fromEntries(value.entries());else if (typeof value == "object" && value != null && (typeof value[Symbol.iterator] === "function" || value instanceof Response)) serialized_value = $45e05ec4fd7f1ee7$export$39d526a1194b6499(value, depth);else serialized_value = value?.toString?.();
2818
+ output[key] = serialized_value;
5174
2819
  }
5175
- return itms;
2820
+ return output;
5176
2821
  }
5177
2822
  var
5178
2823
  /**
@@ -5313,6 +2958,33 @@ const $febdc40c8da5c25e$export$68c017fd93791405 = ({
5313
2958
  container: container
5314
2959
  };
5315
2960
  };
2961
+ const $f3f05d97149aec76$export$deca40f48c0569f8 = typeof window === "undefined" ? false : /*@__PURE__*/localStorage.getItem("colorize-logics") === "true";
2962
+ function $f3f05d97149aec76$export$16501883f477737a(elements, display) {
2963
+ elements.forEach(elem => {
2964
+ if (elem.nodeType !== Node.TEXT_NODE) {
2965
+ // calc a hash for given string
2966
+ const hc = (str = "") => {
2967
+ let hash = 0;
2968
+ if (str.length === 0) return hash;
2969
+ for (let i = 0; i < str.length; i++) {
2970
+ const chr = str.charCodeAt(i);
2971
+ hash = (hash << 5) - hash + chr;
2972
+ hash |= 0;
2973
+ }
2974
+ return hash;
2975
+ };
2976
+ const hash = hc(display.logic);
2977
+ // Change hue based on hash
2978
+ const color = "hsl(" + hash % 360 + ",100%,75%)";
2979
+ if ("style" in elem) elem.style.background = color;
2980
+ // @ts-ignore
2981
+ elem?.setAttribute?.("data-logic", display.logic);
2982
+ // @ts-ignore
2983
+ elem?.setAttribute?.("title", "Logic: " + display.logic);
2984
+ }
2985
+ });
2986
+ return elements;
2987
+ }
5316
2988
  function $ef237c2bba47492f$export$f8913c8a18f7ca21(iterables) {
5317
2989
  const ourselves = $9a42a570de51ea3d$export$e806c6c1615a59ae();
5318
2990
  const values = new Array(iterables.length);
@@ -5555,98 +3227,6 @@ class $1cc2444a0f1b992e$var$CSSMeasurement {
5555
3227
  this.u = unit;
5556
3228
  }
5557
3229
  }
5558
- async function $a7315720bf2a1638$export$b0a773486c1c2312(t, recommendation_renderer_options, {
5559
- container_elements: container_elements,
5560
- container_selector: container_selector,
5561
- override_rec_renderer: override_rec_renderer,
5562
- lazyfier_options = {},
5563
- eager_images: eager_images,
5564
- ...options_for_grid
5565
- }) {
5566
- const [insertion_point] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(container_elements, container_selector || ".grid");
5567
- const rendering_result = await (override_rec_renderer || (0, $92bde32714bb1e07$export$2e2bcd8739ae039))(t, recommendation_renderer_options);
5568
- const {
5569
- elements: elements
5570
- } = rendering_result;
5571
- if (!elements) return rendering_result;
5572
- if (!eager_images)
5573
- // convoluted lazy loading that
5574
- // when the elements are in the DOM starts IntersectionObserver on whole grid
5575
- // when grid intersects starts Lazyfier
5576
- // this is because Lazyfier is fucking stupid
5577
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element(insertion_point).then($268cbd9e4ade92db$export$b3bbfd758f11cfa9(element => {
5578
- let start_lazy_loading;
5579
- const lazy_loading_promise = new Promise(r => start_lazy_loading = r);
5580
- const lf = new (0, $1da560af170fb839$export$3be7054c61590ee3)({
5581
- only_load_intersecting: true,
5582
- wait_for_dominsertion: lazy_loading_promise,
5583
- ...lazyfier_options
5584
- });
5585
- lf.start_observing_for_new_children_(element);
5586
- const i_o = new IntersectionObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(records => {
5587
- for (const record of records) if (record.intersectionRatio > 0) {
5588
- start_lazy_loading();
5589
- i_o.disconnect();
5590
- return;
5591
- }
5592
- }));
5593
- i_o.observe(insertion_point);
5594
- }));
5595
- insertion_point.append(...elements);
5596
- $1cc2444a0f1b992e$export$c84671f46d6a1ca({
5597
- ...options_for_grid,
5598
- container_element: insertion_point,
5599
- layout: "grid"
5600
- }).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
5601
- return {
5602
- ...rendering_result,
5603
- elements: container_elements
5604
- };
5605
- }
5606
-
5607
- // @ts-ignore
5608
- var $a1e0549e8669396a$exports = {};
5609
- $a1e0549e8669396a$exports = ".depict-slider {\n width: 100%;\n position: relative;\n}\n\n.depict-slider .sliding {\n scroll-behavior: smooth;\n -ms-overflow-style: none;\n scrollbar-width: none;\n flex-flow: row;\n display: flex;\n overflow-x: scroll;\n}\n\n.depict-slider .sliding::-webkit-scrollbar {\n display: none;\n}\n\n.depict-slider .sliding > * {\n box-sizing: border-box;\n flex: none;\n}\n\n";
5610
- let $79804e8d76404ae4$var$slider_styling_was_inserted = false;
5611
- async function $79804e8d76404ae4$export$82cfdc85a4d15688(t, recommendation_renderer_options, {
5612
- container_elements: container_elements,
5613
- container_selector: container_selector,
5614
- override_rec_renderer: override_rec_renderer,
5615
- lazyfier_options = {},
5616
- eager_images: eager_images,
5617
- grid_spacing: grid_spacing,
5618
- cols_at_size: cols_at_size,
5619
- override_vertical_spacing: override_vertical_spacing,
5620
- rows = "all",
5621
- ...slider_options
5622
- }) {
5623
- const [insertion_point] = $bf7f12fe044e41b2$export$5e63aea0cac01fa0(container_elements, container_selector || ".grid");
5624
- const slider = eager_images ? new (0, $1683d0164abd7c1d$export$692b27c28639e5b9)(slider_options) : new (0, $a69a5236b5814082$export$68babfc5be0de5da)(slider_options, lazyfier_options);
5625
- const rendering_result = await (override_rec_renderer || (0, $92bde32714bb1e07$export$2e2bcd8739ae039))(t, recommendation_renderer_options);
5626
- const {
5627
- elements: elements
5628
- } = rendering_result;
5629
- if (!elements) return rendering_result;
5630
- if (!$79804e8d76404ae4$var$slider_styling_was_inserted) {
5631
- $79804e8d76404ae4$var$slider_styling_was_inserted = true;
5632
- $e4bebbfa0f0b1454$export$59ba1eb2c083f0cd((0, /*@__PURE__*/$parcel$interopDefault($a1e0549e8669396a$exports)));
5633
- }
5634
- insertion_point.replaceWith(slider.container);
5635
- slider.insert_here.append(...elements);
5636
- $1cc2444a0f1b992e$export$c84671f46d6a1ca({
5637
- grid_spacing: grid_spacing,
5638
- cols_at_size: cols_at_size,
5639
- container_element: slider.insert_here,
5640
- rows: rows,
5641
- layout: "slider",
5642
- override_vertical_spacing: override_vertical_spacing
5643
- }).catch(e => $268cbd9e4ade92db$export$f18d5b0af29128b7([e, "Grid had an error"], "warning"));
5644
- return {
5645
- ...rendering_result,
5646
- slider: slider,
5647
- elements: container_elements
5648
- };
5649
- }
5650
3230
  function $535c6ee2337e2717$export$8cbd8aa1c70f9a13(interval = 5000) {
5651
3231
  let timer;
5652
3232
  let direction = 1;
@@ -5694,16 +3274,11 @@ function $edc9fe0b09e00df6$export$af88b4929c2dc86() {
5694
3274
  }
5695
3275
  var $158313c0231e6555$var$_tmpl$ = /*#__PURE__*/$z0IcO$solidjsweb.template(`<label class=checkbox_container><input type=radio><span class=checkmark>`);
5696
3276
  function $158313c0231e6555$export$1d17a045bcc711b1({
5697
- t: t,
5698
3277
  navcont_insertion_fn: navcont_insertion_fn,
5699
3278
  navdot: navdot,
5700
3279
  dontshowonedot = false,
5701
3280
  bitesize: bitesize
5702
3281
  }) {
5703
- const {
5704
- dlog: dlog,
5705
- catchify: catchify
5706
- } = t;
5707
3282
  const button_states = [];
5708
3283
  const unique_name = Math.round(Math.random() * 1000000);
5709
3284
  function constructor_plugin() {
@@ -5740,14 +3315,14 @@ function $158313c0231e6555$export$1d17a045bcc711b1({
5740
3315
  const position = Math.round(first_shown_element / amount_of_elements * number_of_slides);
5741
3316
  const get_inputs = () => navcont.querySelectorAll("input");
5742
3317
  if (number_of_radio_buttons != number_of_slides) {
5743
- dlog("Number of buttons doesn't match number of slides, rerendering buttons", button_states);
3318
+ $e6c6e7929ea385ae$export$de56f1198d121036("Number of buttons doesn't match number of slides, rerendering buttons", button_states);
5744
3319
  navcont.innerHTML = "";
5745
3320
  if (number_of_slides === 1 && dontshowonedot) {
5746
- dlog("dontshowonedot is on, not rendering any dots");
3321
+ $e6c6e7929ea385ae$export$de56f1198d121036("dontshowonedot is on, not rendering any dots");
5747
3322
  return;
5748
3323
  }
5749
3324
  if (number_of_slides == Infinity) {
5750
- dlog("Infinite number of slides, wtf", number_of_slides);
3325
+ $e6c6e7929ea385ae$export$de56f1198d121036("Infinite number of slides, wtf", number_of_slides);
5751
3326
  return;
5752
3327
  }
5753
3328
  for (let i = 0; i < number_of_slides; i++) {
@@ -5755,10 +3330,10 @@ function $158313c0231e6555$export$1d17a045bcc711b1({
5755
3330
  const input = a_navdot.querySelector("input");
5756
3331
  if (process.env.DEBUG === "true" && !input) throw new Error("You need to provide a navdot that contains an <input> element to slider_dots");
5757
3332
  input.checked = button_states[i];
5758
- input.addEventListener("click", catchify(e => {
3333
+ input.addEventListener("click", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => {
5759
3334
  e.preventDefault();
5760
3335
  e.stopPropagation();
5761
- dlog("Someone checked a box", e);
3336
+ $e6c6e7929ea385ae$export$de56f1198d121036("Someone checked a box", e);
5762
3337
  this.scroll_to_abs(Math.round(amount_of_visible_elements * i));
5763
3338
  return false;
5764
3339
  }));
@@ -5798,12 +3373,7 @@ function $158313c0231e6555$export$a09282b33e69b43f(unique_name) {
5798
3373
  // });
5799
3374
  // });
5800
3375
 
5801
- function $98ef92db220106f3$export$411b0f20794697ce(t) {
5802
- const {
5803
- dlog: dlog,
5804
- catchify: catchify,
5805
- err: err
5806
- } = t;
3376
+ function $98ef92db220106f3$export$411b0f20794697ce() {
5807
3377
  function constructor_plugin(slider_options) {
5808
3378
  const {
5809
3379
  insert_here: sliding
@@ -5811,7 +3381,7 @@ function $98ef92db220106f3$export$411b0f20794697ce(t) {
5811
3381
  let last_mouse_position = 0;
5812
3382
  let starting_position = 0;
5813
3383
  let block_anchor_clicks = false;
5814
- sliding.addEventListener("mousedown", catchify(e => {
3384
+ sliding.addEventListener("mousedown", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => {
5815
3385
  sliding.classList.remove("slider_snap");
5816
3386
  const {
5817
3387
  snap_style: snap_style
@@ -5821,7 +3391,7 @@ function $98ef92db220106f3$export$411b0f20794697ce(t) {
5821
3391
  last_mouse_position = starting_position = e.clientX;
5822
3392
  sliding.addEventListener("mousemove", scroll_on_mousemove);
5823
3393
  }));
5824
- window.addEventListener("mouseup", catchify(e => {
3394
+ window.addEventListener("mouseup", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => {
5825
3395
  // use window to prevent dragging from getting stuck
5826
3396
  sliding.classList.remove("grabbing");
5827
3397
  sliding.classList.add("slider_snap");
@@ -5841,9 +3411,9 @@ function $98ef92db220106f3$export$411b0f20794697ce(t) {
5841
3411
  });
5842
3412
  }
5843
3413
  }));
5844
- sliding.addEventListener("click", catchify(e => {
3414
+ sliding.addEventListener("click", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => {
5845
3415
  if (block_anchor_clicks) {
5846
- dlog("Block anchor clicks is true, blocking click", e);
3416
+ $e6c6e7929ea385ae$export$de56f1198d121036("Block anchor clicks is true, blocking click", e);
5847
3417
  block_anchor_clicks = false;
5848
3418
  e.preventDefault();
5849
3419
  return false;
@@ -5860,7 +3430,7 @@ function $98ef92db220106f3$export$411b0f20794697ce(t) {
5860
3430
  });
5861
3431
  last_mouse_position = clientX;
5862
3432
  } catch (e) {
5863
- err(e);
3433
+ $548fd58b14b25a52$export$8048b892d651b310(e);
5864
3434
  }
5865
3435
  }
5866
3436
  }
@@ -6134,228 +3704,61 @@ function $379066823f8eeb0b$export$dac64fd35a4805a4(options = {}) {
6134
3704
  mutation_plugin: $268cbd9e4ade92db$export$b3bbfd758f11cfa9(mutation_plugin)
6135
3705
  };
6136
3706
  }
6137
- function $3d8df0a23b9bebac$export$53306504b987cbf7({
6138
- clones_per_side = 8
6139
- } = {}) {
6140
- // YOU NEED TO USE slider_snap_css FOR THIS TO WORK
6141
- // only for usage with recommendation_renderer which you need to pass post_processor as LAST post processor
6142
- const time_of_no_events_to_count_as_scroll_idle = 150;
6143
- const originally_rendered_elements = [];
6144
- const sets_of_els = [originally_rendered_elements];
6145
- const removed_by_us = new Set();
6146
- let mutation_busy = false;
6147
- let surplus_in_body = true;
6148
- let last_move = window?.performance?.now?.() || +new Date();
6149
- let touches = 0;
6150
- let inactive_checker_running = false;
6151
- let smallest_seen_intersection_ratio = 0.1;
6152
- let largest_seen_interection_ratio = 0.9;
6153
- let are_far_right = false;
6154
- let inactive_checker_timeout;
6155
- // let elgreen;
6156
- const check_if_we_inactive = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(function () {
6157
- // const { insert_here: sliding } = this;
6158
- const now = window?.performance?.now?.() || +new Date();
6159
- const time_since_ran = now - last_move;
6160
- const last_left_intersection = this.first_intersecting;
6161
- // dlog(last_left_intersection.intersectionRatio, smallest_seen_intersection_ratio, largest_seen_interection_ratio);
6162
- if (time_since_ran > time_of_no_events_to_count_as_scroll_idle && !touches && last_left_intersection && (last_left_intersection.intersectionRatio <= smallest_seen_intersection_ratio || last_left_intersection.intersectionRatio >= largest_seen_interection_ratio || are_far_right)) {
6163
- // if (!elgreen) {
6164
- // sliding.style.background = "green";
6165
- // elgreen = true;
6166
- // }
6167
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9($3d8df0a23b9bebac$var$scroll_idle)(this, originally_rendered_elements.length, clones_per_side);
6168
- inactive_checker_running = false;
6169
- } else {
6170
- // if (elgreen !== false) {
6171
- // sliding.style.background = "red";
6172
- // elgreen = false;
6173
- // }
6174
- const timeleft = time_of_no_events_to_count_as_scroll_idle - time_since_ran;
6175
- if (timeleft < 1) requestAnimationFrame(check_if_we_inactive.bind(this));else setTimeout(check_if_we_inactive.bind(this), timeleft);
6176
- }
6177
- });
6178
- function constructor_plugin() {
6179
- window.addEventListener("touchstart", () => touches++);
6180
- window.addEventListener("touchend", () => touches--);
6181
- this.insert_here.addEventListener("scroll", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
6182
- last_move = window?.performance?.now?.() || +new Date();
6183
- }));
6184
- const mo = new MutationObserver($268cbd9e4ade92db$export$b3bbfd758f11cfa9(records => {
6185
- for (const record of records) for (const node of record.removedNodes) {
6186
- if (removed_by_us.has(node)) {
6187
- removed_by_us.delete(node);
6188
- continue;
6189
- }
6190
- for (const a_set of sets_of_els) {
6191
- const index_in_el_set = a_set.indexOf(node);
6192
- if (index_in_el_set >= 0) {
6193
- $e6c6e7929ea385ae$export$de56f1198d121036("Removing", node, "from el set", a_set);
6194
- a_set.splice(index_in_el_set, 1);
6195
- }
6196
- }
6197
- }
6198
- }));
6199
- mo.observe(this.insert_here, {
6200
- childList: true
6201
- });
6202
- }
6203
- function mutation_plugin(intersections, intersecting_mutations) {
6204
- for (let i = 0; i < intersections.length; i++) {
6205
- const {
6206
- intersectionRatio: intersectionRatio
6207
- } = intersections[i];
6208
- const target_large = intersectionRatio * 0.95;
6209
- const target_small = intersectionRatio * 1.05;
6210
- if (target_large > largest_seen_interection_ratio && target_large < 0.999) largest_seen_interection_ratio = target_large;else if (intersectionRatio && target_small < smallest_seen_intersection_ratio && target_small > 0.0001) smallest_seen_intersection_ratio = target_small;
6211
- }
6212
- if (mutation_busy) return;
6213
- mutation_busy = true;
6214
- last_move = window?.performance?.now?.() || +new Date();
6215
- const first_element = this.element_by_index(0);
6216
- const second_element = this.element_by_index(1);
6217
- let dont_wraparound = false;
6218
- if (!first_element || !second_element) dont_wraparound = true;else {
6219
- // calculate how many cards including margin the slider fits
6220
- const first_rect = first_element.getBoundingClientRect();
6221
- if (!first_rect.width) {
6222
- $e6c6e7929ea385ae$export$de56f1198d121036(first_rect);
6223
- throw new Error("First rect doesn't have width");
6224
- }
6225
- const second_rect = second_element.getBoundingClientRect();
6226
- const container_rect = this.insert_here.getBoundingClientRect();
6227
- const margin = second_rect.left - first_rect.right;
6228
- let width = 0;
6229
- let amount = 0;
6230
- while (width < container_rect.width) {
6231
- if (width < 0) throw new Error("width can't be < 0");
6232
- width += first_rect.width + margin;
6233
- amount++;
6234
- }
6235
- // dlog(originally_rendered_elements.length, amount);
6236
- if (originally_rendered_elements.length <= amount) dont_wraparound = true;
6237
- }
6238
- if (dont_wraparound) {
6239
- if (surplus_in_body) {
6240
- $e6c6e7929ea385ae$export$de56f1198d121036("Removing surplus of els. Total els: ", sets_of_els);
6241
- // @ts-ignore
6242
- for (let i = (sets_of_els.length || 1) - 1; i--;) for (let j = 0; j < sets_of_els[i].length; j++) {
6243
- const el = sets_of_els[i][j];
6244
- if ("remove" in el) {
6245
- removed_by_us.add(el);
6246
- el.remove();
6247
- }
6248
- }
6249
- this.invalidate_cache();
6250
- surplus_in_body = false;
6251
- }
6252
- mutation_busy = false;
6253
- return;
6254
- }
6255
- if (!surplus_in_body) {
6256
- $e6c6e7929ea385ae$export$de56f1198d121036("Adding surplus of els");
6257
- this.insert_here.append(...sets_of_els.slice(0, -1).flat());
6258
- this.invalidate_cache();
6259
- surplus_in_body = true;
6260
- }
6261
- are_far_right = intersecting_mutations[this.index_of_last_element]?.intersectionRatio >= largest_seen_interection_ratio;
6262
- clearTimeout(inactive_checker_timeout);
6263
- inactive_checker_timeout = setTimeout(function () {
6264
- if (!inactive_checker_running) {
6265
- inactive_checker_running = true;
6266
- check_if_we_inactive.call(this);
6267
- }
6268
- }.bind(this), time_of_no_events_to_count_as_scroll_idle * 0.8 // schedule a bit earlier so we hit our target
6269
- );
6270
-
6271
- mutation_busy = false;
3707
+ const $69f7524c8bdd85b4$export$20e9533e68ee72e7 = /*@__PURE__*/$9a42a570de51ea3d$export$e806c6c1615a59ae(false);
3708
+ const $69f7524c8bdd85b4$export$a9d39e43ae273d26 = /*@__PURE__*/$9a42a570de51ea3d$export$e806c6c1615a59ae();
3709
+ const $69f7524c8bdd85b4$export$7500cdfd37aafd43 = /*@__PURE__*/new Set();
3710
+ let $69f7524c8bdd85b4$var$old_url;
3711
+ const $69f7524c8bdd85b4$var$maybe_navigation = (what_happened, args) => {
3712
+ if (typeof location === "undefined") return;
3713
+ const new_url = location.href;
3714
+ if ($69f7524c8bdd85b4$var$old_url !== new_url) {
3715
+ $69f7524c8bdd85b4$export$a9d39e43ae273d26(new_url);
3716
+ if ($69f7524c8bdd85b4$var$old_url !== undefined)
3717
+ // don't resolve stateless href change ipns with the initial value - it's not a navigation
3718
+ $69f7524c8bdd85b4$export$20e9533e68ee72e7(new_url);
3719
+ $69f7524c8bdd85b4$var$old_url = new_url;
6272
3720
  }
6273
- async function post_processor(elements, _display, info) {
6274
- const {
6275
- index: index,
6276
- rendering_options: rendering_options
6277
- } = info;
6278
- originally_rendered_elements.push(...elements);
6279
- if (index === 0) {
6280
- const {
6281
- event_listeners: event_listeners
6282
- } = info; // so we don't want event listeners to be added twice. We will return our actual index 0 elements and all elements of all indexes. Tracking needs to be right per element per index. That's why we will now add our event listeners to our elements and then prevent RR from doing it for us on all returned elements, on which each RR run will get to add the correct individual ones
6283
- while (event_listeners?.length) {
6284
- // order shouldn't matter, this is fast
6285
- const event_listener = event_listeners.pop();
6286
- for (let i = 0; i < elements.length; i++) elements[i].addEventListener(...event_listener);
6287
- }
6288
- // render all elements again four times and adds them to the beginning
6289
- const post_processors = [...(rendering_options.post_processors || [])];
6290
- const our_index = post_processors.indexOf(post_processor);
6291
- if (our_index >= 0) post_processors.splice(our_index, 1);else {
6292
- const msg = "Couldn't find ourselves in post processors, infinite loop might ensue. Exiting. Wraparound will be broken.";
6293
- (0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).captureException(new Error(msg));
6294
- $e6c6e7929ea385ae$export$de56f1198d121036(msg, () => {});
6295
- return elements;
6296
- }
6297
- for (let i = 0; i < clones_per_side * 2; i++) {
6298
- const additional_render = await $558ccd2de887e6d9$export$a9fc160c5ed83bd7(info.t, {
6299
- ...rendering_options,
6300
- post_processors: post_processors,
6301
- pre_processors: [],
6302
- // don't need to execute pre processors again, displays are already pre-processed
6303
- recs: info.displays
6304
- });
6305
- sets_of_els.push([...additional_render.elements]);
6306
- }
6307
- sets_of_els.reverse(); // here sets_of_els gets modified and reversed
6308
- const sets_of_els_without_items_1_plus_n_from_first_render = [...sets_of_els];
6309
- const index_of_first_render = sets_of_els_without_items_1_plus_n_from_first_render.indexOf(originally_rendered_elements);
6310
- if (index_of_first_render < 0) throw new Error("Something's weird, pls check");
6311
- sets_of_els_without_items_1_plus_n_from_first_render[index_of_first_render] = elements;
6312
- // we cannot return the array that _might_ contain the elements from the other rendering passes that run asynchronously, this might lead to duplicated event listeners
6313
- return sets_of_els_without_items_1_plus_n_from_first_render.flat();
6314
- } else return elements;
3721
+ for (const fn of $69f7524c8bdd85b4$export$7500cdfd37aafd43) fn(what_happened, args);
3722
+ };
3723
+ $69f7524c8bdd85b4$export$baccefee4a395d8f((args, what_happened) => $69f7524c8bdd85b4$var$maybe_navigation(what_happened, args));
3724
+ $69f7524c8bdd85b4$var$maybe_navigation();
3725
+ globalThis?.window?.addEventListener("popstate", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => $69f7524c8bdd85b4$var$maybe_navigation("popstate", e)));
3726
+ async function $69f7524c8bdd85b4$export$1cd22bab0d2c3b0b(callback) {
3727
+ const catchified_callback = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(callback);
3728
+ for await (const href of $69f7524c8bdd85b4$export$20e9533e68ee72e7) {
3729
+ catchified_callback(href);
3730
+ break;
6315
3731
  }
6316
- return {
6317
- constructor_plugin: constructor_plugin,
6318
- mutation_plugin: mutation_plugin,
6319
- post_processor: post_processor
6320
- };
6321
3732
  }
6322
- function $3d8df0a23b9bebac$var$scroll_idle(slider, chunk_size, clones_per_side) {
6323
- const {
6324
- insert_here: sliding
6325
- } = slider;
6326
- const slider_box = sliding.getBoundingClientRect();
6327
- const leftmost_rect = slider.element_by_index(0).getBoundingClientRect();
6328
- const rightmost_rect = slider.element_by_index(slider.index_of_last_element).getBoundingClientRect();
6329
- const leftmost_card_to_left_viewport_edge = slider_box.left - leftmost_rect.left;
6330
- const rightmost_card_to_right_viewport_edge = rightmost_rect.right - slider_box.right;
6331
- const children = [...sliding.children];
3733
+ async function $69f7524c8bdd85b4$export$baccefee4a395d8f(after_navigation, replace_replaceState = true) {
3734
+ if (typeof History === "undefined") return;
6332
3735
  const {
6333
- intersecting_items_object: intersecting_items_object
6334
- } = slider;
6335
- const index_of_first_intersecting = slider.first_intersecting_index();
6336
- const index_of_last_intersecting = Math.max(...Object.keys(intersecting_items_object).map(v => +v));
6337
- const post_move = direction => {
6338
- // slider.invalidate_cache();
6339
- // for (const key in intersecting_items_object) {
6340
- // const value = intersecting_items_object[key];
6341
- // delete intersecting_items_object[key];
6342
- // intersecting_items_object[slider.get_index_of_element(value.target)] = value;
6343
- // }
6344
- slider.scroll_to_abs(index_of_first_intersecting - direction * chunk_size, true);
3736
+ prototype: prototype
3737
+ } = History;
3738
+ const instance = history;
3739
+ const polyfill_dance = the_thing => {
3740
+ const proxy_the_thing = obj => {
3741
+ const orig_pushState = obj[the_thing];
3742
+ obj[the_thing] = new Proxy(orig_pushState, {
3743
+ apply: (target, this_arg, arguments_list) => {
3744
+ const nav_result = Reflect.apply(target, this_arg, arguments_list);
3745
+ try {
3746
+ after_navigation(arguments_list, the_thing);
3747
+ } catch (e) {
3748
+ $548fd58b14b25a52$export$8048b892d651b310(e);
3749
+ }
3750
+ return nav_result;
3751
+ }
3752
+ });
3753
+ };
3754
+ proxy_the_thing(prototype);
3755
+ if (Object.getOwnPropertyNames(instance).includes(the_thing))
3756
+ // we don't want to just change the instance because that's not the way to do it, but we don't want to not work because someone else did it wrong
3757
+ proxy_the_thing(instance);
6345
3758
  };
6346
- // dlog(index_of_first_intersecting, index_of_last_intersecting);
6347
- if (index_of_first_intersecting >= chunk_size * clones_per_side && index_of_first_intersecting <= chunk_size * (clones_per_side + 1)) ;else {
6348
- if (leftmost_card_to_left_viewport_edge > rightmost_card_to_right_viewport_edge * 1.1 /* add 10% margin */)
6349
- // dlog("Moving", chunk_size, "to the right");
6350
- // sliding.append(...children.slice(0, chunk_size));
6351
- post_move(1);else if (rightmost_card_to_right_viewport_edge > leftmost_card_to_left_viewport_edge * 1.1)
6352
- // dlog("Moving", chunk_size, "to the left");
6353
- // sliding.prepend(...children.slice(-chunk_size));
6354
- post_move(-1);
6355
- }
6356
- // dlog("Scroll idle", leftmost_card_to_left_viewport_edge, rightmost_card_to_right_viewport_edge);
3759
+ polyfill_dance("pushState");
3760
+ if (replace_replaceState) polyfill_dance("replaceState");
6357
3761
  }
6358
-
6359
3762
  const $3721a5ccba25c247$var$connection_map = /*@__PURE__*/new WeakMap();
6360
3763
  function $3721a5ccba25c247$export$3d04c40e7acc1a32(initial_value) {
6361
3764
  let subscribed = false;
@@ -6519,122 +3922,329 @@ function $bf76a92ec2055e1a$export$419f84efad7d9fe(surface_per_size, cleanup_prom
6519
3922
  function $bf76a92ec2055e1a$export$be95cb0e8cfd099e() {
6520
3923
  return new Promise(r => $69f7524c8bdd85b4$export$1cd22bab0d2c3b0b(r));
6521
3924
  }
6522
- function $0c9d834f187cc4ff$export$3ebd86018b39d9d2(t, selector, filter) {
6523
- (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(selector, eoe => {
6524
- $e6c6e7929ea385ae$export$de56f1198d121036("Order confirmation element showed up!", eoe);
6525
- const {
6526
- element: element
6527
- } = eoe;
6528
- const the_id = element.innerText;
6529
- $0c9d834f187cc4ff$export$1ac466d53a6636ac(t, the_id, $e0a87646d12cb987$export$61e7e1f11e96692f(), filter);
3925
+ function $c8263a2185830bf1$export$82a685f2da2fb027(a_element, product_id, recommendation_id, additional_listener) {
3926
+ if (!a_element ||
3927
+ // @ts-ignore
3928
+ !a_element.depict_tracked ||
3929
+ // @ts-ignore
3930
+ a_element?.depict_tracked?.recommendation_id != recommendation_id ||
3931
+ // @ts-ignore
3932
+ a_element?.depict_tracked?.product_id != product_id) {
3933
+ const listener = e => {
3934
+ localStorage.setItem(`depict_attribution_${product_id}`, recommendation_id);
3935
+ if (additional_listener) additional_listener(e, product_id, recommendation_id);
3936
+ };
3937
+ // @ts-ignore
3938
+ if (a_element.depict_tracked)
3939
+ // @ts-ignore
3940
+ a_element.removeEventListener("click", a_element.depict_tracked?.listener);
3941
+ // @ts-ignore
3942
+ a_element.depict_tracked = {
3943
+ product_id: product_id,
3944
+ recommendation_id: recommendation_id,
3945
+ listener: listener
3946
+ };
3947
+ a_element.addEventListener("click", listener);
3948
+ return listener;
3949
+ }
3950
+ }
3951
+ async function $c8263a2185830bf1$export$2c34560c3749dc63(button, get_product_id, tracking_fn, unmatching_tracking, event) {
3952
+ // @ts-ignore
3953
+ if (!button || button.depict_tracked) return;
3954
+ button.addEventListener(event ? event : "click", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async e => {
3955
+ if (!e.isTrusted) {
3956
+ $e6c6e7929ea385ae$export$de56f1198d121036("ignoring event", e, "because it's not user generated");
3957
+ return;
3958
+ }
3959
+ const product_id = await get_product_id(undefined, e);
3960
+ if (product_id) {
3961
+ const item_name = `depict_attribution_${product_id}`;
3962
+ const recommendation_id = localStorage.getItem(item_name);
3963
+ if (recommendation_id) {
3964
+ localStorage.removeItem(item_name);
3965
+ tracking_fn(product_id, recommendation_id, false, e);
3966
+ } else if (unmatching_tracking) tracking_fn(product_id, recommendation_id, true, e);
3967
+ }
3968
+ }));
3969
+ // @ts-ignore
3970
+ button.depict_tracked = true;
3971
+ }
3972
+ function $c18ce8dadd041cdd$export$edfedd0557ca5a2d(ga_tracker, append_to_url) {
3973
+ if (!ga_tracker) return;
3974
+ // Docs for analytics.js Tasks:
3975
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks
3976
+ const sendHitTask = "sendHitTask";
3977
+ const originalSendHitTask = ga_tracker.get(sendHitTask);
3978
+ ga_tracker.set(sendHitTask, model => {
3979
+ originalSendHitTask(model);
3980
+ // console.log('Sent original hit, now sending to depict');
3981
+ try {
3982
+ const payLoad = model.get("hitPayload");
3983
+ const path = (0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/collect-ga";
3984
+ let url = path + "?" + payLoad;
3985
+ if (append_to_url) url += append_to_url;
3986
+ const n = navigator;
3987
+ const sb = "sendBeacon";
3988
+ if (n[sb])
3989
+ // this is actually smaller, I tested
3990
+ n[sb](url);else {
3991
+ const xhttp = new XMLHttpRequest();
3992
+ xhttp.open("GET", url);
3993
+ xhttp.send();
3994
+ }
3995
+ } catch (e) {
3996
+ // console.log('Could not send beacon to /collect-ga', e);
3997
+ }
6530
3998
  });
6531
3999
  }
6532
- function $0c9d834f187cc4ff$export$b11248fa13a8a86c(tenant, id_extractor) {
6533
- // Use the given extractor to find a transaction ID from each entry pushed to dataLayer.
6534
- // If it finds any IDs, send them.
6535
- $0c9d834f187cc4ff$export$9ed4fbc47d558f94(layer_entry => {
6536
- const id = id_extractor(layer_entry);
6537
- if (id && typeof id === "string") $0c9d834f187cc4ff$export$1ac466d53a6636ac(tenant, id);
4000
+ function $c18ce8dadd041cdd$export$674d8cd8b6868154() {
4001
+ // Snippet to load GA async
4002
+ const w = window;
4003
+ // @ts-ignore
4004
+ w.ga ||= function () {
4005
+ (w.ga.q ||= []).push(arguments);
4006
+ };
4007
+ w.ga.l = +new Date();
4008
+ }
4009
+
4010
+ /**
4011
+ * Elements currently intersecting with the viewport.
4012
+ * If they are intersecting for the `has_to_be_intersecting_for` duration, we count it as an impression, and call the callback.
4013
+ */
4014
+ const $72ed530554068e4f$var$current_intersections = /*@__PURE__*/new WeakMap();
4015
+ /**
4016
+ * Currently watched elements by the intersection observer with their respective callback
4017
+ * */
4018
+ const $72ed530554068e4f$var$watched_elements = /*@__PURE__*/new WeakMap();
4019
+ const $72ed530554068e4f$var$unwatch_element = element => {
4020
+ $72ed530554068e4f$var$intersection_observer?.unobserve(element);
4021
+ $72ed530554068e4f$var$watched_elements.delete(element);
4022
+ $72ed530554068e4f$var$current_intersections.delete(element);
4023
+ };
4024
+ const $72ed530554068e4f$export$4c51576248bcdf31 = (element, callback) => {
4025
+ if ($72ed530554068e4f$var$watched_elements.has(element)) {
4026
+ $e6c6e7929ea385ae$export$de56f1198d121036("Not watching", element, "as it's already being watched");
4027
+ return () => {};
4028
+ }
4029
+ $72ed530554068e4f$var$intersection_observer?.observe(element);
4030
+ /** Calls the given callback and makes sure to stop watching the element */
4031
+ const wrapped_callback = element => {
4032
+ callback(element);
4033
+ $72ed530554068e4f$var$unwatch_element(element);
4034
+ };
4035
+ $72ed530554068e4f$var$watched_elements.set(element, wrapped_callback);
4036
+ const disconnect_observer = (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onremoved(element, () => {
4037
+ // Sometimes it has already rapidly been reinserted. The observer events lag by one tick.
4038
+ // For that case, make sure we're really out of the DOM
4039
+ if (document.documentElement.contains(element)) return;
4040
+ $72ed530554068e4f$var$unwatch_element(element);
4041
+ });
4042
+ return () => {
4043
+ disconnect_observer();
4044
+ $72ed530554068e4f$var$unwatch_element(element);
4045
+ };
4046
+ };
4047
+ const $72ed530554068e4f$var$intersection_observer_callback = entries => {
4048
+ for (const record of entries) {
4049
+ const {
4050
+ target: target
4051
+ } = record;
4052
+ const callback = $72ed530554068e4f$var$watched_elements.get(target);
4053
+ // Skip the element if it's no longer being watched.
4054
+ if (!callback) {
4055
+ $72ed530554068e4f$var$intersection_observer?.unobserve(target);
4056
+ continue;
4057
+ }
4058
+ const currently_intersecting = $72ed530554068e4f$var$current_intersections.has(target);
4059
+ if (!currently_intersecting && record.intersectionRatio >= (0, $dd025eb6f77f8f8b$export$135da44d0ba958bc)[0]) {
4060
+ // we're intersecting enough and not already in the process of "measuring"
4061
+ const started_intersecting_at_ = +new Date(); // save start time
4062
+ // Schedule the callback function to be called after the element has been intersecting for the required duration
4063
+ const callback_timeout_ = setTimeout(callback, (0, $dd025eb6f77f8f8b$export$ca8321ea61dc2544), target);
4064
+ $72ed530554068e4f$var$current_intersections.set(target, {
4065
+ started_intersecting_at_: started_intersecting_at_,
4066
+ callback_timeout_: callback_timeout_
4067
+ });
4068
+ } else if (currently_intersecting && record.intersectionRatio < (0, $dd025eb6f77f8f8b$export$135da44d0ba958bc)[1]) {
4069
+ // we are in the process of "measuring" and went below the threshold
4070
+ const {
4071
+ started_intersecting_at_: started_intersecting_at_,
4072
+ callback_timeout_: callback_timeout_
4073
+ } = $72ed530554068e4f$var$current_intersections.get(target);
4074
+ const time_elapsed = +new Date() - started_intersecting_at_;
4075
+ // If we stopped intersecting too early we want to abort our timeout.
4076
+ // if we did not we also want to abort the timeout since it's been lagging and just instantly send the event
4077
+ // (the browser can delay setTimeout timers)
4078
+ clearTimeout(callback_timeout_);
4079
+ if (time_elapsed <= (0, $dd025eb6f77f8f8b$export$ca8321ea61dc2544)) $72ed530554068e4f$var$current_intersections.delete(target);else {
4080
+ // we intersected long enough
4081
+ $e6c6e7929ea385ae$export$de56f1198d121036("intersection_observer: setTimeout lagged", time_elapsed, (0, $dd025eb6f77f8f8b$export$ca8321ea61dc2544), "ms", target);
4082
+ callback(target);
4083
+ }
4084
+ }
4085
+ }
4086
+ };
4087
+ /**
4088
+ * Global IntersectionObserver used for all impression tracking.
4089
+ * It's faster to use one observer for all elements than to create a new one for each element.
4090
+ */
4091
+ const $72ed530554068e4f$var$intersection_observer = typeof window === "object" ? /*@__PURE__*/new IntersectionObserver( /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9($72ed530554068e4f$var$intersection_observer_callback), {
4092
+ threshold: /*@__PURE__*/$0da0cad4f39e8f32$export$f8ea2e7b15b5d129(8)
4093
+ }) : undefined;
4094
+ const $11ff7b46c1fb674c$export$d0efd8ed14f5c33 = (items, display, info) => {
4095
+ if (!items?.length) return items;
4096
+ const node_array = Array.isArray(items) ? items : [...items]; // if it's a NodeList convert it to an array
4097
+ const first_watchable_el = node_array.find(el => el instanceof Element);
4098
+ if (!first_watchable_el) {
4099
+ $e6c6e7929ea385ae$export$de56f1198d121036("Impression tracking: Can't observe", items, display);
4100
+ return items;
4101
+ }
4102
+ if (!info.t) {
4103
+ $e6c6e7929ea385ae$export$de56f1198d121036("Impression tracking: No tenant instance, can't track", items, display);
4104
+ return items;
4105
+ }
4106
+ (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(first_watchable_el, ({
4107
+ element: element
4108
+ }) => {
4109
+ $72ed530554068e4f$export$4c51576248bcdf31(element, () => {
4110
+ const {
4111
+ recommendation_id: recommendation_id,
4112
+ search_result_id: search_result_id,
4113
+ product_listing_result_id: product_listing_result_id,
4114
+ suggestions_result_id: suggestions_result_id
4115
+ } = display;
4116
+ $dd025eb6f77f8f8b$export$4205dc6835bc0d9f({
4117
+ ...$e0a87646d12cb987$export$8c6f26a5b6921b95(),
4118
+ recommendation_type: info.rendering_options.type,
4119
+ entity_price: display.sale_price,
4120
+ market: info.t.market,
4121
+ tenant: info.t.tenant,
4122
+ product_id: display.product_id,
4123
+ recommendation_id: recommendation_id,
4124
+ search_result_id: search_result_id,
4125
+ product_listing_result_id: product_listing_result_id,
4126
+ suggestions_result_id: suggestions_result_id
4127
+ });
4128
+ });
6538
4129
  });
4130
+ return items;
4131
+ };
4132
+ const $8e19f8200d357fe7$export$37125ccc5dd98050 = ({
4133
+ element: element,
4134
+ data: data,
4135
+ wait_for_dom_insertion = true
4136
+ }) => {
4137
+ const disconnectors = [];
4138
+ const impression_track = () => {
4139
+ const disconnector = $72ed530554068e4f$export$4c51576248bcdf31(element, () => {
4140
+ $dd025eb6f77f8f8b$export$4205dc6835bc0d9f({
4141
+ ...$e0a87646d12cb987$export$8c6f26a5b6921b95(),
4142
+ ...data
4143
+ });
4144
+ });
4145
+ disconnectors.push(disconnector);
4146
+ };
4147
+ if (wait_for_dom_insertion) disconnectors.push((0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onexists(element, impression_track));else impression_track();
4148
+ return () => disconnectors.forEach(disconnector => disconnector());
4149
+ };
4150
+ let $dd025eb6f77f8f8b$export$135da44d0ba958bc = [0.6, 0.5];
4151
+ const $dd025eb6f77f8f8b$export$c543ee4cdb0d0964 = (start, end) => $dd025eb6f77f8f8b$export$135da44d0ba958bc = [start, end];
4152
+ const $dd025eb6f77f8f8b$export$ca8321ea61dc2544 = 500;
4153
+ const $dd025eb6f77f8f8b$export$4205dc6835bc0d9f = data => {
4154
+ data.type = "element_visible"; // Set the type to element_visible as this is optional to pass here.
4155
+ $0c84f8e99aac5765$export$28cacbd9b4306ffc([data], true);
4156
+ };
4157
+
4158
+ // https://stackoverflow.com/a/39941616
4159
+ function $2fafbbbf345dcde0$var$invert_promise(promise) {
4160
+ return new Promise((res, rej) => promise.then(rej, res));
6539
4161
  }
6540
- function $0c9d834f187cc4ff$export$9ed4fbc47d558f94(interception_callback) {
6541
- const process_entries = entries => entries.forEach(interception_callback);
6542
- const dataLayer = globalThis.dataLayer ||= [];
6543
- // Process entries that are already queued at this point
6544
- process_entries(dataLayer);
6545
- // And then process any future entries, making sure to pass them on to other potential proxies to the push function
6546
- dataLayer.push = new Proxy(dataLayer.push, {
6547
- apply(target, this_arg, args_list) {
6548
- try {
6549
- process_entries(args_list);
6550
- } catch (e) {
6551
- $268cbd9e4ade92db$export$f18d5b0af29128b7([e, "Processing entries from dataLayer failed"], "warning");
6552
- }
6553
- return target.apply(this_arg, args_list);
6554
- }
6555
- });
4162
+ function $2fafbbbf345dcde0$export$947a20746936143d(promises) {
4163
+ return Promise?.any?.(promises) ?? $2fafbbbf345dcde0$var$invert_promise(Promise.all([...promises].map($2fafbbbf345dcde0$var$invert_promise)));
6556
4164
  }
6557
- function $0c9d834f187cc4ff$export$ff8673d5dea82bd4(tenant, id_extractor) {
6558
- (async () => {
6559
- for await (const href of (0, $69f7524c8bdd85b4$export$a9d39e43ae273d26)) {
6560
- const order_id = id_extractor(new URL(href));
6561
- if (order_id && typeof order_id === "string") $0c9d834f187cc4ff$export$1ac466d53a6636ac(tenant, order_id);
6562
- }
6563
- })().catch(e => $268cbd9e4ade92db$export$f18d5b0af29128b7([e, "Extracting and sending transaction IDs from URL failed"], "warning"));
4165
+ async function $44909e19109bf973$export$836f70a28c317905(product_id) {
4166
+ if (typeof BroadcastChannel != "function") return;
4167
+ const bc = new BroadcastChannel("right_click_attribution");
4168
+ $e6c6e7929ea385ae$export$de56f1198d121036("Broadcasting", product_id, "to", bc);
4169
+ bc.postMessage(product_id);
4170
+ bc.close();
6564
4171
  }
6565
- function $0c9d834f187cc4ff$export$1ac466d53a6636ac(t, input_id, session_id = $e0a87646d12cb987$export$61e7e1f11e96692f(), filter) {
6566
- const transaction_id = typeof filter == "function" ? filter(input_id) : input_id;
6567
- if (!transaction_id) {
6568
- $e6c6e7929ea385ae$export$de56f1198d121036("Not sending", transaction_id, "because it didn't pass filter");
6569
- return;
4172
+ function $44909e19109bf973$export$58c56fe2313fdbe3(elements, display, info, get_event_listener_remover) {
4173
+ if (typeof BroadcastChannel != "function") return elements;
4174
+ const disconnectors = [];
4175
+ const handler = $268cbd9e4ade92db$export$b3bbfd758f11cfa9(e => $44909e19109bf973$export$8f66c4c7fb96eda2(e, ("variant_index" in display ? display.variant_displays[display.variant_index] : display).product_id));
4176
+ const auxclick_handler = e => e.button === 1 && handler(e);
4177
+ for (let i = 0; i < elements?.length; i++) {
4178
+ const element = elements[i];
4179
+ element.addEventListener("contextmenu", handler);
4180
+ element.addEventListener("auxclick", auxclick_handler); // actual wheel click - some mouses / OS:es also dispatch auxclick on rightclick
4181
+ if (get_event_listener_remover) disconnectors.push(() => {
4182
+ element.removeEventListener("contextmenu", handler);
4183
+ element.removeEventListener("auxclick", auxclick_handler);
4184
+ });
6570
4185
  }
6571
- $e6c6e7929ea385ae$export$de56f1198d121036("Sending this order id:", transaction_id, "(before filtering it was", input_id, ")");
6572
- const payload = {
6573
- tenant: t.tenant,
6574
- market: t.market,
6575
- events: [{
6576
- event_type: "transaction_mapping",
6577
- transaction_id: transaction_id,
6578
- session_id: session_id
6579
- }]
6580
- };
6581
- $0c84f8e99aac5765$export$cc3b6ddf805f6156((0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/v2/track", payload);
4186
+ get_event_listener_remover?.(() => disconnectors.forEach(disconnector => disconnector()));
4187
+ return elements;
6582
4188
  }
6583
- function $5a44db2d2c8361b9$export$1ff14fec60ed5697(t, filter) {
6584
- try {
6585
- $c18ce8dadd041cdd$export$674d8cd8b6868154();
6586
- // @ts-ignore
6587
- ga($268cbd9e4ade92db$export$b3bbfd758f11cfa9(async function (tracker) {
6588
- let get_all_function = window?.ga?.getAll; // https://sentry.io/organizations/depictai-0o/issues/3621911835/?project=5476183&referrer=slack
6589
- if (typeof get_all_function !== "function") get_all_function = await $e6d67ef355abb2dc$export$2fc1a072736ae2f6(window, "ga", "getAll");
6590
- // @ts-ignore
6591
- const all_trackers = get_all_function.call(ga);
6592
- $e6c6e7929ea385ae$export$de56f1198d121036("we have trackers", all_trackers);
6593
- // @ts-ignore
4189
+ async function $44909e19109bf973$export$8f66c4c7fb96eda2(e, product_id) {
4190
+ $e6c6e7929ea385ae$export$de56f1198d121036("Contextmenu was invoked", e);
4191
+ const element = e.currentTarget || e.target;
4192
+ const bc = new BroadcastChannel("right_click_attribution");
4193
+ const got_wanted_event = await $2fafbbbf345dcde0$export$947a20746936143d([new Promise(resolve => {
4194
+ bc.addEventListener("message", $268cbd9e4ade92db$export$b3bbfd758f11cfa9(msg => {
6594
4195
  const {
6595
- P: P
6596
- } = ga;
6597
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9(modify_trackers_of_iterable)(all_trackers);
6598
- if (typeof P?.push === "function")
6599
- // this check is just so we don't fail if this doesn't exist for some reason, but it always should
6600
- P.push = new Proxy(P.push, {
6601
- apply(target, this_arg, args_list) {
6602
- const retval = target.apply(this_arg, args_list);
6603
- $268cbd9e4ade92db$export$b3bbfd758f11cfa9(modify_trackers_of_iterable)(args_list);
6604
- return retval;
6605
- }
6606
- });
6607
- function modify_trackers_of_iterable(array) {
6608
- for (const tracker of array) $268cbd9e4ade92db$export$b3bbfd758f11cfa9($5a44db2d2c8361b9$var$make_tracker_send_to_depict)(tracker, t, filter);
6609
- }
4196
+ data: data
4197
+ } = msg;
4198
+ $e6c6e7929ea385ae$export$de56f1198d121036("Recieved broadcast channel event", data, msg);
4199
+ if (data == product_id) resolve(true);
6610
4200
  }));
4201
+ }), new Promise(r => setTimeout(r, 60000, false))]);
4202
+ if (got_wanted_event) {
4203
+ const click = new MouseEvent("click", {
4204
+ view: window,
4205
+ bubbles: true,
4206
+ cancelable: true,
4207
+ metaKey: true
4208
+ });
4209
+ $e6c6e7929ea385ae$export$de56f1198d121036("Someone broadcasted our product_id! Simulating a click event on the element that was contextmenu'd", element, click);
4210
+ element.addEventListener("click", e => (e.preventDefault(), false), {
4211
+ once: true
4212
+ });
4213
+ element.dispatchEvent(click);
4214
+ } else $e6c6e7929ea385ae$export$de56f1198d121036("Our product_id did not get broadcasted, closing channel");
4215
+ bc.close();
4216
+ }
4217
+ let $72ee205b59322497$var$last_page_pageview_sent_for;
4218
+ async function $72ee205b59322497$export$eee4c4d924348b05(data) {
4219
+ // Send page view to depict if needed
4220
+ try {
4221
+ const {
4222
+ href: href
4223
+ } = location;
4224
+ if ($72ee205b59322497$var$last_page_pageview_sent_for !== href) {
4225
+ $72ee205b59322497$var$last_page_pageview_sent_for = href;
4226
+ $e0a87646d12cb987$export$82badda1f9923310({
4227
+ ...data,
4228
+ type: "page_view"
4229
+ });
4230
+ if (data.product_id) await $44909e19109bf973$export$836f70a28c317905(data.product_id); // this takes care of right click click attribution - broadcasts the URL of the current page
4231
+ }
6611
4232
  } catch (error) {
6612
- $268cbd9e4ade92db$export$f18d5b0af29128b7(error, "error");
4233
+ $268cbd9e4ade92db$export$f18d5b0af29128b7([error, "Sending page view failed"], "warning");
6613
4234
  }
6614
4235
  }
6615
- function $5a44db2d2c8361b9$var$make_tracker_send_to_depict(
6616
- // @ts-ignore
6617
- ga_tracker, t, filter) {
6618
- // Docs for analytics.js Tasks:
6619
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks
6620
- const sendHitTask = "sendHitTask";
6621
- const originalSendHitTask = ga_tracker.get(sendHitTask);
6622
- ga_tracker.set(sendHitTask, model => {
6623
- originalSendHitTask(model);
6624
- // console.log('Sent original hit, now sending to depict');
6625
- try {
6626
- const dsid = $e0a87646d12cb987$export$61e7e1f11e96692f();
6627
- const payload = model.get("hitPayload");
6628
- const sp = new URLSearchParams(payload);
6629
- const id = sp.get("ti");
6630
- if (id) {
6631
- $e6c6e7929ea385ae$export$de56f1198d121036("Got interesting analytics request", payload, id);
6632
- $0c9d834f187cc4ff$export$1ac466d53a6636ac(t, id, dsid, filter);
6633
- }
6634
- } catch (e) {
6635
- $268cbd9e4ade92db$export$f18d5b0af29128b7(e, "error");
6636
- }
6637
- });
4236
+ let $72ee205b59322497$var$sending_on_navigation = false;
4237
+ async function $72ee205b59322497$export$f7cb1bd47199ec38(data) {
4238
+ if (!$72ee205b59322497$var$sending_on_navigation) {
4239
+ $72ee205b59322497$var$sending_on_navigation = true;
4240
+ $268cbd9e4ade92db$export$b3bbfd758f11cfa9(async () => {
4241
+ for await (const _href of (0, $69f7524c8bdd85b4$export$a9d39e43ae273d26)) $72ee205b59322497$export$eee4c4d924348b05({
4242
+ tenant: data.tenant,
4243
+ market: data.market,
4244
+ product_id: await data.get_product_id(_href)
4245
+ });
4246
+ })();
4247
+ }
6638
4248
  }
6639
4249
 
6640
4250
  /**
@@ -6832,40 +4442,62 @@ const $23d6393391c08860$export$783ef16647773b3d = /*@__PURE__*/$41f528c04cc8a8da
6832
4442
  const meta = await $e6d67ef355abb2dc$export$2fc1a072736ae2f6(window, "ShopifyAnalytics", "meta");
6833
4443
  return meta?.product;
6834
4444
  }));
6835
- async function $40f3ad8d5c440ce9$export$b404e20f3c4a490e({
6836
- t: t,
6837
- experiment_id: experiment_id,
6838
- functions_to_variants: functions_to_variants
6839
- }) {
4445
+ const $55769f63ea4d8da4$export$5c069c93d2b7493f = delay => new Promise(resolve => setTimeout(resolve, delay));
4446
+ async function $d2fc3fb450961938$export$bcd70d5ed1cf6313(url, options, max_retries = 10, useFetch = fetch) {
4447
+ const ONE_MINUTE = 60000;
4448
+ const max_backoff_ms = ONE_MINUTE;
6840
4449
  const {
6841
- dlog: dlog,
6842
- err: err,
6843
- Sentry: Sentry
6844
- } = t,
6845
- start = new Date().getTime(),
6846
- optimize = await $e6d67ef355abb2dc$export$2fc1a072736ae2f6(window, "google_optimize"),
6847
- end = new Date().getTime();
6848
- dlog("Waited for google_optimize for", end - start, "ms");
6849
- // if (!optimize.get) {
6850
- // debugger;
6851
- // }
6852
- let modify_asnum = Number(optimize.get(experiment_id));
6853
- dlog("optimize says variant is", modify_asnum);
6854
- if (isNaN(modify_asnum)) {
6855
- fail_hard("couldn't get if we're version A or B from google optimize, please check experiment id (" + experiment_id + ")");
6856
- return;
4450
+ stack: stack
4451
+ } = new Error();
4452
+ const calculate_retry = delay => {
4453
+ delay *= 2 + Math.random();
4454
+ if (delay > max_backoff_ms) delay = max_backoff_ms * (1 + Math.random() / 10);
4455
+ return delay;
4456
+ };
4457
+ let try_again_in_ms = 100;
4458
+ let has_succeeded = false;
4459
+ let result = false;
4460
+ while (max_retries && !has_succeeded) try {
4461
+ const response = await useFetch(url, options);
4462
+ const {
4463
+ status: status,
4464
+ ok: ok
4465
+ } = response;
4466
+ if (!response || !ok || status !== 200) {
4467
+ if (status >= 400 && status < 500) {
4468
+ $268cbd9e4ade92db$export$b3bbfd758f11cfa9($d2fc3fb450961938$var$send_sentry_4xx)(response, options?.body || {}, stack);
4469
+ has_succeeded = true;
4470
+ } else if (status === 404) has_succeeded = true;
4471
+ $e6c6e7929ea385ae$export$de56f1198d121036("Response not ok", response);
4472
+ } else has_succeeded = true;
4473
+ result = response;
4474
+ } catch (error) {
4475
+ $e6c6e7929ea385ae$export$de56f1198d121036("Error while fetching: ", error, url, options);
4476
+ // Don't retry CORS
4477
+ if (error.message.includes("CORS") && error.name.includes("CORS")) has_succeeded = true;
4478
+ } finally {
4479
+ if (!has_succeeded) await $55769f63ea4d8da4$export$5c069c93d2b7493f(try_again_in_ms);
4480
+ try_again_in_ms = calculate_retry(try_again_in_ms);
4481
+ max_retries -= 1;
6857
4482
  }
6858
- const function_for_variant = functions_to_variants[modify_asnum];
6859
- if (!function_for_variant) {
6860
- fail_hard("Invalid variant " + modify_asnum);
4483
+ return result;
4484
+ }
4485
+ async function $d2fc3fb450961938$var$send_sentry_4xx(response, body, stack) {
4486
+ if (process.env.TENANT === "shopify-config" && response.status === 403)
4487
+ // Don't send requests in the shopify admin that say we need to re-authorize to sentry
6861
4488
  return;
6862
- }
6863
- dlog("found function for variant", function_for_variant, "executing");
6864
- return function_for_variant.call(t); // be nice to someone who needs t
6865
- function fail_hard(msg) {
6866
- dlog(msg);
6867
- Sentry.captureMessage(msg);
6868
- }
4489
+ const msg = `Validation error: got 4XX from API`;
4490
+ const text = await response.clone().text();
4491
+ $e6c6e7929ea385ae$export$de56f1198d121036(msg, "body", body, "response", response, "text", text, "stack", stack);
4492
+ (0, $61a34358bf0d3d8b$export$af2e17a20c2ea3c5).withScope(function (scope) {
4493
+ scope.setExtra("stack", stack);
4494
+ scope.setExtra("request_body", body);
4495
+ scope.setExtra("response", response);
4496
+ scope.setExtra("serialized_response", $45e05ec4fd7f1ee7$export$39d526a1194b6499(response));
4497
+ scope.setExtra("response_text", text);
4498
+ scope.setLevel("error");
4499
+ this.captureException(new Error(msg));
4500
+ });
6869
4501
  }
6870
4502
  function $b6542de877d46468$export$2c2f50b30b7b2576(el, attribute_name, async_iterable, quit_after_navigation = true) {
6871
4503
  (async () => {
@@ -7113,80 +4745,85 @@ function $c693a2d89c78efe6$var$deal_w_removal_of_node_array(node_array, push_dis
7113
4745
  push_disconnector(disconnect_observer);
7114
4746
  }
7115
4747
  }
7116
- const $fac9c96b6bbe43cd$export$3b75288f46cadd96 = () => new Array($3f34dc07544c5857$export$bb0a9c36cf454ea0(3, 8)).fill("\u2B1C").join("");
7117
- const $fac9c96b6bbe43cd$var$make_sel = (image_url, attribute) => `[${attribute}=${JSON.stringify(image_url)}]`;
7118
- const $fac9c96b6bbe43cd$export$a4eccf92efefa04d = (image_width, image_height, color = "#f6f7f8") => `data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='${image_width}' height='${image_height}' xmlns:v='https://vecta.io/nano'%3e%3cpath d='M0 0h${image_width}.016v${image_height}.01H0' fill='${encodeURIComponent(color)}'/%3e%3c/svg%3e`;
7119
- async function $fac9c96b6bbe43cd$export$2dd69958012e3e49({
7120
- override_rec_renderer = (0, $92bde32714bb1e07$export$50ce83ace0cdd87e),
7121
- image_width = 2000,
7122
- image_height = 2000,
7123
- num_items = 10,
7124
- color = "#d9d9d9",
7125
- on_no_rendering_result: on_no_rendering_result,
7126
- post_rendering: post_rendering
7127
- } = {}) {
7128
- const image_url = $fac9c96b6bbe43cd$export$a4eccf92efefa04d(image_width, image_height, color);
7129
- return async (t, rendering_options) => {
7130
- // @ts-ignore FIXME: this is a hack to make the type checker happy
7131
- const actual_rendering = override_rec_renderer(t, rendering_options).catch((0, $548fd58b14b25a52$export$8048b892d651b310)); // start rendering first
7132
- const placeholder_opts = {
7133
- ...rendering_options,
7134
- type: "placeholder",
7135
- recs: Array(num_items).fill(1).map(_ => ({
7136
- sale_price: NaN,
7137
- page_url: "#",
7138
- image_url: image_url,
7139
- original_price: NaN,
7140
- product_id: "placeholder",
7141
- recommendation_id: "placeholder",
7142
- title: $fac9c96b6bbe43cd$export$3b75288f46cadd96(),
7143
- brand: $fac9c96b6bbe43cd$export$3b75288f46cadd96()
7144
- })),
7145
- view_tracking: [],
7146
- click_tracking: [],
7147
- pre_processors: [],
7148
- post_processors: [elems => {
7149
- if (!elems?.length) return elems;
7150
- for (const elem of elems) {
7151
- if (elem instanceof HTMLElement) elem.style.cursor = "default";
7152
- elem?.classList?.add?.("placeholder");
7153
- elem.addEventListener("click", e => ($e6c6e7929ea385ae$export$de56f1198d121036("Supressing placeholder click", e), e.preventDefault(), e.stopPropagation(), false), true);
7154
- }
7155
- for (const img of $bf7f12fe044e41b2$export$5e63aea0cac01fa0(elems, ["src", "srcset", "data-src", "data-srcset"].map(attribute => $fac9c96b6bbe43cd$var$make_sel(image_url, attribute)).join(", "))) img.classList.add("nolazy"); // this gets ignored by all lazyloaders
7156
- return elems;
7157
- }]
7158
- };
7159
- // @ts-ignore FIXME: this is a hack to make the type checker happy
7160
- const placeholder_rendering = await override_rec_renderer(t, placeholder_opts).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
7161
- let set_should_stay_inserted;
7162
- const should_stay_inserted = new Promise(r => set_should_stay_inserted = r);
7163
- if (placeholder_rendering?.elements) {
7164
- const [template_els, _get_state, set_state] = $3721a5ccba25c247$export$3d04c40e7acc1a32(placeholder_rendering.elements);
7165
- actual_rendering.then(async rendering_result => {
7166
- if (typeof post_rendering == "function") await $268cbd9e4ade92db$export$b3bbfd758f11cfa9(post_rendering)(rendering_result);
7167
- const {
7168
- elements: elements
7169
- } = rendering_result || {};
7170
- await (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element(placeholder_rendering.elements[0]);
7171
- // await new Promise(r => window.addEventListener("contextmenu", r, { once: true }));
7172
- // it's possible that something after this ruins the array reference (aka [...elements]) and therefore it's not safe to call set_state again before the elements are sure to have a parentElement aka being in the DOM
7173
- set_state(elements ?? "");
7174
- if (!elements) {
7175
- on_no_rendering_result?.(rendering_result);
7176
- set_should_stay_inserted(false);
4748
+ let $e4bebbfa0f0b1454$var$existing_style_tag;
4749
+ let $e4bebbfa0f0b1454$var$reactions_in_last_s = 0;
4750
+ const $e4bebbfa0f0b1454$export$59ba1eb2c083f0cd = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(async css => {
4751
+ const style_tag = await ($e4bebbfa0f0b1454$var$existing_style_tag ||= (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).wait_for_element("head").then(head => {
4752
+ const tag = document.createElement("style");
4753
+ (0, $2a1cbc63a04d4a2d$export$b6ae1bc530f4c149).onremoved(
4754
+ // reinsertion for next.js's "portable" <head>
4755
+ tag, eoe => {
4756
+ if (document.head.contains(tag))
4757
+ // just make sure to not freak out if it's already been added again
4758
+ return;
4759
+ if ($e4bebbfa0f0b1454$var$reactions_in_last_s >= 10) {
4760
+ $268cbd9e4ade92db$export$f18d5b0af29128b7(new Error("Someone removed our styling but insists on it (10 removals in previous second). Giving up \uD83D\uDE2B"), "error");
4761
+ return;
4762
+ }
4763
+ $e6c6e7929ea385ae$export$de56f1198d121036("Someone removed our styling \uD83D\uDE24, reinserting", eoe);
4764
+ $e4bebbfa0f0b1454$var$reactions_in_last_s++;
4765
+ setTimeout(() => $e4bebbfa0f0b1454$var$reactions_in_last_s--, 1000);
4766
+ document.head.append(tag); // we're sure that head exists now since we inserted it there previously
4767
+ });
4768
+
4769
+ $e6c6e7929ea385ae$export$de56f1198d121036("inserting", tag, "into", head);
4770
+ return head.appendChild(tag);
4771
+ }));
4772
+ style_tag.append(css);
4773
+ });
4774
+ const $e4bebbfa0f0b1454$export$a4f97b27a0592e6c = url => (url ? new URL(url, window.location.origin) : window.location).pathname.split("/").filter(a => a).pop()?.replace(/\.html?$/i, "") || "";
4775
+ const $e4bebbfa0f0b1454$export$692b606677218a16 = callback => {
4776
+ if (document.depictwashere) {
4777
+ if (process.env.BUILD_TARGET === "dev") {
4778
+ $e6c6e7929ea385ae$export$de56f1198d121036("HMR tried to rerun us, reloading page");
4779
+ /* eslint-disable no-self-assign */
4780
+ location.href = location.href;
4781
+ }
4782
+ $e6c6e7929ea385ae$export$de56f1198d121036("Script has already ran", document.currentScript, "is exiting");
4783
+ return;
4784
+ }
4785
+ if (process.env.BUILD_TARGET === "dev") /* eslint-disable no-console */console.clear = new Proxy(console.clear, {
4786
+ apply(target, this_arg, arg_list) {
4787
+ if (new Error().stack?.split("\n").filter(Boolean).some(s => s.includes("http://localhost:1234/depict-ai.js"))) {
4788
+ /* eslint-disable no-console */console.log("CSS change detected through hack, reloading");
4789
+ location.reload();
7177
4790
  }
7178
- set_should_stay_inserted(true);
7179
- }).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
7180
- return {
7181
- ...placeholder_rendering,
7182
- elements: template_els,
7183
- should_stay_inserted: should_stay_inserted
7184
- };
4791
+ return target.apply(this_arg, arg_list);
4792
+ }
4793
+ });
4794
+ document.depictwashere = true;
4795
+ callback().catch((0, $548fd58b14b25a52$export$8048b892d651b310));
4796
+ };
4797
+ function $e4bebbfa0f0b1454$export$328e81c44cddf3c0(callback, get_market, supported_markets, unsupported_markets, preferred_demo_market) {
4798
+ $e4bebbfa0f0b1454$export$692b606677218a16(async () => {
4799
+ // Handle override for debug scripts (could be used on demo pages too)
4800
+ if (process.env.DEBUG === "true") {
4801
+ let localstorage_override;
4802
+ const query_param_override = new URLSearchParams(location.search).get("depict-override-market");
4803
+ if (query_param_override !== null) {
4804
+ $e6c6e7929ea385ae$export$de56f1198d121036(`Found ?depict-override-market=${query_param_override}. Using that as the market`);
4805
+ get_market = () => query_param_override;
4806
+ localStorage.setItem("depict-override-market", query_param_override);
4807
+ } else if ((localstorage_override = localStorage.getItem("depict-override-market")) !== null) {
4808
+ $e6c6e7929ea385ae$export$de56f1198d121036(`Found depict-override-market="${localstorage_override}" in localStorage. Using that as the market`);
4809
+ get_market = () => localstorage_override;
4810
+ }
4811
+ }
4812
+ const market = await get_market();
4813
+ if (supported_markets.includes(market)) {
4814
+ $e6c6e7929ea385ae$export$de56f1198d121036(`Initializing with market: ${market}`);
4815
+ return callback(market).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
4816
+ } else if (unsupported_markets.includes(market)) {
4817
+ $e6c6e7929ea385ae$export$de56f1198d121036(`Unsupported market: ${market}. Exiting...`);
4818
+ return;
4819
+ } else if (process.env.DEBUG === "true" && location.host.endsWith(".demo.depict.ai") && preferred_demo_market) {
4820
+ $e6c6e7929ea385ae$export$de56f1198d121036(`On demosite with default market override. Setting market to ${preferred_demo_market}`);
4821
+ return callback(preferred_demo_market).catch((0, $548fd58b14b25a52$export$8048b892d651b310));
7185
4822
  } else {
7186
- $e6c6e7929ea385ae$export$de56f1198d121036("Placeholder rendering went wrong, this is bad! Ditching placeholders");
7187
- return (await actual_rendering) || {};
4823
+ $548fd58b14b25a52$export$8048b892d651b310(new Error(`Unknown market: "${market}". Exiting...`));
4824
+ return;
7188
4825
  }
7189
- };
4826
+ });
7190
4827
  }
7191
4828
  function $d91a08ea384e6cd4$export$8ec5c86406f333ff() {
7192
4829
  const element_weak_set = new WeakSet();
@@ -8103,6 +5740,7 @@ var $a312bccd722ac9e4$var$_tmpl$ = /*#__PURE__*/$z0IcO$solidjsweb.template(`<div
8103
5740
  const $a312bccd722ac9e4$var$rendering_options_to_sourceset_component = /*@__PURE__*/new WeakMap();
8104
5741
  // Add nolazy to placeholders to avoid errors with the stupid lazyfier
8105
5742
  const $a312bccd722ac9e4$var$add_nolazy_to_placeholder = type => type === "placeholder" ? "nolazy" : "";
5743
+ const $a312bccd722ac9e4$export$a4eccf92efefa04d = (image_width, image_height, color = "#f6f7f8") => `data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='${image_width}' height='${image_height}' xmlns:v='https://vecta.io/nano'%3e%3cpath d='M0 0h${image_width}.016v${image_height}.01H0' fill='${encodeURIComponent(color)}'/%3e%3c/svg%3e`;
8106
5744
  let $a312bccd722ac9e4$var$inserted = false;
8107
5745
  const $a312bccd722ac9e4$export$788756b42446dc2d = ({
8108
5746
  init_with_placeholder: init_with_placeholder,
@@ -8116,7 +5754,7 @@ const $a312bccd722ac9e4$export$788756b42446dc2d = ({
8116
5754
  const img = process.env.BUILD_TARGET === "modern" || process.env.BUILD_TARGET === "dev" ? $a312bccd722ac9e4$var$Image(options) : $a312bccd722ac9e4$var$CompatibleImage(options);
8117
5755
  if (init_with_placeholder)
8118
5756
  // 10000 is a magic value, that is just supposed to be bigger than the size of the actual image.
8119
- img.querySelectorAll("img").forEach(i => i.src = $fac9c96b6bbe43cd$export$a4eccf92efefa04d(10000 * options.aspect_ratio, 10000));
5757
+ img.querySelectorAll("img").forEach(i => i.src = $a312bccd722ac9e4$export$a4eccf92efefa04d(10000 * options.aspect_ratio, 10000));
8120
5758
  return img;
8121
5759
  };
8122
5760
  function $a312bccd722ac9e4$var$Image({
@@ -8462,5 +6100,4 @@ function $da35c7e27be2a442$export$e35115e6d0715f77() {
8462
6100
  $z0IcO$solidjs.onCleanup(() => (0, $69f7524c8bdd85b4$export$7500cdfd37aafd43).delete(handler));
8463
6101
  return href;
8464
6102
  }
8465
- $e4a18bf12ad092d9$export$2cefb7e61fcbae00("utilishared", (0, $815f67c61b4c0a42$export$83d89fbfd8236492));
8466
- $parcel$exportWildcard(module.exports, $28e42b0009d694b2$exports);
6103
+ $e4a18bf12ad092d9$export$2cefb7e61fcbae00("utilishared", (0, $815f67c61b4c0a42$export$83d89fbfd8236492));