@depict-ai/ui 4.7.32 → 4.7.34

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
@@ -12,6 +12,9 @@ function $parcel$export(e, n, v, s) {
12
12
  configurable: true
13
13
  });
14
14
  }
15
+ $parcel$export(module.exports, "ModernResponsiveImage", () => $d212a67662c5cf38$export$140423fa4bfb6d63);
16
+ $parcel$export(module.exports, "setExtraDisplayTransformers", () => $606c221d98ba4d92$export$f98b8d5ea7207a1);
17
+ $parcel$export(module.exports, "getExtraDisplayTransformers", () => $606c221d98ba4d92$export$b2d94be4f02525b2);
15
18
  $parcel$export(module.exports, "remap_blocks_to_index", () => $d92f338ba8f9da9b$export$92aa5d691d588f3f);
16
19
  $parcel$export(module.exports, "useMobileHover", () => $8bf678c45948a297$export$d4d96868197be50e);
17
20
  $parcel$export(module.exports, "useVisibilityState", () => $55cbacb79d3e0cea$export$54299a3c81f5425);
@@ -52,7 +55,6 @@ $parcel$export(module.exports, "make_accurate_width_accessor", () => $f13855d1b9
52
55
  $parcel$export(module.exports, "RecommendationSlider", () => $72f96c4782db0b1b$export$9574e176201e5e8d);
53
56
  $parcel$export(module.exports, "RecommendationGrid", () => $1f8dbf7e28b3eff2$export$9756467d34d91cdb);
54
57
  $parcel$export(module.exports, "ShopifyResponsiveImg", () => $19950faaac026e09$export$6e5611bc7e57e477);
55
- $parcel$export(module.exports, "makeSizeAccessor", () => $19950faaac026e09$export$e6fffe67d4cdd848);
56
58
  $parcel$export(module.exports, "ImageContainer", () => $93304d59a9747aa6$export$94026ee33dbabc26);
57
59
  $parcel$export(module.exports, "SentryErrorBoundary", () => $edafe91daf3091d7$export$b69d0d92862de18b);
58
60
  $parcel$export(module.exports, "ExtraSentryContextProvider", () => $edafe91daf3091d7$export$240ecf5363d76c0f);
@@ -104,187 +106,32 @@ $parcel$export(module.exports, "SearchField", () => $c0a0659cf97e8eb2$export$316
104
106
  $parcel$export(module.exports, "BreadCrumbs", () => $1f4925833f07df29$export$5b7c3ce0ebe51f86);
105
107
  $parcel$export(module.exports, "QuickLinks", () => $1f4925833f07df29$export$de035477d6fef996);
106
108
  $parcel$export(module.exports, "CategoryPage", () => $14f289047713d67a$export$e2bf8ce7779e827e);
109
+ $parcel$export(module.exports, "makeSizeAccessors", () => $128302ab61dab8f1$export$54c6d6ff54e72743);
107
110
  /*! Depict.ai search and product listing SDK */
108
- const $b757f75811f3261f$export$83d89fbfd8236492 = "4.7.32";
109
- function $b54e6192d0caa293$export$d9f36cf74e24d595(media_query) {
110
- const signal = $gVhhF$solidjs.createSignal(false);
111
- $gVhhF$solidjs.onCleanup($gVhhF$depictaiutilishared.javascript_media_query(media_query, ({
112
- matches: matches
113
- }) => signal[1](matches)).remove);
114
- return signal[0];
115
- }
116
- function $17d06b3bcb035500$export$a79e666719b3647c(cols_at_size_) {
117
- const size_active = $gVhhF$solidjs.createMemo(() => cols_at_size_().map(([n_cols, min_width, max_width]) => {
118
- const media_query = $gVhhF$depictaiutilishared.layout_media_query_header(min_width, max_width).replaceAll("@media", "");
119
- const matches = $b54e6192d0caa293$export$d9f36cf74e24d595(media_query);
120
- return [matches, n_cols];
121
- }));
122
- const n_cols_currently_showing = $gVhhF$solidjs.createMemo(() => {
123
- try {
124
- const [, n_cols_currently_showing] = size_active().find(([media_query]) => media_query());
125
- return n_cols_currently_showing;
126
- } catch (e) {
127
- $gVhhF$depictaiutilishared.dwarn("No active size found in columnsAtSize - can't render content blocks or looks");
128
- return null;
129
- }
130
- });
131
- return n_cols_currently_showing;
132
- }
133
-
134
- // Errors caused by SDK consuming code interfacing with the SDK, not the SDK itself or other Depict packages
135
- class $7dd1edb2ee2b43ad$export$e1d52e4f0c7557a1 extends Error {}
136
- class $7dd1edb2ee2b43ad$export$aa14a9f43128f61f extends $7dd1edb2ee2b43ad$export$e1d52e4f0c7557a1 {
137
- constructor(templateError) {
138
- super("Uncaught error in product card template", {
139
- cause: templateError
140
- });
141
- }
142
- }
143
- var $edafe91daf3091d7$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div><!$><!/><!$><!/>`);
144
- const $edafe91daf3091d7$var$ExtraInfoContext = /*@__PURE__*/$gVhhF$solidjs.createContext();
145
- function $edafe91daf3091d7$export$240ecf5363d76c0f(props) {
146
- return $gVhhF$solidjsweb.createComponent($edafe91daf3091d7$var$ExtraInfoContext.Provider, {
147
- get value() {
148
- return props.getContext_;
149
- },
150
- get children() {
151
- return props.children;
152
- }
153
- });
154
- }
155
- function $edafe91daf3091d7$export$b69d0d92862de18b(props) {
156
- const getContextFunction = $gVhhF$solidjs.useContext($edafe91daf3091d7$var$ExtraInfoContext);
157
- return $gVhhF$solidjs.ErrorBoundary({
158
- fallback(err, retry) {
159
- const {
160
- message_: message_,
161
- severity_: severity_
162
- } = props;
163
- let message = message_;
164
- if (err instanceof (0, $7dd1edb2ee2b43ad$export$aa14a9f43128f61f)) {
165
- console.error(err.cause);
166
- message = `${message}: ${err.message}`;
167
- } else $gVhhF$depictaiutilishared.report([err, message_], severity_, getContextFunction?.());
168
- return (() => {
169
- var _el$ = $gVhhF$solidjsweb.getNextElement($edafe91daf3091d7$var$_tmpl$),
170
- _el$2 = _el$.firstChild,
171
- [_el$3, _co$] = $gVhhF$solidjsweb.getNextMarker(_el$2.nextSibling),
172
- _el$4 = _el$3.nextSibling,
173
- [_el$5, _co$2] = $gVhhF$solidjsweb.getNextMarker(_el$4.nextSibling);
174
- $gVhhF$solidjsweb.insert(_el$, message, _el$3, _co$);
175
- $gVhhF$solidjsweb.insert(_el$, () => props.on_error_?.(retry), _el$5, _co$2);
176
- $gVhhF$solidjsweb.effect(_$p => $gVhhF$solidjsweb.classList(_el$, Object.fromEntries(props.class_list_?.map(c => [c, true]) || []), _$p));
177
- return _el$;
178
- })();
179
- },
111
+ const $b757f75811f3261f$export$83d89fbfd8236492 = "4.7.34";
112
+ const $84798aaa863a4909$var$ListingContext = /*@__PURE__*/$gVhhF$solidjs.createContext();
113
+ function $84798aaa863a4909$export$e68cff63f76bd15b(props) {
114
+ const our_object = {};
115
+ return $gVhhF$solidjsweb.createComponent($84798aaa863a4909$var$ListingContext.Provider, {
116
+ value: our_object,
180
117
  get children() {
181
118
  return props.children;
182
119
  }
183
120
  });
184
121
  }
185
- var $75777da1687ba3f6$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div>`),
186
- $75777da1687ba3f6$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<style type=text/css>`);
187
- const $75777da1687ba3f6$export$c500183c31c2b22e = "--spans-columns";
188
- function $75777da1687ba3f6$export$ab6b147eec64fea5(props) {
189
- const container_class = "x" + $gVhhF$solidjs.createUniqueId();
190
- const container_element_ = (() => {
191
- var _el$ = $gVhhF$solidjsweb.getNextElement($75777da1687ba3f6$var$_tmpl$);
192
- $gVhhF$solidjsweb.spread(_el$, $gVhhF$solidjsweb.mergeProps(() => props.element_attributes, {
193
- "classList": {
194
- [container_class]: true
195
- }
196
- }), false, true);
197
- $gVhhF$solidjsweb.insert(_el$, () => props.children);
198
- $gVhhF$solidjsweb.runHydrationEvents();
199
- return _el$;
200
- })(); // Don't want this in the error boundary below, it should only be for the actual layouting
201
- return $gVhhF$solidjsweb.createComponent((0, $edafe91daf3091d7$export$b69d0d92862de18b), {
202
- message_: "Failed calculating css grid layout",
203
- severity_: "error",
204
- get children() {
205
- return $75777da1687ba3f6$export$e2f22da34aaf310a(props, container_element_, false, container_class);
206
- }
207
- });
208
- }
209
- function $75777da1687ba3f6$export$e2f22da34aaf310a(props, container_element, insert_after_container = false, container_class) {
210
- if (!container_class) {
211
- // only try to add if it wasn't provided, so that we have a code path without classList when doing SSR
212
- container_class = $gVhhF$depictaiutilishared.make_random_classname();
213
- container_element.classList.add(container_class);
214
- }
215
- const container_selector = `.depict .${container_class}`; // class so ppl can have id if needed
216
- const col_styling = $gVhhF$solidjs.createMemo(() => $75777da1687ba3f6$var$generate_media_queried_declarations({
217
- container_selector_: container_selector,
218
- default_grid_spacing_text: props.grid_spacing,
219
- cols_at_size_: props.cols_at_size,
220
- override_vertical_spacing_: props.override_vertical_spacing,
221
- top_row_shortened_by_: props.top_row_shortened_by_()
222
- }));
223
- const base_styling = $gVhhF$solidjs.createMemo(() => {
224
- return `${container_selector}{display:grid;}`;
225
- });
226
- const get_styling = $gVhhF$solidjs.createMemo(() => base_styling() + col_styling());
227
- const style_element = (() => {
228
- var _el$2 = $gVhhF$solidjsweb.getNextElement($75777da1687ba3f6$var$_tmpl$2);
229
- $gVhhF$solidjsweb.insert(_el$2, get_styling);
230
- return _el$2;
231
- })(); // need to create this after set_styling has been called or else there will be no styling in the SSR'd output
232
- if (insert_after_container) container_element.after(style_element);
233
- return [container_element, style_element];
234
- }
235
- function $75777da1687ba3f6$var$generate_media_queried_declarations({
236
- container_selector_: container_selector_,
237
- default_grid_spacing_text: default_grid_spacing_text,
238
- cols_at_size_: cols_at_size_,
239
- override_vertical_spacing_: override_vertical_spacing_,
240
- top_row_shortened_by_: top_row_shortened_by_
241
- }) {
242
- return cols_at_size_.map(options => {
243
- const [n_cols, min, max, grid_spacing_for_size] = options;
244
- const main_spacing_to_use = grid_spacing_for_size || default_grid_spacing_text;
245
- // See comment in else block below
246
- const can_use_gap = override_vertical_spacing_ ? $75777da1687ba3f6$var$can_use_gap_for_unit(override_vertical_spacing_) : $75777da1687ba3f6$var$can_use_gap_for_unit(main_spacing_to_use);
247
- let spacing_styling;
248
- let additional_styling = ""; // outside the media query
249
- if (can_use_gap) spacing_styling = `gap:${main_spacing_to_use};${override_vertical_spacing_ ? `row-gap:${override_vertical_spacing_};` : ``}`;else {
250
- // When using percent units, which our default styling does (because convenient) and our interface relies on (hard to specify different gaps for different screen sizes)
251
- // row gaps in grids are relative to the whole height of the grid, maybe see also https://stackoverflow.com/a/53563865. The issue with that is that as we load more products, the gap grows. Also, it breaks existing integrations.
252
- // Logical thought: use margins for the vertical spacing. But margins in grids are apparently relative to the size of the individual items in grids.
253
- // Given that, and that content blocks can be of different width, we have to do some complicated calculations to convert the provided gap, which is in gap of the total container width, to a margin of the individual items.
254
- const vertical_spacing_to_use = override_vertical_spacing_ ?? main_spacing_to_use;
255
- const width_multiplier = `var(${$75777da1687ba3f6$export$c500183c31c2b22e}, 1)`; // How many cards wide the current item is (needed because content blocks)
256
- const one_item_width_exclusing_gaps = `calc(calc(100 / ${n_cols}) - calc(calc(${n_cols * 2 - 2} * calc(${$75777da1687ba3f6$var$strip_percent_unit(vertical_spacing_to_use)} / 2)) / ${n_cols}))`; // Width of one item in percent of the whole
257
- // Equation from layout.tsx, also used in CheckboxGrid. Needs half spacing for some reason
258
- const this_item_width_meat = `calc(${one_item_width_exclusing_gaps} * ${width_multiplier})`; // Width of just the card
259
- const this_item_width_gaps = `calc(calc(${width_multiplier} - 1) * ${$75777da1687ba3f6$var$strip_percent_unit(vertical_spacing_to_use)})`; // Width of the gaps
260
- const this_item_width = `calc(${this_item_width_meat} + ${this_item_width_gaps})`; // Width of this item including gaps
261
- // this_item_width needs to be unitless, and since plain css can't do calc(40% / 5%) which would become unitless we need to strip all units in the calculations before
262
- const convert_top_spacing_to_item_width_percentage = spacing => `calc(calc(100 / ${this_item_width}) * ${spacing})`; // Now finally we can convert the desired spacing to a percentage of this individual item's width (including gaps that would be there but aren't because content blocks span them)
263
- spacing_styling = `column-gap:${main_spacing_to_use};`; // Still use gaps in the horizontal direction because that works flawlessly
264
- // Re-use old layout code to get the correct :nth-child declarations for the top margins
265
- additional_styling = $gVhhF$depictaiutilishared.n_col_styling_with_dist(container_selector_ + ">", convert_top_spacing_to_item_width_percentage(default_grid_spacing_text), [[n_cols, min, max, grid_spacing_for_size ? convert_top_spacing_to_item_width_percentage(grid_spacing_for_size) : null]], "grid", override_vertical_spacing_ ? convert_top_spacing_to_item_width_percentage(override_vertical_spacing_) : override_vertical_spacing_, top_row_shortened_by_);
266
- }
267
- const media_query_body = `${container_selector_}{${spacing_styling}grid-template-columns:repeat(${n_cols},minmax(0,1fr));}`;
268
- return `${$gVhhF$depictaiutilishared.layout_media_query_header(min, max)}{${media_query_body}}${additional_styling}`;
269
- }).join("");
270
- }
271
- function $75777da1687ba3f6$var$can_use_gap_for_unit(spacing) {
272
- const trimmed_spacing = spacing.trim();
273
- return !trimmed_spacing.includes("%");
274
- }
275
- function $75777da1687ba3f6$var$strip_percent_unit(css_value) {
276
- return css_value.replaceAll("%", "");
122
+ function $84798aaa863a4909$export$8d0c4fdbb05a2f2e() {
123
+ return $gVhhF$solidjs.useContext($84798aaa863a4909$var$ListingContext);
277
124
  }
278
- var $9fe9883b1d8ecccc$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<span>`);
279
- function $9fe9883b1d8ecccc$export$acb3eaade4b23afd(props) {
280
- // Work around https://github.com/solidjs/solid/issues/1980
125
+ var $93304d59a9747aa6$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div>`);
126
+ function $93304d59a9747aa6$export$94026ee33dbabc26(props) {
281
127
  return (() => {
282
- var _el$ = $gVhhF$solidjsweb.getNextElement($9fe9883b1d8ecccc$var$_tmpl$);
128
+ var _el$ = $gVhhF$solidjsweb.getNextElement($93304d59a9747aa6$var$_tmpl$);
129
+ $gVhhF$solidjsweb.insert(_el$, () => props.children);
283
130
  $gVhhF$solidjsweb.effect(_p$ => {
284
- var _v$ = `${props.class || ""} depict-placeholder`,
285
- _v$2 = props.style;
286
- _v$ !== _p$.e && $gVhhF$solidjsweb.className(_el$, _p$.e = _v$);
287
- _p$.t = $gVhhF$solidjsweb.style(_el$, _v$2, _p$.t);
131
+ var _v$ = `padding-bottom:calc(calc(1 / ${props.aspectRatio}) * 100%)`,
132
+ _v$2 = "s-image-container" + (props.class ? " " + props.class : "");
133
+ _p$.e = $gVhhF$solidjsweb.style(_el$, _v$, _p$.e);
134
+ _v$2 !== _p$.t && $gVhhF$solidjsweb.className(_el$, _p$.t = _v$2);
288
135
  return _p$;
289
136
  }, {
290
137
  e: undefined,
@@ -293,59 +140,624 @@ function $9fe9883b1d8ecccc$export$acb3eaade4b23afd(props) {
293
140
  return _el$;
294
141
  })();
295
142
  }
296
- function $3bc4a89b971a3af5$export$3f37af283f8fb843(props) {
297
- const style = $gVhhF$solidjs.createMemo(() => {
298
- const {
299
- style: style,
300
- height: height,
301
- width: width,
302
- aspectRatio: aspectRatio
303
- } = props;
304
- const is_image = aspectRatio != undefined;
305
- const size_data = is_image ? {
306
- width: "100%",
307
- "padding-bottom": `calc(calc(1 / ${aspectRatio}) * 100%)`
308
- } : {
309
- width: width,
310
- height: height
311
- };
312
- return {
313
- display: "block",
314
- ...(style || {}),
315
- ...size_data
316
- };
317
- });
318
- return $gVhhF$solidjsweb.createComponent((0, $9fe9883b1d8ecccc$export$acb3eaade4b23afd), {
319
- get style() {
320
- return style();
143
+ const $129b9b9c010039d0$var$ProductCardIndexContext = /*@__PURE__*/$gVhhF$solidjs.createContext();
144
+ function $129b9b9c010039d0$export$11354f017ddc9790(props) {
145
+ return $gVhhF$solidjsweb.createComponent($129b9b9c010039d0$var$ProductCardIndexContext.Provider, {
146
+ get value() {
147
+ return props.index_;
321
148
  },
322
- get ["class"]() {
323
- return props.class;
149
+ get children() {
150
+ return props.children;
324
151
  }
325
152
  });
326
153
  }
327
- var $d92f338ba8f9da9b$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class=content-block-wrapper>`);
328
- function $d92f338ba8f9da9b$export$791ef57e62e21c3f({
329
- content_blocks_: incoming_content_blocks,
330
- cols_at_size_: cols_at_size_,
331
- set_top_row_shortened_by_: set_top_row_shortened_by_
154
+ function $129b9b9c010039d0$export$e3faf4d95300054f() {
155
+ return $gVhhF$solidjs.useContext($129b9b9c010039d0$var$ProductCardIndexContext);
156
+ }
157
+ let $3ea8e0af95b5b7d2$var$browserIsBugged = false;
158
+ function $3ea8e0af95b5b7d2$export$2972b890694ced75(callback, {
159
+ timeout: timeout
332
160
  }) {
333
- // these are by row
334
- const [content_blocks, set_content_blocks] = $gVhhF$solidjsstore.createStore([]);
335
- const n_cols_currently_showing_ = $17d06b3bcb035500$export$a79e666719b3647c(cols_at_size_);
336
- $gVhhF$solidjs.createEffect(() => {
337
- const incoming_value = incoming_content_blocks();
338
- if (!incoming_value) {
339
- set_content_blocks([]);
340
- return;
341
- }
342
- set_content_blocks($gVhhF$solidjsstore.reconcile(incoming_value, {
343
- key: "content"
344
- })); // key: Make moving blocks faster, see https://github.com/solidjs/solid/issues/1925#issuecomment-1769671596
161
+ if ($3ea8e0af95b5b7d2$var$browserIsBugged) timeout /= 4;
162
+ const cancel = () => {
163
+ cancelIdleCallback(idleHandle);
164
+ clearTimeout(racingTimeout);
165
+ };
166
+ const idleHandle = requestIdleCallback(deadline => {
167
+ cancel();
168
+ return callback(deadline);
169
+ }, {
170
+ timeout: timeout
345
171
  });
346
-
347
- const get_wrapped_blocks_ = $d92f338ba8f9da9b$var$wrap_blocks_in_div(content_blocks, n_cols_currently_showing_);
348
- $gVhhF$solidjs.createComputed(() => {
172
+ const racingTimeout = setTimeout(() => {
173
+ $gVhhF$depictaiutilishared.dwarn("Browser did not respect requestIdleCallback timeout");
174
+ $3ea8e0af95b5b7d2$var$browserIsBugged = true;
175
+ cancel();
176
+ callback({
177
+ didTimeout: false,
178
+ timeRemaining() {
179
+ return 500;
180
+ }
181
+ });
182
+ }, timeout + 1000);
183
+ return cancel;
184
+ }
185
+ const $19950faaac026e09$var$onIdleFunctionsSymbol = /*@__PURE__*/Symbol("onIdleFunctions");
186
+ const $19950faaac026e09$export$f8945274f08a3105 = /*@__PURE__*/Symbol("listingContextAspectRatios");
187
+ const $19950faaac026e09$export$6066eb417ed2e9f7 = /*@__PURE__*/Symbol("listingContextAspectRatios");
188
+ function $19950faaac026e09$export$6e5611bc7e57e477(props) {
189
+ const img = new Image(); // Need to use new Image or browser might not start loading image before it's in the DOM
190
+ const [ourRatioKeyed, setOurRatioKeyed] = $gVhhF$solidjs.createSignal();
191
+ const sizeToUse = $gVhhF$solidjs.createMemo(() => {
192
+ // props.size could be a getter that expects a cleanup so get it in this memo instead of where we set img.sizes (also we need to multiply, and it's good with some diffing here so people calling the comp don't have to)
193
+ const incomingSize = props.size();
194
+ const ratio = ourRatioKeyed();
195
+ const containerHeight = props.sizeHeight?.();
196
+ if (!incomingSize || !ratio || !containerHeight || getComputedStyle(img).objectFit !== "cover") return incomingSize;
197
+ const maybeCorrectedSize = ratio * containerHeight;
198
+ return Math.round(Math.max(incomingSize, maybeCorrectedSize));
199
+ });
200
+ const src_options = $gVhhF$solidjs.createMemo(() => {
201
+ const {
202
+ src: src,
203
+ customUrls: customUrls
204
+ } = props;
205
+ const fallback_src = (customUrls || $19950faaac026e09$export$1d6267828870adda)(src, 400);
206
+ const srcset = $19950faaac026e09$var$make_srcset(props.src, props.resolutions || [64, 128, 256, 300, 400, 512, 640, 768, 1024, 1280, 1536, 2048, 2560, 3072, 3584, 4096], customUrls);
207
+ // The order here *might* matter - I've seen mobile safari always start with loading the 400px version when it was reversed
208
+ return {
209
+ srcset: srcset,
210
+ src: fallback_src
211
+ };
212
+ });
213
+ // Work around https://github.com/solidjs/solid/issues/1828
214
+ const [, otherAttributes] = $gVhhF$solidjs.splitProps(props, ["resolutions", "size", "src", "srcSet", "loading", "keyRatioUpdating", "sizeHeight", "customUrls" // Can't have properties ending on underscore because the property name mangling will get confused by this <-
215
+ ]);
216
+
217
+ const [hasSetSize, setHasSetSize] = $gVhhF$solidjs.createSignal(false);
218
+ const [hasDecoded, setHasDecoded] = $gVhhF$solidjs.createSignal(false);
219
+ const productCardIndexAccessor = $129b9b9c010039d0$export$e3faf4d95300054f();
220
+ const listingContext = $84798aaa863a4909$export$8d0c4fdbb05a2f2e();
221
+ const isPrioritisedImage = $gVhhF$solidjs.createMemo(() => productCardIndexAccessor?.() < 8);
222
+ const shouldActuallyEnableLazyLoading = $gVhhF$solidjs.createMemo(() => {
223
+ const {
224
+ loading: loading
225
+ } = props;
226
+ if (loading === "force-lazy") return true;
227
+ return loading === "lazy" && !isPrioritisedImage();
228
+ });
229
+ const modifiedOtherAttributes = $gVhhF$solidjs.mergeProps(otherAttributes, {
230
+ get loading() {
231
+ return shouldActuallyEnableLazyLoading() ? "lazy" : undefined;
232
+ }
233
+ });
234
+ // Batch idle callbacks so that MutationObserver can batch the resulting mutations better, so we don't lose tons of CPU time to MutationObservers doing lots of things for each image
235
+ // Happened on singular, they have some weird observer (+we also have one but ours is at least 3x more efficient)
236
+ const executeWhenIdleBatched = (fn, isSizesUpdate) => {
237
+ if (typeof requestIdleCallback !== "function") return setTimeout(fn); // Old browsers don't get optimisation
238
+ if ((!isSizesUpdate || !sizeSetFastPath) && $gVhhF$solidjs.untrack(isPrioritisedImage)) return fn(); // If we're one of the first 8 images, execute the callbacks immediately (improves lighthouse metrics)
239
+ // unless we're just a `sizes` update after the initial sizes setting (this optimisation makes the looks animation a lot smoother on low-cpu devices)
240
+ const existingStack = listingContext?.[$19950faaac026e09$var$onIdleFunctionsSymbol];
241
+ if (existingStack) return existingStack.add(fn);
242
+ const newStack = new Set([fn]);
243
+ if (listingContext) listingContext[$19950faaac026e09$var$onIdleFunctionsSymbol] = newStack;
244
+ const processStackWhenIdle = () => $3ea8e0af95b5b7d2$export$2972b890694ced75($gVhhF$depictaiutilishared.catchify(deadline => {
245
+ const start = performance.now();
246
+ const thirdDeadlineTime = deadline.timeRemaining() / 3; // observers coming after this take up 2-3x the time so don't use all of it
247
+ for (const fn of newStack) {
248
+ newStack.delete(fn);
249
+ fn();
250
+ const timeTaken = performance.now() - start;
251
+ if ((!deadline.timeRemaining() || timeTaken > thirdDeadlineTime) && newStack.size) {
252
+ // There's still work to be done but no time, so schedule another idle callback
253
+ processStackWhenIdle();
254
+ return;
255
+ }
256
+ }
257
+ // Stack is empty
258
+ if (listingContext) delete listingContext[$19950faaac026e09$var$onIdleFunctionsSymbol];
259
+ }), {
260
+ timeout: 15000
261
+ } // long timeout, better to not have images than to freeze the browser. But also we don't want to confuse user why no iamges are loading
262
+ );
263
+
264
+ processStackWhenIdle();
265
+ };
266
+ let sizeSetFastPath = false;
267
+ let hasDecodedFastPath = false;
268
+ let timeoutSet = false;
269
+ let gotCleanedUp = false;
270
+ let srcJustChanged = true;
271
+ img.classList.add("s-responsive-image");
272
+ if (listingContext) {
273
+ let prevValue;
274
+ const aspectRatios = listingContext[$19950faaac026e09$export$f8945274f08a3105] ||= new Set();
275
+ const [, setMostPrevalentAspectRatio] = listingContext[$19950faaac026e09$export$6066eb417ed2e9f7] ||= $gVhhF$solidjs.createSignal();
276
+ img.addEventListener("load", $gVhhF$depictaiutilishared.catchify(() => {
277
+ const aspectRatio_ = img.naturalWidth / img.naturalHeight;
278
+ if (srcJustChanged)
279
+ // Always key object-fit-cover compensation to avoid loading-different-images-infinite-loop
280
+ setOurRatioKeyed(aspectRatio_);else if (props.keyRatioUpdating) return;
281
+ srcJustChanged = false;
282
+ // Save our aspect ratio whenever it changes, so that we can base the containers on the most dominant aspect ratio, used in SearchModalV2 and LookItem
283
+ if (prevValue) aspectRatios.delete(prevValue);
284
+ const newValue = !isNaN(aspectRatio_) ? {
285
+ aspectRatio_: aspectRatio_
286
+ } : undefined;
287
+ if (newValue) aspectRatios.add(newValue);
288
+ prevValue = newValue;
289
+ // Do all calculations resulting of an update directly, for performance
290
+ const asArray = [...aspectRatios].map(({
291
+ aspectRatio_: aspectRatio_
292
+ }) => aspectRatio_);
293
+ const mostPrevalentAspectRatio = $gVhhF$depictaiutilishared.findMostFrequentItem(asArray);
294
+ setMostPrevalentAspectRatio(mostPrevalentAspectRatio);
295
+ }));
296
+ $gVhhF$solidjs.onCleanup(() => prevValue && aspectRatios.delete(prevValue));
297
+ }
298
+ $gVhhF$solidjs.onCleanup(() => gotCleanedUp = true);
299
+ $gVhhF$solidjsweb.spread(img, $gVhhF$solidjs.mergeProps(modifiedOtherAttributes), false, true);
300
+ $gVhhF$solidjs.createRenderEffect(() => {
301
+ props.src;
302
+ srcJustChanged = true;
303
+ });
304
+ $gVhhF$solidjs.createEffect(() => {
305
+ if (!sizeToUse()) return; // wait until we have a size, run every time the size changes
306
+ if (timeoutSet) return;
307
+ const handler = $gVhhF$depictaiutilishared.catchify(() => {
308
+ if (gotCleanedUp) return;
309
+ img.sizes = `${sizeToUse()}px`; // use latest available value of size in case it has changed
310
+ if (!sizeSetFastPath) {
311
+ setHasSetSize(true);
312
+ sizeSetFastPath = true;
313
+ }
314
+ timeoutSet = false;
315
+ });
316
+ // Throttle the updating of sizes to avoid unnecessary image re-fetches during resize
317
+ // And also because we first set src after sizes has been set, wait with loading and decoding images until browser is idle
318
+ // This greatly improves performance when loading (more) products
319
+ // See https://depictaiworkspace.slack.com/archives/C05NJ0K3WRL/p1698220617663139
320
+ timeoutSet = true; // Important to set timeoutSet before the call to executeWhenIdleBatched since if this is an important image executeWhenIdleBatched will execute fn immediately
321
+ executeWhenIdleBatched(handler, true);
322
+ });
323
+ const dontLoadImageYet = $gVhhF$solidjs.createMemo(() => !sizeToUse() || !hasSetSize()); // Moving this condition into a memo saves us from re-setting src and srcset (expensive) if just props.size changes
324
+ $gVhhF$solidjs.createEffect(() => {
325
+ if (dontLoadImageYet()) return; // If size isn't known or set, don't assign src yet since it would cause the most low res image to load
326
+ Object.assign(img, src_options());
327
+ // Add to DOM once decoded to not require/block any paints before image has completed loading and avoid showing broken image symbol
328
+ // We can do this because there has to be a container around us giving us a size
329
+ // No need to listen if we're already in the DOM
330
+ if (hasDecodedFastPath) return;
331
+ if (shouldActuallyEnableLazyLoading()) {
332
+ // For lazy loading there's no decoding to wait for as it only occurs when the image is visible
333
+ // Make sure src is set before we put the image into the DOM though so no broken image symbol is shown
334
+ setHasDecoded(true);
335
+ hasDecodedFastPath = true;
336
+ return;
337
+ }
338
+ img.decode().catch(e => $gVhhF$depictaiutilishared.dwarn("Failed to decode image", e, img)) // Display the image also if loading failed so webdev can debug and doesn't get "no image"
339
+ .then(async () => {
340
+ // Also wait with inserting image (i.e. paint) until browser is idle
341
+ await new Promise(r => executeWhenIdleBatched(r, false));
342
+ if (gotCleanedUp) return;
343
+ setHasDecoded(true);
344
+ hasDecodedFastPath = true;
345
+ });
346
+ });
347
+ return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
348
+ get when() {
349
+ return hasDecoded();
350
+ },
351
+ children: img
352
+ });
353
+ }
354
+ function $19950faaac026e09$var$make_srcset(url, resolutions, customGenerateImageUrl_) {
355
+ return resolutions.map(width => `${(customGenerateImageUrl_ || $19950faaac026e09$export$1d6267828870adda)(url, width)} ${width}w`).join(", ");
356
+ }
357
+ function $19950faaac026e09$export$1d6267828870adda(url, width) {
358
+ // Even just creating one `URL` object per image src and then setting the search parameter is quite slow (0.25ms to set the width param)
359
+ // We're making the assumptions that the url has already at least one query parameter and that the image resizing service will choose the last one out of a duplicate width parameter (shopify's does)
360
+ // That way we can just to string concatenation which is insanely fast
361
+ return url + "&width=" + encodeURIComponent(width);
362
+ }
363
+ var $9fe9883b1d8ecccc$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<span>`);
364
+ function $9fe9883b1d8ecccc$export$acb3eaade4b23afd(props) {
365
+ // Work around https://github.com/solidjs/solid/issues/1980
366
+ return (() => {
367
+ var _el$ = $gVhhF$solidjsweb.getNextElement($9fe9883b1d8ecccc$var$_tmpl$);
368
+ $gVhhF$solidjsweb.effect(_p$ => {
369
+ var _v$ = `${props.class || ""} depict-placeholder`,
370
+ _v$2 = props.style;
371
+ _v$ !== _p$.e && $gVhhF$solidjsweb.className(_el$, _p$.e = _v$);
372
+ _p$.t = $gVhhF$solidjsweb.style(_el$, _v$2, _p$.t);
373
+ return _p$;
374
+ }, {
375
+ e: undefined,
376
+ t: undefined
377
+ });
378
+ return _el$;
379
+ })();
380
+ }
381
+ function $3bc4a89b971a3af5$export$3f37af283f8fb843(props) {
382
+ const style = $gVhhF$solidjs.createMemo(() => {
383
+ const {
384
+ style: style,
385
+ height: height,
386
+ width: width,
387
+ aspectRatio: aspectRatio
388
+ } = props;
389
+ const is_image = aspectRatio != undefined;
390
+ const size_data = is_image ? {
391
+ width: "100%",
392
+ "padding-bottom": `calc(calc(1 / ${aspectRatio}) * 100%)`
393
+ } : {
394
+ width: width,
395
+ height: height
396
+ };
397
+ return {
398
+ display: "block",
399
+ ...(style || {}),
400
+ ...size_data
401
+ };
402
+ });
403
+ return $gVhhF$solidjsweb.createComponent((0, $9fe9883b1d8ecccc$export$acb3eaade4b23afd), {
404
+ get style() {
405
+ return style();
406
+ },
407
+ get ["class"]() {
408
+ return props.class;
409
+ }
410
+ });
411
+ }
412
+ function $061ff5b4c3d36171$export$89c6019e4baa40b1(props) {
413
+ const style = $gVhhF$solidjs.createMemo(() => {
414
+ const {
415
+ style: style,
416
+ height: height,
417
+ width: width
418
+ } = props;
419
+ return {
420
+ ...(style || {}),
421
+ height: height ?? "1em",
422
+ ...(width && {
423
+ width: width
424
+ })
425
+ };
426
+ });
427
+ return $gVhhF$solidjsweb.createComponent((0, $9fe9883b1d8ecccc$export$acb3eaade4b23afd), {
428
+ get style() {
429
+ return style();
430
+ },
431
+ get ["class"]() {
432
+ return props.class;
433
+ }
434
+ });
435
+ }
436
+ var $6f604560873e4f69$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class=instant-card><div class=img-part></div><div class=right-part><div class=title-brand-tagline><span class=title></span></div><div class=price-container>`);
437
+ const $6f604560873e4f69$export$8a2234b5b1a5ebd4 = "--image-aspect-ratio";
438
+ function $6f604560873e4f69$export$ee1733d9a8495996() {
439
+ return (() => {
440
+ var _el$ = $gVhhF$solidjsweb.getNextElement($6f604560873e4f69$var$_tmpl$),
441
+ _el$2 = _el$.firstChild,
442
+ _el$3 = _el$2.nextSibling,
443
+ _el$4 = _el$3.firstChild,
444
+ _el$5 = _el$4.firstChild,
445
+ _el$6 = _el$4.nextSibling;
446
+ $gVhhF$solidjsweb.insert(_el$2, $gVhhF$solidjsweb.createComponent((0, $3bc4a89b971a3af5$export$3f37af283f8fb843), {
447
+ aspectRatio: `var(${$6f604560873e4f69$export$8a2234b5b1a5ebd4}, 1)`
448
+ }));
449
+ $gVhhF$solidjsweb.insert(_el$5, $gVhhF$solidjsweb.createComponent((0, $061ff5b4c3d36171$export$89c6019e4baa40b1), {
450
+ width: "20ch",
451
+ height: "1em"
452
+ }));
453
+ $gVhhF$solidjsweb.insert(_el$6, $gVhhF$solidjsweb.createComponent((0, $061ff5b4c3d36171$export$89c6019e4baa40b1), {
454
+ width: "5ch",
455
+ height: "1em",
456
+ "class": "price"
457
+ }));
458
+ return _el$;
459
+ })();
460
+ }
461
+ function $128302ab61dab8f1$export$54c6d6ff54e72743(whatToWatch) {
462
+ const [width, setWidth] = $gVhhF$solidjs.createSignal(0);
463
+ const [height, setHeight] = $gVhhF$solidjs.createSignal(0);
464
+ const resizeObserver = new ResizeObserver($gVhhF$depictaiutilishared.catchify(records => $gVhhF$solidjs.batch(() => {
465
+ for (let j = 0; j < records.length; j++) {
466
+ const {
467
+ width: width,
468
+ height: height
469
+ } = records[j].contentRect;
470
+ // Padding hack makes that we can't use contentRect to get the height since that's apparently without padding
471
+ const definitiveHeight = height || whatToWatch.getBoundingClientRect().height;
472
+ if (definitiveHeight) setHeight(Math.ceil(definitiveHeight));
473
+ if (width) setWidth(Math.ceil(width));
474
+ }
475
+ })));
476
+ // If we start observing elements before they're in the DOM Chrome (Version 117.0.5938.92 (Official Build) (arm64)) sometimes gives us a resize event with a width of 0 and then doesn't dispatch one with the actual width once it's in the DOM. So we wait until the element is in the DOM before we start observing it.
477
+ // It doesn't seem to work even when waiting for it to be in the DOM, also wait an animation frame
478
+ const disconnect = (0, $gVhhF$depictaiutilishared.observer).onexists(whatToWatch, ({
479
+ element: element
480
+ }) => requestAnimationFrame($gVhhF$depictaiutilishared.catchify(() => resizeObserver.observe(element))));
481
+ $gVhhF$solidjs.onCleanup(() => {
482
+ resizeObserver.disconnect();
483
+ disconnect();
484
+ });
485
+ return [width, height];
486
+ }
487
+ const $a33065cfed827fc0$var$backupSizeSignal = /*@__PURE__*/$gVhhF$solidjs.createSignal();
488
+ const $a33065cfed827fc0$export$d7b7ab832c20e2f4 = /*@__PURE__*/Symbol("ShopifyContainedImage");
489
+ function $a33065cfed827fc0$export$e4b984597b71e989(props) {
490
+ const context = $84798aaa863a4909$export$8d0c4fdbb05a2f2e();
491
+ if (context && !context[$a33065cfed827fc0$export$d7b7ab832c20e2f4])
492
+ // create a signal that's the same for all items in this listing
493
+ context[$a33065cfed827fc0$export$d7b7ab832c20e2f4] = $gVhhF$solidjs.createSignal();
494
+ const [currentImageSize, setCurrentImageSize] = context?.[$a33065cfed827fc0$export$d7b7ab832c20e2f4] || $a33065cfed827fc0$var$backupSizeSignal; // use global fallback signal (might lead to blurry images) if no context is available
495
+ const [mostPrevalentAspectRatio] = context ?
496
+ // If the context exists we have to create the signal here as getting it here would be too late when it's created by ShopifyResponsiveImg below
497
+ context[(0, $19950faaac026e09$export$6066eb417ed2e9f7)] ||= $gVhhF$solidjs.createSignal() : [];
498
+ const container = $93304d59a9747aa6$export$94026ee33dbabc26({
499
+ // Write getters manually instead of using JSX, so we can do more complex logic in the aspectRatio getter without increasing bundle size
500
+ get class() {
501
+ return props.class;
502
+ },
503
+ get aspectRatio() {
504
+ if (props.autoAdjustAspectRatio) {
505
+ const targetRatio = mostPrevalentAspectRatio?.();
506
+ if (targetRatio != undefined) return `var(${(0, $6f604560873e4f69$export$8a2234b5b1a5ebd4)}, ${targetRatio})`;
507
+ }
508
+ return props.aspectRatio;
509
+ }
510
+ });
511
+ const owner = $gVhhF$solidjs.getOwner();
512
+ let createdSizeAccessor = false;
513
+ let wasCleanedUp = false;
514
+ $gVhhF$solidjs.createEffect(() => {
515
+ if (currentImageSize() || wasCleanedUp) return; // We get into the effect when onCleanup is called if we don't have wasCleanedUp
516
+ // ensure we always have a size accessor
517
+ // what this whole thing does is set the sizes attribute to the actual size of one of the existing image containers, therefore the value doesn't have to manually be specified
518
+ createdSizeAccessor = true;
519
+ setCurrentImageSize(() => $gVhhF$solidjs.runWithOwner(owner, () => $128302ab61dab8f1$export$54c6d6ff54e72743(container)));
520
+ });
521
+ $gVhhF$solidjs.onCleanup(() => {
522
+ wasCleanedUp = true; // important to set this before the function call below and always, so the dead effects don't create dead size accessors
523
+ if (!createdSizeAccessor) return;
524
+ $gVhhF$depictaiutilishared.queueMacroTask(() => setCurrentImageSize()); // unset the size accessor next event loop iteration, so that all onCleanup's have time to run, since the effects run more aggressively and can create a size accessor with a cleaned up owner otherwise
525
+ });
526
+
527
+ $gVhhF$solidjsweb.insert(container, $gVhhF$solidjsweb.createComponent((0, $19950faaac026e09$export$6e5611bc7e57e477), $gVhhF$solidjsweb.mergeProps({
528
+ size: () => currentImageSize()?.[0]?.() || 0,
529
+ sizeHeight: () => currentImageSize()?.[1]?.() || 0,
530
+ get src() {
531
+ return props.src;
532
+ }
533
+ }, () => props.imgProps, {
534
+ get style() {
535
+ return props.imgProps?.style;
536
+ }
537
+ })));
538
+ return container;
539
+ }
540
+ const $d212a67662c5cf38$var$customUrls = (url, width) => {
541
+ if (url?.startsWith?.("https://cdn.shopify.com"))
542
+ // The shopify image resizing CDN blocks Cloudflare's image resizer. It's possible that we can't detect shopify image URLs sometimes because they go to the merchant's domain,
543
+ // but it seems like the URLs returned by the Depict API always goes to the cdn.shopify.com version of an image, so this simple workaround works.
544
+ return $19950faaac026e09$export$1d6267828870adda(url, width);
545
+ // Use cloudflare image resizer instead of img.depict.ai because it's a lot faster (and also auto-chooses other formats if webp is not supported)
546
+ return `https://app.depict.ai/cdn-cgi/image/width=${width},format=auto/${url}`;
547
+ };
548
+ function $d212a67662c5cf38$export$9d4a4b669b1929ab(props) {
549
+ return $gVhhF$solidjsweb.createComponent((0, $a33065cfed827fc0$export$e4b984597b71e989), $gVhhF$solidjsweb.mergeProps(props, {
550
+ get imgProps() {
551
+ return {
552
+ ...props.imgProps,
553
+ customUrls: $d212a67662c5cf38$var$customUrls
554
+ };
555
+ }
556
+ }));
557
+ }
558
+ function $d212a67662c5cf38$export$140423fa4bfb6d63(props) {
559
+ return $gVhhF$solidjsweb.createComponent((0, $19950faaac026e09$export$6e5611bc7e57e477), $gVhhF$solidjsweb.mergeProps(props, {
560
+ customUrls: $d212a67662c5cf38$var$customUrls
561
+ }));
562
+ }
563
+
564
+ // Value first so shopify merchants can set (extra) display transformers in the shopify app
565
+ // Calling these functions normally doesn't do anything, but our shopify app respects them
566
+ // Them being here is value first too because this can be easily imported in the product card editor
567
+ let $606c221d98ba4d92$var$extraDisplayTransformers;
568
+ const $606c221d98ba4d92$export$b2d94be4f02525b2 = () => $606c221d98ba4d92$var$extraDisplayTransformers;
569
+ const $606c221d98ba4d92$export$f98b8d5ea7207a1 = displayTransformers => $606c221d98ba4d92$var$extraDisplayTransformers = displayTransformers;
570
+ function $b54e6192d0caa293$export$d9f36cf74e24d595(media_query) {
571
+ const signal = $gVhhF$solidjs.createSignal(false);
572
+ $gVhhF$solidjs.onCleanup($gVhhF$depictaiutilishared.javascript_media_query(media_query, ({
573
+ matches: matches
574
+ }) => signal[1](matches)).remove);
575
+ return signal[0];
576
+ }
577
+ function $17d06b3bcb035500$export$a79e666719b3647c(cols_at_size_) {
578
+ const size_active = $gVhhF$solidjs.createMemo(() => cols_at_size_().map(([n_cols, min_width, max_width]) => {
579
+ const media_query = $gVhhF$depictaiutilishared.layout_media_query_header(min_width, max_width).replaceAll("@media", "");
580
+ const matches = $b54e6192d0caa293$export$d9f36cf74e24d595(media_query);
581
+ return [matches, n_cols];
582
+ }));
583
+ const n_cols_currently_showing = $gVhhF$solidjs.createMemo(() => {
584
+ try {
585
+ const [, n_cols_currently_showing] = size_active().find(([media_query]) => media_query());
586
+ return n_cols_currently_showing;
587
+ } catch (e) {
588
+ $gVhhF$depictaiutilishared.dwarn("No active size found in columnsAtSize - can't render content blocks or looks");
589
+ return null;
590
+ }
591
+ });
592
+ return n_cols_currently_showing;
593
+ }
594
+
595
+ // Errors caused by SDK consuming code interfacing with the SDK, not the SDK itself or other Depict packages
596
+ class $7dd1edb2ee2b43ad$export$e1d52e4f0c7557a1 extends Error {}
597
+ class $7dd1edb2ee2b43ad$export$aa14a9f43128f61f extends $7dd1edb2ee2b43ad$export$e1d52e4f0c7557a1 {
598
+ constructor(templateError) {
599
+ super("Uncaught error in product card template", {
600
+ cause: templateError
601
+ });
602
+ }
603
+ }
604
+ var $edafe91daf3091d7$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div><!$><!/><!$><!/>`);
605
+ const $edafe91daf3091d7$var$ExtraInfoContext = /*@__PURE__*/$gVhhF$solidjs.createContext();
606
+ function $edafe91daf3091d7$export$240ecf5363d76c0f(props) {
607
+ return $gVhhF$solidjsweb.createComponent($edafe91daf3091d7$var$ExtraInfoContext.Provider, {
608
+ get value() {
609
+ return props.getContext_;
610
+ },
611
+ get children() {
612
+ return props.children;
613
+ }
614
+ });
615
+ }
616
+ function $edafe91daf3091d7$export$b69d0d92862de18b(props) {
617
+ const getContextFunction = $gVhhF$solidjs.useContext($edafe91daf3091d7$var$ExtraInfoContext);
618
+ return $gVhhF$solidjs.ErrorBoundary({
619
+ fallback(err, retry) {
620
+ const {
621
+ message_: message_,
622
+ severity_: severity_
623
+ } = props;
624
+ let message = message_;
625
+ if (err instanceof (0, $7dd1edb2ee2b43ad$export$aa14a9f43128f61f)) {
626
+ console.error(err.cause);
627
+ message = `${message}: ${err.message}`;
628
+ } else $gVhhF$depictaiutilishared.report([err, message_], severity_, getContextFunction?.());
629
+ return (() => {
630
+ var _el$ = $gVhhF$solidjsweb.getNextElement($edafe91daf3091d7$var$_tmpl$),
631
+ _el$2 = _el$.firstChild,
632
+ [_el$3, _co$] = $gVhhF$solidjsweb.getNextMarker(_el$2.nextSibling),
633
+ _el$4 = _el$3.nextSibling,
634
+ [_el$5, _co$2] = $gVhhF$solidjsweb.getNextMarker(_el$4.nextSibling);
635
+ $gVhhF$solidjsweb.insert(_el$, message, _el$3, _co$);
636
+ $gVhhF$solidjsweb.insert(_el$, () => props.on_error_?.(retry), _el$5, _co$2);
637
+ $gVhhF$solidjsweb.effect(_$p => $gVhhF$solidjsweb.classList(_el$, Object.fromEntries(props.class_list_?.map(c => [c, true]) || []), _$p));
638
+ return _el$;
639
+ })();
640
+ },
641
+ get children() {
642
+ return props.children;
643
+ }
644
+ });
645
+ }
646
+ var $75777da1687ba3f6$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div>`),
647
+ $75777da1687ba3f6$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<style type=text/css>`);
648
+ const $75777da1687ba3f6$export$c500183c31c2b22e = "--spans-columns";
649
+ function $75777da1687ba3f6$export$ab6b147eec64fea5(props) {
650
+ const container_class = "x" + $gVhhF$solidjs.createUniqueId();
651
+ const container_element_ = (() => {
652
+ var _el$ = $gVhhF$solidjsweb.getNextElement($75777da1687ba3f6$var$_tmpl$);
653
+ $gVhhF$solidjsweb.spread(_el$, $gVhhF$solidjsweb.mergeProps(() => props.element_attributes, {
654
+ "classList": {
655
+ [container_class]: true
656
+ }
657
+ }), false, true);
658
+ $gVhhF$solidjsweb.insert(_el$, () => props.children);
659
+ $gVhhF$solidjsweb.runHydrationEvents();
660
+ return _el$;
661
+ })(); // Don't want this in the error boundary below, it should only be for the actual layouting
662
+ return $gVhhF$solidjsweb.createComponent((0, $edafe91daf3091d7$export$b69d0d92862de18b), {
663
+ message_: "Failed calculating css grid layout",
664
+ severity_: "error",
665
+ get children() {
666
+ return $75777da1687ba3f6$export$e2f22da34aaf310a(props, container_element_, false, container_class);
667
+ }
668
+ });
669
+ }
670
+ function $75777da1687ba3f6$export$e2f22da34aaf310a(props, container_element, insert_after_container = false, container_class) {
671
+ if (!container_class) {
672
+ // only try to add if it wasn't provided, so that we have a code path without classList when doing SSR
673
+ container_class = $gVhhF$depictaiutilishared.make_random_classname();
674
+ container_element.classList.add(container_class);
675
+ }
676
+ const container_selector = `.depict .${container_class}`; // class so ppl can have id if needed
677
+ const col_styling = $gVhhF$solidjs.createMemo(() => $75777da1687ba3f6$var$generate_media_queried_declarations({
678
+ container_selector_: container_selector,
679
+ default_grid_spacing_text: props.grid_spacing,
680
+ cols_at_size_: props.cols_at_size,
681
+ override_vertical_spacing_: props.override_vertical_spacing,
682
+ top_row_shortened_by_: props.top_row_shortened_by_()
683
+ }));
684
+ const base_styling = $gVhhF$solidjs.createMemo(() => {
685
+ return `${container_selector}{display:grid;}`;
686
+ });
687
+ const get_styling = $gVhhF$solidjs.createMemo(() => base_styling() + col_styling());
688
+ const style_element = (() => {
689
+ var _el$2 = $gVhhF$solidjsweb.getNextElement($75777da1687ba3f6$var$_tmpl$2);
690
+ $gVhhF$solidjsweb.insert(_el$2, get_styling);
691
+ return _el$2;
692
+ })(); // need to create this after set_styling has been called or else there will be no styling in the SSR'd output
693
+ if (insert_after_container) container_element.after(style_element);
694
+ return [container_element, style_element];
695
+ }
696
+ function $75777da1687ba3f6$var$generate_media_queried_declarations({
697
+ container_selector_: container_selector_,
698
+ default_grid_spacing_text: default_grid_spacing_text,
699
+ cols_at_size_: cols_at_size_,
700
+ override_vertical_spacing_: override_vertical_spacing_,
701
+ top_row_shortened_by_: top_row_shortened_by_
702
+ }) {
703
+ return cols_at_size_.map(options => {
704
+ const [n_cols, min, max, grid_spacing_for_size] = options;
705
+ const main_spacing_to_use = grid_spacing_for_size || default_grid_spacing_text;
706
+ // See comment in else block below
707
+ const can_use_gap = override_vertical_spacing_ ? $75777da1687ba3f6$var$can_use_gap_for_unit(override_vertical_spacing_) : $75777da1687ba3f6$var$can_use_gap_for_unit(main_spacing_to_use);
708
+ let spacing_styling;
709
+ let additional_styling = ""; // outside the media query
710
+ if (can_use_gap) spacing_styling = `gap:${main_spacing_to_use};${override_vertical_spacing_ ? `row-gap:${override_vertical_spacing_};` : ``}`;else {
711
+ // When using percent units, which our default styling does (because convenient) and our interface relies on (hard to specify different gaps for different screen sizes)
712
+ // row gaps in grids are relative to the whole height of the grid, maybe see also https://stackoverflow.com/a/53563865. The issue with that is that as we load more products, the gap grows. Also, it breaks existing integrations.
713
+ // Logical thought: use margins for the vertical spacing. But margins in grids are apparently relative to the size of the individual items in grids.
714
+ // Given that, and that content blocks can be of different width, we have to do some complicated calculations to convert the provided gap, which is in gap of the total container width, to a margin of the individual items.
715
+ const vertical_spacing_to_use = override_vertical_spacing_ ?? main_spacing_to_use;
716
+ const width_multiplier = `var(${$75777da1687ba3f6$export$c500183c31c2b22e}, 1)`; // How many cards wide the current item is (needed because content blocks)
717
+ const one_item_width_exclusing_gaps = `calc(calc(100 / ${n_cols}) - calc(calc(${n_cols * 2 - 2} * calc(${$75777da1687ba3f6$var$strip_percent_unit(vertical_spacing_to_use)} / 2)) / ${n_cols}))`; // Width of one item in percent of the whole
718
+ // Equation from layout.tsx, also used in CheckboxGrid. Needs half spacing for some reason
719
+ const this_item_width_meat = `calc(${one_item_width_exclusing_gaps} * ${width_multiplier})`; // Width of just the card
720
+ const this_item_width_gaps = `calc(calc(${width_multiplier} - 1) * ${$75777da1687ba3f6$var$strip_percent_unit(vertical_spacing_to_use)})`; // Width of the gaps
721
+ const this_item_width = `calc(${this_item_width_meat} + ${this_item_width_gaps})`; // Width of this item including gaps
722
+ // this_item_width needs to be unitless, and since plain css can't do calc(40% / 5%) which would become unitless we need to strip all units in the calculations before
723
+ const convert_top_spacing_to_item_width_percentage = spacing => `calc(calc(100 / ${this_item_width}) * ${spacing})`; // Now finally we can convert the desired spacing to a percentage of this individual item's width (including gaps that would be there but aren't because content blocks span them)
724
+ spacing_styling = `column-gap:${main_spacing_to_use};`; // Still use gaps in the horizontal direction because that works flawlessly
725
+ // Re-use old layout code to get the correct :nth-child declarations for the top margins
726
+ additional_styling = $gVhhF$depictaiutilishared.n_col_styling_with_dist(container_selector_ + ">", convert_top_spacing_to_item_width_percentage(default_grid_spacing_text), [[n_cols, min, max, grid_spacing_for_size ? convert_top_spacing_to_item_width_percentage(grid_spacing_for_size) : null]], "grid", override_vertical_spacing_ ? convert_top_spacing_to_item_width_percentage(override_vertical_spacing_) : override_vertical_spacing_, top_row_shortened_by_);
727
+ }
728
+ const media_query_body = `${container_selector_}{${spacing_styling}grid-template-columns:repeat(${n_cols},minmax(0,1fr));}`;
729
+ return `${$gVhhF$depictaiutilishared.layout_media_query_header(min, max)}{${media_query_body}}${additional_styling}`;
730
+ }).join("");
731
+ }
732
+ function $75777da1687ba3f6$var$can_use_gap_for_unit(spacing) {
733
+ const trimmed_spacing = spacing.trim();
734
+ return !trimmed_spacing.includes("%");
735
+ }
736
+ function $75777da1687ba3f6$var$strip_percent_unit(css_value) {
737
+ return css_value.replaceAll("%", "");
738
+ }
739
+ var $d92f338ba8f9da9b$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class=content-block-wrapper>`);
740
+ function $d92f338ba8f9da9b$export$791ef57e62e21c3f({
741
+ content_blocks_: incoming_content_blocks,
742
+ cols_at_size_: cols_at_size_,
743
+ set_top_row_shortened_by_: set_top_row_shortened_by_
744
+ }) {
745
+ // these are by row
746
+ const [content_blocks, set_content_blocks] = $gVhhF$solidjsstore.createStore([]);
747
+ const n_cols_currently_showing_ = $17d06b3bcb035500$export$a79e666719b3647c(cols_at_size_);
748
+ $gVhhF$solidjs.createEffect(() => {
749
+ const incoming_value = incoming_content_blocks();
750
+ if (!incoming_value) {
751
+ set_content_blocks([]);
752
+ return;
753
+ }
754
+ set_content_blocks($gVhhF$solidjsstore.reconcile(incoming_value, {
755
+ key: "content"
756
+ })); // key: Make moving blocks faster, see https://github.com/solidjs/solid/issues/1925#issuecomment-1769671596
757
+ });
758
+
759
+ const get_wrapped_blocks_ = $d92f338ba8f9da9b$var$wrap_blocks_in_div(content_blocks, n_cols_currently_showing_);
760
+ $gVhhF$solidjs.createComputed(() => {
349
761
  // Update our styling if a content block forces some items that should be in the top row into a lower one, so we can generate margin-top declarations for them
350
762
  const top_row_block = get_wrapped_blocks_()[0];
351
763
  const blocks_in_top_row_taken = top_row_block?.span_columns;
@@ -656,1137 +1068,752 @@ function $a0e53f99354809d9$export$6649caad96ef8870(props) {
656
1068
  }).constructor_plugin, ...(fading_plugin ? [fading_plugin.constructor_plugin] : [])],
657
1069
  mutation_plugins: [...(fading_plugin ? [fading_plugin.mutation_plugin_] : []), ...mutation_plugins_, entries => setIntersectionEntries(entries)]
658
1070
  });
