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

// src/highlight/preview.ts
var ve = {};
he(ve, {
  default: () => Ee
});
module.exports = ye(ve);
var S = require("storybook/preview-api");

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

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

// src/highlight/icons.ts
var P = {
  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 be = "svg,path,rect,circle,line,polyline,polygon,ellipse,text".split(","), b = /* @__PURE__ */ d((t, e, l) => {
  let c = be.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"), A = /* @__PURE__ */ d((t) => P[t] && b(
  "svg",
  { width: "14", height: "14", viewBox: "0 0 14 14", xmlns: "http://www.w3.org/2000/svg" },
  P[t].map(
    (e) => b("path", {
      fill: "currentColor",
      "fill-rule": "evenodd",
      "clip-rule": "evenodd",
      d: e
    })
  )
), "createIcon"), te = /* @__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"), xe = /* @__PURE__ */ d((t) => t instanceof Function, "isFunction"), k = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(),
F = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ d((t) => {
  let e = Symbol();
  return I.set(e, []), k.set(e, t), { get: /* @__PURE__ */ d(() => k.get(e), "get"), set: /* @__PURE__ */ d((u) => {
    let m = k.get(e), h = xe(u) ? u(m) : u;
    h !== m && (k.set(e, h), I.get(e)?.forEach((w) => {
      F.get(w)?.(), F.set(w, w(h));
    }));
  }, "set"), subscribe: /* @__PURE__ */ d((u) => (I.get(e)?.push(u), () => {
    let m = I.get(e);
    m && I.set(
      e,
      m.filter((h) => h !== u)
    );
  }), "subscribe"), teardown: /* @__PURE__ */ d(() => {
    I.get(e)?.forEach((u) => {
      F.get(u)?.(), F.delete(u);
    }), I.delete(e), k.delete(e);
  }, "teardown") };
}, "useStore"), z = /* @__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 h = l.get(m);
        (!h || h.priority <= r) && l.set(m, {
          ...c,
          priority: r,
          selectors: Array.from(new Set((h?.selectors || []).concat(p)))
        });
      }
    }
  }
  return l;
}, "mapElements"), oe = /* @__PURE__ */ d((t) => Array.from(t.entries()).map(([e, { selectors: l, styles: c, hoverStyles: r, focusStyles: p,
menu: u }]) => {
  let { top: m, left: h, width: w, height: E } = 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" ? h : h + window.scrollX,
    width: w,
    height: E
  };
}).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 === 0 || p === 0) && (c -= 10, r -= 10, p += 20, u += 20), e.style.position === "fixed" && (c += window.scrollX, r += window.scrollY);
  let { x: m, y: h } = l;
  return m >= c && m <= c + p && h >= r && h <= r + u;
}, "isTargeted"), ne = /* @__PURE__ */ d((t, e, l = {}) => {
  let { x: c, y: r } = e, { margin: p = 5, topOffset: u = 0, centered: m = !1 } = l, { scrollX: h, scrollY: w, innerHeight: E, innerWidth: v } = window,
  T = Math.min(
    t.style.position === "fixed" ? r - w : r,
    E - t.clientHeight - p - u + w
  ), H = m ? t.clientWidth / 2 : 0, O = t.style.position === "fixed" ? Math.max(Math.min(c - h, v - H - p), H + p) : Math.max(
    Math.min(c, v - H - p + h),
    H + p + h
  );
  Object.assign(t.style, {
    ...O !== c && { left: `${O}px` },
    ...T !== r && { top: `${T}px` }
  });
}, "keepInViewport"), Y = /* @__PURE__ */ d((t) => {
  window.HTMLElement.prototype.hasOwnProperty("showPopover") && t.showPopover();
}, "showPopover"), se = /* @__PURE__ */ d((t) => {
  window.HTMLElement.prototype.hasOwnProperty("showPopover") && t.hidePopover();
}, "hidePopover"), ie = /* @__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", re = "storybook-highlights-root", we = "storybook-root", ce = /* @__PURE__ */ d((t) => {
  if (globalThis.__STORYBOOK_HIGHLIGHT_INITIALIZED)
    return;
  globalThis.__STORYBOOK_HIGHLIGHT_INITIALIZED = !0;
  let { document: e } = globalThis, l = M([]), c = M(/* @__PURE__ */ new Map()), r = M([]), p = M(), u = M(), m = M([]), h = M([]), w = M(),
  E = M(), v = e.getElementById(re);
  l.subscribe(() => {
    v || (v = b("div", { id: re }), e.body.appendChild(v));
  }), l.subscribe((s) => {
    let o = e.getElementById(we);
    if (!o)
      return;
    c.set(z(s));
    let n = new MutationObserver(() => c.set(z(s)));
    return n.observe(o, { subtree: !0, childList: !0 }), () => {
      n.disconnect();
    };
  }), c.subscribe((s) => {
    let o = /* @__PURE__ */ d(() => requestAnimationFrame(() => r.set(oe(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: f, overflowX: x, overflowY: y } = window.getComputedStyle(i);
      return ["auto", "scroll"].some((L) => [f, x, y].includes(L));
    });
    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: f, left: x } = i.element.getBoundingClientRect();
            return { ...i, top: f + 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 ? (E.set((o) => s.some((n) => n.element === o?.element) ? o : void 0), w.set((o) => s.some((n) => n.element === o?.element) ? o :
    void 0)) : (E.set(void 0), w.set(void 0), p.set(void 0));
  });
  let T = new Map(/* @__PURE__ */ new Map());
  l.subscribe((s) => {
    s.forEach(({ keyframes: o }) => {
      if (o) {
        let n = T.get(o);
        n || (n = e.createElement("style"), n.setAttribute("data-highlight", "keyframes"), T.set(o, n), e.head.appendChild(n)), n.innerHTML =
        o;
      }
    }), T.forEach((o, n) => {
      s.some((a) => a.keyframes === n) || (o.remove(), T.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)), 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), f = { x: a.pageX, y: a.pageY };
        if (i && !X(i, f)) {
          let x = o.filter((y) => {
            let L = H.get(y.element);
            return V(y, L, f);
          });
          p.set(x.length ? f : void 0), m.set(x);
        }
      });
    }, "onClick");
    return e.addEventListener("click", n), () => e.removeEventListener("click", n);
  });
  let O = /* @__PURE__ */ d(() => {
    let s = e.getElementById(g), o = u.get();
    !o || s && X(s, o) || h.set((n) => {
      let a = r.get().filter((y) => {
        let L = H.get(y.element);
        return V(y, L, o);
      }), i = n.filter((y) => a.includes(y)), f = a.filter((y) => !n.includes(y)), x = n.length - i.length;
      return f.length || x ? [...i, ...f] : n;
    });
  }, "updateHovered");
  u.subscribe(O), r.subscribe(O);
  let $ = /* @__PURE__ */ d(() => {
    let s = E.get(), o = s ? [s] : m.get(), n = o.length === 1 ? o[0] : w.get(), a = p.get() !== void 0;
    r.get().forEach((i) => {
      let f = H.get(i.element);
      if (f) {
        let x = n === i, y = a ? n ? x : o.includes(i) : h.get()?.includes(i);
        Object.assign(f.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 ? "pointer" : "default",
          pointerEvents: i.menu ? "auto" : "none"
        }), Y(f);
      }
    });
  }, "updateBoxStyles");
  r.subscribe($), m.subscribe($), h.subscribe($), w.subscribe($), E.subscribe($);
  let q = /* @__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 = E.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 f = n.length > 1 && !!i.menu?.some(
            (L) => L.some(
              (C) => !C.selectors || C.selectors.some((B) => i.selectors.includes(B))
            )
          ), x = f ? {
            class: "selectable",
            onClick: /* @__PURE__ */ d(() => E.set(i), "onClick"),
            onMouseEnter: /* @__PURE__ */ d(() => w.set(i), "onMouseEnter"),
            onMouseLeave: /* @__PURE__ */ d(() => w.set(void 0), "onMouseLeave")
          } : o ? { class: "selected", onClick: /* @__PURE__ */ d(() => E.set(void 0), "onClick") } : {}, y = f || o;
          return b("li", x, [
            b(y ? "button" : "div", y ? { type: "button" } : {}, [
              o ? A("chevronLeft") : null,
              b("code", {}, [i.element.outerHTML]),
              f ? A("chevronRight") : null
            ])
          ]);
        })
      )
    )), E.get() || m.get().length === 1) {
      let i = E.get() || m.get()[0], f = i.menu?.filter(
        (x) => x.some(
          (y) => !y.selectors || y.selectors.some((L) => i.selectors.includes(L))
        )
      );
      f?.length && s.appendChild(
        b(
          "ul",
          { class: "menu-list" },
          f.map(
            (x) => b("li", {}, [
              b(
                "ul",
                { class: "menu-items" },
                x.map(
                  ({ id: y, title: L, description: C, iconLeft: B, iconRight: W, clickEvent: K }) => {
                    let _ = K && (() => t.emit(K, y, ie(i)));
                    return b("li", {}, [
                      b(
                        _ ? "button" : "div",
                        _ ? { class: "menu-item", type: "button", onClick: _ } : { class: "menu-item" },
                        [
                          B ? A(B) : null,
                          b("div", { class: "menu-item-content" }, [
                            b(C ? "strong" : "span", {}, [L]),
                            C && b("span", {}, [C])
                          ]),
                          W ? A(W) : 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(() => ne(s, a, { topOffset: 15, centered: !0 }))) : (se(s), Object.assign(s.style, { display: "none" }));
  }, "renderMenu");
  m.subscribe(q), E.subscribe(q);
  let de = /* @__PURE__ */ d((s) => {
    let o = te(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"), j = /* @__PURE__ */ d(() => {
    l.set([]), c.set(/* @__PURE__ */ new Map()), r.set([]), p.set(void 0), u.set(void 0), m.set([]), h.set([]), w.set(void 0), E.set(void 0);
  }, "resetState"), Z, ae = /* @__PURE__ */ d((s, o) => {
    let n = "scrollIntoView-highlight";
    clearTimeout(Z), 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((f) => [
      ...f,
      {
        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; }
        }`
      }
    ]), Z = setTimeout(() => N(n), 3500);
  }, "scrollIntoView"), pe = /* @__PURE__ */ d((s) => {
    requestAnimationFrame(() => u.set({ x: s.pageX, y: s.pageY }));
  }, "onMouseMove");
  e.body.addEventListener("mousemove", pe), t.on(U, de), t.on(J, N), t.on(Q, j), t.on(ee, ae), t.on(le.STORY_RENDER_PHASE_CHANGED, ({ newPhase: s }) => {
    s === "loading" && j();
  });
}, "useHighlights");

// src/highlight/preview.ts
globalThis?.FEATURES?.highlight && S.addons?.ready && S.addons.ready().then(ce);
var Ee = /* @__PURE__ */ d(() => (0, S.definePreview)({}), "default");
