@noirmd/previewer 2.0.4 → 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/NReditor.cjs CHANGED
@@ -1963,6 +1963,7 @@ var hover3d_default = hover3dDirective;
1963
1963
 
1964
1964
  // vanilla/directives/hovergallery.ts
1965
1965
  var IMG_RE3 = /!\[([^\]]*)\]\(([^)]+)\)/g;
1966
+ var MAX_IMAGES = 10;
1966
1967
  var hovergalleryDirective = ({ props, slots }) => {
1967
1968
  const images = [];
1968
1969
  const raw = slots.default || "";
@@ -1974,18 +1975,56 @@ var hovergalleryDirective = ({ props, slots }) => {
1974
1975
  if (images.length === 0) {
1975
1976
  return document.createDocumentFragment();
1976
1977
  }
1978
+ const count = Math.min(images.length, MAX_IMAGES);
1977
1979
  const figure = document.createElement("figure");
1978
1980
  figure.className = "nr-hover-gallery";
1979
1981
  if (props.aspect) figure.style.aspectRatio = props.aspect;
1980
1982
  if (props.class) figure.classList.add(...props.class.split(/\s+/).filter(Boolean));
1981
- if (props.style) figure.setAttribute("style", props.style);
1982
- for (const img of images) {
1983
+ if (props.style) figure.setAttribute("style", (figure.getAttribute("style") || "") + ";" + props.style);
1984
+ const imgEls = [];
1985
+ for (let i = 0; i < count; i++) {
1983
1986
  const el = document.createElement("img");
1984
- el.src = img.src;
1985
- el.alt = img.alt;
1987
+ el.src = images[i].src;
1988
+ el.alt = images[i].alt;
1986
1989
  el.loading = "lazy";
1990
+ el.draggable = false;
1991
+ if (i === 0) el.classList.add("nr-hg-active");
1992
+ imgEls.push(el);
1987
1993
  figure.appendChild(el);
1988
1994
  }
1995
+ for (let i = 0; i < count; i++) {
1996
+ const strip = document.createElement("div");
1997
+ strip.className = "nr-hg-trigger";
1998
+ strip.style.left = `${i / count * 100}%`;
1999
+ strip.style.width = `${1 / count * 100}%`;
2000
+ strip.addEventListener("mouseenter", () => {
2001
+ for (let j = 0; j < imgEls.length; j++) {
2002
+ imgEls[j].classList.toggle("nr-hg-active", j === i);
2003
+ }
2004
+ for (let j = 0; j < dotEls.length; j++) {
2005
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === i);
2006
+ }
2007
+ });
2008
+ figure.appendChild(strip);
2009
+ }
2010
+ figure.addEventListener("mouseleave", () => {
2011
+ for (let j = 0; j < imgEls.length; j++) {
2012
+ imgEls[j].classList.toggle("nr-hg-active", j === 0);
2013
+ }
2014
+ for (let j = 0; j < dotEls.length; j++) {
2015
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === 0);
2016
+ }
2017
+ });
2018
+ const dotContainer = document.createElement("div");
2019
+ dotContainer.className = "nr-hg-dots";
2020
+ const dotEls = [];
2021
+ for (let i = 0; i < count; i++) {
2022
+ const dot = document.createElement("span");
2023
+ if (i === 0) dot.classList.add("nr-hg-dot-active");
2024
+ dotEls.push(dot);
2025
+ dotContainer.appendChild(dot);
2026
+ }
2027
+ figure.appendChild(dotContainer);
1989
2028
  return figure;
1990
2029
  };
1991
2030
  var hovergallery_default = hovergalleryDirective;