659
- $gVhhF$solidjsweb.insert(slider.insert_here, () => $gVhhF$solidjsweb.createComponent($a0e53f99354809d9$var$SlidableContext.Provider, {
660
- value: {
661
- slider_: slider,
662
- intersectionEntries_: intersectionEntries_
663
- },
664
- get children() {
665
- return props.children;
666
- }
667
- }));
668
- $gVhhF$solidjs.onCleanup(() => slider.observer.disconnect());
669
- slider_ref_?.(slider);
670
- return slider.container;
671
- })();
672
- }
673
- });
674
- }
675
- function $a0e53f99354809d9$export$eaa625fb39439e37() {
676
- return $gVhhF$solidjs.useContext($a0e53f99354809d9$var$SlidableContext);
677
- }
678
-
679
- /**
680
- * Gets product_id (the thing we key the rendering on) from a display
681
- */
682
- function $a5871dacf261adf8$export$548d053aba053d79(display) {
683
- if ("variant_index" in display) {
684
- const actual_display = display.variant_displays[display.variant_index];
685
- return actual_display.product_id;
686
- }
687
- if ("listing_id" in display) return display.listing_id;
688
- return display.product_id;
689
- }
690
- function $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52(elements) {
691
- // FYI this probably doesn't work on hugely deep nestings or large amount of elements
692
- return $gVhhF$solidjs.createMemo(() => $5f7d55c710fd1bc2$var$unwrapping_helper(elements));
693
- }
694
- function $5f7d55c710fd1bc2$var$unwrapping_helper(elements) {
695
- const result = [];
696
- if (Array.isArray(elements)) for (let i = 0; i < elements.length; i++) {
697
- const element = elements[i];
698
- result.push(...$5f7d55c710fd1bc2$var$unwrapping_helper(element));
699
- } else if (typeof elements == "function") result.push(...$5f7d55c710fd1bc2$var$unwrapping_helper(elements()));else if (elements != undefined && typeof elements != "boolean") result.push(elements);
700
- return result;
701
- }
702
- const $129b9b9c010039d0$var$ProductCardIndexContext = /*@__PURE__*/$gVhhF$solidjs.createContext();
703
- function $129b9b9c010039d0$export$11354f017ddc9790(props) {
704
- return $gVhhF$solidjsweb.createComponent($129b9b9c010039d0$var$ProductCardIndexContext.Provider, {
705
- get value() {
706
- return props.index_;
707
- },
708
- get children() {
709
- return props.children;
710
- }
711
- });
712
- }
713
- function $129b9b9c010039d0$export$e3faf4d95300054f() {
714
- return $gVhhF$solidjs.useContext($129b9b9c010039d0$var$ProductCardIndexContext);
715
- }
716
-
717
- /**
718
- * This is a function that will safely clone an object that may contain promises.
719
- * It will use structuredClone to clone the object and then re-apply (copy) any promises that were in the original object to the cloned object.
720
- * @param obj Anything to clone
721
- */
722
- function $ac946c6b782bb900$export$83bb9af5671e1dbe(obj) {
723
- if (obj instanceof Promise) return obj;
724
- // Extract all promises, keep a map of them, and then re-apply them to both the original object and the target object after cloning
725
- const seen = new Set();
726
- const keyStack = [[]];
727
- const valueStack = [obj];
728
- const promiseLocationStack = [];
729
- while (valueStack.length) {
730
- const value = valueStack.pop();
731
- const keyPath = keyStack.pop();
732
- // Promises can only be in objects and we don't need to check for objects we've already seen (like in circular references)
733
- if (typeof value !== "object" || value === null || seen.has(value)) continue;
734
- seen.add(value);
735
- if (Array.isArray(value)) {
736
- for (let i = 0; i < value.length; i++) {
737
- const ourValue = value[i];
738
- const valuesKeyPath = [...keyPath, i];
739
- if (ourValue instanceof Promise) {
740
- promiseLocationStack.push([valuesKeyPath, ourValue]);
741
- delete value[i]; // This will leave a hole in the array, but it's fine since we'll put it back soon
742
- // This way both the indexes will be correct when putting the value back and our for loop doesn't get messed up
743
- } else {
744
- keyStack.push(valuesKeyPath);
745
- valueStack.push(ourValue);
746
- }
747
- }
748
- continue;
749
- }
750
- for (const innerKey in value) {
751
- const ourValue = value[innerKey];
752
- const valuesKeyPath = [...keyPath, innerKey];
753
- if (ourValue instanceof Promise) {
754
- promiseLocationStack.push([valuesKeyPath, ourValue]);
755
- delete value[innerKey];
756
- } else {
757
- keyStack.push(valuesKeyPath);
758
- valueStack.push(ourValue);
759
- }
760
- }
761
- }
762
- let structuredClonedObject;
763
- let error;
764
- try {
765
- structuredClonedObject = structuredClone(obj);
766
- } catch (e) {
767
- // We still need to put back the promises in the original object, even if we threw an error
768
- error = e;
769
- }
770
- // Put back the promises in both the original object and the cloned object
771
- while (promiseLocationStack.length) {
772
- const [keyPath, promise] = promiseLocationStack.pop();
773
- let targetInClone = structuredClonedObject;
774
- let targetInOriginal = obj;
775
- for (let i = 0; i < keyPath.length - 1; i++) {
776
- if (!error) targetInClone = targetInClone[keyPath[i]];
777
- targetInOriginal = targetInOriginal[keyPath[i]];
778
- }
779
- if (!error) targetInClone[keyPath[keyPath.length - 1]] = promise;
780
- targetInOriginal[keyPath[keyPath.length - 1]] = promise;
781
- }
782
- if (error) throw error;
783
- return structuredClonedObject;
784
- }
785
- let $a73063cc642f3e5f$var$printedCloneError = false;
786
- function $a73063cc642f3e5f$export$7f8bd308237ab5a5(get_displays_) {
787
- const displays_by_key_ = $gVhhF$solidjs.createMemo(() => {
788
- const displays = get_displays_();
789
- // We key by product_id because that's what can be used to uniquely identify products
790
- // This way <For> can optimize the rendering
791
- const map = new Map();
792
- for (let i = 0; i < displays.length; i++) {
793
- const display = displays[i];
794
- const product_id = $a5871dacf261adf8$export$548d053aba053d79(display);
795
- map.set(product_id, display);
796
- }
797
- return map;
798
- });
799
- return displays_by_key_;
800
- }
801
- const $a73063cc642f3e5f$var$result_ids = ["search_result_id", "product_listing_result_id", "recommendation_id"];
802
- function $a73063cc642f3e5f$export$43f0fb951fcb0c54({
803
- displays_by_key_: displays_by_key_,
804
- product_card_template_: product_card_template_,
805
- do_per_elements_: do_per_elements_,
806
- content_blocks_: content_blocks_
807
- }) {
808
- return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.For), {
809
- get each() {
810
- return [...displays_by_key_().keys()];
811
- },
812
- children: (product_id, index) => {
813
- const owner = $gVhhF$solidjs.getOwner();
814
- const possible_content_block = $gVhhF$solidjs.createMemo(() => content_blocks_?.()?.()?.[index()]);
815
- const display_accessor = $gVhhF$solidjs.createMemo(prev => {
816
- const new_display = displays_by_key_().get(product_id);
817
- if (prev && $a73063cc642f3e5f$var$deep_equal(prev, new_display))
818
- // If displays are identical, they haven't changed due to merchant/market changing OR we made a new query and the displays are the same. Return the old display (same object reference) to avoid re-rendering.
819
- // This doesn't work if people mutate the displays from within the template but we hope they don't
820
- // (We can't know if the display changing is due to merchant/market changing or a new query otherwise and don't want to run into https://gitlab.com/depict-ai/depict.ai/-/merge_requests/6890/diffs)
821
- return prev;
822
- return new_display;
823
- });
824
- const [product_card_resource] = $gVhhF$solidjs.createResource(display_accessor,
825
- // re-render when the reference to the display object changes
826
- display => {
827
- // It's easy for merchants to accidentally mutate the display or some sub-object thereof
828
- // We had a case on singular where they popped an image url and due to use caching after some time there was no image
829
- // Attempt cloning the displays if possible (99.9% of the cases probably) and if not, just use the original display
830
- try {
831
- // Use promiseSafeStructuredClone so that:
832
- // 1. When fetching for example prices from an API, one can start that API request
833
- // 2. Add the promise to the display
834
- // 3. Already render the product card with placeholders for prices while the price loads
835
- // 4. When the price loads, re-render the display with the new price
836
- display = $ac946c6b782bb900$export$83bb9af5671e1dbe(display);
837
- } catch (e) {
838
- if (!$a73063cc642f3e5f$var$printedCloneError) {
839
- $a73063cc642f3e5f$var$printedCloneError = true;
840
- $gVhhF$depictaiutilishared.dlog("Can't clone display", display, " (uncloneable objects in it), make sure you don't mutate it in the template since we cache.", e);
841
- }
842
- }
843
- let renderingResult;
844
- // Wrap the product card in a ProductCardIndexProvider so that the index is available to the product card
845
- // This is wo we can do intelligent image loading in ShopifyContainedImage without shopify devs having to pass in the index
846
- // We don't care about the return value of ProductCardIndexProvider because our rendering result might be a promise which solid doesn't support until it has gone through createResource
847
- $129b9b9c010039d0$export$11354f017ddc9790({
848
- index_: index,
849
- get children() {
850
- // This is the key - the functions called inside of the children getter of the provider are the one that have the context defined in their solid-internal Owner
851
- renderingResult = product_card_template_(display, {
852
- set_on_index_change: fn => $gVhhF$solidjs.runWithOwner(owner, () => $gVhhF$solidjs.createEffect(() => fn(index())))
853
- });
854
- return undefined; // just to satisfy the typing
855
- }
856
- });
857
- // renderingResult is guaranteed to be defined here (if rendering returned something) because the children getter of ProductCardIndexProvider is called synchronously (createRenderEffect is used solid-internally)
858
- return renderingResult;
859
- });
860
- const node_accessor = $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52(product_card_resource);
861
- $gVhhF$solidjs.createEffect(() => {
862
- const product_card_nodes = node_accessor();
863
- const display = display_accessor();
864
- const elements = [];
865
- for (let i = 0; i < product_card_nodes.length; i++) {
866
- const element = product_card_nodes[i];
867
- if (!(element instanceof Element)) continue;
868
- elements.push(element);
869
- // Add tracking ids
870
- if (!(element instanceof HTMLElement)) continue; // Apparently only HTMLElements have dataset
871
- for (let i = 0; i < $a73063cc642f3e5f$var$result_ids.length; i++) {
872
- const id = $a73063cc642f3e5f$var$result_ids[i];
873
- const value = display[id];
874
- if (value) Object.assign(element.dataset, $gVhhF$depictaiutilishared.camelCasifyObject({
875
- [id]: value
876
- }));
1071
+ $gVhhF$solidjsweb.insert(slider.insert_here, () => $gVhhF$solidjsweb.createComponent($a0e53f99354809d9$var$SlidableContext.Provider, {
1072
+ value: {
1073
+ slider_: slider,
1074
+ intersectionEntries_: intersectionEntries_
1075
+ },
1076
+ get children() {
1077
+ return props.children;
877
1078
  }
878
- }
879
- do_per_elements_?.(elements, index);
880
- });
881
- return [
882
- // Show content block before product card, so it's *at* that index
883
- possible_content_block, node_accessor // Don't return product_card_resource as calling it could be creating the nodes which would mean we'd be double-creating the nodes,
884
- ]; // Regarding the as unknown shenanigans: https://github.com/solidjs/solid/releases/tag/v1.7.0
1079
+ }));
1080
+ $gVhhF$solidjs.onCleanup(() => slider.observer.disconnect());
1081
+ slider_ref_?.(slider);
1082
+ return slider.container;
1083
+ })();
885
1084
  }
