{
  "version": 3,
  "sources": ["notify.js"],
  "sourcesContent": ["import $ from \"./jquery.js\";\n\nconst CONTAINER_ID = \"notificationsContainer\";\nconst GAP = 10;\nconst ENTER_DURATION = 300;\nconst EXIT_DURATION = 600;\n\n/** Stack the notifications bottom-up, closing the gaps left by dismissed ones. */\nfunction rearrange(notifications) {\n    let bottom = GAP;\n    notifications.each(function () {\n        const notification = $(this);\n        notification.css(\"bottom\", `${bottom}px`);\n        bottom += notification.outerHeight() + GAP;\n    });\n}\n\nfunction getContainer() {\n    let container = $(`#${CONTAINER_ID}`);\n    if (container.length === 0) {\n        container = $(\"<div></div>\").attr(\"id\", CONTAINER_ID).appendTo(\"body\");\n    }\n    return container;\n}\n\nfunction stackHeight(container) {\n    let bottom = GAP;\n    container.find(\".notification\").each(function () {\n        bottom += $(this).outerHeight() + GAP;\n    });\n    return bottom;\n}\n\n/**\n * Show a popup notification in the bottom-right corner.\n *\n * Width and display time scale with the message length.\n *\n * A notification passed an `id` that is already on screen replaces it rather than\n * piling up, so a repeated message (upload progress, say) stays a single\n * notification. The replacement enters at the top of the stack like any new one.\n *\n * `link: { text, href }` adds a link under the message, opened in a new tab; only\n * web addresses are linked, and its text is always text, never markup.\n */\nexport function notify(message, level = \"info\", options = {}) {\n    const {\n        id = null,\n        icon = null,\n        displayTime = null,\n        width = null,\n        link = null,\n    } = options;\n\n    const length = String(message).length;\n    const finalWidth = width ?? Math.min(500, 250 + length * 10);\n    const finalDisplayTime = displayTime ?? 2500 + length * 80;\n\n    const container = getContainer();\n    const existing = id ? container.find(`.notification[data-id=\"${id}\"]`) : $();\n\n    const element = $(`\n        <div class=\"notification\">\n            <p class=\"notification__message\"></p>\n            <div class=\"notification__progress\"><div class=\"notification__bar\"></div></div>\n        </div>\n    `);\n    element.attr(\"data-id\", id ?? \"\");\n    element.find(\".notification__message\").text(message);\n    if (link && /^https?:\\/\\//i.test(link.href)) {\n        $(\"<a></a>\")\n            .addClass(\"notification__link\")\n            .attr({ href: link.href, target: \"_blank\", rel: \"noopener noreferrer\" })\n            .text(link.text)\n            .appendTo(element.find(\".notification__message\").append(\"<br>\"));\n    }\n    if (level) {\n        element.addClass(level);\n    }\n    if (icon) {\n        $(\"<img>\").addClass(\"notification__icon\").attr(\"src\", icon).prependTo(element);\n    }\n    if (finalDisplayTime === 0) {\n        element.addClass(\"notification--no-progress\");\n    }\n\n    const dismiss = () => {\n        element.animate(\n            { right: `-${finalWidth}px`, opacity: 0 },\n            EXIT_DURATION,\n            function () {\n                element.remove();\n                const remaining = container.find(\".notification\");\n                if (remaining.length === 0) {\n                    container.remove();\n                } else {\n                    rearrange(remaining);\n                }\n            },\n        );\n    };\n\n    if (existing.length > 0) {\n        clearTimeout(existing.data(\"dismissTimeout\"));\n        existing.remove();\n        rearrange(container.find(\".notification\"));\n    }\n\n    element.css({\n        width: `${finalWidth}px`,\n        right: `-${finalWidth}px`,\n        bottom: `${stackHeight(container)}px`,\n        opacity: 0,\n    });\n    container.append(element);\n\n    element.animate({ right: \"0px\", opacity: 0.93 }, ENTER_DURATION);\n\n    const progressBar = element.find(\".notification__bar\");\n    progressBar.css({ width: \"100%\", opacity: 0.6 });\n    if (finalDisplayTime > 0) {\n        progressBar.animate(\n            { width: \"0%\", opacity: 0.1 },\n            {\n                duration: finalDisplayTime,\n                easing: \"linear\",\n            },\n        );\n        element.data(\n            \"dismissTimeout\",\n            setTimeout(dismiss, Math.max(finalDisplayTime, 1500)),\n        );\n    }\n\n    return element;\n}\n"],
  "mappings": "AAAA,OAAOA,MAAO,cAEd,MAAMC,EAAe,yBACfC,EAAM,GACNC,EAAiB,IACjBC,EAAgB,IAGtB,SAASC,EAAUC,EAAe,CAC9B,IAAIC,EAASL,EACbI,EAAc,KAAK,UAAY,CAC3B,MAAME,EAAeR,EAAE,IAAI,EAC3BQ,EAAa,IAAI,SAAU,GAAGD,CAAM,IAAI,EACxCA,GAAUC,EAAa,YAAY,EAAIN,CAC3C,CAAC,CACL,CAEA,SAASO,GAAe,CACpB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GACrBE,EAAQ,SAAS,2BAA2B,EAGhD,MAAMC,EAAU,IAAM,CAClBD,EAAQ,QACJ,CAAE,MAAO,IAAIH,CAAU,KAAM,QAAS,CAAE,EACxCjB,EACA,UAAY,CACRoB,EAAQ,OAAO,EACf,MAAME,EAAYhB,EAAU,KAAK,eAAe,EAC5CgB,EAAU,SAAW,EACrBhB,EAAU,OAAO,EAEjBL,EAAUqB,CAAS,CAE3B,CACJ,CACJ,EAEIH,EAAS,OAAS,IAClB,aAAaA,EAAS,KAAK,gBAAgB,CAAC,EAC5CA,EAAS,OAAO,EAChBlB,EAAUK,EAAU,KAAK,eAAe,CAAC,GAG7Cc,EAAQ,IAAI,CACR,MAAO,GAAGH,CAAU,KACpB,MAAO,IAAIA,CAAU,KACrB,OAAQ,GAAGV,EAAYD,CAAS,CAAC,KACjC,QAAS,CACb,CAAC,EACDA,EAAU,OAAOc,CAAO,EAExBA,EAAQ,QAAQ,CAAE,MAAO,MAAO,QAAS,GAAK,EAAGrB,CAAc,EAE/D,MAAMwB,EAAcH,EAAQ,KAAK,oBAAoB,EACrD,OAAAG,EAAY,IAAI,CAAE,MAAO,OAAQ,QAAS,EAAI,CAAC,EAC3CL,EAAmB,IACnBK,EAAY,QACR,CAAE,MAAO,KAAM,QAAS,EAAI,EAC5B,CACI,SAAUL,EACV,OAAQ,QACZ,CACJ,EACAE,EAAQ,KACJ,iBACA,WAAWC,EAAS,KAAK,IAAIH,EAAkB,IAAI,CAAC,CACxD,GAGGE,CACX",
  "names": ["$", "CONTAINER_ID", "GAP", "ENTER_DURATION", "EXIT_DURATION", "rearrange", "notifications", "bottom", "notification", "getContainer", "container", "stackHeight", "message", "level", "options", "id", "icon", "displayTime", "width", "link", "length", "finalWidth", "finalDisplayTime", "existing", "element", "dismiss", "remaining", "progressBar"]
}
