{
  "version": 3,
  "sources": ["toast.js"],
  "sourcesContent": ["(() => {\n  // A toast that carries an undo (\"Put Rio back\") stays twice as long, and does not\n  // go while the coach is on its button: the way back must not vanish under a thumb.\n  // `held()` says whether they are; `done` runs when the toast should go. Returns what\n  // stops the wait. Run's Undo after a move keeps the same time (run-session.js).\n  function holdUndo(held, done) {\n    let timeoutId = null;\n    const wait = (ms) => {\n      timeoutId = window.setTimeout(() => (held() ? wait(2000) : done()), ms);\n    };\n    wait(8000);\n    return () => window.clearTimeout(timeoutId);\n  }\n\n  document.addEventListener(\"alpine:init\", () => {\n    window.Alpine.data(\"toastItem\", ({ sticky = false, undo = false } = {}) => ({\n      open: true,\n      timeoutId: null,\n      stopWait: null,\n      init() {\n        // A failure is felt as well as read (the success haptics are the build's and the kit's).\n        const kind = this.$el.classList.contains(\"toast--error\") ? \"ERROR\" : this.$el.classList.contains(\"toast--warning\") ? \"WARNING\" : \"\";\n        // In the apps only: on the web hapticNotify falls back to a vibration.\n        if (kind && document.documentElement.classList.contains(\"is-native\")) window.BibsOnNative?.hapticNotify?.(kind);\n        if (sticky) {\n          return;\n        }\n        if (undo) {\n          this.stopWait = holdUndo(() => this.$el.contains(document.activeElement), () => this.dismiss());\n        } else {\n          this.timeoutId = window.setTimeout(() => this.dismiss(), 4000);\n        }\n      },\n      clearWait() {\n        if (this.timeoutId) {\n          window.clearTimeout(this.timeoutId);\n          this.timeoutId = null;\n        }\n        if (this.stopWait) {\n          this.stopWait();\n          this.stopWait = null;\n        }\n      },\n      dismiss() {\n        if (!this.open) {\n          return;\n        }\n        this.open = false;\n        this.clearWait();\n        // Remove the node after the opacity transition so HTMX/Alpine cannot\n        // re-init a hidden toast and make the same message pop back up.\n        window.setTimeout(() => this.$el.remove(), 200);\n      },\n      destroy() {\n        this.clearWait();\n      },\n    }));\n  });\n\n  // A toast raised from a script. The template is the error toast, which stays until\n  // dismissed and is read out at once. A plain one, such as \"Link copied\", is made\n  // polite and goes by itself, like the server's success toasts.\n  function addToast(message, { error, refresh = false }) {\n    const region = document.getElementById(\"toast-region\");\n    const template = document.getElementById(\"toast-item-template\");\n    if (!region || !template || !message) {\n      return;\n    }\n    const node = template.content.firstElementChild.cloneNode(true);\n    if (!error) {\n      node.classList.replace(\"toast--error\", \"toast--success\");\n      node.setAttribute(\"role\", \"status\");\n      node.setAttribute(\"x-data\", \"toastItem({ sticky: false })\");\n    }\n    const text = node.querySelector(\".toast__message\");\n    if (text) {\n      text.textContent = message;\n    }\n    const again = node.querySelector(\"[data-toast-refresh]\");\n    if (again && refresh) again.hidden = false;\n    region.appendChild(node);\n    if (window.Alpine) {\n      window.Alpine.initTree(node);\n    }\n  }\n\n  window.BibsOnToast = {\n    holdUndo,\n    show(message) {\n      addToast(message, { error: false });\n    },\n    showError(message, { refresh = false } = {}) {\n      addToast(message, { error: true, refresh });\n    },\n  };\n})();\n"],
  "mappings": "CAAC,IAAM,CAKL,SAASA,EAASC,EAAMC,EAAM,CAC5B,IAAIC,EAAY,KAChB,MAAMC,EAAQC,GAAO,CACnBF,EAAY,OAAO,WAAW,IAAOF,EAAK,EAAIG,EAAK,GAAI,EAAIF,EAAK,EAAIG,CAAE,CACxE,EACA,OAAAD,EAAK,GAAI,EACF,IAAM,OAAO,aAAaD,CAAS,CAC5C,CAEA,SAAS,iBAAiB,cAAe,IAAM,CAC7C,OAAO,OAAO,KAAK,YAAa,CAAC,CAAE,OAAAG,EAAS,GAAO,KAAAC,EAAO,EAAM,EAAI,CAAC,KAAO,CAC1E,KAAM,GACN,UAAW,KACX,SAAU,KACV,MAAO,CAEL,MAAMC,EAAO,KAAK,IAAI,UAAU,SAAS,cAAc,EAAI,QAAU,KAAK,IAAI,UAAU,SAAS,gBAAgB,EAAI,UAAY,GAE7HA,GAAQ,SAAS,gBAAgB,UAAU,SAAS,WAAW,GAAG,OAAO,cAAc,eAAeA,CAAI,EAC1G,CAAAF,IAGAC,EACF,KAAK,SAAWP,EAAS,IAAM,KAAK,IAAI,SAAS,SAAS,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holdUndo", "held", "done", "timeoutId", "wait", "ms", "sticky", "undo", "kind", "addToast", "message", "error", "refresh", "region", "template", "node", "text", "again"]
}
