var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  DEFAULT_EVENTS: () => DEFAULT_EVENTS,
  DEFAULT_URL: () => DEFAULT_URL,
  addCssClassName: () => addCssClassName,
  call: () => call,
  debounce: () => debounce,
  hasIntersectionObserver: () => hasIntersectionObserver,
  loadImage: () => loadImage,
  modeType: () => modeType,
  setImage: () => setImage,
  throttle: () => throttle
});
module.exports = __toCommonJS(stdin_exports);
const inBrowser = typeof window !== "undefined";
const DEFAULT_URL = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
const DEFAULT_EVENTS = [
  "scroll",
  "wheel",
  "resize",
  "mousewheel",
  "animationend",
  "transitionend",
  "touchmove"
];
const hasIntersectionObserver = inBrowser && "IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype;
const modeType = {
  event: "event",
  observer: "observer"
};
const call = (fn) => fn && fn();
function setImage(element, imagePath) {
  if (element instanceof HTMLIFrameElement || element instanceof HTMLImageElement || element instanceof HTMLMediaElement) {
    element.src = imagePath;
  } else {
    element.style.backgroundImage = `url('${imagePath}')`;
  }
}
function loadImage(imagePath) {
  return new Promise((resolve, reject) => {
    const img = new Image();
    img.onload = () => resolve(imagePath);
    img.onerror = (err) => reject(err);
    img.src = imagePath;
  });
}
function addCssClassName(element, cssClassName) {
  if (!element.className.includes(cssClassName)) {
    element.className += ` ${cssClassName}`;
  }
}
function throttle(fn, threshold = 250, scope) {
  let last;
  let deferTimer;
  return () => {
    const context = scope || this;
    const now = +/* @__PURE__ */ new Date();
    const args = arguments;
    if (last && now < last + threshold) {
      clearTimeout(deferTimer);
      deferTimer = setTimeout(() => {
        last = now;
        fn.apply(context, args);
      }, threshold);
    } else {
      last = now;
      fn.apply(context, args);
    }
  };
}
function debounce(func, wait, immediate) {
  let timeout;
  let args;
  let context;
  let timestamp;
  let result;
  const later = function later2() {
    const last = +/* @__PURE__ */ new Date() - timestamp;
    if (last < wait && last >= 0) {
      timeout = setTimeout(later2, wait - last);
    } else {
      timeout = null;
      if (!immediate) {
        result = func.apply(context, args);
        if (!timeout) {
          context = null;
          args = null;
        }
      }
    }
  };
  return function debounced() {
    context = this;
    args = arguments;
    timestamp = +/* @__PURE__ */ new Date();
    const callNow = immediate && !timeout;
    if (!timeout) {
      timeout = setTimeout(later, wait);
    }
    if (callNow) {
      result = func.apply(context, args);
      context = null;
      args = null;
    }
    return result;
  };
}
