@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.js CHANGED
@@ -1929,6 +1929,7 @@ var hover3d_default = hover3dDirective;
1929
1929
 
1930
1930
  // vanilla/directives/hovergallery.ts
1931
1931
  var IMG_RE3 = /!\[([^\]]*)\]\(([^)]+)\)/g;
1932
+ var MAX_IMAGES = 10;
1932
1933
  var hovergalleryDirective = ({ props, slots }) => {
1933
1934
  const images = [];
1934
1935
  const raw = slots.default || "";
@@ -1940,18 +1941,56 @@ var hovergalleryDirective = ({ props, slots }) => {
1940
1941
  if (images.length === 0) {
1941
1942
  return document.createDocumentFragment();
1942
1943
  }
1944
+ const count = Math.min(images.length, MAX_IMAGES);
1943
1945
  const figure = document.createElement("figure");
1944
1946
  figure.className = "nr-hover-gallery";
1945
1947
  if (props.aspect) figure.style.aspectRatio = props.aspect;
1946
1948
  if (props.class) figure.classList.add(...props.class.split(/\s+/).filter(Boolean));
1947
- if (props.style) figure.setAttribute("style", props.style);
1948
- for (const img of images) {
1949
+ if (props.style) figure.setAttribute("style", (figure.getAttribute("style") || "") + ";" + props.style);
1950
+ const imgEls = [];
1951
+ for (let i = 0; i < count; i++) {
1949
1952
  const el = document.createElement("img");
1950
- el.src = img.src;
1951
- el.alt = img.alt;
1953
+ el.src = images[i].src;
1954
+ el.alt = images[i].alt;
1952
1955
  el.loading = "lazy";
1956
+ el.draggable = false;
1957
+ if (i === 0) el.classList.add("nr-hg-active");
1958
+ imgEls.push(el);
1953
1959
  figure.appendChild(el);
1954
1960
  }
1961
+ for (let i = 0; i < count; i++) {
1962
+ const strip = document.createElement("div");
1963
+ strip.className = "nr-hg-trigger";
1964
+ strip.style.left = `${i / count * 100}%`;
1965
+ strip.style.width = `${1 / count * 100}%`;
1966
+ strip.addEventListener("mouseenter", () => {
1967
+ for (let j = 0; j < imgEls.length; j++) {
1968
+ imgEls[j].classList.toggle("nr-hg-active", j === i);
1969
+ }
1970
+ for (let j = 0; j < dotEls.length; j++) {
1971
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === i);
1972
+ }
1973
+ });
1974
+ figure.appendChild(strip);
1975
+ }
1976
+ figure.addEventListener("mouseleave", () => {
1977
+ for (let j = 0; j < imgEls.length; j++) {
1978
+ imgEls[j].classList.toggle("nr-hg-active", j === 0);
1979
+ }
1980
+ for (let j = 0; j < dotEls.length; j++) {
1981
+ dotEls[j].classList.toggle("nr-hg-dot-active", j === 0);
1982
+ }
1983
+ });
1984
+ const dotContainer = document.createElement("div");
1985
+ dotContainer.className = "nr-hg-dots";
1986
+ const dotEls = [];
1987
+ for (let i = 0; i < count; i++) {
1988
+ const dot = document.createElement("span");
1989
+ if (i === 0) dot.classList.add("nr-hg-dot-active");
1990
+ dotEls.push(dot);
1991
+ dotContainer.appendChild(dot);
1992
+ }
1993
+ figure.appendChild(dotContainer);
1955
1994
  return figure;
1956
1995
  };
1957
1996
  var hovergallery_default = hovergalleryDirective;