@noirmd/previewer 2.0.5 → 2.1.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.
package/dist/vanilla.cjs CHANGED
@@ -11941,6 +11941,7 @@ var hover3d_default = hover3dDirective;
11941
11941
 
11942
11942
  // vanilla/directives/hovergallery.ts
11943
11943
  var IMG_RE3 = /!\[([^\]]*)\]\(([^)]+)\)/g;
11944
+ var MAX_IMAGES = 10;
11944
11945
  var hovergalleryDirective = ({ props, slots }) => {
11945
11946
  const images = [];
11946
11947
  const raw = slots.default || "";
@@ -11952,18 +11953,56 @@ var hovergalleryDirective = ({ props, slots }) => {
11952
11953
  if (images.length === 0) {
11953
11954
  return document.createDocumentFragment();
11954
11955
  }
11956
+ const count = Math.min(images.length, MAX_IMAGES);
11955
11957
  const figure = document.createElement("figure");
11956
11958
  figure.className = "nr-hover-gallery";
11957
11959
  if (props.aspect) figure.style.aspectRatio = props.aspect;
11958
11960
  if (props.class) figure.classList.add(...props.class.split(/\s+/).filter(Boolean));
11959
- if (props.style) figure.setAttribute("style", props.style);
11960
- for (const img of images) {
11961
+ if (props.style) figure.setAttribute("style", (figure.getAttribute("style") || "") + ";" + props.style);
11962
+ const imgEls = [];
11963
+ for (let i = 0; i < count; i++) {
11961
11964
  const el = document.createElement("img");
11962
- el.src = img.src;
11963
- el.alt = img.alt;
11965
+ el.src = images[i].src;
11966
+ el.alt = images[i].alt;
11964
11967
  el.loading = "lazy";
11968
+ el.draggable = false;
11969
+ if (i === 0) el.classList.add("nr-hg-active");
11970
+ imgEls.push(el);
11965
11971
  figure.appendChild(el);
11966
11972
  }
11973
+ for (let i = 0; i < count; i++) {
11974
+ const strip = document.createElement("div");
11975
+ strip.className = "nr-hg-trigger";
11976
+ strip.style.left = `${i / count * 100}%`;
11977
+ strip.style.width = `${1 / count * 100}%`;
11978
+ strip.addEventListener("mouseenter", () => {
11979
+ for (let j = 0; j < imgEls.length; j++) {
11980
+ imgEls[j].classList.toggle("nr-hg-active", j === i);
11981
+ }
11982
+ for (let j = 0; j < dotEls.length; j++) {
11983
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === i);
11984
+ }
11985
+ });
11986
+ figure.appendChild(strip);
11987
+ }
11988
+ figure.addEventListener("mouseleave", () => {
11989
+ for (let j = 0; j < imgEls.length; j++) {
11990
+ imgEls[j].classList.toggle("nr-hg-active", j === 0);
11991
+ }
11992
+ for (let j = 0; j < dotEls.length; j++) {
11993
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === 0);
11994
+ }
11995
+ });
11996
+ const dotContainer = document.createElement("div");
11997
+ dotContainer.className = "nr-hg-dots";
11998
+ const dotEls = [];
11999
+ for (let i = 0; i < count; i++) {
12000
+ const dot = document.createElement("span");
12001
+ if (i === 0) dot.classList.add("nr-hg-dot-active");
12002
+ dotEls.push(dot);
12003
+ dotContainer.appendChild(dot);
12004
+ }
12005
+ figure.appendChild(dotContainer);
11967
12006
  return figure;
11968
12007
  };
11969
12008
  var hovergallery_default = hovergalleryDirective;