"use strict";
var _ = Object.defineProperty;
var he = Object.getOwnPropertyDescriptor;
var ge = Object.getOwnPropertyNames;
var fe = Object.prototype.hasOwnProperty;
var d = (t, e) => _(t, "name", { value: e, configurable: !0 });
var ye = (t, e) => {
  for (var l in e)
    _(t, l, { get: e[l], enumerable: !0 });
}, be = (t, e, l, c) => {
  if (e && typeof e == "object" || typeof e == "function")
    for (let r of ge(e))
      !fe.call(t, r) && r !== l && _(t, r, { get: () => e[r], enumerable: !(c = he(e, r)) || c.enumerable });
  return t;
};
var xe = (t) => be(_({}, "__esModule", { value: !0 }), t);

// src/highlight/preview.ts
var Me = {};
ye(Me, {
  default: () => He
});
module.exports = xe(Me);
var ae = require("storybook/internal/csf"), Z = require("storybook/preview-api");

// src/highlight/useHighlights.ts
var ce = require("storybook/internal/core-events");

// src/highlight/constants.ts
var R = "storybook/highlight", J = `${R}/add`, Q = `${R}/remove`, ee = `${R}/reset`, te = `${R}/scroll-into-view`, G = 2147483647, L = 28;

// src/highlight/icons.ts
var z = {
  chevronLeft: [
    "M9.10355 10.1464C9.29882 10.3417 9.29882 10.6583 9.10355 10.8536C8.90829 11.0488 8.59171 11.0488 8.39645 10.8536L4.89645 7.35355C4.7011\
8 7.15829 4.70118 6.84171 4.89645 6.64645L8.39645 3.14645C8.59171 2.95118 8.90829 2.95118 9.10355 3.14645C9.29882 3.34171 9.29882 3.65829 9.\
10355 3.85355L5.95711 7L9.10355 10.1464Z"
  ],
  chevronRight: [
    "M4.89645 10.1464C4.70118 10.3417 4.70118 10.6583 4.89645 10.8536C5.09171 11.0488 5.40829 11.0488 5.60355 10.8536L9.10355 7.35355C9.2988\
2 7.15829 9.29882 6.84171 9.10355 6.64645L5.60355 3.14645C5.40829 2.95118 5.09171 2.95118 4.89645 3.14645C4.70118 3.34171 4.70118 3.65829 4.\
89645 3.85355L8.04289 7L4.89645 10.1464Z"
  ],
  info: [
    "M7 5.5a.5.5 0 01.5.5v4a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zM7 4.5A.75.75 0 107 3a.75.75 0 000 1.5z",
    "M7 14A7 7 0 107 0a7 7 0 000 14zm0-1A6 6 0 107 1a6 6 0 000 12z"
  ],
  shareAlt: [
    "M2 1.004a1 1 0 00-1 1v10a1 1 0 001 1h10a1 1 0 001-1v-4.5a.5.5 0 00-1 0v4.5H2v-10h4.5a.5.5 0 000-1H2z",
    "M7.354 7.357L12 2.711v1.793a.5.5 0 001 0v-3a.5.5 0 00-.5-.5h-3a.5.5 0 100 1h1.793L6.646 6.65a.5.5 0 10.708.707z"
  ]
};

