@pixodesk/svg-animator-web 1.0.28 → 1.0.30

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.
@@ -2440,8 +2440,11 @@ var PixodeskAnimator = (() => {
2440
2440
  driver.refresh();
2441
2441
  return driver;
2442
2442
  }
2443
+ function pinScrollportHeight(svgRoot) {
2444
+ const scroller = findNearestScroller(svgRoot, "y");
2445
+ return scroller ? scroller.clientHeight : document.documentElement.clientHeight;
2446
+ }
2443
2447
  function applyScrollPin(svgRoot, scroll) {
2444
- var _a;
2445
2448
  const styled = svgRoot;
2446
2449
  if (!(scroll == null ? void 0 : scroll.pin) || !styled.style) return () => {
2447
2450
  };
@@ -2449,7 +2452,28 @@ var PixodeskAnimator = (() => {
2449
2452
  const prevPosition = style.position;
2450
2453
  const prevTop = style.top;
2451
2454
  style.position = "sticky";
2452
- style.top = ((_a = scroll.pinTop) != null ? _a : 0) + "px";
2455
+ const alignFactor = scroll.pinAlign === "center" ? 0.5 : scroll.pinAlign === "bottom" ? 1 : 0;
2456
+ const applyTop = () => {
2457
+ var _a;
2458
+ const extra = (_a = scroll.pinTop) != null ? _a : 0;
2459
+ if (!alignFactor) {
2460
+ style.top = extra + "px";
2461
+ return;
2462
+ }
2463
+ const portSize = pinScrollportHeight(svgRoot);
2464
+ const ownSize = svgRoot.getBoundingClientRect().height;
2465
+ style.top = Math.round((portSize - ownSize) * alignFactor + extra) + "px";
2466
+ };
2467
+ applyTop();
2468
+ let resizeObserver = null;
2469
+ const onWindowResize = alignFactor ? applyTop : null;
2470
+ if (alignFactor) {
2471
+ if (onWindowResize) window.addEventListener("resize", onWindowResize);
2472
+ if (typeof ResizeObserver !== "undefined") {
2473
+ resizeObserver = new ResizeObserver(applyTop);
2474
+ resizeObserver.observe(svgRoot);
2475
+ }
2476
+ }
2453
2477
  let wrapper = null;
2454
2478
  const parent = svgRoot.parentElement;
2455
2479
  if (scroll.pinDistance && scroll.pinDistance > 0 && parent) {
@@ -2460,6 +2484,8 @@ var PixodeskAnimator = (() => {
2460
2484
  wrapper.appendChild(svgRoot);
2461
2485
  }
2462
2486
  return () => {
2487
+ if (onWindowResize) window.removeEventListener("resize", onWindowResize);
2488
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
2463
2489
  style.position = prevPosition;
2464
2490
  style.top = prevTop;
2465
2491
  if (wrapper == null ? void 0 : wrapper.parentElement) {