var O = Object.defineProperty;
var a = (e, t) => O(e, "name", { value: t, configurable: !0 });

// src/backgrounds/preview.ts
import { definePreview as j } from "storybook/preview-api";

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

// src/backgrounds/decorator.ts
import { useEffect as L } from "storybook/preview-api";

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

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

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

// src/backgrounds/preview.ts
var V = [w], X = {
  [c]: {
    grid: {
      cellSize: 20,
      opacity: 0.5,
      cellAmount: 5
    },
    disable: !1
  }
}, q = {
  [c]: { value: void 0, grid: !1 }
}, pt = /* @__PURE__ */ a(() => j({
  decorators: V,
  parameters: X,
  initialGlobals: q
}), "default");
export {
  pt as default
};