886
1085
  });
887
1086
  }
888
- // source: https://medium.com/@pancemarko/deep-equality-in-javascript-determining-if-two-objects-are-equal-bf98cf47e934
889
- // deeply diffs two objects
890
- // Modified by chatGPT to not be recursive, since stiga was getting a stack overflow just due to the size of their data
891
- // Modified futher to bias towards saying objects are equal non-primitive objects differ
892
- function $a73063cc642f3e5f$var$deep_equal(obj1, obj2) {
893
- const stack = [[obj1, obj2]];
894
- while (stack.length) {
895
- const [currentObj1, currentObj2] = stack.pop();
896
- if (currentObj1 === currentObj2) continue;
897
- if (Array.isArray(currentObj1) && Array.isArray(currentObj2)) {
898
- if (currentObj1.length !== currentObj2.length) return false;
899
- for (let i = 0; i < currentObj1.length; i++) stack.push([currentObj1[i], currentObj2[i]]);
900
- } else if (typeof currentObj1 === "object" && typeof currentObj2 === "object" && currentObj1 !== null && currentObj2 !== null) {
901
- if (Array.isArray(currentObj1) || Array.isArray(currentObj2)) return false;
902
- const keys1 = Object.keys(currentObj1);
903
- const keys2 = Object.keys(currentObj2);
904
- if (keys1.length !== keys2.length || !keys1.every(key => keys2.includes(key))) return false;
905
- for (let key in currentObj1) {
906
- if ($a73063cc642f3e5f$var$result_ids.includes(key)) continue; // ignore comparing values for keys we know are changing with every request
907
- stack.push([currentObj1[key], currentObj2[key]]);
908
- }
909
- } else if (typeof currentObj1 !== "function" && typeof currentObj2 !== "function")
910
- // Claim that all functions are equal, since the only way a function ends up here is because someone added it in the displayTransformer and that shouldn't force us to re-render, right?
911
- return false;
1087
+ function $a0e53f99354809d9$export$eaa625fb39439e37() {
1088
+ return $gVhhF$solidjs.useContext($a0e53f99354809d9$var$SlidableContext);
1089
+ }
1090
+
1091
+ /**
1092
+ * Gets product_id (the thing we key the rendering on) from a display
1093
+ */
1094
+ function $a5871dacf261adf8$export$548d053aba053d79(display) {
1095
+ if ("variant_index" in display) {
1096
+ const actual_display = display.variant_displays[display.variant_index];
1097
+ return actual_display.product_id;
912
1098
  }
913
- return true;
1099
+ if ("listing_id" in display) return display.listing_id;
1100
+ return display.product_id;
914
1101
  }
915
- const $67155e1aeb7073f6$export$f223d69ed12f5fb7 = /*@__PURE__*/$gVhhF$solidjs.createContext();
916
- function $67155e1aeb7073f6$export$4a14175d33d81a96({
917
- displays_by_key_: displays_by_key_,
918
- product_card_template_: product_card_template_,
919
- content_blocks_: content_blocks_,
920
- alwaysObserveCards_: alwaysObserveCards_
921
- }) {
922
- const targetToIndexMap_ = new Map();
923
- const indexToTargetMap_ = new Map();
924
- const [listenersForIntersecting, setListenersForIntersecting] = $gVhhF$solidjs.createSignal(0);
925
- const [currentlyIntersecting, setCurrentlyIntersecting] = $gVhhF$solidjs.createSignal(new Set(), {
926
- equals: false
927
- });
928
- if (0, $gVhhF$solidjsweb.isServer) return {
929
- renderedDisplays_: $a73063cc642f3e5f$export$43f0fb951fcb0c54({
930
- displays_by_key_: displays_by_key_,
931
- product_card_template_: product_card_template_,
932
- content_blocks_: content_blocks_
933
- }),
934
- indexToTargetMap_: indexToTargetMap_,
935
- currentlyIntersecting: currentlyIntersecting
936
- };
937
- // The following sets up an intersection observer to determine which results are in the viewport, used for the ScrollStatus indicator, knowing when to load more and any other consumer of the useProductCardIsVisible hook.
938
- const shouldObserve = $gVhhF$solidjs.createMemo(() => alwaysObserveCards_ || listenersForIntersecting() > 0);
939
- const intersection_observer = new IntersectionObserver($gVhhF$depictaiutilishared.catchify(records => {
940
- const intersectingValue = currentlyIntersecting();
941
- for (let i = 0; i < records.length; i++) {
942
- const record = records[i];
943
- const {
944
- target: target,
945
- intersectionRatio: intersectionRatio
946
- } = record;
947
- const index_of_target = targetToIndexMap_.get(target);
948
- if (index_of_target == undefined) return; // It seems like it can happen that we get IntersectionObserverEntries after the onCleanup function for a recommendation card has run, in Firefox. Probably a bug in Firefox? If I understood the bug correctly, this is a workaround.
949
- const is_in_set = intersectingValue.has(index_of_target);
950
- if (intersectionRatio > 0) {
951
- if (!is_in_set) intersectingValue.add(index_of_target);
952
- } else if (is_in_set) intersectingValue.delete(index_of_target);
953
- }
954
- setCurrentlyIntersecting(intersectingValue);
955
- }, "renderDisplays IO failed"));
956
- const renderedDisplays_ = $gVhhF$solidjsweb.createComponent($67155e1aeb7073f6$export$f223d69ed12f5fb7.Provider, {
957
- value: {
958
- currentlyIntersecting_: currentlyIntersecting,
959
- setIsListening_: setListenersForIntersecting
960
- },
961
- get children() {
962
- return $a73063cc642f3e5f$export$43f0fb951fcb0c54({
963
- displays_by_key_: displays_by_key_,
964
- product_card_template_: product_card_template_,
965
- content_blocks_: content_blocks_,
966
- do_per_elements_: (elements, index_accessor) =>
967
- // Adds/removes elements from the "results in viewport" intersection observer above
968
- $gVhhF$solidjs.createEffect(() => {
969
- if (!shouldObserve()) return;
970
- const display_index = index_accessor();
971
- // Nested createEffect because we only want to re-run this when the index changes (or we should/shouldn't observe)
972
- // We need to save in a map which index the elements of this template are so that we can know that in the IntersectionObserver callback
973
- for (let i = 0; i < elements.length; i++) {
974
- const element = elements[i];
975
- targetToIndexMap_.set(element, display_index);
976
- intersection_observer.observe(element);
977
- $gVhhF$solidjs.onCleanup(() => {
978
- intersection_observer.unobserve(element);
979
- targetToIndexMap_.delete(element);
980
- const intersecting = $gVhhF$solidjs.untrack(currentlyIntersecting);
981
- const wasDeleted = intersecting.delete(display_index);
982
- if (wasDeleted) setCurrentlyIntersecting(intersecting);
983
- });
984
- }
985
- indexToTargetMap_.set(display_index, elements);
986
- $gVhhF$solidjs.onCleanup(() => indexToTargetMap_.delete(display_index));
987
- })
988
- });
989
- }
990
- });
991
- return {
992
- renderedDisplays_: renderedDisplays_,
993
- indexToTargetMap_: indexToTargetMap_,
994
- currentlyIntersecting: currentlyIntersecting
995
- };
1102
+ function $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52(elements) {
1103
+ // FYI this probably doesn't work on hugely deep nestings or large amount of elements
1104
+ return $gVhhF$solidjs.createMemo(() => $5f7d55c710fd1bc2$var$unwrapping_helper(elements));
996
1105
  }
997
- function $67155e1aeb7073f6$export$80bb7300ce6a8be3() {
998
- const {
999
- setIsListening_: setIsListening_,
1000
- currentlyIntersecting_: currentlyIntersecting_
1001
- } = $gVhhF$solidjs.useContext($67155e1aeb7073f6$export$f223d69ed12f5fb7) || {};
1002
- const getOurIndex = $129b9b9c010039d0$export$e3faf4d95300054f();
1003
- const isVisible = $gVhhF$solidjs.createMemo(() => currentlyIntersecting_?.().has(getOurIndex?.()));
1004
- setIsListening_?.(prev => prev + 1);
1005
- $gVhhF$solidjs.onCleanup(() => setIsListening_?.(prev => prev + 1));
1006
- return isVisible;
1106
+ function $5f7d55c710fd1bc2$var$unwrapping_helper(elements) {
1107
+ const result = [];
1108
+ if (Array.isArray(elements)) for (let i = 0; i < elements.length; i++) {
1109
+ const element = elements[i];
1110
+ result.push(...$5f7d55c710fd1bc2$var$unwrapping_helper(element));
1111
+ } else if (typeof elements == "function") result.push(...$5f7d55c710fd1bc2$var$unwrapping_helper(elements()));else if (elements != undefined && typeof elements != "boolean") result.push(elements);
1112
+ return result;
1007
1113
  }
1008
- function $4b455f60dadde8b8$export$5bad61ecde080b1f(...params) {
1009
- const {
1010
- collapse: collapse,
1011
- expand: expand,
1012
- ExpandingContainer: ExpandingContainer
1013
- } = $gVhhF$depictaiutilishared.useExpandingContainer(...params);
1014
- return {
1015
- collapse: collapse,
1016
- expand: expand,
1017
- ExpandingContainer: ({
1018
- children: children
1019
- }) => {
1020
- // get reactive signals/solid's jsx elements into `ExpandingContainer`
1021
- const fake_div = document.createElement("div");
1022
- const outer_expanding = $gVhhF$solidjsweb.createComponent(ExpandingContainer, {
1023
- children: [fake_div]
1024
- });
1025
- const parent = fake_div.parentElement;
1026
- fake_div.remove();
1027
- $gVhhF$solidjsweb.insert(parent, children);
1028
- return outer_expanding;
1114
+
1115
+ /**
1116
+ * This is a function that will safely clone an object that may contain promises.
1117
+ * It will use structuredClone to clone the object and then re-apply (copy) any promises that were in the original object to the cloned object.
1118
+ * @param obj Anything to clone
1119
+ */
1120
+ function $ac946c6b782bb900$export$83bb9af5671e1dbe(obj) {
1121
+ if (obj instanceof Promise) return obj;
1122
+ // Extract all promises, keep a map of them, and then re-apply them to both the original object and the target object after cloning
1123
+ const seen = new Set();
1124
+ const keyStack = [[]];
1125
+ const valueStack = [obj];
1126
+ const promiseLocationStack = [];
1127
+ while (valueStack.length) {
1128
+ const value = valueStack.pop();
1129
+ const keyPath = keyStack.pop();
1130
+ // Promises can only be in objects and we don't need to check for objects we've already seen (like in circular references)
1131
+ if (typeof value !== "object" || value === null || seen.has(value)) continue;
1132
+ seen.add(value);
1133
+ if (Array.isArray(value)) {
1134
+ for (let i = 0; i < value.length; i++) {
1135
+ const ourValue = value[i];
1136
+ const valuesKeyPath = [...keyPath, i];
1137
+ if (ourValue instanceof Promise) {
1138
+ promiseLocationStack.push([valuesKeyPath, ourValue]);
1139
+ delete value[i]; // This will leave a hole in the array, but it's fine since we'll put it back soon
1140
+ // This way both the indexes will be correct when putting the value back and our for loop doesn't get messed up
1141
+ } else {
1142
+ keyStack.push(valuesKeyPath);
1143
+ valueStack.push(ourValue);
1144
+ }
1145
+ }
1146
+ continue;
1029
1147
  }
1030
- };
1031
- }
1032
- const $4e04be41243c3d80$var$transform_elements = sorted_cols_at_size => {
1033
- const cols_at_size = [];
1034
- for (let i = 0; i < sorted_cols_at_size.length; i++) {
1035
- const [nb_cols, width] = sorted_cols_at_size[i];
1036
- const next_width = sorted_cols_at_size[i + 1]?.[1];
1037
- const max_width = i === 0 ? "" : `${width}px`;
1038
- const min_width = next_width !== undefined ? `${next_width + 1}px` : "";
1039
- const col_at_size = [nb_cols, min_width, max_width];
1040
- cols_at_size.push(col_at_size);
1148
+ for (const innerKey in value) {
1149
+ const ourValue = value[innerKey];
1150
+ const valuesKeyPath = [...keyPath, innerKey];
1151
+ if (ourValue instanceof Promise) {
1152
+ promiseLocationStack.push([valuesKeyPath, ourValue]);
1153
+ delete value[innerKey];
1154
+ } else {
1155
+ keyStack.push(valuesKeyPath);
1156
+ valueStack.push(ourValue);
1157
+ }
1158
+ }
1159
+ }
1160
+ let structuredClonedObject;
1161
+ let error;
1162
+ try {
1163
+ structuredClonedObject = structuredClone(obj);
1164
+ } catch (e) {
1165
+ // We still need to put back the promises in the original object, even if we threw an error
1166
+ error = e;
1041
1167
  }
1042
- return cols_at_size;
1043
- };
1044
- const $4e04be41243c3d80$export$6daf8749b65a1b77 = cols_at_size => {
1045
- // Check that every element is an array
1046
- const are_arrays = cols_at_size?.every?.(element => Array.isArray(element));
1047
- if (!are_arrays) throw new Error("Every element in cols_at_size must be an array");
1048
- // Check width duplicates
1049
- const widths = cols_at_size.map(([_, width]) => width);
1050
- const widths_set = new Set(widths);
1051
- if (widths_set.size < widths.length) throw new Error("There are duplicate widths in cols_at_size");
1052
- if (cols_at_size.length === 1) {
1053
- const [nb_cols, width] = cols_at_size[0];
1054
- const max_width = width !== undefined ? `${width}px` : "";
1055
- return [[nb_cols, "", max_width]];
1168
+ // Put back the promises in both the original object and the cloned object
1169
+ while (promiseLocationStack.length) {
1170
+ const [keyPath, promise] = promiseLocationStack.pop();
1171
+ let targetInClone = structuredClonedObject;
1172
+ let targetInOriginal = obj;
1173
+ for (let i = 0; i < keyPath.length - 1; i++) {
1174
+ if (!error) targetInClone = targetInClone[keyPath[i]];
1175
+ targetInOriginal = targetInOriginal[keyPath[i]];
1176
+ }
1177
+ if (!error) targetInClone[keyPath[keyPath.length - 1]] = promise;
1178
+ targetInOriginal[keyPath[keyPath.length - 1]] = promise;
1056
1179
  }
1057
- // Sort widths in ascending order
1058
- const sorted_cols_at_size = [...cols_at_size].sort((a, b) => {
1059
- const [_b, width_A] = a;
1060
- const [_a, width_b] = b;
1061
- if (width_A === undefined) return -1;
1062
- if (width_b === undefined) return 1;
1063
- return width_b - width_A;
1064
- });
1065
- return $4e04be41243c3d80$var$transform_elements(sorted_cols_at_size);
1066
- };
1067
- function $fc23d7668ae0011d$export$a2cc176055f8f08(what = "grid") {
1068
- const text = "Please try setting `columnsAtSize`/`gridSpacing` on the `SearchPage`/`CategoryPage` components to change the " + what + " before setting it with CSS. If you do with CSS, set `columnsAtSize` to an empty array to ensure no declarations created by the SDK leak through.";
1069
- return (0, $gVhhF$solidjsweb.isServer) ? {
1070
- t: `<!-- ${text} -->`
1071
- } : document.createComment(text);
1180
+ if (error) throw error;
1181
+ return structuredClonedObject;
1072
1182
  }
1073
- const $0caf87eaa19079da$var$defaultCacheKey = /*@__PURE__*/Symbol();
1074
- const $0caf87eaa19079da$var$cachedPlaceholderElements = {};
1075
- const $0caf87eaa19079da$var$renderingCachedPlaceholderElement = {};
1076
- function $0caf87eaa19079da$export$f33414a4df0afd3f({
1077
- product_card_template_: product_card_template_,
1078
- num_placeholders_: num_placeholders_,
1079
- content_blocks_: content_blocks_,
1080
- placeholderCacheKey_: placeholderCacheKey_
1081
- }) {
1082
- const [num_to_actually_show, set_num_to_actually_show] = $gVhhF$solidjs.createSignal($gVhhF$solidjs.untrack(num_placeholders_));
1083
- if (0, $gVhhF$solidjsweb.isServer)
1084
- // want to render simple placeholders on server, effects don't run there
1085
- // FIXME when adding proper SSR: also SSR content blocks
1086
- return $gVhhF$solidjs.createMemo(() => Array.from({
1087
- length: num_placeholders_()
1088
- }).map(() => {
1089
- const template_result = product_card_template_(null, undefined);
1090
- // @ts-ignore
1091
- if (typeof template_result?.then !== "function") return template_result;
1092
- }));
1093
- $gVhhF$solidjs.createRenderEffect(() => {
1094
- const existing_num = num_to_actually_show();
1095
- const to_add = num_placeholders_() - existing_num;
1096
- if (to_add <= 0) return;
1097
- // Below comment is from when we used recommendation renderer and manual DOM manipulation for this, but I'm still scared to remove placeholders and mess up scroll restoration, so I'm keeping the way it worked. Otherwise, <Index> could be used which would be far more elegant.
1098
- // We don't need to remove placeholders, only need to add. The reason for that is that chrome restores the scroll position once all tasks queued as reaction of the "popstate" events have been completed in the task queue. That means that we need to get the placeholders in fast, or we might lose scroll position if the previous site was shorter.
1099
- // The query id and the amount might update in separate tasks because one comes from href_change_ipns and the other one from another "popstate" listener. Therefore, we need to be able to dynamically add more placeholders. I'm not entirely sure about this anymore though, since we have the scroll position on a per-id basis it might work anyway but THIS WORKS, and I've been working on this bug for 3 hours so let's just keep it this way.
1100
- // Above comments were from when we added elements in this createRenderEffect. Now I changed it to just increment the number and render them from an <Index> instead, so I can add content blocks better
1101
- // Functionality should be the same
1102
- set_num_to_actually_show(existing_num + to_add);
1103
- });
1104
- return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Index), {
1105
- get each() {
1106
- return Array.from({
1107
- length: num_to_actually_show()
1108
- });
1109
- },
1110
- children: (_item, index) => {
1111
- const possible_content_block = $gVhhF$solidjs.createMemo(() => content_blocks_?.()?.()?.[index]);
1112
- // Show content block before product card, so it's *at* that index
1113
- return [possible_content_block, $0caf87eaa19079da$var$Placeholder({
1114
- product_card_template_: product_card_template_,
1115
- placeholderCacheKey_: placeholderCacheKey_
1116
- })]; // https://github.com/solidjs/solid/releases/tag/v1.7.0
1183
+ let $a73063cc642f3e5f$var$printedCloneError = false;
1184
+ function $a73063cc642f3e5f$export$7f8bd308237ab5a5(get_displays_) {
1185
+ const displays_by_key_ = $gVhhF$solidjs.createMemo(() => {
1186
+ const displays = get_displays_();
1187
+ // We key by product_id because that's what can be used to uniquely identify products
1188
+ // This way <For> can optimize the rendering
1189
+ const map = new Map();
1190
+ for (let i = 0; i < displays.length; i++) {
1191
+ const display = displays[i];
1192
+ const product_id = $a5871dacf261adf8$export$548d053aba053d79(display);
1193
+ map.set(product_id, display);
1117
1194
  }
1195
+ return map;
1118
1196
  });
1197
+ return displays_by_key_;
1119
1198
  }
1120
- /**
1121
- * Get one placeholder element. It will be cloned for each placeholder for ultimate performance even when solid-js isn't rendering the placeholders.
1122
- */
1123
- function $0caf87eaa19079da$var$Placeholder({
1199
+ const $a73063cc642f3e5f$var$result_ids = ["search_result_id", "product_listing_result_id", "recommendation_id"];
1200
+ function $a73063cc642f3e5f$export$43f0fb951fcb0c54({
1201
+ displays_by_key_: displays_by_key_,
1124
1202
  product_card_template_: product_card_template_,
1125
- placeholderCacheKey_ = $0caf87eaa19079da$var$defaultCacheKey
1203
+ do_per_elements_: do_per_elements_,
1204
+ content_blocks_: content_blocks_
1126
1205
  }) {
1127
- const get_cloned_placeholders = (element_to_clone = $0caf87eaa19079da$var$cachedPlaceholderElements[placeholderCacheKey_]) => Array.isArray(element_to_clone) ? element_to_clone.map(el => el instanceof Node ? el.cloneNode(true) : el) : element_to_clone;
1128
- if ($0caf87eaa19079da$var$cachedPlaceholderElements[placeholderCacheKey_]) return get_cloned_placeholders();
1129
- let dispose_original_copy;
1130
- const get_unwrapped_element = $gVhhF$solidjs.createRoot(dispose => {
1131
- dispose_original_copy = dispose;
1132
- // if product_card_template_ is async and rejects the resource will take care of throwing upwards here in the solid-js error handling system
1133
- const [resource] = $gVhhF$solidjs.createResource(() => {
1134
- const rendering_cached_placeholder_element = $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_];
1135
- if (rendering_cached_placeholder_element) return rendering_cached_placeholder_element;
1136
- const return_value = product_card_template_(null, undefined);
1137
- if (typeof return_value === "object" && typeof return_value?.then === "function")
1138
- // Is Promise or promise-like object
1139
- $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_] = return_value;
1140
- return return_value;
1141
- });
1142
- return $gVhhF$solidjs.createMemo(() => {
1143
- if (resource.loading) return () => [];
1144
- return $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52(resource);
1145
- });
1146
- });
1147
- $gVhhF$solidjs.onCleanup(() => {
1148
- const rendering = $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_];
1149
- if (rendering) {
1150
- // If we're still rendering in our separate root, let the rendering finish or other <Placeholder> components waiting for it might get an incomplete result
1151
- const unset_current_rendering = () => {
1152
- dispose_original_copy();
1153
- $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_] = undefined;
1154
- };
1155
- rendering?.then(unset_current_rendering, unset_current_rendering);
1156
- } else
1157
- // Otherwise, just make sure we've disposed our root
1158
- dispose_original_copy();
1159
- });
1160
- return $gVhhF$solidjs.createMemo(() => {
1161
- const unwrapped_array = get_unwrapped_element()();
1162
- if (!unwrapped_array?.length || !unwrapped_array.every(item => item))
1163
- // Haven't finished rendering yet in case of "async" rendering, so don't freeze the elements yet
1164
- return;
1165
- // placeholders have finished rendering, freeze the elements
1166
- // here we might receive the result of a promise that has already been received, tore down and put into cached_placeholder_element, so don't overwrite that more valid result if it's already set
1167
- $0caf87eaa19079da$var$cachedPlaceholderElements[placeholderCacheKey_] ||= get_cloned_placeholders(unwrapped_array); // Clone initial return value so that who gave us the elements can't mutate them, which has caused issues before with react
1168
- $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_] = undefined;
1169
- dispose_original_copy(); // So that this memo will never re-run and the placeholder rendering function can clean up
1170
- return get_cloned_placeholders(); // clone, just in case. If we wouldn't, someone could modify the copy in the DOM, and it would affect the cached version
1171
- });
1172
- }
1173
-
1174
- var $f48d0fbb00835aaa$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div>`),
1175
- $f48d0fbb00835aaa$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<style type=text/css>`);
1176
- function $f48d0fbb00835aaa$export$d21e32dfedac04be(props) {
1177
- const container_class = "x" + $gVhhF$solidjs.createUniqueId();
1178
- const container_element_ = (() => {
1179
- var _el$ = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$);
1180
- $gVhhF$solidjsweb.spread(_el$, $gVhhF$solidjsweb.mergeProps(() => props.element_attributes, {
1181
- "classList": {
1182
- [container_class]: true
1183
- }
1184
- }), false, true);
1185
- $gVhhF$solidjsweb.insert(_el$, () => props.children);
1186
- $gVhhF$solidjsweb.runHydrationEvents();
1187
- return _el$;
1188
- })(); // Don't want this in the error boundary below, it should only be for the actual layouting
1189
- return $gVhhF$solidjsweb.createComponent((0, $edafe91daf3091d7$export$b69d0d92862de18b), {
1190
- get message_() {
1191
- return "Failed calculating " + props.layout + " layout";
1206
+ return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.For), {
1207
+ get each() {
1208
+ return [...displays_by_key_().keys()];
1192
1209
  },
1193
- severity_: "error",
1194
- get children() {
1195
- return $f48d0fbb00835aaa$export$445d8d3f5f706a40(props, container_element_, false, container_class);
1210
+ children: (product_id, index) => {
1211
+ const owner = $gVhhF$solidjs.getOwner();
1212
+ const possible_content_block = $gVhhF$solidjs.createMemo(() => content_blocks_?.()?.()?.[index()]);
1213
+ const display_accessor = $gVhhF$solidjs.createMemo(prev => {
1214
+ const new_display = displays_by_key_().get(product_id);
1215
+ if (prev && $a73063cc642f3e5f$var$deep_equal(prev, new_display))
1216
+ // If displays are identical, they haven't changed due to merchant/market changing OR we made a new query and the displays are the same. Return the old display (same object reference) to avoid re-rendering.
1217
+ // This doesn't work if people mutate the displays from within the template but we hope they don't
1218
+ // (We can't know if the display changing is due to merchant/market changing or a new query otherwise and don't want to run into https://gitlab.com/depict-ai/depict.ai/-/merge_requests/6890/diffs)
1219
+ return prev;
1220
+ return new_display;
1221
+ });
1222
+ const [product_card_resource] = $gVhhF$solidjs.createResource(display_accessor,
1223
+ // re-render when the reference to the display object changes
1224
+ display => {
1225
+ // It's easy for merchants to accidentally mutate the display or some sub-object thereof
1226
+ // We had a case on singular where they popped an image url and due to use caching after some time there was no image
1227
+ // Attempt cloning the displays if possible (99.9% of the cases probably) and if not, just use the original display
1228
+ try {
1229
+ // Use promiseSafeStructuredClone so that:
1230
+ // 1. When fetching for example prices from an API, one can start that API request
1231
+ // 2. Add the promise to the display
1232
+ // 3. Already render the product card with placeholders for prices while the price loads
1233
+ // 4. When the price loads, re-render the display with the new price
1234
+ display = $ac946c6b782bb900$export$83bb9af5671e1dbe(display);
1235
+ } catch (e) {
1236
+ if (!$a73063cc642f3e5f$var$printedCloneError) {
1237
+ $a73063cc642f3e5f$var$printedCloneError = true;
1238
+ $gVhhF$depictaiutilishared.dlog("Can't clone display", display, " (uncloneable objects in it), make sure you don't mutate it in the template since we cache.", e);
1239
+ }
1240
+ }
1241
+ let renderingResult;
1242
+ // Wrap the product card in a ProductCardIndexProvider so that the index is available to the product card
1243
+ // This is wo we can do intelligent image loading in ShopifyContainedImage without shopify devs having to pass in the index
1244
+ // We don't care about the return value of ProductCardIndexProvider because our rendering result might be a promise which solid doesn't support until it has gone through createResource
1245
+ $129b9b9c010039d0$export$11354f017ddc9790({
1246
+ index_: index,
1247
+ get children() {
1248
+ // This is the key - the functions called inside of the children getter of the provider are the one that have the context defined in their solid-internal Owner
1249
+ renderingResult = product_card_template_(display, {
1250
+ set_on_index_change: fn => $gVhhF$solidjs.runWithOwner(owner, () => $gVhhF$solidjs.createEffect(() => fn(index())))
1251
+ });
1252
+ return undefined; // just to satisfy the typing
1253
+ }
1254
+ });
1255
+ // renderingResult is guaranteed to be defined here (if rendering returned something) because the children getter of ProductCardIndexProvider is called synchronously (createRenderEffect is used solid-internally)
1256
+ return renderingResult;
1257
+ });
1258
+ const node_accessor = $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52(product_card_resource);
1259
+ $gVhhF$solidjs.createEffect(() => {
1260
+ const product_card_nodes = node_accessor();
1261
+ const display = display_accessor();
1262
+ const elements = [];
1263
+ for (let i = 0; i < product_card_nodes.length; i++) {
1264
+ const element = product_card_nodes[i];
1265
+ if (!(element instanceof Element)) continue;
1266
+ elements.push(element);
1267
+ // Add tracking ids
1268
+ if (!(element instanceof HTMLElement)) continue; // Apparently only HTMLElements have dataset
1269
+ for (let i = 0; i < $a73063cc642f3e5f$var$result_ids.length; i++) {
1270
+ const id = $a73063cc642f3e5f$var$result_ids[i];
1271
+ const value = display[id];
1272
+ if (value) Object.assign(element.dataset, $gVhhF$depictaiutilishared.camelCasifyObject({
1273
+ [id]: value
1274
+ }));
1275
+ }
1276
+ }
1277
+ do_per_elements_?.(elements, index);
1278
+ });
1279
+ return [
1280
+ // Show content block before product card, so it's *at* that index
1281
+ possible_content_block, node_accessor // Don't return product_card_resource as calling it could be creating the nodes which would mean we'd be double-creating the nodes,
1282
+ ]; // Regarding the as unknown shenanigans: https://github.com/solidjs/solid/releases/tag/v1.7.0
1196
1283
  }
1197
1284
  });
1198
1285
  }
1199
- function $f48d0fbb00835aaa$export$445d8d3f5f706a40(props, container_element, insert_after_container = false, container_class) {
1200
- if (!container_class) {
1201
- // only try to add if it wasn't provided, so that we have a code path without classList when doing SSR
1202
- container_class = $gVhhF$depictaiutilishared.make_random_classname();
1203
- container_element.classList.add(container_class);
1286
+ // source: https://medium.com/@pancemarko/deep-equality-in-javascript-determining-if-two-objects-are-equal-bf98cf47e934
1287
+ // deeply diffs two objects
1288
+ // Modified by chatGPT to not be recursive, since stiga was getting a stack overflow just due to the size of their data
1289
+ // Modified futher to bias towards saying objects are equal non-primitive objects differ
1290
+ function $a73063cc642f3e5f$var$deep_equal(obj1, obj2) {
1291
+ const stack = [[obj1, obj2]];
1292
+ while (stack.length) {
1293
+ const [currentObj1, currentObj2] = stack.pop();
1294
+ if (currentObj1 === currentObj2) continue;
1295
+ if (Array.isArray(currentObj1) && Array.isArray(currentObj2)) {
1296
+ if (currentObj1.length !== currentObj2.length) return false;
1297
+ for (let i = 0; i < currentObj1.length; i++) stack.push([currentObj1[i], currentObj2[i]]);
1298
+ } else if (typeof currentObj1 === "object" && typeof currentObj2 === "object" && currentObj1 !== null && currentObj2 !== null) {
1299
+ if (Array.isArray(currentObj1) || Array.isArray(currentObj2)) return false;
1300
+ const keys1 = Object.keys(currentObj1);
1301
+ const keys2 = Object.keys(currentObj2);
1302
+ if (keys1.length !== keys2.length || !keys1.every(key => keys2.includes(key))) return false;
1303
+ for (let key in currentObj1) {
1304
+ if ($a73063cc642f3e5f$var$result_ids.includes(key)) continue; // ignore comparing values for keys we know are changing with every request
1305
+ stack.push([currentObj1[key], currentObj2[key]]);
1306
+ }
1307
+ } else if (typeof currentObj1 !== "function" && typeof currentObj2 !== "function")
1308
+ // Claim that all functions are equal, since the only way a function ends up here is because someone added it in the displayTransformer and that shouldn't force us to re-render, right?
1309
+ return false;
1204
1310
  }
1205
- // Copy of Layout from utilishared but using solid-js signals instead of async iterable IPNS
1206
- const show_all_rows = $gVhhF$solidjs.createMemo(() => props.rows === "all");
1207
- const rows_or_empty_object = $gVhhF$solidjs.createMemo(() => show_all_rows() ? {} : props.rows);
1208
- const view_more_button_elements = $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52($gVhhF$solidjs.createMemo(() => rows_or_empty_object().button));
1209
- const view_less_button_elements = $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52($gVhhF$solidjs.createMemo(() => rows_or_empty_object().view_less_button));
1210
- const have_a_view_more_button = $gVhhF$solidjs.createMemo(() => {
1211
- const button = view_more_button_elements();
1212
- return !(!button || Array.isArray(button) && !button.length);
1213
- });
1214
- const have_a_view_less_button = $gVhhF$solidjs.createMemo(() => {
1215
- const button = view_less_button_elements();
1216
- return !(!button || Array.isArray(button) && !button.length);
1217
- });
1218
- const [get_styling, set_styling] = $gVhhF$solidjs.createSignal();
1219
- const selector_beginning = `.depict .${container_class}>`; // class so ppl can have id if needed
1220
- const [get_children_count, set_children_count] = $gVhhF$solidjs.createSignal(0);
1221
- const update_children_count = () => (0, $gVhhF$solidjsweb.isServer) ? 20 : set_children_count(container_element.children.length);
1222
- const col_styling = $gVhhF$solidjs.createMemo(() => $gVhhF$depictaiutilishared.n_col_styling_with_dist(selector_beginning, props.grid_spacing, props.cols_at_size, props.layout, props.override_vertical_spacing));
1223
- const default_currently_visible_signal = $gVhhF$solidjs.createSignal($gVhhF$solidjs.untrack(() => rows_or_empty_object().start_rows ?? 1)); // Keep this signal here, so it doesn't change when rows_or_empty_object and I think it's to be expected that the "internal default signal" stays the same
1224
- const rows_visible_signal = $gVhhF$solidjs.createMemo(() => rows_or_empty_object().currently_visible || default_currently_visible_signal);
1225
- const get_rows_visible = $gVhhF$solidjs.createMemo(() => rows_visible_signal()[0]());
1226
- const set_rows_visible = $gVhhF$solidjs.createMemo(() => rows_visible_signal()[1]);
1227
- const view_more_button_class = "m" + $gVhhF$solidjs.createUniqueId();
1228
- const view_less_button_class = "l" + $gVhhF$solidjs.createUniqueId(); // https://github.com/solidjs/solid-docs/issues/263#issuecomment-1622388079
1229
- const view_more_button_container = $gVhhF$solidjs.createMemo(() => have_a_view_more_button() && (() => {
1230
- var _el$2 = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$);
1231
- $gVhhF$solidjsweb.addEventListener(_el$2, "click", $gVhhF$depictaiutilishared.catchify(() => set_rows_visible()(prev => prev + (rows_or_empty_object().rows_per_click ?? 1))), true);
1232
- $gVhhF$solidjsweb.className(_el$2, `load-more-container ${view_more_button_class}`);
1233
- $gVhhF$solidjsweb.insert(_el$2, () => rows_or_empty_object().button);
1234
- $gVhhF$solidjsweb.runHydrationEvents();
1235
- return _el$2;
1236
- })());
1237
- // We need to have duplicate buttons because which ones is shown depends on the number of rows visible and therefore on the viewport size and therefore on the css media queries
1238
- const view_less_button_container = $gVhhF$solidjs.createMemo(() => have_a_view_less_button() && (() => {
1239
- var _el$3 = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$);
1240
- $gVhhF$solidjsweb.addEventListener(_el$3, "click", $gVhhF$depictaiutilishared.catchify(() => set_rows_visible()(() => rows_or_empty_object().start_rows ?? 1)), true);
1241
- $gVhhF$solidjsweb.className(_el$3, `load-less-container ${view_less_button_class}`);
1242
- $gVhhF$solidjsweb.insert(_el$3, () => rows_or_empty_object().view_less_button);
1243
- $gVhhF$solidjsweb.runHydrationEvents();
1244
- return _el$3;
1245
- })());
1246
- const [force_style_update, set_force_style_update] = $gVhhF$solidjs.createSignal("");
1247
- $gVhhF$solidjs.createComputed(() => {
1248
- // Make sure we don't have more rows visible than max_rows (this could happen by max_rows being decreased)
1249
- const rows_visible = get_rows_visible();
1250
- const max_rows = rows_or_empty_object().max_rows;
1251
- if (!isNaN(max_rows) && max_rows >= 0 && rows_visible > max_rows) set_rows_visible()(max_rows);
1252
- });
1253
- $gVhhF$solidjs.createEffect(() => set_force_style_update(" ")); // force style update after hydration due to https://discord.com/channels/722131463138705510/722167424186843267/1151544212517552168
1254
- $gVhhF$solidjs.createRenderEffect(() => {
1255
- // Be careful to only read show_all_rows in here (ofc doesn't apply to nested effects)
1256
- if (show_all_rows()) {
1257
- // no view more functionality requested
1258
- set_styling(() => col_styling);
1259
- return;
1260
- }
1261
- update_children_count();
1262
- if (!(0, $gVhhF$solidjsweb.isServer)) {
1263
- const mutation_observer = new MutationObserver($gVhhF$depictaiutilishared.catchify(update_children_count));
1264
- mutation_observer.observe(container_element, {
1265
- childList: true
1266
- });
1267
- $gVhhF$solidjs.onCleanup(() => mutation_observer.disconnect());
1268
- }
1269
- set_styling(
1270
- // this is needed because solid will think that the memo-accessor is a setter function otherwise
1271
- () => $gVhhF$solidjs.createMemo(() => {
1272
- const {
1273
- rows_per_click: rows_per_click,
1274
- max_rows = -1,
1275
- start_rows: start_rows
1276
- } = rows_or_empty_object();
1277
- const rows_visible = get_rows_visible();
1278
- const children_count = get_children_count();
1279
- return force_style_update() + col_styling() + props.cols_at_size.map(options => {
1280
- const [recs_per_row, min, max] = options;
1281
- let should_hide_view_more_button;
1282
- let visible_recs;
1283
- if (props.disable_partial_rows) {
1284
- visible_recs = $gVhhF$depictaiutilishared.layout_get_visible_recs_without_partial_rows(rows_visible, children_count, options);
1285
- const visible_recs_next_show_more = $gVhhF$depictaiutilishared.layout_get_visible_recs_without_partial_rows(rows_visible + (rows_per_click || 0),
1286
- // Should this really be zero when we default rows_per_click to 1?
1287
- children_count, options);
1288
- should_hide_view_more_button = visible_recs === visible_recs_next_show_more;
1289
- } else {
1290
- visible_recs = $gVhhF$depictaiutilishared.layout_get_total_rec_amount_for_row(rows_visible, options);
1291
- should_hide_view_more_button = visible_recs >= children_count;
1292
- }
1293
- const should_hide_button_final = should_hide_view_more_button || max_rows !== -1 && rows_visible >= max_rows;
1294
- // I don't really understand the logic for when the view more button gets hidden so IDK if below is correct, but it works how it should for now
1295
- const should_hide_view_less_button = !should_hide_view_more_button || start_rows == undefined || rows_visible <= start_rows || children_count <= recs_per_row * start_rows;
1296
- return `${$gVhhF$depictaiutilishared.layout_media_query_header(min, max)}{${selector_beginning}:nth-child(n+${visible_recs + 1}){display:none}${props.layout == "slider" ? `${selector_beginning}:nth-child(n+${visible_recs}){margin-right:0}` : ""}${should_hide_button_final ? `.depict .${view_more_button_class}{display:none!important}` : ``}${should_hide_view_less_button ? `.depict .${view_less_button_class}{display:none!important}` : ``}}`;
1297
- }).join("");
1298
- }));
1299
- });
1300
- const style_element = (() => {
1301
- var _el$4 = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$2);
1302
- $gVhhF$solidjsweb.insert(_el$4, get_styling);
1303
- return _el$4;
1304
- })(); // need to create this after set_styling has been called or else there will be no styling in the SSR'd output
1305
- if (insert_after_container) container_element.after(style_element);
1306
- return [container_element, $gVhhF$solidjsweb.memo(view_more_button_container), $gVhhF$solidjsweb.memo(view_less_button_container), style_element];
1311
+ return true;
1307
1312
  }
1308
- $gVhhF$solidjsweb.delegateEvents(["click"]);
1309
- var $363ce4d1d71041aa$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<h2 class=recs-title>`);
1310
- function $363ce4d1d71041aa$export$d41d19e89346fa2({
1311
- recommendations_resource_: recommendations_resource_,
1313
+ const $67155e1aeb7073f6$export$f223d69ed12f5fb7 = /*@__PURE__*/$gVhhF$solidjs.createContext();
1314
+ function $67155e1aeb7073f6$export$4a14175d33d81a96({
1315
+ displays_by_key_: displays_by_key_,
1312
1316
  product_card_template_: product_card_template_,
1313
- layout_options_: layout_options_,
1314
- title_: title_,
1315
- NoResultsFallback_: NoResultsFallback_,
1316
- placeholderCacheKey_: placeholderCacheKey_
1317
+ content_blocks_: content_blocks_,
1318
+ alwaysObserveCards_: alwaysObserveCards_
1317
1319
  }) {
1318
- const is_showing_something = $gVhhF$solidjs.createMemo(() => recommendations_resource_.loading || recommendations_resource_()?.length);
1319
- const title = $gVhhF$solidjs.createMemo(() => title_?.()); // In case getter/accessor creates elements, don't create them twice
1320
- const num_placeholders_ = () => 20;
1321
- const slider = [$gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
1322
- get when() {
1323
- return title();
1324
- },
1325
- get children() {
1326
- var _el$ = $gVhhF$solidjsweb.getNextElement($363ce4d1d71041aa$var$_tmpl$);
1327
- $gVhhF$solidjsweb.insert(_el$, title);
1328
- return _el$;
1329
- }
1330
- }), $gVhhF$solidjsweb.createComponent((0, $a0e53f99354809d9$export$6649caad96ef8870), {
1331
- arrow_height_: 25,
1332
- arrow_width_: 12.5,
1333
- disable_fading_: true,
1334
- slider_ref_: slider => {
1320
+ const targetToIndexMap_ = new Map();
1321
+ const indexToTargetMap_ = new Map();
1322
+ const [listenersForIntersecting, setListenersForIntersecting] = $gVhhF$solidjs.createSignal(0);
1323
+ const [currentlyIntersecting, setCurrentlyIntersecting] = $gVhhF$solidjs.createSignal(new Set(), {
1324
+ equals: false
1325
+ });
1326
+ if (0, $gVhhF$solidjsweb.isServer) return {
1327
+ renderedDisplays_: $a73063cc642f3e5f$export$43f0fb951fcb0c54({
1328
+ displays_by_key_: displays_by_key_,
1329
+ product_card_template_: product_card_template_,
1330
+ content_blocks_: content_blocks_
1331
+ }),
1332
+ indexToTargetMap_: indexToTargetMap_,
1333
+ currentlyIntersecting: currentlyIntersecting
1334
+ };
1335
+ // The following sets up an intersection observer to determine which results are in the viewport, used for the ScrollStatus indicator, knowing when to load more and any other consumer of the useProductCardIsVisible hook.
1336
+ const shouldObserve = $gVhhF$solidjs.createMemo(() => alwaysObserveCards_ || listenersForIntersecting() > 0);
1337
+ const intersection_observer = new IntersectionObserver($gVhhF$depictaiutilishared.catchify(records => {
1338
+ const intersectingValue = currentlyIntersecting();
1339
+ for (let i = 0; i < records.length; i++) {
1340
+ const record = records[i];
1335
1341
  const {
1336
- insert_here: insert_here,
1337
- container: container
1338
- } = slider;
1339
- const Layout = props => $f48d0fbb00835aaa$export$445d8d3f5f706a40(props, insert_here, true);
1340
- // Do like this, so we don't have to call mergeProps ourselves
1341
- $gVhhF$solidjsweb.createComponent(Layout, $gVhhF$solidjsweb.mergeProps({
1342
- rows: "all",
1343
- layout: "slider"
1344
- }, layout_options_));
1345
- $gVhhF$depictaiutilishared.slider_fractional_factory(0, 0.75).constructor_plugin.call(slider, {}); // enable fractional scrolling
1346
- insert_here.before($fc23d7668ae0011d$export$a2cc176055f8f08());
1347
- container.classList.add("products");
1342
+ target: target,
1343
+ intersectionRatio: intersectionRatio
1344
+ } = record;
1345
+ const index_of_target = targetToIndexMap_.get(target);
1346
+ if (index_of_target == undefined) return; // It seems like it can happen that we get IntersectionObserverEntries after the onCleanup function for a recommendation card has run, in Firefox. Probably a bug in Firefox? If I understood the bug correctly, this is a workaround.
1347
+ const is_in_set = intersectingValue.has(index_of_target);
1348
+ if (intersectionRatio > 0) {
1349
+ if (!is_in_set) intersectingValue.add(index_of_target);
1350
+ } else if (is_in_set) intersectingValue.delete(index_of_target);
1351
+ }
1352
+ setCurrentlyIntersecting(intersectingValue);
1353
+ }, "renderDisplays IO failed"));
1354
+ const renderedDisplays_ = $gVhhF$solidjsweb.createComponent($67155e1aeb7073f6$export$f223d69ed12f5fb7.Provider, {
1355
+ value: {
1356
+ currentlyIntersecting_: currentlyIntersecting,
1357
+ setIsListening_: setListenersForIntersecting
1348
1358
  },
1349
1359
  get children() {
1350
- return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Suspense), {
1351
- get fallback() {
1352
- return $0caf87eaa19079da$export$f33414a4df0afd3f({
1353
- num_placeholders_: num_placeholders_,
1354
- product_card_template_: product_card_template_,
1355
- placeholderCacheKey_: placeholderCacheKey_
1356
- });
1357
- },
1358
- get children() {
1359
- return (() => {
1360
- // IIFE to make sure we access both the recommendations_resource and the resources containing the product card rendering results themselves within the Suspense boundary
1361
- const displays_by_key_ = $a73063cc642f3e5f$export$7f8bd308237ab5a5($gVhhF$solidjs.createMemo(() => recommendations_resource_() || []));
1362
- const {
1363
- renderedDisplays_: renderedDisplays_
1364
- } = $67155e1aeb7073f6$export$4a14175d33d81a96({
1365
- displays_by_key_: displays_by_key_,
1366
- product_card_template_: product_card_template_
1360
+ return $a73063cc642f3e5f$export$43f0fb951fcb0c54({
1361
+ displays_by_key_: displays_by_key_,
1362
+ product_card_template_: product_card_template_,
1363
+ content_blocks_: content_blocks_,
1364
+ do_per_elements_: (elements, index_accessor) =>
1365
+ // Adds/removes elements from the "results in viewport" intersection observer above
1366
+ $gVhhF$solidjs.createEffect(() => {
1367
+ if (!shouldObserve()) return;
1368
+ const display_index = index_accessor();
1369
+ // Nested createEffect because we only want to re-run this when the index changes (or we should/shouldn't observe)
1370
+ // We need to save in a map which index the elements of this template are so that we can know that in the IntersectionObserver callback
1371
+ for (let i = 0; i < elements.length; i++) {
1372
+ const element = elements[i];
1373
+ targetToIndexMap_.set(element, display_index);
1374
+ intersection_observer.observe(element);
1375
+ $gVhhF$solidjs.onCleanup(() => {
1376
+ intersection_observer.unobserve(element);
1377
+ targetToIndexMap_.delete(element);
1378
+ const intersecting = $gVhhF$solidjs.untrack(currentlyIntersecting);
1379
+ const wasDeleted = intersecting.delete(display_index);
1380
+ if (wasDeleted) setCurrentlyIntersecting(intersecting);
1367
1381
  });
1368
- return renderedDisplays_;
1369
- })();
1370
- }
1382
+ }
1383
+ indexToTargetMap_.set(display_index, elements);
1384
+ $gVhhF$solidjs.onCleanup(() => indexToTargetMap_.delete(display_index));
1385
+ })
1371
1386
  });
1372
1387
  }
1373
- })];
1374
- return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
1375
- get when() {
1376
- return is_showing_something();
1377
- },
1378
- get fallback() {
1379
- return NoResultsFallback_?.();
1380
- },
1381
- children: slider
1382
1388
  });
1383
- }
1384
- function $95837413165cc2df$export$23fca46f3143581f(component, error_message) {
1385
- const component_in_error_boundary = do_with_elements => {
1386
- const error_boundary_wrapped = $edafe91daf3091d7$export$b69d0d92862de18b({
1387
- severity_: "error",
1388
- message_: error_message,
1389
- get children() {
1390
- const elements = component();
1391
- do_with_elements?.(elements);
1392
- return elements;
1393
- }
1394
- });
1395
- // This might return an accessor, in that case we need to "unwrap" it since our SDK consumers expect HTML elements or arrays thereof
1396
- if (typeof error_boundary_wrapped === "function")
1397
- // @ts-ignore
1398
- return error_boundary_wrapped();
1399
- // On the server it returns a string, so we just return that
1400
- return error_boundary_wrapped;
1389
+ return {
1390
+ renderedDisplays_: renderedDisplays_,
1391
+ indexToTargetMap_: indexToTargetMap_,
1392
+ currentlyIntersecting: currentlyIntersecting
1401
1393
  };
1402
- const owner = $gVhhF$solidjs.getOwner();
1403
- if (owner == null) return $gVhhF$solidjs.createRoot(dispose => {
1404
- // if we're not already run in a root, create a root and automatically dispose it when the first returned element is removed from the DOM
1405
- return component_in_error_boundary(elements => {
1406
- const have_multiple = Array.isArray(elements);
1407
- if (have_multiple ? !elements?.length : !elements) return;
1408
- (0, $gVhhF$depictaiutilishared.observer).onremoved(have_multiple ? elements[0] : elements, ({
1409
- element: element
1410
- }) => {
1411
- if (document.documentElement.contains(element)) return; // If element has instantly been re-inserted, don't dispose
1412
- // See https://depictaiworkspace.slack.com/archives/C050GHEPBTR/p1695809102791259?thread_ts=1695106805.459729&cid=C050GHEPBTR
1413
- dispose();
1414
- });
1415
- });
1416
- });else
1417
- // we're already in a root so cleanups are handled
1418
- return component_in_error_boundary();
1419
- }
1420
- const $84798aaa863a4909$var$ListingContext = /*@__PURE__*/$gVhhF$solidjs.createContext();
1421
- function $84798aaa863a4909$export$e68cff63f76bd15b(props) {
1422
- const our_object = {};
1423
- return $gVhhF$solidjsweb.createComponent($84798aaa863a4909$var$ListingContext.Provider, {
1424
- value: our_object,
1425
- get children() {
1426
- return props.children;
1427
- }
1428
- });
1429
1394
  }
1430
- function $84798aaa863a4909$export$8d0c4fdbb05a2f2e() {
1431
- return $gVhhF$solidjs.useContext($84798aaa863a4909$var$ListingContext);
1395
+ function $67155e1aeb7073f6$export$80bb7300ce6a8be3() {
1396
+ const {
1397
+ setIsListening_: setIsListening_,
1398
+ currentlyIntersecting_: currentlyIntersecting_
1399
+ } = $gVhhF$solidjs.useContext($67155e1aeb7073f6$export$f223d69ed12f5fb7) || {};
1400
+ const getOurIndex = $129b9b9c010039d0$export$e3faf4d95300054f();
1401
+ const isVisible = $gVhhF$solidjs.createMemo(() => currentlyIntersecting_?.().has(getOurIndex?.()));
1402
+ setIsListening_?.(prev => prev + 1);
1403
+ $gVhhF$solidjs.onCleanup(() => setIsListening_?.(prev => prev + 1));
1404
+ return isVisible;
1432
1405
  }
1433
- function $061ff5b4c3d36171$export$89c6019e4baa40b1(props) {
1434
- const style = $gVhhF$solidjs.createMemo(() => {
1435
- const {
1436
- style: style,
1437
- height: height,
1438
- width: width
1439
- } = props;
1440
- return {
1441
- ...(style || {}),
1442
- height: height ?? "1em",
1443
- ...(width && {
1444
- width: width
1445
- })
1446
- };
1447
- });
1448
- return $gVhhF$solidjsweb.createComponent((0, $9fe9883b1d8ecccc$export$acb3eaade4b23afd), {
1449
- get style() {
1450
- return style();
1451
- },
1452
- get ["class"]() {
1453
- return props.class;
1406
+ function $4b455f60dadde8b8$export$5bad61ecde080b1f(...params) {
1407
+ const {
1408
+ collapse: collapse,
1409
+ expand: expand,
1410
+ ExpandingContainer: ExpandingContainer
1411
+ } = $gVhhF$depictaiutilishared.useExpandingContainer(...params);
1412
+ return {
1413
+ collapse: collapse,
1414
+ expand: expand,
1415
+ ExpandingContainer: ({
1416
+ children: children
1417
+ }) => {
1418
+ // get reactive signals/solid's jsx elements into `ExpandingContainer`
1419
+ const fake_div = document.createElement("div");
1420
+ const outer_expanding = $gVhhF$solidjsweb.createComponent(ExpandingContainer, {
1421
+ children: [fake_div]
1422
+ });
1423
+ const parent = fake_div.parentElement;
1424
+ fake_div.remove();
1425
+ $gVhhF$solidjsweb.insert(parent, children);
1426
+ return outer_expanding;
1454
1427
  }
1455
- });
1456
- }
1457
- var $6f604560873e4f69$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class=instant-card><div class=img-part></div><div class=right-part><div class=title-brand-tagline><span class=title></span></div><div class=price-container>`);
1458
- const $6f604560873e4f69$export$8a2234b5b1a5ebd4 = "--image-aspect-ratio";
1459
- function $6f604560873e4f69$export$ee1733d9a8495996() {
1460
- return (() => {
1461
- var _el$ = $gVhhF$solidjsweb.getNextElement($6f604560873e4f69$var$_tmpl$),
1462
- _el$2 = _el$.firstChild,
1463
- _el$3 = _el$2.nextSibling,
1464
- _el$4 = _el$3.firstChild,
1465
- _el$5 = _el$4.firstChild,
1466
- _el$6 = _el$4.nextSibling;
1467
- $gVhhF$solidjsweb.insert(_el$2, $gVhhF$solidjsweb.createComponent((0, $3bc4a89b971a3af5$export$3f37af283f8fb843), {
1468
- aspectRatio: `var(${$6f604560873e4f69$export$8a2234b5b1a5ebd4}, 1)`
1469
- }));
1470
- $gVhhF$solidjsweb.insert(_el$5, $gVhhF$solidjsweb.createComponent((0, $061ff5b4c3d36171$export$89c6019e4baa40b1), {
1471
- width: "20ch",
1472
- height: "1em"
1473
- }));
1474
- $gVhhF$solidjsweb.insert(_el$6, $gVhhF$solidjsweb.createComponent((0, $061ff5b4c3d36171$export$89c6019e4baa40b1), {
1475
- width: "5ch",
1476
- height: "1em",
1477
- "class": "price"
1478
- }));
1479
- return _el$;
1480
- })();
1481
- }
1482
- var $93304d59a9747aa6$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div>`);
1483
- function $93304d59a9747aa6$export$94026ee33dbabc26(props) {
1484
- return (() => {
1485
- var _el$ = $gVhhF$solidjsweb.getNextElement($93304d59a9747aa6$var$_tmpl$);
1486
- $gVhhF$solidjsweb.insert(_el$, () => props.children);
1487
- $gVhhF$solidjsweb.effect(_p$ => {
1488
- var _v$ = `padding-bottom:calc(calc(1 / ${props.aspectRatio}) * 100%)`,
1489
- _v$2 = "s-image-container" + (props.class ? " " + props.class : "");
1490
- _p$.e = $gVhhF$solidjsweb.style(_el$, _v$, _p$.e);
1491
- _v$2 !== _p$.t && $gVhhF$solidjsweb.className(_el$, _p$.t = _v$2);
1492
- return _p$;
1493
- }, {
1494
- e: undefined,
1495
- t: undefined
1496
- });
1497
- return _el$;
1498
- })();
1499
- }
1500
- let $3ea8e0af95b5b7d2$var$browserIsBugged = false;
1501
- function $3ea8e0af95b5b7d2$export$2972b890694ced75(callback, {
1502
- timeout: timeout
1503
- }) {
1504
- if ($3ea8e0af95b5b7d2$var$browserIsBugged) timeout /= 4;
1505
- const cancel = () => {
1506
- cancelIdleCallback(idleHandle);
1507
- clearTimeout(racingTimeout);
1508
1428
  };
1509
- const idleHandle = requestIdleCallback(deadline => {
1510
- cancel();
1511
- return callback(deadline);
1512
- }, {
1513
- timeout: timeout
1429
+ }
1430
+ const $4e04be41243c3d80$var$transform_elements = sorted_cols_at_size => {
1431
+ const cols_at_size = [];
1432
+ for (let i = 0; i < sorted_cols_at_size.length; i++) {
1433
+ const [nb_cols, width] = sorted_cols_at_size[i];
1434
+ const next_width = sorted_cols_at_size[i + 1]?.[1];
1435
+ const max_width = i === 0 ? "" : `${width}px`;
1436
+ const min_width = next_width !== undefined ? `${next_width + 1}px` : "";
1437
+ const col_at_size = [nb_cols, min_width, max_width];
1438
+ cols_at_size.push(col_at_size);
1439
+ }
1440
+ return cols_at_size;
1441
+ };
1442
+ const $4e04be41243c3d80$export$6daf8749b65a1b77 = cols_at_size => {
1443
+ // Check that every element is an array
1444
+ const are_arrays = cols_at_size?.every?.(element => Array.isArray(element));
1445
+ if (!are_arrays) throw new Error("Every element in cols_at_size must be an array");
1446
+ // Check width duplicates
1447
+ const widths = cols_at_size.map(([_, width]) => width);
1448
+ const widths_set = new Set(widths);
1449
+ if (widths_set.size < widths.length) throw new Error("There are duplicate widths in cols_at_size");
1450
+ if (cols_at_size.length === 1) {
1451
+ const [nb_cols, width] = cols_at_size[0];
1452
+ const max_width = width !== undefined ? `${width}px` : "";
1453
+ return [[nb_cols, "", max_width]];
1454
+ }
1455
+ // Sort widths in ascending order
1456
+ const sorted_cols_at_size = [...cols_at_size].sort((a, b) => {
1457
+ const [_b, width_A] = a;
1458
+ const [_a, width_b] = b;
1459
+ if (width_A === undefined) return -1;
1460
+ if (width_b === undefined) return 1;
1461
+ return width_b - width_A;
1514
1462
  });
1515
- const racingTimeout = setTimeout(() => {
1516
- $gVhhF$depictaiutilishared.dwarn("Browser did not respect requestIdleCallback timeout");
1517
- $3ea8e0af95b5b7d2$var$browserIsBugged = true;
1518
- cancel();
1519
- callback({
1520
- didTimeout: false,
1521
- timeRemaining() {
1522
- return 500;
1523
- }
1524
- });
1525
- }, timeout + 1000);
1526
- return cancel;
1463
+ return $4e04be41243c3d80$var$transform_elements(sorted_cols_at_size);
1464
+ };
1465
+ function $fc23d7668ae0011d$export$a2cc176055f8f08(what = "grid") {
1466
+ const text = "Please try setting `columnsAtSize`/`gridSpacing` on the `SearchPage`/`CategoryPage` components to change the " + what + " before setting it with CSS. If you do with CSS, set `columnsAtSize` to an empty array to ensure no declarations created by the SDK leak through.";
1467
+ return (0, $gVhhF$solidjsweb.isServer) ? {
1468
+ t: `<!-- ${text} -->`
1469
+ } : document.createComment(text);
1527
1470
  }
1528
- function $19950faaac026e09$export$e6fffe67d4cdd848(whatToWatch) {
1529
- const [size, setSize] = $gVhhF$solidjs.createSignal(0);
1530
- const resizeObserver = new ResizeObserver($gVhhF$depictaiutilishared.catchify(records => {
1531
- for (let j = 0; j < records.length; j++) {
1532
- const {
1533
- width: width
1534
- } = records[j].contentRect;
1535
- if (!width) continue;
1536
- setSize(Math.ceil(width));
1471
+ const $0caf87eaa19079da$var$defaultCacheKey = /*@__PURE__*/Symbol();
1472
+ const $0caf87eaa19079da$var$cachedPlaceholderElements = {};
1473
+ const $0caf87eaa19079da$var$renderingCachedPlaceholderElement = {};
1474
+ function $0caf87eaa19079da$export$f33414a4df0afd3f({
1475
+ product_card_template_: product_card_template_,
1476
+ num_placeholders_: num_placeholders_,
1477
+ content_blocks_: content_blocks_,
1478
+ placeholderCacheKey_: placeholderCacheKey_
1479
+ }) {
1480
+ const [num_to_actually_show, set_num_to_actually_show] = $gVhhF$solidjs.createSignal($gVhhF$solidjs.untrack(num_placeholders_));
1481
+ if (0, $gVhhF$solidjsweb.isServer)
1482
+ // want to render simple placeholders on server, effects don't run there
1483
+ // FIXME when adding proper SSR: also SSR content blocks
1484
+ return $gVhhF$solidjs.createMemo(() => Array.from({
1485
+ length: num_placeholders_()
1486
+ }).map(() => {
1487
+ const template_result = product_card_template_(null, undefined);
1488
+ // @ts-ignore
1489
+ if (typeof template_result?.then !== "function") return template_result;
1490
+ }));
1491
+ $gVhhF$solidjs.createRenderEffect(() => {
1492
+ const existing_num = num_to_actually_show();
1493
+ const to_add = num_placeholders_() - existing_num;
1494
+ if (to_add <= 0) return;
1495
+ // Below comment is from when we used recommendation renderer and manual DOM manipulation for this, but I'm still scared to remove placeholders and mess up scroll restoration, so I'm keeping the way it worked. Otherwise, <Index> could be used which would be far more elegant.
1496
+ // We don't need to remove placeholders, only need to add. The reason for that is that chrome restores the scroll position once all tasks queued as reaction of the "popstate" events have been completed in the task queue. That means that we need to get the placeholders in fast, or we might lose scroll position if the previous site was shorter.
1497
+ // The query id and the amount might update in separate tasks because one comes from href_change_ipns and the other one from another "popstate" listener. Therefore, we need to be able to dynamically add more placeholders. I'm not entirely sure about this anymore though, since we have the scroll position on a per-id basis it might work anyway but THIS WORKS, and I've been working on this bug for 3 hours so let's just keep it this way.
1498
+ // Above comments were from when we added elements in this createRenderEffect. Now I changed it to just increment the number and render them from an <Index> instead, so I can add content blocks better
1499
+ // Functionality should be the same
1500
+ set_num_to_actually_show(existing_num + to_add);
1501
+ });
1502
+ return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Index), {
1503
+ get each() {
1504
+ return Array.from({
1505
+ length: num_to_actually_show()
1506
+ });
1507
+ },
1508
+ children: (_item, index) => {
1509
+ const possible_content_block = $gVhhF$solidjs.createMemo(() => content_blocks_?.()?.()?.[index]);
1510
+ // Show content block before product card, so it's *at* that index
1511
+ return [possible_content_block, $0caf87eaa19079da$var$Placeholder({
1512
+ product_card_template_: product_card_template_,
1513
+ placeholderCacheKey_: placeholderCacheKey_
1514
+ })]; // https://github.com/solidjs/solid/releases/tag/v1.7.0
1537
1515
  }
1538
- }));
1539
- // If we start observing elements before they're in the DOM Chrome (Version 117.0.5938.92 (Official Build) (arm64)) sometimes gives us a resize event with a width of 0 and then doesn't dispatch one with the actual width once it's in the DOM. So we wait until the element is in the DOM before we start observing it.
1540
- // It doesn't seem to work even when waiting for it to be in the DOM, also wait an animation frame
1541
- const disconnect = (0, $gVhhF$depictaiutilishared.observer).onexists(whatToWatch, ({
1542
- element: element
1543
- }) => requestAnimationFrame($gVhhF$depictaiutilishared.catchify(() => resizeObserver.observe(element))));
1544
- $gVhhF$solidjs.onCleanup(() => {
1545
- resizeObserver.disconnect();
1546
- disconnect();
1547
1516
  });
1548
- return size;
1549
1517
  }
1550
- const $19950faaac026e09$var$onIdleFunctionsSymbol = /*@__PURE__*/Symbol("onIdleFunctions");
1551
- const $19950faaac026e09$export$f8945274f08a3105 = /*@__PURE__*/Symbol("listingContextAspectRatios");
1552
- const $19950faaac026e09$export$6066eb417ed2e9f7 = /*@__PURE__*/Symbol("listingContextAspectRatios");
1553
- function $19950faaac026e09$export$6e5611bc7e57e477(props) {
1554
- const src_options = $gVhhF$solidjs.createMemo(() => {
1555
- const {
1556
- src: src,
1557
- customUrls: customUrls
1558
- } = props;
1559
- const fallback_src = (customUrls || $19950faaac026e09$export$1d6267828870adda)(src, 400);
1560
- const srcset = $19950faaac026e09$var$make_srcset(props.src, props.resolutions || [64, 128, 256, 300, 400, 512, 640, 768, 1024, 1280, 1536, 2048, 2560, 3072, 3584, 4096], customUrls);
1561
- // The order here *might* matter - I've seen mobile safari always start with loading the 400px version when it was reversed
1562
- return {
1563
- srcset: srcset,
1564
- src: fallback_src
1565
- };
1518
+ /**
1519
+ * Get one placeholder element. It will be cloned for each placeholder for ultimate performance even when solid-js isn't rendering the placeholders.
1520
+ */
1521
+ function $0caf87eaa19079da$var$Placeholder({
1522
+ product_card_template_: product_card_template_,
1523
+ placeholderCacheKey_ = $0caf87eaa19079da$var$defaultCacheKey
1524
+ }) {
1525
+ const get_cloned_placeholders = (element_to_clone = $0caf87eaa19079da$var$cachedPlaceholderElements[placeholderCacheKey_]) => Array.isArray(element_to_clone) ? element_to_clone.map(el => el instanceof Node ? el.cloneNode(true) : el) : element_to_clone;
1526
+ if ($0caf87eaa19079da$var$cachedPlaceholderElements[placeholderCacheKey_]) return get_cloned_placeholders();
1527
+ let dispose_original_copy;
1528
+ const get_unwrapped_element = $gVhhF$solidjs.createRoot(dispose => {
1529
+ dispose_original_copy = dispose;
1530
+ // if product_card_template_ is async and rejects the resource will take care of throwing upwards here in the solid-js error handling system
1531
+ const [resource] = $gVhhF$solidjs.createResource(() => {
1532
+ const rendering_cached_placeholder_element = $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_];
1533
+ if (rendering_cached_placeholder_element) return rendering_cached_placeholder_element;
1534
+ const return_value = product_card_template_(null, undefined);
1535
+ if (typeof return_value === "object" && typeof return_value?.then === "function")
1536
+ // Is Promise or promise-like object
1537
+ $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_] = return_value;
1538
+ return return_value;
1539
+ });
1540
+ return $gVhhF$solidjs.createMemo(() => {
1541
+ if (resource.loading) return () => [];
1542
+ return $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52(resource);
1543
+ });
1566
1544
  });
1567
- // Work around https://github.com/solidjs/solid/issues/1828
1568
- const img = new Image(); // Need to use new Image or browser might not start loading image before it's in the DOM
1569
- const [, otherAttributes] = $gVhhF$solidjs.splitProps(props, ["resolutions", "size", "src", "srcSet", "loading", "keyRatioUpdating", "customUrls" // Can't have properties ending on underscore because the property name mangling will get confused by this <-
1570
- ]);
1571
-
1572
- const [hasSetSize, setHasSetSize] = $gVhhF$solidjs.createSignal(false);
1573
- const [hasDecoded, setHasDecoded] = $gVhhF$solidjs.createSignal(false);
1574
- const productCardIndexAccessor = $129b9b9c010039d0$export$e3faf4d95300054f();
1575
- const sizePX = $gVhhF$solidjs.createMemo(() => `${props.size()}px`); // props.size could be a getter that expects a cleanup so get it in this memo instead of where we set img.sizes
1576
- const listingContext = $84798aaa863a4909$export$8d0c4fdbb05a2f2e();
1577
- const isPrioritisedImage = $gVhhF$solidjs.createMemo(() => productCardIndexAccessor?.() < 8);
1578
- const shouldActuallyEnableLazyLoading = $gVhhF$solidjs.createMemo(() => {
1579
- const {
1580
- loading: loading
1581
- } = props;
1582
- if (loading === "force-lazy") return true;
1583
- return loading === "lazy" && !isPrioritisedImage();
1545
+ $gVhhF$solidjs.onCleanup(() => {
1546
+ const rendering = $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_];
1547
+ if (rendering) {
1548
+ // If we're still rendering in our separate root, let the rendering finish or other <Placeholder> components waiting for it might get an incomplete result
1549
+ const unset_current_rendering = () => {
1550
+ dispose_original_copy();
1551
+ $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_] = undefined;
1552
+ };
1553
+ rendering?.then(unset_current_rendering, unset_current_rendering);
1554
+ } else
1555
+ // Otherwise, just make sure we've disposed our root
1556
+ dispose_original_copy();
1584
1557
  });
1585
- const modifiedOtherAttributes = $gVhhF$solidjs.mergeProps(otherAttributes, {
1586
- get loading() {
1587
- return shouldActuallyEnableLazyLoading() ? "lazy" : undefined;
1588
- }
1558
+ return $gVhhF$solidjs.createMemo(() => {
1559
+ const unwrapped_array = get_unwrapped_element()();
1560
+ if (!unwrapped_array?.length || !unwrapped_array.every(item => item))
1561
+ // Haven't finished rendering yet in case of "async" rendering, so don't freeze the elements yet
1562
+ return;
1563
+ // placeholders have finished rendering, freeze the elements
1564
+ // here we might receive the result of a promise that has already been received, tore down and put into cached_placeholder_element, so don't overwrite that more valid result if it's already set
1565
+ $0caf87eaa19079da$var$cachedPlaceholderElements[placeholderCacheKey_] ||= get_cloned_placeholders(unwrapped_array); // Clone initial return value so that who gave us the elements can't mutate them, which has caused issues before with react
1566
+ $0caf87eaa19079da$var$renderingCachedPlaceholderElement[placeholderCacheKey_] = undefined;
1567
+ dispose_original_copy(); // So that this memo will never re-run and the placeholder rendering function can clean up
1568
+ return get_cloned_placeholders(); // clone, just in case. If we wouldn't, someone could modify the copy in the DOM, and it would affect the cached version
1589
1569
  });
1590
- // Batch idle callbacks so that MutationObserver can batch the resulting mutations better, so we don't lose tons of CPU time to MutationObservers doing lots of things for each image
1591
- // Happened on singular, they have some weird observer (+we also have one but ours is at least 3x more efficient)
1592
- const executeWhenIdleBatched = (fn, isSizesUpdate) => {
1593
- if (typeof requestIdleCallback !== "function") return setTimeout(fn); // Old browsers don't get optimisation
1594
- if ((!isSizesUpdate || !sizeSetFastPath) && $gVhhF$solidjs.untrack(isPrioritisedImage)) return fn(); // If we're one of the first 8 images, execute the callbacks immediately (improves lighthouse metrics)
1595
- // unless we're just a `sizes` update after the initial sizes setting (this optimisation makes the looks animation a lot smoother on low-cpu devices)
1596
- const existingStack = listingContext?.[$19950faaac026e09$var$onIdleFunctionsSymbol];
1597
- if (existingStack) return existingStack.add(fn);
1598
- const newStack = new Set([fn]);
1599
- if (listingContext) listingContext[$19950faaac026e09$var$onIdleFunctionsSymbol] = newStack;
1600
- const processStackWhenIdle = () => $3ea8e0af95b5b7d2$export$2972b890694ced75($gVhhF$depictaiutilishared.catchify(deadline => {
1601
- const start = performance.now();
1602
- const thirdDeadlineTime = deadline.timeRemaining() / 3; // observers coming after this take up 2-3x the time so don't use all of it
1603
- for (const fn of newStack) {
1604
- newStack.delete(fn);
1605
- fn();
1606
- const timeTaken = performance.now() - start;
1607
- if ((!deadline.timeRemaining() || timeTaken > thirdDeadlineTime) && newStack.size) {
1608
- // There's still work to be done but no time, so schedule another idle callback
1609
- processStackWhenIdle();
1610
- return;
1611
- }
1612
- }
1613
- // Stack is empty
1614
- if (listingContext) delete listingContext[$19950faaac026e09$var$onIdleFunctionsSymbol];
1615
- }), {
1616
- timeout: 15000
1617
- } // long timeout, better to not have images than to freeze the browser. But also we don't want to confuse user why no iamges are loading
1618
- );
1570
+ }
1619
1571
 
1620
- processStackWhenIdle();
1621
- };
1622
- let sizeSetFastPath = false;
1623
- let hasDecodedFastPath = false;
1624
- let timeoutSet = false;
1625
- let gotCleanedUp = false;
1626
- let srcJustChanged = true;
1627
- img.classList.add("s-responsive-image");
1628
- if (listingContext) {
1629
- let prevValue;
1630
- const aspectRatios = listingContext[$19950faaac026e09$export$f8945274f08a3105] ||= new Set();
1631
- const [, setMostPrevalentAspectRatio] = listingContext[$19950faaac026e09$export$6066eb417ed2e9f7] ||= $gVhhF$solidjs.createSignal();
1632
- img.addEventListener("load", $gVhhF$depictaiutilishared.catchify(() => {
1633
- if (props.keyRatioUpdating) {
1634
- if (!srcJustChanged) return;
1635
- srcJustChanged = false;
1572
+ var $f48d0fbb00835aaa$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div>`),
1573
+ $f48d0fbb00835aaa$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<style type=text/css>`);
1574
+ function $f48d0fbb00835aaa$export$d21e32dfedac04be(props) {
1575
+ const container_class = "x" + $gVhhF$solidjs.createUniqueId();
1576
+ const container_element_ = (() => {
1577
+ var _el$ = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$);
1578
+ $gVhhF$solidjsweb.spread(_el$, $gVhhF$solidjsweb.mergeProps(() => props.element_attributes, {
1579
+ "classList": {
1580
+ [container_class]: true
1636
1581
  }
1637
- // Save our aspect ratio whenever it changes, so that we can base the containers on the most dominant aspect ratio, used in SearchModalV2 and LookItem
1638
- const aspectRatio_ = img.naturalWidth / img.naturalHeight;
1639
- if (prevValue) aspectRatios.delete(prevValue);
1640
- const newValue = !isNaN(aspectRatio_) ? {
1641
- aspectRatio_: aspectRatio_
1642
- } : undefined;
1643
- if (newValue) aspectRatios.add(newValue);
1644
- prevValue = newValue;
1645
- // Do all calculations resulting of an update directly, for performance
1646
- const asArray = [...aspectRatios].map(({
1647
- aspectRatio_: aspectRatio_
1648
- }) => aspectRatio_);
1649
- const mostPrevalentAspectRatio = $gVhhF$depictaiutilishared.findMostFrequentItem(asArray);
1650
- setMostPrevalentAspectRatio(mostPrevalentAspectRatio);
1651
- }));
1652
- $gVhhF$solidjs.onCleanup(() => prevValue && aspectRatios.delete(prevValue));
1582
+ }), false, true);
1583
+ $gVhhF$solidjsweb.insert(_el$, () => props.children);
1584
+ $gVhhF$solidjsweb.runHydrationEvents();
1585
+ return _el$;
1586
+ })(); // Don't want this in the error boundary below, it should only be for the actual layouting
1587
+ return $gVhhF$solidjsweb.createComponent((0, $edafe91daf3091d7$export$b69d0d92862de18b), {
1588
+ get message_() {
1589
+ return "Failed calculating " + props.layout + " layout";
1590
+ },
1591
+ severity_: "error",
1592
+ get children() {
1593
+ return $f48d0fbb00835aaa$export$445d8d3f5f706a40(props, container_element_, false, container_class);
1594
+ }
1595
+ });
1596
+ }
1597
+ function $f48d0fbb00835aaa$export$445d8d3f5f706a40(props, container_element, insert_after_container = false, container_class) {
1598
+ if (!container_class) {
1599
+ // only try to add if it wasn't provided, so that we have a code path without classList when doing SSR
1600
+ container_class = $gVhhF$depictaiutilishared.make_random_classname();
1601
+ container_element.classList.add(container_class);
1653
1602
  }
1654
- $gVhhF$solidjs.onCleanup(() => gotCleanedUp = true);
1655
- $gVhhF$solidjsweb.spread(img, $gVhhF$solidjs.mergeProps(modifiedOtherAttributes), false, true);
1656
- $gVhhF$solidjs.createRenderEffect(() => {
1657
- props.src;
1658
- srcJustChanged = true;
1603
+ // Copy of Layout from utilishared but using solid-js signals instead of async iterable IPNS
1604
+ const show_all_rows = $gVhhF$solidjs.createMemo(() => props.rows === "all");
1605
+ const rows_or_empty_object = $gVhhF$solidjs.createMemo(() => show_all_rows() ? {} : props.rows);
1606
+ const view_more_button_elements = $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52($gVhhF$solidjs.createMemo(() => rows_or_empty_object().button));
1607
+ const view_less_button_elements = $5f7d55c710fd1bc2$export$2f0cbfbb4354bb52($gVhhF$solidjs.createMemo(() => rows_or_empty_object().view_less_button));
1608
+ const have_a_view_more_button = $gVhhF$solidjs.createMemo(() => {
1609
+ const button = view_more_button_elements();
1610
+ return !(!button || Array.isArray(button) && !button.length);
1659
1611
  });
1660
- $gVhhF$solidjs.createEffect(() => {
1661
- if (!props.size()) return; // wait until we have a size, run every time the size changes
1662
- if (timeoutSet) return;
1663
- const handler = $gVhhF$depictaiutilishared.catchify(() => {
1664
- if (gotCleanedUp) return;
1665
- img.sizes = sizePX(); // use latest available value of props.size
1666
- if (!sizeSetFastPath) {
1667
- setHasSetSize(true);
1668
- sizeSetFastPath = true;
1669
- }
1670
- timeoutSet = false;
1671
- });
1672
- // Throttle the updating of sizes to avoid unnecessary image re-fetches during resize
1673
- // And also because we first set src after sizes has been set, wait with loading and decoding images until browser is idle
1674
- // This greatly improves performance when loading (more) products
1675
- // See https://depictaiworkspace.slack.com/archives/C05NJ0K3WRL/p1698220617663139
1676
- timeoutSet = true; // Important to set timeoutSet before the call to executeWhenIdleBatched since if this is an important image executeWhenIdleBatched will execute fn immediately
1677
- executeWhenIdleBatched(handler, true);
1612
+ const have_a_view_less_button = $gVhhF$solidjs.createMemo(() => {
1613
+ const button = view_less_button_elements();
1614
+ return !(!button || Array.isArray(button) && !button.length);
1615
+ });
1616
+ const [get_styling, set_styling] = $gVhhF$solidjs.createSignal();
1617
+ const selector_beginning = `.depict .${container_class}>`; // class so ppl can have id if needed
1618
+ const [get_children_count, set_children_count] = $gVhhF$solidjs.createSignal(0);
1619
+ const update_children_count = () => (0, $gVhhF$solidjsweb.isServer) ? 20 : set_children_count(container_element.children.length);
1620
+ const col_styling = $gVhhF$solidjs.createMemo(() => $gVhhF$depictaiutilishared.n_col_styling_with_dist(selector_beginning, props.grid_spacing, props.cols_at_size, props.layout, props.override_vertical_spacing));
1621
+ const default_currently_visible_signal = $gVhhF$solidjs.createSignal($gVhhF$solidjs.untrack(() => rows_or_empty_object().start_rows ?? 1)); // Keep this signal here, so it doesn't change when rows_or_empty_object and I think it's to be expected that the "internal default signal" stays the same
1622
+ const rows_visible_signal = $gVhhF$solidjs.createMemo(() => rows_or_empty_object().currently_visible || default_currently_visible_signal);
1623
+ const get_rows_visible = $gVhhF$solidjs.createMemo(() => rows_visible_signal()[0]());
1624
+ const set_rows_visible = $gVhhF$solidjs.createMemo(() => rows_visible_signal()[1]);
1625
+ const view_more_button_class = "m" + $gVhhF$solidjs.createUniqueId();
1626
+ const view_less_button_class = "l" + $gVhhF$solidjs.createUniqueId(); // https://github.com/solidjs/solid-docs/issues/263#issuecomment-1622388079
1627
+ const view_more_button_container = $gVhhF$solidjs.createMemo(() => have_a_view_more_button() && (() => {
1628
+ var _el$2 = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$);
1629
+ $gVhhF$solidjsweb.addEventListener(_el$2, "click", $gVhhF$depictaiutilishared.catchify(() => set_rows_visible()(prev => prev + (rows_or_empty_object().rows_per_click ?? 1))), true);
1630
+ $gVhhF$solidjsweb.className(_el$2, `load-more-container ${view_more_button_class}`);
1631
+ $gVhhF$solidjsweb.insert(_el$2, () => rows_or_empty_object().button);
1632
+ $gVhhF$solidjsweb.runHydrationEvents();
1633
+ return _el$2;
1634
+ })());
1635
+ // We need to have duplicate buttons because which ones is shown depends on the number of rows visible and therefore on the viewport size and therefore on the css media queries
1636
+ const view_less_button_container = $gVhhF$solidjs.createMemo(() => have_a_view_less_button() && (() => {
1637
+ var _el$3 = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$);
1638
+ $gVhhF$solidjsweb.addEventListener(_el$3, "click", $gVhhF$depictaiutilishared.catchify(() => set_rows_visible()(() => rows_or_empty_object().start_rows ?? 1)), true);
1639
+ $gVhhF$solidjsweb.className(_el$3, `load-less-container ${view_less_button_class}`);
1640
+ $gVhhF$solidjsweb.insert(_el$3, () => rows_or_empty_object().view_less_button);
1641
+ $gVhhF$solidjsweb.runHydrationEvents();
1642
+ return _el$3;
1643
+ })());
1644
+ const [force_style_update, set_force_style_update] = $gVhhF$solidjs.createSignal("");
1645
+ $gVhhF$solidjs.createComputed(() => {
1646
+ // Make sure we don't have more rows visible than max_rows (this could happen by max_rows being decreased)
1647
+ const rows_visible = get_rows_visible();
1648
+ const max_rows = rows_or_empty_object().max_rows;
1649
+ if (!isNaN(max_rows) && max_rows >= 0 && rows_visible > max_rows) set_rows_visible()(max_rows);
1678
1650
  });
1679
- const dontLoadImageYet = $gVhhF$solidjs.createMemo(() => !props.size() || !hasSetSize()); // Moving this condition into a memo saves us from re-setting src and srcset (expensive) if just props.size changes
1680
- $gVhhF$solidjs.createEffect(() => {
1681
- if (dontLoadImageYet()) return; // If size isn't known or set, don't assign src yet since it would cause the most low res image to load
1682
- Object.assign(img, src_options());
1683
- // Add to DOM once decoded to not require/block any paints before image has completed loading and avoid showing broken image symbol
1684
- // We can do this because there has to be a container around us giving us a size
1685
- // No need to listen if we're already in the DOM
1686
- if (hasDecodedFastPath) return;
1687
- if (shouldActuallyEnableLazyLoading()) {
1688
- // For lazy loading there's no decoding to wait for as it only occurs when the image is visible
1689
- // Make sure src is set before we put the image into the DOM though so no broken image symbol is shown
1690
- setHasDecoded(true);
1691
- hasDecodedFastPath = true;
1651
+ $gVhhF$solidjs.createEffect(() => set_force_style_update(" ")); // force style update after hydration due to https://discord.com/channels/722131463138705510/722167424186843267/1151544212517552168
1652
+ $gVhhF$solidjs.createRenderEffect(() => {
1653
+ // Be careful to only read show_all_rows in here (ofc doesn't apply to nested effects)
1654
+ if (show_all_rows()) {
1655
+ // no view more functionality requested
1656
+ set_styling(() => col_styling);
1692
1657
  return;
1693
1658
  }
1694
- img.decode().catch(e => $gVhhF$depictaiutilishared.dwarn("Failed to decode image", e, img)) // Display the image also if loading failed so webdev can debug and doesn't get "no image"
1695
- .then(async () => {
1696
- // Also wait with inserting image (i.e. paint) until browser is idle
1697
- await new Promise(r => executeWhenIdleBatched(r, false));
1698
- if (gotCleanedUp) return;
1699
- setHasDecoded(true);
1700
- hasDecodedFastPath = true;
1701
- });
1659
+ update_children_count();
1660
+ if (!(0, $gVhhF$solidjsweb.isServer)) {
1661
+ const mutation_observer = new MutationObserver($gVhhF$depictaiutilishared.catchify(update_children_count));
1662
+ mutation_observer.observe(container_element, {
1663
+ childList: true
1664
+ });
1665
+ $gVhhF$solidjs.onCleanup(() => mutation_observer.disconnect());
1666
+ }
1667
+ set_styling(
1668
+ // this is needed because solid will think that the memo-accessor is a setter function otherwise
1669
+ () => $gVhhF$solidjs.createMemo(() => {
1670
+ const {
1671
+ rows_per_click: rows_per_click,
1672
+ max_rows = -1,
1673
+ start_rows: start_rows
1674
+ } = rows_or_empty_object();
1675
+ const rows_visible = get_rows_visible();
1676
+ const children_count = get_children_count();
1677
+ return force_style_update() + col_styling() + props.cols_at_size.map(options => {
1678
+ const [recs_per_row, min, max] = options;
1679
+ let should_hide_view_more_button;
1680
+ let visible_recs;
1681
+ if (props.disable_partial_rows) {
1682
+ visible_recs = $gVhhF$depictaiutilishared.layout_get_visible_recs_without_partial_rows(rows_visible, children_count, options);
1683
+ const visible_recs_next_show_more = $gVhhF$depictaiutilishared.layout_get_visible_recs_without_partial_rows(rows_visible + (rows_per_click || 0),
1684
+ // Should this really be zero when we default rows_per_click to 1?
1685
+ children_count, options);
1686
+ should_hide_view_more_button = visible_recs === visible_recs_next_show_more;
1687
+ } else {
1688
+ visible_recs = $gVhhF$depictaiutilishared.layout_get_total_rec_amount_for_row(rows_visible, options);
1689
+ should_hide_view_more_button = visible_recs >= children_count;
1690
+ }
1691
+ const should_hide_button_final = should_hide_view_more_button || max_rows !== -1 && rows_visible >= max_rows;
1692
+ // I don't really understand the logic for when the view more button gets hidden so IDK if below is correct, but it works how it should for now
1693
+ const should_hide_view_less_button = !should_hide_view_more_button || start_rows == undefined || rows_visible <= start_rows || children_count <= recs_per_row * start_rows;
1694
+ return `${$gVhhF$depictaiutilishared.layout_media_query_header(min, max)}{${selector_beginning}:nth-child(n+${visible_recs + 1}){display:none}${props.layout == "slider" ? `${selector_beginning}:nth-child(n+${visible_recs}){margin-right:0}` : ""}${should_hide_button_final ? `.depict .${view_more_button_class}{display:none!important}` : ``}${should_hide_view_less_button ? `.depict .${view_less_button_class}{display:none!important}` : ``}}`;
1695
+ }).join("");
1696
+ }));
1702
1697
  });
1698
+ const style_element = (() => {
1699
+ var _el$4 = $gVhhF$solidjsweb.getNextElement($f48d0fbb00835aaa$var$_tmpl$2);
1700
+ $gVhhF$solidjsweb.insert(_el$4, get_styling);
1701
+ return _el$4;
1702
+ })(); // need to create this after set_styling has been called or else there will be no styling in the SSR'd output
1703
+ if (insert_after_container) container_element.after(style_element);
1704
+ return [container_element, $gVhhF$solidjsweb.memo(view_more_button_container), $gVhhF$solidjsweb.memo(view_less_button_container), style_element];
1705
+ }
1706
+ $gVhhF$solidjsweb.delegateEvents(["click"]);
1707
+ var $363ce4d1d71041aa$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<h2 class=recs-title>`);
1708
+ function $363ce4d1d71041aa$export$d41d19e89346fa2({
1709
+ recommendations_resource_: recommendations_resource_,
1710
+ product_card_template_: product_card_template_,
1711
+ layout_options_: layout_options_,
1712
+ title_: title_,
1713
+ NoResultsFallback_: NoResultsFallback_,
1714
+ placeholderCacheKey_: placeholderCacheKey_
1715
+ }) {
1716
+ const is_showing_something = $gVhhF$solidjs.createMemo(() => recommendations_resource_.loading || recommendations_resource_()?.length);
1717
+ const title = $gVhhF$solidjs.createMemo(() => title_?.()); // In case getter/accessor creates elements, don't create them twice
1718
+ const num_placeholders_ = () => 20;
1719
+ const slider = [$gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
1720
+ get when() {
1721
+ return title();
1722
+ },
1723
+ get children() {
1724
+ var _el$ = $gVhhF$solidjsweb.getNextElement($363ce4d1d71041aa$var$_tmpl$);
1725
+ $gVhhF$solidjsweb.insert(_el$, title);
1726
+ return _el$;
1727
+ }
1728
+ }), $gVhhF$solidjsweb.createComponent((0, $a0e53f99354809d9$export$6649caad96ef8870), {
1729
+ arrow_height_: 25,
1730
+ arrow_width_: 12.5,
1731
+ disable_fading_: true,
1732
+ slider_ref_: slider => {
1733
+ const {
1734
+ insert_here: insert_here,
1735
+ container: container
1736
+ } = slider;
1737
+ const Layout = props => $f48d0fbb00835aaa$export$445d8d3f5f706a40(props, insert_here, true);
1738
+ // Do like this, so we don't have to call mergeProps ourselves
1739
+ $gVhhF$solidjsweb.createComponent(Layout, $gVhhF$solidjsweb.mergeProps({
1740
+ rows: "all",
1741
+ layout: "slider"
1742
+ }, layout_options_));
1743
+ $gVhhF$depictaiutilishared.slider_fractional_factory(0, 0.75).constructor_plugin.call(slider, {}); // enable fractional scrolling
1744
+ insert_here.before($fc23d7668ae0011d$export$a2cc176055f8f08());
1745
+ container.classList.add("products");
1746
+ },
1747
+ get children() {
1748
+ return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Suspense), {
1749
+ get fallback() {
1750
+ return $0caf87eaa19079da$export$f33414a4df0afd3f({
1751
+ num_placeholders_: num_placeholders_,
1752
+ product_card_template_: product_card_template_,
1753
+ placeholderCacheKey_: placeholderCacheKey_
1754
+ });
1755
+ },
1756
+ get children() {
1757
+ return (() => {
1758
+ // IIFE to make sure we access both the recommendations_resource and the resources containing the product card rendering results themselves within the Suspense boundary
1759
+ const displays_by_key_ = $a73063cc642f3e5f$export$7f8bd308237ab5a5($gVhhF$solidjs.createMemo(() => recommendations_resource_() || []));
1760
+ const {
1761
+ renderedDisplays_: renderedDisplays_
1762
+ } = $67155e1aeb7073f6$export$4a14175d33d81a96({
1763
+ displays_by_key_: displays_by_key_,
1764
+ product_card_template_: product_card_template_
1765
+ });
1766
+ return renderedDisplays_;
1767
+ })();
1768
+ }
1769
+ });
1770
+ }
1771
+ })];
1703
1772
  return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
