@getflip/swirl-components 0.271.0 → 0.273.0

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.
@@ -1,7 +1,12 @@
1
1
  import { h, Host, } from "@stencil/core";
2
2
  import classnames from "classnames";
3
+ import { debounce } from "../../utils";
3
4
  export class SwirlImageGridItem {
4
5
  constructor() {
6
+ this.handleIntersectionEntries = debounce((entries) => {
7
+ const sorted = [...entries].sort((a, b) => a.time - b.time);
8
+ this.inViewport = sorted.at(-1).isIntersecting;
9
+ }, 250);
5
10
  this.onLoad = () => {
6
11
  this.error = false;
7
12
  this.loaded = true;
@@ -76,14 +81,11 @@ export class SwirlImageGridItem {
76
81
  if (this.loading !== "intersecting") {
77
82
  return;
78
83
  }
79
- this.intersectionObserver = new IntersectionObserver(this.onVisibilityChange.bind(this), {
80
- threshold: 0,
84
+ this.intersectionObserver = new IntersectionObserver((entries) => {
85
+ this.handleIntersectionEntries(entries);
81
86
  });
82
87
  this.intersectionObserver.observe(this.el);
83
88
  }
84
- onVisibilityChange(entries) {
85
- this.inViewport = entries.some((entry) => entry.isIntersecting);
86
- }
87
89
  async pauseGif() {
88
90
  const imageEl = this.img;
89
91
  const staticImage = await this.readImageFromCanvas(imageEl.src);
@@ -117,16 +119,16 @@ export class SwirlImageGridItem {
117
119
  "image-grid-item--has-error": this.error,
118
120
  "image-grid-item--has-overlay": this.overlay,
119
121
  });
120
- return (h(Host, { key: '76485aab929a8e33cc8f3b226497d9f1df3bb49d', "data-sibling-count": siblingCount, role: "listitem" }, h(Tag, { key: '12d24ad20f9a877584cbb3d2e9cdfbad6a4dc2e9', class: className, type: this.interactive ? "button" : undefined }, h("div", { key: '6d0fa0c2d90033e3b357323d403e887fb80fe4ec', class: "image-grid-item__background", style: {
122
+ return (h(Host, { key: '3df6b790bbb8606b4eed5d6d0788d105e04f4b8a', "data-sibling-count": siblingCount, role: "listitem" }, h(Tag, { key: 'bb91bd8a691464f03e90ed9e89149f395df74a9d', class: className, type: this.interactive ? "button" : undefined }, h("div", { key: '8c1193c46a7d739a0b0980bbb8ba1fc6085800d7', class: "image-grid-item__background", style: {
121
123
  backgroundImage: showBlurredBackground
122
124
  ? `url(${this.computedSrc})`
123
125
  : undefined,
124
126
  } }), this.loading !== "intersecting" ||
125
127
  this.inViewport ||
126
- this.gifPaused ? (h("img", { alt: this.alt, class: "image-grid-item__image", loading: this.loading !== "intersecting" ? this.loading : undefined, onError: this.onError, onLoad: this.onLoad, ref: (el) => (this.img = el), src: this.computedSrc })) : (h("div", { class: "image-grid-item__loading-placeholder" })), this.showGifControls && (h("swirl-stack", { key: '827ad86b66876e451aef554fc24ff090e4d5777d', class: "image-grid-item__gif-controls", orientation: "horizontal", spacing: "4" }, h("button", { key: '83026738dfc9cbb8a145d309c540712fdb16b000', class: "image-grid-item__gif-controls__icon image-grid-item__gif-controls__icon--button", onClick: this.handleControlClick, type: "button", "aria-label": this.gifPaused ? this.gifPlayLabel : this.gifPauseLabel }, this.gifPaused ? (h("swirl-icon-play-arrow", { size: 20 })) : (h("swirl-icon-pause", { size: 20 }))), h("div", { key: '6b666841df8cbaae189d2ef21dafa54fd1891377', class: "image-grid-item__gif-controls__icon image-grid-item__gif-controls__icon--label" }, h("swirl-icon-gif", { key: '76908d564832b3b6f63a43928be8815502943425', size: 20 })))), this.loaded &&
128
+ this.gifPaused ? (h("img", { alt: this.alt, class: "image-grid-item__image", loading: this.loading !== "intersecting" ? this.loading : undefined, onError: this.onError, onLoad: this.onLoad, ref: (el) => (this.img = el), src: this.computedSrc })) : (h("div", { class: "image-grid-item__loading-placeholder" })), this.showGifControls && (h("swirl-stack", { key: 'ddbdaa408afe0d8fe445256196a23ace3c0fb75b', class: "image-grid-item__gif-controls", orientation: "horizontal", spacing: "4" }, h("button", { key: 'd0d2b4ca348272191442dba90619f4ac9a1bd7ec', class: "image-grid-item__gif-controls__icon image-grid-item__gif-controls__icon--button", onClick: this.handleControlClick, type: "button", "aria-label": this.gifPaused ? this.gifPlayLabel : this.gifPauseLabel }, this.gifPaused ? (h("swirl-icon-play-arrow", { size: 20 })) : (h("swirl-icon-pause", { size: 20 }))), h("div", { key: '2818e0abc2a61e1483a69c32678c2ac4e4989290', class: "image-grid-item__gif-controls__icon image-grid-item__gif-controls__icon--label" }, h("swirl-icon-gif", { key: 'c514991c015cd6f9767dd175f2370eb20937eeda', size: 20 })))), this.loaded &&
127
129
  !this.error &&
128
130
  this.icon &&
129
- !Boolean(this.overlay) && (h("div", { key: '1870a25ab75a9e71e9f0028312489242e76b3d82', class: "image-grid-item__icon", innerHTML: this.icon })), this.overlay && (h("div", { key: 'b8cfc7ed5e18b5df4d319418520a8e599d93563b', class: "image-grid-item__overlay" }, this.overlay)), !this.loaded && (h("div", { key: 'c6e3fef4dc7e639902af85cd6118754e8d58d3f3', class: "image-grid-item__spinner" }, h("swirl-spinner", { key: '6df4e1823d1761eb9344655b30bb4eecfa3807aa' }))), this.loaded && this.error && (h("div", { key: '2a059146e82ae8fd6ec968b34267239f3f1b7071', class: "image-grid-item__error" }, h("swirl-icon-error", { key: '37a20227d442b202a0cd5a66c2203f827836fcb9', color: "critical" }))))));
131
+ !Boolean(this.overlay) && (h("div", { key: '3fbb938d73610ca670018d66422ce58d92a2c91c', class: "image-grid-item__icon", innerHTML: this.icon })), this.overlay && (h("div", { key: '435b2fd7a8a94fbe0905636b82a1793202cb1c41', class: "image-grid-item__overlay" }, this.overlay)), !this.loaded && (h("div", { key: 'a4a2276318afe3424504a200185a038d6dc4161f', class: "image-grid-item__spinner" }, h("swirl-spinner", { key: '55a074bfe0459222049673788d7b755608fd9f27' }))), this.loaded && this.error && (h("div", { key: 'cd48b68ce0970d73fed49bad653b9de2f0f4907f', class: "image-grid-item__error" }, h("swirl-icon-error", { key: '60b1c44bb59cf45b8cf5a27528dc680100344896', color: "critical" }))))));
130
132
  }
131
133
  static get is() { return "swirl-image-grid-item"; }
132
134
  static get encapsulation() { return "shadow"; }