@canopy-iiif/app 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2126,12 +2126,9 @@ function Container({
2126
2126
  );
2127
2127
  }
2128
2128
 
2129
- // ui/src/content/ReferencedItems.jsx
2130
- import React24 from "react";
2131
- import navigationHelpers4 from "@canopy-iiif/app/lib/components/navigation.js";
2132
-
2133
2129
  // ui/src/layout/Card.jsx
2134
2130
  import React23, { useEffect as useEffect5, useRef, useState as useState5 } from "react";
2131
+ var DEFAULT_CARD_ASPECT_RATIO = 4 / 3;
2135
2132
  function Card({
2136
2133
  href,
2137
2134
  src,
@@ -2149,12 +2146,15 @@ function Card({
2149
2146
  ...rest
2150
2147
  }) {
2151
2148
  const containerRef = useRef(null);
2152
- const [inView, setInView] = useState5(!lazy);
2153
- const [imageLoaded, setImageLoaded] = useState5(!lazy);
2149
+ const isBrowser = typeof window !== "undefined";
2150
+ const supportsIntersectionObserver = typeof IntersectionObserver === "function";
2151
+ const shouldRenderImmediately = !lazy || !isBrowser || !supportsIntersectionObserver;
2152
+ const [inView, setInView] = useState5(shouldRenderImmediately);
2153
+ const [imageLoaded, setImageLoaded] = useState5(shouldRenderImmediately);
2154
2154
  useEffect5(() => {
2155
2155
  if (!lazy) return;
2156
2156
  if (!containerRef.current) return;
2157
- if (typeof IntersectionObserver !== "function") {
2157
+ if (!supportsIntersectionObserver) {
2158
2158
  setInView(true);
2159
2159
  return;
2160
2160
  }
@@ -2184,10 +2184,12 @@ function Card({
2184
2184
  } catch (_) {
2185
2185
  }
2186
2186
  };
2187
- }, [lazy]);
2187
+ }, [lazy, supportsIntersectionObserver]);
2188
2188
  const w = Number(imgWidth);
2189
2189
  const h = Number(imgHeight);
2190
- const ratio = Number.isFinite(Number(aspectRatio)) && Number(aspectRatio) > 0 ? Number(aspectRatio) : Number.isFinite(w) && w > 0 && Number.isFinite(h) && h > 0 ? w / h : void 0;
2190
+ const hasAspectRatio = Number.isFinite(Number(aspectRatio)) && Number(aspectRatio) > 0;
2191
+ const hasDimensions = Number.isFinite(w) && w > 0 && Number.isFinite(h) && h > 0;
2192
+ const ratio = hasAspectRatio ? Number(aspectRatio) : hasDimensions ? w / h : src ? DEFAULT_CARD_ASPECT_RATIO : void 0;
2191
2193
  const paddingPercent = ratio ? 100 / ratio : 100;
2192
2194
  const caption = /* @__PURE__ */ React23.createElement("figcaption", null, title && /* @__PURE__ */ React23.createElement("span", null, title), subtitle && /* @__PURE__ */ React23.createElement("span", null, subtitle), children);
2193
2195
  return /* @__PURE__ */ React23.createElement(
@@ -2233,6 +2235,8 @@ function Card({
2233
2235
  }
2234
2236
 
2235
2237
  // ui/src/content/ReferencedItems.jsx
2238
+ import React24 from "react";
2239
+ import navigationHelpers4 from "@canopy-iiif/app/lib/components/navigation.js";
2236
2240
  function useReferencedItems(itemsProp) {
2237
2241
  if (Array.isArray(itemsProp)) return itemsProp;
2238
2242
  const PageContext = navigationHelpers4 && typeof navigationHelpers4.getPageContext === "function" ? navigationHelpers4.getPageContext() : null;
@@ -7394,6 +7398,7 @@ export {
7394
7398
  CanopyFooter,
7395
7399
  CanopyHeader,
7396
7400
  CanopyModal,
7401
+ Card,
7397
7402
  Container,
7398
7403
  DocsCodeBlock,
7399
7404
  MarkdownTable as DocsMarkdownTable,