// src/highlight/utils.ts
var Ee = "svg,path,rect,circle,line,polyline,polygon,ellipse,text".split(","), b = /* @__PURE__ */ d((t, e = {}, l) => {
  let c = Ee.includes(t) ? document.createElementNS("http://www.w3.org/2000/svg", t) : document.createElement(t);
  return Object.entries(e).forEach(([r, p]) => {
    /[A-Z]/.test(r) ? (r === "onClick" && (c.addEventListener("click", p), c.addEventListener("keydown", (u) => {
      (u.key === "Enter" || u.key === " ") && (u.preventDefault(), p());
    })), r === "onMouseEnter" && c.addEventListener("mouseenter", p), r === "onMouseLeave" && c.addEventListener("mouseleave", p)) : c.setAttribute(
    r, p);
  }), l?.forEach((r) => {
    if (!(r == null || r === !1))
      try {
        c.appendChild(r);
      } catch {
        c.appendChild(document.createTextNode(String(r)));
      }
  }), c;
}, "createElement"), k = /* @__PURE__ */ d((t) => z[t] && b(
  "svg",
  { width: "14", height: "14", viewBox: "0 0 14 14", xmlns: "http://www.w3.org/2000/svg" },
  z[t].map(
    (e) => b("path", {
      fill: "currentColor",
      "fill-rule": "evenodd",
      "clip-rule": "evenodd",
      d: e
    })
  )
), "createIcon"), oe = /* @__PURE__ */ d((t) => {
  if ("elements" in t) {
    let { elements: c, color: r, style: p } = t;
    return {
      id: void 0,
      priority: 0,
      selectors: c,
      styles: {
        outline: `2px ${p} ${r}`,
        outlineOffset: "2px",
        boxShadow: "0 0 0 6px rgba(255,255,255,0.6)"
      },
      menu: void 0
    };
  }
  let { menu: e, ...l } = t;
  return {
    id: void 0,
    priority: 0,
    styles: {
      outline: "2px dashed #029cfd"
    },
    ...l,
    menu: Array.isArray(e) ? e.every(Array.isArray) ? e : [e] : void 0
  };
}, "normalizeOptions"), we = /* @__PURE__ */ d((t) => t instanceof Function, "isFunction"), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(),
D = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ d((t) => {
  let e = Symbol();
  return C.set(e, []), S.set(e, t), { get: /* @__PURE__ */ d(() => S.get(e), "get"), set: /* @__PURE__ */ d((u) => {
    let m = S.get(e), f = we(u) ? u(m) : u;
    f !== m && (S.set(e, f), C.get(e)?.forEach((E) => {
      D.get(E)?.(), D.set(E, E(f));
    }));
  }, "set"), subscribe: /* @__PURE__ */ d((u) => (C.get(e)?.push(u), () => {
    let m = C.get(e);
    m && C.set(
      e,
      m.filter((f) => f !== u)
    );
  }), "subscribe"), teardown: /* @__PURE__ */ d(() => {
    C.get(e)?.forEach((u) => {
      D.get(u)?.(), D.delete(u);
    }), C.delete(e), S.delete(e);
  }, "teardown") };
}, "useStore"), P = /* @__PURE__ */ d((t) => {
  let e = document.getElementById("storybook-root"), l = /* @__PURE__ */ new Map();
  for (let c of t) {
    let { priority: r = 0 } = c;
    for (let p of c.selectors) {
      let u = [
        ...document.querySelectorAll(
          // Elements matching the selector, excluding storybook elements and their descendants.
          // Necessary to find portaled elements (e.g. children of `body`).
          `:is(${p}):not([id^="storybook-"], [id^="storybook-"] *, [class^="sb-"], [class^="sb-"] *)`
        ),
        // Elements matching the selector inside the storybook root, as these were excluded above.
        ...e?.querySelectorAll(p) || []
      ];
      for (let m of u) {
        let f = l.get(m);
        (!f || f.priority <= r) && l.set(m, {
          ...c,
          priority: r,
          selectors: Array.from(new Set((f?.selectors || []).concat(p)))
        });
      }
    }
  }
  return l;
}, "mapElements"), ne = /* @__PURE__ */ d((t) => Array.from(t.entries()).map(([e, { selectors: l, styles: c, hoverStyles: r, focusStyles: p,
menu: u }]) => {
  let { top: m, left: f, width: E, height: w } = e.getBoundingClientRect(), { position: v } = getComputedStyle(e);
  return {
    element: e,
    selectors: l,
    styles: c,
    hoverStyles: r,
    focusStyles: p,
    menu: u,
    top: v === "fixed" ? m : m + window.scrollY,
    left: v === "fixed" ? f : f + window.scrollX,
    width: E,
    height: w
  };
}).sort((e, l) => l.width * l.height - e.width * e.height), "mapBoxes"), X = /* @__PURE__ */ d((t, e) => {
  let l = t.getBoundingClientRect(), { x: c, y: r } = e;
  return l?.top && l?.left && c >= l.left && c <= l.left + l.width && r >= l.top && r <= l.top + l.height;
}, "isOverMenu"), V = /* @__PURE__ */ d((t, e, l) => {
  if (!e || !l)
    return !1;
  let { left: c, top: r, width: p, height: u } = t;
  u < L && (r = r - Math.round((L - u) / 2), u = L), p < L && (c = c - Math.round((L - p) / 2), p = L), e.style.position === "fixed" && (c +=
  window.scrollX, r += window.scrollY);
  let { x: m, y: f } = l;
  return m >= c && m <= c + p && f >= r && f <= r + u;
}, "isTargeted"), se = /* @__PURE__ */ d((t, e, l = {}) => {
  let { x: c, y: r } = e, { margin: p = 5, topOffset: u = 0, centered: m = !1 } = l, { scrollX: f, scrollY: E, innerHeight: w, innerWidth: v } = window,
  I = Math.min(
    t.style.position === "fixed" ? r - E : r,
    w - t.clientHeight - p - u + E
  ), H = m ? t.clientWidth / 2 : 0, A = t.style.position === "fixed" ? Math.max(Math.min(c - f, v - H - p), H + p) : Math.max(
    Math.min(c, v - H - p + f),
    H + p + f
  );
  Object.assign(t.style, {
    ...A !== c && { left: `${A}px` },
    ...I !== r && { top: `${I}px` }
  });
}, "keepInViewport"), Y = /* @__PURE__ */ d((t) => {
  window.HTMLElement.prototype.hasOwnProperty("showPopover") && t.showPopover();
}, "showPopover"), ie = /* @__PURE__ */ d((t) => {
  window.HTMLElement.prototype.hasOwnProperty("showPopover") && t.hidePopover();
}, "hidePopover"), re = /* @__PURE__ */ d((t) => ({
  top: t.top,
  left: t.left,
  width: t.width,
  height: t.height,
  selectors: t.selectors,
  element: {
    attributes: Object.fromEntries(
      Array.from(t.element.attributes).map((e) => [e.name, e.value])
    ),
    localName: t.element.localName,
    tagName: t.element.tagName,
    outerHTML: t.element.outerHTML
  }
}), "getEventDetails");

