"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var src_exports = {};
__export(src_exports, {
  Carousel: () => Carousel,
  Cube: () => Cube,
  Fade: () => Fade,
  SliderControls: () => SliderControls,
  Tile: () => Tile
});
module.exports = __toCommonJS(src_exports);

// src/Carousel.ts
var import_Carousel = __toESM(require("@boxslider/slider/effects/Carousel"), 1);

// src/Slider.ts
var import_BoxSlider = __toESM(require("@boxslider/slider/BoxSlider"), 1);
function camelize(str) {
  return str.replace(/-./g, (m) => m[1].toUpperCase());
}
function getNumericAttribute(el, attribute, defaultValue) {
  const attributeValue = el.getAttribute(attribute);
  let value = NaN;
  if (attributeValue !== null) {
    value = parseInt(attributeValue, 10);
  }
  return isNaN(value) ? defaultValue : value;
}
function getBbooleanAttribute(el, attribute, defaultValue) {
  if (el.hasAttribute(attribute)) {
    return el.getAttribute(attribute) !== "false";
  }
  return defaultValue;
}
var BOOLEAN_ATTRIBUTES = ["auto-scroll", "pause-on-hover"];
var NUMBER_ATTRIBUTES = [
  "speed",
  "timeout",
  "start-index",
  "swipe",
  "swipe-tolerance"
];
var SLIDER_ATTRIBUTES = [...BOOLEAN_ATTRIBUTES, ...NUMBER_ATTRIBUTES];
var Slider = class extends HTMLElement {
  #slider;
  get slider() {
    return this.#slider;
  }
  get autoScroll() {
    return getBbooleanAttribute(this, "auto-scroll", import_BoxSlider.defaultOptions.autoScroll);
  }
  get pauseOnHover() {
    return getBbooleanAttribute(
      this,
      "pause-on-hover",
      import_BoxSlider.defaultOptions.pauseOnHover
    );
  }
  get speed() {
    return getNumericAttribute(this, "speed", import_BoxSlider.defaultOptions.speed);
  }
  get startIndex() {
    return getNumericAttribute(this, "start-index", import_BoxSlider.defaultOptions.startIndex);
  }
  get swipe() {
    return getBbooleanAttribute(this, "swipe", import_BoxSlider.defaultOptions.swipe);
  }
  get swipeTolerance() {
    return getNumericAttribute(
      this,
      "swipe-tolerance",
      import_BoxSlider.defaultOptions.swipeTolerance
    );
  }
  get timeout() {
    return getNumericAttribute(this, "timeout", import_BoxSlider.defaultOptions.timeout);
  }
  get options() {
    return {
      autoScroll: this.autoScroll,
      pauseOnHover: this.pauseOnHover,
      speed: this.speed,
      startIndex: this.startIndex,
      swipe: this.swipe,
      swipeTolerance: this.swipeTolerance,
      timeout: this.timeout
    };
  }
  init(effect) {
    const slider = new import_BoxSlider.default(this, effect, this.options);
    const events = [
      "play",
      "pause",
      "before",
      "after",
      "destroy"
    ];
    events.forEach(
      (ev) => slider.addEventListener(
        ev,
        (detail) => this.dispatchEvent(new CustomEvent(ev, { detail }))
      )
    );
    this.#slider = slider;
  }
  reset(options, effect) {
    this.slider?.reset(options, effect);
  }
  attributeChangedCallback(name) {
    if (SLIDER_ATTRIBUTES.includes(name)) {
      const propName = camelize(name);
      this.reset({ [propName]: this[propName] });
    }
  }
  disconnectedCallback() {
    this.slider?.destroy();
    this.#slider = void 0;
  }
};

