@canopy-iiif/app 1.9.19 → 1.9.20

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": "1.9.19",
3
+ "version": "1.9.20",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",
package/ui/dist/index.mjs CHANGED
@@ -45526,21 +45526,16 @@ var ImageStory = (props = {}) => {
45526
45526
  if (!node) return void 0;
45527
45527
  let cleanup = null;
45528
45528
  let cancelled = false;
45529
+ let mounted = false;
45530
+ let resizeObserver = null;
45531
+ let pollId = null;
45529
45532
  const payload = sanitizeImageStoryProps({
45530
45533
  iiifContent,
45531
45534
  disablePanAndZoom,
45532
45535
  pointOfInterestSvgUrl,
45533
45536
  viewerOptions
45534
45537
  });
45535
- mountImageStory(node, payload).then((destroy) => {
45536
- if (cancelled) {
45537
- destroy && destroy();
45538
- return;
45539
- }
45540
- cleanup = typeof destroy === "function" ? destroy : null;
45541
- });
45542
- return () => {
45543
- cancelled = true;
45538
+ const destroyCleanup = () => {
45544
45539
  if (cleanup) {
45545
45540
  try {
45546
45541
  cleanup();
@@ -45549,6 +45544,67 @@ var ImageStory = (props = {}) => {
45549
45544
  cleanup = null;
45550
45545
  }
45551
45546
  };
45547
+ const disconnectWatchers = () => {
45548
+ if (resizeObserver) {
45549
+ try {
45550
+ resizeObserver.disconnect();
45551
+ } catch (_) {
45552
+ }
45553
+ resizeObserver = null;
45554
+ }
45555
+ if (pollId) {
45556
+ window.clearTimeout(pollId);
45557
+ pollId = null;
45558
+ }
45559
+ };
45560
+ const hasUsableSize = () => {
45561
+ if (!node) return false;
45562
+ const rect = node.getBoundingClientRect();
45563
+ const width = (rect == null ? void 0 : rect.width) || node.offsetWidth || node.clientWidth;
45564
+ const height2 = (rect == null ? void 0 : rect.height) || node.offsetHeight || node.clientHeight;
45565
+ return width > 2 && height2 > 2;
45566
+ };
45567
+ const mountViewer = () => {
45568
+ if (!node || mounted || cancelled) return false;
45569
+ if (!hasUsableSize()) return false;
45570
+ mounted = true;
45571
+ disconnectWatchers();
45572
+ mountImageStory(node, payload).then((destroy) => {
45573
+ if (cancelled) {
45574
+ destroy && destroy();
45575
+ return;
45576
+ }
45577
+ cleanup = typeof destroy === "function" ? destroy : null;
45578
+ });
45579
+ return true;
45580
+ };
45581
+ if (!mountViewer()) {
45582
+ if (typeof window !== "undefined" && typeof window.ResizeObserver === "function") {
45583
+ resizeObserver = new window.ResizeObserver(() => {
45584
+ if (mounted || cancelled) return;
45585
+ mountViewer();
45586
+ });
45587
+ try {
45588
+ resizeObserver.observe(node);
45589
+ } catch (_) {
45590
+ }
45591
+ }
45592
+ const schedulePoll = () => {
45593
+ if (mounted || cancelled) return;
45594
+ pollId = window.setTimeout(() => {
45595
+ pollId = null;
45596
+ if (!mountViewer()) {
45597
+ schedulePoll();
45598
+ }
45599
+ }, 200);
45600
+ };
45601
+ schedulePoll();
45602
+ }
45603
+ return () => {
45604
+ cancelled = true;
45605
+ disconnectWatchers();
45606
+ destroyCleanup();
45607
+ };
45552
45608
  }, [iiifContent, disablePanAndZoom, pointOfInterestSvgUrl, viewerOptions]);
45553
45609
  return /* @__PURE__ */ React27.createElement(
45554
45610
  "div",