@depict-ai/ui 2.1.3 → 2.1.5

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
@@ -70,7 +70,7 @@ $parcel$export(module.exports, "defaultColsAtSize", () => $a3280f0aad997933$expo
70
70
  $parcel$export(module.exports, "defaultCategoryTitlePlugin", () => $a3280f0aad997933$export$7bf543b9d9be2c22);
71
71
  $parcel$export(module.exports, "version", () => $b757f75811f3261f$export$83d89fbfd8236492);
72
72
  /*! Depict.ai search and product listing SDK */
73
- const $b757f75811f3261f$export$83d89fbfd8236492 = "2.1.3";
73
+ const $b757f75811f3261f$export$83d89fbfd8236492 = "2.1.5";
74
74
  const $1ab22f2cd39b3061$var$fallback_operator = "in";
75
75
  const $1ab22f2cd39b3061$var$fallback_token = "";
76
76
  const $1ab22f2cd39b3061$var$legacy_filter_prefix = "filter_";
@@ -265,7 +265,6 @@ function $93304d59a9747aa6$export$94026ee33dbabc26(props) {
265
265
  return _el$;
266
266
  })();
267
267
  }
268
- const $19950faaac026e09$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<img>`);
269
268
  function $19950faaac026e09$export$e6fffe67d4cdd848(whatToWatch) {
270
269
  const [size, setSize] = $gVhhF$solidjs.createSignal(0);
271
270
  const resizeObserver = new ResizeObserver($gVhhF$depictaiutilishared.catchify(records => {
@@ -290,6 +289,7 @@ function $19950faaac026e09$export$e6fffe67d4cdd848(whatToWatch) {
290
289
  });
291
290
  return size;
292
291
  }
292
+ const $19950faaac026e09$var$onIdleFunctionsSymbol = /*@__PURE__*/Symbol("onIdleFunctions");
293
293
  function $19950faaac026e09$export$6e5611bc7e57e477(props) {
294
294
  // Enable reactive props
295
295
  const otherOptions = $gVhhF$solidjs.createMemo(() => {
@@ -312,16 +312,91 @@ function $19950faaac026e09$export$6e5611bc7e57e477(props) {
312
312
  srcset: srcset
313
313
  };
314
314
  });
315
- return (() => {
316
- const _el$ = $gVhhF$solidjsweb.getNextElement($19950faaac026e09$var$_tmpl$);
317
- $gVhhF$solidjsweb.spread(_el$, $gVhhF$solidjsweb.mergeProps(otherOptions, src_options, {
318
- get sizes() {
319
- return props.size() + "px";
315
+ // Work around https://github.com/solidjs/solid/issues/1828
316
+ const img = new Image(); // Need to use new Image or browser might not start loading image before it's in the DOM
317
+ const [hasSetSize, setHasSetSize] = $gVhhF$solidjs.createSignal(false);
318
+ const [hasDecoded, setHasDecoded] = $gVhhF$solidjs.createSignal(false);
319
+ 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
320
+ const listingContext = $84798aaa863a4909$export$8d0c4fdbb05a2f2e();
321
+ // 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
322
+ // Happened on singular, they have some weird observer (+we also have one but ours is at least 3x more efficient)
323
+ const executeWhenIdleBatched = fn => {
324
+ if (typeof requestIdleCallback !== "function") setTimeout(fn); // Old browsers don't get optimisation
325
+ const existingStack = listingContext?.[$19950faaac026e09$var$onIdleFunctionsSymbol];
326
+ if (existingStack) return existingStack.add(fn);
327
+ const newStack = new Set([fn]);
328
+ if (listingContext) listingContext[$19950faaac026e09$var$onIdleFunctionsSymbol] = newStack;
329
+ const processStackWhenIdle = () => requestIdleCallback(deadline => {
330
+ const start = performance.now();
331
+ const thirdDeadlineTime = deadline.timeRemaining() / 3; // observers coming after this take up 2-3x the time so don't use all of it
332
+ for (const fn of newStack) {
333
+ newStack.delete(fn);
334
+ fn();
335
+ const timeTaken = performance.now() - start;
336
+ if ((!deadline.timeRemaining() || timeTaken > thirdDeadlineTime) && newStack.size) {
337
+ // There's still work to be done but no time, so schedule another idle callback
338
+ processStackWhenIdle();
339
+ return;
340
+ }
320
341
  }
321
- }), false, false);
322
- $gVhhF$solidjsweb.runHydrationEvents();
323
- return _el$;
324
- })();
342
+ // Stack is empty
343
+ if (listingContext) delete listingContext[$19950faaac026e09$var$onIdleFunctionsSymbol];
344
+ }, {
345
+ timeout: 15000
346
+ } // 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
347
+ );
348
+
349
+ processStackWhenIdle();
350
+ };
351
+ let sizeSetFastPath = false;
352
+ let hasDecodedFastPath = false;
353
+ let timeoutSet = false;
354
+ $gVhhF$solidjsweb.spread(img, $gVhhF$solidjs.mergeProps(otherOptions), false, true);
355
+ $gVhhF$solidjs.createEffect(() => {
356
+ if (!props.size()) return; // wait until we have a size
357
+ if (timeoutSet) return;
358
+ const handler = $gVhhF$depictaiutilishared.catchify(() => {
359
+ img.sizes = sizePX(); // use latest available value of props.size
360
+ if (!sizeSetFastPath) {
361
+ setHasSetSize(true);
362
+ sizeSetFastPath = true;
363
+ }
364
+ timeoutSet = false;
365
+ });
366
+ // Throttle the updating of sizes to avoid unnecessary image re-fetches during resize
367
+ // And also because we first set src after sizes has been set, wait with loading and decoding images until browser is idle
368
+ // This greatly improves performance when loading (more) products
369
+ // See https://depictaiworkspace.slack.com/archives/C05NJ0K3WRL/p1698220617663139
370
+ executeWhenIdleBatched(handler);
371
+ timeoutSet = true;
372
+ });
373
+ $gVhhF$solidjs.createEffect(() => {
374
+ if (!props.size() || !hasSetSize()) return; // If size isn't known or set, don't assign src yet since it would cause the most low res image to load
375
+ Object.assign(img, src_options());
376
+ // Add to DOM once decoded to not require/block any paints before image has completed loading and avoid showing broken image symbol
377
+ // We can do this because there has to be a container around us giving us a size
378
+ // No need to listen if we're already in the DOM
379
+ if (hasDecodedFastPath) return;
380
+ if (props.loading === "lazy") {
381
+ // For lazy loading there's no decoding to wait for as it only occurs when the image is visible
382
+ // Make sure src is set before we put the image into the DOM though so no broken image symbol is shown
383
+ setHasDecoded(true);
384
+ hasDecodedFastPath = true;
385
+ }
386
+ 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"
387
+ .then(async () => {
388
+ // Also wait with inserting image (i.e. paint) until browser is idle
389
+ await new Promise(r => executeWhenIdleBatched(r));
390
+ setHasDecoded(true);
391
+ hasDecodedFastPath = true;
392
+ });
393
+ });
394
+ return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
395
+ get when() {
396
+ return hasDecoded();
397
+ },
398
+ children: img
399
+ });
325
400
  }
326
401
  function $19950faaac026e09$var$make_srcset(url, resolutions) {
327
402
  return resolutions.map(width => `${$19950faaac026e09$var$generateImageUrl(url, width)} ${width}w`).join(", ");
@@ -359,7 +434,7 @@ function $a33065cfed827fc0$export$e4b984597b71e989(props) {
359
434
  $gVhhF$depictaiutilishared.queueMacroTask(() => setCurrentImageSize(undefined)); // 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
360
435
  });
361
436
 
362
- container.append($gVhhF$solidjsweb.createComponent((0, $19950faaac026e09$export$6e5611bc7e57e477), {
437
+ $gVhhF$solidjsweb.insert(container, $gVhhF$solidjsweb.createComponent((0, $19950faaac026e09$export$6e5611bc7e57e477), {
363
438
  style: "width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0;",
364
439
  get size() {
365
440
  return $gVhhF$solidjs.createMemo(() => currentImageSize()?.() || 0);
@@ -4920,6 +4995,9 @@ function $d92f338ba8f9da9b$var$remap_blocks_to_index({
4920
4995
  const cols_showing = n_cols_currently_showing_();
4921
4996
  // Need to keep track of products displaced by blocks above when mapping rows to indexes in the actual grid
4922
4997
  const displaced_products = []; // undefined = is product, true = is content block if number instead of tuple number indicates content blocks in that row. Index in first array is row, index in second array is column
4998
+ if (!cols_showing)
4999
+ // Nope out of here if we don't know how many columns are showing
5000
+ return content_blocks_by_index;
4923
5001
  for (let i = 0; i < wrapped_blocks.length; i++) {
4924
5002
  // i = row to show at
4925
5003
  const block = wrapped_blocks[i];
@@ -4980,7 +5058,9 @@ function $d92f338ba8f9da9b$var$remap_blocks_to_index({
4980
5058
  function $d92f338ba8f9da9b$var$wrap_blocks_in_div(rendered_content_blocks, max_span_columns) {
4981
5059
  const get_wrapped_blocks = $gVhhF$solidjs.mapArray(() => rendered_content_blocks, block => {
4982
5060
  if (!block) return;
4983
- const get_span_columns = () => Math.min(block.span_columns, max_span_columns() ?? Infinity);
5061
+ const final_span_columns = $gVhhF$solidjs.createMemo(() => Math.min(block.span_columns, max_span_columns() ?? Infinity));
5062
+ // If the item spans an entire row, limit the height to 1 row since there's no concept of "rows" if there are no products beside the block
5063
+ const final_span_rows = $gVhhF$solidjs.createMemo(() => final_span_columns() === max_span_columns() ? 1 : block.span_rows);
4984
5064
  const [rendering_delayed, set_rendering_delayed_] = $gVhhF$solidjs.createSignal(true);
4985
5065
  const content = $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
4986
5066
  get when() {
@@ -4995,10 +5075,10 @@ function $d92f338ba8f9da9b$var$wrap_blocks_in_div(rendered_content_blocks, max_s
4995
5075
  }));
4996
5076
  $gVhhF$solidjsweb.effect(_p$ => {
4997
5077
  const _v$ = {
4998
- [(0, $75777da1687ba3f6$export$c500183c31c2b22e)]: get_span_columns()
5078
+ [(0, $75777da1687ba3f6$export$c500183c31c2b22e)]: final_span_columns()
4999
5079
  },
5000
- _v$2 = `span ${get_span_columns()}`,
5001
- _v$3 = `span ${block.span_rows}`;
5080
+ _v$2 = `span ${final_span_columns()}`,
5081
+ _v$3 = `span ${final_span_rows()}`;
5002
5082
  _p$._v$ = $gVhhF$solidjsweb.style(_el$, _v$, _p$._v$);
5003
5083
  _v$2 !== _p$._v$2 && ((_p$._v$2 = _v$2) != null ? _el$.style.setProperty("grid-column", _v$2) : _el$.style.removeProperty("grid-column"));
5004
5084
  _v$3 !== _p$._v$3 && ((_p$._v$3 = _v$3) != null ? _el$.style.setProperty("grid-row", _v$3) : _el$.style.removeProperty("grid-row"));
@@ -5021,7 +5101,10 @@ function $d92f338ba8f9da9b$var$wrap_blocks_in_div(rendered_content_blocks, max_s
5021
5101
  },
5022
5102
  get span_columns() {
5023
5103
  // Cap max width of block to the number of columns available, for everyone downstream
5024
- return get_span_columns();
5104
+ return final_span_columns();
5105
+ },
5106
+ get span_rows() {
5107
+ return final_span_rows();
5025
5108
  }
5026
5109
  });
5027
5110
  });
package/latest/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { CategorySuggestion, SearchSuggestionsResponse } from "@depict-ai/types/
7
7
  import { BaseSearchRequest } from "@depict-ai/types/api/BaseSearchRequest";
8
8
  import { SearchSuggestionsRequest } from "@depict-ai/types/api/SearchSuggestionsRequest";
9
9
  import { ProductListingRequestV2 } from "@depict-ai/types/api/ProductListingRequestV2";
10
- export const version = "2.1.3";
10
+ export const version = "2.1.5";
11
11
  /**
12
12
  * Use `javascript_media_query` but return a reactive accessor instead of taking a callback function
13
13
  */
@@ -152,17 +152,19 @@ export function ImageContainer(props: {
152
152
  export function makeSizeAccessor(whatToWatch: HTMLElement): Accessor<number>;
153
153
  /**
154
154
  * Automatically generate a srcset from the shopify CDN for an image and set the sizes attribute to the provided accessor.
155
+ * Will also delay loading and decoding of image until the browser is idle (with 5s timeout) to improve filtering/loading more performance.
155
156
  * This is used for our responsive images:
156
157
  * 1. The image must have a container with a fixed size (or aspect ratio) that is independent of the image. When aspectRatio is configured on the depict-cards element as data attribute, we will wrap the image in a ImageContainer for this. If it's false, the user has to provide this container themselves.
157
158
  * 2. We set a ResizeObserver on one of the currently visible images (see makeSizeAccessor)
158
159
  * 3. We set the size attribute of all the visible images to the size of the container we're observing. The point of this is that the sizes attribute is used to determine which image to load, and usually it's set by the user and depends on the relationship between image size and viewport size. By using a ResizeObserver, we can make sure the sizes attribute is always set to the correct value without it having to be configured. This will make so the browser always loads the correct image size for a crisp image but still fast load.
160
+ * You need to use insert(domNode, <ShopifyResponsiveImg size={sizeAccessor} src={src} />) if you want to insert the return value of this component into a DOM element manually, where you `import { insert } from "solid-js/web";` because we first want to insert the image once it has loaded.
159
161
  */
160
162
  export function ShopifyResponsiveImg(props: {
161
163
  resolutions?: number[];
162
164
  size: Accessor<number>;
163
165
  } & Omit<JSX.ImgHTMLAttributes<HTMLImageElement>, "srcset" | "src" | "sizes"> & {
164
166
  src: string;
165
- }): HTMLImageElement;
167
+ }): JSX.Element;
166
168
  export const shopifyContainedImageContextSymbol: unique symbol;
167
169
  /**
168
170
  * Abstraction built on top of ShopifyResponsiveImg. This is your one-stop-shop If you just need a responsive image.
package/latest/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { add_to_version_info as $9HbP8$add_to_version_info, base64_encode_unicode as $9HbP8$base64_encode_unicode, base64_decode_unicode as $9HbP8$base64_decode_unicode, dlog as $9HbP8$dlog, queueMacroTask as $9HbP8$queueMacroTask, catchify as $9HbP8$catchify, is_safari as $9HbP8$is_safari, observer as $9HbP8$observer, Amazing_Slider as $9HbP8$Amazing_Slider, slider_snap_css as $9HbP8$slider_snap_css, slider_fading_factory as $9HbP8$slider_fading_factory, slider_fractional_factory as $9HbP8$slider_fractional_factory, camelCasifyObject as $9HbP8$camelCasifyObject, make_random_classname as $9HbP8$make_random_classname, n_col_styling_with_dist as $9HbP8$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $9HbP8$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $9HbP8$layout_get_total_rec_amount_for_row, layout_media_query_header as $9HbP8$layout_media_query_header, report as $9HbP8$report, useExpandingContainer as $9HbP8$useExpandingContainer, standard_price_format as $9HbP8$standard_price_format, hex_to_rgb as $9HbP8$hex_to_rgb, relative_luminance_from_rgb as $9HbP8$relative_luminance_from_rgb, fetch_recs as $9HbP8$fetch_recs, snakeCasifyObject as $9HbP8$snakeCasifyObject, instant_exec_on_suspect_history_change as $9HbP8$instant_exec_on_suspect_history_change, base_url as $9HbP8$base_url, get_depict_id as $9HbP8$get_depict_id, get_user_id as $9HbP8$get_user_id, get_session_id as $9HbP8$get_session_id, sort_obj as $9HbP8$sort_obj, fetch_retry as $9HbP8$fetch_retry, add_version_query_params as $9HbP8$add_version_query_params, dwarn as $9HbP8$dwarn, make_url_with_query_params as $9HbP8$make_url_with_query_params, edit_current_page_meta_tags as $9HbP8$edit_current_page_meta_tags, javascript_media_query as $9HbP8$javascript_media_query, use_href_accessor as $9HbP8$use_href_accessor, is_debug as $9HbP8$is_debug, make_asyncIterable_exiter as $9HbP8$make_asyncIterable_exiter, href_change_ipns as $9HbP8$href_change_ipns, ContainedImage as $9HbP8$ContainedImage, buildThresholdList as $9HbP8$buildThresholdList, deparallelize_no_drop as $9HbP8$deparallelize_no_drop, ListenableSet as $9HbP8$ListenableSet, insert_surfaces as $9HbP8$insert_surfaces } from "@depict-ai/utilishared/latest";
2
- import { createComponent as $9HbP8$createComponent, template as $9HbP8$template, getNextElement as $9HbP8$getNextElement, effect as $9HbP8$effect, style as $9HbP8$style, spread as $9HbP8$spread, mergeProps as $9HbP8$mergeProps, runHydrationEvents as $9HbP8$runHydrationEvents, insert as $9HbP8$insert, setAttribute as $9HbP8$setAttribute, isServer as $9HbP8$isServer, addEventListener as $9HbP8$addEventListener, className as $9HbP8$className, memo as $9HbP8$memo, delegateEvents as $9HbP8$delegateEvents, classList as $9HbP8$classList, getNextMarker as $9HbP8$getNextMarker, Dynamic as $9HbP8$Dynamic, use as $9HbP8$use, setProperty as $9HbP8$setProperty } from "solid-js/web";
3
- import { createSignal as $9HbP8$createSignal, getOwner as $9HbP8$getOwner, createEffect as $9HbP8$createEffect, runWithOwner as $9HbP8$runWithOwner, onCleanup as $9HbP8$onCleanup, createMemo as $9HbP8$createMemo, createContext as $9HbP8$createContext, useContext as $9HbP8$useContext, createResource as $9HbP8$createResource, Suspense as $9HbP8$Suspense, Show as $9HbP8$Show, untrack as $9HbP8$untrack, createRenderEffect as $9HbP8$createRenderEffect, Index as $9HbP8$Index, createRoot as $9HbP8$createRoot, For as $9HbP8$For, createUniqueId as $9HbP8$createUniqueId, createComputed as $9HbP8$createComputed, ErrorBoundary as $9HbP8$ErrorBoundary, on as $9HbP8$on, batch as $9HbP8$batch, createReaction as $9HbP8$createReaction, mapArray as $9HbP8$mapArray, mergeProps as $9HbP8$mergeProps1 } from "solid-js";
1
+ import { add_to_version_info as $9HbP8$add_to_version_info, base64_encode_unicode as $9HbP8$base64_encode_unicode, base64_decode_unicode as $9HbP8$base64_decode_unicode, dlog as $9HbP8$dlog, queueMacroTask as $9HbP8$queueMacroTask, catchify as $9HbP8$catchify, is_safari as $9HbP8$is_safari, observer as $9HbP8$observer, dwarn as $9HbP8$dwarn, Amazing_Slider as $9HbP8$Amazing_Slider, slider_snap_css as $9HbP8$slider_snap_css, slider_fading_factory as $9HbP8$slider_fading_factory, slider_fractional_factory as $9HbP8$slider_fractional_factory, camelCasifyObject as $9HbP8$camelCasifyObject, make_random_classname as $9HbP8$make_random_classname, n_col_styling_with_dist as $9HbP8$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $9HbP8$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $9HbP8$layout_get_total_rec_amount_for_row, layout_media_query_header as $9HbP8$layout_media_query_header, report as $9HbP8$report, useExpandingContainer as $9HbP8$useExpandingContainer, standard_price_format as $9HbP8$standard_price_format, hex_to_rgb as $9HbP8$hex_to_rgb, relative_luminance_from_rgb as $9HbP8$relative_luminance_from_rgb, fetch_recs as $9HbP8$fetch_recs, snakeCasifyObject as $9HbP8$snakeCasifyObject, instant_exec_on_suspect_history_change as $9HbP8$instant_exec_on_suspect_history_change, base_url as $9HbP8$base_url, get_depict_id as $9HbP8$get_depict_id, get_user_id as $9HbP8$get_user_id, get_session_id as $9HbP8$get_session_id, sort_obj as $9HbP8$sort_obj, fetch_retry as $9HbP8$fetch_retry, add_version_query_params as $9HbP8$add_version_query_params, make_url_with_query_params as $9HbP8$make_url_with_query_params, edit_current_page_meta_tags as $9HbP8$edit_current_page_meta_tags, javascript_media_query as $9HbP8$javascript_media_query, use_href_accessor as $9HbP8$use_href_accessor, is_debug as $9HbP8$is_debug, make_asyncIterable_exiter as $9HbP8$make_asyncIterable_exiter, href_change_ipns as $9HbP8$href_change_ipns, ContainedImage as $9HbP8$ContainedImage, buildThresholdList as $9HbP8$buildThresholdList, deparallelize_no_drop as $9HbP8$deparallelize_no_drop, ListenableSet as $9HbP8$ListenableSet, insert_surfaces as $9HbP8$insert_surfaces } from "@depict-ai/utilishared/latest";
2
+ import { createComponent as $9HbP8$createComponent, insert as $9HbP8$insert, template as $9HbP8$template, getNextElement as $9HbP8$getNextElement, effect as $9HbP8$effect, style as $9HbP8$style, spread as $9HbP8$spread, setAttribute as $9HbP8$setAttribute, mergeProps as $9HbP8$mergeProps1, isServer as $9HbP8$isServer, runHydrationEvents as $9HbP8$runHydrationEvents, addEventListener as $9HbP8$addEventListener, className as $9HbP8$className, memo as $9HbP8$memo, delegateEvents as $9HbP8$delegateEvents, classList as $9HbP8$classList, getNextMarker as $9HbP8$getNextMarker, Dynamic as $9HbP8$Dynamic, use as $9HbP8$use, setProperty as $9HbP8$setProperty } from "solid-js/web";
3
+ import { createSignal as $9HbP8$createSignal, getOwner as $9HbP8$getOwner, createEffect as $9HbP8$createEffect, runWithOwner as $9HbP8$runWithOwner, onCleanup as $9HbP8$onCleanup, createMemo as $9HbP8$createMemo, createContext as $9HbP8$createContext, useContext as $9HbP8$useContext, mergeProps as $9HbP8$mergeProps, Show as $9HbP8$Show, createResource as $9HbP8$createResource, Suspense as $9HbP8$Suspense, untrack as $9HbP8$untrack, createRenderEffect as $9HbP8$createRenderEffect, Index as $9HbP8$Index, createRoot as $9HbP8$createRoot, For as $9HbP8$For, createUniqueId as $9HbP8$createUniqueId, createComputed as $9HbP8$createComputed, ErrorBoundary as $9HbP8$ErrorBoundary, on as $9HbP8$on, batch as $9HbP8$batch, createReaction as $9HbP8$createReaction, mapArray as $9HbP8$mapArray } from "solid-js";
4
4
  import { createStore as $9HbP8$createStore, reconcile as $9HbP8$reconcile } from "solid-js/store";
5
5
 
6
6
  /*! Depict.ai search and product listing SDK */
7
7
  import { register_es_version } from "../multi_import_deduplicator.mjs";
8
8
  register_es_version("ui", "latest");
9
- const $ec291e0010116877$export$83d89fbfd8236492 = "2.1.3";
9
+ const $ec291e0010116877$export$83d89fbfd8236492 = "2.1.5";
10
10
  const $4147651646da990a$var$fallback_operator = "in";
11
11
  const $4147651646da990a$var$fallback_token = "";
12
12
  const $4147651646da990a$var$legacy_filter_prefix = "filter_";
@@ -201,7 +201,6 @@ function $f18d425032111270$export$94026ee33dbabc26(props) {
201
201
  return _el$;
202
202
  })();
203
203
  }
204
- const $e8ffe11ed01df0fe$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<img>`);
205
204
  function $e8ffe11ed01df0fe$export$e6fffe67d4cdd848(whatToWatch) {
206
205
  const [size, setSize] = $9HbP8$createSignal(0);
207
206
  const resizeObserver = new ResizeObserver($9HbP8$catchify(records => {
@@ -226,6 +225,7 @@ function $e8ffe11ed01df0fe$export$e6fffe67d4cdd848(whatToWatch) {
226
225
  });
227
226
  return size;
228
227
  }
228
+ const $e8ffe11ed01df0fe$var$onIdleFunctionsSymbol = /*@__PURE__*/Symbol("onIdleFunctions");
229
229
  function $e8ffe11ed01df0fe$export$6e5611bc7e57e477(props) {
230
230
  // Enable reactive props
231
231
  const otherOptions = $9HbP8$createMemo(() => {
@@ -248,16 +248,91 @@ function $e8ffe11ed01df0fe$export$6e5611bc7e57e477(props) {
248
248
  srcset: srcset
249
249
  };
250
250
  });
251
- return (() => {
252
- const _el$ = $9HbP8$getNextElement($e8ffe11ed01df0fe$var$_tmpl$);
253
- $9HbP8$spread(_el$, $9HbP8$mergeProps(otherOptions, src_options, {
254
- get sizes() {
255
- return props.size() + "px";
251
+ // Work around https://github.com/solidjs/solid/issues/1828
252
+ const img = new Image(); // Need to use new Image or browser might not start loading image before it's in the DOM
253
+ const [hasSetSize, setHasSetSize] = $9HbP8$createSignal(false);
254
+ const [hasDecoded, setHasDecoded] = $9HbP8$createSignal(false);
255
+ const sizePX = $9HbP8$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
256
+ const listingContext = $011607bdf658f807$export$8d0c4fdbb05a2f2e();
257
+ // 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
258
+ // Happened on singular, they have some weird observer (+we also have one but ours is at least 3x more efficient)
259
+ const executeWhenIdleBatched = fn => {
260
+ if (typeof requestIdleCallback !== "function") setTimeout(fn); // Old browsers don't get optimisation
261
+ const existingStack = listingContext?.[$e8ffe11ed01df0fe$var$onIdleFunctionsSymbol];
262
+ if (existingStack) return existingStack.add(fn);
263
+ const newStack = new Set([fn]);
264
+ if (listingContext) listingContext[$e8ffe11ed01df0fe$var$onIdleFunctionsSymbol] = newStack;
265
+ const processStackWhenIdle = () => requestIdleCallback(deadline => {
266
+ const start = performance.now();
267
+ const thirdDeadlineTime = deadline.timeRemaining() / 3; // observers coming after this take up 2-3x the time so don't use all of it
268
+ for (const fn of newStack) {
269
+ newStack.delete(fn);
270
+ fn();
271
+ const timeTaken = performance.now() - start;
272
+ if ((!deadline.timeRemaining() || timeTaken > thirdDeadlineTime) && newStack.size) {
273
+ // There's still work to be done but no time, so schedule another idle callback
274
+ processStackWhenIdle();
275
+ return;
276
+ }
256
277
  }
257
- }), false, false);
258
- $9HbP8$runHydrationEvents();
259
- return _el$;
260
- })();
278
+ // Stack is empty
279
+ if (listingContext) delete listingContext[$e8ffe11ed01df0fe$var$onIdleFunctionsSymbol];
280
+ }, {
281
+ timeout: 15000
282
+ } // 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
283
+ );
284
+
285
+ processStackWhenIdle();
286
+ };
287
+ let sizeSetFastPath = false;
288
+ let hasDecodedFastPath = false;
289
+ let timeoutSet = false;
290
+ $9HbP8$spread(img, $9HbP8$mergeProps(otherOptions), false, true);
291
+ $9HbP8$createEffect(() => {
292
+ if (!props.size()) return; // wait until we have a size
293
+ if (timeoutSet) return;
294
+ const handler = $9HbP8$catchify(() => {
295
+ img.sizes = sizePX(); // use latest available value of props.size
296
+ if (!sizeSetFastPath) {
297
+ setHasSetSize(true);
298
+ sizeSetFastPath = true;
299
+ }
300
+ timeoutSet = false;
301
+ });
302
+ // Throttle the updating of sizes to avoid unnecessary image re-fetches during resize
303
+ // And also because we first set src after sizes has been set, wait with loading and decoding images until browser is idle
304
+ // This greatly improves performance when loading (more) products
305
+ // See https://depictaiworkspace.slack.com/archives/C05NJ0K3WRL/p1698220617663139
306
+ executeWhenIdleBatched(handler);
307
+ timeoutSet = true;
308
+ });
309
+ $9HbP8$createEffect(() => {
310
+ if (!props.size() || !hasSetSize()) return; // If size isn't known or set, don't assign src yet since it would cause the most low res image to load
311
+ Object.assign(img, src_options());
312
+ // Add to DOM once decoded to not require/block any paints before image has completed loading and avoid showing broken image symbol
313
+ // We can do this because there has to be a container around us giving us a size
314
+ // No need to listen if we're already in the DOM
315
+ if (hasDecodedFastPath) return;
316
+ if (props.loading === "lazy") {
317
+ // For lazy loading there's no decoding to wait for as it only occurs when the image is visible
318
+ // Make sure src is set before we put the image into the DOM though so no broken image symbol is shown
319
+ setHasDecoded(true);
320
+ hasDecodedFastPath = true;
321
+ }
322
+ img.decode().catch(e => $9HbP8$dwarn("Failed to decode image", e, img)) // Display the image also if loading failed so webdev can debug and doesn't get "no image"
323
+ .then(async () => {
324
+ // Also wait with inserting image (i.e. paint) until browser is idle
325
+ await new Promise(r => executeWhenIdleBatched(r));
326
+ setHasDecoded(true);
327
+ hasDecodedFastPath = true;
328
+ });
329
+ });
330
+ return $9HbP8$createComponent((0, $9HbP8$Show), {
331
+ get when() {
332
+ return hasDecoded();
333
+ },
334
+ children: img
335
+ });
261
336
  }
262
337
  function $e8ffe11ed01df0fe$var$make_srcset(url, resolutions) {
263
338
  return resolutions.map(width => `${$e8ffe11ed01df0fe$var$generateImageUrl(url, width)} ${width}w`).join(", ");
@@ -295,7 +370,7 @@ function $660070e2a394b3c3$export$e4b984597b71e989(props) {
295
370
  $9HbP8$queueMacroTask(() => setCurrentImageSize(undefined)); // 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
296
371
  });
297
372
 
298
- container.append($9HbP8$createComponent((0, $e8ffe11ed01df0fe$export$6e5611bc7e57e477), {
373
+ $9HbP8$insert(container, $9HbP8$createComponent((0, $e8ffe11ed01df0fe$export$6e5611bc7e57e477), {
299
374
  style: "width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0;",
300
375
  get size() {
301
376
  return $9HbP8$createMemo(() => currentImageSize()?.() || 0);
@@ -698,7 +773,7 @@ function $c8d5ff4524619fcd$export$d21e32dfedac04be(props) {
698
773
  const container_class = "x" + $9HbP8$createUniqueId();
699
774
  const container_element_ = (() => {
700
775
  const _el$ = $9HbP8$getNextElement($c8d5ff4524619fcd$var$_tmpl$);
701
- $9HbP8$spread(_el$, $9HbP8$mergeProps(() => props.element_attributes, {
776
+ $9HbP8$spread(_el$, $9HbP8$mergeProps1(() => props.element_attributes, {
702
777
  "classList": {
703
778
  [container_class]: true
704
779
  }
@@ -846,7 +921,7 @@ function $c4492d24952ed731$export$d41d19e89346fa2({
846
921
  } = slider;
847
922
  const Layout = props => $c8d5ff4524619fcd$export$445d8d3f5f706a40(props, insert_here, true);
848
923
  // Do like this, so we don't have to call mergeProps ourselves
849
- $9HbP8$createComponent(Layout, $9HbP8$mergeProps({
924
+ $9HbP8$createComponent(Layout, $9HbP8$mergeProps1({
850
925
  rows: "all",
851
926
  layout: "slider"
852
927
  }, layout_options_));
@@ -972,7 +1047,7 @@ function $3da8afe3ed57cf34$export$7da560f849543dff({
972
1047
  _el$4 = _el$3.nextSibling,
973
1048
  [_el$5, _co$2] = $9HbP8$getNextMarker(_el$4.nextSibling);
974
1049
  $9HbP8$insert(_el$, (0, $a458486f22b22f63$export$a2cc176055f8f08), _el$3, _co$);
975
- $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
1050
+ $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps1({
976
1051
  get rows() {
977
1052
  return rows_object_();
978
1053
  },
@@ -1369,7 +1444,7 @@ const $19976a74d273070d$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<svg><path d=
1369
1444
  function $19976a74d273070d$export$3b621d86b1566b2(props = {}) {
1370
1445
  return (() => {
1371
1446
  const _el$ = $9HbP8$getNextElement($19976a74d273070d$var$_tmpl$);
1372
- $9HbP8$spread(_el$, $9HbP8$mergeProps(props, {
1447
+ $9HbP8$spread(_el$, $9HbP8$mergeProps1(props, {
1373
1448
  "xmlns": "http://www.w3.org/2000/svg",
1374
1449
  "width": "21.064",
1375
1450
  "height": "21.047",
@@ -1750,7 +1825,7 @@ const $f8a56ba74eedd0c6$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<svg><path d=
1750
1825
  function $f8a56ba74eedd0c6$export$f21ab0717a89c77f(props) {
1751
1826
  return (() => {
1752
1827
  const _el$ = $9HbP8$getNextElement($f8a56ba74eedd0c6$var$_tmpl$);
1753
- $9HbP8$spread(_el$, $9HbP8$mergeProps(props, {
1828
+ $9HbP8$spread(_el$, $9HbP8$mergeProps1(props, {
1754
1829
  "xmlns": "http://www.w3.org/2000/svg",
1755
1830
  "width": "11",
1756
1831
  "height": "12"
@@ -2883,7 +2958,7 @@ const $93716a9ad0dea854$export$414f6a19d38e655c = ({
2883
2958
  [_el$6, _co$] = $9HbP8$getNextMarker(_el$5.nextSibling),
2884
2959
  _el$7 = _el$6.nextSibling,
2885
2960
  [_el$8, _co$2] = $9HbP8$getNextMarker(_el$7.nextSibling);
2886
- $9HbP8$spread(_el$2, $9HbP8$mergeProps(attributes, {
2961
+ $9HbP8$spread(_el$2, $9HbP8$mergeProps1(attributes, {
2887
2962
  get disabled() {
2888
2963
  return $9HbP8$memo(() => value().count_ === 0)() && !is_selected();
2889
2964
  },
@@ -4646,7 +4721,7 @@ function $6dee9211e57ac31a$export$ab6b147eec64fea5(props) {
4646
4721
  const container_class = "x" + $9HbP8$createUniqueId();
4647
4722
  const container_element_ = (() => {
4648
4723
  const _el$ = $9HbP8$getNextElement($6dee9211e57ac31a$var$_tmpl$);
4649
- $9HbP8$spread(_el$, $9HbP8$mergeProps(() => props.element_attributes, {
4724
+ $9HbP8$spread(_el$, $9HbP8$mergeProps1(() => props.element_attributes, {
4650
4725
  "classList": {
4651
4726
  [container_class]: true
4652
4727
  }
@@ -4856,6 +4931,9 @@ function $e7a7eb102ddc0c79$var$remap_blocks_to_index({
4856
4931
  const cols_showing = n_cols_currently_showing_();
4857
4932
  // Need to keep track of products displaced by blocks above when mapping rows to indexes in the actual grid
4858
4933
  const displaced_products = []; // undefined = is product, true = is content block if number instead of tuple number indicates content blocks in that row. Index in first array is row, index in second array is column
4934
+ if (!cols_showing)
4935
+ // Nope out of here if we don't know how many columns are showing
4936
+ return content_blocks_by_index;
4859
4937
  for (let i = 0; i < wrapped_blocks.length; i++) {
4860
4938
  // i = row to show at
4861
4939
  const block = wrapped_blocks[i];
@@ -4916,7 +4994,9 @@ function $e7a7eb102ddc0c79$var$remap_blocks_to_index({
4916
4994
  function $e7a7eb102ddc0c79$var$wrap_blocks_in_div(rendered_content_blocks, max_span_columns) {
4917
4995
  const get_wrapped_blocks = $9HbP8$mapArray(() => rendered_content_blocks, block => {
4918
4996
  if (!block) return;
4919
- const get_span_columns = () => Math.min(block.span_columns, max_span_columns() ?? Infinity);
4997
+ const final_span_columns = $9HbP8$createMemo(() => Math.min(block.span_columns, max_span_columns() ?? Infinity));
4998
+ // If the item spans an entire row, limit the height to 1 row since there's no concept of "rows" if there are no products beside the block
4999
+ const final_span_rows = $9HbP8$createMemo(() => final_span_columns() === max_span_columns() ? 1 : block.span_rows);
4920
5000
  const [rendering_delayed, set_rendering_delayed_] = $9HbP8$createSignal(true);
4921
5001
  const content = $9HbP8$createComponent((0, $9HbP8$Show), {
4922
5002
  get when() {
@@ -4931,10 +5011,10 @@ function $e7a7eb102ddc0c79$var$wrap_blocks_in_div(rendered_content_blocks, max_s
4931
5011
  }));
4932
5012
  $9HbP8$effect(_p$ => {
4933
5013
  const _v$ = {
4934
- [(0, $6dee9211e57ac31a$export$c500183c31c2b22e)]: get_span_columns()
5014
+ [(0, $6dee9211e57ac31a$export$c500183c31c2b22e)]: final_span_columns()
4935
5015
  },
4936
- _v$2 = `span ${get_span_columns()}`,
4937
- _v$3 = `span ${block.span_rows}`;
5016
+ _v$2 = `span ${final_span_columns()}`,
5017
+ _v$3 = `span ${final_span_rows()}`;
4938
5018
  _p$._v$ = $9HbP8$style(_el$, _v$, _p$._v$);
4939
5019
  _v$2 !== _p$._v$2 && ((_p$._v$2 = _v$2) != null ? _el$.style.setProperty("grid-column", _v$2) : _el$.style.removeProperty("grid-column"));
4940
5020
  _v$3 !== _p$._v$3 && ((_p$._v$3 = _v$3) != null ? _el$.style.setProperty("grid-row", _v$3) : _el$.style.removeProperty("grid-row"));
@@ -4947,7 +5027,7 @@ function $e7a7eb102ddc0c79$var$wrap_blocks_in_div(rendered_content_blocks, max_s
4947
5027
  return _el$;
4948
5028
  }
4949
5029
  });
4950
- return $9HbP8$mergeProps1(block, {
5030
+ return $9HbP8$mergeProps(block, {
4951
5031
  // Create content divs for the blocks with as much fine-grained diffing as possible?
4952
5032
  content: () => {
4953
5033
  // Sneaky on-demand rendering, so we don't render more blocks than we can show: we have the rendered value here and don't return a function that renders because if our block would be moved around we'd be guaranteed to re-render
@@ -4957,7 +5037,10 @@ function $e7a7eb102ddc0c79$var$wrap_blocks_in_div(rendered_content_blocks, max_s
4957
5037
  },
4958
5038
  get span_columns() {
4959
5039
  // Cap max width of block to the number of columns available, for everyone downstream
4960
- return get_span_columns();
5040
+ return final_span_columns();
5041
+ },
5042
+ get span_rows() {
5043
+ return final_span_rows();
4961
5044
  }
4962
5045
  });
4963
5046
  });
@@ -5633,7 +5716,7 @@ function $757dac7f7c6c5241$export$9bf11afa910f536e({
5633
5716
  get children() {
5634
5717
  return (() => {
5635
5718
  const _el$34 = $9HbP8$getNextElement($757dac7f7c6c5241$var$_tmpl$5);
5636
- $9HbP8$insert(_el$34, $9HbP8$createComponent((0, $fab07f52c9861732$export$3f1a388cc0d8fed7), $9HbP8$mergeProps(args_for_filtering_, {
5719
+ $9HbP8$insert(_el$34, $9HbP8$createComponent((0, $fab07f52c9861732$export$3f1a388cc0d8fed7), $9HbP8$mergeProps1(args_for_filtering_, {
5637
5720
  are_in_modal_: true
5638
5721
  })));
5639
5722
  return _el$34;
@@ -7842,7 +7925,7 @@ const $16f0ed5ea30d8d9c$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<svg><path d=
7842
7925
  function $16f0ed5ea30d8d9c$export$82eafebb825fc23f(props = {}) {
7843
7926
  return (() => {
7844
7927
  const _el$ = $9HbP8$getNextElement($16f0ed5ea30d8d9c$var$_tmpl$);
7845
- $9HbP8$spread(_el$, $9HbP8$mergeProps(props, {
7928
+ $9HbP8$spread(_el$, $9HbP8$mergeProps1(props, {
7846
7929
  "xmlns": "http://www.w3.org/2000/svg",
7847
7930
  "width": "20",
7848
7931
  "height": "22"
@@ -8015,7 +8098,7 @@ function $172e1b898d457050$export$7de92c4c2205ebf3({
8015
8098
  [_el$6, _co$2] = $9HbP8$getNextMarker(_el$5.nextSibling);
8016
8099
  $9HbP8$insert(_el$2, () => i18n_.search_recs_title_());
8017
8100
  $9HbP8$insert(_el$, (0, $a458486f22b22f63$export$a2cc176055f8f08), _el$4, _co$);
8018
- $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
8101
+ $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps1({
8019
8102
  rows: rows_object,
8020
8103
  layout: "grid",
8021
8104
  element_attributes: {
@@ -9959,7 +10042,7 @@ function $b2bf2cdcff8142d8$export$f631859cab12b342({
9959
10042
  [_el$8, _co$] = $9HbP8$getNextMarker(_el$7.nextSibling),
9960
10043
  _el$9 = _el$8.nextSibling,
9961
10044
  [_el$10, _co$2] = $9HbP8$getNextMarker(_el$9.nextSibling);
9962
- $9HbP8$insert(_el$4, $9HbP8$createComponent(LinkIfPossible, $9HbP8$mergeProps(make_link_attributes, {
10045
+ $9HbP8$insert(_el$4, $9HbP8$createComponent(LinkIfPossible, $9HbP8$mergeProps1(make_link_attributes, {
9963
10046
  tabIndex: "-1",
9964
10047
  get children() {
9965
10048
  return $9HbP8$createComponent((0, $190927650b4840eb$export$605674723bcc715c), {
@@ -9968,7 +10051,7 @@ function $b2bf2cdcff8142d8$export$f631859cab12b342({
9968
10051
  });
9969
10052
  }
9970
10053
  })));
9971
- $9HbP8$insert(_el$5, $9HbP8$createComponent(LinkIfPossible, $9HbP8$mergeProps({
10054
+ $9HbP8$insert(_el$5, $9HbP8$createComponent(LinkIfPossible, $9HbP8$mergeProps1({
9972
10055
  "class": "content-title line-clamp"
9973
10056
  }, make_link_attributes, {
9974
10057
  get title() {
@@ -10112,7 +10195,7 @@ function $49de9d31aeea1b5e$export$6d0c9c22f6652669({
10112
10195
  },
10113
10196
  number_of_results_: num_results
10114
10197
  }), _el$3, _co$);
10115
- $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
10198
+ $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps1({
10116
10199
  layout: "grid",
10117
10200
  element_attributes: {
10118
10201
  class: "cards"
@@ -10272,7 +10355,7 @@ function $7097477c78a89208$export$a54ec244c8863715({
10272
10355
  });
10273
10356
  const [sort_and_filter_element_, set_sort_and_filter_element_] = $9HbP8$createSignal();
10274
10357
  const no_results_text_ = $9HbP8$createMemo(() => (search_results_()?.content_search_links?.length ? i18n_.no_products_ : i18n_.no_results_text_)());
10275
- const results_for = $9HbP8$createComponent((0, $f8c929beb82c512b$export$9dd50d35b9d94fdf), $9HbP8$mergeProps({
10358
+ const results_for = $9HbP8$createComponent((0, $f8c929beb82c512b$export$9dd50d35b9d94fdf), $9HbP8$mergeProps1({
10276
10359
  get type() {
10277
10360
  return (0, $f8c929beb82c512b$export$2452208c79fe93ea).products;
10278
10361
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/ui",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Base package containing the actual UI of Depict UI along with translations, with a not-simplified API. We recommend using @depict-ai/js-ui or @depict-ai/react-ui instead.",
5
5
  "packageManager": "yarn@3.2.2",
6
6
  "sass": "styles.scss",