Download ui/web/src/components/DownloadConfirmDialog.svelte from localailb/assistant: direct link, hf CLI and curl.
- Browser
- Download file 4.07 kB
-
https://huggingface.co/spaces/localailb/assistant/resolve/main/ui/web/src/components/DownloadConfirmDialog.svelte
- Command line
-
hf download hf://spaces/localailb/assistant/ui/web/src/components/DownloadConfirmDialog.svelte
-
curl -L -o DownloadConfirmDialog.svelte https://huggingface.co/spaces/localailb/assistant/resolve/main/ui/web/src/components/DownloadConfirmDialog.svelte
4.07 kB
| <script> | |
| import { t } from "../lib/stores.svelte.js"; | |
| import "./DownloadConfirmDialog.css"; | |
| /** | |
| * Lightweight download confirmation popup β asks "Are you sure you want | |
| * to download X?" before kicking off a direct download (components like | |
| * Poppler/Playwright or any AI model across tabs). | |
| * | |
| * Props: | |
| * component β the download component id (e.g. "poppler", "playwright") | |
| * model β model id or model object { id, label, size } | |
| * onclose β called when the user cancels or dismisses | |
| * onconfirm β called with component or model when confirmed | |
| */ | |
| let { component, model, onclose, onconfirm } = $props(); | |
| /** Map component id to its i18n label key. */ | |
| const LABEL_MAP = { | |
| poppler: "btn_dl_poppler", | |
| playwright: "btn_dl_playwright", | |
| }; | |
| let rootEl; | |
| let boxEl = $state(null); | |
| // ββ Draggable ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| let dragOffsetX = 0; | |
| let dragOffsetY = 0; | |
| let posX = $state(null); | |
| let posY = $state(null); | |
| let dragging = $state(false); | |
| function onDragStart(e) { | |
| if (!boxEl) return; | |
| if (e.button !== 0) return; | |
| e.preventDefault(); | |
| const rect = boxEl.getBoundingClientRect(); | |
| dragOffsetX = e.clientX - rect.left; | |
| dragOffsetY = e.clientY - rect.top; | |
| if (posX === null) posX = rect.left; | |
| if (posY === null) posY = rect.top; | |
| dragging = true; | |
| } | |
| function onDragMove(e) { | |
| if (!dragging) return; | |
| const w = window.innerWidth; | |
| const h = window.innerHeight; | |
| let x = e.clientX - dragOffsetX; | |
| let y = e.clientY - dragOffsetY; | |
| const bw = boxEl ? boxEl.offsetWidth : 400; | |
| const bh = boxEl ? boxEl.offsetHeight : 250; | |
| x = Math.max(0, Math.min(x, w - bw)); | |
| y = Math.max(0, Math.min(y, h - bh)); | |
| posX = x; | |
| posY = y; | |
| } | |
| function onDragEnd() { | |
| dragging = false; | |
| } | |
| function close() { | |
| onclose?.(); | |
| } | |
| function confirm() { | |
| onconfirm?.(component || model); | |
| } | |
| // Close on Escape | |
| function handleKeydown(e) { | |
| if (e.key === "Escape") { | |
| e.preventDefault(); | |
| close(); | |
| } | |
| } | |
| const isModel = $derived(!!model); | |
| const modelName = $derived( | |
| typeof model === "object" ? (model.label || model.id || "") : (model || "") | |
| ); | |
| const modelSize = $derived( | |
| typeof model === "object" && model.size ? `(~${model.size} GB)` : "" | |
| ); | |
| </script> | |
| <!-- svelte-ignore a11y_no_static_element_interactions --> | |
| <svelte:window | |
| onkeydown={handleKeydown} | |
| onmousemove={onDragMove} | |
| onmouseup={onDragEnd} | |
| /> | |
| <div | |
| class="dlcfm-overlay" | |
| role="presentation" | |
| onmousedown={(e) => { | |
| if (e.target === e.currentTarget) close(); | |
| }} | |
| > | |
| <div | |
| class="dlcfm-box" | |
| class:dragging | |
| role="dialog" | |
| aria-modal="true" | |
| bind:this={boxEl} | |
| style="{posX !== null ? `left:${posX}px;top:${posY}px;transform:none` : ''}" | |
| > | |
| <!-- svelte-ignore a11y_no_static_element_interactions --> | |
| <div | |
| class="dlcfm-title dlcfm-drag-handle" | |
| role="none" | |
| onmousedown={onDragStart} | |
| > | |
| {isModel ? t("model_dl_confirm_title") : t("dl_confirm_title")} | |
| </div> | |
| <div class="dlcfm-body"> | |
| {#if isModel} | |
| {@html t("model_dl_confirm_body") | |
| .replace("{model}", `<b>${modelName}</b>`) | |
| .replace("{size}", modelSize ? `<b>${modelSize}</b>` : "")} | |
| {:else} | |
| {@html t("dl_confirm_body") | |
| .replace("{component}", `<b>${t(LABEL_MAP[component] || component)}</b>`) | |
| .replace("{component}", `<b>${t(LABEL_MAP[component] || component)}</b>`)} | |
| {/if} | |
| </div> | |
| <div class="dlcfm-actions"> | |
| <button | |
| type="button" | |
| class="dlcfm-cancel" | |
| onclick={close} | |
| data-tooltip={t("dl_confirm_cancel")}>{t("dl_confirm_cancel")}</button | |
| > | |
| <button | |
| type="button" | |
| class="dlcfm-confirm" | |
| onclick={confirm} | |
| data-tooltip={t("dl_confirm_ok")}>{t("dl_confirm_ok")}</button | |
| > | |
| </div> | |
| </div> | |
| </div> | |