@noirmd/previewer 2.0.5 → 2.1.1

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.js CHANGED
@@ -11912,6 +11912,7 @@ var hover3d_default = hover3dDirective;
11912
11912
 
11913
11913
  // vanilla/directives/hovergallery.ts
11914
11914
  var IMG_RE3 = /!\[([^\]]*)\]\(([^)]+)\)/g;
11915
+ var MAX_IMAGES = 10;
11915
11916
  var hovergalleryDirective = ({ props, slots }) => {
11916
11917
  const images = [];
11917
11918
  const raw = slots.default || "";
@@ -11923,18 +11924,56 @@ var hovergalleryDirective = ({ props, slots }) => {
11923
11924
  if (images.length === 0) {
11924
11925
  return document.createDocumentFragment();
11925
11926
  }
11927
+ const count = Math.min(images.length, MAX_IMAGES);
11926
11928
  const figure = document.createElement("figure");
11927
11929
  figure.className = "nr-hover-gallery";
11928
11930
  if (props.aspect) figure.style.aspectRatio = props.aspect;
11929
11931
  if (props.class) figure.classList.add(...props.class.split(/\s+/).filter(Boolean));
11930
- if (props.style) figure.setAttribute("style", props.style);
11931
- for (const img of images) {
11932
+ if (props.style) figure.setAttribute("style", (figure.getAttribute("style") || "") + ";" + props.style);
11933
+ const imgEls = [];
11934
+ for (let i = 0; i < count; i++) {
11932
11935
  const el = document.createElement("img");
11933
- el.src = img.src;
11934
- el.alt = img.alt;
11936
+ el.src = images[i].src;
11937
+ el.alt = images[i].alt;
11935
11938
  el.loading = "lazy";
11939
+ el.draggable = false;
11940
+ if (i === 0) el.classList.add("nr-hg-active");
11941
+ imgEls.push(el);
11936
11942
  figure.appendChild(el);
11937
11943
  }
11944
+ for (let i = 0; i < count; i++) {
11945
+ const strip = document.createElement("div");
11946
+ strip.className = "nr-hg-trigger";
11947
+ strip.style.left = `${i / count * 100}%`;
11948
+ strip.style.width = `${1 / count * 100}%`;
11949
+ strip.addEventListener("mouseenter", () => {
11950
+ for (let j = 0; j < imgEls.length; j++) {
11951
+ imgEls[j].classList.toggle("nr-hg-active", j === i);
11952
+ }
11953
+ for (let j = 0; j < dotEls.length; j++) {
11954
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === i);
11955
+ }
11956
+ });
11957
+ figure.appendChild(strip);
11958
+ }
11959
+ figure.addEventListener("mouseleave", () => {
11960
+ for (let j = 0; j < imgEls.length; j++) {
11961
+ imgEls[j].classList.toggle("nr-hg-active", j === 0);
11962
+ }
11963
+ for (let j = 0; j < dotEls.length; j++) {
11964
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === 0);
11965
+ }
11966
+ });
11967
+ const dotContainer = document.createElement("div");
11968
+ dotContainer.className = "nr-hg-dots";
11969
+ const dotEls = [];
11970
+ for (let i = 0; i < count; i++) {
11971
+ const dot = document.createElement("span");
11972
+ if (i === 0) dot.classList.add("nr-hg-dot-active");
11973
+ dotEls.push(dot);
11974
+ dotContainer.appendChild(dot);
11975
+ }
11976
+ figure.appendChild(dotContainer);
11938
11977
  return figure;
11939
11978
  };
11940
11979
  var hovergallery_default = hovergalleryDirective;