// src/Carousel.ts
var CAROUSEL_ATTRIBUTES = ["cover", "timing-function"];
var Carousel = class extends Slider {
  static observedAttributes = [...SLIDER_ATTRIBUTES, ...CAROUSEL_ATTRIBUTES];
  get cover() {
    return getBbooleanAttribute(this, "cover", false);
  }
  get timingFunction() {
    return this.getAttribute("timing-function") || "ease-out";
  }
  connectedCallback() {
    this.init(
      new import_Carousel.default({
        cover: this.cover,
        timingFunction: this.timingFunction
      })
    );
  }
  attributeChangedCallback(name) {
    if (CAROUSEL_ATTRIBUTES.includes(name)) {
      const propName = camelize(name);
      this.reset(
        { [propName]: this[propName] },
        new import_Carousel.default({
          cover: this.cover,
          timingFunction: this.timingFunction
        })
      );
    } else {
      super.attributeChangedCallback(name);
    }
  }
};
if (typeof customElements !== "undefined") {
  customElements.define("bs-carousel", Carousel);
}

// src/Cube.ts
var import_Cube = __toESM(require("@boxslider/slider/effects/Cube"), 1);
var CUBE_ATTRIBUTES = ["direction", "perspective"];
var Cube = class extends Slider {
  static observedAttributes = [...SLIDER_ATTRIBUTES, ...CUBE_ATTRIBUTES];
  get direction() {
    const propDirection = this.getAttribute("direction")?.trim();
    if (propDirection === "horizontal" || propDirection === "vertical") {
      return propDirection;
    }
    return "horizontal";
  }
  get perspective() {
    return getNumericAttribute(this, "perspective", 1e3);
  }
  attributeChangedCallback(name) {
    if (CUBE_ATTRIBUTES.includes(name)) {
      const propName = camelize(name);
      this.reset(
        { [propName]: this[propName] },
        new import_Cube.default({
          direction: this.direction,
          perspective: this.perspective
        })
      );
    } else {
      super.attributeChangedCallback(name);
    }
  }
  connectedCallback() {
    this.init(
      new import_Cube.default({
        direction: this.direction,
        perspective: this.perspective
      })
    );
  }
};
if (typeof customElements !== "undefined") {
  customElements.define("bs-cube", Cube);
}

// src/Fade.ts
var import_Fade = __toESM(require("@boxslider/slider/effects/Fade"), 1);
var FADE_ATTRIBUTES = ["timing-function"];
var Fade = class extends Slider {
  static observedAttributes = [...SLIDER_ATTRIBUTES, ...FADE_ATTRIBUTES];
  get timingFunction() {
    return this.getAttribute("timing-function")?.trim() || "ease-in-out";
  }
  attributeChangedCallback(name) {
    if (FADE_ATTRIBUTES.includes(name)) {
      const propName = camelize(name);
      this.reset(
        { [propName]: this[propName] },
        new import_Fade.default({
          timingFunction: this.timingFunction
        })
      );
    } else {
      super.attributeChangedCallback(name);
    }
  }
  connectedCallback() {
    this.init(
      new import_Fade.default({
        timingFunction: this.timingFunction
      })
    );
  }
};
if (typeof customElements !== "undefined") {
  customElements.define("bs-fade", Fade);
}

// src/Tile.ts
var import_Tile = __toESM(require("@boxslider/slider/effects/Tile"), 1);
var TILE_ATTRIBUTES = ["rows", "row-offset", "tile-effect"];
var Tile = class extends Slider {
  static observedAttributes = [...SLIDER_ATTRIBUTES, ...TILE_ATTRIBUTES];
  get rows() {
    return getNumericAttribute(this, "rows", 8);
  }
  get rowOffset() {
    return getNumericAttribute(this, "row-offset", 50);
  }
  get tileEffect() {
    return this.getAttribute("tile-effect") || "fade";
  }
  attributeChangedCallback(name) {
    if (TILE_ATTRIBUTES.includes(name)) {
      const propName = camelize(name);
      this.reset(
        { [propName]: this[propName] },
        new import_Tile.default({
          rows: this.rows,
          rowOffset: this.rowOffset,
          tileEffect: this.tileEffect
        })
      );
    } else {
      super.attributeChangedCallback(name);
    }
  }
  connectedCallback() {
    this.init(
      new import_Tile.default({
        rows: this.rows,
        rowOffset: this.rowOffset,
        tileEffect: this.tileEffect
      })
    );
  }
};
if (typeof customElements !== "undefined") {
  customElements.define("bs-tile", Tile);
}

