{
  "version": 3,
  "sources": ["copy_text.js"],
  "sourcesContent": ["// @ts-check\n/*\n * static/js/copy_text.js \u2014 a Copy button for a line of text (SNOW-1606).\n *\n * The /claude/ page's connector address (public/claude/_connector_address.html)\n * has a Copy button beside it. The address itself is plain selectable text in\n * a <code>, so without JavaScript \u2014 or in a browser with no Clipboard API \u2014 it\n * is copied by hand and nothing is lost. The button is rendered ``hidden`` for\n * that reason, and this module reveals it only where ``navigator.clipboard``\n * can write.\n *\n * A click on any ``[data-action=\"copy-text\"]`` (delegated from the document,\n * so a button drawn later works too) writes its ``data-copy-value`` to the\n * clipboard, swaps its label to \"Copied\" for RESTORE_MS, then puts the label\n * back. A refused write leaves the label alone: the address is still there\n * to select.\n *\n * Why not static/js/share.js: its shareOrCopy opens the native share sheet\n * first, which is wrong for an address you paste into a settings form.\n *\n * \"Copied\" is read from #copy-text-strings-template via\n * window.pwaStrings.read(), with the English as the fallback (docs/i18n.md).\n *\n * Markup contract:\n *   [data-action=\"copy-text\"]  the button; ``data-copy-value`` is the text,\n *                              rendered ``hidden`` until this module runs.\n *   #copy-text-strings-template  the strings <template>, key ``copied``.\n */\n\n(function () {\n  'use strict';\n\n  var SELECTOR = '[data-action=\"copy-text\"]';\n  // How long \"Copied\" shows before the button's own label comes back.\n  var RESTORE_MS = 2000;\n\n  /** @returns {boolean} whether this browser can write to the clipboard. */\n  function canCopy() {\n    var nav = window.navigator;\n    return Boolean(nav && nav.clipboard && typeof nav.clipboard.writeText === 'function');\n  }\n\n  /** @returns {Record<string, string>} the module's strings. */\n  function strings() {\n    return window.pwaStrings.read('copy-text-strings-template', {\n      copied: 'Copied',\n    });\n  }\n\n  /**\n   * Copy one button's value and say so on the button.\n   *\n   * @param {HTMLElement} button The clicked copy button.\n   * @returns {Promise<void>} Settles once the label has been swapped (or not).\n   */\n  function copy(button) {\n    var value = button.getAttribute('data-copy-value') || '';\n    return window.navigator.clipboard.writeText(value).then(\n      function () {\n        // The button's own label, kept on it while \"Copied\" shows, so a\n        // second click in that time does not take \"Copied\" for the label.\n        var label = button.getAttribute('data-copy-label');\n        if (label === null) {\n          label = button.textContent || '';\n          button.setAttribute('data-copy-label', label);\n        }\n        var copied = strings().copied;\n        button.textContent = copied;\n        // The visually hidden status beside the button, so a screen\n        // reader hears \"Copied\" too: the button's aria-label does not\n        // change with its text.\n        var status = button.parentElement\n          ? button.parentElement.querySelector('[data-copy-status]')\n          : null;\n        if (status) status.textContent = copied;\n        window.setTimeout(function () {\n          button.textContent = label || '';\n          if (status) status.textContent = '';\n          button.removeAttribute('data-copy-label');\n        }, RESTORE_MS);\n      },\n      function () {\n        // Refused (permissions, an insecure origin): the text is still\n        // there to select by hand, so there is nothing more to do.\n      },\n    );\n  }\n\n  /** Reveal every copy button, where the clipboard can be written. */\n  function reveal() {\n    if (!canCopy()) return;\n    document.querySelectorAll(SELECTOR).forEach(function (button) {\n      button.removeAttribute('hidden');\n    });\n  }\n\n  document.addEventListener('click', function (event) {\n    var target = /** @type {Element | null} */ (event.target);\n    var button = target && target.closest ? target.closest(SELECTOR) : null;\n    if (!button || !canCopy()) return;\n    event.preventDefault();\n    copy(/** @type {HTMLElement} */ (button));\n  });\n\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', reveal);\n  } else {\n    reveal();\n  }\n})();\n"],
  "mappings": "CA6BC,UAAY,CACX,aAEA,IAAIA,EAAW,4BAEXC,EAAa,IAGjB,SAASC,GAAU,CACjB,IAAIC,EAAM,OAAO,UACjB,MAAO,GAAQA,GAAOA,EAAI,WAAa,OAAOA,EAAI,UAAU,WAAc,WAC5E,CAGA,SAASC,GAAU,CACjB,OAAO,OAAO,WAAW,KAAK,6BAA8B,CAC1D,OAAQ,QACV,CAAC,CACH,CAQA,SAASC,EAAKC,EAAQ,CACpB,IAAIC,EAAQD,EAAO,aAAa,iBAAiB,GAAK,GACtD,OAAO,OAAO,UAAU,UAAU,UAAUC,CAAK,EAAE,KACjD,UAAY,CAGV,IAAIC,EAAQF,EAA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