Spaces:
Paused

File size: 3,527 Bytes
bc9f3e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<script>
  import { onMount } from "svelte";
  import { t } from "../lib/stores.svelte.js";
  import { postJSON } from "../lib/api.js";
  import "./FirstRunDialog.css";

  /** Close callback fired when the user dismisses the dialog (clicking OK,
   * Escape, or the dimmed backdrop). */
  let { onclose } = $props();

  let rootEl;
  let boxEl = $state(null);

  // ── Draggable ──────────────────────────────────────────────────
  let dragOffsetX = 0;
  let dragOffsetY = 0;
  /** Dynamic left/top in px (null = CSS-centered default). */
  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 : 440;
    const bh = boxEl ? boxEl.offsetHeight : 300;
    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 dismiss() {
    // Persist that the onboarding was seen β€” the popup never blocks the
    // close (a failed save must not trap the user in the dialog).
    postJSON("/api/first-run/dismiss", {}).catch(() => {});
    onclose?.();
  }

  onMount(() => {
    // Focus the OK button so Enter dismisses immediately (like the app's
    // other themed dialogs).
    rootEl?.querySelector(".firstrun-ok")?.focus();
    const onKey = (e) => {
      if (e.key === "Escape") {
        e.preventDefault();
        dismiss();
      }
    };
    document.addEventListener("keydown", onKey, true);
    return () => document.removeEventListener("keydown", onKey, true);
  });
</script>

<!-- svelte-ignore a11y_no_static_element_interactions -->
<svelte:window
  onmousemove={onDragMove}
  onmouseup={onDragEnd}
/>

<div
  class="firstrun-overlay"
  role="presentation"
  bind:this={rootEl}
  onmousedown={(e) => {
    if (e.target === rootEl) dismiss();
  }}
>
  <div
    class="firstrun-box"
    class:dragging
    role="dialog"
    aria-modal="true"
    aria-labelledby="firstrun-title"
    bind:this={boxEl}
    style="{posX !== null ? `left:${posX}px;top:${posY}px;transform:none` : ''}"
  >
    <!-- svelte-ignore a11y_no_static_element_interactions -->
    <div
      class="firstrun-title firstrun-drag-handle"
      id="firstrun-title"
      role="none"
      onmousedown={onDragStart}
    >{t("firstrun_title")}</div>
    <div class="firstrun-lines">
      <div class="firstrun-line">{t("firstrun_install_pytorch")}</div>
      <div class="firstrun-line">{t("firstrun_install_llama")}</div>
      <div class="firstrun-line">{t("firstrun_set_hf")}</div>
      <div class="firstrun-line firstrun-tip">{t("firstrun_gguf_tip")}</div>
    </div>
    <div class="firstrun-actions">
      <button
        type="button"
        class="firstrun-ok"
        data-tooltip={t("firstrun_ok")}
        onclick={dismiss}
      >
        {t("firstrun_ok")}
      </button>
    </div>
  </div>
</div>