dynaura 0.0.0-stage → 0.1.1

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