Pixiv Downloader

Pixiv | Danbooru | Rule34 | Yande. 一键下载各页面原图。批量下载画师作品,按作品标签下载。转换动图格式:Gif | Apng | Webp | Webm | MP4。自定义图片文件名,保存路径。保留 / 导出下载历史。

// ==UserScript==
// @name               Pixiv Downloader
// @namespace          https://greasyfork.org/zh-CN/scripts/432150
// @version            1.4.0
// @author             ruaruarua
// @description        Pixiv | Danbooru | Rule34 | Yande. 一键下载各页面原图。批量下载画师作品,按作品标签下载。转换动图格式:Gif | Apng | Webp | Webm | MP4。自定义图片文件名,保存路径。保留 / 导出下载历史。
// @description:zh-TW  Pixiv | Danbooru | Rule34 | Yande. 一鍵下載各頁面原圖。批次下載畫師作品,按作品標籤下載。轉換動圖格式:Gif | Apng | Webp | Webm | MP4。自定義圖片檔名,儲存路徑。保留 / 匯出下載歷史。
// @description:en     Pixiv | Danbooru | Rule34 | Yande. Download artworks with one click. Batch download artworks or download by tags. Convert ugoira formats: Gif | Apng | Webp | Webm | MP4. Customize image file name, save path. Save / export download history.
// @license            MIT
// @icon               https://www.pixiv.net/favicon.ico
// @supportURL         https://github.com/drunkg00se/Pixiv-Downloader/issues
// @match              https://www.pixiv.net/*
// @match              https://rule34.xxx/*
// @match              https://danbooru.donmai.us/*
// @match              https://yande.re/*
// @match              https://booru.allthefallen.moe/*
// @require            https://unpkg.com/dexie@3.2.7/dist/dexie.min.js
// @require            https://unpkg.com/jszip@3.9.1/dist/jszip.min.js
// @require            https://unpkg.com/gif.js@0.2.0/dist/gif.js
// @require            https://unpkg.com/dayjs@1.11.11/dayjs.min.js
// @resource           ../wasm/toWebpWorker?raw    https://update.greasyfork.org/scripts/500281/1409041/libwebp_wasm.js
// @resource           gif.js/dist/gif.worker?raw  https://unpkg.com/gif.js@0.2.0/dist/gif.worker.js
// @resource           pako/dist/pako.js?raw       https://unpkg.com/pako@2.1.0/dist/pako.min.js
// @resource           upng-js?raw                 https://unpkg.com/upng-js@2.1.0/UPNG.js
// @connect            i.pximg.net
// @connect            source.pixiv.net
// @connect            rule34.xxx
// @connect            donmai.us
// @connect            yande.re
// @connect            allthefallen.moe
// @grant              GM_download
// @grant              GM_getResourceText
// @grant              GM_info
// @grant              GM_registerMenuCommand
// @grant              GM_xmlhttpRequest
// @grant              unsafeWindow
// @noframes
// ==/UserScript==

(t=>{const r=new CSSStyleSheet;r.replaceSync(t),window._pdlShadowStyle=r})(` .anim-indeterminate.svelte-12wvf64{transform-origin:0% 50%;animation:svelte-12wvf64-anim-indeterminate 2s infinite linear}@keyframes svelte-12wvf64-anim-indeterminate{0%{transform:translate(0) scaleX(0)}40%{transform:translate(0) scaleX(.4)}to{transform:translate(100%) scaleX(.5)}}*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}:host [data-theme=skeleton],:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}:host [data-theme=skeleton]{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h3{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}dl,dd,h1,h3,hr,figure,p{margin:0}fieldset{margin:0;padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}[type=text],input:where(:not([type])),[type=email],[type=url],[type=password],[type=number],[type=date],[type=datetime-local],[type=month],[type=search],[type=tel],[type=time],[type=week],[multiple],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:#fff;border-color:#6b7280;border-width:1px;border-radius:0;padding:8px 12px;font-size:16px;line-height:24px;--tw-shadow: 0 0 #0000}[type=text]:focus,input:where(:not([type])):focus,[type=email]:focus,[type=url]:focus,[type=password]:focus,[type=number]:focus,[type=date]:focus,[type=datetime-local]:focus,[type=month]:focus,[type=search]:focus,[type=tel]:focus,[type=time]:focus,[type=week]:focus,[multiple]:focus,textarea:focus,select:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-inset: var(--tw-empty, );--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: #2563eb;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow);border-color:#2563eb}input::-moz-placeholder,textarea::-moz-placeholder{color:#6b7280;opacity:1}input::placeholder,textarea::placeholder{color:#6b7280;opacity:1}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-date-and-time-value{min-height:1.5em;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field{padding-top:0;padding-bottom:0}select{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");background-position:right 8px center;background-repeat:no-repeat;background-size:1.5em 1.5em;padding-right:40px;-webkit-print-color-adjust:exact;print-color-adjust:exact}[multiple],[size]:where(select:not([size="1"])){background-image:initial;background-position:initial;background-repeat:unset;background-size:initial;padding-right:12px;-webkit-print-color-adjust:unset;print-color-adjust:unset}[type=checkbox],[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;-webkit-print-color-adjust:exact;print-color-adjust:exact;display:inline-block;vertical-align:middle;background-origin:border-box;-webkit-user-select:none;-moz-user-select:none;user-select:none;flex-shrink:0;height:16px;width:16px;color:#2563eb;background-color:#fff;border-color:#6b7280;border-width:1px;--tw-shadow: 0 0 #0000}[type=checkbox]{border-radius:0}[type=radio]{border-radius:100%}[type=checkbox]:focus,[type=radio]:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-inset: var(--tw-empty, );--tw-ring-offset-width: 2px;--tw-ring-offset-color: #fff;--tw-ring-color: #2563eb;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}[type=checkbox]:checked,[type=radio]:checked{border-color:transparent;background-color:currentColor;background-size:100% 100%;background-position:center;background-repeat:no-repeat}[type=checkbox]:checked{background-image:url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e")}@media (forced-colors: active){[type=checkbox]:checked{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}}[type=radio]:checked{background-image:url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e")}@media (forced-colors: active){[type=radio]:checked{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}}[type=checkbox]:checked:hover,[type=checkbox]:checked:focus,[type=radio]:checked:hover,[type=radio]:checked:focus{border-color:transparent;background-color:currentColor}[type=checkbox]:indeterminate{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");border-color:transparent;background-color:currentColor;background-size:100% 100%;background-position:center;background-repeat:no-repeat}@media (forced-colors: active){[type=checkbox]:indeterminate{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}}[type=checkbox]:indeterminate:hover,[type=checkbox]:indeterminate:focus{border-color:transparent;background-color:currentColor}[type=file]{background:unset;border-color:inherit;border-width:0;border-radius:0;padding:0;font-size:unset;line-height:inherit}[type=file]:focus{outline:1px solid ButtonText;outline:1px auto -webkit-focus-ring-color}:host [data-theme=skeleton]{background-color:rgb(var(--color-surface-50));font-size:16px;line-height:24px;font-family:var(--theme-font-family-base);color:rgba(var(--theme-font-color-base))}:host .dark [data-theme=skeleton]{background-color:rgb(var(--color-surface-900));color:rgba(var(--theme-font-color-dark))}::-moz-selection{background-color:rgb(var(--color-primary-500) / .3)}::selection{background-color:rgb(var(--color-primary-500) / .3)}:host [data-theme=skeleton]{-webkit-tap-highlight-color:rgba(128,128,128,.5);scrollbar-color:rgba(0,0,0,.2) rgba(255,255,255,.05)}:host [data-theme=skeleton]{scrollbar-color:rgba(128,128,128,.5) rgba(0,0,0,.1);scrollbar-width:thin}:host.dark{scrollbar-color:rgba(255,255,255,.1) rgba(0,0,0,.05)}hr:not(.divider){display:block;border-top-width:1px;border-style:solid;border-color:rgb(var(--color-surface-300))}.dark hr:not(.divider){border-color:rgb(var(--color-surface-600))}fieldset,label{display:block}::-moz-placeholder{color:rgb(var(--color-surface-500))}::placeholder{color:rgb(var(--color-surface-500))}.dark ::-moz-placeholder{color:rgb(var(--color-surface-400))}.dark ::placeholder{color:rgb(var(--color-surface-400))}:is(.dark input::-webkit-calendar-picker-indicator){--tw-invert: invert(100%);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}input[type=search]::-webkit-search-cancel-button{-webkit-appearance:none;background:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z'/%3E%3C/svg%3E") no-repeat 50% 50%;pointer-events:none;height:16px;width:16px;border-radius:9999px;background-size:contain;opacity:0}input[type=search]:focus::-webkit-search-cancel-button{pointer-events:auto;opacity:1}:is(.dark input[type=search]::-webkit-search-cancel-button){--tw-invert: invert(100%);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}progress{webkit-appearance:none;-moz-appearance:none;-webkit-appearance:none;appearance:none;height:8px;width:100%;overflow:hidden;border-radius:var(--theme-rounded-base);background-color:rgb(var(--color-surface-400))}.dark progress{background-color:rgb(var(--color-surface-500))}progress::-webkit-progress-bar{background-color:rgb(var(--color-surface-400))}.dark progress::-webkit-progress-bar{background-color:rgb(var(--color-surface-500))}progress::-webkit-progress-value{background-color:rgb(var(--color-surface-900))}.dark progress::-webkit-progress-value{background-color:rgb(var(--color-surface-50))}::-moz-progress-bar{background-color:rgb(var(--color-surface-900))}.dark ::-moz-progress-bar{background-color:rgb(var(--color-surface-50))}:indeterminate::-moz-progress-bar{width:0}input[type=file]:not(.file-dropzone-input)::file-selector-button:disabled{cursor:not-allowed;opacity:.5}input[type=file]:not(.file-dropzone-input)::file-selector-button:disabled:hover{--tw-brightness: brightness(1);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}input[type=file]:not(.file-dropzone-input)::file-selector-button:disabled:active{--tw-scale-x: 1;--tw-scale-y: 1;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}input[type=file]:not(.file-dropzone-input)::file-selector-button{font-size:14px;line-height:20px;padding:6px 12px;white-space:nowrap;text-align:center;display:inline-flex;align-items:center;justify-content:center;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;border-radius:var(--theme-rounded-base);background-color:rgb(var(--color-surface-900));color:rgb(var(--color-surface-50));margin-right:8px;border-width:0px}input[type=file]:not(.file-dropzone-input)::file-selector-button>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(8px * var(--tw-space-x-reverse));margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))}input[type=file]:not(.file-dropzone-input)::file-selector-button:hover{--tw-brightness: brightness(1.15);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}input[type=file]:not(.file-dropzone-input)::file-selector-button:active{--tw-scale-x: 95%;--tw-scale-y: 95%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));--tw-brightness: brightness(.9);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.dark input[type=file]:not(.file-dropzone-input)::file-selector-button{background-color:rgb(var(--color-surface-50));color:rgb(var(--color-surface-900))}[type=range]{width:100%;accent-color:rgb(var(--color-surface-900) / 1)}:is(.dark [type=range]){accent-color:rgb(var(--color-surface-50) / 1)}[data-sort]{cursor:pointer}[data-sort]:hover:hover,.dark [data-sort]:hover:hover{background-color:rgb(var(--color-primary-500) / .1)}[data-sort]:after{margin-left:8px!important;opacity:0;--tw-content: "\u2193" !important;content:var(--tw-content)!important}[data-popup]{position:absolute;top:0;left:0;display:none;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}:host [data-theme=skeleton]{--theme-font-family-base: system-ui;--theme-font-family-heading: system-ui;--theme-font-color-base: 0 0 0;--theme-font-color-dark: 255 255 255;--theme-rounded-base: 9999px;--theme-rounded-container: 8px;--theme-border-base: 1px;--on-primary: 0 0 0;--on-secondary: 255 255 255;--on-tertiary: 0 0 0;--on-success: 0 0 0;--on-warning: 0 0 0;--on-error: 255 255 255;--on-surface: 255 255 255;--color-primary-50: 219 245 236;--color-primary-100: 207 241 230;--color-primary-200: 195 238 224;--color-primary-300: 159 227 205;--color-primary-400: 87 207 167;--color-primary-500: 15 186 129;--color-primary-600: 14 167 116;--color-primary-700: 11 140 97;--color-primary-800: 9 112 77;--color-primary-900: 7 91 63;--color-secondary-50: 229 227 251;--color-secondary-100: 220 218 250;--color-secondary-200: 211 209 249;--color-secondary-300: 185 181 245;--color-secondary-400: 132 126 237;--color-secondary-500: 79 70 229;--color-secondary-600: 71 63 206;--color-secondary-700: 59 53 172;--color-secondary-800: 47 42 137;--color-secondary-900: 39 34 112;--color-tertiary-50: 219 242 252;--color-tertiary-100: 207 237 251;--color-tertiary-200: 195 233 250;--color-tertiary-300: 159 219 246;--color-tertiary-400: 86 192 240;--color-tertiary-500: 14 165 233;--color-tertiary-600: 13 149 210;--color-tertiary-700: 11 124 175;--color-tertiary-800: 8 99 140;--color-tertiary-900: 7 81 114;--color-success-50: 237 247 220;--color-success-100: 230 245 208;--color-success-200: 224 242 197;--color-success-300: 206 235 162;--color-success-400: 169 219 92;--color-success-500: 132 204 22;--color-success-600: 119 184 20;--color-success-700: 99 153 17;--color-success-800: 79 122 13;--color-success-900: 65 100 11;--color-warning-50: 252 244 218;--color-warning-100: 251 240 206;--color-warning-200: 250 236 193;--color-warning-300: 247 225 156;--color-warning-400: 240 202 82;--color-warning-500: 234 179 8;--color-warning-600: 211 161 7;--color-warning-700: 176 134 6;--color-warning-800: 140 107 5;--color-warning-900: 115 88 4;--color-error-50: 249 221 234;--color-error-100: 246 209 228;--color-error-200: 244 198 221;--color-error-300: 238 163 200;--color-error-400: 225 94 159;--color-error-500: 212 25 118;--color-error-600: 191 23 106;--color-error-700: 159 19 89;--color-error-800: 127 15 71;--color-error-900: 104 12 58;--color-surface-50: 228 230 238;--color-surface-100: 219 222 233;--color-surface-200: 210 214 227;--color-surface-300: 182 189 210;--color-surface-400: 128 140 177;--color-surface-500: 73 90 143;--color-surface-600: 66 81 129;--color-surface-700: 55 68 107;--color-surface-800: 44 54 86;--color-surface-900: 36 44 70}[data-theme=skeleton] h1,[data-theme=skeleton] h3{font-weight:700}[data-theme=skeleton]{background-image:radial-gradient(at 0% 0%,rgba(var(--color-secondary-500) / .33) 0px,transparent 50%),radial-gradient(at 98% 1%,rgba(var(--color-error-500) / .33) 0px,transparent 50%);background-attachment:fixed;background-position:center;background-repeat:no-repeat;background-size:cover}*{scrollbar-color:initial;scrollbar-width:initial}*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.\\!container{width:100%!important}.container{width:100%}@media (min-width: 640px){.\\!container{max-width:640px!important}.container{max-width:640px}}@media (min-width: 768px){.\\!container{max-width:768px!important}.container{max-width:768px}}@media (min-width: 1024px){.\\!container{max-width:1024px!important}.container{max-width:1024px}}@media (min-width: 1280px){.\\!container{max-width:1280px!important}.container{max-width:1280px}}@media (min-width: 1536px){.\\!container{max-width:1536px!important}.container{max-width:1536px}}.hide-scrollbar::-webkit-scrollbar{display:none}.hide-scrollbar{-ms-overflow-style:none;scrollbar-width:none}.h3{font-size:20px;line-height:28px;font-family:var(--theme-font-family-heading)}.anchor{--tw-text-opacity: 1;color:rgb(var(--color-primary-700) / var(--tw-text-opacity));text-decoration-line:underline}.anchor:hover{--tw-brightness: brightness(1.1);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}:is(.dark .anchor){--tw-text-opacity: 1;color:rgb(var(--color-primary-500) / var(--tw-text-opacity))}.time{font-size:14px;line-height:20px;--tw-text-opacity: 1;color:rgb(var(--color-surface-500) / var(--tw-text-opacity))}:is(.dark .time){--tw-text-opacity: 1;color:rgb(var(--color-surface-400) / var(--tw-text-opacity))}.code{white-space:nowrap;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:12px;line-height:16px;--tw-text-opacity: 1;color:rgb(var(--color-primary-700) / var(--tw-text-opacity));background-color:rgb(var(--color-primary-500) / .3);border-radius:4px;padding:2px 4px}:is(.dark .code){--tw-text-opacity: 1;color:rgb(var(--color-primary-400) / var(--tw-text-opacity));background-color:rgb(var(--color-primary-500) / .2)}.del{position:relative;display:block;padding:2px 2px 2px 20px;text-decoration:none}.del:before{position:absolute;left:4px;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.del:before{content:"\u2212"}.del{--tw-bg-opacity: 1;background-color:rgb(var(--color-error-500) / var(--tw-bg-opacity));font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;color:rgb(var(--on-error))}.alert{display:flex;flex-direction:column;align-items:flex-start;padding:16px;color:rgb(var(--color-surface-900));border-radius:var(--theme-rounded-container)}.alert>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(16px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(16px * var(--tw-space-y-reverse))}.dark .alert{color:rgb(var(--color-surface-50))}.\\!btn:disabled{cursor:not-allowed!important;opacity:.5!important}.btn:disabled,.btn-icon:disabled,.btn-group>*:disabled{cursor:not-allowed!important;opacity:.5!important}.\\!btn:disabled:hover{--tw-brightness: brightness(1) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.btn:disabled:hover,.btn-icon:disabled:hover,.btn-group>*:disabled:hover{--tw-brightness: brightness(1);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.\\!btn:disabled:active{--tw-scale-x: 1 !important;--tw-scale-y: 1 !important;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))!important}.btn:disabled:active,.btn-icon:disabled:active,.btn-group>*:disabled:active{--tw-scale-x: 1;--tw-scale-y: 1;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.\\!btn{font-size:16px!important;line-height:24px!important;padding:9px 20px!important;white-space:nowrap!important;text-align:center!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;transition-property:all!important;transition-timing-function:cubic-bezier(.4,0,.2,1)!important;transition-duration:.15s!important;border-radius:var(--theme-rounded-base)!important}.btn{font-size:16px;line-height:24px;padding:9px 20px;white-space:nowrap;text-align:center;display:inline-flex;align-items:center;justify-content:center;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;border-radius:var(--theme-rounded-base)}.\\!btn>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0 !important;margin-right:calc(8px * var(--tw-space-x-reverse))!important;margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))!important}.btn>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(8px * var(--tw-space-x-reverse));margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))}.\\!btn:hover{--tw-brightness: brightness(1.15) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.btn:hover{--tw-brightness: brightness(1.15);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.\\!btn:active{--tw-scale-x: 95% !important;--tw-scale-y: 95% !important;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))!important;--tw-brightness: brightness(.9) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.btn:active{--tw-scale-x: 95%;--tw-scale-y: 95%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));--tw-brightness: brightness(.9);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.btn-sm{padding:6px 12px;font-size:14px;line-height:20px}.btn-icon{font-size:16px;line-height:24px;white-space:nowrap;text-align:center;display:inline-flex;align-items:center;justify-content:center;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;padding:0;aspect-ratio:1 / 1;width:43px;border-radius:9999px}.btn-icon>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(8px * var(--tw-space-x-reverse));margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))}.btn-icon:hover{--tw-brightness: brightness(1.15);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.btn-icon:active{--tw-scale-x: 95%;--tw-scale-y: 95%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));--tw-brightness: brightness(.9);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.btn-icon-sm{aspect-ratio:1 / 1;width:33px;font-size:14px;line-height:20px}.btn-group{display:inline-flex;flex-direction:row;overflow:hidden;border-radius:var(--theme-rounded-base);isolation:isolate}.btn-group>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(0px * var(--tw-space-x-reverse));margin-left:calc(0px * calc(1 - var(--tw-space-x-reverse)))}.btn-group button,.btn-group a{font-size:16px;line-height:24px;padding:9px 20px;white-space:nowrap;text-align:center;display:inline-flex;align-items:center;justify-content:center;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;color:inherit!important;text-decoration-line:none!important}.btn-group button>:not([hidden])~:not([hidden]),.btn-group a>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(8px * var(--tw-space-x-reverse));margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))}.btn-group button:hover,.btn-group a:hover{--tw-brightness: brightness(1.15);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);background-color:rgb(var(--color-surface-50) / 3%)}.btn-group button:active,.btn-group a:active{background-color:rgb(var(--color-surface-900) / 3%)}.btn-group>*+*{border-top-width:0px;border-left-width:1px;border-color:rgb(var(--color-surface-500) / .2)}.card{background-color:rgb(var(--color-surface-100));--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000);--tw-ring-inset: inset;--tw-ring-color: rgb(23 23 23 / .05);border-radius:var(--theme-rounded-container)}.dark .card{background-color:rgb(var(--color-surface-800));--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000);--tw-ring-inset: inset;--tw-ring-color: rgb(250 250 250 / .05)}a.card{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}a.card:hover{--tw-brightness: brightness(1.05);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.\\!chip{cursor:pointer!important;white-space:nowrap!important;padding:6px 12px!important;text-align:center!important;font-size:12px!important;line-height:16px!important;border-radius:4px!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;transition-property:all!important;transition-timing-function:cubic-bezier(.4,0,.2,1)!important;transition-duration:.15s!important}.chip{cursor:pointer;white-space:nowrap;padding:6px 12px;text-align:center;font-size:12px;line-height:16px;border-radius:4px;display:inline-flex;align-items:center;justify-content:center;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.\\!chip>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0 !important;margin-right:calc(8px * var(--tw-space-x-reverse))!important;margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))!important}.chip>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(8px * var(--tw-space-x-reverse));margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))}a.chip:hover,button.chip:hover{--tw-brightness: brightness(1.15);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}a.\\!chip:hover,button.\\!chip:hover{--tw-brightness: brightness(1.15) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.\\!chip:disabled{cursor:not-allowed!important;opacity:.5!important}.chip:disabled{cursor:not-allowed!important;opacity:.5!important}.\\!chip:disabled:active{--tw-scale-x: 1 !important;--tw-scale-y: 1 !important;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))!important}.chip:disabled:active{--tw-scale-x: 1;--tw-scale-y: 1;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.label>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(4px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(4px * var(--tw-space-y-reverse))}.\\!input{width:100%!important;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter!important;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter!important;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter!important;transition-timing-function:cubic-bezier(.4,0,.2,1)!important;transition-duration:.2s!important;background-color:rgb(var(--color-surface-200))!important;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;border-width:var(--theme-border-base)!important;border-color:rgb(var(--color-surface-400))!important}.input,.textarea,.select,.input-group{width:100%;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.2s;background-color:rgb(var(--color-surface-200));--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;border-width:var(--theme-border-base);border-color:rgb(var(--color-surface-400))}.dark .input,.dark .textarea,.dark .select,.dark .input-group{background-color:rgb(var(--color-surface-700));border-color:rgb(var(--color-surface-500))}.dark .\\!input{background-color:rgb(var(--color-surface-700))!important;border-color:rgb(var(--color-surface-500))!important}.\\!input:hover{--tw-brightness: brightness(1.05) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.input:hover,.textarea:hover,.select:hover,.input-group:hover{--tw-brightness: brightness(1.05);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.\\!input:focus{--tw-brightness: brightness(1.05) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.input:focus,.textarea:focus,.select:focus,.input-group:focus{--tw-brightness: brightness(1.05);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.\\!input:focus-within{--tw-border-opacity: 1 !important;border-color:rgb(var(--color-primary-500) / var(--tw-border-opacity))!important}.input:focus-within,.textarea:focus-within,.select:focus-within,.input-group:focus-within{--tw-border-opacity: 1;border-color:rgb(var(--color-primary-500) / var(--tw-border-opacity))}.\\!input{border-radius:var(--theme-rounded-base)!important}.input,.input-group{border-radius:var(--theme-rounded-base)}.textarea,.select{border-radius:var(--theme-rounded-container)}.select>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(4px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(4px * var(--tw-space-y-reverse))}.select{padding:8px 32px 8px 8px}.select[size]{background-image:none}.select optgroup>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(4px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(4px * var(--tw-space-y-reverse))}.select optgroup{font-weight:700}.select optgroup option{margin-left:0;padding-left:0}.select optgroup option:first-of-type{margin-top:12px}.select optgroup option:last-child{margin-bottom:12px!important}.select option{cursor:pointer;padding:8px 16px;background-color:rgb(var(--color-surface-200));border-radius:var(--theme-rounded-base)}.dark .select option{background-color:rgb(var(--color-surface-700))}.select option:checked{background:rgb(var(--color-primary-500)) linear-gradient(0deg,rgb(var(--color-primary-500)),rgb(var(--color-primary-500)));color:rgb(var(--on-primary))}.checkbox,.radio{height:20px;width:20px;cursor:pointer;border-radius:4px;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;background-color:rgb(var(--color-surface-200));border-width:var(--theme-border-base);border-color:rgb(var(--color-surface-400))}.dark .checkbox,.dark .radio{background-color:rgb(var(--color-surface-700));border-color:rgb(var(--color-surface-500))}.checkbox:hover,.radio:hover{--tw-brightness: brightness(1.05);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.checkbox:focus,.radio:focus{--tw-brightness: brightness(1.05);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);--tw-border-opacity: 1;border-color:rgb(var(--color-primary-500) / var(--tw-border-opacity))}.checkbox:checked,.checkbox:indeterminate,.radio:checked{--tw-bg-opacity: 1;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))}.checkbox:checked:hover,.checkbox:indeterminate:hover,.radio:checked:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))}.checkbox:checked:focus,.checkbox:indeterminate:focus,.radio:checked:focus{--tw-bg-opacity: 1;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity));--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.radio{border-radius:var(--theme-rounded-base)}.\\!input[type=file]{padding:4px!important}.input[type=file]{padding:4px}.\\!input[type=color]{height:40px!important;width:40px!important;cursor:pointer!important;overflow:hidden!important;border-style:none!important;border-radius:var(--theme-rounded-base)!important;-webkit-appearance:none!important}.input[type=color]{height:40px;width:40px;cursor:pointer;overflow:hidden;border-style:none;border-radius:var(--theme-rounded-base);-webkit-appearance:none}.\\!input[type=color]::-webkit-color-swatch-wrapper{padding:0!important}.input[type=color]::-webkit-color-swatch-wrapper{padding:0}.\\!input[type=color]::-webkit-color-swatch{border-style:none!important}.input[type=color]::-webkit-color-swatch{border-style:none}.\\!input[type=color]::-webkit-color-swatch:hover{--tw-brightness: brightness(1.1) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.input[type=color]::-webkit-color-swatch:hover{--tw-brightness: brightness(1.1);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.\\!input[type=color]::-moz-color-swatch{border-style:none!important}.input[type=color]::-moz-color-swatch{border-style:none}.\\!input:disabled{cursor:not-allowed!important;opacity:.5!important}.input:disabled,.textarea:disabled,.select:disabled,.input-group>input:disabled,.input-group>textarea:disabled,.input-group>select:disabled{cursor:not-allowed!important;opacity:.5!important}.\\!input:disabled:hover{--tw-brightness: brightness(1) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.input:disabled:hover,.textarea:disabled:hover,.select:disabled:hover,.input-group>input:disabled:hover,.input-group>textarea:disabled:hover,.input-group>select:disabled:hover{--tw-brightness: brightness(1) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.\\!input[readonly],.input[readonly],.textarea[readonly],.select[readonly]{cursor:not-allowed!important;border-color:transparent!important}.\\!input[readonly]:hover,.input[readonly]:hover,.textarea[readonly]:hover,.select[readonly]:hover{--tw-brightness: brightness(1) !important;filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)!important}.input-group{display:grid;overflow:hidden}.input-group input,.input-group select{border-width:0px;background-color:transparent;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important}.input-group select option{background-color:rgb(var(--color-surface-200))}.dark .input-group select option{background-color:rgb(var(--color-surface-700))}.input-group div,.input-group a,.input-group button{display:flex;align-items:center;justify-content:space-between;padding-left:16px;padding-right:16px}.input-group-divider input,.input-group-divider select,.input-group-divider div,.input-group-divider a{border-left-width:1px;border-color:rgb(var(--color-surface-400));--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;min-width:-moz-fit-content!important;min-width:fit-content!important}.dark .input-group-divider input,.dark .input-group-divider select,.dark .input-group-divider div,.dark .input-group-divider a{border-color:rgb(var(--color-surface-500))}.input-group-divider input:focus,.input-group-divider select:focus,.input-group-divider div:focus,.input-group-divider a:focus{border-color:rgb(var(--color-surface-400))}.dark .input-group-divider input:focus,.dark .input-group-divider select:focus,.dark .input-group-divider div:focus,.dark .input-group-divider a:focus{border-color:rgb(var(--color-surface-500))}.input-group-divider *:first-child{border-left-width:0px!important}.input-group-shim{background-color:rgb(var(--color-surface-400) / .1);color:rgb(var(--color-surface-600))}.dark .input-group-shim{color:rgb(var(--color-surface-300))}.input-error{--tw-border-opacity: 1;border-color:rgb(var(--color-error-500) / var(--tw-border-opacity));--tw-bg-opacity: 1;background-color:rgb(var(--color-error-200) / var(--tw-bg-opacity));--tw-text-opacity: 1;color:rgb(var(--color-error-500) / var(--tw-text-opacity))}:is(.dark .input-error){--tw-border-opacity: 1;border-color:rgb(var(--color-error-500) / var(--tw-border-opacity));--tw-bg-opacity: 1;background-color:rgb(var(--color-error-200) / var(--tw-bg-opacity));--tw-text-opacity: 1;color:rgb(var(--color-error-500) / var(--tw-text-opacity))}.input-error::-moz-placeholder{--tw-text-opacity: 1;color:rgb(var(--color-error-500) / var(--tw-text-opacity))}.input-error::placeholder{--tw-text-opacity: 1;color:rgb(var(--color-error-500) / var(--tw-text-opacity))}.list{list-style-type:none}.list>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(4px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(4px * var(--tw-space-y-reverse))}.list li{display:flex;align-items:center;border-radius:var(--theme-rounded-base)}.list li>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(16px * var(--tw-space-x-reverse));margin-left:calc(16px * calc(1 - var(--tw-space-x-reverse)))}.placeholder{height:20px;background-color:rgb(var(--color-surface-300));border-radius:var(--theme-rounded-base)}.dark .placeholder{background-color:rgb(var(--color-surface-600))}.w-modal{width:100%;max-width:640px}.modal *:focus:not([tabindex="-1"]):not(.input):not(.textarea):not(.select):not(.input-group):not(.input-group input){outline-style:auto;outline-color:-webkit-focus-ring-color}.variant-filled{background-color:rgb(var(--color-surface-900));color:rgb(var(--color-surface-50))}.dark .variant-filled{background-color:rgb(var(--color-surface-50));color:rgb(var(--color-surface-900))}.\\!variant-filled-primary{--tw-bg-opacity: 1 !important;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))!important;color:rgb(var(--on-primary))!important}.variant-filled-primary{--tw-bg-opacity: 1;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity));color:rgb(var(--on-primary))}:is(.dark .variant-filled-primary){--tw-bg-opacity: 1;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity));color:rgb(var(--on-primary))}:is(.dark .\\!variant-filled-primary){--tw-bg-opacity: 1 !important;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))!important;color:rgb(var(--on-primary))!important}.variant-ghost-surface{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000);--tw-ring-inset: inset;--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-surface-500) / var(--tw-ring-opacity));background-color:rgb(var(--color-surface-500) / .2)}:is(.dark .variant-ghost-surface){--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-surface-500) / var(--tw-ring-opacity));background-color:rgb(var(--color-surface-500) / .2)}.variant-soft,.variant-soft-surface{background-color:rgb(var(--color-surface-400) / .2);--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;color:rgb(var(--color-surface-700))}.dark .variant-soft,.dark .variant-soft-surface{color:rgb(var(--color-surface-200))}:is(.dark .variant-soft),:is(.dark .variant-soft-surface){background-color:rgb(var(--color-surface-500) / .2)}@media (min-width: 768px){.h3{font-size:24px;line-height:32px}}@media (min-width: 1024px){.alert{flex-direction:row;align-items:center}.alert>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(0px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(0px * var(--tw-space-y-reverse));--tw-space-x-reverse: 0;margin-right:calc(16px * var(--tw-space-x-reverse));margin-left:calc(16px * calc(1 - var(--tw-space-x-reverse)))}}.modal *:focus:not([tabindex="-1"]):not(.input):not(.textarea):not(.select):not(.input-group):not(.input-group input){outline-width:0px!important}.visible{visibility:visible}.static{position:static}.fixed{position:fixed}.\\!absolute{position:absolute!important}.absolute{position:absolute}.relative{position:relative}.bottom-0{bottom:0}.bottom-24{bottom:96px}.left-0{left:0}.left-1\\/2{left:50%}.right-0{right:0}.right-2{right:8px}.right-20{right:80px}.right-4{right:16px}.top-0{top:0}.top-1\\/2{top:50%}.top-2{top:8px}.top-36{top:144px}.-z-10{z-index:-10}.z-\\[999\\]{z-index:999}.row-span-2{grid-row:span 2 / span 2}.row-start-1{grid-row-start:1}.\\!m-0{margin:0!important}.m-auto{margin:auto}.mx-2{margin-left:8px;margin-right:8px}.my-4{margin-top:16px;margin-bottom:16px}.my-\\[1px\\]{margin-top:1px;margin-bottom:1px}.ml-1{margin-left:4px}.ml-3{margin-left:12px}.ml-4{margin-left:16px}.mr-2{margin-right:8px}.mr-6{margin-right:24px}.mt-2{margin-top:8px}.mt-4{margin-top:16px}.block{display:block}.inline-block{display:inline-block}.flex{display:flex}.inline-flex{display:inline-flex}.grid{display:grid}.contents{display:contents}.hidden{display:none}.size-14{width:56px;height:56px}.size-full{width:100%;height:100%}.h-0{height:0px}.h-10{height:40px}.h-2{height:8px}.h-4{height:16px}.h-48{height:192px}.h-6{height:24px}.h-8{height:32px}.h-\\[38px\\]{height:38px}.h-auto{height:auto}.h-fit{height:-moz-fit-content;height:fit-content}.h-full{height:100%}.h-screen{height:100vh}.max-h-\\[200px\\]{max-height:200px}.min-h-0{min-height:0px}.min-h-full{min-height:100%}.w-0{width:0px}.w-12{width:48px}.w-16{width:64px}.w-20{width:80px}.w-32{width:128px}.w-36{width:144px}.w-48{width:192px}.w-5{width:20px}.w-6{width:24px}.w-8{width:32px}.w-\\[140px\\]{width:140px}.w-\\[38px\\]{width:38px}.w-\\[50\\%\\]{width:50%}.w-\\[600px\\]{width:600px}.w-full{width:100%}.w-screen{width:100vw}.max-w-full{max-width:100%}.flex-1{flex:1 1 0%}.flex-auto{flex:1 1 auto}.flex-none{flex:none}.shrink-0{flex-shrink:0}.flex-grow{flex-grow:1}.basis-0{flex-basis:0px}.origin-\\[50\\%_50\\%\\]{transform-origin:50% 50%}.-translate-x-1\\/2{--tw-translate-x: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-translate-x-full{--tw-translate-x: -100%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-translate-y-1\\/2{--tw-translate-y: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-0{--tw-translate-x: 0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-\\[calc\\(100\\%-44px\\)\\]{--tw-translate-x: calc(100% - 44px) ;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-full{--tw-translate-x: 100%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rotate-90{--tw-rotate: -90deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.scale-\\[0\\.8\\]{--tw-scale-x: .8;--tw-scale-y: .8;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.\\!transform-none{transform:none!important}@keyframes spin{to{transform:rotate(360deg)}}.animate-spin{animation:spin 1s linear infinite}.\\!cursor-default{cursor:default!important}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.list-inside{list-style-position:inside}.list-disc{list-style-type:disc}.grid-cols-\\[0px_1fr\\]{grid-template-columns:0px 1fr}.grid-cols-\\[140px_1fr\\]{grid-template-columns:140px 1fr}.grid-cols-\\[auto_1fr_auto\\]{grid-template-columns:auto 1fr auto}.grid-cols-\\[auto_1fr_auto_auto\\]{grid-template-columns:auto 1fr auto auto}.grid-rows-\\[0fr\\]{grid-template-rows:0fr}.grid-rows-\\[1fr\\]{grid-template-rows:1fr}.grid-rows-\\[auto_1fr\\]{grid-template-rows:auto 1fr}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.\\!items-start{align-items:flex-start!important}.items-center{align-items:center}.\\!items-stretch{align-items:stretch!important}.justify-start{justify-content:flex-start}.justify-end{justify-content:flex-end}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.justify-evenly{justify-content:space-evenly}.gap-1{gap:4px}.gap-14{gap:56px}.gap-2{gap:8px}.gap-3{gap:12px}.gap-4{gap:16px}.gap-6{gap:24px}.space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(8px * var(--tw-space-x-reverse));margin-left:calc(8px * calc(1 - var(--tw-space-x-reverse)))}.space-x-4>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(16px * var(--tw-space-x-reverse));margin-left:calc(16px * calc(1 - var(--tw-space-x-reverse)))}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(4px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(4px * var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(8px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(8px * var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(16px * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(16px * var(--tw-space-y-reverse))}.divide-y-\\[1px\\]>:not([hidden])~:not([hidden]){--tw-divide-y-reverse: 0;border-top-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px * var(--tw-divide-y-reverse))}.self-start{align-self:flex-start}.self-stretch{align-self:stretch}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.overflow-y-hidden{overflow-y:hidden}.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.break-words{overflow-wrap:break-word}.rounded{border-radius:4px}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:8px}.rounded-md{border-radius:6px}.rounded-none{border-radius:0}.rounded-e-\\[4px\\]{border-start-end-radius:4px;border-end-end-radius:4px}.rounded-s-full{border-start-start-radius:9999px;border-end-start-radius:9999px}.border{border-width:1px}.border-0{border-width:0px}.\\!border-t-0{border-top-width:0px!important}.border-b{border-bottom-width:1px}.border-b-2{border-bottom-width:2px}.border-l{border-left-width:1px}.\\!border-surface-700{--tw-border-opacity: 1 !important;border-color:rgb(var(--color-surface-700) / var(--tw-border-opacity))!important}.border-surface-400\\/20{border-color:rgb(var(--color-surface-400) / .2)}.bg-primary-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))}.bg-primary-500\\/30{background-color:rgb(var(--color-primary-500) / .3)}.bg-surface-400{--tw-bg-opacity: 1;background-color:rgb(var(--color-surface-400) / var(--tw-bg-opacity))}.bg-surface-400\\/20{background-color:rgb(var(--color-surface-400) / .2)}.bg-surface-900{--tw-bg-opacity: 1;background-color:rgb(var(--color-surface-900) / var(--tw-bg-opacity))}.bg-transparent{background-color:transparent}.bg-white{--tw-bg-opacity: 1;background-color:rgb(255 255 255 / var(--tw-bg-opacity))}.bg-white\\/30{background-color:#ffffff4d}.bg-white\\/75{background-color:#ffffffbf}.bg-scroll{background-attachment:scroll}.fill-current{fill:currentColor}.fill-primary-500{fill:rgb(var(--color-primary-500) / 1)}.fill-slate-700{fill:#334155}.fill-transparent{fill:transparent}.stroke-primary-500{stroke:rgb(var(--color-primary-500) / 1)}.stroke-primary-500\\/30{stroke:rgb(var(--color-primary-500) / .3)}.stroke-surface-500\\/30{stroke:rgb(var(--color-surface-500) / .3)}.stroke-surface-900{stroke:rgb(var(--color-surface-900) / 1)}.object-cover{-o-object-fit:cover;object-fit:cover}.object-center{-o-object-position:center;object-position:center}.\\!p-0{padding:0!important}.p-0{padding:0}.p-1{padding:4px}.p-2{padding:8px}.p-4{padding:16px}.\\!px-1{padding-left:4px!important;padding-right:4px!important}.\\!py-2{padding-top:8px!important;padding-bottom:8px!important}.\\!py-\\[7px\\]{padding-top:7px!important;padding-bottom:7px!important}.px-3{padding-left:12px;padding-right:12px}.px-4{padding-left:16px;padding-right:16px}.px-8{padding-left:32px;padding-right:32px}.py-1{padding-top:4px;padding-bottom:4px}.py-2{padding-top:8px;padding-bottom:8px}.py-6{padding-top:24px;padding-bottom:24px}.pb-6{padding-bottom:24px}.pl-6{padding-left:24px}.pr-0{padding-right:0}.pr-2{padding-right:8px}.pr-4{padding-right:16px}.pr-6{padding-right:24px}.pt-4{padding-top:16px}.text-center{text-align:center}.text-2xl{font-size:24px;line-height:32px}.text-\\[12px\\]{font-size:12px}.text-base{font-size:16px;line-height:24px}.text-sm{font-size:14px;line-height:20px}.text-xs{font-size:12px;line-height:16px}.font-bold{font-weight:700}.italic{font-style:italic}.leading-\\[14px\\]{line-height:14px}.leading-loose{line-height:2}.\\!text-error-500{--tw-text-opacity: 1 !important;color:rgb(var(--color-error-500) / var(--tw-text-opacity))!important}.text-error-500{--tw-text-opacity: 1;color:rgb(var(--color-error-500) / var(--tw-text-opacity))}.text-surface-400{--tw-text-opacity: 1;color:rgb(var(--color-surface-400) / var(--tw-text-opacity))}.underline-offset-2{text-underline-offset:2px}.accent-surface-900{accent-color:rgb(var(--color-surface-900) / 1)}.opacity-40{opacity:.4}.opacity-50{opacity:.5}.opacity-70{opacity:.7}.mix-blend-hard-light{mix-blend-mode:hard-light}.shadow{--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-xl{--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.-outline-offset-\\[3px\\]{outline-offset:-3px}.\\!ring-0{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important}.blur{--tw-blur: blur(8px);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.blur-\\[1px\\]{--tw-blur: blur(1px);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.drop-shadow-xl{--tw-drop-shadow: drop-shadow(0 20px 13px rgb(0 0 0 / .03)) drop-shadow(0 8px 5px rgb(0 0 0 / .08));filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.backdrop-blur-sm{--tw-backdrop-blur: blur(4px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\\[grid-template-columns\\]{transition-property:grid-template-columns;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\\[grid-template-rows\\]{transition-property:grid-template-rows;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\\[stroke-dashoffset\\]{transition-property:stroke-dashoffset;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\\[transform\\]{transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\\[width\\]{transition-property:width;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-opacity{transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.delay-100{transition-delay:.1s}.duration-100{transition-duration:.1s}.duration-\\[200ms\\]{transition-duration:.2s}.duration-\\[250ms\\]{transition-duration:.25s}.duration-\\[400ms\\]{transition-duration:.4s}.bg-surface-backdrop-token{background-color:rgb(var(--color-surface-400) / .7)}.dark .bg-surface-backdrop-token{background-color:rgb(var(--color-surface-900) / .7)}.bg-surface-100-800-token{background-color:rgb(var(--color-surface-100))}.dark .bg-surface-100-800-token{background-color:rgb(var(--color-surface-800))}.bg-surface-200-700-token{background-color:rgb(var(--color-surface-200))}.dark .bg-surface-200-700-token{background-color:rgb(var(--color-surface-700))}.bg-surface-900-50-token{background-color:rgb(var(--color-surface-900))}.dark .bg-surface-900-50-token{background-color:rgb(var(--color-surface-50))}.border-token{border-width:var(--theme-border-base)}.border-surface-400-500-token{border-color:rgb(var(--color-surface-400))}.dark .border-surface-400-500-token{border-color:rgb(var(--color-surface-500))}.border-surface-900-50-token{border-color:rgb(var(--color-surface-900))}.dark .border-surface-900-50-token{border-color:rgb(var(--color-surface-50))}.border-surface-800-100-token{border-color:rgb(var(--color-surface-800))}.dark .border-surface-800-100-token{border-color:rgb(var(--color-surface-100))}.rounded-token{border-radius:var(--theme-rounded-base)}.rounded-container-token{border-radius:var(--theme-rounded-container)}.rounded-tl-container-token{border-top-left-radius:var(--theme-rounded-container)}.rounded-tr-container-token{border-top-right-radius:var(--theme-rounded-container)}.fill-token{fill:rgba(var(--theme-font-color-base))}.dark .fill-token{fill:rgba(var(--theme-font-color-dark))}.text-surface-700-200-token{color:rgb(var(--color-surface-700))}.dark .text-surface-700-200-token{color:rgb(var(--color-surface-200))}.scrollbar-thin::-webkit-scrollbar-track{background-color:var(--scrollbar-track);border-radius:var(--scrollbar-track-radius)}.scrollbar-thin::-webkit-scrollbar-track:hover{background-color:var(--scrollbar-track-hover, var(--scrollbar-track))}.scrollbar-thin::-webkit-scrollbar-track:active{background-color:var(--scrollbar-track-active, var(--scrollbar-track-hover, var(--scrollbar-track)))}.scrollbar-thin::-webkit-scrollbar-thumb{background-color:var(--scrollbar-thumb);border-radius:var(--scrollbar-thumb-radius)}.scrollbar-thin::-webkit-scrollbar-thumb:hover{background-color:var(--scrollbar-thumb-hover, var(--scrollbar-thumb))}.scrollbar-thin::-webkit-scrollbar-thumb:active{background-color:var(--scrollbar-thumb-active, var(--scrollbar-thumb-hover, var(--scrollbar-thumb)))}.scrollbar-thin::-webkit-scrollbar-corner{background-color:var(--scrollbar-corner);border-radius:var(--scrollbar-corner-radius)}.scrollbar-thin::-webkit-scrollbar-corner:hover{background-color:var(--scrollbar-corner-hover, var(--scrollbar-corner))}.scrollbar-thin::-webkit-scrollbar-corner:active{background-color:var(--scrollbar-corner-active, var(--scrollbar-corner-hover, var(--scrollbar-corner)))}.scrollbar-thin{scrollbar-width:thin;scrollbar-color:var(--scrollbar-thumb, initial) var(--scrollbar-track, initial)}.scrollbar-thin::-webkit-scrollbar{display:block;width:8px;height:8px}.scrollbar-track-transparent{--scrollbar-track: transparent !important}.scrollbar-thumb-slate-400\\/50{--scrollbar-thumb: rgb(148 163 184 / .5) !important}.scrollbar-corner-transparent{--scrollbar-corner: transparent !important}.has-\\[\\:checked\\]\\:\\!variant-filled-primary:has(:checked){--tw-bg-opacity: 1 !important;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))!important;color:rgb(var(--on-primary))!important}:is(.dark .has-\\[\\:checked\\]\\:\\!variant-filled-primary:has(:checked)){--tw-bg-opacity: 1 !important;background-color:rgb(var(--color-primary-500) / var(--tw-bg-opacity))!important;color:rgb(var(--on-primary))!important}.hover\\:variant-filled:hover{background-color:rgb(var(--color-surface-900));color:rgb(var(--color-surface-50))}.dark .hover\\:variant-filled:hover{background-color:rgb(var(--color-surface-50));color:rgb(var(--color-surface-900))}.hover\\:variant-soft:hover,.hover\\:variant-soft-surface:hover{background-color:rgb(var(--color-surface-400) / .2);--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;color:rgb(var(--color-surface-700))}.dark .hover\\:variant-soft:hover,.dark .hover\\:variant-soft-surface:hover{color:rgb(var(--color-surface-200))}:is(.dark .hover\\:variant-soft:hover){background-color:rgb(var(--color-surface-500) / .2)}:is(.dark .hover\\:variant-soft-surface:hover){background-color:rgb(var(--color-surface-500) / .2)}.\\[\\&\\:not\\(\\[disabled\\]\\)\\]\\:variant-soft-primary:not([disabled]){background-color:rgb(var(--color-primary-400) / .2);--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color) !important;--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color) !important;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)!important;color:rgb(var(--color-primary-700))}.dark .\\[\\&\\:not\\(\\[disabled\\]\\)\\]\\:variant-soft-primary:not([disabled]){color:rgb(var(--color-primary-200))}:is(.dark .\\[\\&\\:not\\(\\[disabled\\]\\)\\]\\:variant-soft-primary:not([disabled])){background-color:rgb(var(--color-primary-500) / .2)}.\\*\\:\\!m-0>*{margin:0!important}.\\*\\:items-center>*{align-items:center}.\\*\\:\\!rounded-none>*{border-radius:0!important}.\\*\\:py-4>*{padding-top:16px;padding-bottom:16px}.\\*\\:text-sm>*{font-size:14px;line-height:20px}.\\*\\:border-surface-300-600-token>*{border-color:rgb(var(--color-surface-300))}.dark .\\*\\:border-surface-300-600-token>*{border-color:rgb(var(--color-surface-600))}.hover\\:translate-x-0:hover{--tw-translate-x: 0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.hover\\:text-xl:hover{font-size:20px;line-height:28px}.hover\\:opacity-100:hover{opacity:1}.hover\\:brightness-110:hover{--tw-brightness: brightness(1.1);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.hover\\:brightness-\\[105\\%\\]:hover{--tw-brightness: brightness(105%);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.focus\\:decoration-wavy:focus{text-decoration-style:wavy}.focus\\:\\!outline-none:focus{outline:2px solid transparent!important;outline-offset:2px!important}.disabled\\:cursor-wait:disabled{cursor:wait}.disabled\\:opacity-70:disabled{opacity:.7}.dark\\:\\!border-surface-200:is(.dark *){--tw-border-opacity: 1 !important;border-color:rgb(var(--color-surface-200) / var(--tw-border-opacity))!important}.dark\\:border-surface-500\\/20:is(.dark *){border-color:rgb(var(--color-surface-500) / .2)}.dark\\:bg-black\\/15:is(.dark *){background-color:#00000026}.dark\\:bg-surface-300:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(var(--color-surface-300) / var(--tw-bg-opacity))}.dark\\:bg-surface-500\\/20:is(.dark *){background-color:rgb(var(--color-surface-500) / .2)}.dark\\:bg-surface-700:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(var(--color-surface-700) / var(--tw-bg-opacity))}.dark\\:fill-slate-200:is(.dark *){fill:#e2e8f0}.dark\\:stroke-surface-50:is(.dark *){stroke:rgb(var(--color-surface-50) / 1)}.dark\\:accent-surface-50:is(.dark *){accent-color:rgb(var(--color-surface-50) / 1)}.dark\\:hover\\:brightness-110:hover:is(.dark *){--tw-brightness: brightness(1.1);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}@media (min-width: 768px){.md\\:h-\\[600px\\]{height:600px}.md\\:max-w-screen-md{max-width:768px}.md\\:max-w-screen-sm{max-width:640px}.md\\:flex-row{flex-direction:row}.md\\:\\!items-baseline{align-items:baseline!important}}@media (min-width: 1024px){.lg\\:max-w-screen-md{max-width:768px}}@media (min-width: 1280px){.xl\\:max-w-screen-lg{max-width:1024px}}.\\[\\&\\:last-child\\]\\:\\*\\:pt-4>*:last-child{padding-top:16px}.\\[\\&\\:not\\(\\:last-child\\)\\]\\:\\*\\:py-4>*:not(:last-child){padding-top:16px;padding-bottom:16px}.\\[\\&\\:not\\(\\[disabled\\]\\)\\]\\:hover\\:bg-slate-400\\/30:hover:not([disabled]){background-color:#94a3b84d}.\\[\\&\\>input\\]\\:\\!min-w-0>input{min-width:0px!important}.\\[\\&\\>input\\]\\:\\!border-transparent>input{border-color:transparent!important} `);

(function (Dexie, dayjs, JSZip, GIF) {
  'use strict';

  var __defProp = Object.defineProperty;
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  var _GM_download = /* @__PURE__ */ (() => typeof GM_download != "undefined" ? GM_download : void 0)();
  var _GM_info = /* @__PURE__ */ (() => typeof GM_info != "undefined" ? GM_info : void 0)();
  var _GM_registerMenuCommand = /* @__PURE__ */ (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)();
  var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)();
  var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  function getLogger() {
    const methods = ["info", "warn", "error"];
    const style = ["color: green;", "color: orange;", "color: red;"];
    const logLevel = 2;
    const namePrefix = "[Pixiv Downlaoder] ";
    function log(level, args) {
      if (logLevel <= level) console[methods[level]]("%c[Pixiv Downloader]", style[level], ...args);
    }
    return {
      info(...args) {
        log(0, args);
      },
      warn(...args) {
        log(1, args);
      },
      error(...args) {
        log(2, args);
      },
      time(label) {
        console.time(namePrefix + label);
      },
      timeLog(label) {
        console.timeLog(namePrefix + label);
      },
      timeEnd(label) {
        console.timeEnd(namePrefix + label);
      },
      throw(msg, Err) {
        if (Err) {
          throw new Err(`${namePrefix}${msg}`);
        } else {
          throw new Error(`${namePrefix}${msg}`);
        }
      }
    };
  }
  const logger = getLogger();
  function sleep(delay) {
    return new Promise((resolve) => {
      setTimeout(resolve, delay);
    });
  }
  function replaceInvalidChar(str) {
    if (typeof str !== "string") throw new TypeError("expect string but got " + typeof str);
    if (!str) return "";
    return str.replace(new RegExp("\\p{C}", "gu"), "").replace(/\\/g, "\").replace(/\//g, "/").replace(/:/g, ":").replace(/\*/g, "*").replace(/\?/g, "?").replace(/\|/g, "|").replace(/"/g, """).replace(/</g, "﹤").replace(/>/g, "﹥").replace(/~/g, "~").trim().replace(/^\.|\.$/g, ".");
  }
  function unescapeHtml(str) {
    if (typeof str !== "string") throw new TypeError("expect string but got " + typeof str);
    if (!str) return "";
    const el = document.createElement("p");
    el.innerHTML = str;
    return el.innerText;
  }
  function generateCsv(sheetData) {
    const sheetStr = sheetData.map((row) => {
      return row.map((cell) => {
        return '"' + cell.replace(/"/g, '""') + '"';
      }).join(",");
    }).join("\r\n");
    return new Blob(["\uFEFF" + sheetStr], { type: "text/csv" });
  }
  function evalScript(script) {
    const el = document.createElement("script");
    el.text = script;
    document.head.appendChild(el).parentNode.removeChild(el);
  }
  function readBlobAsDataUrl(blob) {
    return new Promise((resolve) => {
      const reader = new FileReader();
      reader.onload = () => {
        resolve(reader.result);
      };
      reader.readAsDataURL(blob);
    });
  }
  async function addStyleToShadow(shadowRoot) {
    {
      shadowRoot.adoptedStyleSheets = [window._pdlShadowStyle];
    }
  }
  function getElementText(el) {
    el.normalize();
    if (el.childNodes.length === 0) return "";
    const blockNode = [
      "ADDRESS",
      "ARTICLE",
      "ASIDE",
      "BLOCKQUOTE",
      "DD",
      "DIV",
      "DL",
      "DT",
      "FIELDSET",
      "FIGCAPTION",
      "FIGURE",
      "FOOTER",
      "FORM",
      "H1",
      "H2",
      "H3",
      "H4",
      "H5",
      "H6",
      "HEADER",
      "HR",
      "LI",
      "MAIN",
      "NAV",
      "OL",
      "P",
      "PRE",
      "SECTION",
      "TABLE",
      "UL"
    ];
    let str = "";
    for (let i = 0; i < el.childNodes.length; i++) {
      const node = el.childNodes[i];
      if (node.nodeType === Node.TEXT_NODE) {
        const val = node.nodeValue;
        (val == null ? void 0 : val.trim()) && (str += val);
      } else if (node.nodeType === Node.ELEMENT_NODE) {
        if (node.nodeName === "BR") {
          str += "\n";
          continue;
        }
        if (!blockNode.includes(node.nodeName)) {
          const childText = getElementText(node);
          childText && (str += childText);
        } else {
          const childText = getElementText(node);
          if (childText) {
            str ? str += "\n" + childText : str += childText;
          }
        }
      }
    }
    return str;
  }
  function aDownload$1(blob, filename) {
    const el = document.createElement("a");
    el.href = URL.createObjectURL(blob);
    el.download = filename;
    el.click();
    URL.revokeObjectURL(el.href);
  }
  class RequestError extends Error {
    constructor(url2, status) {
      super(status + " " + url2);
      __publicField(this, "url");
      __publicField(this, "status");
      this.name = "RequestError";
      this.url = url2;
      this.status = status;
    }
  }
  class CancelError extends Error {
    constructor() {
      super("User aborted.");
      this.name = "CancelError";
    }
  }
  class JsonDataError extends Error {
    constructor(msg) {
      super(msg);
      this.name = "JsonDataError";
    }
  }
  const env = {
    isFirefox() {
      return navigator.userAgent.includes("Firefox");
    },
    isViolentmonkey() {
      return _GM_info.scriptHandler === "Violentmonkey";
    },
    isTampermonkey() {
      return _GM_info.scriptHandler === "Tampermonkey";
    },
    isBlobDlAvaliable() {
      return !this.isFirefox() || this.isFirefox() && this.isTampermonkey() && parseFloat(_GM_info.version ?? "") < 4.18;
    },
    // firefox使用tampermonkey,downloadmod为默认时也支持子目录,但GM_info显示为原生的“native”,而“原生”不支持子目录
    isSupportSubpath() {
      return this.isBrowserDownloadMode();
    },
    isBrowserDownloadMode() {
      return _GM_info.downloadMode === "browser";
    },
    isConflictActionEnable() {
      return this.isTampermonkey() && parseFloat(_GM_info.version ?? "") >= 4.18 && this.isBrowserDownloadMode();
    },
    isConflictActionPromptEnable() {
      return !this.isFirefox() && this.isConflictActionEnable();
    },
    isFileSystemAccessAvaliable() {
      return typeof _unsafeWindow.showDirectoryPicker === "function" && typeof _unsafeWindow.showSaveFilePicker === "function";
    },
    videoFrameSupported() {
      return typeof _unsafeWindow.VideoFrame === "function";
    },
    isPixiv() {
      return location.hostname === "www.pixiv.net";
    },
    isYande() {
      return location.hostname === "yande.re";
    },
    isRule34() {
      return location.hostname === "rule34.xxx";
    }
  };
  class FileSystemAccessHandler {
    constructor(channelName) {
      __publicField(this, "filenameConflictAction", "uniquify");
      __publicField(this, "updateDirHandleChannel");
      __publicField(this, "dirHandle");
      __publicField(this, "dirHandleStatus", 0);
      __publicField(this, "cachedTasks", []);
      __publicField(this, "duplicateFilenameCached", {});
      this.updateDirHandleChannel = new BroadcastChannel(channelName);
      this.updateDirHandleChannel.onmessage = (evt) => {
        const data = evt.data;
        switch (data.kind) {
          case 1:
            this.dirHandleStatus = 1;
            logger.info("正在选择目录");
            break;
          case 0:
            logger.warn("取消更新dirHandle");
            if (this.dirHandle) {
              this.dirHandleStatus = 2;
              this.processCachedTasks();
            } else {
              this.dirHandleStatus = 0;
              this.rejectCachedTasks();
            }
            break;
          case 2:
            this.dirHandleStatus = 2;
            this.dirHandle = data.handle;
            logger.info("更新dirHandle", this.dirHandle);
            this.processCachedTasks();
            break;
          case "request":
            if (this.dirHandle) {
              this.updateDirHandleChannel.postMessage({
                kind: "response",
                handle: this.dirHandle
              });
              logger.info("响应请求dirHandle");
            }
            break;
          case "response":
            if (!this.dirHandle) {
              if (this.dirHandleStatus === 0)
                this.dirHandleStatus = 2;
              this.dirHandle = data.handle;
              logger.info("首次获取dirHandle", this.dirHandle);
            }
            break;
          default:
            throw new Error("Invalid data kind.");
        }
      };
      this.updateDirHandleChannel.postMessage({ kind: "request" });
    }
    async getDirHandleRecursive(dirs) {
      if (!this.dirHandle) throw new Error("未选择保存文件夹");
      let handler = this.dirHandle;
      if (typeof dirs === "string") {
        if (dirs.indexOf("/") === -1) return await handler.getDirectoryHandle(dirs, { create: true });
        dirs = dirs.split("/").filter((dir) => !!dir);
      }
      for await (const dir of dirs) {
        handler = await handler.getDirectoryHandle(dir, { create: true });
      }
      return handler;
    }
    processCachedTasks() {
      const { length } = this.cachedTasks;
      for (let i = 0; i < length; i++) {
        const [blob, downloadMeta, onSaveFullfilled, onSaveRejected] = this.cachedTasks[i];
        this.saveFile(blob, downloadMeta).then(onSaveFullfilled, onSaveRejected);
      }
      logger.info(`执行${length}个缓存任务`);
      if (this.cachedTasks.length > length) {
        this.cachedTasks = this.cachedTasks.slice(length);
      } else {
        this.cachedTasks.length = 0;
      }
    }
    rejectCachedTasks() {
      this.cachedTasks.forEach(([, , , onSaveRejected]) => onSaveRejected(new CancelError()));
      this.cachedTasks.length = 0;
      logger.info(`取消${this.cachedTasks.length}个缓存任务`);
    }
    async getFilenameHandle(dirHandle, filename) {
      if (this.filenameConflictAction === "overwrite")
        return await dirHandle.getFileHandle(filename, { create: true });
      if (!(filename in this.duplicateFilenameCached)) {
        this.duplicateFilenameCached[filename] = [];
        try {
          await dirHandle.getFileHandle(filename);
          logger.warn("存在同名文件", filename);
        } catch (error) {
          return await dirHandle.getFileHandle(filename, { create: true });
        }
      }
      const extIndex = filename.lastIndexOf(".");
      const ext = filename.slice(extIndex + 1);
      const name = filename.slice(0, extIndex);
      if (this.filenameConflictAction === "prompt") {
        return await _unsafeWindow.showSaveFilePicker({
          suggestedName: filename,
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          //@ts-ignore
          types: [{ description: "Image file", accept: { ["image/" + ext]: ["." + ext] } }]
        });
      } else {
        for (let suffix = 1; suffix < 1e3; suffix++) {
          const newName = `${name} (${suffix}).${ext}`;
          try {
            await dirHandle.getFileHandle(newName);
          } catch (error) {
            if (this.duplicateFilenameCached[filename].includes(newName)) {
              continue;
            } else {
              this.duplicateFilenameCached[filename].push(newName);
            }
            logger.info("使用文件名:", newName);
            return await dirHandle.getFileHandle(newName, { create: true });
          }
        }
        throw new RangeError("Oops, you have too many duplicate files.");
      }
    }
    clearFilenameCached(duplicateName, actualName) {
      if (!(duplicateName in this.duplicateFilenameCached)) return;
      const usedNameArr = this.duplicateFilenameCached[duplicateName];
      logger.info("清理重名文件名", usedNameArr, actualName);
      if (usedNameArr.length === 0) {
        delete this.duplicateFilenameCached[duplicateName];
        return;
      }
      const index = usedNameArr.indexOf(actualName);
      if (index === -1) return;
      usedNameArr.splice(index, 1);
      if (usedNameArr.length === 0) delete this.duplicateFilenameCached[duplicateName];
    }
    async updateDirHandle() {
      try {
        this.dirHandleStatus = 1;
        this.updateDirHandleChannel.postMessage({
          kind: 1
          /* picking */
        });
        this.dirHandle = await _unsafeWindow.showDirectoryPicker({ id: "pdl", mode: "readwrite" });
        logger.info("更新dirHandle", this.dirHandle);
        this.dirHandleStatus = 2;
        this.updateDirHandleChannel.postMessage({
          kind: 2,
          handle: this.dirHandle
        });
        this.processCachedTasks();
        return true;
      } catch (error) {
        logger.warn(error);
        this.updateDirHandleChannel.postMessage({
          kind: 0
          /* unpick */
        });
        if (this.dirHandle) {
          this.dirHandleStatus = 2;
          this.processCachedTasks();
        } else {
          this.dirHandleStatus = 0;
          this.rejectCachedTasks();
        }
        return false;
      }
    }
    getCurrentDirName() {
      var _a;
      return ((_a = this.dirHandle) == null ? void 0 : _a.name) ?? "";
    }
    isDirHandleNotSet() {
      return this.dirHandleStatus === 0;
    }
    setFilenameConflictAction(action) {
      this.filenameConflictAction = action;
    }
    async saveFile(blob, downloadMeta) {
      if (downloadMeta.isAborted) throw new CancelError();
      if (this.dirHandleStatus === 1) {
        let onSaveFullfilled;
        let onSaveRejected;
        const promiseExcutor = new Promise((resolve, reject) => {
          onSaveFullfilled = resolve;
          onSaveRejected = reject;
        });
        this.cachedTasks.push([blob, downloadMeta, onSaveFullfilled, onSaveRejected]);
        return promiseExcutor;
      }
      if (this.dirHandleStatus === 0) {
        const isSuccess = await this.updateDirHandle();
        if (!isSuccess) throw new TypeError("Failed to get dir handle.");
      }
      let currenDirHandle;
      let filename;
      const path = downloadMeta.config.path;
      const index = path.lastIndexOf("/");
      if (index === -1) {
        filename = path;
        currenDirHandle = this.dirHandle;
      } else {
        filename = path.slice(index + 1);
        currenDirHandle = await this.getDirHandleRecursive(path.slice(0, index));
      }
      if (downloadMeta.isAborted) throw new CancelError();
      const fileHandle = await this.getFilenameHandle(currenDirHandle, filename);
      const writableStream = await fileHandle.createWritable();
      await writableStream.write(blob);
      await writableStream.close();
      this.clearFilenameCached(filename, fileHandle.name);
    }
  }
  const fsaHandler = new FileSystemAccessHandler("update_dir_channel");
  function gmDownload(blob, downloadMeta) {
    return new Promise((resolve, reject) => {
      if (downloadMeta.isAborted) return reject(new CancelError());
      const imgUrl = URL.createObjectURL(blob);
      const request = {
        url: URL.createObjectURL(blob),
        name: downloadMeta.config.path,
        onerror: (error) => {
          URL.revokeObjectURL(imgUrl);
          if (downloadMeta.isAborted) {
            resolve();
          } else {
            console.error(error);
            reject(new Error(`FileSave error: ${downloadMeta.config.path}`));
          }
        },
        onload: () => {
          URL.revokeObjectURL(imgUrl);
          resolve();
        }
      };
      downloadMeta.abort = _GM_download(request).abort;
    });
  }
  function aDownload(blob, downloadMeta) {
    if (downloadMeta.isAborted) return Promise.reject(new CancelError());
    let path = downloadMeta.config.path;
    const separaterIndex = path.lastIndexOf("/");
    if (separaterIndex !== -1) path = path.slice(separaterIndex + 1);
    const dlEle = document.createElement("a");
    dlEle.href = URL.createObjectURL(blob);
    dlEle.download = path;
    dlEle.click();
    URL.revokeObjectURL(dlEle.href);
    return Promise.resolve();
  }
  var UgoiraFormat = /* @__PURE__ */ ((UgoiraFormat2) => {
    UgoiraFormat2["ZIP"] = "zip";
    UgoiraFormat2["GIF"] = "gif";
    UgoiraFormat2["WEBP"] = "webp";
    UgoiraFormat2["PNG"] = "png";
    UgoiraFormat2["WEBM"] = "webm";
    UgoiraFormat2["MP4"] = "mp4";
    return UgoiraFormat2;
  })(UgoiraFormat || {});
  var FilenameConfigAction = /* @__PURE__ */ ((FilenameConfigAction2) => {
    FilenameConfigAction2["UNIQUIFY"] = "uniquify";
    FilenameConfigAction2["OVERWRITE"] = "overwrite";
    FilenameConfigAction2["PROMPT"] = "prompt";
    return FilenameConfigAction2;
  })(FilenameConfigAction || {});
  var TagLanguage = /* @__PURE__ */ ((TagLanguage2) => {
    TagLanguage2["JAPANESE"] = "ja";
    TagLanguage2["CHINESE"] = "zh";
    TagLanguage2["TRADITIONAL_CHINESE"] = "zh_tw";
    TagLanguage2["ENGLISH"] = "en";
    return TagLanguage2;
  })(TagLanguage || {});
  var HistoryBackupInterval = /* @__PURE__ */ ((HistoryBackupInterval2) => {
    HistoryBackupInterval2[HistoryBackupInterval2["NEVER"] = 0] = "NEVER";
    HistoryBackupInterval2[HistoryBackupInterval2["EVERY_DAY"] = 86400] = "EVERY_DAY";
    HistoryBackupInterval2[HistoryBackupInterval2["EVERY_7_DAY"] = 604800] = "EVERY_7_DAY";
    HistoryBackupInterval2[HistoryBackupInterval2["EVERY_30_DAY"] = 2592e3] = "EVERY_30_DAY";
    return HistoryBackupInterval2;
  })(HistoryBackupInterval || {});
  let config;
  function loadConfig(customConfig = {}) {
    if (config) throw new Error("`config` has already been defined.");
    const defaultConfig = Object.freeze({
      version: "1.4.0",
      ugoiraFormat: "zip",
      folderPattern: "",
      filenamePattern: "{id}",
      tagLang: "ja",
      showMsg: true,
      mixEffect: false,
      bundleIllusts: false,
      bundleManga: false,
      addBookmark: false,
      addBookmarkWithTags: false,
      privateR18: false,
      useFileSystemAccess: false,
      fileSystemFilenameConflictAction: "uniquify",
      showPopupButton: true,
      gifQuality: 10,
      webmQuality: 95,
      mp4Bitrate: 20,
      losslessWebp: false,
      webpQuality: 95,
      webpMehtod: 4,
      pngColor: 256,
      historyBackupInterval: 0,
      lastHistoryBackup: 0,
      token: "",
      "pdl-btn-self-bookmark-left": 100,
      "pdl-btn-self-bookmark-top": 76,
      "pdl-btn-left": 0,
      "pdl-btn-top": 100,
      ...customConfig
    });
    let configData;
    if (!localStorage.pdlSetting) {
      configData = Object.assign({}, defaultConfig);
    } else {
      try {
        configData = JSON.parse(localStorage.pdlSetting);
      } catch (error) {
        logger.error("Use default config because: ", error);
        configData = Object.assign({}, defaultConfig);
      }
    }
    if (configData.version !== defaultConfig.version) {
      configData = {
        ...defaultConfig,
        ...configData,
        version: defaultConfig.version,
        showMsg: true
      };
      localStorage.pdlSetting = JSON.stringify(configData);
    }
    return config = {
      get(key) {
        return configData[key] ?? defaultConfig[key];
      },
      set(key, value) {
        if (configData[key] !== value) {
          configData[key] = value;
          localStorage.pdlSetting = JSON.stringify(configData);
          logger.info("Config set:", key, value);
        }
      },
      getAll() {
        return { ...configData };
      },
      update(newConfig) {
        configData = { ...newConfig };
        localStorage.pdlSetting = JSON.stringify(configData);
      }
    };
  }
  function gmDownloadDataUrl(blob, downloadMeta) {
    return readBlobAsDataUrl(blob).then((dataUrl) => {
      return new Promise((resolve, reject) => {
        if (downloadMeta.isAborted) return reject(new CancelError());
        const request = {
          url: dataUrl,
          name: downloadMeta.config.path,
          onerror: (error) => {
            if (downloadMeta.isAborted) {
              resolve();
            } else {
              console.error(error);
              reject(new Error(`FileSave error: ${downloadMeta.config.path}`));
            }
          },
          onload: () => {
            resolve();
          }
        };
        downloadMeta.abort = _GM_download(request).abort;
      });
    });
  }
  let saveFile;
  const blobAvaliable = env.isBlobDlAvaliable();
  const subPathAvaliable = env.isSupportSubpath();
  if (subPathAvaliable) {
    if (!blobAvaliable) {
      saveFile = gmDownloadDataUrl;
    } else {
      saveFile = gmDownload;
    }
  } else {
    saveFile = aDownload;
    logger.warn("Download function is not fully supported:", _GM_info.scriptHandler, _GM_info.version);
  }
  const fileSaveAdapters = {
    getAdapter() {
      if (this.isFileSystemAccessEnable()) {
        fsaHandler.setFilenameConflictAction(config.get("fileSystemFilenameConflictAction"));
        return fsaHandler.saveFile.bind(fsaHandler);
      } else {
        return saveFile;
      }
    },
    isFileSystemAccessEnable() {
      return env.isFileSystemAccessAvaliable() && config.get("useFileSystemAccess");
    },
    dirHandleCheck() {
      if (this.isFileSystemAccessEnable() && fsaHandler.isDirHandleNotSet())
        fsaHandler.updateDirHandle();
    },
    async updateDirHandle() {
      if (this.isFileSystemAccessEnable()) {
        await fsaHandler.updateDirHandle();
        return fsaHandler.getCurrentDirName();
      }
      return "";
    },
    getFsaDirName() {
      if (this.isFileSystemAccessEnable()) {
        return fsaHandler.getCurrentDirName();
      } else {
        return "";
      }
    }
  };
  function createDownloader() {
    const MAX_DOWNLOAD = 5;
    const MAX_RETRY = 3;
    const DOWNLOAD_INTERVAL = 500;
    let queue = [];
    let active2 = [];
    const cleanAndStartNext = (removeMeta, nextMeta) => {
      sleep(DOWNLOAD_INTERVAL).then(() => {
        active2.splice(active2.indexOf(removeMeta), 1);
        if (nextMeta) {
          active2.push(nextMeta);
          dispatchDownload(nextMeta);
        } else if (queue.length) {
          const meta = queue.shift();
          active2.push(meta);
          dispatchDownload(meta);
        }
      });
    };
    const xhr = (downloadMeta) => {
      const { taskId, config: config2, timeout } = downloadMeta;
      const saveFile2 = fileSaveAdapters.getAdapter();
      return _GM_xmlhttpRequest({
        url: config2.src,
        timeout,
        method: "GET",
        headers: config2.headers,
        responseType: "blob",
        ontimeout() {
          var _a;
          const { taskId: taskId2, config: config22, isAborted } = downloadMeta;
          if (isAborted) return;
          downloadMeta.retry++;
          logger.warn("Download timeout", downloadMeta.retry, ":", config22.src);
          if (downloadMeta.retry > MAX_RETRY) {
            const err = new Error(`Download timout. ${taskId2} | ${config22.src}`);
            (_a = config22.onError) == null ? void 0 : _a.call(config22, err, config22);
            downloadMeta.reject(err);
            cleanAndStartNext(downloadMeta);
          } else {
            logger.info("Retry download:", downloadMeta.retry, config22.src);
            cleanAndStartNext(downloadMeta, downloadMeta);
          }
        },
        onerror(error) {
          var _a;
          const { taskId: taskId2, config: config22, isAborted } = downloadMeta;
          if (isAborted) return;
          let err;
          if (error.status === 429) {
            err = new RequestError(config22.src, error.status);
          } else {
            err = new Error(`Download failed. ID: ${taskId2}.`);
            logger.error(error);
          }
          (_a = config22.onError) == null ? void 0 : _a.call(config22, err, config22);
          downloadMeta.reject(err);
          cleanAndStartNext(downloadMeta);
        },
        onprogress: (res) => {
          var _a;
          if (res.loaded > 0 && res.total > 0) {
            const progress = Math.floor(res.loaded / res.total * 100);
            (_a = config2.onProgress) == null ? void 0 : _a.call(config2, progress, config2);
          }
        },
        onload: async (e) => {
          var _a, _b, _c, _d;
          logger.info("Xhr complete:", config2.src);
          cleanAndStartNext(downloadMeta);
          if (downloadMeta.isAborted)
            return logger.warn("Download was canceled.", taskId, config2.path);
          (_a = config2.onXhrLoaded) == null ? void 0 : _a.call(config2, config2);
          try {
            let modRes;
            if (typeof config2.beforeFileSave === "function") {
              modRes = await config2.beforeFileSave(e.response, config2);
              if (modRes && !downloadMeta.isAborted) {
                await saveFile2(modRes, downloadMeta);
                (_b = config2.onFileSaved) == null ? void 0 : _b.call(config2, config2);
                logger.info("Download complete:", config2.path);
              }
            } else {
              await saveFile2(e.response, downloadMeta);
              (_c = config2.onFileSaved) == null ? void 0 : _c.call(config2, config2);
              logger.info("Download complete:", config2.path);
            }
            downloadMeta.resolve(downloadMeta.taskId);
          } catch (error) {
            (_d = config2.onError) == null ? void 0 : _d.call(config2, error, config2);
            downloadMeta.reject(error);
          }
        }
      });
    };
    const dispatchDownload = (downloadMeta) => {
      logger.info("Start download:", downloadMeta.config.src);
      const abortObj = xhr(downloadMeta);
      downloadMeta.abort = abortObj.abort;
    };
    return {
      get fileSystemAccessEnabled() {
        return fileSaveAdapters.isFileSystemAccessEnable();
      },
      /**
       * 下载触发后应该先弹窗选择文件保存位置,避免下载/转换用时过长导致错误
       * Must be handling a user gesture to show a file picker.
       * https://bugs.chromium.org/p/chromium/issues/detail?id=1193489
       */
      dirHandleCheck() {
        fileSaveAdapters.dirHandleCheck();
      },
      updateDirHandle() {
        return fileSaveAdapters.updateDirHandle();
      },
      getCurrentFsaDirName() {
        return fileSaveAdapters.getFsaDirName();
      },
      async download(configs) {
        logger.info("Downloader add:", configs);
        if (!Array.isArray(configs)) configs = [configs];
        if (configs.length < 1) return Promise.resolve([]);
        const promises = [];
        configs.forEach((config2) => {
          promises.push(
            new Promise((resolve, reject) => {
              const downloadMeta = {
                taskId: config2.taskId,
                config: config2,
                isAborted: false,
                retry: 0,
                timeout: config2.timeout,
                resolve,
                reject
              };
              queue.push(downloadMeta);
            })
          );
        });
        while (active2.length < MAX_DOWNLOAD && queue.length) {
          const meta = queue.shift();
          active2.push(meta);
          dispatchDownload(meta);
        }
        const results = await Promise.allSettled(promises);
        const resultIds = [];
        for (let i = 0; i < results.length; i++) {
          const result = results[i];
          if (result.status === "rejected") throw result.reason;
          resultIds.push(result.value);
        }
        return resultIds;
      },
      abort(taskIds) {
        if (typeof taskIds === "string") taskIds = [taskIds];
        if (!taskIds.length) return;
        logger.info("Downloader delete, active:", active2.length, "queue", queue.length);
        active2 = active2.filter((downloadMeta) => {
          var _a, _b, _c;
          if (taskIds.includes(downloadMeta.taskId) && !downloadMeta.isAborted) {
            downloadMeta.isAborted = true;
            (_a = downloadMeta.abort) == null ? void 0 : _a.call(downloadMeta);
            (_c = (_b = downloadMeta.config).onAbort) == null ? void 0 : _c.call(_b, downloadMeta.config);
            downloadMeta.reject(new CancelError());
            logger.warn("Download aborted:", downloadMeta.config.path);
          } else {
            return true;
          }
        });
        queue = queue.filter((downloadMeta) => !taskIds.includes(downloadMeta.taskId));
        while (active2.length < MAX_DOWNLOAD && queue.length) {
          const meta = queue.shift();
          active2.push(meta);
          dispatchDownload(meta);
        }
      }
    };
  }
  const downloader = createDownloader();
  class HistoryDb extends Dexie {
    constructor() {
      super("PdlHistory");
      __publicField(this, "history");
      __publicField(this, "imageEffect");
      this.version(3).stores({
        history: "pid, userId, user, title, *tags",
        imageEffect: "id"
      });
    }
    throwIfInvalidNumber(num) {
      if (typeof num === "string") {
        if (num !== "") {
          num = +num;
        } else {
          return logger.throw('Invalid argument: can not be "".', RangeError);
        }
      }
      if (num < 0 || !Number.isSafeInteger(num)) {
        logger.throw(`Invalid number: ${num}, must be a non-negative integer.`, RangeError);
      }
      return num;
    }
    async add(historyData) {
      const { pid, page } = historyData;
      return this.transaction("rw", this.history, async () => {
        if (page !== void 0) {
          this.throwIfInvalidNumber(page);
          const historyItem = await this.get(pid);
          if (historyItem && historyItem.page === void 0) {
            delete historyData.page;
            this.history.put(historyData);
          } else {
            const u8arr = HistoryDb.updatePageData(page, historyItem == null ? void 0 : historyItem.page);
            this.history.put({ ...historyData, page: u8arr });
          }
        } else {
          this.history.put(historyData);
        }
      });
    }
    import(objArr) {
      const historyItems = objArr.map((historyObj) => {
        if (historyObj.page) {
          return { ...historyObj, page: new Uint8Array(Object.values(historyObj.page)) };
        } else {
          return historyObj;
        }
      });
      return this.history.bulkPut(historyItems);
    }
    async has(pid, page) {
      if (page === void 0) {
        return !!await this.get(pid);
      } else {
        this.throwIfInvalidNumber(page);
        const historyItem = await this.get(pid);
        if (!historyItem) return false;
        if (!historyItem.page) return true;
        return HistoryDb.isPageInData(page, historyItem.page);
      }
    }
    get(pid) {
      pid = this.throwIfInvalidNumber(pid);
      return this.history.get(pid);
    }
    getAll() {
      return this.history.toArray();
    }
    generateCsv() {
      return this.getAll().then((datas) => {
        const csvData = datas.map((historyData) => {
          const { pid, userId = "", user = "", title = "", tags = "", comment = "" } = historyData;
          return [String(pid), String(userId), user, title, comment, tags ? tags.join(",") : tags];
        });
        csvData.unshift(["id", "userId", "user", "title", "comment", "tags"]);
        return generateCsv(csvData);
      });
    }
    clear() {
      return this.history.clear();
    }
    // Firefox does not support storing `ImageData`, so it will always return `undefined`.
    async getImageEffect(effectId) {
      const item = await this.imageEffect.get(effectId);
      if (!item) return item;
      return item;
    }
    addImageEffect(effectData) {
      return this.imageEffect.put(effectData);
    }
    static updatePageData(page, pageData) {
      const byteIndex = Math.floor(page / 8);
      const bitIndex = page % 8;
      if (!pageData) {
        const newArr = new Uint8Array(byteIndex + 1);
        newArr[byteIndex] |= 1 << bitIndex;
        return newArr;
      } else if (byteIndex > pageData.length - 1) {
        const newArr = new Uint8Array(byteIndex + 1);
        newArr.set(pageData);
        newArr[byteIndex] |= 1 << bitIndex;
        return newArr;
      } else {
        pageData[byteIndex] |= 1 << bitIndex;
        return pageData;
      }
    }
    static isPageInData(page, pageData) {
      const byteIndex = Math.floor(page / 8);
      const bitIndex = page % 8;
      return !(byteIndex > pageData.length - 1) && (pageData[byteIndex] & 1 << bitIndex) !== 0;
    }
  }
  class CachedHistoryDb extends HistoryDb {
    constructor() {
      super();
      __publicField(this, "cache", /* @__PURE__ */ new Map());
      __publicField(this, "initCachePromise");
      __publicField(this, "channel");
      this.initCachePromise = this.initCache();
      this.channel = this.initChannel();
    }
    async initCache() {
      logger.time("loadDb");
      const historyItems = await this.getAll();
      let historyItem;
      for (let i = 0; historyItem = historyItems[i++]; ) {
        const { pid, page = null } = historyItem;
        this.cache.set(pid, page);
      }
      logger.timeEnd("loadDb");
    }
    initChannel() {
      const CHANNEL_NAME = "pdl_sync-cache";
      const channel = new BroadcastChannel(CHANNEL_NAME);
      channel.addEventListener("message", (evt) => {
        const { data } = evt;
        if (data === void 0) {
          this.cache.clear();
          logger.info("clear database cache");
          return;
        }
        if (Array.isArray(data)) {
          data.forEach((item) => {
            this.cache.set(item.pid, item.page);
          });
          logger.info("Sync database cache:", data.length);
        } else {
          this.cache.set(data.pid, data.page);
        }
      });
      return channel;
    }
    syncCacheViaChannel(item) {
      this.channel.postMessage(item);
    }
    updateCache(item) {
      if (Array.isArray(item)) {
        item.forEach((cache) => {
          this.cache.set(cache.pid, cache.page);
        });
      } else {
        this.cache.set(item.pid, item.page);
      }
      this.syncCacheViaChannel(item);
    }
    clearCache() {
      this.cache.clear();
      this.syncCacheViaChannel();
    }
    async getCache(pid) {
      pid = this.throwIfInvalidNumber(pid);
      await this.initCachePromise;
      return this.cache.get(pid);
    }
    async add(historyData) {
      const { pid, page } = historyData;
      if (page === void 0) {
        !await this.has(pid) && this.updateCache({ pid, page: null });
      } else {
        this.throwIfInvalidNumber(page);
        const pageData = await this.getCache(pid);
        if (pageData !== null) {
          this.updateCache({ pid, page: HistoryDb.updatePageData(page, pageData) });
        } else {
          this.updateCache({ pid, page: null });
        }
      }
      return super.add(historyData);
    }
    import(objArr) {
      const cacheItems = objArr.map((historyObj) => {
        return {
          pid: historyObj.pid,
          page: historyObj.page ? new Uint8Array(Object.values(historyObj.page)) : null
        };
      });
      this.updateCache(cacheItems);
      return super.import(objArr);
    }
    async has(pid, page) {
      pid = this.throwIfInvalidNumber(pid);
      await this.initCachePromise;
      if (page === void 0) {
        return this.cache.has(pid);
      } else {
        this.throwIfInvalidNumber(page);
        const cachesData = await this.getCache(pid);
        if (cachesData === void 0) return false;
        if (cachesData === null) return true;
        return HistoryDb.isPageInData(page, cachesData);
      }
    }
    clear() {
      this.clearCache();
      return super.clear();
    }
  }
  class ReadableHistoryDb extends CachedHistoryDb {
    constructor() {
      super(...arguments);
      __publicField(this, "subscribers", /* @__PURE__ */ new Set());
    }
    runSubscription() {
      logger.info("runSubscription", this.subscribers.size);
      this.subscribers.forEach((subscription) => {
        subscription(this.cache);
      });
    }
    async initCache() {
      await super.initCache();
      this.runSubscription();
    }
    initChannel() {
      const channel = super.initChannel();
      channel.addEventListener("message", () => {
        this.runSubscription();
      });
      return channel;
    }
    updateCache(item) {
      super.updateCache(item);
      this.runSubscription();
    }
    clearCache() {
      super.clearCache();
      this.runSubscription();
    }
    subscribe(subscription) {
      this.subscribers.add(subscription);
      subscription(this.cache);
      return () => {
        this.subscribers.delete(subscription);
      };
    }
  }
  const historyDb = new ReadableHistoryDb();
  const rule34Parser = {
    async parse(id) {
      var _a, _b, _c, _d, _e, _f;
      const res = await fetch("index.php?page=post&s=view&id=" + id);
      if (!res.ok) throw new RequestError(res.url, res.status);
      const html = await res.text();
      const doc = new DOMParser().parseFromString(html, "text/html");
      const src = ((_a = doc.querySelector("#gelcomVideoPlayer > source")) == null ? void 0 : _a.src) || doc.querySelector('meta[property="og:image"]').getAttribute("content");
      const imageNameMatch = new RegExp("(?<=\\/)\\w+\\.\\w+(?=\\?)").exec(src);
      if (!imageNameMatch) throw new Error("Can not parse image name from src.");
      const imageName = imageNameMatch[0];
      const [title, extendName] = imageName.split(".");
      const artists = [];
      const characters = [];
      const tags = [];
      const tagEls = doc.querySelectorAll('li[class*="tag-type"]');
      tagEls.forEach((tagEl) => {
        var _a2;
        const tagTypeMatch = new RegExp("(?<=tag-type-)\\w+").exec(tagEl.className);
        if (!tagTypeMatch) throw new Error("Unknown tag: " + tagEl.className);
        const tagType = tagTypeMatch[0];
        const tag = ((_a2 = tagEl.querySelector('a[href*="page=post"]')) == null ? void 0 : _a2.textContent) || "";
        if (tagType === "artist") {
          artists.push(tag);
        } else if (tagType === "character") {
          characters.push(tag);
        }
        tags.push(tagType + ":" + tag);
      });
      const uploaderEl = doc.querySelector('a[href*="page=account&s=profile"]');
      const postDateStr = (_c = (_b = uploaderEl == null ? void 0 : uploaderEl.parentElement) == null ? void 0 : _b.firstChild) == null ? void 0 : _c.nodeValue;
      const postDate = postDateStr ? postDateStr.split(": ")[1] : "";
      const sourceEl = (_e = (_d = uploaderEl == null ? void 0 : uploaderEl.parentElement) == null ? void 0 : _d.nextElementSibling) == null ? void 0 : _e.nextElementSibling;
      if (sourceEl && ((_f = sourceEl.textContent) == null ? void 0 : _f.toLowerCase().includes("source"))) {
        const sourceLink = sourceEl.querySelector("a");
        if (sourceLink) {
          tags.push("source:" + sourceLink.href);
        } else {
          tags.push("source:" + sourceEl.textContent.replace("Source: ", ""));
        }
      }
      return {
        id,
        src,
        extendName,
        artist: artists.join(",") || "UnknownArtist",
        character: characters.join(",") || "UnknownCharacter",
        title,
        tags,
        createDate: postDate
      };
    }
  };
  const btnStyle = ".pdl-thumbnail{position:absolute;display:flex;justify-content:center;align-items:center;margin:0;padding:0;height:32px;width:32px;top:calc((100% - 32px) * var(--pdl-btn-top) / 100);left:calc((100% - 32px) * var(--pdl-btn-left) / 100);border:none;border-radius:4px;overflow:hidden;white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;user-select:none;font-family:system-ui;font-size:13px;font-weight:700;color:#262626;background-color:#ffffff80;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);z-index:1;cursor:pointer}.pdl-thumbnail:disabled{cursor:not-allowed}.pdl-thumbnail>svg{position:absolute;width:85%;height:85%;fill:currentColor;stroke:currentColor}.pdl-thumbnail>span{opacity:0;transition:opacity .2s}.pdl-thumbnail>span.show{opacity:1}:host([data-type=gallery]) .pdl-thumbnail{position:sticky;top:40px;left:0}:host([data-type=pixiv-my-bookmark]) .pdl-thumbnail{top:calc((100% - 32px) * var(--pdl-btn-self-bookmark-top) / 100);left:calc((100% - 32px) * var(--pdl-btn-self-bookmark-left) / 100)}:host([data-type=pixiv-history]) .pdl-thumbnail{z-index:auto}:host([data-type=pixiv-presentation]) .pdl-thumbnail{position:fixed;top:50px;right:20px;left:auto}:host([data-type=pixiv-toolbar]) .pdl-thumbnail{position:relative;top:auto;left:auto;color:inherit;background-color:transparent}:host([data-type=pixiv-manga-viewer]) .pdl-thumbnail{top:80%;right:4px;left:auto}:host([data-type=yande-browse]) .pdl-thumbnail{top:320px;right:4px;left:auto}:host([data-status]) .pdl-thumbnail{color:#16a34a}:host([data-status=error]) .pdl-thumbnail{color:#ef4444}";
  const svgGroup = `<svg xmlns="http://www.w3.org/2000/svg" style="display: none">
  <symbol id="pdl-download" viewBox="0 0 512 512">
    <path
      d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm-32-316v116h-67c-10.7 0-16 12.9-8.5 20.5l99 99c4.7 4.7 12.3 4.7 17 0l99-99c7.6-7.6 2.2-20.5-8.5-20.5h-67V140c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12z"
    ></path>
  </symbol>

  <symbol id="pdl-loading" viewBox="0 0 512 512">
    <style>
      @keyframes pdl-loading {
        0% {
          transform: rotate3d(0, 0, 1, -90deg) rotate3d(1, 0, 0, 0deg);
          stroke-dashoffset: 1407.43;
        }

        49.99% {
          transform: rotate3d(0, 0, 1, 90deg) rotate3d(1, 0, 0, 0deg);
        }

        50% {
          transform: rotate3d(0, 0, 1, 90deg) rotate3d(1, 0, 0, 180deg);
          stroke-dashoffset: 0;
        }

        100% {
          transform: rotate3d(0, 0, 1, 270deg) rotate3d(1, 0, 0, 180deg);
          stroke-dashoffset: 1407.43;
        }
      }

      circle.rotate {
        transform-origin: 50% 50%;
        animation: 2.5s infinite ease-in-out pdl-loading;
      }
    </style>
    <circle
      class="rotate"
      cx="256"
      cy="256"
      r="224"
      stroke-width="48"
      fill="none"
      stroke-dasharray="1407.43"
      stroke-dashoffset="1055.57"
      stroke-linecap="round"
    ></circle>
  </symbol>

  <symbol id="pdl-progress" viewBox="0 0 512 512">
    <style>
      circle.progress {
        transition: stroke-dashoffset 0.2s ease;
      }
    </style>
    <circle
      class="progress"
      cx="256"
      cy="256"
      r="224"
      stroke-width="48"
      fill="none"
      stroke-dasharray="1407.43"
      stroke-linecap="round"
      transform="rotate(-90 256 256)"
    ></circle>
  </symbol>

  <symbol id="pdl-error" viewBox="0 0 512 512">
    <path
      d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm101.8-262.2L295.6 256l62.2 62.2c4.7 4.7 4.7 12.3 0 17l-22.6 22.6c-4.7 4.7-12.3 4.7-17 0L256 295.6l-62.2 62.2c-4.7 4.7-12.3 4.7-17 0l-22.6-22.6c-4.7-4.7-4.7-12.3 0-17l62.2-62.2-62.2-62.2c-4.7-4.7-4.7-12.3 0-17l22.6-22.6c4.7-4.7 12.3-4.7 17 0l62.2 62.2 62.2-62.2c4.7-4.7 12.3-4.7 17 0l22.6 22.6c4.7 4.7 4.7 12.3 0 17z"
    ></path>
  </symbol>

  <symbol id="pdl-complete" viewBox="0 0 512 512">
    <path
      d="M256 8C119.033 8 8 119.033 8 256s111.033 248 248 248 248-111.033 248-248S392.967 8 256 8zm0 48c110.532 0 200 89.451 200 200 0 110.532-89.451 200-200 200-110.532 0-200-89.451-200-200 0-110.532 89.451-200 200-200m140.204 130.267l-22.536-22.718c-4.667-4.705-12.265-4.736-16.97-.068L215.346 303.697l-59.792-60.277c-4.667-4.705-12.265-4.736-16.97-.069l-22.719 22.536c-4.705 4.667-4.736 12.265-.068 16.971l90.781 91.516c4.667 4.705 12.265 4.736 16.97.068l172.589-171.204c4.704-4.668 4.734-12.266.067-16.971z"
    ></path>
  </symbol>
</svg>
`;
  const iconTypeMap = {
    init: "#pdl-download",
    loading: "#pdl-loading",
    progress: "#pdl-progress",
    complete: "#pdl-complete",
    error: "#pdl-error"
  };
  var ThumbnailBtnStatus = /* @__PURE__ */ ((ThumbnailBtnStatus2) => {
    ThumbnailBtnStatus2["Init"] = "init";
    ThumbnailBtnStatus2["Loading"] = "loading";
    ThumbnailBtnStatus2["Progress"] = "progress";
    ThumbnailBtnStatus2["Complete"] = "complete";
    ThumbnailBtnStatus2["Error"] = "error";
    return ThumbnailBtnStatus2;
  })(ThumbnailBtnStatus || {});
  var ThumbnailBtnType = /* @__PURE__ */ ((ThumbnailBtnType2) => {
    ThumbnailBtnType2["Gallery"] = "gallery";
    ThumbnailBtnType2["PixivMyBookmark"] = "pixiv-my-bookmark";
    ThumbnailBtnType2["PixivHistory"] = "pixiv-history";
    ThumbnailBtnType2["PixivPresentation"] = "pixiv-presentation";
    ThumbnailBtnType2["PixivToolbar"] = "pixiv-toolbar";
    ThumbnailBtnType2["PixivMangaViewer"] = "pixiv-manga-viewer";
    ThumbnailBtnType2["YandeBrowse"] = "yande-browse";
    return ThumbnailBtnType2;
  })(ThumbnailBtnType || {});
  class ThumbnailButton extends HTMLElement {
    constructor(props) {
      super();
      __publicField(this, "btn");
      __publicField(this, "status", "init");
      __publicField(this, "mediaId");
      __publicField(this, "page");
      __publicField(this, "type");
      __publicField(this, "onClick");
      __publicField(this, "unsubscriber");
      __publicField(this, "connectedFlag", false);
      __publicField(this, "shouldObserveDb", true);
      __publicField(this, "progress", 0);
      __publicField(this, "dirty", false);
      this.dispatchDownload = this.dispatchDownload.bind(this);
      this.onClick = props.onClick;
      this.mediaId = this.checkNumberValidity(props.id);
      this.dataset.id = String(this.mediaId);
      if (props.type) {
        this.dataset.type = this.type = props.type;
      }
      if (props.page !== void 0) {
        this.page = this.checkNumberValidity(props.page);
        this.dataset.page = String(this.page);
      }
      props.shouldObserveDb !== void 0 && (this.shouldObserveDb = props.shouldObserveDb);
      if (props.extraData) {
        for (const key in props.extraData) {
          this.dataset[key] = props.extraData[key];
        }
      }
    }
    static get tagNameLowerCase() {
      return "pdl-button";
    }
    checkNumberValidity(num) {
      if (typeof num === "string") {
        if (num !== "") {
          num = +num;
        } else {
          return logger.throw('Invalid argument: can not be "".', RangeError);
        }
      }
      if (num < 0 || !Number.isSafeInteger(num)) {
        return logger.throw(`Invalid number: ${num}, must be a non-negative integer.`, RangeError);
      }
      return num;
    }
    static get observedAttributes() {
      return ["data-id", "data-status", "data-page", "data-type", "disabled"];
    }
    attributeChangedCallback(name, oldValue, newValue) {
      switch (name) {
        case "data-id":
          this.updateId(newValue);
          break;
        case "data-status":
          this.updateIcon(newValue);
          break;
        case "data-page":
          this.updatePage(newValue);
          break;
        case "data-type":
          this.resetType(newValue);
          break;
        case "disabled":
          this.updateDisableStatus(newValue);
          break;
      }
    }
    resetType(newVal) {
      if (newVal === null && this.type === void 0) return;
      if (newVal !== this.type) {
        if (this.type === void 0) {
          delete this.dataset.type;
        } else {
          this.dataset.type = this.type;
        }
        logger.error('Changes to "data-type" is not allowed.');
      }
    }
    updateId(id) {
      try {
        if (id === null) throw new Error('Attribute "data-id" is required.');
        this.mediaId = this.checkNumberValidity(id);
        this.connectedFlag && this.shouldObserveDb && this.observeDb()();
      } catch (error) {
        logger.error(error);
        this.dataset.id = String(this.mediaId);
      }
    }
    updateDisableStatus(val) {
      if (!this.connectedFlag) {
        this.dirty = true;
        return;
      }
      if (typeof val === "string") {
        this.btn.setAttribute("disabled", "");
      } else {
        this.btn.removeAttribute("disabled");
      }
    }
    updatePage(page) {
      try {
        if (page === null) {
          this.page = void 0;
        } else {
          this.page = this.checkNumberValidity(page);
        }
        this.connectedFlag && this.shouldObserveDb && this.observeDb()();
      } catch (error) {
        logger.error(error);
        if (this.page === void 0) {
          delete this.dataset.page;
        } else {
          this.dataset.page = String(this.page);
        }
      }
    }
    updateIcon(status) {
      if (status === null) {
        status = "init";
      } else if (status === "init") {
        delete this.dataset.status;
        return;
      } else if (!(status in iconTypeMap)) {
        this.dataset.status = this.status;
        return;
      }
      this.status = status;
      if (!this.connectedFlag) {
        this.dirty = true;
        return;
      }
      const useEl = this.shadowRoot.querySelector("use");
      useEl.setAttribute("xlink:href", iconTypeMap[status]);
      useEl.animate([{ opacity: 0.5 }, { opactiy: 1 }], { duration: 200 });
    }
    render() {
      let shadowRoot;
      if ((shadowRoot = this.shadowRoot) && !this.dirty) return;
      const statusIsProgress = this.status === "progress";
      shadowRoot ?? (shadowRoot = this.attachShadow({ mode: "open" }));
      shadowRoot.innerHTML = `<style>${btnStyle}</style>${svgGroup}<button class="pdl-thumbnail" ${this.hasAttribute("disabled") ? "disabled" : ""}>
      <svg xmlns="http://www.w3.org/2000/svg" class="pdl-icon" ${statusIsProgress ? `style="stroke-dashoffset: ${this.clacProgressRadial(this.progress)};"` : ""}>
        <use xlink:href="${iconTypeMap[this.status]}"></use>
      </svg>
      ${statusIsProgress ? `<span class="show">${this.progress}</span>` : "<span></span>"}
    </button>`;
    }
    dispatchDownload(evt) {
      evt == null ? void 0 : evt.preventDefault();
      evt == null ? void 0 : evt.stopPropagation();
      this.setAttribute("disabled", "");
      this.setStatus(
        "loading"
        /* Loading */
      );
      Promise.resolve(this.onClick(this)).then(
        () => {
          this.setStatus(
            "complete"
            /* Complete */
          );
        },
        (err) => {
          if (err) logger.error(err);
          this.setStatus(
            "error"
            /* Error */
          );
        }
      ).finally(() => {
        this.removeAttribute("disabled");
      });
    }
    observeDb() {
      return historyDb.subscribe(async () => {
        const downloaded = await historyDb.has(this.mediaId, this.page);
        if (this.status === "complete") {
          !downloaded && this.setStatus(
            "init"
            /* Init */
          );
        } else {
          downloaded && this.setStatus(
            "complete"
            /* Complete */
          );
        }
      });
    }
    connectedCallback() {
      this.render();
      this.dirty && (this.dirty = false);
      this.connectedFlag = true;
      this.btn = this.shadowRoot.querySelector("button");
      this.btn.addEventListener("click", this.dispatchDownload);
      this.shouldObserveDb && (this.unsubscriber = this.observeDb());
    }
    disconnectedCallback() {
      var _a, _b;
      this.connectedFlag = false;
      (_a = this.btn) == null ? void 0 : _a.removeEventListener("click", this.dispatchDownload);
      (_b = this.unsubscriber) == null ? void 0 : _b.call(this);
    }
    clacProgressRadial(progress) {
      const radius = 224;
      const circumference = 2 * Math.PI * radius;
      const offset = circumference - progress / 100 * circumference;
      return offset;
    }
    setProgress(progress, updateProgressbar = true) {
      if (progress < 0 || progress > 100) throw new RangeError('Value "progress" must between 0-100');
      this.progress = Math.floor(progress);
      if (this.status !== "progress") {
        this.dataset.status = "progress";
      }
      if (!this.connectedFlag) {
        this.dirty = true;
        return;
      }
      const shadowRoot = this.shadowRoot;
      const span = shadowRoot.querySelector("span");
      span.classList.add("show");
      span.textContent = String(this.progress);
      if (!updateProgressbar) return;
      const svg = shadowRoot.querySelector("svg.pdl-icon");
      svg.style.strokeDashoffset = String(this.clacProgressRadial(progress));
    }
    removeProgress() {
      if (this.status === "progress") this.dataset.status = "init";
      this.progress = 0;
      if (!this.connectedFlag) {
        this.dirty = true;
        return;
      }
      const shadowRoot = this.shadowRoot;
      const span = shadowRoot.querySelector("span");
      const svg = shadowRoot.querySelector("svg.pdl-icon");
      span.classList.remove("show");
      span.addEventListener(
        "transitionend",
        () => {
          span.textContent = "";
        },
        { once: true }
      );
      svg.style.removeProperty("stroke-dashoffset");
    }
    setStatus(status) {
      if (status !== this.status) {
        if (status === "init") {
          delete this.dataset.status;
          return;
        }
        if (status === "progress") {
          this.setProgress(0);
          return;
        }
        if (this.status === "progress") {
          this.removeProgress();
        }
        this.dataset.status = status;
      }
    }
  }
  customElements.define(ThumbnailButton.tagNameLowerCase, ThumbnailButton);
  class DownloadConfigBuilder {
    constructor(meta) {
      this.meta = meta;
    }
    normalizeString(str) {
      return replaceInvalidChar(unescapeHtml(str));
    }
    getFolderPattern() {
      return config.get("folderPattern");
    }
    getFilenamePattern() {
      return config.get("filenamePattern");
    }
    getFullpathPattern() {
      const folder = this.getFolderPattern();
      const filename = this.getFilenamePattern() + "." + this.meta.extendName;
      return folder ? folder + "/" + filename : filename;
    }
    isBrowserApi() {
      return env.isBrowserDownloadMode();
    }
    isFsaEnable() {
      return downloader.fileSystemAccessEnabled;
    }
    supportSubpath() {
      return this.isBrowserApi() || this.isFsaEnable();
    }
    isImage() {
      return /bmp|jp(e)?g|png|tif|gif|exif|svg|webp/i.test(this.meta.extendName);
    }
    buildFilePath() {
      const path = this.getFullpathPattern();
      const { id, createDate } = this.meta;
      let { artist, title, tags } = this.meta;
      artist = this.normalizeString(artist);
      title = this.normalizeString(title);
      tags = tags.map((tag) => this.normalizeString(tag));
      const replaceDate = (_, p1) => {
        const format = p1 || "YYYY-MM-DD";
        return dayjs(createDate).format(format);
      };
      return path.replaceAll(/\{date\((.*?)\)\}|\{date\}/g, replaceDate).replaceAll("{artist}", artist).replaceAll("{title}", title).replaceAll("{tags}", tags.join("_")).replaceAll("{id}", id);
    }
  }
  function artworkProgressFactory$1(btn2) {
    if (!btn2) return;
    return function onArtworkProgress(progress) {
      btn2.setProgress(progress);
    };
  }
  class Rule34DownloadConfig extends DownloadConfigBuilder {
    constructor(meta) {
      super(meta);
      __publicField(this, "headers", config.get("token") ? {
        cookie: `cf_clearance=${config.get("token")}`
      } : void 0);
      this.meta = meta;
    }
    getDownloadConfig(btn2) {
      return {
        headers: this.headers,
        taskId: Math.random().toString(36).slice(2),
        src: this.meta.src,
        path: this.buildFilePath(),
        source: this.meta,
        timeout: this.isImage() ? 6e4 : void 0,
        onProgress: artworkProgressFactory$1(btn2)
      };
    }
    buildFilePath() {
      const path = super.buildFilePath();
      return path.replaceAll("{character}", this.normalizeString(this.meta.character));
    }
  }
  function addBookmark$2(id) {
    _unsafeWindow.addFav(id);
  }
  async function downloadArtwork$2(btn2) {
    downloader.dirHandleCheck();
    const id = btn2.dataset.id;
    const mediaMeta = await rule34Parser.parse(id);
    const { tags, artist, title } = mediaMeta;
    const downloadConfigs = new Rule34DownloadConfig(mediaMeta).getDownloadConfig(btn2);
    config.get("addBookmark") && addBookmark$2(id);
    await downloader.download(downloadConfigs);
    const historyData = {
      pid: Number(id),
      user: artist,
      title,
      tags
    };
    historyDb.add(historyData);
  }
  const zh = {
    setting: {
      save_to: {
        title: "保存至",
        label: {
          directory: "保存位置",
          filename: "文件名"
        },
        options: {
          use_fsa: "使用FileSystemAccess API",
          fsa_directory: "选择保存文件夹",
          fsa_filename_conflict: "当文件名重复时",
          tag_language: "使用的标签语言",
          tag_language_tips: "无翻译的标签仍可能是其他语言"
        },
        button: {
          choose_fsa_directory: "浏览"
        },
        radio: {
          filename_conflict_option_uniquify: "重命名",
          filename_conflict_option_overwrite: "覆盖",
          filename_conflict_option_prompt: "提示"
        },
        placeholder: {
          sub_directory_unused: "如不需要保存到子目录,此行留空即可",
          vm_not_supported: "Violentmonkey不支持",
          need_browser_api: '请将下载模式设置为"Browser Api"',
          filename_requried: "必填"
        }
      },
      ugoira: {
        title: "动图转换",
        label: {
          format: "动图格式",
          quality: "动图质量"
        },
        options: {
          select_format: "将动图转换到所选格式",
          gif_tips: "数值越低颜色越好,但处理速度显著减慢",
          webm_tips: "0最差,99最好",
          webp_lossy: "无损转换",
          webp_quality: "图片质量",
          webp_quality_tips: "有损:0表示文件最小,100表示文件最大。无损:0最快,但文件较大,100最慢,但质量最好。",
          webp_method: "压缩方法",
          webp_method_tips: "0=快,6=慢但效果更好",
          png_tips: "颜色数量。0:所有颜色(无损PNG)"
        }
      },
      history: {
        title: "下载历史",
        label: {
          scheduled_backups: "定期备份",
          export: "导出",
          import: "导入",
          clear: "清理"
        },
        options: {
          scheduled_backups: "以选定的时间间隔自动备份下载历史",
          export_as_json: "将下载历史导出为JSON文件",
          export_as_csv: "将下载历史导出为CSV文件",
          import_json: "导入JSON格式下载历史",
          clear_history: "清除下载历史"
        },
        button: {
          export: "导出记录",
          import: "导入记录",
          clear: "清除记录"
        },
        select: {
          backup_interval_never: "不备份",
          backup_interval_every_day: "每天",
          backup_interval_every_7_day: "每7天",
          backup_interval_every_30_day: "每30天"
        },
        text: {
          confirm_clear_history: "真的要清除历史记录吗?"
        }
      },
      button_position: {
        title: "按钮位置",
        label: {
          common: "通用",
          my_bookmark: "我的收藏"
        },
        options: {
          horizon_position: "水平位置",
          vertical_position: "垂直位置"
        }
      },
      others: {
        title: "其它",
        options: {
          show_setting_button: "显示设置按钮",
          bundle_multipage_illust: "将多页插图打包为zip压缩包",
          bundle_manga: "将漫画作品打包为zip压缩包",
          add_bookmark_when_download: "下载单个作品时收藏作品",
          add_bookmark_with_tags: "收藏时添加作品标签",
          add_bookmark_private_r18: "将R-18作品收藏到不公开类别"
        }
      },
      feedback: {
        title: "反馈 / 赞赏",
        label: {
          feedback: "反馈",
          donate: "赞赏"
        },
        text: {
          feedback_desc: `如果你在使用中发现了问题或有改进建议,欢迎到<a href="https://github.com/drunkg00se/Pixiv-Downloader/issues" target="_blank" class="anchor">此链接</a>反馈。`,
          give_me_a_star: '如果脚本有帮助到你,<a href="https://github.com/drunkg00se/Pixiv-Downloader" target="_blank" class="anchor">欢迎点此在GitHub中给我一个 ⭐Star。</a>',
          donate_desc: "或者,扫码请我喝杯可乐 ^_^"
        }
      }
    },
    downloader: {
      category: {
        tab_name: "类别",
        filter: {
          exclude_downloaded: "排除已下载",
          image: "图片",
          video: "视频",
          download_all_pages: "下载所有页",
          download_selected_pages: "自定义页数",
          pixiv_illust: "插画",
          pixiv_manga: "漫画",
          pixiv_ugoira: "动图"
        }
      },
      tag_filter: {
        tab_name: "标签",
        placeholder: {
          blacklist_tag: "黑名单,将排除含有以下标签的作品。",
          whitelist_tag: "白名单,只下载包含以下标签的作品。"
        }
      },
      others: {
        tab_name: "其它",
        options: {
          retry_failed: "对首次下载失败的图片进行重试"
        }
      },
      download_type: {
        stop: "停止",
        pixiv_works: "作品",
        pixiv_bookmark: "收藏",
        pixiv_bookmark_public: "公开收藏",
        pixiv_bookmark_private: "不公开收藏",
        pixiv_follow_latest_all: "全部",
        pixiv_follow_latest_r18: "R-18",
        pixiv_series: "系列"
      }
    },
    button: {
      setting: "设置"
    },
    changelog: {
      feedback: "有问题or想建议?这里反馈",
      credit: "脚本还行?请点这里支持我!",
      give_me_a_star: "在GitHub中给我一个 ⭐Star,",
      buy_me_a_drink: "或者,扫码请我喝杯香草味冰可乐。^_^"
    }
  };
  const en = {
    setting: {
      save_to: {
        title: "Save To",
        label: {
          directory: "Save Path",
          filename: "Filename"
        },
        options: {
          use_fsa: "Use FileSystemAccess API",
          fsa_directory: "Select directory",
          fsa_filename_conflict: "When filename conflicts",
          tag_language: "Tag Language",
          tag_language_tips: "Tags without translation may still be in another language"
        },
        button: {
          choose_fsa_directory: "Browse"
        },
        radio: {
          filename_conflict_option_uniquify: "Uniquify",
          filename_conflict_option_overwrite: "Overwrite",
          filename_conflict_option_prompt: "Prompt"
        },
        placeholder: {
          sub_directory_unused: "Leave folder name blank if not saving to a subdirectory",
          vm_not_supported: "Not supported by Violentmonkey",
          need_browser_api: "Browser API required",
          filename_requried: "Required"
        }
      },
      ugoira: {
        title: "Ugoira",
        label: {
          format: "Ugoira Format",
          quality: "Ugoira Quality"
        },
        options: {
          select_format: "Convert Ugoira to selected format",
          gif_tips: "Lower values produce better colors, but slow processing significantly",
          webm_tips: "0 (worst) to 99 (best)",
          webp_lossy: "Lossless Webp",
          webp_quality: "Image Quality",
          webp_quality_tips: "For lossy, 0 gives the smallest size and 100 the largest. For lossless, 0 is the fastest but gives larger files compared to the slowest, but best, 100.",
          webp_method: "Compression Method",
          webp_method_tips: "Quality/speed trade-off (0=fast, 6=slower-better)",
          png_tips: "Number of colors in the result; 0: all colors (lossless PNG)"
        }
      },
      history: {
        title: "History",
        label: {
          scheduled_backups: "Scheduled Backups",
          export: "Export",
          import: "Import",
          clear: "Clear"
        },
        options: {
          scheduled_backups: "Automatically back up download history at selected intervals.",
          export_as_json: "Export download history as JSON file",
          export_as_csv: "Export download history as CSV file",
          import_json: "Import JSON format download history",
          clear_history: "Clear download history"
        },
        button: {
          export: "Export",
          import: "Import",
          clear: "Clear"
        },
        select: {
          backup_interval_never: "Never",
          backup_interval_every_day: "Every day",
          backup_interval_every_7_day: "7 days",
          backup_interval_every_30_day: "30 days"
        },
        text: {
          confirm_clear_history: "Do you really want to clear history?"
        }
      },
      button_position: {
        title: "Button",
        label: {
          common: "Common",
          my_bookmark: "My Bookmark"
        },
        options: {
          horizon_position: "Horizontal Position",
          vertical_position: "Vertical Position"
        }
      },
      others: {
        title: "Others",
        options: {
          show_setting_button: "Show Setting Button",
          bundle_multipage_illust: "Bundle multipage illustrations into a zip file",
          bundle_manga: "Bundle manga into a zip file",
          add_bookmark_when_download: "Bookmark artwork when downloading",
          add_bookmark_with_tags: "Add tags when bookmarking",
          add_bookmark_private_r18: "Bookmark R-18 artwork as private"
        }
      },
      feedback: {
        title: "Feedback",
        label: {
          feedback: "Feedback",
          donate: "Donate"
        },
        text: {
          feedback_desc: 'If you encounter any issues or have suggestions for improvements, feel free to provide feedback <a href="https://github.com/drunkg00se/Pixiv-Downloader/issues" target="_blank" class=" anchor">here.</a>',
          give_me_a_star: 'If the script is helpful to you, please <a href="https://github.com/drunkg00se/Pixiv-Downloader" target="_blank" class="anchor">click here and give me a ⭐Star on GitHub.</a>',
          donate_desc: "Or, buy me a cola. ^_^"
        }
      }
    },
    downloader: {
      category: {
        tab_name: "Category",
        filter: {
          exclude_downloaded: "Exclude Downloaded",
          image: "Image",
          video: "Video",
          download_all_pages: "All Pages",
          download_selected_pages: "Custom Pages",
          pixiv_illust: "Illustration",
          pixiv_manga: "Manga",
          pixiv_ugoira: "Ugoira"
        }
      },
      tag_filter: {
        tab_name: "Tags",
        placeholder: {
          blacklist_tag: "Blacklist: Exclude works with these tags.",
          whitelist_tag: "Whitelist: Only download works with these tags."
        }
      },
      others: {
        tab_name: "others",
        options: {
          retry_failed: "Retry failed image downloads."
        }
      },
      download_type: {
        stop: "Stop",
        pixiv_works: "Works",
        pixiv_bookmark: "Bookmarks",
        pixiv_bookmark_public: "Public",
        pixiv_bookmark_private: "Private",
        pixiv_follow_latest_all: "All",
        pixiv_follow_latest_r18: "R-18",
        pixiv_series: "Series"
      }
    },
    button: {
      setting: "Setting"
    },
    changelog: {
      feedback: "Feedback / Report an issue",
      credit: "Click here to support me!",
      give_me_a_star: "Give me a ⭐Star on GitHub.",
      buy_me_a_drink: "Or, buy me a vanilla-flavored iced cola. ^_^"
    }
  };
  const messages = {
    "zh-cn": zh,
    "zh-tw": zh,
    zh,
    en
  };
  const curLang = navigator.language.toLowerCase();
  const lang = curLang in messages ? curLang : "en";
  function t(key) {
    const paths = key.split(".");
    let last2 = messages[lang];
    for (let i = 0; i < paths.length; i++) {
      const value = last2[paths[i]];
      if (value === void 0 || value === null) return null;
      last2 = value;
    }
    return last2;
  }
  function noop() {
  }
  const identity = (x) => x;
  function assign(tar, src) {
    for (const k in src) tar[k] = src[k];
    return (
      /** @type {T & S} */
      tar
    );
  }
  function is_promise(value) {
    return !!value && (typeof value === "object" || typeof value === "function") && typeof /** @type {any} */
    value.then === "function";
  }
  function run(fn) {
    return fn();
  }
  function blank_object() {
    return /* @__PURE__ */ Object.create(null);
  }
  function run_all(fns) {
    fns.forEach(run);
  }
  function is_function(thing) {
    return typeof thing === "function";
  }
  function safe_not_equal(a, b) {
    return a != a ? b == b : a !== b || a && typeof a === "object" || typeof a === "function";
  }
  let src_url_equal_anchor;
  function src_url_equal(element_src, url2) {
    if (element_src === url2) return true;
    if (!src_url_equal_anchor) {
      src_url_equal_anchor = document.createElement("a");
    }
    src_url_equal_anchor.href = url2;
    return element_src === src_url_equal_anchor.href;
  }
  function is_empty(obj) {
    return Object.keys(obj).length === 0;
  }
  function subscribe(store, ...callbacks) {
    if (store == null) {
      for (const callback of callbacks) {
        callback(void 0);
      }
      return noop;
    }
    const unsub = store.subscribe(...callbacks);
    return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
  }
  function get_store_value(store) {
    let value;
    subscribe(store, (_) => value = _)();
    return value;
  }
  function component_subscribe(component, store, callback) {
    component.$$.on_destroy.push(subscribe(store, callback));
  }
  function create_slot(definition, ctx, $$scope, fn) {
    if (definition) {
      const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
      return definition[0](slot_ctx);
    }
  }
  function get_slot_context(definition, ctx, $$scope, fn) {
    return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;
  }
  function get_slot_changes(definition, $$scope, dirty, fn) {
    if (definition[2] && fn) {
      const lets = definition[2](fn(dirty));
      if ($$scope.dirty === void 0) {
        return lets;
      }
      if (typeof lets === "object") {
        const merged = [];
        const len = Math.max($$scope.dirty.length, lets.length);
        for (let i = 0; i < len; i += 1) {
          merged[i] = $$scope.dirty[i] | lets[i];
        }
        return merged;
      }
      return $$scope.dirty | lets;
    }
    return $$scope.dirty;
  }
  function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
    if (slot_changes) {
      const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
      slot.p(slot_context, slot_changes);
    }
  }
  function get_all_dirty_from_scope($$scope) {
    if ($$scope.ctx.length > 32) {
      const dirty = [];
      const length = $$scope.ctx.length / 32;
      for (let i = 0; i < length; i++) {
        dirty[i] = -1;
      }
      return dirty;
    }
    return -1;
  }
  function exclude_internal_props(props) {
    const result = {};
    for (const k in props) if (k[0] !== "$") result[k] = props[k];
    return result;
  }
  function compute_rest_props(props, keys) {
    const rest = {};
    keys = new Set(keys);
    for (const k in props) if (!keys.has(k) && k[0] !== "$") rest[k] = props[k];
    return rest;
  }
  function compute_slots(slots) {
    const result = {};
    for (const key in slots) {
      result[key] = true;
    }
    return result;
  }
  function set_store_value(store, ret, value) {
    store.set(value);
    return ret;
  }
  function action_destroyer(action_result) {
    return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;
  }
  function split_css_unit(value) {
    const split = typeof value === "string" && value.match(/^\s*(-?[\d.]+)([^\s]*)\s*$/);
    return split ? [parseFloat(split[1]), split[2] || "px"] : [
      /** @type {number} */
      value,
      "px"
    ];
  }
  const is_client = typeof window !== "undefined";
  let now = is_client ? () => window.performance.now() : () => Date.now();
  let raf = is_client ? (cb) => requestAnimationFrame(cb) : noop;
  const tasks = /* @__PURE__ */ new Set();
  function run_tasks(now2) {
    tasks.forEach((task) => {
      if (!task.c(now2)) {
        tasks.delete(task);
        task.f();
      }
    });
    if (tasks.size !== 0) raf(run_tasks);
  }
  function loop(callback) {
    let task;
    if (tasks.size === 0) raf(run_tasks);
    return {
      promise: new Promise((fulfill) => {
        tasks.add(task = { c: callback, f: fulfill });
      }),
      abort() {
        tasks.delete(task);
      }
    };
  }
  function append(target, node) {
    target.appendChild(node);
  }
  function get_root_for_style(node) {
    if (!node) return document;
    const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
    if (root && /** @type {ShadowRoot} */
    root.host) {
      return (
        /** @type {ShadowRoot} */
        root
      );
    }
    return node.ownerDocument;
  }
  function append_empty_stylesheet(node) {
    const style_element = element("style");
    style_element.textContent = "/* empty */";
    append_stylesheet(get_root_for_style(node), style_element);
    return style_element.sheet;
  }
  function append_stylesheet(node, style) {
    append(
      /** @type {Document} */
      node.head || node,
      style
    );
    return style.sheet;
  }
  function insert(target, node, anchor) {
    target.insertBefore(node, anchor || null);
  }
  function detach(node) {
    if (node.parentNode) {
      node.parentNode.removeChild(node);
    }
  }
  function destroy_each(iterations, detaching) {
    for (let i = 0; i < iterations.length; i += 1) {
      if (iterations[i]) iterations[i].d(detaching);
    }
  }
  function element(name) {
    return document.createElement(name);
  }
  function svg_element(name) {
    return document.createElementNS("http://www.w3.org/2000/svg", name);
  }
  function text(data) {
    return document.createTextNode(data);
  }
  function space() {
    return text(" ");
  }
  function empty() {
    return text("");
  }
  function listen(node, event, handler, options) {
    node.addEventListener(event, handler, options);
    return () => node.removeEventListener(event, handler, options);
  }
  function stop_propagation(fn) {
    return function(event) {
      event.stopPropagation();
      return fn.call(this, event);
    };
  }
  function attr(node, attribute, value) {
    if (value == null) node.removeAttribute(attribute);
    else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value);
  }
  const always_set_through_set_attribute = ["width", "height"];
  function set_attributes(node, attributes) {
    const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
    for (const key in attributes) {
      if (attributes[key] == null) {
        node.removeAttribute(key);
      } else if (key === "style") {
        node.style.cssText = attributes[key];
      } else if (key === "__value") {
        node.value = node[key] = attributes[key];
      } else if (descriptors[key] && descriptors[key].set && always_set_through_set_attribute.indexOf(key) === -1) {
        node[key] = attributes[key];
      } else {
        attr(node, key, attributes[key]);
      }
    }
  }
  function get_binding_group_value(group, __value, checked) {
    const value = /* @__PURE__ */ new Set();
    for (let i = 0; i < group.length; i += 1) {
      if (group[i].checked) value.add(group[i].__value);
    }
    if (!checked) {
      value.delete(__value);
    }
    return Array.from(value);
  }
  function init_binding_group(group) {
    let _inputs;
    return {
      /* push */
      p(...inputs) {
        _inputs = inputs;
        _inputs.forEach((input) => group.push(input));
      },
      /* remove */
      r() {
        _inputs.forEach((input) => group.splice(group.indexOf(input), 1));
      }
    };
  }
  function to_number(value) {
    return value === "" ? null : +value;
  }
  function children(element2) {
    return Array.from(element2.childNodes);
  }
  function set_data(text2, data) {
    data = "" + data;
    if (text2.data === data) return;
    text2.data = /** @type {string} */
    data;
  }
  function set_input_value(input, value) {
    input.value = value == null ? "" : value;
  }
  function set_style(node, key, value, important) {
    if (value == null) {
      node.style.removeProperty(key);
    } else {
      node.style.setProperty(key, value, "");
    }
  }
  function select_option(select, value, mounting) {
    for (let i = 0; i < select.options.length; i += 1) {
      const option = select.options[i];
      if (option.__value === value) {
        option.selected = true;
        return;
      }
    }
    if (!mounting || value !== void 0) {
      select.selectedIndex = -1;
    }
  }
  function select_options(select, value) {
    for (let i = 0; i < select.options.length; i += 1) {
      const option = select.options[i];
      option.selected = ~value.indexOf(option.__value);
    }
  }
  function select_value(select) {
    const selected_option = select.querySelector(":checked");
    return selected_option && selected_option.__value;
  }
  function select_multiple_value(select) {
    return [].map.call(select.querySelectorAll(":checked"), (option) => option.__value);
  }
  function toggle_class(element2, name, toggle) {
    element2.classList.toggle(name, !!toggle);
  }
  function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
    return new CustomEvent(type, { detail, bubbles, cancelable });
  }
  class HtmlTag {
    constructor(is_svg = false) {
      /**
       * @private
       * @default false
       */
      __publicField(this, "is_svg", false);
      /** parent for creating node */
      __publicField(this, "e");
      /** html tag nodes */
      __publicField(this, "n");
      /** target */
      __publicField(this, "t");
      /** anchor */
      __publicField(this, "a");
      this.is_svg = is_svg;
      this.e = this.n = null;
    }
    /**
     * @param {string} html
     * @returns {void}
     */
    c(html) {
      this.h(html);
    }
    /**
     * @param {string} html
     * @param {HTMLElement | SVGElement} target
     * @param {HTMLElement | SVGElement} anchor
     * @returns {void}
     */
    m(html, target, anchor = null) {
      if (!this.e) {
        if (this.is_svg)
          this.e = svg_element(
            /** @type {keyof SVGElementTagNameMap} */
            target.nodeName
          );
        else
          this.e = element(
            /** @type {keyof HTMLElementTagNameMap} */
            target.nodeType === 11 ? "TEMPLATE" : target.nodeName
          );
        this.t = target.tagName !== "TEMPLATE" ? target : (
          /** @type {HTMLTemplateElement} */
          target.content
        );
        this.c(html);
      }
      this.i(anchor);
    }
    /**
     * @param {string} html
     * @returns {void}
     */
    h(html) {
      this.e.innerHTML = html;
      this.n = Array.from(
        this.e.nodeName === "TEMPLATE" ? this.e.content.childNodes : this.e.childNodes
      );
    }
    /**
     * @returns {void} */
    i(anchor) {
      for (let i = 0; i < this.n.length; i += 1) {
        insert(this.t, this.n[i], anchor);
      }
    }
    /**
     * @param {string} html
     * @returns {void}
     */
    p(html) {
      this.d();
      this.h(html);
      this.i(this.a);
    }
    /**
     * @returns {void} */
    d() {
      this.n.forEach(detach);
    }
  }
  function get_custom_elements_slots(element2) {
    const result = {};
    element2.childNodes.forEach(
      /** @param {Element} node */
      (node) => {
        result[node.slot || "default"] = true;
      }
    );
    return result;
  }
  function construct_svelte_component(component, props) {
    return new component(props);
  }
  const managed_styles = /* @__PURE__ */ new Map();
  let active = 0;
  function hash(str) {
    let hash2 = 5381;
    let i = str.length;
    while (i--) hash2 = (hash2 << 5) - hash2 ^ str.charCodeAt(i);
    return hash2 >>> 0;
  }
  function create_style_information(doc, node) {
    const info = { stylesheet: append_empty_stylesheet(node), rules: {} };
    managed_styles.set(doc, info);
    return info;
  }
  function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
    const step2 = 16.666 / duration;
    let keyframes = "{\n";
    for (let p = 0; p <= 1; p += step2) {
      const t2 = a + (b - a) * ease(p);
      keyframes += p * 100 + `%{${fn(t2, 1 - t2)}}
`;
    }
    const rule = keyframes + `100% {${fn(b, 1 - b)}}
}`;
    const name = `__svelte_${hash(rule)}_${uid}`;
    const doc = get_root_for_style(node);
    const { stylesheet, rules } = managed_styles.get(doc) || create_style_information(doc, node);
    if (!rules[name]) {
      rules[name] = true;
      stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length);
    }
    const animation = node.style.animation || "";
    node.style.animation = `${animation ? `${animation}, ` : ""}${name} ${duration}ms linear ${delay}ms 1 both`;
    active += 1;
    return name;
  }
  function delete_rule(node, name) {
    const previous = (node.style.animation || "").split(", ");
    const next = previous.filter(
      name ? (anim) => anim.indexOf(name) < 0 : (anim) => anim.indexOf("__svelte") === -1
      // remove all Svelte animations
    );
    const deleted = previous.length - next.length;
    if (deleted) {
      node.style.animation = next.join(", ");
      active -= deleted;
      if (!active) clear_rules();
    }
  }
  function clear_rules() {
    raf(() => {
      if (active) return;
      managed_styles.forEach((info) => {
        const { ownerNode } = info.stylesheet;
        if (ownerNode) detach(ownerNode);
      });
      managed_styles.clear();
    });
  }
  function create_animation(node, from, fn, params) {
    if (!from) return noop;
    const to = node.getBoundingClientRect();
    if (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom)
      return noop;
    const {
      delay = 0,
      duration = 300,
      easing = identity,
      // @ts-ignore todo: should this be separated from destructuring? Or start/end added to public api and documentation?
      start: start_time = now() + delay,
      // @ts-ignore todo:
      end = start_time + duration,
      tick: tick2 = noop,
      css
    } = fn(node, { from, to }, params);
    let running = true;
    let started = false;
    let name;
    function start() {
      if (css) {
        name = create_rule(node, 0, 1, duration, delay, easing, css);
      }
      if (!delay) {
        started = true;
      }
    }
    function stop() {
      if (css) delete_rule(node, name);
      running = false;
    }
    loop((now2) => {
      if (!started && now2 >= start_time) {
        started = true;
      }
      if (started && now2 >= end) {
        tick2(1, 0);
        stop();
      }
      if (!running) {
        return false;
      }
      if (started) {
        const p = now2 - start_time;
        const t2 = 0 + 1 * easing(p / duration);
        tick2(t2, 1 - t2);
      }
      return true;
    });
    start();
    tick2(0, 1);
    return stop;
  }
  function fix_position(node) {
    const style = getComputedStyle(node);
    if (style.position !== "absolute" && style.position !== "fixed") {
      const { width, height } = style;
      const a = node.getBoundingClientRect();
      node.style.position = "absolute";
      node.style.width = width;
      node.style.height = height;
      add_transform(node, a);
    }
  }
  function add_transform(node, a) {
    const b = node.getBoundingClientRect();
    if (a.left !== b.left || a.top !== b.top) {
      const style = getComputedStyle(node);
      const transform = style.transform === "none" ? "" : style.transform;
      node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`;
    }
  }
  let current_component;
  function set_current_component(component) {
    current_component = component;
  }
  function get_current_component() {
    if (!current_component) throw new Error("Function called outside component initialization");
    return current_component;
  }
  function onMount(fn) {
    get_current_component().$$.on_mount.push(fn);
  }
  function afterUpdate(fn) {
    get_current_component().$$.after_update.push(fn);
  }
  function createEventDispatcher() {
    const component = get_current_component();
    return (type, detail, { cancelable = false } = {}) => {
      const callbacks = component.$$.callbacks[type];
      if (callbacks) {
        const event = custom_event(
          /** @type {string} */
          type,
          detail,
          { cancelable }
        );
        callbacks.slice().forEach((fn) => {
          fn.call(component, event);
        });
        return !event.defaultPrevented;
      }
      return true;
    };
  }
  function setContext(key, context) {
    get_current_component().$$.context.set(key, context);
    return context;
  }
  function getContext(key) {
    return get_current_component().$$.context.get(key);
  }
  function bubble(component, event) {
    const callbacks = component.$$.callbacks[event.type];
    if (callbacks) {
      callbacks.slice().forEach((fn) => fn.call(this, event));
    }
  }
  const dirty_components = [];
  const binding_callbacks = [];
  let render_callbacks = [];
  const flush_callbacks = [];
  const resolved_promise = /* @__PURE__ */ Promise.resolve();
  let update_scheduled = false;
  function schedule_update() {
    if (!update_scheduled) {
      update_scheduled = true;
      resolved_promise.then(flush);
    }
  }
  function tick() {
    schedule_update();
    return resolved_promise;
  }
  function add_render_callback(fn) {
    render_callbacks.push(fn);
  }
  function add_flush_callback(fn) {
    flush_callbacks.push(fn);
  }
  const seen_callbacks = /* @__PURE__ */ new Set();
  let flushidx = 0;
  function flush() {
    if (flushidx !== 0) {
      return;
    }
    const saved_component = current_component;
    do {
      try {
        while (flushidx < dirty_components.length) {
          const component = dirty_components[flushidx];
          flushidx++;
          set_current_component(component);
          update(component.$$);
        }
      } catch (e) {
        dirty_components.length = 0;
        flushidx = 0;
        throw e;
      }
      set_current_component(null);
      dirty_components.length = 0;
      flushidx = 0;
      while (binding_callbacks.length) binding_callbacks.pop()();
      for (let i = 0; i < render_callbacks.length; i += 1) {
        const callback = render_callbacks[i];
        if (!seen_callbacks.has(callback)) {
          seen_callbacks.add(callback);
          callback();
        }
      }
      render_callbacks.length = 0;
    } while (dirty_components.length);
    while (flush_callbacks.length) {
      flush_callbacks.pop()();
    }
    update_scheduled = false;
    seen_callbacks.clear();
    set_current_component(saved_component);
  }
  function update($$) {
    if ($$.fragment !== null) {
      $$.update();
      run_all($$.before_update);
      const dirty = $$.dirty;
      $$.dirty = [-1];
      $$.fragment && $$.fragment.p($$.ctx, dirty);
      $$.after_update.forEach(add_render_callback);
    }
  }
  function flush_render_callbacks(fns) {
    const filtered = [];
    const targets = [];
    render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
    targets.forEach((c) => c());
    render_callbacks = filtered;
  }
  let promise;
  function wait() {
    if (!promise) {
      promise = Promise.resolve();
      promise.then(() => {
        promise = null;
      });
    }
    return promise;
  }
  function dispatch(node, direction, kind) {
    node.dispatchEvent(custom_event(`${direction ? "intro" : "outro"}${kind}`));
  }
  const outroing = /* @__PURE__ */ new Set();
  let outros;
  function group_outros() {
    outros = {
      r: 0,
      c: [],
      p: outros
      // parent group
    };
  }
  function check_outros() {
    if (!outros.r) {
      run_all(outros.c);
    }
    outros = outros.p;
  }
  function transition_in(block, local) {
    if (block && block.i) {
      outroing.delete(block);
      block.i(local);
    }
  }
  function transition_out(block, local, detach2, callback) {
    if (block && block.o) {
      if (outroing.has(block)) return;
      outroing.add(block);
      outros.c.push(() => {
        outroing.delete(block);
        if (callback) {
          if (detach2) block.d(1);
          callback();
        }
      });
      block.o(local);
    } else if (callback) {
      callback();
    }
  }
  const null_transition = { duration: 0 };
  function create_in_transition(node, fn, params) {
    const options = { direction: "in" };
    let config2 = fn(node, params, options);
    let running = false;
    let animation_name;
    let task;
    let uid = 0;
    function cleanup() {
      if (animation_name) delete_rule(node, animation_name);
    }
    function go() {
      const {
        delay = 0,
        duration = 300,
        easing = identity,
        tick: tick2 = noop,
        css
      } = config2 || null_transition;
      if (css) animation_name = create_rule(node, 0, 1, duration, delay, easing, css, uid++);
      tick2(0, 1);
      const start_time = now() + delay;
      const end_time = start_time + duration;
      if (task) task.abort();
      running = true;
      add_render_callback(() => dispatch(node, true, "start"));
      task = loop((now2) => {
        if (running) {
          if (now2 >= end_time) {
            tick2(1, 0);
            dispatch(node, true, "end");
            cleanup();
            return running = false;
          }
          if (now2 >= start_time) {
            const t2 = easing((now2 - start_time) / duration);
            tick2(t2, 1 - t2);
          }
        }
        return running;
      });
    }
    let started = false;
    return {
      start() {
        if (started) return;
        started = true;
        delete_rule(node);
        if (is_function(config2)) {
          config2 = config2(options);
          wait().then(go);
        } else {
          go();
        }
      },
      invalidate() {
        started = false;
      },
      end() {
        if (running) {
          cleanup();
          running = false;
        }
      }
    };
  }
  function create_out_transition(node, fn, params) {
    const options = { direction: "out" };
    let config2 = fn(node, params, options);
    let running = true;
    let animation_name;
    const group = outros;
    group.r += 1;
    let original_inert_value;
    function go() {
      const {
        delay = 0,
        duration = 300,
        easing = identity,
        tick: tick2 = noop,
        css
      } = config2 || null_transition;
      if (css) animation_name = create_rule(node, 1, 0, duration, delay, easing, css);
      const start_time = now() + delay;
      const end_time = start_time + duration;
      add_render_callback(() => dispatch(node, false, "start"));
      if ("inert" in node) {
        original_inert_value = /** @type {HTMLElement} */
        node.inert;
        node.inert = true;
      }
      loop((now2) => {
        if (running) {
          if (now2 >= end_time) {
            tick2(0, 1);
            dispatch(node, false, "end");
            if (!--group.r) {
              run_all(group.c);
            }
            return false;
          }
          if (now2 >= start_time) {
            const t2 = easing((now2 - start_time) / duration);
            tick2(1 - t2, t2);
          }
        }
        return running;
      });
    }
    if (is_function(config2)) {
      wait().then(() => {
        config2 = config2(options);
        go();
      });
    } else {
      go();
    }
    return {
      end(reset) {
        if (reset && "inert" in node) {
          node.inert = original_inert_value;
        }
        if (reset && config2.tick) {
          config2.tick(1, 0);
        }
        if (running) {
          if (animation_name) delete_rule(node, animation_name);
          running = false;
        }
      }
    };
  }
  function create_bidirectional_transition(node, fn, params, intro) {
    const options = { direction: "both" };
    let config2 = fn(node, params, options);
    let t2 = intro ? 0 : 1;
    let running_program = null;
    let pending_program = null;
    let animation_name = null;
    let original_inert_value;
    function clear_animation() {
      if (animation_name) delete_rule(node, animation_name);
    }
    function init2(program, duration) {
      const d = (
        /** @type {Program['d']} */
        program.b - t2
      );
      duration *= Math.abs(d);
      return {
        a: t2,
        b: program.b,
        d,
        duration,
        start: program.start,
        end: program.start + duration,
        group: program.group
      };
    }
    function go(b) {
      const {
        delay = 0,
        duration = 300,
        easing = identity,
        tick: tick2 = noop,
        css
      } = config2 || null_transition;
      const program = {
        start: now() + delay,
        b
      };
      if (!b) {
        program.group = outros;
        outros.r += 1;
      }
      if ("inert" in node) {
        if (b) {
          if (original_inert_value !== void 0) {
            node.inert = original_inert_value;
          }
        } else {
          original_inert_value = /** @type {HTMLElement} */
          node.inert;
          node.inert = true;
        }
      }
      if (running_program || pending_program) {
        pending_program = program;
      } else {
        if (css) {
          clear_animation();
          animation_name = create_rule(node, t2, b, duration, delay, easing, css);
        }
        if (b) tick2(0, 1);
        running_program = init2(program, duration);
        add_render_callback(() => dispatch(node, b, "start"));
        loop((now2) => {
          if (pending_program && now2 > pending_program.start) {
            running_program = init2(pending_program, duration);
            pending_program = null;
            dispatch(node, running_program.b, "start");
            if (css) {
              clear_animation();
              animation_name = create_rule(
                node,
                t2,
                running_program.b,
                running_program.duration,
                0,
                easing,
                config2.css
              );
            }
          }
          if (running_program) {
            if (now2 >= running_program.end) {
              tick2(t2 = running_program.b, 1 - t2);
              dispatch(node, running_program.b, "end");
              if (!pending_program) {
                if (running_program.b) {
                  clear_animation();
                } else {
                  if (!--running_program.group.r) run_all(running_program.group.c);
                }
              }
              running_program = null;
            } else if (now2 >= running_program.start) {
              const p = now2 - running_program.start;
              t2 = running_program.a + running_program.d * easing(p / running_program.duration);
              tick2(t2, 1 - t2);
            }
          }
          return !!(running_program || pending_program);
        });
      }
    }
    return {
      run(b) {
        if (is_function(config2)) {
          wait().then(() => {
            const opts = { direction: b ? "in" : "out" };
            config2 = config2(opts);
            go(b);
          });
        } else {
          go(b);
        }
      },
      end() {
        clear_animation();
        running_program = pending_program = null;
      }
    };
  }
  function handle_promise(promise2, info) {
    const token = info.token = {};
    function update2(type, index, key, value) {
      if (info.token !== token) return;
      info.resolved = value;
      let child_ctx = info.ctx;
      if (key !== void 0) {
        child_ctx = child_ctx.slice();
        child_ctx[key] = value;
      }
      const block = type && (info.current = type)(child_ctx);
      let needs_flush = false;
      if (info.block) {
        if (info.blocks) {
          info.blocks.forEach((block2, i) => {
            if (i !== index && block2) {
              group_outros();
              transition_out(block2, 1, 1, () => {
                if (info.blocks[i] === block2) {
                  info.blocks[i] = null;
                }
              });
              check_outros();
            }
          });
        } else {
          info.block.d(1);
        }
        block.c();
        transition_in(block, 1);
        block.m(info.mount(), info.anchor);
        needs_flush = true;
      }
      info.block = block;
      if (info.blocks) info.blocks[index] = block;
      if (needs_flush) {
        flush();
      }
    }
    if (is_promise(promise2)) {
      const current_component2 = get_current_component();
      promise2.then(
        (value) => {
          set_current_component(current_component2);
          update2(info.then, 1, info.value, value);
          set_current_component(null);
        },
        (error) => {
          set_current_component(current_component2);
          update2(info.catch, 2, info.error, error);
          set_current_component(null);
          if (!info.hasCatch) {
            throw error;
          }
        }
      );
      if (info.current !== info.pending) {
        update2(info.pending, 0);
        return true;
      }
    } else {
      if (info.current !== info.then) {
        update2(info.then, 1, info.value, promise2);
        return true;
      }
      info.resolved = /** @type {T} */
      promise2;
    }
  }
  function update_await_block_branch(info, ctx, dirty) {
    const child_ctx = ctx.slice();
    const { resolved } = info;
    if (info.current === info.then) {
      child_ctx[info.value] = resolved;
    }
    if (info.current === info.catch) {
      child_ctx[info.error] = resolved;
    }
    info.block.p(child_ctx, dirty);
  }
  function ensure_array_like(array_like_or_iterator) {
    return (array_like_or_iterator == null ? void 0 : array_like_or_iterator.length) !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator);
  }
  function outro_and_destroy_block(block, lookup) {
    transition_out(block, 1, 1, () => {
      lookup.delete(block.key);
    });
  }
  function fix_and_outro_and_destroy_block(block, lookup) {
    block.f();
    outro_and_destroy_block(block, lookup);
  }
  function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block2, next, get_context) {
    let o = old_blocks.length;
    let n = list.length;
    let i = o;
    const old_indexes = {};
    while (i--) old_indexes[old_blocks[i].key] = i;
    const new_blocks = [];
    const new_lookup = /* @__PURE__ */ new Map();
    const deltas = /* @__PURE__ */ new Map();
    const updates = [];
    i = n;
    while (i--) {
      const child_ctx = get_context(ctx, list, i);
      const key = get_key(child_ctx);
      let block = lookup.get(key);
      if (!block) {
        block = create_each_block2(key, child_ctx);
        block.c();
      } else {
        updates.push(() => block.p(child_ctx, dirty));
      }
      new_lookup.set(key, new_blocks[i] = block);
      if (key in old_indexes) deltas.set(key, Math.abs(i - old_indexes[key]));
    }
    const will_move = /* @__PURE__ */ new Set();
    const did_move = /* @__PURE__ */ new Set();
    function insert2(block) {
      transition_in(block, 1);
      block.m(node, next);
      lookup.set(block.key, block);
      next = block.first;
      n--;
    }
    while (o && n) {
      const new_block = new_blocks[n - 1];
      const old_block = old_blocks[o - 1];
      const new_key = new_block.key;
      const old_key = old_block.key;
      if (new_block === old_block) {
        next = new_block.first;
        o--;
        n--;
      } else if (!new_lookup.has(old_key)) {
        destroy(old_block, lookup);
        o--;
      } else if (!lookup.has(new_key) || will_move.has(new_key)) {
        insert2(new_block);
      } else if (did_move.has(old_key)) {
        o--;
      } else if (deltas.get(new_key) > deltas.get(old_key)) {
        did_move.add(new_key);
        insert2(new_block);
      } else {
        will_move.add(old_key);
        o--;
      }
    }
    while (o--) {
      const old_block = old_blocks[o];
      if (!new_lookup.has(old_block.key)) destroy(old_block, lookup);
    }
    while (n) insert2(new_blocks[n - 1]);
    run_all(updates);
    return new_blocks;
  }
  function get_spread_update(levels, updates) {
    const update2 = {};
    const to_null_out = {};
    const accounted_for = { $$scope: 1 };
    let i = levels.length;
    while (i--) {
      const o = levels[i];
      const n = updates[i];
      if (n) {
        for (const key in o) {
          if (!(key in n)) to_null_out[key] = 1;
        }
        for (const key in n) {
          if (!accounted_for[key]) {
            update2[key] = n[key];
            accounted_for[key] = 1;
          }
        }
        levels[i] = n;
      } else {
        for (const key in o) {
          accounted_for[key] = 1;
        }
      }
    }
    for (const key in to_null_out) {
      if (!(key in update2)) update2[key] = void 0;
    }
    return update2;
  }
  function get_spread_object(spread_props) {
    return typeof spread_props === "object" && spread_props !== null ? spread_props : {};
  }
  function bind(component, name, callback) {
    const index = component.$$.props[name];
    if (index !== void 0) {
      component.$$.bound[index] = callback;
      callback(component.$$.ctx[index]);
    }
  }
  function create_component(block) {
    block && block.c();
  }
  function mount_component(component, target, anchor) {
    const { fragment, after_update } = component.$$;
    fragment && fragment.m(target, anchor);
    add_render_callback(() => {
      const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
      if (component.$$.on_destroy) {
        component.$$.on_destroy.push(...new_on_destroy);
      } else {
        run_all(new_on_destroy);
      }
      component.$$.on_mount = [];
    });
    after_update.forEach(add_render_callback);
  }
  function destroy_component(component, detaching) {
    const $$ = component.$$;
    if ($$.fragment !== null) {
      flush_render_callbacks($$.after_update);
      run_all($$.on_destroy);
      $$.fragment && $$.fragment.d(detaching);
      $$.on_destroy = $$.fragment = null;
      $$.ctx = [];
    }
  }
  function make_dirty(component, i) {
    if (component.$$.dirty[0] === -1) {
      dirty_components.push(component);
      schedule_update();
      component.$$.dirty.fill(0);
    }
    component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
  }
  function init(component, options, instance2, create_fragment2, not_equal, props, append_styles = null, dirty = [-1]) {
    const parent_component = current_component;
    set_current_component(component);
    const $$ = component.$$ = {
      fragment: null,
      ctx: [],
      // state
      props,
      update: noop,
      not_equal,
      bound: blank_object(),
      // lifecycle
      on_mount: [],
      on_destroy: [],
      on_disconnect: [],
      before_update: [],
      after_update: [],
      context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
      // everything else
      callbacks: blank_object(),
      dirty,
      skip_bound: false,
      root: options.target || parent_component.$$.root
    };
    append_styles && append_styles($$.root);
    let ready = false;
    $$.ctx = instance2 ? instance2(component, options.props || {}, (i, ret, ...rest) => {
      const value = rest.length ? rest[0] : ret;
      if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
        if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value);
        if (ready) make_dirty(component, i);
      }
      return ret;
    }) : [];
    $$.update();
    ready = true;
    run_all($$.before_update);
    $$.fragment = create_fragment2 ? create_fragment2($$.ctx) : false;
    if (options.target) {
      if (options.hydrate) {
        const nodes = children(options.target);
        $$.fragment && $$.fragment.l(nodes);
        nodes.forEach(detach);
      } else {
        $$.fragment && $$.fragment.c();
      }
      if (options.intro) transition_in(component.$$.fragment);
      mount_component(component, options.target, options.anchor);
      flush();
    }
    set_current_component(parent_component);
  }
  let SvelteElement;
  if (typeof HTMLElement === "function") {
    SvelteElement = class extends HTMLElement {
      constructor($$componentCtor, $$slots, use_shadow_dom) {
        super();
        /** The Svelte component constructor */
        __publicField(this, "$$ctor");
        /** Slots */
        __publicField(this, "$$s");
        /** The Svelte component instance */
        __publicField(this, "$$c");
        /** Whether or not the custom element is connected */
        __publicField(this, "$$cn", false);
        /** Component props data */
        __publicField(this, "$$d", {});
        /** `true` if currently in the process of reflecting component props back to attributes */
        __publicField(this, "$$r", false);
        /** @type {Record<string, CustomElementPropDefinition>} Props definition (name, reflected, type etc) */
        __publicField(this, "$$p_d", {});
        /** @type {Record<string, Function[]>} Event listeners */
        __publicField(this, "$$l", {});
        /** @type {Map<Function, Function>} Event listener unsubscribe functions */
        __publicField(this, "$$l_u", /* @__PURE__ */ new Map());
        this.$$ctor = $$componentCtor;
        this.$$s = $$slots;
        if (use_shadow_dom) {
          this.attachShadow({ mode: "open" });
        }
      }
      addEventListener(type, listener, options) {
        this.$$l[type] = this.$$l[type] || [];
        this.$$l[type].push(listener);
        if (this.$$c) {
          const unsub = this.$$c.$on(type, listener);
          this.$$l_u.set(listener, unsub);
        }
        super.addEventListener(type, listener, options);
      }
      removeEventListener(type, listener, options) {
        super.removeEventListener(type, listener, options);
        if (this.$$c) {
          const unsub = this.$$l_u.get(listener);
          if (unsub) {
            unsub();
            this.$$l_u.delete(listener);
          }
        }
      }
      async connectedCallback() {
        this.$$cn = true;
        if (!this.$$c) {
          let create_slot2 = function(name) {
            return () => {
              let node;
              const obj = {
                c: function create() {
                  node = element("slot");
                  if (name !== "default") {
                    attr(node, "name", name);
                  }
                },
                /**
                 * @param {HTMLElement} target
                 * @param {HTMLElement} [anchor]
                 */
                m: function mount(target, anchor) {
                  insert(target, node, anchor);
                },
                d: function destroy(detaching) {
                  if (detaching) {
                    detach(node);
                  }
                }
              };
              return obj;
            };
          };
          await Promise.resolve();
          if (!this.$$cn || this.$$c) {
            return;
          }
          const $$slots = {};
          const existing_slots = get_custom_elements_slots(this);
          for (const name of this.$$s) {
            if (name in existing_slots) {
              $$slots[name] = [create_slot2(name)];
            }
          }
          for (const attribute of this.attributes) {
            const name = this.$$g_p(attribute.name);
            if (!(name in this.$$d)) {
              this.$$d[name] = get_custom_element_value(name, attribute.value, this.$$p_d, "toProp");
            }
          }
          for (const key in this.$$p_d) {
            if (!(key in this.$$d) && this[key] !== void 0) {
              this.$$d[key] = this[key];
              delete this[key];
            }
          }
          this.$$c = new this.$$ctor({
            target: this.shadowRoot || this,
            props: {
              ...this.$$d,
              $$slots,
              $$scope: {
                ctx: []
              }
            }
          });
          const reflect_attributes = () => {
            this.$$r = true;
            for (const key in this.$$p_d) {
              this.$$d[key] = this.$$c.$$.ctx[this.$$c.$$.props[key]];
              if (this.$$p_d[key].reflect) {
                const attribute_value = get_custom_element_value(
                  key,
                  this.$$d[key],
                  this.$$p_d,
                  "toAttribute"
                );
                if (attribute_value == null) {
                  this.removeAttribute(this.$$p_d[key].attribute || key);
                } else {
                  this.setAttribute(this.$$p_d[key].attribute || key, attribute_value);
                }
              }
            }
            this.$$r = false;
          };
          this.$$c.$$.after_update.push(reflect_attributes);
          reflect_attributes();
          for (const type in this.$$l) {
            for (const listener of this.$$l[type]) {
              const unsub = this.$$c.$on(type, listener);
              this.$$l_u.set(listener, unsub);
            }
          }
          this.$$l = {};
        }
      }
      // We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte
      // and setting attributes through setAttribute etc, this is helpful
      attributeChangedCallback(attr2, _oldValue, newValue) {
        var _a;
        if (this.$$r) return;
        attr2 = this.$$g_p(attr2);
        this.$$d[attr2] = get_custom_element_value(attr2, newValue, this.$$p_d, "toProp");
        (_a = this.$$c) == null ? void 0 : _a.$set({ [attr2]: this.$$d[attr2] });
      }
      disconnectedCallback() {
        this.$$cn = false;
        Promise.resolve().then(() => {
          if (!this.$$cn && this.$$c) {
            this.$$c.$destroy();
            this.$$c = void 0;
          }
        });
      }
      $$g_p(attribute_name) {
        return Object.keys(this.$$p_d).find(
          (key) => this.$$p_d[key].attribute === attribute_name || !this.$$p_d[key].attribute && key.toLowerCase() === attribute_name
        ) || attribute_name;
      }
    };
  }
  function get_custom_element_value(prop, value, props_definition, transform) {
    var _a;
    const type = (_a = props_definition[prop]) == null ? void 0 : _a.type;
    value = type === "Boolean" && typeof value !== "boolean" ? value != null : value;
    if (!transform || !props_definition[prop]) {
      return value;
    } else if (transform === "toAttribute") {
      switch (type) {
        case "Object":
        case "Array":
          return value == null ? null : JSON.stringify(value);
        case "Boolean":
          return value ? "" : null;
        case "Number":
          return value == null ? null : value;
        default:
          return value;
      }
    } else {
      switch (type) {
        case "Object":
        case "Array":
          return value && JSON.parse(value);
        case "Boolean":
          return value;
        case "Number":
          return value != null ? +value : value;
        default:
          return value;
      }
    }
  }
  function create_custom_element(Component, props_definition, slots, accessors, use_shadow_dom, extend) {
    let Class = class extends SvelteElement {
      constructor() {
        super(Component, slots, use_shadow_dom);
        this.$$p_d = props_definition;
      }
      static get observedAttributes() {
        return Object.keys(props_definition).map(
          (key) => (props_definition[key].attribute || key).toLowerCase()
        );
      }
    };
    Object.keys(props_definition).forEach((prop) => {
      Object.defineProperty(Class.prototype, prop, {
        get() {
          return this.$$c && prop in this.$$c ? this.$$c[prop] : this.$$d[prop];
        },
        set(value) {
          var _a;
          value = get_custom_element_value(prop, value, props_definition);
          this.$$d[prop] = value;
          (_a = this.$$c) == null ? void 0 : _a.$set({ [prop]: value });
        }
      });
    });
    accessors.forEach((accessor) => {
      Object.defineProperty(Class.prototype, accessor, {
        get() {
          var _a;
          return (_a = this.$$c) == null ? void 0 : _a[accessor];
        }
      });
    });
    if (extend) {
      Class = extend(Class);
    }
    Component.element = /** @type {any} */
    Class;
    return Class;
  }
  class SvelteComponent {
    constructor() {
      /**
       * ### PRIVATE API
       *
       * Do not use, may change at any time
       *
       * @type {any}
       */
      __publicField(this, "$$");
      /**
       * ### PRIVATE API
       *
       * Do not use, may change at any time
       *
       * @type {any}
       */
      __publicField(this, "$$set");
    }
    /** @returns {void} */
    $destroy() {
      destroy_component(this, 1);
      this.$destroy = noop;
    }
    /**
     * @template {Extract<keyof Events, string>} K
     * @param {K} type
     * @param {((e: Events[K]) => void) | null | undefined} callback
     * @returns {() => void}
     */
    $on(type, callback) {
      if (!is_function(callback)) {
        return noop;
      }
      const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
      callbacks.push(callback);
      return () => {
        const index = callbacks.indexOf(callback);
        if (index !== -1) callbacks.splice(index, 1);
      };
    }
    /**
     * @param {Partial<Props>} props
     * @returns {void}
     */
    $set(props) {
      if (this.$$set && !is_empty(props)) {
        this.$$.skip_bound = true;
        this.$$set(props);
        this.$$.skip_bound = false;
      }
    }
  }
  const PUBLIC_VERSION = "4";
  if (typeof window !== "undefined")
    (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(PUBLIC_VERSION);
  const subscriber_queue = [];
  function readable(value, start) {
    return {
      subscribe: writable(value, start).subscribe
    };
  }
  function writable(value, start = noop) {
    let stop;
    const subscribers = /* @__PURE__ */ new Set();
    function set(new_value) {
      if (safe_not_equal(value, new_value)) {
        value = new_value;
        if (stop) {
          const run_queue = !subscriber_queue.length;
          for (const subscriber of subscribers) {
            subscriber[1]();
            subscriber_queue.push(subscriber, value);
          }
          if (run_queue) {
            for (let i = 0; i < subscriber_queue.length; i += 2) {
              subscriber_queue[i][0](subscriber_queue[i + 1]);
            }
            subscriber_queue.length = 0;
          }
        }
      }
    }
    function update2(fn) {
      set(fn(value));
    }
    function subscribe2(run2, invalidate = noop) {
      const subscriber = [run2, invalidate];
      subscribers.add(subscriber);
      if (subscribers.size === 1) {
        stop = start(set, update2) || noop;
      }
      run2(value);
      return () => {
        subscribers.delete(subscriber);
        if (subscribers.size === 0 && stop) {
          stop();
          stop = null;
        }
      };
    }
    return { set, update: update2, subscribe: subscribe2 };
  }
  function derived(stores2, fn, initial_value) {
    const single = !Array.isArray(stores2);
    const stores_array = single ? [stores2] : stores2;
    if (!stores_array.every(Boolean)) {
      throw new Error("derived() expects stores as input, got a falsy value");
    }
    const auto = fn.length < 2;
    return readable(initial_value, (set, update2) => {
      let started = false;
      const values = [];
      let pending = 0;
      let cleanup = noop;
      const sync = () => {
        if (pending) {
          return;
        }
        cleanup();
        const result = fn(single ? values[0] : values, set, update2);
        if (auto) {
          set(result);
        } else {
          cleanup = is_function(result) ? result : noop;
        }
      };
      const unsubscribers = stores_array.map(
        (store, i) => subscribe(
          store,
          (value) => {
            values[i] = value;
            pending &= ~(1 << i);
            if (started) {
              sync();
            }
          },
          () => {
            pending |= 1 << i;
          }
        )
      );
      started = true;
      sync();
      return function stop() {
        run_all(unsubscribers);
        cleanup();
        started = false;
      };
    });
  }
  function readonly(store) {
    return {
      subscribe: store.subscribe.bind(store)
    };
  }
  const DRAWER_STORE_KEY = "drawerStore";
  function initializeDrawerStore() {
    const drawerStore = drawerService();
    return setContext(DRAWER_STORE_KEY, drawerStore);
  }
  function drawerService() {
    const { subscribe: subscribe2, set, update: update2 } = writable({});
    return {
      subscribe: subscribe2,
      set,
      update: update2,
      /** Open the drawer. */
      open: (newSettings) => update2(() => {
        return { open: true, ...newSettings };
      }),
      /** Close the drawer. */
      close: () => update2((d) => {
        d.open = false;
        return d;
      })
    };
  }
  const MODAL_STORE_KEY = "modalStore";
  function getModalStore() {
    const modalStore = getContext(MODAL_STORE_KEY);
    if (!modalStore)
      throw new Error("modalStore is not initialized. Please ensure that `initializeStores()` is invoked in the root layout file of this app!");
    return modalStore;
  }
  function initializeModalStore() {
    const modalStore = modalService();
    return setContext(MODAL_STORE_KEY, modalStore);
  }
  function modalService() {
    const { subscribe: subscribe2, set, update: update2 } = writable([]);
    return {
      subscribe: subscribe2,
      set,
      update: update2,
      /** Append to end of queue. */
      trigger: (modal) => update2((mStore) => {
        mStore.push(modal);
        return mStore;
      }),
      /**  Remove first item in queue. */
      close: () => update2((mStore) => {
        if (mStore.length > 0)
          mStore.shift();
        return mStore;
      }),
      /** Remove all items from queue. */
      clear: () => set([])
    };
  }
  const toastDefaults = { message: "Missing Toast Message", autohide: true, timeout: 5e3 };
  const TOAST_STORE_KEY = "toastStore";
  function initializeToastStore() {
    const toastStore = toastService();
    return setContext(TOAST_STORE_KEY, toastStore);
  }
  function randomUUID() {
    const random = Math.random();
    return Number(random).toString(32);
  }
  function toastService() {
    const { subscribe: subscribe2, set, update: update2 } = writable([]);
    const close = (id) => update2((tStore) => {
      if (tStore.length > 0) {
        const index = tStore.findIndex((t2) => t2.id === id);
        const selectedToast = tStore[index];
        if (selectedToast) {
          if (selectedToast.callback)
            selectedToast.callback({ id, status: "closed" });
          if (selectedToast.timeoutId)
            clearTimeout(selectedToast.timeoutId);
          tStore.splice(index, 1);
        }
      }
      return tStore;
    });
    function handleAutoHide(toast) {
      if (toast.autohide === true) {
        return setTimeout(() => {
          close(toast.id);
        }, toast.timeout);
      }
    }
    return {
      subscribe: subscribe2,
      close,
      /** Add a new toast to the queue. */
      trigger: (toast) => {
        const id = randomUUID();
        update2((tStore) => {
          if (toast && toast.callback)
            toast.callback({ id, status: "queued" });
          if (toast.hideDismiss)
            toast.autohide = true;
          const tMerged = { ...toastDefaults, ...toast, id };
          tMerged.timeoutId = handleAutoHide(tMerged);
          tStore.push(tMerged);
          return tStore;
        });
        return id;
      },
      /** Remain visible on hover */
      freeze: (index) => update2((tStore) => {
        if (tStore.length > 0)
          clearTimeout(tStore[index].timeoutId);
        return tStore;
      }),
      /** Cancel remain visible on leave */
      unfreeze: (index) => update2((tStore) => {
        if (tStore.length > 0)
          tStore[index].timeoutId = handleAutoHide(tStore[index]);
        return tStore;
      }),
      /** Remove all toasts from queue */
      clear: () => set([])
    };
  }
  function initializeStores() {
    initializeModalStore();
    initializeToastStore();
    initializeDrawerStore();
  }
  const stores = {};
  function getStorage(type) {
    return type === "local" ? localStorage : sessionStorage;
  }
  function localStorageStore(key, initialValue, options) {
    const serializer = JSON;
    const storageType = "local";
    function updateStorage(key2, value) {
      getStorage(storageType).setItem(key2, serializer.stringify(value));
    }
    if (!stores[key]) {
      const store = writable(initialValue, (set2) => {
        const json = getStorage(storageType).getItem(key);
        if (json) {
          set2(serializer.parse(json));
        }
        {
          const handleStorage = (event) => {
            if (event.key === key)
              set2(event.newValue ? serializer.parse(event.newValue) : null);
          };
          window.addEventListener("storage", handleStorage);
          return () => window.removeEventListener("storage", handleStorage);
        }
      });
      const { subscribe: subscribe2, set } = store;
      stores[key] = {
        set(value) {
          updateStorage(key, value);
          set(value);
        },
        update(updater) {
          const value = updater(get_store_value(store));
          updateStorage(key, value);
          set(value);
        },
        subscribe: subscribe2
      };
    }
    return stores[key];
  }
  localStorageStore("modeOsPrefers", false);
  localStorageStore("modeUserPrefers", void 0);
  localStorageStore("modeCurrent", false);
  const reducedMotionQuery = "(prefers-reduced-motion: reduce)";
  function prefersReducedMotion() {
    return window.matchMedia(reducedMotionQuery).matches;
  }
  const prefersReducedMotionStore = readable(prefersReducedMotion(), (set) => {
    {
      const setReducedMotion = (event) => {
        set(event.matches);
      };
      const mediaQueryList = window.matchMedia(reducedMotionQuery);
      mediaQueryList.addEventListener("change", setReducedMotion);
      return () => {
        mediaQueryList.removeEventListener("change", setReducedMotion);
      };
    }
  });
  function focusTrap(node, enabled) {
    const elemWhitelist = 'a[href]:not([tabindex="-1"]), button:not([tabindex="-1"]), input:not([tabindex="-1"]), textarea:not([tabindex="-1"]), select:not([tabindex="-1"]), details:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"])';
    let elemFirst;
    let elemLast;
    function onFirstElemKeydown(e) {
      if (e.shiftKey && e.code === "Tab") {
        e.preventDefault();
        elemLast.focus();
      }
    }
    function onLastElemKeydown(e) {
      if (!e.shiftKey && e.code === "Tab") {
        e.preventDefault();
        elemFirst.focus();
      }
    }
    const sortByTabIndex = (focusableElems) => {
      return focusableElems.filter((elem) => elem.tabIndex >= 0).sort((a, b) => {
        if (a.tabIndex === 0 && b.tabIndex > 0)
          return 1;
        else if (a.tabIndex > 0 && b.tabIndex === 0)
          return -1;
        else
          return a.tabIndex - b.tabIndex;
      });
    };
    const getFocusTrapTarget = (elemFirst2) => {
      const focusindexElements = [...node.querySelectorAll("[data-focusindex]")];
      if (!focusindexElements || focusindexElements.length === 0)
        return elemFirst2;
      return focusindexElements.sort((a, b) => {
        return +a.dataset.focusindex - +b.dataset.focusindex;
      })[0] || elemFirst2;
    };
    const onScanElements = (fromObserver) => {
      if (enabled === false)
        return;
      const focusableElems = sortByTabIndex(Array.from(node.querySelectorAll(elemWhitelist)));
      if (focusableElems.length) {
        elemFirst = focusableElems[0];
        elemLast = focusableElems[focusableElems.length - 1];
        if (!fromObserver)
          getFocusTrapTarget(elemFirst).focus();
        elemFirst.addEventListener("keydown", onFirstElemKeydown);
        elemLast.addEventListener("keydown", onLastElemKeydown);
      }
    };
    onScanElements(false);
    function onCleanUp() {
      if (elemFirst)
        elemFirst.removeEventListener("keydown", onFirstElemKeydown);
      if (elemLast)
        elemLast.removeEventListener("keydown", onLastElemKeydown);
    }
    const onObservationChange = (mutationRecords, observer3) => {
      if (mutationRecords.length) {
        onCleanUp();
        onScanElements(true);
      }
      return observer3;
    };
    const observer2 = new MutationObserver(onObservationChange);
    observer2.observe(node, { childList: true, subtree: true });
    return {
      update(newArgs) {
        enabled = newArgs;
        newArgs ? onScanElements(false) : onCleanUp();
      },
      destroy() {
        onCleanUp();
        observer2.disconnect();
      }
    };
  }
  function cubicOut(t2) {
    const f = t2 - 1;
    return f * f * f + 1;
  }
  function fade(node, { delay = 0, duration = 400, easing = identity } = {}) {
    const o = +getComputedStyle(node).opacity;
    return {
      delay,
      duration,
      easing,
      css: (t2) => `opacity: ${t2 * o}`
    };
  }
  function fly(node, { delay = 0, duration = 400, easing = cubicOut, x = 0, y = 0, opacity = 0 } = {}) {
    const style = getComputedStyle(node);
    const target_opacity = +style.opacity;
    const transform = style.transform === "none" ? "" : style.transform;
    const od = target_opacity * (1 - opacity);
    const [xValue, xUnit] = split_css_unit(x);
    const [yValue, yUnit] = split_css_unit(y);
    return {
      delay,
      duration,
      easing,
      css: (t2, u) => `
			transform: ${transform} translate(${(1 - t2) * xValue}${xUnit}, ${(1 - t2) * yValue}${yUnit});
			opacity: ${target_opacity - od * u}`
    };
  }
  function slide(node, { delay = 0, duration = 400, easing = cubicOut, axis = "y" } = {}) {
    const style = getComputedStyle(node);
    const opacity = +style.opacity;
    const primary_property = axis === "y" ? "height" : "width";
    const primary_property_value = parseFloat(style[primary_property]);
    const secondary_properties = axis === "y" ? ["top", "bottom"] : ["left", "right"];
    const capitalized_secondary_properties = secondary_properties.map(
      (e) => `${e[0].toUpperCase()}${e.slice(1)}`
    );
    const padding_start_value = parseFloat(style[`padding${capitalized_secondary_properties[0]}`]);
    const padding_end_value = parseFloat(style[`padding${capitalized_secondary_properties[1]}`]);
    const margin_start_value = parseFloat(style[`margin${capitalized_secondary_properties[0]}`]);
    const margin_end_value = parseFloat(style[`margin${capitalized_secondary_properties[1]}`]);
    const border_width_start_value = parseFloat(
      style[`border${capitalized_secondary_properties[0]}Width`]
    );
    const border_width_end_value = parseFloat(
      style[`border${capitalized_secondary_properties[1]}Width`]
    );
    return {
      delay,
      duration,
      easing,
      css: (t2) => `overflow: hidden;opacity: ${Math.min(t2 * 20, 1) * opacity};${primary_property}: ${t2 * primary_property_value}px;padding-${secondary_properties[0]}: ${t2 * padding_start_value}px;padding-${secondary_properties[1]}: ${t2 * padding_end_value}px;margin-${secondary_properties[0]}: ${t2 * margin_start_value}px;margin-${secondary_properties[1]}: ${t2 * margin_end_value}px;border-${secondary_properties[0]}-width: ${t2 * border_width_start_value}px;border-${secondary_properties[1]}-width: ${t2 * border_width_end_value}px;`
    };
  }
  function scale(node, { delay = 0, duration = 400, easing = cubicOut, start = 0, opacity = 0 } = {}) {
    const style = getComputedStyle(node);
    const target_opacity = +style.opacity;
    const transform = style.transform === "none" ? "" : style.transform;
    const sd = 1 - start;
    const od = target_opacity * (1 - opacity);
    return {
      delay,
      duration,
      easing,
      css: (_t, u) => `
			transform: ${transform} scale(${1 - sd * u});
			opacity: ${target_opacity - od * u}
		`
    };
  }
  function dynamicTransition(node, dynParams) {
    const { transition, params, enabled } = dynParams;
    if (enabled)
      return transition(node, params);
    if ("duration" in params)
      return transition(node, { duration: 0 });
    return { duration: 0 };
  }
  const get_headline_slot_changes = (dirty) => ({});
  const get_headline_slot_context = (ctx) => ({});
  const get_trail_slot_changes$2 = (dirty) => ({});
  const get_trail_slot_context$2 = (ctx) => ({});
  const get_lead_slot_changes$2 = (dirty) => ({});
  const get_lead_slot_context$2 = (ctx) => ({});
  function create_if_block_2$7(ctx) {
    let div;
    let div_class_value;
    let current;
    const lead_slot_template = (
      /*#slots*/
      ctx[22].lead
    );
    const lead_slot = create_slot(
      lead_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      get_lead_slot_context$2
    );
    return {
      c() {
        div = element("div");
        if (lead_slot) lead_slot.c();
        attr(div, "class", div_class_value = "app-bar-slot-lead " + /*classesSlotLead*/
        ctx[4]);
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (lead_slot) {
          lead_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (lead_slot) {
          if (lead_slot.p && (!current || dirty & /*$$scope*/
          2097152)) {
            update_slot_base(
              lead_slot,
              lead_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                lead_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                get_lead_slot_changes$2
              ),
              get_lead_slot_context$2
            );
          }
        }
        if (!current || dirty & /*classesSlotLead*/
        16 && div_class_value !== (div_class_value = "app-bar-slot-lead " + /*classesSlotLead*/
        ctx2[4])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(lead_slot, local);
        current = true;
      },
      o(local) {
        transition_out(lead_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (lead_slot) lead_slot.d(detaching);
      }
    };
  }
  function create_if_block_1$9(ctx) {
    let div;
    let div_class_value;
    let current;
    const trail_slot_template = (
      /*#slots*/
      ctx[22].trail
    );
    const trail_slot = create_slot(
      trail_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      get_trail_slot_context$2
    );
    return {
      c() {
        div = element("div");
        if (trail_slot) trail_slot.c();
        attr(div, "class", div_class_value = "app-bar-slot-trail " + /*classesSlotTrail*/
        ctx[2]);
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (trail_slot) {
          trail_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (trail_slot) {
          if (trail_slot.p && (!current || dirty & /*$$scope*/
          2097152)) {
            update_slot_base(
              trail_slot,
              trail_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                trail_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                get_trail_slot_changes$2
              ),
              get_trail_slot_context$2
            );
          }
        }
        if (!current || dirty & /*classesSlotTrail*/
        4 && div_class_value !== (div_class_value = "app-bar-slot-trail " + /*classesSlotTrail*/
        ctx2[2])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(trail_slot, local);
        current = true;
      },
      o(local) {
        transition_out(trail_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (trail_slot) trail_slot.d(detaching);
      }
    };
  }
  function create_if_block$g(ctx) {
    let div;
    let div_class_value;
    let current;
    const headline_slot_template = (
      /*#slots*/
      ctx[22].headline
    );
    const headline_slot = create_slot(
      headline_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      get_headline_slot_context
    );
    return {
      c() {
        div = element("div");
        if (headline_slot) headline_slot.c();
        attr(div, "class", div_class_value = "app-bar-row-headline " + /*classesRowHeadline*/
        ctx[5]);
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (headline_slot) {
          headline_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (headline_slot) {
          if (headline_slot.p && (!current || dirty & /*$$scope*/
          2097152)) {
            update_slot_base(
              headline_slot,
              headline_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                headline_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                get_headline_slot_changes
              ),
              get_headline_slot_context
            );
          }
        }
        if (!current || dirty & /*classesRowHeadline*/
        32 && div_class_value !== (div_class_value = "app-bar-row-headline " + /*classesRowHeadline*/
        ctx2[5])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(headline_slot, local);
        current = true;
      },
      o(local) {
        transition_out(headline_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (headline_slot) headline_slot.d(detaching);
      }
    };
  }
  function create_fragment$o(ctx) {
    let div2;
    let div1;
    let t0;
    let div0;
    let div0_class_value;
    let t1;
    let div1_class_value;
    let t2;
    let div2_class_value;
    let current;
    let if_block0 = (
      /*$$slots*/
      ctx[8].lead && create_if_block_2$7(ctx)
    );
    const default_slot_template = (
      /*#slots*/
      ctx[22].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      null
    );
    let if_block1 = (
      /*$$slots*/
      ctx[8].trail && create_if_block_1$9(ctx)
    );
    let if_block2 = (
      /*$$slots*/
      ctx[8].headline && create_if_block$g(ctx)
    );
    return {
      c() {
        div2 = element("div");
        div1 = element("div");
        if (if_block0) if_block0.c();
        t0 = space();
        div0 = element("div");
        if (default_slot) default_slot.c();
        t1 = space();
        if (if_block1) if_block1.c();
        t2 = space();
        if (if_block2) if_block2.c();
        attr(div0, "class", div0_class_value = "app-bar-slot-default " + /*classesSlotDefault*/
        ctx[3]);
        attr(div1, "class", div1_class_value = "app-bar-row-main " + /*classesRowMain*/
        ctx[6]);
        attr(div2, "class", div2_class_value = "app-bar " + /*classesBase*/
        ctx[7]);
        attr(div2, "data-testid", "app-bar");
        attr(div2, "role", "toolbar");
        attr(
          div2,
          "aria-label",
          /*label*/
          ctx[0]
        );
        attr(
          div2,
          "aria-labelledby",
          /*labelledby*/
          ctx[1]
        );
      },
      m(target, anchor) {
        insert(target, div2, anchor);
        append(div2, div1);
        if (if_block0) if_block0.m(div1, null);
        append(div1, t0);
        append(div1, div0);
        if (default_slot) {
          default_slot.m(div0, null);
        }
        append(div1, t1);
        if (if_block1) if_block1.m(div1, null);
        append(div2, t2);
        if (if_block2) if_block2.m(div2, null);
        current = true;
      },
      p(ctx2, [dirty]) {
        if (
          /*$$slots*/
          ctx2[8].lead
        ) {
          if (if_block0) {
            if_block0.p(ctx2, dirty);
            if (dirty & /*$$slots*/
            256) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_2$7(ctx2);
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(div1, t0);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          2097152)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*classesSlotDefault*/
        8 && div0_class_value !== (div0_class_value = "app-bar-slot-default " + /*classesSlotDefault*/
        ctx2[3])) {
          attr(div0, "class", div0_class_value);
        }
        if (
          /*$$slots*/
          ctx2[8].trail
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
            if (dirty & /*$$slots*/
            256) {
              transition_in(if_block1, 1);
            }
          } else {
            if_block1 = create_if_block_1$9(ctx2);
            if_block1.c();
            transition_in(if_block1, 1);
            if_block1.m(div1, null);
          }
        } else if (if_block1) {
          group_outros();
          transition_out(if_block1, 1, 1, () => {
            if_block1 = null;
          });
          check_outros();
        }
        if (!current || dirty & /*classesRowMain*/
        64 && div1_class_value !== (div1_class_value = "app-bar-row-main " + /*classesRowMain*/
        ctx2[6])) {
          attr(div1, "class", div1_class_value);
        }
        if (
          /*$$slots*/
          ctx2[8].headline
        ) {
          if (if_block2) {
            if_block2.p(ctx2, dirty);
            if (dirty & /*$$slots*/
            256) {
              transition_in(if_block2, 1);
            }
          } else {
            if_block2 = create_if_block$g(ctx2);
            if_block2.c();
            transition_in(if_block2, 1);
            if_block2.m(div2, null);
          }
        } else if (if_block2) {
          group_outros();
          transition_out(if_block2, 1, 1, () => {
            if_block2 = null;
          });
          check_outros();
        }
        if (!current || dirty & /*classesBase*/
        128 && div2_class_value !== (div2_class_value = "app-bar " + /*classesBase*/
        ctx2[7])) {
          attr(div2, "class", div2_class_value);
        }
        if (!current || dirty & /*label*/
        1) {
          attr(
            div2,
            "aria-label",
            /*label*/
            ctx2[0]
          );
        }
        if (!current || dirty & /*labelledby*/
        2) {
          attr(
            div2,
            "aria-labelledby",
            /*labelledby*/
            ctx2[1]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block0);
        transition_in(default_slot, local);
        transition_in(if_block1);
        transition_in(if_block2);
        current = true;
      },
      o(local) {
        transition_out(if_block0);
        transition_out(default_slot, local);
        transition_out(if_block1);
        transition_out(if_block2);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div2);
        }
        if (if_block0) if_block0.d();
        if (default_slot) default_slot.d(detaching);
        if (if_block1) if_block1.d();
        if (if_block2) if_block2.d();
      }
    };
  }
  const cBase$a = "flex flex-col";
  const cRowMain = "grid items-center";
  const cRowHeadline = "";
  const cSlotLead = "flex-none flex justify-between items-center";
  const cSlotDefault = "flex-auto";
  const cSlotTrail = "flex-none flex items-center space-x-4";
  function instance$o($$self, $$props, $$invalidate) {
    let classesBase;
    let classesRowMain;
    let classesRowHeadline;
    let classesSlotLead;
    let classesSlotDefault;
    let classesSlotTrail;
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    let { background = "bg-surface-100-800-token" } = $$props;
    let { border = "" } = $$props;
    let { padding = "p-4" } = $$props;
    let { shadow = "" } = $$props;
    let { spacing = "space-y-4" } = $$props;
    let { gridColumns = "grid-cols-[auto_1fr_auto]" } = $$props;
    let { gap = "gap-4" } = $$props;
    let { regionRowMain = "" } = $$props;
    let { regionRowHeadline = "" } = $$props;
    let { slotLead = "" } = $$props;
    let { slotDefault = "" } = $$props;
    let { slotTrail = "" } = $$props;
    let { label = "" } = $$props;
    let { labelledby = "" } = $$props;
    $$self.$$set = ($$new_props) => {
      $$invalidate(23, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("background" in $$new_props) $$invalidate(9, background = $$new_props.background);
      if ("border" in $$new_props) $$invalidate(10, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(11, padding = $$new_props.padding);
      if ("shadow" in $$new_props) $$invalidate(12, shadow = $$new_props.shadow);
      if ("spacing" in $$new_props) $$invalidate(13, spacing = $$new_props.spacing);
      if ("gridColumns" in $$new_props) $$invalidate(14, gridColumns = $$new_props.gridColumns);
      if ("gap" in $$new_props) $$invalidate(15, gap = $$new_props.gap);
      if ("regionRowMain" in $$new_props) $$invalidate(16, regionRowMain = $$new_props.regionRowMain);
      if ("regionRowHeadline" in $$new_props) $$invalidate(17, regionRowHeadline = $$new_props.regionRowHeadline);
      if ("slotLead" in $$new_props) $$invalidate(18, slotLead = $$new_props.slotLead);
      if ("slotDefault" in $$new_props) $$invalidate(19, slotDefault = $$new_props.slotDefault);
      if ("slotTrail" in $$new_props) $$invalidate(20, slotTrail = $$new_props.slotTrail);
      if ("label" in $$new_props) $$invalidate(0, label = $$new_props.label);
      if ("labelledby" in $$new_props) $$invalidate(1, labelledby = $$new_props.labelledby);
      if ("$$scope" in $$new_props) $$invalidate(21, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(7, classesBase = `${cBase$a} ${background} ${border} ${spacing} ${padding} ${shadow} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty & /*gridColumns, gap, regionRowMain*/
      114688) {
        $$invalidate(6, classesRowMain = `${cRowMain} ${gridColumns} ${gap} ${regionRowMain}`);
      }
      if ($$self.$$.dirty & /*regionRowHeadline*/
      131072) {
        $$invalidate(5, classesRowHeadline = `${cRowHeadline} ${regionRowHeadline}`);
      }
      if ($$self.$$.dirty & /*slotLead*/
      262144) {
        $$invalidate(4, classesSlotLead = `${cSlotLead} ${slotLead}`);
      }
      if ($$self.$$.dirty & /*slotDefault*/
      524288) {
        $$invalidate(3, classesSlotDefault = `${cSlotDefault} ${slotDefault}`);
      }
      if ($$self.$$.dirty & /*slotTrail*/
      1048576) {
        $$invalidate(2, classesSlotTrail = `${cSlotTrail} ${slotTrail}`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      label,
      labelledby,
      classesSlotTrail,
      classesSlotDefault,
      classesSlotLead,
      classesRowHeadline,
      classesRowMain,
      classesBase,
      $$slots,
      background,
      border,
      padding,
      shadow,
      spacing,
      gridColumns,
      gap,
      regionRowMain,
      regionRowHeadline,
      slotLead,
      slotDefault,
      slotTrail,
      $$scope,
      slots
    ];
  }
  class AppBar extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$o, create_fragment$o, safe_not_equal, {
        background: 9,
        border: 10,
        padding: 11,
        shadow: 12,
        spacing: 13,
        gridColumns: 14,
        gap: 15,
        regionRowMain: 16,
        regionRowHeadline: 17,
        slotLead: 18,
        slotDefault: 19,
        slotTrail: 20,
        label: 0,
        labelledby: 1
      });
    }
  }
  function fallback_block(ctx) {
    let t2;
    return {
      c() {
        t2 = text("Select a File");
      },
      m(target, anchor) {
        insert(target, t2, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t2);
        }
      }
    };
  }
  function create_fragment$n(ctx) {
    let div1;
    let div0;
    let input;
    let t2;
    let button_1;
    let button_1_class_value;
    let button_1_disabled_value;
    let div1_class_value;
    let current;
    let mounted;
    let dispose;
    let input_levels = [
      { type: "file" },
      { name: (
        /*name*/
        ctx[2]
      ) },
      /*prunedRestProps*/
      ctx[6]()
    ];
    let input_data = {};
    for (let i = 0; i < input_levels.length; i += 1) {
      input_data = assign(input_data, input_levels[i]);
    }
    const default_slot_template = (
      /*#slots*/
      ctx[11].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[10],
      null
    );
    const default_slot_or_fallback = default_slot || fallback_block();
    return {
      c() {
        div1 = element("div");
        div0 = element("div");
        input = element("input");
        t2 = space();
        button_1 = element("button");
        if (default_slot_or_fallback) default_slot_or_fallback.c();
        set_attributes(input, input_data);
        attr(div0, "class", "w-0 h-0 overflow-hidden");
        attr(button_1, "type", "button");
        attr(button_1, "class", button_1_class_value = "file-button-btn " + /*classesButton*/
        ctx[3]);
        button_1.disabled = button_1_disabled_value = /*$$restProps*/
        ctx[7].disabled;
        attr(div1, "class", div1_class_value = "file-button " + /*classesBase*/
        ctx[4]);
        attr(div1, "data-testid", "file-button");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, div0);
        append(div0, input);
        if (input.autofocus) input.focus();
        ctx[16](input);
        append(div1, t2);
        append(div1, button_1);
        if (default_slot_or_fallback) {
          default_slot_or_fallback.m(button_1, null);
        }
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_handler*/
              ctx[17]
            ),
            listen(
              input,
              "change",
              /*change_handler*/
              ctx[15]
            ),
            listen(
              button_1,
              "click",
              /*onButtonClick*/
              ctx[5]
            ),
            listen(
              button_1,
              "keydown",
              /*keydown_handler*/
              ctx[12]
            ),
            listen(
              button_1,
              "keyup",
              /*keyup_handler*/
              ctx[13]
            ),
            listen(
              button_1,
              "keypress",
              /*keypress_handler*/
              ctx[14]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, [dirty]) {
        set_attributes(input, input_data = get_spread_update(input_levels, [
          { type: "file" },
          (!current || dirty & /*name*/
          4) && { name: (
            /*name*/
            ctx2[2]
          ) },
          /*prunedRestProps*/
          ctx2[6]()
        ]));
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          1024)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[10],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[10]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[10],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*classesButton*/
        8 && button_1_class_value !== (button_1_class_value = "file-button-btn " + /*classesButton*/
        ctx2[3])) {
          attr(button_1, "class", button_1_class_value);
        }
        if (!current || dirty & /*$$restProps*/
        128 && button_1_disabled_value !== (button_1_disabled_value = /*$$restProps*/
        ctx2[7].disabled)) {
          button_1.disabled = button_1_disabled_value;
        }
        if (!current || dirty & /*classesBase*/
        16 && div1_class_value !== (div1_class_value = "file-button " + /*classesBase*/
        ctx2[4])) {
          attr(div1, "class", div1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot_or_fallback, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot_or_fallback, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        ctx[16](null);
        if (default_slot_or_fallback) default_slot_or_fallback.d(detaching);
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function instance$n($$self, $$props, $$invalidate) {
    let classesBase;
    let classesButton;
    const omit_props_names = ["files", "fileInput", "name", "width", "button"];
    let $$restProps = compute_rest_props($$props, omit_props_names);
    let { $$slots: slots = {}, $$scope } = $$props;
    let { files = void 0 } = $$props;
    let { fileInput = void 0 } = $$props;
    let { name } = $$props;
    let { width = "" } = $$props;
    let { button = "btn variant-filled" } = $$props;
    function onButtonClick() {
      if (fileInput) fileInput.click();
    }
    function prunedRestProps() {
      delete $$restProps.class;
      return $$restProps;
    }
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keyup_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keypress_handler(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler(event) {
      bubble.call(this, $$self, event);
    }
    function input_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        fileInput = $$value;
        $$invalidate(1, fileInput);
      });
    }
    function input_change_handler() {
      files = this.files;
      $$invalidate(0, files);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(18, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      $$invalidate(7, $$restProps = compute_rest_props($$props, omit_props_names));
      if ("files" in $$new_props) $$invalidate(0, files = $$new_props.files);
      if ("fileInput" in $$new_props) $$invalidate(1, fileInput = $$new_props.fileInput);
      if ("name" in $$new_props) $$invalidate(2, name = $$new_props.name);
      if ("width" in $$new_props) $$invalidate(8, width = $$new_props.width);
      if ("button" in $$new_props) $$invalidate(9, button = $$new_props.button);
      if ("$$scope" in $$new_props) $$invalidate(10, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(4, classesBase = `${$$props.class ?? ""}`);
      if ($$self.$$.dirty & /*button, width*/
      768) {
        $$invalidate(3, classesButton = `${button} ${width}`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      files,
      fileInput,
      name,
      classesButton,
      classesBase,
      onButtonClick,
      prunedRestProps,
      $$restProps,
      width,
      button,
      $$scope,
      slots,
      keydown_handler,
      keyup_handler,
      keypress_handler,
      change_handler,
      input_binding,
      input_change_handler
    ];
  }
  class FileButton extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$n, create_fragment$n, safe_not_equal, {
        files: 0,
        fileInput: 1,
        name: 2,
        width: 8,
        button: 9
      });
    }
  }
  function flip(node, { from, to }, params = {}) {
    const style = getComputedStyle(node);
    const transform = style.transform === "none" ? "" : style.transform;
    const [ox, oy] = style.transformOrigin.split(" ").map(parseFloat);
    const dx = from.left + from.width * ox / to.width - (to.left + ox);
    const dy = from.top + from.height * oy / to.height - (to.top + oy);
    const { delay = 0, duration = (d) => Math.sqrt(d) * 120, easing = cubicOut } = params;
    return {
      delay,
      duration: is_function(duration) ? duration(Math.sqrt(dx * dx + dy * dy)) : duration,
      easing,
      css: (t2, u) => {
        const x = u * dx;
        const y = u * dy;
        const sx = t2 + u * from.width / to.width;
        const sy = t2 + u * from.height / to.height;
        return `transform: ${transform} translate(${x}px, ${y}px) scale(${sx}, ${sy});`;
      }
    };
  }
  function get_each_context$5(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[65] = list[i].id;
    child_ctx[66] = list[i].val;
    child_ctx[68] = i;
    return child_ctx;
  }
  function get_each_context_1$3(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[69] = list[i];
    return child_ctx;
  }
  function create_each_block_1$3(ctx) {
    let option_1;
    let t_value = (
      /*option*/
      ctx[69] + ""
    );
    let t2;
    let option_1_value_value;
    return {
      c() {
        option_1 = element("option");
        t2 = text(t_value);
        option_1.__value = option_1_value_value = /*option*/
        ctx[69];
        set_input_value(option_1, option_1.__value);
      },
      m(target, anchor) {
        insert(target, option_1, anchor);
        append(option_1, t2);
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*value*/
        1 && t_value !== (t_value = /*option*/
        ctx2[69] + "")) set_data(t2, t_value);
        if (dirty[0] & /*value*/
        1 && option_1_value_value !== (option_1_value_value = /*option*/
        ctx2[69])) {
          option_1.__value = option_1_value_value;
          set_input_value(option_1, option_1.__value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(option_1);
        }
      }
    };
  }
  function create_if_block$f(ctx) {
    let div;
    let each_blocks = [];
    let each_1_lookup = /* @__PURE__ */ new Map();
    let div_class_value;
    let div_intro;
    let div_outro;
    let current;
    let each_value = ensure_array_like(
      /*chipValues*/
      ctx[16]
    );
    const get_key = (ctx2) => (
      /*id*/
      ctx2[65]
    );
    for (let i = 0; i < each_value.length; i += 1) {
      let child_ctx = get_each_context$5(ctx, each_value, i);
      let key = get_key(child_ctx);
      each_1_lookup.set(key, each_blocks[i] = create_each_block$5(key, child_ctx));
    }
    return {
      c() {
        div = element("div");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        attr(div, "class", div_class_value = "input-chip-list " + /*classesChipList*/
        ctx[19]);
      },
      m(target, anchor) {
        insert(target, div, anchor);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(div, null);
          }
        }
        current = true;
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        if (dirty[0] & /*chips, chipTransitionOut, chipTransitionOutParams, transitions, removeChipInternally, chipValues*/
        8503456) {
          each_value = ensure_array_like(
            /*chipValues*/
            ctx[16]
          );
          group_outros();
          for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].r();
          each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, div, fix_and_outro_and_destroy_block, create_each_block$5, null, get_each_context$5);
          for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].a();
          check_outros();
        }
        if (!current || dirty[0] & /*classesChipList*/
        524288 && div_class_value !== (div_class_value = "input-chip-list " + /*classesChipList*/
        ctx[19])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        for (let i = 0; i < each_value.length; i += 1) {
          transition_in(each_blocks[i]);
        }
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (div_outro) div_outro.end(1);
            div_intro = create_in_transition(div, dynamicTransition, {
              transition: (
                /*listTransitionIn*/
                ctx[8]
              ),
              params: (
                /*listTransitionInParams*/
                ctx[9]
              ),
              enabled: (
                /*transitions*/
                ctx[7]
              )
            });
            div_intro.start();
          });
        }
        current = true;
      },
      o(local) {
        for (let i = 0; i < each_blocks.length; i += 1) {
          transition_out(each_blocks[i]);
        }
        if (div_intro) div_intro.invalidate();
        if (local) {
          div_outro = create_out_transition(div, dynamicTransition, {
            transition: (
              /*listTransitionOut*/
              ctx[10]
            ),
            params: (
              /*listTransitionOutParams*/
              ctx[11]
            ),
            enabled: (
              /*transitions*/
              ctx[7]
            )
          });
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].d();
        }
        if (detaching && div_outro) div_outro.end();
      }
    };
  }
  function create_each_block$5(key_1, ctx) {
    let div;
    let button;
    let span0;
    let t0_value = (
      /*val*/
      ctx[66] + ""
    );
    let t0;
    let t1;
    let span1;
    let button_class_value;
    let button_intro;
    let button_outro;
    let t3;
    let rect;
    let stop_animation = noop;
    let current;
    let mounted;
    let dispose;
    function click_handler_1(...args) {
      return (
        /*click_handler_1*/
        ctx[52](
          /*i*/
          ctx[68],
          /*val*/
          ctx[66],
          ...args
        )
      );
    }
    return {
      key: key_1,
      first: null,
      c() {
        div = element("div");
        button = element("button");
        span0 = element("span");
        t0 = text(t0_value);
        t1 = space();
        span1 = element("span");
        span1.textContent = "✕";
        t3 = space();
        attr(button, "type", "button");
        attr(button, "class", button_class_value = "chip " + /*chips*/
        ctx[5]);
        this.first = div;
      },
      m(target, anchor) {
        insert(target, div, anchor);
        append(div, button);
        append(button, span0);
        append(span0, t0);
        append(button, t1);
        append(button, span1);
        append(div, t3);
        current = true;
        if (!mounted) {
          dispose = [
            listen(button, "click", click_handler_1),
            listen(
              button,
              "click",
              /*click_handler*/
              ctx[42]
            ),
            listen(
              button,
              "keypress",
              /*keypress_handler*/
              ctx[43]
            ),
            listen(
              button,
              "keydown",
              /*keydown_handler*/
              ctx[44]
            ),
            listen(
              button,
              "keyup",
              /*keyup_handler*/
              ctx[45]
            )
          ];
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        if ((!current || dirty[0] & /*chipValues*/
        65536) && t0_value !== (t0_value = /*val*/
        ctx[66] + "")) set_data(t0, t0_value);
        if (!current || dirty[0] & /*chips*/
        32 && button_class_value !== (button_class_value = "chip " + /*chips*/
        ctx[5])) {
          attr(button, "class", button_class_value);
        }
      },
      r() {
        rect = div.getBoundingClientRect();
      },
      f() {
        fix_position(div);
        stop_animation();
      },
      a() {
        stop_animation();
        stop_animation = create_animation(div, rect, flip, { duration: (
          /*duration*/
          ctx[3]
        ) });
      },
      i(local) {
        if (current) return;
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (button_outro) button_outro.end(1);
            button_intro = create_in_transition(button, dynamicTransition, {
              transition: (
                /*chipTransitionIn*/
                ctx[12]
              ),
              params: (
                /*chipTransitionInParams*/
                ctx[13]
              ),
              enabled: (
                /*transitions*/
                ctx[7]
              )
            });
            button_intro.start();
          });
        }
        current = true;
      },
      o(local) {
        if (button_intro) button_intro.invalidate();
        if (local) {
          button_outro = create_out_transition(button, dynamicTransition, {
            transition: (
              /*chipTransitionOut*/
              ctx[14]
            ),
            params: (
              /*chipTransitionOutParams*/
              ctx[15]
            ),
            enabled: (
              /*transitions*/
              ctx[7]
            )
          });
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (detaching && button_outro) button_outro.end();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_fragment$m(ctx) {
    let div2;
    let div0;
    let select;
    let t0;
    let div1;
    let input_1;
    let input_1_placeholder_value;
    let input_1_class_value;
    let input_1_disabled_value;
    let t1;
    let div1_class_value;
    let div2_class_value;
    let current;
    let mounted;
    let dispose;
    let each_value_1 = ensure_array_like(
      /*value*/
      ctx[0]
    );
    let each_blocks = [];
    for (let i = 0; i < each_value_1.length; i += 1) {
      each_blocks[i] = create_each_block_1$3(get_each_context_1$3(ctx, each_value_1, i));
    }
    let if_block = (
      /*chipValues*/
      ctx[16].length && create_if_block$f(ctx)
    );
    return {
      c() {
        div2 = element("div");
        div0 = element("div");
        select = element("select");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        t0 = space();
        div1 = element("div");
        input_1 = element("input");
        t1 = space();
        if (if_block) if_block.c();
        attr(
          select,
          "name",
          /*name*/
          ctx[2]
        );
        select.multiple = true;
        select.required = /*required*/
        ctx[4];
        attr(
          select,
          "aria-label",
          /*label*/
          ctx[6]
        );
        attr(select, "tabindex", "-1");
        if (
          /*value*/
          ctx[0] === void 0
        ) add_render_callback(() => (
          /*select_change_handler*/
          ctx[50].call(select)
        ));
        attr(div0, "class", "h-0 overflow-hidden");
        attr(input_1, "type", "text");
        attr(input_1, "placeholder", input_1_placeholder_value = /*$$restProps*/
        ctx[24].placeholder ?? "Enter values...");
        attr(input_1, "class", input_1_class_value = "input-chip-field " + /*classesInput*/
        ctx[18]);
        input_1.disabled = input_1_disabled_value = /*$$restProps*/
        ctx[24].disabled;
        attr(div1, "class", div1_class_value = "input-chip-wrapper " + /*classesChipWrapper*/
        ctx[20]);
        attr(div2, "class", div2_class_value = "input-chip " + /*classesBase*/
        ctx[21]);
        toggle_class(
          div2,
          "opacity-50",
          /*$$restProps*/
          ctx[24].disabled
        );
      },
      m(target, anchor) {
        insert(target, div2, anchor);
        append(div2, div0);
        append(div0, select);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(select, null);
          }
        }
        ctx[49](select);
        select_options(
          select,
          /*value*/
          ctx[0]
        );
        append(div2, t0);
        append(div2, div1);
        append(div1, input_1);
        set_input_value(
          input_1,
          /*input*/
          ctx[1]
        );
        append(div1, t1);
        if (if_block) if_block.m(div1, null);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              select,
              "change",
              /*select_change_handler*/
              ctx[50]
            ),
            listen(
              input_1,
              "input",
              /*input_1_input_handler*/
              ctx[51]
            ),
            listen(
              input_1,
              "keydown",
              /*onKeyHandler*/
              ctx[22]
            ),
            listen(
              input_1,
              "input",
              /*input_handler*/
              ctx[46]
            ),
            listen(
              input_1,
              "focus",
              /*focus_handler*/
              ctx[47]
            ),
            listen(
              input_1,
              "blur",
              /*blur_handler*/
              ctx[48]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*value*/
        1) {
          each_value_1 = ensure_array_like(
            /*value*/
            ctx2[0]
          );
          let i;
          for (i = 0; i < each_value_1.length; i += 1) {
            const child_ctx = get_each_context_1$3(ctx2, each_value_1, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
            } else {
              each_blocks[i] = create_each_block_1$3(child_ctx);
              each_blocks[i].c();
              each_blocks[i].m(select, null);
            }
          }
          for (; i < each_blocks.length; i += 1) {
            each_blocks[i].d(1);
          }
          each_blocks.length = each_value_1.length;
        }
        if (!current || dirty[0] & /*name*/
        4) {
          attr(
            select,
            "name",
            /*name*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*required*/
        16) {
          select.required = /*required*/
          ctx2[4];
        }
        if (!current || dirty[0] & /*label*/
        64) {
          attr(
            select,
            "aria-label",
            /*label*/
            ctx2[6]
          );
        }
        if (dirty[0] & /*value*/
        1) {
          select_options(
            select,
            /*value*/
            ctx2[0]
          );
        }
        if (!current || dirty[0] & /*$$restProps*/
        16777216 && input_1_placeholder_value !== (input_1_placeholder_value = /*$$restProps*/
        ctx2[24].placeholder ?? "Enter values...")) {
          attr(input_1, "placeholder", input_1_placeholder_value);
        }
        if (!current || dirty[0] & /*classesInput*/
        262144 && input_1_class_value !== (input_1_class_value = "input-chip-field " + /*classesInput*/
        ctx2[18])) {
          attr(input_1, "class", input_1_class_value);
        }
        if (!current || dirty[0] & /*$$restProps*/
        16777216 && input_1_disabled_value !== (input_1_disabled_value = /*$$restProps*/
        ctx2[24].disabled)) {
          input_1.disabled = input_1_disabled_value;
        }
        if (dirty[0] & /*input*/
        2 && input_1.value !== /*input*/
        ctx2[1]) {
          set_input_value(
            input_1,
            /*input*/
            ctx2[1]
          );
        }
        if (
          /*chipValues*/
          ctx2[16].length
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty[0] & /*chipValues*/
            65536) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$f(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(div1, null);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*classesChipWrapper*/
        1048576 && div1_class_value !== (div1_class_value = "input-chip-wrapper " + /*classesChipWrapper*/
        ctx2[20])) {
          attr(div1, "class", div1_class_value);
        }
        if (!current || dirty[0] & /*classesBase*/
        2097152 && div2_class_value !== (div2_class_value = "input-chip " + /*classesBase*/
        ctx2[21])) {
          attr(div2, "class", div2_class_value);
        }
        if (!current || dirty[0] & /*classesBase, $$restProps*/
        18874368) {
          toggle_class(
            div2,
            "opacity-50",
            /*$$restProps*/
            ctx2[24].disabled
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div2);
        }
        destroy_each(each_blocks, detaching);
        ctx[49](null);
        if (if_block) if_block.d();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBase$9 = "textarea cursor-pointer";
  const cChipWrapper = "space-y-4";
  const cChipList = "flex flex-wrap gap-2";
  const cInputField = "unstyled bg-transparent border-0 !ring-0 p-0 w-full";
  function instance$m($$self, $$props, $$invalidate) {
    let classesInvalid;
    let classesBase;
    let classesChipWrapper;
    let classesChipList;
    let classesInput;
    const omit_props_names = [
      "input",
      "name",
      "value",
      "whitelist",
      "max",
      "minlength",
      "maxlength",
      "allowUpperCase",
      "allowDuplicates",
      "validation",
      "duration",
      "required",
      "chips",
      "invalid",
      "padding",
      "rounded",
      "regionChipWrapper",
      "regionChipList",
      "regionInput",
      "label",
      "transitions",
      "listTransitionIn",
      "listTransitionInParams",
      "listTransitionOut",
      "listTransitionOutParams",
      "chipTransitionIn",
      "chipTransitionInParams",
      "chipTransitionOut",
      "chipTransitionOutParams",
      "addChip",
      "removeChip"
    ];
    let $$restProps = compute_rest_props($$props, omit_props_names);
    let $prefersReducedMotionStore;
    component_subscribe($$self, prefersReducedMotionStore, ($$value) => $$invalidate(53, $prefersReducedMotionStore = $$value));
    const dispatch2 = createEventDispatcher();
    let { input = "" } = $$props;
    let { name } = $$props;
    let { value = [] } = $$props;
    let { whitelist = [] } = $$props;
    let { max: max2 = -1 } = $$props;
    let { minlength = -1 } = $$props;
    let { maxlength = -1 } = $$props;
    let { allowUpperCase = false } = $$props;
    let { allowDuplicates = false } = $$props;
    let { validation = () => true } = $$props;
    let { duration = 150 } = $$props;
    let { required = false } = $$props;
    let { chips = "variant-filled" } = $$props;
    let { invalid = "input-error" } = $$props;
    let { padding = "p-2" } = $$props;
    let { rounded = "rounded-container-token" } = $$props;
    let { regionChipWrapper = "" } = $$props;
    let { regionChipList = "" } = $$props;
    let { regionInput = "" } = $$props;
    let { label = "Chips select" } = $$props;
    let { transitions = !$prefersReducedMotionStore } = $$props;
    let { listTransitionIn = fly } = $$props;
    let { listTransitionInParams = { duration: 150, opacity: 0, y: -20 } } = $$props;
    let { listTransitionOut = fly } = $$props;
    let { listTransitionOutParams = { duration: 150, opacity: 0, y: -20 } } = $$props;
    let { chipTransitionIn = scale } = $$props;
    let { chipTransitionInParams = { duration: 150, opacity: 0 } } = $$props;
    let { chipTransitionOut = scale } = $$props;
    let { chipTransitionOutParams = { duration: 150, opacity: 0 } } = $$props;
    let inputValid = true;
    let chipValues = (value == null ? void 0 : value.map((val) => {
      return { val, id: Math.random() };
    })) || [];
    function resetFormHandler() {
      $$invalidate(0, value = []);
    }
    let selectElement;
    onMount(() => {
      if (!selectElement.form) return;
      const externalForm = selectElement.form;
      externalForm.addEventListener("reset", resetFormHandler);
      return () => {
        externalForm.removeEventListener("reset", resetFormHandler);
      };
    });
    function validateCustom(chip) {
      return validation === void 0 || validation(chip);
    }
    function validateCount() {
      return max2 === -1 || value.length < max2;
    }
    function validateLength(chip) {
      return (minlength === -1 || chip.length >= minlength) && (maxlength === -1 || chip.length <= maxlength);
    }
    function validateWhiteList(chip) {
      return whitelist.length === 0 || whitelist.includes(chip);
    }
    function validateDuplicates(chip) {
      return allowDuplicates || !value.includes(chip);
    }
    function validate(chip = "") {
      if (!chip && !input) return false;
      chip = chip !== "" ? chip.trim() : input.trim();
      return validateCustom(chip) && validateCount() && validateLength(chip) && validateWhiteList(chip) && validateDuplicates(chip);
    }
    function addChipCommon(chip) {
      chip = allowUpperCase ? chip : chip.toLowerCase();
      value.push(chip);
      $$invalidate(0, value);
      chipValues.push({ val: chip, id: Math.random() });
      $$invalidate(16, chipValues), $$invalidate(0, value);
    }
    function removeChipCommon(chip) {
      let chipIndex = value.indexOf(chip);
      value.splice(chipIndex, 1);
      $$invalidate(0, value);
      chipValues.splice(chipIndex, 1);
      $$invalidate(16, chipValues), $$invalidate(0, value);
    }
    function onKeyHandler(event) {
      if (event.key !== "Enter") return;
      event.preventDefault();
      $$invalidate(40, inputValid = validate());
      if (inputValid === false) {
        dispatch2("invalid", { event, input });
        return;
      }
      addChipCommon(input);
      dispatch2("add", {
        event,
        chipIndex: value.length - 1,
        chipValue: input
      });
      $$invalidate(1, input = "");
    }
    function removeChipInternally(event, chipIndex, chipValue) {
      if ($$restProps.disabled) return;
      removeChipCommon(chipValue);
      dispatch2("remove", { event, chipIndex, chipValue });
    }
    function addChip(chip) {
      $$invalidate(40, inputValid = validate(chip));
      if (inputValid === false) {
        dispatch2("invalidManually", { input: chip });
        return;
      }
      addChipCommon(chip);
      dispatch2("addManually", {
        chipIndex: value.length - 1,
        chipValue: chip
      });
    }
    function removeChip(chip) {
      if ($$restProps.disabled) return;
      removeChipCommon(chip);
      dispatch2("removeManually", { chipValue: chip });
    }
    function click_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keypress_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keyup_handler(event) {
      bubble.call(this, $$self, event);
    }
    function input_handler(event) {
      bubble.call(this, $$self, event);
    }
    function focus_handler(event) {
      bubble.call(this, $$self, event);
    }
    function blur_handler(event) {
      bubble.call(this, $$self, event);
    }
    function select_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        selectElement = $$value;
        $$invalidate(17, selectElement);
      });
    }
    function select_change_handler() {
      value = select_multiple_value(this);
      $$invalidate(0, value);
    }
    function input_1_input_handler() {
      input = this.value;
      $$invalidate(1, input);
    }
    const click_handler_1 = (i, val, e) => removeChipInternally(e, i, val);
    $$self.$$set = ($$new_props) => {
      $$invalidate(64, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      $$invalidate(24, $$restProps = compute_rest_props($$props, omit_props_names));
      if ("input" in $$new_props) $$invalidate(1, input = $$new_props.input);
      if ("name" in $$new_props) $$invalidate(2, name = $$new_props.name);
      if ("value" in $$new_props) $$invalidate(0, value = $$new_props.value);
      if ("whitelist" in $$new_props) $$invalidate(25, whitelist = $$new_props.whitelist);
      if ("max" in $$new_props) $$invalidate(26, max2 = $$new_props.max);
      if ("minlength" in $$new_props) $$invalidate(27, minlength = $$new_props.minlength);
      if ("maxlength" in $$new_props) $$invalidate(28, maxlength = $$new_props.maxlength);
      if ("allowUpperCase" in $$new_props) $$invalidate(29, allowUpperCase = $$new_props.allowUpperCase);
      if ("allowDuplicates" in $$new_props) $$invalidate(30, allowDuplicates = $$new_props.allowDuplicates);
      if ("validation" in $$new_props) $$invalidate(31, validation = $$new_props.validation);
      if ("duration" in $$new_props) $$invalidate(3, duration = $$new_props.duration);
      if ("required" in $$new_props) $$invalidate(4, required = $$new_props.required);
      if ("chips" in $$new_props) $$invalidate(5, chips = $$new_props.chips);
      if ("invalid" in $$new_props) $$invalidate(32, invalid = $$new_props.invalid);
      if ("padding" in $$new_props) $$invalidate(33, padding = $$new_props.padding);
      if ("rounded" in $$new_props) $$invalidate(34, rounded = $$new_props.rounded);
      if ("regionChipWrapper" in $$new_props) $$invalidate(35, regionChipWrapper = $$new_props.regionChipWrapper);
      if ("regionChipList" in $$new_props) $$invalidate(36, regionChipList = $$new_props.regionChipList);
      if ("regionInput" in $$new_props) $$invalidate(37, regionInput = $$new_props.regionInput);
      if ("label" in $$new_props) $$invalidate(6, label = $$new_props.label);
      if ("transitions" in $$new_props) $$invalidate(7, transitions = $$new_props.transitions);
      if ("listTransitionIn" in $$new_props) $$invalidate(8, listTransitionIn = $$new_props.listTransitionIn);
      if ("listTransitionInParams" in $$new_props) $$invalidate(9, listTransitionInParams = $$new_props.listTransitionInParams);
      if ("listTransitionOut" in $$new_props) $$invalidate(10, listTransitionOut = $$new_props.listTransitionOut);
      if ("listTransitionOutParams" in $$new_props) $$invalidate(11, listTransitionOutParams = $$new_props.listTransitionOutParams);
      if ("chipTransitionIn" in $$new_props) $$invalidate(12, chipTransitionIn = $$new_props.chipTransitionIn);
      if ("chipTransitionInParams" in $$new_props) $$invalidate(13, chipTransitionInParams = $$new_props.chipTransitionInParams);
      if ("chipTransitionOut" in $$new_props) $$invalidate(14, chipTransitionOut = $$new_props.chipTransitionOut);
      if ("chipTransitionOutParams" in $$new_props) $$invalidate(15, chipTransitionOutParams = $$new_props.chipTransitionOutParams);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty[1] & /*inputValid, invalid*/
      514) {
        $$invalidate(41, classesInvalid = inputValid === false ? invalid : "");
      }
      $$invalidate(21, classesBase = `${cBase$9} ${padding} ${rounded} ${$$props.class ?? ""} ${classesInvalid}`);
      if ($$self.$$.dirty[1] & /*regionChipWrapper*/
      16) {
        $$invalidate(20, classesChipWrapper = `${cChipWrapper} ${regionChipWrapper}`);
      }
      if ($$self.$$.dirty[1] & /*regionChipList*/
      32) {
        $$invalidate(19, classesChipList = `${cChipList} ${regionChipList}`);
      }
      if ($$self.$$.dirty[1] & /*regionInput*/
      64) {
        $$invalidate(18, classesInput = `${cInputField} ${regionInput}`);
      }
      if ($$self.$$.dirty[0] & /*value, chipValues*/
      65537) {
        $$invalidate(16, chipValues = (value == null ? void 0 : value.map((val, i) => {
          var _a;
          if (((_a = chipValues[i]) == null ? void 0 : _a.val) === val) return chipValues[i];
          return { id: Math.random(), val };
        })) || []);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      value,
      input,
      name,
      duration,
      required,
      chips,
      label,
      transitions,
      listTransitionIn,
      listTransitionInParams,
      listTransitionOut,
      listTransitionOutParams,
      chipTransitionIn,
      chipTransitionInParams,
      chipTransitionOut,
      chipTransitionOutParams,
      chipValues,
      selectElement,
      classesInput,
      classesChipList,
      classesChipWrapper,
      classesBase,
      onKeyHandler,
      removeChipInternally,
      $$restProps,
      whitelist,
      max2,
      minlength,
      maxlength,
      allowUpperCase,
      allowDuplicates,
      validation,
      invalid,
      padding,
      rounded,
      regionChipWrapper,
      regionChipList,
      regionInput,
      addChip,
      removeChip,
      inputValid,
      classesInvalid,
      click_handler,
      keypress_handler,
      keydown_handler,
      keyup_handler,
      input_handler,
      focus_handler,
      blur_handler,
      select_binding,
      select_change_handler,
      input_1_input_handler,
      click_handler_1
    ];
  }
  class InputChip extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$m,
        create_fragment$m,
        safe_not_equal,
        {
          input: 1,
          name: 2,
          value: 0,
          whitelist: 25,
          max: 26,
          minlength: 27,
          maxlength: 28,
          allowUpperCase: 29,
          allowDuplicates: 30,
          validation: 31,
          duration: 3,
          required: 4,
          chips: 5,
          invalid: 32,
          padding: 33,
          rounded: 34,
          regionChipWrapper: 35,
          regionChipList: 36,
          regionInput: 37,
          label: 6,
          transitions: 7,
          listTransitionIn: 8,
          listTransitionInParams: 9,
          listTransitionOut: 10,
          listTransitionOutParams: 11,
          chipTransitionIn: 12,
          chipTransitionInParams: 13,
          chipTransitionOut: 14,
          chipTransitionOutParams: 15,
          addChip: 38,
          removeChip: 39
        },
        null,
        [-1, -1, -1]
      );
    }
    get addChip() {
      return this.$$.ctx[38];
    }
    get removeChip() {
      return this.$$.ctx[39];
    }
  }
  function create_fragment$l(ctx) {
    let div;
    let div_class_value;
    let current;
    const default_slot_template = (
      /*#slots*/
      ctx[13].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[12],
      null
    );
    return {
      c() {
        div = element("div");
        if (default_slot) default_slot.c();
        attr(div, "class", div_class_value = "listbox " + /*classesBase*/
        ctx[1]);
        attr(div, "role", "listbox");
        attr(
          div,
          "aria-labelledby",
          /*labelledby*/
          ctx[0]
        );
        attr(div, "data-testid", "listbox");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (default_slot) {
          default_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, [dirty]) {
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          4096)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[12],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[12]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[12],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*classesBase*/
        2 && div_class_value !== (div_class_value = "listbox " + /*classesBase*/
        ctx2[1])) {
          attr(div, "class", div_class_value);
        }
        if (!current || dirty & /*labelledby*/
        1) {
          attr(
            div,
            "aria-labelledby",
            /*labelledby*/
            ctx2[0]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (default_slot) default_slot.d(detaching);
      }
    };
  }
  const cBase$8 = "";
  function instance$l($$self, $$props, $$invalidate) {
    let classesBase;
    let { $$slots: slots = {}, $$scope } = $$props;
    let { multiple = false } = $$props;
    let { disabled = false } = $$props;
    let { spacing = "space-y-1" } = $$props;
    let { rounded = "rounded-token" } = $$props;
    let { active: active2 = "variant-filled" } = $$props;
    let { hover = "hover:variant-soft" } = $$props;
    let { padding = "px-4 py-2" } = $$props;
    let { regionLead = "" } = $$props;
    let { regionDefault = "" } = $$props;
    let { regionTrail = "" } = $$props;
    let { labelledby = "" } = $$props;
    setContext("disabled", disabled);
    setContext("multiple", multiple);
    setContext("rounded", rounded);
    setContext("active", active2);
    setContext("hover", hover);
    setContext("padding", padding);
    setContext("regionLead", regionLead);
    setContext("regionDefault", regionDefault);
    setContext("regionTrail", regionTrail);
    $$self.$$set = ($$new_props) => {
      $$invalidate(14, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("multiple" in $$new_props) $$invalidate(2, multiple = $$new_props.multiple);
      if ("disabled" in $$new_props) $$invalidate(3, disabled = $$new_props.disabled);
      if ("spacing" in $$new_props) $$invalidate(4, spacing = $$new_props.spacing);
      if ("rounded" in $$new_props) $$invalidate(5, rounded = $$new_props.rounded);
      if ("active" in $$new_props) $$invalidate(6, active2 = $$new_props.active);
      if ("hover" in $$new_props) $$invalidate(7, hover = $$new_props.hover);
      if ("padding" in $$new_props) $$invalidate(8, padding = $$new_props.padding);
      if ("regionLead" in $$new_props) $$invalidate(9, regionLead = $$new_props.regionLead);
      if ("regionDefault" in $$new_props) $$invalidate(10, regionDefault = $$new_props.regionDefault);
      if ("regionTrail" in $$new_props) $$invalidate(11, regionTrail = $$new_props.regionTrail);
      if ("labelledby" in $$new_props) $$invalidate(0, labelledby = $$new_props.labelledby);
      if ("$$scope" in $$new_props) $$invalidate(12, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(1, classesBase = `${cBase$8} ${spacing} ${rounded} ${$$props.class ?? ""}`);
    };
    $$props = exclude_internal_props($$props);
    return [
      labelledby,
      classesBase,
      multiple,
      disabled,
      spacing,
      rounded,
      active2,
      hover,
      padding,
      regionLead,
      regionDefault,
      regionTrail,
      $$scope,
      slots
    ];
  }
  class ListBox extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$l, create_fragment$l, safe_not_equal, {
        multiple: 2,
        disabled: 3,
        spacing: 4,
        rounded: 5,
        active: 6,
        hover: 7,
        padding: 8,
        regionLead: 9,
        regionDefault: 10,
        regionTrail: 11,
        labelledby: 0
      });
    }
  }
  const get_trail_slot_changes$1 = (dirty) => ({});
  const get_trail_slot_context$1 = (ctx) => ({});
  const get_lead_slot_changes$1 = (dirty) => ({});
  const get_lead_slot_context$1 = (ctx) => ({});
  function create_else_block$4(ctx) {
    let input;
    let value_has_changed = false;
    let binding_group;
    let mounted;
    let dispose;
    binding_group = init_binding_group(
      /*$$binding_groups*/
      ctx[37][0]
    );
    return {
      c() {
        input = element("input");
        input.disabled = /*disabled*/
        ctx[3];
        attr(input, "type", "radio");
        attr(
          input,
          "name",
          /*name*/
          ctx[1]
        );
        input.__value = /*value*/
        ctx[2];
        set_input_value(input, input.__value);
        attr(input, "tabindex", "-1");
        binding_group.p(input);
      },
      m(target, anchor) {
        insert(target, input, anchor);
        ctx[35](input);
        input.checked = input.__value === /*group*/
        ctx[0];
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_handler_1*/
              ctx[36]
            ),
            listen(
              input,
              "click",
              /*click_handler_1*/
              ctx[31]
            ),
            listen(
              input,
              "change",
              /*change_handler_1*/
              ctx[32]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*disabled*/
        8) {
          input.disabled = /*disabled*/
          ctx2[3];
        }
        if (dirty[0] & /*name*/
        2) {
          attr(
            input,
            "name",
            /*name*/
            ctx2[1]
          );
        }
        if (dirty[0] & /*value*/
        4) {
          input.__value = /*value*/
          ctx2[2];
          set_input_value(input, input.__value);
          value_has_changed = true;
        }
        if (value_has_changed || dirty[0] & /*group*/
        1) {
          input.checked = input.__value === /*group*/
          ctx2[0];
        }
      },
      d(detaching) {
        if (detaching) {
          detach(input);
        }
        ctx[35](null);
        binding_group.r();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_2$6(ctx) {
    let input;
    let mounted;
    let dispose;
    return {
      c() {
        input = element("input");
        input.disabled = /*disabled*/
        ctx[3];
        attr(input, "type", "checkbox");
        attr(
          input,
          "name",
          /*name*/
          ctx[1]
        );
        input.__value = /*value*/
        ctx[2];
        set_input_value(input, input.__value);
        attr(input, "tabindex", "-1");
      },
      m(target, anchor) {
        insert(target, input, anchor);
        ctx[33](input);
        input.checked = /*checked*/
        ctx[5];
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_handler*/
              ctx[34]
            ),
            listen(
              input,
              "click",
              /*click_handler*/
              ctx[29]
            ),
            listen(
              input,
              "change",
              /*change_handler*/
              ctx[30]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*disabled*/
        8) {
          input.disabled = /*disabled*/
          ctx2[3];
        }
        if (dirty[0] & /*name*/
        2) {
          attr(
            input,
            "name",
            /*name*/
            ctx2[1]
          );
        }
        if (dirty[0] & /*value*/
        4) {
          input.__value = /*value*/
          ctx2[2];
          set_input_value(input, input.__value);
        }
        if (dirty[0] & /*checked*/
        32) {
          input.checked = /*checked*/
          ctx2[5];
        }
      },
      d(detaching) {
        if (detaching) {
          detach(input);
        }
        ctx[33](null);
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_1$8(ctx) {
    let div;
    let div_class_value;
    let current;
    const lead_slot_template = (
      /*#slots*/
      ctx[25].lead
    );
    const lead_slot = create_slot(
      lead_slot_template,
      ctx,
      /*$$scope*/
      ctx[24],
      get_lead_slot_context$1
    );
    return {
      c() {
        div = element("div");
        if (lead_slot) lead_slot.c();
        attr(div, "class", div_class_value = "listbox-label-lead " + /*classesRegionLead*/
        ctx[10]);
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (lead_slot) {
          lead_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (lead_slot) {
          if (lead_slot.p && (!current || dirty[0] & /*$$scope*/
          16777216)) {
            update_slot_base(
              lead_slot,
              lead_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[24],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[24]
              ) : get_slot_changes(
                lead_slot_template,
                /*$$scope*/
                ctx2[24],
                dirty,
                get_lead_slot_changes$1
              ),
              get_lead_slot_context$1
            );
          }
        }
        if (!current || dirty[0] & /*classesRegionLead*/
        1024 && div_class_value !== (div_class_value = "listbox-label-lead " + /*classesRegionLead*/
        ctx2[10])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(lead_slot, local);
        current = true;
      },
      o(local) {
        transition_out(lead_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (lead_slot) lead_slot.d(detaching);
      }
    };
  }
  function create_if_block$e(ctx) {
    let div;
    let div_class_value;
    let current;
    const trail_slot_template = (
      /*#slots*/
      ctx[25].trail
    );
    const trail_slot = create_slot(
      trail_slot_template,
      ctx,
      /*$$scope*/
      ctx[24],
      get_trail_slot_context$1
    );
    return {
      c() {
        div = element("div");
        if (trail_slot) trail_slot.c();
        attr(div, "class", div_class_value = "listbox-label-trail " + /*classesRegionTrail*/
        ctx[8]);
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (trail_slot) {
          trail_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (trail_slot) {
          if (trail_slot.p && (!current || dirty[0] & /*$$scope*/
          16777216)) {
            update_slot_base(
              trail_slot,
              trail_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[24],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[24]
              ) : get_slot_changes(
                trail_slot_template,
                /*$$scope*/
                ctx2[24],
                dirty,
                get_trail_slot_changes$1
              ),
              get_trail_slot_context$1
            );
          }
        }
        if (!current || dirty[0] & /*classesRegionTrail*/
        256 && div_class_value !== (div_class_value = "listbox-label-trail " + /*classesRegionTrail*/
        ctx2[8])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(trail_slot, local);
        current = true;
      },
      o(local) {
        transition_out(trail_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (trail_slot) trail_slot.d(detaching);
      }
    };
  }
  function create_fragment$k(ctx) {
    let label;
    let div3;
    let div0;
    let t0;
    let div2;
    let t1;
    let div1;
    let div1_class_value;
    let t2;
    let div2_class_value;
    let div3_class_value;
    let current;
    let mounted;
    let dispose;
    function select_block_type(ctx2, dirty) {
      if (
        /*multiple*/
        ctx2[4]
      ) return create_if_block_2$6;
      return create_else_block$4;
    }
    let current_block_type = select_block_type(ctx);
    let if_block0 = current_block_type(ctx);
    let if_block1 = (
      /*$$slots*/
      ctx[14].lead && create_if_block_1$8(ctx)
    );
    const default_slot_template = (
      /*#slots*/
      ctx[25].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[24],
      null
    );
    let if_block2 = (
      /*$$slots*/
      ctx[14].trail && create_if_block$e(ctx)
    );
    return {
      c() {
        label = element("label");
        div3 = element("div");
        div0 = element("div");
        if_block0.c();
        t0 = space();
        div2 = element("div");
        if (if_block1) if_block1.c();
        t1 = space();
        div1 = element("div");
        if (default_slot) default_slot.c();
        t2 = space();
        if (if_block2) if_block2.c();
        attr(div0, "class", "h-0 w-0 overflow-hidden");
        attr(div1, "class", div1_class_value = "listbox-label-content " + /*classesRegionDefault*/
        ctx[9]);
        attr(div2, "class", div2_class_value = "listbox-label " + /*classesLabel*/
        ctx[11]);
        attr(div3, "class", div3_class_value = "listbox-item " + /*classesBase*/
        ctx[12]);
        attr(div3, "data-testid", "listbox-item");
        attr(div3, "role", "option");
        attr(
          div3,
          "aria-selected",
          /*selected*/
          ctx[6]
        );
        attr(div3, "tabindex", "0");
      },
      m(target, anchor) {
        insert(target, label, anchor);
        append(label, div3);
        append(div3, div0);
        if_block0.m(div0, null);
        append(div3, t0);
        append(div3, div2);
        if (if_block1) if_block1.m(div2, null);
        append(div2, t1);
        append(div2, div1);
        if (default_slot) {
          default_slot.m(div1, null);
        }
        append(div2, t2);
        if (if_block2) if_block2.m(div2, null);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              div3,
              "keydown",
              /*onKeyDown*/
              ctx[13]
            ),
            listen(
              div3,
              "keydown",
              /*keydown_handler*/
              ctx[26]
            ),
            listen(
              div3,
              "keyup",
              /*keyup_handler*/
              ctx[27]
            ),
            listen(
              div3,
              "keypress",
              /*keypress_handler*/
              ctx[28]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block0) {
          if_block0.p(ctx2, dirty);
        } else {
          if_block0.d(1);
          if_block0 = current_block_type(ctx2);
          if (if_block0) {
            if_block0.c();
            if_block0.m(div0, null);
          }
        }
        if (
          /*$$slots*/
          ctx2[14].lead
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
            if (dirty[0] & /*$$slots*/
            16384) {
              transition_in(if_block1, 1);
            }
          } else {
            if_block1 = create_if_block_1$8(ctx2);
            if_block1.c();
            transition_in(if_block1, 1);
            if_block1.m(div2, t1);
          }
        } else if (if_block1) {
          group_outros();
          transition_out(if_block1, 1, 1, () => {
            if_block1 = null;
          });
          check_outros();
        }
        if (default_slot) {
          if (default_slot.p && (!current || dirty[0] & /*$$scope*/
          16777216)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[24],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[24]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[24],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty[0] & /*classesRegionDefault*/
        512 && div1_class_value !== (div1_class_value = "listbox-label-content " + /*classesRegionDefault*/
        ctx2[9])) {
          attr(div1, "class", div1_class_value);
        }
        if (
          /*$$slots*/
          ctx2[14].trail
        ) {
          if (if_block2) {
            if_block2.p(ctx2, dirty);
            if (dirty[0] & /*$$slots*/
            16384) {
              transition_in(if_block2, 1);
            }
          } else {
            if_block2 = create_if_block$e(ctx2);
            if_block2.c();
            transition_in(if_block2, 1);
            if_block2.m(div2, null);
          }
        } else if (if_block2) {
          group_outros();
          transition_out(if_block2, 1, 1, () => {
            if_block2 = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*classesLabel*/
        2048 && div2_class_value !== (div2_class_value = "listbox-label " + /*classesLabel*/
        ctx2[11])) {
          attr(div2, "class", div2_class_value);
        }
        if (!current || dirty[0] & /*classesBase*/
        4096 && div3_class_value !== (div3_class_value = "listbox-item " + /*classesBase*/
        ctx2[12])) {
          attr(div3, "class", div3_class_value);
        }
        if (!current || dirty[0] & /*selected*/
        64) {
          attr(
            div3,
            "aria-selected",
            /*selected*/
            ctx2[6]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block1);
        transition_in(default_slot, local);
        transition_in(if_block2);
        current = true;
      },
      o(local) {
        transition_out(if_block1);
        transition_out(default_slot, local);
        transition_out(if_block2);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(label);
        }
        if_block0.d();
        if (if_block1) if_block1.d();
        if (default_slot) default_slot.d(detaching);
        if (if_block2) if_block2.d();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBase$7 = "cursor-pointer -outline-offset-[3px]";
  const cDisabled$1 = "opacity-50 !cursor-default";
  const cLabel$1 = "flex items-center space-x-4";
  const cRegionLead = "";
  const cRegionDefault = "flex-1";
  const cRegionTrail = "";
  function areDeeplyEqual(param1, param2) {
    if (param1 === param2) return true;
    if (!(param1 instanceof Object) || !(param2 instanceof Object)) return false;
    const keys1 = Object.keys(param1);
    const keys2 = Object.keys(param2);
    if (keys1.length !== keys2.length) return false;
    for (const key of keys1) {
      const value1 = param1[key];
      const value2 = param2[key];
      if (!areDeeplyEqual(value1, value2)) return false;
    }
    return true;
  }
  function instance$k($$self, $$props, $$invalidate) {
    let selected;
    let classesActive;
    let classesDisabled;
    let classesBase;
    let classesLabel;
    let classesRegionLead;
    let classesRegionDefault;
    let classesRegionTrail;
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    let { group } = $$props;
    let { name } = $$props;
    let { value } = $$props;
    let { disabled = getContext("disabled") } = $$props;
    let { multiple = getContext("multiple") } = $$props;
    let { rounded = getContext("rounded") } = $$props;
    let { active: active2 = getContext("active") } = $$props;
    let { hover = getContext("hover") } = $$props;
    let { padding = getContext("padding") } = $$props;
    let { regionLead = getContext("regionLead") } = $$props;
    let { regionDefault = getContext("regionDefault") } = $$props;
    let { regionTrail = getContext("regionTrail") } = $$props;
    let checked;
    let elemInput;
    function updateCheckbox(group2) {
      $$invalidate(5, checked = group2.indexOf(value) >= 0);
    }
    function updateGroup(checked2) {
      const index = group.indexOf(value);
      if (checked2) {
        if (index < 0) {
          group.push(value);
          $$invalidate(0, group);
        }
      } else {
        if (index >= 0) {
          group.splice(index, 1);
          $$invalidate(0, group);
        }
      }
    }
    function onKeyDown(event) {
      if (["Enter", "Space"].includes(event.code)) {
        event.preventDefault();
        elemInput.click();
      }
    }
    const $$binding_groups = [[]];
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keyup_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keypress_handler(event) {
      bubble.call(this, $$self, event);
    }
    function click_handler(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler(event) {
      bubble.call(this, $$self, event);
    }
    function click_handler_1(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler_1(event) {
      bubble.call(this, $$self, event);
    }
    function input_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        elemInput = $$value;
        $$invalidate(7, elemInput);
      });
    }
    function input_change_handler() {
      checked = this.checked;
      $$invalidate(5, checked);
    }
    function input_binding_1($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        elemInput = $$value;
        $$invalidate(7, elemInput);
      });
    }
    function input_change_handler_1() {
      group = this.__value;
      $$invalidate(0, group);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(40, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("group" in $$new_props) $$invalidate(0, group = $$new_props.group);
      if ("name" in $$new_props) $$invalidate(1, name = $$new_props.name);
      if ("value" in $$new_props) $$invalidate(2, value = $$new_props.value);
      if ("disabled" in $$new_props) $$invalidate(3, disabled = $$new_props.disabled);
      if ("multiple" in $$new_props) $$invalidate(4, multiple = $$new_props.multiple);
      if ("rounded" in $$new_props) $$invalidate(15, rounded = $$new_props.rounded);
      if ("active" in $$new_props) $$invalidate(16, active2 = $$new_props.active);
      if ("hover" in $$new_props) $$invalidate(17, hover = $$new_props.hover);
      if ("padding" in $$new_props) $$invalidate(18, padding = $$new_props.padding);
      if ("regionLead" in $$new_props) $$invalidate(19, regionLead = $$new_props.regionLead);
      if ("regionDefault" in $$new_props) $$invalidate(20, regionDefault = $$new_props.regionDefault);
      if ("regionTrail" in $$new_props) $$invalidate(21, regionTrail = $$new_props.regionTrail);
      if ("$$scope" in $$new_props) $$invalidate(24, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty[0] & /*multiple, group*/
      17) {
        if (multiple) updateCheckbox(group);
      }
      if ($$self.$$.dirty[0] & /*multiple, checked*/
      48) {
        if (multiple) updateGroup(checked);
      }
      if ($$self.$$.dirty[0] & /*multiple, group, value*/
      21) {
        $$invalidate(6, selected = multiple ? group.some((groupVal) => areDeeplyEqual(value, groupVal)) : areDeeplyEqual(group, value));
      }
      if ($$self.$$.dirty[0] & /*selected, active, disabled, hover*/
      196680) {
        $$invalidate(22, classesActive = selected ? active2 : !disabled ? hover : "");
      }
      if ($$self.$$.dirty[0] & /*disabled*/
      8) {
        $$invalidate(23, classesDisabled = disabled ? cDisabled$1 : "");
      }
      $$invalidate(12, classesBase = `${cBase$7} ${classesDisabled} ${rounded} ${padding} ${classesActive} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty[0] & /*regionLead*/
      524288) {
        $$invalidate(10, classesRegionLead = `${cRegionLead} ${regionLead}`);
      }
      if ($$self.$$.dirty[0] & /*regionDefault*/
      1048576) {
        $$invalidate(9, classesRegionDefault = `${cRegionDefault} ${regionDefault}`);
      }
      if ($$self.$$.dirty[0] & /*regionTrail*/
      2097152) {
        $$invalidate(8, classesRegionTrail = `${cRegionTrail} ${regionTrail}`);
      }
    };
    $$invalidate(11, classesLabel = `${cLabel$1}`);
    $$props = exclude_internal_props($$props);
    return [
      group,
      name,
      value,
      disabled,
      multiple,
      checked,
      selected,
      elemInput,
      classesRegionTrail,
      classesRegionDefault,
      classesRegionLead,
      classesLabel,
      classesBase,
      onKeyDown,
      $$slots,
      rounded,
      active2,
      hover,
      padding,
      regionLead,
      regionDefault,
      regionTrail,
      classesActive,
      classesDisabled,
      $$scope,
      slots,
      keydown_handler,
      keyup_handler,
      keypress_handler,
      click_handler,
      change_handler,
      click_handler_1,
      change_handler_1,
      input_binding,
      input_change_handler,
      input_binding_1,
      input_change_handler_1,
      $$binding_groups
    ];
  }
  class ListBoxItem extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$k,
        create_fragment$k,
        safe_not_equal,
        {
          group: 0,
          name: 1,
          value: 2,
          disabled: 3,
          multiple: 4,
          rounded: 15,
          active: 16,
          hover: 17,
          padding: 18,
          regionLead: 19,
          regionDefault: 20,
          regionTrail: 21
        },
        null,
        [-1, -1]
      );
    }
  }
  function create_fragment$j(ctx) {
    let div1;
    let div0;
    let div0_class_value;
    let style_width = `${/*indeterminate*/
  ctx[4] ? 100 : (
    /*fillPercent*/
    ctx[7]
  )}%`;
    let div1_class_value;
    let div1_aria_valuemax_value;
    return {
      c() {
        div1 = element("div");
        div0 = element("div");
        attr(div0, "class", div0_class_value = "progress-bar-meter " + /*classesMeter*/
        ctx[5] + " svelte-12wvf64");
        set_style(div0, "width", style_width);
        attr(div1, "class", div1_class_value = "progress-bar " + /*classesTrack*/
        ctx[6] + " svelte-12wvf64");
        attr(div1, "data-testid", "progress-bar");
        attr(div1, "role", "progressbar");
        attr(
          div1,
          "aria-labelledby",
          /*labelledby*/
          ctx[3]
        );
        attr(
          div1,
          "aria-valuenow",
          /*value*/
          ctx[0]
        );
        attr(
          div1,
          "aria-valuemin",
          /*min*/
          ctx[1]
        );
        attr(div1, "aria-valuemax", div1_aria_valuemax_value = /*max*/
        ctx[2] - /*min*/
        ctx[1]);
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, div0);
      },
      p(ctx2, [dirty]) {
        if (dirty & /*classesMeter*/
        32 && div0_class_value !== (div0_class_value = "progress-bar-meter " + /*classesMeter*/
        ctx2[5] + " svelte-12wvf64")) {
          attr(div0, "class", div0_class_value);
        }
        if (dirty & /*indeterminate, fillPercent*/
        144 && style_width !== (style_width = `${/*indeterminate*/
      ctx2[4] ? 100 : (
        /*fillPercent*/
        ctx2[7]
      )}%`)) {
          set_style(div0, "width", style_width);
        }
        if (dirty & /*classesTrack*/
        64 && div1_class_value !== (div1_class_value = "progress-bar " + /*classesTrack*/
        ctx2[6] + " svelte-12wvf64")) {
          attr(div1, "class", div1_class_value);
        }
        if (dirty & /*labelledby*/
        8) {
          attr(
            div1,
            "aria-labelledby",
            /*labelledby*/
            ctx2[3]
          );
        }
        if (dirty & /*value*/
        1) {
          attr(
            div1,
            "aria-valuenow",
            /*value*/
            ctx2[0]
          );
        }
        if (dirty & /*min*/
        2) {
          attr(
            div1,
            "aria-valuemin",
            /*min*/
            ctx2[1]
          );
        }
        if (dirty & /*max, min*/
        6 && div1_aria_valuemax_value !== (div1_aria_valuemax_value = /*max*/
        ctx2[2] - /*min*/
        ctx2[1])) {
          attr(div1, "aria-valuemax", div1_aria_valuemax_value);
        }
      },
      i: noop,
      o: noop,
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
      }
    };
  }
  const cTrack$1 = "w-full overflow-hidden";
  const cMeter = "h-full";
  function instance$j($$self, $$props, $$invalidate) {
    let fillPercent;
    let indeterminate;
    let classesIndeterminate;
    let classesTrack;
    let classesMeter;
    let { value = void 0 } = $$props;
    let { min = 0 } = $$props;
    let { max: max2 = 100 } = $$props;
    let { height = "h-2" } = $$props;
    let { rounded = "rounded-token" } = $$props;
    let { transition = "transition-[width]" } = $$props;
    let { animIndeterminate = "anim-indeterminate" } = $$props;
    let { meter = "bg-surface-900-50-token" } = $$props;
    let { track = "bg-surface-200-700-token" } = $$props;
    let { labelledby = "" } = $$props;
    $$self.$$set = ($$new_props) => {
      $$invalidate(15, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("value" in $$new_props) $$invalidate(0, value = $$new_props.value);
      if ("min" in $$new_props) $$invalidate(1, min = $$new_props.min);
      if ("max" in $$new_props) $$invalidate(2, max2 = $$new_props.max);
      if ("height" in $$new_props) $$invalidate(8, height = $$new_props.height);
      if ("rounded" in $$new_props) $$invalidate(9, rounded = $$new_props.rounded);
      if ("transition" in $$new_props) $$invalidate(10, transition = $$new_props.transition);
      if ("animIndeterminate" in $$new_props) $$invalidate(11, animIndeterminate = $$new_props.animIndeterminate);
      if ("meter" in $$new_props) $$invalidate(12, meter = $$new_props.meter);
      if ("track" in $$new_props) $$invalidate(13, track = $$new_props.track);
      if ("labelledby" in $$new_props) $$invalidate(3, labelledby = $$new_props.labelledby);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty & /*value, min, max*/
      7) {
        $$invalidate(7, fillPercent = value ? 100 * (value - min) / (max2 - min) : 0);
      }
      if ($$self.$$.dirty & /*value*/
      1) {
        $$invalidate(4, indeterminate = value === void 0 || value < 0);
      }
      if ($$self.$$.dirty & /*indeterminate, animIndeterminate*/
      2064) {
        $$invalidate(14, classesIndeterminate = indeterminate ? animIndeterminate : "");
      }
      $$invalidate(6, classesTrack = `${cTrack$1} ${track} ${height} ${rounded} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty & /*meter, rounded, classesIndeterminate, transition*/
      22016) {
        $$invalidate(5, classesMeter = `${cMeter} ${meter} ${rounded} ${classesIndeterminate} ${transition}`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      value,
      min,
      max2,
      labelledby,
      indeterminate,
      classesMeter,
      classesTrack,
      fillPercent,
      height,
      rounded,
      transition,
      animIndeterminate,
      meter,
      track,
      classesIndeterminate
    ];
  }
  class ProgressBar extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$j, create_fragment$j, safe_not_equal, {
        value: 0,
        min: 1,
        max: 2,
        height: 8,
        rounded: 9,
        transition: 10,
        animIndeterminate: 11,
        meter: 12,
        track: 13,
        labelledby: 3
      });
    }
  }
  function create_if_block$d(ctx) {
    let text_1;
    let text_1_class_value;
    let current;
    const default_slot_template = (
      /*#slots*/
      ctx[16].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[15],
      null
    );
    return {
      c() {
        text_1 = svg_element("text");
        if (default_slot) default_slot.c();
        attr(text_1, "x", "50%");
        attr(text_1, "y", "50%");
        attr(text_1, "text-anchor", "middle");
        attr(text_1, "dominant-baseline", "middle");
        attr(text_1, "font-weight", "bold");
        attr(
          text_1,
          "font-size",
          /*font*/
          ctx[2]
        );
        attr(text_1, "class", text_1_class_value = "progress-radial-text " + /*fill*/
        ctx[7]);
      },
      m(target, anchor) {
        insert(target, text_1, anchor);
        if (default_slot) {
          default_slot.m(text_1, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          32768)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[15],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[15]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[15],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*font*/
        4) {
          attr(
            text_1,
            "font-size",
            /*font*/
            ctx2[2]
          );
        }
        if (!current || dirty & /*fill*/
        128 && text_1_class_value !== (text_1_class_value = "progress-radial-text " + /*fill*/
        ctx2[7])) {
          attr(text_1, "class", text_1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(text_1);
        }
        if (default_slot) default_slot.d(detaching);
      }
    };
  }
  function create_fragment$i(ctx) {
    let figure;
    let svg;
    let circle0;
    let circle0_class_value;
    let circle1;
    let circle1_class_value;
    let style_stroke_dasharray = `${/*circumference*/
  ctx[9]}
			${/*circumference*/
  ctx[9]}`;
    let figure_class_value;
    let figure_aria_valuenow_value;
    let figure_aria_valuetext_value;
    let current;
    let if_block = (
      /*value*/
      ctx[0] != void 0 && /*value*/
      ctx[0] >= 0 && /*$$slots*/
      ctx[13].default && create_if_block$d(ctx)
    );
    return {
      c() {
        figure = element("figure");
        svg = svg_element("svg");
        circle0 = svg_element("circle");
        circle1 = svg_element("circle");
        if (if_block) if_block.c();
        attr(circle0, "class", circle0_class_value = "progress-radial-track " + cBaseTrack + " " + /*track*/
        ctx[6]);
        attr(
          circle0,
          "stroke-width",
          /*stroke*/
          ctx[1]
        );
        attr(
          circle0,
          "r",
          /*radius*/
          ctx[12]
        );
        attr(circle0, "cx", "50%");
        attr(circle0, "cy", "50%");
        attr(circle1, "class", circle1_class_value = "progress-radial-meter " + cBaseMeter + " " + /*meter*/
        ctx[5] + " " + /*transition*/
        ctx[4]);
        attr(
          circle1,
          "stroke-width",
          /*stroke*/
          ctx[1]
        );
        attr(
          circle1,
          "r",
          /*radius*/
          ctx[12]
        );
        attr(circle1, "cx", "50%");
        attr(circle1, "cy", "50%");
        attr(
          circle1,
          "stroke-linecap",
          /*strokeLinecap*/
          ctx[3]
        );
        set_style(circle1, "stroke-dasharray", style_stroke_dasharray);
        set_style(
          circle1,
          "stroke-dashoffset",
          /*dashoffset*/
          ctx[10]
        );
        attr(svg, "viewBox", "0 0 " + baseSize + " " + baseSize);
        attr(svg, "class", "rounded-full");
        toggle_class(
          svg,
          "animate-spin",
          /*value*/
          ctx[0] === void 0
        );
        attr(figure, "class", figure_class_value = "progress-radial " + /*classesBase*/
        ctx[11]);
        attr(figure, "data-testid", "progress-radial");
        attr(figure, "role", "meter");
        attr(
          figure,
          "aria-labelledby",
          /*labelledby*/
          ctx[8]
        );
        attr(figure, "aria-valuenow", figure_aria_valuenow_value = /*value*/
        ctx[0] || 0);
        attr(figure, "aria-valuetext", figure_aria_valuetext_value = /*value*/
        ctx[0] ? `${/*value*/
      ctx[0]}%` : "Indeterminate Spinner");
        attr(figure, "aria-valuemin", 0);
        attr(figure, "aria-valuemax", 100);
      },
      m(target, anchor) {
        insert(target, figure, anchor);
        append(figure, svg);
        append(svg, circle0);
        append(svg, circle1);
        if (if_block) if_block.m(svg, null);
        current = true;
      },
      p(ctx2, [dirty]) {
        if (!current || dirty & /*track*/
        64 && circle0_class_value !== (circle0_class_value = "progress-radial-track " + cBaseTrack + " " + /*track*/
        ctx2[6])) {
          attr(circle0, "class", circle0_class_value);
        }
        if (!current || dirty & /*stroke*/
        2) {
          attr(
            circle0,
            "stroke-width",
            /*stroke*/
            ctx2[1]
          );
        }
        if (!current || dirty & /*meter, transition*/
        48 && circle1_class_value !== (circle1_class_value = "progress-radial-meter " + cBaseMeter + " " + /*meter*/
        ctx2[5] + " " + /*transition*/
        ctx2[4])) {
          attr(circle1, "class", circle1_class_value);
        }
        if (!current || dirty & /*stroke*/
        2) {
          attr(
            circle1,
            "stroke-width",
            /*stroke*/
            ctx2[1]
          );
        }
        if (!current || dirty & /*strokeLinecap*/
        8) {
          attr(
            circle1,
            "stroke-linecap",
            /*strokeLinecap*/
            ctx2[3]
          );
        }
        if (dirty & /*circumference*/
        512 && style_stroke_dasharray !== (style_stroke_dasharray = `${/*circumference*/
      ctx2[9]}
			${/*circumference*/
      ctx2[9]}`)) {
          set_style(circle1, "stroke-dasharray", style_stroke_dasharray);
        }
        if (dirty & /*dashoffset*/
        1024) {
          set_style(
            circle1,
            "stroke-dashoffset",
            /*dashoffset*/
            ctx2[10]
          );
        }
        if (
          /*value*/
          ctx2[0] != void 0 && /*value*/
          ctx2[0] >= 0 && /*$$slots*/
          ctx2[13].default
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty & /*value, $$slots*/
            8193) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$d(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(svg, null);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
        if (!current || dirty & /*value, undefined*/
        1) {
          toggle_class(
            svg,
            "animate-spin",
            /*value*/
            ctx2[0] === void 0
          );
        }
        if (!current || dirty & /*classesBase*/
        2048 && figure_class_value !== (figure_class_value = "progress-radial " + /*classesBase*/
        ctx2[11])) {
          attr(figure, "class", figure_class_value);
        }
        if (!current || dirty & /*labelledby*/
        256) {
          attr(
            figure,
            "aria-labelledby",
            /*labelledby*/
            ctx2[8]
          );
        }
        if (!current || dirty & /*value*/
        1 && figure_aria_valuenow_value !== (figure_aria_valuenow_value = /*value*/
        ctx2[0] || 0)) {
          attr(figure, "aria-valuenow", figure_aria_valuenow_value);
        }
        if (!current || dirty & /*value*/
        1 && figure_aria_valuetext_value !== (figure_aria_valuetext_value = /*value*/
        ctx2[0] ? `${/*value*/
      ctx2[0]}%` : "Indeterminate Spinner")) {
          attr(figure, "aria-valuetext", figure_aria_valuetext_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(figure);
        }
        if (if_block) if_block.d();
      }
    };
  }
  const cBase$6 = "progress-radial relative overflow-hidden";
  const cBaseTrack = "fill-transparent";
  const cBaseMeter = "fill-transparent -rotate-90 origin-[50%_50%]";
  const baseSize = 512;
  function instance$i($$self, $$props, $$invalidate) {
    let classesBase;
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    let { value = void 0 } = $$props;
    let { stroke = 40 } = $$props;
    let { font = 56 } = $$props;
    let { strokeLinecap = "butt" } = $$props;
    let { transition = "transition-[stroke-dashoffset]" } = $$props;
    let { width = "w-36" } = $$props;
    let { meter = "stroke-surface-900 dark:stroke-surface-50" } = $$props;
    let { track = "stroke-surface-500/30" } = $$props;
    let { fill = "fill-token" } = $$props;
    let { labelledby = "" } = $$props;
    const radius = baseSize / 2 - stroke / 2;
    let circumference = radius;
    let dashoffset;
    function setProgress(percent) {
      $$invalidate(9, circumference = radius * 2 * Math.PI);
      $$invalidate(10, dashoffset = circumference - percent / 100 * circumference);
    }
    setProgress(0);
    afterUpdate(() => {
      setProgress(value === void 0 ? 25 : value);
    });
    $$self.$$set = ($$new_props) => {
      $$invalidate(18, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("value" in $$new_props) $$invalidate(0, value = $$new_props.value);
      if ("stroke" in $$new_props) $$invalidate(1, stroke = $$new_props.stroke);
      if ("font" in $$new_props) $$invalidate(2, font = $$new_props.font);
      if ("strokeLinecap" in $$new_props) $$invalidate(3, strokeLinecap = $$new_props.strokeLinecap);
      if ("transition" in $$new_props) $$invalidate(4, transition = $$new_props.transition);
      if ("width" in $$new_props) $$invalidate(14, width = $$new_props.width);
      if ("meter" in $$new_props) $$invalidate(5, meter = $$new_props.meter);
      if ("track" in $$new_props) $$invalidate(6, track = $$new_props.track);
      if ("fill" in $$new_props) $$invalidate(7, fill = $$new_props.fill);
      if ("labelledby" in $$new_props) $$invalidate(8, labelledby = $$new_props.labelledby);
      if ("$$scope" in $$new_props) $$invalidate(15, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(11, classesBase = `${cBase$6} ${width} ${$$props.class ?? ""}`);
    };
    $$props = exclude_internal_props($$props);
    return [
      value,
      stroke,
      font,
      strokeLinecap,
      transition,
      meter,
      track,
      fill,
      labelledby,
      circumference,
      dashoffset,
      classesBase,
      radius,
      $$slots,
      width,
      $$scope,
      slots
    ];
  }
  class ProgressRadial extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$i, create_fragment$i, safe_not_equal, {
        value: 0,
        stroke: 1,
        font: 2,
        strokeLinecap: 3,
        transition: 4,
        width: 14,
        meter: 5,
        track: 6,
        fill: 7,
        labelledby: 8
      });
    }
  }
  function create_fragment$h(ctx) {
    let div;
    let div_class_value;
    let current;
    const default_slot_template = (
      /*#slots*/
      ctx[15].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[14],
      null
    );
    return {
      c() {
        div = element("div");
        if (default_slot) default_slot.c();
        attr(div, "class", div_class_value = "radio-group " + /*classesBase*/
        ctx[1]);
        attr(div, "data-testid", "radio-group");
        attr(div, "role", "radiogroup");
        attr(
          div,
          "aria-labelledby",
          /*labelledby*/
          ctx[0]
        );
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (default_slot) {
          default_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, [dirty]) {
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          16384)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[14],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[14]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[14],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*classesBase*/
        2 && div_class_value !== (div_class_value = "radio-group " + /*classesBase*/
        ctx2[1])) {
          attr(div, "class", div_class_value);
        }
        if (!current || dirty & /*labelledby*/
        1) {
          attr(
            div,
            "aria-labelledby",
            /*labelledby*/
            ctx2[0]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (default_slot) default_slot.d(detaching);
      }
    };
  }
  const cBase$5 = "p-1";
  function instance$h($$self, $$props, $$invalidate) {
    let classesBase;
    let { $$slots: slots = {}, $$scope } = $$props;
    let { display = "inline-flex" } = $$props;
    let { flexDirection = "flex-row" } = $$props;
    let { gap = "gap-1" } = $$props;
    let { background = "bg-surface-200-700-token" } = $$props;
    let { border = "border-token border-surface-400-500-token" } = $$props;
    let { rounded = "rounded-token" } = $$props;
    let { padding = "px-4 py-1" } = $$props;
    let { active: active2 = "variant-filled" } = $$props;
    let { hover = "hover:variant-soft" } = $$props;
    let { color = "" } = $$props;
    let { fill = "" } = $$props;
    let { regionLabel = "" } = $$props;
    let { labelledby = "" } = $$props;
    setContext("rounded", rounded);
    setContext("padding", padding);
    setContext("active", active2);
    setContext("hover", hover);
    setContext("color", color);
    setContext("fill", fill);
    setContext("regionLabel", regionLabel);
    $$self.$$set = ($$new_props) => {
      $$invalidate(16, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("display" in $$new_props) $$invalidate(2, display = $$new_props.display);
      if ("flexDirection" in $$new_props) $$invalidate(3, flexDirection = $$new_props.flexDirection);
      if ("gap" in $$new_props) $$invalidate(4, gap = $$new_props.gap);
      if ("background" in $$new_props) $$invalidate(5, background = $$new_props.background);
      if ("border" in $$new_props) $$invalidate(6, border = $$new_props.border);
      if ("rounded" in $$new_props) $$invalidate(7, rounded = $$new_props.rounded);
      if ("padding" in $$new_props) $$invalidate(8, padding = $$new_props.padding);
      if ("active" in $$new_props) $$invalidate(9, active2 = $$new_props.active);
      if ("hover" in $$new_props) $$invalidate(10, hover = $$new_props.hover);
      if ("color" in $$new_props) $$invalidate(11, color = $$new_props.color);
      if ("fill" in $$new_props) $$invalidate(12, fill = $$new_props.fill);
      if ("regionLabel" in $$new_props) $$invalidate(13, regionLabel = $$new_props.regionLabel);
      if ("labelledby" in $$new_props) $$invalidate(0, labelledby = $$new_props.labelledby);
      if ("$$scope" in $$new_props) $$invalidate(14, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(1, classesBase = `${cBase$5} ${display} ${flexDirection} ${gap} ${background} ${border} ${rounded} ${$$props.class ?? ""}`);
    };
    $$props = exclude_internal_props($$props);
    return [
      labelledby,
      classesBase,
      display,
      flexDirection,
      gap,
      background,
      border,
      rounded,
      padding,
      active2,
      hover,
      color,
      fill,
      regionLabel,
      $$scope,
      slots
    ];
  }
  class RadioGroup extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$h, create_fragment$h, safe_not_equal, {
        display: 2,
        flexDirection: 3,
        gap: 4,
        background: 5,
        border: 6,
        rounded: 7,
        padding: 8,
        active: 9,
        hover: 10,
        color: 11,
        fill: 12,
        regionLabel: 13,
        labelledby: 0
      });
    }
  }
  function create_fragment$g(ctx) {
    let label_1;
    let div1;
    let div0;
    let input;
    let t2;
    let div1_class_value;
    let label_1_class_value;
    let current;
    let binding_group;
    let mounted;
    let dispose;
    let input_levels = [
      { type: "radio" },
      { name: (
        /*name*/
        ctx[1]
      ) },
      { __value: (
        /*value*/
        ctx[2]
      ) },
      /*prunedRestProps*/
      ctx[11](),
      { tabindex: "-1" }
    ];
    let input_data = {};
    for (let i = 0; i < input_levels.length; i += 1) {
      input_data = assign(input_data, input_levels[i]);
    }
    const default_slot_template = (
      /*#slots*/
      ctx[21].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[20],
      null
    );
    binding_group = init_binding_group(
      /*$$binding_groups*/
      ctx[29][0]
    );
    return {
      c() {
        label_1 = element("label");
        div1 = element("div");
        div0 = element("div");
        input = element("input");
        t2 = space();
        if (default_slot) default_slot.c();
        set_attributes(input, input_data);
        attr(div0, "class", "h-0 w-0 overflow-hidden");
        attr(div1, "class", div1_class_value = "radio-item " + /*classesWrapper*/
        ctx[8]);
        attr(div1, "data-testid", "radio-item");
        attr(div1, "role", "radio");
        attr(
          div1,
          "aria-checked",
          /*checked*/
          ctx[6]
        );
        attr(
          div1,
          "aria-label",
          /*label*/
          ctx[4]
        );
        attr(div1, "tabindex", "0");
        attr(
          div1,
          "title",
          /*title*/
          ctx[3]
        );
        attr(label_1, "class", label_1_class_value = "radio-label " + /*classsBase*/
        ctx[9] + " " + /*regionLabel*/
        ctx[5]);
        binding_group.p(input);
      },
      m(target, anchor) {
        insert(target, label_1, anchor);
        append(label_1, div1);
        append(div1, div0);
        append(div0, input);
        if (input.autofocus) input.focus();
        ctx[27](input);
        input.checked = input.__value === /*group*/
        ctx[0];
        append(div1, t2);
        if (default_slot) {
          default_slot.m(div1, null);
        }
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_handler*/
              ctx[28]
            ),
            listen(
              input,
              "click",
              /*click_handler*/
              ctx[25]
            ),
            listen(
              input,
              "change",
              /*change_handler*/
              ctx[26]
            ),
            listen(
              div1,
              "keydown",
              /*onKeyDown*/
              ctx[10]
            ),
            listen(
              div1,
              "keydown",
              /*keydown_handler*/
              ctx[22]
            ),
            listen(
              div1,
              "keyup",
              /*keyup_handler*/
              ctx[23]
            ),
            listen(
              div1,
              "keypress",
              /*keypress_handler*/
              ctx[24]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        set_attributes(input, input_data = get_spread_update(input_levels, [
          { type: "radio" },
          (!current || dirty[0] & /*name*/
          2) && { name: (
            /*name*/
            ctx2[1]
          ) },
          (!current || dirty[0] & /*value*/
          4) && { __value: (
            /*value*/
            ctx2[2]
          ) },
          /*prunedRestProps*/
          ctx2[11](),
          { tabindex: "-1" }
        ]));
        if (dirty[0] & /*group*/
        1) {
          input.checked = input.__value === /*group*/
          ctx2[0];
        }
        if (default_slot) {
          if (default_slot.p && (!current || dirty[0] & /*$$scope*/
          1048576)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[20],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[20]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[20],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty[0] & /*classesWrapper*/
        256 && div1_class_value !== (div1_class_value = "radio-item " + /*classesWrapper*/
        ctx2[8])) {
          attr(div1, "class", div1_class_value);
        }
        if (!current || dirty[0] & /*checked*/
        64) {
          attr(
            div1,
            "aria-checked",
            /*checked*/
            ctx2[6]
          );
        }
        if (!current || dirty[0] & /*label*/
        16) {
          attr(
            div1,
            "aria-label",
            /*label*/
            ctx2[4]
          );
        }
        if (!current || dirty[0] & /*title*/
        8) {
          attr(
            div1,
            "title",
            /*title*/
            ctx2[3]
          );
        }
        if (!current || dirty[0] & /*classsBase, regionLabel*/
        544 && label_1_class_value !== (label_1_class_value = "radio-label " + /*classsBase*/
        ctx2[9] + " " + /*regionLabel*/
        ctx2[5])) {
          attr(label_1, "class", label_1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(label_1);
        }
        ctx[27](null);
        if (default_slot) default_slot.d(detaching);
        binding_group.r();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBase$4 = "flex-auto";
  const cWrapper = "text-base text-center cursor-pointer";
  const cDisabled = "opacity-50 cursor-not-allowed";
  function instance$g($$self, $$props, $$invalidate) {
    let checked;
    let classesActive;
    let classesDisabled;
    let classsBase;
    let classesWrapper;
    const omit_props_names = [
      "group",
      "name",
      "value",
      "title",
      "label",
      "rounded",
      "padding",
      "active",
      "hover",
      "color",
      "fill",
      "regionLabel"
    ];
    let $$restProps = compute_rest_props($$props, omit_props_names);
    let { $$slots: slots = {}, $$scope } = $$props;
    let { group } = $$props;
    let { name } = $$props;
    let { value } = $$props;
    let { title = "" } = $$props;
    let { label = "" } = $$props;
    let { rounded = getContext("rounded") } = $$props;
    let { padding = getContext("padding") } = $$props;
    let { active: active2 = getContext("active") } = $$props;
    let { hover = getContext("hover") } = $$props;
    let { color = getContext("color") } = $$props;
    let { fill = getContext("fill") } = $$props;
    let { regionLabel = getContext("regionLabel") } = $$props;
    let elemInput;
    function onKeyDown(event) {
      if (["Enter", "Space"].includes(event.code)) {
        event.preventDefault();
        elemInput.click();
      }
    }
    function prunedRestProps() {
      delete $$restProps.class;
      return $$restProps;
    }
    const $$binding_groups = [[]];
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keyup_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keypress_handler(event) {
      bubble.call(this, $$self, event);
    }
    function click_handler(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler(event) {
      bubble.call(this, $$self, event);
    }
    function input_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        elemInput = $$value;
        $$invalidate(7, elemInput);
      });
    }
    function input_change_handler() {
      group = this.__value;
      $$invalidate(0, group);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(31, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      $$invalidate(30, $$restProps = compute_rest_props($$props, omit_props_names));
      if ("group" in $$new_props) $$invalidate(0, group = $$new_props.group);
      if ("name" in $$new_props) $$invalidate(1, name = $$new_props.name);
      if ("value" in $$new_props) $$invalidate(2, value = $$new_props.value);
      if ("title" in $$new_props) $$invalidate(3, title = $$new_props.title);
      if ("label" in $$new_props) $$invalidate(4, label = $$new_props.label);
      if ("rounded" in $$new_props) $$invalidate(12, rounded = $$new_props.rounded);
      if ("padding" in $$new_props) $$invalidate(13, padding = $$new_props.padding);
      if ("active" in $$new_props) $$invalidate(14, active2 = $$new_props.active);
      if ("hover" in $$new_props) $$invalidate(15, hover = $$new_props.hover);
      if ("color" in $$new_props) $$invalidate(16, color = $$new_props.color);
      if ("fill" in $$new_props) $$invalidate(17, fill = $$new_props.fill);
      if ("regionLabel" in $$new_props) $$invalidate(5, regionLabel = $$new_props.regionLabel);
      if ("$$scope" in $$new_props) $$invalidate(20, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty[0] & /*value, group*/
      5) {
        $$invalidate(6, checked = value === group);
      }
      if ($$self.$$.dirty[0] & /*checked, active, color, fill, hover*/
      245824) {
        $$invalidate(19, classesActive = checked ? `${active2} ${color} ${fill}` : hover);
      }
      $$invalidate(18, classesDisabled = $$props.disabled ? cDisabled : "");
      $$invalidate(8, classesWrapper = `${cWrapper} ${padding} ${rounded} ${classesActive} ${classesDisabled} ${$$props.class ?? ""}`);
    };
    $$invalidate(9, classsBase = `${cBase$4}`);
    $$props = exclude_internal_props($$props);
    return [
      group,
      name,
      value,
      title,
      label,
      regionLabel,
      checked,
      elemInput,
      classesWrapper,
      classsBase,
      onKeyDown,
      prunedRestProps,
      rounded,
      padding,
      active2,
      hover,
      color,
      fill,
      classesDisabled,
      classesActive,
      $$scope,
      slots,
      keydown_handler,
      keyup_handler,
      keypress_handler,
      click_handler,
      change_handler,
      input_binding,
      input_change_handler,
      $$binding_groups
    ];
  }
  class RadioItem extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$g,
        create_fragment$g,
        safe_not_equal,
        {
          group: 0,
          name: 1,
          value: 2,
          title: 3,
          label: 4,
          rounded: 12,
          padding: 13,
          active: 14,
          hover: 15,
          color: 16,
          fill: 17,
          regionLabel: 5
        },
        null,
        [-1, -1]
      );
    }
  }
  const get_trail_slot_changes = (dirty) => ({});
  const get_trail_slot_context = (ctx) => ({});
  function get_each_context$4(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[23] = list[i];
    return child_ctx;
  }
  function create_if_block_2$5(ctx) {
    let label_1;
    let current;
    const default_slot_template = (
      /*#slots*/
      ctx[15].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[14],
      null
    );
    return {
      c() {
        label_1 = element("label");
        if (default_slot) default_slot.c();
        attr(label_1, "class", "range-slider-label " + cBaseLabel);
        attr(
          label_1,
          "for",
          /*id*/
          ctx[2]
        );
      },
      m(target, anchor) {
        insert(target, label_1, anchor);
        if (default_slot) {
          default_slot.m(label_1, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          16384)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[14],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[14]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[14],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*id*/
        4) {
          attr(
            label_1,
            "for",
            /*id*/
            ctx2[2]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(label_1);
        }
        if (default_slot) default_slot.d(detaching);
      }
    };
  }
  function create_if_block_1$7(ctx) {
    let datalist;
    let datalist_id_value;
    let each_value = ensure_array_like(
      /*tickmarks*/
      ctx[8]
    );
    let each_blocks = [];
    for (let i = 0; i < each_value.length; i += 1) {
      each_blocks[i] = create_each_block$4(get_each_context$4(ctx, each_value, i));
    }
    return {
      c() {
        datalist = element("datalist");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        attr(datalist, "id", datalist_id_value = "tickmarks-" + /*id*/
        ctx[2]);
        attr(datalist, "class", "range-slider-ticks");
      },
      m(target, anchor) {
        insert(target, datalist, anchor);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(datalist, null);
          }
        }
      },
      p(ctx2, dirty) {
        if (dirty & /*tickmarks*/
        256) {
          each_value = ensure_array_like(
            /*tickmarks*/
            ctx2[8]
          );
          let i;
          for (i = 0; i < each_value.length; i += 1) {
            const child_ctx = get_each_context$4(ctx2, each_value, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
            } else {
              each_blocks[i] = create_each_block$4(child_ctx);
              each_blocks[i].c();
              each_blocks[i].m(datalist, null);
            }
          }
          for (; i < each_blocks.length; i += 1) {
            each_blocks[i].d(1);
          }
          each_blocks.length = each_value.length;
        }
        if (dirty & /*id*/
        4 && datalist_id_value !== (datalist_id_value = "tickmarks-" + /*id*/
        ctx2[2])) {
          attr(datalist, "id", datalist_id_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(datalist);
        }
        destroy_each(each_blocks, detaching);
      }
    };
  }
  function create_each_block$4(ctx) {
    let option;
    let option_value_value;
    let option_label_value;
    return {
      c() {
        option = element("option");
        option.__value = option_value_value = /*tm*/
        ctx[23];
        set_input_value(option, option.__value);
        attr(option, "label", option_label_value = /*tm*/
        ctx[23]);
      },
      m(target, anchor) {
        insert(target, option, anchor);
      },
      p(ctx2, dirty) {
        if (dirty & /*tickmarks*/
        256 && option_value_value !== (option_value_value = /*tm*/
        ctx2[23])) {
          option.__value = option_value_value;
          set_input_value(option, option.__value);
        }
        if (dirty & /*tickmarks*/
        256 && option_label_value !== (option_label_value = /*tm*/
        ctx2[23])) {
          attr(option, "label", option_label_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(option);
        }
      }
    };
  }
  function create_if_block$c(ctx) {
    let div;
    let current;
    const trail_slot_template = (
      /*#slots*/
      ctx[15].trail
    );
    const trail_slot = create_slot(
      trail_slot_template,
      ctx,
      /*$$scope*/
      ctx[14],
      get_trail_slot_context
    );
    return {
      c() {
        div = element("div");
        if (trail_slot) trail_slot.c();
        attr(div, "class", "range-slider-trail");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (trail_slot) {
          trail_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (trail_slot) {
          if (trail_slot.p && (!current || dirty & /*$$scope*/
          16384)) {
            update_slot_base(
              trail_slot,
              trail_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[14],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[14]
              ) : get_slot_changes(
                trail_slot_template,
                /*$$scope*/
                ctx2[14],
                dirty,
                get_trail_slot_changes
              ),
              get_trail_slot_context
            );
          }
        }
      },
      i(local) {
        if (current) return;
        transition_in(trail_slot, local);
        current = true;
      },
      o(local) {
        transition_out(trail_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (trail_slot) trail_slot.d(detaching);
      }
    };
  }
  function create_fragment$f(ctx) {
    let div1;
    let t0;
    let div0;
    let input;
    let input_class_value;
    let input_list_value;
    let t1;
    let t2;
    let div1_class_value;
    let current;
    let mounted;
    let dispose;
    let if_block0 = (
      /*$$slots*/
      ctx[12].default && create_if_block_2$5(ctx)
    );
    let input_levels = [
      { type: "range" },
      { id: (
        /*id*/
        ctx[2]
      ) },
      { name: (
        /*name*/
        ctx[1]
      ) },
      {
        class: input_class_value = "range-slider-input " + /*classesInput*/
        ctx[9]
      },
      {
        list: input_list_value = "tickmarks-" + /*id*/
        ctx[2]
      },
      { "aria-label": (
        /*label*/
        ctx[7]
      ) },
      { min: (
        /*min*/
        ctx[3]
      ) },
      { max: (
        /*max*/
        ctx[4]
      ) },
      { step: (
        /*step*/
        ctx[5]
      ) },
      /*prunedRestProps*/
      ctx[11]()
    ];
    let input_data = {};
    for (let i = 0; i < input_levels.length; i += 1) {
      input_data = assign(input_data, input_levels[i]);
    }
    let if_block1 = (
      /*ticked*/
      ctx[6] && /*tickmarks*/
      ctx[8] && /*tickmarks*/
      ctx[8].length && create_if_block_1$7(ctx)
    );
    let if_block2 = (
      /*$$slots*/
      ctx[12].trail && create_if_block$c(ctx)
    );
    return {
      c() {
        div1 = element("div");
        if (if_block0) if_block0.c();
        t0 = space();
        div0 = element("div");
        input = element("input");
        t1 = space();
        if (if_block1) if_block1.c();
        t2 = space();
        if (if_block2) if_block2.c();
        set_attributes(input, input_data);
        attr(div0, "class", "range-content " + cBaseContent);
        attr(div1, "class", div1_class_value = "range-slider " + /*classesBase*/
        ctx[10]);
        attr(div1, "data-testid", "range-slider");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        if (if_block0) if_block0.m(div1, null);
        append(div1, t0);
        append(div1, div0);
        append(div0, input);
        if (input.autofocus) input.focus();
        set_input_value(
          input,
          /*value*/
          ctx[0]
        );
        append(div0, t1);
        if (if_block1) if_block1.m(div0, null);
        append(div1, t2);
        if (if_block2) if_block2.m(div1, null);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_input_handler*/
              ctx[19]
            ),
            listen(
              input,
              "input",
              /*input_change_input_handler*/
              ctx[19]
            ),
            listen(
              input,
              "click",
              /*click_handler*/
              ctx[16]
            ),
            listen(
              input,
              "change",
              /*change_handler*/
              ctx[17]
            ),
            listen(
              input,
              "blur",
              /*blur_handler*/
              ctx[18]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, [dirty]) {
        if (
          /*$$slots*/
          ctx2[12].default
        ) {
          if (if_block0) {
            if_block0.p(ctx2, dirty);
            if (dirty & /*$$slots*/
            4096) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_2$5(ctx2);
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(div1, t0);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        set_attributes(input, input_data = get_spread_update(input_levels, [
          { type: "range" },
          (!current || dirty & /*id*/
          4) && { id: (
            /*id*/
            ctx2[2]
          ) },
          (!current || dirty & /*name*/
          2) && { name: (
            /*name*/
            ctx2[1]
          ) },
          (!current || dirty & /*classesInput*/
          512 && input_class_value !== (input_class_value = "range-slider-input " + /*classesInput*/
          ctx2[9])) && { class: input_class_value },
          (!current || dirty & /*id*/
          4 && input_list_value !== (input_list_value = "tickmarks-" + /*id*/
          ctx2[2])) && { list: input_list_value },
          (!current || dirty & /*label*/
          128) && { "aria-label": (
            /*label*/
            ctx2[7]
          ) },
          (!current || dirty & /*min*/
          8) && { min: (
            /*min*/
            ctx2[3]
          ) },
          (!current || dirty & /*max*/
          16) && { max: (
            /*max*/
            ctx2[4]
          ) },
          (!current || dirty & /*step*/
          32) && { step: (
            /*step*/
            ctx2[5]
          ) },
          /*prunedRestProps*/
          ctx2[11]()
        ]));
        if (dirty & /*value*/
        1) {
          set_input_value(
            input,
            /*value*/
            ctx2[0]
          );
        }
        if (
          /*ticked*/
          ctx2[6] && /*tickmarks*/
          ctx2[8] && /*tickmarks*/
          ctx2[8].length
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
          } else {
            if_block1 = create_if_block_1$7(ctx2);
            if_block1.c();
            if_block1.m(div0, null);
          }
        } else if (if_block1) {
          if_block1.d(1);
          if_block1 = null;
        }
        if (
          /*$$slots*/
          ctx2[12].trail
        ) {
          if (if_block2) {
            if_block2.p(ctx2, dirty);
            if (dirty & /*$$slots*/
            4096) {
              transition_in(if_block2, 1);
            }
          } else {
            if_block2 = create_if_block$c(ctx2);
            if_block2.c();
            transition_in(if_block2, 1);
            if_block2.m(div1, null);
          }
        } else if (if_block2) {
          group_outros();
          transition_out(if_block2, 1, 1, () => {
            if_block2 = null;
          });
          check_outros();
        }
        if (!current || dirty & /*classesBase*/
        1024 && div1_class_value !== (div1_class_value = "range-slider " + /*classesBase*/
        ctx2[10])) {
          attr(div1, "class", div1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block0);
        transition_in(if_block2);
        current = true;
      },
      o(local) {
        transition_out(if_block0);
        transition_out(if_block2);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        if (if_block0) if_block0.d();
        if (if_block1) if_block1.d();
        if (if_block2) if_block2.d();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBase$3 = "space-y-2";
  const cBaseLabel = "";
  const cBaseContent = "flex justify-center py-2";
  const cBaseInput = "w-full h-2";
  function instance$f($$self, $$props, $$invalidate) {
    let classesBase;
    let classesInput;
    const omit_props_names = ["name", "id", "value", "min", "max", "step", "ticked", "accent", "label"];
    let $$restProps = compute_rest_props($$props, omit_props_names);
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    let { name } = $$props;
    let { id = String(Math.random()) } = $$props;
    let { value = 0 } = $$props;
    let { min = 0 } = $$props;
    let { max: max2 = 100 } = $$props;
    let { step: step2 = 1 } = $$props;
    let { ticked = false } = $$props;
    let { accent = "accent-surface-900 dark:accent-surface-50" } = $$props;
    let { label = "" } = $$props;
    let tickmarks;
    function setTicks() {
      if (ticked == false) return;
      $$invalidate(8, tickmarks = Array.from({ length: max2 - min + 1 }, (_, i) => i + min));
    }
    if (ticked) setTicks();
    afterUpdate(() => {
      setTicks();
    });
    function prunedRestProps() {
      delete $$restProps.class;
      return $$restProps;
    }
    function click_handler(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler(event) {
      bubble.call(this, $$self, event);
    }
    function blur_handler(event) {
      bubble.call(this, $$self, event);
    }
    function input_change_input_handler() {
      value = to_number(this.value);
      $$invalidate(0, value);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(22, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      $$invalidate(21, $$restProps = compute_rest_props($$props, omit_props_names));
      if ("name" in $$new_props) $$invalidate(1, name = $$new_props.name);
      if ("id" in $$new_props) $$invalidate(2, id = $$new_props.id);
      if ("value" in $$new_props) $$invalidate(0, value = $$new_props.value);
      if ("min" in $$new_props) $$invalidate(3, min = $$new_props.min);
      if ("max" in $$new_props) $$invalidate(4, max2 = $$new_props.max);
      if ("step" in $$new_props) $$invalidate(5, step2 = $$new_props.step);
      if ("ticked" in $$new_props) $$invalidate(6, ticked = $$new_props.ticked);
      if ("accent" in $$new_props) $$invalidate(13, accent = $$new_props.accent);
      if ("label" in $$new_props) $$invalidate(7, label = $$new_props.label);
      if ("$$scope" in $$new_props) $$invalidate(14, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(10, classesBase = `${cBase$3} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty & /*accent*/
      8192) {
        $$invalidate(9, classesInput = `${cBaseInput} ${accent}`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      value,
      name,
      id,
      min,
      max2,
      step2,
      ticked,
      label,
      tickmarks,
      classesInput,
      classesBase,
      prunedRestProps,
      $$slots,
      accent,
      $$scope,
      slots,
      click_handler,
      change_handler,
      blur_handler,
      input_change_input_handler
    ];
  }
  class RangeSlider extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$f, create_fragment$f, safe_not_equal, {
        name: 1,
        id: 2,
        value: 0,
        min: 3,
        max: 4,
        step: 5,
        ticked: 6,
        accent: 13,
        label: 7
      });
    }
  }
  function create_if_block$b(ctx) {
    let div;
    let current;
    const default_slot_template = (
      /*#slots*/
      ctx[22].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      null
    );
    return {
      c() {
        div = element("div");
        if (default_slot) default_slot.c();
        attr(div, "class", "slide-toggle-text ml-3");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (default_slot) {
          default_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (default_slot) {
          if (default_slot.p && (!current || dirty[0] & /*$$scope*/
          2097152)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                null
              ),
              null
            );
          }
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (default_slot) default_slot.d(detaching);
      }
    };
  }
  function create_fragment$e(ctx) {
    let div2;
    let label_1;
    let input;
    let input_disabled_value;
    let t0;
    let div1;
    let div0;
    let div0_class_value;
    let div1_class_value;
    let t1;
    let label_1_class_value;
    let div2_class_value;
    let current;
    let mounted;
    let dispose;
    let input_levels = [
      { type: "checkbox" },
      { class: "slide-toggle-input hidden" },
      { name: (
        /*name*/
        ctx[1]
      ) },
      /*prunedRestProps*/
      ctx[8](),
      {
        disabled: input_disabled_value = /*$$props*/
        ctx[9].disabled
      }
    ];
    let input_data = {};
    for (let i = 0; i < input_levels.length; i += 1) {
      input_data = assign(input_data, input_levels[i]);
    }
    let if_block = (
      /*$$slots*/
      ctx[10].default && create_if_block$b(ctx)
    );
    return {
      c() {
        div2 = element("div");
        label_1 = element("label");
        input = element("input");
        t0 = space();
        div1 = element("div");
        div0 = element("div");
        t1 = space();
        if (if_block) if_block.c();
        set_attributes(input, input_data);
        attr(div0, "class", div0_class_value = "slide-toggle-thumb " + /*classesThumb*/
        ctx[3]);
        toggle_class(
          div0,
          "cursor-not-allowed",
          /*$$props*/
          ctx[9].disabled
        );
        attr(div1, "class", div1_class_value = "slide-toggle-track " + /*classesTrack*/
        ctx[4]);
        toggle_class(
          div1,
          "cursor-not-allowed",
          /*$$props*/
          ctx[9].disabled
        );
        attr(label_1, "class", label_1_class_value = "slide-toggle-label " + /*classesLabel*/
        ctx[5]);
        attr(
          div2,
          "id",
          /*label*/
          ctx[2]
        );
        attr(div2, "class", div2_class_value = "slide-toggle " + /*classesBase*/
        ctx[6]);
        attr(div2, "data-testid", "slide-toggle");
        attr(div2, "role", "switch");
        attr(
          div2,
          "aria-label",
          /*label*/
          ctx[2]
        );
        attr(
          div2,
          "aria-checked",
          /*checked*/
          ctx[0]
        );
        attr(div2, "tabindex", "0");
      },
      m(target, anchor) {
        insert(target, div2, anchor);
        append(div2, label_1);
        append(label_1, input);
        if (input.autofocus) input.focus();
        input.checked = /*checked*/
        ctx[0];
        append(label_1, t0);
        append(label_1, div1);
        append(div1, div0);
        append(label_1, t1);
        if (if_block) if_block.m(label_1, null);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_handler*/
              ctx[31]
            ),
            listen(
              input,
              "click",
              /*click_handler*/
              ctx[23]
            ),
            listen(
              input,
              "keydown",
              /*keydown_handler*/
              ctx[24]
            ),
            listen(
              input,
              "keyup",
              /*keyup_handler*/
              ctx[25]
            ),
            listen(
              input,
              "keypress",
              /*keypress_handler*/
              ctx[26]
            ),
            listen(
              input,
              "mouseover",
              /*mouseover_handler*/
              ctx[27]
            ),
            listen(
              input,
              "change",
              /*change_handler*/
              ctx[28]
            ),
            listen(
              input,
              "focus",
              /*focus_handler*/
              ctx[29]
            ),
            listen(
              input,
              "blur",
              /*blur_handler*/
              ctx[30]
            ),
            listen(
              div2,
              "keydown",
              /*onKeyDown*/
              ctx[7]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        set_attributes(input, input_data = get_spread_update(input_levels, [
          { type: "checkbox" },
          { class: "slide-toggle-input hidden" },
          (!current || dirty[0] & /*name*/
          2) && { name: (
            /*name*/
            ctx2[1]
          ) },
          /*prunedRestProps*/
          ctx2[8](),
          (!current || dirty[0] & /*$$props*/
          512 && input_disabled_value !== (input_disabled_value = /*$$props*/
          ctx2[9].disabled)) && { disabled: input_disabled_value }
        ]));
        if (dirty[0] & /*checked*/
        1) {
          input.checked = /*checked*/
          ctx2[0];
        }
        if (!current || dirty[0] & /*classesThumb*/
        8 && div0_class_value !== (div0_class_value = "slide-toggle-thumb " + /*classesThumb*/
        ctx2[3])) {
          attr(div0, "class", div0_class_value);
        }
        if (!current || dirty[0] & /*classesThumb, $$props*/
        520) {
          toggle_class(
            div0,
            "cursor-not-allowed",
            /*$$props*/
            ctx2[9].disabled
          );
        }
        if (!current || dirty[0] & /*classesTrack*/
        16 && div1_class_value !== (div1_class_value = "slide-toggle-track " + /*classesTrack*/
        ctx2[4])) {
          attr(div1, "class", div1_class_value);
        }
        if (!current || dirty[0] & /*classesTrack, $$props*/
        528) {
          toggle_class(
            div1,
            "cursor-not-allowed",
            /*$$props*/
            ctx2[9].disabled
          );
        }
        if (
          /*$$slots*/
          ctx2[10].default
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty[0] & /*$$slots*/
            1024) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$b(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(label_1, null);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*classesLabel*/
        32 && label_1_class_value !== (label_1_class_value = "slide-toggle-label " + /*classesLabel*/
        ctx2[5])) {
          attr(label_1, "class", label_1_class_value);
        }
        if (!current || dirty[0] & /*label*/
        4) {
          attr(
            div2,
            "id",
            /*label*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*classesBase*/
        64 && div2_class_value !== (div2_class_value = "slide-toggle " + /*classesBase*/
        ctx2[6])) {
          attr(div2, "class", div2_class_value);
        }
        if (!current || dirty[0] & /*label*/
        4) {
          attr(
            div2,
            "aria-label",
            /*label*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*checked*/
        1) {
          attr(
            div2,
            "aria-checked",
            /*checked*/
            ctx2[0]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div2);
        }
        if (if_block) if_block.d();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBase$2 = "inline-block";
  const cLabel = "unstyled flex items-center";
  const cTrack = "flex transition-all duration-[200ms] cursor-pointer";
  const cThumb = "w-[50%] h-full scale-[0.8] transition-all duration-[200ms] shadow";
  function instance$e($$self, $$props, $$invalidate) {
    let cTrackActive;
    let cThumbBackground;
    let cThumbPos;
    let classesDisabled;
    let classesBase;
    let classesLabel;
    let classesTrack;
    let classesThumb;
    const omit_props_names = ["name", "checked", "size", "background", "active", "border", "rounded", "label"];
    let $$restProps = compute_rest_props($$props, omit_props_names);
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    const dispatch2 = createEventDispatcher();
    let { name } = $$props;
    let { checked = false } = $$props;
    let { size = "md" } = $$props;
    let { background = "bg-surface-400 dark:bg-surface-700" } = $$props;
    let { active: active2 = "bg-surface-900 dark:bg-surface-300" } = $$props;
    let { border = "" } = $$props;
    let { rounded = "rounded-full" } = $$props;
    let { label = "" } = $$props;
    let trackSize;
    switch (size) {
      case "sm":
        trackSize = "w-12 h-6";
        break;
      case "lg":
        trackSize = "w-20 h-10";
        break;
      default:
        trackSize = "w-16 h-8";
    }
    function onKeyDown(event) {
      if (["Enter", "Space"].includes(event.code)) {
        event.preventDefault();
        dispatch2("keyup", event);
        const inputElem = event.currentTarget.firstChild;
        inputElem.click();
      }
    }
    function prunedRestProps() {
      delete $$restProps.class;
      return $$restProps;
    }
    function click_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keyup_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keypress_handler(event) {
      bubble.call(this, $$self, event);
    }
    function mouseover_handler(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler(event) {
      bubble.call(this, $$self, event);
    }
    function focus_handler(event) {
      bubble.call(this, $$self, event);
    }
    function blur_handler(event) {
      bubble.call(this, $$self, event);
    }
    function input_change_handler() {
      checked = this.checked;
      $$invalidate(0, checked);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(9, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      $$invalidate(33, $$restProps = compute_rest_props($$props, omit_props_names));
      if ("name" in $$new_props) $$invalidate(1, name = $$new_props.name);
      if ("checked" in $$new_props) $$invalidate(0, checked = $$new_props.checked);
      if ("size" in $$new_props) $$invalidate(11, size = $$new_props.size);
      if ("background" in $$new_props) $$invalidate(12, background = $$new_props.background);
      if ("active" in $$new_props) $$invalidate(13, active2 = $$new_props.active);
      if ("border" in $$new_props) $$invalidate(14, border = $$new_props.border);
      if ("rounded" in $$new_props) $$invalidate(15, rounded = $$new_props.rounded);
      if ("label" in $$new_props) $$invalidate(2, label = $$new_props.label);
      if ("$$scope" in $$new_props) $$invalidate(21, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty[0] & /*checked, active, background*/
      12289) {
        $$invalidate(19, cTrackActive = checked ? active2 : `${background} cursor-pointer`);
      }
      if ($$self.$$.dirty[0] & /*checked*/
      1) {
        $$invalidate(18, cThumbBackground = checked ? "bg-white/75" : "bg-white");
      }
      if ($$self.$$.dirty[0] & /*checked*/
      1) {
        $$invalidate(17, cThumbPos = checked ? "translate-x-full" : "");
      }
      $$invalidate(20, classesDisabled = $$props.disabled === true ? "opacity-50" : "hover:brightness-[105%] dark:hover:brightness-110 cursor-pointer");
      $$invalidate(6, classesBase = `${cBase$2} ${rounded} ${classesDisabled} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty[0] & /*border, rounded, trackSize, cTrackActive*/
      638976) {
        $$invalidate(4, classesTrack = `${cTrack} ${border} ${rounded} ${trackSize} ${cTrackActive}`);
      }
      if ($$self.$$.dirty[0] & /*rounded, cThumbBackground, cThumbPos*/
      425984) {
        $$invalidate(3, classesThumb = `${cThumb} ${rounded} ${cThumbBackground} ${cThumbPos}`);
      }
    };
    $$invalidate(5, classesLabel = `${cLabel}`);
    $$props = exclude_internal_props($$props);
    return [
      checked,
      name,
      label,
      classesThumb,
      classesTrack,
      classesLabel,
      classesBase,
      onKeyDown,
      prunedRestProps,
      $$props,
      $$slots,
      size,
      background,
      active2,
      border,
      rounded,
      trackSize,
      cThumbPos,
      cThumbBackground,
      cTrackActive,
      classesDisabled,
      $$scope,
      slots,
      click_handler,
      keydown_handler,
      keyup_handler,
      keypress_handler,
      mouseover_handler,
      change_handler,
      focus_handler,
      blur_handler,
      input_change_handler
    ];
  }
  class SlideToggle extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$e,
        create_fragment$e,
        safe_not_equal,
        {
          name: 1,
          checked: 0,
          size: 11,
          background: 12,
          active: 13,
          border: 14,
          rounded: 15,
          label: 2
        },
        null,
        [-1, -1]
      );
    }
  }
  const get_panel_slot_changes = (dirty) => ({});
  const get_panel_slot_context = (ctx) => ({});
  function create_if_block$a(ctx) {
    let div;
    let div_class_value;
    let current;
    const panel_slot_template = (
      /*#slots*/
      ctx[17].panel
    );
    const panel_slot = create_slot(
      panel_slot_template,
      ctx,
      /*$$scope*/
      ctx[16],
      get_panel_slot_context
    );
    return {
      c() {
        div = element("div");
        if (panel_slot) panel_slot.c();
        attr(div, "class", div_class_value = "tab-panel " + /*classesPanel*/
        ctx[2]);
        attr(div, "role", "tabpanel");
        attr(
          div,
          "aria-labelledby",
          /*panel*/
          ctx[1]
        );
        attr(div, "tabindex", "0");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (panel_slot) {
          panel_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (panel_slot) {
          if (panel_slot.p && (!current || dirty & /*$$scope*/
          65536)) {
            update_slot_base(
              panel_slot,
              panel_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[16],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[16]
              ) : get_slot_changes(
                panel_slot_template,
                /*$$scope*/
                ctx2[16],
                dirty,
                get_panel_slot_changes
              ),
              get_panel_slot_context
            );
          }
        }
        if (!current || dirty & /*classesPanel*/
        4 && div_class_value !== (div_class_value = "tab-panel " + /*classesPanel*/
        ctx2[2])) {
          attr(div, "class", div_class_value);
        }
        if (!current || dirty & /*panel*/
        2) {
          attr(
            div,
            "aria-labelledby",
            /*panel*/
            ctx2[1]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(panel_slot, local);
        current = true;
      },
      o(local) {
        transition_out(panel_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (panel_slot) panel_slot.d(detaching);
      }
    };
  }
  function create_fragment$d(ctx) {
    let div1;
    let div0;
    let div0_class_value;
    let t2;
    let div1_class_value;
    let current;
    const default_slot_template = (
      /*#slots*/
      ctx[17].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[16],
      null
    );
    let if_block = (
      /*$$slots*/
      ctx[5].panel && create_if_block$a(ctx)
    );
    return {
      c() {
        div1 = element("div");
        div0 = element("div");
        if (default_slot) default_slot.c();
        t2 = space();
        if (if_block) if_block.c();
        attr(div0, "class", div0_class_value = "tab-list " + /*classesList*/
        ctx[3]);
        attr(div0, "role", "tablist");
        attr(
          div0,
          "aria-labelledby",
          /*labelledby*/
          ctx[0]
        );
        attr(div1, "class", div1_class_value = "tab-group " + /*classesBase*/
        ctx[4]);
        attr(div1, "data-testid", "tab-group");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, div0);
        if (default_slot) {
          default_slot.m(div0, null);
        }
        append(div1, t2);
        if (if_block) if_block.m(div1, null);
        current = true;
      },
      p(ctx2, [dirty]) {
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          65536)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[16],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[16]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[16],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*classesList*/
        8 && div0_class_value !== (div0_class_value = "tab-list " + /*classesList*/
        ctx2[3])) {
          attr(div0, "class", div0_class_value);
        }
        if (!current || dirty & /*labelledby*/
        1) {
          attr(
            div0,
            "aria-labelledby",
            /*labelledby*/
            ctx2[0]
          );
        }
        if (
          /*$$slots*/
          ctx2[5].panel
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty & /*$$slots*/
            32) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$a(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(div1, null);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
        if (!current || dirty & /*classesBase*/
        16 && div1_class_value !== (div1_class_value = "tab-group " + /*classesBase*/
        ctx2[4])) {
          attr(div1, "class", div1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        if (default_slot) default_slot.d(detaching);
        if (if_block) if_block.d();
      }
    };
  }
  const cBase$1 = "space-y-4";
  const cList = "flex overflow-x-auto hide-scrollbar";
  const cPanel = "";
  function instance$d($$self, $$props, $$invalidate) {
    let classesBase;
    let classesList;
    let classesPanel;
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    let { justify = "justify-start" } = $$props;
    let { border = "border-b border-surface-400-500-token" } = $$props;
    let { active: active2 = "border-b-2 border-surface-900-50-token" } = $$props;
    let { hover = "hover:variant-soft" } = $$props;
    let { flex = "flex-none" } = $$props;
    let { padding = "px-4 py-2" } = $$props;
    let { rounded = "rounded-tl-container-token rounded-tr-container-token" } = $$props;
    let { spacing = "space-y-1" } = $$props;
    let { regionList = "" } = $$props;
    let { regionPanel = "" } = $$props;
    let { labelledby = "" } = $$props;
    let { panel = "" } = $$props;
    setContext("active", active2);
    setContext("hover", hover);
    setContext("flex", flex);
    setContext("padding", padding);
    setContext("rounded", rounded);
    setContext("spacing", spacing);
    $$self.$$set = ($$new_props) => {
      $$invalidate(18, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("justify" in $$new_props) $$invalidate(6, justify = $$new_props.justify);
      if ("border" in $$new_props) $$invalidate(7, border = $$new_props.border);
      if ("active" in $$new_props) $$invalidate(8, active2 = $$new_props.active);
      if ("hover" in $$new_props) $$invalidate(9, hover = $$new_props.hover);
      if ("flex" in $$new_props) $$invalidate(10, flex = $$new_props.flex);
      if ("padding" in $$new_props) $$invalidate(11, padding = $$new_props.padding);
      if ("rounded" in $$new_props) $$invalidate(12, rounded = $$new_props.rounded);
      if ("spacing" in $$new_props) $$invalidate(13, spacing = $$new_props.spacing);
      if ("regionList" in $$new_props) $$invalidate(14, regionList = $$new_props.regionList);
      if ("regionPanel" in $$new_props) $$invalidate(15, regionPanel = $$new_props.regionPanel);
      if ("labelledby" in $$new_props) $$invalidate(0, labelledby = $$new_props.labelledby);
      if ("panel" in $$new_props) $$invalidate(1, panel = $$new_props.panel);
      if ("$$scope" in $$new_props) $$invalidate(16, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(4, classesBase = `${cBase$1} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty & /*justify, border, regionList*/
      16576) {
        $$invalidate(3, classesList = `${cList} ${justify} ${border} ${regionList}`);
      }
      if ($$self.$$.dirty & /*regionPanel*/
      32768) {
        $$invalidate(2, classesPanel = `${cPanel} ${regionPanel}`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      labelledby,
      panel,
      classesPanel,
      classesList,
      classesBase,
      $$slots,
      justify,
      border,
      active2,
      hover,
      flex,
      padding,
      rounded,
      spacing,
      regionList,
      regionPanel,
      $$scope,
      slots
    ];
  }
  class TabGroup extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$d, create_fragment$d, safe_not_equal, {
        justify: 6,
        border: 7,
        active: 8,
        hover: 9,
        flex: 10,
        padding: 11,
        rounded: 12,
        spacing: 13,
        regionList: 14,
        regionPanel: 15,
        labelledby: 0,
        panel: 1
      });
    }
  }
  const get_lead_slot_changes = (dirty) => ({});
  const get_lead_slot_context = (ctx) => ({});
  function create_if_block$9(ctx) {
    let div;
    let current;
    const lead_slot_template = (
      /*#slots*/
      ctx[22].lead
    );
    const lead_slot = create_slot(
      lead_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      get_lead_slot_context
    );
    return {
      c() {
        div = element("div");
        if (lead_slot) lead_slot.c();
        attr(div, "class", "tab-lead");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (lead_slot) {
          lead_slot.m(div, null);
        }
        current = true;
      },
      p(ctx2, dirty) {
        if (lead_slot) {
          if (lead_slot.p && (!current || dirty[0] & /*$$scope*/
          2097152)) {
            update_slot_base(
              lead_slot,
              lead_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                lead_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                get_lead_slot_changes
              ),
              get_lead_slot_context
            );
          }
        }
      },
      i(local) {
        if (current) return;
        transition_in(lead_slot, local);
        current = true;
      },
      o(local) {
        transition_out(lead_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (lead_slot) lead_slot.d(detaching);
      }
    };
  }
  function create_fragment$c(ctx) {
    let label;
    let div3;
    let div0;
    let input;
    let t0;
    let div2;
    let t1;
    let div1;
    let div2_class_value;
    let div3_class_value;
    let div3_tabindex_value;
    let current;
    let binding_group;
    let mounted;
    let dispose;
    let input_levels = [
      { type: "radio" },
      { name: (
        /*name*/
        ctx[1]
      ) },
      { __value: (
        /*value*/
        ctx[2]
      ) },
      /*prunedRestProps*/
      ctx[11](),
      { tabindex: "-1" }
    ];
    let input_data = {};
    for (let i = 0; i < input_levels.length; i += 1) {
      input_data = assign(input_data, input_levels[i]);
    }
    let if_block = (
      /*$$slots*/
      ctx[12].lead && create_if_block$9(ctx)
    );
    const default_slot_template = (
      /*#slots*/
      ctx[22].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[21],
      null
    );
    binding_group = init_binding_group(
      /*$$binding_groups*/
      ctx[30][0]
    );
    return {
      c() {
        label = element("label");
        div3 = element("div");
        div0 = element("div");
        input = element("input");
        t0 = space();
        div2 = element("div");
        if (if_block) if_block.c();
        t1 = space();
        div1 = element("div");
        if (default_slot) default_slot.c();
        set_attributes(input, input_data);
        attr(div0, "class", "h-0 w-0 overflow-hidden");
        attr(div1, "class", "tab-label");
        attr(div2, "class", div2_class_value = "tab-interface " + /*classesInterface*/
        ctx[8]);
        attr(div3, "class", div3_class_value = "tab " + /*classesTab*/
        ctx[7]);
        attr(div3, "data-testid", "tab");
        attr(div3, "role", "tab");
        attr(
          div3,
          "aria-controls",
          /*controls*/
          ctx[4]
        );
        attr(
          div3,
          "aria-selected",
          /*selected*/
          ctx[5]
        );
        attr(div3, "tabindex", div3_tabindex_value = /*selected*/
        ctx[5] ? 0 : -1);
        attr(
          label,
          "class",
          /*classesBase*/
          ctx[9]
        );
        attr(
          label,
          "title",
          /*title*/
          ctx[3]
        );
        binding_group.p(input);
      },
      m(target, anchor) {
        insert(target, label, anchor);
        append(label, div3);
        append(div3, div0);
        append(div0, input);
        if (input.autofocus) input.focus();
        ctx[28](input);
        input.checked = input.__value === /*group*/
        ctx[0];
        append(div3, t0);
        append(div3, div2);
        if (if_block) if_block.m(div2, null);
        append(div2, t1);
        append(div2, div1);
        if (default_slot) {
          default_slot.m(div1, null);
        }
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              input,
              "change",
              /*input_change_handler*/
              ctx[29]
            ),
            listen(
              input,
              "click",
              /*click_handler*/
              ctx[26]
            ),
            listen(
              input,
              "change",
              /*change_handler*/
              ctx[27]
            ),
            listen(
              div3,
              "keydown",
              /*onKeyDown*/
              ctx[10]
            ),
            listen(
              div3,
              "keydown",
              /*keydown_handler*/
              ctx[23]
            ),
            listen(
              div3,
              "keyup",
              /*keyup_handler*/
              ctx[24]
            ),
            listen(
              div3,
              "keypress",
              /*keypress_handler*/
              ctx[25]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        set_attributes(input, input_data = get_spread_update(input_levels, [
          { type: "radio" },
          (!current || dirty[0] & /*name*/
          2) && { name: (
            /*name*/
            ctx2[1]
          ) },
          (!current || dirty[0] & /*value*/
          4) && { __value: (
            /*value*/
            ctx2[2]
          ) },
          /*prunedRestProps*/
          ctx2[11](),
          { tabindex: "-1" }
        ]));
        if (dirty[0] & /*group*/
        1) {
          input.checked = input.__value === /*group*/
          ctx2[0];
        }
        if (
          /*$$slots*/
          ctx2[12].lead
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty[0] & /*$$slots*/
            4096) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$9(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(div2, t1);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
        if (default_slot) {
          if (default_slot.p && (!current || dirty[0] & /*$$scope*/
          2097152)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx2,
              /*$$scope*/
              ctx2[21],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx2[21]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx2[21],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty[0] & /*classesInterface*/
        256 && div2_class_value !== (div2_class_value = "tab-interface " + /*classesInterface*/
        ctx2[8])) {
          attr(div2, "class", div2_class_value);
        }
        if (!current || dirty[0] & /*classesTab*/
        128 && div3_class_value !== (div3_class_value = "tab " + /*classesTab*/
        ctx2[7])) {
          attr(div3, "class", div3_class_value);
        }
        if (!current || dirty[0] & /*controls*/
        16) {
          attr(
            div3,
            "aria-controls",
            /*controls*/
            ctx2[4]
          );
        }
        if (!current || dirty[0] & /*selected*/
        32) {
          attr(
            div3,
            "aria-selected",
            /*selected*/
            ctx2[5]
          );
        }
        if (!current || dirty[0] & /*selected*/
        32 && div3_tabindex_value !== (div3_tabindex_value = /*selected*/
        ctx2[5] ? 0 : -1)) {
          attr(div3, "tabindex", div3_tabindex_value);
        }
        if (!current || dirty[0] & /*classesBase*/
        512) {
          attr(
            label,
            "class",
            /*classesBase*/
            ctx2[9]
          );
        }
        if (!current || dirty[0] & /*title*/
        8) {
          attr(
            label,
            "title",
            /*title*/
            ctx2[3]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(label);
        }
        ctx[28](null);
        if (if_block) if_block.d();
        if (default_slot) default_slot.d(detaching);
        binding_group.r();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBase = "text-center cursor-pointer transition-colors duration-100";
  const cInterface = "";
  function instance$c($$self, $$props, $$invalidate) {
    let selected;
    let classesActive;
    let classesBase;
    let classesInterface;
    let classesTab;
    const omit_props_names = [
      "group",
      "name",
      "value",
      "title",
      "controls",
      "regionTab",
      "active",
      "hover",
      "flex",
      "padding",
      "rounded",
      "spacing"
    ];
    let $$restProps = compute_rest_props($$props, omit_props_names);
    let { $$slots: slots = {}, $$scope } = $$props;
    const $$slots = compute_slots(slots);
    let { group } = $$props;
    let { name } = $$props;
    let { value } = $$props;
    let { title = "" } = $$props;
    let { controls = "" } = $$props;
    let { regionTab = "" } = $$props;
    let { active: active2 = getContext("active") } = $$props;
    let { hover = getContext("hover") } = $$props;
    let { flex = getContext("flex") } = $$props;
    let { padding = getContext("padding") } = $$props;
    let { rounded = getContext("rounded") } = $$props;
    let { spacing = getContext("spacing") } = $$props;
    let elemInput;
    function onKeyDown(event) {
      if (["Enter", "Space"].includes(event.code)) {
        event.preventDefault();
        elemInput.click();
      } else if (event.code === "ArrowRight") {
        const tabList = elemInput.closest(".tab-list");
        if (!tabList) return;
        const tabs = Array.from(tabList.querySelectorAll(".tab"));
        const currTab = elemInput.closest(".tab");
        if (!currTab) return;
        const currIndex = tabs.indexOf(currTab);
        const nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
        const nextTab = tabs[nextIndex];
        const nextTabInput = nextTab == null ? void 0 : nextTab.querySelector("input");
        if (nextTab && nextTabInput) {
          nextTabInput.click();
          nextTab.focus();
        }
      } else if (event.code === "ArrowLeft") {
        const tabList = elemInput.closest(".tab-list");
        if (!tabList) return;
        const tabs = Array.from(tabList.querySelectorAll(".tab"));
        const currTab = elemInput.closest(".tab");
        if (!currTab) return;
        const currIndex = tabs.indexOf(currTab);
        const nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
        const nextTab = tabs[nextIndex];
        const nextTabInput = nextTab == null ? void 0 : nextTab.querySelector("input");
        if (nextTab && nextTabInput) {
          nextTabInput.click();
          nextTab.focus();
        }
      }
    }
    function prunedRestProps() {
      delete $$restProps.class;
      return $$restProps;
    }
    const $$binding_groups = [[]];
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keyup_handler(event) {
      bubble.call(this, $$self, event);
    }
    function keypress_handler(event) {
      bubble.call(this, $$self, event);
    }
    function click_handler(event) {
      bubble.call(this, $$self, event);
    }
    function change_handler(event) {
      bubble.call(this, $$self, event);
    }
    function input_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        elemInput = $$value;
        $$invalidate(6, elemInput);
      });
    }
    function input_change_handler() {
      group = this.__value;
      $$invalidate(0, group);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(32, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      $$invalidate(31, $$restProps = compute_rest_props($$props, omit_props_names));
      if ("group" in $$new_props) $$invalidate(0, group = $$new_props.group);
      if ("name" in $$new_props) $$invalidate(1, name = $$new_props.name);
      if ("value" in $$new_props) $$invalidate(2, value = $$new_props.value);
      if ("title" in $$new_props) $$invalidate(3, title = $$new_props.title);
      if ("controls" in $$new_props) $$invalidate(4, controls = $$new_props.controls);
      if ("regionTab" in $$new_props) $$invalidate(13, regionTab = $$new_props.regionTab);
      if ("active" in $$new_props) $$invalidate(14, active2 = $$new_props.active);
      if ("hover" in $$new_props) $$invalidate(15, hover = $$new_props.hover);
      if ("flex" in $$new_props) $$invalidate(16, flex = $$new_props.flex);
      if ("padding" in $$new_props) $$invalidate(17, padding = $$new_props.padding);
      if ("rounded" in $$new_props) $$invalidate(18, rounded = $$new_props.rounded);
      if ("spacing" in $$new_props) $$invalidate(19, spacing = $$new_props.spacing);
      if ("$$scope" in $$new_props) $$invalidate(21, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty[0] & /*value, group*/
      5) {
        $$invalidate(5, selected = value === group);
      }
      if ($$self.$$.dirty[0] & /*selected, active, hover*/
      49184) {
        $$invalidate(20, classesActive = selected ? active2 : hover);
      }
      $$invalidate(9, classesBase = `${cBase} ${flex} ${padding} ${rounded} ${classesActive} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty[0] & /*spacing*/
      524288) {
        $$invalidate(8, classesInterface = `${cInterface} ${spacing}`);
      }
      if ($$self.$$.dirty[0] & /*regionTab*/
      8192) {
        $$invalidate(7, classesTab = `${regionTab}`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      group,
      name,
      value,
      title,
      controls,
      selected,
      elemInput,
      classesTab,
      classesInterface,
      classesBase,
      onKeyDown,
      prunedRestProps,
      $$slots,
      regionTab,
      active2,
      hover,
      flex,
      padding,
      rounded,
      spacing,
      classesActive,
      $$scope,
      slots,
      keydown_handler,
      keyup_handler,
      keypress_handler,
      click_handler,
      change_handler,
      input_binding,
      input_change_handler,
      $$binding_groups
    ];
  }
  class Tab extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$c,
        create_fragment$c,
        safe_not_equal,
        {
          group: 0,
          name: 1,
          value: 2,
          title: 3,
          controls: 4,
          regionTab: 13,
          active: 14,
          hover: 15,
          flex: 16,
          padding: 17,
          rounded: 18,
          spacing: 19
        },
        null,
        [-1, -1]
      );
    }
  }
  function create_if_block$8(ctx) {
    let previous_key = (
      /*$modalStore*/
      ctx[14]
    );
    let key_block_anchor;
    let current;
    let key_block = create_key_block(ctx);
    return {
      c() {
        key_block.c();
        key_block_anchor = empty();
      },
      m(target, anchor) {
        key_block.m(target, anchor);
        insert(target, key_block_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*$modalStore*/
        16384 && safe_not_equal(previous_key, previous_key = /*$modalStore*/
        ctx2[14])) {
          group_outros();
          transition_out(key_block, 1, 1, noop);
          check_outros();
          key_block = create_key_block(ctx2);
          key_block.c();
          transition_in(key_block, 1);
          key_block.m(key_block_anchor.parentNode, key_block_anchor);
        } else {
          key_block.p(ctx2, dirty);
        }
      },
      i(local) {
        if (current) return;
        transition_in(key_block);
        current = true;
      },
      o(local) {
        transition_out(key_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(key_block_anchor);
        }
        key_block.d(detaching);
      }
    };
  }
  function create_else_block$3(ctx) {
    let div;
    let current_block_type_index;
    let if_block;
    let div_class_value;
    let div_aria_label_value;
    let current;
    const if_block_creators = [create_if_block_8$1, create_else_block_1];
    const if_blocks = [];
    function select_block_type_2(ctx2, dirty) {
      var _a;
      if (
        /*currentComponent*/
        (_a = ctx2[16]) == null ? void 0 : _a.slot
      ) return 0;
      return 1;
    }
    current_block_type_index = select_block_type_2(ctx);
    if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
    return {
      c() {
        var _a;
        div = element("div");
        if_block.c();
        attr(div, "class", div_class_value = "modal contents " + /*$modalStore*/
        (((_a = ctx[14][0]) == null ? void 0 : _a.modalClasses) ?? ""));
        attr(div, "data-testid", "modal-component");
        attr(div, "role", "dialog");
        attr(div, "aria-modal", "true");
        attr(div, "aria-label", div_aria_label_value = /*$modalStore*/
        ctx[14][0].title ?? "");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if_blocks[current_block_type_index].m(div, null);
        ctx[47](div);
        current = true;
      },
      p(ctx2, dirty) {
        var _a;
        let previous_block_index = current_block_type_index;
        current_block_type_index = select_block_type_2(ctx2);
        if (current_block_type_index === previous_block_index) {
          if_blocks[current_block_type_index].p(ctx2, dirty);
        } else {
          group_outros();
          transition_out(if_blocks[previous_block_index], 1, 1, () => {
            if_blocks[previous_block_index] = null;
          });
          check_outros();
          if_block = if_blocks[current_block_type_index];
          if (!if_block) {
            if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2);
            if_block.c();
          } else {
            if_block.p(ctx2, dirty);
          }
          transition_in(if_block, 1);
          if_block.m(div, null);
        }
        if (!current || dirty[0] & /*$modalStore*/
        16384 && div_class_value !== (div_class_value = "modal contents " + /*$modalStore*/
        (((_a = ctx2[14][0]) == null ? void 0 : _a.modalClasses) ?? ""))) {
          attr(div, "class", div_class_value);
        }
        if (!current || dirty[0] & /*$modalStore*/
        16384 && div_aria_label_value !== (div_aria_label_value = /*$modalStore*/
        ctx2[14][0].title ?? "")) {
          attr(div, "aria-label", div_aria_label_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if_blocks[current_block_type_index].d();
        ctx[47](null);
      }
    };
  }
  function create_if_block_1$6(ctx) {
    var _a, _b, _c, _d;
    let div;
    let t0;
    let t1;
    let t2;
    let div_class_value;
    let div_aria_label_value;
    let if_block0 = (
      /*$modalStore*/
      ((_a = ctx[14][0]) == null ? void 0 : _a.title) && create_if_block_7$1(ctx)
    );
    let if_block1 = (
      /*$modalStore*/
      ((_b = ctx[14][0]) == null ? void 0 : _b.body) && create_if_block_6$1(ctx)
    );
    let if_block2 = (
      /*$modalStore*/
      ((_c = ctx[14][0]) == null ? void 0 : _c.image) && typeof /*$modalStore*/
      ((_d = ctx[14][0]) == null ? void 0 : _d.image) === "string" && create_if_block_5$1(ctx)
    );
    function select_block_type_1(ctx2, dirty) {
      if (
        /*$modalStore*/
        ctx2[14][0].type === "alert"
      ) return create_if_block_2$4;
      if (
        /*$modalStore*/
        ctx2[14][0].type === "confirm"
      ) return create_if_block_3$3;
      if (
        /*$modalStore*/
        ctx2[14][0].type === "prompt"
      ) return create_if_block_4$2;
    }
    let current_block_type = select_block_type_1(ctx);
    let if_block3 = current_block_type && current_block_type(ctx);
    return {
      c() {
        div = element("div");
        if (if_block0) if_block0.c();
        t0 = space();
        if (if_block1) if_block1.c();
        t1 = space();
        if (if_block2) if_block2.c();
        t2 = space();
        if (if_block3) if_block3.c();
        attr(div, "class", div_class_value = "modal " + /*classesModal*/
        ctx[20]);
        attr(div, "data-testid", "modal");
        attr(div, "role", "dialog");
        attr(div, "aria-modal", "true");
        attr(div, "aria-label", div_aria_label_value = /*$modalStore*/
        ctx[14][0].title ?? "");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        if (if_block0) if_block0.m(div, null);
        append(div, t0);
        if (if_block1) if_block1.m(div, null);
        append(div, t1);
        if (if_block2) if_block2.m(div, null);
        append(div, t2);
        if (if_block3) if_block3.m(div, null);
        ctx[46](div);
      },
      p(ctx2, dirty) {
        var _a2, _b2, _c2, _d2;
        if (
          /*$modalStore*/
          (_a2 = ctx2[14][0]) == null ? void 0 : _a2.title
        ) {
          if (if_block0) {
            if_block0.p(ctx2, dirty);
          } else {
            if_block0 = create_if_block_7$1(ctx2);
            if_block0.c();
            if_block0.m(div, t0);
          }
        } else if (if_block0) {
          if_block0.d(1);
          if_block0 = null;
        }
        if (
          /*$modalStore*/
          (_b2 = ctx2[14][0]) == null ? void 0 : _b2.body
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
          } else {
            if_block1 = create_if_block_6$1(ctx2);
            if_block1.c();
            if_block1.m(div, t1);
          }
        } else if (if_block1) {
          if_block1.d(1);
          if_block1 = null;
        }
        if (
          /*$modalStore*/
          ((_c2 = ctx2[14][0]) == null ? void 0 : _c2.image) && typeof /*$modalStore*/
          ((_d2 = ctx2[14][0]) == null ? void 0 : _d2.image) === "string"
        ) {
          if (if_block2) {
            if_block2.p(ctx2, dirty);
          } else {
            if_block2 = create_if_block_5$1(ctx2);
            if_block2.c();
            if_block2.m(div, t2);
          }
        } else if (if_block2) {
          if_block2.d(1);
          if_block2 = null;
        }
        if (current_block_type === (current_block_type = select_block_type_1(ctx2)) && if_block3) {
          if_block3.p(ctx2, dirty);
        } else {
          if (if_block3) if_block3.d(1);
          if_block3 = current_block_type && current_block_type(ctx2);
          if (if_block3) {
            if_block3.c();
            if_block3.m(div, null);
          }
        }
        if (dirty[0] & /*classesModal*/
        1048576 && div_class_value !== (div_class_value = "modal " + /*classesModal*/
        ctx2[20])) {
          attr(div, "class", div_class_value);
        }
        if (dirty[0] & /*$modalStore*/
        16384 && div_aria_label_value !== (div_aria_label_value = /*$modalStore*/
        ctx2[14][0].title ?? "")) {
          attr(div, "aria-label", div_aria_label_value);
        }
      },
      i: noop,
      o: noop,
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (if_block0) if_block0.d();
        if (if_block1) if_block1.d();
        if (if_block2) if_block2.d();
        if (if_block3) {
          if_block3.d();
        }
        ctx[46](null);
      }
    };
  }
  function create_else_block_1(ctx) {
    var _a, _b;
    let switch_instance;
    let switch_instance_anchor;
    let current;
    const switch_instance_spread_levels = [
      /*currentComponent*/
      (_a = ctx[16]) == null ? void 0 : _a.props,
      { parent: (
        /*parent*/
        ctx[19]
      ) }
    ];
    var switch_value = (
      /*currentComponent*/
      (_b = ctx[16]) == null ? void 0 : _b.ref
    );
    function switch_props(ctx2, dirty) {
      var _a2;
      let switch_instance_props = {};
      for (let i = 0; i < switch_instance_spread_levels.length; i += 1) {
        switch_instance_props = assign(switch_instance_props, switch_instance_spread_levels[i]);
      }
      if (dirty !== void 0 && dirty[0] & /*currentComponent, parent*/
      589824) {
        switch_instance_props = assign(switch_instance_props, get_spread_update(switch_instance_spread_levels, [
          dirty[0] & /*currentComponent*/
          65536 && get_spread_object(
            /*currentComponent*/
            (_a2 = ctx2[16]) == null ? void 0 : _a2.props
          ),
          dirty[0] & /*parent*/
          524288 && { parent: (
            /*parent*/
            ctx2[19]
          ) }
        ]));
      }
      return { props: switch_instance_props };
    }
    if (switch_value) {
      switch_instance = construct_svelte_component(switch_value, switch_props(ctx));
    }
    return {
      c() {
        if (switch_instance) create_component(switch_instance.$$.fragment);
        switch_instance_anchor = empty();
      },
      m(target, anchor) {
        if (switch_instance) mount_component(switch_instance, target, anchor);
        insert(target, switch_instance_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        var _a2, _b2;
        if (dirty[0] & /*currentComponent*/
        65536 && switch_value !== (switch_value = /*currentComponent*/
        (_a2 = ctx2[16]) == null ? void 0 : _a2.ref)) {
          if (switch_instance) {
            group_outros();
            const old_component = switch_instance;
            transition_out(old_component.$$.fragment, 1, 0, () => {
              destroy_component(old_component, 1);
            });
            check_outros();
          }
          if (switch_value) {
            switch_instance = construct_svelte_component(switch_value, switch_props(ctx2, dirty));
            create_component(switch_instance.$$.fragment);
            transition_in(switch_instance.$$.fragment, 1);
            mount_component(switch_instance, switch_instance_anchor.parentNode, switch_instance_anchor);
          } else {
            switch_instance = null;
          }
        } else if (switch_value) {
          const switch_instance_changes = dirty[0] & /*currentComponent, parent*/
          589824 ? get_spread_update(switch_instance_spread_levels, [
            dirty[0] & /*currentComponent*/
            65536 && get_spread_object(
              /*currentComponent*/
              (_b2 = ctx2[16]) == null ? void 0 : _b2.props
            ),
            dirty[0] & /*parent*/
            524288 && { parent: (
              /*parent*/
              ctx2[19]
            ) }
          ]) : {};
          switch_instance.$set(switch_instance_changes);
        }
      },
      i(local) {
        if (current) return;
        if (switch_instance) transition_in(switch_instance.$$.fragment, local);
        current = true;
      },
      o(local) {
        if (switch_instance) transition_out(switch_instance.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(switch_instance_anchor);
        }
        if (switch_instance) destroy_component(switch_instance, detaching);
      }
    };
  }
  function create_if_block_8$1(ctx) {
    var _a, _b;
    let switch_instance;
    let switch_instance_anchor;
    let current;
    const switch_instance_spread_levels = [
      /*currentComponent*/
      (_a = ctx[16]) == null ? void 0 : _a.props,
      { parent: (
        /*parent*/
        ctx[19]
      ) }
    ];
    var switch_value = (
      /*currentComponent*/
      (_b = ctx[16]) == null ? void 0 : _b.ref
    );
    function switch_props(ctx2, dirty) {
      var _a2;
      let switch_instance_props = {
        $$slots: { default: [create_default_slot$7] },
        $$scope: { ctx: ctx2 }
      };
      for (let i = 0; i < switch_instance_spread_levels.length; i += 1) {
        switch_instance_props = assign(switch_instance_props, switch_instance_spread_levels[i]);
      }
      if (dirty !== void 0 && dirty[0] & /*currentComponent, parent*/
      589824) {
        switch_instance_props = assign(switch_instance_props, get_spread_update(switch_instance_spread_levels, [
          dirty[0] & /*currentComponent*/
          65536 && get_spread_object(
            /*currentComponent*/
            (_a2 = ctx2[16]) == null ? void 0 : _a2.props
          ),
          dirty[0] & /*parent*/
          524288 && { parent: (
            /*parent*/
            ctx2[19]
          ) }
        ]));
      }
      return { props: switch_instance_props };
    }
    if (switch_value) {
      switch_instance = construct_svelte_component(switch_value, switch_props(ctx));
    }
    return {
      c() {
        if (switch_instance) create_component(switch_instance.$$.fragment);
        switch_instance_anchor = empty();
      },
      m(target, anchor) {
        if (switch_instance) mount_component(switch_instance, target, anchor);
        insert(target, switch_instance_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        var _a2, _b2;
        if (dirty[0] & /*currentComponent*/
        65536 && switch_value !== (switch_value = /*currentComponent*/
        (_a2 = ctx2[16]) == null ? void 0 : _a2.ref)) {
          if (switch_instance) {
            group_outros();
            const old_component = switch_instance;
            transition_out(old_component.$$.fragment, 1, 0, () => {
              destroy_component(old_component, 1);
            });
            check_outros();
          }
          if (switch_value) {
            switch_instance = construct_svelte_component(switch_value, switch_props(ctx2, dirty));
            create_component(switch_instance.$$.fragment);
            transition_in(switch_instance.$$.fragment, 1);
            mount_component(switch_instance, switch_instance_anchor.parentNode, switch_instance_anchor);
          } else {
            switch_instance = null;
          }
        } else if (switch_value) {
          const switch_instance_changes = dirty[0] & /*currentComponent, parent*/
          589824 ? get_spread_update(switch_instance_spread_levels, [
            dirty[0] & /*currentComponent*/
            65536 && get_spread_object(
              /*currentComponent*/
              (_b2 = ctx2[16]) == null ? void 0 : _b2.props
            ),
            dirty[0] & /*parent*/
            524288 && { parent: (
              /*parent*/
              ctx2[19]
            ) }
          ]) : {};
          if (dirty[0] & /*currentComponent*/
          65536 | dirty[1] & /*$$scope*/
          16777216) {
            switch_instance_changes.$$scope = { dirty, ctx: ctx2 };
          }
          switch_instance.$set(switch_instance_changes);
        }
      },
      i(local) {
        if (current) return;
        if (switch_instance) transition_in(switch_instance.$$.fragment, local);
        current = true;
      },
      o(local) {
        if (switch_instance) transition_out(switch_instance.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(switch_instance_anchor);
        }
        if (switch_instance) destroy_component(switch_instance, detaching);
      }
    };
  }
  function create_default_slot$7(ctx) {
    var _a;
    let html_tag;
    let raw_value = (
      /*currentComponent*/
      ((_a = ctx[16]) == null ? void 0 : _a.slot) + ""
    );
    let html_anchor;
    return {
      c() {
        html_tag = new HtmlTag(false);
        html_anchor = empty();
        html_tag.a = html_anchor;
      },
      m(target, anchor) {
        html_tag.m(raw_value, target, anchor);
        insert(target, html_anchor, anchor);
      },
      p(ctx2, dirty) {
        var _a2;
        if (dirty[0] & /*currentComponent*/
        65536 && raw_value !== (raw_value = /*currentComponent*/
        ((_a2 = ctx2[16]) == null ? void 0 : _a2.slot) + "")) html_tag.p(raw_value);
      },
      d(detaching) {
        if (detaching) {
          detach(html_anchor);
          html_tag.d();
        }
      }
    };
  }
  function create_if_block_7$1(ctx) {
    let header;
    let raw_value = (
      /*$modalStore*/
      ctx[14][0].title + ""
    );
    let header_class_value;
    return {
      c() {
        header = element("header");
        attr(header, "class", header_class_value = "modal-header " + /*regionHeader*/
        ctx[5]);
      },
      m(target, anchor) {
        insert(target, header, anchor);
        header.innerHTML = raw_value;
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*$modalStore*/
        16384 && raw_value !== (raw_value = /*$modalStore*/
        ctx2[14][0].title + "")) header.innerHTML = raw_value;
        if (dirty[0] & /*regionHeader*/
        32 && header_class_value !== (header_class_value = "modal-header " + /*regionHeader*/
        ctx2[5])) {
          attr(header, "class", header_class_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(header);
        }
      }
    };
  }
  function create_if_block_6$1(ctx) {
    let article;
    let raw_value = (
      /*$modalStore*/
      ctx[14][0].body + ""
    );
    let article_class_value;
    return {
      c() {
        article = element("article");
        attr(article, "class", article_class_value = "modal-body " + /*regionBody*/
        ctx[6]);
      },
      m(target, anchor) {
        insert(target, article, anchor);
        article.innerHTML = raw_value;
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*$modalStore*/
        16384 && raw_value !== (raw_value = /*$modalStore*/
        ctx2[14][0].body + "")) article.innerHTML = raw_value;
        if (dirty[0] & /*regionBody*/
        64 && article_class_value !== (article_class_value = "modal-body " + /*regionBody*/
        ctx2[6])) {
          attr(article, "class", article_class_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(article);
        }
      }
    };
  }
  function create_if_block_5$1(ctx) {
    let img;
    let img_src_value;
    return {
      c() {
        var _a;
        img = element("img");
        attr(img, "class", "modal-image " + cModalImage);
        if (!src_url_equal(img.src, img_src_value = /*$modalStore*/
        (_a = ctx[14][0]) == null ? void 0 : _a.image)) attr(img, "src", img_src_value);
        attr(img, "alt", "Modal");
      },
      m(target, anchor) {
        insert(target, img, anchor);
      },
      p(ctx2, dirty) {
        var _a;
        if (dirty[0] & /*$modalStore*/
        16384 && !src_url_equal(img.src, img_src_value = /*$modalStore*/
        (_a = ctx2[14][0]) == null ? void 0 : _a.image)) {
          attr(img, "src", img_src_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(img);
        }
      }
    };
  }
  function create_if_block_4$2(ctx) {
    let form;
    let input;
    let t0;
    let footer;
    let button0;
    let t1;
    let button0_class_value;
    let t2;
    let button1;
    let t3;
    let button1_class_value;
    let footer_class_value;
    let mounted;
    let dispose;
    let input_levels = [
      { class: "modal-prompt-input input" },
      { name: "prompt" },
      { type: "text" },
      /*$modalStore*/
      ctx[14][0].valueAttr
    ];
    let input_data = {};
    for (let i = 0; i < input_levels.length; i += 1) {
      input_data = assign(input_data, input_levels[i]);
    }
    return {
      c() {
        form = element("form");
        input = element("input");
        t0 = space();
        footer = element("footer");
        button0 = element("button");
        t1 = text(
          /*buttonTextCancel*/
          ctx[0]
        );
        t2 = space();
        button1 = element("button");
        t3 = text(
          /*buttonTextSubmit*/
          ctx[2]
        );
        set_attributes(input, input_data);
        attr(button0, "type", "button");
        attr(button0, "class", button0_class_value = "btn " + /*buttonNeutral*/
        ctx[3]);
        attr(button1, "type", "submit");
        attr(button1, "class", button1_class_value = "btn " + /*buttonPositive*/
        ctx[4]);
        attr(footer, "class", footer_class_value = "modal-footer " + /*regionFooter*/
        ctx[7]);
        attr(form, "class", "space-y-4");
      },
      m(target, anchor) {
        insert(target, form, anchor);
        append(form, input);
        if (input.autofocus) input.focus();
        set_input_value(
          input,
          /*promptValue*/
          ctx[15]
        );
        append(form, t0);
        append(form, footer);
        append(footer, button0);
        append(button0, t1);
        append(footer, t2);
        append(footer, button1);
        append(button1, t3);
        if (!mounted) {
          dispose = [
            listen(
              input,
              "input",
              /*input_input_handler*/
              ctx[45]
            ),
            listen(
              button0,
              "click",
              /*onClose*/
              ctx[26]
            ),
            listen(
              form,
              "submit",
              /*onPromptSubmit*/
              ctx[28]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        set_attributes(input, input_data = get_spread_update(input_levels, [
          { class: "modal-prompt-input input" },
          { name: "prompt" },
          { type: "text" },
          dirty[0] & /*$modalStore*/
          16384 && /*$modalStore*/
          ctx2[14][0].valueAttr
        ]));
        if (dirty[0] & /*promptValue*/
        32768 && input.value !== /*promptValue*/
        ctx2[15]) {
          set_input_value(
            input,
            /*promptValue*/
            ctx2[15]
          );
        }
        if (dirty[0] & /*buttonTextCancel*/
        1) set_data(
          t1,
          /*buttonTextCancel*/
          ctx2[0]
        );
        if (dirty[0] & /*buttonNeutral*/
        8 && button0_class_value !== (button0_class_value = "btn " + /*buttonNeutral*/
        ctx2[3])) {
          attr(button0, "class", button0_class_value);
        }
        if (dirty[0] & /*buttonTextSubmit*/
        4) set_data(
          t3,
          /*buttonTextSubmit*/
          ctx2[2]
        );
        if (dirty[0] & /*buttonPositive*/
        16 && button1_class_value !== (button1_class_value = "btn " + /*buttonPositive*/
        ctx2[4])) {
          attr(button1, "class", button1_class_value);
        }
        if (dirty[0] & /*regionFooter*/
        128 && footer_class_value !== (footer_class_value = "modal-footer " + /*regionFooter*/
        ctx2[7])) {
          attr(footer, "class", footer_class_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(form);
        }
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_3$3(ctx) {
    let footer;
    let button0;
    let t0;
    let button0_class_value;
    let t1;
    let button1;
    let t2;
    let button1_class_value;
    let footer_class_value;
    let mounted;
    let dispose;
    return {
      c() {
        footer = element("footer");
        button0 = element("button");
        t0 = text(
          /*buttonTextCancel*/
          ctx[0]
        );
        t1 = space();
        button1 = element("button");
        t2 = text(
          /*buttonTextConfirm*/
          ctx[1]
        );
        attr(button0, "type", "button");
        attr(button0, "class", button0_class_value = "btn " + /*buttonNeutral*/
        ctx[3]);
        attr(button1, "type", "button");
        attr(button1, "class", button1_class_value = "btn " + /*buttonPositive*/
        ctx[4]);
        attr(footer, "class", footer_class_value = "modal-footer " + /*regionFooter*/
        ctx[7]);
      },
      m(target, anchor) {
        insert(target, footer, anchor);
        append(footer, button0);
        append(button0, t0);
        append(footer, t1);
        append(footer, button1);
        append(button1, t2);
        if (!mounted) {
          dispose = [
            listen(
              button0,
              "click",
              /*onClose*/
              ctx[26]
            ),
            listen(
              button1,
              "click",
              /*onConfirm*/
              ctx[27]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*buttonTextCancel*/
        1) set_data(
          t0,
          /*buttonTextCancel*/
          ctx2[0]
        );
        if (dirty[0] & /*buttonNeutral*/
        8 && button0_class_value !== (button0_class_value = "btn " + /*buttonNeutral*/
        ctx2[3])) {
          attr(button0, "class", button0_class_value);
        }
        if (dirty[0] & /*buttonTextConfirm*/
        2) set_data(
          t2,
          /*buttonTextConfirm*/
          ctx2[1]
        );
        if (dirty[0] & /*buttonPositive*/
        16 && button1_class_value !== (button1_class_value = "btn " + /*buttonPositive*/
        ctx2[4])) {
          attr(button1, "class", button1_class_value);
        }
        if (dirty[0] & /*regionFooter*/
        128 && footer_class_value !== (footer_class_value = "modal-footer " + /*regionFooter*/
        ctx2[7])) {
          attr(footer, "class", footer_class_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(footer);
        }
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_2$4(ctx) {
    let footer;
    let button;
    let t2;
    let button_class_value;
    let footer_class_value;
    let mounted;
    let dispose;
    return {
      c() {
        footer = element("footer");
        button = element("button");
        t2 = text(
          /*buttonTextCancel*/
          ctx[0]
        );
        attr(button, "type", "button");
        attr(button, "class", button_class_value = "btn " + /*buttonNeutral*/
        ctx[3]);
        attr(footer, "class", footer_class_value = "modal-footer " + /*regionFooter*/
        ctx[7]);
      },
      m(target, anchor) {
        insert(target, footer, anchor);
        append(footer, button);
        append(button, t2);
        if (!mounted) {
          dispose = listen(
            button,
            "click",
            /*onClose*/
            ctx[26]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*buttonTextCancel*/
        1) set_data(
          t2,
          /*buttonTextCancel*/
          ctx2[0]
        );
        if (dirty[0] & /*buttonNeutral*/
        8 && button_class_value !== (button_class_value = "btn " + /*buttonNeutral*/
        ctx2[3])) {
          attr(button, "class", button_class_value);
        }
        if (dirty[0] & /*regionFooter*/
        128 && footer_class_value !== (footer_class_value = "modal-footer " + /*regionFooter*/
        ctx2[7])) {
          attr(footer, "class", footer_class_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(footer);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_key_block(ctx) {
    let div1;
    let div0;
    let current_block_type_index;
    let if_block;
    let div0_class_value;
    let div0_intro;
    let div0_outro;
    let div1_class_value;
    let div1_transition;
    let current;
    let mounted;
    let dispose;
    const if_block_creators = [create_if_block_1$6, create_else_block$3];
    const if_blocks = [];
    function select_block_type(ctx2, dirty) {
      if (
        /*$modalStore*/
        ctx2[14][0].type !== "component"
      ) return 0;
      return 1;
    }
    current_block_type_index = select_block_type(ctx);
    if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
    return {
      c() {
        div1 = element("div");
        div0 = element("div");
        if_block.c();
        attr(div0, "class", div0_class_value = "modal-transition " + /*classesTransitionLayer*/
        ctx[21]);
        attr(div1, "class", div1_class_value = "modal-backdrop " + /*classesBackdrop*/
        ctx[22] + " " + /*backdropOverflow*/
        ctx[18]);
        attr(div1, "data-testid", "modal-backdrop");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, div0);
        if_blocks[current_block_type_index].m(div0, null);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              div1,
              "mousedown",
              /*onBackdropInteractionBegin*/
              ctx[24]
            ),
            listen(
              div1,
              "mouseup",
              /*onBackdropInteractionEnd*/
              ctx[25]
            ),
            listen(
              div1,
              "touchstart",
              /*touchstart_handler*/
              ctx[42],
              { passive: true }
            ),
            listen(
              div1,
              "touchend",
              /*touchend_handler*/
              ctx[43],
              { passive: true }
            ),
            action_destroyer(focusTrap.call(null, div1, true))
          ];
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        let previous_block_index = current_block_type_index;
        current_block_type_index = select_block_type(ctx);
        if (current_block_type_index === previous_block_index) {
          if_blocks[current_block_type_index].p(ctx, dirty);
        } else {
          group_outros();
          transition_out(if_blocks[previous_block_index], 1, 1, () => {
            if_blocks[previous_block_index] = null;
          });
          check_outros();
          if_block = if_blocks[current_block_type_index];
          if (!if_block) {
            if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
            if_block.c();
          } else {
            if_block.p(ctx, dirty);
          }
          transition_in(if_block, 1);
          if_block.m(div0, null);
        }
        if (!current || dirty[0] & /*classesTransitionLayer*/
        2097152 && div0_class_value !== (div0_class_value = "modal-transition " + /*classesTransitionLayer*/
        ctx[21])) {
          attr(div0, "class", div0_class_value);
        }
        if (!current || dirty[0] & /*classesBackdrop, backdropOverflow*/
        4456448 && div1_class_value !== (div1_class_value = "modal-backdrop " + /*classesBackdrop*/
        ctx[22] + " " + /*backdropOverflow*/
        ctx[18])) {
          attr(div1, "class", div1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        add_render_callback(() => {
          if (!current) return;
          if (div0_outro) div0_outro.end(1);
          div0_intro = create_in_transition(div0, dynamicTransition, {
            transition: (
              /*transitionIn*/
              ctx[9]
            ),
            params: (
              /*transitionInParams*/
              ctx[10]
            ),
            enabled: (
              /*transitions*/
              ctx[8]
            )
          });
          div0_intro.start();
        });
        add_render_callback(() => {
          if (!current) return;
          if (!div1_transition) div1_transition = create_bidirectional_transition(
            div1,
            dynamicTransition,
            {
              transition: fade,
              params: { duration: 150 },
              enabled: (
                /*transitions*/
                ctx[8]
              )
            },
            true
          );
          div1_transition.run(1);
        });
        current = true;
      },
      o(local) {
        transition_out(if_block);
        if (div0_intro) div0_intro.invalidate();
        div0_outro = create_out_transition(div0, dynamicTransition, {
          transition: (
            /*transitionOut*/
            ctx[11]
          ),
          params: (
            /*transitionOutParams*/
            ctx[12]
          ),
          enabled: (
            /*transitions*/
            ctx[8]
          )
        });
        if (!div1_transition) div1_transition = create_bidirectional_transition(
          div1,
          dynamicTransition,
          {
            transition: fade,
            params: { duration: 150 },
            enabled: (
              /*transitions*/
              ctx[8]
            )
          },
          false
        );
        div1_transition.run(0);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        if_blocks[current_block_type_index].d();
        if (detaching && div0_outro) div0_outro.end();
        if (detaching && div1_transition) div1_transition.end();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_fragment$b(ctx) {
    let if_block_anchor;
    let current;
    let mounted;
    let dispose;
    add_render_callback(
      /*onwindowresize*/
      ctx[44]
    );
    let if_block = (
      /*$modalStore*/
      ctx[14].length > 0 && create_if_block$8(ctx)
    );
    return {
      c() {
        if (if_block) if_block.c();
        if_block_anchor = empty();
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, if_block_anchor, anchor);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              window,
              "keydown",
              /*onKeyDown*/
              ctx[29]
            ),
            listen(
              window,
              "resize",
              /*onwindowresize*/
              ctx[44]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (
          /*$modalStore*/
          ctx2[14].length > 0
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty[0] & /*$modalStore*/
            16384) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$8(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(if_block_anchor.parentNode, if_block_anchor);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(if_block_anchor);
        }
        if (if_block) if_block.d(detaching);
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 bg-surface-backdrop-token p-4";
  const cTransitionLayer = "w-full h-fit min-h-full overflow-y-auto flex justify-center";
  const cModal = "block overflow-y-auto";
  const cModalImage = "w-full h-auto";
  function instance$b($$self, $$props, $$invalidate) {
    let cPosition;
    let classesBackdrop;
    let classesTransitionLayer;
    let classesModal;
    let parent;
    let $modalStore;
    let $prefersReducedMotionStore;
    component_subscribe($$self, prefersReducedMotionStore, ($$value) => $$invalidate(49, $prefersReducedMotionStore = $$value));
    const dispatch2 = createEventDispatcher();
    let { components = {} } = $$props;
    let { position = "items-center" } = $$props;
    let { background = "bg-surface-100-800-token" } = $$props;
    let { width = "w-modal" } = $$props;
    let { height = "h-auto" } = $$props;
    let { padding = "p-4" } = $$props;
    let { spacing = "space-y-4" } = $$props;
    let { rounded = "rounded-container-token" } = $$props;
    let { shadow = "shadow-xl" } = $$props;
    let { zIndex = "z-[999]" } = $$props;
    let { buttonNeutral = "variant-ghost-surface" } = $$props;
    let { buttonPositive = "variant-filled" } = $$props;
    let { buttonTextCancel = "Cancel" } = $$props;
    let { buttonTextConfirm = "Confirm" } = $$props;
    let { buttonTextSubmit = "Submit" } = $$props;
    let { regionBackdrop = "" } = $$props;
    let { regionHeader = "text-2xl font-bold" } = $$props;
    let { regionBody = "max-h-[200px] overflow-hidden" } = $$props;
    let { regionFooter = "flex justify-end space-x-2" } = $$props;
    let { transitions = !$prefersReducedMotionStore } = $$props;
    let { transitionIn = fly } = $$props;
    let { transitionInParams = { duration: 150, opacity: 0, x: 0, y: 100 } } = $$props;
    let { transitionOut = fly } = $$props;
    let { transitionOutParams = { duration: 150, opacity: 0, x: 0, y: 100 } } = $$props;
    let promptValue;
    const buttonTextDefaults = {
      buttonTextCancel,
      buttonTextConfirm,
      buttonTextSubmit
    };
    let currentComponent;
    let registeredInteractionWithBackdrop = false;
    let modalElement;
    let windowHeight;
    let backdropOverflow = "overflow-y-hidden";
    const modalStore = getModalStore();
    component_subscribe($$self, modalStore, (value) => $$invalidate(14, $modalStore = value));
    function handleModals(modals) {
      if (modals[0].type === "prompt") $$invalidate(15, promptValue = modals[0].value);
      $$invalidate(0, buttonTextCancel = modals[0].buttonTextCancel || buttonTextDefaults.buttonTextCancel);
      $$invalidate(1, buttonTextConfirm = modals[0].buttonTextConfirm || buttonTextDefaults.buttonTextConfirm);
      $$invalidate(2, buttonTextSubmit = modals[0].buttonTextSubmit || buttonTextDefaults.buttonTextSubmit);
      $$invalidate(16, currentComponent = typeof modals[0].component === "string" ? components[modals[0].component] : modals[0].component);
    }
    function onModalHeightChange(modal) {
      var _a;
      let modalHeight = modal == null ? void 0 : modal.clientHeight;
      if (!modalHeight) modalHeight = (_a = modal == null ? void 0 : modal.firstChild) == null ? void 0 : _a.clientHeight;
      if (!modalHeight) return;
      if (modalHeight > windowHeight) {
        $$invalidate(18, backdropOverflow = "overflow-y-auto");
      } else {
        $$invalidate(18, backdropOverflow = "overflow-y-hidden");
      }
    }
    function onBackdropInteractionBegin(event) {
      if (!(event.target instanceof Element)) return;
      const classList = event.target.classList;
      if (classList.contains("modal-backdrop") || classList.contains("modal-transition")) {
        registeredInteractionWithBackdrop = true;
      }
    }
    function onBackdropInteractionEnd(event) {
      if (!(event.target instanceof Element)) return;
      const classList = event.target.classList;
      if ((classList.contains("modal-backdrop") || classList.contains("modal-transition")) && registeredInteractionWithBackdrop) {
        if ($modalStore[0].response) $modalStore[0].response(void 0);
        modalStore.close();
        dispatch2("backdrop", event);
      }
      registeredInteractionWithBackdrop = false;
    }
    function onClose() {
      if ($modalStore[0].response) $modalStore[0].response(false);
      modalStore.close();
    }
    function onConfirm() {
      if ($modalStore[0].response) $modalStore[0].response(true);
      modalStore.close();
    }
    function onPromptSubmit(event) {
      event.preventDefault();
      if ($modalStore[0].response) {
        if ($modalStore[0].valueAttr !== void 0 && "type" in $modalStore[0].valueAttr && $modalStore[0].valueAttr.type === "number") $modalStore[0].response(parseInt(promptValue));
        else $modalStore[0].response(promptValue);
      }
      modalStore.close();
    }
    function onKeyDown(event) {
      if (!$modalStore.length) return;
      if (event.code === "Escape") onClose();
    }
    function touchstart_handler(event) {
      bubble.call(this, $$self, event);
    }
    function touchend_handler(event) {
      bubble.call(this, $$self, event);
    }
    function onwindowresize() {
      $$invalidate(17, windowHeight = window.innerHeight);
    }
    function input_input_handler() {
      promptValue = this.value;
      $$invalidate(15, promptValue);
    }
    function div_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        modalElement = $$value;
        $$invalidate(13, modalElement);
      });
    }
    function div_binding_1($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        modalElement = $$value;
        $$invalidate(13, modalElement);
      });
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(54, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("components" in $$new_props) $$invalidate(30, components = $$new_props.components);
      if ("position" in $$new_props) $$invalidate(31, position = $$new_props.position);
      if ("background" in $$new_props) $$invalidate(32, background = $$new_props.background);
      if ("width" in $$new_props) $$invalidate(33, width = $$new_props.width);
      if ("height" in $$new_props) $$invalidate(34, height = $$new_props.height);
      if ("padding" in $$new_props) $$invalidate(35, padding = $$new_props.padding);
      if ("spacing" in $$new_props) $$invalidate(36, spacing = $$new_props.spacing);
      if ("rounded" in $$new_props) $$invalidate(37, rounded = $$new_props.rounded);
      if ("shadow" in $$new_props) $$invalidate(38, shadow = $$new_props.shadow);
      if ("zIndex" in $$new_props) $$invalidate(39, zIndex = $$new_props.zIndex);
      if ("buttonNeutral" in $$new_props) $$invalidate(3, buttonNeutral = $$new_props.buttonNeutral);
      if ("buttonPositive" in $$new_props) $$invalidate(4, buttonPositive = $$new_props.buttonPositive);
      if ("buttonTextCancel" in $$new_props) $$invalidate(0, buttonTextCancel = $$new_props.buttonTextCancel);
      if ("buttonTextConfirm" in $$new_props) $$invalidate(1, buttonTextConfirm = $$new_props.buttonTextConfirm);
      if ("buttonTextSubmit" in $$new_props) $$invalidate(2, buttonTextSubmit = $$new_props.buttonTextSubmit);
      if ("regionBackdrop" in $$new_props) $$invalidate(40, regionBackdrop = $$new_props.regionBackdrop);
      if ("regionHeader" in $$new_props) $$invalidate(5, regionHeader = $$new_props.regionHeader);
      if ("regionBody" in $$new_props) $$invalidate(6, regionBody = $$new_props.regionBody);
      if ("regionFooter" in $$new_props) $$invalidate(7, regionFooter = $$new_props.regionFooter);
      if ("transitions" in $$new_props) $$invalidate(8, transitions = $$new_props.transitions);
      if ("transitionIn" in $$new_props) $$invalidate(9, transitionIn = $$new_props.transitionIn);
      if ("transitionInParams" in $$new_props) $$invalidate(10, transitionInParams = $$new_props.transitionInParams);
      if ("transitionOut" in $$new_props) $$invalidate(11, transitionOut = $$new_props.transitionOut);
      if ("transitionOutParams" in $$new_props) $$invalidate(12, transitionOutParams = $$new_props.transitionOutParams);
    };
    $$self.$$.update = () => {
      var _a, _b, _c;
      if ($$self.$$.dirty[0] & /*$modalStore*/
      16384) {
        if ($modalStore.length) handleModals($modalStore);
      }
      if ($$self.$$.dirty[0] & /*modalElement*/
      8192) {
        onModalHeightChange(modalElement);
      }
      if ($$self.$$.dirty[0] & /*$modalStore*/
      16384 | $$self.$$.dirty[1] & /*position*/
      1) {
        $$invalidate(41, cPosition = ((_a = $modalStore[0]) == null ? void 0 : _a.position) ?? position);
      }
      $$invalidate(22, classesBackdrop = `${cBackdrop} ${regionBackdrop} ${zIndex} ${$$props.class ?? ""} ${((_b = $modalStore[0]) == null ? void 0 : _b.backdropClasses) ?? ""}`);
      if ($$self.$$.dirty[1] & /*cPosition*/
      1024) {
        $$invalidate(21, classesTransitionLayer = `${cTransitionLayer} ${cPosition ?? ""}`);
      }
      if ($$self.$$.dirty[0] & /*$modalStore*/
      16384 | $$self.$$.dirty[1] & /*background, width, height, padding, spacing, rounded, shadow*/
      254) {
        $$invalidate(20, classesModal = `${cModal} ${background} ${width} ${height} ${padding} ${spacing} ${rounded} ${shadow} ${((_c = $modalStore[0]) == null ? void 0 : _c.modalClasses) ?? ""}`);
      }
      if ($$self.$$.dirty[0] & /*buttonNeutral, buttonPositive, buttonTextCancel, buttonTextConfirm, buttonTextSubmit, regionHeader, regionBody, regionFooter*/
      255 | $$self.$$.dirty[1] & /*position, background, width, height, padding, spacing, rounded, shadow, regionBackdrop*/
      767) {
        $$invalidate(19, parent = {
          position,
          // ---
          background,
          width,
          height,
          padding,
          spacing,
          rounded,
          shadow,
          // ---
          buttonNeutral,
          buttonPositive,
          buttonTextCancel,
          buttonTextConfirm,
          buttonTextSubmit,
          // ---
          regionBackdrop,
          regionHeader,
          regionBody,
          regionFooter,
          // ---
          onClose
        });
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      buttonTextCancel,
      buttonTextConfirm,
      buttonTextSubmit,
      buttonNeutral,
      buttonPositive,
      regionHeader,
      regionBody,
      regionFooter,
      transitions,
      transitionIn,
      transitionInParams,
      transitionOut,
      transitionOutParams,
      modalElement,
      $modalStore,
      promptValue,
      currentComponent,
      windowHeight,
      backdropOverflow,
      parent,
      classesModal,
      classesTransitionLayer,
      classesBackdrop,
      modalStore,
      onBackdropInteractionBegin,
      onBackdropInteractionEnd,
      onClose,
      onConfirm,
      onPromptSubmit,
      onKeyDown,
      components,
      position,
      background,
      width,
      height,
      padding,
      spacing,
      rounded,
      shadow,
      zIndex,
      regionBackdrop,
      cPosition,
      touchstart_handler,
      touchend_handler,
      onwindowresize,
      input_input_handler,
      div_binding,
      div_binding_1
    ];
  }
  class Modal extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$b,
        create_fragment$b,
        safe_not_equal,
        {
          components: 30,
          position: 31,
          background: 32,
          width: 33,
          height: 34,
          padding: 35,
          spacing: 36,
          rounded: 37,
          shadow: 38,
          zIndex: 39,
          buttonNeutral: 3,
          buttonPositive: 4,
          buttonTextCancel: 0,
          buttonTextConfirm: 1,
          buttonTextSubmit: 2,
          regionBackdrop: 40,
          regionHeader: 5,
          regionBody: 6,
          regionFooter: 7,
          transitions: 8,
          transitionIn: 9,
          transitionInParams: 10,
          transitionOut: 11,
          transitionOutParams: 12
        },
        null,
        [-1, -1]
      );
    }
  }
  const creditCode = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAACxMAAAsTAQCanBgAADzWSURBVHhe7Z0HnBRF9sdrMyxZoiCegKCCOZ3xzKcCgp56CoqKohj+6pmznBGMGM+cQDALBgwneuZ4nieGU5KKIoqAIrCEDf1/3zddQ29vd09P2oD++BQzW93TXV316uWqLvhZUCowv8P8+OOP5uOPPzY9evQwvXr1MoWFhe6RYDiOY2bPnm2+/vprs+WWW5p27dq5R37bWCEwNTU1K6WDfvNYvny5M2LECKd58+bOjjvu6Hz77bfukXB88803zuabb+60aNHCueqqq5xVq1a5R+JB+t79tmZBnms5U7IqQWdrHhYvXmymTZvm/hWNlStXmpkzZxohMOVCcK9UKCkpMT/88INZtmyZqa6uNgUFBe6RaHzxxRdm6dKl7l9rJKqieX0Txi+//GKGDh1qhKOYs846y1RVRc+fsrIy0759eyWOyspK2Ll7JBxrr722ef31182ECRPMyJEjTXFxsXskHOeee67p27ev+b//+79Y92iqWGMJCy4yb9481YNeeOGFlBwINbNbt26qV8G94g567969lYDXWmsttyYatIM2iWqLGuLWrnlYYwmrdevWyoHATz/9ZL777jv9HgYIqmPHjqaoqEg5FmIUAsg1xo4dax588EFz/fXXm/Lycrd2zUOTIiy4CDqNKMluTThatmxpNt54YxVPiMXvv/8+JaF07dpVCYvrw1nywVHatm1rDjvsMLU64+hk6G60Jc4zNyY0GcJCPI0ePdoMGjTIiAWmXCUKDNr+++9vNthgA7PeeuupmEs1kB06dFDCgqDgcg0tqrj/zTffbAYPHmzGjRuXUk9sVJDGL5OZ3OghHMfZZpttYDmO6DXOl19+6R4JhwyEI7PdmTNnjn5PhX/9619Oq1at9B4nn3yyuiDiQvrR/ZY7VFRUOMJFtT177723s2TJEvdI44b0xZImw7FQjvv166cc5auvvjJTp05VMREFzu3UqZPp3r27fk8FxJQ9LxXH4t633Xab2XrrrVVfSsVBM0GzZs3MlVdeaf70pz+Z4cOHm+bNm7tHmgCaCscC77//vtOmTRudwZtuuqkjg+8eiQYz/7PPPnNk8N2aYMyePdvp3LmzXn+PPfZwfv31V/dIXcyfP9/Zbrvt9Ny+ffsqV4xC3DYEAU4lhOz+1fjRpDiWtNdstdVWZt9999W/P/30UzNlyhT9ngrXXHON2XHHHdWHFAUh2mRYZtGiRZEcCwcnliOAy6XyYV133XXahlGjRrk18dGiRYuU4aVGh8bAscTaiz0jZ8yYoSEUabrqWmLxuUfCIaJEzxcCcObNm+fW1gXtsHrcH/7wh0iO+MUXXzg9evTQc//4xz86QojukbrgulZXEmPCrQ0HoaFrr73WkYngiBUcW3+jD9PRC/OFRsGx3nvvPXPUUUeZ++67L5aesv7665tjjjlGvwuRmXvuuUe/R0EGXj/Ri15++WX9HgS87zvttJN+h3NFcSFcHzhhgYjPSP1HjAJ1kwARsfoZhaefflq565gxY8xTTz0Vyy1BKOqGG25QVwb6Z4OjoTnWgQce6EjHafD3zTffdGuj8c477ziiaMfiFkBEpiNEo+eLEhzKHeEMIt6cCy+8UC3EKC767rvvOq1bt9ZrCqG7tcE47rjj9DzKs88+69YGg/tvttlmei5t5j5xMHPmTGejjTbSvtxnn30y0uVyhUbBsbB40FGYccOGDdMwTCrgm8IaYyb/73//M//+97/dI8HgfOl09XSjR4VxAOrx2F922WVm1113jeQUePJFIdfv1sMfBvxjOGy32GILs+2227q1wXj44YfNl19+qd+HDBlixEjR76lAG0jd6dmzp+qhcazgvKKhORbWkrDv5Iw++OCDI60xi0cffVR1LazEl156ya0NBj6s//znP8ot0tFZoiDErHqTEIxytygsXLjQefHFF9UqTKVL3nXXXcq9hRidV155Ja22LliwQP176HQNCThWAYQlM7NBg1b//e9/zX777adcoFWrVkaIxuy99956LIxr4IV+5plnVNfBw17fPh70tY8++kitVThFrjgEz/PEE08ohxswYECsjInGBumTpQ3OsZiRzOKLLrrIKSkpUa5Fot3PP//snpFbYOkxo9PhBL8jPcCxGlzHgiPhozn99NONKPJah2ed2GBcEGT+8MMPk7E0eTb99IPcKeJuf//732OnxdQnPvnkkzUnAbChOZYX0qnO3/72N+eBBx5QX04criImv3PEEUeolYjfB+4X9jtSj+WRndLSUmfatGlubV288MILzvHHH+98+umnbk1dfPzxx3rOk08+6dZkDtorBoM+A5xbJpV7JByiPqi1+fLLL6fU2+obcKx6JSzcAjgWGRQGdvr06UlXgZ8Y+NtfFwQcntapKRaRI1aie6QurrvuOj2Pcs0117i1tcEg9evXT88R68qtrYujjz5az0HRZkJkA4wL3CZcb+DAgSmDzfRfly5d9Pw999yzjrGDGuHtZxR6FPv6Qr0RFlzl/vvvVw/4euutp51CWX/99bVu/Pjxah1mAjgbXE6UXC1XXHFF6KIGvPbWn7XTTju5tbUBMW+88cZ6Dt73MO7x8MMPKzFw7ziZE6mAxSgi2nn77bcjORA6IgQv6oOW8847L9lGnnvixIka5yQqYPuZCcfz3n333VlPgjioF8KCqE488UQ1yxmsoIKjcezYsaEEkQrMTBuchtuEKf4MWJ8+ffQ8wjuk4gRh11131XNoc1AICOLDAYkzkxAKf+cCccT/PffcoxOI9jEx4UwAg+Tss89OOm2DCu6ZSy+9NJaozQb1QljEvNBpmF277LKLM2HCBEcUbc1UuOOOO3TWYw3SWRCXv2MhTEQmeVVRIH/KdiDXCcMJJ5yQPI+2BAHvPMchrKBlYLkiJIAYw7cWR0/6/PPP1b9F2+C89957r3vEce68804VyxzDqkZPxdf2wQcf6HnUWW6NHpdPz3zeCeutt97SGSSWn3POOedoqokfyP4zzzxTCYuO8TobETFXX321cpn99tsvMjUFztKtWzftOJTgr7/+2j1SGyjbEDrnocwHEQmDwbH77rsvp0TkB4P717/+VScXYaooMLG22morbTflggsuSIpgOHb79u21HukQxGXh4qNGjdJnp6+feeYZ90jukXfC2n///fVhIYoovxQEs+WWW+q5WHh2MGHvgwYN0npEFwp31ExD3+BcyujRo93a2hCT3llnnXX0HJT+oDgj3AOdLxe6UxQgcjg5bbnkkkvc2mCghNv46IABA2q121q7iPCojAw44/bbb6/nDh48OG8iMa+EhQhBcYT9ouhaYqFDCFs8+OCDSUWSY6eddprOJBL46ACLJ554wmnXrp12BmIgKigL6+/YsaOeS/JdkBjj2tYC6969u5rtuQTPgni76aabnIsvvtj57rvv3CO1AQFsuOGG2g7SoVHao4D+dfvtt2vA25uWzb1IxaHvUC3sZCCdCIMJkYiVafsfAkb1IGAdxtWzhdwrf4SFlcMMo7z66qturePceuutTrNmzVTZJhZmgV4EEdLZX331lVubEBdXXnmlDgAF300YUKSJO8IFYPnoUH7dhQEaMmRIMqMCrmE7PR0Q+8O1EfRbYpLoZ3BZxGmQ/mSfl2fCH5Yqj8rex3+tuXPn6gTmfvjfLCAqng+F3VuP8k99r169Yq0byAQQVt487zbGJ/eBePU7YMMNmV0aE/RuoiEzzf1WG5x7xhlnmIMOOkhz0v/85z+7R+qCHHEbNxQCMo899phmTXjBsvjttttOc684hrc77N5heOihh7Q95JHZLFIvyEiQCaLrFMmqEEJ3jyRApECIT6ML9ANtpu1BIDfrueeeS7bRfy3bz/SxEJ1+B6xMsv3sXUyb7rNmDGlQxhwLvQmrLQhE9FG6mbU4Jr26EfqC15GJrB82bJhyGnSAIH2MGY0Ca2duGGjPzjvvrJyA602ePNk9shrc34pXIdRY2RReYFDAdfEVhek0tCNsYxE4NeKP+2OtBel5cNbLL79cuRoqQFiuGn2HaIcD+732WJFED+gzCmOAcs+YbLHFFrVUDgvOoz+ycajKNTIXhVgiuA8OPfTQ0Ie2IgxHY5QO8c9//jO5iIFdW3i4bADRwu65HjqbX8xgFDCgHIfArC8oLvBfCTdUq9fqNOlg6NChem+K12XgBVaiTWfu1KlTpG6JbsV5iET6Mgy011rOGDpBbcdyx92CQzVu4qUfWREWpisNhCvgUkCx9DeUAcSJx3kQznvvveceWQ3ypNZdd12dcXRgutwjDFhO3Jfr4o32gyxRe/y2225za+MD4s9kAjAhbRYHHC/MMkNXpG2c95e//CVSB+Ma1qpGd33ttdfcI6vB5EHJ55pw2zDnMD5G67o49dRT3dr0kBVhwWZRtLFGaASNxfloRZztdIKkmPc8EIo8pjFugzFjxqgSDavnGGIzlWWUDlCurbd/9913rxN/gwMgEuzABSGKG2XCqRBvpGJzT4jr8ccfd4/UhSUULNco6832M8+DQk5fMtFF/1PuT0HNKC8v1+sxib3KvB+I9iOPPFJVklS+tTBkRVhg1qxZGiuzDkcKK2fGjRuXtF6Q6zg9Ca7C3ex53oJPhZkSZD1lAjobcxuuRUfjR/MTFoNswzvMUL+uRGQAfQQrystVaCOW3imnnJK2CBVFPKlbsbI5ijvDdYh7wtHjgHZBCGJUJCe7vxBj5JxU/YwbKM7qpzBkRVgMHgUWjb6BGLMPwEJOq4Db8xhYTHs8zdtuu62zww476KyaNGmSPgjn5Ar2WiwwIPCK+yLo+taxSPHOYgiJFGk4GlyZkJIFDlbEOoOHcg2BesHAMeH89+OaPDuEznW9ky8I/N5/7ShwPoW+xKuONGAc6OfDDz9cU7m9/qx8Qu6RHcfygswBvOTIcYKhYbpDYwLOQ8tF4by20xkAVrpQj0IM97J46qmnkusa0UHQIy2YONQj+ukPLyBIxBDHcd6y6npNBYSVMz8W6/3YEQWfCxmaIh61njVud955p5HB0r8bAiKOjYgUXYfoxSabbKJ7OwAhnqRPCh8XPighOv2tTBKtB8uWLUtmqLL6hnOA6Fzm1ltv1e8iVutkggrRJffoEp3OiKWs3+sTCxcuNP/4xz/Uh5Z35Ipj2dnuBWwZ5RPFHo97QwGzGW6BCEM8WmAZ2cAuFhoGCeBZTj/9dBV3KL1wKft8N998sz4Pv7nhhhuSSjz6ls08QPx4fXH49KzrAA7pbUN9ggwI2o5Rw8a8+UJOOZboDu631aBOxIYWy8HSBVxERJaZOHFich1fupBO1PWKcBUv58Tzzzo82sl36XSt52/pfOVG1Nl6AAezx+E6lmNNmzZNPd88p+hSetxCLDYjirpywvPOO083XWsIcH/WVvKsoue5tflB3pd/CRfQDTZYrAmBEUZ59dVXVQSxbIpBigJiVPQfHdzJkyfrAtd0wY54hEZE/9Ml9JYYAEvPWGQh5nWtZVxz5swxzz//vIpElqLRdgCBIu7FpDeih2nIBPCMr7zyihIQCza8i1h5ZlQCjrGki9BUQ4BJxZI1Fu1uttlmbm3uIUwr3vKvVOZpOsCRinkv+k2sICieZEx0RBnOxUwR5ndCxIUdoz7o2cPqo67FsVz2Y0PBa6yEQZ41tShkI1Z2BmbZuVeJzRTsBcoMRrn1K7hB2GuvvXRp10svvaTB3UwRxvrhmGHHqPdyN4uw+qhrcSzoN00BGCMywZVzY6RhAAj9uEdDkIpj4c+R0yI3ImM2xgWBz4ceekgDsXGoPwjc77dUGhKkPBET9ubS9+/fP9LHJm1O7cciRIMjU/SNJJvHYUhiHp7hTKLgiIRMO4zf8fvfUmlIEKYTTpskKpyuXr9eECCsSOVdzqmjXFN34oknmrvuukutIPKNjjjiCM0pItcKq8j/m7hAuUXZR/ENe0kS96f8lhAmQul/Xs8iUkDfduE1GDIBfi728kL1wcfHfTFszj//fLUoMaLYyYY8ryjI+GS2dwMhHGKCXMMWUmPI7iQ9OFOwrg6Wy7VZphQketc0jhXnecLAWgF8ZkQCiAJwrTgIO48FL/ju8O15Y4Xki5EqBOLcQ87JzI8Fd3rzzTd11znMboCviN312LFu7ty5WpcuRNQq18JDfvnll5vDDz9clf01DdL37rfa39MFv8WFQDQgHcMKicJvRcetdf+uXbvqGODn8nJJ/rbjHFsaCXVl7HmHeslKIDYIl8FLjXfbG7TFAw21x6F0YnRwPa+iiEwn9cbmI3GdoFm9JpcwcIwsCBZuBGWDekG/UcjiQCE/5JBDNCrCekw7Nnzi3onzSr0oyHVyG4QmDZjovm0oYQNyobAsUy04tWDZFYl5drtECnlchE+4LsXf8WtyCfOLxYEdB0BYiUxTxsOuGqeQiMl9cgm5b+4Iyw66Fyz7ovFYFXGT+LgGnQmns2sKKaxRpJ7j/s7PZeEeQfUNUWhLNoQFcOmMGzdOtx4gXVtEmfYnn7vttlvGyXxRkDHK745+ONZ4Lx8ymh2ACWWgCxBWwAIhrIBcD7N6iBPy9gfOP+WUU3SfdGl3VnpJKnDt2HpEPYD20D/ptgldVcSkZlywU7QQqF6DscDJecIJJ2hMk9hhriFtzv+OfswYrzONhDoi/cweXnvLnlbkKsGJwkAWqkW6HCtzDiS/q1klpTLgWP2WqL4Jw4033phMzabwna2Xpk6dqmIxn5D21rUKpdLMnz/f/St74P9gLZ8Ff2PJENYhAMwbGwjbXHLJJWrdAGmbflqk8ptEISvuY4elnuB/7mxAaAkuxSf7u+KPuuWWW4zoWLFf2ulHUPuQPGR81IEQUpJjsfSH/HCsO5TnkSNHqnwmryqXIJzDEiiyM2Xg7fApJwtaB+hFuhwru8K96u9+Ydw1DFjK+JuCOBpGEH3JHveZ7j0WBO7JIhCW+rM2EQuexReso7SAY9UiLHLD7W52tuAwI7aXa9BAQgM4Re0eBhQWMEShfgmrcRQ/ICYWZrCmkxhuPhRwwBiRwOhVRQjtwXi8NMKCWetABXUIi4dgcQPuAbuAlJJqH/VsgP6FW+L888/XZUreFdJwNlH+nTfeeMOt+Z2wRKSpNUcqEdY240O2az7A/hIiNtUjb4HfUsSr3pdjLGfzv8WjDmF5gVh87rnnMl4NmwvYvUVpvMVvnbDsNpYU0VdVZWGFcz7AUjLuwzI5LyAumE2YbxLCKho1atQFoues1q5dkDFJMHLdddd1a+ofdvHBWWedpQHu+gDKfqYlX/BeG2WcV+rheqFfLr74Yg1A5+P+bCxCYJut0vlusfbaa2tKt82qDcCqenszxbfffmtEXus7cPClACFu/QzrFHxeIir1Aayvi9/Y32UK+2vvXblmJv4iP6Q/3W+5g9fPhwVG/JQ+pF/CEgu94NlEnVCfIT6suOB33A+rPp1+kd8trRfCEr1JXQoEp8l1J/cc5xyvhyOXPc1Ga4kDrht0rpiiUmTAalYf41wyVVmmhSPXO2Ac81/L2w7Meghq+PDhOptzTVxewvKC+8fpO17/izuHxR/k66dDXJlA2rU0uMU5Bg9vBwofGbPniiuu0L2pbMcsWLDAvP322xlnRgTBSwheFDAgvmO0A9FL+8hx+uyzz8z06dM1a4M2UViUAbfgO2/P4DhiyZ5HpCGX8BJvEGzf0Sbe++hdgeSFPY9P+z3fqBeOxQxGDLIRGoslCdEgEh9//HGzzjrraIeMGDHCvPjii7qChNxqVuPwySoZL1J1dqagwy2h3HTTTZpSUlpSagqLCk1hgZRCGRQpYjvo89AGUaz1O8mNJD+i93Tr1i1nHMs+pxXR/G0Jg1VB9BeFkA0hHPqQCetdrgZ4lhdeeEH7mpVIYRwwV5B21o8o9IJOZ3azitgunWLGsWTK/95BiIz3+9FhiE5A59oOzyUYMJZ2jRs3TnfsIwpguaxTzf3kvgWO1BXrM9iBBhDWcccdZ0aOHKmRhVwRloWXEPCe83Ywoha//PKLW5vALrvsom9Es/3aUICw6kUUekEnYeF5Hx69i2X5EBAWjg0BEYRmdQ5rAusDtA2FGEsIwiGURCkpKzGlzcrke4mGQyAerXfbybNQ5yW2fIFkStZlWqKiDeisRx99tK6kykdQORPUO8cKA7McKxCxyMphcq9ZAAo3YJb+0X2vcz45FiutH3roYfPIow+br0WHKi0tc48m2oeIsZmacDPqsFoRfyeddJI54IADIsWMbTf3Sgfea7IqnMxdOD5xP3LQt9lmGyWodA2hfAGOpYQlnKH8wgsvVKUUC4IFEoAAI0vH6RAsJWYlM4TBZmbzcPl8EKwt7m05A+BvO0C5BgM4ZcpzZuzY682cb78xRYWY2QlCIGi+1VZbqdKOmKTO1tNfo0aNUr0xCrbd6faZn1jRr0gVziY4nwq01bYTyYFhw8TjO/dFV7Ppyh988IG59NJL1beF5BFaSaTNkPpLiEAupPtJ4e0lIMrWPgQZOcb+6WzPw65xbMPDjm9kevo9w4AwDd5gPPd4aYVg1WOeCnHPsR7pXBeuzersQYMGO336bKDP2r37OhrL5JlZvY2neyP5m33S+/btp3t6EoTlGUHQdbMpjEOcfkkF0pdYqkcCZdj1OM7e9GzvJJxZ60hAYMdDxp4QDuk3ZKCSDm1jiKSmC7E5a6+9ti6mkesnQjqswmBzLgKadscVHoj9x4XlM80CC7sTB2U+EOPjJrYRNIo1iF6Qo024iMal03GcGzQAuShcm8Ar+6uutVZ7JZ6BA/dTwiI9muwLCIy3aXXp3MVp224tp43UswEbgeGga+aiZAN2BCT2y9oB0cU0yYB9vILAjkAiHXQLBLs9JWEb/vaPPVt9WsIiCG430oOWIKxIHQufDoozPh18NBSheGX/cj3N6kTh9rNqdobBWYj+YYHoxA/Ep9xT91qHhY4ePVp1BsC1zznnHDX7cTNgFaIsH3roocp6Afel5AOwfgrPjIXYv/8AEcPF5pJLLhXrdBszc+YsscgeN7379DEbbriBaVHeQp2OGB/sP+91qoaBtlsRExfe/sVtgO6J8o5IZIwIt+Bm6N69u3vWatAuDCAvcOWQXeoHm6CQWUoYD1eQ3TsMp/H999+fHA+2OmCPLxtB8UOeMX4GKRyMvB5YKWyfV3kwwyl+2MR99ulk91/y1WGvdvbxG1ItpMOU8i14vQnt8hdmnAW/9c/oXBauz7ORUcGMRKwjIsjLYoXLpElP6r5anEtfIO6pz2e7vPCnNdkiBo57Rm3Qv0Igym0JYLM6x/umEC+4F/vCs0rHP66IRmjAC/85FlKfu8UUftAI5DoJYIhLf6NYbEmaLMdsA8moYBWJcLVanebdtI1z/R2f68I9yBVj52UL2g/BkdYDwTHJSKJjEzXOz2e7vDj22GNr9Q3qBmLIvzWlBWPAtpSoHkwExsO2N1+Qa+d3MUVcSFuS4kE6Utk7bgdEJ+IFJ6m1gDiXkm8gfnDYYgnh6uCeDzwwzgwdOkSPsfWkjfJ7258PeEUhHnYWC+M769Kli4on1IZ07p/v9sr169/zni3oFEoYctlpDCjuBfZGwJWAzgjBE/bBKUm2QD4HyMJLWE0BayRh5RLch0HFyBArSTmY6Clmzz33VG5VX+34nbBiQHQVLcx+0VWSn3i0bYHd45wV/UstUbZXJNQD6pOwLMfCInrkkUe0TbRj6NCh5sADD8x4tUu68BIWFiEE3rlzZxWHhJ9wVOJExvNundh84tSuD47qR84JC4Ih/QXPNCID/YTBgDggFnQmvmMm48H1EhMuDM6H0IjG84m+RcHdQGAY1Cdh4WYhc4ClU7SfZyNhEZcJbcLVEie3ifZmM8BewmKRL9EQdE8KBARBEQ0hrMMr9ajjk3DPmWeemdRP6XtcOUQQvBkQjBt9znPlghCThCXfy1NdMFXnQCxnn322+kzgNBAEv5HrJ9NL7Cf1lLi45pprtINAur/NBDznO++8o23Ff0a7AUSF4swxJsbAgQPNzjvvrMTFuUH9Y9uazYB5CYsdeCZMmOD+FQ2IDX2QFHPAPmZPPfWUxjUJ3QEmMz5H6zvEF0Z6DRyR52Iz4HQD2/LMCcKSL+XsEmw38YJImJ1QOE5Lsj+HDBlSi8r9INGMLYzgVn7QqcwuZg7FsmquR6P5zmwh9oiVA3u3qbcoydzfxgvzTVi0FQIitYedlO1sDwJcmb05xdxXCy1f7fISFuNBFqiVAvxtvzNu9L/l+JtvvrmKcUQm4HnQF8lzmzJlitaRgsNLPYPAfSFGlukzTkiWcePGaUYw3JoYKf2FtIF24JI4a6UuQViffPJJOWkX/IAf2xlqgUlNQzbccEO3pi4gyAsuuECzQvHYQiA8ELMAIkHeU4c+YIkKwuFvGkRhhkGA3o70I5+EZbkKxIKLgfYG3cuexycDChfbbbfd9Lks+J09L134fxvVHwBuafVWOBAF4iIqQL9aoJuRZLnrrrsmuRjjduqpp5qPP/44SZzQgAWrqImktGzZUrkfHBqvP4s4GG/G7I477lAOSJYH2RfC6RKed2J7BJrlOoGFhZE416Ig11HnGzEzmcn6nbibNFIdikKssZ1yUedxjGvlo3DtefPm6Tq5uPcBeLL5XdDxTIoQiRb7t0Xc/guDfSY/GCvGl4iKcDR9EwfbphPfxfFq7yuEp0vx8OITcbDXsjsBeoPQyrHkIcqR21A04oiCOQ17t7JWfp/xDEwXzD5mDso+XBRRg9wHtIOSD/B8KOtwUmKZce4DN0HJ5zeIAelP90jmsPe1/W05FvUo7l9++aXp16+fSgPUBrh8fQKOhQSiPbSRlJq7775b9TN0QOFi9e9uSAX0luuvv15zuWUGKatGzrOZLuBh4gx4phg/frym+CJG4tyHQaed6GSIz3xMPq8oRE/C68+EZ7IdfPDBmm/vFcMNDem3+k9NToVZs2bpBvVYXhgU6A1ePSFfgCCw9CBsBi0dwDHgriIa3Jr8gb6gTzAw6CN2NIZjeAGhc05Dot4IC2sFpTIVYO2kZcBW4QBXXXWVZidmg7gcDhYPkaRDyFwbyxGCRAzmg2N5wUZ0p512mvqiSG+BuyKWAAo71nufPn00BMUCj4cffjjQUs838ioK4QDobTgY+cRkJXUV/SAMDBQzEB0LPc8fYOV4XEJJB9yDJWoUcte99wi6n7dNDByWJA5JrN1cty/IKsTFgJqABU4fcQ7EjW7IXvkW9DmWGvlT9jo2Lw5LLx+Q58/Pjn7PPvus7p9ExiLWJlmJ3E8erNY7/jKBtDdpLeWycF32SSUtJl3wW3aBsa/sDbp+NiUuuDdWGTlXZLzS56J76V6wtl2kILEnP3u5X3LJJWoBC6dzr5C95QnkGrlPm2EpN1zJC2YKMwSF+MYbb1Sfj3fG+yFtc7/V5gyAY97juQJtnPTkk+app59WHw/3QCxyf45R+C69ZqTrTZVTY5xqKfwtBb2G/VZ5owN/5xLcG9Am2sD1bV0YSD1ipRN+Jl5/h3iHs7I+EwerF1izOLeJydpzgb2f/YwLOX9p6G4zFuledNKkSeqF5zc4VskEOOqoozSNmbRXYl12kMLAMQpeYgiRB0f3yivkfhXLl5v5IiYYDPQm66y17bFt5rOQIsdsQWzjPIyKTsSFv8+998UdIlxfnZhMAO4dBCYymRh4x23UgmfCIY3IpBB6A+iWOE4J96CmWFUFAwDXBvflemlgVSxRiJMTJ+B0z4sBwoCz7d5779WEfTJCyRDFQZoJeOsUjjc2ZbWQ9tYRFbkqlSKiEQs8byYlX23zYtttt9UFLjLQzuDBg9Wh6T8nCqghQlS6eyNikRU4pC4LMWjhhQQWvKZYJrTuBX/SSSfpixzijKX0Q+3UZDpGFG71wHr1IGS0zETVl0hzzTW4ryiUqqMwQBZ0XIcOHXQZmkW+Bs8W//X52xZvfapjuSxeDBw4UPUmSwiinCtxsHUkfWjbkw7EEHBIw2ZFjxd42e19KBD0+PHj3aMJiAFRZ6WW3L82YYkl5owYMUIVu0cffdStdXQzU3KrcdnbZUG5BB3CggmUfdY1WpDUzxIxOJ9FPgeRyRRU39DFC/Lu77vvPkdUjFqve2N8WOI1evTorF9ZYgE3ZEnXpptuqoyFezzyyCPuUUdz/uGgbKlO+M6iDmFhEYk+ow0dMmSI1jGQFRUVujUgaw75O9dgA1XW6nFf1jdGIZ+E1ViLH0wA4nZMeAZddKAkgYl+qGsfWSic7VjZsSf+i/WImPRakMSQuScLe2FKFvK72ltFEhbAmkBpJeJt37aO8oci7vcpZQIi6Dj5ePk2KTH4UlAMpT2qoLP9ITHK37Ea/j5HYWesyGY97LDDNGcMZRwl3Gbd4mAmxspYZgruy9hjkGBAYdVjAFiQ80/KNpYmhovn2OqtIhlYYNOEbQ5PrsHiR2J/WBy8b5pYFw/A/WV21mp4EDjPtvW3gjDLzwsIi9QX8qvI2uWllVtssUXWjCAMjAHXxoUBkXvHTY7VfxAaz/agQYN0ZrHiONVGGn40NsKyHZwO0v1NHMKygCkwQeEy3CPoPpm0OR3I9es/CE2yIHt9UtIlqsaKdAk900HFz4QD9thjj03uAuQH3IMwDsQYdR8kBqEz4ovptj8OckpYiNE4jUTM4lBcExDGFfIBUonI4iT3Ca7Pe4jQWdMF7RXLUrND2b4qL0AUCjFkDRyivDHhjDPOCLRkcgUsFWsteb83tKsgn/e3IJuTHXBk2LTgzyImi1M6XfTv31+vgaPVe49cQMYlu70bcGby4vF99tkn+bAUNpbIBOxNxbt0uGaYhzcXxNSYCDJO8YINSXBcQhC2v/E74nNKB7zejxeN3nPPPW6No+nVV111lboW6JdMkTVhsSEGr8OwD4iX/IQTTtCQQSYgbMB18M3gOwmClygaY8kHofpBfjoSgk3gbN/jU6Jv4oJz8Ul5f8M7ebgWu9KkWuMQBblm/LfYy/nut9XAB0V+PCBjgb2bSCumPgpcK+h6LEvCl8UqEpTQ3xEMEvv2339/8+ijj2pWAjor+2Clo+txLn3s/Q3LxQBrHGzgOlOkdDfIDNQ0WJyjQQSDQ5WEM6w9sgLiAKLCGmHPd3wuhxxySHITL/6mo8KuFUaUDQ3bJjtQfOaqnVHuBtwLJFTaTdKyBYtXWMZFFoQfrGEkAZPjUVkc8typE/2IgKMw8to3bzwoWxByIHJOO3jNbDqAfTe24hVdYfX+Y0El6LzGAFQTm7zJsrAoHUzanFoUwm6hYkxdZke2kPvqJ9yPBaGAUEE6gBs0tgJXsSWs3n8sqASdFwekFlaLupX4lH6m0gfq7HE+00lHhFPxShrys1B5kGRRSCkKyVVnn1A2wSAXPFXIJQy8fYIYFkRkCYpl2YQEWDyRLeQ5VCQgRjNtY2MGkQry6nnO/v37qxPUC1EQEp+Vy82qioVm1YpfTOWyn0xNNe9rdkxRSUtT2rKDKW3W1hRLKShupr8REtbfpQIOVfxn7FNKuAjdLgzCPOKFdHB8MlhxZ48XNAiud/PNN2vAkpUjOOVyqZzDBdlfgA1Zhw8froFZL3Ghz/GKEN6I4V/ahY6I0xGPNnqkBdz5/fffV+OELEwL6lnXhw7iXxTCwlUIgBid1RFpG/02Y8YM3eOA32QSGGZBMesHuRbxVl4e4MWqigXmp88nm4q575jlC6YbZ+UvcnN4E0LJ5V8Fxaa4RWdTttb6plXPvUz73nuZ4tL0FlTw/KnGDsKKZRVmSlSA1OKTTz5ZB4lBZDdiZl0csHSJVGcIOwoQ77XXXqs7AU+ePLmOyIZw2M8KTzOeaiuOAS9k4hhhEq8Xm5Ut1BMk9656oT1wbgoEZkG2BlYt9exhZe9BvxEfJUUbTsNayUxgNx0hH71lqwQx2FWMi2a9Yr58/Ejz/WuXmyVfv2mcFUuED5WYgsIyEavFUkq0SGNM5dIfzOJZU82cF880s6acZpb+9IWSHYINDpbgfKv7xwvuH5chxCKsdIlKlE/lEOxiwtZGpHMwS1kDx5q4OOv2kOeskeMabLoRBR6W+/DqD5Y5+R+eTSsQxeTQs8DAPg8ZAeTn0z6OzZw5U+sBxIAVBKeBsCyhsOLZ1vMbO0m4PvVMHF6U5CVuFpYSl2PBBZtneAk7LhA977z9jnle9BsbY61e9qOZPfUCM2PS0WbVohmmtEUHU9SstSkoEm4pBAWHqqpxzMqqai1VMi4FUl/SvI0pLW9rfv1qqvl84gFm3gd3moJVdu2hFap1kQ4dxCKsdEGHQxCwbMDCyquvvlo3T4taU+gFsUQWXtCJ5P2kwvHHH69KJcToFTWIJ3bjA+SUsce5BVs1MdgA0WYXbKCYwr0gGnLFEIe2U2mXFbMQkiUsBt6KUjiWl/vRF4haQKoQ7wrKBP027mc2ZzFKQaFZsWSucJxTzC+fPiL6luiVQlAgQbSJUlW5zJS27Wm6/+l8s96frzRt199XdC72KBMCk39l5e1N85JCM+/ta8yc10ebmiomA8+ZHiMJQl4Ii8FEMech2V8AgmKVTtzAM78jsYwVKWyfxMreVMCSYutGv9geM2aMcibAu429m94jmuE0AOK3viAIC0OAdthENwsIzV4fw8MSFsRvX3LAJmb0gQUGBaIWoO8hZjPhWoBfVS5faGZPOdlUfPu+KS5ra5zCZkoo/EMZr5GzqqtXiKgsNt33uMx02vSvpkOfAWa93S4wrXvsaqqEO+lbZrleYbkpKW1tFnw03nzz2hVSw++zR04IC7bP4NnOQuQhkthzi1egkcnIgHMOBIf7goJYsYPu7Wg7cHAQ69nPBIgg+0o6xCQ7oXgBZ4WAADvXWRGNTod4pE2IVa8FBvFCxIBzLGHRZvQrQB2rv71A/4IDcy0v4acLp3ql+fbN64Wo3jMl5WvJjWsPIb3I1WsqV5hW62xjWnfpZ37874Pm8ydHCrdaaTpscqj8pLm00aO3FhSJGG1nFvz7djP/v+NMgXC0bJE1YeGOgIAYNPQqBoOQACyfHWJIb0bn4u2qpLDaRZEsR+c7BIhC7PeLeDvfPxCcm8oIgNjZXAQrDQsNa9QfOfC+CgTl2oLfYsEBfuvV2XCVWMLCt+NtA8q5nQgYEd7JgkVKqgrqwUUXXZQWcSlnSXw1i4Wgfv7iGVPaMvFOxdVHErBXdZwaIbz2xhECWv7jf8yCjx80i6Y/b5p37Guate8hs2eFnGt/K5ar6F7NW3U0c9/9h1m+aLZb6796fGRFWKyoxb+F9YbCyiy1HY34YAAYJNwLI0aMUB0IpRjLCG6FuMCa4hjbB0Ew3sEIA0SK7sW+pGHnoyxjidIe8r/RrfxmvrXQEGPepEMmgrVE+Y03bublOP4kOTis3d3Z7mNlwXVwQ8C54uiMXnifcP7HE02BU2lqCspEZAUTJ+o377wuKipTAnOkD0plclQvX2AKy1qK+GxjatQVsRrco1rEorNqsfl55vNKkNkgY8JC/yEQyrZDDB6ciY6zs9mCWYrLAWWW3WPwN+EW4PfsJINegkhhw1V0jzgzGQJFN2J/TfScIEDoWG4An49dGOIFjj7ENi4HL/F4OZaa9x5OB0ey23AT1/RzTd4LDahHiQ8C4p+Vx8Rg48D2yK/zPjSLv3rVFJag8wnxJKp9gERExxLCKm3dVURnlalZ9av0a6EQS5VwJplcxeWmGiuxcqXUJQiMa2kpKjE/f/mcqVqxOFmXCVIusQ8D3Am2DmfCEhs7dqzOei9hocMMHz5cOxJfFk5SBhnvO6KBQSATEuLgXAaCzAY4TBT4PVYcyjhWpp8Y8WsdeeSRKqpoH2LZq6tZLoOlRgAcz7/3GhAZ+7tjMSLiyRywz8X14KxMKByxPIOXE/KdfqENXAdR7+eUqAhwaYgfP5nfix4EWvzjh3eYiu8+EI7TWgacfxC1o9ZctViANdWr5PsKU7VymSnvurVZZ4dTVdea/5/7jVNVYYqEU7Xtubtp3W1r0w7naMsupmL+Z/qbQghOrojFWbl0vilbq6cp75Sw4DMgrtWrdNyK2GBWw2Gw9EiZCcp8QKdCbMH+2SA1bMN9PPJwP1aZoK8ROojiXBCGHTg/hwRwSPxlnAeBwTWjrucHv0PMwUlps1fH4hhiEg6Mtef3meELQ3fEMoRgibH6l7OhGvAaOODdajwMENVKEWPTHx1qqhfPMUWldgWVcB2x8ApL25jmbbooR0KZb9ahr+m8zfGmebse5vuPJph5b44xJcVFprKmwHTa+gTTfoOBpqxNV1Mo5y+Y8az5+oVzTVmpcMHCRLRg1bIFpnXvP5veg+7Qe6cr1qSPMl9MQYeiEOPNDiIqRNVbb72lyu+wYcOSm4NhhUFkzGq7ERscCJHEzGaRBTHFKEAk3D+IqOAyiFgIAPcBg+gnKtqAbgeXDPLqcz4ikEnjJxyO8UxwQP8xgJ5ldSivn8wLDAWblkKohvOiQOsrF8811UvnSh+tTieCQzXr+kfT+6CJZoMhk80GQ5/Rsu6eo01hcXOxBseZH96+NsExC4pNUYFjfnjrWjN9Yn/zxcRBpmLRLNNxwwNEod9IRPdq46mwuMRULf5Kro+CnxkyJqxUYPAgHNg8+TuWCFD08ekgChhYwGBBXLgk4IRxdv7zA0Ki8JZ3dB9wzDHHqH/KC85BbBOuQcx5wzW5AFYjnIpnwU8GF/brYezGh74JmIBej38YVi37yTiiExV4JhNKeefNDjEt2vcyi2b80/z40QMi9u4zc1670syYNMLMff0qUyzEVFhULM9dJdytwrTrtYtp1WUTs+z7j8yyH7DiRbFvs45cbLUyX4jHvmKRqVq+yK1JH3kjLAsG0gvEAoSErhLE6TIF14TTodgjJhFhiGAbDLZAn8O/hShD1FklPVdgAkE4iGl0MZR02uMFInTkyJHqbIUrxnIcJ/vR8hA+xfIrFq4pX38UPeqbqRebb4WoFk0bb1b+MlvaUmCcQmmHcOUVi380HfodaNr3PcAs/1msYRR4wjhCWMWlLTzXF0hfJqKGtccuHeSNsAhvIBYYSILA1k81ePBgdZpCANZTjTjiHD6Z8Tatht/ce++9mjLL3lreMEkQEKOY+QAL1abaeoFCjw8M0Ea7zXeuwETCALHPQJwziAPDMXnZAr40uHVK1BljKshSTXDDwpLmpqRZay2kyJS139CUdugnivxSU1DWzvQYcJMQ1UHmuzeuFm40XwiyNGEh6jXIwNDLJJG4XSMkLHQQRA3EgTLtFTlYj15LjEAwSi4iA8XX6mN0PLsDIk5wTyBaooDVad0PKO92cL1ARFudho3L0t0h2QJxCyHbCWPBM2HV8vJOgGESJtqxjL2pOlEguFwoCrglpNVI9CH3JUyjnyLWSsrbmV4DbzI9B99lNjjwPrEIW5lZz55sKpctNMUlhICE27WQe4uyj9jzOi/4Pek0q42E9JFXUcgGH3AETHPCHXAlP9Av0LfgIhAC/ixLcKNGjUpuNc3udOhqYcBQsJ50fFaIwSAgduBkED7iyOu/Sge4Ogg833LLLW7NatB+tsmmvbzIyRufzATwjZIWHeS/lkm/U11In2m3FahOtfjr183MZ/9m2v5hB1Mx/1Mz+7nTTM2qJeoDSwi5QlNW3onGCrHNl4/VpFBTXWWKytsLcdXNe4+LvO/dQBAZFwLchsHErwWnwLsNR8LHhIhjluPwxM8FFyAcw443gAF64403dIaHAX8UCYVYaoRTCBuFAQ6C3mM5Y7pAdGAUQPToUxghdjJ4wX1Q4i3xBp0TBxAWsb3Zz55olsx8WdSjRBYGvqv1Btxo2vXc00yfdIxZ8t17ci/inRAOBLPQtOy2uan8VSxK0acKSsqlvsY4K381JW16mt5/ud9Urlxs/vfQX00ZUrEQK9cRQ2Gh6bTdiab7jmfpvdPlPtI/+d+7AecifilCKogg/DZwCrIhIR6ICmIiAwLdBLBjCi8BArgMMMmjiAoQZEanY79TXBdRwFLNlKgABGIzIbDqwkQd98F44PwoorIGDiEm/GdBIFGv7fp7m6qaKiUOMhjcI/o/3MhZschUr1go5WdTI9+LigrNsu/e1+Q+p3q5qVm+wFRjXRaVm7V3OMUUCxec/+G9ouRWqJIPOdaI9VjcqrPpsMEgZYCZTYV64Fh0GoVgMHlRcBXEHtYTSiued+KNWEjUsQc53mosN3532WWXmXPOOSelyMJNAQdBZwlaupRrMAkITdFm9KhU0YJUuP3221Wf5FnZfdn7vJaEqqsqzKcPDFACKSJnXYipx363mTY9djPfvD7aLP/hE9HDiA/S5wmvvCUM5WFCPM3ar286bnygad6ut1k04znz1T/PEQJM+AQ5t7JypWn1hx1Nr33HihGQGVnI/RvmXTpYf8xgxIQfODfPO+887Rx8PXjusx20dMG9QRSX4ZVqcFzENMYHEyNToBbwrBgD6GRwb68rhtZQ4E3ff3iP+f6ta01JaQvjVC0z7Tc/yqy9zfEarllNROFwCPmsWGyWzP1AXRNO5ZIEkeoz18jYrDK99rvFtFtvF/mL/K700WCEFQb0Md63jHhEV8IStEHd+gSZFliicA4SDv1gELAKMUYwTkgTyhZwaJzHcHC4oT++aLFSRNmMycea6oWfmQKx3ETNNq26bqOcKEEcQl7JCSGfLpVRhbW3aslcs2LBdP0slIOFbhiHE6ukrnW/Q0yPva7MmFuBRkVYiBP0MBvxv/zyy9WyAlGcIy4QlXfeeafqPYSY/I5TC9wRiGjcFhAWXno/GMA4bUoMdCLDA2OBuGVYvj/n0kbahVgKAyJt0eyXzcwnjjKlzRPLuKoqlwsnWmUcaRLpMom7EqTWHySBO6KosEh+wz0SmbaJs0TRX77QOCWtzSZHTjGlrbomfpshIKy8K+9xgPebmB5xNR6WiD8pLfrgMQYwDnAL4P4499xzNTkxDOSIQVxYpnwGIW6bOA8LlbRsAs24Qyyx+cG5NocNfTTMIEBrWkuswJ4Db9I3ZJCwV1ZSZsqatzTNm7U0zZq3ksJba/mUv8vlU0oZn/J3aVlz4Ybe9O0asRiXmpK2PUyfg+5XovJ7yjJBoyAsMkhJIRbuqdwCIstGZ/EDSws/lw2thA0uwMqziPKbxQX6E4AD0oagoLcXED3qAItDrA/PCxybkFfHjf5ieg64yRQ0byNGnVh6Ul0jYrFGh7RIzqAUu5+I1UThu8vLDKnKlUu+N2UdN5Jr3Whad95UjwQL4fTQ4IRFh+NasLnvOEtxhuYSrKbBlIegcDNEbaDh9e7HCrWkABEGK3bRo8LcCRbkaBHuIgOEpWpMtrpA3NWYdmIN9trvH6a02w5m+a/zVSRCesKOEp8BJcGpakSB/9WsWlFhWvUbYnrvf5dp0amvHOZYbtDghEX+N555wNvqsQijdAzA4OCURGxZjhAFjAFihABlOyroi1UGMWA0RDlZ44IoAIsoAOnYqTgWDlf0QJ4LhzGTwovE0CeIpLqg0LTovJnpd8gjwnFuMM1If6mGaJaqeMOB6lRWmBopfKeucuVS5Wwt19vZbHjQA6b3vteY4uZrCaHmjqgUKO8ykxsM7FwiFpBuM8n7XeKAjfOF6zjdu3d33n//fbc2HMINdbecPfbYw+HVHmGQvtBP0fV0dzv7d7bgdXX77ruvM2bMmFob8AdB9E1n+PDhKu+Ki4udCRMmuEeiUSP/VlUsdJb+MM354ZOJzjf/GuXMnHKCM+PpEVpmP3+KM+eNK52F059zlv30P6dqZWab48WB9Ft2O/rlAnQkb70QURV7IHfYYYeEoiFl6tSpbm00uI9wLt0iqL7Bc0HcYvW5NdFgr1EmG8/32GOPubXR4Klq5H96sKamyqmuWuFUV1Y41auWJYp8r6mS+0tb9Bz33HwAwmpUfqw4YGUQGRAA0YnvK9NAcrawS+rJkCCclEuQWoT4RjSHuUa8gAot+B4m2PzHciwAFUJb+XnDar6wYMGC5L6bLVu2dN599133SDTGjx+v4qgqiw1b/UCknXzyyc66667rDBs2LON9V4MQl3M3VsCxGoW7IS7Ym8ku6SItJs4+ECQKEvQmP9+mLOcCGAS4BrA22YuBGGeusNrHlAAuEH/eV2NHkyEsnIbE0HCm4uMiiTCVrwsLDG87zkb2SQ1zOmYCnJn2/vjHaFeuITNfExYJGRFDtX64poAmQ1gQCcQlnFY5VZwYIu4Iy+FI7gtbfpYJ0HtI4IO7MOCEY3INuBS+L4iW5WRNiWs1GcLCscmsxStPVgFJg36R4QdZB5ZLkQ4Nl8kVMBggLHxuEFYqx2cm4B7kopFJSygqzr5ijQVNhrAgou22207zs3AipiIqHIzsuAeng7vAsVJZj+hNbBHOmsNUhAJBYQnyybn8Ni6wJmkX3DcVcLCSp8V2lameuTGhSSnv6YDBs555uBvp0KkGhjAKcTrep8jOOamAaIWwEIO4HdCJUsFuNYnul0q0NSVC8mONJSxEoOUicZZ5McjsTkPs0pZUIFMVwoJ4SbuOQ1iIczJPCdfk0phobFhjCQsuxSoaRCB5VamWWaEnseAV8USSIfG6VEDvg6vwG/9eWWFgFRLrKVlX2JR0prQhndFkHKTpQjiCviFfntGtCcfixYud3XffXZ2vOD2nTZvmHgnH66+/7gjX0t/wginCRnGAozdueKcpQvq7aTlI0wUcgRSZOLoKy95JC4ZTbb/99roRbiqwKJVd/BCJrDSKE3oBKP1xz22qaHKxwnwDJRyxGbTQIwzkcEXleP3WIExraYEorVVFYZn7v+N3ZABoCo7FZlS58xz+jt9hTMX/A/eR72+RaQ9jAAAAAElFTkSuQmCC";
  const githubMark = `<svg viewBox="0 0 98 96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"/></svg>`;
  function create_if_block$7(ctx) {
    let div1;
    let section;
    let t0;
    let div0;
    let a;
    let t1;
    let button;
    let div1_class_value;
    let current;
    let mounted;
    let dispose;
    const default_slot_template = (
      /*#slots*/
      ctx[8].default
    );
    const default_slot = create_slot(
      default_slot_template,
      ctx,
      /*$$scope*/
      ctx[7],
      null
    );
    return {
      c() {
        div1 = element("div");
        section = element("section");
        if (default_slot) default_slot.c();
        t0 = space();
        div0 = element("div");
        a = element("a");
        t1 = space();
        button = element("button");
        button.textContent = "✕";
        attr(section, "class", "overflow-hidden h-full");
        attr(a, "target", "_blank");
        attr(a, "href", "https://github.com/drunkg00se/Pixiv-Downloader");
        attr(a, "class", "w-5 fill-current");
        attr(button, "class", "btn-icon btn-icon-sm bg-transparent font-bold hover:text-xl");
        attr(div0, "class", "absolute top-2 right-2 z-1 select-none flex items-center gap-1");
        attr(div1, "data-theme", "skeleton");
        attr(div1, "class", div1_class_value = "relative rounded-container-token shadow-xl bg-scroll " + /*classes*/
        ctx[1]);
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, section);
        if (default_slot) {
          default_slot.m(section, null);
        }
        append(div1, t0);
        append(div1, div0);
        append(div0, a);
        a.innerHTML = githubMark;
        append(div0, t1);
        append(div0, button);
        current = true;
        if (!mounted) {
          dispose = listen(button, "click", function() {
            if (is_function(
              /*parent*/
              ctx[0].onClose
            )) ctx[0].onClose.apply(this, arguments);
          });
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        if (default_slot) {
          if (default_slot.p && (!current || dirty & /*$$scope*/
          128)) {
            update_slot_base(
              default_slot,
              default_slot_template,
              ctx,
              /*$$scope*/
              ctx[7],
              !current ? get_all_dirty_from_scope(
                /*$$scope*/
                ctx[7]
              ) : get_slot_changes(
                default_slot_template,
                /*$$scope*/
                ctx[7],
                dirty,
                null
              ),
              null
            );
          }
        }
        if (!current || dirty & /*classes*/
        2 && div1_class_value !== (div1_class_value = "relative rounded-container-token shadow-xl bg-scroll " + /*classes*/
        ctx[1])) {
          attr(div1, "class", div1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(default_slot, local);
        current = true;
      },
      o(local) {
        transition_out(default_slot, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        if (default_slot) default_slot.d(detaching);
        mounted = false;
        dispose();
      }
    };
  }
  function create_fragment$a(ctx) {
    let if_block_anchor;
    let current;
    let if_block = (
      /*$modalStore*/
      ctx[2][0] && create_if_block$7(ctx)
    );
    return {
      c() {
        if (if_block) if_block.c();
        if_block_anchor = empty();
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, if_block_anchor, anchor);
        current = true;
      },
      p(ctx2, [dirty]) {
        if (
          /*$modalStore*/
          ctx2[2][0]
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty & /*$modalStore*/
            4) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block$7(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(if_block_anchor.parentNode, if_block_anchor);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(if_block_anchor);
        }
        if (if_block) if_block.d(detaching);
      }
    };
  }
  function instance$a($$self, $$props, $$invalidate) {
    let classes;
    let $modalStore;
    let { $$slots: slots = {}, $$scope } = $$props;
    let { parent } = $$props;
    let { padding = "py-6 px-8" } = $$props;
    let { width = "w-full md:max-w-screen-sm lg:max-w-screen-md xl:max-w-screen-lg" } = $$props;
    let { height = "" } = $$props;
    const modalStore = getModalStore();
    component_subscribe($$self, modalStore, (value) => $$invalidate(2, $modalStore = value));
    $$self.$$set = ($$new_props) => {
      $$invalidate(9, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("parent" in $$new_props) $$invalidate(0, parent = $$new_props.parent);
      if ("padding" in $$new_props) $$invalidate(4, padding = $$new_props.padding);
      if ("width" in $$new_props) $$invalidate(5, width = $$new_props.width);
      if ("height" in $$new_props) $$invalidate(6, height = $$new_props.height);
      if ("$$scope" in $$new_props) $$invalidate(7, $$scope = $$new_props.$$scope);
    };
    $$self.$$.update = () => {
      $$invalidate(1, classes = `${padding} ${width} ${height} ${$$props.class ?? ""}`);
    };
    $$props = exclude_internal_props($$props);
    return [
      parent,
      classes,
      $modalStore,
      modalStore,
      padding,
      width,
      height,
      $$scope,
      slots
    ];
  }
  class ModalWrapper extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$a, create_fragment$a, safe_not_equal, {
        parent: 0,
        padding: 4,
        width: 5,
        height: 6
      });
    }
  }
  function create_default_slot$6(ctx) {
    let header;
    let t2;
    let article;
    let t14;
    let footer;
    let div0;
    let button;
    let t15_value = t("changelog.credit") + "";
    let t15;
    let t16;
    let a1;
    let t17_value = t("changelog.feedback") + "";
    let t17;
    let t18;
    let div2;
    let div1;
    let img;
    let img_src_value;
    let t19;
    let p;
    let a2;
    let t21;
    let span;
    let div2_class_value;
    let mounted;
    let dispose;
    return {
      c() {
        header = element("header");
        header.textContent = `Pixiv Downloader ${"1.4.0"}`;
        t2 = space();
        article = element("article");
        article.innerHTML = `<ul class="list-disc list-inside leading-loose"><li>新增:现在可以批量下载pixiv<a href="https://www.pixiv.net/user/3617446/series/136196" target="_blank" class="anchor">漫画系列</a>。</li> <li>新增:现在可以批量下载Danbooru: posts, pools, favorite groups。</li> <li>新增:现在可以在【设置】【其它】中填入cf_clearance cookie(rule34无法正常下载图片时)。</li> <li>修复:Pixiv多图预览按钮被遮挡的问题。</li> <li>修复:切换主题时Pixiv收藏标签按钮颜色不改变的问题。</li></ul>`;
        t14 = space();
        footer = element("footer");
        div0 = element("div");
        button = element("button");
        t15 = text(t15_value);
        t16 = space();
        a1 = element("a");
        t17 = text(t17_value);
        t18 = space();
        div2 = element("div");
        div1 = element("div");
        img = element("img");
        t19 = space();
        p = element("p");
        a2 = element("a");
        a2.textContent = `${t("changelog.give_me_a_star")}`;
        t21 = space();
        span = element("span");
        span.textContent = `${t("changelog.buy_me_a_drink")}`;
        attr(header, "class", "modal-header text-2xl font-bold");
        attr(article, "class", "modal-body mt-4");
        attr(
          button,
          "class",
          /*anchor*/
          ctx[3]
        );
        attr(
          a1,
          "class",
          /*anchor*/
          ctx[3]
        );
        attr(a1, "target", "_blank");
        attr(a1, "href", "https://github.com/drunkg00se/Pixiv-Downloader/issues");
        attr(div0, "class", "flex justify-between items-center text-sm");
        if (!src_url_equal(img.src, img_src_value = creditCode)) attr(img, "src", img_src_value);
        attr(img, "alt", "credit");
        attr(img, "class", "rounded-full");
        attr(a2, "href", "https://github.com/drunkg00se/Pixiv-Downloader");
        attr(a2, "target", "_blank");
        attr(a2, "class", "anchor");
        attr(p, "class", "flex flex-col h-full justify-evenly");
        attr(div1, "class", "flex justify-center items-center min-h-0 gap-14 overflow-hidden");
        attr(div2, "class", div2_class_value = "grid transition-[grid-template-rows] duration-[400ms] " + /*gridRows*/
        ctx[2]);
        attr(footer, "class", "modal-footer mt-4");
      },
      m(target, anchor) {
        insert(target, header, anchor);
        insert(target, t2, anchor);
        insert(target, article, anchor);
        insert(target, t14, anchor);
        insert(target, footer, anchor);
        append(footer, div0);
        append(div0, button);
        append(button, t15);
        append(div0, t16);
        append(div0, a1);
        append(a1, t17);
        append(footer, t18);
        append(footer, div2);
        append(div2, div1);
        append(div1, img);
        append(div1, t19);
        append(div1, p);
        append(p, a2);
        append(p, t21);
        append(p, span);
        if (!mounted) {
          dispose = listen(
            button,
            "click",
            /*click_handler*/
            ctx[4]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty & /*gridRows*/
        4 && div2_class_value !== (div2_class_value = "grid transition-[grid-template-rows] duration-[400ms] " + /*gridRows*/
        ctx2[2])) {
          attr(div2, "class", div2_class_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(header);
          detach(t2);
          detach(article);
          detach(t14);
          detach(footer);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_fragment$9(ctx) {
    let modalwrapper;
    let current;
    modalwrapper = new ModalWrapper({
      props: {
        parent: (
          /*parent*/
          ctx[0]
        ),
        $$slots: { default: [create_default_slot$6] },
        $$scope: { ctx }
      }
    });
    return {
      c() {
        create_component(modalwrapper.$$.fragment);
      },
      m(target, anchor) {
        mount_component(modalwrapper, target, anchor);
        current = true;
      },
      p(ctx2, [dirty]) {
        const modalwrapper_changes = {};
        if (dirty & /*parent*/
        1) modalwrapper_changes.parent = /*parent*/
        ctx2[0];
        if (dirty & /*$$scope, gridRows, showCreditCode*/
        70) {
          modalwrapper_changes.$$scope = { dirty, ctx: ctx2 };
        }
        modalwrapper.$set(modalwrapper_changes);
      },
      i(local) {
        if (current) return;
        transition_in(modalwrapper.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(modalwrapper.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(modalwrapper, detaching);
      }
    };
  }
  function instance$9($$self, $$props, $$invalidate) {
    let gridRows;
    const anchorFocus = `focus:!outline-none focus:decoration-wavy`;
    const anchor = `leading-loose anchor underline-offset-2 ${anchorFocus}`;
    let { parent } = $$props;
    let showCreditCode = false;
    const click_handler = () => $$invalidate(1, showCreditCode = !showCreditCode);
    $$self.$$set = ($$props2) => {
      if ("parent" in $$props2) $$invalidate(0, parent = $$props2.parent);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty & /*showCreditCode*/
      2) {
        $$invalidate(2, gridRows = showCreditCode ? "grid-rows-[1fr] mt-2" : "grid-rows-[0fr]");
      }
    };
    return [parent, showCreditCode, gridRows, anchor, click_handler];
  }
  class Changelog extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$9, create_fragment$9, safe_not_equal, { parent: 0 });
    }
  }
  const check = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>check</title><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" /></svg>`;
  const folderSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6H12L10,4Z" /></svg>`;
  const fileSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13,9V3.5L18.5,9M6,2C4.89,2 4,2.89 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2H6Z" /></svg>`;
  const configStore = writable();
  function initConfigStore() {
    const data = config.getAll();
    configStore.set(data);
    configStore.subscribe(config.update);
    return configStore;
  }
  function get_each_context$3(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[40] = list[i];
    return child_ctx;
  }
  function get_each_context_1$2(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[40] = list[i];
    return child_ctx;
  }
  function create_else_block$2(ctx) {
    let input;
    return {
      c() {
        input = element("input");
        attr(input, "type", "text");
        input.disabled = true;
        attr(
          input,
          "placeholder",
          /*directoryPlaceholder*/
          ctx[11]
        );
      },
      m(target, anchor) {
        insert(target, input, anchor);
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*directoryPlaceholder*/
        2048) {
          attr(
            input,
            "placeholder",
            /*directoryPlaceholder*/
            ctx2[11]
          );
        }
      },
      d(detaching) {
        if (detaching) {
          detach(input);
        }
      }
    };
  }
  function create_if_block_2$3(ctx) {
    let input;
    let mounted;
    let dispose;
    return {
      c() {
        input = element("input");
        attr(input, "type", "text");
        attr(
          input,
          "placeholder",
          /*directoryPlaceholder*/
          ctx[11]
        );
      },
      m(target, anchor) {
        insert(target, input, anchor);
        ctx[27](input);
        set_input_value(
          input,
          /*directory*/
          ctx[4]
        );
        if (!mounted) {
          dispose = listen(
            input,
            "input",
            /*input_input_handler*/
            ctx[28]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*directoryPlaceholder*/
        2048) {
          attr(
            input,
            "placeholder",
            /*directoryPlaceholder*/
            ctx2[11]
          );
        }
        if (dirty[0] & /*directory*/
        16 && input.value !== /*directory*/
        ctx2[4]) {
          set_input_value(
            input,
            /*directory*/
            ctx2[4]
          );
        }
      },
      d(detaching) {
        if (detaching) {
          detach(input);
        }
        ctx[27](null);
        mounted = false;
        dispose();
      }
    };
  }
  function create_each_block_1$2(ctx) {
    let button;
    let span;
    let t0_value = (
      /*template*/
      ctx[40] + ""
    );
    let t0;
    let t1;
    let button_disabled_value;
    let mounted;
    let dispose;
    return {
      c() {
        button = element("button");
        span = element("span");
        t0 = text(t0_value);
        t1 = space();
        attr(button, "class", "chip variant-soft hover:variant-filled");
        button.disabled = button_disabled_value = !/*subDirectoryAvailable*/
        ctx[6];
      },
      m(target, anchor) {
        insert(target, button, anchor);
        append(button, span);
        append(span, t0);
        append(button, t1);
        if (!mounted) {
          dispose = listen(button, "click", function() {
            if (is_function(
              /*insertDirTemplateAtCursor*/
              ctx[20](
                /*template*/
                ctx[40]
              )
            )) ctx[20](
              /*template*/
              ctx[40]
            ).apply(this, arguments);
          });
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        if (dirty[0] & /*templates*/
        8 && t0_value !== (t0_value = /*template*/
        ctx[40] + "")) set_data(t0, t0_value);
        if (dirty[0] & /*subDirectoryAvailable*/
        64 && button_disabled_value !== (button_disabled_value = !/*subDirectoryAvailable*/
        ctx[6])) {
          button.disabled = button_disabled_value;
        }
      },
      d(detaching) {
        if (detaching) {
          detach(button);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_if_block_1$5(ctx) {
    let li0;
    let p0;
    let t1;
    let span;
    let t2;
    let t3;
    let button;
    let t5;
    let li1;
    let p1;
    let t7;
    let radiogroup;
    let current;
    let mounted;
    let dispose;
    radiogroup = new RadioGroup({
      props: {
        class: "shrink-0",
        $$slots: { default: [create_default_slot_5$2] },
        $$scope: { ctx }
      }
    });
    return {
      c() {
        li0 = element("li");
        p0 = element("p");
        p0.textContent = `${t("setting.save_to.options.fsa_directory")}`;
        t1 = space();
        span = element("span");
        t2 = text(
          /*fsaDirectory*/
          ctx[10]
        );
        t3 = space();
        button = element("button");
        button.textContent = `${t("setting.save_to.button.choose_fsa_directory")}`;
        t5 = space();
        li1 = element("li");
        p1 = element("p");
        p1.textContent = `${t("setting.save_to.options.fsa_filename_conflict")}`;
        t7 = space();
        create_component(radiogroup.$$.fragment);
        attr(p0, "class", "flex-auto");
        attr(span, "class", "text-sm italic");
        attr(button, "class", "btn btn-sm variant-filled");
        attr(p1, "class", "flex-auto");
      },
      m(target, anchor) {
        insert(target, li0, anchor);
        append(li0, p0);
        append(li0, t1);
        append(li0, span);
        append(span, t2);
        append(li0, t3);
        append(li0, button);
        insert(target, t5, anchor);
        insert(target, li1, anchor);
        append(li1, p1);
        append(li1, t7);
        mount_component(radiogroup, li1, null);
        current = true;
        if (!mounted) {
          dispose = listen(
            button,
            "click",
            /*updatefsaDir*/
            ctx[19]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (!current || dirty[0] & /*fsaDirectory*/
        1024) set_data(
          t2,
          /*fsaDirectory*/
          ctx2[10]
        );
        const radiogroup_changes = {};
        if (dirty[0] & /*$store*/
        128 | dirty[1] & /*$$scope*/
        16384) {
          radiogroup_changes.$$scope = { dirty, ctx: ctx2 };
        }
        radiogroup.$set(radiogroup_changes);
      },
      i(local) {
        if (current) return;
        transition_in(radiogroup.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radiogroup.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(li0);
          detach(t5);
          detach(li1);
        }
        destroy_component(radiogroup);
        mounted = false;
        dispose();
      }
    };
  }
  function create_default_slot_8(ctx) {
    let t_1_value = t("setting.save_to.radio.filename_conflict_option_uniquify") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_7(ctx) {
    let t_1_value = t("setting.save_to.radio.filename_conflict_option_overwrite") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_6$2(ctx) {
    let t_1_value = t("setting.save_to.radio.filename_conflict_option_prompt") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_5$2(ctx) {
    let radioitem0;
    let updating_group;
    let t0;
    let radioitem1;
    let updating_group_1;
    let t1;
    let radioitem2;
    let updating_group_2;
    let current;
    function radioitem0_group_binding(value) {
      ctx[30](value);
    }
    let radioitem0_props = {
      name: "filenameConfigAction",
      class: "text-sm",
      value: FilenameConfigAction.UNIQUIFY,
      $$slots: { default: [create_default_slot_8] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].fileSystemFilenameConflictAction !== void 0
    ) {
      radioitem0_props.group = /*$store*/
      ctx[7].fileSystemFilenameConflictAction;
    }
    radioitem0 = new RadioItem({ props: radioitem0_props });
    binding_callbacks.push(() => bind(radioitem0, "group", radioitem0_group_binding));
    function radioitem1_group_binding(value) {
      ctx[31](value);
    }
    let radioitem1_props = {
      name: "filenameConfigAction",
      class: "text-sm",
      value: FilenameConfigAction.OVERWRITE,
      $$slots: { default: [create_default_slot_7] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].fileSystemFilenameConflictAction !== void 0
    ) {
      radioitem1_props.group = /*$store*/
      ctx[7].fileSystemFilenameConflictAction;
    }
    radioitem1 = new RadioItem({ props: radioitem1_props });
    binding_callbacks.push(() => bind(radioitem1, "group", radioitem1_group_binding));
    function radioitem2_group_binding(value) {
      ctx[32](value);
    }
    let radioitem2_props = {
      name: "filenameConfigAction",
      class: "text-sm",
      value: FilenameConfigAction.PROMPT,
      $$slots: { default: [create_default_slot_6$2] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].fileSystemFilenameConflictAction !== void 0
    ) {
      radioitem2_props.group = /*$store*/
      ctx[7].fileSystemFilenameConflictAction;
    }
    radioitem2 = new RadioItem({ props: radioitem2_props });
    binding_callbacks.push(() => bind(radioitem2, "group", radioitem2_group_binding));
    return {
      c() {
        create_component(radioitem0.$$.fragment);
        t0 = space();
        create_component(radioitem1.$$.fragment);
        t1 = space();
        create_component(radioitem2.$$.fragment);
      },
      m(target, anchor) {
        mount_component(radioitem0, target, anchor);
        insert(target, t0, anchor);
        mount_component(radioitem1, target, anchor);
        insert(target, t1, anchor);
        mount_component(radioitem2, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const radioitem0_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty[0] & /*$store*/
        128) {
          updating_group = true;
          radioitem0_changes.group = /*$store*/
          ctx2[7].fileSystemFilenameConflictAction;
          add_flush_callback(() => updating_group = false);
        }
        radioitem0.$set(radioitem0_changes);
        const radioitem1_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_1 && dirty[0] & /*$store*/
        128) {
          updating_group_1 = true;
          radioitem1_changes.group = /*$store*/
          ctx2[7].fileSystemFilenameConflictAction;
          add_flush_callback(() => updating_group_1 = false);
        }
        radioitem1.$set(radioitem1_changes);
        const radioitem2_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem2_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_2 && dirty[0] & /*$store*/
        128) {
          updating_group_2 = true;
          radioitem2_changes.group = /*$store*/
          ctx2[7].fileSystemFilenameConflictAction;
          add_flush_callback(() => updating_group_2 = false);
        }
        radioitem2.$set(radioitem2_changes);
      },
      i(local) {
        if (current) return;
        transition_in(radioitem0.$$.fragment, local);
        transition_in(radioitem1.$$.fragment, local);
        transition_in(radioitem2.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radioitem0.$$.fragment, local);
        transition_out(radioitem1.$$.fragment, local);
        transition_out(radioitem2.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t0);
          detach(t1);
        }
        destroy_component(radioitem0, detaching);
        destroy_component(radioitem1, detaching);
        destroy_component(radioitem2, detaching);
      }
    };
  }
  function create_each_block$3(ctx) {
    let button;
    let span;
    let t0_value = (
      /*template*/
      ctx[40] + ""
    );
    let t0;
    let t1;
    let mounted;
    let dispose;
    return {
      c() {
        button = element("button");
        span = element("span");
        t0 = text(t0_value);
        t1 = space();
        attr(button, "class", "chip variant-soft hover:variant-filled");
      },
      m(target, anchor) {
        insert(target, button, anchor);
        append(button, span);
        append(span, t0);
        append(button, t1);
        if (!mounted) {
          dispose = listen(button, "click", function() {
            if (is_function(
              /*insertFilenameTemplateAtCursor*/
              ctx[21](
                /*template*/
                ctx[40]
              )
            )) ctx[21](
              /*template*/
              ctx[40]
            ).apply(this, arguments);
          });
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        if (dirty[0] & /*templates*/
        8 && t0_value !== (t0_value = /*template*/
        ctx[40] + "")) set_data(t0, t0_value);
      },
      d(detaching) {
        if (detaching) {
          detach(button);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_if_block$6(ctx) {
    let li;
    let div;
    let p0;
    let t1;
    let p1;
    let t2_value = t("setting.save_to.options.tag_language_tips") + "";
    let t2;
    let t3;
    let radiogroup;
    let current;
    radiogroup = new RadioGroup({
      props: {
        class: " shrink-0",
        $$slots: { default: [create_default_slot$5] },
        $$scope: { ctx }
      }
    });
    return {
      c() {
        li = element("li");
        div = element("div");
        p0 = element("p");
        p0.textContent = `${t("setting.save_to.options.tag_language")}`;
        t1 = space();
        p1 = element("p");
        t2 = text(t2_value);
        t3 = space();
        create_component(radiogroup.$$.fragment);
        attr(
          p1,
          "class",
          /*descritionText*/
          ctx[0]
        );
        attr(div, "class", "flex-auto");
      },
      m(target, anchor) {
        insert(target, li, anchor);
        append(li, div);
        append(div, p0);
        append(div, t1);
        append(div, p1);
        append(p1, t2);
        append(li, t3);
        mount_component(radiogroup, li, null);
        current = true;
      },
      p(ctx2, dirty) {
        if (!current || dirty[0] & /*descritionText*/
        1) {
          attr(
            p1,
            "class",
            /*descritionText*/
            ctx2[0]
          );
        }
        const radiogroup_changes = {};
        if (dirty[0] & /*$store*/
        128 | dirty[1] & /*$$scope*/
        16384) {
          radiogroup_changes.$$scope = { dirty, ctx: ctx2 };
        }
        radiogroup.$set(radiogroup_changes);
      },
      i(local) {
        if (current) return;
        transition_in(radiogroup.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radiogroup.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(li);
        }
        destroy_component(radiogroup);
      }
    };
  }
  function create_default_slot_4$2(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("日本語");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_3$4(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("简中");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_2$4(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("繁中");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_1$4(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("En");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot$5(ctx) {
    let radioitem0;
    let updating_group;
    let t0;
    let radioitem1;
    let updating_group_1;
    let t1;
    let radioitem2;
    let updating_group_2;
    let t2;
    let radioitem3;
    let updating_group_3;
    let current;
    function radioitem0_group_binding_1(value) {
      ctx[35](value);
    }
    let radioitem0_props = {
      name: "tagLang",
      class: "text-sm",
      value: TagLanguage.JAPANESE,
      $$slots: { default: [create_default_slot_4$2] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].tagLang !== void 0
    ) {
      radioitem0_props.group = /*$store*/
      ctx[7].tagLang;
    }
    radioitem0 = new RadioItem({ props: radioitem0_props });
    binding_callbacks.push(() => bind(radioitem0, "group", radioitem0_group_binding_1));
    function radioitem1_group_binding_1(value) {
      ctx[36](value);
    }
    let radioitem1_props = {
      name: "tagLang",
      class: "text-sm",
      value: TagLanguage.CHINESE,
      $$slots: { default: [create_default_slot_3$4] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].tagLang !== void 0
    ) {
      radioitem1_props.group = /*$store*/
      ctx[7].tagLang;
    }
    radioitem1 = new RadioItem({ props: radioitem1_props });
    binding_callbacks.push(() => bind(radioitem1, "group", radioitem1_group_binding_1));
    function radioitem2_group_binding_1(value) {
      ctx[37](value);
    }
    let radioitem2_props = {
      name: "tagLang",
      class: "text-sm",
      value: TagLanguage.TRADITIONAL_CHINESE,
      $$slots: { default: [create_default_slot_2$4] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].tagLang !== void 0
    ) {
      radioitem2_props.group = /*$store*/
      ctx[7].tagLang;
    }
    radioitem2 = new RadioItem({ props: radioitem2_props });
    binding_callbacks.push(() => bind(radioitem2, "group", radioitem2_group_binding_1));
    function radioitem3_group_binding(value) {
      ctx[38](value);
    }
    let radioitem3_props = {
      name: "tagLang",
      class: "text-sm",
      value: TagLanguage.ENGLISH,
      $$slots: { default: [create_default_slot_1$4] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].tagLang !== void 0
    ) {
      radioitem3_props.group = /*$store*/
      ctx[7].tagLang;
    }
    radioitem3 = new RadioItem({ props: radioitem3_props });
    binding_callbacks.push(() => bind(radioitem3, "group", radioitem3_group_binding));
    return {
      c() {
        create_component(radioitem0.$$.fragment);
        t0 = space();
        create_component(radioitem1.$$.fragment);
        t1 = space();
        create_component(radioitem2.$$.fragment);
        t2 = space();
        create_component(radioitem3.$$.fragment);
      },
      m(target, anchor) {
        mount_component(radioitem0, target, anchor);
        insert(target, t0, anchor);
        mount_component(radioitem1, target, anchor);
        insert(target, t1, anchor);
        mount_component(radioitem2, target, anchor);
        insert(target, t2, anchor);
        mount_component(radioitem3, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const radioitem0_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty[0] & /*$store*/
        128) {
          updating_group = true;
          radioitem0_changes.group = /*$store*/
          ctx2[7].tagLang;
          add_flush_callback(() => updating_group = false);
        }
        radioitem0.$set(radioitem0_changes);
        const radioitem1_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_1 && dirty[0] & /*$store*/
        128) {
          updating_group_1 = true;
          radioitem1_changes.group = /*$store*/
          ctx2[7].tagLang;
          add_flush_callback(() => updating_group_1 = false);
        }
        radioitem1.$set(radioitem1_changes);
        const radioitem2_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem2_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_2 && dirty[0] & /*$store*/
        128) {
          updating_group_2 = true;
          radioitem2_changes.group = /*$store*/
          ctx2[7].tagLang;
          add_flush_callback(() => updating_group_2 = false);
        }
        radioitem2.$set(radioitem2_changes);
        const radioitem3_changes = {};
        if (dirty[1] & /*$$scope*/
        16384) {
          radioitem3_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_3 && dirty[0] & /*$store*/
        128) {
          updating_group_3 = true;
          radioitem3_changes.group = /*$store*/
          ctx2[7].tagLang;
          add_flush_callback(() => updating_group_3 = false);
        }
        radioitem3.$set(radioitem3_changes);
      },
      i(local) {
        if (current) return;
        transition_in(radioitem0.$$.fragment, local);
        transition_in(radioitem1.$$.fragment, local);
        transition_in(radioitem2.$$.fragment, local);
        transition_in(radioitem3.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radioitem0.$$.fragment, local);
        transition_out(radioitem1.$$.fragment, local);
        transition_out(radioitem2.$$.fragment, local);
        transition_out(radioitem3.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t0);
          detach(t1);
          detach(t2);
        }
        destroy_component(radioitem0, detaching);
        destroy_component(radioitem1, detaching);
        destroy_component(radioitem2, detaching);
        destroy_component(radioitem3, detaching);
      }
    };
  }
  function create_fragment$8(ctx) {
    let div4;
    let section0;
    let p0;
    let t0_value = t("setting.save_to.label.directory") + "";
    let t0;
    let t1;
    let ul0;
    let li0;
    let div0;
    let button0;
    let i0;
    let t2;
    let t3;
    let button1;
    let i1;
    let t4;
    let div1;
    let t5;
    let li1;
    let p1;
    let t7;
    let slidetoggle;
    let updating_checked;
    let t8;
    let t9;
    let section1;
    let p2;
    let t10_value = t("setting.save_to.label.filename") + "";
    let t10;
    let t11;
    let ul1;
    let li2;
    let div2;
    let button2;
    let i2;
    let t12;
    let input;
    let t13;
    let button3;
    let i3;
    let t14;
    let div3;
    let t15;
    let show_if = env.isPixiv();
    let current;
    let mounted;
    let dispose;
    function select_block_type(ctx2, dirty) {
      if (
        /*subDirectoryAvailable*/
        ctx2[6]
      ) return create_if_block_2$3;
      return create_else_block$2;
    }
    let current_block_type = select_block_type(ctx);
    let if_block0 = current_block_type(ctx);
    let each_value_1 = ensure_array_like(
      /*templates*/
      ctx[3]
    );
    let each_blocks_1 = [];
    for (let i = 0; i < each_value_1.length; i += 1) {
      each_blocks_1[i] = create_each_block_1$2(get_each_context_1$2(ctx, each_value_1, i));
    }
    function slidetoggle_checked_binding(value) {
      ctx[29](value);
    }
    let slidetoggle_props = {
      size: "sm",
      name: "fsa-enable",
      disabled: !env.isFileSystemAccessAvaliable()
    };
    if (
      /*$store*/
      ctx[7].useFileSystemAccess !== void 0
    ) {
      slidetoggle_props.checked = /*$store*/
      ctx[7].useFileSystemAccess;
    }
    slidetoggle = new SlideToggle({ props: slidetoggle_props });
    binding_callbacks.push(() => bind(slidetoggle, "checked", slidetoggle_checked_binding));
    let if_block1 = (
      /*$store*/
      ctx[7].useFileSystemAccess && create_if_block_1$5(ctx)
    );
    let each_value = ensure_array_like(
      /*templates*/
      ctx[3]
    );
    let each_blocks = [];
    for (let i = 0; i < each_value.length; i += 1) {
      each_blocks[i] = create_each_block$3(get_each_context$3(ctx, each_value, i));
    }
    let if_block2 = show_if && create_if_block$6(ctx);
    return {
      c() {
        div4 = element("div");
        section0 = element("section");
        p0 = element("p");
        t0 = text(t0_value);
        t1 = space();
        ul0 = element("ul");
        li0 = element("li");
        div0 = element("div");
        button0 = element("button");
        i0 = element("i");
        t2 = space();
        if_block0.c();
        t3 = space();
        button1 = element("button");
        i1 = element("i");
        t4 = space();
        div1 = element("div");
        for (let i = 0; i < each_blocks_1.length; i += 1) {
          each_blocks_1[i].c();
        }
        t5 = space();
        li1 = element("li");
        p1 = element("p");
        p1.textContent = `${t("setting.save_to.options.use_fsa")}`;
        t7 = space();
        create_component(slidetoggle.$$.fragment);
        t8 = space();
        if (if_block1) if_block1.c();
        t9 = space();
        section1 = element("section");
        p2 = element("p");
        t10 = text(t10_value);
        t11 = space();
        ul1 = element("ul");
        li2 = element("li");
        div2 = element("div");
        button2 = element("button");
        i2 = element("i");
        t12 = space();
        input = element("input");
        t13 = space();
        button3 = element("button");
        i3 = element("i");
        t14 = space();
        div3 = element("div");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        t15 = space();
        if (if_block2) if_block2.c();
        attr(
          p0,
          "class",
          /*sectionTitle*/
          ctx[2]
        );
        attr(i0, "class", "w-6 fill-current");
        attr(button0, "type", "button");
        attr(button0, "class", "[&:not([disabled])]:variant-soft-primary");
        button0.disabled = /*folderBtnDisabled*/
        ctx[13];
        attr(i1, "class", "w-6 fill-current");
        attr(button1, "type", "button");
        attr(button1, "class", "variant-soft-surface [&:not([disabled])]:variant-soft-primary");
        button1.disabled = /*folderBtnDisabled*/
        ctx[13];
        attr(div0, "class", "input-group input-group-divider grid-cols-[auto_1fr_auto_auto]");
        attr(div1, "class", "self-start space-x-2");
        attr(li0, "class", "flex-col gap-3");
        attr(p1, "class", "flex-auto");
        attr(
          ul0,
          "class",
          /*ulClasses*/
          ctx[14]
        );
        attr(
          p2,
          "class",
          /*sectionTitle*/
          ctx[2]
        );
        attr(i2, "class", "w-6 fill-current");
        attr(button2, "type", "button");
        attr(button2, "class", "[&:not([disabled])]:variant-soft-primary");
        button2.disabled = /*filenameBtnDisabled*/
        ctx[12];
        attr(input, "type", "text");
        input.required = true;
        attr(input, "placeholder", t("setting.save_to.placeholder.filename_requried"));
        attr(i3, "class", "w-6 fill-current");
        attr(button3, "type", "button");
        attr(button3, "class", "variant-soft-surface dark:variant-fill-surface [&:not([disabled])]:variant-soft-primary");
        button3.disabled = /*filenameBtnDisabled*/
        ctx[12];
        attr(div2, "class", "input-group input-group-divider grid-cols-[auto_1fr_auto]");
        attr(div3, "class", "self-start space-x-2");
        attr(li2, "class", "flex-col gap-3");
        attr(
          ul1,
          "class",
          /*ulClasses*/
          ctx[14]
        );
        attr(
          div4,
          "class",
          /*sectionSpace*/
          ctx[1]
        );
      },
      m(target, anchor) {
        insert(target, div4, anchor);
        append(div4, section0);
        append(section0, p0);
        append(p0, t0);
        append(section0, t1);
        append(section0, ul0);
        append(ul0, li0);
        append(li0, div0);
        append(div0, button0);
        append(button0, i0);
        i0.innerHTML = folderSvg;
        append(div0, t2);
        if_block0.m(div0, null);
        append(div0, t3);
        append(div0, button1);
        append(button1, i1);
        i1.innerHTML = check;
        append(li0, t4);
        append(li0, div1);
        for (let i = 0; i < each_blocks_1.length; i += 1) {
          if (each_blocks_1[i]) {
            each_blocks_1[i].m(div1, null);
          }
        }
        append(ul0, t5);
        append(ul0, li1);
        append(li1, p1);
        append(li1, t7);
        mount_component(slidetoggle, li1, null);
        append(ul0, t8);
        if (if_block1) if_block1.m(ul0, null);
        append(div4, t9);
        append(div4, section1);
        append(section1, p2);
        append(p2, t10);
        append(section1, t11);
        append(section1, ul1);
        append(ul1, li2);
        append(li2, div2);
        append(div2, button2);
        append(button2, i2);
        i2.innerHTML = fileSvg;
        append(div2, t12);
        append(div2, input);
        ctx[33](input);
        set_input_value(
          input,
          /*filename*/
          ctx[5]
        );
        append(div2, t13);
        append(div2, button3);
        append(button3, i3);
        i3.innerHTML = check;
        append(li2, t14);
        append(li2, div3);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(div3, null);
          }
        }
        append(ul1, t15);
        if (if_block2) if_block2.m(ul1, null);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              button0,
              "click",
              /*resetFolder*/
              ctx[17]
            ),
            listen(
              button1,
              "click",
              /*updateDirectory*/
              ctx[15]
            ),
            listen(
              button2,
              "click",
              /*resetFilename*/
              ctx[18]
            ),
            listen(
              input,
              "input",
              /*input_input_handler_1*/
              ctx[34]
            ),
            listen(
              button3,
              "click",
              /*updateFilename*/
              ctx[16]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (!current || dirty[0] & /*sectionTitle*/
        4) {
          attr(
            p0,
            "class",
            /*sectionTitle*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*folderBtnDisabled*/
        8192) {
          button0.disabled = /*folderBtnDisabled*/
          ctx2[13];
        }
        if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block0) {
          if_block0.p(ctx2, dirty);
        } else {
          if_block0.d(1);
          if_block0 = current_block_type(ctx2);
          if (if_block0) {
            if_block0.c();
            if_block0.m(div0, t3);
          }
        }
        if (!current || dirty[0] & /*folderBtnDisabled*/
        8192) {
          button1.disabled = /*folderBtnDisabled*/
          ctx2[13];
        }
        if (dirty[0] & /*subDirectoryAvailable, insertDirTemplateAtCursor, templates*/
        1048648) {
          each_value_1 = ensure_array_like(
            /*templates*/
            ctx2[3]
          );
          let i;
          for (i = 0; i < each_value_1.length; i += 1) {
            const child_ctx = get_each_context_1$2(ctx2, each_value_1, i);
            if (each_blocks_1[i]) {
              each_blocks_1[i].p(child_ctx, dirty);
            } else {
              each_blocks_1[i] = create_each_block_1$2(child_ctx);
              each_blocks_1[i].c();
              each_blocks_1[i].m(div1, null);
            }
          }
          for (; i < each_blocks_1.length; i += 1) {
            each_blocks_1[i].d(1);
          }
          each_blocks_1.length = each_value_1.length;
        }
        const slidetoggle_changes = {};
        if (!updating_checked && dirty[0] & /*$store*/
        128) {
          updating_checked = true;
          slidetoggle_changes.checked = /*$store*/
          ctx2[7].useFileSystemAccess;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle.$set(slidetoggle_changes);
        if (
          /*$store*/
          ctx2[7].useFileSystemAccess
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
            if (dirty[0] & /*$store*/
            128) {
              transition_in(if_block1, 1);
            }
          } else {
            if_block1 = create_if_block_1$5(ctx2);
            if_block1.c();
            transition_in(if_block1, 1);
            if_block1.m(ul0, null);
          }
        } else if (if_block1) {
          group_outros();
          transition_out(if_block1, 1, 1, () => {
            if_block1 = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*ulClasses*/
        16384) {
          attr(
            ul0,
            "class",
            /*ulClasses*/
            ctx2[14]
          );
        }
        if (!current || dirty[0] & /*sectionTitle*/
        4) {
          attr(
            p2,
            "class",
            /*sectionTitle*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*filenameBtnDisabled*/
        4096) {
          button2.disabled = /*filenameBtnDisabled*/
          ctx2[12];
        }
        if (dirty[0] & /*filename*/
        32 && input.value !== /*filename*/
        ctx2[5]) {
          set_input_value(
            input,
            /*filename*/
            ctx2[5]
          );
        }
        if (!current || dirty[0] & /*filenameBtnDisabled*/
        4096) {
          button3.disabled = /*filenameBtnDisabled*/
          ctx2[12];
        }
        if (dirty[0] & /*insertFilenameTemplateAtCursor, templates*/
        2097160) {
          each_value = ensure_array_like(
            /*templates*/
            ctx2[3]
          );
          let i;
          for (i = 0; i < each_value.length; i += 1) {
            const child_ctx = get_each_context$3(ctx2, each_value, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
            } else {
              each_blocks[i] = create_each_block$3(child_ctx);
              each_blocks[i].c();
              each_blocks[i].m(div3, null);
            }
          }
          for (; i < each_blocks.length; i += 1) {
            each_blocks[i].d(1);
          }
          each_blocks.length = each_value.length;
        }
        if (show_if) if_block2.p(ctx2, dirty);
        if (!current || dirty[0] & /*ulClasses*/
        16384) {
          attr(
            ul1,
            "class",
            /*ulClasses*/
            ctx2[14]
          );
        }
        if (!current || dirty[0] & /*sectionSpace*/
        2) {
          attr(
            div4,
            "class",
            /*sectionSpace*/
            ctx2[1]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle.$$.fragment, local);
        transition_in(if_block1);
        transition_in(if_block2);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle.$$.fragment, local);
        transition_out(if_block1);
        transition_out(if_block2);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div4);
        }
        if_block0.d();
        destroy_each(each_blocks_1, detaching);
        destroy_component(slidetoggle);
        if (if_block1) if_block1.d();
        ctx[33](null);
        destroy_each(each_blocks, detaching);
        if (if_block2) if_block2.d();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function instance$8($$self, $$props, $$invalidate) {
    let ulClasses;
    let subDirectoryAvailable;
    let folderBtnDisabled;
    let filenameBtnDisabled;
    let directoryPlaceholder;
    let $store;
    component_subscribe($$self, configStore, ($$value) => $$invalidate(7, $store = $$value));
    let { bg = "bg-white/30 dark:bg-black/15" } = $$props;
    let { border = "divide-y-[1px] *:border-surface-300-600-token" } = $$props;
    let { padding = "px-4 *:py-4" } = $$props;
    let { margin = "mt-2 *:!m-0" } = $$props;
    let { rounded = "rounded-container-token *:!rounded-none" } = $$props;
    let { descritionText = "text-sm text-surface-400" } = $$props;
    let { sectionSpace = `space-y-4` } = $$props;
    let { sectionTitle = "font-bold" } = $$props;
    let { templates = getContext("filenameTemplate") } = $$props;
    let directoryRef;
    let filenameRef;
    let directory = $store.folderPattern;
    let filename = $store.filenamePattern;
    let fsaDirectory = downloader.getCurrentFsaDirName();
    function updateDirectory() {
      const newDirectory = directory.split("/").map(replaceInvalidChar).filter((path) => !!path).join("/");
      set_store_value(configStore, $store.folderPattern = $$invalidate(4, directory = newDirectory), $store);
    }
    function updateFilename() {
      const newFilename = replaceInvalidChar(filename);
      if (newFilename === "") {
        $$invalidate(5, filename = $store.filenamePattern);
      } else {
        set_store_value(configStore, $store.filenamePattern = $$invalidate(5, filename = newFilename), $store);
      }
    }
    async function resetFolder() {
      $$invalidate(4, directory = $store.folderPattern);
      await tick();
      const pos = directory.length;
      directoryRef.focus();
      directoryRef.setSelectionRange(pos, pos);
    }
    async function resetFilename() {
      $$invalidate(5, filename = $store.filenamePattern);
      await tick();
      const pos = filename.length;
      filenameRef.focus();
      filenameRef.setSelectionRange(pos, pos);
    }
    async function updatefsaDir() {
      $$invalidate(10, fsaDirectory = await downloader.updateDirHandle());
      console.log(fsaDirectory);
    }
    function insertDirTemplateAtCursor(template) {
      return async () => {
        const start = directoryRef.selectionStart;
        const end = directoryRef.selectionEnd;
        $$invalidate(4, directory = directory.slice(0, start) + template + directory.slice(end));
        await tick();
        const newStart = start + template.length;
        directoryRef.focus();
        directoryRef.setSelectionRange(newStart, newStart);
      };
    }
    function insertFilenameTemplateAtCursor(template) {
      return async () => {
        const start = filenameRef.selectionStart;
        const end = filenameRef.selectionEnd;
        $$invalidate(5, filename = filename.slice(0, start) + template + filename.slice(end));
        await tick();
        const newStart = start + template.length;
        filenameRef.focus();
        filenameRef.setSelectionRange(newStart, newStart);
      };
    }
    function input_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        directoryRef = $$value;
        $$invalidate(8, directoryRef);
      });
    }
    function input_input_handler() {
      directory = this.value;
      $$invalidate(4, directory);
    }
    function slidetoggle_checked_binding(value) {
      if ($$self.$$.not_equal($store.useFileSystemAccess, value)) {
        $store.useFileSystemAccess = value;
        configStore.set($store);
      }
    }
    function radioitem0_group_binding(value) {
      if ($$self.$$.not_equal($store.fileSystemFilenameConflictAction, value)) {
        $store.fileSystemFilenameConflictAction = value;
        configStore.set($store);
      }
    }
    function radioitem1_group_binding(value) {
      if ($$self.$$.not_equal($store.fileSystemFilenameConflictAction, value)) {
        $store.fileSystemFilenameConflictAction = value;
        configStore.set($store);
      }
    }
    function radioitem2_group_binding(value) {
      if ($$self.$$.not_equal($store.fileSystemFilenameConflictAction, value)) {
        $store.fileSystemFilenameConflictAction = value;
        configStore.set($store);
      }
    }
    function input_binding_1($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        filenameRef = $$value;
        $$invalidate(9, filenameRef);
      });
    }
    function input_input_handler_1() {
      filename = this.value;
      $$invalidate(5, filename);
    }
    function radioitem0_group_binding_1(value) {
      if ($$self.$$.not_equal($store.tagLang, value)) {
        $store.tagLang = value;
        configStore.set($store);
      }
    }
    function radioitem1_group_binding_1(value) {
      if ($$self.$$.not_equal($store.tagLang, value)) {
        $store.tagLang = value;
        configStore.set($store);
      }
    }
    function radioitem2_group_binding_1(value) {
      if ($$self.$$.not_equal($store.tagLang, value)) {
        $store.tagLang = value;
        configStore.set($store);
      }
    }
    function radioitem3_group_binding(value) {
      if ($$self.$$.not_equal($store.tagLang, value)) {
        $store.tagLang = value;
        configStore.set($store);
      }
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(39, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("bg" in $$new_props) $$invalidate(22, bg = $$new_props.bg);
      if ("border" in $$new_props) $$invalidate(23, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(24, padding = $$new_props.padding);
      if ("margin" in $$new_props) $$invalidate(25, margin = $$new_props.margin);
      if ("rounded" in $$new_props) $$invalidate(26, rounded = $$new_props.rounded);
      if ("descritionText" in $$new_props) $$invalidate(0, descritionText = $$new_props.descritionText);
      if ("sectionSpace" in $$new_props) $$invalidate(1, sectionSpace = $$new_props.sectionSpace);
      if ("sectionTitle" in $$new_props) $$invalidate(2, sectionTitle = $$new_props.sectionTitle);
      if ("templates" in $$new_props) $$invalidate(3, templates = $$new_props.templates);
    };
    $$self.$$.update = () => {
      $$invalidate(14, ulClasses = `list *:items-center ${padding} ${margin} ${border} ${bg} ${rounded} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty[0] & /*$store*/
      128) {
        $$invalidate(6, subDirectoryAvailable = $store.useFileSystemAccess || env.isSupportSubpath());
      }
      if ($$self.$$.dirty[0] & /*directory, $store*/
      144) {
        $$invalidate(13, folderBtnDisabled = directory === $store.folderPattern);
      }
      if ($$self.$$.dirty[0] & /*filename, $store*/
      160) {
        $$invalidate(12, filenameBtnDisabled = filename === $store.filenamePattern);
      }
      if ($$self.$$.dirty[0] & /*subDirectoryAvailable*/
      64) {
        $$invalidate(11, directoryPlaceholder = subDirectoryAvailable ? t("setting.save_to.placeholder.sub_directory_unused") : env.isViolentmonkey() ? t("setting.save_to.placeholder.vm_not_supported") : t("setting.save_to.placeholder.need_browser_api"));
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      descritionText,
      sectionSpace,
      sectionTitle,
      templates,
      directory,
      filename,
      subDirectoryAvailable,
      $store,
      directoryRef,
      filenameRef,
      fsaDirectory,
      directoryPlaceholder,
      filenameBtnDisabled,
      folderBtnDisabled,
      ulClasses,
      updateDirectory,
      updateFilename,
      resetFolder,
      resetFilename,
      updatefsaDir,
      insertDirTemplateAtCursor,
      insertFilenameTemplateAtCursor,
      bg,
      border,
      padding,
      margin,
      rounded,
      input_binding,
      input_input_handler,
      slidetoggle_checked_binding,
      radioitem0_group_binding,
      radioitem1_group_binding,
      radioitem2_group_binding,
      input_binding_1,
      input_input_handler_1,
      radioitem0_group_binding_1,
      radioitem1_group_binding_1,
      radioitem2_group_binding_1,
      radioitem3_group_binding
    ];
  }
  class SaveTo extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$8,
        create_fragment$8,
        safe_not_equal,
        {
          bg: 22,
          border: 23,
          padding: 24,
          margin: 25,
          rounded: 26,
          descritionText: 0,
          sectionSpace: 1,
          sectionTitle: 2,
          templates: 3
        },
        null,
        [-1, -1]
      );
    }
  }
  const nonNegativeInt = (node, params) => {
    if (!(node instanceof HTMLInputElement) || node.type !== "number")
      throw new Error('Node should be an HTMLInputElement with a `type` of "number".');
    const resetStore = (newVal) => {
      if ("key" in params) {
        const { key, store } = params;
        store.update((currentVal) => {
          if (typeof newVal === "number") {
            return { ...currentVal, [key]: newVal };
          } else {
            return currentVal;
          }
        });
      } else {
        params.update((currentVal) => {
          if (typeof newVal === "number") {
            if (currentVal === newVal) {
              node.value = "" + newVal;
            }
            return newVal;
          } else {
            const nodeValToNumber = node.value === "" ? null : +node.value;
            nodeValToNumber !== currentVal && (node.value = typeof currentVal === "number" ? "" + currentVal : "");
            return currentVal;
          }
        });
      }
    };
    node.addEventListener("input", (evt) => {
      const el = evt.currentTarget;
      const { min, max: max2, value } = el;
      const minVal = min === "" ? 0 : +min;
      const maxVal = max2 === "" ? null : +max2;
      if (!el.checkValidity()) {
        if (/^[0-9]+$/.test(value)) {
          const numVal = +value;
          if (numVal < minVal) {
            resetStore(minVal);
          } else if (maxVal && numVal > maxVal) {
            resetStore(maxVal);
          }
        } else {
          resetStore();
        }
      }
    });
    node.addEventListener("blur", (evt) => {
      const el = evt.currentTarget;
      const { min, value } = el;
      const minVal = min === "" ? 0 : +min;
      if (value === "") {
        resetStore(minVal);
      }
    });
    return {};
  };
  function get_each_context$2(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[27] = list[i];
    return child_ctx;
  }
  function get_each_context_1$1(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[27] = list[i];
    return child_ctx;
  }
  function create_default_slot_6$1(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("Zip");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_5$1(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("Webm");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_4$1(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("Mp4");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_3$3(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("Webp");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_2$3(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("Gif");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_1$3(ctx) {
    let t_1;
    return {
      c() {
        t_1 = text("Png");
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot$4(ctx) {
    let radioitem0;
    let updating_group;
    let t0;
    let radioitem1;
    let updating_group_1;
    let t1;
    let radioitem2;
    let updating_group_2;
    let t2;
    let radioitem3;
    let updating_group_3;
    let t3;
    let radioitem4;
    let updating_group_4;
    let t4;
    let radioitem5;
    let updating_group_5;
    let current;
    function radioitem0_group_binding(value) {
      ctx[13](value);
    }
    let radioitem0_props = {
      name: "ugoiraFormat",
      class: "text-sm",
      value: UgoiraFormat.ZIP,
      $$slots: { default: [create_default_slot_6$1] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].ugoiraFormat !== void 0
    ) {
      radioitem0_props.group = /*$store*/
      ctx[7].ugoiraFormat;
    }
    radioitem0 = new RadioItem({ props: radioitem0_props });
    binding_callbacks.push(() => bind(radioitem0, "group", radioitem0_group_binding));
    function radioitem1_group_binding(value) {
      ctx[14](value);
    }
    let radioitem1_props = {
      name: "ugoiraFormat",
      class: "text-sm",
      value: UgoiraFormat.WEBM,
      $$slots: { default: [create_default_slot_5$1] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].ugoiraFormat !== void 0
    ) {
      radioitem1_props.group = /*$store*/
      ctx[7].ugoiraFormat;
    }
    radioitem1 = new RadioItem({ props: radioitem1_props });
    binding_callbacks.push(() => bind(radioitem1, "group", radioitem1_group_binding));
    function radioitem2_group_binding(value) {
      ctx[15](value);
    }
    let radioitem2_props = {
      disabled: !env.videoFrameSupported(),
      class: "text-sm",
      name: "ugoiraFormat",
      value: UgoiraFormat.MP4,
      $$slots: { default: [create_default_slot_4$1] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].ugoiraFormat !== void 0
    ) {
      radioitem2_props.group = /*$store*/
      ctx[7].ugoiraFormat;
    }
    radioitem2 = new RadioItem({ props: radioitem2_props });
    binding_callbacks.push(() => bind(radioitem2, "group", radioitem2_group_binding));
    function radioitem3_group_binding(value) {
      ctx[16](value);
    }
    let radioitem3_props = {
      name: "ugoiraFormat",
      class: "text-sm",
      value: UgoiraFormat.WEBP,
      $$slots: { default: [create_default_slot_3$3] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].ugoiraFormat !== void 0
    ) {
      radioitem3_props.group = /*$store*/
      ctx[7].ugoiraFormat;
    }
    radioitem3 = new RadioItem({ props: radioitem3_props });
    binding_callbacks.push(() => bind(radioitem3, "group", radioitem3_group_binding));
    function radioitem4_group_binding(value) {
      ctx[17](value);
    }
    let radioitem4_props = {
      name: "ugoiraFormat",
      class: "text-sm",
      value: UgoiraFormat.GIF,
      $$slots: { default: [create_default_slot_2$3] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].ugoiraFormat !== void 0
    ) {
      radioitem4_props.group = /*$store*/
      ctx[7].ugoiraFormat;
    }
    radioitem4 = new RadioItem({ props: radioitem4_props });
    binding_callbacks.push(() => bind(radioitem4, "group", radioitem4_group_binding));
    function radioitem5_group_binding(value) {
      ctx[18](value);
    }
    let radioitem5_props = {
      name: "ugoiraFormat",
      class: "text-sm",
      value: UgoiraFormat.PNG,
      $$slots: { default: [create_default_slot_1$3] },
      $$scope: { ctx }
    };
    if (
      /*$store*/
      ctx[7].ugoiraFormat !== void 0
    ) {
      radioitem5_props.group = /*$store*/
      ctx[7].ugoiraFormat;
    }
    radioitem5 = new RadioItem({ props: radioitem5_props });
    binding_callbacks.push(() => bind(radioitem5, "group", radioitem5_group_binding));
    return {
      c() {
        create_component(radioitem0.$$.fragment);
        t0 = space();
        create_component(radioitem1.$$.fragment);
        t1 = space();
        create_component(radioitem2.$$.fragment);
        t2 = space();
        create_component(radioitem3.$$.fragment);
        t3 = space();
        create_component(radioitem4.$$.fragment);
        t4 = space();
        create_component(radioitem5.$$.fragment);
      },
      m(target, anchor) {
        mount_component(radioitem0, target, anchor);
        insert(target, t0, anchor);
        mount_component(radioitem1, target, anchor);
        insert(target, t1, anchor);
        mount_component(radioitem2, target, anchor);
        insert(target, t2, anchor);
        mount_component(radioitem3, target, anchor);
        insert(target, t3, anchor);
        mount_component(radioitem4, target, anchor);
        insert(target, t4, anchor);
        mount_component(radioitem5, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const radioitem0_changes = {};
        if (dirty[1] & /*$$scope*/
        2) {
          radioitem0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty[0] & /*$store*/
        128) {
          updating_group = true;
          radioitem0_changes.group = /*$store*/
          ctx2[7].ugoiraFormat;
          add_flush_callback(() => updating_group = false);
        }
        radioitem0.$set(radioitem0_changes);
        const radioitem1_changes = {};
        if (dirty[1] & /*$$scope*/
        2) {
          radioitem1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_1 && dirty[0] & /*$store*/
        128) {
          updating_group_1 = true;
          radioitem1_changes.group = /*$store*/
          ctx2[7].ugoiraFormat;
          add_flush_callback(() => updating_group_1 = false);
        }
        radioitem1.$set(radioitem1_changes);
        const radioitem2_changes = {};
        if (dirty[1] & /*$$scope*/
        2) {
          radioitem2_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_2 && dirty[0] & /*$store*/
        128) {
          updating_group_2 = true;
          radioitem2_changes.group = /*$store*/
          ctx2[7].ugoiraFormat;
          add_flush_callback(() => updating_group_2 = false);
        }
        radioitem2.$set(radioitem2_changes);
        const radioitem3_changes = {};
        if (dirty[1] & /*$$scope*/
        2) {
          radioitem3_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_3 && dirty[0] & /*$store*/
        128) {
          updating_group_3 = true;
          radioitem3_changes.group = /*$store*/
          ctx2[7].ugoiraFormat;
          add_flush_callback(() => updating_group_3 = false);
        }
        radioitem3.$set(radioitem3_changes);
        const radioitem4_changes = {};
        if (dirty[1] & /*$$scope*/
        2) {
          radioitem4_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_4 && dirty[0] & /*$store*/
        128) {
          updating_group_4 = true;
          radioitem4_changes.group = /*$store*/
          ctx2[7].ugoiraFormat;
          add_flush_callback(() => updating_group_4 = false);
        }
        radioitem4.$set(radioitem4_changes);
        const radioitem5_changes = {};
        if (dirty[1] & /*$$scope*/
        2) {
          radioitem5_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_5 && dirty[0] & /*$store*/
        128) {
          updating_group_5 = true;
          radioitem5_changes.group = /*$store*/
          ctx2[7].ugoiraFormat;
          add_flush_callback(() => updating_group_5 = false);
        }
        radioitem5.$set(radioitem5_changes);
      },
      i(local) {
        if (current) return;
        transition_in(radioitem0.$$.fragment, local);
        transition_in(radioitem1.$$.fragment, local);
        transition_in(radioitem2.$$.fragment, local);
        transition_in(radioitem3.$$.fragment, local);
        transition_in(radioitem4.$$.fragment, local);
        transition_in(radioitem5.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radioitem0.$$.fragment, local);
        transition_out(radioitem1.$$.fragment, local);
        transition_out(radioitem2.$$.fragment, local);
        transition_out(radioitem3.$$.fragment, local);
        transition_out(radioitem4.$$.fragment, local);
        transition_out(radioitem5.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t0);
          detach(t1);
          detach(t2);
          detach(t3);
          detach(t4);
        }
        destroy_component(radioitem0, detaching);
        destroy_component(radioitem1, detaching);
        destroy_component(radioitem2, detaching);
        destroy_component(radioitem3, detaching);
        destroy_component(radioitem4, detaching);
        destroy_component(radioitem5, detaching);
      }
    };
  }
  function create_each_block_1$1(ctx) {
    let option;
    let t_1_value = (
      /*quality*/
      ctx[27] + ""
    );
    let t_1;
    return {
      c() {
        option = element("option");
        t_1 = text(t_1_value);
        option.__value = /*quality*/
        ctx[27];
        set_input_value(option, option.__value);
      },
      m(target, anchor) {
        insert(target, option, anchor);
        append(option, t_1);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(option);
        }
      }
    };
  }
  function create_each_block$2(ctx) {
    let option;
    let t_1_value = (
      /*quality*/
      ctx[27] + 1 + ""
    );
    let t_1;
    return {
      c() {
        option = element("option");
        t_1 = text(t_1_value);
        option.__value = /*quality*/
        ctx[27] + 1;
        set_input_value(option, option.__value);
      },
      m(target, anchor) {
        insert(target, option, anchor);
        append(option, t_1);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(option);
        }
      }
    };
  }
  function create_fragment$7(ctx) {
    let div6;
    let section0;
    let p0;
    let t0_value = t("setting.ugoira.label.format") + "";
    let t0;
    let t1;
    let ul0;
    let li0;
    let p1;
    let t3;
    let radiogroup;
    let t4;
    let section1;
    let p2;
    let t5_value = t("setting.ugoira.label.quality") + "";
    let t5;
    let t6;
    let ul2;
    let li1;
    let div0;
    let p3;
    let t8;
    let p4;
    let t9_value = t("setting.ugoira.options.webm_tips") + "";
    let t9;
    let t10;
    let input0;
    let input0_class_value;
    let t11;
    let li2;
    let div1;
    let p5;
    let t13;
    let p6;
    let t14;
    let t15;
    let input1;
    let input1_class_value;
    let t16;
    let li6;
    let p7;
    let t18;
    let ul1;
    let li3;
    let p8;
    let t20;
    let slidetoggle;
    let updating_checked;
    let t21;
    let li4;
    let div2;
    let p9;
    let t23;
    let p10;
    let t24_value = t("setting.ugoira.options.webp_quality_tips") + "";
    let t24;
    let t25;
    let input2;
    let input2_class_value;
    let t26;
    let li5;
    let div3;
    let p11;
    let t28;
    let p12;
    let t29_value = t("setting.ugoira.options.webp_method_tips") + "";
    let t29;
    let t30;
    let select0;
    let select0_class_value;
    let ul1_class_value;
    let t31;
    let li7;
    let div4;
    let p13;
    let t33;
    let p14;
    let t34_value = t("setting.ugoira.options.gif_tips") + "";
    let t34;
    let t35;
    let select1;
    let select1_class_value;
    let t36;
    let li8;
    let div5;
    let p15;
    let t38;
    let p16;
    let t39_value = t("setting.ugoira.options.png_tips") + "";
    let t39;
    let t40;
    let input3;
    let input3_class_value;
    let current;
    let mounted;
    let dispose;
    radiogroup = new RadioGroup({
      props: {
        class: "shrink-0",
        $$slots: { default: [create_default_slot$4] },
        $$scope: { ctx }
      }
    });
    function slidetoggle_checked_binding(value) {
      ctx[21](value);
    }
    let slidetoggle_props = { name: "lossless-webp", size: "sm" };
    if (
      /*$store*/
      ctx[7].losslessWebp !== void 0
    ) {
      slidetoggle_props.checked = /*$store*/
      ctx[7].losslessWebp;
    }
    slidetoggle = new SlideToggle({ props: slidetoggle_props });
    binding_callbacks.push(() => bind(slidetoggle, "checked", slidetoggle_checked_binding));
    let each_value_1 = ensure_array_like(Array.from({ length: 7 }, func));
    let each_blocks_1 = [];
    for (let i = 0; i < each_value_1.length; i += 1) {
      each_blocks_1[i] = create_each_block_1$1(get_each_context_1$1(ctx, each_value_1, i));
    }
    let each_value = ensure_array_like(Array.from({ length: 20 }, func_1));
    let each_blocks = [];
    for (let i = 0; i < each_value.length; i += 1) {
      each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i));
    }
    return {
      c() {
        div6 = element("div");
        section0 = element("section");
        p0 = element("p");
        t0 = text(t0_value);
        t1 = space();
        ul0 = element("ul");
        li0 = element("li");
        p1 = element("p");
        p1.textContent = `${t("setting.ugoira.options.select_format")}`;
        t3 = space();
        create_component(radiogroup.$$.fragment);
        t4 = space();
        section1 = element("section");
        p2 = element("p");
        t5 = text(t5_value);
        t6 = space();
        ul2 = element("ul");
        li1 = element("li");
        div0 = element("div");
        p3 = element("p");
        p3.textContent = "Webm";
        t8 = space();
        p4 = element("p");
        t9 = text(t9_value);
        t10 = space();
        input0 = element("input");
        t11 = space();
        li2 = element("li");
        div1 = element("div");
        p5 = element("p");
        p5.textContent = "Mp4";
        t13 = space();
        p6 = element("p");
        t14 = text("Bitrate (Mbps)");
        t15 = space();
        input1 = element("input");
        t16 = space();
        li6 = element("li");
        p7 = element("p");
        p7.textContent = "Webp";
        t18 = space();
        ul1 = element("ul");
        li3 = element("li");
        p8 = element("p");
        p8.textContent = `${t("setting.ugoira.options.webp_lossy")}`;
        t20 = space();
        create_component(slidetoggle.$$.fragment);
        t21 = space();
        li4 = element("li");
        div2 = element("div");
        p9 = element("p");
        p9.textContent = `${t("setting.ugoira.options.webp_quality")}`;
        t23 = space();
        p10 = element("p");
        t24 = text(t24_value);
        t25 = space();
        input2 = element("input");
        t26 = space();
        li5 = element("li");
        div3 = element("div");
        p11 = element("p");
        p11.textContent = `${t("setting.ugoira.options.webp_method")}`;
        t28 = space();
        p12 = element("p");
        t29 = text(t29_value);
        t30 = space();
        select0 = element("select");
        for (let i = 0; i < each_blocks_1.length; i += 1) {
          each_blocks_1[i].c();
        }
        t31 = space();
        li7 = element("li");
        div4 = element("div");
        p13 = element("p");
        p13.textContent = "Gif";
        t33 = space();
        p14 = element("p");
        t34 = text(t34_value);
        t35 = space();
        select1 = element("select");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        t36 = space();
        li8 = element("li");
        div5 = element("div");
        p15 = element("p");
        p15.textContent = "Png";
        t38 = space();
        p16 = element("p");
        t39 = text(t39_value);
        t40 = space();
        input3 = element("input");
        attr(
          p0,
          "class",
          /*sectionTitle*/
          ctx[4]
        );
        attr(p1, "class", "flex-auto");
        attr(
          ul0,
          "class",
          /*ulClasses*/
          ctx[6]
        );
        attr(
          p2,
          "class",
          /*sectionTitle*/
          ctx[4]
        );
        attr(
          p4,
          "class",
          /*descriptionText*/
          ctx[2]
        );
        attr(div0, "class", "flex-auto");
        attr(input0, "type", "number");
        attr(input0, "class", input0_class_value = "input " + /*inputClasses*/
        ctx[5]);
        attr(input0, "min", "0");
        attr(input0, "max", "99");
        attr(input0, "step", "1");
        attr(
          p6,
          "class",
          /*descriptionText*/
          ctx[2]
        );
        attr(div1, "class", "flex-auto");
        attr(input1, "type", "number");
        attr(input1, "class", input1_class_value = "input " + /*inputClasses*/
        ctx[5]);
        attr(input1, "min", "1");
        attr(input1, "max", "99");
        attr(input1, "step", "1");
        attr(p8, "class", "flex-auto");
        attr(li3, "class", "items-center");
        attr(
          p10,
          "class",
          /*descriptionText*/
          ctx[2]
        );
        attr(div2, "class", "flex-auto");
        attr(input2, "type", "number");
        attr(input2, "class", input2_class_value = "input " + /*inputClasses*/
        ctx[5]);
        attr(input2, "min", "0");
        attr(input2, "max", "100");
        attr(input2, "step", "1");
        attr(li4, "class", "items-center");
        attr(
          p12,
          "class",
          /*descriptionText*/
          ctx[2]
        );
        attr(div3, "class", "flex-auto");
        attr(select0, "class", select0_class_value = "select " + /*inputClasses*/
        ctx[5]);
        if (
          /*$store*/
          ctx[7].webpMehtod === void 0
        ) add_render_callback(() => (
          /*select0_change_handler*/
          ctx[23].call(select0)
        ));
        attr(li5, "class", "items-center");
        attr(ul1, "class", ul1_class_value = "list " + /*border*/
        ctx[0] + " " + /*rounded*/
        ctx[1] + " [&:not(:last-child)]:*:py-4 [&:last-child]:*:pt-4");
        attr(li6, "class", "flex-col !items-stretch");
        attr(
          p14,
          "class",
          /*descriptionText*/
          ctx[2]
        );
        attr(div4, "class", "flex-auto");
        attr(select1, "class", select1_class_value = "select " + /*inputClasses*/
        ctx[5]);
        if (
          /*$store*/
          ctx[7].gifQuality === void 0
        ) add_render_callback(() => (
          /*select1_change_handler*/
          ctx[24].call(select1)
        ));
        attr(
          p16,
          "class",
          /*descriptionText*/
          ctx[2]
        );
        attr(div5, "class", "flex-auto");
        attr(input3, "type", "number");
        attr(input3, "class", input3_class_value = "input " + /*inputClasses*/
        ctx[5]);
        attr(input3, "min", "0");
        attr(input3, "max", "256");
        attr(input3, "step", "1");
        attr(
          ul2,
          "class",
          /*ulClasses*/
          ctx[6]
        );
        attr(
          div6,
          "class",
          /*sectionSpace*/
          ctx[3]
        );
      },
      m(target, anchor) {
        insert(target, div6, anchor);
        append(div6, section0);
        append(section0, p0);
        append(p0, t0);
        append(section0, t1);
        append(section0, ul0);
        append(ul0, li0);
        append(li0, p1);
        append(li0, t3);
        mount_component(radiogroup, li0, null);
        append(div6, t4);
        append(div6, section1);
        append(section1, p2);
        append(p2, t5);
        append(section1, t6);
        append(section1, ul2);
        append(ul2, li1);
        append(li1, div0);
        append(div0, p3);
        append(div0, t8);
        append(div0, p4);
        append(p4, t9);
        append(li1, t10);
        append(li1, input0);
        set_input_value(
          input0,
          /*$store*/
          ctx[7].webmQuality
        );
        append(ul2, t11);
        append(ul2, li2);
        append(li2, div1);
        append(div1, p5);
        append(div1, t13);
        append(div1, p6);
        append(p6, t14);
        append(li2, t15);
        append(li2, input1);
        set_input_value(
          input1,
          /*$store*/
          ctx[7].mp4Bitrate
        );
        append(ul2, t16);
        append(ul2, li6);
        append(li6, p7);
        append(li6, t18);
        append(li6, ul1);
        append(ul1, li3);
        append(li3, p8);
        append(li3, t20);
        mount_component(slidetoggle, li3, null);
        append(ul1, t21);
        append(ul1, li4);
        append(li4, div2);
        append(div2, p9);
        append(div2, t23);
        append(div2, p10);
        append(p10, t24);
        append(li4, t25);
        append(li4, input2);
        set_input_value(
          input2,
          /*$store*/
          ctx[7].webpQuality
        );
        append(ul1, t26);
        append(ul1, li5);
        append(li5, div3);
        append(div3, p11);
        append(div3, t28);
        append(div3, p12);
        append(p12, t29);
        append(li5, t30);
        append(li5, select0);
        for (let i = 0; i < each_blocks_1.length; i += 1) {
          if (each_blocks_1[i]) {
            each_blocks_1[i].m(select0, null);
          }
        }
        select_option(
          select0,
          /*$store*/
          ctx[7].webpMehtod,
          true
        );
        append(ul2, t31);
        append(ul2, li7);
        append(li7, div4);
        append(div4, p13);
        append(div4, t33);
        append(div4, p14);
        append(p14, t34);
        append(li7, t35);
        append(li7, select1);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(select1, null);
          }
        }
        select_option(
          select1,
          /*$store*/
          ctx[7].gifQuality,
          true
        );
        append(ul2, t36);
        append(ul2, li8);
        append(li8, div5);
        append(div5, p15);
        append(div5, t38);
        append(div5, p16);
        append(p16, t39);
        append(li8, t40);
        append(li8, input3);
        set_input_value(
          input3,
          /*$store*/
          ctx[7].pngColor
        );
        current = true;
        if (!mounted) {
          dispose = [
            action_destroyer(nonNegativeInt.call(null, input0, { store: configStore, key: "webmQuality" })),
            listen(
              input0,
              "input",
              /*input0_input_handler*/
              ctx[19]
            ),
            action_destroyer(nonNegativeInt.call(null, input1, { store: configStore, key: "mp4Bitrate" })),
            listen(
              input1,
              "input",
              /*input1_input_handler*/
              ctx[20]
            ),
            action_destroyer(nonNegativeInt.call(null, input2, { store: configStore, key: "webpQuality" })),
            listen(
              input2,
              "input",
              /*input2_input_handler*/
              ctx[22]
            ),
            listen(
              select0,
              "change",
              /*select0_change_handler*/
              ctx[23]
            ),
            listen(
              select1,
              "change",
              /*select1_change_handler*/
              ctx[24]
            ),
            action_destroyer(nonNegativeInt.call(null, input3, { store: configStore, key: "pngColor" })),
            listen(
              input3,
              "input",
              /*input3_input_handler*/
              ctx[25]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (!current || dirty[0] & /*sectionTitle*/
        16) {
          attr(
            p0,
            "class",
            /*sectionTitle*/
            ctx2[4]
          );
        }
        const radiogroup_changes = {};
        if (dirty[0] & /*$store*/
        128 | dirty[1] & /*$$scope*/
        2) {
          radiogroup_changes.$$scope = { dirty, ctx: ctx2 };
        }
        radiogroup.$set(radiogroup_changes);
        if (!current || dirty[0] & /*ulClasses*/
        64) {
          attr(
            ul0,
            "class",
            /*ulClasses*/
            ctx2[6]
          );
        }
        if (!current || dirty[0] & /*sectionTitle*/
        16) {
          attr(
            p2,
            "class",
            /*sectionTitle*/
            ctx2[4]
          );
        }
        if (!current || dirty[0] & /*descriptionText*/
        4) {
          attr(
            p4,
            "class",
            /*descriptionText*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*inputClasses*/
        32 && input0_class_value !== (input0_class_value = "input " + /*inputClasses*/
        ctx2[5])) {
          attr(input0, "class", input0_class_value);
        }
        if (dirty[0] & /*$store*/
        128 && to_number(input0.value) !== /*$store*/
        ctx2[7].webmQuality) {
          set_input_value(
            input0,
            /*$store*/
            ctx2[7].webmQuality
          );
        }
        if (!current || dirty[0] & /*descriptionText*/
        4) {
          attr(
            p6,
            "class",
            /*descriptionText*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*inputClasses*/
        32 && input1_class_value !== (input1_class_value = "input " + /*inputClasses*/
        ctx2[5])) {
          attr(input1, "class", input1_class_value);
        }
        if (dirty[0] & /*$store*/
        128 && to_number(input1.value) !== /*$store*/
        ctx2[7].mp4Bitrate) {
          set_input_value(
            input1,
            /*$store*/
            ctx2[7].mp4Bitrate
          );
        }
        const slidetoggle_changes = {};
        if (!updating_checked && dirty[0] & /*$store*/
        128) {
          updating_checked = true;
          slidetoggle_changes.checked = /*$store*/
          ctx2[7].losslessWebp;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle.$set(slidetoggle_changes);
        if (!current || dirty[0] & /*descriptionText*/
        4) {
          attr(
            p10,
            "class",
            /*descriptionText*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*inputClasses*/
        32 && input2_class_value !== (input2_class_value = "input " + /*inputClasses*/
        ctx2[5])) {
          attr(input2, "class", input2_class_value);
        }
        if (dirty[0] & /*$store*/
        128 && to_number(input2.value) !== /*$store*/
        ctx2[7].webpQuality) {
          set_input_value(
            input2,
            /*$store*/
            ctx2[7].webpQuality
          );
        }
        if (!current || dirty[0] & /*descriptionText*/
        4) {
          attr(
            p12,
            "class",
            /*descriptionText*/
            ctx2[2]
          );
        }
        if (dirty & /*Array*/
        0) {
          each_value_1 = ensure_array_like(Array.from({ length: 7 }, func));
          let i;
          for (i = 0; i < each_value_1.length; i += 1) {
            const child_ctx = get_each_context_1$1(ctx2, each_value_1, i);
            if (each_blocks_1[i]) {
              each_blocks_1[i].p(child_ctx, dirty);
            } else {
              each_blocks_1[i] = create_each_block_1$1(child_ctx);
              each_blocks_1[i].c();
              each_blocks_1[i].m(select0, null);
            }
          }
          for (; i < each_blocks_1.length; i += 1) {
            each_blocks_1[i].d(1);
          }
          each_blocks_1.length = each_value_1.length;
        }
        if (!current || dirty[0] & /*inputClasses*/
        32 && select0_class_value !== (select0_class_value = "select " + /*inputClasses*/
        ctx2[5])) {
          attr(select0, "class", select0_class_value);
        }
        if (dirty[0] & /*$store*/
        128) {
          select_option(
            select0,
            /*$store*/
            ctx2[7].webpMehtod
          );
        }
        if (!current || dirty[0] & /*border, rounded*/
        3 && ul1_class_value !== (ul1_class_value = "list " + /*border*/
        ctx2[0] + " " + /*rounded*/
        ctx2[1] + " [&:not(:last-child)]:*:py-4 [&:last-child]:*:pt-4")) {
          attr(ul1, "class", ul1_class_value);
        }
        if (!current || dirty[0] & /*descriptionText*/
        4) {
          attr(
            p14,
            "class",
            /*descriptionText*/
            ctx2[2]
          );
        }
        if (dirty & /*Array*/
        0) {
          each_value = ensure_array_like(Array.from({ length: 20 }, func_1));
          let i;
          for (i = 0; i < each_value.length; i += 1) {
            const child_ctx = get_each_context$2(ctx2, each_value, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
            } else {
              each_blocks[i] = create_each_block$2(child_ctx);
              each_blocks[i].c();
              each_blocks[i].m(select1, null);
            }
          }
          for (; i < each_blocks.length; i += 1) {
            each_blocks[i].d(1);
          }
          each_blocks.length = each_value.length;
        }
        if (!current || dirty[0] & /*inputClasses*/
        32 && select1_class_value !== (select1_class_value = "select " + /*inputClasses*/
        ctx2[5])) {
          attr(select1, "class", select1_class_value);
        }
        if (dirty[0] & /*$store*/
        128) {
          select_option(
            select1,
            /*$store*/
            ctx2[7].gifQuality
          );
        }
        if (!current || dirty[0] & /*descriptionText*/
        4) {
          attr(
            p16,
            "class",
            /*descriptionText*/
            ctx2[2]
          );
        }
        if (!current || dirty[0] & /*inputClasses*/
        32 && input3_class_value !== (input3_class_value = "input " + /*inputClasses*/
        ctx2[5])) {
          attr(input3, "class", input3_class_value);
        }
        if (dirty[0] & /*$store*/
        128 && to_number(input3.value) !== /*$store*/
        ctx2[7].pngColor) {
          set_input_value(
            input3,
            /*$store*/
            ctx2[7].pngColor
          );
        }
        if (!current || dirty[0] & /*ulClasses*/
        64) {
          attr(
            ul2,
            "class",
            /*ulClasses*/
            ctx2[6]
          );
        }
        if (!current || dirty[0] & /*sectionSpace*/
        8) {
          attr(
            div6,
            "class",
            /*sectionSpace*/
            ctx2[3]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(radiogroup.$$.fragment, local);
        transition_in(slidetoggle.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radiogroup.$$.fragment, local);
        transition_out(slidetoggle.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div6);
        }
        destroy_component(radiogroup);
        destroy_component(slidetoggle);
        destroy_each(each_blocks_1, detaching);
        destroy_each(each_blocks, detaching);
        mounted = false;
        run_all(dispose);
      }
    };
  }
  const func = (_, idx) => idx;
  const func_1 = (_, idx) => idx;
  function instance$7($$self, $$props, $$invalidate) {
    let ulClasses;
    let inputClasses;
    let $store;
    component_subscribe($$self, configStore, ($$value) => $$invalidate(7, $store = $$value));
    let { bg = "bg-white/30 dark:bg-black/15" } = $$props;
    let { border = "divide-y-[1px] *:border-surface-300-600-token" } = $$props;
    let { padding = "px-4 *:py-4" } = $$props;
    let { margin = "mt-2 *:!m-0" } = $$props;
    let { rounded = "rounded-container-token *:!rounded-none" } = $$props;
    let { descriptionText = "text-sm text-surface-400" } = $$props;
    let { inputRounded = "rounded-full" } = $$props;
    let { inputWidth = "w-32" } = $$props;
    let { sectionSpace = `space-y-4` } = $$props;
    let { sectionTitle = "font-bold" } = $$props;
    function radioitem0_group_binding(value) {
      if ($$self.$$.not_equal($store.ugoiraFormat, value)) {
        $store.ugoiraFormat = value;
        configStore.set($store);
      }
    }
    function radioitem1_group_binding(value) {
      if ($$self.$$.not_equal($store.ugoiraFormat, value)) {
        $store.ugoiraFormat = value;
        configStore.set($store);
      }
    }
    function radioitem2_group_binding(value) {
      if ($$self.$$.not_equal($store.ugoiraFormat, value)) {
        $store.ugoiraFormat = value;
        configStore.set($store);
      }
    }
    function radioitem3_group_binding(value) {
      if ($$self.$$.not_equal($store.ugoiraFormat, value)) {
        $store.ugoiraFormat = value;
        configStore.set($store);
      }
    }
    function radioitem4_group_binding(value) {
      if ($$self.$$.not_equal($store.ugoiraFormat, value)) {
        $store.ugoiraFormat = value;
        configStore.set($store);
      }
    }
    function radioitem5_group_binding(value) {
      if ($$self.$$.not_equal($store.ugoiraFormat, value)) {
        $store.ugoiraFormat = value;
        configStore.set($store);
      }
    }
    function input0_input_handler() {
      $store.webmQuality = to_number(this.value);
      configStore.set($store);
    }
    function input1_input_handler() {
      $store.mp4Bitrate = to_number(this.value);
      configStore.set($store);
    }
    function slidetoggle_checked_binding(value) {
      if ($$self.$$.not_equal($store.losslessWebp, value)) {
        $store.losslessWebp = value;
        configStore.set($store);
      }
    }
    function input2_input_handler() {
      $store.webpQuality = to_number(this.value);
      configStore.set($store);
    }
    function select0_change_handler() {
      $store.webpMehtod = select_value(this);
      configStore.set($store);
    }
    function select1_change_handler() {
      $store.gifQuality = select_value(this);
      configStore.set($store);
    }
    function input3_input_handler() {
      $store.pngColor = to_number(this.value);
      configStore.set($store);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(26, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("bg" in $$new_props) $$invalidate(8, bg = $$new_props.bg);
      if ("border" in $$new_props) $$invalidate(0, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(9, padding = $$new_props.padding);
      if ("margin" in $$new_props) $$invalidate(10, margin = $$new_props.margin);
      if ("rounded" in $$new_props) $$invalidate(1, rounded = $$new_props.rounded);
      if ("descriptionText" in $$new_props) $$invalidate(2, descriptionText = $$new_props.descriptionText);
      if ("inputRounded" in $$new_props) $$invalidate(11, inputRounded = $$new_props.inputRounded);
      if ("inputWidth" in $$new_props) $$invalidate(12, inputWidth = $$new_props.inputWidth);
      if ("sectionSpace" in $$new_props) $$invalidate(3, sectionSpace = $$new_props.sectionSpace);
      if ("sectionTitle" in $$new_props) $$invalidate(4, sectionTitle = $$new_props.sectionTitle);
    };
    $$self.$$.update = () => {
      $$invalidate(6, ulClasses = `list *:items-center ${padding} ${margin} ${border} ${bg} ${rounded} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty[0] & /*inputWidth, inputRounded*/
      6144) {
        $$invalidate(5, inputClasses = `${inputWidth} ${inputRounded} shrink-0`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      border,
      rounded,
      descriptionText,
      sectionSpace,
      sectionTitle,
      inputClasses,
      ulClasses,
      $store,
      bg,
      padding,
      margin,
      inputRounded,
      inputWidth,
      radioitem0_group_binding,
      radioitem1_group_binding,
      radioitem2_group_binding,
      radioitem3_group_binding,
      radioitem4_group_binding,
      radioitem5_group_binding,
      input0_input_handler,
      input1_input_handler,
      slidetoggle_checked_binding,
      input2_input_handler,
      select0_change_handler,
      select1_change_handler,
      input3_input_handler
    ];
  }
  class UgoiraConvert extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$7,
        create_fragment$7,
        safe_not_equal,
        {
          bg: 8,
          border: 0,
          padding: 9,
          margin: 10,
          rounded: 1,
          descriptionText: 2,
          inputRounded: 11,
          inputWidth: 12,
          sectionSpace: 3,
          sectionTitle: 4
        },
        null,
        [-1, -1]
      );
    }
  }
  function readHistoryFile(type, file) {
    return new Promise((resolve) => {
      if (file.type !== type) throw new Error("Invalid file");
      const reader = new FileReader();
      reader.readAsText(file);
      reader.onload = (readEvt) => {
        var _a;
        const text2 = (_a = readEvt.target) == null ? void 0 : _a.result;
        if (typeof text2 !== "string") throw new Error("Invalid file");
        const history2 = JSON.parse(text2);
        if (!(history2 instanceof Array)) throw new Error("Invalid file");
        resolve(history2);
      };
    });
  }
  function importJSON(file) {
    return readHistoryFile("application/json", file).then((data) => historyDb.import(data));
  }
  function exportAsJSON() {
    return historyDb.getAll().then((datas) => {
      const str = JSON.stringify(datas);
      const blob = new Blob([str], { type: "application/json" });
      const filename = `Pixiv Downloader_${location.hostname}_${(/* @__PURE__ */ new Date()).toLocaleString()}.json`;
      aDownload$1(blob, filename);
    });
  }
  function exportAsCSV() {
    return historyDb.generateCsv().then((csv) => {
      const filename = `Pixiv Downloader_${location.hostname}_${(/* @__PURE__ */ new Date()).toLocaleString()}.csv`;
      aDownload$1(csv, filename);
    });
  }
  function scheduleBackup() {
    const interval = config.get("historyBackupInterval");
    if (interval === HistoryBackupInterval.NEVER) return;
    const lastTimestamp = config.get("lastHistoryBackup");
    const timestamp = (/* @__PURE__ */ new Date()).getTime();
    if (!lastTimestamp || lastTimestamp + interval * 1e3 < timestamp) {
      exportAsJSON();
      config.set("lastHistoryBackup", timestamp);
    }
  }
  function useHistoryBackup() {
    return {
      importJSON,
      exportAsJSON,
      exportAsCSV,
      scheduleBackup
    };
  }
  function create_if_block_3$2(ctx) {
    let progressradial;
    let current;
    progressradial = new ProgressRadial({
      props: {
        stroke: 80,
        width: "w-5",
        meter: "stroke-primary-500",
        track: "stroke-primary-500/30"
      }
    });
    return {
      c() {
        create_component(progressradial.$$.fragment);
      },
      m(target, anchor) {
        mount_component(progressradial, target, anchor);
        current = true;
      },
      i(local) {
        if (current) return;
        transition_in(progressradial.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(progressradial.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(progressradial, detaching);
      }
    };
  }
  function create_if_block_2$2(ctx) {
    let progressradial;
    let current;
    progressradial = new ProgressRadial({
      props: {
        stroke: 80,
        width: "w-5",
        meter: "stroke-primary-500",
        track: "stroke-primary-500/30"
      }
    });
    return {
      c() {
        create_component(progressradial.$$.fragment);
      },
      m(target, anchor) {
        mount_component(progressradial, target, anchor);
        current = true;
      },
      i(local) {
        if (current) return;
        transition_in(progressradial.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(progressradial.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(progressradial, detaching);
      }
    };
  }
  function create_if_block_1$4(ctx) {
    let progressradial;
    let current;
    progressradial = new ProgressRadial({
      props: {
        stroke: 80,
        width: "w-5",
        meter: "stroke-primary-500",
        track: "stroke-primary-500/30"
      }
    });
    return {
      c() {
        create_component(progressradial.$$.fragment);
      },
      m(target, anchor) {
        mount_component(progressradial, target, anchor);
        current = true;
      },
      i(local) {
        if (current) return;
        transition_in(progressradial.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(progressradial.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(progressradial, detaching);
      }
    };
  }
  function create_default_slot$3(ctx) {
    let t0;
    let span;
    let current;
    let if_block = (
      /*$importPending*/
      ctx[7] && create_if_block_1$4()
    );
    return {
      c() {
        if (if_block) if_block.c();
        t0 = space();
        span = element("span");
        span.textContent = `${t("setting.history.button.import")}`;
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, t0, anchor);
        insert(target, span, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        if (
          /*$importPending*/
          ctx2[7]
        ) {
          if (if_block) {
            if (dirty[0] & /*$importPending*/
            128) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block_1$4();
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(t0.parentNode, t0);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t0);
          detach(span);
        }
        if (if_block) if_block.d(detaching);
      }
    };
  }
  function create_if_block$5(ctx) {
    let progressradial;
    let current;
    progressradial = new ProgressRadial({
      props: {
        stroke: 80,
        width: "w-5",
        meter: "stroke-primary-500",
        track: "stroke-primary-500/30"
      }
    });
    return {
      c() {
        create_component(progressradial.$$.fragment);
      },
      m(target, anchor) {
        mount_component(progressradial, target, anchor);
        current = true;
      },
      i(local) {
        if (current) return;
        transition_in(progressradial.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(progressradial.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(progressradial, detaching);
      }
    };
  }
  function create_fragment$6(ctx) {
    let div;
    let section0;
    let p0;
    let t0_value = t("setting.history.label.scheduled_backups") + "";
    let t0;
    let t1;
    let ul0;
    let li0;
    let p1;
    let t3;
    let select;
    let option0;
    let option1;
    let option2;
    let option3;
    let select_class_value;
    let t8;
    let section1;
    let p2;
    let t9_value = t("setting.history.label.export") + "";
    let t9;
    let t10;
    let ul1;
    let li1;
    let p3;
    let t12;
    let button0;
    let t13;
    let span0;
    let t15;
    let li2;
    let p4;
    let t17;
    let button1;
    let t18;
    let span1;
    let t20;
    let section2;
    let p5;
    let t21_value = t("setting.history.label.import") + "";
    let t21;
    let t22;
    let ul2;
    let li3;
    let p6;
    let t24;
    let filebutton;
    let updating_disabled;
    let t25;
    let section3;
    let p7;
    let t26_value = t("setting.history.label.clear") + "";
    let t26;
    let t27;
    let ul3;
    let li4;
    let p8;
    let t29;
    let button2;
    let t30;
    let span2;
    let current;
    let mounted;
    let dispose;
    let if_block0 = (
      /*$exportJsonPending*/
      ctx[5] && create_if_block_3$2()
    );
    let if_block1 = (
      /*$exportCsvPending*/
      ctx[6] && create_if_block_2$2()
    );
    function filebutton_disabled_binding(value) {
      ctx[25](value);
    }
    let filebutton_props = {
      name: "import-file",
      accept: ".json",
      $$slots: { default: [create_default_slot$3] },
      $$scope: { ctx }
    };
    if (
      /*$importPending*/
      ctx[7] !== void 0
    ) {
      filebutton_props.disabled = /*$importPending*/
      ctx[7];
    }
    filebutton = new FileButton({ props: filebutton_props });
    binding_callbacks.push(() => bind(filebutton, "disabled", filebutton_disabled_binding));
    filebutton.$on(
      "change",
      /*wrapImportFromJSON*/
      ctx[10]
    );
    let if_block2 = (
      /*$clearPending*/
      ctx[8] && create_if_block$5()
    );
    return {
      c() {
        div = element("div");
        section0 = element("section");
        p0 = element("p");
        t0 = text(t0_value);
        t1 = space();
        ul0 = element("ul");
        li0 = element("li");
        p1 = element("p");
        p1.textContent = `${t("setting.history.options.scheduled_backups")}`;
        t3 = space();
        select = element("select");
        option0 = element("option");
        option0.textContent = `${t("setting.history.select.backup_interval_never")}`;
        option1 = element("option");
        option1.textContent = `${t("setting.history.select.backup_interval_every_day")}`;
        option2 = element("option");
        option2.textContent = `${t("setting.history.select.backup_interval_every_7_day")}`;
        option3 = element("option");
        option3.textContent = `${t("setting.history.select.backup_interval_every_30_day")}`;
        t8 = space();
        section1 = element("section");
        p2 = element("p");
        t9 = text(t9_value);
        t10 = space();
        ul1 = element("ul");
        li1 = element("li");
        p3 = element("p");
        p3.textContent = `${t("setting.history.options.export_as_json")}`;
        t12 = space();
        button0 = element("button");
        if (if_block0) if_block0.c();
        t13 = space();
        span0 = element("span");
        span0.textContent = `${t("setting.history.button.export")}`;
        t15 = space();
        li2 = element("li");
        p4 = element("p");
        p4.textContent = `${t("setting.history.options.export_as_csv")}`;
        t17 = space();
        button1 = element("button");
        if (if_block1) if_block1.c();
        t18 = space();
        span1 = element("span");
        span1.textContent = `${t("setting.history.button.export")}`;
        t20 = space();
        section2 = element("section");
        p5 = element("p");
        t21 = text(t21_value);
        t22 = space();
        ul2 = element("ul");
        li3 = element("li");
        p6 = element("p");
        p6.textContent = `${t("setting.history.options.import_json")}`;
        t24 = space();
        create_component(filebutton.$$.fragment);
        t25 = space();
        section3 = element("section");
        p7 = element("p");
        t26 = text(t26_value);
        t27 = space();
        ul3 = element("ul");
        li4 = element("li");
        p8 = element("p");
        p8.textContent = `${t("setting.history.options.clear_history")}`;
        t29 = space();
        button2 = element("button");
        if (if_block2) if_block2.c();
        t30 = space();
        span2 = element("span");
        span2.textContent = `${t("setting.history.button.clear")}`;
        attr(
          p0,
          "class",
          /*sectionTitle*/
          ctx[1]
        );
        attr(p1, "class", "flex-auto");
        option0.__value = HistoryBackupInterval.NEVER;
        set_input_value(option0, option0.__value);
        option1.__value = HistoryBackupInterval.EVERY_DAY;
        set_input_value(option1, option1.__value);
        option2.__value = HistoryBackupInterval.EVERY_7_DAY;
        set_input_value(option2, option2.__value);
        option3.__value = HistoryBackupInterval.EVERY_30_DAY;
        set_input_value(option3, option3.__value);
        attr(select, "class", select_class_value = "select " + /*inputClasses*/
        ctx[2]);
        if (
          /*$configStore*/
          ctx[4].historyBackupInterval === void 0
        ) add_render_callback(() => (
          /*select_change_handler*/
          ctx[24].call(select)
        ));
        attr(
          ul0,
          "class",
          /*ulClasses*/
          ctx[3]
        );
        attr(
          p2,
          "class",
          /*sectionTitle*/
          ctx[1]
        );
        attr(p3, "class", "flex-auto");
        button0.disabled = /*$exportJsonPending*/
        ctx[5];
        attr(button0, "class", "btn variant-filled");
        attr(p4, "class", "flex-auto");
        button1.disabled = /*$exportCsvPending*/
        ctx[6];
        attr(button1, "class", "btn variant-filled");
        attr(
          ul1,
          "class",
          /*ulClasses*/
          ctx[3]
        );
        attr(
          p5,
          "class",
          /*sectionTitle*/
          ctx[1]
        );
        attr(p6, "class", "flex-auto");
        attr(
          ul2,
          "class",
          /*ulClasses*/
          ctx[3]
        );
        attr(
          p7,
          "class",
          /*sectionTitle*/
          ctx[1]
        );
        attr(p8, "class", "flex-auto");
        button2.disabled = /*$clearPending*/
        ctx[8];
        attr(button2, "class", "btn variant-filled");
        attr(
          ul3,
          "class",
          /*ulClasses*/
          ctx[3]
        );
        attr(
          div,
          "class",
          /*sectionSpace*/
          ctx[0]
        );
      },
      m(target, anchor) {
        insert(target, div, anchor);
        append(div, section0);
        append(section0, p0);
        append(p0, t0);
        append(section0, t1);
        append(section0, ul0);
        append(ul0, li0);
        append(li0, p1);
        append(li0, t3);
        append(li0, select);
        append(select, option0);
        append(select, option1);
        append(select, option2);
        append(select, option3);
        select_option(
          select,
          /*$configStore*/
          ctx[4].historyBackupInterval,
          true
        );
        append(div, t8);
        append(div, section1);
        append(section1, p2);
        append(p2, t9);
        append(section1, t10);
        append(section1, ul1);
        append(ul1, li1);
        append(li1, p3);
        append(li1, t12);
        append(li1, button0);
        if (if_block0) if_block0.m(button0, null);
        append(button0, t13);
        append(button0, span0);
        append(ul1, t15);
        append(ul1, li2);
        append(li2, p4);
        append(li2, t17);
        append(li2, button1);
        if (if_block1) if_block1.m(button1, null);
        append(button1, t18);
        append(button1, span1);
        append(div, t20);
        append(div, section2);
        append(section2, p5);
        append(p5, t21);
        append(section2, t22);
        append(section2, ul2);
        append(ul2, li3);
        append(li3, p6);
        append(li3, t24);
        mount_component(filebutton, li3, null);
        append(div, t25);
        append(div, section3);
        append(section3, p7);
        append(p7, t26);
        append(section3, t27);
        append(section3, ul3);
        append(ul3, li4);
        append(li4, p8);
        append(li4, t29);
        append(li4, button2);
        if (if_block2) if_block2.m(button2, null);
        append(button2, t30);
        append(button2, span2);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              select,
              "change",
              /*select_change_handler*/
              ctx[24]
            ),
            listen(
              button0,
              "click",
              /*wrapExportAsJSON*/
              ctx[14]
            ),
            listen(
              button1,
              "click",
              /*wrapExportAsCSV*/
              ctx[16]
            ),
            listen(
              button2,
              "click",
              /*wrapClearDb*/
              ctx[12]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (!current || dirty[0] & /*sectionTitle*/
        2) {
          attr(
            p0,
            "class",
            /*sectionTitle*/
            ctx2[1]
          );
        }
        if (!current || dirty[0] & /*inputClasses*/
        4 && select_class_value !== (select_class_value = "select " + /*inputClasses*/
        ctx2[2])) {
          attr(select, "class", select_class_value);
        }
        if (dirty[0] & /*$configStore*/
        16) {
          select_option(
            select,
            /*$configStore*/
            ctx2[4].historyBackupInterval
          );
        }
        if (!current || dirty[0] & /*ulClasses*/
        8) {
          attr(
            ul0,
            "class",
            /*ulClasses*/
            ctx2[3]
          );
        }
        if (!current || dirty[0] & /*sectionTitle*/
        2) {
          attr(
            p2,
            "class",
            /*sectionTitle*/
            ctx2[1]
          );
        }
        if (
          /*$exportJsonPending*/
          ctx2[5]
        ) {
          if (if_block0) {
            if (dirty[0] & /*$exportJsonPending*/
            32) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_3$2();
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(button0, t13);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*$exportJsonPending*/
        32) {
          button0.disabled = /*$exportJsonPending*/
          ctx2[5];
        }
        if (
          /*$exportCsvPending*/
          ctx2[6]
        ) {
          if (if_block1) {
            if (dirty[0] & /*$exportCsvPending*/
            64) {
              transition_in(if_block1, 1);
            }
          } else {
            if_block1 = create_if_block_2$2();
            if_block1.c();
            transition_in(if_block1, 1);
            if_block1.m(button1, t18);
          }
        } else if (if_block1) {
          group_outros();
          transition_out(if_block1, 1, 1, () => {
            if_block1 = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*$exportCsvPending*/
        64) {
          button1.disabled = /*$exportCsvPending*/
          ctx2[6];
        }
        if (!current || dirty[0] & /*ulClasses*/
        8) {
          attr(
            ul1,
            "class",
            /*ulClasses*/
            ctx2[3]
          );
        }
        if (!current || dirty[0] & /*sectionTitle*/
        2) {
          attr(
            p5,
            "class",
            /*sectionTitle*/
            ctx2[1]
          );
        }
        const filebutton_changes = {};
        if (dirty[0] & /*$importPending*/
        128 | dirty[1] & /*$$scope*/
        4) {
          filebutton_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_disabled && dirty[0] & /*$importPending*/
        128) {
          updating_disabled = true;
          filebutton_changes.disabled = /*$importPending*/
          ctx2[7];
          add_flush_callback(() => updating_disabled = false);
        }
        filebutton.$set(filebutton_changes);
        if (!current || dirty[0] & /*ulClasses*/
        8) {
          attr(
            ul2,
            "class",
            /*ulClasses*/
            ctx2[3]
          );
        }
        if (!current || dirty[0] & /*sectionTitle*/
        2) {
          attr(
            p7,
            "class",
            /*sectionTitle*/
            ctx2[1]
          );
        }
        if (
          /*$clearPending*/
          ctx2[8]
        ) {
          if (if_block2) {
            if (dirty[0] & /*$clearPending*/
            256) {
              transition_in(if_block2, 1);
            }
          } else {
            if_block2 = create_if_block$5();
            if_block2.c();
            transition_in(if_block2, 1);
            if_block2.m(button2, t30);
          }
        } else if (if_block2) {
          group_outros();
          transition_out(if_block2, 1, 1, () => {
            if_block2 = null;
          });
          check_outros();
        }
        if (!current || dirty[0] & /*$clearPending*/
        256) {
          button2.disabled = /*$clearPending*/
          ctx2[8];
        }
        if (!current || dirty[0] & /*ulClasses*/
        8) {
          attr(
            ul3,
            "class",
            /*ulClasses*/
            ctx2[3]
          );
        }
        if (!current || dirty[0] & /*sectionSpace*/
        1) {
          attr(
            div,
            "class",
            /*sectionSpace*/
            ctx2[0]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block0);
        transition_in(if_block1);
        transition_in(filebutton.$$.fragment, local);
        transition_in(if_block2);
        current = true;
      },
      o(local) {
        transition_out(if_block0);
        transition_out(if_block1);
        transition_out(filebutton.$$.fragment, local);
        transition_out(if_block2);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        if (if_block0) if_block0.d();
        if (if_block1) if_block1.d();
        destroy_component(filebutton);
        if (if_block2) if_block2.d();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function instance$6($$self, $$props, $$invalidate) {
    let ulClasses;
    let inputClasses;
    let $configStore;
    let $exportJsonPending;
    let $exportCsvPending;
    let $importPending;
    let $clearPending;
    component_subscribe($$self, configStore, ($$value) => $$invalidate(4, $configStore = $$value));
    let { bg = "bg-white/30 dark:bg-black/15" } = $$props;
    let { border = "divide-y-[1px] *:border-surface-300-600-token" } = $$props;
    let { padding = "px-4 *:py-4" } = $$props;
    let { margin = "mt-2 *:!m-0" } = $$props;
    let { rounded = "rounded-container-token *:!rounded-none" } = $$props;
    let { inputRounded = "rounded-full" } = $$props;
    let { inputWidth = "w-32" } = $$props;
    let { sectionSpace = `space-y-4` } = $$props;
    let { sectionTitle = "font-bold" } = $$props;
    function usePendingButton(fn) {
      const store = writable(false);
      const wrapFn = async (...args) => {
        store.set(true);
        const result = await fn(...args);
        store.set(false);
        return result;
      };
      return { store, wrapFn };
    }
    async function importFromJSON(evt) {
      var _a;
      const file = (_a = evt.currentTarget.files) == null ? void 0 : _a[0];
      if (!file) return;
      try {
        await importJSON2(file);
      } catch (error) {
        logger.error(error);
        alert(error);
      }
    }
    function clearDb() {
      const isConfirm = confirm(t("setting.history.text.confirm_clear_history"));
      if (!isConfirm) return;
      return historyDb.clear();
    }
    const { importJSON: importJSON2, exportAsJSON: exportAsJSON2, exportAsCSV: exportAsCSV2 } = useHistoryBackup();
    const { store: importPending, wrapFn: wrapImportFromJSON } = usePendingButton(importFromJSON);
    component_subscribe($$self, importPending, (value) => $$invalidate(7, $importPending = value));
    const { store: clearPending, wrapFn: wrapClearDb } = usePendingButton(clearDb);
    component_subscribe($$self, clearPending, (value) => $$invalidate(8, $clearPending = value));
    const { store: exportJsonPending, wrapFn: wrapExportAsJSON } = usePendingButton(exportAsJSON2);
    component_subscribe($$self, exportJsonPending, (value) => $$invalidate(5, $exportJsonPending = value));
    const { store: exportCsvPending, wrapFn: wrapExportAsCSV } = usePendingButton(exportAsCSV2);
    component_subscribe($$self, exportCsvPending, (value) => $$invalidate(6, $exportCsvPending = value));
    function select_change_handler() {
      $configStore.historyBackupInterval = select_value(this);
      configStore.set($configStore);
    }
    function filebutton_disabled_binding(value) {
      $importPending = value;
      importPending.set($importPending);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(32, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("bg" in $$new_props) $$invalidate(17, bg = $$new_props.bg);
      if ("border" in $$new_props) $$invalidate(18, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(19, padding = $$new_props.padding);
      if ("margin" in $$new_props) $$invalidate(20, margin = $$new_props.margin);
      if ("rounded" in $$new_props) $$invalidate(21, rounded = $$new_props.rounded);
      if ("inputRounded" in $$new_props) $$invalidate(22, inputRounded = $$new_props.inputRounded);
      if ("inputWidth" in $$new_props) $$invalidate(23, inputWidth = $$new_props.inputWidth);
      if ("sectionSpace" in $$new_props) $$invalidate(0, sectionSpace = $$new_props.sectionSpace);
      if ("sectionTitle" in $$new_props) $$invalidate(1, sectionTitle = $$new_props.sectionTitle);
    };
    $$self.$$.update = () => {
      $$invalidate(3, ulClasses = `list *:items-center ${padding} ${margin} ${border} ${bg} ${rounded} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty[0] & /*inputWidth, inputRounded*/
      12582912) {
        $$invalidate(2, inputClasses = `${inputWidth} ${inputRounded} shrink-0`);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      sectionSpace,
      sectionTitle,
      inputClasses,
      ulClasses,
      $configStore,
      $exportJsonPending,
      $exportCsvPending,
      $importPending,
      $clearPending,
      importPending,
      wrapImportFromJSON,
      clearPending,
      wrapClearDb,
      exportJsonPending,
      wrapExportAsJSON,
      exportCsvPending,
      wrapExportAsCSV,
      bg,
      border,
      padding,
      margin,
      rounded,
      inputRounded,
      inputWidth,
      select_change_handler,
      filebutton_disabled_binding
    ];
  }
  class DownloadHistory extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$6,
        create_fragment$6,
        safe_not_equal,
        {
          bg: 17,
          border: 18,
          padding: 19,
          margin: 20,
          rounded: 21,
          inputRounded: 22,
          inputWidth: 23,
          sectionSpace: 0,
          sectionTitle: 1
        },
        null,
        [-1, -1]
      );
    }
  }
  function create_default_slot_3$2(ctx) {
    let div1;
    let p;
    let t1;
    let div0;
    let t2;
    let t3;
    let t4;
    return {
      c() {
        div1 = element("div");
        p = element("p");
        p.textContent = `${t("setting.button_position.options.horizon_position")}`;
        t1 = space();
        div0 = element("div");
        t2 = text(
          /*btnLeft*/
          ctx[3]
        );
        t3 = text(" / ");
        t4 = text(max);
        attr(div0, "class", "text-xs");
        attr(div1, "class", "flex justify-between items-center");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, p);
        append(div1, t1);
        append(div1, div0);
        append(div0, t2);
        append(div0, t3);
        append(div0, t4);
      },
      p(ctx2, dirty) {
        if (dirty & /*btnLeft*/
        8) set_data(
          t2,
          /*btnLeft*/
          ctx2[3]
        );
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
      }
    };
  }
  function create_default_slot_2$2(ctx) {
    let div1;
    let p;
    let t1;
    let div0;
    let t2;
    let t3;
    let t4;
    return {
      c() {
        div1 = element("div");
        p = element("p");
        p.textContent = `${t("setting.button_position.options.vertical_position")}`;
        t1 = space();
        div0 = element("div");
        t2 = text(
          /*btnTop*/
          ctx[4]
        );
        t3 = text(" / ");
        t4 = text(max);
        attr(div0, "class", "text-xs");
        attr(div1, "class", "flex justify-between items-center");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, p);
        append(div1, t1);
        append(div1, div0);
        append(div0, t2);
        append(div0, t3);
        append(div0, t4);
      },
      p(ctx2, dirty) {
        if (dirty & /*btnTop*/
        16) set_data(
          t2,
          /*btnTop*/
          ctx2[4]
        );
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
      }
    };
  }
  function create_if_block$4(ctx) {
    let section;
    let p;
    let t0_value = t("setting.button_position.label.my_bookmark") + "";
    let t0;
    let t1;
    let ul;
    let li;
    let rangeslider0;
    let updating_value;
    let t2;
    let rangeslider1;
    let updating_value_1;
    let current;
    function rangeslider0_value_binding_1(value) {
      ctx[19](value);
    }
    let rangeslider0_props = {
      name: "pdl-bookmark-btn-left",
      step,
      max,
      ticked: true,
      class: "flex-grow",
      $$slots: { default: [create_default_slot_1$2] },
      $$scope: { ctx }
    };
    if (
      /*bookmarkBtnLeft*/
      ctx[5] !== void 0
    ) {
      rangeslider0_props.value = /*bookmarkBtnLeft*/
      ctx[5];
    }
    rangeslider0 = new RangeSlider({ props: rangeslider0_props });
    binding_callbacks.push(() => bind(rangeslider0, "value", rangeslider0_value_binding_1));
    rangeslider0.$on(
      "change",
      /*change_handler_2*/
      ctx[20]
    );
    function rangeslider1_value_binding_1(value) {
      ctx[21](value);
    }
    let rangeslider1_props = {
      name: "pdl-bookmark-btn-top",
      step,
      max,
      ticked: true,
      class: "flex-grow",
      $$slots: { default: [create_default_slot$2] },
      $$scope: { ctx }
    };
    if (
      /*bookmarkBtnTop*/
      ctx[6] !== void 0
    ) {
      rangeslider1_props.value = /*bookmarkBtnTop*/
      ctx[6];
    }
    rangeslider1 = new RangeSlider({ props: rangeslider1_props });
    binding_callbacks.push(() => bind(rangeslider1, "value", rangeslider1_value_binding_1));
    rangeslider1.$on(
      "change",
      /*change_handler_3*/
      ctx[22]
    );
    return {
      c() {
        section = element("section");
        p = element("p");
        t0 = text(t0_value);
        t1 = space();
        ul = element("ul");
        li = element("li");
        create_component(rangeslider0.$$.fragment);
        t2 = space();
        create_component(rangeslider1.$$.fragment);
        attr(
          p,
          "class",
          /*sectionTitle*/
          ctx[2]
        );
        attr(li, "class", "flex-col !items-stretch md:flex-row md:!items-baseline gap-4 *:!m-0");
        attr(
          ul,
          "class",
          /*ulClasses*/
          ctx[8]
        );
      },
      m(target, anchor) {
        insert(target, section, anchor);
        append(section, p);
        append(p, t0);
        append(section, t1);
        append(section, ul);
        append(ul, li);
        mount_component(rangeslider0, li, null);
        append(li, t2);
        mount_component(rangeslider1, li, null);
        current = true;
      },
      p(ctx2, dirty) {
        if (!current || dirty & /*sectionTitle*/
        4) {
          attr(
            p,
            "class",
            /*sectionTitle*/
            ctx2[2]
          );
        }
        const rangeslider0_changes = {};
        if (dirty & /*$$scope, bookmarkBtnLeft*/
        33554464) {
          rangeslider0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_value && dirty & /*bookmarkBtnLeft*/
        32) {
          updating_value = true;
          rangeslider0_changes.value = /*bookmarkBtnLeft*/
          ctx2[5];
          add_flush_callback(() => updating_value = false);
        }
        rangeslider0.$set(rangeslider0_changes);
        const rangeslider1_changes = {};
        if (dirty & /*$$scope, bookmarkBtnTop*/
        33554496) {
          rangeslider1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_value_1 && dirty & /*bookmarkBtnTop*/
        64) {
          updating_value_1 = true;
          rangeslider1_changes.value = /*bookmarkBtnTop*/
          ctx2[6];
          add_flush_callback(() => updating_value_1 = false);
        }
        rangeslider1.$set(rangeslider1_changes);
        if (!current || dirty & /*ulClasses*/
        256) {
          attr(
            ul,
            "class",
            /*ulClasses*/
            ctx2[8]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(rangeslider0.$$.fragment, local);
        transition_in(rangeslider1.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(rangeslider0.$$.fragment, local);
        transition_out(rangeslider1.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(section);
        }
        destroy_component(rangeslider0);
        destroy_component(rangeslider1);
      }
    };
  }
  function create_default_slot_1$2(ctx) {
    let div1;
    let p;
    let t1;
    let div0;
    let t2;
    let t3;
    let t4;
    return {
      c() {
        div1 = element("div");
        p = element("p");
        p.textContent = `${t("setting.button_position.options.horizon_position")}`;
        t1 = space();
        div0 = element("div");
        t2 = text(
          /*bookmarkBtnLeft*/
          ctx[5]
        );
        t3 = text(" / ");
        t4 = text(max);
        attr(div0, "class", "text-xs");
        attr(div1, "class", "flex justify-between items-center");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, p);
        append(div1, t1);
        append(div1, div0);
        append(div0, t2);
        append(div0, t3);
        append(div0, t4);
      },
      p(ctx2, dirty) {
        if (dirty & /*bookmarkBtnLeft*/
        32) set_data(
          t2,
          /*bookmarkBtnLeft*/
          ctx2[5]
        );
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
      }
    };
  }
  function create_default_slot$2(ctx) {
    let div1;
    let p;
    let t1;
    let div0;
    let t2;
    let t3;
    let t4;
    return {
      c() {
        div1 = element("div");
        p = element("p");
        p.textContent = `${t("setting.button_position.options.vertical_position")}`;
        t1 = space();
        div0 = element("div");
        t2 = text(
          /*bookmarkBtnTop*/
          ctx[6]
        );
        t3 = text(" / ");
        t4 = text(max);
        attr(div0, "class", "text-xs");
        attr(div1, "class", "flex justify-between items-center");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, p);
        append(div1, t1);
        append(div1, div0);
        append(div0, t2);
        append(div0, t3);
        append(div0, t4);
      },
      p(ctx2, dirty) {
        if (dirty & /*bookmarkBtnTop*/
        64) set_data(
          t2,
          /*bookmarkBtnTop*/
          ctx2[6]
        );
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
      }
    };
  }
  function create_fragment$5(ctx) {
    let div2;
    let div1;
    let div0;
    let div0_class_value;
    let t0;
    let section;
    let p;
    let t1_value = t("setting.button_position.label.common") + "";
    let t1;
    let t2;
    let ul;
    let li;
    let rangeslider0;
    let updating_value;
    let t3;
    let rangeslider1;
    let updating_value_1;
    let t4;
    let show_if = env.isPixiv();
    let current;
    function rangeslider0_value_binding(value) {
      ctx[15](value);
    }
    let rangeslider0_props = {
      name: "pdl-btn-left",
      step,
      max,
      ticked: true,
      class: "flex-grow",
      $$slots: { default: [create_default_slot_3$2] },
      $$scope: { ctx }
    };
    if (
      /*btnLeft*/
      ctx[3] !== void 0
    ) {
      rangeslider0_props.value = /*btnLeft*/
      ctx[3];
    }
    rangeslider0 = new RangeSlider({ props: rangeslider0_props });
    binding_callbacks.push(() => bind(rangeslider0, "value", rangeslider0_value_binding));
    rangeslider0.$on(
      "change",
      /*change_handler*/
      ctx[16]
    );
    function rangeslider1_value_binding(value) {
      ctx[17](value);
    }
    let rangeslider1_props = {
      name: "pdl-btn-top",
      step,
      max,
      ticked: true,
      class: "flex-grow",
      $$slots: { default: [create_default_slot_2$2] },
      $$scope: { ctx }
    };
    if (
      /*btnTop*/
      ctx[4] !== void 0
    ) {
      rangeslider1_props.value = /*btnTop*/
      ctx[4];
    }
    rangeslider1 = new RangeSlider({ props: rangeslider1_props });
    binding_callbacks.push(() => bind(rangeslider1, "value", rangeslider1_value_binding));
    rangeslider1.$on(
      "change",
      /*change_handler_1*/
      ctx[18]
    );
    let if_block = show_if && create_if_block$4(ctx);
    return {
      c() {
        div2 = element("div");
        div1 = element("div");
        div0 = element("div");
        t0 = space();
        section = element("section");
        p = element("p");
        t1 = text(t1_value);
        t2 = space();
        ul = element("ul");
        li = element("li");
        create_component(rangeslider0.$$.fragment);
        t3 = space();
        create_component(rangeslider1.$$.fragment);
        t4 = space();
        if (if_block) if_block.c();
        attr(div0, "class", div0_class_value = "w-48 h-48 backdrop-blur-sm rounded-lg relative " + /*bg*/
        ctx[0]);
        attr(div1, "class", "flex items-center justify-center");
        attr(
          p,
          "class",
          /*sectionTitle*/
          ctx[2]
        );
        attr(li, "class", "flex-col !items-stretch md:flex-row md:!items-baseline gap-4 *:!m-0");
        attr(
          ul,
          "class",
          /*ulClasses*/
          ctx[8]
        );
        attr(
          div2,
          "class",
          /*sectionSpace*/
          ctx[1]
        );
      },
      m(target, anchor) {
        insert(target, div2, anchor);
        append(div2, div1);
        append(div1, div0);
        ctx[14](div0);
        append(div2, t0);
        append(div2, section);
        append(section, p);
        append(p, t1);
        append(section, t2);
        append(section, ul);
        append(ul, li);
        mount_component(rangeslider0, li, null);
        append(li, t3);
        mount_component(rangeslider1, li, null);
        append(div2, t4);
        if (if_block) if_block.m(div2, null);
        current = true;
      },
      p(ctx2, [dirty]) {
        if (!current || dirty & /*bg*/
        1 && div0_class_value !== (div0_class_value = "w-48 h-48 backdrop-blur-sm rounded-lg relative " + /*bg*/
        ctx2[0])) {
          attr(div0, "class", div0_class_value);
        }
        if (!current || dirty & /*sectionTitle*/
        4) {
          attr(
            p,
            "class",
            /*sectionTitle*/
            ctx2[2]
          );
        }
        const rangeslider0_changes = {};
        if (dirty & /*$$scope, btnLeft*/
        33554440) {
          rangeslider0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_value && dirty & /*btnLeft*/
        8) {
          updating_value = true;
          rangeslider0_changes.value = /*btnLeft*/
          ctx2[3];
          add_flush_callback(() => updating_value = false);
        }
        rangeslider0.$set(rangeslider0_changes);
        const rangeslider1_changes = {};
        if (dirty & /*$$scope, btnTop*/
        33554448) {
          rangeslider1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_value_1 && dirty & /*btnTop*/
        16) {
          updating_value_1 = true;
          rangeslider1_changes.value = /*btnTop*/
          ctx2[4];
          add_flush_callback(() => updating_value_1 = false);
        }
        rangeslider1.$set(rangeslider1_changes);
        if (!current || dirty & /*ulClasses*/
        256) {
          attr(
            ul,
            "class",
            /*ulClasses*/
            ctx2[8]
          );
        }
        if (show_if) if_block.p(ctx2, dirty);
        if (!current || dirty & /*sectionSpace*/
        2) {
          attr(
            div2,
            "class",
            /*sectionSpace*/
            ctx2[1]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(rangeslider0.$$.fragment, local);
        transition_in(rangeslider1.$$.fragment, local);
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(rangeslider0.$$.fragment, local);
        transition_out(rangeslider1.$$.fragment, local);
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div2);
        }
        ctx[14](null);
        destroy_component(rangeslider0);
        destroy_component(rangeslider1);
        if (if_block) if_block.d();
      }
    };
  }
  const max = 100;
  const step = 4;
  function changeCssProp(key, value) {
    document.documentElement.style.setProperty(key, String(value));
  }
  function instance$5($$self, $$props, $$invalidate) {
    let ulClasses;
    let $store;
    component_subscribe($$self, configStore, ($$value) => $$invalidate(23, $store = $$value));
    let { bg = "bg-white/30 dark:bg-black/15" } = $$props;
    let { border = "divide-y-[1px] *:border-surface-300-600-token" } = $$props;
    let { padding = "px-4 *:py-4" } = $$props;
    let { margin = "mt-2 *:!m-0" } = $$props;
    let { rounded = "rounded-container-token *:!rounded-none" } = $$props;
    let { sectionSpace = `space-y-4` } = $$props;
    let { sectionTitle = "font-bold" } = $$props;
    let btnLeft = $store["pdl-btn-left"];
    let btnTop = $store["pdl-btn-top"];
    let bookmarkBtnLeft = $store["pdl-btn-self-bookmark-left"];
    let bookmarkBtnTop = $store["pdl-btn-self-bookmark-top"];
    function updateBtnPosConfig(key, val) {
      set_store_value(configStore, $store[key] = val, $store);
    }
    let buttonContainer;
    onMount(() => {
      const sampleBtn = new ThumbnailButton({
        id: "0",
        shouldObserveDb: false,
        onClick: () => void 0
      });
      sampleBtn.setAttribute("disabled", "");
      buttonContainer.appendChild(sampleBtn);
      if (!env.isPixiv()) return;
      const sampleBookmarkBtn = new ThumbnailButton({
        id: "0",
        type: ThumbnailBtnType.PixivMyBookmark,
        shouldObserveDb: false,
        onClick: () => void 0
      });
      sampleBookmarkBtn.setAttribute("disabled", "");
      sampleBookmarkBtn.setStatus(ThumbnailBtnStatus.Complete);
      buttonContainer.appendChild(sampleBookmarkBtn);
    });
    function div0_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        buttonContainer = $$value;
        $$invalidate(7, buttonContainer);
      });
    }
    function rangeslider0_value_binding(value) {
      btnLeft = value;
      $$invalidate(3, btnLeft);
    }
    const change_handler = () => updateBtnPosConfig("pdl-btn-left", btnLeft);
    function rangeslider1_value_binding(value) {
      btnTop = value;
      $$invalidate(4, btnTop);
    }
    const change_handler_1 = () => updateBtnPosConfig("pdl-btn-top", btnTop);
    function rangeslider0_value_binding_1(value) {
      bookmarkBtnLeft = value;
      $$invalidate(5, bookmarkBtnLeft);
    }
    const change_handler_2 = () => updateBtnPosConfig("pdl-btn-self-bookmark-left", bookmarkBtnLeft);
    function rangeslider1_value_binding_1(value) {
      bookmarkBtnTop = value;
      $$invalidate(6, bookmarkBtnTop);
    }
    const change_handler_3 = () => updateBtnPosConfig("pdl-btn-self-bookmark-top", bookmarkBtnTop);
    $$self.$$set = ($$new_props) => {
      $$invalidate(24, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("bg" in $$new_props) $$invalidate(0, bg = $$new_props.bg);
      if ("border" in $$new_props) $$invalidate(10, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(11, padding = $$new_props.padding);
      if ("margin" in $$new_props) $$invalidate(12, margin = $$new_props.margin);
      if ("rounded" in $$new_props) $$invalidate(13, rounded = $$new_props.rounded);
      if ("sectionSpace" in $$new_props) $$invalidate(1, sectionSpace = $$new_props.sectionSpace);
      if ("sectionTitle" in $$new_props) $$invalidate(2, sectionTitle = $$new_props.sectionTitle);
    };
    $$self.$$.update = () => {
      $$invalidate(8, ulClasses = `list *:items-center ${padding} ${margin} ${border} ${bg} ${rounded} ${$$props.class ?? ""}`);
      if ($$self.$$.dirty & /*btnLeft*/
      8) {
        changeCssProp("--pdl-btn-left", btnLeft);
      }
      if ($$self.$$.dirty & /*btnTop*/
      16) {
        changeCssProp("--pdl-btn-top", btnTop);
      }
      if ($$self.$$.dirty & /*bookmarkBtnLeft*/
      32) {
        changeCssProp("--pdl-btn-self-bookmark-left", bookmarkBtnLeft);
      }
      if ($$self.$$.dirty & /*bookmarkBtnTop*/
      64) {
        changeCssProp("--pdl-btn-self-bookmark-top", bookmarkBtnTop);
      }
    };
    $$props = exclude_internal_props($$props);
    return [
      bg,
      sectionSpace,
      sectionTitle,
      btnLeft,
      btnTop,
      bookmarkBtnLeft,
      bookmarkBtnTop,
      buttonContainer,
      ulClasses,
      updateBtnPosConfig,
      border,
      padding,
      margin,
      rounded,
      div0_binding,
      rangeslider0_value_binding,
      change_handler,
      rangeslider1_value_binding,
      change_handler_1,
      rangeslider0_value_binding_1,
      change_handler_2,
      rangeslider1_value_binding_1,
      change_handler_3
    ];
  }
  class BtnPosition extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$5, create_fragment$5, safe_not_equal, {
        bg: 0,
        border: 10,
        padding: 11,
        margin: 12,
        rounded: 13,
        sectionSpace: 1,
        sectionTitle: 2
      });
    }
  }
  function create_if_block_4$1(ctx) {
    let li0;
    let p0;
    let t1;
    let slidetoggle0;
    let updating_checked;
    let t2;
    let li1;
    let p1;
    let t4;
    let slidetoggle1;
    let updating_checked_1;
    let current;
    function slidetoggle0_checked_binding(value) {
      ctx[11](value);
    }
    let slidetoggle0_props = { name: "bundle-illusts", size: "sm" };
    if (
      /*$store*/
      ctx[6].bundleIllusts !== void 0
    ) {
      slidetoggle0_props.checked = /*$store*/
      ctx[6].bundleIllusts;
    }
    slidetoggle0 = new SlideToggle({ props: slidetoggle0_props });
    binding_callbacks.push(() => bind(slidetoggle0, "checked", slidetoggle0_checked_binding));
    function slidetoggle1_checked_binding(value) {
      ctx[12](value);
    }
    let slidetoggle1_props = { name: "bundle-manga", size: "sm" };
    if (
      /*$store*/
      ctx[6].bundleManga !== void 0
    ) {
      slidetoggle1_props.checked = /*$store*/
      ctx[6].bundleManga;
    }
    slidetoggle1 = new SlideToggle({ props: slidetoggle1_props });
    binding_callbacks.push(() => bind(slidetoggle1, "checked", slidetoggle1_checked_binding));
    return {
      c() {
        li0 = element("li");
        p0 = element("p");
        p0.textContent = `${t("setting.others.options.bundle_multipage_illust")}`;
        t1 = space();
        create_component(slidetoggle0.$$.fragment);
        t2 = space();
        li1 = element("li");
        p1 = element("p");
        p1.textContent = `${t("setting.others.options.bundle_manga")}`;
        t4 = space();
        create_component(slidetoggle1.$$.fragment);
        attr(p0, "class", "flex-auto");
        attr(p1, "class", "flex-auto");
      },
      m(target, anchor) {
        insert(target, li0, anchor);
        append(li0, p0);
        append(li0, t1);
        mount_component(slidetoggle0, li0, null);
        insert(target, t2, anchor);
        insert(target, li1, anchor);
        append(li1, p1);
        append(li1, t4);
        mount_component(slidetoggle1, li1, null);
        current = true;
      },
      p(ctx2, dirty) {
        const slidetoggle0_changes = {};
        if (!updating_checked && dirty & /*$store*/
        64) {
          updating_checked = true;
          slidetoggle0_changes.checked = /*$store*/
          ctx2[6].bundleIllusts;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle0.$set(slidetoggle0_changes);
        const slidetoggle1_changes = {};
        if (!updating_checked_1 && dirty & /*$store*/
        64) {
          updating_checked_1 = true;
          slidetoggle1_changes.checked = /*$store*/
          ctx2[6].bundleManga;
          add_flush_callback(() => updating_checked_1 = false);
        }
        slidetoggle1.$set(slidetoggle1_changes);
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle0.$$.fragment, local);
        transition_in(slidetoggle1.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle0.$$.fragment, local);
        transition_out(slidetoggle1.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(li0);
          detach(t2);
          detach(li1);
        }
        destroy_component(slidetoggle0);
        destroy_component(slidetoggle1);
      }
    };
  }
  function create_if_block_2$1(ctx) {
    let li;
    let div;
    let p;
    let t1;
    let slidetoggle;
    let updating_checked;
    let t2;
    let show_if = (
      /*$store*/
      ctx[6].addBookmark && env.isPixiv()
    );
    let current;
    function slidetoggle_checked_binding_1(value) {
      ctx[13](value);
    }
    let slidetoggle_props = { name: "fsa-enable", size: "sm" };
    if (
      /*$store*/
      ctx[6].addBookmark !== void 0
    ) {
      slidetoggle_props.checked = /*$store*/
      ctx[6].addBookmark;
    }
    slidetoggle = new SlideToggle({ props: slidetoggle_props });
    binding_callbacks.push(() => bind(slidetoggle, "checked", slidetoggle_checked_binding_1));
    let if_block = show_if && create_if_block_3$1(ctx);
    return {
      c() {
        li = element("li");
        div = element("div");
        p = element("p");
        p.textContent = `${t("setting.others.options.add_bookmark_when_download")}`;
        t1 = space();
        create_component(slidetoggle.$$.fragment);
        t2 = space();
        if (if_block) if_block.c();
        attr(p, "class", "flex-auto");
        attr(div, "class", "flex items-center");
        attr(li, "class", "flex-col !items-stretch");
      },
      m(target, anchor) {
        insert(target, li, anchor);
        append(li, div);
        append(div, p);
        append(div, t1);
        mount_component(slidetoggle, div, null);
        append(li, t2);
        if (if_block) if_block.m(li, null);
        current = true;
      },
      p(ctx2, dirty) {
        const slidetoggle_changes = {};
        if (!updating_checked && dirty & /*$store*/
        64) {
          updating_checked = true;
          slidetoggle_changes.checked = /*$store*/
          ctx2[6].addBookmark;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle.$set(slidetoggle_changes);
        if (dirty & /*$store*/
        64) show_if = /*$store*/
        ctx2[6].addBookmark && env.isPixiv();
        if (show_if) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty & /*$store*/
            64) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block_3$1(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(li, null);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle.$$.fragment, local);
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle.$$.fragment, local);
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(li);
        }
        destroy_component(slidetoggle);
        if (if_block) if_block.d();
      }
    };
  }
  function create_if_block_3$1(ctx) {
    let ul;
    let li0;
    let label0;
    let p0;
    let t1;
    let slidetoggle0;
    let updating_checked;
    let t2;
    let li1;
    let label1;
    let p1;
    let t4;
    let slidetoggle1;
    let updating_checked_1;
    let ul_class_value;
    let current;
    function slidetoggle0_checked_binding_1(value) {
      ctx[14](value);
    }
    let slidetoggle0_props = { name: "fsa-enable", size: "sm" };
    if (
      /*$store*/
      ctx[6].addBookmarkWithTags !== void 0
    ) {
      slidetoggle0_props.checked = /*$store*/
      ctx[6].addBookmarkWithTags;
    }
    slidetoggle0 = new SlideToggle({ props: slidetoggle0_props });
    binding_callbacks.push(() => bind(slidetoggle0, "checked", slidetoggle0_checked_binding_1));
    function slidetoggle1_checked_binding_1(value) {
      ctx[15](value);
    }
    let slidetoggle1_props = { name: "fsa-enable", size: "sm" };
    if (
      /*$store*/
      ctx[6].privateR18 !== void 0
    ) {
      slidetoggle1_props.checked = /*$store*/
      ctx[6].privateR18;
    }
    slidetoggle1 = new SlideToggle({ props: slidetoggle1_props });
    binding_callbacks.push(() => bind(slidetoggle1, "checked", slidetoggle1_checked_binding_1));
    return {
      c() {
        ul = element("ul");
        li0 = element("li");
        label0 = element("label");
        p0 = element("p");
        p0.textContent = `${t("setting.others.options.add_bookmark_with_tags")}`;
        t1 = space();
        create_component(slidetoggle0.$$.fragment);
        t2 = space();
        li1 = element("li");
        label1 = element("label");
        p1 = element("p");
        p1.textContent = `${t("setting.others.options.add_bookmark_private_r18")}`;
        t4 = space();
        create_component(slidetoggle1.$$.fragment);
        attr(p0, "class", "flex-auto");
        attr(label0, "class", "label flex flex-grow items-center justify-center");
        attr(p1, "class", "flex-auto");
        attr(label1, "class", "label flex flex-grow items-center justify-center");
        attr(ul, "class", ul_class_value = "list " + /*border*/
        ctx[0] + " " + /*rounded*/
        ctx[1] + " [&:not(:last-child)]:*:py-4 [&:last-child]:*:pt-4");
      },
      m(target, anchor) {
        insert(target, ul, anchor);
        append(ul, li0);
        append(li0, label0);
        append(label0, p0);
        append(label0, t1);
        mount_component(slidetoggle0, label0, null);
        append(ul, t2);
        append(ul, li1);
        append(li1, label1);
        append(label1, p1);
        append(label1, t4);
        mount_component(slidetoggle1, label1, null);
        current = true;
      },
      p(ctx2, dirty) {
        const slidetoggle0_changes = {};
        if (!updating_checked && dirty & /*$store*/
        64) {
          updating_checked = true;
          slidetoggle0_changes.checked = /*$store*/
          ctx2[6].addBookmarkWithTags;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle0.$set(slidetoggle0_changes);
        const slidetoggle1_changes = {};
        if (!updating_checked_1 && dirty & /*$store*/
        64) {
          updating_checked_1 = true;
          slidetoggle1_changes.checked = /*$store*/
          ctx2[6].privateR18;
          add_flush_callback(() => updating_checked_1 = false);
        }
        slidetoggle1.$set(slidetoggle1_changes);
        if (!current || dirty & /*border, rounded*/
        3 && ul_class_value !== (ul_class_value = "list " + /*border*/
        ctx2[0] + " " + /*rounded*/
        ctx2[1] + " [&:not(:last-child)]:*:py-4 [&:last-child]:*:pt-4")) {
          attr(ul, "class", ul_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle0.$$.fragment, local);
        transition_in(slidetoggle1.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle0.$$.fragment, local);
        transition_out(slidetoggle1.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(ul);
        }
        destroy_component(slidetoggle0);
        destroy_component(slidetoggle1);
      }
    };
  }
  function create_if_block_1$3(ctx) {
    let section;
    let p0;
    let t0;
    let t1;
    let ul;
    let li;
    let div;
    let p1;
    let t3;
    let p2;
    let t4;
    let p2_class_value;
    let t5;
    let slidetoggle;
    let updating_checked;
    let current;
    function slidetoggle_checked_binding_2(value) {
      ctx[16](value);
    }
    let slidetoggle_props = { name: "mix-effect", size: "sm" };
    if (
      /*$store*/
      ctx[6].mixEffect !== void 0
    ) {
      slidetoggle_props.checked = /*$store*/
      ctx[6].mixEffect;
    }
    slidetoggle = new SlideToggle({ props: slidetoggle_props });
    binding_callbacks.push(() => bind(slidetoggle, "checked", slidetoggle_checked_binding_2));
    return {
      c() {
        section = element("section");
        p0 = element("p");
        t0 = text("实验性功能");
        t1 = space();
        ul = element("ul");
        li = element("li");
        div = element("div");
        p1 = element("p");
        p1.textContent = "为单页插图增加 #pixivGlow2024 效果";
        t3 = space();
        p2 = element("p");
        t4 = text("* 转换至动图格式。如果插图尺寸过大,可能占用大量内存 / 转换失败");
        t5 = space();
        create_component(slidetoggle.$$.fragment);
        attr(
          p0,
          "class",
          /*sectionTitle*/
          ctx[4]
        );
        attr(p2, "class", p2_class_value = /*descritionText*/
        ctx[2] + " !text-error-500");
        attr(div, "class", "flex-auto");
        attr(
          ul,
          "class",
          /*ulClasses*/
          ctx[5]
        );
      },
      m(target, anchor) {
        insert(target, section, anchor);
        append(section, p0);
        append(p0, t0);
        append(section, t1);
        append(section, ul);
        append(ul, li);
        append(li, div);
        append(div, p1);
        append(div, t3);
        append(div, p2);
        append(p2, t4);
        append(li, t5);
        mount_component(slidetoggle, li, null);
        current = true;
      },
      p(ctx2, dirty) {
        if (!current || dirty & /*sectionTitle*/
        16) {
          attr(
            p0,
            "class",
            /*sectionTitle*/
            ctx2[4]
          );
        }
        if (!current || dirty & /*descritionText*/
        4 && p2_class_value !== (p2_class_value = /*descritionText*/
        ctx2[2] + " !text-error-500")) {
          attr(p2, "class", p2_class_value);
        }
        const slidetoggle_changes = {};
        if (!updating_checked && dirty & /*$store*/
        64) {
          updating_checked = true;
          slidetoggle_changes.checked = /*$store*/
          ctx2[6].mixEffect;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle.$set(slidetoggle_changes);
        if (!current || dirty & /*ulClasses*/
        32) {
          attr(
            ul,
            "class",
            /*ulClasses*/
            ctx2[5]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(section);
        }
        destroy_component(slidetoggle);
      }
    };
  }
  function create_if_block$3(ctx) {
    let section;
    let p0;
    let t0;
    let t1;
    let ul;
    let li;
    let input;
    let t2;
    let p1;
    let t3;
    let mounted;
    let dispose;
    return {
      c() {
        section = element("section");
        p0 = element("p");
        t0 = text("cf_clearance");
        t1 = space();
        ul = element("ul");
        li = element("li");
        input = element("input");
        t2 = space();
        p1 = element("p");
        t3 = text("如果无法正常下载,可尝试填入cf_clearance cookie");
        attr(
          p0,
          "class",
          /*sectionTitle*/
          ctx[4]
        );
        attr(input, "type", "text");
        attr(input, "class", "input");
        attr(input, "name", "cf_clearance");
        attr(
          p1,
          "class",
          /*descritionText*/
          ctx[2]
        );
        attr(li, "class", "flex-col !items-start gap-2");
        attr(
          ul,
          "class",
          /*ulClasses*/
          ctx[5]
        );
      },
      m(target, anchor) {
        insert(target, section, anchor);
        append(section, p0);
        append(p0, t0);
        append(section, t1);
        append(section, ul);
        append(ul, li);
        append(li, input);
        set_input_value(
          input,
          /*$store*/
          ctx[6].token
        );
        append(li, t2);
        append(li, p1);
        append(p1, t3);
        if (!mounted) {
          dispose = listen(
            input,
            "input",
            /*input_input_handler*/
            ctx[17]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty & /*sectionTitle*/
        16) {
          attr(
            p0,
            "class",
            /*sectionTitle*/
            ctx2[4]
          );
        }
        if (dirty & /*$store*/
        64 && input.value !== /*$store*/
        ctx2[6].token) {
          set_input_value(
            input,
            /*$store*/
            ctx2[6].token
          );
        }
        if (dirty & /*descritionText*/
        4) {
          attr(
            p1,
            "class",
            /*descritionText*/
            ctx2[2]
          );
        }
        if (dirty & /*ulClasses*/
        32) {
          attr(
            ul,
            "class",
            /*ulClasses*/
            ctx2[5]
          );
        }
      },
      d(detaching) {
        if (detaching) {
          detach(section);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_fragment$4(ctx) {
    let div;
    let ul;
    let li;
    let p;
    let t1;
    let slidetoggle;
    let updating_checked;
    let t2;
    let show_if_3 = env.isPixiv();
    let t3;
    let show_if_2 = !env.isYande();
    let t4;
    let show_if_1 = env.isPixiv();
    let t5;
    let show_if = env.isRule34();
    let current;
    function slidetoggle_checked_binding(value) {
      ctx[10](value);
    }
    let slidetoggle_props = { name: "show-popup-button", size: "sm" };
    if (
      /*$store*/
      ctx[6].showPopupButton !== void 0
    ) {
      slidetoggle_props.checked = /*$store*/
      ctx[6].showPopupButton;
    }
    slidetoggle = new SlideToggle({ props: slidetoggle_props });
    binding_callbacks.push(() => bind(slidetoggle, "checked", slidetoggle_checked_binding));
    let if_block0 = show_if_3 && create_if_block_4$1(ctx);
    let if_block1 = show_if_2 && create_if_block_2$1(ctx);
    let if_block2 = show_if_1 && create_if_block_1$3(ctx);
    let if_block3 = show_if && create_if_block$3(ctx);
    return {
      c() {
        div = element("div");
        ul = element("ul");
        li = element("li");
        p = element("p");
        p.textContent = `${t("setting.others.options.show_setting_button")}`;
        t1 = space();
        create_component(slidetoggle.$$.fragment);
        t2 = space();
        if (if_block0) if_block0.c();
        t3 = space();
        if (if_block1) if_block1.c();
        t4 = space();
        if (if_block2) if_block2.c();
        t5 = space();
        if (if_block3) if_block3.c();
        attr(p, "class", "flex-auto");
        attr(
          ul,
          "class",
          /*ulClasses*/
          ctx[5]
        );
        attr(
          div,
          "class",
          /*sectionSpace*/
          ctx[3]
        );
      },
      m(target, anchor) {
        insert(target, div, anchor);
        append(div, ul);
        append(ul, li);
        append(li, p);
        append(li, t1);
        mount_component(slidetoggle, li, null);
        append(ul, t2);
        if (if_block0) if_block0.m(ul, null);
        append(ul, t3);
        if (if_block1) if_block1.m(ul, null);
        append(div, t4);
        if (if_block2) if_block2.m(div, null);
        append(div, t5);
        if (if_block3) if_block3.m(div, null);
        current = true;
      },
      p(ctx2, [dirty]) {
        const slidetoggle_changes = {};
        if (!updating_checked && dirty & /*$store*/
        64) {
          updating_checked = true;
          slidetoggle_changes.checked = /*$store*/
          ctx2[6].showPopupButton;
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle.$set(slidetoggle_changes);
        if (show_if_3) if_block0.p(ctx2, dirty);
        if (show_if_2) if_block1.p(ctx2, dirty);
        if (!current || dirty & /*ulClasses*/
        32) {
          attr(
            ul,
            "class",
            /*ulClasses*/
            ctx2[5]
          );
        }
        if (show_if_1) if_block2.p(ctx2, dirty);
        if (show_if) if_block3.p(ctx2, dirty);
        if (!current || dirty & /*sectionSpace*/
        8) {
          attr(
            div,
            "class",
            /*sectionSpace*/
            ctx2[3]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle.$$.fragment, local);
        transition_in(if_block0);
        transition_in(if_block1);
        transition_in(if_block2);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle.$$.fragment, local);
        transition_out(if_block0);
        transition_out(if_block1);
        transition_out(if_block2);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        destroy_component(slidetoggle);
        if (if_block0) if_block0.d();
        if (if_block1) if_block1.d();
        if (if_block2) if_block2.d();
        if (if_block3) if_block3.d();
      }
    };
  }
  function instance$4($$self, $$props, $$invalidate) {
    let ulClasses;
    let $store;
    component_subscribe($$self, configStore, ($$value) => $$invalidate(6, $store = $$value));
    let { bg = "bg-white/30 dark:bg-black/15" } = $$props;
    let { border = "divide-y-[1px] *:border-surface-300-600-token" } = $$props;
    let { padding = "px-4 *:py-4" } = $$props;
    let { margin = "mt-2 *:!m-0" } = $$props;
    let { rounded = "rounded-container-token *:!rounded-none" } = $$props;
    let { descritionText = "text-sm text-surface-400" } = $$props;
    let { sectionSpace = `space-y-4` } = $$props;
    let { sectionTitle = "font-bold" } = $$props;
    function slidetoggle_checked_binding(value) {
      if ($$self.$$.not_equal($store.showPopupButton, value)) {
        $store.showPopupButton = value;
        configStore.set($store);
      }
    }
    function slidetoggle0_checked_binding(value) {
      if ($$self.$$.not_equal($store.bundleIllusts, value)) {
        $store.bundleIllusts = value;
        configStore.set($store);
      }
    }
    function slidetoggle1_checked_binding(value) {
      if ($$self.$$.not_equal($store.bundleManga, value)) {
        $store.bundleManga = value;
        configStore.set($store);
      }
    }
    function slidetoggle_checked_binding_1(value) {
      if ($$self.$$.not_equal($store.addBookmark, value)) {
        $store.addBookmark = value;
        configStore.set($store);
      }
    }
    function slidetoggle0_checked_binding_1(value) {
      if ($$self.$$.not_equal($store.addBookmarkWithTags, value)) {
        $store.addBookmarkWithTags = value;
        configStore.set($store);
      }
    }
    function slidetoggle1_checked_binding_1(value) {
      if ($$self.$$.not_equal($store.privateR18, value)) {
        $store.privateR18 = value;
        configStore.set($store);
      }
    }
    function slidetoggle_checked_binding_2(value) {
      if ($$self.$$.not_equal($store.mixEffect, value)) {
        $store.mixEffect = value;
        configStore.set($store);
      }
    }
    function input_input_handler() {
      $store.token = this.value;
      configStore.set($store);
    }
    $$self.$$set = ($$new_props) => {
      $$invalidate(18, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("bg" in $$new_props) $$invalidate(7, bg = $$new_props.bg);
      if ("border" in $$new_props) $$invalidate(0, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(8, padding = $$new_props.padding);
      if ("margin" in $$new_props) $$invalidate(9, margin = $$new_props.margin);
      if ("rounded" in $$new_props) $$invalidate(1, rounded = $$new_props.rounded);
      if ("descritionText" in $$new_props) $$invalidate(2, descritionText = $$new_props.descritionText);
      if ("sectionSpace" in $$new_props) $$invalidate(3, sectionSpace = $$new_props.sectionSpace);
      if ("sectionTitle" in $$new_props) $$invalidate(4, sectionTitle = $$new_props.sectionTitle);
    };
    $$self.$$.update = () => {
      $$invalidate(5, ulClasses = `list *:items-center ${padding} ${margin} ${border} ${bg} ${rounded} ${$$props.class ?? ""}`);
    };
    $$props = exclude_internal_props($$props);
    return [
      border,
      rounded,
      descritionText,
      sectionSpace,
      sectionTitle,
      ulClasses,
      $store,
      bg,
      padding,
      margin,
      slidetoggle_checked_binding,
      slidetoggle0_checked_binding,
      slidetoggle1_checked_binding,
      slidetoggle_checked_binding_1,
      slidetoggle0_checked_binding_1,
      slidetoggle1_checked_binding_1,
      slidetoggle_checked_binding_2,
      input_input_handler
    ];
  }
  class Others extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$4, create_fragment$4, safe_not_equal, {
        bg: 7,
        border: 0,
        padding: 8,
        margin: 9,
        rounded: 1,
        descritionText: 2,
        sectionSpace: 3,
        sectionTitle: 4
      });
    }
  }
  function create_fragment$3(ctx) {
    let div;
    let section0;
    let p0;
    let t0_value = t("setting.feedback.label.feedback") + "";
    let t0;
    let t1;
    let ul0;
    let li0;
    let span;
    let raw0_value = t("setting.feedback.text.feedback_desc") + "";
    let t2;
    let section1;
    let p1;
    let t3_value = t("setting.feedback.label.donate") + "";
    let t3;
    let t4;
    let ul1;
    let li1;
    let p2;
    let raw1_value = t("setting.feedback.text.give_me_a_star") + "";
    let t5;
    let li2;
    let figure;
    let img;
    let img_src_value;
    let t6;
    let figcaption;
    return {
      c() {
        div = element("div");
        section0 = element("section");
        p0 = element("p");
        t0 = text(t0_value);
        t1 = space();
        ul0 = element("ul");
        li0 = element("li");
        span = element("span");
        t2 = space();
        section1 = element("section");
        p1 = element("p");
        t3 = text(t3_value);
        t4 = space();
        ul1 = element("ul");
        li1 = element("li");
        p2 = element("p");
        t5 = space();
        li2 = element("li");
        figure = element("figure");
        img = element("img");
        t6 = space();
        figcaption = element("figcaption");
        figcaption.textContent = `${t("setting.feedback.text.donate_desc")}`;
        attr(
          p0,
          "class",
          /*sectionTitle*/
          ctx[1]
        );
        attr(
          ul0,
          "class",
          /*ulClasses*/
          ctx[2]
        );
        attr(
          p1,
          "class",
          /*sectionTitle*/
          ctx[1]
        );
        if (!src_url_equal(img.src, img_src_value = creditCode)) attr(img, "src", img_src_value);
        attr(img, "alt", "credit");
        attr(img, "class", "rounded-full m-auto");
        attr(figcaption, "class", "mt-4");
        attr(li2, "class", "justify-center");
        attr(
          ul1,
          "class",
          /*ulClasses*/
          ctx[2]
        );
        attr(
          div,
          "class",
          /*sectionSpace*/
          ctx[0]
        );
      },
      m(target, anchor) {
        insert(target, div, anchor);
        append(div, section0);
        append(section0, p0);
        append(p0, t0);
        append(section0, t1);
        append(section0, ul0);
        append(ul0, li0);
        append(li0, span);
        span.innerHTML = raw0_value;
        append(div, t2);
        append(div, section1);
        append(section1, p1);
        append(p1, t3);
        append(section1, t4);
        append(section1, ul1);
        append(ul1, li1);
        append(li1, p2);
        p2.innerHTML = raw1_value;
        append(ul1, t5);
        append(ul1, li2);
        append(li2, figure);
        append(figure, img);
        append(figure, t6);
        append(figure, figcaption);
      },
      p(ctx2, [dirty]) {
        if (dirty & /*sectionTitle*/
        2) {
          attr(
            p0,
            "class",
            /*sectionTitle*/
            ctx2[1]
          );
        }
        if (dirty & /*ulClasses*/
        4) {
          attr(
            ul0,
            "class",
            /*ulClasses*/
            ctx2[2]
          );
        }
        if (dirty & /*sectionTitle*/
        2) {
          attr(
            p1,
            "class",
            /*sectionTitle*/
            ctx2[1]
          );
        }
        if (dirty & /*ulClasses*/
        4) {
          attr(
            ul1,
            "class",
            /*ulClasses*/
            ctx2[2]
          );
        }
        if (dirty & /*sectionSpace*/
        1) {
          attr(
            div,
            "class",
            /*sectionSpace*/
            ctx2[0]
          );
        }
      },
      i: noop,
      o: noop,
      d(detaching) {
        if (detaching) {
          detach(div);
        }
      }
    };
  }
  function instance$3($$self, $$props, $$invalidate) {
    let ulClasses;
    let { bg = "bg-white/30 dark:bg-black/15" } = $$props;
    let { border = "divide-y-[1px] *:border-surface-300-600-token" } = $$props;
    let { padding = "px-4 *:py-4" } = $$props;
    let { margin = "mt-2 *:!m-0" } = $$props;
    let { rounded = "rounded-container-token *:!rounded-none" } = $$props;
    let { sectionSpace = `space-y-4` } = $$props;
    let { sectionTitle = "font-bold" } = $$props;
    $$self.$$set = ($$new_props) => {
      $$invalidate(8, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
      if ("bg" in $$new_props) $$invalidate(3, bg = $$new_props.bg);
      if ("border" in $$new_props) $$invalidate(4, border = $$new_props.border);
      if ("padding" in $$new_props) $$invalidate(5, padding = $$new_props.padding);
      if ("margin" in $$new_props) $$invalidate(6, margin = $$new_props.margin);
      if ("rounded" in $$new_props) $$invalidate(7, rounded = $$new_props.rounded);
      if ("sectionSpace" in $$new_props) $$invalidate(0, sectionSpace = $$new_props.sectionSpace);
      if ("sectionTitle" in $$new_props) $$invalidate(1, sectionTitle = $$new_props.sectionTitle);
    };
    $$self.$$.update = () => {
      $$invalidate(2, ulClasses = `list *:items-center ${padding} ${margin} ${border} ${bg} ${rounded} ${$$props.class ?? ""}`);
    };
    $$props = exclude_internal_props($$props);
    return [sectionSpace, sectionTitle, ulClasses, bg, border, padding, margin, rounded];
  }
  class FeedBack extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$3, create_fragment$3, safe_not_equal, {
        bg: 3,
        border: 4,
        padding: 5,
        margin: 6,
        rounded: 7,
        sectionSpace: 0,
        sectionTitle: 1
      });
    }
  }
  const menuOpen = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21,15.61L19.59,17L14.58,12L19.59,7L21,8.39L17.44,12L21,15.61M3,6H16V8H3V6M3,13V11H13V13H3M3,18V16H16V18H3Z" /></svg>`;
  const menuClose = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6H13V8H3V6M3 16H13V18H3V16M3 11H15V13H3V11M16 7L14.58 8.39L18.14 12L14.58 15.61L16 17L21 12L16 7Z" /></svg>`;
  function get_each_context$1(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[8] = list[i];
    child_ctx[10] = i;
    return child_ctx;
  }
  function create_if_block_1$2(ctx) {
    let listboxitem;
    let updating_group;
    let current;
    function listboxitem_group_binding(value) {
      ctx[6](value);
    }
    let listboxitem_props = {
      name: "option",
      value: (
        /*idx*/
        ctx[10]
      ),
      class: "rounded-token",
      $$slots: { default: [create_default_slot_3$1] },
      $$scope: { ctx }
    };
    if (
      /*slected*/
      ctx[2] !== void 0
    ) {
      listboxitem_props.group = /*slected*/
      ctx[2];
    }
    listboxitem = new ListBoxItem({ props: listboxitem_props });
    binding_callbacks.push(() => bind(listboxitem, "group", listboxitem_group_binding));
    return {
      c() {
        create_component(listboxitem.$$.fragment);
      },
      m(target, anchor) {
        mount_component(listboxitem, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const listboxitem_changes = {};
        if (dirty & /*$$scope*/
        2048) {
          listboxitem_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty & /*slected*/
        4) {
          updating_group = true;
          listboxitem_changes.group = /*slected*/
          ctx2[2];
          add_flush_callback(() => updating_group = false);
        }
        listboxitem.$set(listboxitem_changes);
      },
      i(local) {
        if (current) return;
        transition_in(listboxitem.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(listboxitem.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(listboxitem, detaching);
      }
    };
  }
  function create_default_slot_3$1(ctx) {
    let t_1_value = (
      /*option*/
      ctx[8].name + ""
    );
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_each_block$1(ctx) {
    let if_block_anchor;
    let current;
    let if_block = (!("show" in /*option*/
    ctx[8]) || /*option*/
    ctx[8].show) && create_if_block_1$2(ctx);
    return {
      c() {
        if (if_block) if_block.c();
        if_block_anchor = empty();
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, if_block_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        if (!("show" in /*option*/
        ctx2[8]) || /*option*/
        ctx2[8].show) if_block.p(ctx2, dirty);
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(if_block_anchor);
        }
        if (if_block) if_block.d(detaching);
      }
    };
  }
  function create_default_slot_2$1(ctx) {
    let each_1_anchor;
    let current;
    let each_value = ensure_array_like(
      /*optionList*/
      ctx[5]
    );
    let each_blocks = [];
    for (let i = 0; i < each_value.length; i += 1) {
      each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
    }
    const out = (i) => transition_out(each_blocks[i], 1, 1, () => {
      each_blocks[i] = null;
    });
    return {
      c() {
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        each_1_anchor = empty();
      },
      m(target, anchor) {
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(target, anchor);
          }
        }
        insert(target, each_1_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        if (dirty & /*slected, optionList*/
        36) {
          each_value = ensure_array_like(
            /*optionList*/
            ctx2[5]
          );
          let i;
          for (i = 0; i < each_value.length; i += 1) {
            const child_ctx = get_each_context$1(ctx2, each_value, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
              transition_in(each_blocks[i], 1);
            } else {
              each_blocks[i] = create_each_block$1(child_ctx);
              each_blocks[i].c();
              transition_in(each_blocks[i], 1);
              each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
            }
          }
          group_outros();
          for (i = each_value.length; i < each_blocks.length; i += 1) {
            out(i);
          }
          check_outros();
        }
      },
      i(local) {
        if (current) return;
        for (let i = 0; i < each_value.length; i += 1) {
          transition_in(each_blocks[i]);
        }
        current = true;
      },
      o(local) {
        each_blocks = each_blocks.filter(Boolean);
        for (let i = 0; i < each_blocks.length; i += 1) {
          transition_out(each_blocks[i]);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(each_1_anchor);
        }
        destroy_each(each_blocks, detaching);
      }
    };
  }
  function create_default_slot_1$1(ctx) {
    let h3;
    let t_1_value = (
      /*optionList*/
      (ctx[5][
        /*slected*/
        ctx[2]
      ].name || "设置") + ""
    );
    let t_1;
    return {
      c() {
        h3 = element("h3");
        t_1 = text(t_1_value);
        attr(h3, "class", "h3");
      },
      m(target, anchor) {
        insert(target, h3, anchor);
        append(h3, t_1);
      },
      p(ctx2, dirty) {
        if (dirty & /*slected*/
        4 && t_1_value !== (t_1_value = /*optionList*/
        (ctx2[5][
          /*slected*/
          ctx2[2]
        ].name || "设置") + "")) set_data(t_1, t_1_value);
      },
      d(detaching) {
        if (detaching) {
          detach(h3);
        }
      }
    };
  }
  function create_else_block$1(ctx) {
    let html_tag;
    let html_anchor;
    return {
      c() {
        html_tag = new HtmlTag(false);
        html_anchor = empty();
        html_tag.a = html_anchor;
      },
      m(target, anchor) {
        html_tag.m(menuOpen, target, anchor);
        insert(target, html_anchor, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(html_anchor);
          html_tag.d();
        }
      }
    };
  }
  function create_if_block$2(ctx) {
    let html_tag;
    let html_anchor;
    return {
      c() {
        html_tag = new HtmlTag(false);
        html_anchor = empty();
        html_tag.a = html_anchor;
      },
      m(target, anchor) {
        html_tag.m(menuClose, target, anchor);
        insert(target, html_anchor, anchor);
      },
      d(detaching) {
        if (detaching) {
          detach(html_anchor);
          html_tag.d();
        }
      }
    };
  }
  function create_lead_slot(ctx) {
    let button;
    let i;
    let mounted;
    let dispose;
    function select_block_type(ctx2, dirty) {
      if (
        /*showListbox*/
        ctx2[1]
      ) return create_if_block$2;
      return create_else_block$1;
    }
    let current_block_type = select_block_type(ctx);
    let if_block = current_block_type(ctx);
    return {
      c() {
        button = element("button");
        i = element("i");
        if_block.c();
        attr(i, "class", "w-8 fill-current");
        attr(button, "type", "button");
        attr(button, "class", "btn-icon hover:variant-soft-surface ml-1");
      },
      m(target, anchor) {
        insert(target, button, anchor);
        append(button, i);
        if_block.m(i, null);
        if (!mounted) {
          dispose = listen(
            button,
            "click",
            /*click_handler*/
            ctx[7]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (current_block_type !== (current_block_type = select_block_type(ctx2))) {
          if_block.d(1);
          if_block = current_block_type(ctx2);
          if (if_block) {
            if_block.c();
            if_block.m(i, null);
          }
        }
      },
      d(detaching) {
        if (detaching) {
          detach(button);
        }
        if_block.d();
        mounted = false;
        dispose();
      }
    };
  }
  function create_default_slot$1(ctx) {
    let div1;
    let listbox;
    let t0;
    let appbar;
    let t1;
    let div0;
    let switch_instance;
    let div1_class_value;
    let current;
    listbox = new ListBox({
      props: {
        class: "pt-4 pr-6 row-start-1 row-span-2 " + sidebarWidth + " transition-[transform] " + /*transform*/
        ctx[3],
        $$slots: { default: [create_default_slot_2$1] },
        $$scope: { ctx }
      }
    });
    appbar = new AppBar({
      props: {
        padding: "py-2",
        background: "bg-transparent",
        class: "mr-6 border-b border-surface-800-100-token",
        $$slots: {
          lead: [create_lead_slot],
          default: [create_default_slot_1$1]
        },
        $$scope: { ctx }
      }
    });
    var switch_value = (
      /*optionList*/
      ctx[5][
        /*slected*/
        ctx[2]
      ].component
    );
    function switch_props(ctx2, dirty) {
      return {
        props: {
          bg: "bg-white/30 dark:bg-surface-500/20 backdrop-blur-sm"
        }
      };
    }
    if (switch_value) {
      switch_instance = construct_svelte_component(switch_value, switch_props());
    }
    return {
      c() {
        div1 = element("div");
        create_component(listbox.$$.fragment);
        t0 = space();
        create_component(appbar.$$.fragment);
        t1 = space();
        div0 = element("div");
        if (switch_instance) create_component(switch_instance.$$.fragment);
        attr(div0, "class", "mt-4 pr-4 scrollbar-track-transparent scrollbar-thumb-slate-400/50 scrollbar-corner-transparent scrollbar-thin overflow-y-auto");
        set_style(div0, "scrollbar-gutter", "stable");
        attr(div1, "class", div1_class_value = "h-full pt-4 pb-6 pl-6 grid grid-rows-[auto_1fr] transition-[grid-template-columns] " + /*gridCol*/
        ctx[4]);
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        mount_component(listbox, div1, null);
        append(div1, t0);
        mount_component(appbar, div1, null);
        append(div1, t1);
        append(div1, div0);
        if (switch_instance) mount_component(switch_instance, div0, null);
        current = true;
      },
      p(ctx2, dirty) {
        const listbox_changes = {};
        if (dirty & /*transform*/
        8) listbox_changes.class = "pt-4 pr-6 row-start-1 row-span-2 " + sidebarWidth + " transition-[transform] " + /*transform*/
        ctx2[3];
        if (dirty & /*$$scope, slected*/
        2052) {
          listbox_changes.$$scope = { dirty, ctx: ctx2 };
        }
        listbox.$set(listbox_changes);
        const appbar_changes = {};
        if (dirty & /*$$scope, showListbox, slected*/
        2054) {
          appbar_changes.$$scope = { dirty, ctx: ctx2 };
        }
        appbar.$set(appbar_changes);
        if (dirty & /*slected*/
        4 && switch_value !== (switch_value = /*optionList*/
        ctx2[5][
          /*slected*/
          ctx2[2]
        ].component)) {
          if (switch_instance) {
            group_outros();
            const old_component = switch_instance;
            transition_out(old_component.$$.fragment, 1, 0, () => {
              destroy_component(old_component, 1);
            });
            check_outros();
          }
          if (switch_value) {
            switch_instance = construct_svelte_component(switch_value, switch_props());
            create_component(switch_instance.$$.fragment);
            transition_in(switch_instance.$$.fragment, 1);
            mount_component(switch_instance, div0, null);
          } else {
            switch_instance = null;
          }
        }
        if (!current || dirty & /*gridCol*/
        16 && div1_class_value !== (div1_class_value = "h-full pt-4 pb-6 pl-6 grid grid-rows-[auto_1fr] transition-[grid-template-columns] " + /*gridCol*/
        ctx2[4])) {
          attr(div1, "class", div1_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(listbox.$$.fragment, local);
        transition_in(appbar.$$.fragment, local);
        if (switch_instance) transition_in(switch_instance.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(listbox.$$.fragment, local);
        transition_out(appbar.$$.fragment, local);
        if (switch_instance) transition_out(switch_instance.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        destroy_component(listbox);
        destroy_component(appbar);
        if (switch_instance) destroy_component(switch_instance);
      }
    };
  }
  function create_fragment$2(ctx) {
    let modalwrapper;
    let current;
    modalwrapper = new ModalWrapper({
      props: {
        parent: (
          /*parent*/
          ctx[0]
        ),
        height: "h-screen md:h-[600px]",
        width: "w-screen md:max-w-screen-md xl:max-w-screen-lg",
        padding: "",
        $$slots: { default: [create_default_slot$1] },
        $$scope: { ctx }
      }
    });
    return {
      c() {
        create_component(modalwrapper.$$.fragment);
      },
      m(target, anchor) {
        mount_component(modalwrapper, target, anchor);
        current = true;
      },
      p(ctx2, [dirty]) {
        const modalwrapper_changes = {};
        if (dirty & /*parent*/
        1) modalwrapper_changes.parent = /*parent*/
        ctx2[0];
        if (dirty & /*$$scope, gridCol, slected, showListbox, transform*/
        2078) {
          modalwrapper_changes.$$scope = { dirty, ctx: ctx2 };
        }
        modalwrapper.$set(modalwrapper_changes);
      },
      i(local) {
        if (current) return;
        transition_in(modalwrapper.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(modalwrapper.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(modalwrapper, detaching);
      }
    };
  }
  const sidebarWidth = "w-[140px]";
  function instance$2($$self, $$props, $$invalidate) {
    let gridCol;
    let transform;
    let { parent } = $$props;
    let slected = 0;
    const optionList = [
      {
        name: t("setting.save_to.title"),
        component: SaveTo
      },
      {
        name: t("setting.ugoira.title"),
        component: UgoiraConvert,
        show: env.isPixiv()
      },
      {
        name: t("setting.history.title"),
        component: DownloadHistory
      },
      {
        name: t("setting.button_position.title"),
        component: BtnPosition
      },
      {
        name: t("setting.others.title"),
        component: Others
      },
      {
        name: t("setting.feedback.title"),
        component: FeedBack
      }
    ];
    let showListbox = true;
    function listboxitem_group_binding(value) {
      slected = value;
      $$invalidate(2, slected);
    }
    const click_handler = () => $$invalidate(1, showListbox = !showListbox);
    $$self.$$set = ($$props2) => {
      if ("parent" in $$props2) $$invalidate(0, parent = $$props2.parent);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty & /*showListbox*/
      2) {
        $$invalidate(4, gridCol = showListbox ? "grid-cols-[140px_1fr]" : "grid-cols-[0px_1fr]");
      }
      if ($$self.$$.dirty & /*showListbox*/
      2) {
        $$invalidate(3, transform = showListbox ? "translate-x-0" : "-translate-x-full");
      }
    };
    return [
      parent,
      showListbox,
      slected,
      transform,
      gridCol,
      optionList,
      listboxitem_group_binding,
      click_handler
    ];
  }
  class Config extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance$2, create_fragment$2, safe_not_equal, { parent: 0 });
    }
  }
  const defaultData = {
    selectedFilters: null,
    blacklistTag: [],
    whitelistTag: [],
    downloadAllPages: true,
    pageStart: 1,
    pageEnd: 1,
    retryFailed: false
  };
  const STORAGE_KEY = "pdl-downloader_option";
  const saveData = localStorage.getItem(STORAGE_KEY);
  const storeData = saveData ? JSON.parse(saveData) : defaultData;
  function storeBuilder(data) {
    const obj = {};
    for (const key in defaultData) {
      if (!(key in data)) {
        obj[key] = writable(defaultData[key]);
      } else {
        obj[key] = writable(data[key]);
      }
    }
    return obj;
  }
  const optionStore = storeBuilder(storeData);
  const watchStoreData = derived(Object.values(optionStore), (data) => {
    const obj = {};
    Object.keys(optionStore).forEach((key, idx) => {
      obj[key] = data[idx];
    });
    return obj;
  });
  watchStoreData.subscribe((val) => {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(val));
  });
  function useChannel() {
    const CHANNEL_NAME = "pdl_batch-download";
    const TAB_ID = String(Math.random());
    const channel = new BroadcastChannel(CHANNEL_NAME);
    const queue = [];
    let downloading = false;
    let pending = false;
    let onFullfilled;
    let onRejected;
    channel.addEventListener("message", (evt) => {
      const { data } = evt;
      switch (data.type) {
        case 5:
          logger.info("channel receive: QUERY");
          downloading && channel.postMessage({
            type: 0,
            value: null
          });
          break;
        case 0:
          logger.info("channel receive: SET_PENDING");
          !pending && (pending = true);
          break;
        case 1:
          logger.info("channel receive: SET_IDLE");
          pending && (pending = false);
          break;
        case 2:
          logger.info("channel receive: ADD_QUEUE");
          downloading && queue.push(data.value);
          break;
        case 3:
          logger.info("channel receive: REMOVE_QUEUE");
          if (downloading) {
            const idx = queue.findIndex((id) => id === data.value);
            idx !== -1 && queue.splice(idx, 1);
          }
          break;
        case 4:
          logger.info("channel receive: PROCESS_NEXT", TAB_ID, data.value);
          if (data.value[0] !== TAB_ID) return;
          queue.push(...data.value.slice(1));
          pending = false;
          downloading = true;
          onFullfilled();
          break;
      }
    });
    window.addEventListener("unload", () => {
      if (pending) {
        channel.postMessage({
          type: 3,
          value: TAB_ID
        });
        return;
      }
      if (downloading) {
        queue.length ? channel.postMessage({
          type: 4,
          value: queue
        }) : channel.postMessage({
          type: 1,
          value: null
        });
      }
    });
    channel.postMessage({
      type: 5,
      value: null
    });
    return {
      async requestDownload() {
        if (!pending) {
          downloading = true;
          channel.postMessage({
            type: 0,
            value: null
          });
          logger.info("channel post: SET_PENDING");
          return;
        }
        const waitUntilIdle = new Promise((resolve, reject) => {
          onFullfilled = resolve;
          onRejected = reject;
        });
        channel.postMessage({
          type: 2,
          value: TAB_ID
        });
        logger.info("channel post: ADD_QUEUE", TAB_ID);
        return waitUntilIdle;
      },
      cancelDownloadRequest(reason) {
        if (!pending) return;
        channel.postMessage({
          type: 3,
          value: TAB_ID
        });
        logger.info("channel post: REMOVE_QUEUE", TAB_ID);
        onRejected(reason);
      },
      processNextDownload() {
        if (!downloading) return;
        downloading = false;
        if (queue.length) {
          pending = true;
          channel.postMessage({
            type: 4,
            value: queue
          });
          queue.length = 0;
          logger.info("channel post: PROCESS_NEXT");
        } else {
          channel.postMessage({
            type: 1,
            value: null
          });
          logger.info("channel post: SET_IDLE");
        }
      }
    };
  }
  const ERROR_MASKED = "Masked.";
  function defineBatchDownload(downloaderConfig) {
    const artworkCount = writable(0);
    const successd = writable([]);
    const failed = writable([]);
    const excluded = writable([]);
    const downloading = writable(false);
    const log = writable();
    const { requestDownload, cancelDownloadRequest, processNextDownload } = useChannel();
    const tasks2 = [];
    const failedTasks = [];
    const unavaliableTasks = [];
    let controller;
    let downloadCompleted;
    let downloadAbort;
    const readonlyStore = {
      artworkCount: readonly(artworkCount),
      successd: readonly(successd),
      failed: readonly(failed),
      excluded: readonly(excluded),
      downloading: readonly(downloading),
      log: readonly(log)
    };
    let $pageStart;
    let $pageEnd;
    let $downloadAllPages;
    let $blacklistTag = [];
    let $whitelistTag = [];
    let $retryFailed = false;
    const includeFilters = [];
    const excludeFilters = [];
    const {
      selectedFilters,
      blacklistTag,
      whitelistTag,
      downloadAllPages,
      pageStart,
      pageEnd,
      retryFailed
    } = optionStore;
    const watchPageRange = derived([downloadAllPages, pageStart, pageEnd], (data) => data);
    watchPageRange.subscribe(([downloadAllPages2, pageStart2, pageEnd2]) => {
      $downloadAllPages = downloadAllPages2;
      $pageStart = pageStart2;
      $pageEnd = pageEnd2;
    });
    selectedFilters.subscribe((selected) => {
      if (!selected) return;
      includeFilters.length = 0;
      excludeFilters.length = 0;
      selected.forEach((id) => {
        const filter = downloaderConfig.filterOption.filters.find((filter2) => filter2.id === id);
        if (filter) {
          if (filter.type === "include") {
            includeFilters.push(filter.fn);
          } else {
            excludeFilters.push(filter.fn);
          }
        }
      });
    });
    blacklistTag.subscribe((val) => {
      $blacklistTag = [...val];
    });
    whitelistTag.subscribe((val) => {
      $whitelistTag = [...val];
    });
    retryFailed.subscribe((val) => {
      $retryFailed = val;
    });
    const checkIfDownloadCompleted = derived(
      [artworkCount, successd, failed, excluded],
      ([$artworkCount, $successd, $failed, $excluded]) => $artworkCount === $successd.length + $failed.length + $excluded.length
    );
    checkIfDownloadCompleted.subscribe((isDone) => {
      isDone && (downloadCompleted == null ? void 0 : downloadCompleted());
    });
    function reset() {
      artworkCount.set(0);
      successd.set([]);
      failed.set([]);
      excluded.set([]);
      tasks2.length = 0;
      failedTasks.length = 0;
      unavaliableTasks.length = 0;
      controller = null;
      downloadCompleted = () => {
      };
      downloadAbort = () => {
      };
      writeLog("Info", "Reset store.");
    }
    function setDownloading(isDownloading) {
      downloading.update((val) => {
        if (val && isDownloading) throw new Error("Already downloading.");
        return isDownloading;
      });
    }
    function setArtworkCount(num) {
      artworkCount.set(num);
    }
    function addSuccessd(id) {
      successd.update((val) => {
        if (Array.isArray(id)) {
          val.push(...id);
          writeLog("Complete", id[id.length - 1]);
        } else {
          val.push(id);
          writeLog("Complete", id);
        }
        return val;
      });
    }
    function addFailed(item) {
      failed.update((val) => {
        let id;
        let reason;
        if (Array.isArray(item)) {
          val.push(...item);
          const lastItem = item[item.length - 1];
          id = lastItem.id;
          reason = lastItem.reason;
        } else {
          val.push(item);
          id = item.id;
          reason = item.reason;
        }
        if (reason instanceof Error || typeof reason === "string") {
          writeLog("Fail", id, reason);
        }
        return val;
      });
    }
    function addExcluded(id) {
      excluded.update((val) => {
        if (Array.isArray(id)) {
          val.push(...id);
          writeLog("Info", `${id.length} was excluded...`);
        } else {
          val.push(id);
          writeLog("Info", `${id} was excluded...`);
        }
        return val;
      });
    }
    function writeLog(type, arg, error) {
      const item = {
        type,
        message: ""
      };
      switch (type) {
        case "Error":
          if (!(arg instanceof Error))
            throw new TypeError("error` is expected to be error, but got " + typeof arg);
          item.message = `[${arg.name}] ${arg.message}`;
          break;
        case "Fail":
          if (typeof arg !== "string")
            throw new TypeError("`id` is expected to be string, but got " + typeof arg);
          typeof error === "string" ? item.message = `[Fail] ${arg}...${error}` : item.message = `[Fail] ${arg}...${error ? error.name + ":" + error.message : ""}`;
          break;
        default:
          item.message = `[${type}] ${arg}`;
          break;
      }
      log.set(item);
    }
    function filterTag(partialMeta, customTagFilter) {
      if (!("tags" in partialMeta) || !Array.isArray(partialMeta.tags)) return true;
      const defaultTagFilter = (userTags, metaTags) => userTags.some((tag) => metaTags.includes(tag));
      customTagFilter ?? (customTagFilter = defaultTagFilter);
      if ($whitelistTag.length) {
        return customTagFilter($whitelistTag, partialMeta.tags);
      }
      if ($blacklistTag.length) {
        return !customTagFilter($blacklistTag, partialMeta.tags);
      }
      return true;
    }
    async function checkValidity(partialMeta) {
      try {
        const { enableTagFilter } = downloaderConfig.filterOption;
        if (enableTagFilter === true) {
          if (!filterTag(partialMeta)) return false;
        } else if (enableTagFilter) {
          if (!filterTag(partialMeta, enableTagFilter)) return false;
        }
        if (!includeFilters.length) return false;
        for (let i = 0; i < excludeFilters.length; i++) {
          const fn = excludeFilters[i];
          const isExcluded = await fn(partialMeta);
          if (isExcluded) return false;
        }
        for (let i = 0; i < includeFilters.length; i++) {
          const fn = includeFilters[i];
          const isValid = await fn(partialMeta);
          if (isValid) return true;
        }
      } catch (error) {
        console.error(error);
      }
      return false;
    }
    async function batchDownload(fnId, ...restArgs) {
      setDownloading(true);
      writeLog("Info", "Start download...");
      reset();
      controller = new AbortController();
      const signal = controller.signal;
      let downloadError;
      signal.addEventListener(
        "abort",
        () => {
          cancelDownloadRequest(signal.reason);
          downloadAbort == null ? void 0 : downloadAbort(signal.reason);
          downloaderConfig.onDownloadAbort(tasks2);
        },
        { once: true }
      );
      let generator;
      try {
        const pageIdItem = getGenPageIdItem(fnId);
        if (!pageIdItem || !("fn" in pageIdItem))
          throw new Error("Invalid generator id: " + fnId);
        generator = getGenerator(pageIdItem, ...restArgs);
        writeLog("Info", "Waiting for other downloads to finish...");
        await requestDownload();
        await dispatchDownload(generator, pageIdItem.filterWhenGenerateIngPage, signal);
        if ($retryFailed && failedTasks.length) {
          writeLog("Info", "Retry...");
          generator = retryGenerator(
            get_store_value(artworkCount),
            failedTasks.slice(),
            unavaliableTasks.slice()
          );
          failedTasks.length = 0;
          unavaliableTasks.length = 0;
          failed.set([]);
          await dispatchDownload(generator, pageIdItem.filterWhenGenerateIngPage, signal);
        }
        writeLog("Info", "Download complete.");
      } catch (error) {
        downloadError = error;
        generator == null ? void 0 : generator.return();
        if (!signal.aborted) {
          controller.abort(error);
        }
        if (error instanceof Error) {
          writeLog("Error", error);
        }
      }
      setDownloading(false);
      processNextDownload();
      if (downloadError) throw downloadError;
    }
    function getGenPageIdItem(fnId) {
      const { pageMatch } = downloaderConfig;
      for (const key in pageMatch) {
        if (key === fnId) {
          return pageMatch[key];
        }
      }
    }
    function getGenerator(item, ...restArgs) {
      let generator;
      if (!$downloadAllPages && $pageEnd < $pageStart)
        throw new Error("End page must not be less than the start page.");
      const pageRange = $downloadAllPages ? null : [$pageStart, $pageEnd];
      if (item.filterWhenGenerateIngPage) {
        generator = item.fn(pageRange, checkValidity, ...restArgs);
      } else {
        generator = item.fn(pageRange, ...restArgs);
      }
      return generator;
    }
    function* retryGenerator(total, failedArtworks, unavaliableTasks2) {
      yield {
        total,
        page: 0,
        avaliable: failedArtworks,
        invalid: [],
        unavaliable: unavaliableTasks2
      };
    }
    async function dispatchDownload(generator, filterWhenGenerateIngPage, signal) {
      signal.throwIfAborted();
      const waitUntilDownloadComplete = new Promise((resolve, reject) => {
        downloadCompleted = resolve;
        downloadAbort = reject;
      });
      const THRESHOLD = 5;
      const { parseMetaByArtworkId, downloadByArtworkId } = downloaderConfig;
      const dlPromise = [];
      let result;
      let status429 = false;
      const failedHanlderFactory = (id) => {
        return (reason) => {
          if (signal.aborted) return;
          addFailed({ id, reason });
          reason && logger.error(reason);
          reason !== ERROR_MASKED && failedTasks.push(id);
          if (reason instanceof RequestError && reason.status === 429) {
            status429 = true;
          }
        };
      };
      while ((result = await Promise.race([generator.next(), waitUntilDownloadComplete])) && !result.done) {
        const { total, avaliable, invalid, unavaliable } = result.value;
        logger.info(total, avaliable, invalid, unavaliable);
        signal.throwIfAborted();
        setArtworkCount(total);
        invalid.length && addExcluded(invalid);
        if (unavaliable.length) {
          addFailed(unavaliable.map((id) => ({ id, reason: ERROR_MASKED })));
          unavaliableTasks.push(...unavaliable);
        }
        if (!avaliable.length) await Promise.race([sleep(1500), waitUntilDownloadComplete]);
        for (const id of avaliable) {
          if (status429) {
            writeLog("Error", new Error("Http status: 429, wait for 30 seconds."));
            await Promise.race([sleep(3e4), waitUntilDownloadComplete]);
            status429 = false;
          }
          const artworkMeta = await parseMetaByArtworkId(id).catch(failedHanlderFactory(id));
          signal.throwIfAborted();
          if (!artworkMeta) continue;
          if (!filterWhenGenerateIngPage) {
            const isValid = await checkValidity(artworkMeta);
            if (!isValid) {
              addExcluded(id);
              await Promise.race([sleep(1e3), waitUntilDownloadComplete]);
              continue;
            }
          }
          writeLog("Add", id);
          const taskId = generateTaskID(id);
          const processDownload = downloadByArtworkId(artworkMeta, taskId).then(function handleSucccess() {
            !signal.aborted && addSuccessd(id);
          }, failedHanlderFactory(id)).finally(function removeTask() {
            const idx = tasks2.findIndex((storeId) => storeId === id);
            idx !== -1 && tasks2.splice(idx, 1);
          });
          tasks2.push(taskId);
          dlPromise.push(processDownload);
          if (dlPromise.length >= THRESHOLD) {
            await Promise.race([...dlPromise, waitUntilDownloadComplete]);
            dlPromise.length = 0;
          } else {
            await Promise.race([sleep(1e3), waitUntilDownloadComplete]);
          }
        }
      }
      return waitUntilDownloadComplete;
    }
    function abort() {
      controller && controller.abort(new CancelError());
    }
    function generateTaskID(id) {
      return id + "_" + Math.random().toString(36).slice(2);
    }
    function overwrite(partialConfig) {
      for (const key in partialConfig) {
        const val = partialConfig[key];
        if (val !== void 0) {
          downloaderConfig[key] = val;
        }
      }
      return definition;
    }
    function definition() {
      return {
        ...readonlyStore,
        batchDownload,
        abort,
        overwrite
      };
    }
    return definition;
  }
  const downloadSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm-32-316v116h-67c-10.7 0-16 12.9-8.5 20.5l99 99c4.7 4.7 12.3 4.7 17 0l99-99c7.6-7.6 2.2-20.5-8.5-20.5h-67V140c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12z"></path></svg>`;
  const stopSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm101.8-262.2L295.6 256l62.2 62.2c4.7 4.7 4.7 12.3 0 17l-22.6 22.6c-4.7 4.7-12.3 4.7-17 0L256 295.6l-62.2 62.2c-4.7 4.7-12.3 4.7-17 0l-22.6-22.6c-4.7-4.7-4.7-12.3 0-17l62.2-62.2-62.2-62.2c-4.7-4.7-4.7-12.3 0-17l22.6-22.6c4.7-4.7 12.3-4.7 17 0l62.2 62.2 62.2-62.2c4.7-4.7 12.3-4.7 17 0l22.6 22.6c4.7 4.7 4.7 12.3 0 17z"></path></svg>
`;
  const playSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M10,16.5L16,12L10,7.5V16.5Z" /></svg>`;
  const stopOutLineSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4M9,9V15H15V9" /></svg>`;
  const downloadMultipleSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9,1V7H5L12,14L19,7H15V1H9M5,16V18H19V16H5M5,20V22H19V20H5Z" /></svg>`;
  function get_each_context(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[80] = list[i][0];
    child_ctx[81] = list[i][1];
    return child_ctx;
  }
  function get_each_context_1(ctx, list, i) {
    const child_ctx = ctx.slice();
    child_ctx[80] = list[i].id;
    child_ctx[84] = list[i].name;
    return child_ctx;
  }
  function create_if_block_5(ctx) {
    let div1;
    let t_1;
    let div0;
    let current_block_type_index;
    let if_block1;
    let div1_transition;
    let current;
    let if_block0 = !/*$downloading*/
    ctx[5] && create_if_block_10(ctx);
    const if_block_creators = [create_if_block_6, create_else_block];
    const if_blocks = [];
    function select_block_type_1(ctx2, dirty) {
      if (!/*$downloading*/
      ctx2[5]) return 0;
      return 1;
    }
    current_block_type_index = select_block_type_1(ctx);
    if_block1 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
    return {
      c() {
        div1 = element("div");
        if (if_block0) if_block0.c();
        t_1 = space();
        div0 = element("div");
        if_block1.c();
        attr(div0, "class", "flex relative my-4");
        attr(div1, "data-theme", "skeleton");
        attr(div1, "class", "card px-4 fixed right-20 top-36 w-[600px] *:text-sm shadow-xl bg-scroll");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        if (if_block0) if_block0.m(div1, null);
        append(div1, t_1);
        append(div1, div0);
        if_blocks[current_block_type_index].m(div0, null);
        current = true;
      },
      p(ctx2, dirty) {
        if (!/*$downloading*/
        ctx2[5]) {
          if (if_block0) {
            if_block0.p(ctx2, dirty);
            if (dirty[0] & /*$downloading*/
            32) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_10(ctx2);
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(div1, t_1);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        let previous_block_index = current_block_type_index;
        current_block_type_index = select_block_type_1(ctx2);
        if (current_block_type_index === previous_block_index) {
          if_blocks[current_block_type_index].p(ctx2, dirty);
        } else {
          group_outros();
          transition_out(if_blocks[previous_block_index], 1, 1, () => {
            if_blocks[previous_block_index] = null;
          });
          check_outros();
          if_block1 = if_blocks[current_block_type_index];
          if (!if_block1) {
            if_block1 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2);
            if_block1.c();
          } else {
            if_block1.p(ctx2, dirty);
          }
          transition_in(if_block1, 1);
          if_block1.m(div0, null);
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block0);
        transition_in(if_block1);
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div1_transition) div1_transition = create_bidirectional_transition(div1, fly, { x: 50, opacity: 0 }, true);
            div1_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        transition_out(if_block0);
        transition_out(if_block1);
        if (local) {
          if (!div1_transition) div1_transition = create_bidirectional_transition(div1, fly, { x: 50, opacity: 0 }, false);
          div1_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        if (if_block0) if_block0.d();
        if_blocks[current_block_type_index].d();
        if (detaching && div1_transition) div1_transition.end();
      }
    };
  }
  function create_if_block_10(ctx) {
    let div;
    let tabgroup;
    let t_1;
    let hr;
    let div_transition;
    let current;
    tabgroup = new TabGroup({
      props: {
        regionList: "text-surface-700-200-token",
        class: "text-sm",
        $$slots: {
          panel: [create_panel_slot],
          default: [create_default_slot_3]
        },
        $$scope: { ctx }
      }
    });
    return {
      c() {
        div = element("div");
        create_component(tabgroup.$$.fragment);
        t_1 = space();
        hr = element("hr");
        attr(hr, "class", "!border-t-1 my-4");
        attr(div, "class", "downloader-filter");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        mount_component(tabgroup, div, null);
        append(div, t_1);
        append(div, hr);
        current = true;
      },
      p(ctx2, dirty) {
        const tabgroup_changes = {};
        if (dirty[0] & /*$downloadAllPages, $pageEnd, $pageStart, downloaderConfig, $selectedFilters, tabSet, $whitelistTag, $blacklistTag, $retryFailed*/
        8327169 | dirty[2] & /*$$scope*/
        33554432) {
          tabgroup_changes.$$scope = { dirty, ctx: ctx2 };
        }
        tabgroup.$set(tabgroup_changes);
      },
      i(local) {
        if (current) return;
        transition_in(tabgroup.$$.fragment, local);
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div_transition) div_transition = create_bidirectional_transition(div, slide, {}, true);
            div_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        transition_out(tabgroup.$$.fragment, local);
        if (local) {
          if (!div_transition) div_transition = create_bidirectional_transition(div, slide, {}, false);
          div_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        destroy_component(tabgroup);
        if (detaching && div_transition) div_transition.end();
      }
    };
  }
  function create_default_slot_6(ctx) {
    let t_1_value = t("downloader.category.tab_name") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_if_block_15(ctx) {
    let tab;
    let updating_group;
    let current;
    function tab_group_binding(value) {
      ctx[53](value);
    }
    let tab_props = {
      name: "tag_filter",
      value: 1,
      $$slots: { default: [create_default_slot_5] },
      $$scope: { ctx }
    };
    if (
      /*tabSet*/
      ctx[12] !== void 0
    ) {
      tab_props.group = /*tabSet*/
      ctx[12];
    }
    tab = new Tab({ props: tab_props });
    binding_callbacks.push(() => bind(tab, "group", tab_group_binding));
    return {
      c() {
        create_component(tab.$$.fragment);
      },
      m(target, anchor) {
        mount_component(tab, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const tab_changes = {};
        if (dirty[2] & /*$$scope*/
        33554432) {
          tab_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty[0] & /*tabSet*/
        4096) {
          updating_group = true;
          tab_changes.group = /*tabSet*/
          ctx2[12];
          add_flush_callback(() => updating_group = false);
        }
        tab.$set(tab_changes);
      },
      i(local) {
        if (current) return;
        transition_in(tab.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(tab.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(tab, detaching);
      }
    };
  }
  function create_default_slot_5(ctx) {
    let t_1_value = t("downloader.tag_filter.tab_name") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_4(ctx) {
    let t_1_value = t("downloader.others.tab_name") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_3(ctx) {
    let tab0;
    let updating_group;
    let t0;
    let t1;
    let tab1;
    let updating_group_1;
    let current;
    function tab0_group_binding(value) {
      ctx[52](value);
    }
    let tab0_props = {
      name: "category",
      value: 0,
      $$slots: { default: [create_default_slot_6] },
      $$scope: { ctx }
    };
    if (
      /*tabSet*/
      ctx[12] !== void 0
    ) {
      tab0_props.group = /*tabSet*/
      ctx[12];
    }
    tab0 = new Tab({ props: tab0_props });
    binding_callbacks.push(() => bind(tab0, "group", tab0_group_binding));
    let if_block = !!/*downloaderConfig*/
    ctx[0].filterOption.enableTagFilter && create_if_block_15(ctx);
    function tab1_group_binding(value) {
      ctx[54](value);
    }
    let tab1_props = {
      name: "tag_filter",
      value: 2,
      $$slots: { default: [create_default_slot_4] },
      $$scope: { ctx }
    };
    if (
      /*tabSet*/
      ctx[12] !== void 0
    ) {
      tab1_props.group = /*tabSet*/
      ctx[12];
    }
    tab1 = new Tab({ props: tab1_props });
    binding_callbacks.push(() => bind(tab1, "group", tab1_group_binding));
    return {
      c() {
        create_component(tab0.$$.fragment);
        t0 = space();
        if (if_block) if_block.c();
        t1 = space();
        create_component(tab1.$$.fragment);
      },
      m(target, anchor) {
        mount_component(tab0, target, anchor);
        insert(target, t0, anchor);
        if (if_block) if_block.m(target, anchor);
        insert(target, t1, anchor);
        mount_component(tab1, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const tab0_changes = {};
        if (dirty[2] & /*$$scope*/
        33554432) {
          tab0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty[0] & /*tabSet*/
        4096) {
          updating_group = true;
          tab0_changes.group = /*tabSet*/
          ctx2[12];
          add_flush_callback(() => updating_group = false);
        }
        tab0.$set(tab0_changes);
        if (!!/*downloaderConfig*/
        ctx2[0].filterOption.enableTagFilter) {
          if (if_block) {
            if_block.p(ctx2, dirty);
            if (dirty[0] & /*downloaderConfig*/
            1) {
              transition_in(if_block, 1);
            }
          } else {
            if_block = create_if_block_15(ctx2);
            if_block.c();
            transition_in(if_block, 1);
            if_block.m(t1.parentNode, t1);
          }
        } else if (if_block) {
          group_outros();
          transition_out(if_block, 1, 1, () => {
            if_block = null;
          });
          check_outros();
        }
        const tab1_changes = {};
        if (dirty[2] & /*$$scope*/
        33554432) {
          tab1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_1 && dirty[0] & /*tabSet*/
        4096) {
          updating_group_1 = true;
          tab1_changes.group = /*tabSet*/
          ctx2[12];
          add_flush_callback(() => updating_group_1 = false);
        }
        tab1.$set(tab1_changes);
      },
      i(local) {
        if (current) return;
        transition_in(tab0.$$.fragment, local);
        transition_in(if_block);
        transition_in(tab1.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(tab0.$$.fragment, local);
        transition_out(if_block);
        transition_out(tab1.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t0);
          detach(t1);
        }
        destroy_component(tab0, detaching);
        if (if_block) if_block.d(detaching);
        destroy_component(tab1, detaching);
      }
    };
  }
  function create_if_block_14(ctx) {
    let div;
    let p;
    let t1;
    let slidetoggle;
    let updating_checked;
    let current;
    function slidetoggle_checked_binding(value) {
      ctx[51](value);
    }
    let slidetoggle_props = { size: "sm", name: "download-retry" };
    if (
      /*$retryFailed*/
      ctx[22] !== void 0
    ) {
      slidetoggle_props.checked = /*$retryFailed*/
      ctx[22];
    }
    slidetoggle = new SlideToggle({ props: slidetoggle_props });
    binding_callbacks.push(() => bind(slidetoggle, "checked", slidetoggle_checked_binding));
    return {
      c() {
        div = element("div");
        p = element("p");
        p.textContent = `${t("downloader.others.options.retry_failed")}`;
        t1 = space();
        create_component(slidetoggle.$$.fragment);
        attr(div, "class", "flex justify-between items-center text-base text-surface-700-200-token");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        append(div, p);
        append(div, t1);
        mount_component(slidetoggle, div, null);
        current = true;
      },
      p(ctx2, dirty) {
        const slidetoggle_changes = {};
        if (!updating_checked && dirty[0] & /*$retryFailed*/
        4194304) {
          updating_checked = true;
          slidetoggle_changes.checked = /*$retryFailed*/
          ctx2[22];
          add_flush_callback(() => updating_checked = false);
        }
        slidetoggle.$set(slidetoggle_changes);
      },
      i(local) {
        if (current) return;
        transition_in(slidetoggle.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(slidetoggle.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        destroy_component(slidetoggle);
      }
    };
  }
  function create_if_block_13(ctx) {
    let inputchip0;
    let updating_value;
    let t_1;
    let inputchip1;
    let updating_value_1;
    let current;
    function inputchip0_value_binding(value) {
      ctx[49](value);
    }
    let inputchip0_props = {
      allowUpperCase: true,
      name: "blacklist",
      chips: "variant-filled-primary",
      placeholder: t("downloader.tag_filter.placeholder.blacklist_tag")
    };
    if (
      /*$blacklistTag*/
      ctx[20] !== void 0
    ) {
      inputchip0_props.value = /*$blacklistTag*/
      ctx[20];
    }
    inputchip0 = new InputChip({ props: inputchip0_props });
    binding_callbacks.push(() => bind(inputchip0, "value", inputchip0_value_binding));
    function inputchip1_value_binding(value) {
      ctx[50](value);
    }
    let inputchip1_props = {
      allowUpperCase: true,
      name: "whitelist",
      chips: "variant-filled-primary",
      placeholder: t("downloader.tag_filter.placeholder.whitelist_tag"),
      class: "my-4"
    };
    if (
      /*$whitelistTag*/
      ctx[21] !== void 0
    ) {
      inputchip1_props.value = /*$whitelistTag*/
      ctx[21];
    }
    inputchip1 = new InputChip({ props: inputchip1_props });
    binding_callbacks.push(() => bind(inputchip1, "value", inputchip1_value_binding));
    return {
      c() {
        create_component(inputchip0.$$.fragment);
        t_1 = space();
        create_component(inputchip1.$$.fragment);
      },
      m(target, anchor) {
        mount_component(inputchip0, target, anchor);
        insert(target, t_1, anchor);
        mount_component(inputchip1, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const inputchip0_changes = {};
        if (!updating_value && dirty[0] & /*$blacklistTag*/
        1048576) {
          updating_value = true;
          inputchip0_changes.value = /*$blacklistTag*/
          ctx2[20];
          add_flush_callback(() => updating_value = false);
        }
        inputchip0.$set(inputchip0_changes);
        const inputchip1_changes = {};
        if (!updating_value_1 && dirty[0] & /*$whitelistTag*/
        2097152) {
          updating_value_1 = true;
          inputchip1_changes.value = /*$whitelistTag*/
          ctx2[21];
          add_flush_callback(() => updating_value_1 = false);
        }
        inputchip1.$set(inputchip1_changes);
      },
      i(local) {
        if (current) return;
        transition_in(inputchip0.$$.fragment, local);
        transition_in(inputchip1.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(inputchip0.$$.fragment, local);
        transition_out(inputchip1.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
        destroy_component(inputchip0, detaching);
        destroy_component(inputchip1, detaching);
      }
    };
  }
  function create_if_block_11(ctx) {
    let t0;
    let div4;
    let div0;
    let radiogroup;
    let t1;
    let div3;
    let label0;
    let div1;
    let i0;
    let t2;
    let input0;
    let t3;
    let label1;
    let div2;
    let i1;
    let t4;
    let input1;
    let current;
    let mounted;
    let dispose;
    let if_block = (
      /*downloaderConfig*/
      ctx[0].filterOption.filters.length && create_if_block_12(ctx)
    );
    radiogroup = new RadioGroup({
      props: {
        regionLabel: "text-surface-700-200-token",
        active: "variant-filled-primary",
        background: "bg-surface-400/20 dark:bg-surface-500/20",
        border: "",
        display: "flex",
        $$slots: { default: [create_default_slot] },
        $$scope: { ctx }
      }
    });
    return {
      c() {
        if (if_block) if_block.c();
        t0 = space();
        div4 = element("div");
        div0 = element("div");
        create_component(radiogroup.$$.fragment);
        t1 = space();
        div3 = element("div");
        label0 = element("label");
        div1 = element("div");
        i0 = element("i");
        t2 = space();
        input0 = element("input");
        t3 = space();
        label1 = element("label");
        div2 = element("div");
        i1 = element("i");
        t4 = space();
        input1 = element("input");
        attr(div0, "class", "flex-grow w-full");
        attr(i0, "class", "w-6 fill-current");
        attr(div1, "class", "input-group-shim !px-1 flex-none");
        attr(input0, "class", "w-20 pr-0 text-surface-700-200-token text-sm");
        attr(input0, "type", "number");
        attr(input0, "min", "1");
        attr(input0, "step", "1");
        input0.disabled = /*$downloadAllPages*/
        ctx[17];
        attr(label0, "class", "input-group input-group-divider flex [&>input]:!min-w-0 [&>input]:!border-transparent border-surface-400/20 dark:border-surface-500/20 bg-surface-400/20 dark:bg-surface-500/20");
        attr(i1, "class", "w-6 fill-current");
        attr(div2, "class", "input-group-shim !px-1 flex-none");
        attr(input1, "class", "w-20 pr-0 text-surface-700-200-token text-sm");
        attr(input1, "type", "number");
        attr(input1, "min", "1");
        attr(input1, "step", "1");
        input1.disabled = /*$downloadAllPages*/
        ctx[17];
        attr(label1, "class", "input-group input-group-divider flex [&>input]:!min-w-0 [&>input]:!border-transparent border-surface-400/20 dark:border-surface-500/20 bg-surface-400/20 dark:bg-surface-500/20");
        attr(div3, "class", "flex justify-between items-center gap-4 w-full");
        attr(div4, "class", "flex justify-between items-center my-4 gap-4");
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, t0, anchor);
        insert(target, div4, anchor);
        append(div4, div0);
        mount_component(radiogroup, div0, null);
        append(div4, t1);
        append(div4, div3);
        append(div3, label0);
        append(label0, div1);
        append(div1, i0);
        i0.innerHTML = playSvg;
        append(label0, t2);
        append(label0, input0);
        set_input_value(
          input0,
          /*$pageStart*/
          ctx[18]
        );
        append(div3, t3);
        append(div3, label1);
        append(label1, div2);
        append(div2, i1);
        i1.innerHTML = stopOutLineSvg;
        append(label1, t4);
        append(label1, input1);
        set_input_value(
          input1,
          /*$pageEnd*/
          ctx[19]
        );
        current = true;
        if (!mounted) {
          dispose = [
            action_destroyer(nonNegativeInt.call(
              null,
              input0,
              /*pageStart*/
              ctx[29]
            )),
            listen(
              input0,
              "input",
              /*input0_input_handler*/
              ctx[47]
            ),
            action_destroyer(nonNegativeInt.call(
              null,
              input1,
              /*pageEnd*/
              ctx[30]
            )),
            listen(
              input1,
              "input",
              /*input1_input_handler*/
              ctx[48]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (
          /*downloaderConfig*/
          ctx2[0].filterOption.filters.length
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
          } else {
            if_block = create_if_block_12(ctx2);
            if_block.c();
            if_block.m(t0.parentNode, t0);
          }
        } else if (if_block) {
          if_block.d(1);
          if_block = null;
        }
        const radiogroup_changes = {};
        if (dirty[0] & /*$downloadAllPages*/
        131072 | dirty[2] & /*$$scope*/
        33554432) {
          radiogroup_changes.$$scope = { dirty, ctx: ctx2 };
        }
        radiogroup.$set(radiogroup_changes);
        if (!current || dirty[0] & /*$downloadAllPages*/
        131072) {
          input0.disabled = /*$downloadAllPages*/
          ctx2[17];
        }
        if (dirty[0] & /*$pageStart*/
        262144 && to_number(input0.value) !== /*$pageStart*/
        ctx2[18]) {
          set_input_value(
            input0,
            /*$pageStart*/
            ctx2[18]
          );
        }
        if (!current || dirty[0] & /*$downloadAllPages*/
        131072) {
          input1.disabled = /*$downloadAllPages*/
          ctx2[17];
        }
        if (dirty[0] & /*$pageEnd*/
        524288 && to_number(input1.value) !== /*$pageEnd*/
        ctx2[19]) {
          set_input_value(
            input1,
            /*$pageEnd*/
            ctx2[19]
          );
        }
      },
      i(local) {
        if (current) return;
        transition_in(radiogroup.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radiogroup.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t0);
          detach(div4);
        }
        if (if_block) if_block.d(detaching);
        destroy_component(radiogroup);
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_12(ctx) {
    let div1;
    let div0;
    let each_value_1 = ensure_array_like(
      /*downloaderConfig*/
      ctx[0].filterOption.filters
    );
    let each_blocks = [];
    for (let i = 0; i < each_value_1.length; i += 1) {
      each_blocks[i] = create_each_block_1(get_each_context_1(ctx, each_value_1, i));
    }
    return {
      c() {
        div1 = element("div");
        div0 = element("div");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        attr(div0, "class", "btn-group w-full");
        attr(div1, "class", "flex justify-end items-center my-4");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, div0);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(div0, null);
          }
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*downloaderConfig, $selectedFilters*/
        65537) {
          each_value_1 = ensure_array_like(
            /*downloaderConfig*/
            ctx2[0].filterOption.filters
          );
          let i;
          for (i = 0; i < each_value_1.length; i += 1) {
            const child_ctx = get_each_context_1(ctx2, each_value_1, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
            } else {
              each_blocks[i] = create_each_block_1(child_ctx);
              each_blocks[i].c();
              each_blocks[i].m(div0, null);
            }
          }
          for (; i < each_blocks.length; i += 1) {
            each_blocks[i].d(1);
          }
          each_blocks.length = each_value_1.length;
        }
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        destroy_each(each_blocks, detaching);
      }
    };
  }
  function create_each_block_1(ctx) {
    let label;
    let div0;
    let input;
    let input_value_value;
    let value_has_changed = false;
    let t0;
    let div1;
    let t1_value = (
      /*name*/
      ctx[84] + ""
    );
    let t1;
    let t2;
    let binding_group;
    let mounted;
    let dispose;
    binding_group = init_binding_group(
      /*$$binding_groups*/
      ctx[44][0]
    );
    return {
      c() {
        label = element("label");
        div0 = element("div");
        input = element("input");
        t0 = space();
        div1 = element("div");
        t1 = text(t1_value);
        t2 = space();
        attr(input, "type", "checkbox");
        input.__value = input_value_value = /*id*/
        ctx[80];
        set_input_value(input, input.__value);
        attr(div0, "class", "w-0 h-0 overflow-hidden hidden");
        attr(div1, "class", "!m-0");
        attr(label, "class", "btn !py-2 rounded-none !transform-none cursor-pointer variant-soft-surface has-[:checked]:!variant-filled-primary text-sm w-full");
        binding_group.p(input);
      },
      m(target, anchor) {
        insert(target, label, anchor);
        append(label, div0);
        append(div0, input);
        input.checked = ~/*$selectedFilters*/
        (ctx[16] || []).indexOf(input.__value);
        append(label, t0);
        append(label, div1);
        append(div1, t1);
        append(label, t2);
        if (!mounted) {
          dispose = listen(
            input,
            "change",
            /*input_change_handler*/
            ctx[43]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*downloaderConfig*/
        1 && input_value_value !== (input_value_value = /*id*/
        ctx2[80])) {
          input.__value = input_value_value;
          set_input_value(input, input.__value);
          value_has_changed = true;
        }
        if (value_has_changed || dirty[0] & /*$selectedFilters, downloaderConfig*/
        65537) {
          input.checked = ~/*$selectedFilters*/
          (ctx2[16] || []).indexOf(input.__value);
        }
        if (dirty[0] & /*downloaderConfig*/
        1 && t1_value !== (t1_value = /*name*/
        ctx2[84] + "")) set_data(t1, t1_value);
      },
      d(detaching) {
        if (detaching) {
          detach(label);
        }
        binding_group.r();
        mounted = false;
        dispose();
      }
    };
  }
  function create_default_slot_2(ctx) {
    let t_1_value = t("downloader.category.filter.download_all_pages") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot_1(ctx) {
    let t_1_value = t("downloader.category.filter.download_selected_pages") + "";
    let t_1;
    return {
      c() {
        t_1 = text(t_1_value);
      },
      m(target, anchor) {
        insert(target, t_1, anchor);
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
      }
    };
  }
  function create_default_slot(ctx) {
    let radioitem0;
    let updating_group;
    let t_1;
    let radioitem1;
    let updating_group_1;
    let current;
    function radioitem0_group_binding(value) {
      ctx[45](value);
    }
    let radioitem0_props = {
      class: "text-sm !py-[7px]",
      name: "justify",
      value: true,
      $$slots: { default: [create_default_slot_2] },
      $$scope: { ctx }
    };
    if (
      /*$downloadAllPages*/
      ctx[17] !== void 0
    ) {
      radioitem0_props.group = /*$downloadAllPages*/
      ctx[17];
    }
    radioitem0 = new RadioItem({ props: radioitem0_props });
    binding_callbacks.push(() => bind(radioitem0, "group", radioitem0_group_binding));
    function radioitem1_group_binding(value) {
      ctx[46](value);
    }
    let radioitem1_props = {
      class: "text-sm !py-[7px]",
      name: "justify",
      value: false,
      $$slots: { default: [create_default_slot_1] },
      $$scope: { ctx }
    };
    if (
      /*$downloadAllPages*/
      ctx[17] !== void 0
    ) {
      radioitem1_props.group = /*$downloadAllPages*/
      ctx[17];
    }
    radioitem1 = new RadioItem({ props: radioitem1_props });
    binding_callbacks.push(() => bind(radioitem1, "group", radioitem1_group_binding));
    return {
      c() {
        create_component(radioitem0.$$.fragment);
        t_1 = space();
        create_component(radioitem1.$$.fragment);
      },
      m(target, anchor) {
        mount_component(radioitem0, target, anchor);
        insert(target, t_1, anchor);
        mount_component(radioitem1, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const radioitem0_changes = {};
        if (dirty[2] & /*$$scope*/
        33554432) {
          radioitem0_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group && dirty[0] & /*$downloadAllPages*/
        131072) {
          updating_group = true;
          radioitem0_changes.group = /*$downloadAllPages*/
          ctx2[17];
          add_flush_callback(() => updating_group = false);
        }
        radioitem0.$set(radioitem0_changes);
        const radioitem1_changes = {};
        if (dirty[2] & /*$$scope*/
        33554432) {
          radioitem1_changes.$$scope = { dirty, ctx: ctx2 };
        }
        if (!updating_group_1 && dirty[0] & /*$downloadAllPages*/
        131072) {
          updating_group_1 = true;
          radioitem1_changes.group = /*$downloadAllPages*/
          ctx2[17];
          add_flush_callback(() => updating_group_1 = false);
        }
        radioitem1.$set(radioitem1_changes);
      },
      i(local) {
        if (current) return;
        transition_in(radioitem0.$$.fragment, local);
        transition_in(radioitem1.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(radioitem0.$$.fragment, local);
        transition_out(radioitem1.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
        }
        destroy_component(radioitem0, detaching);
        destroy_component(radioitem1, detaching);
      }
    };
  }
  function create_panel_slot(ctx) {
    let current_block_type_index;
    let if_block;
    let if_block_anchor;
    let current;
    const if_block_creators = [create_if_block_11, create_if_block_13, create_if_block_14];
    const if_blocks = [];
    function select_block_type(ctx2, dirty) {
      if (
        /*tabSet*/
        ctx2[12] === 0
      ) return 0;
      if (
        /*tabSet*/
        ctx2[12] === 1
      ) return 1;
      if (
        /*tabSet*/
        ctx2[12] === 2
      ) return 2;
      return -1;
    }
    if (~(current_block_type_index = select_block_type(ctx))) {
      if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
    }
    return {
      c() {
        if (if_block) if_block.c();
        if_block_anchor = empty();
      },
      m(target, anchor) {
        if (~current_block_type_index) {
          if_blocks[current_block_type_index].m(target, anchor);
        }
        insert(target, if_block_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        let previous_block_index = current_block_type_index;
        current_block_type_index = select_block_type(ctx2);
        if (current_block_type_index === previous_block_index) {
          if (~current_block_type_index) {
            if_blocks[current_block_type_index].p(ctx2, dirty);
          }
        } else {
          if (if_block) {
            group_outros();
            transition_out(if_blocks[previous_block_index], 1, 1, () => {
              if_blocks[previous_block_index] = null;
            });
            check_outros();
          }
          if (~current_block_type_index) {
            if_block = if_blocks[current_block_type_index];
            if (!if_block) {
              if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2);
              if_block.c();
            } else {
              if_block.p(ctx2, dirty);
            }
            transition_in(if_block, 1);
            if_block.m(if_block_anchor.parentNode, if_block_anchor);
          } else {
            if_block = null;
          }
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block);
        current = true;
      },
      o(local) {
        transition_out(if_block);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(if_block_anchor);
        }
        if (~current_block_type_index) {
          if_blocks[current_block_type_index].d(detaching);
        }
      }
    };
  }
  function create_else_block(ctx) {
    var _a;
    let div2;
    let div1;
    let progressbar;
    let t0;
    let div0;
    let p0;
    let t1_value = (
      /*$log*/
      (((_a = ctx[23]) == null ? void 0 : _a.message) ?? "") + ""
    );
    let t1;
    let t2;
    let p1;
    let t3_value = (
      /*$artworkCount*/
      ctx[4] ? `${/*processed*/
    ctx[2]} / ${/*$artworkCount*/
    ctx[4]}` : ""
    );
    let t3;
    let t4;
    let button;
    let i;
    let t5;
    let span;
    let div2_transition;
    let current;
    let mounted;
    let dispose;
    progressbar = new ProgressBar({
      props: {
        height: "h-4",
        rounded: "rounded-md",
        meter: "bg-primary-500",
        track: "bg-primary-500/30",
        max: 100,
        value: (
          /*downloadProgress*/
          ctx[15]
        )
      }
    });
    return {
      c() {
        var _a2;
        div2 = element("div");
        div1 = element("div");
        create_component(progressbar.$$.fragment);
        t0 = space();
        div0 = element("div");
        p0 = element("p");
        t1 = text(t1_value);
        t2 = space();
        p1 = element("p");
        t3 = text(t3_value);
        t4 = space();
        button = element("button");
        i = element("i");
        t5 = space();
        span = element("span");
        span.textContent = `${t("downloader.download_type.stop")}`;
        attr(p0, "class", "truncate");
        toggle_class(
          p0,
          "text-error-500",
          /*$log*/
          ((_a2 = ctx[23]) == null ? void 0 : _a2.type) === "Error"
        );
        attr(p1, "class", "flex-none");
        attr(div0, "class", "flex items-center justify-between gap-4 basis-0 text-surface-700-200-token");
        attr(div1, "class", "flex flex-grow flex-col justify-between h-full overflow-hidden");
        attr(i, "class", "w-5");
        attr(button, "class", "btn variant-filled-primary");
        attr(div2, "class", "flex flex-grow w-full gap-6 items-center");
      },
      m(target, anchor) {
        insert(target, div2, anchor);
        append(div2, div1);
        mount_component(progressbar, div1, null);
        append(div1, t0);
        append(div1, div0);
        append(div0, p0);
        append(p0, t1);
        append(div0, t2);
        append(div0, p1);
        append(p1, t3);
        append(div2, t4);
        append(div2, button);
        append(button, i);
        i.innerHTML = stopSvg;
        append(button, t5);
        append(button, span);
        ctx[61](div2);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              button,
              "click",
              /*click_handler_2*/
              ctx[60]
            ),
            listen(
              div2,
              "introstart",
              /*introstart_handler_1*/
              ctx[62]
            ),
            listen(
              div2,
              "outrostart",
              /*outrostart_handler_1*/
              ctx[63]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        var _a2, _b;
        const progressbar_changes = {};
        if (dirty[0] & /*downloadProgress*/
        32768) progressbar_changes.value = /*downloadProgress*/
        ctx2[15];
        progressbar.$set(progressbar_changes);
        if ((!current || dirty[0] & /*$log*/
        8388608) && t1_value !== (t1_value = /*$log*/
        (((_a2 = ctx2[23]) == null ? void 0 : _a2.message) ?? "") + "")) set_data(t1, t1_value);
        if (!current || dirty[0] & /*$log*/
        8388608) {
          toggle_class(
            p0,
            "text-error-500",
            /*$log*/
            ((_b = ctx2[23]) == null ? void 0 : _b.type) === "Error"
          );
        }
        if ((!current || dirty[0] & /*$artworkCount, processed*/
        20) && t3_value !== (t3_value = /*$artworkCount*/
        ctx2[4] ? `${/*processed*/
      ctx2[2]} / ${/*$artworkCount*/
      ctx2[4]}` : "")) set_data(t3, t3_value);
      },
      i(local) {
        if (current) return;
        transition_in(progressbar.$$.fragment, local);
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div2_transition) div2_transition = create_bidirectional_transition(div2, fade, { duration: 250 }, true);
            div2_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        transition_out(progressbar.$$.fragment, local);
        if (local) {
          if (!div2_transition) div2_transition = create_bidirectional_transition(div2, fade, { duration: 250 }, false);
          div2_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div2);
        }
        destroy_component(progressbar);
        ctx[61](null);
        if (detaching && div2_transition) div2_transition.end();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_6(ctx) {
    var _a;
    let div1;
    let div0;
    let p0;
    let t0;
    let t1;
    let p1;
    let t2_value = (
      /*$log*/
      (((_a = ctx[23]) == null ? void 0 : _a.message) ?? "") + ""
    );
    let t2;
    let t3;
    let div1_transition;
    let current;
    let mounted;
    let dispose;
    function select_block_type_2(ctx2, dirty) {
      if (
        /*pageConfig*/
        ctx2[1] && /*pageConfig*/
        ctx2[1].length > 1
      ) return create_if_block_7;
      if (
        /*pageConfig*/
        ctx2[1] && "fn" in /*pageConfig*/
        ctx2[1][0][1]
      ) return create_if_block_9;
    }
    let current_block_type = select_block_type_2(ctx);
    let if_block = current_block_type && current_block_type(ctx);
    return {
      c() {
        var _a2;
        div1 = element("div");
        div0 = element("div");
        p0 = element("p");
        t0 = text(
          /*downloadResult*/
          ctx[14]
        );
        t1 = space();
        p1 = element("p");
        t2 = text(t2_value);
        t3 = space();
        if (if_block) if_block.c();
        attr(p0, "class", "truncate");
        attr(p1, "class", "break-words");
        toggle_class(
          p1,
          "text-error-500",
          /*$log*/
          ((_a2 = ctx[23]) == null ? void 0 : _a2.type) === "Error"
        );
        attr(div0, "class", "flex flex-grow flex-col justify-between overflow-hidden text-surface-700-200-token");
        attr(div1, "class", "flex justify-end flex-grow w-full gap-4");
      },
      m(target, anchor) {
        insert(target, div1, anchor);
        append(div1, div0);
        append(div0, p0);
        append(p0, t0);
        append(div0, t1);
        append(div0, p1);
        append(p1, t2);
        append(div1, t3);
        if (if_block) if_block.m(div1, null);
        ctx[57](div1);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              div1,
              "introstart",
              /*introstart_handler*/
              ctx[58]
            ),
            listen(
              div1,
              "outrostart",
              /*outrostart_handler*/
              ctx[59]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        var _a2, _b;
        if (!current || dirty[0] & /*downloadResult*/
        16384) set_data(
          t0,
          /*downloadResult*/
          ctx2[14]
        );
        if ((!current || dirty[0] & /*$log*/
        8388608) && t2_value !== (t2_value = /*$log*/
        (((_a2 = ctx2[23]) == null ? void 0 : _a2.message) ?? "") + "")) set_data(t2, t2_value);
        if (!current || dirty[0] & /*$log*/
        8388608) {
          toggle_class(
            p1,
            "text-error-500",
            /*$log*/
            ((_b = ctx2[23]) == null ? void 0 : _b.type) === "Error"
          );
        }
        if (current_block_type === (current_block_type = select_block_type_2(ctx2)) && if_block) {
          if_block.p(ctx2, dirty);
        } else {
          if (if_block) if_block.d(1);
          if_block = current_block_type && current_block_type(ctx2);
          if (if_block) {
            if_block.c();
            if_block.m(div1, null);
          }
        }
      },
      i(local) {
        if (current) return;
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div1_transition) div1_transition = create_bidirectional_transition(div1, fade, { duration: 250 }, true);
            div1_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        if (local) {
          if (!div1_transition) div1_transition = create_bidirectional_transition(div1, fade, { duration: 250 }, false);
          div1_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div1);
        }
        if (if_block) {
          if_block.d();
        }
        ctx[57](null);
        if (detaching && div1_transition) div1_transition.end();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_9(ctx) {
    let button;
    let i;
    let t0;
    let span;
    let t1_value = (
      /*pageConfig*/
      ctx[1][0][1].name + ""
    );
    let t1;
    let mounted;
    let dispose;
    return {
      c() {
        button = element("button");
        i = element("i");
        t0 = space();
        span = element("span");
        t1 = text(t1_value);
        attr(i, "class", "w-5");
        attr(button, "class", "btn variant-filled-primary self-start");
      },
      m(target, anchor) {
        insert(target, button, anchor);
        append(button, i);
        i.innerHTML = downloadSvg;
        append(button, t0);
        append(button, span);
        append(span, t1);
        if (!mounted) {
          dispose = listen(
            button,
            "click",
            /*click_handler_1*/
            ctx[56]
          );
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*pageConfig*/
        2 && t1_value !== (t1_value = /*pageConfig*/
        ctx2[1][0][1].name + "")) set_data(t1, t1_value);
      },
      d(detaching) {
        if (detaching) {
          detach(button);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_if_block_7(ctx) {
    let div;
    let each_value = ensure_array_like(
      /*pageConfig*/
      ctx[1]
    );
    let each_blocks = [];
    for (let i = 0; i < each_value.length; i += 1) {
      each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
    }
    return {
      c() {
        div = element("div");
        for (let i = 0; i < each_blocks.length; i += 1) {
          each_blocks[i].c();
        }
        attr(div, "class", "flex-none btn-group self-start");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        for (let i = 0; i < each_blocks.length; i += 1) {
          if (each_blocks[i]) {
            each_blocks[i].m(div, null);
          }
        }
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*startDownload, pageConfig*/
        16777218) {
          each_value = ensure_array_like(
            /*pageConfig*/
            ctx2[1]
          );
          let i;
          for (i = 0; i < each_value.length; i += 1) {
            const child_ctx = get_each_context(ctx2, each_value, i);
            if (each_blocks[i]) {
              each_blocks[i].p(child_ctx, dirty);
            } else {
              each_blocks[i] = create_each_block(child_ctx);
              each_blocks[i].c();
              each_blocks[i].m(div, null);
            }
          }
          for (; i < each_blocks.length; i += 1) {
            each_blocks[i].d(1);
          }
          each_blocks.length = each_value.length;
        }
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        destroy_each(each_blocks, detaching);
      }
    };
  }
  function create_if_block_8(ctx) {
    let button;
    let i;
    let t0;
    let span;
    let t1_value = (
      /*item*/
      ctx[81].name + ""
    );
    let t1;
    let t2;
    let mounted;
    let dispose;
    function click_handler() {
      return (
        /*click_handler*/
        ctx[55](
          /*id*/
          ctx[80]
        )
      );
    }
    return {
      c() {
        button = element("button");
        i = element("i");
        t0 = space();
        span = element("span");
        t1 = text(t1_value);
        t2 = space();
        attr(i, "class", "w-5");
        attr(button, "class", "btn rounded-none !transform-none !variant-filled-primary");
      },
      m(target, anchor) {
        insert(target, button, anchor);
        append(button, i);
        i.innerHTML = downloadSvg;
        append(button, t0);
        append(button, span);
        append(span, t1);
        append(button, t2);
        if (!mounted) {
          dispose = listen(button, "click", click_handler);
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        if (dirty[0] & /*pageConfig*/
        2 && t1_value !== (t1_value = /*item*/
        ctx[81].name + "")) set_data(t1, t1_value);
      },
      d(detaching) {
        if (detaching) {
          detach(button);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_each_block(ctx) {
    let if_block_anchor;
    let if_block = "fn" in /*item*/
    ctx[81] && create_if_block_8(ctx);
    return {
      c() {
        if (if_block) if_block.c();
        if_block_anchor = empty();
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, if_block_anchor, anchor);
      },
      p(ctx2, dirty) {
        if ("fn" in /*item*/
        ctx2[81]) {
          if (if_block) {
            if_block.p(ctx2, dirty);
          } else {
            if_block = create_if_block_8(ctx2);
            if_block.c();
            if_block.m(if_block_anchor.parentNode, if_block_anchor);
          }
        } else if (if_block) {
          if_block.d(1);
          if_block = null;
        }
      },
      d(detaching) {
        if (detaching) {
          detach(if_block_anchor);
        }
        if (if_block) if_block.d(detaching);
      }
    };
  }
  function create_if_block$1(ctx) {
    let div2;
    let div0;
    let promise2;
    let t0;
    let t1;
    let div1;
    let current_block_type_index;
    let if_block1;
    let div2_transition;
    let current;
    let mounted;
    let dispose;
    let info = {
      ctx,
      current: null,
      token: null,
      hasCatch: false,
      pending: create_pending_block,
      then: create_then_block,
      catch: create_catch_block,
      value: 79
    };
    handle_promise(promise2 = /*avatarUpdated*/
    ctx[11], info);
    let if_block0 = (
      /*$downloading*/
      ctx[5] && !/*showDownloadMenu*/
      ctx[13] && create_if_block_3(ctx)
    );
    const if_block_creators = [create_if_block_1$1, create_if_block_2];
    const if_blocks = [];
    function select_block_type_3(ctx2, dirty) {
      if (
        /*$downloading*/
        ctx2[5] && /*$artworkCount*/
        ctx2[4] && !/*showDownloadMenu*/
        ctx2[13]
      ) return 0;
      if (!/*showDownloadMenu*/
      ctx2[13]) return 1;
      return -1;
    }
    if (~(current_block_type_index = select_block_type_3(ctx))) {
      if_block1 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
    }
    return {
      c() {
        div2 = element("div");
        div0 = element("div");
        info.block.c();
        t0 = space();
        if (if_block0) if_block0.c();
        t1 = space();
        div1 = element("div");
        if (if_block1) if_block1.c();
        attr(div0, "data-theme", "skeleton");
        attr(div0, "class", "avatar absolute -z-10 size-14 rounded-full overflow-hidden bg-scroll transition-opacity duration-[250ms]");
        toggle_class(div0, "opacity-70", !/*showDownloadMenu*/
        ctx[13]);
        toggle_class(div0, "blur-[1px]", !/*showDownloadMenu*/
        ctx[13]);
        attr(div1, "class", "size-14 flex justify-center items-center relative");
        attr(div2, "class", "size-14 rounded-full fixed right-4 top-36 drop-shadow-xl cursor-pointer hover:brightness-110 backdrop-blur-sm");
      },
      m(target, anchor) {
        insert(target, div2, anchor);
        append(div2, div0);
        info.block.m(div0, info.anchor = null);
        info.mount = () => div0;
        info.anchor = null;
        append(div2, t0);
        if (if_block0) if_block0.m(div2, null);
        append(div2, t1);
        append(div2, div1);
        if (~current_block_type_index) {
          if_blocks[current_block_type_index].m(div1, null);
        }
        current = true;
        if (!mounted) {
          dispose = listen(
            div2,
            "click",
            /*click_handler_3*/
            ctx[71]
          );
          mounted = true;
        }
      },
      p(new_ctx, dirty) {
        ctx = new_ctx;
        info.ctx = ctx;
        if (dirty[0] & /*avatarUpdated*/
        2048 && promise2 !== (promise2 = /*avatarUpdated*/
        ctx[11]) && handle_promise(promise2, info)) ;
        else {
          update_await_block_branch(info, ctx, dirty);
        }
        if (!current || dirty[0] & /*showDownloadMenu*/
        8192) {
          toggle_class(div0, "opacity-70", !/*showDownloadMenu*/
          ctx[13]);
        }
        if (!current || dirty[0] & /*showDownloadMenu*/
        8192) {
          toggle_class(div0, "blur-[1px]", !/*showDownloadMenu*/
          ctx[13]);
        }
        if (
          /*$downloading*/
          ctx[5] && !/*showDownloadMenu*/
          ctx[13]
        ) {
          if (if_block0) {
            if_block0.p(ctx, dirty);
            if (dirty[0] & /*$downloading, showDownloadMenu*/
            8224) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_3(ctx);
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(div2, t1);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        let previous_block_index = current_block_type_index;
        current_block_type_index = select_block_type_3(ctx);
        if (current_block_type_index === previous_block_index) {
          if (~current_block_type_index) {
            if_blocks[current_block_type_index].p(ctx, dirty);
          }
        } else {
          if (if_block1) {
            group_outros();
            transition_out(if_blocks[previous_block_index], 1, 1, () => {
              if_blocks[previous_block_index] = null;
            });
            check_outros();
          }
          if (~current_block_type_index) {
            if_block1 = if_blocks[current_block_type_index];
            if (!if_block1) {
              if_block1 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
              if_block1.c();
            } else {
              if_block1.p(ctx, dirty);
            }
            transition_in(if_block1, 1);
            if_block1.m(div1, null);
          } else {
            if_block1 = null;
          }
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block0);
        transition_in(if_block1);
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div2_transition) div2_transition = create_bidirectional_transition(div2, fly, { opacity: 0, x: 50 }, true);
            div2_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        transition_out(if_block0);
        transition_out(if_block1);
        if (local) {
          if (!div2_transition) div2_transition = create_bidirectional_transition(div2, fly, { opacity: 0, x: 50 }, false);
          div2_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div2);
        }
        info.block.d();
        info.token = null;
        info = null;
        if (if_block0) if_block0.d();
        if (~current_block_type_index) {
          if_blocks[current_block_type_index].d();
        }
        if (detaching && div2_transition) div2_transition.end();
        mounted = false;
        dispose();
      }
    };
  }
  function create_catch_block(ctx) {
    return { c: noop, m: noop, p: noop, d: noop };
  }
  function create_then_block(ctx) {
    let if_block_anchor;
    let if_block = (
      /*val*/
      ctx[79] && create_if_block_4(ctx)
    );
    return {
      c() {
        if (if_block) if_block.c();
        if_block_anchor = empty();
      },
      m(target, anchor) {
        if (if_block) if_block.m(target, anchor);
        insert(target, if_block_anchor, anchor);
      },
      p(ctx2, dirty) {
        if (
          /*val*/
          ctx2[79]
        ) {
          if (if_block) {
            if_block.p(ctx2, dirty);
          } else {
            if_block = create_if_block_4(ctx2);
            if_block.c();
            if_block.m(if_block_anchor.parentNode, if_block_anchor);
          }
        } else if (if_block) {
          if_block.d(1);
          if_block = null;
        }
      },
      d(detaching) {
        if (detaching) {
          detach(if_block_anchor);
        }
        if (if_block) if_block.d(detaching);
      }
    };
  }
  function create_if_block_4(ctx) {
    let img;
    let img_src_value;
    return {
      c() {
        img = element("img");
        if (!src_url_equal(img.src, img_src_value = /*val*/
        ctx[79])) attr(img, "src", img_src_value);
        attr(img, "alt", "batch download");
        attr(img, "class", "object-cover object-center size-full");
      },
      m(target, anchor) {
        insert(target, img, anchor);
        ctx[64](img);
      },
      p(ctx2, dirty) {
        if (dirty[0] & /*avatarUpdated*/
        2048 && !src_url_equal(img.src, img_src_value = /*val*/
        ctx2[79])) {
          attr(img, "src", img_src_value);
        }
      },
      d(detaching) {
        if (detaching) {
          detach(img);
        }
        ctx[64](null);
      }
    };
  }
  function create_pending_block(ctx) {
    return { c: noop, m: noop, p: noop, d: noop };
  }
  function create_if_block_3(ctx) {
    let div;
    let progressradial;
    let div_transition;
    let current;
    progressradial = new ProgressRadial({
      props: {
        width: "w-16",
        stroke: 32,
        meter: "stroke-primary-500",
        track: "stroke-primary-500/30",
        fill: "fill-primary-500",
        strokeLinecap: "butt",
        value: (
          /*downloadProgress*/
          ctx[15]
        )
      }
    });
    return {
      c() {
        div = element("div");
        create_component(progressradial.$$.fragment);
        attr(div, "class", "!absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        mount_component(progressradial, div, null);
        current = true;
      },
      p(ctx2, dirty) {
        const progressradial_changes = {};
        if (dirty[0] & /*downloadProgress*/
        32768) progressradial_changes.value = /*downloadProgress*/
        ctx2[15];
        progressradial.$set(progressradial_changes);
      },
      i(local) {
        if (current) return;
        transition_in(progressradial.$$.fragment, local);
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div_transition) div_transition = create_bidirectional_transition(div, fade, { duration: 250 }, true);
            div_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        transition_out(progressradial.$$.fragment, local);
        if (local) {
          if (!div_transition) div_transition = create_bidirectional_transition(div, fade, { duration: 250 }, false);
          div_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        destroy_component(progressradial);
        if (detaching && div_transition) div_transition.end();
      }
    };
  }
  function create_if_block_2(ctx) {
    let i;
    let i_transition;
    let current;
    let mounted;
    let dispose;
    return {
      c() {
        i = element("i");
        attr(i, "class", "w-6 fill-slate-700 dark:fill-slate-200 mix-blend-hard-light mt-4");
      },
      m(target, anchor) {
        insert(target, i, anchor);
        i.innerHTML = downloadMultipleSvg;
        ctx[68](i);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              i,
              "introstart",
              /*introstart_handler_3*/
              ctx[69]
            ),
            listen(
              i,
              "outrostart",
              /*outrostart_handler_3*/
              ctx[70]
            )
          ];
          mounted = true;
        }
      },
      p: noop,
      i(local) {
        if (current) return;
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!i_transition) i_transition = create_bidirectional_transition(i, fade, { duration: 250 }, true);
            i_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        if (local) {
          if (!i_transition) i_transition = create_bidirectional_transition(i, fade, { duration: 250 }, false);
          i_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(i);
        }
        ctx[68](null);
        if (detaching && i_transition) i_transition.end();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_if_block_1$1(ctx) {
    let div;
    let span0;
    let t0;
    let t1;
    let hr;
    let t2;
    let span1;
    let t3;
    let div_transition;
    let current;
    let mounted;
    let dispose;
    return {
      c() {
        div = element("div");
        span0 = element("span");
        t0 = text(
          /*processed*/
          ctx[2]
        );
        t1 = space();
        hr = element("hr");
        t2 = space();
        span1 = element("span");
        t3 = text(
          /*$artworkCount*/
          ctx[4]
        );
        attr(span0, "class", "truncate max-w-full");
        attr(hr, "class", "!border-t-1 my-[1px] self-stretch !border-surface-700 dark:!border-surface-200");
        attr(span1, "class", "truncate max-w-full");
        attr(div, "class", "flex flex-col justify-center items-center px-3 font-bold text-[12px] leading-[14px] overflow-hidden text-surface-700-200-token");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        append(div, span0);
        append(span0, t0);
        append(div, t1);
        append(div, hr);
        append(div, t2);
        append(div, span1);
        append(span1, t3);
        ctx[65](div);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              div,
              "introstart",
              /*introstart_handler_2*/
              ctx[66]
            ),
            listen(
              div,
              "outrostart",
              /*outrostart_handler_2*/
              ctx[67]
            )
          ];
          mounted = true;
        }
      },
      p(ctx2, dirty) {
        if (!current || dirty[0] & /*processed*/
        4) set_data(
          t0,
          /*processed*/
          ctx2[2]
        );
        if (!current || dirty[0] & /*$artworkCount*/
        16) set_data(
          t3,
          /*$artworkCount*/
          ctx2[4]
        );
      },
      i(local) {
        if (current) return;
        if (local) {
          add_render_callback(() => {
            if (!current) return;
            if (!div_transition) div_transition = create_bidirectional_transition(div, fade, { duration: 250 }, true);
            div_transition.run(1);
          });
        }
        current = true;
      },
      o(local) {
        if (local) {
          if (!div_transition) div_transition = create_bidirectional_transition(div, fade, { duration: 250 }, false);
          div_transition.run(0);
        }
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        ctx[65](null);
        if (detaching && div_transition) div_transition.end();
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function create_fragment$1(ctx) {
    let t_1;
    let if_block1_anchor;
    let current;
    let if_block0 = (
      /*showDownloadMenu*/
      ctx[13] && /*ifDownloaderCanShow*/
      ctx[3] && create_if_block_5(ctx)
    );
    let if_block1 = (
      /*ifDownloaderCanShow*/
      ctx[3] && create_if_block$1(ctx)
    );
    return {
      c() {
        if (if_block0) if_block0.c();
        t_1 = space();
        if (if_block1) if_block1.c();
        if_block1_anchor = empty();
      },
      m(target, anchor) {
        if (if_block0) if_block0.m(target, anchor);
        insert(target, t_1, anchor);
        if (if_block1) if_block1.m(target, anchor);
        insert(target, if_block1_anchor, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        if (
          /*showDownloadMenu*/
          ctx2[13] && /*ifDownloaderCanShow*/
          ctx2[3]
        ) {
          if (if_block0) {
            if_block0.p(ctx2, dirty);
            if (dirty[0] & /*showDownloadMenu, ifDownloaderCanShow*/
            8200) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_5(ctx2);
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(t_1.parentNode, t_1);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        if (
          /*ifDownloaderCanShow*/
          ctx2[3]
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
            if (dirty[0] & /*ifDownloaderCanShow*/
            8) {
              transition_in(if_block1, 1);
            }
          } else {
            if_block1 = create_if_block$1(ctx2);
            if_block1.c();
            transition_in(if_block1, 1);
            if_block1.m(if_block1_anchor.parentNode, if_block1_anchor);
          }
        } else if (if_block1) {
          group_outros();
          transition_out(if_block1, 1, 1, () => {
            if_block1 = null;
          });
          check_outros();
        }
      },
      i(local) {
        if (current) return;
        transition_in(if_block0);
        transition_in(if_block1);
        current = true;
      },
      o(local) {
        transition_out(if_block0);
        transition_out(if_block1);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(t_1);
          detach(if_block1_anchor);
        }
        if (if_block0) if_block0.d(detaching);
        if (if_block1) if_block1.d(detaching);
      }
    };
  }
  function beforeUnloadHandler(evt) {
    evt.preventDefault();
    evt.returnValue = true;
  }
  function instance$1($$self, $$props, $$invalidate) {
    let ifDownloaderCanShow;
    let processed;
    let downloadProgress;
    let downloadResult;
    let $excluded;
    let $failed;
    let $successd;
    let $artworkCount;
    let $downloading;
    let $selectedFilters;
    let $downloadAllPages;
    let $pageStart;
    let $pageEnd;
    let $blacklistTag;
    let $whitelistTag;
    let $retryFailed;
    let $log;
    function initFilterStore() {
      Array.isArray($selectedFilters) || set_store_value(selectedFilters, $selectedFilters = downloaderConfig.filterOption.filters.filter((filter) => filter.checked).map((filter) => filter.id), $selectedFilters);
    }
    async function updateAvatarSrc(url2) {
      if (!downloaderConfig.avatar) return;
      if ($downloading && avatarUpdated !== void 0) {
        updateAvatarAfterDownload = url2;
        return;
      }
      let src;
      if (typeof downloaderConfig.avatar === "string") {
        src = downloaderConfig.avatar;
      } else {
        if (url2 in avatarCache) {
          src = avatarCache[url2];
        } else {
          src = await downloaderConfig.avatar(url2);
          avatarCache[url2] = src;
        }
      }
      if (!src || avatarEl && avatarEl.src === src) return;
      let imageLoaded;
      $$invalidate(11, avatarUpdated = new Promise((resolve) => {
        imageLoaded = resolve;
      }));
      const el = document.createElement("img");
      el.src = src;
      el.onload = () => {
        imageLoaded(src);
      };
    }
    function onUrlChange(url2) {
      logger.info("Navigating to ", url2);
      if (!downloaderConfig) return;
      const { pageMatch } = downloaderConfig;
      const generatorMatches = [];
      for (const key in pageMatch) {
        const item = pageMatch[key];
        const { match: matchPattern } = item;
        if (typeof matchPattern === "string") {
          url2.match(matchPattern) && generatorMatches.push([key, item]);
        } else if (typeof matchPattern === "function") {
          matchPattern(url2) && generatorMatches.push([key, item]);
        } else {
          matchPattern.test(url2) && generatorMatches.push([key, item]);
        }
      }
      if (generatorMatches.length) {
        $$invalidate(1, pageConfig = generatorMatches);
        updateAvatarSrc(url2);
      } else {
        $$invalidate(1, pageConfig = null);
        updateAvatarAfterDownload = "";
      }
    }
    function watchUrlChange() {
      if ("navigation" in window) {
        let prevUrl;
        let nextUrl;
        navigation.addEventListener("navigatesuccess", () => {
          prevUrl !== nextUrl && onUrlChange(nextUrl);
        });
        navigation.addEventListener("navigate", (evt) => {
          prevUrl = location.href;
          nextUrl = evt.destination.url;
        });
      } else {
        const rewrite = (type) => {
          const oriHistory = history[type];
          return function(...args) {
            const currentUrl = location.href;
            const res = oriHistory.apply(this, args);
            const navigateUrl = location.href;
            currentUrl !== navigateUrl && onUrlChange(navigateUrl);
            return res;
          };
        };
        history.pushState = rewrite("pushState");
        history.replaceState = rewrite("replaceState");
      }
    }
    async function startDownload(id) {
      try {
        await batchDownload(id);
      } catch (error) {
        logger.error(error);
      }
    }
    let { downloaderConfig } = $$props;
    let { useBatchDownload } = $$props;
    let pageConfig;
    const { selectedFilters, blacklistTag, whitelistTag, downloadAllPages, pageStart, pageEnd, retryFailed } = optionStore;
    component_subscribe($$self, selectedFilters, (value) => $$invalidate(16, $selectedFilters = value));
    component_subscribe($$self, blacklistTag, (value) => $$invalidate(20, $blacklistTag = value));
    component_subscribe($$self, whitelistTag, (value) => $$invalidate(21, $whitelistTag = value));
    component_subscribe($$self, downloadAllPages, (value) => $$invalidate(17, $downloadAllPages = value));
    component_subscribe($$self, pageStart, (value) => $$invalidate(18, $pageStart = value));
    component_subscribe($$self, pageEnd, (value) => $$invalidate(19, $pageEnd = value));
    component_subscribe($$self, retryFailed, (value) => $$invalidate(22, $retryFailed = value));
    let startDownloadEl;
    let stopDownloadEl;
    let avatarEl;
    let avatarProgressEl;
    let avatarDownloadIcon;
    const avatarCache = {};
    let avatarUpdated;
    let updateAvatarAfterDownload;
    let tabSet = 0;
    let showDownloadMenu = false;
    initFilterStore();
    const { artworkCount, successd, failed, excluded, downloading, log, batchDownload, abort } = useBatchDownload();
    component_subscribe($$self, artworkCount, (value) => $$invalidate(4, $artworkCount = value));
    component_subscribe($$self, successd, (value) => $$invalidate(42, $successd = value));
    component_subscribe($$self, failed, (value) => $$invalidate(41, $failed = value));
    component_subscribe($$self, excluded, (value) => $$invalidate(40, $excluded = value));
    component_subscribe($$self, downloading, (value) => $$invalidate(5, $downloading = value));
    component_subscribe($$self, log, (value) => $$invalidate(23, $log = value));
    watchUrlChange();
    onUrlChange(location.href);
    downloading.subscribe((val) => {
      if (val) {
        if (!avatarUpdated) updateAvatarSrc(location.href);
        window.addEventListener("beforeunload", beforeUnloadHandler);
      } else {
        window.removeEventListener("beforeunload", beforeUnloadHandler);
        updateAvatarAfterDownload && pageConfig && updateAvatarSrc(updateAvatarAfterDownload);
      }
    });
    const $$binding_groups = [[]];
    function input_change_handler() {
      $selectedFilters = get_binding_group_value($$binding_groups[0], this.__value, this.checked);
      selectedFilters.set($selectedFilters);
    }
    function radioitem0_group_binding(value) {
      $downloadAllPages = value;
      downloadAllPages.set($downloadAllPages);
    }
    function radioitem1_group_binding(value) {
      $downloadAllPages = value;
      downloadAllPages.set($downloadAllPages);
    }
    function input0_input_handler() {
      $pageStart = to_number(this.value);
      pageStart.set($pageStart);
    }
    function input1_input_handler() {
      $pageEnd = to_number(this.value);
      pageEnd.set($pageEnd);
    }
    function inputchip0_value_binding(value) {
      $blacklistTag = value;
      blacklistTag.set($blacklistTag);
    }
    function inputchip1_value_binding(value) {
      $whitelistTag = value;
      whitelistTag.set($whitelistTag);
    }
    function slidetoggle_checked_binding(value) {
      $retryFailed = value;
      retryFailed.set($retryFailed);
    }
    function tab0_group_binding(value) {
      tabSet = value;
      $$invalidate(12, tabSet);
    }
    function tab_group_binding(value) {
      tabSet = value;
      $$invalidate(12, tabSet);
    }
    function tab1_group_binding(value) {
      tabSet = value;
      $$invalidate(12, tabSet);
    }
    const click_handler = (id) => {
      startDownload(id);
    };
    const click_handler_1 = () => {
      startDownload((pageConfig == null ? void 0 : pageConfig[0][0]) ?? "");
    };
    function div1_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        startDownloadEl = $$value;
        $$invalidate(6, startDownloadEl);
      });
    }
    const introstart_handler = () => (
      // required when the transition reverses
      startDownloadEl.classList.remove("absolute")
    );
    const outrostart_handler = () => startDownloadEl.classList.add("absolute");
    const click_handler_2 = () => {
      abort();
    };
    function div2_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        stopDownloadEl = $$value;
        $$invalidate(7, stopDownloadEl);
      });
    }
    const introstart_handler_1 = () => stopDownloadEl.classList.remove("absolute");
    const outrostart_handler_1 = () => stopDownloadEl.classList.add("absolute");
    function img_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        avatarEl = $$value;
        $$invalidate(8, avatarEl);
      });
    }
    function div_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        avatarProgressEl = $$value;
        $$invalidate(9, avatarProgressEl);
      });
    }
    const introstart_handler_2 = () => avatarProgressEl.classList.remove("absolute");
    const outrostart_handler_2 = () => avatarProgressEl.classList.add("absolute");
    function i_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        avatarDownloadIcon = $$value;
        $$invalidate(10, avatarDownloadIcon);
      });
    }
    const introstart_handler_3 = () => avatarDownloadIcon.classList.remove("absolute");
    const outrostart_handler_3 = () => avatarDownloadIcon.classList.add("absolute");
    const click_handler_3 = () => {
      $$invalidate(13, showDownloadMenu = !showDownloadMenu);
    };
    $$self.$$set = ($$props2) => {
      if ("downloaderConfig" in $$props2) $$invalidate(0, downloaderConfig = $$props2.downloaderConfig);
      if ("useBatchDownload" in $$props2) $$invalidate(39, useBatchDownload = $$props2.useBatchDownload);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty[0] & /*$downloading, pageConfig*/
      34) {
        $$invalidate(3, ifDownloaderCanShow = $downloading || !!pageConfig);
      }
      if ($$self.$$.dirty[0] & /*ifDownloaderCanShow*/
      8) {
        {
          if (!ifDownloaderCanShow) $$invalidate(13, showDownloadMenu = false);
        }
      }
      if ($$self.$$.dirty[1] & /*$successd, $failed, $excluded*/
      3584) {
        $$invalidate(2, processed = $successd.length + $failed.length + $excluded.length);
      }
      if ($$self.$$.dirty[0] & /*$artworkCount, processed*/
      20) {
        $$invalidate(15, downloadProgress = $artworkCount ? processed / $artworkCount * 100 : void 0);
      }
      if ($$self.$$.dirty[0] & /*$downloading, $artworkCount*/
      48 | $$self.$$.dirty[1] & /*$successd, $failed, $excluded*/
      3584) {
        $$invalidate(14, downloadResult = !$downloading && $artworkCount ? `Completed: ${$successd.length}. Failed: ${$failed.length}. Excluded: ${$excluded.length}.` : "");
      }
    };
    return [
      downloaderConfig,
      pageConfig,
      processed,
      ifDownloaderCanShow,
      $artworkCount,
      $downloading,
      startDownloadEl,
      stopDownloadEl,
      avatarEl,
      avatarProgressEl,
      avatarDownloadIcon,
      avatarUpdated,
      tabSet,
      showDownloadMenu,
      downloadResult,
      downloadProgress,
      $selectedFilters,
      $downloadAllPages,
      $pageStart,
      $pageEnd,
      $blacklistTag,
      $whitelistTag,
      $retryFailed,
      $log,
      startDownload,
      selectedFilters,
      blacklistTag,
      whitelistTag,
      downloadAllPages,
      pageStart,
      pageEnd,
      retryFailed,
      artworkCount,
      successd,
      failed,
      excluded,
      downloading,
      log,
      abort,
      useBatchDownload,
      $excluded,
      $failed,
      $successd,
      input_change_handler,
      $$binding_groups,
      radioitem0_group_binding,
      radioitem1_group_binding,
      input0_input_handler,
      input1_input_handler,
      inputchip0_value_binding,
      inputchip1_value_binding,
      slidetoggle_checked_binding,
      tab0_group_binding,
      tab_group_binding,
      tab1_group_binding,
      click_handler,
      click_handler_1,
      div1_binding,
      introstart_handler,
      outrostart_handler,
      click_handler_2,
      div2_binding,
      introstart_handler_1,
      outrostart_handler_1,
      img_binding,
      div_binding,
      introstart_handler_2,
      outrostart_handler_2,
      i_binding,
      introstart_handler_3,
      outrostart_handler_3,
      click_handler_3
    ];
  }
  class Downloader extends SvelteComponent {
    constructor(options) {
      super();
      init(
        this,
        options,
        instance$1,
        create_fragment$1,
        safe_not_equal,
        {
          downloaderConfig: 0,
          useBatchDownload: 39
        },
        null,
        [-1, -1, -1]
      );
    }
  }
  const cog = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z" /></svg>`;
  function create_if_block_1(ctx) {
    let downloader2;
    let current;
    downloader2 = new Downloader({
      props: {
        downloaderConfig: (
          /*downloaderConfig*/
          ctx[0]
        ),
        useBatchDownload: (
          /*useBatchDownload*/
          ctx[1]
        )
      }
    });
    return {
      c() {
        create_component(downloader2.$$.fragment);
      },
      m(target, anchor) {
        mount_component(downloader2, target, anchor);
        current = true;
      },
      p(ctx2, dirty) {
        const downloader_changes = {};
        if (dirty & /*downloaderConfig*/
        1) downloader_changes.downloaderConfig = /*downloaderConfig*/
        ctx2[0];
        if (dirty & /*useBatchDownload*/
        2) downloader_changes.useBatchDownload = /*useBatchDownload*/
        ctx2[1];
        downloader2.$set(downloader_changes);
      },
      i(local) {
        if (current) return;
        transition_in(downloader2.$$.fragment, local);
        current = true;
      },
      o(local) {
        transition_out(downloader2.$$.fragment, local);
        current = false;
      },
      d(detaching) {
        destroy_component(downloader2, detaching);
      }
    };
  }
  function create_if_block(ctx) {
    let button;
    let i;
    let t0;
    let span;
    let mounted;
    let dispose;
    return {
      c() {
        button = element("button");
        i = element("i");
        t0 = space();
        span = element("span");
        span.textContent = `${t("button.setting")}`;
        attr(i, "class", "text-sm w-6 fill-current");
        attr(span, "class", "text-sm");
        attr(button, "type", "button");
        attr(button, "class", "btn btn-sm variant-filled fixed bottom-24 rounded-none rounded-s-full opacity-40 hover:opacity-100 right-0 translate-x-[calc(100%-44px)] hover:translate-x-0 delay-100");
      },
      m(target, anchor) {
        insert(target, button, anchor);
        append(button, i);
        i.innerHTML = cog;
        append(button, t0);
        append(button, span);
        if (!mounted) {
          dispose = listen(
            button,
            "click",
            /*click_handler*/
            ctx[16]
          );
          mounted = true;
        }
      },
      p: noop,
      d(detaching) {
        if (detaching) {
          detach(button);
        }
        mounted = false;
        dispose();
      }
    };
  }
  function create_fragment(ctx) {
    let div;
    let modal;
    let t0;
    let t1;
    let div_class_value;
    let current;
    let mounted;
    let dispose;
    modal = new Modal({
      props: {
        components: (
          /*components*/
          ctx[7]
        ),
        class: "!p-0"
      }
    });
    let if_block0 = (
      /*downloaderConfig*/
      ctx[0] && /*useBatchDownload*/
      ctx[1] && create_if_block_1(ctx)
    );
    let if_block1 = (
      /*$store*/
      ctx[4].showPopupButton && create_if_block(ctx)
    );
    return {
      c() {
        div = element("div");
        create_component(modal.$$.fragment);
        t0 = space();
        if (if_block0) if_block0.c();
        t1 = space();
        if (if_block1) if_block1.c();
        attr(div, "class", div_class_value = "contents " + /*darkMode*/
        ctx[3]);
        attr(div, "data-theme", "skeleton");
      },
      m(target, anchor) {
        insert(target, div, anchor);
        mount_component(modal, div, null);
        append(div, t0);
        if (if_block0) if_block0.m(div, null);
        append(div, t1);
        if (if_block1) if_block1.m(div, null);
        ctx[17](div);
        current = true;
        if (!mounted) {
          dispose = [
            listen(
              window,
              "keydown",
              /*handleKeydown*/
              ctx[9],
              true
            ),
            listen(div, "keydown", stop_propagation(
              /*keydown_handler*/
              ctx[15]
            )),
            listen(div, "mousedown", preventBackDropClick, true),
            listen(div, "mouseup", preventBackDropClick, true)
          ];
          mounted = true;
        }
      },
      p(ctx2, [dirty]) {
        if (
          /*downloaderConfig*/
          ctx2[0] && /*useBatchDownload*/
          ctx2[1]
        ) {
          if (if_block0) {
            if_block0.p(ctx2, dirty);
            if (dirty & /*downloaderConfig, useBatchDownload*/
            3) {
              transition_in(if_block0, 1);
            }
          } else {
            if_block0 = create_if_block_1(ctx2);
            if_block0.c();
            transition_in(if_block0, 1);
            if_block0.m(div, t1);
          }
        } else if (if_block0) {
          group_outros();
          transition_out(if_block0, 1, 1, () => {
            if_block0 = null;
          });
          check_outros();
        }
        if (
          /*$store*/
          ctx2[4].showPopupButton
        ) {
          if (if_block1) {
            if_block1.p(ctx2, dirty);
          } else {
            if_block1 = create_if_block(ctx2);
            if_block1.c();
            if_block1.m(div, null);
          }
        } else if (if_block1) {
          if_block1.d(1);
          if_block1 = null;
        }
        if (!current || dirty & /*darkMode*/
        8 && div_class_value !== (div_class_value = "contents " + /*darkMode*/
        ctx2[3])) {
          attr(div, "class", div_class_value);
        }
      },
      i(local) {
        if (current) return;
        transition_in(modal.$$.fragment, local);
        transition_in(if_block0);
        current = true;
      },
      o(local) {
        transition_out(modal.$$.fragment, local);
        transition_out(if_block0);
        current = false;
      },
      d(detaching) {
        if (detaching) {
          detach(div);
        }
        destroy_component(modal);
        if (if_block0) if_block0.d();
        if (if_block1) if_block1.d();
        ctx[17](null);
        mounted = false;
        run_all(dispose);
      }
    };
  }
  function preventBackDropClick(event) {
    if (!(event.target instanceof Element)) return;
    const classList = event.target.classList;
    if (classList.contains("modal-backdrop") || classList.contains("modal-transition")) {
      event.stopPropagation();
    }
  }
  function instance($$self, $$props, $$invalidate) {
    let darkMode;
    let $store;
    let { dark = false } = $$props;
    let { updated = false } = $$props;
    let { filenameTemplate = [] } = $$props;
    let { downloaderConfig } = $$props;
    let { useBatchDownload } = $$props;
    setContext("filenameTemplate", filenameTemplate);
    initializeStores();
    const store = initConfigStore();
    component_subscribe($$self, store, (value) => $$invalidate(4, $store = value));
    const modalStore = getModalStore();
    let root;
    const components = {
      changelog: { ref: Changelog },
      setting: { ref: Config }
    };
    const changelogModal = {
      type: "component",
      component: "changelog"
    };
    const settingModal = { type: "component", component: "setting" };
    function showChangelog() {
      modalStore.trigger(changelogModal);
    }
    function showSetting() {
      modalStore.trigger(settingModal);
    }
    onMount(async () => {
      const shadow = root.getRootNode();
      addStyleToShadow(shadow);
      shadow.host.setAttribute("style", "position:fixed; z-index:99999");
      if (updated) {
        showChangelog();
      }
    });
    function modalExist() {
      return !!(root == null ? void 0 : root.querySelector(".modal-backdrop"));
    }
    function handleKeydown(event) {
      if (!modalExist()) return;
      if (event.code === "Escape") {
        modalStore.close();
        return;
      } else if (event.ctrlKey || event.shiftKey) {
        return;
      }
      if (!event.composedPath().includes(root)) {
        event.stopImmediatePropagation();
        event.preventDefault();
      }
    }
    function keydown_handler(event) {
      bubble.call(this, $$self, event);
    }
    const click_handler = () => modalStore.trigger(settingModal);
    function div_binding($$value) {
      binding_callbacks[$$value ? "unshift" : "push"](() => {
        root = $$value;
        $$invalidate(2, root);
      });
    }
    $$self.$$set = ($$props2) => {
      if ("dark" in $$props2) $$invalidate(10, dark = $$props2.dark);
      if ("updated" in $$props2) $$invalidate(11, updated = $$props2.updated);
      if ("filenameTemplate" in $$props2) $$invalidate(12, filenameTemplate = $$props2.filenameTemplate);
      if ("downloaderConfig" in $$props2) $$invalidate(0, downloaderConfig = $$props2.downloaderConfig);
      if ("useBatchDownload" in $$props2) $$invalidate(1, useBatchDownload = $$props2.useBatchDownload);
    };
    $$self.$$.update = () => {
      if ($$self.$$.dirty & /*dark*/
      1024) {
        $$invalidate(3, darkMode = dark ? "dark" : "");
      }
    };
    return [
      downloaderConfig,
      useBatchDownload,
      root,
      darkMode,
      $store,
      store,
      modalStore,
      components,
      settingModal,
      handleKeydown,
      dark,
      updated,
      filenameTemplate,
      showChangelog,
      showSetting,
      keydown_handler,
      click_handler,
      div_binding
    ];
  }
  class App extends SvelteComponent {
    constructor(options) {
      super();
      init(this, options, instance, create_fragment, safe_not_equal, {
        dark: 10,
        updated: 11,
        filenameTemplate: 12,
        downloaderConfig: 0,
        useBatchDownload: 1,
        showChangelog: 13,
        showSetting: 14
      });
    }
    get showChangelog() {
      return this.$$.ctx[13];
    }
    get showSetting() {
      return this.$$.ctx[14];
    }
  }
  const PdlApp = create_custom_element(
    App,
    {
      dark: { type: "Boolean" },
      updated: { type: "Boolean" },
      filenameTemplate: {},
      downloaderConfig: {},
      useBatchDownload: {}
    },
    [],
    ["showChangelog", "showSetting"],
    true,
    (customElementConstructor) => {
      return class extends customElementConstructor {
        constructor(props) {
          super();
          this.filenameTemplate = props.filenameTemplate;
          this.updated = props.updated ?? false;
        }
        initBatchDownloader(config2) {
          this.downloaderConfig = config2;
          const useBatchDownload = this.useBatchDownload = defineBatchDownload(config2);
          return useBatchDownload;
        }
      };
    }
  );
  customElements.define("pdl-app", PdlApp);
  class SiteInject {
    constructor() {
      __publicField(this, "app");
      __publicField(this, "config");
      __publicField(this, "useBatchDownload");
      this.config = loadConfig(this.getCustomConfig() || void 0);
      this.app = this.createApp();
    }
    static get hostname() {
      throw new Error("`hostname` should be overwritten by a subclass.");
    }
    createApp() {
      const updated = this.config.get("showMsg");
      updated && this.config.set("showMsg", false);
      const app = new PdlApp({
        updated,
        filenameTemplate: this.getFilenameTemplate()
      });
      return app;
    }
    injectStyle() {
      [
        "pdl-btn-self-bookmark-left",
        "pdl-btn-self-bookmark-top",
        "pdl-btn-left",
        "pdl-btn-top"
      ].forEach((key) => {
        let val;
        if ((val = this.config.get(key)) !== void 0) {
          document.documentElement.style.setProperty("--" + key, val);
        }
      });
    }
    runScheduledTask() {
      useHistoryBackup().scheduleBackup();
    }
    setAppDarkMode() {
      this.app.setAttribute("dark", "");
    }
    setAppLightMode() {
      this.app.removeAttribute("dark");
    }
    observeColorScheme() {
      const query = window.matchMedia("(prefers-color-scheme: dark)");
      query.matches && this.setAppDarkMode();
      query.addEventListener("change", (e) => {
        e.matches ? this.setAppDarkMode() : this.setAppLightMode();
      });
    }
    inject() {
      this.observeColorScheme();
      this.injectStyle();
      _GM_registerMenuCommand(
        t("button.setting"),
        () => {
          var _a;
          if ((_a = this.app.shadowRoot) == null ? void 0 : _a.querySelector(".modal")) {
            return;
          }
          this.app.showSetting();
        },
        "s"
      );
      document.body.append(this.app);
      this.runScheduledTask();
    }
  }
  const wrapperStyle = ".button-wrapper{position:absolute;right:8px;top:0;bottom:0;margin-top:40px}.button-wrapper.rule34{bottom:calc(1em + 22px)}.button-wrapper.yande{right:calc(5em + 8px)}";
  class ArtworkButton extends HTMLElement {
    constructor(props) {
      super();
      __publicField(this, "props");
      this.props = props;
    }
    static get tagNameLowerCase() {
      return "pdl-artwork-button";
    }
    render() {
      if (this.shadowRoot) return;
      const shadowRoot = this.attachShadow({ mode: "open" });
      const btnProps = { ...this.props };
      shadowRoot.innerHTML = `<style>${wrapperStyle}</style><div class="button-wrapper${btnProps.site ? " " + btnProps.site : ""}"></div>`;
      delete btnProps.site;
      const thumbnailButton = new ThumbnailButton({
        type: ThumbnailBtnType.Gallery,
        ...btnProps
      });
      const wrapper = shadowRoot.querySelector(".button-wrapper");
      wrapper.appendChild(thumbnailButton);
    }
    connectedCallback() {
      this.render();
    }
  }
  customElements.define(ArtworkButton.tagNameLowerCase, ArtworkButton);
  class Rule34 extends SiteInject {
    static get hostname() {
      return "rule34.xxx";
    }
    inject() {
      super.inject();
      const query = location.search;
      if (!query) return;
      const searchParams = new URLSearchParams(query);
      const page = searchParams.get("page");
      const s = searchParams.get("s");
      if (page === "post" && s === "view") {
        if (!document.querySelector("#image, #gelcomVideoPlayer")) return;
        const id = searchParams.get("id");
        this.createArtworkBtn(id);
      } else {
        this.createThumbnailBtn();
      }
    }
    createThumbnailBtn() {
      const btnContainers = document.querySelectorAll(
        ".thumb:not(.blacklisted-image) > a:first-child"
      );
      if (!btnContainers.length) return;
      btnContainers.forEach((el) => {
        el.style.display = "inline-block";
        el.style.position = "relative";
        const imgEl = el.querySelector("img");
        imgEl.style.boxSizing = "border-box";
        let aspectRatio = imgEl.naturalHeight / imgEl.naturalWidth;
        aspectRatio > 1 && (el.style.height = "inherit");
        imgEl.onload = () => {
          aspectRatio = imgEl.naturalHeight / imgEl.naturalWidth;
          aspectRatio > 1 && (el.style.height = "inherit");
        };
        const idMathch = new RegExp("(?<=&id=)\\d+").exec(el.href);
        if (!idMathch) return;
        const id = idMathch[0];
        el.appendChild(
          new ThumbnailButton({
            id,
            onClick: downloadArtwork$2
          })
        );
      });
    }
    createArtworkBtn(id) {
      const btnContainer = document.querySelector("div.flexi > div");
      btnContainer.style.position = "relative";
      btnContainer.appendChild(
        new ArtworkButton({
          id,
          site: "rule34",
          onClick: downloadArtwork$2
        })
      );
    }
    getCustomConfig() {
      return {
        folderPattern: "rule34/{artist}",
        filenamePattern: "{id}_{artist}_{character}"
      };
    }
    getFilenameTemplate() {
      return ["{artist}", "{character}", "{id}", "{date}"];
    }
  }
  function createDanbooruApi() {
    async function requestJson(url2, init2) {
      logger.info("Fetch url:", url2);
      const res = await fetch(url2, init2);
      if (res.status >= 500) throw new RequestError(res.url, res.status);
      const data = await res.json();
      if ("success" in data && !data.success) {
        const { error, message } = data;
        throw new JsonDataError(error + ", " + message);
      }
      return data;
    }
    return {
      async getPool(id) {
        return await requestJson(`/pools/${id}.json`);
      },
      async getPost(id) {
        return await requestJson(`/posts/${id}.json`);
      },
      async getPostList(param) {
        const { tags = [], limit = 0, page = 0 } = param ?? {};
        const searchParam = new URLSearchParams();
        (tags == null ? void 0 : tags.length) && searchParam.append("tags", tags.join(" "));
        limit && searchParam.append("limit", String(limit));
        page && searchParam.append("page", String(page));
        return await requestJson(`/posts.json?${searchParam.toString()}`);
      },
      async getArtistCommentary(id) {
        return await requestJson(`/posts/${id}/artist_commentary.json`);
      },
      async getFavoriteGroups(id) {
        return await requestJson(`/favorite_groups/${id}.json`);
      },
      async getProfile() {
        return await requestJson(`/profile.json`);
      },
      async addFavorite(id, token) {
        const res = await fetch(`/favorites?post_id=${id}`, {
          method: "POST",
          headers: {
            "X-Csrf-Token": token
          }
        });
        if (!res.ok) throw new RequestError(res.url, res.status);
        return await res.text();
      },
      async getDoc(url2) {
        logger.info("Fetch url:", url2);
        const res = await fetch(url2);
        if (!res.ok) throw new RequestError(res.url, res.status);
        const html = await res.text();
        return new DOMParser().parseFromString(html, "text/html");
      }
    };
  }
  const danbooruApi = createDanbooruApi();
  const danbooruParser = {
    async parse(id, params) {
      const { type } = params;
      if (type === "html") {
        return this.parseIdByHtml(id);
      } else {
        return this.parseIdByApi(id);
      }
    },
    async parseIdByHtml(id) {
      var _a, _b, _c;
      const doc = await danbooruApi.getDoc("/posts/" + id);
      const src = (_a = doc.querySelector("a[download]")) == null ? void 0 : _a.href;
      if (!src) throw new Error("Can not get media src");
      const ogImageMeta = doc.querySelector('meta[property="og:image"]');
      const mediaSrc = ogImageMeta.getAttribute("content");
      const title = mediaSrc.slice(mediaSrc.lastIndexOf("/") + 1).split(".")[0];
      const ogTypeMeta = doc.querySelector('meta[property="og:video:type"]') || doc.querySelector('meta[property="og:image:type"]');
      const mimeType = ogTypeMeta.getAttribute("content");
      const extendName = mimeType.slice(mimeType.lastIndexOf("/") + 1);
      const artists = [];
      const characters = [];
      const tags = [];
      const tagLists = doc.querySelectorAll(
        'section#tag-list  ul[class*="-tag-list"]'
      );
      if (tagLists.length) {
        tagLists.forEach((ul) => {
          const tagTypeMatch = /[a-zA-Z]+(?=-tag-list)/.exec(ul.className);
          if (!tagTypeMatch) throw new Error("Unknown tag: " + ul.className);
          const tagType = tagTypeMatch[0];
          const liEls = ul.children;
          let tagRef;
          if (tagType === "artist") {
            tagRef = artists;
          } else if (tagType === "character") {
            tagRef = characters;
          }
          for (let i = 0; i < liEls.length; i++) {
            const tag = liEls[i].getAttribute("data-tag-name");
            if (!tag) continue;
            tagRef && tagRef.push(tag);
            tags.push(tagType + ":" + tag);
          }
        });
      }
      const postDate = ((_b = doc.querySelector("time")) == null ? void 0 : _b.getAttribute("datetime")) ?? "";
      const source = (_c = doc.querySelector("li#post-info-source > a")) == null ? void 0 : _c.href;
      if (source) tags.push("source:" + source);
      let comment = "";
      const commentEl = doc.querySelector("#original-artist-commentary");
      commentEl && (comment = getElementText(commentEl));
      return {
        id,
        src,
        extendName,
        artist: artists.join(",") || "UnknownArtist",
        character: characters.join(",") || "UnknownCharacter",
        title,
        comment,
        tags,
        createDate: postDate
      };
    },
    async parseIdByApi(id) {
      const [postDataResult, commentDataResult] = await Promise.allSettled([
        danbooruApi.getPost(id),
        danbooruApi.getArtistCommentary(id)
      ]);
      if (postDataResult.status === "rejected") throw postDataResult.reason;
      if (commentDataResult.status === "rejected" && !(commentDataResult.reason instanceof JsonDataError))
        throw commentDataResult.reason;
      const {
        created_at,
        file_ext,
        file_url,
        md5,
        tag_string_artist,
        tag_string_character,
        tag_string_copyright,
        tag_string_general,
        tag_string_meta,
        source
      } = postDataResult.value;
      const { original_title = "", original_description = "" } = "value" in commentDataResult ? commentDataResult.value : {};
      const addTypeToTag = (type, tag) => tag.split(" ").map((tag2) => type + ":" + tag2);
      const tags = [
        ...addTypeToTag("artist", tag_string_artist),
        ...addTypeToTag("character", tag_string_character),
        ...addTypeToTag("copyright", tag_string_copyright),
        ...addTypeToTag("general", tag_string_general),
        ...addTypeToTag("meta", tag_string_meta)
      ];
      source && tags.push(`source:${source}`);
      const comment = original_title && original_description ? original_title + "\n" + original_description : original_title || original_description;
      return {
        id,
        src: file_url,
        extendName: file_ext,
        artist: tag_string_artist.replaceAll(" ", ",") || "UnknownArtist",
        character: tag_string_character.replaceAll(" ", ",") || "UnknownCharacter",
        title: md5,
        comment,
        tags,
        createDate: created_at
      };
    },
    async *poolAndGroupGenerator(pageRange, poolOrGroupId, type) {
      const dataPromise = type === "pool" ? danbooruApi.getPool(poolOrGroupId) : danbooruApi.getFavoriteGroups(poolOrGroupId);
      const [data, profile] = await Promise.all([dataPromise, danbooruApi.getProfile()]);
      const { post_ids } = data;
      const { per_page } = profile;
      const [pageStart = null, pageEnd = null] = pageRange ?? [];
      const idsPerPage = [];
      const postCount = post_ids.length;
      for (let i = 0; i < postCount; i += per_page) {
        const ids = post_ids.slice(i, i + per_page).map((id) => String(id));
        idsPerPage.push(ids);
      }
      const poolPage = idsPerPage.length;
      const start = pageStart ?? 1;
      const end = pageEnd ? pageEnd > poolPage ? poolPage : pageEnd : poolPage;
      const total = end === poolPage ? (end - start) * per_page + idsPerPage[poolPage - 1].length : (end - start + 1) * per_page;
      if (start > poolPage) throw new RangeError(`Page ${start} exceeds the limit.`);
      for (let page = start - 1; page < end; page++) {
        yield {
          total,
          page,
          avaliable: idsPerPage[page],
          invalid: [],
          unavaliable: []
        };
      }
    },
    async *postListGenerator(pageRange, checkValidity, tags, limit) {
      const [pageStart = 1, pageEnd = 0] = pageRange ?? [];
      let page = pageStart;
      let postListData = await danbooruApi.getPostList({
        page,
        tags,
        limit
      });
      let total = postListData.length;
      let fetchError = null;
      if (total === 0) throw new Error(`There is no post in page ${page}.`);
      do {
        let nextPageData = null;
        if (page !== pageEnd) {
          try {
            nextPageData = await danbooruApi.getPostList({ page: page + 1, tags, limit });
            if (nextPageData.length) {
              total += nextPageData.length;
            } else {
              nextPageData = null;
            }
          } catch (error) {
            fetchError = error;
            nextPageData = null;
          }
        }
        const avaliable = [];
        const invalid = [];
        const unavaliable = [];
        for (let i = 0; i < postListData.length; i++) {
          const { id, file_ext, tag_string } = postListData[i];
          const idStr = String(id);
          const validityCheckMeta = {
            id: idStr,
            extendName: file_ext,
            tags: tag_string.split(" ")
          };
          const isValid = await checkValidity(validityCheckMeta);
          isValid ? avaliable.push(idStr) : invalid.push(idStr);
        }
        yield {
          total,
          page,
          avaliable,
          invalid,
          unavaliable
        };
        page++;
        postListData = nextPageData;
      } while (postListData);
      if (fetchError) throw fetchError;
    }
  };
  function artworkProgressFactory(btn2) {
    if (!btn2) return;
    return function onArtworkProgress(progress) {
      btn2.setProgress(progress);
    };
  }
  class DanbooruDownloadConfig extends DownloadConfigBuilder {
    constructor(meta) {
      super(meta);
      this.meta = meta;
    }
    getDownloadConfig(btn2) {
      return {
        taskId: Math.random().toString(36).slice(2),
        src: this.meta.src,
        path: this.buildFilePath(),
        source: this.meta,
        timeout: this.isImage() ? 6e4 : void 0,
        onProgress: artworkProgressFactory(btn2)
      };
    }
    buildFilePath() {
      const path = super.buildFilePath();
      return path.replaceAll("{character}", this.normalizeString(this.meta.character));
    }
  }
  class DanbooruPoolButton extends ThumbnailButton {
    constructor(props) {
      super({
        ...props,
        shouldObserveDb: false
      });
      __publicField(this, "downloading");
      this.downloading = props.downloading;
    }
    static get tagNameLowerCase() {
      return "pdl-danbooru-pool-button";
    }
    connectedCallback() {
      super.connectedCallback();
      this.unsubscriber = this.downloading.subscribe((val) => {
        if (val) {
          this.setAttribute("disabled", "");
        } else {
          this.removeAttribute("disabled");
        }
      });
    }
  }
  customElements.define(DanbooruPoolButton.tagNameLowerCase, DanbooruPoolButton);
  async function addBookmark$1(id) {
    var _a;
    try {
      const token = (_a = document.head.querySelector('meta[name="csrf-token"]')) == null ? void 0 : _a.content;
      if (!token) throw new Error("Can not get csrf-token");
      const script = await danbooruApi.addFavorite(id, token);
      const galleryMatch = new RegExp("(?<=^\\/posts\\/)\\d+").exec(location.pathname);
      if (galleryMatch && id !== galleryMatch[0]) {
        _unsafeWindow.Danbooru.Utility.notice("You have favorited " + id);
      } else {
        evalScript(script);
      }
    } catch (error) {
      logger.error(error);
    }
  }
  class Danbooru extends SiteInject {
    constructor() {
      super(...arguments);
      __publicField(this, "useBatchDownload", this.app.initBatchDownloader({
        metaType: {},
        avatar: "/packs/static/danbooru-logo-128x128-ea111b6658173e847734.png",
        filterOption: {
          filters: [
            {
              id: "exclude_downloaded",
              type: "exclude",
              name: t("downloader.category.filter.exclude_downloaded"),
              checked: false,
              fn(meta) {
                return !!meta.id && historyDb.has(meta.id);
              }
            },
            {
              id: "allow_image",
              type: "include",
              name: t("downloader.category.filter.image"),
              checked: true,
              fn(meta) {
                return !!meta.extendName && /bmp|jp(e)?g|png|tif|gif|exif|svg|webp/i.test(meta.extendName);
              }
            },
            {
              id: "allow_video",
              type: "include",
              name: t("downloader.category.filter.video"),
              checked: true,
              fn(meta) {
                return !!meta.extendName && /mp4|avi|mov|mkv|flv|wmv|webm|mpeg|mpg|m4v/i.test(meta.extendName);
              }
            }
          ],
          enableTagFilter: (userTags, metaTags) => {
            const pureTags = metaTags.map((typedTag) => {
              var _a;
              return ((_a = new RegExp("(?<=[a-z]+:).+").exec(typedTag)) == null ? void 0 : _a[0]) ?? "";
            });
            return userTags.some((tag) => pureTags.includes(tag));
          }
        },
        pageMatch: {
          pool: {
            name: "Pool",
            match: new RegExp("(?<=\\/pools\\/)[0-9]+"),
            filterWhenGenerateIngPage: false,
            fn: (pageRange) => {
              var _a;
              const poolId = (_a = new RegExp("(?<=\\/pools\\/)[0-9]+").exec(location.pathname)) == null ? void 0 : _a[0];
              if (!poolId) throw new Error("Invalid pool id");
              return danbooruParser.poolAndGroupGenerator(pageRange, poolId, "pool");
            }
          },
          favorite_groups: {
            name: "FavoriteGroups",
            match: new RegExp("(?<=\\/favorite_groups\\/)[0-9]+"),
            filterWhenGenerateIngPage: false,
            fn: (pageRange) => {
              var _a;
              const groupId = (_a = new RegExp("(?<=\\/favorite_groups\\/)[0-9]+").exec(location.pathname)) == null ? void 0 : _a[0];
              if (!groupId) throw new Error("Invalid pool id");
              return danbooruParser.poolAndGroupGenerator(pageRange, groupId, "favoriteGroup");
            }
          },
          post_list: {
            name: "Post",
            match: /\/posts(?!\/[0-9]+)/,
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              var _a;
              const searchParam = new URLSearchParams(new URL(location.href).search);
              const tags = (_a = searchParam.get("tags")) == null ? void 0 : _a.split(" ");
              const limit = searchParam.get("limit");
              const limitParam = limit ? Number(limit) : void 0;
              return danbooruParser.postListGenerator(pageRange, checkValidity, tags, limitParam);
            }
          },
          pool_gallery_button: {
            name: "pool_gallery_button",
            match: () => false,
            filterWhenGenerateIngPage: false,
            fn: (pageRange, poolId) => {
              if (!poolId) throw new Error("Invalid pool id");
              return danbooruParser.poolAndGroupGenerator(pageRange, poolId, "pool");
            }
          },
          show_downloader_in_pool_gallery: {
            name: "pool_gallery",
            match: /\/pools\/gallery/
          }
        },
        parseMetaByArtworkId(id) {
          return danbooruParser.parseIdByApi(id);
        },
        async downloadByArtworkId(meta, taskId) {
          downloader.dirHandleCheck();
          const downloadConfigs = new DanbooruDownloadConfig(meta).getDownloadConfig();
          downloadConfigs.taskId = taskId;
          await downloader.download(downloadConfigs);
          const { id, tags, artist, title, comment } = meta;
          historyDb.add({
            pid: Number(id),
            user: artist,
            title,
            comment,
            tags
          });
        },
        onDownloadAbort(taskIds) {
          downloader.abort(taskIds);
        }
      }));
    }
    static get hostname() {
      return "danbooru.donmai.us";
    }
    inject() {
      super.inject();
      this.downloadArtwork = this.downloadArtwork.bind(this);
      const path = location.pathname;
      if (/^\/posts\/\d+/.test(path)) {
        const imageContainer = document.querySelector(
          "section.image-container:not(.blacklisted-active)"
        );
        if (!imageContainer) return;
        const id = imageContainer.getAttribute("data-id");
        this.createArtworkBtn(id);
        this.createThumbnailBtn();
      } else if (/^\/pools\/gallery/.test(path)) {
        this.createPoolThumbnailBtn();
      } else {
        this.createThumbnailBtn();
      }
    }
    createThumbnailBtn() {
      const btnContainers = document.querySelectorAll(
        "article a.post-preview-link"
      );
      if (!btnContainers.length) return;
      btnContainers.forEach((el) => {
        var _a;
        const id = (_a = new RegExp("(?<=\\/posts\\/)\\d+").exec(el.href)) == null ? void 0 : _a[0];
        if (!id) return;
        const btn2 = new ThumbnailButton({
          id,
          onClick: this.downloadArtwork
        });
        el.appendChild(btn2);
      });
    }
    createArtworkBtn(id) {
      const btnContainer = document.querySelector(
        "section.image-container:has(picture)"
      );
      btnContainer == null ? void 0 : btnContainer.appendChild(
        new ArtworkButton({
          id,
          onClick: this.downloadArtwork
        })
      );
    }
    createPoolThumbnailBtn() {
      const btnContainers = document.querySelectorAll(
        "article a.post-preview-link"
      );
      if (!btnContainers.length) return;
      const { downloading, batchDownload } = this.useBatchDownload();
      const onClick = (btn2) => {
        const poolId = btn2.dataset.id;
        return batchDownload("pool_gallery_button", poolId);
      };
      btnContainers.forEach((el) => {
        var _a;
        const poolId = (_a = new RegExp("(?<=\\/pools\\/)\\d+").exec(el.href)) == null ? void 0 : _a[0];
        if (!poolId) return;
        const btn2 = new DanbooruPoolButton({ id: poolId, downloading, onClick });
        el.appendChild(btn2);
      });
    }
    observeColorScheme() {
      const query = window.matchMedia("(prefers-color-scheme: dark)");
      let uaPreferDark = query.matches;
      const siteSetting = document.body.getAttribute("data-current-user-theme");
      const sitePreferDark = siteSetting === "dark";
      if (sitePreferDark || siteSetting === "auto" && uaPreferDark) {
        this.setAppDarkMode();
      }
      if (siteSetting === "auto") {
        query.addEventListener("change", (e) => {
          uaPreferDark = e.matches;
          uaPreferDark ? this.setAppDarkMode() : this.setAppLightMode();
        });
      }
    }
    getCustomConfig() {
      return {
        folderPattern: "danbooru/{artist}",
        filenamePattern: "{id}_{artist}_{character}"
      };
    }
    getFilenameTemplate() {
      return ["{artist}", "{character}", "{id}", "{date}"];
    }
    async downloadArtwork(btn2) {
      downloader.dirHandleCheck();
      const id = btn2.dataset.id;
      const mediaMeta = await danbooruParser.parse(id, { type: "api" });
      const downloadConfigs = new DanbooruDownloadConfig(mediaMeta).getDownloadConfig(btn2);
      this.config.get("addBookmark") && addBookmark$1(id);
      await downloader.download(downloadConfigs);
      const { tags, artist, title, comment } = mediaMeta;
      historyDb.add({
        pid: Number(id),
        user: artist,
        title,
        comment,
        tags
      });
    }
  }
  var IllustType = /* @__PURE__ */ ((IllustType2) => {
    IllustType2[IllustType2["illusts"] = 0] = "illusts";
    IllustType2[IllustType2["manga"] = 1] = "manga";
    IllustType2[IllustType2["ugoira"] = 2] = "ugoira";
    return IllustType2;
  })(IllustType || {});
  var BookmarkRestrict = /* @__PURE__ */ ((BookmarkRestrict2) => {
    BookmarkRestrict2[BookmarkRestrict2["public"] = 0] = "public";
    BookmarkRestrict2[BookmarkRestrict2["private"] = 1] = "private";
    return BookmarkRestrict2;
  })(BookmarkRestrict || {});
  function createService() {
    async function _requestJson(url2, init2) {
      logger.info("Fetch url:", url2);
      const res = await fetch(url2, init2);
      if (!res.ok) throw new RequestError(res.url, res.status);
      const data = await res.json();
      if (data.error) throw new JsonDataError(data.message);
      return data.body;
    }
    return {
      async getJson(url2) {
        return await _requestJson(url2);
      },
      async getArtworkHtml(illustId, lang2) {
        const res = await fetch(`/artworks/${illustId}?lang=${lang2}`);
        if (!res.ok) throw new RequestError(res.url, res.status);
        return await res.text();
      },
      getArtworkDetail(illustId, lang2) {
        return _requestJson(`/ajax/illust/${illustId}?lang=${lang2}`);
      },
      getUnlistedArtworkDetail(unlistedId, lang2) {
        return _requestJson(`/ajax/illust/unlisted/${unlistedId}?lang=${lang2}`);
      },
      addBookmark(illustId, token, tags = [], restrict = BookmarkRestrict.public) {
        return _requestJson("/ajax/illusts/bookmarks/add", {
          method: "POST",
          headers: {
            accept: "application/json",
            "content-type": "application/json; charset=utf-8",
            "x-csrf-token": token
          },
          body: JSON.stringify({
            illust_id: illustId,
            restrict,
            comment: "",
            tags
          })
        });
      },
      getFollowLatestWorks(page, mode = "all") {
        return _requestJson(
          `/ajax/follow_latest/illust?p=${page}&mode=${mode}&lang=jp`
        );
      },
      getUserAllProfile(userId) {
        return _requestJson("/ajax/user/" + userId + "/profile/all");
      },
      getUgoiraMeta(illustId) {
        return _requestJson("/ajax/illust/" + illustId + "/ugoira_meta");
      },
      getUserData(userId) {
        return _requestJson("/ajax/user/" + userId);
      },
      getSeriesData(seriesId, page) {
        return _requestJson(`/ajax/series/${seriesId}?p=${page}`);
      }
    };
  }
  const api = createService();
  const regexp = {
    preloadData: /"meta-preload-data" content='(.*?)'>/,
    globalData: /"meta-global-data" content='(.*?)'>/,
    artworksPage: /artworks\/(\d+)$/,
    userPage: /\/users\/(\d+)$|\/users\/(\d+)\/(?!following|mypixiv|followers)/,
    bookmarkPage: /users\/(\d+)\/bookmarks\/artworks/,
    userPageTags: new RegExp("(?<=users\\/)([0-9]+)\\/(artworks|illustrations|manga|bookmarks(?=\\/artworks))(?:\\/artworks)?\\/?([^?]*)"),
    searchPage: /\/tags\/.*\/(artworks|illustrations|manga)/,
    activityHref: /illust_id=(\d+)/,
    originSrcPageNum: new RegExp("(?<=_p)\\d+"),
    followLatest: /\/bookmark_new_illust(?:_r18)?\.php/,
    historyPage: /\/history\.php/,
    historyThumbnailsId: /\d+(?=_)/,
    series: /\/user\/([0-9]+)\/series\/([0-9]+)/,
    unlisted: new RegExp("(?<=artworks\\/unlisted\\/)[A-Za-z0-9]+")
  };
  const pixivParser = {
    async parse(illustId, param) {
      let illustData;
      let token;
      const { tagLang, type } = param;
      if (type === "api") {
        illustData = await api.getArtworkDetail(illustId, tagLang);
        token = "";
      } else if (type === "unlisted") {
        illustData = await api.getUnlistedArtworkDetail(illustId, tagLang);
        token = "";
      } else {
        const htmlText = await api.getArtworkHtml(illustId, tagLang);
        const preloadDataText = htmlText.match(regexp.preloadData);
        if (!preloadDataText) throw new Error("Fail to parse preload data: " + illustId);
        const globalDataText = htmlText.match(regexp.globalData);
        if (!globalDataText) throw new Error("Fail to parse global data: " + illustId);
        const preloadData = JSON.parse(preloadDataText[1]);
        const globalData = JSON.parse(globalDataText[1]);
        illustData = preloadData.illust[illustId];
        token = globalData.token;
      }
      const {
        id,
        illustType,
        userName,
        userId,
        illustTitle,
        illustComment,
        tags,
        pageCount,
        createDate,
        urls,
        bookmarkData
      } = illustData;
      const tagsArr = [];
      const tagsTranslatedArr = [];
      tags.tags.forEach((tagData) => {
        var _a;
        tagsArr.push(tagData.tag);
        tagsTranslatedArr.push(((_a = tagData.translation) == null ? void 0 : _a.en) || tagData.tag);
      });
      const unescapeComment = illustComment.replaceAll(/&lt;|&amp;lt;/g, "<").replaceAll(/&gt;|&amp;gt;/g, ">");
      const p = document.createElement("p");
      p.innerHTML = unescapeComment;
      const comment = getElementText(p);
      const meta = {
        id,
        src: urls.original,
        extendName: urls.original.slice(-3),
        artist: userName,
        title: illustTitle,
        tags: tagsArr,
        tagsTranslated: tagsTranslatedArr,
        userId,
        pageCount,
        comment,
        bookmarkData,
        createDate,
        token
      };
      if (illustType === IllustType.ugoira) {
        return {
          ...meta,
          illustType,
          ugoiraMeta: await api.getUgoiraMeta(illustId)
        };
      } else {
        return {
          ...meta,
          illustType
        };
      }
    },
    async *illustMangaGenerator(pageRange, checkValidity, userId) {
      const ARTWORKS_PER_PAGE = 48;
      const profile = await api.getUserAllProfile(userId);
      let ids = [];
      typeof profile.illusts === "object" && ids.push(...Object.keys(profile.illusts));
      typeof profile.manga === "object" && ids.push(...Object.keys(profile.manga));
      if (!ids.length) throw new Error(`User ${userId} has no illusts or mangas.`);
      ids = ids.sort((a, b) => Number(b) - Number(a));
      let sliceStart;
      let sliceEnd;
      const [startPage = null, endPage = null] = pageRange ?? [];
      let page = startPage ?? 1;
      startPage === null ? sliceStart = 0 : sliceStart = (startPage - 1) * ARTWORKS_PER_PAGE;
      endPage === null ? sliceEnd = ids.length : sliceEnd = endPage * ARTWORKS_PER_PAGE;
      const selectedIds = ids.slice(sliceStart, sliceEnd);
      if (!selectedIds.length) throw new RangeError(`Page ${page} exceeds the limit.`);
      const baseUrl = `https://www.pixiv.net/ajax/user/${userId}/profile/illusts?`;
      const total = selectedIds.length;
      do {
        const chunk = selectedIds.splice(0, ARTWORKS_PER_PAGE);
        const queryStr = chunk.map((id) => "ids[]=" + id).join("&") + `&work_category=illustManga&is_first_page=0&lang=ja`;
        const data = await api.getJson(baseUrl + queryStr);
        const workDatas = Object.values(data.works).sort((a, b) => Number(b.id) - Number(a.id));
        const avaliable = [];
        const invalid = [];
        const unavaliable = [];
        for (let i = 0; i < workDatas.length; i++) {
          const work = workDatas[i];
          const { id, isMasked } = work;
          if (isMasked) {
            unavaliable.push(String(id));
            continue;
          }
          const isValid = await checkValidity(work);
          isValid ? avaliable.push(id) : invalid.push(id);
        }
        yield {
          total,
          page,
          avaliable,
          invalid,
          unavaliable
        };
        page++;
      } while (selectedIds.length > 0);
    },
    async *chunkGenerator(pageRange, checkValidity, userId, category, tag, bookmarkRest = "show") {
      const ARTWORKS_PER_PAGE = 48;
      const [startPage = null, endPage = null] = pageRange ?? [];
      if (!userId) throw new Error('Require argument "userId".');
      let offset;
      let offsetEnd;
      let total;
      let page = startPage ?? 1;
      startPage === null ? offset = 0 : offset = (startPage - 1) * ARTWORKS_PER_PAGE;
      do {
        let requestUrl;
        if (category === "bookmarks") {
          requestUrl = `/ajax/user/${userId}/illusts/bookmarks?tag=${tag}&offset=${offset}&limit=${ARTWORKS_PER_PAGE}&rest=${bookmarkRest}&lang=ja`;
        } else {
          requestUrl = `/ajax/user/${userId}/${category}/tag?tag=${tag}&offset=${offset}&limit=${ARTWORKS_PER_PAGE}&lang=ja`;
        }
        const userPageData = await api.getJson(requestUrl);
        const { works, total: totalArtwork } = userPageData;
        if (totalArtwork === 0)
          throw new Error(`User ${userId} has no ${category} tagged with ${tag}.`);
        if (!offsetEnd) {
          endPage === null ? offsetEnd = totalArtwork : offsetEnd = endPage * ARTWORKS_PER_PAGE > totalArtwork ? totalArtwork : endPage * ARTWORKS_PER_PAGE;
          if (offsetEnd <= offset) throw new RangeError(`Page ${page} exceeds the limit.`);
          total = offsetEnd - offset;
        }
        const avaliable = [];
        const invalid = [];
        const unavaliable = [];
        for (let i = 0; i < works.length; i++) {
          const work = works[i];
          const { id, isMasked } = work;
          if (isMasked) {
            unavaliable.push(String(id));
            continue;
          }
          const isValid = await checkValidity(work);
          isValid ? avaliable.push(id) : invalid.push(id);
        }
        yield {
          total,
          page,
          avaliable,
          invalid,
          unavaliable
        };
        page++;
      } while ((offset += ARTWORKS_PER_PAGE) < offsetEnd);
    },
    async *bookmarkGenerator(pageRange, checkValidity, userId, bookmarkRest = "show", tag = "") {
      yield* this.chunkGenerator(pageRange, checkValidity, userId, "bookmarks", tag, bookmarkRest);
    },
    async *taggedArtworkGenerator(pageRange, checkValidity, userId, category, tag, bookmarkRest = "show") {
      if (category === "bookmarks") {
        yield* this.bookmarkGenerator(pageRange, checkValidity, userId, bookmarkRest, tag);
      } else {
        yield* this.chunkGenerator(pageRange, checkValidity, userId, category, tag);
      }
    },
    async *followLatestGenerator(pageRange, checkValidity, mode = "all") {
      const PAGE_LIMIT = 34;
      const ARTWORKS_PER_PAGE = 60;
      let [startPage = null, endPage = null] = pageRange ?? [];
      startPage === null && (startPage = 1);
      (endPage === null || endPage > PAGE_LIMIT) && (endPage = PAGE_LIMIT);
      if (startPage > PAGE_LIMIT) throw new RangeError(`Page ${startPage} exceeds the limit.`);
      let earliestId;
      let total;
      let cache;
      let page = startPage;
      function findEarliestId(ids2) {
        return Math.min(...ids2);
      }
      async function* yieldData(data2, page2) {
        const avaliable = [];
        const invalid = [];
        const unavaliable = [];
        const { illust } = data2.thumbnails;
        for (let i = 0; i < illust.length; i++) {
          const work = illust[i];
          const { id, isMasked } = work;
          if (isMasked) {
            unavaliable.push(String(id));
            continue;
          }
          const isValid = await checkValidity(work);
          isValid ? avaliable.push(id) : invalid.push(id);
        }
        const { ids: ids2 } = data2.page;
        if (ids2.length !== illust.length) {
          const idDiff = ids2.filter((id) => !illust.some((item) => +item.id === id));
          unavaliable.push(...idDiff.map((id) => String(id)));
        }
        yield {
          total,
          page: page2,
          avaliable,
          invalid,
          unavaliable
        };
      }
      const data = await api.getFollowLatestWorks(page, mode);
      const ids = data.page.ids;
      total = ids.length;
      earliestId = findEarliestId(ids);
      if (endPage === startPage) {
        yield* yieldData(data, startPage);
        return;
      }
      if (total === ARTWORKS_PER_PAGE) {
        const secondPageData = await api.getFollowLatestWorks(++page, mode);
        const secondIds = secondPageData.page.ids;
        const secondPageEarliestId = findEarliestId(secondIds);
        if (secondPageEarliestId < earliestId) {
          earliestId = secondPageEarliestId;
          cache = secondPageData;
          total += secondIds.length;
        }
      }
      yield* yieldData(data, startPage);
      if (total === ARTWORKS_PER_PAGE) return;
      if (total < ARTWORKS_PER_PAGE * 2 || endPage - startPage === 1) {
        yield* yieldData(cache, page);
        return;
      }
      while (++page <= endPage) {
        const data2 = await api.getFollowLatestWorks(page, mode);
        const ids2 = data2.page.ids;
        const pageEarliestId = findEarliestId(ids2);
        if (pageEarliestId >= earliestId) {
          logger.info("getFollowLatestGenerator: got duplicate works");
          yield* yieldData(cache, page - 1);
          break;
        }
        earliestId = pageEarliestId;
        total += ids2.length;
        yield* yieldData(cache, page - 1);
        cache = data2;
      }
      yield* yieldData(cache, page - 1);
    },
    async *seriesGenerator(pageRange, checkValidity, seriesId) {
      const [startPage = 1, endPage = 0] = pageRange ?? [];
      let yieldedId = 0;
      let total = 0;
      let currentPage = startPage;
      do {
        const seriesData = await api.getSeriesData(seriesId, currentPage);
        const { series } = seriesData.page;
        if (!series.length) throw new Error(`Invalid page: ${currentPage}`);
        const { illust } = seriesData.thumbnails;
        if (!total) {
          const isLastPage = series.some(({ order }) => order === 1);
          const totalWorkCount = seriesData.page.total;
          if (isLastPage) {
            total = series.length;
          } else if (endPage === 0) {
            total = totalWorkCount;
          } else {
            const artworksPerPage = series.length;
            const lastPage = Math.ceil(totalWorkCount / artworksPerPage);
            if (endPage >= lastPage) {
              const lastPageWorkCount = totalWorkCount % artworksPerPage || artworksPerPage;
              total = (lastPage - startPage) * artworksPerPage + lastPageWorkCount;
            } else {
              total = (endPage - startPage + 1) * artworksPerPage;
            }
          }
        }
        const avaliable = [];
        const invalid = [];
        const unavaliable = [];
        for (let i = 0; i < series.length; i++) {
          const { workId } = series[i];
          const thumbnail = illust.find((thumbnail2) => thumbnail2.id === workId);
          if (!thumbnail || thumbnail.isMasked) {
            unavaliable.push(workId);
            continue;
          }
          const isValid = await checkValidity(thumbnail);
          isValid ? avaliable.push(workId) : invalid.push(workId);
        }
        yield {
          total,
          page: currentPage,
          avaliable,
          invalid,
          unavaliable
        };
        yieldedId += series.length;
        currentPage++;
      } while (yieldedId < total);
    }
  };
  function createCompressor() {
    const zip = new JSZip();
    return {
      add(id, name, data) {
        var _a;
        (_a = zip.folder(id)) == null ? void 0 : _a.file(name, data);
      },
      bundle(id, comment) {
        const folder = zip.folder(id);
        if (!folder) throw new TypeError("no such folder:" + id);
        return folder.generateAsync({ type: "blob", comment });
      },
      remove(ids) {
        if (typeof ids === "string") {
          zip.remove(ids);
        } else {
          const dirs = zip.filter((_, file) => file.dir).map((dir) => dir.name);
          const dirsToDel = ids.filter((id) => dirs.some((dir) => dir.includes(id)));
          dirsToDel.forEach((dir) => zip.remove(dir));
          logger.info("Compressor: Remove", zip);
        }
      },
      fileCount(id) {
        var _a;
        let count = 0;
        (_a = zip.folder(id)) == null ? void 0 : _a.forEach(() => count++);
        return count;
      },
      async unzip(data) {
        const id = Math.random().toString(36);
        let folder = zip.folder(id);
        if (!folder) throw TypeError("Can not get new root folder");
        const filesPromises = [];
        folder = await folder.loadAsync(data);
        folder.forEach((_, file) => {
          filesPromises.push(file.async("blob"));
        });
        const files = await Promise.all(filesPromises);
        zip.remove(id);
        return files;
      }
    };
  }
  const compressor = createCompressor();
  const gifWorker = (() => GM_getResourceText("gif.js/dist/gif.worker?raw"))();
  const workerUrl$2 = URL.createObjectURL(new Blob([gifWorker], { type: "text/javascript" }));
  function gif(frames, convertMeta) {
    return Promise.all(
      frames.map((frame) => {
        if (frame instanceof Blob) {
          return createImageBitmap(frame);
        } else {
          return frame;
        }
      })
    ).then((bitmaps) => {
      return new Promise((resolve, reject) => {
        logger.info("Start convert:", convertMeta.id);
        logger.time(convertMeta.id);
        const canvas = document.createElement("canvas");
        const width = canvas.width = bitmaps[0].width;
        const height = canvas.height = bitmaps[0].height;
        const ctx = canvas.getContext("2d", { willReadFrequently: true });
        const gif2 = new GIF({
          workers: 2,
          quality: config.get("gifQuality"),
          width,
          height,
          workerScript: workerUrl$2
        });
        convertMeta.abort = () => {
          gif2.abort();
        };
        bitmaps.forEach((bitmap, i) => {
          ctx.drawImage(bitmap, 0, 0);
          gif2.addFrame(ctx, {
            copy: true,
            delay: convertMeta.source.delays[i]
          });
          bitmap.close();
        });
        gif2.on("progress", (progress) => {
          var _a;
          (_a = convertMeta.onProgress) == null ? void 0 : _a.call(convertMeta, progress * 100);
        });
        gif2.on("finished", (gifBlob) => {
          logger.timeEnd(convertMeta.id);
          resolve(gifBlob);
        });
        gif2.on("abort", () => {
          logger.timeEnd(convertMeta.id);
          logger.warn("Convert stop manually. " + convertMeta.id);
          convertMeta.isAborted = true;
          reject(new CancelError());
        });
        gif2.render();
      });
    });
  }
  const pngWorkerFragment = 'async function encodeAPNG(frames, delays, cnum) {\n    const bitmaps = await Promise.all(frames.map((frame) => {\n        if (frame instanceof Blob) {\n            return createImageBitmap(frame);\n        }\n        else {\n            return frame;\n        }\n    }));\n    const width = bitmaps[0].width;\n    const height = bitmaps[0].height;\n    const canvas = new OffscreenCanvas(width, height);\n    const ctx = canvas.getContext("2d", { willReadFrequently: true });\n    const u8arrs = [];\n    for (let i = 0; i < bitmaps.length; i++) {\n        ctx.drawImage(bitmaps[i], 0, 0);\n        bitmaps[i].close();\n        u8arrs.push(ctx.getImageData(0, 0, width, height).data);\n    }\n    const png = UPNG.encode(u8arrs, width, height, cnum, delays, { loop: 0 });\n    if (!png)\n        throw new Error("Failed to encode apng.");\n    return png;\n}\nasync function decodeApng(ab) {\n    const img = UPNG.decode(ab);\n    const rgba = UPNG.toRGBA8(img);\n    const { width, height } = img;\n    const delays = img.frames.map((frame) => frame.delay);\n    return { frames: rgba, delays, width, height };\n}\nasync function appendEffect(illustBlob, effect, delays, width, height) {\n    if (!Array.isArray(effect)) {\n        const apngDatas = await decodeApng(effect);\n        effect = apngDatas.frames;\n        delays = apngDatas.delays;\n        width = apngDatas.width;\n        height = apngDatas.height;\n    }\n    else {\n        if (!delays || width === void 0 || height === void 0)\n            throw new Error("Missing argument.");\n    }\n    const illustBitmap = await createImageBitmap(illustBlob);\n    const effectBitmaps = await Promise.all(effect.map((buf) => createImageBitmap(new ImageData(new Uint8ClampedArray(buf), width, height))));\n    const { width: illustWidth, height: illustHeight } = illustBitmap;\n    const illustAspectRatio = illustWidth / illustHeight;\n    const effectAspectRatio = width / height;\n    let dx;\n    let dy;\n    let dWidth;\n    let dHeight;\n    if (effectAspectRatio > illustAspectRatio) {\n        dWidth = illustHeight * effectAspectRatio;\n        dHeight = illustHeight;\n        dx = (illustWidth - dWidth) / 2;\n        dy = 0;\n    }\n    else {\n        dWidth = illustWidth;\n        dHeight = illustWidth / effectAspectRatio;\n        dx = 0;\n        dy = (illustHeight - dHeight) / 2;\n    }\n    const canvas = new OffscreenCanvas(illustWidth, illustHeight);\n    const ctx = canvas.getContext("2d", { willReadFrequently: true });\n    const finalDatas = [];\n    for (let i = 0; i < effectBitmaps.length; i++) {\n        ctx.drawImage(illustBitmap, 0, 0);\n        ctx.drawImage(effectBitmaps[i], dx, dy, dWidth, dHeight);\n        finalDatas.push(ctx.getImageData(0, 0, illustWidth, illustHeight));\n        effectBitmaps[i].close();\n    }\n    illustBitmap.close();\n    const bitmaps = [];\n    for (let i = 0; i < finalDatas.length; i++) {\n        const bitmap = await createImageBitmap(finalDatas[i]);\n        bitmaps.push(bitmap);\n    }\n    return {\n        bitmaps,\n        frames: effect,\n        width,\n        height,\n        delays\n    };\n}\nself.onmessage = async (evt) => {\n    try {\n        const data = evt.data;\n        if ("effect" in data) {\n            let result;\n            if ("delays" in data) {\n                const { illust, effect, width, height, delays } = data;\n                result = await appendEffect(illust, effect, delays, width, height);\n            }\n            else {\n                const { illust, effect } = data;\n                result = await appendEffect(illust, effect);\n            }\n            self.postMessage(result, [...result.frames, ...result.bitmaps]);\n        }\n        else {\n            const { frames, delays, cnum = 256 } = data;\n            const apng = await encodeAPNG(frames, delays, cnum);\n            self.postMessage(apng, [apng]);\n        }\n    }\n    catch (error) {\n        console.error(error);\n        self.postMessage(void 0);\n    }\n};\n';
  const UPNG = (() => GM_getResourceText("upng-js?raw"))();
  const pako = (() => GM_getResourceText("pako/dist/pako.js?raw"))();
  const workerUrl$1 = URL.createObjectURL(
    new Blob(
      [
        pngWorkerFragment + pako + UPNG.replace("window.UPNG", "self.UPNG").replace("window.pako", "self.pako")
      ],
      {
        type: "text/javascript"
      }
    )
  );
  const freeApngWorkers = [];
  function png(frames, convertMeta) {
    return new Promise((resolve, reject) => {
      logger.info("Start convert:", convertMeta.id);
      logger.time(convertMeta.id);
      let worker;
      if (freeApngWorkers.length) {
        worker = freeApngWorkers.shift();
        logger.info("Reuse apng workers.");
      } else {
        worker = new Worker(workerUrl$1);
      }
      convertMeta.abort = () => {
        logger.timeEnd(convertMeta.id);
        logger.warn("Convert stop manually. " + convertMeta.id);
        reject(new CancelError());
        convertMeta.isAborted = true;
        worker.terminate();
      };
      worker.onmessage = function(e) {
        freeApngWorkers.push(worker);
        logger.timeEnd(convertMeta.id);
        if (!e.data) {
          return reject(new TypeError("Failed to get png data. " + convertMeta.id));
        }
        const pngBlob = new Blob([e.data], { type: "image/png" });
        resolve(pngBlob);
      };
      const delays = convertMeta.source.delays;
      const cfg = { frames, delays, cnum: config.get("pngColor") };
      worker.postMessage(
        cfg,
        cfg.frames[0] instanceof ImageBitmap ? cfg.frames : []
      );
    });
  }
  function mixPngEffect(convertMeta) {
    logger.info("Start convert:", convertMeta.id);
    logger.time(convertMeta.id);
    const { illust, data } = convertMeta.source;
    let p;
    if (data instanceof Blob) {
      p = data.arrayBuffer();
    } else {
      p = Promise.resolve(data);
    }
    return p.then((effect) => {
      return new Promise((resolve, reject) => {
        let worker;
        if (freeApngWorkers.length) {
          worker = freeApngWorkers.shift();
          logger.info("Reuse apng workers.");
        } else {
          worker = new Worker(workerUrl$1);
        }
        convertMeta.abort = () => {
          logger.timeEnd(convertMeta.id);
          logger.warn("Convert stop manually. " + convertMeta.id);
          reject(new CancelError());
          convertMeta.isAborted = true;
          worker.terminate();
        };
        worker.onmessage = function(e) {
          logger.timeEnd(convertMeta.id);
          worker.terminate();
          if (!e.data) {
            return reject(new Error("Mix Effect convert Failed " + convertMeta.id));
          }
          resolve(e.data);
        };
        let cfg;
        if (effect instanceof ArrayBuffer) {
          cfg = { illust, effect };
          worker.postMessage(cfg, [effect]);
        } else {
          const { frames, delays, width, height } = effect;
          cfg = { illust, delays, effect: frames, width, height };
          worker.postMessage(cfg, frames);
        }
      });
    });
  }
  const webpWorkerFragment = 'let webpApi = {};\nModule.onRuntimeInitialized = () => {\n    webpApi = {\n        init: Module.cwrap("init", "", ["number", "number", "number"]),\n        createBuffer: Module.cwrap("createBuffer", "number", ["number"]),\n        addFrame: Module.cwrap("addFrame", "number", ["number", "number", "number"]),\n        generate: Module.cwrap("generate", "number", []),\n        freeResult: Module.cwrap("freeResult", "", []),\n        getResultPointer: Module.cwrap("getResultPointer", "number", []),\n        getResultSize: Module.cwrap("getResultSize", "number", [])\n    };\n    postMessage("ok");\n};\nonmessage = async (evt) => {\n    const { frames, delays, lossless = 0, quality = 95, method = 4 } = evt.data;\n    webpApi.init(lossless, quality, method);\n    const bitmaps = await Promise.all(frames.map((frame) => {\n        if (frame instanceof Blob) {\n            return createImageBitmap(frame);\n        }\n        else {\n            return frame;\n        }\n    }));\n    const width = bitmaps[0].width;\n    const height = bitmaps[0].height;\n    const canvas = new OffscreenCanvas(width, height);\n    const ctx = canvas.getContext("2d");\n    for (let i = 0; i < bitmaps.length; i++) {\n        ctx?.drawImage(bitmaps[i], 0, 0);\n        bitmaps[i].close();\n        const webpBlob = await canvas.convertToBlob({\n            type: "image/webp",\n            quality: lossless ? 1 : quality / 100\n        });\n        const buffer = await webpBlob.arrayBuffer();\n        const u8a = new Uint8Array(buffer);\n        const pointer = webpApi.createBuffer(u8a.length);\n        Module.HEAPU8.set(u8a, pointer);\n        webpApi.addFrame(pointer, u8a.length, delays[i]);\n        postMessage((i + 1) / bitmaps.length * 100);\n    }\n    webpApi.generate();\n    const resultPointer = webpApi.getResultPointer();\n    const resultSize = webpApi.getResultSize();\n    const result = new Uint8Array(Module.HEAP8.buffer, resultPointer, resultSize);\n    postMessage(result);\n    webpApi.freeResult();\n};\n';
  const webpWasm = (() => GM_getResourceText("../wasm/toWebpWorker?raw"))();
  const workerUrl = URL.createObjectURL(
    new Blob([webpWasm + webpWorkerFragment], { type: "text/javascript" })
  );
  const freeWebpWorkers = [];
  function webp(frames, convertMeta) {
    return new Promise((resolve, reject) => {
      logger.time(convertMeta.id);
      let worker;
      if (freeWebpWorkers.length) {
        logger.info("Reuse webp workers.");
        worker = freeWebpWorkers.shift();
        resolve(worker);
      } else {
        worker = new Worker(workerUrl);
        worker.onmessage = (evt) => {
          if (evt.data === "ok") {
            logger.info("Webp worker loaded.");
            resolve(worker);
          } else {
            reject(evt.data);
          }
        };
      }
    }).then((worker) => {
      if (convertMeta.isAborted) {
        freeWebpWorkers.push(worker);
        logger.timeEnd(convertMeta.id);
        logger.warn("Convert stop manually." + convertMeta.id);
        throw new CancelError();
      }
      return new Promise((resolve, reject) => {
        worker.onmessage = (evt) => {
          var _a;
          if (convertMeta.isAborted) {
            worker.terminate();
            logger.timeEnd(convertMeta.id);
            logger.warn("Convert stop manually." + convertMeta.id);
            reject(new CancelError());
          } else {
            const data = evt.data;
            if (typeof data !== "object") {
              (_a = convertMeta.onProgress) == null ? void 0 : _a.call(convertMeta, evt.data);
            } else {
              logger.timeEnd(convertMeta.id);
              freeWebpWorkers.push(worker);
              resolve(new Blob([evt.data], { type: "image/webp" }));
            }
          }
        };
        const delays = convertMeta.source.delays;
        worker.postMessage(
          {
            frames,
            delays,
            lossless: Number(config.get("losslessWebp")),
            quality: config.get("webpQuality"),
            method: config.get("webpMehtod")
          },
          frames[0] instanceof ImageBitmap ? frames : []
        );
      });
    });
  }
  function getDefaultExportFromCjs(x) {
    return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
  }
  var WebMWriter$1 = { exports: {} };
  (function(module) {
    (function() {
      function extend(base, top) {
        let target = {};
        [base, top].forEach(function(obj) {
          for (let prop in obj) {
            if (Object.prototype.hasOwnProperty.call(obj, prop)) {
              target[prop] = obj[prop];
            }
          }
        });
        return target;
      }
      function decodeBase64WebPDataURL(url2) {
        if (typeof url2 !== "string" || !url2.match(/^data:image\/webp;base64,/i)) {
          throw new Error("Failed to decode WebP Base64 URL");
        }
        return window.atob(url2.substring("data:image/webp;base64,".length));
      }
      function renderAsWebP(canvas, quality) {
        let frame = typeof canvas === "string" && /^data:image\/webp/.test(canvas) ? canvas : canvas.toDataURL("image/webp", quality);
        return decodeBase64WebPDataURL(frame);
      }
      function byteStringToUint32LE(string) {
        let a = string.charCodeAt(0), b = string.charCodeAt(1), c = string.charCodeAt(2), d = string.charCodeAt(3);
        return (a | b << 8 | c << 16 | d << 24) >>> 0;
      }
      function extractKeyframeFromWebP(webP) {
        let cursor = webP.indexOf("VP8", 12);
        if (cursor === -1) {
          throw new Error("Bad image format, does this browser support WebP?");
        }
        let hasAlpha = false;
        while (cursor < webP.length - 8) {
          let chunkLength, fourCC;
          fourCC = webP.substring(cursor, cursor + 4);
          cursor += 4;
          chunkLength = byteStringToUint32LE(webP.substring(cursor, cursor + 4));
          cursor += 4;
          switch (fourCC) {
            case "VP8 ":
              return {
                frame: webP.substring(cursor, cursor + chunkLength),
                hasAlpha
              };
            case "ALPH":
              hasAlpha = true;
              break;
          }
          cursor += chunkLength;
          if ((chunkLength & 1) !== 0) {
            cursor++;
          }
        }
        throw new Error("Failed to find VP8 keyframe in WebP image, is this image mistakenly encoded in the Lossless WebP format?");
      }
      const EBML_SIZE_UNKNOWN = -1, EBML_SIZE_UNKNOWN_5_BYTES = -2;
      function EBMLFloat32(value) {
        this.value = value;
      }
      function EBMLFloat64(value) {
        this.value = value;
      }
      function writeEBML(buffer, bufferFileOffset, ebml) {
        if (Array.isArray(ebml)) {
          for (let i = 0; i < ebml.length; i++) {
            writeEBML(buffer, bufferFileOffset, ebml[i]);
          }
        } else if (typeof ebml === "string") {
          buffer.writeString(ebml);
        } else if (ebml instanceof Uint8Array) {
          buffer.writeBytes(ebml);
        } else if (ebml.id) {
          ebml.offset = buffer.pos + bufferFileOffset;
          buffer.writeUnsignedIntBE(ebml.id);
          if (Array.isArray(ebml.data)) {
            let sizePos, dataBegin, dataEnd;
            if (ebml.size === EBML_SIZE_UNKNOWN) {
              buffer.writeByte(255);
            } else if (ebml.size === EBML_SIZE_UNKNOWN_5_BYTES) {
              sizePos = buffer.pos;
              buffer.writeBytes([15, 255, 255, 255, 255]);
            } else {
              sizePos = buffer.pos;
              buffer.writeBytes([0, 0, 0, 0]);
            }
            dataBegin = buffer.pos;
            ebml.dataOffset = dataBegin + bufferFileOffset;
            writeEBML(buffer, bufferFileOffset, ebml.data);
            if (ebml.size !== EBML_SIZE_UNKNOWN && ebml.size !== EBML_SIZE_UNKNOWN_5_BYTES) {
              dataEnd = buffer.pos;
              ebml.size = dataEnd - dataBegin;
              buffer.seek(sizePos);
              buffer.writeEBMLVarIntWidth(ebml.size, 4);
              buffer.seek(dataEnd);
            }
          } else if (typeof ebml.data === "string") {
            buffer.writeEBMLVarInt(ebml.data.length);
            ebml.dataOffset = buffer.pos + bufferFileOffset;
            buffer.writeString(ebml.data);
          } else if (typeof ebml.data === "number") {
            if (!ebml.size) {
              ebml.size = buffer.measureUnsignedInt(ebml.data);
            }
            buffer.writeEBMLVarInt(ebml.size);
            ebml.dataOffset = buffer.pos + bufferFileOffset;
            buffer.writeUnsignedIntBE(ebml.data, ebml.size);
          } else if (ebml.data instanceof EBMLFloat64) {
            buffer.writeEBMLVarInt(8);
            ebml.dataOffset = buffer.pos + bufferFileOffset;
            buffer.writeDoubleBE(ebml.data.value);
          } else if (ebml.data instanceof EBMLFloat32) {
            buffer.writeEBMLVarInt(4);
            ebml.dataOffset = buffer.pos + bufferFileOffset;
            buffer.writeFloatBE(ebml.data.value);
          } else if (ebml.data instanceof Uint8Array) {
            buffer.writeEBMLVarInt(ebml.data.byteLength);
            ebml.dataOffset = buffer.pos + bufferFileOffset;
            buffer.writeBytes(ebml.data);
          } else {
            throw new Error("Bad EBML datatype " + typeof ebml.data);
          }
        } else {
          throw new Error("Bad EBML datatype " + typeof ebml.data);
        }
      }
      let WebMWriter2 = function(ArrayBufferDataStream2, BlobBuffer2) {
        return function(options) {
          let MAX_CLUSTER_DURATION_MSEC = 5e3, DEFAULT_TRACK_NUMBER = 1, writtenHeader = false, videoWidth = 0, videoHeight = 0, alphaBuffer = null, alphaBufferContext = null, alphaBufferData = null, clusterFrameBuffer = [], clusterStartTime = 0, clusterDuration = 0, optionDefaults = {
            quality: 0.95,
            // WebM image quality from 0.0 (worst) to 0.99999 (best), 1.00 (WebP lossless) is not supported
            transparent: false,
            // True if an alpha channel should be included in the video
            alphaQuality: void 0,
            // Allows you to set the quality level of the alpha channel separately.
            // If not specified this defaults to the same value as `quality`.
            fileWriter: null,
            // Chrome FileWriter in order to stream to a file instead of buffering to memory (optional)
            fd: null,
            // Node.JS file descriptor to write to instead of buffering (optional)
            // You must supply one of:
            frameDuration: null,
            // Duration of frames in milliseconds
            frameRate: null
            // Number of frames per second
          }, seekPoints = {
            Cues: { id: new Uint8Array([28, 83, 187, 107]), positionEBML: null },
            SegmentInfo: { id: new Uint8Array([21, 73, 169, 102]), positionEBML: null },
            Tracks: { id: new Uint8Array([22, 84, 174, 107]), positionEBML: null }
          }, ebmlSegment, segmentDuration = {
            "id": 17545,
            // Duration
            "data": new EBMLFloat64(0)
          }, seekHead, cues = [], blobBuffer = new BlobBuffer2(options.fileWriter || options.fd);
          function fileOffsetToSegmentRelative(fileOffset) {
            return fileOffset - ebmlSegment.dataOffset;
          }
          function convertAlphaToGrayscaleImage(source) {
            if (alphaBuffer === null || alphaBuffer.width !== source.width || alphaBuffer.height !== source.height) {
              alphaBuffer = document.createElement("canvas");
              alphaBuffer.width = source.width;
              alphaBuffer.height = source.height;
              alphaBufferContext = alphaBuffer.getContext("2d");
              alphaBufferData = alphaBufferContext.createImageData(alphaBuffer.width, alphaBuffer.height);
            }
            let sourceContext = source.getContext("2d"), sourceData = sourceContext.getImageData(0, 0, source.width, source.height).data, destData = alphaBufferData.data, dstCursor = 0, srcEnd = source.width * source.height * 4;
            for (let srcCursor = 3; srcCursor < srcEnd; srcCursor += 4) {
              let alpha = sourceData[srcCursor];
              destData[dstCursor++] = alpha;
              destData[dstCursor++] = alpha;
              destData[dstCursor++] = alpha;
              destData[dstCursor++] = 255;
            }
            alphaBufferContext.putImageData(alphaBufferData, 0, 0);
            return alphaBuffer;
          }
          function createSeekHead() {
            let seekPositionEBMLTemplate = {
              "id": 21420,
              // SeekPosition
              "size": 5,
              // Allows for 32GB video files
              "data": 0
              // We'll overwrite this when the file is complete
            }, result = {
              "id": 290298740,
              // SeekHead
              "data": []
            };
            for (let name in seekPoints) {
              let seekPoint = seekPoints[name];
              seekPoint.positionEBML = Object.create(seekPositionEBMLTemplate);
              result.data.push({
                "id": 19899,
                // Seek
                "data": [
                  {
                    "id": 21419,
                    // SeekID
                    "data": seekPoint.id
                  },
                  seekPoint.positionEBML
                ]
              });
            }
            return result;
          }
          function writeHeader() {
            seekHead = createSeekHead();
            let ebmlHeader = {
              "id": 440786851,
              // EBML
              "data": [
                {
                  "id": 17030,
                  // EBMLVersion
                  "data": 1
                },
                {
                  "id": 17143,
                  // EBMLReadVersion
                  "data": 1
                },
                {
                  "id": 17138,
                  // EBMLMaxIDLength
                  "data": 4
                },
                {
                  "id": 17139,
                  // EBMLMaxSizeLength
                  "data": 8
                },
                {
                  "id": 17026,
                  // DocType
                  "data": "webm"
                },
                {
                  "id": 17031,
                  // DocTypeVersion
                  "data": 2
                },
                {
                  "id": 17029,
                  // DocTypeReadVersion
                  "data": 2
                }
              ]
            }, segmentInfo = {
              "id": 357149030,
              // Info
              "data": [
                {
                  "id": 2807729,
                  // TimecodeScale
                  "data": 1e6
                  // Times will be in miliseconds (1e6 nanoseconds per step = 1ms)
                },
                {
                  "id": 19840,
                  // MuxingApp
                  "data": "webm-writer-js"
                },
                {
                  "id": 22337,
                  // WritingApp
                  "data": "webm-writer-js"
                },
                segmentDuration
                // To be filled in later
              ]
            }, videoProperties = [
              {
                "id": 176,
                // PixelWidth
                "data": videoWidth
              },
              {
                "id": 186,
                // PixelHeight
                "data": videoHeight
              }
            ];
            if (options.transparent) {
              videoProperties.push(
                {
                  "id": 21440,
                  // AlphaMode
                  "data": 1
                }
              );
            }
            let tracks = {
              "id": 374648427,
              // Tracks
              "data": [
                {
                  "id": 174,
                  // TrackEntry
                  "data": [
                    {
                      "id": 215,
                      // TrackNumber
                      "data": DEFAULT_TRACK_NUMBER
                    },
                    {
                      "id": 29637,
                      // TrackUID
                      "data": DEFAULT_TRACK_NUMBER
                    },
                    {
                      "id": 156,
                      // FlagLacing
                      "data": 0
                    },
                    {
                      "id": 2274716,
                      // Language
                      "data": "und"
                    },
                    {
                      "id": 134,
                      // CodecID
                      "data": "V_VP8"
                    },
                    {
                      "id": 2459272,
                      // CodecName
                      "data": "VP8"
                    },
                    {
                      "id": 131,
                      // TrackType
                      "data": 1
                    },
                    {
                      "id": 224,
                      // Video
                      "data": videoProperties
                    }
                  ]
                }
              ]
            };
            ebmlSegment = {
              "id": 408125543,
              // Segment
              "size": EBML_SIZE_UNKNOWN_5_BYTES,
              // We'll seek back and fill this in at completion
              "data": [
                seekHead,
                segmentInfo,
                tracks
              ]
            };
            let bufferStream = new ArrayBufferDataStream2(256);
            writeEBML(bufferStream, blobBuffer.pos, [ebmlHeader, ebmlSegment]);
            blobBuffer.write(bufferStream.getAsDataArray());
            seekPoints.SegmentInfo.positionEBML.data = fileOffsetToSegmentRelative(segmentInfo.offset);
            seekPoints.Tracks.positionEBML.data = fileOffsetToSegmentRelative(tracks.offset);
            writtenHeader = true;
          }
          function createBlockGroupForTransparentKeyframe(keyframe) {
            let block, blockAdditions, bufferStream = new ArrayBufferDataStream2(1 + 2 + 1);
            if (!(keyframe.trackNumber > 0 && keyframe.trackNumber < 127)) {
              throw new Error("TrackNumber must be > 0 and < 127");
            }
            bufferStream.writeEBMLVarInt(keyframe.trackNumber);
            bufferStream.writeU16BE(keyframe.timecode);
            bufferStream.writeByte(0);
            block = {
              "id": 161,
              // Block
              "data": [
                bufferStream.getAsDataArray(),
                keyframe.frame
              ]
            };
            blockAdditions = {
              "id": 30113,
              // BlockAdditions
              "data": [
                {
                  "id": 166,
                  // BlockMore
                  "data": [
                    {
                      "id": 238,
                      // BlockAddID
                      "data": 1
                      // Means "BlockAdditional has a codec-defined meaning, pass it to the codec"
                    },
                    {
                      "id": 165,
                      // BlockAdditional
                      "data": keyframe.alpha
                      // The actual alpha channel image
                    }
                  ]
                }
              ]
            };
            return {
              "id": 160,
              // BlockGroup
              "data": [
                block,
                blockAdditions
              ]
            };
          }
          function createSimpleBlockForKeyframe(keyframe) {
            let bufferStream = new ArrayBufferDataStream2(1 + 2 + 1);
            if (!(keyframe.trackNumber > 0 && keyframe.trackNumber < 127)) {
              throw new Error("TrackNumber must be > 0 and < 127");
            }
            bufferStream.writeEBMLVarInt(keyframe.trackNumber);
            bufferStream.writeU16BE(keyframe.timecode);
            bufferStream.writeByte(
              1 << 7
              // Keyframe
            );
            return {
              "id": 163,
              // SimpleBlock
              "data": [
                bufferStream.getAsDataArray(),
                keyframe.frame
              ]
            };
          }
          function createContainerForKeyframe(keyframe) {
            if (keyframe.alpha) {
              return createBlockGroupForTransparentKeyframe(keyframe);
            }
            return createSimpleBlockForKeyframe(keyframe);
          }
          function createCluster(cluster) {
            return {
              "id": 524531317,
              "data": [
                {
                  "id": 231,
                  // Timecode
                  "data": Math.round(cluster.timecode)
                }
              ]
            };
          }
          function addCuePoint(trackIndex, clusterTime, clusterFileOffset) {
            cues.push({
              "id": 187,
              // Cue
              "data": [
                {
                  "id": 179,
                  // CueTime
                  "data": clusterTime
                },
                {
                  "id": 183,
                  // CueTrackPositions
                  "data": [
                    {
                      "id": 247,
                      // CueTrack
                      "data": trackIndex
                    },
                    {
                      "id": 241,
                      // CueClusterPosition
                      "data": fileOffsetToSegmentRelative(clusterFileOffset)
                    }
                  ]
                }
              ]
            });
          }
          function writeCues() {
            let ebml = {
              "id": 475249515,
              "data": cues
            }, cuesBuffer = new ArrayBufferDataStream2(16 + cues.length * 32);
            writeEBML(cuesBuffer, blobBuffer.pos, ebml);
            blobBuffer.write(cuesBuffer.getAsDataArray());
            seekPoints.Cues.positionEBML.data = fileOffsetToSegmentRelative(ebml.offset);
          }
          function flushClusterFrameBuffer() {
            if (clusterFrameBuffer.length === 0) {
              return;
            }
            let rawImageSize = 0;
            for (let i = 0; i < clusterFrameBuffer.length; i++) {
              rawImageSize += clusterFrameBuffer[i].frame.length + (clusterFrameBuffer[i].alpha ? clusterFrameBuffer[i].alpha.length : 0);
            }
            let buffer = new ArrayBufferDataStream2(rawImageSize + clusterFrameBuffer.length * 64), cluster = createCluster({
              timecode: Math.round(clusterStartTime)
            });
            for (let i = 0; i < clusterFrameBuffer.length; i++) {
              cluster.data.push(createContainerForKeyframe(clusterFrameBuffer[i]));
            }
            writeEBML(buffer, blobBuffer.pos, cluster);
            blobBuffer.write(buffer.getAsDataArray());
            addCuePoint(DEFAULT_TRACK_NUMBER, Math.round(clusterStartTime), cluster.offset);
            clusterFrameBuffer = [];
            clusterStartTime += clusterDuration;
            clusterDuration = 0;
          }
          function validateOptions() {
            if (!options.frameDuration) {
              if (options.frameRate) {
                options.frameDuration = 1e3 / options.frameRate;
              } else {
                throw new Error("Missing required frameDuration or frameRate setting");
              }
            }
            options.quality = Math.max(Math.min(options.quality, 0.99999), 0);
            if (options.alphaQuality === void 0) {
              options.alphaQuality = options.quality;
            } else {
              options.alphaQuality = Math.max(Math.min(options.alphaQuality, 0.99999), 0);
            }
          }
          function addFrameToCluster(frame) {
            frame.trackNumber = DEFAULT_TRACK_NUMBER;
            frame.timecode = Math.round(clusterDuration);
            clusterFrameBuffer.push(frame);
            clusterDuration += frame.duration;
            if (clusterDuration >= MAX_CLUSTER_DURATION_MSEC) {
              flushClusterFrameBuffer();
            }
          }
          function rewriteSeekHead() {
            let seekHeadBuffer = new ArrayBufferDataStream2(seekHead.size), oldPos = blobBuffer.pos;
            writeEBML(seekHeadBuffer, seekHead.dataOffset, seekHead.data);
            blobBuffer.seek(seekHead.dataOffset);
            blobBuffer.write(seekHeadBuffer.getAsDataArray());
            blobBuffer.seek(oldPos);
          }
          function rewriteDuration() {
            let buffer = new ArrayBufferDataStream2(8), oldPos = blobBuffer.pos;
            buffer.writeDoubleBE(clusterStartTime);
            blobBuffer.seek(segmentDuration.dataOffset);
            blobBuffer.write(buffer.getAsDataArray());
            blobBuffer.seek(oldPos);
          }
          function rewriteSegmentLength() {
            let buffer = new ArrayBufferDataStream2(10), oldPos = blobBuffer.pos;
            buffer.writeUnsignedIntBE(ebmlSegment.id);
            buffer.writeEBMLVarIntWidth(blobBuffer.pos - ebmlSegment.dataOffset, 5);
            blobBuffer.seek(ebmlSegment.offset);
            blobBuffer.write(buffer.getAsDataArray());
            blobBuffer.seek(oldPos);
          }
          this.addFrame = function(frame, alpha, overrideFrameDuration) {
            if (!writtenHeader) {
              videoWidth = frame.width || 0;
              videoHeight = frame.height || 0;
              writeHeader();
            }
            let keyframe = extractKeyframeFromWebP(renderAsWebP(frame, options.quality)), frameDuration, frameAlpha = null;
            if (overrideFrameDuration) {
              frameDuration = overrideFrameDuration;
            } else if (typeof alpha == "number") {
              frameDuration = alpha;
            } else {
              frameDuration = options.frameDuration;
            }
            if (options.transparent) {
              if (alpha instanceof HTMLCanvasElement || typeof alpha === "string") {
                frameAlpha = alpha;
              } else if (keyframe.hasAlpha) {
                frameAlpha = convertAlphaToGrayscaleImage(frame);
              }
            }
            addFrameToCluster({
              frame: keyframe.frame,
              duration: frameDuration,
              alpha: frameAlpha ? extractKeyframeFromWebP(renderAsWebP(frameAlpha, options.alphaQuality)).frame : null
            });
          };
          this.complete = function() {
            if (!writtenHeader) {
              writeHeader();
            }
            flushClusterFrameBuffer();
            writeCues();
            rewriteSeekHead();
            rewriteDuration();
            rewriteSegmentLength();
            return blobBuffer.complete("video/webm");
          };
          this.getWrittenSize = function() {
            return blobBuffer.length;
          };
          options = extend(optionDefaults, options || {});
          validateOptions();
        };
      };
      {
        module.exports = WebMWriter2;
      }
    })();
  })(WebMWriter$1);
  var WebMWriterExports = WebMWriter$1.exports;
  var ArrayBufferDataStream = { exports: {} };
  (function(module) {
    (function() {
      let ArrayBufferDataStream2 = function(length) {
        this.data = new Uint8Array(length);
        this.pos = 0;
      };
      ArrayBufferDataStream2.prototype.seek = function(toOffset) {
        this.pos = toOffset;
      };
      ArrayBufferDataStream2.prototype.writeBytes = function(arr) {
        for (let i = 0; i < arr.length; i++) {
          this.data[this.pos++] = arr[i];
        }
      };
      ArrayBufferDataStream2.prototype.writeByte = function(b) {
        this.data[this.pos++] = b;
      };
      ArrayBufferDataStream2.prototype.writeU8 = ArrayBufferDataStream2.prototype.writeByte;
      ArrayBufferDataStream2.prototype.writeU16BE = function(u) {
        this.data[this.pos++] = u >> 8;
        this.data[this.pos++] = u;
      };
      ArrayBufferDataStream2.prototype.writeDoubleBE = function(d) {
        let bytes2 = new Uint8Array(new Float64Array([d]).buffer);
        for (let i = bytes2.length - 1; i >= 0; i--) {
          this.writeByte(bytes2[i]);
        }
      };
      ArrayBufferDataStream2.prototype.writeFloatBE = function(d) {
        let bytes2 = new Uint8Array(new Float32Array([d]).buffer);
        for (let i = bytes2.length - 1; i >= 0; i--) {
          this.writeByte(bytes2[i]);
        }
      };
      ArrayBufferDataStream2.prototype.writeString = function(s) {
        for (let i = 0; i < s.length; i++) {
          this.data[this.pos++] = s.charCodeAt(i);
        }
      };
      ArrayBufferDataStream2.prototype.writeEBMLVarIntWidth = function(i, width) {
        switch (width) {
          case 1:
            this.writeU8(1 << 7 | i);
            break;
          case 2:
            this.writeU8(1 << 6 | i >> 8);
            this.writeU8(i);
            break;
          case 3:
            this.writeU8(1 << 5 | i >> 16);
            this.writeU8(i >> 8);
            this.writeU8(i);
            break;
          case 4:
            this.writeU8(1 << 4 | i >> 24);
            this.writeU8(i >> 16);
            this.writeU8(i >> 8);
            this.writeU8(i);
            break;
          case 5:
            this.writeU8(1 << 3 | i / 4294967296 & 7);
            this.writeU8(i >> 24);
            this.writeU8(i >> 16);
            this.writeU8(i >> 8);
            this.writeU8(i);
            break;
          default:
            throw new Error("Bad EBML VINT size " + width);
        }
      };
      ArrayBufferDataStream2.prototype.measureEBMLVarInt = function(val) {
        if (val < (1 << 7) - 1) {
          return 1;
        } else if (val < (1 << 14) - 1) {
          return 2;
        } else if (val < (1 << 21) - 1) {
          return 3;
        } else if (val < (1 << 28) - 1) {
          return 4;
        } else if (val < 34359738367) {
          return 5;
        } else {
          throw new Error("EBML VINT size not supported " + val);
        }
      };
      ArrayBufferDataStream2.prototype.writeEBMLVarInt = function(i) {
        this.writeEBMLVarIntWidth(i, this.measureEBMLVarInt(i));
      };
      ArrayBufferDataStream2.prototype.writeUnsignedIntBE = function(u, width) {
        if (width === void 0) {
          width = this.measureUnsignedInt(u);
        }
        switch (width) {
          case 5:
            this.writeU8(Math.floor(u / 4294967296));
          case 4:
            this.writeU8(u >> 24);
          case 3:
            this.writeU8(u >> 16);
          case 2:
            this.writeU8(u >> 8);
          case 1:
            this.writeU8(u);
            break;
          default:
            throw new Error("Bad UINT size " + width);
        }
      };
      ArrayBufferDataStream2.prototype.measureUnsignedInt = function(val) {
        if (val < 1 << 8) {
          return 1;
        } else if (val < 1 << 16) {
          return 2;
        } else if (val < 1 << 24) {
          return 3;
        } else if (val < 4294967296) {
          return 4;
        } else {
          return 5;
        }
      };
      ArrayBufferDataStream2.prototype.getAsDataArray = function() {
        if (this.pos < this.data.byteLength) {
          return this.data.subarray(0, this.pos);
        } else if (this.pos == this.data.byteLength) {
          return this.data;
        } else {
          throw new Error("ArrayBufferDataStream's pos lies beyond end of buffer");
        }
      };
      {
        module.exports = ArrayBufferDataStream2;
      }
    })();
  })(ArrayBufferDataStream);
  var ArrayBufferDataStreamExports = ArrayBufferDataStream.exports;
  var BlobBuffer = { exports: {} };
  (function(module) {
    (function() {
      let BlobBuffer2 = function(fs) {
        return function(destination) {
          let buffer = [], writePromise = Promise.resolve(), fileWriter = null, fd = null;
          if (destination && destination.constructor.name === "FileWriter") {
            fileWriter = destination;
          } else if (fs && destination) {
            fd = destination;
          }
          this.pos = 0;
          this.length = 0;
          function readBlobAsBuffer(blob) {
            return new Promise(function(resolve, reject) {
              let reader = new FileReader();
              reader.addEventListener("loadend", function() {
                resolve(reader.result);
              });
              reader.readAsArrayBuffer(blob);
            });
          }
          function convertToUint8Array(thing) {
            return new Promise(function(resolve, reject) {
              if (thing instanceof Uint8Array) {
                resolve(thing);
              } else if (thing instanceof ArrayBuffer || ArrayBuffer.isView(thing)) {
                resolve(new Uint8Array(thing));
              } else if (thing instanceof Blob) {
                resolve(readBlobAsBuffer(thing).then(function(buffer2) {
                  return new Uint8Array(buffer2);
                }));
              } else {
                resolve(readBlobAsBuffer(new Blob([thing])).then(function(buffer2) {
                  return new Uint8Array(buffer2);
                }));
              }
            });
          }
          function measureData(data) {
            let result = data.byteLength || data.length || data.size;
            if (!Number.isInteger(result)) {
              throw new Error("Failed to determine size of element");
            }
            return result;
          }
          this.seek = function(offset) {
            if (offset < 0) {
              throw new Error("Offset may not be negative");
            }
            if (isNaN(offset)) {
              throw new Error("Offset may not be NaN");
            }
            if (offset > this.length) {
              throw new Error("Seeking beyond the end of file is not allowed");
            }
            this.pos = offset;
          };
          this.write = function(data) {
            let newEntry = {
              offset: this.pos,
              data,
              length: measureData(data)
            }, isAppend = newEntry.offset >= this.length;
            this.pos += newEntry.length;
            this.length = Math.max(this.length, this.pos);
            writePromise = writePromise.then(function() {
              if (fd) {
                return new Promise(function(resolve, reject) {
                  convertToUint8Array(newEntry.data).then(function(dataArray) {
                    let totalWritten = 0, buffer2 = Buffer.from(dataArray.buffer), handleWriteComplete = function(err, written, buffer3) {
                      totalWritten += written;
                      if (totalWritten >= buffer3.length) {
                        resolve();
                      } else {
                        fs.write(fd, buffer3, totalWritten, buffer3.length - totalWritten, newEntry.offset + totalWritten, handleWriteComplete);
                      }
                    };
                    fs.write(fd, buffer2, 0, buffer2.length, newEntry.offset, handleWriteComplete);
                  });
                });
              } else if (fileWriter) {
                return new Promise(function(resolve, reject) {
                  fileWriter.onwriteend = resolve;
                  fileWriter.seek(newEntry.offset);
                  fileWriter.write(new Blob([newEntry.data]));
                });
              } else if (!isAppend) {
                for (let i = 0; i < buffer.length; i++) {
                  let entry = buffer[i];
                  if (!(newEntry.offset + newEntry.length <= entry.offset || newEntry.offset >= entry.offset + entry.length)) {
                    if (newEntry.offset < entry.offset || newEntry.offset + newEntry.length > entry.offset + entry.length) {
                      throw new Error("Overwrite crosses blob boundaries");
                    }
                    if (newEntry.offset == entry.offset && newEntry.length == entry.length) {
                      entry.data = newEntry.data;
                      return;
                    } else {
                      return convertToUint8Array(entry.data).then(function(entryArray) {
                        entry.data = entryArray;
                        return convertToUint8Array(newEntry.data);
                      }).then(function(newEntryArray) {
                        newEntry.data = newEntryArray;
                        entry.data.set(newEntry.data, newEntry.offset - entry.offset);
                      });
                    }
                  }
                }
              }
              buffer.push(newEntry);
            });
          };
          this.complete = function(mimeType) {
            if (fd || fileWriter) {
              writePromise = writePromise.then(function() {
                return null;
              });
            } else {
              writePromise = writePromise.then(function() {
                let result = [];
                for (let i = 0; i < buffer.length; i++) {
                  result.push(buffer[i].data);
                }
                return new Blob(result, { type: mimeType });
              });
            }
            return writePromise;
          };
        };
      };
      {
        module.exports = BlobBuffer2;
      }
    })();
  })(BlobBuffer);
  var BlobBufferExports = BlobBuffer.exports;
  var browser = WebMWriterExports(ArrayBufferDataStreamExports, BlobBufferExports(null));
  const WebMWriter = /* @__PURE__ */ getDefaultExportFromCjs(browser);
  function webm(frames, convertMeta) {
    const quality = config.get("webmQuality") / 100;
    return Promise.all(
      frames.map((frame) => {
        if (frame instanceof Blob) {
          return createImageBitmap(frame);
        } else {
          return frame;
        }
      })
    ).then((bitmaps) => {
      if (convertMeta.isAborted) throw new CancelError();
      const width = bitmaps[0].width;
      const height = bitmaps[0].height;
      const canvas = new OffscreenCanvas(width, height);
      const ctx = canvas.getContext("2d");
      const dataUrls = [];
      for (let i = 0; i < frames.length; i++) {
        ctx.drawImage(bitmaps[i], 0, 0);
        bitmaps[i].close();
        const url2 = canvas.convertToBlob({ type: "image/webp", quality }).then(readBlobAsDataUrl);
        dataUrls.push(url2);
      }
      return Promise.all(dataUrls);
    }).then((dataUrls) => {
      if (convertMeta.isAborted) throw new CancelError();
      const videoWriter = new WebMWriter({
        quality,
        // WebM image quality from 0.0 (worst) to 0.99999 (best), 1.00 (VP8L lossless) is not supported
        frameRate: 30,
        // Number of frames per second
        transparent: false
        // True if an alpha channel should be included in the video
      });
      const delays = convertMeta.source.delays;
      for (let i = 0; i < dataUrls.length; i++) {
        videoWriter.addFrame(dataUrls[i], delays[i]);
      }
      return videoWriter.complete();
    }).then((blob) => {
      if (convertMeta.isAborted) throw new CancelError();
      return blob;
    });
  }
  var __accessCheck = (obj, member, msg) => {
    if (!member.has(obj))
      throw TypeError("Cannot " + msg);
  };
  var __privateGet = (obj, member, getter) => {
    __accessCheck(obj, member, "read from private field");
    return getter ? getter.call(obj) : member.get(obj);
  };
  var __privateAdd = (obj, member, value) => {
    if (member.has(obj))
      throw TypeError("Cannot add the same private member more than once");
    member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
  };
  var __privateSet = (obj, member, value, setter) => {
    __accessCheck(obj, member, "write to private field");
    member.set(obj, value);
    return value;
  };
  var __privateWrapper = (obj, member, setter, getter) => ({
    set _(value) {
      __privateSet(obj, member, value);
    },
    get _() {
      return __privateGet(obj, member, getter);
    }
  });
  var __privateMethod = (obj, member, method) => {
    __accessCheck(obj, member, "access private method");
    return method;
  };
  var bytes = new Uint8Array(8);
  var view = new DataView(bytes.buffer);
  var u8 = (value) => {
    return [(value % 256 + 256) % 256];
  };
  var u16 = (value) => {
    view.setUint16(0, value, false);
    return [bytes[0], bytes[1]];
  };
  var i16 = (value) => {
    view.setInt16(0, value, false);
    return [bytes[0], bytes[1]];
  };
  var u24 = (value) => {
    view.setUint32(0, value, false);
    return [bytes[1], bytes[2], bytes[3]];
  };
  var u32 = (value) => {
    view.setUint32(0, value, false);
    return [bytes[0], bytes[1], bytes[2], bytes[3]];
  };
  var i32 = (value) => {
    view.setInt32(0, value, false);
    return [bytes[0], bytes[1], bytes[2], bytes[3]];
  };
  var u64 = (value) => {
    view.setUint32(0, Math.floor(value / 2 ** 32), false);
    view.setUint32(4, value, false);
    return [bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]];
  };
  var fixed_8_8 = (value) => {
    view.setInt16(0, 2 ** 8 * value, false);
    return [bytes[0], bytes[1]];
  };
  var fixed_16_16 = (value) => {
    view.setInt32(0, 2 ** 16 * value, false);
    return [bytes[0], bytes[1], bytes[2], bytes[3]];
  };
  var fixed_2_30 = (value) => {
    view.setInt32(0, 2 ** 30 * value, false);
    return [bytes[0], bytes[1], bytes[2], bytes[3]];
  };
  var ascii = (text2, nullTerminated = false) => {
    let bytes2 = Array(text2.length).fill(null).map((_, i) => text2.charCodeAt(i));
    if (nullTerminated)
      bytes2.push(0);
    return bytes2;
  };
  var last = (arr) => {
    return arr && arr[arr.length - 1];
  };
  var lastPresentedSample = (samples) => {
    let result = void 0;
    for (let sample of samples) {
      if (!result || sample.presentationTimestamp > result.presentationTimestamp) {
        result = sample;
      }
    }
    return result;
  };
  var intoTimescale = (timeInSeconds, timescale, round = true) => {
    let value = timeInSeconds * timescale;
    return round ? Math.round(value) : value;
  };
  var rotationMatrix = (rotationInDegrees) => {
    let theta = rotationInDegrees * (Math.PI / 180);
    let cosTheta = Math.cos(theta);
    let sinTheta = Math.sin(theta);
    return [
      cosTheta,
      sinTheta,
      0,
      -sinTheta,
      cosTheta,
      0,
      0,
      0,
      1
    ];
  };
  var IDENTITY_MATRIX = rotationMatrix(0);
  var matrixToBytes = (matrix) => {
    return [
      fixed_16_16(matrix[0]),
      fixed_16_16(matrix[1]),
      fixed_2_30(matrix[2]),
      fixed_16_16(matrix[3]),
      fixed_16_16(matrix[4]),
      fixed_2_30(matrix[5]),
      fixed_16_16(matrix[6]),
      fixed_16_16(matrix[7]),
      fixed_2_30(matrix[8])
    ];
  };
  var deepClone = (x) => {
    if (!x)
      return x;
    if (typeof x !== "object")
      return x;
    if (Array.isArray(x))
      return x.map(deepClone);
    return Object.fromEntries(Object.entries(x).map(([key, value]) => [key, deepClone(value)]));
  };
  var isU32 = (value) => {
    return value >= 0 && value < 2 ** 32;
  };
  var box = (type, contents, children2) => ({
    type,
    contents: contents && new Uint8Array(contents.flat(10)),
    children: children2
  });
  var fullBox = (type, version, flags, contents, children2) => box(
    type,
    [u8(version), u24(flags), contents ?? []],
    children2
  );
  var ftyp = (details) => {
    let minorVersion = 512;
    if (details.fragmented)
      return box("ftyp", [
        ascii("iso5"),
        // Major brand
        u32(minorVersion),
        // Minor version
        // Compatible brands
        ascii("iso5"),
        ascii("iso6"),
        ascii("mp41")
      ]);
    return box("ftyp", [
      ascii("isom"),
      // Major brand
      u32(minorVersion),
      // Minor version
      // Compatible brands
      ascii("isom"),
      details.holdsAvc ? ascii("avc1") : [],
      ascii("mp41")
    ]);
  };
  var mdat = (reserveLargeSize) => ({ type: "mdat", largeSize: reserveLargeSize });
  var free = (size) => ({ type: "free", size });
  var moov = (tracks, creationTime, fragmented = false) => box("moov", null, [
    mvhd(creationTime, tracks),
    ...tracks.map((x) => trak(x, creationTime)),
    fragmented ? mvex(tracks) : null
  ]);
  var mvhd = (creationTime, tracks) => {
    let duration = intoTimescale(Math.max(
      0,
      ...tracks.filter((x) => x.samples.length > 0).map((x) => {
        const lastSample = lastPresentedSample(x.samples);
        return lastSample.presentationTimestamp + lastSample.duration;
      })
    ), GLOBAL_TIMESCALE);
    let nextTrackId = Math.max(...tracks.map((x) => x.id)) + 1;
    let needsU64 = !isU32(creationTime) || !isU32(duration);
    let u32OrU64 = needsU64 ? u64 : u32;
    return fullBox("mvhd", +needsU64, 0, [
      u32OrU64(creationTime),
      // Creation time
      u32OrU64(creationTime),
      // Modification time
      u32(GLOBAL_TIMESCALE),
      // Timescale
      u32OrU64(duration),
      // Duration
      fixed_16_16(1),
      // Preferred rate
      fixed_8_8(1),
      // Preferred volume
      Array(10).fill(0),
      // Reserved
      matrixToBytes(IDENTITY_MATRIX),
      // Matrix
      Array(24).fill(0),
      // Pre-defined
      u32(nextTrackId)
      // Next track ID
    ]);
  };
  var trak = (track, creationTime) => box("trak", null, [
    tkhd(track, creationTime),
    mdia(track, creationTime)
  ]);
  var tkhd = (track, creationTime) => {
    let lastSample = lastPresentedSample(track.samples);
    let durationInGlobalTimescale = intoTimescale(
      lastSample ? lastSample.presentationTimestamp + lastSample.duration : 0,
      GLOBAL_TIMESCALE
    );
    let needsU64 = !isU32(creationTime) || !isU32(durationInGlobalTimescale);
    let u32OrU64 = needsU64 ? u64 : u32;
    let matrix;
    if (track.info.type === "video") {
      matrix = typeof track.info.rotation === "number" ? rotationMatrix(track.info.rotation) : track.info.rotation;
    } else {
      matrix = IDENTITY_MATRIX;
    }
    return fullBox("tkhd", +needsU64, 3, [
      u32OrU64(creationTime),
      // Creation time
      u32OrU64(creationTime),
      // Modification time
      u32(track.id),
      // Track ID
      u32(0),
      // Reserved
      u32OrU64(durationInGlobalTimescale),
      // Duration
      Array(8).fill(0),
      // Reserved
      u16(0),
      // Layer
      u16(0),
      // Alternate group
      fixed_8_8(track.info.type === "audio" ? 1 : 0),
      // Volume
      u16(0),
      // Reserved
      matrixToBytes(matrix),
      // Matrix
      fixed_16_16(track.info.type === "video" ? track.info.width : 0),
      // Track width
      fixed_16_16(track.info.type === "video" ? track.info.height : 0)
      // Track height
    ]);
  };
  var mdia = (track, creationTime) => box("mdia", null, [
    mdhd(track, creationTime),
    hdlr(track.info.type === "video" ? "vide" : "soun"),
    minf(track)
  ]);
  var mdhd = (track, creationTime) => {
    let lastSample = lastPresentedSample(track.samples);
    let localDuration = intoTimescale(
      lastSample ? lastSample.presentationTimestamp + lastSample.duration : 0,
      track.timescale
    );
    let needsU64 = !isU32(creationTime) || !isU32(localDuration);
    let u32OrU64 = needsU64 ? u64 : u32;
    return fullBox("mdhd", +needsU64, 0, [
      u32OrU64(creationTime),
      // Creation time
      u32OrU64(creationTime),
      // Modification time
      u32(track.timescale),
      // Timescale
      u32OrU64(localDuration),
      // Duration
      u16(21956),
      // Language ("und", undetermined)
      u16(0)
      // Quality
    ]);
  };
  var hdlr = (componentSubtype) => fullBox("hdlr", 0, 0, [
    ascii("mhlr"),
    // Component type
    ascii(componentSubtype),
    // Component subtype
    u32(0),
    // Component manufacturer
    u32(0),
    // Component flags
    u32(0),
    // Component flags mask
    ascii("mp4-muxer-hdlr", true)
    // Component name
  ]);
  var minf = (track) => box("minf", null, [
    track.info.type === "video" ? vmhd() : smhd(),
    dinf(),
    stbl(track)
  ]);
  var vmhd = () => fullBox("vmhd", 0, 1, [
    u16(0),
    // Graphics mode
    u16(0),
    // Opcolor R
    u16(0),
    // Opcolor G
    u16(0)
    // Opcolor B
  ]);
  var smhd = () => fullBox("smhd", 0, 0, [
    u16(0),
    // Balance
    u16(0)
    // Reserved
  ]);
  var dinf = () => box("dinf", null, [
    dref()
  ]);
  var dref = () => fullBox("dref", 0, 0, [
    u32(1)
    // Entry count
  ], [
    url()
  ]);
  var url = () => fullBox("url ", 0, 1);
  var stbl = (track) => {
    const needsCtts = track.compositionTimeOffsetTable.length > 1 || track.compositionTimeOffsetTable.some((x) => x.sampleCompositionTimeOffset !== 0);
    return box("stbl", null, [
      stsd(track),
      stts(track),
      stss(track),
      stsc(track),
      stsz(track),
      stco(track),
      needsCtts ? ctts(track) : null
    ]);
  };
  var stsd = (track) => fullBox("stsd", 0, 0, [
    u32(1)
    // Entry count
  ], [
    track.info.type === "video" ? videoSampleDescription(
      VIDEO_CODEC_TO_BOX_NAME[track.info.codec],
      track
    ) : soundSampleDescription(
      AUDIO_CODEC_TO_BOX_NAME[track.info.codec],
      track
    )
  ]);
  var videoSampleDescription = (compressionType, track) => box(compressionType, [
    Array(6).fill(0),
    // Reserved
    u16(1),
    // Data reference index
    u16(0),
    // Pre-defined
    u16(0),
    // Reserved
    Array(12).fill(0),
    // Pre-defined
    u16(track.info.width),
    // Width
    u16(track.info.height),
    // Height
    u32(4718592),
    // Horizontal resolution
    u32(4718592),
    // Vertical resolution
    u32(0),
    // Reserved
    u16(1),
    // Frame count
    Array(32).fill(0),
    // Compressor name
    u16(24),
    // Depth
    i16(65535)
    // Pre-defined
  ], [
    VIDEO_CODEC_TO_CONFIGURATION_BOX[track.info.codec](track)
  ]);
  var avcC = (track) => track.info.decoderConfig && box("avcC", [
    // For AVC, description is an AVCDecoderConfigurationRecord, so nothing else to do here
    ...new Uint8Array(track.info.decoderConfig.description)
  ]);
  var hvcC = (track) => track.info.decoderConfig && box("hvcC", [
    // For HEVC, description is a HEVCDecoderConfigurationRecord, so nothing else to do here
    ...new Uint8Array(track.info.decoderConfig.description)
  ]);
  var vpcC = (track) => {
    if (!track.info.decoderConfig) {
      return null;
    }
    let decoderConfig = track.info.decoderConfig;
    if (!decoderConfig.colorSpace) {
      throw new Error(`'colorSpace' is required in the decoder config for VP9.`);
    }
    let parts = decoderConfig.codec.split(".");
    let profile = Number(parts[1]);
    let level = Number(parts[2]);
    let bitDepth = Number(parts[3]);
    let chromaSubsampling = 0;
    let thirdByte = (bitDepth << 4) + (chromaSubsampling << 1) + Number(decoderConfig.colorSpace.fullRange);
    let colourPrimaries = 2;
    let transferCharacteristics = 2;
    let matrixCoefficients = 2;
    return fullBox("vpcC", 1, 0, [
      u8(profile),
      // Profile
      u8(level),
      // Level
      u8(thirdByte),
      // Bit depth, chroma subsampling, full range
      u8(colourPrimaries),
      // Colour primaries
      u8(transferCharacteristics),
      // Transfer characteristics
      u8(matrixCoefficients),
      // Matrix coefficients
      u16(0)
      // Codec initialization data size
    ]);
  };
  var av1C = () => {
    let marker = 1;
    let version = 1;
    let firstByte = (marker << 7) + version;
    return box("av1C", [
      firstByte,
      0,
      0,
      0
    ]);
  };
  var soundSampleDescription = (compressionType, track) => box(compressionType, [
    Array(6).fill(0),
    // Reserved
    u16(1),
    // Data reference index
    u16(0),
    // Version
    u16(0),
    // Revision level
    u32(0),
    // Vendor
    u16(track.info.numberOfChannels),
    // Number of channels
    u16(16),
    // Sample size (bits)
    u16(0),
    // Compression ID
    u16(0),
    // Packet size
    fixed_16_16(track.info.sampleRate)
    // Sample rate
  ], [
    AUDIO_CODEC_TO_CONFIGURATION_BOX[track.info.codec](track)
  ]);
  var esds = (track) => {
    let description = new Uint8Array(track.info.decoderConfig.description);
    return fullBox("esds", 0, 0, [
      // https://stackoverflow.com/a/54803118
      u32(58753152),
      // TAG(3) = Object Descriptor ([2])
      u8(32 + description.byteLength),
      // length of this OD (which includes the next 2 tags)
      u16(1),
      // ES_ID = 1
      u8(0),
      // flags etc = 0
      u32(75530368),
      // TAG(4) = ES Descriptor ([2]) embedded in above OD
      u8(18 + description.byteLength),
      // length of this ESD
      u8(64),
      // MPEG-4 Audio
      u8(21),
      // stream type(6bits)=5 audio, flags(2bits)=1
      u24(0),
      // 24bit buffer size
      u32(130071),
      // max bitrate
      u32(130071),
      // avg bitrate
      u32(92307584),
      // TAG(5) = ASC ([2],[3]) embedded in above OD
      u8(description.byteLength),
      // length
      ...description,
      u32(109084800),
      // TAG(6)
      u8(1),
      // length
      u8(2)
      // data
    ]);
  };
  var dOps = (track) => box("dOps", [
    u8(0),
    // Version
    u8(track.info.numberOfChannels),
    // OutputChannelCount
    u16(3840),
    // PreSkip, should be at least 80 milliseconds worth of playback, measured in 48000 Hz samples
    u32(track.info.sampleRate),
    // InputSampleRate
    fixed_8_8(0),
    // OutputGain
    u8(0)
    // ChannelMappingFamily
  ]);
  var stts = (track) => {
    return fullBox("stts", 0, 0, [
      u32(track.timeToSampleTable.length),
      // Number of entries
      track.timeToSampleTable.map((x) => [
        // Time-to-sample table
        u32(x.sampleCount),
        // Sample count
        u32(x.sampleDelta)
        // Sample duration
      ])
    ]);
  };
  var stss = (track) => {
    if (track.samples.every((x) => x.type === "key"))
      return null;
    let keySamples = [...track.samples.entries()].filter(([, sample]) => sample.type === "key");
    return fullBox("stss", 0, 0, [
      u32(keySamples.length),
      // Number of entries
      keySamples.map(([index]) => u32(index + 1))
      // Sync sample table
    ]);
  };
  var stsc = (track) => {
    return fullBox("stsc", 0, 0, [
      u32(track.compactlyCodedChunkTable.length),
      // Number of entries
      track.compactlyCodedChunkTable.map((x) => [
        // Sample-to-chunk table
        u32(x.firstChunk),
        // First chunk
        u32(x.samplesPerChunk),
        // Samples per chunk
        u32(1)
        // Sample description index
      ])
    ]);
  };
  var stsz = (track) => fullBox("stsz", 0, 0, [
    u32(0),
    // Sample size (0 means non-constant size)
    u32(track.samples.length),
    // Number of entries
    track.samples.map((x) => u32(x.size))
    // Sample size table
  ]);
  var stco = (track) => {
    if (track.finalizedChunks.length > 0 && last(track.finalizedChunks).offset >= 2 ** 32) {
      return fullBox("co64", 0, 0, [
        u32(track.finalizedChunks.length),
        // Number of entries
        track.finalizedChunks.map((x) => u64(x.offset))
        // Chunk offset table
      ]);
    }
    return fullBox("stco", 0, 0, [
      u32(track.finalizedChunks.length),
      // Number of entries
      track.finalizedChunks.map((x) => u32(x.offset))
      // Chunk offset table
    ]);
  };
  var ctts = (track) => {
    return fullBox("ctts", 0, 0, [
      u32(track.compositionTimeOffsetTable.length),
      // Number of entries
      track.compositionTimeOffsetTable.map((x) => [
        // Time-to-sample table
        u32(x.sampleCount),
        // Sample count
        u32(x.sampleCompositionTimeOffset)
        // Sample offset
      ])
    ]);
  };
  var mvex = (tracks) => {
    return box("mvex", null, tracks.map(trex));
  };
  var trex = (track) => {
    return fullBox("trex", 0, 0, [
      u32(track.id),
      // Track ID
      u32(1),
      // Default sample description index
      u32(0),
      // Default sample duration
      u32(0),
      // Default sample size
      u32(0)
      // Default sample flags
    ]);
  };
  var moof = (sequenceNumber, tracks) => {
    return box("moof", null, [
      mfhd(sequenceNumber),
      ...tracks.map(traf)
    ]);
  };
  var mfhd = (sequenceNumber) => {
    return fullBox("mfhd", 0, 0, [
      u32(sequenceNumber)
      // Sequence number
    ]);
  };
  var fragmentSampleFlags = (sample) => {
    let byte1 = 0;
    let byte2 = 0;
    let byte3 = 0;
    let byte4 = 0;
    let sampleIsDifferenceSample = sample.type === "delta";
    byte2 |= +sampleIsDifferenceSample;
    if (sampleIsDifferenceSample) {
      byte1 |= 1;
    } else {
      byte1 |= 2;
    }
    return byte1 << 24 | byte2 << 16 | byte3 << 8 | byte4;
  };
  var traf = (track) => {
    return box("traf", null, [
      tfhd(track),
      tfdt(track),
      trun(track)
    ]);
  };
  var tfhd = (track) => {
    let tfFlags = 0;
    tfFlags |= 8;
    tfFlags |= 16;
    tfFlags |= 32;
    tfFlags |= 131072;
    let referenceSample = track.currentChunk.samples[1] ?? track.currentChunk.samples[0];
    let referenceSampleInfo = {
      duration: referenceSample.timescaleUnitsToNextSample,
      size: referenceSample.size,
      flags: fragmentSampleFlags(referenceSample)
    };
    return fullBox("tfhd", 0, tfFlags, [
      u32(track.id),
      // Track ID
      u32(referenceSampleInfo.duration),
      // Default sample duration
      u32(referenceSampleInfo.size),
      // Default sample size
      u32(referenceSampleInfo.flags)
      // Default sample flags
    ]);
  };
  var tfdt = (track) => {
    return fullBox("tfdt", 1, 0, [
      u64(intoTimescale(track.currentChunk.startTimestamp, track.timescale))
      // Base Media Decode Time
    ]);
  };
  var trun = (track) => {
    let allSampleDurations = track.currentChunk.samples.map((x) => x.timescaleUnitsToNextSample);
    let allSampleSizes = track.currentChunk.samples.map((x) => x.size);
    let allSampleFlags = track.currentChunk.samples.map(fragmentSampleFlags);
    let allSampleCompositionTimeOffsets = track.currentChunk.samples.map((x) => intoTimescale(x.presentationTimestamp - x.decodeTimestamp, track.timescale));
    let uniqueSampleDurations = new Set(allSampleDurations);
    let uniqueSampleSizes = new Set(allSampleSizes);
    let uniqueSampleFlags = new Set(allSampleFlags);
    let uniqueSampleCompositionTimeOffsets = new Set(allSampleCompositionTimeOffsets);
    let firstSampleFlagsPresent = uniqueSampleFlags.size === 2 && allSampleFlags[0] !== allSampleFlags[1];
    let sampleDurationPresent = uniqueSampleDurations.size > 1;
    let sampleSizePresent = uniqueSampleSizes.size > 1;
    let sampleFlagsPresent = !firstSampleFlagsPresent && uniqueSampleFlags.size > 1;
    let sampleCompositionTimeOffsetsPresent = uniqueSampleCompositionTimeOffsets.size > 1 || [...uniqueSampleCompositionTimeOffsets].some((x) => x !== 0);
    let flags = 0;
    flags |= 1;
    flags |= 4 * +firstSampleFlagsPresent;
    flags |= 256 * +sampleDurationPresent;
    flags |= 512 * +sampleSizePresent;
    flags |= 1024 * +sampleFlagsPresent;
    flags |= 2048 * +sampleCompositionTimeOffsetsPresent;
    return fullBox("trun", 1, flags, [
      u32(track.currentChunk.samples.length),
      // Sample count
      u32(track.currentChunk.offset - track.currentChunk.moofOffset || 0),
      // Data offset
      firstSampleFlagsPresent ? u32(allSampleFlags[0]) : [],
      track.currentChunk.samples.map((_, i) => [
        sampleDurationPresent ? u32(allSampleDurations[i]) : [],
        // Sample duration
        sampleSizePresent ? u32(allSampleSizes[i]) : [],
        // Sample size
        sampleFlagsPresent ? u32(allSampleFlags[i]) : [],
        // Sample flags
        // Sample composition time offsets
        sampleCompositionTimeOffsetsPresent ? i32(allSampleCompositionTimeOffsets[i]) : []
      ])
    ]);
  };
  var mfra = (tracks) => {
    return box("mfra", null, [
      ...tracks.map(tfra),
      mfro()
    ]);
  };
  var tfra = (track, trackIndex) => {
    let version = 1;
    return fullBox("tfra", version, 0, [
      u32(track.id),
      // Track ID
      u32(63),
      // This specifies that traf number, trun number and sample number are 32-bit ints
      u32(track.finalizedChunks.length),
      // Number of entries
      track.finalizedChunks.map((chunk) => [
        u64(intoTimescale(chunk.startTimestamp, track.timescale)),
        // Time
        u64(chunk.moofOffset),
        // moof offset
        u32(trackIndex + 1),
        // traf number
        u32(1),
        // trun number
        u32(1)
        // Sample number
      ])
    ]);
  };
  var mfro = () => {
    return fullBox("mfro", 0, 0, [
      // This value needs to be overwritten manually from the outside, where the actual size of the enclosing mfra box
      // is known
      u32(0)
      // Size
    ]);
  };
  var VIDEO_CODEC_TO_BOX_NAME = {
    "avc": "avc1",
    "hevc": "hvc1",
    "vp9": "vp09",
    "av1": "av01"
  };
  var VIDEO_CODEC_TO_CONFIGURATION_BOX = {
    "avc": avcC,
    "hevc": hvcC,
    "vp9": vpcC,
    "av1": av1C
  };
  var AUDIO_CODEC_TO_BOX_NAME = {
    "aac": "mp4a",
    "opus": "Opus"
  };
  var AUDIO_CODEC_TO_CONFIGURATION_BOX = {
    "aac": esds,
    "opus": dOps
  };
  var ArrayBufferTarget = class {
    constructor() {
      this.buffer = null;
    }
  };
  var StreamTarget = class {
    constructor(options) {
      this.options = options;
    }
  };
  var FileSystemWritableFileStreamTarget = class {
    constructor(stream, options) {
      this.stream = stream;
      this.options = options;
    }
  };
  var _helper, _helperView;
  var Writer = class {
    constructor() {
      this.pos = 0;
      __privateAdd(this, _helper, new Uint8Array(8));
      __privateAdd(this, _helperView, new DataView(__privateGet(this, _helper).buffer));
      this.offsets = /* @__PURE__ */ new WeakMap();
    }
    /** Sets the current position for future writes to a new one. */
    seek(newPos) {
      this.pos = newPos;
    }
    writeU32(value) {
      __privateGet(this, _helperView).setUint32(0, value, false);
      this.write(__privateGet(this, _helper).subarray(0, 4));
    }
    writeU64(value) {
      __privateGet(this, _helperView).setUint32(0, Math.floor(value / 2 ** 32), false);
      __privateGet(this, _helperView).setUint32(4, value, false);
      this.write(__privateGet(this, _helper).subarray(0, 8));
    }
    writeAscii(text2) {
      for (let i = 0; i < text2.length; i++) {
        __privateGet(this, _helperView).setUint8(i % 8, text2.charCodeAt(i));
        if (i % 8 === 7)
          this.write(__privateGet(this, _helper));
      }
      if (text2.length % 8 !== 0) {
        this.write(__privateGet(this, _helper).subarray(0, text2.length % 8));
      }
    }
    writeBox(box2) {
      this.offsets.set(box2, this.pos);
      if (box2.contents && !box2.children) {
        this.writeBoxHeader(box2, box2.size ?? box2.contents.byteLength + 8);
        this.write(box2.contents);
      } else {
        let startPos = this.pos;
        this.writeBoxHeader(box2, 0);
        if (box2.contents)
          this.write(box2.contents);
        if (box2.children) {
          for (let child of box2.children)
            if (child)
              this.writeBox(child);
        }
        let endPos = this.pos;
        let size = box2.size ?? endPos - startPos;
        this.seek(startPos);
        this.writeBoxHeader(box2, size);
        this.seek(endPos);
      }
    }
    writeBoxHeader(box2, size) {
      this.writeU32(box2.largeSize ? 1 : size);
      this.writeAscii(box2.type);
      if (box2.largeSize)
        this.writeU64(size);
    }
    measureBoxHeader(box2) {
      return 8 + (box2.largeSize ? 8 : 0);
    }
    patchBox(box2) {
      let endPos = this.pos;
      this.seek(this.offsets.get(box2));
      this.writeBox(box2);
      this.seek(endPos);
    }
    measureBox(box2) {
      if (box2.contents && !box2.children) {
        let headerSize = this.measureBoxHeader(box2);
        return headerSize + box2.contents.byteLength;
      } else {
        let result = this.measureBoxHeader(box2);
        if (box2.contents)
          result += box2.contents.byteLength;
        if (box2.children) {
          for (let child of box2.children)
            if (child)
              result += this.measureBox(child);
        }
        return result;
      }
    }
  };
  _helper = /* @__PURE__ */ new WeakMap();
  _helperView = /* @__PURE__ */ new WeakMap();
  var _target, _buffer, _bytes, _maxPos, _ensureSize, ensureSize_fn;
  var ArrayBufferTargetWriter = class extends Writer {
    constructor(target) {
      super();
      __privateAdd(this, _ensureSize);
      __privateAdd(this, _target, void 0);
      __privateAdd(this, _buffer, new ArrayBuffer(2 ** 16));
      __privateAdd(this, _bytes, new Uint8Array(__privateGet(this, _buffer)));
      __privateAdd(this, _maxPos, 0);
      __privateSet(this, _target, target);
    }
    write(data) {
      __privateMethod(this, _ensureSize, ensureSize_fn).call(this, this.pos + data.byteLength);
      __privateGet(this, _bytes).set(data, this.pos);
      this.pos += data.byteLength;
      __privateSet(this, _maxPos, Math.max(__privateGet(this, _maxPos), this.pos));
    }
    finalize() {
      __privateMethod(this, _ensureSize, ensureSize_fn).call(this, this.pos);
      __privateGet(this, _target).buffer = __privateGet(this, _buffer).slice(0, Math.max(__privateGet(this, _maxPos), this.pos));
    }
  };
  _target = /* @__PURE__ */ new WeakMap();
  _buffer = /* @__PURE__ */ new WeakMap();
  _bytes = /* @__PURE__ */ new WeakMap();
  _maxPos = /* @__PURE__ */ new WeakMap();
  _ensureSize = /* @__PURE__ */ new WeakSet();
  ensureSize_fn = function(size) {
    let newLength = __privateGet(this, _buffer).byteLength;
    while (newLength < size)
      newLength *= 2;
    if (newLength === __privateGet(this, _buffer).byteLength)
      return;
    let newBuffer = new ArrayBuffer(newLength);
    let newBytes = new Uint8Array(newBuffer);
    newBytes.set(__privateGet(this, _bytes), 0);
    __privateSet(this, _buffer, newBuffer);
    __privateSet(this, _bytes, newBytes);
  };
  var _target2, _sections;
  var StreamTargetWriter = class extends Writer {
    constructor(target) {
      super();
      __privateAdd(this, _target2, void 0);
      __privateAdd(this, _sections, []);
      __privateSet(this, _target2, target);
    }
    write(data) {
      __privateGet(this, _sections).push({
        data: data.slice(),
        start: this.pos
      });
      this.pos += data.byteLength;
    }
    flush() {
      var _a, _b;
      if (__privateGet(this, _sections).length === 0)
        return;
      let chunks = [];
      let sorted = [...__privateGet(this, _sections)].sort((a, b) => a.start - b.start);
      chunks.push({
        start: sorted[0].start,
        size: sorted[0].data.byteLength
      });
      for (let i = 1; i < sorted.length; i++) {
        let lastChunk = chunks[chunks.length - 1];
        let section = sorted[i];
        if (section.start <= lastChunk.start + lastChunk.size) {
          lastChunk.size = Math.max(lastChunk.size, section.start + section.data.byteLength - lastChunk.start);
        } else {
          chunks.push({
            start: section.start,
            size: section.data.byteLength
          });
        }
      }
      for (let chunk of chunks) {
        chunk.data = new Uint8Array(chunk.size);
        for (let section of __privateGet(this, _sections)) {
          if (chunk.start <= section.start && section.start < chunk.start + chunk.size) {
            chunk.data.set(section.data, section.start - chunk.start);
          }
        }
        (_b = (_a = __privateGet(this, _target2).options).onData) == null ? void 0 : _b.call(_a, chunk.data, chunk.start);
      }
      __privateGet(this, _sections).length = 0;
    }
    finalize() {
    }
  };
  _target2 = /* @__PURE__ */ new WeakMap();
  _sections = /* @__PURE__ */ new WeakMap();
  var DEFAULT_CHUNK_SIZE = 2 ** 24;
  var MAX_CHUNKS_AT_ONCE = 2;
  var _target3, _chunkSize, _chunks, _writeDataIntoChunks, writeDataIntoChunks_fn, _insertSectionIntoChunk, insertSectionIntoChunk_fn, _createChunk, createChunk_fn, _flushChunks, flushChunks_fn;
  var ChunkedStreamTargetWriter = class extends Writer {
    constructor(target) {
      var _a;
      super();
      __privateAdd(this, _writeDataIntoChunks);
      __privateAdd(this, _insertSectionIntoChunk);
      __privateAdd(this, _createChunk);
      __privateAdd(this, _flushChunks);
      __privateAdd(this, _target3, void 0);
      __privateAdd(this, _chunkSize, void 0);
      __privateAdd(this, _chunks, []);
      __privateSet(this, _target3, target);
      __privateSet(this, _chunkSize, ((_a = target.options) == null ? void 0 : _a.chunkSize) ?? DEFAULT_CHUNK_SIZE);
      if (!Number.isInteger(__privateGet(this, _chunkSize)) || __privateGet(this, _chunkSize) < 2 ** 10) {
        throw new Error("Invalid StreamTarget options: chunkSize must be an integer not smaller than 1024.");
      }
    }
    write(data) {
      __privateMethod(this, _writeDataIntoChunks, writeDataIntoChunks_fn).call(this, data, this.pos);
      __privateMethod(this, _flushChunks, flushChunks_fn).call(this);
      this.pos += data.byteLength;
    }
    finalize() {
      __privateMethod(this, _flushChunks, flushChunks_fn).call(this, true);
    }
  };
  _target3 = /* @__PURE__ */ new WeakMap();
  _chunkSize = /* @__PURE__ */ new WeakMap();
  _chunks = /* @__PURE__ */ new WeakMap();
  _writeDataIntoChunks = /* @__PURE__ */ new WeakSet();
  writeDataIntoChunks_fn = function(data, position) {
    let chunkIndex = __privateGet(this, _chunks).findIndex((x) => x.start <= position && position < x.start + __privateGet(this, _chunkSize));
    if (chunkIndex === -1)
      chunkIndex = __privateMethod(this, _createChunk, createChunk_fn).call(this, position);
    let chunk = __privateGet(this, _chunks)[chunkIndex];
    let relativePosition = position - chunk.start;
    let toWrite = data.subarray(0, Math.min(__privateGet(this, _chunkSize) - relativePosition, data.byteLength));
    chunk.data.set(toWrite, relativePosition);
    let section = {
      start: relativePosition,
      end: relativePosition + toWrite.byteLength
    };
    __privateMethod(this, _insertSectionIntoChunk, insertSectionIntoChunk_fn).call(this, chunk, section);
    if (chunk.written[0].start === 0 && chunk.written[0].end === __privateGet(this, _chunkSize)) {
      chunk.shouldFlush = true;
    }
    if (__privateGet(this, _chunks).length > MAX_CHUNKS_AT_ONCE) {
      for (let i = 0; i < __privateGet(this, _chunks).length - 1; i++) {
        __privateGet(this, _chunks)[i].shouldFlush = true;
      }
      __privateMethod(this, _flushChunks, flushChunks_fn).call(this);
    }
    if (toWrite.byteLength < data.byteLength) {
      __privateMethod(this, _writeDataIntoChunks, writeDataIntoChunks_fn).call(this, data.subarray(toWrite.byteLength), position + toWrite.byteLength);
    }
  };
  _insertSectionIntoChunk = /* @__PURE__ */ new WeakSet();
  insertSectionIntoChunk_fn = function(chunk, section) {
    let low = 0;
    let high = chunk.written.length - 1;
    let index = -1;
    while (low <= high) {
      let mid = Math.floor(low + (high - low + 1) / 2);
      if (chunk.written[mid].start <= section.start) {
        low = mid + 1;
        index = mid;
      } else {
        high = mid - 1;
      }
    }
    chunk.written.splice(index + 1, 0, section);
    if (index === -1 || chunk.written[index].end < section.start)
      index++;
    while (index < chunk.written.length - 1 && chunk.written[index].end >= chunk.written[index + 1].start) {
      chunk.written[index].end = Math.max(chunk.written[index].end, chunk.written[index + 1].end);
      chunk.written.splice(index + 1, 1);
    }
  };
  _createChunk = /* @__PURE__ */ new WeakSet();
  createChunk_fn = function(includesPosition) {
    let start = Math.floor(includesPosition / __privateGet(this, _chunkSize)) * __privateGet(this, _chunkSize);
    let chunk = {
      start,
      data: new Uint8Array(__privateGet(this, _chunkSize)),
      written: [],
      shouldFlush: false
    };
    __privateGet(this, _chunks).push(chunk);
    __privateGet(this, _chunks).sort((a, b) => a.start - b.start);
    return __privateGet(this, _chunks).indexOf(chunk);
  };
  _flushChunks = /* @__PURE__ */ new WeakSet();
  flushChunks_fn = function(force = false) {
    var _a, _b;
    for (let i = 0; i < __privateGet(this, _chunks).length; i++) {
      let chunk = __privateGet(this, _chunks)[i];
      if (!chunk.shouldFlush && !force)
        continue;
      for (let section of chunk.written) {
        (_b = (_a = __privateGet(this, _target3).options).onData) == null ? void 0 : _b.call(
          _a,
          chunk.data.subarray(section.start, section.end),
          chunk.start + section.start
        );
      }
      __privateGet(this, _chunks).splice(i--, 1);
    }
  };
  var FileSystemWritableFileStreamTargetWriter = class extends ChunkedStreamTargetWriter {
    constructor(target) {
      var _a;
      super(new StreamTarget({
        onData: (data, position) => target.stream.write({
          type: "write",
          data,
          position
        }),
        chunkSize: (_a = target.options) == null ? void 0 : _a.chunkSize
      }));
    }
  };
  var GLOBAL_TIMESCALE = 1e3;
  var SUPPORTED_VIDEO_CODECS2 = ["avc", "hevc", "vp9", "av1"];
  var SUPPORTED_AUDIO_CODECS2 = ["aac", "opus"];
  var TIMESTAMP_OFFSET = 2082844800;
  var FIRST_TIMESTAMP_BEHAVIORS = ["strict", "offset", "cross-track-offset"];
  var _options, _writer, _ftypSize, _mdat, _videoTrack, _audioTrack, _creationTime, _finalizedChunks, _nextFragmentNumber, _videoSampleQueue, _audioSampleQueue, _finalized, _validateOptions, validateOptions_fn, _writeHeader, writeHeader_fn, _computeMoovSizeUpperBound, computeMoovSizeUpperBound_fn, _prepareTracks, prepareTracks_fn, _generateMpeg4AudioSpecificConfig, generateMpeg4AudioSpecificConfig_fn, _createSampleForTrack, createSampleForTrack_fn, _addSampleToTrack, addSampleToTrack_fn, _validateTimestamp, validateTimestamp_fn, _finalizeCurrentChunk, finalizeCurrentChunk_fn, _finalizeFragment, finalizeFragment_fn, _maybeFlushStreamingTargetWriter, maybeFlushStreamingTargetWriter_fn, _ensureNotFinalized, ensureNotFinalized_fn;
  var Muxer = class {
    constructor(options) {
      var _a;
      __privateAdd(this, _validateOptions);
      __privateAdd(this, _writeHeader);
      __privateAdd(this, _computeMoovSizeUpperBound);
      __privateAdd(this, _prepareTracks);
      __privateAdd(this, _generateMpeg4AudioSpecificConfig);
      __privateAdd(this, _createSampleForTrack);
      __privateAdd(this, _addSampleToTrack);
      __privateAdd(this, _validateTimestamp);
      __privateAdd(this, _finalizeCurrentChunk);
      __privateAdd(this, _finalizeFragment);
      __privateAdd(this, _maybeFlushStreamingTargetWriter);
      __privateAdd(this, _ensureNotFinalized);
      __privateAdd(this, _options, void 0);
      __privateAdd(this, _writer, void 0);
      __privateAdd(this, _ftypSize, void 0);
      __privateAdd(this, _mdat, void 0);
      __privateAdd(this, _videoTrack, null);
      __privateAdd(this, _audioTrack, null);
      __privateAdd(this, _creationTime, Math.floor(Date.now() / 1e3) + TIMESTAMP_OFFSET);
      __privateAdd(this, _finalizedChunks, []);
      __privateAdd(this, _nextFragmentNumber, 1);
      __privateAdd(this, _videoSampleQueue, []);
      __privateAdd(this, _audioSampleQueue, []);
      __privateAdd(this, _finalized, false);
      __privateMethod(this, _validateOptions, validateOptions_fn).call(this, options);
      options.video = deepClone(options.video);
      options.audio = deepClone(options.audio);
      options.fastStart = deepClone(options.fastStart);
      this.target = options.target;
      __privateSet(this, _options, {
        firstTimestampBehavior: "strict",
        ...options
      });
      if (options.target instanceof ArrayBufferTarget) {
        __privateSet(this, _writer, new ArrayBufferTargetWriter(options.target));
      } else if (options.target instanceof StreamTarget) {
        __privateSet(this, _writer, ((_a = options.target.options) == null ? void 0 : _a.chunked) ? new ChunkedStreamTargetWriter(options.target) : new StreamTargetWriter(options.target));
      } else if (options.target instanceof FileSystemWritableFileStreamTarget) {
        __privateSet(this, _writer, new FileSystemWritableFileStreamTargetWriter(options.target));
      } else {
        throw new Error(`Invalid target: ${options.target}`);
      }
      __privateMethod(this, _prepareTracks, prepareTracks_fn).call(this);
      __privateMethod(this, _writeHeader, writeHeader_fn).call(this);
    }
    addVideoChunk(sample, meta, timestamp, compositionTimeOffset) {
      let data = new Uint8Array(sample.byteLength);
      sample.copyTo(data);
      this.addVideoChunkRaw(
        data,
        sample.type,
        timestamp ?? sample.timestamp,
        sample.duration,
        meta,
        compositionTimeOffset
      );
    }
    addVideoChunkRaw(data, type, timestamp, duration, meta, compositionTimeOffset) {
      __privateMethod(this, _ensureNotFinalized, ensureNotFinalized_fn).call(this);
      if (!__privateGet(this, _options).video)
        throw new Error("No video track declared.");
      if (typeof __privateGet(this, _options).fastStart === "object" && __privateGet(this, _videoTrack).samples.length === __privateGet(this, _options).fastStart.expectedVideoChunks) {
        throw new Error(`Cannot add more video chunks than specified in 'fastStart' (${__privateGet(this, _options).fastStart.expectedVideoChunks}).`);
      }
      let videoSample = __privateMethod(this, _createSampleForTrack, createSampleForTrack_fn).call(this, __privateGet(this, _videoTrack), data, type, timestamp, duration, meta, compositionTimeOffset);
      if (__privateGet(this, _options).fastStart === "fragmented" && __privateGet(this, _audioTrack)) {
        while (__privateGet(this, _audioSampleQueue).length > 0 && __privateGet(this, _audioSampleQueue)[0].decodeTimestamp <= videoSample.decodeTimestamp) {
          let audioSample = __privateGet(this, _audioSampleQueue).shift();
          __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _audioTrack), audioSample);
        }
        if (videoSample.decodeTimestamp <= __privateGet(this, _audioTrack).lastDecodeTimestamp) {
          __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _videoTrack), videoSample);
        } else {
          __privateGet(this, _videoSampleQueue).push(videoSample);
        }
      } else {
        __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _videoTrack), videoSample);
      }
    }
    addAudioChunk(sample, meta, timestamp) {
      let data = new Uint8Array(sample.byteLength);
      sample.copyTo(data);
      this.addAudioChunkRaw(data, sample.type, timestamp ?? sample.timestamp, sample.duration, meta);
    }
    addAudioChunkRaw(data, type, timestamp, duration, meta) {
      __privateMethod(this, _ensureNotFinalized, ensureNotFinalized_fn).call(this);
      if (!__privateGet(this, _options).audio)
        throw new Error("No audio track declared.");
      if (typeof __privateGet(this, _options).fastStart === "object" && __privateGet(this, _audioTrack).samples.length === __privateGet(this, _options).fastStart.expectedAudioChunks) {
        throw new Error(`Cannot add more audio chunks than specified in 'fastStart' (${__privateGet(this, _options).fastStart.expectedAudioChunks}).`);
      }
      let audioSample = __privateMethod(this, _createSampleForTrack, createSampleForTrack_fn).call(this, __privateGet(this, _audioTrack), data, type, timestamp, duration, meta);
      if (__privateGet(this, _options).fastStart === "fragmented" && __privateGet(this, _videoTrack)) {
        while (__privateGet(this, _videoSampleQueue).length > 0 && __privateGet(this, _videoSampleQueue)[0].decodeTimestamp <= audioSample.decodeTimestamp) {
          let videoSample = __privateGet(this, _videoSampleQueue).shift();
          __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _videoTrack), videoSample);
        }
        if (audioSample.decodeTimestamp <= __privateGet(this, _videoTrack).lastDecodeTimestamp) {
          __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _audioTrack), audioSample);
        } else {
          __privateGet(this, _audioSampleQueue).push(audioSample);
        }
      } else {
        __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _audioTrack), audioSample);
      }
    }
    /** Finalizes the file, making it ready for use. Must be called after all video and audio chunks have been added. */
    finalize() {
      if (__privateGet(this, _finalized)) {
        throw new Error("Cannot finalize a muxer more than once.");
      }
      if (__privateGet(this, _options).fastStart === "fragmented") {
        for (let videoSample of __privateGet(this, _videoSampleQueue))
          __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _videoTrack), videoSample);
        for (let audioSample of __privateGet(this, _audioSampleQueue))
          __privateMethod(this, _addSampleToTrack, addSampleToTrack_fn).call(this, __privateGet(this, _audioTrack), audioSample);
        __privateMethod(this, _finalizeFragment, finalizeFragment_fn).call(this, false);
      } else {
        if (__privateGet(this, _videoTrack))
          __privateMethod(this, _finalizeCurrentChunk, finalizeCurrentChunk_fn).call(this, __privateGet(this, _videoTrack));
        if (__privateGet(this, _audioTrack))
          __privateMethod(this, _finalizeCurrentChunk, finalizeCurrentChunk_fn).call(this, __privateGet(this, _audioTrack));
      }
      let tracks = [__privateGet(this, _videoTrack), __privateGet(this, _audioTrack)].filter(Boolean);
      if (__privateGet(this, _options).fastStart === "in-memory") {
        let mdatSize;
        for (let i = 0; i < 2; i++) {
          let movieBox2 = moov(tracks, __privateGet(this, _creationTime));
          let movieBoxSize = __privateGet(this, _writer).measureBox(movieBox2);
          mdatSize = __privateGet(this, _writer).measureBox(__privateGet(this, _mdat));
          let currentChunkPos = __privateGet(this, _writer).pos + movieBoxSize + mdatSize;
          for (let chunk of __privateGet(this, _finalizedChunks)) {
            chunk.offset = currentChunkPos;
            for (let { data } of chunk.samples) {
              currentChunkPos += data.byteLength;
              mdatSize += data.byteLength;
            }
          }
          if (currentChunkPos < 2 ** 32)
            break;
          if (mdatSize >= 2 ** 32)
            __privateGet(this, _mdat).largeSize = true;
        }
        let movieBox = moov(tracks, __privateGet(this, _creationTime));
        __privateGet(this, _writer).writeBox(movieBox);
        __privateGet(this, _mdat).size = mdatSize;
        __privateGet(this, _writer).writeBox(__privateGet(this, _mdat));
        for (let chunk of __privateGet(this, _finalizedChunks)) {
          for (let sample of chunk.samples) {
            __privateGet(this, _writer).write(sample.data);
            sample.data = null;
          }
        }
      } else if (__privateGet(this, _options).fastStart === "fragmented") {
        let startPos = __privateGet(this, _writer).pos;
        let mfraBox = mfra(tracks);
        __privateGet(this, _writer).writeBox(mfraBox);
        let mfraBoxSize = __privateGet(this, _writer).pos - startPos;
        __privateGet(this, _writer).seek(__privateGet(this, _writer).pos - 4);
        __privateGet(this, _writer).writeU32(mfraBoxSize);
      } else {
        let mdatPos = __privateGet(this, _writer).offsets.get(__privateGet(this, _mdat));
        let mdatSize = __privateGet(this, _writer).pos - mdatPos;
        __privateGet(this, _mdat).size = mdatSize;
        __privateGet(this, _mdat).largeSize = mdatSize >= 2 ** 32;
        __privateGet(this, _writer).patchBox(__privateGet(this, _mdat));
        let movieBox = moov(tracks, __privateGet(this, _creationTime));
        if (typeof __privateGet(this, _options).fastStart === "object") {
          __privateGet(this, _writer).seek(__privateGet(this, _ftypSize));
          __privateGet(this, _writer).writeBox(movieBox);
          let remainingBytes = mdatPos - __privateGet(this, _writer).pos;
          __privateGet(this, _writer).writeBox(free(remainingBytes));
        } else {
          __privateGet(this, _writer).writeBox(movieBox);
        }
      }
      __privateMethod(this, _maybeFlushStreamingTargetWriter, maybeFlushStreamingTargetWriter_fn).call(this);
      __privateGet(this, _writer).finalize();
      __privateSet(this, _finalized, true);
    }
  };
  _options = /* @__PURE__ */ new WeakMap();
  _writer = /* @__PURE__ */ new WeakMap();
  _ftypSize = /* @__PURE__ */ new WeakMap();
  _mdat = /* @__PURE__ */ new WeakMap();
  _videoTrack = /* @__PURE__ */ new WeakMap();
  _audioTrack = /* @__PURE__ */ new WeakMap();
  _creationTime = /* @__PURE__ */ new WeakMap();
  _finalizedChunks = /* @__PURE__ */ new WeakMap();
  _nextFragmentNumber = /* @__PURE__ */ new WeakMap();
  _videoSampleQueue = /* @__PURE__ */ new WeakMap();
  _audioSampleQueue = /* @__PURE__ */ new WeakMap();
  _finalized = /* @__PURE__ */ new WeakMap();
  _validateOptions = /* @__PURE__ */ new WeakSet();
  validateOptions_fn = function(options) {
    if (options.video) {
      if (!SUPPORTED_VIDEO_CODECS2.includes(options.video.codec)) {
        throw new Error(`Unsupported video codec: ${options.video.codec}`);
      }
      const videoRotation = options.video.rotation;
      if (typeof videoRotation === "number" && ![0, 90, 180, 270].includes(videoRotation)) {
        throw new Error(`Invalid video rotation: ${videoRotation}. Has to be 0, 90, 180 or 270.`);
      } else if (Array.isArray(videoRotation) && (videoRotation.length !== 9 || videoRotation.some((value) => typeof value !== "number"))) {
        throw new Error(`Invalid video transformation matrix: ${videoRotation.join()}`);
      }
    }
    if (options.audio && !SUPPORTED_AUDIO_CODECS2.includes(options.audio.codec)) {
      throw new Error(`Unsupported audio codec: ${options.audio.codec}`);
    }
    if (options.firstTimestampBehavior && !FIRST_TIMESTAMP_BEHAVIORS.includes(options.firstTimestampBehavior)) {
      throw new Error(`Invalid first timestamp behavior: ${options.firstTimestampBehavior}`);
    }
    if (typeof options.fastStart === "object") {
      if (options.video && options.fastStart.expectedVideoChunks === void 0) {
        throw new Error(`'fastStart' is an object but is missing property 'expectedVideoChunks'.`);
      }
      if (options.audio && options.fastStart.expectedAudioChunks === void 0) {
        throw new Error(`'fastStart' is an object but is missing property 'expectedAudioChunks'.`);
      }
    } else if (![false, "in-memory", "fragmented"].includes(options.fastStart)) {
      throw new Error(`'fastStart' option must be false, 'in-memory', 'fragmented' or an object.`);
    }
  };
  _writeHeader = /* @__PURE__ */ new WeakSet();
  writeHeader_fn = function() {
    var _a;
    __privateGet(this, _writer).writeBox(ftyp({
      holdsAvc: ((_a = __privateGet(this, _options).video) == null ? void 0 : _a.codec) === "avc",
      fragmented: __privateGet(this, _options).fastStart === "fragmented"
    }));
    __privateSet(this, _ftypSize, __privateGet(this, _writer).pos);
    if (__privateGet(this, _options).fastStart === "in-memory") {
      __privateSet(this, _mdat, mdat(false));
    } else if (__privateGet(this, _options).fastStart === "fragmented") ;
    else {
      if (typeof __privateGet(this, _options).fastStart === "object") {
        let moovSizeUpperBound = __privateMethod(this, _computeMoovSizeUpperBound, computeMoovSizeUpperBound_fn).call(this);
        __privateGet(this, _writer).seek(__privateGet(this, _writer).pos + moovSizeUpperBound);
      }
      __privateSet(this, _mdat, mdat(true));
      __privateGet(this, _writer).writeBox(__privateGet(this, _mdat));
    }
    __privateMethod(this, _maybeFlushStreamingTargetWriter, maybeFlushStreamingTargetWriter_fn).call(this);
  };
  _computeMoovSizeUpperBound = /* @__PURE__ */ new WeakSet();
  computeMoovSizeUpperBound_fn = function() {
    if (typeof __privateGet(this, _options).fastStart !== "object")
      return;
    let upperBound = 0;
    let sampleCounts = [
      __privateGet(this, _options).fastStart.expectedVideoChunks,
      __privateGet(this, _options).fastStart.expectedAudioChunks
    ];
    for (let n of sampleCounts) {
      if (!n)
        continue;
      upperBound += (4 + 4) * Math.ceil(2 / 3 * n);
      upperBound += 4 * n;
      upperBound += (4 + 4 + 4) * Math.ceil(2 / 3 * n);
      upperBound += 4 * n;
      upperBound += 8 * n;
    }
    upperBound += 4096;
    return upperBound;
  };
  _prepareTracks = /* @__PURE__ */ new WeakSet();
  prepareTracks_fn = function() {
    if (__privateGet(this, _options).video) {
      __privateSet(this, _videoTrack, {
        id: 1,
        info: {
          type: "video",
          codec: __privateGet(this, _options).video.codec,
          width: __privateGet(this, _options).video.width,
          height: __privateGet(this, _options).video.height,
          rotation: __privateGet(this, _options).video.rotation ?? 0,
          decoderConfig: null
        },
        timescale: 11520,
        // Timescale used by FFmpeg, contains many common frame rates as factors
        samples: [],
        finalizedChunks: [],
        currentChunk: null,
        firstDecodeTimestamp: void 0,
        lastDecodeTimestamp: -1,
        timeToSampleTable: [],
        compositionTimeOffsetTable: [],
        lastTimescaleUnits: null,
        lastSample: null,
        compactlyCodedChunkTable: []
      });
    }
    if (__privateGet(this, _options).audio) {
      let guessedCodecPrivate = __privateMethod(this, _generateMpeg4AudioSpecificConfig, generateMpeg4AudioSpecificConfig_fn).call(
        this,
        2,
        // Object type for AAC-LC, since it's the most common
        __privateGet(this, _options).audio.sampleRate,
        __privateGet(this, _options).audio.numberOfChannels
      );
      __privateSet(this, _audioTrack, {
        id: __privateGet(this, _options).video ? 2 : 1,
        info: {
          type: "audio",
          codec: __privateGet(this, _options).audio.codec,
          numberOfChannels: __privateGet(this, _options).audio.numberOfChannels,
          sampleRate: __privateGet(this, _options).audio.sampleRate,
          decoderConfig: {
            codec: __privateGet(this, _options).audio.codec,
            description: guessedCodecPrivate,
            numberOfChannels: __privateGet(this, _options).audio.numberOfChannels,
            sampleRate: __privateGet(this, _options).audio.sampleRate
          }
        },
        timescale: __privateGet(this, _options).audio.sampleRate,
        samples: [],
        finalizedChunks: [],
        currentChunk: null,
        firstDecodeTimestamp: void 0,
        lastDecodeTimestamp: -1,
        timeToSampleTable: [],
        compositionTimeOffsetTable: [],
        lastTimescaleUnits: null,
        lastSample: null,
        compactlyCodedChunkTable: []
      });
    }
  };
  _generateMpeg4AudioSpecificConfig = /* @__PURE__ */ new WeakSet();
  generateMpeg4AudioSpecificConfig_fn = function(objectType, sampleRate, numberOfChannels) {
    let frequencyIndices = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350];
    let frequencyIndex = frequencyIndices.indexOf(sampleRate);
    let channelConfig = numberOfChannels;
    let configBits = "";
    configBits += objectType.toString(2).padStart(5, "0");
    configBits += frequencyIndex.toString(2).padStart(4, "0");
    if (frequencyIndex === 15)
      configBits += sampleRate.toString(2).padStart(24, "0");
    configBits += channelConfig.toString(2).padStart(4, "0");
    let paddingLength = Math.ceil(configBits.length / 8) * 8;
    configBits = configBits.padEnd(paddingLength, "0");
    let configBytes = new Uint8Array(configBits.length / 8);
    for (let i = 0; i < configBits.length; i += 8) {
      configBytes[i / 8] = parseInt(configBits.slice(i, i + 8), 2);
    }
    return configBytes;
  };
  _createSampleForTrack = /* @__PURE__ */ new WeakSet();
  createSampleForTrack_fn = function(track, data, type, timestamp, duration, meta, compositionTimeOffset) {
    let presentationTimestampInSeconds = timestamp / 1e6;
    let decodeTimestampInSeconds = (timestamp - (compositionTimeOffset ?? 0)) / 1e6;
    let durationInSeconds = duration / 1e6;
    let adjusted = __privateMethod(this, _validateTimestamp, validateTimestamp_fn).call(this, presentationTimestampInSeconds, decodeTimestampInSeconds, track);
    presentationTimestampInSeconds = adjusted.presentationTimestamp;
    decodeTimestampInSeconds = adjusted.decodeTimestamp;
    if (meta == null ? void 0 : meta.decoderConfig) {
      if (track.info.decoderConfig === null) {
        track.info.decoderConfig = meta.decoderConfig;
      } else {
        Object.assign(track.info.decoderConfig, meta.decoderConfig);
      }
    }
    let sample = {
      presentationTimestamp: presentationTimestampInSeconds,
      decodeTimestamp: decodeTimestampInSeconds,
      duration: durationInSeconds,
      data,
      size: data.byteLength,
      type,
      // Will be refined once the next sample comes in
      timescaleUnitsToNextSample: intoTimescale(durationInSeconds, track.timescale)
    };
    return sample;
  };
  _addSampleToTrack = /* @__PURE__ */ new WeakSet();
  addSampleToTrack_fn = function(track, sample) {
    if (__privateGet(this, _options).fastStart !== "fragmented") {
      track.samples.push(sample);
    }
    const sampleCompositionTimeOffset = intoTimescale(sample.presentationTimestamp - sample.decodeTimestamp, track.timescale);
    if (track.lastTimescaleUnits !== null) {
      let timescaleUnits = intoTimescale(sample.decodeTimestamp, track.timescale, false);
      let delta = Math.round(timescaleUnits - track.lastTimescaleUnits);
      track.lastTimescaleUnits += delta;
      track.lastSample.timescaleUnitsToNextSample = delta;
      if (__privateGet(this, _options).fastStart !== "fragmented") {
        let lastTableEntry = last(track.timeToSampleTable);
        if (lastTableEntry.sampleCount === 1) {
          lastTableEntry.sampleDelta = delta;
          lastTableEntry.sampleCount++;
        } else if (lastTableEntry.sampleDelta === delta) {
          lastTableEntry.sampleCount++;
        } else {
          lastTableEntry.sampleCount--;
          track.timeToSampleTable.push({
            sampleCount: 2,
            sampleDelta: delta
          });
        }
        const lastCompositionTimeOffsetTableEntry = last(track.compositionTimeOffsetTable);
        if (lastCompositionTimeOffsetTableEntry.sampleCompositionTimeOffset === sampleCompositionTimeOffset) {
          lastCompositionTimeOffsetTableEntry.sampleCount++;
        } else {
          track.compositionTimeOffsetTable.push({
            sampleCount: 1,
            sampleCompositionTimeOffset
          });
        }
      }
    } else {
      track.lastTimescaleUnits = 0;
      if (__privateGet(this, _options).fastStart !== "fragmented") {
        track.timeToSampleTable.push({
          sampleCount: 1,
          sampleDelta: intoTimescale(sample.duration, track.timescale)
        });
        track.compositionTimeOffsetTable.push({
          sampleCount: 1,
          sampleCompositionTimeOffset
        });
      }
    }
    track.lastSample = sample;
    let beginNewChunk = false;
    if (!track.currentChunk) {
      beginNewChunk = true;
    } else {
      let currentChunkDuration = sample.presentationTimestamp - track.currentChunk.startTimestamp;
      if (__privateGet(this, _options).fastStart === "fragmented") {
        let mostImportantTrack = __privateGet(this, _videoTrack) ?? __privateGet(this, _audioTrack);
        if (track === mostImportantTrack && sample.type === "key" && currentChunkDuration >= 1) {
          beginNewChunk = true;
          __privateMethod(this, _finalizeFragment, finalizeFragment_fn).call(this);
        }
      } else {
        beginNewChunk = currentChunkDuration >= 0.5;
      }
    }
    if (beginNewChunk) {
      if (track.currentChunk) {
        __privateMethod(this, _finalizeCurrentChunk, finalizeCurrentChunk_fn).call(this, track);
      }
      track.currentChunk = {
        startTimestamp: sample.presentationTimestamp,
        samples: []
      };
    }
    track.currentChunk.samples.push(sample);
  };
  _validateTimestamp = /* @__PURE__ */ new WeakSet();
  validateTimestamp_fn = function(presentationTimestamp, decodeTimestamp, track) {
    var _a, _b;
    const strictTimestampBehavior = __privateGet(this, _options).firstTimestampBehavior === "strict";
    const noLastDecodeTimestamp = track.lastDecodeTimestamp === -1;
    const timestampNonZero = decodeTimestamp !== 0;
    if (strictTimestampBehavior && noLastDecodeTimestamp && timestampNonZero) {
      throw new Error(
        `The first chunk for your media track must have a timestamp of 0 (received DTS=${decodeTimestamp}).Non-zero first timestamps are often caused by directly piping frames or audio data from a MediaStreamTrack into the encoder. Their timestamps are typically relative to the age of thedocument, which is probably what you want.

If you want to offset all timestamps of a track such that the first one is zero, set firstTimestampBehavior: 'offset' in the options.
`
      );
    } else if (__privateGet(this, _options).firstTimestampBehavior === "offset" || __privateGet(this, _options).firstTimestampBehavior === "cross-track-offset") {
      if (track.firstDecodeTimestamp === void 0) {
        track.firstDecodeTimestamp = decodeTimestamp;
      }
      let baseDecodeTimestamp;
      if (__privateGet(this, _options).firstTimestampBehavior === "offset") {
        baseDecodeTimestamp = track.firstDecodeTimestamp;
      } else {
        baseDecodeTimestamp = Math.min(
          ((_a = __privateGet(this, _videoTrack)) == null ? void 0 : _a.firstDecodeTimestamp) ?? Infinity,
          ((_b = __privateGet(this, _audioTrack)) == null ? void 0 : _b.firstDecodeTimestamp) ?? Infinity
        );
      }
      decodeTimestamp -= baseDecodeTimestamp;
      presentationTimestamp -= baseDecodeTimestamp;
    }
    if (decodeTimestamp < track.lastDecodeTimestamp) {
      throw new Error(
        `Timestamps must be monotonically increasing (DTS went from ${track.lastDecodeTimestamp * 1e6} to ${decodeTimestamp * 1e6}).`
      );
    }
    track.lastDecodeTimestamp = decodeTimestamp;
    return { presentationTimestamp, decodeTimestamp };
  };
  _finalizeCurrentChunk = /* @__PURE__ */ new WeakSet();
  finalizeCurrentChunk_fn = function(track) {
    if (__privateGet(this, _options).fastStart === "fragmented") {
      throw new Error("Can't finalize individual chunks 'fastStart' is set to 'fragmented'.");
    }
    if (!track.currentChunk)
      return;
    track.finalizedChunks.push(track.currentChunk);
    __privateGet(this, _finalizedChunks).push(track.currentChunk);
    if (track.compactlyCodedChunkTable.length === 0 || last(track.compactlyCodedChunkTable).samplesPerChunk !== track.currentChunk.samples.length) {
      track.compactlyCodedChunkTable.push({
        firstChunk: track.finalizedChunks.length,
        // 1-indexed
        samplesPerChunk: track.currentChunk.samples.length
      });
    }
    if (__privateGet(this, _options).fastStart === "in-memory") {
      track.currentChunk.offset = 0;
      return;
    }
    track.currentChunk.offset = __privateGet(this, _writer).pos;
    for (let sample of track.currentChunk.samples) {
      __privateGet(this, _writer).write(sample.data);
      sample.data = null;
    }
    __privateMethod(this, _maybeFlushStreamingTargetWriter, maybeFlushStreamingTargetWriter_fn).call(this);
  };
  _finalizeFragment = /* @__PURE__ */ new WeakSet();
  finalizeFragment_fn = function(flushStreamingWriter = true) {
    if (__privateGet(this, _options).fastStart !== "fragmented") {
      throw new Error("Can't finalize a fragment unless 'fastStart' is set to 'fragmented'.");
    }
    let tracks = [__privateGet(this, _videoTrack), __privateGet(this, _audioTrack)].filter((track) => track && track.currentChunk);
    if (tracks.length === 0)
      return;
    let fragmentNumber = __privateWrapper(this, _nextFragmentNumber)._++;
    if (fragmentNumber === 1) {
      let movieBox = moov(tracks, __privateGet(this, _creationTime), true);
      __privateGet(this, _writer).writeBox(movieBox);
    }
    let moofOffset = __privateGet(this, _writer).pos;
    let moofBox = moof(fragmentNumber, tracks);
    __privateGet(this, _writer).writeBox(moofBox);
    {
      let mdatBox = mdat(false);
      let totalTrackSampleSize = 0;
      for (let track of tracks) {
        for (let sample of track.currentChunk.samples) {
          totalTrackSampleSize += sample.size;
        }
      }
      let mdatSize = __privateGet(this, _writer).measureBox(mdatBox) + totalTrackSampleSize;
      if (mdatSize >= 2 ** 32) {
        mdatBox.largeSize = true;
        mdatSize = __privateGet(this, _writer).measureBox(mdatBox) + totalTrackSampleSize;
      }
      mdatBox.size = mdatSize;
      __privateGet(this, _writer).writeBox(mdatBox);
    }
    for (let track of tracks) {
      track.currentChunk.offset = __privateGet(this, _writer).pos;
      track.currentChunk.moofOffset = moofOffset;
      for (let sample of track.currentChunk.samples) {
        __privateGet(this, _writer).write(sample.data);
        sample.data = null;
      }
    }
    let endPos = __privateGet(this, _writer).pos;
    __privateGet(this, _writer).seek(__privateGet(this, _writer).offsets.get(moofBox));
    let newMoofBox = moof(fragmentNumber, tracks);
    __privateGet(this, _writer).writeBox(newMoofBox);
    __privateGet(this, _writer).seek(endPos);
    for (let track of tracks) {
      track.finalizedChunks.push(track.currentChunk);
      __privateGet(this, _finalizedChunks).push(track.currentChunk);
      track.currentChunk = null;
    }
    if (flushStreamingWriter) {
      __privateMethod(this, _maybeFlushStreamingTargetWriter, maybeFlushStreamingTargetWriter_fn).call(this);
    }
  };
  _maybeFlushStreamingTargetWriter = /* @__PURE__ */ new WeakSet();
  maybeFlushStreamingTargetWriter_fn = function() {
    if (__privateGet(this, _writer) instanceof StreamTargetWriter) {
      __privateGet(this, _writer).flush();
    }
  };
  _ensureNotFinalized = /* @__PURE__ */ new WeakSet();
  ensureNotFinalized_fn = function() {
    if (__privateGet(this, _finalized)) {
      throw new Error("Cannot add new video or audio chunks after the file has been finalized.");
    }
  };
  async function mp4(frames, convertMeta) {
    const p = frames.map((frame) => {
      if (frame instanceof Blob) {
        return createImageBitmap(frame);
      } else {
        return frame;
      }
    });
    const bitmaps = await Promise.all(p);
    if (convertMeta.isAborted) throw new CancelError();
    let width = bitmaps[0].width;
    let height = bitmaps[0].height;
    if (width % 2 !== 0) width += 1;
    if (height % 2 !== 0) height += 1;
    const muxer = new Muxer({
      target: new ArrayBufferTarget(),
      video: {
        codec: "avc",
        width,
        height
      },
      fastStart: "in-memory"
    });
    const videoEncoder = new VideoEncoder({
      output: (chunk, meta) => muxer.addVideoChunk(chunk, meta),
      error: (e) => logger.error(e)
    });
    videoEncoder.configure({
      codec: "avc1.420034",
      width,
      height,
      bitrate: config.get("mp4Bitrate") * 1e6
    });
    const delays = convertMeta.source.delays.map((delay) => delay *= 1e3);
    let timestamp = 0;
    const videoFrames = [];
    for (let i = 0; i < bitmaps.length; i++) {
      const frame = new VideoFrame(bitmaps[i], { duration: delays[i], timestamp });
      videoFrames.push(frame);
      bitmaps[i].close();
      videoEncoder.encode(frame);
      timestamp += delays[i];
    }
    await videoEncoder.flush();
    if (convertMeta.isAborted) {
      videoFrames.forEach((frame) => frame.close());
      throw new CancelError();
    }
    muxer.finalize();
    const { buffer } = muxer.target;
    videoFrames.forEach((frame) => frame.close());
    return new Blob([buffer], { type: "video/mp4" });
  }
  const adapter = {
    gif,
    png,
    webp,
    webm,
    mp4
  };
  const convertAdapter = {
    getAdapter(format) {
      return adapter[format];
    },
    getMixEffectFn() {
      return mixPngEffect;
    }
  };
  function createConverter() {
    const MAX_CONVERT = 2;
    const framesData = {};
    let isStop = false;
    let queue = [];
    let active2 = [];
    const isConvertSource = (meta) => {
      return Array.isArray(meta.source.data) && meta.source.data[0] instanceof Blob;
    };
    const doConvert = (convertMeta) => {
      var _a;
      const { id, format, resolve, reject } = convertMeta;
      active2.push(convertMeta);
      (_a = convertMeta.onProgress) == null ? void 0 : _a.call(convertMeta, 0);
      const adapter2 = convertAdapter.getAdapter(format);
      if (!isConvertSource(convertMeta)) {
        const mixEffect = convertAdapter.getMixEffectFn();
        mixEffect(convertMeta).then(({ bitmaps, frames, delays, width, height }) => {
          const meta = {
            ...convertMeta,
            source: {
              id,
              data: bitmaps,
              delays
            }
          };
          return Promise.all([adapter2(meta.source.data, meta), frames, delays, width, height]);
        }).then(([blob, frames, delays, width, height]) => {
          resolve({ blob, frames, delays, width, height });
        }, reject).finally(() => {
          active2.splice(active2.indexOf(convertMeta), 1);
          if (queue.length) doConvert(queue.shift());
        });
      } else {
        delete framesData[id];
        adapter2(convertMeta.source.data, convertMeta).then(resolve, reject).finally(() => {
          active2.splice(active2.indexOf(convertMeta), 1);
          if (queue.length) doConvert(queue.shift());
        });
      }
    };
    return {
      del: (taskIds) => {
        if (typeof taskIds === "string") taskIds = [taskIds];
        if (!taskIds.length) return;
        logger.info(
          "Converter del, active:",
          active2.map((meta) => meta.id),
          "queue:",
          queue.map((meta) => meta.id)
        );
        isStop = true;
        taskIds.forEach((taskId) => {
          if (taskId in framesData) delete framesData[taskId];
        });
        active2 = active2.filter((convertMeta) => {
          if (taskIds.includes(convertMeta.id)) {
            convertMeta.abort();
          } else {
            return true;
          }
        });
        queue = queue.filter((convertMeta) => !taskIds.includes(convertMeta.id));
        isStop = false;
        while (active2.length < MAX_CONVERT && queue.length) {
          doConvert(queue.shift());
        }
      },
      addFrame(taskId, data, delay, order) {
        if (!(taskId in framesData)) {
          framesData[taskId] = {
            id: taskId,
            data: [],
            delays: []
          };
        }
        if (order === void 0) {
          const length = framesData[taskId].data.length;
          framesData[taskId]["data"][length] = data;
          framesData[taskId]["delays"][length] = delay;
        } else {
          framesData[taskId]["data"][order] = data;
          framesData[taskId]["delays"][order] = delay;
        }
      },
      framesCount(taskId) {
        return taskId in framesData ? framesData[taskId]["delays"].filter((delay) => delay !== void 0).length : 0;
      },
      convert(taskId, format, onProgress) {
        return new Promise((resolve, reject) => {
          const meta = {
            id: taskId,
            format,
            source: framesData[taskId],
            isAborted: false,
            onProgress,
            resolve,
            reject,
            abort() {
              this.isAborted = true;
            }
          };
          logger.info("Converter add", taskId);
          queue.push(meta);
          while (active2.length < MAX_CONVERT && queue.length && !isStop) {
            doConvert(queue.shift());
          }
        });
      },
      async appendPixivEffect(taskId, format, illust, effect, onProgress) {
        return new Promise((resolve, reject) => {
          const meta = {
            id: taskId,
            format,
            source: {
              id: taskId,
              illust,
              data: effect
            },
            isAborted: false,
            onProgress,
            resolve,
            reject,
            abort() {
              this.isAborted = true;
            }
          };
          logger.info("Converter add", taskId);
          queue.push(meta);
          while (active2.length < MAX_CONVERT && queue.length && !isStop) {
            doConvert(queue.shift());
          }
        });
      }
    };
  }
  const converter = createConverter();
  const pixivHooks = {
    download: {
      singleArtworkProgressFactory(btn2, pageCount) {
        if (!btn2 || !pageCount) return;
        return function onSingleArtworkProgress(progress) {
          if (pageCount === 1) {
            btn2.setProgress(progress);
          }
        };
      },
      mulityArtworksProgressFactory(btn2, pageCount) {
        if (!btn2 || !pageCount) return;
        let pageComplete = 0;
        return function onMulityArtworksProgress() {
          if (pageCount < 2) return;
          const progress = Math.floor(++pageComplete / pageCount * 100);
          btn2.setProgress(progress);
        };
      }
    },
    bundle: {
      async beforeFileSave(imgBlob, config2) {
        const { taskId, source } = config2;
        compressor.add(taskId, source.filename, imgBlob);
        if (compressor.fileCount(taskId) === source.pageCount) {
          let comment;
          if ("ugoiraMeta" in config2.source) {
            const delays = config2.source.ugoiraMeta.frames.map((frames) => frames.delay);
            comment = JSON.stringify(delays);
          }
          const zipData = await compressor.bundle(taskId, comment);
          compressor.remove(taskId);
          return zipData;
        }
      },
      onError(err, config2) {
        compressor.remove(config2.taskId);
      },
      onAbort(config2) {
        compressor.remove(config2.taskId);
      }
    },
    convert: {
      convertProgressFactory(btn2) {
        return function onConvertProgress(progress) {
          if (progress > 0) {
            btn2.setProgress(progress, false);
          } else {
            btn2.setStatus(ThumbnailBtnStatus.Loading);
          }
        };
      },
      beforeFileSaveFactory(btn2) {
        const onProgress = btn2 ? this.convertProgressFactory(btn2) : void 0;
        return async function beforeFileSave(imgBlob, config2) {
          const { taskId, source } = config2;
          if (source.illustType === IllustType.ugoira) {
            converter.addFrame(
              taskId,
              imgBlob,
              source.ugoiraMeta.frames[source.order]["delay"],
              source.order
            );
            if (converter.framesCount(taskId) === source.pageCount) {
              return await converter.convert(taskId, source.extendName, onProgress);
            }
          }
        };
      },
      mixGlowEffect(btn2) {
        const onProgress = btn2 ? this.convertProgressFactory(btn2) : void 0;
        return async function beforeFileSave(imgBlob, pixivConfig) {
          const effectId = "pixivGlow2024";
          const url2 = "https://source.pixiv.net/special/seasonal-effect-tag/pixiv-glow-2024/effect.png";
          const { taskId } = pixivConfig;
          const effectData = await historyDb.getImageEffect(effectId);
          if (effectData && effectData.data[0] instanceof ArrayBuffer) {
            const { data, delays, width, height } = effectData;
            const { blob } = await converter.appendPixivEffect(
              taskId,
              pixivConfig.source.extendName,
              imgBlob,
              { frames: data, delays, width, height },
              onProgress
            );
            return blob;
          } else {
            const effctBlob = await new Promise((resolve, reject) => {
              _GM_xmlhttpRequest({
                url: url2,
                headers: {
                  referer: "https://www.pixiv.net"
                },
                responseType: "blob",
                onload(e) {
                  resolve(e.response);
                },
                onerror: reject,
                ontimeout: () => reject(new Error("Timeout"))
              });
            });
            const { blob, frames, delays, width, height } = await converter.appendPixivEffect(
              taskId,
              pixivConfig.source.extendName,
              imgBlob,
              effctBlob,
              onProgress
            );
            historyDb.addImageEffect({
              id: effectId,
              data: frames,
              delays,
              width,
              height
            });
            return blob;
          }
        };
      },
      onError(err, config2) {
        converter.del(config2.taskId);
      },
      onAbort(config2) {
        converter.del(config2.taskId);
      }
    }
  };
  const downloaderHooks = {
    getHooks(meta, downloadType, button) {
      switch (downloadType) {
        case "download":
          return {
            onProgress: pixivHooks.download.singleArtworkProgressFactory(button, meta.pageCount),
            onFileSaved: pixivHooks.download.mulityArtworksProgressFactory(button, meta.pageCount)
          };
        case "bundle":
          return {
            onXhrLoaded: pixivHooks.download.mulityArtworksProgressFactory(button, meta.pageCount),
            beforeFileSave: pixivHooks.bundle.beforeFileSave,
            onError: pixivHooks.bundle.onError
          };
        case "convert":
          return {
            onXhrLoaded: pixivHooks.download.mulityArtworksProgressFactory(button, meta.pageCount),
            beforeFileSave: pixivHooks.convert.beforeFileSaveFactory(button),
            onError: pixivHooks.convert.onError
          };
        case "mixEffect":
          return {
            onProgress: pixivHooks.download.singleArtworkProgressFactory(button, meta.pageCount),
            beforeFileSave: pixivHooks.convert.mixGlowEffect(button),
            onError: pixivHooks.convert.onError
          };
      }
    }
  };
  class PixivDownloadConfig extends DownloadConfigBuilder {
    constructor(meta) {
      super(meta);
      __publicField(this, "downloadAll", true);
      __publicField(this, "headers", {
        referer: "https://www.pixiv.net"
      });
      __publicField(this, "timeout", 6e4);
      __publicField(this, "getImgSrc", () => "");
      this.meta = meta;
      this.getImgSrc = this.meta.illustType === IllustType.ugoira ? (page) => this.meta.src.replace("ugoira0", "ugoira" + page) : (page) => this.meta.src.replace("_p0", "_p" + page);
    }
    getConvertFormat() {
      return config.get("ugoiraFormat");
    }
    getMixEffectFormat() {
      const format = this.getConvertFormat();
      if (format === "zip") return UgoiraFormat.WEBM;
      return format;
    }
    needConvert() {
      return this.meta.illustType === IllustType.ugoira && config.get("ugoiraFormat") !== "zip";
    }
    needBundle() {
      const { pageCount, illustType } = this.meta;
      return this.downloadAll && (illustType === IllustType.ugoira && this.getConvertFormat() === "zip" || pageCount > 1 && (illustType === IllustType.manga && config.get("bundleManga") || illustType === IllustType.illusts && config.get("bundleIllusts")));
    }
    useTranslatedTags() {
      return config.get("tagLang") !== "ja";
    }
    supportSubpath() {
      return this.isBrowserApi() || this.isFsaEnable();
    }
    buildPattern(pattern, page) {
      const { id, userId, artist, title, tags, tagsTranslated, createDate, pageCount } = this.meta;
      const currPage = page === void 0 ? pageCount : page;
      const useTags = this.useTranslatedTags() ? tagsTranslated : tags;
      const fArtist = this.normalizeString(artist) || userId;
      const fTitle = this.normalizeString(title) || id;
      const fTags = this.normalizeString(useTags.join("_"));
      const replaceDate = (match, p1) => {
        const format = p1 || "YYYY-MM-DD";
        return dayjs(createDate).format(format);
      };
      return pattern.replaceAll(/\{date\((.*?)\)\}|\{date\}/g, replaceDate).replaceAll("{artist}", fArtist).replaceAll("{artistID}", userId).replaceAll("{title}", fTitle).replaceAll("{tags}", fTags).replaceAll("{page}", String(currPage)).replaceAll("{id}", id);
    }
    getDownloadConfig(btn2) {
      const { illustType, src, id, pageCount, extendName } = this.meta;
      const pageAttr = btn2 == null ? void 0 : btn2.dataset.page;
      const downloadPage = pageAttr ? Number(pageAttr) : void 0;
      if (downloadPage && (downloadPage > pageCount - 1 || downloadPage < 0))
        throw new Error("Invalid downloadPage.");
      if (downloadPage !== void 0) this.downloadAll = false;
      const taskId = id + "_" + Math.random().toString(36).slice(2);
      const headers = this.headers;
      const supportSubPath = this.supportSubpath();
      const downloadConfigs = [];
      if ((pageCount === 1 || downloadPage !== void 0) && illustType !== IllustType.ugoira) {
        const imgSrc = downloadPage ? this.getImgSrc(downloadPage) : src;
        let path;
        let hooks;
        let source;
        if (config.get("mixEffect") && btn2) {
          const effectExt = this.getMixEffectFormat();
          const pathPatternNoExt = supportSubPath ? this.getFullpathPattern().slice(0, -4) : this.getFilenamePattern();
          const pathPattern = pathPatternNoExt + "." + effectExt;
          path = this.buildPattern(pathPattern, downloadPage ? downloadPage : 0);
          const filename = path.slice(path.lastIndexOf("/") + 1);
          hooks = downloaderHooks.getHooks({ ...this.meta, pageCount: 1 }, "mixEffect", btn2);
          source = {
            ...this.meta,
            pageCount: 1,
            extendName: effectExt,
            filename,
            order: downloadPage ?? 0
          };
        } else {
          const pathPattern = supportSubPath ? this.getFullpathPattern() : this.getFilenamePattern() + "." + extendName;
          path = this.buildPattern(pathPattern, downloadPage ? downloadPage : 0);
          const filename = path.slice(path.lastIndexOf("/") + 1);
          hooks = downloaderHooks.getHooks({ ...this.meta, pageCount: 1 }, "download", btn2);
          source = {
            ...this.meta,
            pageCount: 1,
            filename,
            order: downloadPage ?? 0
          };
        }
        const downloadConfig = {
          taskId,
          src: imgSrc,
          path,
          source,
          headers,
          timeout: this.timeout,
          ...hooks
        };
        downloadConfigs.push(downloadConfig);
      } else {
        const pathPatternNoExt = supportSubPath ? this.getFullpathPattern().slice(0, -4) : this.getFilenamePattern();
        if (this.needBundle()) {
          const pathPattern = pathPatternNoExt + ".zip";
          const filenamePattern = this.getFilenamePattern().includes("{page}") ? this.getFilenamePattern() + "." + extendName : this.getFilenamePattern() + "_{page}." + extendName;
          let path;
          let imgCount;
          if (illustType === IllustType.ugoira) {
            path = this.buildPattern(pathPattern, 0);
            imgCount = this.meta.ugoiraMeta.frames.length;
          } else {
            path = this.buildPattern(pathPattern);
            imgCount = pageCount;
          }
          const hooks = downloaderHooks.getHooks(
            { ...this.meta, pageCount: imgCount },
            "bundle",
            btn2
          );
          for (let page = 0; page < imgCount; page++) {
            const filename = this.buildPattern(filenamePattern, page);
            const imgSrc = this.getImgSrc(page);
            const source = {
              ...this.meta,
              pageCount: imgCount,
              extendName: "zip",
              filename,
              order: page
            };
            const downloadConfig = {
              taskId,
              src: imgSrc,
              path,
              source,
              headers,
              timeout: this.timeout,
              ...hooks
            };
            downloadConfigs.push(downloadConfig);
          }
        } else if (this.needConvert()) {
          const ext = this.getConvertFormat();
          const pathPattern = pathPatternNoExt + "." + ext;
          const path = this.buildPattern(pathPattern, 0);
          const filename = path.slice(path.lastIndexOf("/") + 1);
          const imgCount = this.meta.ugoiraMeta.frames.length;
          const hooks = downloaderHooks.getHooks(
            { ...this.meta, pageCount: imgCount },
            "convert",
            btn2
          );
          for (let page = 0; page < imgCount; page++) {
            const imgSrc = this.getImgSrc(page);
            const source = {
              ...this.meta,
              pageCount: imgCount,
              extendName: ext,
              filename,
              order: page
            };
            const downloadConfig = {
              taskId,
              src: imgSrc,
              path,
              source,
              headers,
              timeout: this.timeout,
              ...hooks
            };
            downloadConfigs.push(downloadConfig);
          }
        } else {
          const pathPattern = pathPatternNoExt + "." + extendName;
          const hooks = downloaderHooks.getHooks(this.meta, "download", btn2);
          for (let page = 0; page < pageCount; page++) {
            const path = this.buildPattern(pathPattern, page);
            const filename = path.slice(path.lastIndexOf("/") + 1);
            const imgSrc = this.getImgSrc(page);
            const source = {
              ...this.meta,
              filename,
              order: page
            };
            const downloadConfig = {
              taskId,
              src: imgSrc,
              path,
              source,
              headers,
              timeout: this.timeout,
              ...hooks
            };
            downloadConfigs.push(downloadConfig);
          }
        }
      }
      !this.downloadAll && (this.downloadAll = true);
      return downloadConfigs;
    }
  }
  function getSelfId() {
    var _a, _b;
    return ((_b = (_a = _unsafeWindow.dataLayer) == null ? void 0 : _a[0]) == null ? void 0 : _b.user_id) ?? "";
  }
  function getIllustId(node) {
    const isLinkToArtworksPage = regexp.artworksPage.exec(node.getAttribute("href") || "");
    if (isLinkToArtworksPage) {
      if (node.getAttribute("data-gtm-value") || [
        "gtm-illust-recommend-node-node",
        "gtm-discover-user-recommend-node",
        "work",
        "_history-item",
        "_history-related-item"
      ].some((className) => node.classList.contains(className))) {
        return isLinkToArtworksPage[1];
      }
    } else if (node instanceof HTMLSpanElement && node.className.includes("_history-item")) {
      const img = node.querySelector("img");
      if (!img) return "";
      const matchPid = regexp.historyThumbnailsId.exec(img.src);
      if (matchPid) return matchPid[0];
    } else {
      const isActivityThumb = regexp.activityHref.exec(node.getAttribute("href") || "");
      if (isActivityThumb && node.classList.contains("work")) {
        return isActivityThumb[1];
      }
    }
    return "";
  }
  function addBookmark(btn2, illustId, token, tags) {
    if (!config.get("addBookmark")) return;
    api.addBookmark(
      illustId,
      token,
      config.get("addBookmarkWithTags") ? tags : [],
      config.get("privateR18") && tags.includes("R-18") ? BookmarkRestrict.private : BookmarkRestrict.public
    ).then(() => {
      const bookmarkBtnRef = findBookmarkBtn(btn2);
      if (!bookmarkBtnRef) return;
      switch (bookmarkBtnRef.kind) {
        case "main": {
          const pathBorder = bookmarkBtnRef.button.querySelector("svg g path");
          pathBorder && (pathBorder.style.color = "rgb(255, 64, 96)");
          break;
        }
        case "sub": {
          const pathBorder = bookmarkBtnRef.button.querySelector("path");
          pathBorder && (pathBorder.style.color = "rgb(255, 64, 96)");
          break;
        }
        case "rank": {
          bookmarkBtnRef.button.style.backgroundColor = "rgb(255, 64, 96)";
          break;
        }
      }
    }).catch((reason) => {
      logger.error(reason.message);
    });
  }
  function findBookmarkBtn(btn2) {
    var _a, _b, _c, _d, _e;
    const bookmarkBtnRef = {};
    if (!btn2.dataset.type) {
      const favBtn = (_b = (_a = btn2.parentElement) == null ? void 0 : _a.nextElementSibling) == null ? void 0 : _b.querySelector(
        'button[type="button"]'
      );
      if (favBtn) {
        bookmarkBtnRef.kind = "sub";
        bookmarkBtnRef.button = favBtn;
      } else {
        const favBtn2 = (_c = btn2.parentElement) == null ? void 0 : _c.querySelector("div._one-click-bookmark");
        if (favBtn2) {
          bookmarkBtnRef.kind = "rank";
          bookmarkBtnRef.button = favBtn2;
        }
      }
    } else if (btn2.dataset.type === ThumbnailBtnType.PixivToolbar) {
      const favBtn = (_e = (_d = btn2.parentElement) == null ? void 0 : _d.parentElement) == null ? void 0 : _e.querySelector(
        "button.gtm-main-bookmark"
      );
      if (favBtn) {
        bookmarkBtnRef.kind = "main";
        bookmarkBtnRef.button = favBtn;
      }
    } else {
      return logger.warn(new Error("Can not find bookmark button."));
    }
    return bookmarkBtnRef;
  }
  async function downloadArtwork$1(btn2) {
    downloader.dirHandleCheck();
    const { id, page, unlistedId } = btn2.dataset;
    const tagLang = config.get("tagLang");
    let pixivMeta;
    if (!unlistedId) {
      pixivMeta = await pixivParser.parse(id, { tagLang, type: "html" });
      const { bookmarkData, token, tags: tags2 } = pixivMeta;
      if (!bookmarkData) {
        addBookmark(btn2, id, token, tags2);
      }
    } else {
      pixivMeta = await pixivParser.parse(unlistedId, { tagLang, type: "unlisted" });
    }
    const downloadConfigs = new PixivDownloadConfig(pixivMeta).getDownloadConfig(btn2);
    await downloader.download(downloadConfigs);
    const { comment, tags, artist, userId, title } = pixivMeta;
    const historyData = {
      pid: Number(id),
      user: artist,
      userId: Number(userId),
      title,
      comment,
      tags
    };
    if (page !== void 0) {
      historyData.page = Number(page);
    }
    if (unlistedId) {
      historyData.unlistedId = unlistedId;
    }
    historyDb.add(historyData);
  }
  function createThumbnailBtn(nodes) {
    let isSelfBookmark = false;
    const inBookmarkPage = regexp.bookmarkPage.exec(location.pathname);
    inBookmarkPage && inBookmarkPage[1] === getSelfId() && (isSelfBookmark = true);
    nodes.forEach((e) => {
      let illustId;
      let type;
      if ((e.childElementCount !== 0 || e.className.includes("_history-item") || e.className.includes("_history-related-item")) && !e.querySelector(ThumbnailButton.tagNameLowerCase) && (illustId = getIllustId(e))) {
        if (isSelfBookmark) {
          type = ThumbnailBtnType.PixivMyBookmark;
        } else if (e.className.includes("_history-related-item")) {
          e.style.position = "relative";
          type = ThumbnailBtnType.PixivHistory;
        } else if (e.className.includes("_history-item")) {
          type = ThumbnailBtnType.PixivHistory;
        }
        const btn2 = new ThumbnailButton({
          id: illustId,
          type,
          onClick: downloadArtwork$1
        });
        e.appendChild(btn2);
      }
    });
  }
  function fixPixivPreviewer(nodes) {
    if (!regexp.searchPage.test(location.pathname)) return;
    nodes.forEach((node) => {
      var _a;
      (_a = node.querySelector(ThumbnailButton.tagNameLowerCase)) == null ? void 0 : _a.remove();
    });
  }
  function createToolbarBtn(id) {
    const toolbar = document.querySelector("main section section");
    if (!toolbar || toolbar.querySelector(ThumbnailButton.tagNameLowerCase)) return;
    const btn2 = new ThumbnailButton({
      id,
      type: ThumbnailBtnType.PixivToolbar,
      onClick: downloadArtwork$1
    });
    const pdlBtnWrap = toolbar.lastElementChild.cloneNode();
    pdlBtnWrap.appendChild(btn2);
    toolbar.appendChild(pdlBtnWrap);
  }
  function createWorkExpanedViewBtn(id, unlistedId) {
    const works = document.querySelectorAll(
      "figure a.gtm-expand-full-size-illust"
    );
    if (works.length < 2) return;
    works.forEach((work, idx) => {
      var _a;
      const container = (_a = work.parentElement) == null ? void 0 : _a.parentElement;
      if (!container || container.querySelector(ArtworkButton.tagNameLowerCase)) return;
      container.appendChild(
        new ArtworkButton({
          id,
          page: idx,
          extraData: unlistedId ? { unlistedId } : void 0,
          onClick: downloadArtwork$1
        })
      );
    });
  }
  let observer;
  let btn;
  function createPresentationBtn(id, unlistedId) {
    const containers = document.querySelector("body > [role='presentation'] > div");
    if (!containers) {
      if (observer) {
        observer.disconnect();
        observer = null;
        btn = null;
      }
      return;
    }
    if (containers.querySelector(ThumbnailButton.tagNameLowerCase)) return;
    const img = containers.querySelector("div > img");
    if (!img) return;
    const isOriginImg = regexp.originSrcPageNum.exec(img.src);
    if (!isOriginImg) return;
    const [pageNum] = isOriginImg;
    btn = new ThumbnailButton({
      id,
      type: ThumbnailBtnType.PixivPresentation,
      page: Number(pageNum),
      extraData: unlistedId ? { unlistedId } : void 0,
      onClick: downloadArtwork$1
    });
    containers.appendChild(btn);
    observer = new MutationObserver((mutationList) => {
      const newImg = mutationList[1]["addedNodes"][0];
      const [pageNum2] = regexp.originSrcPageNum.exec(newImg.src) ?? [];
      if (!pageNum2) return logger.throw("Invalid image element.");
      btn == null ? void 0 : btn.remove();
      btn = new ThumbnailButton({
        id,
        type: ThumbnailBtnType.PixivPresentation,
        page: Number(pageNum2),
        extraData: unlistedId ? { unlistedId } : void 0,
        onClick: downloadArtwork$1
      });
      containers.appendChild(btn);
    });
    observer.observe(img.parentElement, { childList: true, subtree: true });
  }
  function createPreviewModalBtn(id, unlistedId) {
    var _a;
    const illustModalBtn = document.querySelector(
      ".gtm-manga-viewer-preview-modal-open:not(.pdl-listened)"
    );
    const mangaModalBtn = document.querySelector(".gtm-manga-viewer-open-preview:not(.pdl-listened)");
    const mangaViewerModalBtn = (_a = document.querySelectorAll(
      ".gtm-manga-viewer-close-icon:not(.pdl-listened)"
    )) == null ? void 0 : _a[1];
    if (!illustModalBtn && !mangaModalBtn && !mangaViewerModalBtn) return;
    [illustModalBtn, mangaModalBtn, mangaViewerModalBtn].forEach((node) => {
      if (node) {
        node.classList.add("pdl-listened");
        node.addEventListener("click", () => {
          handleModalClick(id, unlistedId);
        });
      }
    });
  }
  function handleModalClick(id, unlistedId) {
    const timer = setInterval(() => {
      logger.info("Start to find modal.");
      const ulList = document.querySelectorAll("ul");
      const previewList = ulList[ulList.length - 1];
      if (getComputedStyle(previewList).display !== "grid") return;
      clearInterval(timer);
      previewList.childNodes.forEach((node, idx) => {
        node.style.position = "relative";
        node.appendChild(
          new ThumbnailButton({
            id,
            page: idx,
            extraData: unlistedId ? { unlistedId } : void 0,
            onClick: downloadArtwork$1
          })
        );
      });
    }, 300);
  }
  function createMangaViewerBtn(id, unlistedId) {
    const mangaViewerBackBtn = document.querySelector(".gtm-manga-viewer-close-icon");
    if (!mangaViewerBackBtn) return;
    const container = mangaViewerBackBtn.parentElement;
    if (!container || container.querySelector(ThumbnailButton.tagNameLowerCase)) return;
    container.appendChild(
      new ThumbnailButton({
        id,
        type: ThumbnailBtnType.PixivMangaViewer,
        extraData: unlistedId ? { unlistedId } : void 0,
        onClick: downloadArtwork$1
      })
    );
  }
  const toolbarStyle = ".button-wrapper{display:flex;justify-content:flex-end;align-items:center;height:32px;padding:8px 12px}";
  class UnlistedArtworkToolbar extends HTMLElement {
    constructor(props) {
      super();
      __publicField(this, "props");
      this.props = props;
    }
    static get tagNameLowerCase() {
      return "pdl-unlisted-artwork-toolbar";
    }
    render() {
      if (this.shadowRoot) return;
      const shadowRoot = this.attachShadow({ mode: "open" });
      shadowRoot.innerHTML = `<style>${toolbarStyle}</style><div class="button-wrapper"></div>`;
      const thumbnailButton = new ThumbnailButton({
        ...this.props,
        type: ThumbnailBtnType.PixivToolbar
      });
      const wrapper = shadowRoot.querySelector(".button-wrapper");
      wrapper.appendChild(thumbnailButton);
    }
    connectedCallback() {
      this.render();
    }
  }
  customElements.define(UnlistedArtworkToolbar.tagNameLowerCase, UnlistedArtworkToolbar);
  function createUnlistedToolbar(id, unlistedId) {
    const toolbar = document.querySelector(UnlistedArtworkToolbar.tagNameLowerCase);
    if (toolbar) return;
    const container = document.querySelector('div[style^="transform: translateY"]');
    if (!container) return;
    const el = new UnlistedArtworkToolbar({
      id,
      onClick: downloadArtwork$1,
      extraData: {
        unlistedId
      }
    });
    container.appendChild(el);
    const showAllBtn = container.querySelector(
      'button[type="button"]:not([style])'
    );
    showAllBtn && (showAllBtn.style.bottom = "48px");
  }
  class TagListButton extends HTMLElement {
    constructor(tagUrl, downloading, handleDownload) {
      super();
      __publicField(this, "btn");
      __publicField(this, "unsubscriber");
      this.tagUrl = tagUrl;
      this.downloading = downloading;
      this.handleDownload = handleDownload;
      this.dispatchDownload = this.dispatchDownload.bind(this);
    }
    static get tagNameLowerCase() {
      return "pdl-tag-list-button";
    }
    async render() {
      if (this.shadowRoot) return;
      const shadowRoot = this.attachShadow({ mode: "open" });
      addStyleToShadow(shadowRoot);
      shadowRoot.innerHTML = ` 
  <div class=" flex items-center">    
    <hr class="!border-t-0 border-l h-6 ml-4 mr-2" />
    <button class=" h-[38px] w-[38px] btn-icon [&:not([disabled])]:hover:bg-slate-400/30 disabled:cursor-wait disabled:opacity-70">
      <i class="text-sm w-6 fill-current mx-2">
      ${downloadSvg}
      </i>
    </button>
  </div>
  `;
    }
    getTagProps() {
      const url2 = new URL(this.tagUrl);
      const { searchParams, pathname } = url2;
      const extractUrlMatch = regexp.userPageTags.exec(pathname);
      if (!extractUrlMatch) throw new Error(`Could not extract tag props from: ${pathname}`);
      const [, userId, urlCategory, tag] = extractUrlMatch;
      if (!tag) throw new Error(`Could not extract tag from: ${pathname}`);
      let category;
      if (urlCategory === "illustrations" || urlCategory === "artworks") {
        category = "illusts";
      } else {
        category = urlCategory;
      }
      return {
        userId,
        category,
        tag,
        rest: searchParams.get("rest") === "hide" ? "hide" : "show"
      };
    }
    dispatchDownload(evt) {
      evt == null ? void 0 : evt.preventDefault();
      this.handleDownload(this.getTagProps()).catch(logger.error);
    }
    connectedCallback() {
      this.render();
      this.btn ?? (this.btn = this.shadowRoot.querySelector("button"));
      this.btn.addEventListener("click", this.dispatchDownload);
      this.unsubscriber = this.downloading.subscribe((val) => {
        if (val) {
          this.setAttribute("disabled", "");
        } else {
          this.removeAttribute("disabled");
        }
      });
    }
    disconnectedCallback() {
      var _a, _b;
      (_a = this.unsubscriber) == null ? void 0 : _a.call(this);
      (_b = this.btn) == null ? void 0 : _b.removeEventListener("click", this.dispatchDownload);
    }
    static get observedAttributes() {
      return ["disabled"];
    }
    attributeChangedCallback(name, oldValue, newValue) {
      var _a, _b;
      if (typeof newValue === "string") {
        (_a = this.btn) == null ? void 0 : _a.setAttribute("disabled", "");
      } else {
        (_b = this.btn) == null ? void 0 : _b.removeAttribute("disabled");
      }
    }
  }
  customElements.define(TagListButton.tagNameLowerCase, TagListButton);
  function createTagListBtn(downloading, handleDownload) {
    var _a;
    const listContainer = document.querySelector('div[style*="position: relative"]');
    if (!listContainer) return;
    const modalRoot = listContainer == null ? void 0 : listContainer.closest('div[role="presentation"], div[class="charcoal-token"]');
    const closeBtn = (_a = modalRoot == null ? void 0 : modalRoot.querySelector("svg")) == null ? void 0 : _a.parentElement;
    const tagElements = listContainer.querySelectorAll(
      'div[style*="position: absolute"] a'
    );
    tagElements.forEach((ele) => {
      if (ele.querySelector(TagListButton.tagNameLowerCase)) return;
      const btn2 = new TagListButton(ele.href, downloading, (props) => {
        closeBtn == null ? void 0 : closeBtn.click();
        return handleDownload(props);
      });
      ele.appendChild(btn2);
    });
  }
  class ArtworkTagButton extends HTMLElement {
    constructor(tagElement, downloading, handleDownload) {
      super();
      __publicField(this, "btn");
      __publicField(this, "ob");
      __publicField(this, "unsubscriber");
      this.tagElement = tagElement;
      this.downloading = downloading;
      this.handleDownload = handleDownload;
      this.dispatchDownload = this.dispatchDownload.bind(this);
      this.ob = new MutationObserver(() => {
        this.changeBtnColor();
      });
    }
    static get tagNameLowerCase() {
      return "pdl-artwork-tag";
    }
    // 为了美观
    resetTagStyle() {
      this.tagElement.style.borderTopRightRadius = "0px";
      this.tagElement.style.borderBottomRightRadius = "0px";
    }
    changeBtnColor() {
      if (!this.btn) return;
      const { color, backgroundColor } = getComputedStyle(this.tagElement);
      this.btn.style.color = color;
      this.btn.style.backgroundColor = backgroundColor;
    }
    async render() {
      if (this.shadowRoot) return;
      const shadowRoot = this.attachShadow({ mode: "open" });
      addStyleToShadow(shadowRoot);
      shadowRoot.innerHTML = `  <button class="flex h-full items-center pr-2 rounded-e-[4px] disabled:cursor-wait disabled:opacity-70">
    <hr class="!border-t-0 border-l h-6 pr-2" />
    <i class="text-sm w-6 fill-current">
      ${downloadSvg}
    </i>
  </button>`;
      this.resetTagStyle();
    }
    getTagProps() {
      const tagTitles = this.tagElement.querySelectorAll("div[title]");
      const tagStr = tagTitles[tagTitles.length - 1].getAttribute("title");
      const tag = tagStr.startsWith("#") ? tagStr.slice(1) : "未分類";
      const url2 = new URL(this.tagElement.href);
      const { searchParams, pathname } = url2;
      const extractUrlMatch = regexp.userPageTags.exec(pathname);
      if (!extractUrlMatch) throw new Error(`Could not extract tag props from: ${pathname}`);
      const [, userId, urlCategory] = extractUrlMatch;
      let category;
      if (urlCategory === "illustrations" || urlCategory === "artworks") {
        category = "illusts";
      } else {
        category = urlCategory;
      }
      return {
        userId,
        category,
        tag,
        rest: searchParams.get("rest") === "hide" ? "hide" : "show"
      };
    }
    dispatchDownload() {
      this.handleDownload(this.getTagProps()).catch(logger.error);
    }
    connectedCallback() {
      this.render();
      this.btn ?? (this.btn = this.shadowRoot.querySelector("button"));
      this.changeBtnColor();
      this.btn.addEventListener("click", this.dispatchDownload);
      this.unsubscriber = this.downloading.subscribe((val) => {
        if (val) {
          this.setAttribute("disabled", "");
        } else {
          this.removeAttribute("disabled");
        }
      });
      this.ob.observe(this.tagElement, {
        attributes: true,
        attributeFilter: ["class"]
      });
    }
    disconnectedCallback() {
      var _a, _b;
      (_a = this.unsubscriber) == null ? void 0 : _a.call(this);
      (_b = this.btn) == null ? void 0 : _b.removeEventListener("click", this.dispatchDownload);
      this.ob.disconnect();
    }
    static get observedAttributes() {
      return ["disabled"];
    }
    attributeChangedCallback(name, oldValue, newValue) {
      var _a, _b;
      if (typeof newValue === "string") {
        (_a = this.btn) == null ? void 0 : _a.setAttribute("disabled", "");
      } else {
        (_b = this.btn) == null ? void 0 : _b.removeAttribute("disabled");
      }
    }
  }
  customElements.define(ArtworkTagButton.tagNameLowerCase, ArtworkTagButton);
  function createFrequentTagBtn(downloading, handleDownload) {
    const tagsEles = Array.from(document.querySelectorAll("a[status]"));
    if (!tagsEles.length) return;
    tagsEles.forEach((ele) => {
      var _a;
      if (((_a = ele.nextElementSibling) == null ? void 0 : _a.tagName.toLowerCase()) === ArtworkTagButton.tagNameLowerCase) return;
      const artworkTagBtn = new ArtworkTagButton(ele, downloading, handleDownload);
      ele.parentElement.appendChild(artworkTagBtn);
    });
  }
  class Pixiv extends SiteInject {
    constructor() {
      super(...arguments);
      __publicField(this, "firstObserverCbRunFlag", true);
      __publicField(this, "useBatchDownload", this.app.initBatchDownloader({
        metaType: {},
        async avatar(url2) {
          let userId;
          let matchReg;
          if (matchReg = regexp.series.exec(url2)) {
            userId = matchReg[1];
          } else if (matchReg = regexp.userPage.exec(url2)) {
            userId = matchReg[1] || matchReg[2];
          } else {
            userId = getSelfId() ?? "";
          }
          if (!userId) return "";
          try {
            const userData = await api.getUserData(userId);
            return userData.imageBig;
          } catch (error) {
            logger.error(error);
            return "";
          }
        },
        filterOption: {
          filters: [
            {
              id: "exclude_downloaded",
              type: "exclude",
              name: t("downloader.category.filter.exclude_downloaded"),
              checked: false,
              fn(meta) {
                return !!meta.id && historyDb.has(meta.id);
              }
            },
            {
              id: "illust",
              type: "include",
              name: t("downloader.category.filter.pixiv_illust"),
              checked: true,
              fn(meta) {
                return meta.illustType === IllustType.illusts;
              }
            },
            {
              id: "manga",
              type: "include",
              name: t("downloader.category.filter.pixiv_manga"),
              checked: true,
              fn(meta) {
                return meta.illustType === IllustType.manga;
              }
            },
            {
              id: "ugoira",
              type: "include",
              name: t("downloader.category.filter.pixiv_ugoira"),
              checked: true,
              fn(meta) {
                return meta.illustType === IllustType.ugoira;
              }
            }
          ],
          enableTagFilter: true
        },
        pageMatch: {
          self_bookmark_public: {
            name: t("downloader.download_type.pixiv_bookmark_public"),
            match(url2) {
              const userIdMatch = regexp.userPage.exec(url2);
              if (!userIdMatch) return false;
              const userId = userIdMatch[1] || userIdMatch[2];
              return userId === getSelfId();
            },
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              return pixivParser.bookmarkGenerator(pageRange, checkValidity, getSelfId());
            }
          },
          self_bookmark_private: {
            name: t("downloader.download_type.pixiv_bookmark_private"),
            match(url2) {
              const userIdMatch = regexp.userPage.exec(url2);
              if (!userIdMatch) return false;
              const userId = userIdMatch[1] || userIdMatch[2];
              return userId === getSelfId();
            },
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              return pixivParser.bookmarkGenerator(pageRange, checkValidity, getSelfId(), "hide");
            }
          },
          user_page_works: {
            name: t("downloader.download_type.pixiv_works"),
            match: regexp.userPage,
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              const userIdMatch = regexp.userPage.exec(location.href);
              const userId = userIdMatch[1] || userIdMatch[2];
              return pixivParser.illustMangaGenerator(pageRange, checkValidity, userId);
            }
          },
          user_page_bookmark: {
            name: t("downloader.download_type.pixiv_bookmark"),
            match: regexp.userPage,
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              const userIdMatch = regexp.userPage.exec(location.href);
              const userId = userIdMatch[1] || userIdMatch[2];
              return pixivParser.bookmarkGenerator(pageRange, checkValidity, userId);
            }
          },
          follow_latest_all: {
            name: t("downloader.download_type.pixiv_follow_latest_all"),
            match: regexp.followLatest,
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              return pixivParser.followLatestGenerator(pageRange, checkValidity, "all");
            }
          },
          follow_latest_r18: {
            name: t("downloader.download_type.pixiv_follow_latest_r18"),
            match: regexp.followLatest,
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              return pixivParser.followLatestGenerator(pageRange, checkValidity, "r18");
            }
          },
          series: {
            name: t("downloader.download_type.pixiv_series"),
            match: regexp.series,
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity) => {
              const matchSeries = regexp.series.exec(location.pathname);
              return pixivParser.seriesGenerator(pageRange, checkValidity, matchSeries[2]);
            }
          },
          tagged_artwork: {
            name: "tagged_artwork",
            match: () => false,
            // use for user tag download
            filterWhenGenerateIngPage: true,
            fn: (pageRange, checkValidity, userId, category, tag, bookmarkRest = "show") => {
              if (category === "bookmarks") {
                return pixivParser.taggedArtworkGenerator(
                  pageRange,
                  checkValidity,
                  userId,
                  category,
                  tag,
                  bookmarkRest
                );
              } else {
                return pixivParser.taggedArtworkGenerator(
                  pageRange,
                  checkValidity,
                  userId,
                  category,
                  tag
                );
              }
            }
          }
        },
        parseMetaByArtworkId: (id) => {
          return pixivParser.parse(id, { tagLang: this.config.get("tagLang"), type: "api" });
        },
        async downloadByArtworkId(meta, taskId) {
          downloader.dirHandleCheck();
          const downloadConfigs = new PixivDownloadConfig(meta).getDownloadConfig();
          downloadConfigs.forEach((config2) => {
            config2.taskId = taskId;
          });
          await downloader.download(downloadConfigs);
          const { comment, id, tags, artist, userId, title } = meta;
          const historyData = {
            pid: Number(id),
            user: artist,
            userId: Number(userId),
            title,
            comment,
            tags
          };
          historyDb.add(historyData);
        },
        onDownloadAbort(taskIds) {
          downloader.abort(taskIds);
        }
      }));
    }
    static get hostname() {
      return "www.pixiv.net";
    }
    inject() {
      super.inject();
      new MutationObserver((records) => {
        this.injectThumbnailButtons(records);
        this.pageActions();
      }).observe(document.body, {
        childList: true,
        subtree: true
      });
    }
    getCustomConfig() {
      return {
        folderPattern: "pixiv/{artist}",
        filenamePattern: "{artist}_{title}_{id}_p{page}"
      };
    }
    getFilenameTemplate() {
      return ["{artist}", "{artistID}", "{title}", "{id}", "{page}", "{tags}", "{date}"];
    }
    observeColorScheme() {
      const onThemeChange = () => {
        const sitePreferDark = document.documentElement.getAttribute("data-theme");
        sitePreferDark === "dark" ? this.setAppDarkMode() : this.setAppLightMode();
      };
      new MutationObserver(onThemeChange).observe(document.documentElement, {
        attributes: true,
        childList: false,
        subtree: false
      });
      onThemeChange();
    }
    injectThumbnailButtons(records) {
      const addedNodes = [];
      records.forEach((record) => {
        if (!record.addedNodes.length) return;
        record.addedNodes.forEach((node) => {
          if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() !== ThumbnailButton.tagNameLowerCase && node.tagName !== "IMG") {
            addedNodes.push(node);
          }
        });
      });
      if (!addedNodes.length) return;
      if (this.firstObserverCbRunFlag) {
        createThumbnailBtn(document.querySelectorAll("a"));
        this.firstObserverCbRunFlag = false;
      } else {
        fixPixivPreviewer(addedNodes);
        const thumbnails = addedNodes.reduce((prev, current) => {
          return prev.concat(
            current instanceof HTMLAnchorElement ? [current] : Array.from(current.querySelectorAll("a"))
          );
        }, []);
        createThumbnailBtn(thumbnails);
      }
    }
    pageActions() {
      var _a, _b;
      const pathname = location.pathname;
      let param;
      switch (true) {
        case !!(param = regexp.artworksPage.exec(pathname)): {
          const id = param[1];
          createToolbarBtn(id);
          createWorkExpanedViewBtn(id);
          createPresentationBtn(id);
          createPreviewModalBtn(id);
          createMangaViewerBtn(id);
          break;
        }
        case regexp.userPageTags.test(pathname): {
          const { downloading, batchDownload } = this.useBatchDownload();
          const handleDownload = (props) => {
            const { userId, category, tag, rest } = props;
            return batchDownload("tagged_artwork", userId, category, tag, rest);
          };
          createFrequentTagBtn(downloading, handleDownload);
          createTagListBtn(downloading, handleDownload);
          break;
        }
        case regexp.historyPage.test(pathname): {
          createThumbnailBtn(document.querySelectorAll("span[style]._history-item"));
          break;
        }
        case !!(param = regexp.unlisted.exec(pathname)): {
          const unlistedId = param[0];
          const canonicalUrl = (_a = document.querySelector('link[rel="canonical"]')) == null ? void 0 : _a.getAttribute("href");
          if (!canonicalUrl) return;
          const id = (_b = regexp.artworksPage.exec(canonicalUrl)) == null ? void 0 : _b[1];
          if (!id) return;
          createUnlistedToolbar(id, unlistedId);
          createWorkExpanedViewBtn(id, unlistedId);
          createPresentationBtn(id, unlistedId);
          createPreviewModalBtn(id, unlistedId);
          createMangaViewerBtn(id, unlistedId);
          break;
        }
      }
    }
  }
  const yandeParser = {
    async parse(id) {
      const res = await fetch("/post/show/" + id);
      if (!res.ok) throw new RequestError(res.url, res.status);
      const html = await res.text();
      const matchImageData = html.match(new RegExp("(?<=Post\\.register_resp\\().+(?=\\);)"));
      if (!matchImageData) throw new Error("Can not parse image data.");
      const imageData = JSON.parse(matchImageData[0]);
      const postData = imageData.posts[0];
      const artists = [];
      const characters = [];
      const tags = [];
      for (const tag in imageData.tags) {
        const tagType = imageData.tags[tag];
        if (tagType === "artist") {
          artists.push(tag);
        } else if (tagType === "character") {
          characters.push(tag);
        }
        tags.push(tagType + ":" + tag);
      }
      postData.source && tags.push("source:" + postData.source);
      return {
        id,
        src: postData.file_url,
        extendName: postData.file_ext,
        artist: artists.join(",") || "UnknownArtist",
        character: characters.join(",") || "UnknownCharacter",
        title: postData.md5,
        tags,
        createDate: new Date(postData.created_at * 1e3).toISOString()
      };
    }
  };
  class YandeDownloadConfig extends Rule34DownloadConfig {
  }
  async function downloadArtwork(btn2) {
    downloader.dirHandleCheck();
    const id = btn2.dataset.id;
    const mediaMeta = await yandeParser.parse(id);
    const { tags, artist, title } = mediaMeta;
    const downloadConfigs = new YandeDownloadConfig(mediaMeta).getDownloadConfig(btn2);
    await downloader.download(downloadConfigs);
    const historyData = {
      pid: Number(id),
      user: artist,
      title,
      tags
    };
    historyDb.add(historyData);
  }
  class Yande extends SiteInject {
    static get hostname() {
      return "yande.re";
    }
    inject() {
      super.inject();
      const pathname = location.pathname;
      const galleryMatch = pathname.match(new RegExp("(?<=\\/post\\/show\\/)\\d+"));
      if (galleryMatch) {
        this.createArtworkBtn(galleryMatch[0]);
      } else if (pathname === "/post/browse") {
        this.createScrollerBtn();
        this.createImageBrowseBtn();
      } else {
        const btnContainers = document.querySelectorAll(
          "a.thumb, div.post div.col1 a"
        );
        this.createThumbnailBtn(Array.from(btnContainers));
      }
    }
    createThumbnailBtn(containers) {
      if (!containers.length) return;
      containers.forEach((el) => {
        const idMathch = new RegExp("(?<=\\/post\\/show\\/)\\d+|(?<=\\/post\\/browse#)\\d+").exec(el.href);
        if (!idMathch) return;
        const id = idMathch[0];
        const oldBtn = el.querySelector(ThumbnailButton.tagNameLowerCase);
        if (oldBtn) {
          if (oldBtn.dataset.id === id) return;
          oldBtn.remove();
        } else {
          if (el.href.includes("/post/show")) {
            el.style.height = "fit-content";
            if (!el.classList.contains("thumb")) {
              const image = el.querySelector("img");
              if (image.src.includes("blacklisted-preview.png")) return;
              image.onload = () => {
                if (image.src.includes("blacklisted-preview.png") && image.nextElementSibling) {
                  image.nextElementSibling.remove();
                }
              };
              el.style.marginBottom = "1em";
              image.style.marginBottom = "0px";
            }
          }
          el.parentElement.style.display = "flex";
          el.style.position = "relative";
        }
        el.appendChild(
          new ThumbnailButton({
            id,
            onClick: downloadArtwork
          })
        );
      });
    }
    createArtworkBtn(id) {
      const image = document.querySelector("#image");
      const btnContainer = image.closest("div");
      btnContainer.style.position = "relative";
      btnContainer.style.width = "max-content";
      btnContainer.appendChild(
        new ArtworkButton({
          id,
          site: "yande",
          onClick: downloadArtwork
        })
      );
    }
    createScrollerBtn() {
      const scrollerList = document.querySelector("ul.post-browser-posts");
      if (!scrollerList) return;
      const ob = new MutationObserver((records) => {
        const containers = [];
        records.forEach((record) => {
          if (!record.addedNodes.length) return;
          record.addedNodes.forEach((node) => {
            if (!(node instanceof HTMLElement)) return;
            const thumbs = node.querySelectorAll("a.thumb");
            if (thumbs.length) containers.push(...thumbs);
          });
        });
        this.createThumbnailBtn(containers);
      });
      ob.observe(scrollerList, { subtree: true, childList: true });
    }
    createImageBrowseBtn() {
      const postId = document.querySelector("span.post-id");
      if (!postId) return;
      function createBtn() {
        var _a;
        (_a = document.querySelector(
          `${ThumbnailButton.tagNameLowerCase}[data-type="${ThumbnailBtnType.YandeBrowse}"]`
        )) == null ? void 0 : _a.remove();
        const id = postId.textContent;
        if (!id) return;
        document.body.appendChild(
          new ThumbnailButton({
            id,
            type: ThumbnailBtnType.YandeBrowse,
            onClick: downloadArtwork
          })
        );
      }
      createBtn();
      new MutationObserver(createBtn).observe(postId, { childList: true });
    }
    getCustomConfig() {
      return {
        folderPattern: "yande/{artist}",
        filenamePattern: "{id}_{artist}_{character}"
      };
    }
    getFilenameTemplate() {
      return ["{artist}", "{character}", "{id}", "{date}"];
    }
  }
  class ATFbooru extends Danbooru {
    constructor() {
      super();
      __publicField(this, "commentaryAccessible");
      this.useBatchDownload = this.useBatchDownload().overwrite({
        avatar: "/favicon.svg",
        parseMetaByArtworkId: async (id) => {
          return await danbooruParser.parse(id, {
            type: await (this.commentaryAccessible ?? (this.commentaryAccessible = this.isCommentaryAccessible())) ? "api" : "html"
          });
        }
      });
    }
    static get hostname() {
      return "booru.allthefallen.moe";
    }
    getCustomConfig() {
      return {
        folderPattern: "ATFbooru/{artist}",
        filenamePattern: "{id}_{artist}_{character}"
      };
    }
    // check if user has permission to access artist commentary.
    async isCommentaryAccessible() {
      try {
        await danbooruApi.getArtistCommentary("703816");
      } catch (error) {
        if (!(error instanceof RequestError)) return false;
      }
      return true;
    }
    async downloadArtwork(btn2) {
      downloader.dirHandleCheck();
      const id = btn2.dataset.id;
      const mediaMeta = await danbooruParser.parse(id, {
        type: await (this.commentaryAccessible ?? (this.commentaryAccessible = this.isCommentaryAccessible())) ? "api" : "html"
      });
      const downloadConfigs = new DanbooruDownloadConfig(mediaMeta).getDownloadConfig(btn2);
      this.config.get("addBookmark") && addBookmark$1(id);
      await downloader.download(downloadConfigs);
      const { tags, artist, title, comment } = mediaMeta;
      historyDb.add({
        pid: Number(id),
        user: artist,
        title,
        comment,
        tags
      });
    }
  }
  function getSiteInjector() {
    const sitesAdapter = [Pixiv, Danbooru, Rule34, Yande, ATFbooru];
    for (let i = 0; i < sitesAdapter.length; i++) {
      if (location.hostname === sitesAdapter[i].hostname) {
        return sitesAdapter[i];
      }
    }
  }
  const siteInject = getSiteInjector();
  siteInject && new siteInject().inject();

})(Dexie, dayjs, JSZip, GIF);