1704
1773
  get when() {
1705
- return hasDecoded();
1774
+ return is_showing_something();
1706
1775
  },
1707
- children: img
1776
+ get fallback() {
1777
+ return NoResultsFallback_?.();
1778
+ },
1779
+ children: slider
1708
1780
  });
1709
1781
  }
1710
- function $19950faaac026e09$var$make_srcset(url, resolutions, customGenerateImageUrl_) {
1711
- return resolutions.map(width => `${(customGenerateImageUrl_ || $19950faaac026e09$export$1d6267828870adda)(url, width)} ${width}w`).join(", ");
1712
- }
1713
- function $19950faaac026e09$export$1d6267828870adda(url, width) {
1714
- // Even just creating one `URL` object per image src and then setting the search parameter is quite slow (0.25ms to set the width param)
1715
- // We're making the assumptions that the url has already at least one query parameter and that the image resizing service will choose the last one out of a duplicate width parameter (shopify's does)
1716
- // That way we can just to string concatenation which is insanely fast
1717
- return url + "&width=" + encodeURIComponent(width);
1718
- }
1719
- const $a33065cfed827fc0$var$backupSizeSignal = /*@__PURE__*/$gVhhF$solidjs.createSignal();
1720
- const $a33065cfed827fc0$export$d7b7ab832c20e2f4 = /*@__PURE__*/Symbol("ShopifyContainedImage");
1721
- function $a33065cfed827fc0$export$e4b984597b71e989(props) {
1722
- const context = $84798aaa863a4909$export$8d0c4fdbb05a2f2e();
1723
- if (context && !context[$a33065cfed827fc0$export$d7b7ab832c20e2f4])
1724
- // create a signal that's the same for all items in this listing
1725
- context[$a33065cfed827fc0$export$d7b7ab832c20e2f4] = $gVhhF$solidjs.createSignal();
1726
- const [currentImageSize, setCurrentImageSize] = context?.[$a33065cfed827fc0$export$d7b7ab832c20e2f4] || $a33065cfed827fc0$var$backupSizeSignal; // use global fallback signal (might lead to blurry images) if no context is available
1727
- const [mostPrevalentAspectRatio] = context ?
1728
- // If the context exists we have to create the signal here as getting it here would be too late when it's created by ShopifyResponsiveImg below
1729
- context[(0, $19950faaac026e09$export$6066eb417ed2e9f7)] ||= $gVhhF$solidjs.createSignal() : [];
1730
- const container = $93304d59a9747aa6$export$94026ee33dbabc26({
1731
- // Write getters manually instead of using JSX, so we can do more complex logic in the aspectRatio getter without increasing bundle size
1732
- get class() {
1733
- return props.class;
1734
- },
1735
- get aspectRatio() {
1736
- if (props.autoAdjustAspectRatio) {
1737
- const targetRatio = mostPrevalentAspectRatio?.();
1738
- if (targetRatio != undefined) return `var(${(0, $6f604560873e4f69$export$8a2234b5b1a5ebd4)}, ${targetRatio})`;
1782
+ function $95837413165cc2df$export$23fca46f3143581f(component, error_message) {
1783
+ const component_in_error_boundary = do_with_elements => {
1784
+ const error_boundary_wrapped = $edafe91daf3091d7$export$b69d0d92862de18b({
1785
+ severity_: "error",
1786
+ message_: error_message,
1787
+ get children() {
1788
+ const elements = component();
1789
+ do_with_elements?.(elements);
1790
+ return elements;
1739
1791
  }
1740
- return props.aspectRatio;
1741
- }
1742
- });
1792
+ });
1793
+ // This might return an accessor, in that case we need to "unwrap" it since our SDK consumers expect HTML elements or arrays thereof
1794
+ if (typeof error_boundary_wrapped === "function")
1795
+ // @ts-ignore
1796
+ return error_boundary_wrapped();
1797
+ // On the server it returns a string, so we just return that
1798
+ return error_boundary_wrapped;
1799
+ };
1743
1800
  const owner = $gVhhF$solidjs.getOwner();
1744
- let createdSizeAccessor = false;
1745
- let wasCleanedUp = false;
1746
- $gVhhF$solidjs.createEffect(() => {
1747
- if (currentImageSize() || wasCleanedUp) return; // We get into the effect when onCleanup is called if we don't have wasCleanedUp
1748
- // ensure we always have a size accessor
1749
- // what this whole thing does is set the sizes attribute to the actual size of one of the existing image containers, therefore the value doesn't have to manually be specified
1750
- createdSizeAccessor = true;
1751
- setCurrentImageSize(() => $gVhhF$solidjs.runWithOwner(owner, () => $19950faaac026e09$export$e6fffe67d4cdd848(container)));
1752
- });
1753
- $gVhhF$solidjs.onCleanup(() => {
1754
- wasCleanedUp = true; // important to set this before the function call below and always, so the dead effects don't create dead size accessors
1755
- if (!createdSizeAccessor) return;
1756
- $gVhhF$depictaiutilishared.queueMacroTask(() => setCurrentImageSize()); // unset the size accessor next event loop iteration, so that all onCleanup's have time to run, since the effects run more aggressively and can create a size accessor with a cleaned up owner otherwise
1757
- });
1758
-
1759
- $gVhhF$solidjsweb.insert(container, $gVhhF$solidjsweb.createComponent((0, $19950faaac026e09$export$6e5611bc7e57e477), $gVhhF$solidjsweb.mergeProps({
1760
- get size() {
1761
- return $gVhhF$solidjs.createMemo(() => currentImageSize()?.() || 0);
1762
- },
1763
- get src() {
1764
- return props.src;
1765
- }
1766
- }, () => props.imgProps, {
1767
- get style() {
1768
- return props.imgProps?.style;
1769
- }
1770
- })));
1771
- return container;
1772
- }
1773
- function $d212a67662c5cf38$export$9d4a4b669b1929ab(props) {
1774
- return $gVhhF$solidjsweb.createComponent((0, $a33065cfed827fc0$export$e4b984597b71e989), $gVhhF$solidjsweb.mergeProps(props, {
1775
- get imgProps() {
1776
- return {
1777
- ...props.imgProps,
1778
- customUrls: (url, width // Apparently don't have to encode url for CF's service
1779
- ) => {
1780
- if (url?.startsWith?.("https://cdn.shopify.com"))
1781
- // The shopify image resizing CDN blocks Cloudflare's image resizer. It's possible that we can't detect shopify image URLs sometimes because they go to the merchant's domain,
1782
- // but it seems like the URLs returned by the Depict API always goes to the cdn.shopify.com version of an image, so this simple workaround works.
1783
- return $19950faaac026e09$export$1d6267828870adda(url, width);
1784
- // Use cloudflare image resizer instead of img.depict.ai because it's a lot faster (and also auto-chooses other formats if webp is not supported)
1785
- return `https://app.depict.ai/cdn-cgi/image/width=${width},format=auto/${url}`;
1786
- }
1787
- };
1788
- }
1789
- }));
1801
+ if (owner == null) return $gVhhF$solidjs.createRoot(dispose => {
1802
+ // if we're not already run in a root, create a root and automatically dispose it when the first returned element is removed from the DOM
1803
+ return component_in_error_boundary(elements => {
1804
+ const have_multiple = Array.isArray(elements);
1805
+ if (have_multiple ? !elements?.length : !elements) return;
1806
+ (0, $gVhhF$depictaiutilishared.observer).onremoved(have_multiple ? elements[0] : elements, ({
1807
+ element: element
1808
+ }) => {
1809
+ if (document.documentElement.contains(element)) return; // If element has instantly been re-inserted, don't dispose
1810
+ // See https://depictaiworkspace.slack.com/archives/C050GHEPBTR/p1695809102791259?thread_ts=1695106805.459729&cid=C050GHEPBTR
1811
+ dispose();
1812
+ });
1813
+ });
1814
+ });else
1815
+ // we're already in a root so cleanups are handled
1816
+ return component_in_error_boundary();
1790
1817
  }
1791
1818
  function $d659702496cb72ea$export$a71e92cfbb498adc(props) {
1792
1819
  return $gVhhF$solidjs.createMemo(() => {
@@ -14907,7 +14934,7 @@ function $32c662f618f5d80d$export$780a853d15174484({
14907
14934
  return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjsweb.Dynamic), $gVhhF$solidjsweb.mergeProps({
14908
14935
  component: link ? "a" : "div",
14909
14936
  "class": "d-standard-content-wrapper",
14910
- ref: el => setWrapperSize(() => $19950faaac026e09$export$e6fffe67d4cdd848(el)),
14937
+ ref: el => setWrapperSize(() => $128302ab61dab8f1$export$54c6d6ff54e72743(el)),
14911
14938
  get onClick() {
14912
14939
  return $gVhhF$depictaiutilisharedlatest.catchify(ev => link && router_.navigate_.go_to_({
14913
14940
  new_url_: link,
@@ -14919,10 +14946,9 @@ function $32c662f618f5d80d$export$780a853d15174484({
14919
14946
  href: link
14920
14947
  }, {
14921
14948
  get children() {
14922
- return $gVhhF$solidjsweb.createComponent((0, $19950faaac026e09$export$6e5611bc7e57e477), {
14923
- get size() {
14924
- return $gVhhF$solidjs.createMemo(() => wrapperSize()?.() || 0);
14925
- },
14949
+ return $gVhhF$solidjsweb.createComponent((0, $d212a67662c5cf38$export$140423fa4bfb6d63), {
14950
+ size: () => wrapperSize()?.[0]?.() || 0,
14951
+ sizeHeight: () => wrapperSize()?.[1]?.() || 0,
14926
14952
  src: mediaUrl,
14927
14953
  "class": "d-standard-content"
14928
14954
  });