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

// src/backgrounds/preview.ts
var nt = {};
j(nt, {
  default: () => rt
});
module.exports = X(nt);
var F = require("storybook/preview-api");

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

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

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

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

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

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