LeetCode Download as Jupyter Notebook

Download LeetCode problems as Jupyter Notebook files.

As of 2025-04-08. See the latest version.

  1. // ==UserScript==
  2. // @name LeetCode Download as Jupyter Notebook
  3. // @name:zh-CN 把力扣题目下载为 Jupyter Notebook
  4. // @namespace https://github.com/eclipher/leetcode-jupyter
  5. // @version 1.1.2
  6. // @author eclipher
  7. // @description Download LeetCode problems as Jupyter Notebook files.
  8. // @description:zh-CN 将 LeetCode 题目下载为 Jupyter Notebook 文件。
  9. // @license MIT
  10. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAADSGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDx4bXA6TW9kaWZ5RGF0ZT4yMDE3LTA0LTIxVDE5OjA0OjcyPC94bXA6TW9kaWZ5RGF0ZT4KICAgICAgICAgPHhtcDpDcmVhdG9yVG9vbD5QaXhlbG1hdG9yIDMuNjwveG1wOkNyZWF0b3JUb29sPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAgICA8dGlmZjpDb21wcmVzc2lvbj41PC90aWZmOkNvbXByZXNzaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFhEaW1lbnNpb24+MTAyNDwvZXhpZjpQaXhlbFhEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOkNvbG9yU3BhY2U+MTwvZXhpZjpDb2xvclNwYWNlPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MTAyNDwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgrZfc+jAAAG60lEQVRYCbVWa2wUVRS+856d3e22u+22brfvpVK2iE19RDQRjaLW4KNCfykYScQfEhPfiYmu8sMfRo34SDBqKWiIi+IDaIwam2DRP8YfNmiwWg2EQgvtLux2d2bncTx3dmfYlrYg4k1m7sy955zvO+eee+7lyH9rjKMeiURukWW53+v1Xl9XV3cglUppztz/3tfW1t7t9SogCDzIsgjV1cFXLhSUvVDBOXKu5+Fw+J5M5sxnhq4TlmXTALakf478Jf11wanniuIBXhCAEcSsIArg93vH2traGi4pYpkxFxw976XgLIJHq8T80joRIkHvWGVdc3OZ/CX9LAMP3aN4ZCC8AK3VIiabgIGXfyKkPnpJEcuMueChUKjXAb+8VioQwsEjNwdg9LX2Zx15SBAWc8HVccYvtncNUXAPek7DvtQG580HVirmxNuXGfBRA+Q+aPpN3dHRQ4FsEkjkYkEdvbPglZX3UnCaaI0hUUXPrU2rFEhvi4C1s97KvR8xYFcU4KNGKOyMP2qTIIShRBxj8/WLTVJwe1MFA761OTW/xzQtUu1h1CNTID15h495qS94OuDlpwlhGY/McJoK+YJuEIHPvqnuWPYEGoAXqZFFlsP1cA47F7yy0terqvqnFlqRWJLPqMTTGuaO7nms/rkV1/m+H//VMKsD5lXEyG0RZTOu5UFlCMiizBNNDzwurx95ndqmJBicmIMz769LKoCey7IEkiTSZ0bC8Ht9vt/XdLc2ztU8+cVdfm2g7SAko6D21+fV/gjAx02gDizbTGWTScLN1Vn0PxgMrPWUgYsIXuH3jcZbi+CJB4kMyXUcoGEYjEnUGCAJdSA2XCKR1QcioPU3pmd2dUXs+QslEQ5hws0B9/v9f7S3t9dTQ93dRKB9eYNt3fYY7H1YUQfah+GTBoBPMRrbm8bPDFwTorLnS0jbXks0eo3P69GpxzTstEfww2XlVbSNATBQ9qB5BiNiz00n1wXUHUu3qdvbD6g7r7yVyg8lErwjbwMt9KqqrDgwG9w3GovFnApX9BJgsd2zkGl3HIm4+m7C0dnmaHTVyempId0wTPzlJEk6VlMTXjk2NnYE/6l3BeoFNjubBwcHJTwTLBy3G8oxra2tkMmM2AkXDnstZXKGnfIvp/bI5OQk29PTY98THDt8UbX41nTtBtOy7RkctooK/5YSOE0yjTJHcGv//s+XE4t5AwyjduL4uI7htz3yeiQycfwY1uAQ7jpg/s5iJcJchewxdJShhrnBvV9mMG2fQjsHk8kkN4uAZUEzglA2Ap7tOscJw/QHm1FiXPTWZF8NhoI34a2H8DxH97hb+Km2U0RmhZcaMU0SCARIOp16C3+7+vr6zFkEUNMGsCmgHY6z5t+7jE3IrizoCdo6S2AhcDqO4bNlURqjVmyzCKDAX9QgprduWZak5fRVKPYLPjyOu0vACeSp1PQ0zeoayzSpMccyfuKC0AGG7hKbXjFqOIzjXDqVzjI8eYbK0SWgvdvamppW+vBuh7vApDvB5/NOdXR0dJYEnB3ggtGcoEtT/iAMbsckR8eonrP97PGy7HfmXXDnozpU+U35Nqyqqhxfvrx9aWneqQHuNnL0nB69dAk6Y3P7czwvF+hoa+is8CtZAc98WojoTTeIJDo7OztKcm4kEokE6zzUw9Gtm+2SnNmxOqxuX7Iby/KItrPrPqoHQwmeyi7oecm43cVaGlZX+L2Gfc12SVQc7+xcYpOIF2tCuQqBbcXyDO/Fg9r26M+wG+8G+Kj9DZOQ7KqhwvOV4nlD+cdfR7+uCVatkSUJrwCg4JbMZbK5uvFjE9/F47Flh7AgJRNEtA8iPGBGt8YkZhPRIRkPFvjT34oK06XNQNbK04sAwxHVtJdl97Jzl2fR9Wprjt5+ciq1N68VeI5hcoZlKV5FObGisXr1gZGxkfIQQPLqusLMia9EBVZoOcizDPEIWCMKxPOAdP/hDylZpo/YFbFcb1ECVDDW3HDbxKmpfTlN52sUJnfiNCi9V4mn3tlYt6U2pAxls5bJs8a1DFGfx4A101sRxxIPjy/VVDZ6Nhz+APefUy5KJeYshfMSoKItDZHVJ1PpfYKlC6kcyeGQcvrdMPErnKHpxJI9eE7g8YHfOYEjuGQc0Q3pIfHB0X7qOVmHhXuB29DsQnCW2Kyv9JnMn0JV+IfWgH6vIlq+l/sUq7tF0MCysBhZnGmAZpp4ZVNYSddZohPPennD6MD5wCnIBUXAYbNlXcvld67QX4tHmR7Ri6pWKaLUSoEhBYP7kWWVp4X1h4btjH8BT6QFPHds/isCjlJh1xXXGlr+RpZYbVhdOYaYf1uMfNCz4dAQlRlKEH5VgtDUP2fNHRtO/w/NigggN1/kcgAAAABJRU5ErkJggg==
  11. // @homepage https://github.com/eclipher/leetcode-jupyter
  12. // @match *://leetcode.com/problems/*
  13. // @match *://leetcode.cn/problems/*
  14. // @grant GM_addStyle
  15. // ==/UserScript==
  16.  
  17. (t=>{if(typeof GM_addStyle=="function"){GM_addStyle(t);return}const a=document.createElement("style");a.textContent=t,document.head.append(a)})(' :where(html[dir=ltr]),:where([data-sonner-toaster][dir=ltr]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir=rtl]),:where([data-sonner-toaster][dir=rtl]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999}:where([data-sonner-toaster][data-x-position=right]){right:max(var(--offset),env(safe-area-inset-right))}:where([data-sonner-toaster][data-x-position=left]){left:max(var(--offset),env(safe-area-inset-left))}:where([data-sonner-toaster][data-x-position=center]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position=top]){top:max(var(--offset),env(safe-area-inset-top))}:where([data-sonner-toaster][data-y-position=bottom]){bottom:max(var(--offset),env(safe-area-inset-bottom))}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled=true]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position=top]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position=bottom]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise=true]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:#00000014}:where([data-sonner-toast][data-theme=dark]) :where([data-cancel]){background:#ffffff4d}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled=true]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping=true]):before{content:"";position:absolute;left:0;right:0;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position=top][data-swiping=true]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position=bottom][data-swiping=true]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping=false][data-removed=true]):before{content:"";position:absolute;top:0;right:0;bottom:0;left:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted=true]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded=false][data-front=false]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded=false][data-front=false][data-styled=true])>*{opacity:0}:where([data-sonner-toast][data-visible=false]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted=true][data-expanded=true]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]){--y: translateY( calc(var(--lift) * var(--offset) + var(--lift) * -100%) );opacity:0}:where([data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed=true][data-front=false]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount, 0px));transition:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation:swipe-out .2s ease-out forwards}@keyframes swipe-out{0%{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount)));opacity:1}to{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount) + var(--lift) * -100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;--mobile-offset: 16px;right:var(--mobile-offset);left:var(--mobile-offset);width:100%}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset)}[data-sonner-toaster][data-y-position=bottom]{bottom:20px}[data-sonner-toaster][data-y-position=top]{top:20px}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset);right:var(--mobile-offset);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-rich-colors=true] [data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-theme=dark] [data-sonner-toast][data-type=default] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-rich-colors=true] [data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true] [data-sonner-toast][data-type=info],[data-rich-colors=true] [data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true] [data-sonner-toast][data-type=warning],[data-rich-colors=true] [data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true] [data-sonner-toast][data-type=error],[data-rich-colors=true] [data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;top:0;right:0;bottom:0;left:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)} ');
  18.  
  19. (async function () {
  20. 'use strict';
  21.  
  22. var _a, _b, _c;
  23. const DEV = false;
  24. var is_array = Array.isArray;
  25. var index_of = Array.prototype.indexOf;
  26. var array_from = Array.from;
  27. var define_property = Object.defineProperty;
  28. var get_descriptor = Object.getOwnPropertyDescriptor;
  29. var get_descriptors = Object.getOwnPropertyDescriptors;
  30. var object_prototype = Object.prototype;
  31. var array_prototype = Array.prototype;
  32. var get_prototype_of = Object.getPrototypeOf;
  33. var is_extensible = Object.isExtensible;
  34. function is_function(thing) {
  35. return typeof thing === "function";
  36. }
  37. const noop = () => {
  38. };
  39. function run(fn) {
  40. return fn();
  41. }
  42. function run_all(arr) {
  43. for (var i2 = 0; i2 < arr.length; i2++) {
  44. arr[i2]();
  45. }
  46. }
  47. const DERIVED = 1 << 1;
  48. const EFFECT = 1 << 2;
  49. const RENDER_EFFECT = 1 << 3;
  50. const BLOCK_EFFECT = 1 << 4;
  51. const BRANCH_EFFECT = 1 << 5;
  52. const ROOT_EFFECT = 1 << 6;
  53. const BOUNDARY_EFFECT = 1 << 7;
  54. const UNOWNED = 1 << 8;
  55. const DISCONNECTED = 1 << 9;
  56. const CLEAN = 1 << 10;
  57. const DIRTY = 1 << 11;
  58. const MAYBE_DIRTY = 1 << 12;
  59. const INERT = 1 << 13;
  60. const DESTROYED = 1 << 14;
  61. const EFFECT_RAN = 1 << 15;
  62. const EFFECT_TRANSPARENT = 1 << 16;
  63. const LEGACY_DERIVED_PROP = 1 << 17;
  64. const HEAD_EFFECT = 1 << 19;
  65. const EFFECT_HAS_DERIVED = 1 << 20;
  66. const EFFECT_IS_UPDATING = 1 << 21;
  67. const STATE_SYMBOL = Symbol("$state");
  68. const LEGACY_PROPS = Symbol("legacy props");
  69. const LOADING_ATTR_SYMBOL = Symbol("");
  70. function equals(value) {
  71. return value === this.v;
  72. }
  73. function safe_not_equal(a2, b) {
  74. return a2 != a2 ? b == b : a2 !== b || a2 !== null && typeof a2 === "object" || typeof a2 === "function";
  75. }
  76. function safe_equals(value) {
  77. return !safe_not_equal(value, this.v);
  78. }
  79. function effect_in_teardown(rune) {
  80. {
  81. throw new Error(`https://svelte.dev/e/effect_in_teardown`);
  82. }
  83. }
  84. function effect_in_unowned_derived() {
  85. {
  86. throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
  87. }
  88. }
  89. function effect_orphan(rune) {
  90. {
  91. throw new Error(`https://svelte.dev/e/effect_orphan`);
  92. }
  93. }
  94. function effect_update_depth_exceeded() {
  95. {
  96. throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
  97. }
  98. }
  99. function props_invalid_value(key) {
  100. {
  101. throw new Error(`https://svelte.dev/e/props_invalid_value`);
  102. }
  103. }
  104. function state_descriptors_fixed() {
  105. {
  106. throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
  107. }
  108. }
  109. function state_prototype_fixed() {
  110. {
  111. throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
  112. }
  113. }
  114. function state_unsafe_mutation() {
  115. {
  116. throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
  117. }
  118. }
  119. let legacy_mode_flag = false;
  120. let tracing_mode_flag = false;
  121. function enable_legacy_mode_flag() {
  122. legacy_mode_flag = true;
  123. }
  124. const EACH_ITEM_REACTIVE = 1;
  125. const EACH_INDEX_REACTIVE = 1 << 1;
  126. const EACH_IS_CONTROLLED = 1 << 2;
  127. const EACH_IS_ANIMATED = 1 << 3;
  128. const EACH_ITEM_IMMUTABLE = 1 << 4;
  129. const PROPS_IS_IMMUTABLE = 1;
  130. const PROPS_IS_RUNES = 1 << 1;
  131. const PROPS_IS_UPDATED = 1 << 2;
  132. const PROPS_IS_BINDABLE = 1 << 3;
  133. const PROPS_IS_LAZY_INITIAL = 1 << 4;
  134. const TEMPLATE_FRAGMENT = 1;
  135. const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
  136. const UNINITIALIZED = Symbol();
  137. const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
  138. function lifecycle_outside_component(name) {
  139. {
  140. throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
  141. }
  142. }
  143. let component_context = null;
  144. function set_component_context(context) {
  145. component_context = context;
  146. }
  147. function push(props, runes = false, fn) {
  148. var ctx = component_context = {
  149. p: component_context,
  150. c: null,
  151. d: false,
  152. e: null,
  153. m: false,
  154. s: props,
  155. x: null,
  156. l: null
  157. };
  158. if (legacy_mode_flag && !runes) {
  159. component_context.l = {
  160. s: null,
  161. u: null,
  162. r1: [],
  163. r2: source(false)
  164. };
  165. }
  166. teardown(() => {
  167. ctx.d = true;
  168. });
  169. }
  170. function pop(component2) {
  171. const context_stack_item = component_context;
  172. if (context_stack_item !== null) {
  173. const component_effects = context_stack_item.e;
  174. if (component_effects !== null) {
  175. var previous_effect = active_effect;
  176. var previous_reaction = active_reaction;
  177. context_stack_item.e = null;
  178. try {
  179. for (var i2 = 0; i2 < component_effects.length; i2++) {
  180. var component_effect = component_effects[i2];
  181. set_active_effect(component_effect.effect);
  182. set_active_reaction(component_effect.reaction);
  183. effect(component_effect.fn);
  184. }
  185. } finally {
  186. set_active_effect(previous_effect);
  187. set_active_reaction(previous_reaction);
  188. }
  189. }
  190. component_context = context_stack_item.p;
  191. context_stack_item.m = true;
  192. }
  193. return (
  194. /** @type {T} */
  195. {}
  196. );
  197. }
  198. function is_runes() {
  199. return !legacy_mode_flag || component_context !== null && component_context.l === null;
  200. }
  201. function proxy(value, prev) {
  202. if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
  203. return value;
  204. }
  205. const prototype = get_prototype_of(value);
  206. if (prototype !== object_prototype && prototype !== array_prototype) {
  207. return value;
  208. }
  209. var sources = /* @__PURE__ */ new Map();
  210. var is_proxied_array = is_array(value);
  211. var version = state$1(0);
  212. var reaction = active_reaction;
  213. var with_parent = (fn) => {
  214. var previous_reaction = active_reaction;
  215. set_active_reaction(reaction);
  216. var result;
  217. {
  218. result = fn();
  219. }
  220. set_active_reaction(previous_reaction);
  221. return result;
  222. };
  223. if (is_proxied_array) {
  224. sources.set("length", state$1(
  225. /** @type {any[]} */
  226. value.length
  227. ));
  228. }
  229. return new Proxy(
  230. /** @type {any} */
  231. value,
  232. {
  233. defineProperty(_, prop2, descriptor) {
  234. if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
  235. state_descriptors_fixed();
  236. }
  237. var s = sources.get(prop2);
  238. if (s === void 0) {
  239. s = with_parent(() => state$1(descriptor.value));
  240. sources.set(prop2, s);
  241. } else {
  242. set(
  243. s,
  244. with_parent(() => proxy(descriptor.value))
  245. );
  246. }
  247. return true;
  248. },
  249. deleteProperty(target, prop2) {
  250. var s = sources.get(prop2);
  251. if (s === void 0) {
  252. if (prop2 in target) {
  253. sources.set(
  254. prop2,
  255. with_parent(() => state$1(UNINITIALIZED))
  256. );
  257. }
  258. } else {
  259. if (is_proxied_array && typeof prop2 === "string") {
  260. var ls = (
  261. /** @type {Source<number>} */
  262. sources.get("length")
  263. );
  264. var n = Number(prop2);
  265. if (Number.isInteger(n) && n < ls.v) {
  266. set(ls, n);
  267. }
  268. }
  269. set(s, UNINITIALIZED);
  270. update_version(version);
  271. }
  272. return true;
  273. },
  274. get(target, prop2, receiver) {
  275. var _a2;
  276. if (prop2 === STATE_SYMBOL) {
  277. return value;
  278. }
  279. var s = sources.get(prop2);
  280. var exists = prop2 in target;
  281. if (s === void 0 && (!exists || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  282. s = with_parent(() => state$1(proxy(exists ? target[prop2] : UNINITIALIZED)));
  283. sources.set(prop2, s);
  284. }
  285. if (s !== void 0) {
  286. var v = get$1(s);
  287. return v === UNINITIALIZED ? void 0 : v;
  288. }
  289. return Reflect.get(target, prop2, receiver);
  290. },
  291. getOwnPropertyDescriptor(target, prop2) {
  292. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  293. if (descriptor && "value" in descriptor) {
  294. var s = sources.get(prop2);
  295. if (s) descriptor.value = get$1(s);
  296. } else if (descriptor === void 0) {
  297. var source2 = sources.get(prop2);
  298. var value2 = source2 == null ? void 0 : source2.v;
  299. if (source2 !== void 0 && value2 !== UNINITIALIZED) {
  300. return {
  301. enumerable: true,
  302. configurable: true,
  303. value: value2,
  304. writable: true
  305. };
  306. }
  307. }
  308. return descriptor;
  309. },
  310. has(target, prop2) {
  311. var _a2;
  312. if (prop2 === STATE_SYMBOL) {
  313. return true;
  314. }
  315. var s = sources.get(prop2);
  316. var has2 = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop2);
  317. if (s !== void 0 || active_effect !== null && (!has2 || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  318. if (s === void 0) {
  319. s = with_parent(() => state$1(has2 ? proxy(target[prop2]) : UNINITIALIZED));
  320. sources.set(prop2, s);
  321. }
  322. var value2 = get$1(s);
  323. if (value2 === UNINITIALIZED) {
  324. return false;
  325. }
  326. }
  327. return has2;
  328. },
  329. set(target, prop2, value2, receiver) {
  330. var _a2;
  331. var s = sources.get(prop2);
  332. var has2 = prop2 in target;
  333. if (is_proxied_array && prop2 === "length") {
  334. for (var i2 = value2; i2 < /** @type {Source<number>} */
  335. s.v; i2 += 1) {
  336. var other_s = sources.get(i2 + "");
  337. if (other_s !== void 0) {
  338. set(other_s, UNINITIALIZED);
  339. } else if (i2 in target) {
  340. other_s = with_parent(() => state$1(UNINITIALIZED));
  341. sources.set(i2 + "", other_s);
  342. }
  343. }
  344. }
  345. if (s === void 0) {
  346. if (!has2 || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable)) {
  347. s = with_parent(() => state$1(void 0));
  348. set(
  349. s,
  350. with_parent(() => proxy(value2))
  351. );
  352. sources.set(prop2, s);
  353. }
  354. } else {
  355. has2 = s.v !== UNINITIALIZED;
  356. set(
  357. s,
  358. with_parent(() => proxy(value2))
  359. );
  360. }
  361. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  362. if (descriptor == null ? void 0 : descriptor.set) {
  363. descriptor.set.call(receiver, value2);
  364. }
  365. if (!has2) {
  366. if (is_proxied_array && typeof prop2 === "string") {
  367. var ls = (
  368. /** @type {Source<number>} */
  369. sources.get("length")
  370. );
  371. var n = Number(prop2);
  372. if (Number.isInteger(n) && n >= ls.v) {
  373. set(ls, n + 1);
  374. }
  375. }
  376. update_version(version);
  377. }
  378. return true;
  379. },
  380. ownKeys(target) {
  381. get$1(version);
  382. var own_keys = Reflect.ownKeys(target).filter((key2) => {
  383. var source3 = sources.get(key2);
  384. return source3 === void 0 || source3.v !== UNINITIALIZED;
  385. });
  386. for (var [key, source2] of sources) {
  387. if (source2.v !== UNINITIALIZED && !(key in target)) {
  388. own_keys.push(key);
  389. }
  390. }
  391. return own_keys;
  392. },
  393. setPrototypeOf() {
  394. state_prototype_fixed();
  395. }
  396. }
  397. );
  398. }
  399. function update_version(signal, d = 1) {
  400. set(signal, signal.v + d);
  401. }
  402. const old_values = /* @__PURE__ */ new Map();
  403. function source(v, stack) {
  404. var signal = {
  405. f: 0,
  406. // TODO ideally we could skip this altogether, but it causes type errors
  407. v,
  408. reactions: null,
  409. equals,
  410. rv: 0,
  411. wv: 0
  412. };
  413. return signal;
  414. }
  415. function state$1(v, stack) {
  416. const s = source(v);
  417. push_reaction_value(s);
  418. return s;
  419. }
  420. // @__NO_SIDE_EFFECTS__
  421. function mutable_source(initial_value, immutable = false) {
  422. var _a2;
  423. const s = source(initial_value);
  424. if (!immutable) {
  425. s.equals = safe_equals;
  426. }
  427. if (legacy_mode_flag && component_context !== null && component_context.l !== null) {
  428. ((_a2 = component_context.l).s ?? (_a2.s = [])).push(s);
  429. }
  430. return s;
  431. }
  432. function set(source2, value, should_proxy = false) {
  433. if (active_reaction !== null && !untracking && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 && !(reaction_sources == null ? void 0 : reaction_sources.includes(source2))) {
  434. state_unsafe_mutation();
  435. }
  436. let new_value = should_proxy ? proxy(value) : value;
  437. return internal_set(source2, new_value);
  438. }
  439. function internal_set(source2, value) {
  440. if (!source2.equals(value)) {
  441. var old_value = source2.v;
  442. if (is_destroying_effect) {
  443. old_values.set(source2, value);
  444. } else {
  445. old_values.set(source2, old_value);
  446. }
  447. source2.v = value;
  448. source2.wv = increment_write_version();
  449. mark_reactions(source2, DIRTY);
  450. if (is_runes() && active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
  451. if (untracked_writes === null) {
  452. set_untracked_writes([source2]);
  453. } else {
  454. untracked_writes.push(source2);
  455. }
  456. }
  457. }
  458. return value;
  459. }
  460. function update(source2, d = 1) {
  461. var value = get$1(source2);
  462. var result = d === 1 ? value++ : value--;
  463. set(source2, value);
  464. return result;
  465. }
  466. function mark_reactions(signal, status) {
  467. var reactions = signal.reactions;
  468. if (reactions === null) return;
  469. var runes = is_runes();
  470. var length = reactions.length;
  471. for (var i2 = 0; i2 < length; i2++) {
  472. var reaction = reactions[i2];
  473. var flags = reaction.f;
  474. if ((flags & DIRTY) !== 0) continue;
  475. if (!runes && reaction === active_effect) continue;
  476. set_signal_status(reaction, status);
  477. if ((flags & (CLEAN | UNOWNED)) !== 0) {
  478. if ((flags & DERIVED) !== 0) {
  479. mark_reactions(
  480. /** @type {Derived} */
  481. reaction,
  482. MAYBE_DIRTY
  483. );
  484. } else {
  485. schedule_effect(
  486. /** @type {Effect} */
  487. reaction
  488. );
  489. }
  490. }
  491. }
  492. }
  493. let hydrating = false;
  494. var $window;
  495. var is_firefox;
  496. var first_child_getter;
  497. var next_sibling_getter;
  498. function init_operations() {
  499. if ($window !== void 0) {
  500. return;
  501. }
  502. $window = window;
  503. is_firefox = /Firefox/.test(navigator.userAgent);
  504. var element_prototype = Element.prototype;
  505. var node_prototype = Node.prototype;
  506. var text_prototype = Text.prototype;
  507. first_child_getter = get_descriptor(node_prototype, "firstChild").get;
  508. next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
  509. if (is_extensible(element_prototype)) {
  510. element_prototype.__click = void 0;
  511. element_prototype.__className = void 0;
  512. element_prototype.__attributes = null;
  513. element_prototype.__style = void 0;
  514. element_prototype.__e = void 0;
  515. }
  516. if (is_extensible(text_prototype)) {
  517. text_prototype.__t = void 0;
  518. }
  519. }
  520. function create_text(value = "") {
  521. return document.createTextNode(value);
  522. }
  523. // @__NO_SIDE_EFFECTS__
  524. function get_first_child(node) {
  525. return first_child_getter.call(node);
  526. }
  527. // @__NO_SIDE_EFFECTS__
  528. function get_next_sibling(node) {
  529. return next_sibling_getter.call(node);
  530. }
  531. function child(node, is_text) {
  532. {
  533. return /* @__PURE__ */ get_first_child(node);
  534. }
  535. }
  536. function first_child(fragment, is_text) {
  537. {
  538. var first = (
  539. /** @type {DocumentFragment} */
  540. /* @__PURE__ */ get_first_child(
  541. /** @type {Node} */
  542. fragment
  543. )
  544. );
  545. if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
  546. return first;
  547. }
  548. }
  549. function sibling(node, count = 1, is_text = false) {
  550. let next_sibling = node;
  551. while (count--) {
  552. next_sibling = /** @type {TemplateNode} */
  553. /* @__PURE__ */ get_next_sibling(next_sibling);
  554. }
  555. {
  556. return next_sibling;
  557. }
  558. }
  559. function clear_text_content(node) {
  560. node.textContent = "";
  561. }
  562. // @__NO_SIDE_EFFECTS__
  563. function derived(fn) {
  564. var flags = DERIVED | DIRTY;
  565. var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
  566. /** @type {Derived} */
  567. active_reaction
  568. ) : null;
  569. if (active_effect === null || parent_derived !== null && (parent_derived.f & UNOWNED) !== 0) {
  570. flags |= UNOWNED;
  571. } else {
  572. active_effect.f |= EFFECT_HAS_DERIVED;
  573. }
  574. const signal = {
  575. ctx: component_context,
  576. deps: null,
  577. effects: null,
  578. equals,
  579. f: flags,
  580. fn,
  581. reactions: null,
  582. rv: 0,
  583. v: (
  584. /** @type {V} */
  585. null
  586. ),
  587. wv: 0,
  588. parent: parent_derived ?? active_effect
  589. };
  590. return signal;
  591. }
  592. // @__NO_SIDE_EFFECTS__
  593. function derived_safe_equal(fn) {
  594. const signal = /* @__PURE__ */ derived(fn);
  595. signal.equals = safe_equals;
  596. return signal;
  597. }
  598. function destroy_derived_effects(derived2) {
  599. var effects = derived2.effects;
  600. if (effects !== null) {
  601. derived2.effects = null;
  602. for (var i2 = 0; i2 < effects.length; i2 += 1) {
  603. destroy_effect(
  604. /** @type {Effect} */
  605. effects[i2]
  606. );
  607. }
  608. }
  609. }
  610. function get_derived_parent_effect(derived2) {
  611. var parent = derived2.parent;
  612. while (parent !== null) {
  613. if ((parent.f & DERIVED) === 0) {
  614. return (
  615. /** @type {Effect} */
  616. parent
  617. );
  618. }
  619. parent = parent.parent;
  620. }
  621. return null;
  622. }
  623. function execute_derived(derived2) {
  624. var value;
  625. var prev_active_effect = active_effect;
  626. set_active_effect(get_derived_parent_effect(derived2));
  627. {
  628. try {
  629. destroy_derived_effects(derived2);
  630. value = update_reaction(derived2);
  631. } finally {
  632. set_active_effect(prev_active_effect);
  633. }
  634. }
  635. return value;
  636. }
  637. function update_derived(derived2) {
  638. var value = execute_derived(derived2);
  639. var status = (skip_reaction || (derived2.f & UNOWNED) !== 0) && derived2.deps !== null ? MAYBE_DIRTY : CLEAN;
  640. set_signal_status(derived2, status);
  641. if (!derived2.equals(value)) {
  642. derived2.v = value;
  643. derived2.wv = increment_write_version();
  644. }
  645. }
  646. function validate_effect(rune) {
  647. if (active_effect === null && active_reaction === null) {
  648. effect_orphan();
  649. }
  650. if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0 && active_effect === null) {
  651. effect_in_unowned_derived();
  652. }
  653. if (is_destroying_effect) {
  654. effect_in_teardown();
  655. }
  656. }
  657. function push_effect(effect2, parent_effect) {
  658. var parent_last = parent_effect.last;
  659. if (parent_last === null) {
  660. parent_effect.last = parent_effect.first = effect2;
  661. } else {
  662. parent_last.next = effect2;
  663. effect2.prev = parent_last;
  664. parent_effect.last = effect2;
  665. }
  666. }
  667. function create_effect(type, fn, sync, push2 = true) {
  668. var parent = active_effect;
  669. var effect2 = {
  670. ctx: component_context,
  671. deps: null,
  672. nodes_start: null,
  673. nodes_end: null,
  674. f: type | DIRTY,
  675. first: null,
  676. fn,
  677. last: null,
  678. next: null,
  679. parent,
  680. prev: null,
  681. teardown: null,
  682. transitions: null,
  683. wv: 0
  684. };
  685. if (sync) {
  686. try {
  687. update_effect(effect2);
  688. effect2.f |= EFFECT_RAN;
  689. } catch (e) {
  690. destroy_effect(effect2);
  691. throw e;
  692. }
  693. } else if (fn !== null) {
  694. schedule_effect(effect2);
  695. }
  696. var inert = sync && effect2.deps === null && effect2.first === null && effect2.nodes_start === null && effect2.teardown === null && (effect2.f & (EFFECT_HAS_DERIVED | BOUNDARY_EFFECT)) === 0;
  697. if (!inert && push2) {
  698. if (parent !== null) {
  699. push_effect(effect2, parent);
  700. }
  701. if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
  702. var derived2 = (
  703. /** @type {Derived} */
  704. active_reaction
  705. );
  706. (derived2.effects ?? (derived2.effects = [])).push(effect2);
  707. }
  708. }
  709. return effect2;
  710. }
  711. function teardown(fn) {
  712. const effect2 = create_effect(RENDER_EFFECT, null, false);
  713. set_signal_status(effect2, CLEAN);
  714. effect2.teardown = fn;
  715. return effect2;
  716. }
  717. function user_effect(fn) {
  718. validate_effect();
  719. var defer = active_effect !== null && (active_effect.f & BRANCH_EFFECT) !== 0 && component_context !== null && !component_context.m;
  720. if (defer) {
  721. var context = (
  722. /** @type {ComponentContext} */
  723. component_context
  724. );
  725. (context.e ?? (context.e = [])).push({
  726. fn,
  727. effect: active_effect,
  728. reaction: active_reaction
  729. });
  730. } else {
  731. var signal = effect(fn);
  732. return signal;
  733. }
  734. }
  735. function user_pre_effect(fn) {
  736. validate_effect();
  737. return render_effect(fn);
  738. }
  739. function component_root(fn) {
  740. const effect2 = create_effect(ROOT_EFFECT, fn, true);
  741. return (options = {}) => {
  742. return new Promise((fulfil) => {
  743. if (options.outro) {
  744. pause_effect(effect2, () => {
  745. destroy_effect(effect2);
  746. fulfil(void 0);
  747. });
  748. } else {
  749. destroy_effect(effect2);
  750. fulfil(void 0);
  751. }
  752. });
  753. };
  754. }
  755. function effect(fn) {
  756. return create_effect(EFFECT, fn, false);
  757. }
  758. function legacy_pre_effect(deps, fn) {
  759. var context = (
  760. /** @type {ComponentContextLegacy} */
  761. component_context
  762. );
  763. var token = { effect: null, ran: false };
  764. context.l.r1.push(token);
  765. token.effect = render_effect(() => {
  766. deps();
  767. if (token.ran) return;
  768. token.ran = true;
  769. set(context.l.r2, true);
  770. untrack(fn);
  771. });
  772. }
  773. function legacy_pre_effect_reset() {
  774. var context = (
  775. /** @type {ComponentContextLegacy} */
  776. component_context
  777. );
  778. render_effect(() => {
  779. if (!get$1(context.l.r2)) return;
  780. for (var token of context.l.r1) {
  781. var effect2 = token.effect;
  782. if ((effect2.f & CLEAN) !== 0) {
  783. set_signal_status(effect2, MAYBE_DIRTY);
  784. }
  785. if (check_dirtiness(effect2)) {
  786. update_effect(effect2);
  787. }
  788. token.ran = false;
  789. }
  790. context.l.r2.v = false;
  791. });
  792. }
  793. function render_effect(fn) {
  794. return create_effect(RENDER_EFFECT, fn, true);
  795. }
  796. function template_effect(fn, thunks = [], d = derived) {
  797. const deriveds = thunks.map(d);
  798. const effect2 = () => fn(...deriveds.map(get$1));
  799. return block(effect2);
  800. }
  801. function block(fn, flags = 0) {
  802. return create_effect(RENDER_EFFECT | BLOCK_EFFECT | flags, fn, true);
  803. }
  804. function branch(fn, push2 = true) {
  805. return create_effect(RENDER_EFFECT | BRANCH_EFFECT, fn, true, push2);
  806. }
  807. function execute_effect_teardown(effect2) {
  808. var teardown2 = effect2.teardown;
  809. if (teardown2 !== null) {
  810. const previously_destroying_effect = is_destroying_effect;
  811. const previous_reaction = active_reaction;
  812. set_is_destroying_effect(true);
  813. set_active_reaction(null);
  814. try {
  815. teardown2.call(null);
  816. } finally {
  817. set_is_destroying_effect(previously_destroying_effect);
  818. set_active_reaction(previous_reaction);
  819. }
  820. }
  821. }
  822. function destroy_effect_children(signal, remove_dom = false) {
  823. var effect2 = signal.first;
  824. signal.first = signal.last = null;
  825. while (effect2 !== null) {
  826. var next2 = effect2.next;
  827. if ((effect2.f & ROOT_EFFECT) !== 0) {
  828. effect2.parent = null;
  829. } else {
  830. destroy_effect(effect2, remove_dom);
  831. }
  832. effect2 = next2;
  833. }
  834. }
  835. function destroy_block_effect_children(signal) {
  836. var effect2 = signal.first;
  837. while (effect2 !== null) {
  838. var next2 = effect2.next;
  839. if ((effect2.f & BRANCH_EFFECT) === 0) {
  840. destroy_effect(effect2);
  841. }
  842. effect2 = next2;
  843. }
  844. }
  845. function destroy_effect(effect2, remove_dom = true) {
  846. var removed = false;
  847. if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes_start !== null) {
  848. var node = effect2.nodes_start;
  849. var end = effect2.nodes_end;
  850. while (node !== null) {
  851. var next2 = node === end ? null : (
  852. /** @type {TemplateNode} */
  853. /* @__PURE__ */ get_next_sibling(node)
  854. );
  855. node.remove();
  856. node = next2;
  857. }
  858. removed = true;
  859. }
  860. destroy_effect_children(effect2, remove_dom && !removed);
  861. remove_reactions(effect2, 0);
  862. set_signal_status(effect2, DESTROYED);
  863. var transitions = effect2.transitions;
  864. if (transitions !== null) {
  865. for (const transition of transitions) {
  866. transition.stop();
  867. }
  868. }
  869. execute_effect_teardown(effect2);
  870. var parent = effect2.parent;
  871. if (parent !== null && parent.first !== null) {
  872. unlink_effect(effect2);
  873. }
  874. effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes_start = effect2.nodes_end = null;
  875. }
  876. function unlink_effect(effect2) {
  877. var parent = effect2.parent;
  878. var prev = effect2.prev;
  879. var next2 = effect2.next;
  880. if (prev !== null) prev.next = next2;
  881. if (next2 !== null) next2.prev = prev;
  882. if (parent !== null) {
  883. if (parent.first === effect2) parent.first = next2;
  884. if (parent.last === effect2) parent.last = prev;
  885. }
  886. }
  887. function pause_effect(effect2, callback) {
  888. var transitions = [];
  889. pause_children(effect2, transitions, true);
  890. run_out_transitions(transitions, () => {
  891. destroy_effect(effect2);
  892. if (callback) callback();
  893. });
  894. }
  895. function run_out_transitions(transitions, fn) {
  896. var remaining = transitions.length;
  897. if (remaining > 0) {
  898. var check = () => --remaining || fn();
  899. for (var transition of transitions) {
  900. transition.out(check);
  901. }
  902. } else {
  903. fn();
  904. }
  905. }
  906. function pause_children(effect2, transitions, local) {
  907. if ((effect2.f & INERT) !== 0) return;
  908. effect2.f ^= INERT;
  909. if (effect2.transitions !== null) {
  910. for (const transition of effect2.transitions) {
  911. if (transition.is_global || local) {
  912. transitions.push(transition);
  913. }
  914. }
  915. }
  916. var child2 = effect2.first;
  917. while (child2 !== null) {
  918. var sibling2 = child2.next;
  919. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  920. pause_children(child2, transitions, transparent ? local : false);
  921. child2 = sibling2;
  922. }
  923. }
  924. function resume_effect(effect2) {
  925. resume_children(effect2, true);
  926. }
  927. function resume_children(effect2, local) {
  928. if ((effect2.f & INERT) === 0) return;
  929. effect2.f ^= INERT;
  930. if ((effect2.f & CLEAN) === 0) {
  931. effect2.f ^= CLEAN;
  932. }
  933. if (check_dirtiness(effect2)) {
  934. set_signal_status(effect2, DIRTY);
  935. schedule_effect(effect2);
  936. }
  937. var child2 = effect2.first;
  938. while (child2 !== null) {
  939. var sibling2 = child2.next;
  940. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  941. resume_children(child2, transparent ? local : false);
  942. child2 = sibling2;
  943. }
  944. if (effect2.transitions !== null) {
  945. for (const transition of effect2.transitions) {
  946. if (transition.is_global || local) {
  947. transition.in();
  948. }
  949. }
  950. }
  951. }
  952. let micro_tasks = [];
  953. let idle_tasks = [];
  954. function run_micro_tasks() {
  955. var tasks = micro_tasks;
  956. micro_tasks = [];
  957. run_all(tasks);
  958. }
  959. function run_idle_tasks() {
  960. var tasks = idle_tasks;
  961. idle_tasks = [];
  962. run_all(tasks);
  963. }
  964. function queue_micro_task(fn) {
  965. if (micro_tasks.length === 0) {
  966. queueMicrotask(run_micro_tasks);
  967. }
  968. micro_tasks.push(fn);
  969. }
  970. function flush_tasks() {
  971. if (micro_tasks.length > 0) {
  972. run_micro_tasks();
  973. }
  974. if (idle_tasks.length > 0) {
  975. run_idle_tasks();
  976. }
  977. }
  978. let is_throwing_error = false;
  979. let is_flushing = false;
  980. let last_scheduled_effect = null;
  981. let is_updating_effect = false;
  982. let is_destroying_effect = false;
  983. function set_is_destroying_effect(value) {
  984. is_destroying_effect = value;
  985. }
  986. let queued_root_effects = [];
  987. let active_reaction = null;
  988. let untracking = false;
  989. function set_active_reaction(reaction) {
  990. active_reaction = reaction;
  991. }
  992. let active_effect = null;
  993. function set_active_effect(effect2) {
  994. active_effect = effect2;
  995. }
  996. let reaction_sources = null;
  997. function set_reaction_sources(sources) {
  998. reaction_sources = sources;
  999. }
  1000. function push_reaction_value(value) {
  1001. if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
  1002. if (reaction_sources === null) {
  1003. set_reaction_sources([value]);
  1004. } else {
  1005. reaction_sources.push(value);
  1006. }
  1007. }
  1008. }
  1009. let new_deps = null;
  1010. let skipped_deps = 0;
  1011. let untracked_writes = null;
  1012. function set_untracked_writes(value) {
  1013. untracked_writes = value;
  1014. }
  1015. let write_version = 1;
  1016. let read_version = 0;
  1017. let skip_reaction = false;
  1018. function increment_write_version() {
  1019. return ++write_version;
  1020. }
  1021. function check_dirtiness(reaction) {
  1022. var _a2;
  1023. var flags = reaction.f;
  1024. if ((flags & DIRTY) !== 0) {
  1025. return true;
  1026. }
  1027. if ((flags & MAYBE_DIRTY) !== 0) {
  1028. var dependencies = reaction.deps;
  1029. var is_unowned = (flags & UNOWNED) !== 0;
  1030. if (dependencies !== null) {
  1031. var i2;
  1032. var dependency;
  1033. var is_disconnected = (flags & DISCONNECTED) !== 0;
  1034. var is_unowned_connected = is_unowned && active_effect !== null && !skip_reaction;
  1035. var length = dependencies.length;
  1036. if (is_disconnected || is_unowned_connected) {
  1037. var derived2 = (
  1038. /** @type {Derived} */
  1039. reaction
  1040. );
  1041. var parent = derived2.parent;
  1042. for (i2 = 0; i2 < length; i2++) {
  1043. dependency = dependencies[i2];
  1044. if (is_disconnected || !((_a2 = dependency == null ? void 0 : dependency.reactions) == null ? void 0 : _a2.includes(derived2))) {
  1045. (dependency.reactions ?? (dependency.reactions = [])).push(derived2);
  1046. }
  1047. }
  1048. if (is_disconnected) {
  1049. derived2.f ^= DISCONNECTED;
  1050. }
  1051. if (is_unowned_connected && parent !== null && (parent.f & UNOWNED) === 0) {
  1052. derived2.f ^= UNOWNED;
  1053. }
  1054. }
  1055. for (i2 = 0; i2 < length; i2++) {
  1056. dependency = dependencies[i2];
  1057. if (check_dirtiness(
  1058. /** @type {Derived} */
  1059. dependency
  1060. )) {
  1061. update_derived(
  1062. /** @type {Derived} */
  1063. dependency
  1064. );
  1065. }
  1066. if (dependency.wv > reaction.wv) {
  1067. return true;
  1068. }
  1069. }
  1070. }
  1071. if (!is_unowned || active_effect !== null && !skip_reaction) {
  1072. set_signal_status(reaction, CLEAN);
  1073. }
  1074. }
  1075. return false;
  1076. }
  1077. function propagate_error(error, effect2) {
  1078. var current = effect2;
  1079. while (current !== null) {
  1080. if ((current.f & BOUNDARY_EFFECT) !== 0) {
  1081. try {
  1082. current.fn(error);
  1083. return;
  1084. } catch {
  1085. current.f ^= BOUNDARY_EFFECT;
  1086. }
  1087. }
  1088. current = current.parent;
  1089. }
  1090. is_throwing_error = false;
  1091. throw error;
  1092. }
  1093. function should_rethrow_error(effect2) {
  1094. return (effect2.f & DESTROYED) === 0 && (effect2.parent === null || (effect2.parent.f & BOUNDARY_EFFECT) === 0);
  1095. }
  1096. function handle_error(error, effect2, previous_effect, component_context2) {
  1097. if (is_throwing_error) {
  1098. if (previous_effect === null) {
  1099. is_throwing_error = false;
  1100. }
  1101. if (should_rethrow_error(effect2)) {
  1102. throw error;
  1103. }
  1104. return;
  1105. }
  1106. if (previous_effect !== null) {
  1107. is_throwing_error = true;
  1108. }
  1109. {
  1110. propagate_error(error, effect2);
  1111. return;
  1112. }
  1113. }
  1114. function schedule_possible_effect_self_invalidation(signal, effect2, root2 = true) {
  1115. var reactions = signal.reactions;
  1116. if (reactions === null) return;
  1117. for (var i2 = 0; i2 < reactions.length; i2++) {
  1118. var reaction = reactions[i2];
  1119. if (reaction_sources == null ? void 0 : reaction_sources.includes(signal)) continue;
  1120. if ((reaction.f & DERIVED) !== 0) {
  1121. schedule_possible_effect_self_invalidation(
  1122. /** @type {Derived} */
  1123. reaction,
  1124. effect2,
  1125. false
  1126. );
  1127. } else if (effect2 === reaction) {
  1128. if (root2) {
  1129. set_signal_status(reaction, DIRTY);
  1130. } else if ((reaction.f & CLEAN) !== 0) {
  1131. set_signal_status(reaction, MAYBE_DIRTY);
  1132. }
  1133. schedule_effect(
  1134. /** @type {Effect} */
  1135. reaction
  1136. );
  1137. }
  1138. }
  1139. }
  1140. function update_reaction(reaction) {
  1141. var _a2;
  1142. var previous_deps = new_deps;
  1143. var previous_skipped_deps = skipped_deps;
  1144. var previous_untracked_writes = untracked_writes;
  1145. var previous_reaction = active_reaction;
  1146. var previous_skip_reaction = skip_reaction;
  1147. var previous_reaction_sources = reaction_sources;
  1148. var previous_component_context = component_context;
  1149. var previous_untracking = untracking;
  1150. var flags = reaction.f;
  1151. new_deps = /** @type {null | Value[]} */
  1152. null;
  1153. skipped_deps = 0;
  1154. untracked_writes = null;
  1155. skip_reaction = (flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
  1156. active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
  1157. reaction_sources = null;
  1158. set_component_context(reaction.ctx);
  1159. untracking = false;
  1160. read_version++;
  1161. reaction.f |= EFFECT_IS_UPDATING;
  1162. try {
  1163. var result = (
  1164. /** @type {Function} */
  1165. (0, reaction.fn)()
  1166. );
  1167. var deps = reaction.deps;
  1168. if (new_deps !== null) {
  1169. var i2;
  1170. remove_reactions(reaction, skipped_deps);
  1171. if (deps !== null && skipped_deps > 0) {
  1172. deps.length = skipped_deps + new_deps.length;
  1173. for (i2 = 0; i2 < new_deps.length; i2++) {
  1174. deps[skipped_deps + i2] = new_deps[i2];
  1175. }
  1176. } else {
  1177. reaction.deps = deps = new_deps;
  1178. }
  1179. if (!skip_reaction) {
  1180. for (i2 = skipped_deps; i2 < deps.length; i2++) {
  1181. ((_a2 = deps[i2]).reactions ?? (_a2.reactions = [])).push(reaction);
  1182. }
  1183. }
  1184. } else if (deps !== null && skipped_deps < deps.length) {
  1185. remove_reactions(reaction, skipped_deps);
  1186. deps.length = skipped_deps;
  1187. }
  1188. if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
  1189. for (i2 = 0; i2 < /** @type {Source[]} */
  1190. untracked_writes.length; i2++) {
  1191. schedule_possible_effect_self_invalidation(
  1192. untracked_writes[i2],
  1193. /** @type {Effect} */
  1194. reaction
  1195. );
  1196. }
  1197. }
  1198. if (previous_reaction !== reaction) {
  1199. read_version++;
  1200. if (untracked_writes !== null) {
  1201. if (previous_untracked_writes === null) {
  1202. previous_untracked_writes = untracked_writes;
  1203. } else {
  1204. previous_untracked_writes.push(.../** @type {Source[]} */
  1205. untracked_writes);
  1206. }
  1207. }
  1208. }
  1209. return result;
  1210. } finally {
  1211. new_deps = previous_deps;
  1212. skipped_deps = previous_skipped_deps;
  1213. untracked_writes = previous_untracked_writes;
  1214. active_reaction = previous_reaction;
  1215. skip_reaction = previous_skip_reaction;
  1216. reaction_sources = previous_reaction_sources;
  1217. set_component_context(previous_component_context);
  1218. untracking = previous_untracking;
  1219. reaction.f ^= EFFECT_IS_UPDATING;
  1220. }
  1221. }
  1222. function remove_reaction(signal, dependency) {
  1223. let reactions = dependency.reactions;
  1224. if (reactions !== null) {
  1225. var index2 = index_of.call(reactions, signal);
  1226. if (index2 !== -1) {
  1227. var new_length = reactions.length - 1;
  1228. if (new_length === 0) {
  1229. reactions = dependency.reactions = null;
  1230. } else {
  1231. reactions[index2] = reactions[new_length];
  1232. reactions.pop();
  1233. }
  1234. }
  1235. }
  1236. if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
  1237. // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
  1238. // allows us to skip the expensive work of disconnecting and immediately reconnecting it
  1239. (new_deps === null || !new_deps.includes(dependency))) {
  1240. set_signal_status(dependency, MAYBE_DIRTY);
  1241. if ((dependency.f & (UNOWNED | DISCONNECTED)) === 0) {
  1242. dependency.f ^= DISCONNECTED;
  1243. }
  1244. destroy_derived_effects(
  1245. /** @type {Derived} **/
  1246. dependency
  1247. );
  1248. remove_reactions(
  1249. /** @type {Derived} **/
  1250. dependency,
  1251. 0
  1252. );
  1253. }
  1254. }
  1255. function remove_reactions(signal, start_index) {
  1256. var dependencies = signal.deps;
  1257. if (dependencies === null) return;
  1258. for (var i2 = start_index; i2 < dependencies.length; i2++) {
  1259. remove_reaction(signal, dependencies[i2]);
  1260. }
  1261. }
  1262. function update_effect(effect2) {
  1263. var flags = effect2.f;
  1264. if ((flags & DESTROYED) !== 0) {
  1265. return;
  1266. }
  1267. set_signal_status(effect2, CLEAN);
  1268. var previous_effect = active_effect;
  1269. var previous_component_context = component_context;
  1270. var was_updating_effect = is_updating_effect;
  1271. active_effect = effect2;
  1272. is_updating_effect = true;
  1273. try {
  1274. if ((flags & BLOCK_EFFECT) !== 0) {
  1275. destroy_block_effect_children(effect2);
  1276. } else {
  1277. destroy_effect_children(effect2);
  1278. }
  1279. execute_effect_teardown(effect2);
  1280. var teardown2 = update_reaction(effect2);
  1281. effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
  1282. effect2.wv = write_version;
  1283. var deps = effect2.deps;
  1284. var dep;
  1285. if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && deps !== null) ;
  1286. if (DEV) ;
  1287. } catch (error) {
  1288. handle_error(error, effect2, previous_effect, previous_component_context || effect2.ctx);
  1289. } finally {
  1290. is_updating_effect = was_updating_effect;
  1291. active_effect = previous_effect;
  1292. }
  1293. }
  1294. function infinite_loop_guard() {
  1295. try {
  1296. effect_update_depth_exceeded();
  1297. } catch (error) {
  1298. if (last_scheduled_effect !== null) {
  1299. {
  1300. handle_error(error, last_scheduled_effect, null);
  1301. }
  1302. } else {
  1303. throw error;
  1304. }
  1305. }
  1306. }
  1307. function flush_queued_root_effects() {
  1308. var was_updating_effect = is_updating_effect;
  1309. try {
  1310. var flush_count = 0;
  1311. is_updating_effect = true;
  1312. while (queued_root_effects.length > 0) {
  1313. if (flush_count++ > 1e3) {
  1314. infinite_loop_guard();
  1315. }
  1316. var root_effects = queued_root_effects;
  1317. var length = root_effects.length;
  1318. queued_root_effects = [];
  1319. for (var i2 = 0; i2 < length; i2++) {
  1320. var collected_effects = process_effects(root_effects[i2]);
  1321. flush_queued_effects(collected_effects);
  1322. }
  1323. old_values.clear();
  1324. }
  1325. } finally {
  1326. is_flushing = false;
  1327. is_updating_effect = was_updating_effect;
  1328. last_scheduled_effect = null;
  1329. }
  1330. }
  1331. function flush_queued_effects(effects) {
  1332. var length = effects.length;
  1333. if (length === 0) return;
  1334. for (var i2 = 0; i2 < length; i2++) {
  1335. var effect2 = effects[i2];
  1336. if ((effect2.f & (DESTROYED | INERT)) === 0) {
  1337. try {
  1338. if (check_dirtiness(effect2)) {
  1339. update_effect(effect2);
  1340. if (effect2.deps === null && effect2.first === null && effect2.nodes_start === null) {
  1341. if (effect2.teardown === null) {
  1342. unlink_effect(effect2);
  1343. } else {
  1344. effect2.fn = null;
  1345. }
  1346. }
  1347. }
  1348. } catch (error) {
  1349. handle_error(error, effect2, null, effect2.ctx);
  1350. }
  1351. }
  1352. }
  1353. }
  1354. function schedule_effect(signal) {
  1355. if (!is_flushing) {
  1356. is_flushing = true;
  1357. queueMicrotask(flush_queued_root_effects);
  1358. }
  1359. var effect2 = last_scheduled_effect = signal;
  1360. while (effect2.parent !== null) {
  1361. effect2 = effect2.parent;
  1362. var flags = effect2.f;
  1363. if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
  1364. if ((flags & CLEAN) === 0) return;
  1365. effect2.f ^= CLEAN;
  1366. }
  1367. }
  1368. queued_root_effects.push(effect2);
  1369. }
  1370. function process_effects(root2) {
  1371. var effects = [];
  1372. var effect2 = root2;
  1373. while (effect2 !== null) {
  1374. var flags = effect2.f;
  1375. var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
  1376. var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
  1377. if (!is_skippable_branch && (flags & INERT) === 0) {
  1378. if ((flags & EFFECT) !== 0) {
  1379. effects.push(effect2);
  1380. } else if (is_branch) {
  1381. effect2.f ^= CLEAN;
  1382. } else {
  1383. var previous_active_reaction = active_reaction;
  1384. try {
  1385. active_reaction = effect2;
  1386. if (check_dirtiness(effect2)) {
  1387. update_effect(effect2);
  1388. }
  1389. } catch (error) {
  1390. handle_error(error, effect2, null, effect2.ctx);
  1391. } finally {
  1392. active_reaction = previous_active_reaction;
  1393. }
  1394. }
  1395. var child2 = effect2.first;
  1396. if (child2 !== null) {
  1397. effect2 = child2;
  1398. continue;
  1399. }
  1400. }
  1401. var parent = effect2.parent;
  1402. effect2 = effect2.next;
  1403. while (effect2 === null && parent !== null) {
  1404. effect2 = parent.next;
  1405. parent = parent.parent;
  1406. }
  1407. }
  1408. return effects;
  1409. }
  1410. function flushSync(fn) {
  1411. var result;
  1412. flush_tasks();
  1413. while (queued_root_effects.length > 0) {
  1414. is_flushing = true;
  1415. flush_queued_root_effects();
  1416. flush_tasks();
  1417. }
  1418. return (
  1419. /** @type {T} */
  1420. result
  1421. );
  1422. }
  1423. async function tick() {
  1424. await Promise.resolve();
  1425. flushSync();
  1426. }
  1427. function get$1(signal) {
  1428. var flags = signal.f;
  1429. var is_derived = (flags & DERIVED) !== 0;
  1430. if (active_reaction !== null && !untracking) {
  1431. if (!(reaction_sources == null ? void 0 : reaction_sources.includes(signal))) {
  1432. var deps = active_reaction.deps;
  1433. if (signal.rv < read_version) {
  1434. signal.rv = read_version;
  1435. if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
  1436. skipped_deps++;
  1437. } else if (new_deps === null) {
  1438. new_deps = [signal];
  1439. } else if (!skip_reaction || !new_deps.includes(signal)) {
  1440. new_deps.push(signal);
  1441. }
  1442. }
  1443. }
  1444. } else if (is_derived && /** @type {Derived} */
  1445. signal.deps === null && /** @type {Derived} */
  1446. signal.effects === null) {
  1447. var derived2 = (
  1448. /** @type {Derived} */
  1449. signal
  1450. );
  1451. var parent = derived2.parent;
  1452. if (parent !== null && (parent.f & UNOWNED) === 0) {
  1453. derived2.f ^= UNOWNED;
  1454. }
  1455. }
  1456. if (is_derived) {
  1457. derived2 = /** @type {Derived} */
  1458. signal;
  1459. if (check_dirtiness(derived2)) {
  1460. update_derived(derived2);
  1461. }
  1462. }
  1463. if (is_destroying_effect && old_values.has(signal)) {
  1464. return old_values.get(signal);
  1465. }
  1466. return signal.v;
  1467. }
  1468. function untrack(fn) {
  1469. var previous_untracking = untracking;
  1470. try {
  1471. untracking = true;
  1472. return fn();
  1473. } finally {
  1474. untracking = previous_untracking;
  1475. }
  1476. }
  1477. const STATUS_MASK = -7169;
  1478. function set_signal_status(signal, status) {
  1479. signal.f = signal.f & STATUS_MASK | status;
  1480. }
  1481. function deep_read_state(value) {
  1482. if (typeof value !== "object" || !value || value instanceof EventTarget) {
  1483. return;
  1484. }
  1485. if (STATE_SYMBOL in value) {
  1486. deep_read(value);
  1487. } else if (!Array.isArray(value)) {
  1488. for (let key in value) {
  1489. const prop2 = value[key];
  1490. if (typeof prop2 === "object" && prop2 && STATE_SYMBOL in prop2) {
  1491. deep_read(prop2);
  1492. }
  1493. }
  1494. }
  1495. }
  1496. function deep_read(value, visited = /* @__PURE__ */ new Set()) {
  1497. if (typeof value === "object" && value !== null && // We don't want to traverse DOM elements
  1498. !(value instanceof EventTarget) && !visited.has(value)) {
  1499. visited.add(value);
  1500. if (value instanceof Date) {
  1501. value.getTime();
  1502. }
  1503. for (let key in value) {
  1504. try {
  1505. deep_read(value[key], visited);
  1506. } catch (e) {
  1507. }
  1508. }
  1509. const proto = get_prototype_of(value);
  1510. if (proto !== Object.prototype && proto !== Array.prototype && proto !== Map.prototype && proto !== Set.prototype && proto !== Date.prototype) {
  1511. const descriptors = get_descriptors(proto);
  1512. for (let key in descriptors) {
  1513. const get2 = descriptors[key].get;
  1514. if (get2) {
  1515. try {
  1516. get2.call(value);
  1517. } catch (e) {
  1518. }
  1519. }
  1520. }
  1521. }
  1522. }
  1523. }
  1524. function is_capture_event(name) {
  1525. return name.endsWith("capture") && name !== "gotpointercapture" && name !== "lostpointercapture";
  1526. }
  1527. const DELEGATED_EVENTS = [
  1528. "beforeinput",
  1529. "click",
  1530. "change",
  1531. "dblclick",
  1532. "contextmenu",
  1533. "focusin",
  1534. "focusout",
  1535. "input",
  1536. "keydown",
  1537. "keyup",
  1538. "mousedown",
  1539. "mousemove",
  1540. "mouseout",
  1541. "mouseover",
  1542. "mouseup",
  1543. "pointerdown",
  1544. "pointermove",
  1545. "pointerout",
  1546. "pointerover",
  1547. "pointerup",
  1548. "touchend",
  1549. "touchmove",
  1550. "touchstart"
  1551. ];
  1552. function is_delegated(event_name) {
  1553. return DELEGATED_EVENTS.includes(event_name);
  1554. }
  1555. const ATTRIBUTE_ALIASES = {
  1556. // no `class: 'className'` because we handle that separately
  1557. formnovalidate: "formNoValidate",
  1558. ismap: "isMap",
  1559. nomodule: "noModule",
  1560. playsinline: "playsInline",
  1561. readonly: "readOnly",
  1562. defaultvalue: "defaultValue",
  1563. defaultchecked: "defaultChecked",
  1564. srcobject: "srcObject",
  1565. novalidate: "noValidate",
  1566. allowfullscreen: "allowFullscreen",
  1567. disablepictureinpicture: "disablePictureInPicture",
  1568. disableremoteplayback: "disableRemotePlayback"
  1569. };
  1570. function normalize_attribute(name) {
  1571. name = name.toLowerCase();
  1572. return ATTRIBUTE_ALIASES[name] ?? name;
  1573. }
  1574. const PASSIVE_EVENTS = ["touchstart", "touchmove"];
  1575. function is_passive_event(name) {
  1576. return PASSIVE_EVENTS.includes(name);
  1577. }
  1578. function autofocus(dom, value) {
  1579. if (value) {
  1580. const body = document.body;
  1581. dom.autofocus = true;
  1582. queue_micro_task(() => {
  1583. if (document.activeElement === body) {
  1584. dom.focus();
  1585. }
  1586. });
  1587. }
  1588. }
  1589. function without_reactive_context(fn) {
  1590. var previous_reaction = active_reaction;
  1591. var previous_effect = active_effect;
  1592. set_active_reaction(null);
  1593. set_active_effect(null);
  1594. try {
  1595. return fn();
  1596. } finally {
  1597. set_active_reaction(previous_reaction);
  1598. set_active_effect(previous_effect);
  1599. }
  1600. }
  1601. const all_registered_events = /* @__PURE__ */ new Set();
  1602. const root_event_handles = /* @__PURE__ */ new Set();
  1603. function create_event(event_name, dom, handler, options = {}) {
  1604. function target_handler(event2) {
  1605. if (!options.capture) {
  1606. handle_event_propagation.call(dom, event2);
  1607. }
  1608. if (!event2.cancelBubble) {
  1609. return without_reactive_context(() => {
  1610. return handler == null ? void 0 : handler.call(this, event2);
  1611. });
  1612. }
  1613. }
  1614. if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
  1615. queue_micro_task(() => {
  1616. dom.addEventListener(event_name, target_handler, options);
  1617. });
  1618. } else {
  1619. dom.addEventListener(event_name, target_handler, options);
  1620. }
  1621. return target_handler;
  1622. }
  1623. function event(event_name, dom, handler, capture, passive) {
  1624. var options = { capture, passive };
  1625. var target_handler = create_event(event_name, dom, handler, options);
  1626. if (dom === document.body || dom === window || dom === document) {
  1627. teardown(() => {
  1628. dom.removeEventListener(event_name, target_handler, options);
  1629. });
  1630. }
  1631. }
  1632. function delegate(events) {
  1633. for (var i2 = 0; i2 < events.length; i2++) {
  1634. all_registered_events.add(events[i2]);
  1635. }
  1636. for (var fn of root_event_handles) {
  1637. fn(events);
  1638. }
  1639. }
  1640. function handle_event_propagation(event2) {
  1641. var _a2;
  1642. var handler_element = this;
  1643. var owner_document = (
  1644. /** @type {Node} */
  1645. handler_element.ownerDocument
  1646. );
  1647. var event_name = event2.type;
  1648. var path = ((_a2 = event2.composedPath) == null ? void 0 : _a2.call(event2)) || [];
  1649. var current_target = (
  1650. /** @type {null | Element} */
  1651. path[0] || event2.target
  1652. );
  1653. var path_idx = 0;
  1654. var handled_at = event2.__root;
  1655. if (handled_at) {
  1656. var at_idx = path.indexOf(handled_at);
  1657. if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
  1658. window)) {
  1659. event2.__root = handler_element;
  1660. return;
  1661. }
  1662. var handler_idx = path.indexOf(handler_element);
  1663. if (handler_idx === -1) {
  1664. return;
  1665. }
  1666. if (at_idx <= handler_idx) {
  1667. path_idx = at_idx;
  1668. }
  1669. }
  1670. current_target = /** @type {Element} */
  1671. path[path_idx] || event2.target;
  1672. if (current_target === handler_element) return;
  1673. define_property(event2, "currentTarget", {
  1674. configurable: true,
  1675. get() {
  1676. return current_target || owner_document;
  1677. }
  1678. });
  1679. var previous_reaction = active_reaction;
  1680. var previous_effect = active_effect;
  1681. set_active_reaction(null);
  1682. set_active_effect(null);
  1683. try {
  1684. var throw_error;
  1685. var other_errors = [];
  1686. while (current_target !== null) {
  1687. var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
  1688. current_target.host || null;
  1689. try {
  1690. var delegated = current_target["__" + event_name];
  1691. if (delegated != null && (!/** @type {any} */
  1692. current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
  1693. // -> the target could not have been disabled because it emits the event in the first place
  1694. event2.target === current_target)) {
  1695. if (is_array(delegated)) {
  1696. var [fn, ...data] = delegated;
  1697. fn.apply(current_target, [event2, ...data]);
  1698. } else {
  1699. delegated.call(current_target, event2);
  1700. }
  1701. }
  1702. } catch (error) {
  1703. if (throw_error) {
  1704. other_errors.push(error);
  1705. } else {
  1706. throw_error = error;
  1707. }
  1708. }
  1709. if (event2.cancelBubble || parent_element === handler_element || parent_element === null) {
  1710. break;
  1711. }
  1712. current_target = parent_element;
  1713. }
  1714. if (throw_error) {
  1715. for (let error of other_errors) {
  1716. queueMicrotask(() => {
  1717. throw error;
  1718. });
  1719. }
  1720. throw throw_error;
  1721. }
  1722. } finally {
  1723. event2.__root = handler_element;
  1724. delete event2.currentTarget;
  1725. set_active_reaction(previous_reaction);
  1726. set_active_effect(previous_effect);
  1727. }
  1728. }
  1729. function create_fragment_from_html(html) {
  1730. var elem = document.createElement("template");
  1731. elem.innerHTML = html;
  1732. return elem.content;
  1733. }
  1734. function assign_nodes(start, end) {
  1735. var effect2 = (
  1736. /** @type {Effect} */
  1737. active_effect
  1738. );
  1739. if (effect2.nodes_start === null) {
  1740. effect2.nodes_start = start;
  1741. effect2.nodes_end = end;
  1742. }
  1743. }
  1744. // @__NO_SIDE_EFFECTS__
  1745. function template(content, flags) {
  1746. var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
  1747. var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
  1748. var node;
  1749. var has_start = !content.startsWith("<!>");
  1750. return () => {
  1751. if (node === void 0) {
  1752. node = create_fragment_from_html(has_start ? content : "<!>" + content);
  1753. if (!is_fragment) node = /** @type {Node} */
  1754. /* @__PURE__ */ get_first_child(node);
  1755. }
  1756. var clone = (
  1757. /** @type {TemplateNode} */
  1758. use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
  1759. );
  1760. if (is_fragment) {
  1761. var start = (
  1762. /** @type {TemplateNode} */
  1763. /* @__PURE__ */ get_first_child(clone)
  1764. );
  1765. var end = (
  1766. /** @type {TemplateNode} */
  1767. clone.lastChild
  1768. );
  1769. assign_nodes(start, end);
  1770. } else {
  1771. assign_nodes(clone, clone);
  1772. }
  1773. return clone;
  1774. };
  1775. }
  1776. // @__NO_SIDE_EFFECTS__
  1777. function ns_template(content, flags, ns = "svg") {
  1778. var has_start = !content.startsWith("<!>");
  1779. var wrapped = `<${ns}>${has_start ? content : "<!>" + content}</${ns}>`;
  1780. var node;
  1781. return () => {
  1782. if (!node) {
  1783. var fragment = (
  1784. /** @type {DocumentFragment} */
  1785. create_fragment_from_html(wrapped)
  1786. );
  1787. var root2 = (
  1788. /** @type {Element} */
  1789. /* @__PURE__ */ get_first_child(fragment)
  1790. );
  1791. {
  1792. node = /** @type {Element} */
  1793. /* @__PURE__ */ get_first_child(root2);
  1794. }
  1795. }
  1796. var clone = (
  1797. /** @type {TemplateNode} */
  1798. node.cloneNode(true)
  1799. );
  1800. {
  1801. assign_nodes(clone, clone);
  1802. }
  1803. return clone;
  1804. };
  1805. }
  1806. function text(value = "") {
  1807. {
  1808. var t = create_text(value + "");
  1809. assign_nodes(t, t);
  1810. return t;
  1811. }
  1812. }
  1813. function comment() {
  1814. var frag = document.createDocumentFragment();
  1815. var start = document.createComment("");
  1816. var anchor = create_text();
  1817. frag.append(start, anchor);
  1818. assign_nodes(start, anchor);
  1819. return frag;
  1820. }
  1821. function append(anchor, dom) {
  1822. if (anchor === null) {
  1823. return;
  1824. }
  1825. anchor.before(
  1826. /** @type {Node} */
  1827. dom
  1828. );
  1829. }
  1830. function set_text(text2, value) {
  1831. var str = value == null ? "" : typeof value === "object" ? value + "" : value;
  1832. if (str !== (text2.__t ?? (text2.__t = text2.nodeValue))) {
  1833. text2.__t = str;
  1834. text2.nodeValue = str + "";
  1835. }
  1836. }
  1837. function mount(component2, options) {
  1838. return _mount(component2, options);
  1839. }
  1840. const document_listeners = /* @__PURE__ */ new Map();
  1841. function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
  1842. init_operations();
  1843. var registered_events = /* @__PURE__ */ new Set();
  1844. var event_handle = (events2) => {
  1845. for (var i2 = 0; i2 < events2.length; i2++) {
  1846. var event_name = events2[i2];
  1847. if (registered_events.has(event_name)) continue;
  1848. registered_events.add(event_name);
  1849. var passive = is_passive_event(event_name);
  1850. target.addEventListener(event_name, handle_event_propagation, { passive });
  1851. var n = document_listeners.get(event_name);
  1852. if (n === void 0) {
  1853. document.addEventListener(event_name, handle_event_propagation, { passive });
  1854. document_listeners.set(event_name, 1);
  1855. } else {
  1856. document_listeners.set(event_name, n + 1);
  1857. }
  1858. }
  1859. };
  1860. event_handle(array_from(all_registered_events));
  1861. root_event_handles.add(event_handle);
  1862. var component2 = void 0;
  1863. var unmount = component_root(() => {
  1864. var anchor_node = anchor ?? target.appendChild(create_text());
  1865. branch(() => {
  1866. if (context) {
  1867. push({});
  1868. var ctx = (
  1869. /** @type {ComponentContext} */
  1870. component_context
  1871. );
  1872. ctx.c = context;
  1873. }
  1874. if (events) {
  1875. props.$$events = events;
  1876. }
  1877. component2 = Component(anchor_node, props) || {};
  1878. if (context) {
  1879. pop();
  1880. }
  1881. });
  1882. return () => {
  1883. var _a2;
  1884. for (var event_name of registered_events) {
  1885. target.removeEventListener(event_name, handle_event_propagation);
  1886. var n = (
  1887. /** @type {number} */
  1888. document_listeners.get(event_name)
  1889. );
  1890. if (--n === 0) {
  1891. document.removeEventListener(event_name, handle_event_propagation);
  1892. document_listeners.delete(event_name);
  1893. } else {
  1894. document_listeners.set(event_name, n);
  1895. }
  1896. }
  1897. root_event_handles.delete(event_handle);
  1898. if (anchor_node !== anchor) {
  1899. (_a2 = anchor_node.parentNode) == null ? void 0 : _a2.removeChild(anchor_node);
  1900. }
  1901. };
  1902. });
  1903. mounted_components.set(component2, unmount);
  1904. return component2;
  1905. }
  1906. let mounted_components = /* @__PURE__ */ new WeakMap();
  1907. function if_block(node, fn, [root_index, hydrate_index] = [0, 0]) {
  1908. var anchor = node;
  1909. var consequent_effect = null;
  1910. var alternate_effect = null;
  1911. var condition = UNINITIALIZED;
  1912. var flags = root_index > 0 ? EFFECT_TRANSPARENT : 0;
  1913. var has_branch = false;
  1914. const set_branch = (fn2, flag = true) => {
  1915. has_branch = true;
  1916. update_branch(flag, fn2);
  1917. };
  1918. const update_branch = (new_condition, fn2) => {
  1919. if (condition === (condition = new_condition)) return;
  1920. if (condition) {
  1921. if (consequent_effect) {
  1922. resume_effect(consequent_effect);
  1923. } else if (fn2) {
  1924. consequent_effect = branch(() => fn2(anchor));
  1925. }
  1926. if (alternate_effect) {
  1927. pause_effect(alternate_effect, () => {
  1928. alternate_effect = null;
  1929. });
  1930. }
  1931. } else {
  1932. if (alternate_effect) {
  1933. resume_effect(alternate_effect);
  1934. } else if (fn2) {
  1935. alternate_effect = branch(() => fn2(anchor, [root_index + 1, hydrate_index]));
  1936. }
  1937. if (consequent_effect) {
  1938. pause_effect(consequent_effect, () => {
  1939. consequent_effect = null;
  1940. });
  1941. }
  1942. }
  1943. };
  1944. block(() => {
  1945. has_branch = false;
  1946. fn(set_branch);
  1947. if (!has_branch) {
  1948. update_branch(null, null);
  1949. }
  1950. }, flags);
  1951. }
  1952. function index(_, i2) {
  1953. return i2;
  1954. }
  1955. function pause_effects(state2, items, controlled_anchor, items_map) {
  1956. var transitions = [];
  1957. var length = items.length;
  1958. for (var i2 = 0; i2 < length; i2++) {
  1959. pause_children(items[i2].e, transitions, true);
  1960. }
  1961. var is_controlled = length > 0 && transitions.length === 0 && controlled_anchor !== null;
  1962. if (is_controlled) {
  1963. var parent_node = (
  1964. /** @type {Element} */
  1965. /** @type {Element} */
  1966. controlled_anchor.parentNode
  1967. );
  1968. clear_text_content(parent_node);
  1969. parent_node.append(
  1970. /** @type {Element} */
  1971. controlled_anchor
  1972. );
  1973. items_map.clear();
  1974. link(state2, items[0].prev, items[length - 1].next);
  1975. }
  1976. run_out_transitions(transitions, () => {
  1977. for (var i3 = 0; i3 < length; i3++) {
  1978. var item = items[i3];
  1979. if (!is_controlled) {
  1980. items_map.delete(item.k);
  1981. link(state2, item.prev, item.next);
  1982. }
  1983. destroy_effect(item.e, !is_controlled);
  1984. }
  1985. });
  1986. }
  1987. function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) {
  1988. var anchor = node;
  1989. var state2 = { flags, items: /* @__PURE__ */ new Map(), first: null };
  1990. var is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
  1991. if (is_controlled) {
  1992. var parent_node = (
  1993. /** @type {Element} */
  1994. node
  1995. );
  1996. anchor = parent_node.appendChild(create_text());
  1997. }
  1998. var fallback = null;
  1999. var was_empty = false;
  2000. var each_array = /* @__PURE__ */ derived_safe_equal(() => {
  2001. var collection = get_collection();
  2002. return is_array(collection) ? collection : collection == null ? [] : array_from(collection);
  2003. });
  2004. block(() => {
  2005. var array = get$1(each_array);
  2006. var length = array.length;
  2007. if (was_empty && length === 0) {
  2008. return;
  2009. }
  2010. was_empty = length === 0;
  2011. {
  2012. reconcile(array, state2, anchor, render_fn, flags, get_key, get_collection);
  2013. }
  2014. if (fallback_fn !== null) {
  2015. if (length === 0) {
  2016. if (fallback) {
  2017. resume_effect(fallback);
  2018. } else {
  2019. fallback = branch(() => fallback_fn(anchor));
  2020. }
  2021. } else if (fallback !== null) {
  2022. pause_effect(fallback, () => {
  2023. fallback = null;
  2024. });
  2025. }
  2026. }
  2027. get$1(each_array);
  2028. });
  2029. }
  2030. function reconcile(array, state2, anchor, render_fn, flags, get_key, get_collection) {
  2031. var _a2, _b2, _c2, _d;
  2032. var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
  2033. var should_update = (flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0;
  2034. var length = array.length;
  2035. var items = state2.items;
  2036. var first = state2.first;
  2037. var current = first;
  2038. var seen;
  2039. var prev = null;
  2040. var to_animate;
  2041. var matched = [];
  2042. var stashed = [];
  2043. var value;
  2044. var key;
  2045. var item;
  2046. var i2;
  2047. if (is_animated) {
  2048. for (i2 = 0; i2 < length; i2 += 1) {
  2049. value = array[i2];
  2050. key = get_key(value, i2);
  2051. item = items.get(key);
  2052. if (item !== void 0) {
  2053. (_a2 = item.a) == null ? void 0 : _a2.measure();
  2054. (to_animate ?? (to_animate = /* @__PURE__ */ new Set())).add(item);
  2055. }
  2056. }
  2057. }
  2058. for (i2 = 0; i2 < length; i2 += 1) {
  2059. value = array[i2];
  2060. key = get_key(value, i2);
  2061. item = items.get(key);
  2062. if (item === void 0) {
  2063. var child_anchor = current ? (
  2064. /** @type {TemplateNode} */
  2065. current.e.nodes_start
  2066. ) : anchor;
  2067. prev = create_item(
  2068. child_anchor,
  2069. state2,
  2070. prev,
  2071. prev === null ? state2.first : prev.next,
  2072. value,
  2073. key,
  2074. i2,
  2075. render_fn,
  2076. flags,
  2077. get_collection
  2078. );
  2079. items.set(key, prev);
  2080. matched = [];
  2081. stashed = [];
  2082. current = prev.next;
  2083. continue;
  2084. }
  2085. if (should_update) {
  2086. update_item(item, value, i2, flags);
  2087. }
  2088. if ((item.e.f & INERT) !== 0) {
  2089. resume_effect(item.e);
  2090. if (is_animated) {
  2091. (_b2 = item.a) == null ? void 0 : _b2.unfix();
  2092. (to_animate ?? (to_animate = /* @__PURE__ */ new Set())).delete(item);
  2093. }
  2094. }
  2095. if (item !== current) {
  2096. if (seen !== void 0 && seen.has(item)) {
  2097. if (matched.length < stashed.length) {
  2098. var start = stashed[0];
  2099. var j;
  2100. prev = start.prev;
  2101. var a2 = matched[0];
  2102. var b = matched[matched.length - 1];
  2103. for (j = 0; j < matched.length; j += 1) {
  2104. move(matched[j], start, anchor);
  2105. }
  2106. for (j = 0; j < stashed.length; j += 1) {
  2107. seen.delete(stashed[j]);
  2108. }
  2109. link(state2, a2.prev, b.next);
  2110. link(state2, prev, a2);
  2111. link(state2, b, start);
  2112. current = start;
  2113. prev = b;
  2114. i2 -= 1;
  2115. matched = [];
  2116. stashed = [];
  2117. } else {
  2118. seen.delete(item);
  2119. move(item, current, anchor);
  2120. link(state2, item.prev, item.next);
  2121. link(state2, item, prev === null ? state2.first : prev.next);
  2122. link(state2, prev, item);
  2123. prev = item;
  2124. }
  2125. continue;
  2126. }
  2127. matched = [];
  2128. stashed = [];
  2129. while (current !== null && current.k !== key) {
  2130. if ((current.e.f & INERT) === 0) {
  2131. (seen ?? (seen = /* @__PURE__ */ new Set())).add(current);
  2132. }
  2133. stashed.push(current);
  2134. current = current.next;
  2135. }
  2136. if (current === null) {
  2137. continue;
  2138. }
  2139. item = current;
  2140. }
  2141. matched.push(item);
  2142. prev = item;
  2143. current = item.next;
  2144. }
  2145. if (current !== null || seen !== void 0) {
  2146. var to_destroy = seen === void 0 ? [] : array_from(seen);
  2147. while (current !== null) {
  2148. if ((current.e.f & INERT) === 0) {
  2149. to_destroy.push(current);
  2150. }
  2151. current = current.next;
  2152. }
  2153. var destroy_length = to_destroy.length;
  2154. if (destroy_length > 0) {
  2155. var controlled_anchor = (flags & EACH_IS_CONTROLLED) !== 0 && length === 0 ? anchor : null;
  2156. if (is_animated) {
  2157. for (i2 = 0; i2 < destroy_length; i2 += 1) {
  2158. (_c2 = to_destroy[i2].a) == null ? void 0 : _c2.measure();
  2159. }
  2160. for (i2 = 0; i2 < destroy_length; i2 += 1) {
  2161. (_d = to_destroy[i2].a) == null ? void 0 : _d.fix();
  2162. }
  2163. }
  2164. pause_effects(state2, to_destroy, controlled_anchor, items);
  2165. }
  2166. }
  2167. if (is_animated) {
  2168. queue_micro_task(() => {
  2169. var _a3;
  2170. if (to_animate === void 0) return;
  2171. for (item of to_animate) {
  2172. (_a3 = item.a) == null ? void 0 : _a3.apply();
  2173. }
  2174. });
  2175. }
  2176. active_effect.first = state2.first && state2.first.e;
  2177. active_effect.last = prev && prev.e;
  2178. }
  2179. function update_item(item, value, index2, type) {
  2180. if ((type & EACH_ITEM_REACTIVE) !== 0) {
  2181. internal_set(item.v, value);
  2182. }
  2183. if ((type & EACH_INDEX_REACTIVE) !== 0) {
  2184. internal_set(
  2185. /** @type {Value<number>} */
  2186. item.i,
  2187. index2
  2188. );
  2189. } else {
  2190. item.i = index2;
  2191. }
  2192. }
  2193. function create_item(anchor, state2, prev, next2, value, key, index2, render_fn, flags, get_collection) {
  2194. var reactive = (flags & EACH_ITEM_REACTIVE) !== 0;
  2195. var mutable = (flags & EACH_ITEM_IMMUTABLE) === 0;
  2196. var v = reactive ? mutable ? /* @__PURE__ */ mutable_source(value) : source(value) : value;
  2197. var i2 = (flags & EACH_INDEX_REACTIVE) === 0 ? index2 : source(index2);
  2198. var item = {
  2199. i: i2,
  2200. v,
  2201. k: key,
  2202. a: null,
  2203. // @ts-expect-error
  2204. e: null,
  2205. prev,
  2206. next: next2
  2207. };
  2208. try {
  2209. item.e = branch(() => render_fn(anchor, v, i2, get_collection), hydrating);
  2210. item.e.prev = prev && prev.e;
  2211. item.e.next = next2 && next2.e;
  2212. if (prev === null) {
  2213. state2.first = item;
  2214. } else {
  2215. prev.next = item;
  2216. prev.e.next = item.e;
  2217. }
  2218. if (next2 !== null) {
  2219. next2.prev = item;
  2220. next2.e.prev = item.e;
  2221. }
  2222. return item;
  2223. } finally {
  2224. }
  2225. }
  2226. function move(item, next2, anchor) {
  2227. var end = item.next ? (
  2228. /** @type {TemplateNode} */
  2229. item.next.e.nodes_start
  2230. ) : anchor;
  2231. var dest = next2 ? (
  2232. /** @type {TemplateNode} */
  2233. next2.e.nodes_start
  2234. ) : anchor;
  2235. var node = (
  2236. /** @type {TemplateNode} */
  2237. item.e.nodes_start
  2238. );
  2239. while (node !== end) {
  2240. var next_node = (
  2241. /** @type {TemplateNode} */
  2242. /* @__PURE__ */ get_next_sibling(node)
  2243. );
  2244. dest.before(node);
  2245. node = next_node;
  2246. }
  2247. }
  2248. function link(state2, prev, next2) {
  2249. if (prev === null) {
  2250. state2.first = next2;
  2251. } else {
  2252. prev.next = next2;
  2253. prev.e.next = next2 && next2.e;
  2254. }
  2255. if (next2 !== null) {
  2256. next2.prev = prev;
  2257. next2.e.prev = prev && prev.e;
  2258. }
  2259. }
  2260. function slot(anchor, $$props, name, slot_props, fallback_fn) {
  2261. var _a2;
  2262. var slot_fn = (_a2 = $$props.$$slots) == null ? void 0 : _a2[name];
  2263. var is_interop = false;
  2264. if (slot_fn === true) {
  2265. slot_fn = $$props[name === "default" ? "children" : name];
  2266. is_interop = true;
  2267. }
  2268. if (slot_fn === void 0) {
  2269. if (fallback_fn !== null) {
  2270. fallback_fn(anchor);
  2271. }
  2272. } else {
  2273. slot_fn(anchor, is_interop ? () => slot_props : slot_props);
  2274. }
  2275. }
  2276. function snippet(node, get_snippet, ...args) {
  2277. var anchor = node;
  2278. var snippet2 = noop;
  2279. var snippet_effect;
  2280. block(() => {
  2281. if (snippet2 === (snippet2 = get_snippet())) return;
  2282. if (snippet_effect) {
  2283. destroy_effect(snippet_effect);
  2284. snippet_effect = null;
  2285. }
  2286. snippet_effect = branch(() => (
  2287. /** @type {SnippetFn} */
  2288. snippet2(anchor, ...args)
  2289. ));
  2290. }, EFFECT_TRANSPARENT);
  2291. }
  2292. function component(node, get_component, render_fn) {
  2293. var anchor = node;
  2294. var component2;
  2295. var effect2;
  2296. block(() => {
  2297. if (component2 === (component2 = get_component())) return;
  2298. if (effect2) {
  2299. pause_effect(effect2);
  2300. effect2 = null;
  2301. }
  2302. if (component2) {
  2303. effect2 = branch(() => render_fn(anchor, component2));
  2304. }
  2305. }, EFFECT_TRANSPARENT);
  2306. }
  2307. function r(e) {
  2308. var t, f, n = "";
  2309. if ("string" == typeof e || "number" == typeof e) n += e;
  2310. else if ("object" == typeof e) if (Array.isArray(e)) {
  2311. var o2 = e.length;
  2312. for (t = 0; t < o2; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
  2313. } else for (f in e) e[f] && (n && (n += " "), n += f);
  2314. return n;
  2315. }
  2316. function clsx$1() {
  2317. for (var e, t, f = 0, n = "", o2 = arguments.length; f < o2; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
  2318. return n;
  2319. }
  2320. function clsx(value) {
  2321. if (typeof value === "object") {
  2322. return clsx$1(value);
  2323. } else {
  2324. return value ?? "";
  2325. }
  2326. }
  2327. const whitespace = [..." \n\r\f \v\uFEFF"];
  2328. function to_class(value, hash, directives) {
  2329. var classname = value == null ? "" : "" + value;
  2330. if (hash) {
  2331. classname = classname ? classname + " " + hash : hash;
  2332. }
  2333. if (directives) {
  2334. for (var key in directives) {
  2335. if (directives[key]) {
  2336. classname = classname ? classname + " " + key : key;
  2337. } else if (classname.length) {
  2338. var len = key.length;
  2339. var a2 = 0;
  2340. while ((a2 = classname.indexOf(key, a2)) >= 0) {
  2341. var b = a2 + len;
  2342. if ((a2 === 0 || whitespace.includes(classname[a2 - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
  2343. classname = (a2 === 0 ? "" : classname.substring(0, a2)) + classname.substring(b + 1);
  2344. } else {
  2345. a2 = b;
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. return classname === "" ? null : classname;
  2352. }
  2353. function append_styles(styles, important = false) {
  2354. var separator = important ? " !important;" : ";";
  2355. var css = "";
  2356. for (var key in styles) {
  2357. var value = styles[key];
  2358. if (value != null && value !== "") {
  2359. css += " " + key + ": " + value + separator;
  2360. }
  2361. }
  2362. return css;
  2363. }
  2364. function to_css_name(name) {
  2365. if (name[0] !== "-" || name[1] !== "-") {
  2366. return name.toLowerCase();
  2367. }
  2368. return name;
  2369. }
  2370. function to_style(value, styles) {
  2371. if (styles) {
  2372. var new_style = "";
  2373. var normal_styles;
  2374. var important_styles;
  2375. if (Array.isArray(styles)) {
  2376. normal_styles = styles[0];
  2377. important_styles = styles[1];
  2378. } else {
  2379. normal_styles = styles;
  2380. }
  2381. if (value) {
  2382. value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim();
  2383. var in_str = false;
  2384. var in_apo = 0;
  2385. var in_comment = false;
  2386. var reserved_names = [];
  2387. if (normal_styles) {
  2388. reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
  2389. }
  2390. if (important_styles) {
  2391. reserved_names.push(...Object.keys(important_styles).map(to_css_name));
  2392. }
  2393. var start_index = 0;
  2394. var name_index = -1;
  2395. const len = value.length;
  2396. for (var i2 = 0; i2 < len; i2++) {
  2397. var c2 = value[i2];
  2398. if (in_comment) {
  2399. if (c2 === "/" && value[i2 - 1] === "*") {
  2400. in_comment = false;
  2401. }
  2402. } else if (in_str) {
  2403. if (in_str === c2) {
  2404. in_str = false;
  2405. }
  2406. } else if (c2 === "/" && value[i2 + 1] === "*") {
  2407. in_comment = true;
  2408. } else if (c2 === '"' || c2 === "'") {
  2409. in_str = c2;
  2410. } else if (c2 === "(") {
  2411. in_apo++;
  2412. } else if (c2 === ")") {
  2413. in_apo--;
  2414. }
  2415. if (!in_comment && in_str === false && in_apo === 0) {
  2416. if (c2 === ":" && name_index === -1) {
  2417. name_index = i2;
  2418. } else if (c2 === ";" || i2 === len - 1) {
  2419. if (name_index !== -1) {
  2420. var name = to_css_name(value.substring(start_index, name_index).trim());
  2421. if (!reserved_names.includes(name)) {
  2422. if (c2 !== ";") {
  2423. i2++;
  2424. }
  2425. var property = value.substring(start_index, i2).trim();
  2426. new_style += " " + property + ";";
  2427. }
  2428. }
  2429. start_index = i2 + 1;
  2430. name_index = -1;
  2431. }
  2432. }
  2433. }
  2434. }
  2435. if (normal_styles) {
  2436. new_style += append_styles(normal_styles);
  2437. }
  2438. if (important_styles) {
  2439. new_style += append_styles(important_styles, true);
  2440. }
  2441. new_style = new_style.trim();
  2442. return new_style === "" ? null : new_style;
  2443. }
  2444. return value == null ? null : String(value);
  2445. }
  2446. function set_class(dom, is_html, value, hash, prev_classes, next_classes) {
  2447. var prev = dom.__className;
  2448. if (prev !== value || prev === void 0) {
  2449. var next_class_name = to_class(value, hash, next_classes);
  2450. {
  2451. if (next_class_name == null) {
  2452. dom.removeAttribute("class");
  2453. } else if (is_html) {
  2454. dom.className = next_class_name;
  2455. } else {
  2456. dom.setAttribute("class", next_class_name);
  2457. }
  2458. }
  2459. dom.__className = value;
  2460. } else if (next_classes && prev_classes !== next_classes) {
  2461. for (var key in next_classes) {
  2462. var is_present = !!next_classes[key];
  2463. if (prev_classes == null || is_present !== !!prev_classes[key]) {
  2464. dom.classList.toggle(key, is_present);
  2465. }
  2466. }
  2467. }
  2468. return next_classes;
  2469. }
  2470. function update_styles(dom, prev = {}, next2, priority) {
  2471. for (var key in next2) {
  2472. var value = next2[key];
  2473. if (prev[key] !== value) {
  2474. if (next2[key] == null) {
  2475. dom.style.removeProperty(key);
  2476. } else {
  2477. dom.style.setProperty(key, value, priority);
  2478. }
  2479. }
  2480. }
  2481. }
  2482. function set_style(dom, value, prev_styles, next_styles) {
  2483. var prev = dom.__style;
  2484. if (prev !== value) {
  2485. var next_style_attr = to_style(value, next_styles);
  2486. {
  2487. if (next_style_attr == null) {
  2488. dom.removeAttribute("style");
  2489. } else {
  2490. dom.style.cssText = next_style_attr;
  2491. }
  2492. }
  2493. dom.__style = value;
  2494. } else if (next_styles) {
  2495. if (Array.isArray(next_styles)) {
  2496. update_styles(dom, prev_styles == null ? void 0 : prev_styles[0], next_styles[0]);
  2497. update_styles(dom, prev_styles == null ? void 0 : prev_styles[1], next_styles[1], "important");
  2498. } else {
  2499. update_styles(dom, prev_styles, next_styles);
  2500. }
  2501. }
  2502. return next_styles;
  2503. }
  2504. const CLASS = Symbol("class");
  2505. const STYLE = Symbol("style");
  2506. const IS_CUSTOM_ELEMENT = Symbol("is custom element");
  2507. const IS_HTML = Symbol("is html");
  2508. function set_selected(element, selected) {
  2509. if (selected) {
  2510. if (!element.hasAttribute("selected")) {
  2511. element.setAttribute("selected", "");
  2512. }
  2513. } else {
  2514. element.removeAttribute("selected");
  2515. }
  2516. }
  2517. function set_attribute(element, attribute, value, skip_warning) {
  2518. var attributes = get_attributes(element);
  2519. if (attributes[attribute] === (attributes[attribute] = value)) return;
  2520. if (attribute === "loading") {
  2521. element[LOADING_ATTR_SYMBOL] = value;
  2522. }
  2523. if (value == null) {
  2524. element.removeAttribute(attribute);
  2525. } else if (typeof value !== "string" && get_setters(element).includes(attribute)) {
  2526. element[attribute] = value;
  2527. } else {
  2528. element.setAttribute(attribute, value);
  2529. }
  2530. }
  2531. function set_attributes(element, prev, next2, css_hash, skip_warning = false) {
  2532. var attributes = get_attributes(element);
  2533. var is_custom_element = attributes[IS_CUSTOM_ELEMENT];
  2534. var preserve_attribute_case = !attributes[IS_HTML];
  2535. var current = prev || {};
  2536. var is_option_element = element.tagName === "OPTION";
  2537. for (var key in prev) {
  2538. if (!(key in next2)) {
  2539. next2[key] = null;
  2540. }
  2541. }
  2542. if (next2.class) {
  2543. next2.class = clsx(next2.class);
  2544. } else if (css_hash || next2[CLASS]) {
  2545. next2.class = null;
  2546. }
  2547. if (next2[STYLE]) {
  2548. next2.style ?? (next2.style = null);
  2549. }
  2550. var setters = get_setters(element);
  2551. for (const key2 in next2) {
  2552. let value = next2[key2];
  2553. if (is_option_element && key2 === "value" && value == null) {
  2554. element.value = element.__value = "";
  2555. current[key2] = value;
  2556. continue;
  2557. }
  2558. if (key2 === "class") {
  2559. var is_html = element.namespaceURI === "http://www.w3.org/1999/xhtml";
  2560. set_class(element, is_html, value, css_hash, prev == null ? void 0 : prev[CLASS], next2[CLASS]);
  2561. current[key2] = value;
  2562. current[CLASS] = next2[CLASS];
  2563. continue;
  2564. }
  2565. if (key2 === "style") {
  2566. set_style(element, value, prev == null ? void 0 : prev[STYLE], next2[STYLE]);
  2567. current[key2] = value;
  2568. current[STYLE] = next2[STYLE];
  2569. continue;
  2570. }
  2571. var prev_value = current[key2];
  2572. if (value === prev_value) continue;
  2573. current[key2] = value;
  2574. var prefix = key2[0] + key2[1];
  2575. if (prefix === "$$") continue;
  2576. if (prefix === "on") {
  2577. const opts = {};
  2578. const event_handle_key = "$$" + key2;
  2579. let event_name = key2.slice(2);
  2580. var delegated = is_delegated(event_name);
  2581. if (is_capture_event(event_name)) {
  2582. event_name = event_name.slice(0, -7);
  2583. opts.capture = true;
  2584. }
  2585. if (!delegated && prev_value) {
  2586. if (value != null) continue;
  2587. element.removeEventListener(event_name, current[event_handle_key], opts);
  2588. current[event_handle_key] = null;
  2589. }
  2590. if (value != null) {
  2591. if (!delegated) {
  2592. let handle = function(evt) {
  2593. current[key2].call(this, evt);
  2594. };
  2595. current[event_handle_key] = create_event(event_name, element, handle, opts);
  2596. } else {
  2597. element[`__${event_name}`] = value;
  2598. delegate([event_name]);
  2599. }
  2600. } else if (delegated) {
  2601. element[`__${event_name}`] = void 0;
  2602. }
  2603. } else if (key2 === "style") {
  2604. set_attribute(element, key2, value);
  2605. } else if (key2 === "autofocus") {
  2606. autofocus(
  2607. /** @type {HTMLElement} */
  2608. element,
  2609. Boolean(value)
  2610. );
  2611. } else if (!is_custom_element && (key2 === "__value" || key2 === "value" && value != null)) {
  2612. element.value = element.__value = value;
  2613. } else if (key2 === "selected" && is_option_element) {
  2614. set_selected(
  2615. /** @type {HTMLOptionElement} */
  2616. element,
  2617. value
  2618. );
  2619. } else {
  2620. var name = key2;
  2621. if (!preserve_attribute_case) {
  2622. name = normalize_attribute(name);
  2623. }
  2624. var is_default = name === "defaultValue" || name === "defaultChecked";
  2625. if (value == null && !is_custom_element && !is_default) {
  2626. attributes[key2] = null;
  2627. if (name === "value" || name === "checked") {
  2628. let input = (
  2629. /** @type {HTMLInputElement} */
  2630. element
  2631. );
  2632. const use_default = prev === void 0;
  2633. if (name === "value") {
  2634. let previous = input.defaultValue;
  2635. input.removeAttribute(name);
  2636. input.defaultValue = previous;
  2637. input.value = input.__value = use_default ? previous : null;
  2638. } else {
  2639. let previous = input.defaultChecked;
  2640. input.removeAttribute(name);
  2641. input.defaultChecked = previous;
  2642. input.checked = use_default ? previous : false;
  2643. }
  2644. } else {
  2645. element.removeAttribute(key2);
  2646. }
  2647. } else if (is_default || setters.includes(name) && (is_custom_element || typeof value !== "string")) {
  2648. element[name] = value;
  2649. } else if (typeof value !== "function") {
  2650. set_attribute(element, name, value);
  2651. }
  2652. }
  2653. }
  2654. return current;
  2655. }
  2656. function get_attributes(element) {
  2657. return (
  2658. /** @type {Record<string | symbol, unknown>} **/
  2659. // @ts-expect-error
  2660. element.__attributes ?? (element.__attributes = {
  2661. [IS_CUSTOM_ELEMENT]: element.nodeName.includes("-"),
  2662. [IS_HTML]: element.namespaceURI === NAMESPACE_HTML
  2663. })
  2664. );
  2665. }
  2666. var setters_cache = /* @__PURE__ */ new Map();
  2667. function get_setters(element) {
  2668. var setters = setters_cache.get(element.nodeName);
  2669. if (setters) return setters;
  2670. setters_cache.set(element.nodeName, setters = []);
  2671. var descriptors;
  2672. var proto = element;
  2673. var element_proto = Element.prototype;
  2674. while (element_proto !== proto) {
  2675. descriptors = get_descriptors(proto);
  2676. for (var key in descriptors) {
  2677. if (descriptors[key].set) {
  2678. setters.push(key);
  2679. }
  2680. }
  2681. proto = get_prototype_of(proto);
  2682. }
  2683. return setters;
  2684. }
  2685. function is_bound_this(bound_value, element_or_component) {
  2686. return bound_value === element_or_component || (bound_value == null ? void 0 : bound_value[STATE_SYMBOL]) === element_or_component;
  2687. }
  2688. function bind_this(element_or_component = {}, update2, get_value, get_parts) {
  2689. effect(() => {
  2690. var old_parts;
  2691. var parts;
  2692. render_effect(() => {
  2693. old_parts = parts;
  2694. parts = [];
  2695. untrack(() => {
  2696. if (element_or_component !== get_value(...parts)) {
  2697. update2(element_or_component, ...parts);
  2698. if (old_parts && is_bound_this(get_value(...old_parts), element_or_component)) {
  2699. update2(null, ...old_parts);
  2700. }
  2701. }
  2702. });
  2703. });
  2704. return () => {
  2705. queue_micro_task(() => {
  2706. if (parts && is_bound_this(get_value(...parts), element_or_component)) {
  2707. update2(null, ...parts);
  2708. }
  2709. });
  2710. };
  2711. });
  2712. return element_or_component;
  2713. }
  2714. function init(immutable = false) {
  2715. const context = (
  2716. /** @type {ComponentContextLegacy} */
  2717. component_context
  2718. );
  2719. const callbacks = context.l.u;
  2720. if (!callbacks) return;
  2721. let props = () => deep_read_state(context.s);
  2722. if (immutable) {
  2723. let version = 0;
  2724. let prev = (
  2725. /** @type {Record<string, any>} */
  2726. {}
  2727. );
  2728. const d = /* @__PURE__ */ derived(() => {
  2729. let changed = false;
  2730. const props2 = context.s;
  2731. for (const key in props2) {
  2732. if (props2[key] !== prev[key]) {
  2733. prev[key] = props2[key];
  2734. changed = true;
  2735. }
  2736. }
  2737. if (changed) version++;
  2738. return version;
  2739. });
  2740. props = () => get$1(d);
  2741. }
  2742. if (callbacks.b.length) {
  2743. user_pre_effect(() => {
  2744. observe_all(context, props);
  2745. run_all(callbacks.b);
  2746. });
  2747. }
  2748. user_effect(() => {
  2749. const fns = untrack(() => callbacks.m.map(run));
  2750. return () => {
  2751. for (const fn of fns) {
  2752. if (typeof fn === "function") {
  2753. fn();
  2754. }
  2755. }
  2756. };
  2757. });
  2758. if (callbacks.a.length) {
  2759. user_effect(() => {
  2760. observe_all(context, props);
  2761. run_all(callbacks.a);
  2762. });
  2763. }
  2764. }
  2765. function observe_all(context, props) {
  2766. if (context.l.s) {
  2767. for (const signal of context.l.s) get$1(signal);
  2768. }
  2769. props();
  2770. }
  2771. function subscribe_to_store(store, run2, invalidate) {
  2772. if (store == null) {
  2773. run2(void 0);
  2774. return noop;
  2775. }
  2776. const unsub = untrack(
  2777. () => store.subscribe(
  2778. run2,
  2779. // @ts-expect-error
  2780. invalidate
  2781. )
  2782. );
  2783. return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
  2784. }
  2785. const subscriber_queue = [];
  2786. function writable(value, start = noop) {
  2787. let stop = null;
  2788. const subscribers = /* @__PURE__ */ new Set();
  2789. function set2(new_value) {
  2790. if (safe_not_equal(value, new_value)) {
  2791. value = new_value;
  2792. if (stop) {
  2793. const run_queue = !subscriber_queue.length;
  2794. for (const subscriber of subscribers) {
  2795. subscriber[1]();
  2796. subscriber_queue.push(subscriber, value);
  2797. }
  2798. if (run_queue) {
  2799. for (let i2 = 0; i2 < subscriber_queue.length; i2 += 2) {
  2800. subscriber_queue[i2][0](subscriber_queue[i2 + 1]);
  2801. }
  2802. subscriber_queue.length = 0;
  2803. }
  2804. }
  2805. }
  2806. }
  2807. function update2(fn) {
  2808. set2(fn(
  2809. /** @type {T} */
  2810. value
  2811. ));
  2812. }
  2813. function subscribe(run2, invalidate = noop) {
  2814. const subscriber = [run2, invalidate];
  2815. subscribers.add(subscriber);
  2816. if (subscribers.size === 1) {
  2817. stop = start(set2, update2) || noop;
  2818. }
  2819. run2(
  2820. /** @type {T} */
  2821. value
  2822. );
  2823. return () => {
  2824. subscribers.delete(subscriber);
  2825. if (subscribers.size === 0 && stop) {
  2826. stop();
  2827. stop = null;
  2828. }
  2829. };
  2830. }
  2831. return { set: set2, update: update2, subscribe };
  2832. }
  2833. function get(store) {
  2834. let value;
  2835. subscribe_to_store(store, (_) => value = _)();
  2836. return value;
  2837. }
  2838. let is_store_binding = false;
  2839. let IS_UNMOUNTED = Symbol();
  2840. function store_get(store, store_name, stores) {
  2841. const entry = stores[store_name] ?? (stores[store_name] = {
  2842. store: null,
  2843. source: /* @__PURE__ */ mutable_source(void 0),
  2844. unsubscribe: noop
  2845. });
  2846. if (entry.store !== store && !(IS_UNMOUNTED in stores)) {
  2847. entry.unsubscribe();
  2848. entry.store = store ?? null;
  2849. if (store == null) {
  2850. entry.source.v = void 0;
  2851. entry.unsubscribe = noop;
  2852. } else {
  2853. var is_synchronous_callback = true;
  2854. entry.unsubscribe = subscribe_to_store(store, (v) => {
  2855. if (is_synchronous_callback) {
  2856. entry.source.v = v;
  2857. } else {
  2858. set(entry.source, v);
  2859. }
  2860. });
  2861. is_synchronous_callback = false;
  2862. }
  2863. }
  2864. if (store && IS_UNMOUNTED in stores) {
  2865. return get(store);
  2866. }
  2867. return get$1(entry.source);
  2868. }
  2869. function store_unsub(store, store_name, stores) {
  2870. let entry = stores[store_name];
  2871. if (entry && entry.store !== store) {
  2872. entry.unsubscribe();
  2873. entry.unsubscribe = noop;
  2874. }
  2875. return store;
  2876. }
  2877. function setup_stores() {
  2878. const stores = {};
  2879. function cleanup() {
  2880. teardown(() => {
  2881. for (var store_name in stores) {
  2882. const ref = stores[store_name];
  2883. ref.unsubscribe();
  2884. }
  2885. define_property(stores, IS_UNMOUNTED, {
  2886. enumerable: false,
  2887. value: true
  2888. });
  2889. });
  2890. }
  2891. return [stores, cleanup];
  2892. }
  2893. function capture_store_binding(fn) {
  2894. var previous_is_store_binding = is_store_binding;
  2895. try {
  2896. is_store_binding = false;
  2897. return [fn(), is_store_binding];
  2898. } finally {
  2899. is_store_binding = previous_is_store_binding;
  2900. }
  2901. }
  2902. const rest_props_handler = {
  2903. get(target, key) {
  2904. if (target.exclude.includes(key)) return;
  2905. return target.props[key];
  2906. },
  2907. set(target, key) {
  2908. return false;
  2909. },
  2910. getOwnPropertyDescriptor(target, key) {
  2911. if (target.exclude.includes(key)) return;
  2912. if (key in target.props) {
  2913. return {
  2914. enumerable: true,
  2915. configurable: true,
  2916. value: target.props[key]
  2917. };
  2918. }
  2919. },
  2920. has(target, key) {
  2921. if (target.exclude.includes(key)) return false;
  2922. return key in target.props;
  2923. },
  2924. ownKeys(target) {
  2925. return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
  2926. }
  2927. };
  2928. // @__NO_SIDE_EFFECTS__
  2929. function rest_props(props, exclude, name) {
  2930. return new Proxy(
  2931. { props, exclude },
  2932. rest_props_handler
  2933. );
  2934. }
  2935. const legacy_rest_props_handler = {
  2936. get(target, key) {
  2937. if (target.exclude.includes(key)) return;
  2938. get$1(target.version);
  2939. return key in target.special ? target.special[key]() : target.props[key];
  2940. },
  2941. set(target, key, value) {
  2942. if (!(key in target.special)) {
  2943. target.special[key] = prop(
  2944. {
  2945. get [key]() {
  2946. return target.props[key];
  2947. }
  2948. },
  2949. /** @type {string} */
  2950. key,
  2951. PROPS_IS_UPDATED
  2952. );
  2953. }
  2954. target.special[key](value);
  2955. update(target.version);
  2956. return true;
  2957. },
  2958. getOwnPropertyDescriptor(target, key) {
  2959. if (target.exclude.includes(key)) return;
  2960. if (key in target.props) {
  2961. return {
  2962. enumerable: true,
  2963. configurable: true,
  2964. value: target.props[key]
  2965. };
  2966. }
  2967. },
  2968. deleteProperty(target, key) {
  2969. if (target.exclude.includes(key)) return true;
  2970. target.exclude.push(key);
  2971. update(target.version);
  2972. return true;
  2973. },
  2974. has(target, key) {
  2975. if (target.exclude.includes(key)) return false;
  2976. return key in target.props;
  2977. },
  2978. ownKeys(target) {
  2979. return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
  2980. }
  2981. };
  2982. function legacy_rest_props(props, exclude) {
  2983. return new Proxy({ props, exclude, special: {}, version: source(0) }, legacy_rest_props_handler);
  2984. }
  2985. const spread_props_handler = {
  2986. get(target, key) {
  2987. let i2 = target.props.length;
  2988. while (i2--) {
  2989. let p = target.props[i2];
  2990. if (is_function(p)) p = p();
  2991. if (typeof p === "object" && p !== null && key in p) return p[key];
  2992. }
  2993. },
  2994. set(target, key, value) {
  2995. let i2 = target.props.length;
  2996. while (i2--) {
  2997. let p = target.props[i2];
  2998. if (is_function(p)) p = p();
  2999. const desc = get_descriptor(p, key);
  3000. if (desc && desc.set) {
  3001. desc.set(value);
  3002. return true;
  3003. }
  3004. }
  3005. return false;
  3006. },
  3007. getOwnPropertyDescriptor(target, key) {
  3008. let i2 = target.props.length;
  3009. while (i2--) {
  3010. let p = target.props[i2];
  3011. if (is_function(p)) p = p();
  3012. if (typeof p === "object" && p !== null && key in p) {
  3013. const descriptor = get_descriptor(p, key);
  3014. if (descriptor && !descriptor.configurable) {
  3015. descriptor.configurable = true;
  3016. }
  3017. return descriptor;
  3018. }
  3019. }
  3020. },
  3021. has(target, key) {
  3022. if (key === STATE_SYMBOL || key === LEGACY_PROPS) return false;
  3023. for (let p of target.props) {
  3024. if (is_function(p)) p = p();
  3025. if (p != null && key in p) return true;
  3026. }
  3027. return false;
  3028. },
  3029. ownKeys(target) {
  3030. const keys = [];
  3031. for (let p of target.props) {
  3032. if (is_function(p)) p = p();
  3033. for (const key in p) {
  3034. if (!keys.includes(key)) keys.push(key);
  3035. }
  3036. }
  3037. return keys;
  3038. }
  3039. };
  3040. function spread_props(...props) {
  3041. return new Proxy({ props }, spread_props_handler);
  3042. }
  3043. function has_destroyed_component_ctx(current_value) {
  3044. var _a2;
  3045. return ((_a2 = current_value.ctx) == null ? void 0 : _a2.d) ?? false;
  3046. }
  3047. function prop(props, key, flags, fallback) {
  3048. var _a2;
  3049. var immutable = (flags & PROPS_IS_IMMUTABLE) !== 0;
  3050. var runes = !legacy_mode_flag || (flags & PROPS_IS_RUNES) !== 0;
  3051. var bindable = (flags & PROPS_IS_BINDABLE) !== 0;
  3052. var lazy = (flags & PROPS_IS_LAZY_INITIAL) !== 0;
  3053. var is_store_sub = false;
  3054. var prop_value;
  3055. if (bindable) {
  3056. [prop_value, is_store_sub] = capture_store_binding(() => (
  3057. /** @type {V} */
  3058. props[key]
  3059. ));
  3060. } else {
  3061. prop_value = /** @type {V} */
  3062. props[key];
  3063. }
  3064. var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
  3065. var setter = bindable && (((_a2 = get_descriptor(props, key)) == null ? void 0 : _a2.set) ?? (is_entry_props && key in props && ((v) => props[key] = v))) || void 0;
  3066. var fallback_value = (
  3067. /** @type {V} */
  3068. fallback
  3069. );
  3070. var fallback_dirty = true;
  3071. var fallback_used = false;
  3072. var get_fallback = () => {
  3073. fallback_used = true;
  3074. if (fallback_dirty) {
  3075. fallback_dirty = false;
  3076. if (lazy) {
  3077. fallback_value = untrack(
  3078. /** @type {() => V} */
  3079. fallback
  3080. );
  3081. } else {
  3082. fallback_value = /** @type {V} */
  3083. fallback;
  3084. }
  3085. }
  3086. return fallback_value;
  3087. };
  3088. if (prop_value === void 0 && fallback !== void 0) {
  3089. if (setter && runes) {
  3090. props_invalid_value();
  3091. }
  3092. prop_value = get_fallback();
  3093. if (setter) setter(prop_value);
  3094. }
  3095. var getter;
  3096. if (runes) {
  3097. getter = () => {
  3098. var value = (
  3099. /** @type {V} */
  3100. props[key]
  3101. );
  3102. if (value === void 0) return get_fallback();
  3103. fallback_dirty = true;
  3104. fallback_used = false;
  3105. return value;
  3106. };
  3107. } else {
  3108. var derived_getter = (immutable ? derived : derived_safe_equal)(
  3109. () => (
  3110. /** @type {V} */
  3111. props[key]
  3112. )
  3113. );
  3114. derived_getter.f |= LEGACY_DERIVED_PROP;
  3115. getter = () => {
  3116. var value = get$1(derived_getter);
  3117. if (value !== void 0) fallback_value = /** @type {V} */
  3118. void 0;
  3119. return value === void 0 ? fallback_value : value;
  3120. };
  3121. }
  3122. if ((flags & PROPS_IS_UPDATED) === 0) {
  3123. return getter;
  3124. }
  3125. if (setter) {
  3126. var legacy_parent = props.$$legacy;
  3127. return function(value, mutation) {
  3128. if (arguments.length > 0) {
  3129. if (!runes || !mutation || legacy_parent || is_store_sub) {
  3130. setter(mutation ? getter() : value);
  3131. }
  3132. return value;
  3133. } else {
  3134. return getter();
  3135. }
  3136. };
  3137. }
  3138. var from_child = false;
  3139. var inner_current_value = /* @__PURE__ */ mutable_source(prop_value);
  3140. var current_value = /* @__PURE__ */ derived(() => {
  3141. var parent_value = getter();
  3142. var child_value = get$1(inner_current_value);
  3143. if (from_child) {
  3144. from_child = false;
  3145. return child_value;
  3146. }
  3147. return inner_current_value.v = parent_value;
  3148. });
  3149. if (bindable) {
  3150. get$1(current_value);
  3151. }
  3152. if (!immutable) current_value.equals = safe_equals;
  3153. return function(value, mutation) {
  3154. if (arguments.length > 0) {
  3155. const new_value = mutation ? get$1(current_value) : runes && bindable ? proxy(value) : value;
  3156. if (!current_value.equals(new_value)) {
  3157. from_child = true;
  3158. set(inner_current_value, new_value);
  3159. if (fallback_used && fallback_value !== void 0) {
  3160. fallback_value = new_value;
  3161. }
  3162. if (has_destroyed_component_ctx(current_value)) {
  3163. return value;
  3164. }
  3165. untrack(() => get$1(current_value));
  3166. }
  3167. return value;
  3168. }
  3169. if (has_destroyed_component_ctx(current_value)) {
  3170. return current_value.v;
  3171. }
  3172. return get$1(current_value);
  3173. };
  3174. }
  3175. function onMount(fn) {
  3176. if (component_context === null) {
  3177. lifecycle_outside_component();
  3178. }
  3179. if (legacy_mode_flag && component_context.l !== null) {
  3180. init_update_callbacks(component_context).m.push(fn);
  3181. } else {
  3182. user_effect(() => {
  3183. const cleanup = untrack(fn);
  3184. if (typeof cleanup === "function") return (
  3185. /** @type {() => void} */
  3186. cleanup
  3187. );
  3188. });
  3189. }
  3190. }
  3191. function onDestroy(fn) {
  3192. if (component_context === null) {
  3193. lifecycle_outside_component();
  3194. }
  3195. onMount(() => () => untrack(fn));
  3196. }
  3197. function init_update_callbacks(context) {
  3198. var l = (
  3199. /** @type {ComponentContextLegacy} */
  3200. context.l
  3201. );
  3202. return l.u ?? (l.u = { a: [], b: [], m: [] });
  3203. }
  3204. const PUBLIC_VERSION = "5";
  3205. if (typeof window !== "undefined") {
  3206. ((_a = window.__svelte ?? (window.__svelte = {})).v ?? (_a.v = /* @__PURE__ */ new Set())).add(PUBLIC_VERSION);
  3207. }
  3208. enable_legacy_mode_flag();
  3209. var root$4 = /* @__PURE__ */ template(`<button><!></button>`);
  3210. function Button($$anchor, $$props) {
  3211. let restProps = /* @__PURE__ */ rest_props($$props, [
  3212. "$$slots",
  3213. "$$events",
  3214. "$$legacy",
  3215. "children"
  3216. ]);
  3217. var button = root$4();
  3218. let attributes;
  3219. var node = child(button);
  3220. snippet(node, () => $$props.children ?? noop);
  3221. template_effect(() => attributes = set_attributes(button, attributes, {
  3222. class: "relative inline-flex items-center justify-center text-caption px-2 py-1 gap-1 rounded-full bg-fill-secondary cursor-pointer transition-colors hover:bg-fill-primary hover:text-text-primary text-sd-secondary-foreground hover:opacity-80",
  3223. ...restProps
  3224. }));
  3225. append($$anchor, button);
  3226. }
  3227. var root_1$3 = /* @__PURE__ */ ns_template(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd"></path></svg>`);
  3228. var root_3$1 = /* @__PURE__ */ ns_template(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"></path></svg>`);
  3229. var root_5 = /* @__PURE__ */ ns_template(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd"></path></svg>`);
  3230. var root_7 = /* @__PURE__ */ ns_template(`<svg viewBox="0 0 64 64" fill="currentColor" height="20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M32.427,7.987c2.183,0.124 4,1.165 5.096,3.281l17.936,36.208c1.739,3.66 -0.954,8.585 -5.373,8.656l-36.119,0c-4.022,-0.064 -7.322,-4.631 -5.352,-8.696l18.271,-36.207c0.342,-0.65 0.498,-0.838 0.793,-1.179c1.186,-1.375 2.483,-2.111 4.748,-2.063Zm-0.295,3.997c-0.687,0.034 -1.316,0.419 -1.659,1.017c-6.312,11.979 -12.397,24.081 -18.301,36.267c-0.546,1.225 0.391,2.797 1.762,2.863c12.06,0.195 24.125,0.195 36.185,0c1.325,-0.064 2.321,-1.584 1.769,-2.85c-5.793,-12.184 -11.765,-24.286 -17.966,-36.267c-0.366,-0.651 -0.903,-1.042 -1.79,-1.03Z"></path><path d="M33.631,40.581l-3.348,0l-0.368,-16.449l4.1,0l-0.384,16.449Zm-3.828,5.03c0,-0.609 0.197,-1.113 0.592,-1.514c0.396,-0.4 0.935,-0.601 1.618,-0.601c0.684,0 1.223,0.201 1.618,0.601c0.395,0.401 0.593,0.905 0.593,1.514c0,0.587 -0.193,1.078 -0.577,1.473c-0.385,0.395 -0.929,0.593 -1.634,0.593c-0.705,0 -1.249,-0.198 -1.634,-0.593c-0.384,-0.395 -0.576,-0.886 -0.576,-1.473Z"></path></svg>`);
  3231. function Icon($$anchor, $$props) {
  3232. let type = prop($$props, "type", 8, "success");
  3233. var fragment = comment();
  3234. var node = first_child(fragment);
  3235. {
  3236. var consequent = ($$anchor2) => {
  3237. var svg = root_1$3();
  3238. append($$anchor2, svg);
  3239. };
  3240. var alternate = ($$anchor2, $$elseif) => {
  3241. {
  3242. var consequent_1 = ($$anchor3) => {
  3243. var svg_1 = root_3$1();
  3244. append($$anchor3, svg_1);
  3245. };
  3246. var alternate_1 = ($$anchor3, $$elseif2) => {
  3247. {
  3248. var consequent_2 = ($$anchor4) => {
  3249. var svg_2 = root_5();
  3250. append($$anchor4, svg_2);
  3251. };
  3252. var alternate_2 = ($$anchor4, $$elseif3) => {
  3253. {
  3254. var consequent_3 = ($$anchor5) => {
  3255. var svg_3 = root_7();
  3256. append($$anchor5, svg_3);
  3257. };
  3258. var alternate_3 = ($$anchor5) => {
  3259. };
  3260. if_block(
  3261. $$anchor4,
  3262. ($$render) => {
  3263. if (type() === "warning") $$render(consequent_3);
  3264. else $$render(alternate_3, false);
  3265. },
  3266. $$elseif3
  3267. );
  3268. }
  3269. };
  3270. if_block(
  3271. $$anchor3,
  3272. ($$render) => {
  3273. if (type() === "info") $$render(consequent_2);
  3274. else $$render(alternate_2, false);
  3275. },
  3276. $$elseif2
  3277. );
  3278. }
  3279. };
  3280. if_block(
  3281. $$anchor2,
  3282. ($$render) => {
  3283. if (type() === "error") $$render(consequent_1);
  3284. else $$render(alternate_1, false);
  3285. },
  3286. $$elseif
  3287. );
  3288. }
  3289. };
  3290. if_block(node, ($$render) => {
  3291. if (type() === "success") $$render(consequent);
  3292. else $$render(alternate, false);
  3293. });
  3294. }
  3295. append($$anchor, fragment);
  3296. }
  3297. var root_1$2 = /* @__PURE__ */ template(`<div class="sonner-loading-bar"></div>`);
  3298. var root$3 = /* @__PURE__ */ template(`<div class="sonner-loading-wrapper"><div class="sonner-spinner"></div></div>`);
  3299. function Loader($$anchor, $$props) {
  3300. push($$props, false);
  3301. let visible = prop($$props, "visible", 8);
  3302. const bars = Array(12).fill(0);
  3303. init();
  3304. var div = root$3();
  3305. var div_1 = child(div);
  3306. each(div_1, 5, () => bars, index, ($$anchor2, _) => {
  3307. var div_2 = root_1$2();
  3308. append($$anchor2, div_2);
  3309. });
  3310. template_effect(() => set_attribute(div, "data-visible", visible()));
  3311. append($$anchor, div);
  3312. pop();
  3313. }
  3314. function cn(...classes) {
  3315. return classes.filter(Boolean).join(" ");
  3316. }
  3317. const isBrowser = typeof document !== "undefined";
  3318. function clientWritable(initialValue) {
  3319. const store = writable(initialValue);
  3320. function set2(value) {
  3321. if (isBrowser) {
  3322. store.set(value);
  3323. }
  3324. }
  3325. function update2(updater) {
  3326. if (isBrowser) {
  3327. store.update(updater);
  3328. }
  3329. }
  3330. return {
  3331. subscribe: store.subscribe,
  3332. set: set2,
  3333. update: update2
  3334. };
  3335. }
  3336. let toastsCounter = 0;
  3337. function createToastState() {
  3338. const toasts = clientWritable([]);
  3339. const heights = clientWritable([]);
  3340. function addToast(data) {
  3341. toasts.update((prev) => [data, ...prev]);
  3342. }
  3343. function create(data) {
  3344. var _a2;
  3345. const { message: message2, ...rest } = data;
  3346. const id = typeof (data == null ? void 0 : data.id) === "number" || data.id && ((_a2 = data.id) == null ? void 0 : _a2.length) > 0 ? data.id : toastsCounter++;
  3347. const dismissable = data.dismissable === void 0 ? true : data.dismissable;
  3348. const type = data.type === void 0 ? "default" : data.type;
  3349. const $toasts = get(toasts);
  3350. const alreadyExists = $toasts.find((toast2) => {
  3351. return toast2.id === id;
  3352. });
  3353. if (alreadyExists) {
  3354. toasts.update((prev) => prev.map((toast2) => {
  3355. if (toast2.id === id) {
  3356. return {
  3357. ...toast2,
  3358. ...data,
  3359. id,
  3360. title: message2,
  3361. dismissable,
  3362. type,
  3363. updated: true
  3364. };
  3365. }
  3366. return {
  3367. ...toast2,
  3368. updated: false
  3369. };
  3370. }));
  3371. } else {
  3372. addToast({ ...rest, id, title: message2, dismissable, type });
  3373. }
  3374. return id;
  3375. }
  3376. function dismiss(id) {
  3377. if (id === void 0) {
  3378. toasts.update((prev) => prev.map((toast2) => ({ ...toast2, dismiss: true })));
  3379. return;
  3380. }
  3381. toasts.update((prev) => prev.map((toast2) => toast2.id === id ? { ...toast2, dismiss: true } : toast2));
  3382. return id;
  3383. }
  3384. function remove2(id) {
  3385. if (id === void 0) {
  3386. toasts.set([]);
  3387. return;
  3388. }
  3389. toasts.update((prev) => prev.filter((toast2) => toast2.id !== id));
  3390. return id;
  3391. }
  3392. function message(message2, data) {
  3393. return create({ ...data, type: "default", message: message2 });
  3394. }
  3395. function error(message2, data) {
  3396. return create({ ...data, type: "error", message: message2 });
  3397. }
  3398. function success(message2, data) {
  3399. return create({ ...data, type: "success", message: message2 });
  3400. }
  3401. function info(message2, data) {
  3402. return create({ ...data, type: "info", message: message2 });
  3403. }
  3404. function warning(message2, data) {
  3405. return create({ ...data, type: "warning", message: message2 });
  3406. }
  3407. function loading(message2, data) {
  3408. return create({ ...data, type: "loading", message: message2 });
  3409. }
  3410. function promise(promise2, data) {
  3411. if (!data) {
  3412. return;
  3413. }
  3414. let id = void 0;
  3415. if (data.loading !== void 0) {
  3416. id = create({
  3417. ...data,
  3418. promise: promise2,
  3419. type: "loading",
  3420. message: data.loading
  3421. });
  3422. }
  3423. const p = promise2 instanceof Promise ? promise2 : promise2();
  3424. let shouldDismiss = id !== void 0;
  3425. p.then((response) => {
  3426. if (response && typeof response.ok === "boolean" && !response.ok) {
  3427. shouldDismiss = false;
  3428. const message2 = typeof data.error === "function" ? (
  3429. // @ts-expect-error: Incorrect response type
  3430. data.error(`HTTP error! status: ${response.status}`)
  3431. ) : data.error;
  3432. create({ id, type: "error", message: message2 });
  3433. } else if (data.success !== void 0) {
  3434. shouldDismiss = false;
  3435. const message2 = (
  3436. // @ts-expect-error: TODO: Better function checking
  3437. typeof data.success === "function" ? data.success(response) : data.success
  3438. );
  3439. create({ id, type: "success", message: message2 });
  3440. }
  3441. }).catch((error2) => {
  3442. if (data.error !== void 0) {
  3443. shouldDismiss = false;
  3444. const message2 = (
  3445. // @ts-expect-error: TODO: Better function checking
  3446. typeof data.error === "function" ? data.error(error2) : data.error
  3447. );
  3448. create({ id, type: "error", message: message2 });
  3449. }
  3450. }).finally(() => {
  3451. var _a2;
  3452. if (shouldDismiss) {
  3453. dismiss(id);
  3454. id = void 0;
  3455. }
  3456. (_a2 = data.finally) == null ? void 0 : _a2.call(data);
  3457. });
  3458. return id;
  3459. }
  3460. function custom(component2, data) {
  3461. const id = (data == null ? void 0 : data.id) || toastsCounter++;
  3462. create({ component: component2, id, ...data });
  3463. return id;
  3464. }
  3465. function removeHeight(id) {
  3466. heights.update((prev) => prev.filter((height) => height.toastId !== id));
  3467. }
  3468. function setHeight(data) {
  3469. const exists = get(heights).find((el) => el.toastId === data.toastId);
  3470. if (exists === void 0) {
  3471. heights.update((prev) => [data, ...prev]);
  3472. return;
  3473. }
  3474. heights.update((prev) => prev.map((el) => {
  3475. if (el.toastId === data.toastId) {
  3476. return data;
  3477. } else {
  3478. return el;
  3479. }
  3480. }));
  3481. }
  3482. function reset() {
  3483. toasts.set([]);
  3484. heights.set([]);
  3485. }
  3486. return {
  3487. // methods
  3488. create,
  3489. addToast,
  3490. dismiss,
  3491. remove: remove2,
  3492. message,
  3493. error,
  3494. success,
  3495. info,
  3496. warning,
  3497. loading,
  3498. promise,
  3499. custom,
  3500. removeHeight,
  3501. setHeight,
  3502. reset,
  3503. // stores
  3504. toasts,
  3505. heights
  3506. };
  3507. }
  3508. const toastState = createToastState();
  3509. function toastFunction(message, data) {
  3510. return toastState.create({
  3511. message,
  3512. ...data
  3513. });
  3514. }
  3515. const basicToast = toastFunction;
  3516. const toast = Object.assign(basicToast, {
  3517. success: toastState.success,
  3518. info: toastState.info,
  3519. warning: toastState.warning,
  3520. error: toastState.error,
  3521. custom: toastState.custom,
  3522. message: toastState.message,
  3523. promise: toastState.promise,
  3524. dismiss: toastState.dismiss,
  3525. loading: toastState.loading
  3526. });
  3527. const useEffect = (subscribe) => ({ subscribe });
  3528. var root_1$1 = /* @__PURE__ */ template(`<button aria-label="Close toast" data-close-button=""><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></button>`);
  3529. var root_4 = /* @__PURE__ */ template(`<div data-icon=""><!> <!></div>`);
  3530. var root_15 = /* @__PURE__ */ template(`<div data-title=""><!></div>`);
  3531. var root_18 = /* @__PURE__ */ template(`<div data-description=""><!></div>`);
  3532. var root_21 = /* @__PURE__ */ template(`<button data-button="" data-cancel=""> </button>`);
  3533. var root_22 = /* @__PURE__ */ template(`<button data-button=""> </button>`);
  3534. var root_3 = /* @__PURE__ */ template(`<!> <div data-content=""><!> <!></div> <!> <!>`, 1);
  3535. var root$2 = /* @__PURE__ */ template(`<li aria-atomic="true" role="status" data-sonner-toast=""><!> <!></li>`);
  3536. function Toast($$anchor, $$props) {
  3537. const $$sanitized_props = legacy_rest_props($$props, [
  3538. "children",
  3539. "$$slots",
  3540. "$$events",
  3541. "$$legacy"
  3542. ]);
  3543. push($$props, false);
  3544. const [$$stores, $$cleanup] = setup_stores();
  3545. const $heights = () => store_get(heights, "$heights", $$stores);
  3546. const $effect = () => store_get(get$1(effect2), "$effect", $$stores);
  3547. const $toasts = () => store_get(toasts, "$toasts", $$stores);
  3548. const isFront = /* @__PURE__ */ mutable_source(void 0, true);
  3549. const isVisible = /* @__PURE__ */ mutable_source(void 0, true);
  3550. const toastTitle = /* @__PURE__ */ mutable_source(void 0, true);
  3551. const toastDescription = /* @__PURE__ */ mutable_source(void 0, true);
  3552. const toastType = /* @__PURE__ */ mutable_source(void 0, true);
  3553. const toastClass = /* @__PURE__ */ mutable_source(void 0, true);
  3554. const toastDescriptionClass = /* @__PURE__ */ mutable_source(void 0, true);
  3555. const heightIndex = /* @__PURE__ */ mutable_source(void 0, true);
  3556. const coords = /* @__PURE__ */ mutable_source(void 0, true);
  3557. const toastsHeightBefore = /* @__PURE__ */ mutable_source(void 0, true);
  3558. const disabled = /* @__PURE__ */ mutable_source(void 0, true);
  3559. const isPromiseLoadingOrInfiniteDuration = /* @__PURE__ */ mutable_source(void 0, true);
  3560. const TOAST_LIFETIME = 4e3;
  3561. const GAP = 14;
  3562. const SWIPE_TRESHOLD = 20;
  3563. const TIME_BEFORE_UNMOUNT = 200;
  3564. const SCALE_MULTIPLIER = 0.05;
  3565. const defaultClasses = {
  3566. toast: "",
  3567. title: "",
  3568. description: "",
  3569. loader: "",
  3570. closeButton: "",
  3571. cancelButton: "",
  3572. actionButton: "",
  3573. action: "",
  3574. warning: "",
  3575. error: "",
  3576. success: "",
  3577. default: "",
  3578. info: "",
  3579. loading: ""
  3580. };
  3581. const {
  3582. toasts,
  3583. heights,
  3584. removeHeight,
  3585. setHeight,
  3586. remove: remove2
  3587. } = toastState;
  3588. let toast2 = prop($$props, "toast", 9);
  3589. let index2 = prop($$props, "index", 9);
  3590. let expanded = prop($$props, "expanded", 9);
  3591. let invert = prop($$props, "invert", 13);
  3592. let position = prop($$props, "position", 9);
  3593. let visibleToasts = prop($$props, "visibleToasts", 9);
  3594. let expandByDefault = prop($$props, "expandByDefault", 9);
  3595. let closeButton = prop($$props, "closeButton", 9);
  3596. let interacting = prop($$props, "interacting", 9);
  3597. let cancelButtonStyle = prop($$props, "cancelButtonStyle", 9, "");
  3598. let actionButtonStyle = prop($$props, "actionButtonStyle", 9, "");
  3599. let duration = prop($$props, "duration", 9, 4e3);
  3600. let descriptionClass = prop($$props, "descriptionClass", 9, "");
  3601. let classes = prop($$props, "classes", 29, () => ({}));
  3602. let unstyled = prop($$props, "unstyled", 9, false);
  3603. let mounted = /* @__PURE__ */ mutable_source(false, true);
  3604. let removed = /* @__PURE__ */ mutable_source(false, true);
  3605. let swiping = /* @__PURE__ */ mutable_source(false, true);
  3606. let swipeOut = /* @__PURE__ */ mutable_source(false, true);
  3607. let offsetBeforeRemove = /* @__PURE__ */ mutable_source(0, true);
  3608. let initialHeight = /* @__PURE__ */ mutable_source(0, true);
  3609. let toastRef = /* @__PURE__ */ mutable_source(void 0, true);
  3610. let offset = /* @__PURE__ */ mutable_source(0, true);
  3611. let closeTimerStartTimeRef = 0;
  3612. let lastCloseTimerStartTimeRef = 0;
  3613. let pointerStartRef = null;
  3614. async function updateHeights() {
  3615. if (!get$1(mounted)) {
  3616. return;
  3617. }
  3618. await tick();
  3619. let scale;
  3620. if (expanded() || expandByDefault()) {
  3621. scale = 1;
  3622. } else {
  3623. scale = 1 - index2() * SCALE_MULTIPLIER;
  3624. }
  3625. get$1(toastRef).style.setProperty("height", "auto");
  3626. const offsetHeight = get$1(toastRef).offsetHeight;
  3627. const rectHeight = get$1(toastRef).getBoundingClientRect().height;
  3628. const scaledRectHeight = Math.round((rectHeight / scale + Number.EPSILON) * 100) / 100;
  3629. get$1(toastRef).style.removeProperty("height");
  3630. let finalHeight;
  3631. if (Math.abs(scaledRectHeight - offsetHeight) < 1) {
  3632. finalHeight = scaledRectHeight;
  3633. } else {
  3634. finalHeight = offsetHeight;
  3635. }
  3636. set(initialHeight, finalHeight);
  3637. setHeight({ toastId: toast2().id, height: finalHeight });
  3638. }
  3639. function deleteToast() {
  3640. set(removed, true);
  3641. set(offsetBeforeRemove, get$1(offset));
  3642. removeHeight(toast2().id);
  3643. setTimeout(
  3644. () => {
  3645. remove2(toast2().id);
  3646. },
  3647. TIME_BEFORE_UNMOUNT
  3648. );
  3649. }
  3650. let timeoutId = /* @__PURE__ */ mutable_source(void 0, true);
  3651. let remainingTime = /* @__PURE__ */ mutable_source(toast2().duration || duration() || TOAST_LIFETIME, true);
  3652. function pauseTimer() {
  3653. if (lastCloseTimerStartTimeRef < closeTimerStartTimeRef) {
  3654. const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef;
  3655. set(remainingTime, get$1(remainingTime) - elapsedTime);
  3656. }
  3657. lastCloseTimerStartTimeRef = (/* @__PURE__ */ new Date()).getTime();
  3658. }
  3659. function startTimer() {
  3660. closeTimerStartTimeRef = (/* @__PURE__ */ new Date()).getTime();
  3661. set(timeoutId, setTimeout(
  3662. () => {
  3663. var _a2, _b2;
  3664. (_b2 = (_a2 = toast2()).onAutoClose) == null ? void 0 : _b2.call(_a2, toast2());
  3665. deleteToast();
  3666. },
  3667. get$1(remainingTime)
  3668. ));
  3669. }
  3670. let effect2 = /* @__PURE__ */ mutable_source(void 0, true);
  3671. onMount(() => {
  3672. set(mounted, true);
  3673. const height = get$1(toastRef).getBoundingClientRect().height;
  3674. set(initialHeight, height);
  3675. setHeight({ toastId: toast2().id, height });
  3676. return () => removeHeight(toast2().id);
  3677. });
  3678. function onPointerDown(event2) {
  3679. if (get$1(disabled)) {
  3680. return;
  3681. }
  3682. set(offsetBeforeRemove, get$1(offset));
  3683. const target = event2.target;
  3684. target.setPointerCapture(event2.pointerId);
  3685. if (target.tagName === "BUTTON") {
  3686. return;
  3687. }
  3688. set(swiping, true);
  3689. pointerStartRef = { x: event2.clientX, y: event2.clientY };
  3690. }
  3691. function onPointerUp() {
  3692. var _a2, _b2, _c2;
  3693. if (get$1(swipeOut)) {
  3694. return;
  3695. }
  3696. pointerStartRef = null;
  3697. const swipeAmount = Number(((_a2 = get$1(toastRef)) == null ? void 0 : _a2.style.getPropertyValue("--swipe-amount").replace("px", "")) || 0);
  3698. if (Math.abs(swipeAmount) >= SWIPE_TRESHOLD) {
  3699. set(offsetBeforeRemove, get$1(offset));
  3700. (_c2 = (_b2 = toast2()).onDismiss) == null ? void 0 : _c2.call(_b2, toast2());
  3701. deleteToast();
  3702. set(swipeOut, true);
  3703. return;
  3704. }
  3705. get$1(toastRef).style.setProperty("--swipe-amount", "0px");
  3706. set(swiping, false);
  3707. }
  3708. function onPointerMove(event2) {
  3709. if (!pointerStartRef) {
  3710. return;
  3711. }
  3712. const yPosition = event2.clientY - pointerStartRef.y;
  3713. const xPosition = event2.clientX - pointerStartRef.x;
  3714. const clamp = get$1(coords)[0] === "top" ? Math.min : Math.max;
  3715. const clampedY = clamp(0, yPosition);
  3716. const swipeStartThreshold = event2.pointerType === "touch" ? 10 : 2;
  3717. const isAllowedToSwipe = Math.abs(clampedY) > swipeStartThreshold;
  3718. if (isAllowedToSwipe) {
  3719. get$1(toastRef).style.setProperty("--swipe-amount", `${yPosition}px`);
  3720. } else if (Math.abs(xPosition) > swipeStartThreshold) {
  3721. pointerStartRef = null;
  3722. }
  3723. }
  3724. legacy_pre_effect(() => deep_read_state(classes()), () => {
  3725. classes({ ...defaultClasses, ...classes() });
  3726. });
  3727. legacy_pre_effect(() => deep_read_state(index2()), () => {
  3728. set(isFront, index2() === 0);
  3729. });
  3730. legacy_pre_effect(
  3731. () => (deep_read_state(index2()), deep_read_state(visibleToasts())),
  3732. () => {
  3733. set(isVisible, index2() + 1 <= visibleToasts());
  3734. }
  3735. );
  3736. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3737. set(toastTitle, toast2().title);
  3738. });
  3739. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3740. set(toastDescription, toast2().description);
  3741. });
  3742. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3743. set(toastType, toast2().type);
  3744. });
  3745. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3746. set(toastClass, toast2().class || "");
  3747. });
  3748. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3749. set(toastDescriptionClass, toast2().descriptionClass || "");
  3750. });
  3751. legacy_pre_effect(
  3752. () => ($heights(), deep_read_state(toast2())),
  3753. () => {
  3754. set(heightIndex, $heights().findIndex((height) => height.toastId === toast2().id) || 0);
  3755. }
  3756. );
  3757. legacy_pre_effect(() => deep_read_state(position()), () => {
  3758. set(coords, position().split("-"));
  3759. });
  3760. legacy_pre_effect(() => ($heights(), get$1(heightIndex)), () => {
  3761. set(toastsHeightBefore, $heights().reduce(
  3762. (prev, curr, reducerIndex) => {
  3763. if (reducerIndex >= get$1(heightIndex)) return prev;
  3764. return prev + curr.height;
  3765. },
  3766. 0
  3767. ));
  3768. });
  3769. legacy_pre_effect(
  3770. () => (deep_read_state(invert()), deep_read_state(toast2())),
  3771. () => {
  3772. invert(toast2().invert || invert());
  3773. }
  3774. );
  3775. legacy_pre_effect(() => get$1(toastType), () => {
  3776. set(disabled, get$1(toastType) === "loading");
  3777. });
  3778. legacy_pre_effect(
  3779. () => (get$1(heightIndex), get$1(toastsHeightBefore)),
  3780. () => {
  3781. set(offset, Math.round(get$1(heightIndex) * GAP + get$1(toastsHeightBefore)));
  3782. }
  3783. );
  3784. legacy_pre_effect(
  3785. () => (get$1(toastTitle), get$1(toastDescription)),
  3786. () => {
  3787. get$1(toastTitle), get$1(toastDescription), updateHeights();
  3788. }
  3789. );
  3790. legacy_pre_effect(
  3791. () => (deep_read_state(toast2()), get$1(timeoutId), deep_read_state(duration())),
  3792. () => {
  3793. if (toast2().updated) {
  3794. clearTimeout(get$1(timeoutId));
  3795. set(remainingTime, toast2().duration || duration() || TOAST_LIFETIME);
  3796. startTimer();
  3797. }
  3798. }
  3799. );
  3800. legacy_pre_effect(
  3801. () => (deep_read_state(toast2()), get$1(toastType)),
  3802. () => {
  3803. set(isPromiseLoadingOrInfiniteDuration, toast2().promise && get$1(toastType) === "loading" || toast2().duration === Number.POSITIVE_INFINITY);
  3804. }
  3805. );
  3806. legacy_pre_effect(
  3807. () => (get$1(isPromiseLoadingOrInfiniteDuration), deep_read_state(expanded()), deep_read_state(interacting()), get$1(timeoutId)),
  3808. () => {
  3809. store_unsub(
  3810. set(effect2, useEffect(() => {
  3811. if (!get$1(isPromiseLoadingOrInfiniteDuration)) {
  3812. if (expanded() || interacting()) {
  3813. pauseTimer();
  3814. } else {
  3815. startTimer();
  3816. }
  3817. }
  3818. return () => clearTimeout(get$1(timeoutId));
  3819. })),
  3820. "$effect",
  3821. $$stores
  3822. );
  3823. }
  3824. );
  3825. legacy_pre_effect(() => $effect(), () => {
  3826. $effect();
  3827. });
  3828. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3829. if (toast2().delete) {
  3830. deleteToast();
  3831. }
  3832. });
  3833. legacy_pre_effect_reset();
  3834. init(true);
  3835. var li = root$2();
  3836. set_attribute(li, "tabindex", 0);
  3837. let styles;
  3838. var node = child(li);
  3839. {
  3840. var consequent = ($$anchor2) => {
  3841. var button = root_1$1();
  3842. template_effect(
  3843. ($0) => {
  3844. set_attribute(button, "data-disabled", get$1(disabled));
  3845. set_class(button, 1, $0);
  3846. },
  3847. [
  3848. () => {
  3849. var _a2, _b2, _c2;
  3850. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.closeButton, (_c2 = (_b2 = toast2()) == null ? void 0 : _b2.classes) == null ? void 0 : _c2.closeButton));
  3851. }
  3852. ],
  3853. derived_safe_equal
  3854. );
  3855. event("click", button, function(...$$args) {
  3856. var _a2;
  3857. (_a2 = get$1(disabled) ? void 0 : () => {
  3858. var _a3, _b2;
  3859. deleteToast();
  3860. (_b2 = (_a3 = toast2()).onDismiss) == null ? void 0 : _b2.call(_a3, toast2());
  3861. }) == null ? void 0 : _a2.apply(this, $$args);
  3862. });
  3863. append($$anchor2, button);
  3864. };
  3865. if_block(node, ($$render) => {
  3866. if (closeButton() && !toast2().component) $$render(consequent);
  3867. });
  3868. }
  3869. var node_1 = sibling(node, 2);
  3870. {
  3871. var consequent_1 = ($$anchor2) => {
  3872. var fragment = comment();
  3873. var node_2 = first_child(fragment);
  3874. component(node_2, () => toast2().component, ($$anchor3, $$component) => {
  3875. $$component($$anchor3, spread_props(() => toast2().componentProps, { $$events: { closeToast: deleteToast } }));
  3876. });
  3877. append($$anchor2, fragment);
  3878. };
  3879. var alternate = ($$anchor2) => {
  3880. var fragment_1 = root_3();
  3881. var node_3 = first_child(fragment_1);
  3882. {
  3883. var consequent_8 = ($$anchor3) => {
  3884. var div = root_4();
  3885. var node_4 = child(div);
  3886. {
  3887. var consequent_2 = ($$anchor4) => {
  3888. var fragment_2 = comment();
  3889. var node_5 = first_child(fragment_2);
  3890. slot(node_5, $$props, "loading-icon", {}, null);
  3891. append($$anchor4, fragment_2);
  3892. };
  3893. if_block(node_4, ($$render) => {
  3894. if ((toast2().promise || get$1(toastType) === "loading") && !toast2().icon) $$render(consequent_2);
  3895. });
  3896. }
  3897. var node_6 = sibling(node_4, 2);
  3898. {
  3899. var consequent_3 = ($$anchor4) => {
  3900. var fragment_3 = comment();
  3901. var node_7 = first_child(fragment_3);
  3902. component(node_7, () => toast2().icon, ($$anchor5, $$component) => {
  3903. $$component($$anchor5, {});
  3904. });
  3905. append($$anchor4, fragment_3);
  3906. };
  3907. var alternate_1 = ($$anchor4, $$elseif) => {
  3908. {
  3909. var consequent_4 = ($$anchor5) => {
  3910. var fragment_4 = comment();
  3911. var node_8 = first_child(fragment_4);
  3912. slot(node_8, $$props, "success-icon", {}, null);
  3913. append($$anchor5, fragment_4);
  3914. };
  3915. var alternate_2 = ($$anchor5, $$elseif2) => {
  3916. {
  3917. var consequent_5 = ($$anchor6) => {
  3918. var fragment_5 = comment();
  3919. var node_9 = first_child(fragment_5);
  3920. slot(node_9, $$props, "error-icon", {}, null);
  3921. append($$anchor6, fragment_5);
  3922. };
  3923. var alternate_3 = ($$anchor6, $$elseif3) => {
  3924. {
  3925. var consequent_6 = ($$anchor7) => {
  3926. var fragment_6 = comment();
  3927. var node_10 = first_child(fragment_6);
  3928. slot(node_10, $$props, "warning-icon", {}, null);
  3929. append($$anchor7, fragment_6);
  3930. };
  3931. var alternate_4 = ($$anchor7, $$elseif4) => {
  3932. {
  3933. var consequent_7 = ($$anchor8) => {
  3934. var fragment_7 = comment();
  3935. var node_11 = first_child(fragment_7);
  3936. slot(node_11, $$props, "info-icon", {}, null);
  3937. append($$anchor8, fragment_7);
  3938. };
  3939. if_block(
  3940. $$anchor7,
  3941. ($$render) => {
  3942. if (get$1(toastType) === "info") $$render(consequent_7);
  3943. },
  3944. $$elseif4
  3945. );
  3946. }
  3947. };
  3948. if_block(
  3949. $$anchor6,
  3950. ($$render) => {
  3951. if (get$1(toastType) === "warning") $$render(consequent_6);
  3952. else $$render(alternate_4, false);
  3953. },
  3954. $$elseif3
  3955. );
  3956. }
  3957. };
  3958. if_block(
  3959. $$anchor5,
  3960. ($$render) => {
  3961. if (get$1(toastType) === "error") $$render(consequent_5);
  3962. else $$render(alternate_3, false);
  3963. },
  3964. $$elseif2
  3965. );
  3966. }
  3967. };
  3968. if_block(
  3969. $$anchor4,
  3970. ($$render) => {
  3971. if (get$1(toastType) === "success") $$render(consequent_4);
  3972. else $$render(alternate_2, false);
  3973. },
  3974. $$elseif
  3975. );
  3976. }
  3977. };
  3978. if_block(node_6, ($$render) => {
  3979. if (toast2().icon) $$render(consequent_3);
  3980. else $$render(alternate_1, false);
  3981. });
  3982. }
  3983. append($$anchor3, div);
  3984. };
  3985. if_block(node_3, ($$render) => {
  3986. if (get$1(toastType) !== "default" || toast2().icon || toast2().promise) $$render(consequent_8);
  3987. });
  3988. }
  3989. var div_1 = sibling(node_3, 2);
  3990. var node_12 = child(div_1);
  3991. {
  3992. var consequent_10 = ($$anchor3) => {
  3993. var div_2 = root_15();
  3994. var node_13 = child(div_2);
  3995. {
  3996. var consequent_9 = ($$anchor4) => {
  3997. var fragment_8 = comment();
  3998. var node_14 = first_child(fragment_8);
  3999. component(node_14, () => toast2().title, ($$anchor5, $$component) => {
  4000. $$component($$anchor5, spread_props(() => toast2().componentProps));
  4001. });
  4002. append($$anchor4, fragment_8);
  4003. };
  4004. var alternate_5 = ($$anchor4) => {
  4005. var text$1 = text();
  4006. template_effect(() => set_text(text$1, toast2().title));
  4007. append($$anchor4, text$1);
  4008. };
  4009. if_block(node_13, ($$render) => {
  4010. if (typeof toast2().title !== "string") $$render(consequent_9);
  4011. else $$render(alternate_5, false);
  4012. });
  4013. }
  4014. template_effect(
  4015. ($0) => set_class(div_2, 1, $0),
  4016. [
  4017. () => {
  4018. var _a2, _b2, _c2;
  4019. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.title, (_c2 = (_b2 = toast2()) == null ? void 0 : _b2.classes) == null ? void 0 : _c2.title));
  4020. }
  4021. ],
  4022. derived_safe_equal
  4023. );
  4024. append($$anchor3, div_2);
  4025. };
  4026. if_block(node_12, ($$render) => {
  4027. if (toast2().title) $$render(consequent_10);
  4028. });
  4029. }
  4030. var node_15 = sibling(node_12, 2);
  4031. {
  4032. var consequent_12 = ($$anchor3) => {
  4033. var div_3 = root_18();
  4034. var node_16 = child(div_3);
  4035. {
  4036. var consequent_11 = ($$anchor4) => {
  4037. var fragment_10 = comment();
  4038. var node_17 = first_child(fragment_10);
  4039. component(node_17, () => toast2().description, ($$anchor5, $$component) => {
  4040. $$component($$anchor5, spread_props(() => toast2().componentProps));
  4041. });
  4042. append($$anchor4, fragment_10);
  4043. };
  4044. var alternate_6 = ($$anchor4) => {
  4045. var text_1 = text();
  4046. template_effect(() => set_text(text_1, toast2().description));
  4047. append($$anchor4, text_1);
  4048. };
  4049. if_block(node_16, ($$render) => {
  4050. if (typeof toast2().description !== "string") $$render(consequent_11);
  4051. else $$render(alternate_6, false);
  4052. });
  4053. }
  4054. template_effect(
  4055. ($0) => set_class(div_3, 1, $0),
  4056. [
  4057. () => {
  4058. var _a2, _b2;
  4059. return clsx(cn(descriptionClass(), get$1(toastDescriptionClass), (_a2 = classes()) == null ? void 0 : _a2.description, (_b2 = toast2().classes) == null ? void 0 : _b2.description));
  4060. }
  4061. ],
  4062. derived_safe_equal
  4063. );
  4064. append($$anchor3, div_3);
  4065. };
  4066. if_block(node_15, ($$render) => {
  4067. if (toast2().description) $$render(consequent_12);
  4068. });
  4069. }
  4070. var node_18 = sibling(div_1, 2);
  4071. {
  4072. var consequent_13 = ($$anchor3) => {
  4073. var button_1 = root_21();
  4074. var text_2 = child(button_1);
  4075. template_effect(
  4076. ($0) => {
  4077. set_style(button_1, cancelButtonStyle());
  4078. set_class(button_1, 1, $0);
  4079. set_text(text_2, toast2().cancel.label);
  4080. },
  4081. [
  4082. () => {
  4083. var _a2, _b2, _c2;
  4084. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.cancelButton, (_c2 = (_b2 = toast2()) == null ? void 0 : _b2.classes) == null ? void 0 : _c2.cancelButton));
  4085. }
  4086. ],
  4087. derived_safe_equal
  4088. );
  4089. event("click", button_1, () => {
  4090. var _a2;
  4091. deleteToast();
  4092. if ((_a2 = toast2().cancel) == null ? void 0 : _a2.onClick) {
  4093. toast2().cancel.onClick();
  4094. }
  4095. });
  4096. append($$anchor3, button_1);
  4097. };
  4098. if_block(node_18, ($$render) => {
  4099. if (toast2().cancel) $$render(consequent_13);
  4100. });
  4101. }
  4102. var node_19 = sibling(node_18, 2);
  4103. {
  4104. var consequent_14 = ($$anchor3) => {
  4105. var button_2 = root_22();
  4106. var text_3 = child(button_2);
  4107. template_effect(
  4108. ($0) => {
  4109. set_style(button_2, actionButtonStyle());
  4110. set_class(button_2, 1, $0);
  4111. set_text(text_3, toast2().action.label);
  4112. },
  4113. [
  4114. () => {
  4115. var _a2, _b2, _c2;
  4116. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.actionButton, (_c2 = (_b2 = toast2()) == null ? void 0 : _b2.classes) == null ? void 0 : _c2.actionButton));
  4117. }
  4118. ],
  4119. derived_safe_equal
  4120. );
  4121. event("click", button_2, (event2) => {
  4122. var _a2;
  4123. (_a2 = toast2().action) == null ? void 0 : _a2.onClick(event2);
  4124. if (event2.defaultPrevented) return;
  4125. deleteToast();
  4126. });
  4127. append($$anchor3, button_2);
  4128. };
  4129. if_block(node_19, ($$render) => {
  4130. if (toast2().action) $$render(consequent_14);
  4131. });
  4132. }
  4133. append($$anchor2, fragment_1);
  4134. };
  4135. if_block(node_1, ($$render) => {
  4136. if (toast2().component) $$render(consequent_1);
  4137. else $$render(alternate, false);
  4138. });
  4139. }
  4140. bind_this(li, ($$value) => set(toastRef, $$value), () => get$1(toastRef));
  4141. template_effect(
  4142. ($0, $1, $2) => {
  4143. var _a2;
  4144. set_attribute(li, "aria-live", toast2().important ? "assertive" : "polite");
  4145. set_class(li, 1, $0);
  4146. set_attribute(li, "data-styled", !(toast2().component || ((_a2 = toast2()) == null ? void 0 : _a2.unstyled) || unstyled()));
  4147. set_attribute(li, "data-mounted", get$1(mounted));
  4148. set_attribute(li, "data-promise", $1);
  4149. set_attribute(li, "data-removed", get$1(removed));
  4150. set_attribute(li, "data-visible", get$1(isVisible));
  4151. set_attribute(li, "data-y-position", get$1(coords)[0]);
  4152. set_attribute(li, "data-x-position", get$1(coords)[1]);
  4153. set_attribute(li, "data-index", index2());
  4154. set_attribute(li, "data-front", get$1(isFront));
  4155. set_attribute(li, "data-swiping", get$1(swiping));
  4156. set_attribute(li, "data-type", get$1(toastType));
  4157. set_attribute(li, "data-invert", invert());
  4158. set_attribute(li, "data-swipe-out", get$1(swipeOut));
  4159. set_attribute(li, "data-expanded", $2);
  4160. styles = set_style(li, `${$$sanitized_props.style} ${toast2().style}`, styles, {
  4161. "--index": index2(),
  4162. "--toasts-before": index2(),
  4163. "--z-index": $toasts().length - index2(),
  4164. "--offset": `${get$1(removed) ? get$1(offsetBeforeRemove) : get$1(offset)}px`,
  4165. "--initial-height": `${get$1(initialHeight)}px`
  4166. });
  4167. },
  4168. [
  4169. () => {
  4170. var _a2, _b2, _c2, _d, _e, _f;
  4171. return clsx(cn($$sanitized_props.class, get$1(toastClass), (_a2 = classes()) == null ? void 0 : _a2.toast, (_c2 = (_b2 = toast2()) == null ? void 0 : _b2.classes) == null ? void 0 : _c2.toast, (_d = classes()) == null ? void 0 : _d[get$1(toastType)], (_f = (_e = toast2()) == null ? void 0 : _e.classes) == null ? void 0 : _f[get$1(toastType)]));
  4172. },
  4173. () => Boolean(toast2().promise),
  4174. () => Boolean(expanded() || expandByDefault() && get$1(mounted))
  4175. ],
  4176. derived_safe_equal
  4177. );
  4178. event("pointerdown", li, onPointerDown);
  4179. event("pointerup", li, onPointerUp);
  4180. event("pointermove", li, onPointerMove);
  4181. append($$anchor, li);
  4182. pop();
  4183. $$cleanup();
  4184. }
  4185. var root_2 = /* @__PURE__ */ template(`<ol></ol>`);
  4186. var root_1 = /* @__PURE__ */ template(`<section class="svelte-1fo5d1m"></section>`);
  4187. function Toaster($$anchor, $$props) {
  4188. const $$sanitized_props = legacy_rest_props($$props, [
  4189. "children",
  4190. "$$slots",
  4191. "$$events",
  4192. "$$legacy"
  4193. ]);
  4194. const $$restProps = legacy_rest_props($$sanitized_props, [
  4195. "invert",
  4196. "theme",
  4197. "position",
  4198. "hotkey",
  4199. "containerAriaLabel",
  4200. "richColors",
  4201. "expand",
  4202. "duration",
  4203. "visibleToasts",
  4204. "closeButton",
  4205. "toastOptions",
  4206. "offset",
  4207. "dir"
  4208. ]);
  4209. push($$props, false);
  4210. const [$$stores, $$cleanup] = setup_stores();
  4211. const $toasts = () => store_get(toasts, "$toasts", $$stores);
  4212. const $heights = () => store_get(heights, "$heights", $$stores);
  4213. const possiblePositions = /* @__PURE__ */ mutable_source();
  4214. const hotkeyLabel = /* @__PURE__ */ mutable_source();
  4215. const VISIBLE_TOASTS_AMOUNT = 3;
  4216. const VIEWPORT_OFFSET = "32px";
  4217. const TOAST_WIDTH = 356;
  4218. const GAP = 14;
  4219. const DARK = "dark";
  4220. const LIGHT = "light";
  4221. function getInitialTheme(t) {
  4222. if (t !== "system") {
  4223. return t;
  4224. }
  4225. if (typeof window !== "undefined") {
  4226. if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
  4227. return DARK;
  4228. }
  4229. return LIGHT;
  4230. }
  4231. return LIGHT;
  4232. }
  4233. function getDocumentDirection() {
  4234. if (typeof window === "undefined") return "ltr";
  4235. if (typeof document === "undefined") return "ltr";
  4236. const dirAttribute = document.documentElement.getAttribute("dir");
  4237. if (dirAttribute === "auto" || !dirAttribute) {
  4238. return window.getComputedStyle(document.documentElement).direction;
  4239. }
  4240. return dirAttribute;
  4241. }
  4242. let invert = prop($$props, "invert", 8, false);
  4243. let theme = prop($$props, "theme", 8, "light");
  4244. let position = prop($$props, "position", 8, "bottom-right");
  4245. let hotkey = prop($$props, "hotkey", 24, () => ["altKey", "KeyT"]);
  4246. let containerAriaLabel = prop($$props, "containerAriaLabel", 8, "Notifications");
  4247. let richColors = prop($$props, "richColors", 8, false);
  4248. let expand = prop($$props, "expand", 8, false);
  4249. let duration = prop($$props, "duration", 8, 4e3);
  4250. let visibleToasts = prop($$props, "visibleToasts", 8, VISIBLE_TOASTS_AMOUNT);
  4251. let closeButton = prop($$props, "closeButton", 8, false);
  4252. let toastOptions = prop($$props, "toastOptions", 24, () => ({}));
  4253. let offset = prop($$props, "offset", 8, null);
  4254. let dir = prop($$props, "dir", 24, getDocumentDirection);
  4255. const { toasts, heights, reset } = toastState;
  4256. let expanded = /* @__PURE__ */ mutable_source(false);
  4257. let interacting = /* @__PURE__ */ mutable_source(false);
  4258. let actualTheme = /* @__PURE__ */ mutable_source(getInitialTheme(theme()));
  4259. let listRef = /* @__PURE__ */ mutable_source();
  4260. let lastFocusedElementRef = null;
  4261. let isFocusWithinRef = false;
  4262. onDestroy(() => {
  4263. if (get$1(listRef) && lastFocusedElementRef) {
  4264. lastFocusedElementRef.focus({ preventScroll: true });
  4265. lastFocusedElementRef = null;
  4266. isFocusWithinRef = false;
  4267. }
  4268. });
  4269. onMount(() => {
  4270. reset();
  4271. const handleKeydown = (event2) => {
  4272. var _a2, _b2;
  4273. const isHotkeyPressed = hotkey().every((key) => (
  4274. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4275. event2[key] || event2.code === key
  4276. ));
  4277. if (isHotkeyPressed) {
  4278. set(expanded, true);
  4279. (_a2 = get$1(listRef)) == null ? void 0 : _a2.focus();
  4280. }
  4281. if (event2.code === "Escape" && (document.activeElement === get$1(listRef) || ((_b2 = get$1(listRef)) == null ? void 0 : _b2.contains(document.activeElement)))) {
  4282. set(expanded, false);
  4283. }
  4284. };
  4285. document.addEventListener("keydown", handleKeydown);
  4286. return () => {
  4287. document.removeEventListener("keydown", handleKeydown);
  4288. };
  4289. });
  4290. function handleBlur(event2) {
  4291. if (isFocusWithinRef && !event2.currentTarget.contains(event2.relatedTarget)) {
  4292. isFocusWithinRef = false;
  4293. if (lastFocusedElementRef) {
  4294. lastFocusedElementRef.focus({ preventScroll: true });
  4295. lastFocusedElementRef = null;
  4296. }
  4297. }
  4298. }
  4299. function handleFocus(event2) {
  4300. if (!isFocusWithinRef) {
  4301. isFocusWithinRef = true;
  4302. lastFocusedElementRef = event2.relatedTarget;
  4303. }
  4304. }
  4305. legacy_pre_effect(
  4306. () => (deep_read_state(position()), $toasts()),
  4307. () => {
  4308. set(possiblePositions, Array.from(new Set([
  4309. position(),
  4310. ...$toasts().filter((toast2) => toast2.position).map((toast2) => toast2.position)
  4311. ].filter(Boolean))));
  4312. }
  4313. );
  4314. legacy_pre_effect(() => deep_read_state(hotkey()), () => {
  4315. set(hotkeyLabel, hotkey().join("+").replace(/Key/g, "").replace(/Digit/g, ""));
  4316. });
  4317. legacy_pre_effect(() => $toasts(), () => {
  4318. if ($toasts().length <= 1) {
  4319. set(expanded, false);
  4320. }
  4321. });
  4322. legacy_pre_effect(() => $toasts(), () => {
  4323. const toastsToDismiss = $toasts().filter((toast2) => toast2.dismiss && !toast2.delete);
  4324. if (toastsToDismiss.length > 0) {
  4325. const updatedToasts = $toasts().map((toast2) => {
  4326. const matchingToast = toastsToDismiss.find((dismissToast) => dismissToast.id === toast2.id);
  4327. if (matchingToast) {
  4328. return { ...toast2, delete: true };
  4329. }
  4330. return toast2;
  4331. });
  4332. toasts.set(updatedToasts);
  4333. }
  4334. });
  4335. legacy_pre_effect(() => deep_read_state(theme()), () => {
  4336. if (theme() !== "system") {
  4337. set(actualTheme, theme());
  4338. }
  4339. if (typeof window !== "undefined") {
  4340. if (theme() === "system") {
  4341. if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
  4342. set(actualTheme, DARK);
  4343. } else {
  4344. set(actualTheme, LIGHT);
  4345. }
  4346. }
  4347. const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
  4348. const changeHandler = ({ matches }) => {
  4349. set(actualTheme, matches ? DARK : LIGHT);
  4350. };
  4351. if ("addEventListener" in mediaQueryList) {
  4352. mediaQueryList.addEventListener("change", changeHandler);
  4353. } else {
  4354. mediaQueryList.addListener(changeHandler);
  4355. }
  4356. }
  4357. });
  4358. legacy_pre_effect_reset();
  4359. init();
  4360. var fragment = comment();
  4361. var node = first_child(fragment);
  4362. {
  4363. var consequent = ($$anchor2) => {
  4364. var section = root_1();
  4365. set_attribute(section, "tabindex", -1);
  4366. each(section, 5, () => get$1(possiblePositions), index, ($$anchor3, position2, index2, $$array) => {
  4367. var ol = root_2();
  4368. let attributes;
  4369. each(ol, 7, () => $toasts().filter((toast2) => !toast2.position && index2 === 0 || toast2.position === get$1(position2)), (toast2) => toast2.id, ($$anchor4, toast2, index3, $$array_1) => {
  4370. const expression = /* @__PURE__ */ derived_safe_equal(() => {
  4371. var _a2;
  4372. return ((_a2 = toastOptions()) == null ? void 0 : _a2.actionButtonStyle) || "";
  4373. });
  4374. const expression_1 = /* @__PURE__ */ derived_safe_equal(() => {
  4375. var _a2;
  4376. return ((_a2 = toastOptions()) == null ? void 0 : _a2.cancelButtonStyle) || "";
  4377. });
  4378. const expression_2 = /* @__PURE__ */ derived_safe_equal(() => {
  4379. var _a2;
  4380. return ((_a2 = toastOptions()) == null ? void 0 : _a2.class) || "";
  4381. });
  4382. const expression_3 = /* @__PURE__ */ derived_safe_equal(() => {
  4383. var _a2;
  4384. return ((_a2 = toastOptions()) == null ? void 0 : _a2.descriptionClass) || "";
  4385. });
  4386. const expression_4 = /* @__PURE__ */ derived_safe_equal(() => toastOptions().classes || {});
  4387. const expression_5 = /* @__PURE__ */ derived_safe_equal(() => {
  4388. var _a2;
  4389. return ((_a2 = toastOptions()) == null ? void 0 : _a2.duration) ?? duration();
  4390. });
  4391. const expression_6 = /* @__PURE__ */ derived_safe_equal(() => toastOptions().unstyled || false);
  4392. Toast($$anchor4, {
  4393. get index() {
  4394. return get$1(index3);
  4395. },
  4396. get toast() {
  4397. return get$1(toast2);
  4398. },
  4399. get invert() {
  4400. return invert();
  4401. },
  4402. get visibleToasts() {
  4403. return visibleToasts();
  4404. },
  4405. get closeButton() {
  4406. return closeButton();
  4407. },
  4408. get interacting() {
  4409. return get$1(interacting);
  4410. },
  4411. get position() {
  4412. return get$1(position2);
  4413. },
  4414. get expandByDefault() {
  4415. return expand();
  4416. },
  4417. get expanded() {
  4418. return get$1(expanded);
  4419. },
  4420. get actionButtonStyle() {
  4421. return get$1(expression);
  4422. },
  4423. get cancelButtonStyle() {
  4424. return get$1(expression_1);
  4425. },
  4426. get class() {
  4427. return get$1(expression_2);
  4428. },
  4429. get descriptionClass() {
  4430. return get$1(expression_3);
  4431. },
  4432. get classes() {
  4433. return get$1(expression_4);
  4434. },
  4435. get duration() {
  4436. return get$1(expression_5);
  4437. },
  4438. get unstyled() {
  4439. return get$1(expression_6);
  4440. },
  4441. $$slots: {
  4442. "loading-icon": ($$anchor5, $$slotProps) => {
  4443. var fragment_2 = comment();
  4444. var node_1 = first_child(fragment_2);
  4445. slot(node_1, $$props, "loading-icon", {}, ($$anchor6) => {
  4446. const expression_7 = /* @__PURE__ */ derived_safe_equal(() => get$1(toast2).type === "loading");
  4447. Loader($$anchor6, {
  4448. get visible() {
  4449. return get$1(expression_7);
  4450. }
  4451. });
  4452. });
  4453. append($$anchor5, fragment_2);
  4454. },
  4455. "success-icon": ($$anchor5, $$slotProps) => {
  4456. var fragment_4 = comment();
  4457. var node_2 = first_child(fragment_4);
  4458. slot(node_2, $$props, "success-icon", {}, ($$anchor6) => {
  4459. Icon($$anchor6, { type: "success" });
  4460. });
  4461. append($$anchor5, fragment_4);
  4462. },
  4463. "error-icon": ($$anchor5, $$slotProps) => {
  4464. var fragment_6 = comment();
  4465. var node_3 = first_child(fragment_6);
  4466. slot(node_3, $$props, "error-icon", {}, ($$anchor6) => {
  4467. Icon($$anchor6, { type: "error" });
  4468. });
  4469. append($$anchor5, fragment_6);
  4470. },
  4471. "warning-icon": ($$anchor5, $$slotProps) => {
  4472. var fragment_8 = comment();
  4473. var node_4 = first_child(fragment_8);
  4474. slot(node_4, $$props, "warning-icon", {}, ($$anchor6) => {
  4475. Icon($$anchor6, { type: "warning" });
  4476. });
  4477. append($$anchor5, fragment_8);
  4478. },
  4479. "info-icon": ($$anchor5, $$slotProps) => {
  4480. var fragment_10 = comment();
  4481. var node_5 = first_child(fragment_10);
  4482. slot(node_5, $$props, "info-icon", {}, ($$anchor6) => {
  4483. Icon($$anchor6, { type: "info" });
  4484. });
  4485. append($$anchor5, fragment_10);
  4486. }
  4487. }
  4488. });
  4489. });
  4490. bind_this(ol, ($$value) => set(listRef, $$value), () => get$1(listRef));
  4491. template_effect(
  4492. ($0, $1, $2) => {
  4493. var _a2;
  4494. attributes = set_attributes(
  4495. ol,
  4496. attributes,
  4497. {
  4498. tabIndex: -1,
  4499. class: $$sanitized_props.class,
  4500. "data-sonner-toaster": true,
  4501. "data-theme": get$1(actualTheme),
  4502. "data-rich-colors": richColors(),
  4503. dir: $0,
  4504. "data-y-position": $1,
  4505. "data-x-position": $2,
  4506. style: $$sanitized_props.style,
  4507. ...$$restProps,
  4508. [STYLE]: {
  4509. "--front-toast-height": `${(_a2 = $heights()[0]) == null ? void 0 : _a2.height}px`,
  4510. "--offset": typeof offset() === "number" ? `${offset()}px` : offset() || VIEWPORT_OFFSET,
  4511. "--width": `${TOAST_WIDTH}px`,
  4512. "--gap": `${GAP}px`
  4513. }
  4514. },
  4515. "svelte-1fo5d1m"
  4516. );
  4517. ol.dir = ol.dir;
  4518. },
  4519. [
  4520. () => dir() === "auto" ? getDocumentDirection() : dir(),
  4521. () => get$1(position2).split("-")[0],
  4522. () => get$1(position2).split("-")[1]
  4523. ],
  4524. derived_safe_equal
  4525. );
  4526. event("blur", ol, handleBlur);
  4527. event("focus", ol, handleFocus);
  4528. event("mouseenter", ol, () => set(expanded, true));
  4529. event("mousemove", ol, () => set(expanded, true));
  4530. event("mouseleave", ol, () => {
  4531. if (!get$1(interacting)) {
  4532. set(expanded, false);
  4533. }
  4534. });
  4535. event("pointerdown", ol, () => set(interacting, true));
  4536. event("pointerup", ol, () => set(interacting, false));
  4537. append($$anchor3, ol);
  4538. });
  4539. template_effect(() => set_attribute(section, "aria-label", `${containerAriaLabel()} ${get$1(hotkeyLabel)}`));
  4540. append($$anchor2, section);
  4541. };
  4542. if_block(node, ($$render) => {
  4543. if ($toasts().length > 0) $$render(consequent);
  4544. });
  4545. }
  4546. append($$anchor, fragment);
  4547. pop();
  4548. $$cleanup();
  4549. }
  4550. const CONFIG = {
  4551. APP_NAME: "LeetCode Jupyter"
  4552. };
  4553. const messageToastTypes = [
  4554. "success",
  4555. "info",
  4556. "warning",
  4557. "error",
  4558. "message",
  4559. "loading"
  4560. ];
  4561. function addPrefix(message) {
  4562. if (typeof message === "string") {
  4563. return `${CONFIG.APP_NAME}: ${message}`;
  4564. }
  4565. return message;
  4566. }
  4567. const prefixToast = new Proxy(toast, {
  4568. // Handle direct function calls: toast('message')
  4569. apply(target, thisArg, args) {
  4570. if (args.length > 0) {
  4571. args[0] = addPrefix(args[0]);
  4572. }
  4573. return Reflect.apply(target, thisArg, args);
  4574. },
  4575. get(target, prop2, receiver) {
  4576. const originalProp = Reflect.get(target, prop2, receiver);
  4577. if (typeof originalProp === "function" && messageToastTypes.includes(prop2.toString())) {
  4578. return function(...args) {
  4579. if (args.length > 0) {
  4580. args[0] = addPrefix(args[0]);
  4581. }
  4582. return originalProp.apply(this, args);
  4583. };
  4584. }
  4585. return originalProp;
  4586. }
  4587. });
  4588. function findElement(selector, config = {}) {
  4589. const {
  4590. parent = document,
  4591. timeout = 1e4,
  4592. onError = (error) => {
  4593. if (error instanceof ReferenceError) {
  4594. prefixToast.error(
  4595. "Element not found within timeout. Please refresh the page or disable the script."
  4596. );
  4597. }
  4598. }
  4599. } = config;
  4600. return new Promise((resolve, reject) => {
  4601. const observer = new MutationObserver((_mutations, obs) => {
  4602. const targetElement = parent.querySelector(selector);
  4603. if (targetElement) {
  4604. obs.disconnect();
  4605. resolve(targetElement);
  4606. }
  4607. });
  4608. observer.observe(parent, {
  4609. childList: true,
  4610. subtree: true
  4611. });
  4612. const timeoutId = setTimeout(() => {
  4613. observer.disconnect();
  4614. const error = new ReferenceError(
  4615. `Element "${selector}" not found within timeout (${timeout}ms)`
  4616. );
  4617. onError == null ? void 0 : onError(error);
  4618. reject(error);
  4619. }, timeout);
  4620. const initialElement = parent.querySelector(selector);
  4621. if (initialElement) {
  4622. clearTimeout(timeoutId);
  4623. observer.disconnect();
  4624. resolve(initialElement);
  4625. }
  4626. });
  4627. }
  4628. const state = proxy({ site: "global" });
  4629. async function copy(text2) {
  4630. try {
  4631. await navigator.clipboard.writeText(text2);
  4632. prefixToast.success(state.site === "cn" ? "复制到剪贴板!" : "Copied to clipboard!");
  4633. } catch (err) {
  4634. if (err instanceof Error) {
  4635. const errorMessage = state.site === "cn" ? "复制失败" : "Failed to copy";
  4636. prefixToast.error(errorMessage + ": " + err.message);
  4637. console.error(errorMessage + err);
  4638. } else throw err;
  4639. }
  4640. }
  4641. const getTitle = async () => (await findElement(".text-title-large", { timeout: 500 })).textContent ?? "";
  4642. function Copy_title($$anchor, $$props) {
  4643. push($$props, false);
  4644. async function copyTitle() {
  4645. copy(await getTitle());
  4646. }
  4647. init();
  4648. Button($$anchor, {
  4649. onclick: copyTitle,
  4650. children: ($$anchor2, $$slotProps) => {
  4651. var text$1 = text();
  4652. template_effect(() => set_text(text$1, state.site === "cn" ? "复制标题" : "Copy Title"));
  4653. append($$anchor2, text$1);
  4654. },
  4655. $$slots: { default: true }
  4656. });
  4657. pop();
  4658. }
  4659. function extend(destination) {
  4660. for (var i2 = 1; i2 < arguments.length; i2++) {
  4661. var source2 = arguments[i2];
  4662. for (var key in source2) {
  4663. if (source2.hasOwnProperty(key)) destination[key] = source2[key];
  4664. }
  4665. }
  4666. return destination;
  4667. }
  4668. function repeat(character, count) {
  4669. return Array(count + 1).join(character);
  4670. }
  4671. function trimLeadingNewlines(string) {
  4672. return string.replace(/^\n*/, "");
  4673. }
  4674. function trimTrailingNewlines(string) {
  4675. var indexEnd = string.length;
  4676. while (indexEnd > 0 && string[indexEnd - 1] === "\n") indexEnd--;
  4677. return string.substring(0, indexEnd);
  4678. }
  4679. var blockElements = [
  4680. "ADDRESS",
  4681. "ARTICLE",
  4682. "ASIDE",
  4683. "AUDIO",
  4684. "BLOCKQUOTE",
  4685. "BODY",
  4686. "CANVAS",
  4687. "CENTER",
  4688. "DD",
  4689. "DIR",
  4690. "DIV",
  4691. "DL",
  4692. "DT",
  4693. "FIELDSET",
  4694. "FIGCAPTION",
  4695. "FIGURE",
  4696. "FOOTER",
  4697. "FORM",
  4698. "FRAMESET",
  4699. "H1",
  4700. "H2",
  4701. "H3",
  4702. "H4",
  4703. "H5",
  4704. "H6",
  4705. "HEADER",
  4706. "HGROUP",
  4707. "HR",
  4708. "HTML",
  4709. "ISINDEX",
  4710. "LI",
  4711. "MAIN",
  4712. "MENU",
  4713. "NAV",
  4714. "NOFRAMES",
  4715. "NOSCRIPT",
  4716. "OL",
  4717. "OUTPUT",
  4718. "P",
  4719. "PRE",
  4720. "SECTION",
  4721. "TABLE",
  4722. "TBODY",
  4723. "TD",
  4724. "TFOOT",
  4725. "TH",
  4726. "THEAD",
  4727. "TR",
  4728. "UL"
  4729. ];
  4730. function isBlock(node) {
  4731. return is(node, blockElements);
  4732. }
  4733. var voidElements = [
  4734. "AREA",
  4735. "BASE",
  4736. "BR",
  4737. "COL",
  4738. "COMMAND",
  4739. "EMBED",
  4740. "HR",
  4741. "IMG",
  4742. "INPUT",
  4743. "KEYGEN",
  4744. "LINK",
  4745. "META",
  4746. "PARAM",
  4747. "SOURCE",
  4748. "TRACK",
  4749. "WBR"
  4750. ];
  4751. function isVoid(node) {
  4752. return is(node, voidElements);
  4753. }
  4754. function hasVoid(node) {
  4755. return has(node, voidElements);
  4756. }
  4757. var meaningfulWhenBlankElements = [
  4758. "A",
  4759. "TABLE",
  4760. "THEAD",
  4761. "TBODY",
  4762. "TFOOT",
  4763. "TH",
  4764. "TD",
  4765. "IFRAME",
  4766. "SCRIPT",
  4767. "AUDIO",
  4768. "VIDEO"
  4769. ];
  4770. function isMeaningfulWhenBlank(node) {
  4771. return is(node, meaningfulWhenBlankElements);
  4772. }
  4773. function hasMeaningfulWhenBlank(node) {
  4774. return has(node, meaningfulWhenBlankElements);
  4775. }
  4776. function is(node, tagNames) {
  4777. return tagNames.indexOf(node.nodeName) >= 0;
  4778. }
  4779. function has(node, tagNames) {
  4780. return node.getElementsByTagName && tagNames.some(function(tagName) {
  4781. return node.getElementsByTagName(tagName).length;
  4782. });
  4783. }
  4784. var rules = {};
  4785. rules.paragraph = {
  4786. filter: "p",
  4787. replacement: function(content) {
  4788. return "\n\n" + content + "\n\n";
  4789. }
  4790. };
  4791. rules.lineBreak = {
  4792. filter: "br",
  4793. replacement: function(content, node, options) {
  4794. return options.br + "\n";
  4795. }
  4796. };
  4797. rules.heading = {
  4798. filter: ["h1", "h2", "h3", "h4", "h5", "h6"],
  4799. replacement: function(content, node, options) {
  4800. var hLevel = Number(node.nodeName.charAt(1));
  4801. if (options.headingStyle === "setext" && hLevel < 3) {
  4802. var underline = repeat(hLevel === 1 ? "=" : "-", content.length);
  4803. return "\n\n" + content + "\n" + underline + "\n\n";
  4804. } else {
  4805. return "\n\n" + repeat("#", hLevel) + " " + content + "\n\n";
  4806. }
  4807. }
  4808. };
  4809. rules.blockquote = {
  4810. filter: "blockquote",
  4811. replacement: function(content) {
  4812. content = content.replace(/^\n+|\n+$/g, "");
  4813. content = content.replace(/^/gm, "> ");
  4814. return "\n\n" + content + "\n\n";
  4815. }
  4816. };
  4817. rules.list = {
  4818. filter: ["ul", "ol"],
  4819. replacement: function(content, node) {
  4820. var parent = node.parentNode;
  4821. if (parent.nodeName === "LI" && parent.lastElementChild === node) {
  4822. return "\n" + content;
  4823. } else {
  4824. return "\n\n" + content + "\n\n";
  4825. }
  4826. }
  4827. };
  4828. rules.listItem = {
  4829. filter: "li",
  4830. replacement: function(content, node, options) {
  4831. content = content.replace(/^\n+/, "").replace(/\n+$/, "\n").replace(/\n/gm, "\n ");
  4832. var prefix = options.bulletListMarker + " ";
  4833. var parent = node.parentNode;
  4834. if (parent.nodeName === "OL") {
  4835. var start = parent.getAttribute("start");
  4836. var index2 = Array.prototype.indexOf.call(parent.children, node);
  4837. prefix = (start ? Number(start) + index2 : index2 + 1) + ". ";
  4838. }
  4839. return prefix + content + (node.nextSibling && !/\n$/.test(content) ? "\n" : "");
  4840. }
  4841. };
  4842. rules.indentedCodeBlock = {
  4843. filter: function(node, options) {
  4844. return options.codeBlockStyle === "indented" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
  4845. },
  4846. replacement: function(content, node, options) {
  4847. return "\n\n " + node.firstChild.textContent.replace(/\n/g, "\n ") + "\n\n";
  4848. }
  4849. };
  4850. rules.fencedCodeBlock = {
  4851. filter: function(node, options) {
  4852. return options.codeBlockStyle === "fenced" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
  4853. },
  4854. replacement: function(content, node, options) {
  4855. var className = node.firstChild.getAttribute("class") || "";
  4856. var language = (className.match(/language-(\S+)/) || [null, ""])[1];
  4857. var code = node.firstChild.textContent;
  4858. var fenceChar = options.fence.charAt(0);
  4859. var fenceSize = 3;
  4860. var fenceInCodeRegex = new RegExp("^" + fenceChar + "{3,}", "gm");
  4861. var match;
  4862. while (match = fenceInCodeRegex.exec(code)) {
  4863. if (match[0].length >= fenceSize) {
  4864. fenceSize = match[0].length + 1;
  4865. }
  4866. }
  4867. var fence = repeat(fenceChar, fenceSize);
  4868. return "\n\n" + fence + language + "\n" + code.replace(/\n$/, "") + "\n" + fence + "\n\n";
  4869. }
  4870. };
  4871. rules.horizontalRule = {
  4872. filter: "hr",
  4873. replacement: function(content, node, options) {
  4874. return "\n\n" + options.hr + "\n\n";
  4875. }
  4876. };
  4877. rules.inlineLink = {
  4878. filter: function(node, options) {
  4879. return options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href");
  4880. },
  4881. replacement: function(content, node) {
  4882. var href = node.getAttribute("href");
  4883. if (href) href = href.replace(/([()])/g, "\\$1");
  4884. var title = cleanAttribute(node.getAttribute("title"));
  4885. if (title) title = ' "' + title.replace(/"/g, '\\"') + '"';
  4886. return "[" + content + "](" + href + title + ")";
  4887. }
  4888. };
  4889. rules.referenceLink = {
  4890. filter: function(node, options) {
  4891. return options.linkStyle === "referenced" && node.nodeName === "A" && node.getAttribute("href");
  4892. },
  4893. replacement: function(content, node, options) {
  4894. var href = node.getAttribute("href");
  4895. var title = cleanAttribute(node.getAttribute("title"));
  4896. if (title) title = ' "' + title + '"';
  4897. var replacement;
  4898. var reference;
  4899. switch (options.linkReferenceStyle) {
  4900. case "collapsed":
  4901. replacement = "[" + content + "][]";
  4902. reference = "[" + content + "]: " + href + title;
  4903. break;
  4904. case "shortcut":
  4905. replacement = "[" + content + "]";
  4906. reference = "[" + content + "]: " + href + title;
  4907. break;
  4908. default:
  4909. var id = this.references.length + 1;
  4910. replacement = "[" + content + "][" + id + "]";
  4911. reference = "[" + id + "]: " + href + title;
  4912. }
  4913. this.references.push(reference);
  4914. return replacement;
  4915. },
  4916. references: [],
  4917. append: function(options) {
  4918. var references = "";
  4919. if (this.references.length) {
  4920. references = "\n\n" + this.references.join("\n") + "\n\n";
  4921. this.references = [];
  4922. }
  4923. return references;
  4924. }
  4925. };
  4926. rules.emphasis = {
  4927. filter: ["em", "i"],
  4928. replacement: function(content, node, options) {
  4929. if (!content.trim()) return "";
  4930. return options.emDelimiter + content + options.emDelimiter;
  4931. }
  4932. };
  4933. rules.strong = {
  4934. filter: ["strong", "b"],
  4935. replacement: function(content, node, options) {
  4936. if (!content.trim()) return "";
  4937. return options.strongDelimiter + content + options.strongDelimiter;
  4938. }
  4939. };
  4940. rules.code = {
  4941. filter: function(node) {
  4942. var hasSiblings = node.previousSibling || node.nextSibling;
  4943. var isCodeBlock = node.parentNode.nodeName === "PRE" && !hasSiblings;
  4944. return node.nodeName === "CODE" && !isCodeBlock;
  4945. },
  4946. replacement: function(content) {
  4947. if (!content) return "";
  4948. content = content.replace(/\r?\n|\r/g, " ");
  4949. var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? " " : "";
  4950. var delimiter = "`";
  4951. var matches = content.match(/`+/gm) || [];
  4952. while (matches.indexOf(delimiter) !== -1) delimiter = delimiter + "`";
  4953. return delimiter + extraSpace + content + extraSpace + delimiter;
  4954. }
  4955. };
  4956. rules.image = {
  4957. filter: "img",
  4958. replacement: function(content, node) {
  4959. var alt = cleanAttribute(node.getAttribute("alt"));
  4960. var src = node.getAttribute("src") || "";
  4961. var title = cleanAttribute(node.getAttribute("title"));
  4962. var titlePart = title ? ' "' + title + '"' : "";
  4963. return src ? "![" + alt + "](" + src + titlePart + ")" : "";
  4964. }
  4965. };
  4966. function cleanAttribute(attribute) {
  4967. return attribute ? attribute.replace(/(\n+\s*)+/g, "\n") : "";
  4968. }
  4969. function Rules(options) {
  4970. this.options = options;
  4971. this._keep = [];
  4972. this._remove = [];
  4973. this.blankRule = {
  4974. replacement: options.blankReplacement
  4975. };
  4976. this.keepReplacement = options.keepReplacement;
  4977. this.defaultRule = {
  4978. replacement: options.defaultReplacement
  4979. };
  4980. this.array = [];
  4981. for (var key in options.rules) this.array.push(options.rules[key]);
  4982. }
  4983. Rules.prototype = {
  4984. add: function(key, rule) {
  4985. this.array.unshift(rule);
  4986. },
  4987. keep: function(filter) {
  4988. this._keep.unshift({
  4989. filter,
  4990. replacement: this.keepReplacement
  4991. });
  4992. },
  4993. remove: function(filter) {
  4994. this._remove.unshift({
  4995. filter,
  4996. replacement: function() {
  4997. return "";
  4998. }
  4999. });
  5000. },
  5001. forNode: function(node) {
  5002. if (node.isBlank) return this.blankRule;
  5003. var rule;
  5004. if (rule = findRule(this.array, node, this.options)) return rule;
  5005. if (rule = findRule(this._keep, node, this.options)) return rule;
  5006. if (rule = findRule(this._remove, node, this.options)) return rule;
  5007. return this.defaultRule;
  5008. },
  5009. forEach: function(fn) {
  5010. for (var i2 = 0; i2 < this.array.length; i2++) fn(this.array[i2], i2);
  5011. }
  5012. };
  5013. function findRule(rules2, node, options) {
  5014. for (var i2 = 0; i2 < rules2.length; i2++) {
  5015. var rule = rules2[i2];
  5016. if (filterValue(rule, node, options)) return rule;
  5017. }
  5018. return void 0;
  5019. }
  5020. function filterValue(rule, node, options) {
  5021. var filter = rule.filter;
  5022. if (typeof filter === "string") {
  5023. if (filter === node.nodeName.toLowerCase()) return true;
  5024. } else if (Array.isArray(filter)) {
  5025. if (filter.indexOf(node.nodeName.toLowerCase()) > -1) return true;
  5026. } else if (typeof filter === "function") {
  5027. if (filter.call(rule, node, options)) return true;
  5028. } else {
  5029. throw new TypeError("`filter` needs to be a string, array, or function");
  5030. }
  5031. }
  5032. function collapseWhitespace(options) {
  5033. var element = options.element;
  5034. var isBlock2 = options.isBlock;
  5035. var isVoid2 = options.isVoid;
  5036. var isPre = options.isPre || function(node2) {
  5037. return node2.nodeName === "PRE";
  5038. };
  5039. if (!element.firstChild || isPre(element)) return;
  5040. var prevText = null;
  5041. var keepLeadingWs = false;
  5042. var prev = null;
  5043. var node = next(prev, element, isPre);
  5044. while (node !== element) {
  5045. if (node.nodeType === 3 || node.nodeType === 4) {
  5046. var text2 = node.data.replace(/[ \r\n\t]+/g, " ");
  5047. if ((!prevText || / $/.test(prevText.data)) && !keepLeadingWs && text2[0] === " ") {
  5048. text2 = text2.substr(1);
  5049. }
  5050. if (!text2) {
  5051. node = remove(node);
  5052. continue;
  5053. }
  5054. node.data = text2;
  5055. prevText = node;
  5056. } else if (node.nodeType === 1) {
  5057. if (isBlock2(node) || node.nodeName === "BR") {
  5058. if (prevText) {
  5059. prevText.data = prevText.data.replace(/ $/, "");
  5060. }
  5061. prevText = null;
  5062. keepLeadingWs = false;
  5063. } else if (isVoid2(node) || isPre(node)) {
  5064. prevText = null;
  5065. keepLeadingWs = true;
  5066. } else if (prevText) {
  5067. keepLeadingWs = false;
  5068. }
  5069. } else {
  5070. node = remove(node);
  5071. continue;
  5072. }
  5073. var nextNode = next(prev, node, isPre);
  5074. prev = node;
  5075. node = nextNode;
  5076. }
  5077. if (prevText) {
  5078. prevText.data = prevText.data.replace(/ $/, "");
  5079. if (!prevText.data) {
  5080. remove(prevText);
  5081. }
  5082. }
  5083. }
  5084. function remove(node) {
  5085. var next2 = node.nextSibling || node.parentNode;
  5086. node.parentNode.removeChild(node);
  5087. return next2;
  5088. }
  5089. function next(prev, current, isPre) {
  5090. if (prev && prev.parentNode === current || isPre(current)) {
  5091. return current.nextSibling || current.parentNode;
  5092. }
  5093. return current.firstChild || current.nextSibling || current.parentNode;
  5094. }
  5095. var root$1 = typeof window !== "undefined" ? window : {};
  5096. function canParseHTMLNatively() {
  5097. var Parser = root$1.DOMParser;
  5098. var canParse = false;
  5099. try {
  5100. if (new Parser().parseFromString("", "text/html")) {
  5101. canParse = true;
  5102. }
  5103. } catch (e) {
  5104. }
  5105. return canParse;
  5106. }
  5107. function createHTMLParser() {
  5108. var Parser = function() {
  5109. };
  5110. {
  5111. if (shouldUseActiveX()) {
  5112. Parser.prototype.parseFromString = function(string) {
  5113. var doc = new window.ActiveXObject("htmlfile");
  5114. doc.designMode = "on";
  5115. doc.open();
  5116. doc.write(string);
  5117. doc.close();
  5118. return doc;
  5119. };
  5120. } else {
  5121. Parser.prototype.parseFromString = function(string) {
  5122. var doc = document.implementation.createHTMLDocument("");
  5123. doc.open();
  5124. doc.write(string);
  5125. doc.close();
  5126. return doc;
  5127. };
  5128. }
  5129. }
  5130. return Parser;
  5131. }
  5132. function shouldUseActiveX() {
  5133. var useActiveX = false;
  5134. try {
  5135. document.implementation.createHTMLDocument("").open();
  5136. } catch (e) {
  5137. if (root$1.ActiveXObject) useActiveX = true;
  5138. }
  5139. return useActiveX;
  5140. }
  5141. var HTMLParser = canParseHTMLNatively() ? root$1.DOMParser : createHTMLParser();
  5142. function RootNode(input, options) {
  5143. var root2;
  5144. if (typeof input === "string") {
  5145. var doc = htmlParser().parseFromString(
  5146. // DOM parsers arrange elements in the <head> and <body>.
  5147. // Wrapping in a custom element ensures elements are reliably arranged in
  5148. // a single element.
  5149. '<x-turndown id="turndown-root">' + input + "</x-turndown>",
  5150. "text/html"
  5151. );
  5152. root2 = doc.getElementById("turndown-root");
  5153. } else {
  5154. root2 = input.cloneNode(true);
  5155. }
  5156. collapseWhitespace({
  5157. element: root2,
  5158. isBlock,
  5159. isVoid,
  5160. isPre: options.preformattedCode ? isPreOrCode : null
  5161. });
  5162. return root2;
  5163. }
  5164. var _htmlParser;
  5165. function htmlParser() {
  5166. _htmlParser = _htmlParser || new HTMLParser();
  5167. return _htmlParser;
  5168. }
  5169. function isPreOrCode(node) {
  5170. return node.nodeName === "PRE" || node.nodeName === "CODE";
  5171. }
  5172. function Node$1(node, options) {
  5173. node.isBlock = isBlock(node);
  5174. node.isCode = node.nodeName === "CODE" || node.parentNode.isCode;
  5175. node.isBlank = isBlank(node);
  5176. node.flankingWhitespace = flankingWhitespace(node, options);
  5177. return node;
  5178. }
  5179. function isBlank(node) {
  5180. return !isVoid(node) && !isMeaningfulWhenBlank(node) && /^\s*$/i.test(node.textContent) && !hasVoid(node) && !hasMeaningfulWhenBlank(node);
  5181. }
  5182. function flankingWhitespace(node, options) {
  5183. if (node.isBlock || options.preformattedCode && node.isCode) {
  5184. return { leading: "", trailing: "" };
  5185. }
  5186. var edges = edgeWhitespace(node.textContent);
  5187. if (edges.leadingAscii && isFlankedByWhitespace("left", node, options)) {
  5188. edges.leading = edges.leadingNonAscii;
  5189. }
  5190. if (edges.trailingAscii && isFlankedByWhitespace("right", node, options)) {
  5191. edges.trailing = edges.trailingNonAscii;
  5192. }
  5193. return { leading: edges.leading, trailing: edges.trailing };
  5194. }
  5195. function edgeWhitespace(string) {
  5196. var m = string.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);
  5197. return {
  5198. leading: m[1],
  5199. // whole string for whitespace-only strings
  5200. leadingAscii: m[2],
  5201. leadingNonAscii: m[3],
  5202. trailing: m[4],
  5203. // empty for whitespace-only strings
  5204. trailingNonAscii: m[5],
  5205. trailingAscii: m[6]
  5206. };
  5207. }
  5208. function isFlankedByWhitespace(side, node, options) {
  5209. var sibling2;
  5210. var regExp;
  5211. var isFlanked;
  5212. if (side === "left") {
  5213. sibling2 = node.previousSibling;
  5214. regExp = / $/;
  5215. } else {
  5216. sibling2 = node.nextSibling;
  5217. regExp = /^ /;
  5218. }
  5219. if (sibling2) {
  5220. if (sibling2.nodeType === 3) {
  5221. isFlanked = regExp.test(sibling2.nodeValue);
  5222. } else if (options.preformattedCode && sibling2.nodeName === "CODE") {
  5223. isFlanked = false;
  5224. } else if (sibling2.nodeType === 1 && !isBlock(sibling2)) {
  5225. isFlanked = regExp.test(sibling2.textContent);
  5226. }
  5227. }
  5228. return isFlanked;
  5229. }
  5230. var reduce = Array.prototype.reduce;
  5231. var escapes = [
  5232. [/\\/g, "\\\\"],
  5233. [/\*/g, "\\*"],
  5234. [/^-/g, "\\-"],
  5235. [/^\+ /g, "\\+ "],
  5236. [/^(=+)/g, "\\$1"],
  5237. [/^(#{1,6}) /g, "\\$1 "],
  5238. [/`/g, "\\`"],
  5239. [/^~~~/g, "\\~~~"],
  5240. [/\[/g, "\\["],
  5241. [/\]/g, "\\]"],
  5242. [/^>/g, "\\>"],
  5243. [/_/g, "\\_"],
  5244. [/^(\d+)\. /g, "$1\\. "]
  5245. ];
  5246. function TurndownService(options) {
  5247. if (!(this instanceof TurndownService)) return new TurndownService(options);
  5248. var defaults = {
  5249. rules,
  5250. headingStyle: "setext",
  5251. hr: "* * *",
  5252. bulletListMarker: "*",
  5253. codeBlockStyle: "indented",
  5254. fence: "```",
  5255. emDelimiter: "_",
  5256. strongDelimiter: "**",
  5257. linkStyle: "inlined",
  5258. linkReferenceStyle: "full",
  5259. br: " ",
  5260. preformattedCode: false,
  5261. blankReplacement: function(content, node) {
  5262. return node.isBlock ? "\n\n" : "";
  5263. },
  5264. keepReplacement: function(content, node) {
  5265. return node.isBlock ? "\n\n" + node.outerHTML + "\n\n" : node.outerHTML;
  5266. },
  5267. defaultReplacement: function(content, node) {
  5268. return node.isBlock ? "\n\n" + content + "\n\n" : content;
  5269. }
  5270. };
  5271. this.options = extend({}, defaults, options);
  5272. this.rules = new Rules(this.options);
  5273. }
  5274. TurndownService.prototype = {
  5275. /**
  5276. * The entry point for converting a string or DOM node to Markdown
  5277. * @public
  5278. * @param {String|HTMLElement} input The string or DOM node to convert
  5279. * @returns A Markdown representation of the input
  5280. * @type String
  5281. */
  5282. turndown: function(input) {
  5283. if (!canConvert(input)) {
  5284. throw new TypeError(
  5285. input + " is not a string, or an element/document/fragment node."
  5286. );
  5287. }
  5288. if (input === "") return "";
  5289. var output = process.call(this, new RootNode(input, this.options));
  5290. return postProcess.call(this, output);
  5291. },
  5292. /**
  5293. * Add one or more plugins
  5294. * @public
  5295. * @param {Function|Array} plugin The plugin or array of plugins to add
  5296. * @returns The Turndown instance for chaining
  5297. * @type Object
  5298. */
  5299. use: function(plugin) {
  5300. if (Array.isArray(plugin)) {
  5301. for (var i2 = 0; i2 < plugin.length; i2++) this.use(plugin[i2]);
  5302. } else if (typeof plugin === "function") {
  5303. plugin(this);
  5304. } else {
  5305. throw new TypeError("plugin must be a Function or an Array of Functions");
  5306. }
  5307. return this;
  5308. },
  5309. /**
  5310. * Adds a rule
  5311. * @public
  5312. * @param {String} key The unique key of the rule
  5313. * @param {Object} rule The rule
  5314. * @returns The Turndown instance for chaining
  5315. * @type Object
  5316. */
  5317. addRule: function(key, rule) {
  5318. this.rules.add(key, rule);
  5319. return this;
  5320. },
  5321. /**
  5322. * Keep a node (as HTML) that matches the filter
  5323. * @public
  5324. * @param {String|Array|Function} filter The unique key of the rule
  5325. * @returns The Turndown instance for chaining
  5326. * @type Object
  5327. */
  5328. keep: function(filter) {
  5329. this.rules.keep(filter);
  5330. return this;
  5331. },
  5332. /**
  5333. * Remove a node that matches the filter
  5334. * @public
  5335. * @param {String|Array|Function} filter The unique key of the rule
  5336. * @returns The Turndown instance for chaining
  5337. * @type Object
  5338. */
  5339. remove: function(filter) {
  5340. this.rules.remove(filter);
  5341. return this;
  5342. },
  5343. /**
  5344. * Escapes Markdown syntax
  5345. * @public
  5346. * @param {String} string The string to escape
  5347. * @returns A string with Markdown syntax escaped
  5348. * @type String
  5349. */
  5350. escape: function(string) {
  5351. return escapes.reduce(function(accumulator, escape) {
  5352. return accumulator.replace(escape[0], escape[1]);
  5353. }, string);
  5354. }
  5355. };
  5356. function process(parentNode) {
  5357. var self = this;
  5358. return reduce.call(parentNode.childNodes, function(output, node) {
  5359. node = new Node$1(node, self.options);
  5360. var replacement = "";
  5361. if (node.nodeType === 3) {
  5362. replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
  5363. } else if (node.nodeType === 1) {
  5364. replacement = replacementForNode.call(self, node);
  5365. }
  5366. return join(output, replacement);
  5367. }, "");
  5368. }
  5369. function postProcess(output) {
  5370. var self = this;
  5371. this.rules.forEach(function(rule) {
  5372. if (typeof rule.append === "function") {
  5373. output = join(output, rule.append(self.options));
  5374. }
  5375. });
  5376. return output.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
  5377. }
  5378. function replacementForNode(node) {
  5379. var rule = this.rules.forNode(node);
  5380. var content = process.call(this, node);
  5381. var whitespace2 = node.flankingWhitespace;
  5382. if (whitespace2.leading || whitespace2.trailing) content = content.trim();
  5383. return whitespace2.leading + rule.replacement(content, node, this.options) + whitespace2.trailing;
  5384. }
  5385. function join(output, replacement) {
  5386. var s1 = trimTrailingNewlines(output);
  5387. var s2 = trimLeadingNewlines(replacement);
  5388. var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
  5389. var separator = "\n\n".substring(0, nls);
  5390. return s1 + separator + s2;
  5391. }
  5392. function canConvert(input) {
  5393. return input != null && (typeof input === "string" || input.nodeType && (input.nodeType === 1 || input.nodeType === 9 || input.nodeType === 11));
  5394. }
  5395. const turndownService = new TurndownService({
  5396. emDelimiter: "*",
  5397. bulletListMarker: "-"
  5398. });
  5399. turndownService.addRule("pre", {
  5400. filter: ["pre"],
  5401. replacement: (content, node) => {
  5402. var _a2;
  5403. return "\n```txt\n" + ((_a2 = node.textContent) == null ? void 0 : _a2.trim()) + "\n```\n";
  5404. }
  5405. });
  5406. turndownService.addRule("superscript", {
  5407. filter: ["sup"],
  5408. replacement: (content) => "^" + content
  5409. });
  5410. turndownService.addRule("paragraph", {
  5411. filter: ["p"],
  5412. replacement: (content) => "\n\n" + content + "\n\n"
  5413. });
  5414. function htmlToMd(htmlStr) {
  5415. return turndownService.turndown(htmlStr);
  5416. }
  5417. const getDescription = async () => {
  5418. const el = await findElement("[data-track-load='description_content']", { timeout: 500 });
  5419. return htmlToMd(el.innerHTML);
  5420. };
  5421. function Copy_description($$anchor, $$props) {
  5422. push($$props, false);
  5423. async function copyDescription() {
  5424. copy(await getDescription());
  5425. }
  5426. init();
  5427. Button($$anchor, {
  5428. onclick: copyDescription,
  5429. children: ($$anchor2, $$slotProps) => {
  5430. var text$1 = text();
  5431. template_effect(() => set_text(text$1, state.site === "cn" ? "复制描述" : "Copy Description"));
  5432. append($$anchor2, text$1);
  5433. },
  5434. $$slots: { default: true }
  5435. });
  5436. pop();
  5437. }
  5438. function createNotebook({
  5439. title,
  5440. description,
  5441. language = "python",
  5442. url
  5443. }) {
  5444. const notebook = {
  5445. metadata: { language_info: { name: language } },
  5446. nbformat: 5,
  5447. nbformat_minor: 10,
  5448. cells: []
  5449. };
  5450. const regex = /^(https:\/\/(leetcode\.com|leetcode\.cn)\/problems\/[a-zA-Z0-9_-]+)/;
  5451. const match = url.match(regex);
  5452. const titleCell = createMarkdownCell(`# [${title}](${match ? match[0] : url})`);
  5453. const descriptionPrefix = state.site === "cn" ? "题目描述" : "Description";
  5454. const descriptionCell = createMarkdownCell(`## ${descriptionPrefix}
  5455.  
  5456. ` + description);
  5457. const solutionPrefix = state.site === "cn" ? "解答" : "Solution";
  5458. const partitionCell = createMarkdownCell(["---\n\n", `## ${solutionPrefix}`]);
  5459. const codeCell = createCodeCell("");
  5460. notebook.cells.push(titleCell, descriptionCell, partitionCell, codeCell);
  5461. return notebook;
  5462. }
  5463. function createMarkdownCell(content) {
  5464. return {
  5465. cell_type: "markdown",
  5466. metadata: {},
  5467. source: content
  5468. };
  5469. }
  5470. function createCodeCell(content) {
  5471. return {
  5472. cell_type: "code",
  5473. metadata: {},
  5474. source: content,
  5475. execution_count: null,
  5476. outputs: []
  5477. };
  5478. }
  5479. function downloadNotebook(notebook, filename) {
  5480. const blob = new Blob([JSON.stringify(notebook)], { type: "application/x-ipynb+json" });
  5481. const url = URL.createObjectURL(blob);
  5482. const a2 = document.createElement("a");
  5483. a2.href = url;
  5484. a2.download = filename + ".ipynb";
  5485. document.body.appendChild(a2);
  5486. a2.click();
  5487. document.body.removeChild(a2);
  5488. URL.revokeObjectURL(url);
  5489. prefixToast.success(state.site === "cn" ? "已下载为 Jupyter Notebook!" : "Downloaded as Jupyter Notebook!");
  5490. }
  5491. function Download_as_jupyter($$anchor, $$props) {
  5492. push($$props, false);
  5493. const getLanguage = async () => {
  5494. const codeEl = await findElement("[data-keybinding-context='1']", { timeout: 500 });
  5495. return (codeEl == null ? void 0 : codeEl.getAttribute("data-mode-id")) ?? "python";
  5496. };
  5497. async function downloadAsJupyter() {
  5498. const title = await getTitle();
  5499. const notebook = createNotebook({
  5500. title,
  5501. description: await getDescription(),
  5502. language: await getLanguage(),
  5503. url: window.location.href
  5504. });
  5505. downloadNotebook(notebook, title);
  5506. }
  5507. init();
  5508. Button($$anchor, {
  5509. style: "color: oklch(51.1% 0.096 186.391)",
  5510. onclick: downloadAsJupyter,
  5511. children: ($$anchor2, $$slotProps) => {
  5512. var text$1 = text();
  5513. template_effect(() => set_text(text$1, state.site === "cn" ? "下载为 Jupyter Notebook (.ipynb)" : "Download as Jupyter Notebook (.ipynb)"));
  5514. append($$anchor2, text$1);
  5515. },
  5516. $$slots: { default: true }
  5517. });
  5518. pop();
  5519. }
  5520. var root = /* @__PURE__ */ template(`<div><!> <!> <!></div>`);
  5521. function App($$anchor) {
  5522. var div = root();
  5523. var node = child(div);
  5524. Copy_title(node, {});
  5525. var node_1 = sibling(node, 2);
  5526. Copy_description(node_1, {});
  5527. var node_2 = sibling(node_1, 2);
  5528. Download_as_jupyter(node_2, {});
  5529. append($$anchor, div);
  5530. }
  5531. function u$1(o2, n, a2) {
  5532. let t = (r2) => o2(r2, ...n);
  5533. return a2 === void 0 ? t : Object.assign(t, { lazy: a2, lazyArgs: n });
  5534. }
  5535. function u(r2, n, o2) {
  5536. let a2 = r2.length - n.length;
  5537. if (a2 === 0) return r2(...n);
  5538. if (a2 === 1) return u$1(r2, n, o2);
  5539. throw new Error("Wrong number of arguments");
  5540. }
  5541. var o$1 = [" ", `
  5542. `, "\v", "\f", "\r", " ", "…", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "\u2028", "\u2029", " ", " ", " ", "\uFEFF"], c = /* @__PURE__ */ new Set(["-", "_", ...o$1]), i = (r2) => {
  5543. let e = [], t = "", u2 = () => {
  5544. t.length > 0 && (e.push(t), t = "");
  5545. };
  5546. for (let s of r2) {
  5547. if (c.has(s)) {
  5548. u2();
  5549. continue;
  5550. }
  5551. if (/[a-z]$/u.test(t) && /[A-Z]/u.test(s)) u2();
  5552. else if (/[A-Z][A-Z]$/u.test(t) && /[a-z]/u.test(s)) {
  5553. let n = t.slice(-1);
  5554. t = t.slice(0, -1), u2(), t = n;
  5555. } else /\d$/u.test(t) !== /\d/u.test(s) && u2();
  5556. t += s;
  5557. }
  5558. return u2(), e;
  5559. };
  5560. function a(...e) {
  5561. return u(o, e);
  5562. }
  5563. var o = (e) => i(e).join("-").toLowerCase();
  5564. mount(Toaster, {
  5565. target: document.body,
  5566. props: { richColors: true, position: "top-center" }
  5567. });
  5568. const titleContainer = await( findElement("div:has(> .text-title-large)"));
  5569. const app = document.createElement("div");
  5570. app.setAttribute("id", a(CONFIG.APP_NAME));
  5571. app.style.cssText = "display: contents;";
  5572. (_c = (_b = titleContainer.parentElement) == null ? void 0 : _b.parentElement) == null ? void 0 : _c.insertBefore(
  5573. app,
  5574. titleContainer.parentElement
  5575. );
  5576. const hostname = window.location.hostname;
  5577. state.site = hostname === "leetcode.cn" ? "cn" : "global";
  5578. mount(App, {
  5579. target: app
  5580. });
  5581.  
  5582. })();