@canopy-iiif/app 0.13.1 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",
package/ui/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ var HelloWorld = () => {
6
6
 
7
7
  // ui/src/layout/Card.jsx
8
8
  import React2, { useEffect, useRef, useState } from "react";
9
+ var DEFAULT_CARD_ASPECT_RATIO = 4 / 3;
9
10
  function Card({
10
11
  href,
11
12
  src,
@@ -23,12 +24,15 @@ function Card({
23
24
  ...rest
24
25
  }) {
25
26
  const containerRef = useRef(null);
26
- const [inView, setInView] = useState(!lazy);
27
- const [imageLoaded, setImageLoaded] = useState(!lazy);
27
+ const isBrowser = typeof window !== "undefined";
28
+ const supportsIntersectionObserver = typeof IntersectionObserver === "function";
29
+ const shouldRenderImmediately = !lazy || !isBrowser || !supportsIntersectionObserver;
30
+ const [inView, setInView] = useState(shouldRenderImmediately);
31
+ const [imageLoaded, setImageLoaded] = useState(shouldRenderImmediately);
28
32
  useEffect(() => {
29
33
  if (!lazy) return;
30
34
  if (!containerRef.current) return;
31
- if (typeof IntersectionObserver !== "function") {
35
+ if (!supportsIntersectionObserver) {
32
36
  setInView(true);
33
37
  return;
34
38
  }
@@ -58,10 +62,12 @@ function Card({
58
62
  } catch (_) {
59
63
  }
60
64
  };
61
- }, [lazy]);
65
+ }, [lazy, supportsIntersectionObserver]);
62
66
  const w = Number(imgWidth);
63
67
  const h = Number(imgHeight);
64
- 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;
68
+ const hasAspectRatio = Number.isFinite(Number(aspectRatio)) && Number(aspectRatio) > 0;
69
+ const hasDimensions = Number.isFinite(w) && w > 0 && Number.isFinite(h) && h > 0;
70
+ const ratio = hasAspectRatio ? Number(aspectRatio) : hasDimensions ? w / h : src ? DEFAULT_CARD_ASPECT_RATIO : void 0;
65
71
  const paddingPercent = ratio ? 100 / ratio : 100;
66
72
  const caption = /* @__PURE__ */ React2.createElement("figcaption", null, title && /* @__PURE__ */ React2.createElement("span", null, title), subtitle && /* @__PURE__ */ React2.createElement("span", null, subtitle), children);
67
73
  return /* @__PURE__ */ React2.createElement(