// src/SliderControls.ts
var template = document.createElement("template");
template.innerHTML = `
<div part="container">
  <div part="slider">
    <slot id="slider"></slot>
  </div>

  <div part="controls">
    <slot name="prev-btn">
      <button part="prev-btn nav-btn" type="button" aria-label="Previous"></button>
    </slot>
    <slot name="next-btn">
      <button part="next-btn nav-btn" type="button" aria-label="Next"></button>
    </slot>
  </div>

  <slot name="index" part="index"></slot>
</div>
`;
var incrementingId = 1;
var SliderControls = class extends HTMLElement {
  #slider;
  connectedCallback() {
    this.setAttribute("aria-roledescription", "carousel");
    const shadow = this.attachShadow({ mode: "open" });
    const tree = template.content.cloneNode(true);
    const sliderSlot = tree.querySelector("#slider");
    sliderSlot?.addEventListener("slotchange", () => {
      const sliderComponent = sliderSlot.assignedElements()[0];
      if (!sliderComponent.id) {
        sliderComponent.id = `bs-slider-${incrementingId++}`;
      }
      this.#slider = sliderComponent?.slider;
      this.#slider?.addEventListener("after", ({ currentIndex }) => {
        indexSlot?.querySelectorAll("button").forEach((b, index) => {
          const isActive = index === currentIndex;
          b.setAttribute("aria-pressed", isActive ? "true" : "false");
          b.setAttribute("part", isActive ? "index-btn active" : "index-btn");
        });
      });
      const indexSlot = shadow.querySelector('slot[name="index"]');
      const slides = Array.from(this.#slider?.el.children || []).filter(
        (el) => el instanceof HTMLElement
      );
      if (slides.length > 1) {
        const frag = document.createDocumentFragment();
        for (let i = 0; i < slides.length; i++) {
          const btn = document.createElement("button");
          btn.setAttribute("aria-label", `View slide ${i + 1}`);
          btn.setAttribute(
            "part",
            i === this.#slider?.activeIndex ? "index-btn active" : "index-btn"
          );
          btn.setAttribute("type", "button");
          btn.setAttribute("aria-controls", sliderComponent.id);
          btn.addEventListener("click", () => {
            this.#slider?.skipTo(i).then();
          });
          frag.appendChild(btn);
        }
        indexSlot?.appendChild(frag);
      }
      indexSlot?.addEventListener("slotchange", () => {
        const index = indexSlot.assignedElements()[0];
        if (index.hasChildNodes()) {
          index.childNodes.forEach((node, index2) => {
            node.addEventListener("click", () => this.#slider?.skipTo(index2));
          });
        }
      });
    });
    const prevBtnSlot = tree.querySelector(
      'slot[name="prev-btn"]'
    );
    prevBtnSlot?.querySelector("button")?.addEventListener("click", () => this.#slider?.prev());
    prevBtnSlot?.addEventListener("slotchange", () => {
      const button = prevBtnSlot.assignedElements()[0];
      button?.addEventListener("click", () => {
        this.#slider?.prev();
      });
    });
    const nextBtnSlot = tree.querySelector(
      'slot[name="next-btn"]'
    );
    nextBtnSlot?.querySelector("button")?.addEventListener("click", () => this.#slider?.next());
    nextBtnSlot?.addEventListener("slotchange", () => {
      const button = nextBtnSlot.assignedElements()[0];
      button?.addEventListener("click", () => {
        this.#slider?.next();
      });
    });
    shadow.appendChild(tree);
  }
  disconnectedCallback() {
    this.#slider = void 0;
  }
};
if (typeof customElements !== "undefined") {
  customElements.define("bs-slider-controls", SliderControls);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Carousel,
  Cube,
  Fade,
  SliderControls,
  Tile
});
