var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __moduleCache = /* @__PURE__ */ new WeakMap;
var __toCommonJS = (from) => {
  var entry = __moduleCache.get(from), desc;
  if (entry)
    return entry;
  entry = __defProp({}, "__esModule", { value: true });
  if (from && typeof from === "object" || typeof from === "function")
    __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
      get: () => from[key],
      enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
    }));
  __moduleCache.set(from, entry);
  return entry;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: (newValue) => all[name] = () => newValue
    });
};

// src/copy-action.ts
var exports_copy_action = {};
__export(exports_copy_action, {
  copyAction: () => copyAction
});
module.exports = __toCommonJS(exports_copy_action);
var copyAction = (node) => {
  const handleClick = (event) => {
    const target = event.target;
    const button = target.closest("button.copy");
    if (button) {
      const codeText = button.getAttribute("data-code");
      if (codeText) {
        navigator.clipboard.writeText(codeText).then(() => {
          button.classList.add("copied");
          setTimeout(() => {
            button.classList.remove("copied");
          }, 2000);
        }).catch((err) => {
          console.error("Failed to copy code:", err);
        });
      } else {
        const codeBlock = button.closest(".mdsvex-shiki")?.querySelector("code");
        if (codeBlock) {
          navigator.clipboard.writeText(codeBlock.textContent || "").then(() => {
            button.classList.add("copied");
            setTimeout(() => {
              button.classList.remove("copied");
            }, 2000);
          }).catch((err) => {
            console.error("Failed to copy code:", err);
          });
        }
      }
    }
  };
  node.addEventListener("click", handleClick);
  return {
    destroy() {
      node.removeEventListener("click", handleClick);
    }
  };
};