// src/highlight/useHighlights.ts
var g = "storybook-highlights-menu", le = "storybook-highlights-root", ve = "storybook-root", de = /* @__PURE__ */ d((t) => {
  if (globalThis.__STORYBOOK_HIGHLIGHT_INITIALIZED)
    return;
  globalThis.__STORYBOOK_HIGHLIGHT_INITIALIZED = !0;
  let { document: e } = globalThis, l = T([]), c = T(/* @__PURE__ */ new Map()), r = T([]), p = T(), u = T(), m = T([]), f = T([]), E = T(),
  w = T(), v = e.getElementById(le);
  l.subscribe(() => {
    v || (v = b("div", { id: le }), e.body.appendChild(v));
  }), l.subscribe((s) => {
    let o = e.getElementById(ve);
    if (!o)
      return;
    c.set(P(s));
    let n = new MutationObserver(() => c.set(P(s)));
    return n.observe(o, { subtree: !0, childList: !0 }), () => {
      n.disconnect();
    };
  }), c.subscribe((s) => {
    let o = /* @__PURE__ */ d(() => requestAnimationFrame(() => r.set(ne(s))), "updateBoxes"), n = new ResizeObserver(o);
    n.observe(e.body), Array.from(s.keys()).forEach((i) => n.observe(i));
    let a = Array.from(e.body.querySelectorAll("*")).filter((i) => {
      let { overflow: h, overflowX: x, overflowY: y } = window.getComputedStyle(i);
      return ["auto", "scroll"].some((M) => [h, x, y].includes(M));
    });
    return a.forEach((i) => i.addEventListener("scroll", o)), () => {
      n.disconnect(), a.forEach((i) => i.removeEventListener("scroll", o));
    };
  }), c.subscribe((s) => {
    let o = Array.from(s.keys()).filter(({ style: a }) => a.position === "sticky"), n = /* @__PURE__ */ d(() => requestAnimationFrame(() => {
      r.set(
        (a) => a.map((i) => {
          if (o.includes(i.element)) {
            let { top: h, left: x } = i.element.getBoundingClientRect();
            return { ...i, top: h + window.scrollY, left: x + window.scrollX };
          }
          return i;
        })
      );
    }), "updateBoxes");
    return e.addEventListener("scroll", n), () => e.removeEventListener("scroll", n);
  }), c.subscribe((s) => {
    m.set((o) => o.filter(({ element: n }) => s.has(n)));
  }), m.subscribe((s) => {
    s.length ? (w.set((o) => s.some((n) => n.element === o?.element) ? o : void 0), E.set((o) => s.some((n) => n.element === o?.element) ? o :
    void 0)) : (w.set(void 0), E.set(void 0), p.set(void 0));
  });
  let I = new Map(/* @__PURE__ */ new Map());
  l.subscribe((s) => {
    s.forEach(({ keyframes: o }) => {
      if (o) {
        let n = I.get(o);
        n || (n = e.createElement("style"), n.setAttribute("data-highlight", "keyframes"), I.set(o, n), e.head.appendChild(n)), n.innerHTML =
        o;
      }
    }), I.forEach((o, n) => {
      s.some((a) => a.keyframes === n) || (o.remove(), I.delete(n));
    });
  });
  let H = new Map(/* @__PURE__ */ new Map());
  r.subscribe((s) => {
    s.forEach((o) => {
      let n = H.get(o.element);
      if (v && !n) {
        let a = {
          popover: "manual",
          "data-highlight-dimensions": `w${o.width.toFixed(0)}h${o.height.toFixed(0)}`,
          "data-highlight-coordinates": `x${o.left.toFixed(0)}y${o.top.toFixed(0)}`
        };
        n = v.appendChild(
          b("div", a, [b("div")])
        ), H.set(o.element, n);
      }
    }), H.forEach((o, n) => {
      s.some(({ element: a }) => a === n) || (o.remove(), H.delete(n));
    });
  }), r.subscribe((s) => {
    let o = s.filter((a) => a.menu);
    if (!o.length)
      return;
    let n = /* @__PURE__ */ d((a) => {
      requestAnimationFrame(() => {
        let i = e.getElementById(g), h = { x: a.pageX, y: a.pageY };
        if (i && !X(i, h)) {
          let x = o.filter((y) => {
            let M = H.get(y.element);
            return V(y, M, h);
          });
          p.set(x.length ? h : void 0), m.set(x);
        }
      });
    }, "onClick");
    return e.addEventListener("click", n), () => e.removeEventListener("click", n);
  });
  let A = /* @__PURE__ */ d(() => {
    let s = e.getElementById(g), o = u.get();
    !o || s && X(s, o) || f.set((n) => {
      let a = r.get().filter((y) => {
        let M = H.get(y.element);
        return V(y, M, o);
      }), i = n.filter((y) => a.includes(y)), h = a.filter((y) => !n.includes(y)), x = n.length - i.length;
      return h.length || x ? [...i, ...h] : n;
    });
  }, "updateHovered");
  u.subscribe(A), r.subscribe(A);
  let $ = /* @__PURE__ */ d(() => {
    let s = w.get(), o = s ? [s] : m.get(), n = o.length === 1 ? o[0] : E.get(), a = p.get() !== void 0;
    r.get().forEach((i) => {
      let h = H.get(i.element);
      if (h) {
        let x = n === i, y = a ? n ? x : o.includes(i) : f.get()?.includes(i);
        Object.assign(h.style, {
          animation: "none",
          background: "transparent",
          border: "none",
          boxSizing: "border-box",
          outline: "none",
          outlineOffset: "0px",
          ...i.styles,
          ...y ? i.hoverStyles : {},
          ...x ? i.focusStyles : {},
          position: getComputedStyle(i.element).position === "fixed" ? "fixed" : "absolute",
          zIndex: G - 10,
          top: `${i.top}px`,
          left: `${i.left}px`,
          width: `${i.width}px`,
          height: `${i.height}px`,
          margin: 0,
          padding: 0,
          cursor: i.menu && y ? "pointer" : "default",
          pointerEvents: i.menu ? "auto" : "none",
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          overflow: "visible"
        }), Object.assign(h.children[0].style, {
          width: "100%",
          height: "100%",
          minHeight: `${L}px`,
          minWidth: `${L}px`,
          boxSizing: "content-box",
          padding: h.style.outlineWidth || "0px"
        }), Y(h);
      }
    });
  }, "updateBoxStyles");
  r.subscribe($), m.subscribe($), f.subscribe($), E.subscribe($), w.subscribe($);
  let j = /* @__PURE__ */ d(() => {
    if (!v)
      return;
    let s = e.getElementById(g);
    if (s)
      s.innerHTML = "";
    else {
      let i = { id: g, popover: "manual" };
      s = v.appendChild(b("div", i)), v.appendChild(
        b("style", {}, [
          `
            #${g} {
              position: absolute;
              z-index: ${G};
              width: 300px;
              padding: 0px;
              margin: 15px 0 0 0;
              transform: translateX(-50%);
              font-family: "Nunito Sans", -apple-system, ".SFNSText-Regular", "San Francisco", BlinkMacSystemFont, "Segoe UI", "Helvetica Ne\
ue", Helvetica, Arial, sans-serif;
              font-size: 12px;
              background: white;
              border: none;
              border-radius: 6px;
              box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.05), 0 5px 15px 0 rgba(0, 0, 0, 0.1);
              color: #2E3438;
            }
            #${g} ul {
              list-style: none;
              margin: 0;
              padding: 0;
            }
            #${g} > ul {
              max-height: 300px;
              overflow-y: auto;
              padding: 4px 0;
            }
            #${g} li {
              padding: 0 4px;
              margin: 0;
            }
            #${g} li > :not(ul) {
              display: flex;
              padding: 8px;
              margin: 0;
              align-items: center;
              gap: 8px;
              border-radius: 4px;
            }
            #${g} button {
              width: 100%;
              border: 0;
              background: transparent;
              color: inherit;
              text-align: left;
              font-family: inherit;
              font-size: inherit;
            }
            #${g} button:focus-visible {
              outline-color: #029CFD;
            }
            #${g} button:hover {
              background: rgba(2, 156, 253, 0.07);
              color: #029CFD;
              cursor: pointer;
            }
            #${g} li code {
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
              line-height: 16px;
              font-size: 11px;
            }
            #${g} li svg {
              flex-shrink: 0;
              margin: 1px;
              color: #73828C;
            }
            #${g} li > button:hover svg, #${g} li > button:focus-visible svg {
              color: #029CFD;
            }
            #${g} .element-list li svg {
              display: none;
            }
            #${g} li.selectable svg, #${g} li.selected svg {
              display: block;
            }
            #${g} .menu-list {
              border-top: 1px solid rgba(38, 85, 115, 0.15);
            }
            #${g} .menu-list > li:not(:last-child) {
              padding-bottom: 4px;
              margin-bottom: 4px;
              border-bottom: 1px solid rgba(38, 85, 115, 0.15);
            }
            #${g} .menu-items, #${g} .menu-items li {
              padding: 0;
            }
            #${g} .menu-item {
              display: flex;
            }
            #${g} .menu-item-content {
              display: flex;
              flex-direction: column;
              flex-grow: 1;
            }
          `
        ])
      );
    }
    let o = w.get(), n = o ? [o] : m.get();
    if (n.length && (s.style.position = getComputedStyle(n[0].element).position === "fixed" ? "fixed" : "absolute", s.appendChild(
      b(
        "ul",
        { class: "element-list" },
        n.map((i) => {
          let h = n.length > 1 && !!i.menu?.some(
            (M) => M.some(
              (O) => !O.selectors || O.selectors.some((B) => i.selectors.includes(B))
            )
          ), x = h ? {
            class: "selectable",
            onClick: /* @__PURE__ */ d(() => w.set(i), "onClick"),
            onMouseEnter: /* @__PURE__ */ d(() => E.set(i), "onMouseEnter"),
            onMouseLeave: /* @__PURE__ */ d(() => E.set(void 0), "onMouseLeave")
          } : o ? { class: "selected", onClick: /* @__PURE__ */ d(() => w.set(void 0), "onClick") } : {}, y = h || o;
          return b("li", x, [
            b(y ? "button" : "div", y ? { type: "button" } : {}, [
              o ? k("chevronLeft") : null,
              b("code", {}, [i.element.outerHTML]),
              h ? k("chevronRight") : null
            ])
          ]);
        })
      )
    )), w.get() || m.get().length === 1) {
      let i = w.get() || m.get()[0], h = i.menu?.filter(
        (x) => x.some(
          (y) => !y.selectors || y.selectors.some((M) => i.selectors.includes(M))
        )
      );
      h?.length && s.appendChild(
        b(
          "ul",
          { class: "menu-list" },
          h.map(
            (x) => b("li", {}, [
              b(
                "ul",
                { class: "menu-items" },
                x.map(
                  ({ id: y, title: M, description: O, iconLeft: B, iconRight: U, clickEvent: K }) => {
                    let F = K && (() => t.emit(K, y, re(i)));
                    return b("li", {}, [
                      b(
                        F ? "button" : "div",
                        F ? { class: "menu-item", type: "button", onClick: F } : { class: "menu-item" },
                        [
                          B ? k(B) : null,
                          b("div", { class: "menu-item-content" }, [
                            b(O ? "strong" : "span", {}, [M]),
                            O && b("span", {}, [O])
                          ]),
                          U ? k(U) : null
                        ]
                      )
                    ]);
                  }
                )
              )
            ])
          )
        )
      );
    }
    let a = p.get();
    a ? (Object.assign(s.style, {
      display: "block",
      left: `${s.style.position === "fixed" ? a.x - window.scrollX : a.x}px`,
      top: `${s.style.position === "fixed" ? a.y - window.scrollY : a.y}px`
    }), Y(s), requestAnimationFrame(() => se(s, a, { topOffset: 15, centered: !0 }))) : (ie(s), Object.assign(s.style, { display: "none" }));
  }, "renderMenu");
  m.subscribe(j), w.subscribe(j);
  let pe = /* @__PURE__ */ d((s) => {
    let o = oe(s);
    l.set((n) => {
      let a = o.id ? n.filter((i) => i.id !== o.id) : n;
      return o.selectors?.length ? [...a, o] : a;
    });
  }, "addHighlight"), N = /* @__PURE__ */ d((s) => {
    s && l.set((o) => o.filter((n) => n.id !== s));
  }, "removeHighlight"), q = /* @__PURE__ */ d(() => {
    l.set([]), c.set(/* @__PURE__ */ new Map()), r.set([]), p.set(void 0), u.set(void 0), m.set([]), f.set([]), E.set(void 0), w.set(void 0);
  }, "resetState"), W, ue = /* @__PURE__ */ d((s, o) => {
    let n = "scrollIntoView-highlight";
    clearTimeout(W), N(n);
    let a = e.querySelector(s);
    if (!a) {
      console.warn(`Cannot scroll into view: ${s} not found`);
      return;
    }
    a.scrollIntoView({ behavior: "smooth", block: "center", ...o });
    let i = `kf-${Math.random().toString(36).substring(2, 15)}`;
    l.set((h) => [
      ...h,
      {
        id: n,
        priority: 1e3,
        selectors: [s],
        styles: {
          outline: "2px solid #1EA7FD",
          outlineOffset: "-1px",
          animation: `${i} 3s linear forwards`
        },
        keyframes: `@keyframes ${i} {
          0% { outline: 2px solid #1EA7FD; }
          20% { outline: 2px solid #1EA7FD00; }
          40% { outline: 2px solid #1EA7FD; }
          60% { outline: 2px solid #1EA7FD00; }
          80% { outline: 2px solid #1EA7FD; }
          100% { outline: 2px solid #1EA7FD00; }
        }`
      }
    ]), W = setTimeout(() => N(n), 3500);
  }, "scrollIntoView"), me = /* @__PURE__ */ d((s) => {
    requestAnimationFrame(() => u.set({ x: s.pageX, y: s.pageY }));
  }, "onMouseMove");
  e.body.addEventListener("mousemove", me), t.on(J, pe), t.on(Q, N), t.on(ee, q), t.on(te, ue), t.on(ce.STORY_RENDER_PHASE_CHANGED, ({ newPhase: s }) => {
    s === "loading" && q();
  });
}, "useHighlights");

// src/highlight/preview.ts
globalThis?.FEATURES?.highlight && Z.addons?.ready && Z.addons.ready().then(de);
var He = /* @__PURE__ */ d(() => (0, ae.definePreviewAddon)({}), "default");
