dynaura 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +422 -2
- package/dist/chunk-FNLIY6GQ.js +558 -0
- package/dist/index.cjs +614 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +39 -0
- package/dist/styles.css +161 -0
- package/dist/svelte.cjs +590 -0
- package/dist/svelte.d.cts +10 -0
- package/dist/svelte.d.ts +10 -0
- package/dist/svelte.js +15 -0
- package/dist/vanilla.cjs +584 -0
- package/dist/vanilla.d.cts +86 -0
- package/dist/vanilla.d.ts +86 -0
- package/dist/vanilla.js +9 -0
- package/dist/vue.cjs +608 -0
- package/dist/vue.d.cts +43 -0
- package/dist/vue.d.ts +43 -0
- package/dist/vue.js +33 -0
- package/package.json +131 -4
package/dist/svelte.cjs
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/svelte.ts
|
|
22
|
+
var svelte_exports = {};
|
|
23
|
+
__export(svelte_exports, {
|
|
24
|
+
dynaura: () => dynaura,
|
|
25
|
+
toaster: () => toaster
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(svelte_exports);
|
|
28
|
+
|
|
29
|
+
// src/confetti.ts
|
|
30
|
+
function burst(x, y, color) {
|
|
31
|
+
const c = document.createElement("canvas");
|
|
32
|
+
const dpr = window.devicePixelRatio || 1;
|
|
33
|
+
const W = innerWidth, H = innerHeight;
|
|
34
|
+
c.width = W * dpr;
|
|
35
|
+
c.height = H * dpr;
|
|
36
|
+
c.style.cssText = `position:fixed;top:0;left:0;width:${W}px;height:${H}px;pointer-events:none;z-index:2147483647`;
|
|
37
|
+
document.body.append(c);
|
|
38
|
+
const ctx = c.getContext("2d");
|
|
39
|
+
if (!ctx) return c.remove();
|
|
40
|
+
ctx.scale(dpr, dpr);
|
|
41
|
+
const colors = [color, "#fff", color, "#ffd60a", "#0a84ff"];
|
|
42
|
+
const ps = Array.from({ length: 36 }, () => {
|
|
43
|
+
const a = Math.random() * Math.PI * 2, s = 3 + Math.random() * 6;
|
|
44
|
+
return { x, y, vx: Math.cos(a) * s, vy: Math.sin(a) * s - 3, r: 2 + Math.random() * 3, rot: Math.random() * 6, c: colors[Math.random() * colors.length | 0] };
|
|
45
|
+
});
|
|
46
|
+
const t0 = performance.now();
|
|
47
|
+
const frame = (t) => {
|
|
48
|
+
const k = (t - t0) / 1e3;
|
|
49
|
+
if (k >= 1) return c.remove();
|
|
50
|
+
ctx.clearRect(0, 0, W, H);
|
|
51
|
+
for (const p of ps) {
|
|
52
|
+
p.x += p.vx;
|
|
53
|
+
p.y += p.vy;
|
|
54
|
+
p.vy += 0.28;
|
|
55
|
+
p.vx *= 0.985;
|
|
56
|
+
p.rot += 0.2;
|
|
57
|
+
ctx.globalAlpha = 1 - k * k;
|
|
58
|
+
ctx.fillStyle = p.c;
|
|
59
|
+
ctx.save();
|
|
60
|
+
ctx.translate(p.x, p.y);
|
|
61
|
+
ctx.rotate(p.rot);
|
|
62
|
+
ctx.fillRect(-p.r, -p.r / 2, p.r * 2, p.r);
|
|
63
|
+
ctx.restore();
|
|
64
|
+
}
|
|
65
|
+
requestAnimationFrame(frame);
|
|
66
|
+
};
|
|
67
|
+
requestAnimationFrame(frame);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/store.ts
|
|
71
|
+
var g = globalThis;
|
|
72
|
+
var _a;
|
|
73
|
+
var S = (_a = g.__dynaura) != null ? _a : g.__dynaura = { current: null, queue: [], n: 0, subs: /* @__PURE__ */ new Set(), useQueue: false };
|
|
74
|
+
var set = (t) => {
|
|
75
|
+
S.current = t;
|
|
76
|
+
S.subs.forEach((f) => f());
|
|
77
|
+
};
|
|
78
|
+
var subscribe = (f) => {
|
|
79
|
+
S.subs.add(f);
|
|
80
|
+
return () => {
|
|
81
|
+
S.subs.delete(f);
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
var getCurrent = () => S.current;
|
|
85
|
+
var setQueue = (v) => {
|
|
86
|
+
S.useQueue = v;
|
|
87
|
+
};
|
|
88
|
+
var norm = (o) => typeof o === "string" ? { title: o } : o;
|
|
89
|
+
var make = (type) => (o) => {
|
|
90
|
+
var _a2;
|
|
91
|
+
const id = String(++S.n);
|
|
92
|
+
const sticky = type === "loading" || type === "live";
|
|
93
|
+
const t = { duration: sticky ? null : 4e3, ...type === "live" ? { kind: "timer" } : {}, ...norm(o), id, type };
|
|
94
|
+
if (S.current && ((_a2 = t.queue) != null ? _a2 : S.useQueue)) S.queue.push(t);
|
|
95
|
+
else set(t);
|
|
96
|
+
return id;
|
|
97
|
+
};
|
|
98
|
+
var update = (id, patch) => {
|
|
99
|
+
var _a2;
|
|
100
|
+
if (((_a2 = S.current) == null ? void 0 : _a2.id) === id) return set({ ...S.current, ...patch });
|
|
101
|
+
const i = S.queue.findIndex((t) => t.id === id);
|
|
102
|
+
if (i >= 0) S.queue[i] = { ...S.queue[i], ...patch };
|
|
103
|
+
};
|
|
104
|
+
var pick = (r, v) => norm(typeof r === "function" ? r(v) : r);
|
|
105
|
+
var dynaura = {
|
|
106
|
+
success: make("success"),
|
|
107
|
+
error: make("error"),
|
|
108
|
+
warning: make("warning"),
|
|
109
|
+
info: make("info"),
|
|
110
|
+
loading: make("loading"),
|
|
111
|
+
/** Live activity: sticky island with a running timer (default) or waveform. */
|
|
112
|
+
live: make("live"),
|
|
113
|
+
update,
|
|
114
|
+
/** dismiss the current toast (next queued one shows) or a specific id */
|
|
115
|
+
dismiss: (id) => {
|
|
116
|
+
var _a2, _b;
|
|
117
|
+
if (id && ((_a2 = S.current) == null ? void 0 : _a2.id) !== id) {
|
|
118
|
+
S.queue = S.queue.filter((t) => t.id !== id);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
set((_b = S.queue.shift()) != null ? _b : null);
|
|
122
|
+
},
|
|
123
|
+
clear: () => {
|
|
124
|
+
S.queue = [];
|
|
125
|
+
set(null);
|
|
126
|
+
},
|
|
127
|
+
promise(p, o) {
|
|
128
|
+
const id = make("loading")(o.loading);
|
|
129
|
+
p.then(
|
|
130
|
+
(v) => update(id, { duration: 4e3, ...pick(o.success, v), type: "success" }),
|
|
131
|
+
(e) => update(id, { duration: 4e3, ...pick(o.error, e), type: "error" })
|
|
132
|
+
);
|
|
133
|
+
return p;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/core.ts
|
|
138
|
+
var VAR = {
|
|
139
|
+
background: "bg",
|
|
140
|
+
foreground: "fg",
|
|
141
|
+
muted: "muted",
|
|
142
|
+
ring: "ring",
|
|
143
|
+
button: "btn",
|
|
144
|
+
success: "success",
|
|
145
|
+
error: "error",
|
|
146
|
+
warning: "warning",
|
|
147
|
+
info: "info",
|
|
148
|
+
loading: "loading",
|
|
149
|
+
live: "live"
|
|
150
|
+
};
|
|
151
|
+
var svg = (d) => `<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round">${d}</svg>`;
|
|
152
|
+
var ICON = {
|
|
153
|
+
success: svg('<path class="dynaura-draw" d="M5 12.5l4.5 4.5L19 7.5"/>'),
|
|
154
|
+
error: svg('<path class="dynaura-draw" d="M7 7l10 10M17 7L7 17"/>'),
|
|
155
|
+
warning: svg('<path class="dynaura-draw" d="M12 6v7M12 17.5v.01"/>'),
|
|
156
|
+
info: svg('<path class="dynaura-draw" d="M12 11v6M12 7.5v.01"/>'),
|
|
157
|
+
loading: svg('<circle class="dynaura-spin" cx="12" cy="12" r="8" stroke-dasharray="30 50"/>')
|
|
158
|
+
};
|
|
159
|
+
var DOT = '<span class="dynaura-dot"></span>';
|
|
160
|
+
var WAVE = '<span class="dynaura-wave"><i></i><i></i><i></i><i></i></span>';
|
|
161
|
+
var VIBRATE = { success: [12], error: [24, 40, 24], warning: [30], info: [8], loading: [], live: [8] };
|
|
162
|
+
var f2 = (n) => +n.toFixed(2);
|
|
163
|
+
function outline(w, h2, cw, ch, hx) {
|
|
164
|
+
if (h2 <= ch + 1 || w <= cw + 1) {
|
|
165
|
+
const q = f2(Math.min(h2 / 2, w / 2, 32));
|
|
166
|
+
return `M${q} 0H${f2(w - q)}A${q} ${q} 0 0 1 ${f2(w)} ${q}V${f2(h2 - q)}A${q} ${q} 0 0 1 ${f2(w - q)} ${f2(h2)}H${q}A${q} ${q} 0 0 1 0 ${f2(h2 - q)}V${q}A${q} ${q} 0 0 1 ${q} 0Z`;
|
|
167
|
+
}
|
|
168
|
+
const r = f2(Math.min(ch / 2, 32));
|
|
169
|
+
const b = f2(Math.max(0, Math.min(28, (h2 - ch) / 2, (w - cw) / 2)));
|
|
170
|
+
const f = f2(Math.min(16, b));
|
|
171
|
+
const x0 = f2(hx), x1 = f2(hx + cw);
|
|
172
|
+
const flushL = hx < 1, flushR = hx + cw > w - 1;
|
|
173
|
+
let d = `M${f2(x0 + r)} 0H${f2(x1 - r)}A${r} ${r} 0 0 1 ${x1} ${r}`;
|
|
174
|
+
d += flushR ? `V${f2(h2 - b)}` : `V${f2(ch - f)}A${f} ${f} 0 0 0 ${f2(x1 + f)} ${f2(ch)}H${f2(w - b)}A${b} ${b} 0 0 1 ${f2(w)} ${f2(ch + b)}V${f2(h2 - b)}`;
|
|
175
|
+
d += `A${b} ${b} 0 0 1 ${f2(w - b)} ${f2(h2)}H${b}A${b} ${b} 0 0 1 0 ${f2(h2 - b)}`;
|
|
176
|
+
d += flushL ? `V${r}` : `V${f2(ch + b)}A${b} ${b} 0 0 1 ${b} ${f2(ch)}H${f2(x0 - f)}A${f} ${f} 0 0 0 ${x0} ${f2(ch - f)}V${r}`;
|
|
177
|
+
return d + `A${r} ${r} 0 0 1 ${f2(x0 + r)} 0Z`;
|
|
178
|
+
}
|
|
179
|
+
var h = (tag, cls, parent) => {
|
|
180
|
+
const e = document.createElement(tag);
|
|
181
|
+
e.className = cls;
|
|
182
|
+
parent == null ? void 0 : parent.append(e);
|
|
183
|
+
return e;
|
|
184
|
+
};
|
|
185
|
+
var restart = (e) => {
|
|
186
|
+
e.style.animation = "none";
|
|
187
|
+
void e.offsetWidth;
|
|
188
|
+
e.style.animation = "";
|
|
189
|
+
};
|
|
190
|
+
function roll(e, s) {
|
|
191
|
+
const sig = s.replace(/\d/g, "0");
|
|
192
|
+
if (e.dataset.sig !== sig) {
|
|
193
|
+
e.dataset.sig = sig;
|
|
194
|
+
e.replaceChildren();
|
|
195
|
+
e.setAttribute("role", "img");
|
|
196
|
+
for (const ch of s) {
|
|
197
|
+
if (/\d/.test(ch)) {
|
|
198
|
+
const d = h("span", "dynaura-digit", e);
|
|
199
|
+
d.setAttribute("aria-hidden", "true");
|
|
200
|
+
h("span", "dynaura-strip", d).innerHTML = "0123456789".replace(/\d/g, "<i>$&</i>");
|
|
201
|
+
} else h("span", "dynaura-char", e).textContent = ch;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
e.setAttribute("aria-label", s);
|
|
205
|
+
[...s].forEach((ch, i) => {
|
|
206
|
+
if (/\d/.test(ch)) e.children[i].style.setProperty("--d", ch);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function createToaster(initial = {}) {
|
|
210
|
+
const o = { position: "top", offset: 12, theme: "dark", timer: true, haptics: true, queue: false };
|
|
211
|
+
const merge = (n) => {
|
|
212
|
+
for (const k in n) if (n[k] !== void 0) o[k] = n[k];
|
|
213
|
+
};
|
|
214
|
+
merge(initial);
|
|
215
|
+
const root = h("div", "dynaura-root");
|
|
216
|
+
const drag = h("div", "dynaura-drag", root);
|
|
217
|
+
const island = h("div", "dynaura-island", drag);
|
|
218
|
+
island.setAttribute("role", "status");
|
|
219
|
+
island.setAttribute("aria-live", "polite");
|
|
220
|
+
const inner = h("div", "dynaura-inner", island);
|
|
221
|
+
const row = h("div", "dynaura-row", inner);
|
|
222
|
+
const badge = h("span", "dynaura-badge", row);
|
|
223
|
+
const title = h("span", "dynaura-title", row);
|
|
224
|
+
const trail = h("span", "dynaura-trailing", row);
|
|
225
|
+
const body = h("div", "dynaura-body", inner);
|
|
226
|
+
const desc = h("div", "dynaura-desc", body);
|
|
227
|
+
const btn = h("button", "dynaura-button", body);
|
|
228
|
+
const bar = h("div", "dynaura-bar", island);
|
|
229
|
+
island.hidden = true;
|
|
230
|
+
island.dataset.expanded = "false";
|
|
231
|
+
island.dataset.paused = "false";
|
|
232
|
+
document.body.append(root);
|
|
233
|
+
let t = null;
|
|
234
|
+
let expanded = false, hovered = false, pinned = false, dragging = false, ready = false;
|
|
235
|
+
let hideT, expandT, collapseT, dismissT, liveI, lp;
|
|
236
|
+
let remaining = 0, startedAt = 0, liveStart = 0;
|
|
237
|
+
let sz = { cw: 0, ch: 0, ew: 0, eh: 0 };
|
|
238
|
+
let applied = [];
|
|
239
|
+
const hosts = /* @__PURE__ */ new Map();
|
|
240
|
+
const dir = () => o.position.startsWith("bottom") ? 1 : -1;
|
|
241
|
+
const hasBody = () => !!t && (t.description != null && typeof t.description !== "boolean" || !!t.button);
|
|
242
|
+
const paused = () => hovered || pinned || dragging;
|
|
243
|
+
function put(slot, c) {
|
|
244
|
+
var _a2;
|
|
245
|
+
const old = hosts.get(slot);
|
|
246
|
+
if (old) {
|
|
247
|
+
(_a2 = o.render) == null ? void 0 : _a2.call(o, old, null);
|
|
248
|
+
hosts.delete(slot);
|
|
249
|
+
}
|
|
250
|
+
slot.replaceChildren();
|
|
251
|
+
if (c == null || typeof c === "boolean") return;
|
|
252
|
+
if (typeof c === "string" || typeof c === "number") slot.textContent = String(c);
|
|
253
|
+
else if (c instanceof Node) slot.append(c);
|
|
254
|
+
else if (o.render) {
|
|
255
|
+
const host = h("span", "dynaura-host", slot);
|
|
256
|
+
hosts.set(slot, host);
|
|
257
|
+
o.render(host, c);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
let raf = 0;
|
|
261
|
+
const isCard = () => (t == null ? void 0 : t.variant) === "card";
|
|
262
|
+
function shape() {
|
|
263
|
+
if (!isCard()) {
|
|
264
|
+
island.style.clipPath = "";
|
|
265
|
+
row.style.transform = "";
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const cs = getComputedStyle(island);
|
|
269
|
+
const w = parseFloat(cs.width), hh = parseFloat(cs.height);
|
|
270
|
+
if (!isFinite(w) || !isFinite(hh) || w <= 0) return;
|
|
271
|
+
const x = o.position.split("-")[1];
|
|
272
|
+
const hx = x === "left" ? 0 : x === "right" ? Math.max(0, w - sz.cw) : Math.max(0, (w - sz.cw) / 2);
|
|
273
|
+
row.style.transform = `translateX(${f2(hx)}px)`;
|
|
274
|
+
island.style.clipPath = `path('${outline(w, hh, sz.cw, sz.ch, hx)}')`;
|
|
275
|
+
}
|
|
276
|
+
function shapeLoop() {
|
|
277
|
+
cancelAnimationFrame(raf);
|
|
278
|
+
const end = performance.now() + 1300;
|
|
279
|
+
const f = () => {
|
|
280
|
+
shape();
|
|
281
|
+
if (performance.now() < end) raf = requestAnimationFrame(f);
|
|
282
|
+
};
|
|
283
|
+
f();
|
|
284
|
+
}
|
|
285
|
+
function size() {
|
|
286
|
+
if (!sz.cw) return;
|
|
287
|
+
const w = expanded ? sz.ew : sz.cw, hh = expanded ? sz.eh : sz.ch;
|
|
288
|
+
island.style.width = w + "px";
|
|
289
|
+
island.style.height = hh + "px";
|
|
290
|
+
island.style.borderRadius = isCard() ? "0" : Math.min(hh / 2, 32) + "px";
|
|
291
|
+
if (isCard()) shapeLoop();
|
|
292
|
+
else island.style.clipPath = "";
|
|
293
|
+
}
|
|
294
|
+
function measure() {
|
|
295
|
+
if (island.hidden) return;
|
|
296
|
+
sz = { cw: row.offsetWidth, ch: row.offsetHeight, ew: inner.offsetWidth, eh: inner.offsetHeight };
|
|
297
|
+
size();
|
|
298
|
+
if (!ready && sz.cw) requestAnimationFrame(() => {
|
|
299
|
+
ready = true;
|
|
300
|
+
island.dataset.ready = "true";
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const ro = new ResizeObserver(measure);
|
|
304
|
+
ro.observe(row);
|
|
305
|
+
ro.observe(inner);
|
|
306
|
+
function setExpanded(v) {
|
|
307
|
+
v = v && hasBody();
|
|
308
|
+
if (v === expanded) return;
|
|
309
|
+
expanded = v;
|
|
310
|
+
island.dataset.expanded = String(v);
|
|
311
|
+
size();
|
|
312
|
+
}
|
|
313
|
+
function clear() {
|
|
314
|
+
if (startedAt) {
|
|
315
|
+
remaining -= Date.now() - startedAt;
|
|
316
|
+
startedAt = 0;
|
|
317
|
+
}
|
|
318
|
+
clearTimeout(collapseT);
|
|
319
|
+
clearTimeout(dismissT);
|
|
320
|
+
}
|
|
321
|
+
function arm() {
|
|
322
|
+
clear();
|
|
323
|
+
if (!t || t.duration == null || paused()) return;
|
|
324
|
+
const id = t.id;
|
|
325
|
+
startedAt = Date.now();
|
|
326
|
+
collapseT = setTimeout(() => {
|
|
327
|
+
if (!pinned) setExpanded(false);
|
|
328
|
+
}, Math.max(0, remaining - 500));
|
|
329
|
+
dismissT = setTimeout(() => dynaura.dismiss(id), remaining);
|
|
330
|
+
}
|
|
331
|
+
function sync() {
|
|
332
|
+
island.dataset.paused = String(paused());
|
|
333
|
+
if (paused()) {
|
|
334
|
+
clear();
|
|
335
|
+
if (hovered || pinned) setExpanded(true);
|
|
336
|
+
} else arm();
|
|
337
|
+
}
|
|
338
|
+
function tick() {
|
|
339
|
+
var _a2;
|
|
340
|
+
if (!t || t.trailing != null) return;
|
|
341
|
+
if (t.progress != null) roll(trail, Math.round(t.progress * 100) + "%");
|
|
342
|
+
else if (t.type === "live" && ((_a2 = t.kind) != null ? _a2 : "timer") === "timer") {
|
|
343
|
+
const s = Math.floor((Date.now() - liveStart) / 1e3);
|
|
344
|
+
roll(trail, `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const hasTrail = (n) => {
|
|
348
|
+
var _a2;
|
|
349
|
+
return n.trailing != null || n.progress != null || n.type === "live" && ((_a2 = n.kind) != null ? _a2 : "timer") === "timer";
|
|
350
|
+
};
|
|
351
|
+
function apply(n, p) {
|
|
352
|
+
var _a2, _b, _c;
|
|
353
|
+
const ch = (k) => !p || n[k] !== p[k];
|
|
354
|
+
island.dataset.type = n.type;
|
|
355
|
+
island.dataset.variant = drag.dataset.variant = (_a2 = n.variant) != null ? _a2 : "default";
|
|
356
|
+
if (ch("type") || ch("icon") || ch("kind")) {
|
|
357
|
+
put(badge, void 0);
|
|
358
|
+
if (n.icon != null) put(badge, n.icon);
|
|
359
|
+
else badge.innerHTML = n.type === "live" ? ((_b = n.kind) != null ? _b : "timer") === "wave" ? WAVE : DOT : ICON[n.type];
|
|
360
|
+
restart(badge);
|
|
361
|
+
}
|
|
362
|
+
if (ch("title")) {
|
|
363
|
+
title.textContent = n.title;
|
|
364
|
+
restart(title);
|
|
365
|
+
}
|
|
366
|
+
if (ch("trailing") || ch("progress") || ch("type") || ch("kind")) {
|
|
367
|
+
trail.hidden = !hasTrail(n);
|
|
368
|
+
if (n.trailing != null) {
|
|
369
|
+
delete trail.dataset.sig;
|
|
370
|
+
trail.removeAttribute("aria-label");
|
|
371
|
+
put(trail, n.trailing);
|
|
372
|
+
} else if (!hasTrail(n)) {
|
|
373
|
+
delete trail.dataset.sig;
|
|
374
|
+
put(trail, void 0);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (ch("description")) put(desc, n.description);
|
|
378
|
+
desc.hidden = n.description == null || typeof n.description === "boolean";
|
|
379
|
+
btn.hidden = !n.button;
|
|
380
|
+
if (n.button) btn.textContent = n.button.title;
|
|
381
|
+
body.hidden = !(n.description != null && typeof n.description !== "boolean") && !n.button;
|
|
382
|
+
bar.dataset.mode = n.progress != null ? "value" : n.duration != null ? "time" : "none";
|
|
383
|
+
bar.style.setProperty("--p", String((_c = n.progress) != null ? _c : 0));
|
|
384
|
+
}
|
|
385
|
+
function feedback(n) {
|
|
386
|
+
var _a2, _b;
|
|
387
|
+
const active = (_b = (_a2 = navigator.userActivation) == null ? void 0 : _a2.hasBeenActive) != null ? _b : true;
|
|
388
|
+
if (o.haptics && typeof navigator !== "undefined" && navigator.vibrate && active && VIBRATE[n.type].length) navigator.vibrate(VIBRATE[n.type]);
|
|
389
|
+
if (n.confetti && !matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
390
|
+
requestAnimationFrame(() => {
|
|
391
|
+
const r = island.getBoundingClientRect();
|
|
392
|
+
burst(r.left + r.width / 2, r.top + r.height / 2, getComputedStyle(island).getPropertyValue("--state").trim() || "#30d158");
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const onlyProgress = (p, n) => p.progress == null === (n.progress == null) && [.../* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(p)])].every((k) => k === "progress" || n[k] === p[k]);
|
|
397
|
+
function render() {
|
|
398
|
+
var _a2, _b, _c;
|
|
399
|
+
const n = getCurrent();
|
|
400
|
+
const p = t;
|
|
401
|
+
if (!n) {
|
|
402
|
+
if (p) leave();
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const same = !!p && p.id === n.id;
|
|
406
|
+
if (same && onlyProgress(p, n)) {
|
|
407
|
+
t = n;
|
|
408
|
+
bar.style.setProperty("--p", String((_a2 = n.progress) != null ? _a2 : 0));
|
|
409
|
+
tick();
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
t = n;
|
|
413
|
+
clearTimeout(hideT);
|
|
414
|
+
if (island.hidden) {
|
|
415
|
+
island.hidden = false;
|
|
416
|
+
drag.style.transform = "";
|
|
417
|
+
drag.style.opacity = "";
|
|
418
|
+
restart(island);
|
|
419
|
+
}
|
|
420
|
+
island.dataset.open = "true";
|
|
421
|
+
if (!same) {
|
|
422
|
+
liveStart = Date.now();
|
|
423
|
+
pinned = false;
|
|
424
|
+
}
|
|
425
|
+
apply(n, same ? p : null);
|
|
426
|
+
measure();
|
|
427
|
+
if (!same || n.type !== p.type) feedback(n);
|
|
428
|
+
clearInterval(liveI);
|
|
429
|
+
if (n.type === "live") liveI = setInterval(tick, 1e3);
|
|
430
|
+
tick();
|
|
431
|
+
clear();
|
|
432
|
+
startedAt = 0;
|
|
433
|
+
remaining = (_b = n.duration) != null ? _b : 0;
|
|
434
|
+
restart(bar);
|
|
435
|
+
bar.style.animationDuration = ((_c = n.duration) != null ? _c : 0) + "ms";
|
|
436
|
+
if (!pinned) setExpanded(false);
|
|
437
|
+
clearTimeout(expandT);
|
|
438
|
+
if (hasBody()) expandT = setTimeout(() => setExpanded(true), 450);
|
|
439
|
+
sync();
|
|
440
|
+
}
|
|
441
|
+
function leave() {
|
|
442
|
+
clear();
|
|
443
|
+
startedAt = 0;
|
|
444
|
+
clearTimeout(expandT);
|
|
445
|
+
clearInterval(liveI);
|
|
446
|
+
hovered = pinned = dragging = false;
|
|
447
|
+
t = null;
|
|
448
|
+
island.dataset.open = "false";
|
|
449
|
+
hideT = setTimeout(() => {
|
|
450
|
+
cancelAnimationFrame(raf);
|
|
451
|
+
island.style.clipPath = "";
|
|
452
|
+
island.hidden = true;
|
|
453
|
+
ready = false;
|
|
454
|
+
expanded = false;
|
|
455
|
+
delete island.dataset.ready;
|
|
456
|
+
island.dataset.expanded = "false";
|
|
457
|
+
island.style.width = island.style.height = island.style.borderRadius = "";
|
|
458
|
+
[badge, trail, desc].forEach((s) => put(s, void 0));
|
|
459
|
+
delete trail.dataset.sig;
|
|
460
|
+
}, 450);
|
|
461
|
+
}
|
|
462
|
+
btn.onclick = () => {
|
|
463
|
+
const c = t;
|
|
464
|
+
if (c == null ? void 0 : c.button) {
|
|
465
|
+
c.button.onClick();
|
|
466
|
+
dynaura.dismiss(c.id);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
let sy = 0, t0 = 0, moved = false, longed = false;
|
|
470
|
+
island.addEventListener("pointerenter", (e) => {
|
|
471
|
+
if (e.pointerType === "mouse") {
|
|
472
|
+
hovered = true;
|
|
473
|
+
sync();
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
island.addEventListener("pointerleave", (e) => {
|
|
477
|
+
if (e.pointerType !== "mouse") return;
|
|
478
|
+
hovered = false;
|
|
479
|
+
if (!pinned) setExpanded(false);
|
|
480
|
+
sync();
|
|
481
|
+
});
|
|
482
|
+
drag.addEventListener("pointerdown", (e) => {
|
|
483
|
+
var _a2;
|
|
484
|
+
if (!t || e.target.closest("button")) return;
|
|
485
|
+
dragging = true;
|
|
486
|
+
moved = longed = false;
|
|
487
|
+
sy = e.clientY;
|
|
488
|
+
t0 = Date.now();
|
|
489
|
+
(_a2 = drag.setPointerCapture) == null ? void 0 : _a2.call(drag, e.pointerId);
|
|
490
|
+
drag.style.transition = "none";
|
|
491
|
+
lp = setTimeout(() => {
|
|
492
|
+
var _a3;
|
|
493
|
+
if (!moved) {
|
|
494
|
+
longed = true;
|
|
495
|
+
pinned = true;
|
|
496
|
+
if (o.haptics) (_a3 = navigator.vibrate) == null ? void 0 : _a3.call(navigator, 8);
|
|
497
|
+
sync();
|
|
498
|
+
}
|
|
499
|
+
}, 450);
|
|
500
|
+
sync();
|
|
501
|
+
});
|
|
502
|
+
drag.addEventListener("pointermove", (e) => {
|
|
503
|
+
if (!dragging) return;
|
|
504
|
+
const dy = e.clientY - sy;
|
|
505
|
+
if (Math.abs(dy) > 6) {
|
|
506
|
+
moved = true;
|
|
507
|
+
clearTimeout(lp);
|
|
508
|
+
}
|
|
509
|
+
if (!moved) return;
|
|
510
|
+
const d = dy * dir();
|
|
511
|
+
const off = d > 0 ? d : -Math.sqrt(-d) * 4;
|
|
512
|
+
drag.style.transform = `translateY(${off * dir()}px)`;
|
|
513
|
+
});
|
|
514
|
+
const up = (e) => {
|
|
515
|
+
if (!dragging) return;
|
|
516
|
+
dragging = false;
|
|
517
|
+
clearTimeout(lp);
|
|
518
|
+
drag.style.transition = "";
|
|
519
|
+
const d = (e.clientY - sy) * dir();
|
|
520
|
+
const v = d / Math.max(1, Date.now() - t0);
|
|
521
|
+
if (e.type === "pointerup" && moved && (d > 40 || v > 0.5 && d > 10) && t) {
|
|
522
|
+
dynaura.dismiss(t.id);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
drag.style.transform = "";
|
|
526
|
+
if (e.type === "pointerup" && !moved && !longed && hasBody()) {
|
|
527
|
+
pinned = !pinned;
|
|
528
|
+
if (!pinned && !hovered) setExpanded(false);
|
|
529
|
+
}
|
|
530
|
+
sync();
|
|
531
|
+
};
|
|
532
|
+
drag.addEventListener("pointerup", up);
|
|
533
|
+
drag.addEventListener("pointercancel", up);
|
|
534
|
+
const outside = (e) => {
|
|
535
|
+
if (pinned && !island.contains(e.target)) {
|
|
536
|
+
pinned = false;
|
|
537
|
+
if (!hovered) setExpanded(false);
|
|
538
|
+
sync();
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
document.addEventListener("pointerdown", outside);
|
|
542
|
+
function set2(n) {
|
|
543
|
+
merge(n);
|
|
544
|
+
setQueue(o.queue);
|
|
545
|
+
const [y, x = "center"] = o.position.split("-");
|
|
546
|
+
root.dataset.y = y;
|
|
547
|
+
root.dataset.x = x;
|
|
548
|
+
root.dataset.timer = String(o.timer);
|
|
549
|
+
root.dataset.theme = typeof o.theme === "object" ? "custom" : o.theme;
|
|
550
|
+
root.style.setProperty("--dynaura-offset", o.offset + "px");
|
|
551
|
+
applied.forEach((v) => root.style.removeProperty(v));
|
|
552
|
+
applied = [];
|
|
553
|
+
if (typeof o.theme === "object")
|
|
554
|
+
for (const k in o.theme) {
|
|
555
|
+
const v = `--dynaura-${VAR[k]}`;
|
|
556
|
+
root.style.setProperty(v, o.theme[k]);
|
|
557
|
+
applied.push(v);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
set2({});
|
|
561
|
+
const unsub = subscribe(render);
|
|
562
|
+
render();
|
|
563
|
+
return {
|
|
564
|
+
set: set2,
|
|
565
|
+
destroy() {
|
|
566
|
+
unsub();
|
|
567
|
+
ro.disconnect();
|
|
568
|
+
cancelAnimationFrame(raf);
|
|
569
|
+
document.removeEventListener("pointerdown", outside);
|
|
570
|
+
clear();
|
|
571
|
+
[hideT, expandT, liveI, lp].forEach((x) => {
|
|
572
|
+
clearTimeout(x);
|
|
573
|
+
clearInterval(x);
|
|
574
|
+
});
|
|
575
|
+
[badge, trail, desc].forEach((s) => put(s, void 0));
|
|
576
|
+
root.remove();
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// src/svelte.ts
|
|
582
|
+
var toaster = (_node, options) => {
|
|
583
|
+
const c = createToaster(options);
|
|
584
|
+
return { update: (o) => c.set(o), destroy: () => c.destroy() };
|
|
585
|
+
};
|
|
586
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
587
|
+
0 && (module.exports = {
|
|
588
|
+
dynaura,
|
|
589
|
+
toaster
|
|
590
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToasterOptions } from './vanilla.cjs';
|
|
2
|
+
export { CustomTheme, Position, dynaura } from './vanilla.cjs';
|
|
3
|
+
|
|
4
|
+
/** Svelte action: <div use:toaster={{ position: "top", theme: "system" }} /> — mount once. */
|
|
5
|
+
declare const toaster: (_node: HTMLElement, options?: ToasterOptions) => {
|
|
6
|
+
update: (o: ToasterOptions) => void;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { ToasterOptions, toaster };
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToasterOptions } from './vanilla.js';
|
|
2
|
+
export { CustomTheme, Position, dynaura } from './vanilla.js';
|
|
3
|
+
|
|
4
|
+
/** Svelte action: <div use:toaster={{ position: "top", theme: "system" }} /> — mount once. */
|
|
5
|
+
declare const toaster: (_node: HTMLElement, options?: ToasterOptions) => {
|
|
6
|
+
update: (o: ToasterOptions) => void;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { ToasterOptions, toaster };
|
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
createToaster,
|
|
4
|
+
dynaura
|
|
5
|
+
} from "./chunk-FNLIY6GQ.js";
|
|
6
|
+
|
|
7
|
+
// src/svelte.ts
|
|
8
|
+
var toaster = (_node, options) => {
|
|
9
|
+
const c = createToaster(options);
|
|
10
|
+
return { update: (o) => c.set(o), destroy: () => c.destroy() };
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
dynaura,
|
|
14
|
+
toaster
|
|
15
|
+
};
|