"use strict";
var b = Object.defineProperty;
var U = Object.getOwnPropertyDescriptor;
var Y = Object.getOwnPropertyNames;
var j = Object.prototype.hasOwnProperty;
var s = (e, t) => b(e, "name", { value: t, configurable: !0 });
var V = (e, t) => {
  for (var n in t)
    b(e, n, { get: t[n], enumerable: !0 });
}, X = (e, t, n, o) => {
  if (t && typeof t == "object" || typeof t == "function")
    for (let r of Y(t))
      !j.call(e, r) && r !== n && b(e, r, { get: () => t[r], enumerable: !(o = U(t, r)) || o.enumerable });
  return e;
};
var q = (e) => X(b({}, "__esModule", { value: !0 }), e);

// src/backgrounds/index.ts
var nt = {};
V(nt, {
  default: () => ot
});
module.exports = q(nt);

// src/backgrounds/preview.ts
var F = require("storybook/preview-api");

// src/backgrounds/constants.ts
var J = "storybook/background", c = "backgrounds";
var st = {
  UPDATE: `${J}/update`
};

// src/backgrounds/decorator.ts
var E = require("storybook/preview-api");

// src/backgrounds/defaults.ts
var D = {
  light: { name: "light", value: "#F8F8F8" },
  dark: { name: "dark", value: "#333" }
};

// src/backgrounds/utils.ts
var { document: a } = globalThis, _ = /* @__PURE__ */ s(() => globalThis?.matchMedia ? !!globalThis.matchMedia("(prefers-reduced-motion: red\
uce)")?.matches : !1, "isReduceMotionEnabled"), S = /* @__PURE__ */ s((e) => {
  (Array.isArray(e) ? e : [e]).forEach(Q);
}, "clearStyles"), Q = /* @__PURE__ */ s((e) => {
  if (!a)
    return;
  let t = a.getElementById(e);
  t && t.parentElement && t.parentElement.removeChild(t);
}, "clearStyle"), L = /* @__PURE__ */ s((e, t) => {
  if (!a)
    return;
  let n = a.getElementById(e);
  if (n)
    n.innerHTML !== t && (n.innerHTML = t);
  else {
    let o = a.createElement("style");
    o.setAttribute("id", e), o.innerHTML = t, a.head.appendChild(o);
  }
}, "addGridStyle"), v = /* @__PURE__ */ s((e, t, n) => {
  if (!a)
    return;
  let o = a.getElementById(e);
  if (o)
    o.innerHTML !== t && (o.innerHTML = t);
  else {
    let r = a.createElement("style");
    r.setAttribute("id", e), r.innerHTML = t;
    let d = `addon-backgrounds-grid${n ? `-docs-${n}` : ""}`, l = a.getElementById(d);
    l ? l.parentElement?.insertBefore(r, l) : a.head.appendChild(r);
  }
}, "addBackgroundStyle");

// src/backgrounds/decorator.ts
var W = {
  cellSize: 100,
  cellAmount: 10,
  opacity: 0.8
}, C = "addon-backgrounds", w = "addon-backgrounds-grid", Z = _() ? "" : "transition: background-color 0.3s;", I = /* @__PURE__ */ s((e, t) => {
  let { globals: n = {}, parameters: o = {}, viewMode: r, id: d } = t, {
    options: l = D,
    disable: K,
    grid: O = W
  } = o[c] || {}, p = n[c] || {}, A = typeof p == "string" ? p : p?.value, y = A ? l[A] : void 0, B = typeof y == "string" ? y : y?.value ||
  "transparent", h = typeof p == "string" ? !1 : p.grid || !1, M = !!y && !K, G = r === "docs" ? `#anchor--${d} .docs-story` : ".sb-show-mai\
n", T = r === "docs" ? `#anchor--${d} .docs-story` : ".sb-show-main", z = o.layout === void 0 || o.layout === "padded", R = r === "docs" ? 20 :
  z ? 16 : 0, { cellAmount: g, cellSize: i, opacity: u, offsetX: m = R, offsetY: f = R } = O, x = r === "docs" ? `${C}-docs-${d}` : `${C}-co\
lor`, P = r === "docs" ? d : null;
  (0, E.useEffect)(() => {
    let k = `
    ${G} {
      background: ${B} !important;
      ${Z}
      }`;
    if (!M) {
      S(x);
      return;
    }
    v(x, k, P);
  }, [G, x, P, M, B]);
  let $ = r === "docs" ? `${w}-docs-${d}` : `${w}`;
  return (0, E.useEffect)(() => {
    if (!h) {
      S($);
      return;
    }
    let k = [
      `${i * g}px ${i * g}px`,
      `${i * g}px ${i * g}px`,
      `${i}px ${i}px`,
      `${i}px ${i}px`
    ].join(", "), N = `
        ${T} {
          background-size: ${k} !important;
          background-position: ${m}px ${f}px, ${m}px ${f}px, ${m}px ${f}px, ${m}px ${f}px !important;
          background-blend-mode: difference !important;
          background-image: linear-gradient(rgba(130, 130, 130, ${u}) 1px, transparent 1px),
           linear-gradient(90deg, rgba(130, 130, 130, ${u}) 1px, transparent 1px),
           linear-gradient(rgba(130, 130, 130, ${u / 2}) 1px, transparent 1px),
           linear-gradient(90deg, rgba(130, 130, 130, ${u / 2}) 1px, transparent 1px) !important;
        }
      `;
    L($, N);
  }, [g, i, T, $, h, m, f, u]), e();
}, "withBackgroundAndGrid");

// src/backgrounds/preview.ts
var tt = [I], et = {
  [c]: {
    grid: {
      cellSize: 20,
      opacity: 0.5,
      cellAmount: 5
    },
    disable: !1
  }
}, rt = {
  [c]: { value: void 0, grid: !1 }
}, H = /* @__PURE__ */ s(() => (0, F.definePreview)({
  decorators: tt,
  parameters: et,
  initialGlobals: rt
}), "default");

// src/backgrounds/index.ts
var ot = H;
