dopaminejs 3.4.0 → 3.6.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.
@@ -0,0 +1,537 @@
1
+ import { a as e, n as t, o as n, t as r } from "./DataService-B5noGvMr.js";
2
+ import { n as i, r as a, t as o } from "./SoundManager-C6VdZEFo.js";
3
+ import { n as s } from "./storage-C2s4Da9b.js";
4
+ // src/dopamine/ui/dopamine.css?inline
5
+ var c = "#game-ui-overlay,.game-ui-overlay{pointer-events:none;z-index:1000;width:100%;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;position:fixed;top:0;left:0}.game-ui-top-bar{-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#0000004d;align-items:center;gap:12px;padding:12px 16px;display:flex}.level-badge{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:12px;flex-direction:column;align-items:center;min-width:60px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #667eea66}.level-label{color:#fffc;letter-spacing:.5px;font-size:10px;font-weight:600}.level-number{color:#fff;font-size:24px;font-weight:800;line-height:1}.xp-container{flex-direction:column;flex:1;gap:4px;display:flex}.xp-bar-bg{background:#fff3;border-radius:6px;height:12px;overflow:hidden;box-shadow:inset 0 2px 4px #0003}.xp-bar-fill{background:linear-gradient(90deg,#4facfe 0%,#00f2fe 100%);border-radius:6px;height:100%;transition:width .5s ease-out;box-shadow:0 0 10px #4facfe99}.xp-text{color:#fff;text-align:center;text-shadow:0 1px 2px #00000080;font-size:11px;font-weight:600}.streak-badge{background:linear-gradient(135deg,#f80 0%,#f40 100%);border-radius:12px;align-items:center;gap:6px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #f806}.streak-icon{font-size:20px;animation:2s infinite flicker}.streak-number{color:#fff;font-size:18px;font-weight:800}.achievement-popup{top:calc(var(--dopamine-toast-top,80px) + env(safe-area-inset-top,0px));right:var(--dopamine-toast-right,20px);left:var(--dopamine-toast-left,auto);background:var(--dopamine-toast-bg,linear-gradient(135deg, #667eea 0%, #764ba2 100%));border-radius:var(--dopamine-toast-radius,16px);box-shadow:var(--dopamine-toast-shadow,0 8px 32px #0006);z-index:10000;max-width:var(--dopamine-toast-max-width,320px);padding:16px;animation:.5s cubic-bezier(.68,-.55,.265,1.55) slideIn;position:fixed;overflow:hidden}.achievement-shine{background:linear-gradient(90deg,#0000,#ffffff4d,#0000);width:100%;height:100%;animation:2s infinite shine;position:absolute;top:0;left:-100%}.achievement-content{align-items:center;gap:12px;display:flex;position:relative}.achievement-icon{font-size:48px;animation:.6s ease-out bounce}.achievement-info{flex:1}.achievement-title{color:var(--dopamine-toast-muted,#ffffffe6);text-transform:uppercase;letter-spacing:.5px;font-size:12px;font-weight:600}.achievement-name{color:var(--dopamine-toast-text,white);margin:2px 0;font-size:18px;font-weight:800}.achievement-desc{color:var(--dopamine-toast-muted,#fffc);margin-bottom:4px;font-size:13px}.achievement-xp{color:var(--dopamine-toast-accent,gold);background:#fff3;border-radius:8px;padding:4px 8px;font-size:12px;font-weight:700;display:inline-block}.level-up-overlay{z-index:10001;background:#000000d9;justify-content:center;align-items:center;width:100%;height:100%;animation:.3s ease-out fadeIn;display:flex;position:fixed;top:0;left:0}.level-up-content{text-align:center;animation:.5s cubic-bezier(.68,-.55,.265,1.55) scaleIn}.level-up-title{background:linear-gradient(135deg,gold 0%,#ffed4e 100%);-webkit-text-fill-color:transparent;text-transform:uppercase;letter-spacing:4px;-webkit-background-clip:text;background-clip:text;margin-bottom:16px;font-size:32px;font-weight:800}.level-up-number{color:#fff;text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066;font-size:120px;font-weight:900;animation:1s ease-in-out infinite alternate glow}.level-up-subtitle{color:#fffc;margin-top:16px;font-size:24px;font-weight:600}.floating-text{text-shadow:2px 2px #000,-1px -1px #000,1px -1px #000,-1px 1px #000;pointer-events:none;z-index:9998;font-weight:800;animation:2s ease-out forwards floatUp;position:fixed}@keyframes slideIn{0%{opacity:0;transform:translate(400px)}to{opacity:1;transform:translate(0)}}@keyframes slideOut{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(400px)}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes scaleIn{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes glow{0%{text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066}to{text-shadow:0 0 30px gold,0 0 60px #ffd700cc,0 0 90px #ffd70099}}@keyframes shine{0%{left:-100%}30%{left:100%}to{left:100%}}@keyframes flicker{0%,to{opacity:1}50%{opacity:.8}}@keyframes floatUp{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100px)}}@keyframes xp-pulse{0%{transform:scaleY(1)}50%{transform:scaleY(1.2)}to{transform:scaleY(1)}}@keyframes level-pulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@media (width<=480px){.game-ui-top-bar{gap:8px;padding:10px 12px}.level-badge{min-width:50px;padding:6px 10px}.level-number{font-size:20px}.xp-bar-bg{height:10px}.xp-text{font-size:10px}.achievement-popup{right:var(--dopamine-toast-right,12px);max-width:min(var(--dopamine-toast-max-width,320px), calc(100% - 24px))}.level-up-number{font-size:80px}}@media (prefers-reduced-motion:reduce){.game-ui-overlay *,.achievement-popup,.achievement-popup *,.level-up-overlay,.level-up-overlay *{transition:none!important;animation:none!important}.floating-text{animation:none!important}}", l = "game-ui-overlay", u = {
6
+ levelUp: "LEVEL UP!",
7
+ achievementUnlocked: "Achievement Unlocked!"
8
+ }, d = "dopamine-reward-ui-css", f = "🔥", p = (e) => e == null ? "" : String(e), m = (e, t) => Object.prototype.hasOwnProperty.call(e, t), h = (e, t) => typeof e == "object" && e && m(e, t) ? e[t] : void 0, g = "http://www.w3.org/2000/svg", _ = /* @__PURE__ */ new Set([
9
+ "svg",
10
+ "g",
11
+ "path",
12
+ "circle",
13
+ "ellipse",
14
+ "rect",
15
+ "line",
16
+ "polyline",
17
+ "polygon",
18
+ "text",
19
+ "tspan",
20
+ "title",
21
+ "desc",
22
+ "defs",
23
+ "linearGradient",
24
+ "radialGradient",
25
+ "stop",
26
+ "clipPath",
27
+ "mask"
28
+ ]), v = /* @__PURE__ */ new Set(/* @__PURE__ */ "viewBox.width.height.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.d.points.transform.fill.fill-opacity.fill-rule.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-opacity.opacity.offset.stop-color.stop-opacity.gradientUnits.gradientTransform.clip-path.mask.clip-rule.font-size.font-family.font-weight.text-anchor.id.aria-hidden.aria-label.role".split(".")), y = /* @__PURE__ */ new Set([
29
+ "fill",
30
+ "stroke",
31
+ "clip-path",
32
+ "mask"
33
+ ]), b = /* @__PURE__ */ new Set(["transform", "gradientTransform"]), x = /^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/, S = /^[#a-zA-Z0-9(),.%\s-]+$/, C = /^[a-zA-Z0-9(),.\s-]+$/, w = /^[A-Za-z][\w.:-]*$/, T = 0;
34
+ function E(e, t) {
35
+ if (e.nodeType !== 1 || e.namespaceURI !== g || !_.has(e.localName)) return;
36
+ let n = e.getAttribute("id");
37
+ n && w.test(n) && t.add(n);
38
+ for (let n of Array.from(e.childNodes)) E(n, t);
39
+ }
40
+ function D(e, t, n) {
41
+ if (t.includes("\\")) return null;
42
+ let r = t.trim();
43
+ if (e === "id") return w.test(r) ? n.prefix + r : null;
44
+ if (y.has(e)) {
45
+ let e = x.exec(r);
46
+ return e ? n.ids.has(e[1]) ? `url(#${n.prefix}${e[1]})` : null : S.test(r) && !/url/i.test(r) ? r : null;
47
+ }
48
+ return b.has(e) ? C.test(r) && !/url/i.test(r) ? r : null : t.includes("(") ? e === "stop-color" && S.test(r) && !/url/i.test(r) ? r : null : t;
49
+ }
50
+ function O(e, t) {
51
+ if (e.nodeType === 3 || e.nodeType === 4) return document.createTextNode(e.data);
52
+ if (e.nodeType !== 1 || e.namespaceURI !== g || !_.has(e.localName)) return null;
53
+ let n = document.createElementNS(g, e.localName);
54
+ for (let r of Array.from(e.attributes)) {
55
+ if (r.namespaceURI !== null || !v.has(r.name)) continue;
56
+ let e = D(r.name, r.value, t);
57
+ e !== null && n.setAttribute(r.name, e);
58
+ }
59
+ for (let r of Array.from(e.childNodes)) {
60
+ let e = O(r, t);
61
+ e && n.appendChild(e);
62
+ }
63
+ return n;
64
+ }
65
+ function k(e) {
66
+ let t, n = /^\s*<svg[\s>]/.test(e) && !/^\s*<svg\b[^>]*\sxmlns\s*=/.test(e) ? e.replace(/^(\s*<svg)/, `$1 xmlns="${g}"`) : e;
67
+ try {
68
+ t = new DOMParser().parseFromString(n, "image/svg+xml");
69
+ } catch {
70
+ return null;
71
+ }
72
+ let r = t.documentElement;
73
+ if (!r || r.localName !== "svg" || t.getElementsByTagName("parsererror").length > 0) return null;
74
+ let i = /* @__PURE__ */ new Set();
75
+ return E(r, i), O(r, {
76
+ ids: i,
77
+ prefix: `dj-icon-${++T}-`
78
+ });
79
+ }
80
+ var A = class {
81
+ constructor(e = {}, t = {}) {
82
+ this.parts = e || {};
83
+ let n = h(t, "text");
84
+ this.strings = { ...u };
85
+ for (let e of Object.keys(u)) {
86
+ let t = h(n, e);
87
+ typeof t == "string" && (this.strings[e] = t);
88
+ }
89
+ this.safeIcons = h(t, "safeIcons") !== !1, this._streakIcon = h(h(t, "icons"), "streak") ?? f, this._injectCss = h(t, "injectCss"), this.container = null, this.xpBar = null, this.levelDisplay = null, this.streakDisplay = null, this._style = null, this._xp = null, this._level = null, this._timers = /* @__PURE__ */ new Set(), this._detached = [], this._cardQueue = [], this._cardActive = !1, this._build();
90
+ }
91
+ get root() {
92
+ return this.container;
93
+ }
94
+ _build() {
95
+ this._injectCss && this._addStyles(), this.container = document.createElement("div"), this.container.className = "game-ui-overlay", document.getElementById(l) || (this.container.id = l), this.container.innerHTML = "\n <div class=\"game-ui-top-bar\">\n <div class=\"level-badge\">\n <span class=\"level-label\">LVL</span>\n <span class=\"level-number\">1</span>\n </div>\n\n <div class=\"xp-container\">\n <div class=\"xp-bar-bg\">\n <div class=\"xp-bar-fill\" style=\"width: 0%\"></div>\n </div>\n <div class=\"xp-text\">0 / 100 XP</div>\n </div>\n\n <div class=\"streak-badge\">\n <span class=\"streak-icon\"></span>\n <span class=\"streak-number\">1</span>\n </div>\n </div>\n ", this.liveRegion = document.createElement("div"), this.liveRegion.className = "dopamine-live-region", this.liveRegion.setAttribute("aria-live", "polite"), this.liveRegion.setAttribute("role", "status"), Object.assign(this.liveRegion.style, {
96
+ position: "absolute",
97
+ width: "1px",
98
+ height: "1px",
99
+ overflow: "hidden",
100
+ clipPath: "inset(50%)",
101
+ whiteSpace: "nowrap"
102
+ }), this.container.appendChild(this.liveRegion), document.body.appendChild(this.container), this.levelBadge = this.container.querySelector(".level-badge"), this.streakBadge = this.container.querySelector(".streak-badge"), this.xpBar = this.container.querySelector(".xp-bar-fill"), this.xpText = this.container.querySelector(".xp-text"), this.levelDisplay = this.container.querySelector(".level-number"), this.streakDisplay = this.container.querySelector(".streak-number"), this._setIcon(this.container.querySelector(".streak-icon"), this._streakIcon);
103
+ }
104
+ _addStyles() {
105
+ if (document.getElementById(d)) return;
106
+ let e = typeof this._injectCss == "string" ? this._injectCss : c;
107
+ this._style = document.createElement("style"), this._style.id = d, this._style.textContent = e, document.head.appendChild(this._style);
108
+ }
109
+ _setIcon(e, t) {
110
+ if (e.textContent = "", typeof Node < "u" && t instanceof Node) e.appendChild(t);
111
+ else if (typeof t != "string") return;
112
+ else if (!this.safeIcons) e.innerHTML = t;
113
+ else {
114
+ let n = k(t);
115
+ n ? e.appendChild(n) : e.textContent = t;
116
+ }
117
+ }
118
+ _defer(e, t) {
119
+ let n = setTimeout(() => {
120
+ this._timers.delete(n), e();
121
+ }, t);
122
+ return this._timers.add(n), n;
123
+ }
124
+ _mount(e) {
125
+ return document.body.appendChild(e), this._detached.push(e), e;
126
+ }
127
+ _announce(e) {
128
+ this.liveRegion && (this.liveRegion.textContent = e);
129
+ }
130
+ _burst(e, t, n) {
131
+ this.parts.particles?.burst?.(e, t, n);
132
+ }
133
+ _replayAnimation(e, t) {
134
+ e && (e.style.animation = "none", this._defer(() => {
135
+ e.style.animation = t;
136
+ }, 10));
137
+ }
138
+ hud(e) {
139
+ if (!this.container || !e) return;
140
+ let { xp: t, level: n, progress: r, streak: i, next: a } = e, o = Number.isFinite(r) ? r : a > 0 ? t / a : 0;
141
+ this.xpBar.style.width = `${Math.max(0, Math.min(100, o * 100))}%`, this.xpText.textContent = Number.isFinite(a) ? `${t} / ${a} XP` : `${t} XP`, t !== this._xp && this._replayAnimation(this.xpBar, "xp-pulse 0.3s ease-out"), this._xp = t, this.levelDisplay.textContent = n, n !== this._level && this._replayAnimation(this.levelBadge, "level-pulse 0.5s ease-out"), this._level = n, this.streakDisplay.textContent = i, i >= 7 ? this.streakBadge.style.background = "linear-gradient(135deg, #ff6b00 0%, #ff4400 100%)" : i >= 3 ? this.streakBadge.style.background = "linear-gradient(135deg, #ff8800 0%, #ff6b00 100%)" : this.streakBadge.style.background = "";
142
+ }
143
+ popup(e) {
144
+ if (!this.container || !e || typeof e != "object") return;
145
+ let t = h(e, "kind");
146
+ t === "level" ? this._levelPopup(e) : t === "notice" ? this._notice(e) : this._card(e, t === "achievement");
147
+ }
148
+ _card(e, t) {
149
+ let { title: n, body: r, meta: i, icon: a } = e;
150
+ this._cardQueue.push([{
151
+ title: n,
152
+ body: r,
153
+ meta: i,
154
+ icon: a,
155
+ burst: h(e, "burst")
156
+ }, t]), this._nextCard();
157
+ }
158
+ _nextCard() {
159
+ if (this._cardActive) return;
160
+ let e = this._cardQueue.shift();
161
+ if (e) {
162
+ this._cardActive = !0;
163
+ try {
164
+ this._showCard(e[0], e[1]);
165
+ } catch (e) {
166
+ throw this._cardActive = !1, this._nextCard(), e;
167
+ }
168
+ }
169
+ }
170
+ _showCard(e, t) {
171
+ let n = document.createElement("div");
172
+ n.className = "achievement-popup", n.innerHTML = "\n <div class=\"achievement-shine\"></div>\n <div class=\"achievement-content\">\n <div class=\"achievement-icon\"></div>\n <div class=\"achievement-info\">\n <div class=\"achievement-title\"></div>\n <div class=\"achievement-name\"></div>\n <div class=\"achievement-desc\"></div>\n <div class=\"achievement-xp\"></div>\n </div>\n </div>\n ";
173
+ let r = p(e.title);
174
+ n.querySelector(".achievement-title").textContent = t ? this.strings.achievementUnlocked : "", this._setIcon(n.querySelector(".achievement-icon"), e.icon), n.querySelector(".achievement-name").textContent = r, n.querySelector(".achievement-desc").textContent = p(e.body), n.querySelector(".achievement-xp").textContent = p(e.meta), this._mount(n), this._announce(t ? `${this.strings.achievementUnlocked}: ${r}` : r), e.burst !== !1 && this._defer(() => {
175
+ let e = n.getBoundingClientRect();
176
+ this._burst("confetti", {
177
+ x: e.left + e.width / 2,
178
+ y: e.top + e.height / 2
179
+ }, { count: 40 });
180
+ }, 300), this._defer(() => {
181
+ n.style.animation = "slideOut 0.3s ease-in forwards", this._defer(() => {
182
+ this._remove(n), this._cardActive = !1, this._nextCard();
183
+ }, 300);
184
+ }, 4e3);
185
+ }
186
+ _levelPopup(e) {
187
+ let t = typeof e.title == "string" && e.title !== "" ? e.title : this.strings.levelUp, n = p(e.body), r = document.createElement("div");
188
+ r.className = "level-up-overlay", r.innerHTML = "\n <div class=\"level-up-content\">\n <div class=\"level-up-title\"></div>\n <div class=\"level-up-number\"></div>\n <div class=\"level-up-subtitle\">Amazing progress!</div>\n </div>\n ", r.querySelector(".level-up-title").textContent = t, r.querySelector(".level-up-number").textContent = n, this._mount(r), this._announce(`Level up: ${n}`), this._defer(() => {
189
+ for (let e = 0; e < 5; e++) this._defer(() => {
190
+ this._burst("confetti", {
191
+ x: Math.random() * window.innerWidth,
192
+ y: Math.random() * window.innerHeight * .6
193
+ }, { count: 30 });
194
+ }, e * 200);
195
+ }, 300), this._defer(() => {
196
+ r.style.opacity = "0", this._defer(() => this._remove(r), 500);
197
+ }, 2500);
198
+ }
199
+ _notice(e) {
200
+ let t = window.innerWidth / 2, n = window.innerHeight / 3, r = p(e.title);
201
+ e.tier === "legendary" ? (this._floatText({
202
+ text: r,
203
+ x: t,
204
+ y: n,
205
+ color: "#ffd700",
206
+ size: "36px"
207
+ }), this._burst("stars", {
208
+ x: t,
209
+ y: n
210
+ }, { count: 12 }), this._burst("confetti", {
211
+ x: t,
212
+ y: n
213
+ }, { count: 25 })) : e.tier === "rare" ? (this._floatText({
214
+ text: r,
215
+ x: t,
216
+ y: n,
217
+ color: "#ff6b6b",
218
+ size: "32px"
219
+ }), this._burst("fire", {
220
+ x: t,
221
+ y: n
222
+ }, { count: 20 })) : this._floatText({
223
+ text: r,
224
+ x: t,
225
+ y: n,
226
+ color: "#fff",
227
+ size: "24px"
228
+ }), this._announce(r);
229
+ }
230
+ text(e) {
231
+ this._floatText({ ...e });
232
+ }
233
+ _floatText({ text: e, x: t, y: n, color: r = "#ffd700", size: i = "24px" }) {
234
+ if (!this.container) return;
235
+ let a = document.createElement("div");
236
+ a.className = "floating-text", a.textContent = p(e), a.style.left = (Number.isFinite(t) ? t : window.innerWidth / 2) + "px", a.style.top = (Number.isFinite(n) ? n : window.innerHeight / 3) + "px", a.style.color = r, a.style.fontSize = i, this._mount(a), this._defer(() => this._remove(a), 2e3);
237
+ }
238
+ _remove(e) {
239
+ e.remove();
240
+ let t = this._detached.indexOf(e);
241
+ t > -1 && this._detached.splice(t, 1);
242
+ }
243
+ destroy() {
244
+ for (let e of this._timers) clearTimeout(e);
245
+ this._timers.clear(), this._cardQueue = [], this._cardActive = !1;
246
+ for (let e of this._detached) e.remove();
247
+ this._detached = [], this.container?.remove(), this._style?.remove(), this._style = null, this.container = null, this.liveRegion = null, this.xpBar = null, this.xpText = null, this.levelBadge = null, this.streakBadge = null, this.levelDisplay = null, this.streakDisplay = null, this._streakIcon = null;
248
+ }
249
+ };
250
+ // src/dopamine/feel/haptics.js
251
+ function j({ nav: e = globalThis.navigator, enabled: t = !0 } = {}) {
252
+ let n = !!t, r = (t) => {
253
+ if (n) try {
254
+ e.vibrate(t);
255
+ } catch {}
256
+ };
257
+ return {
258
+ tap: () => r(10),
259
+ double: () => r([
260
+ 10,
261
+ 40,
262
+ 10
263
+ ]),
264
+ setEnabled(e) {
265
+ n = !!e;
266
+ }
267
+ };
268
+ }
269
+ // src/dopamine/host.js
270
+ var M = 3, N = [
271
+ "ui",
272
+ "particles",
273
+ "sound",
274
+ "haptics"
275
+ ], P = (e) => typeof e == "object" && !!e && typeof e.then == "function", F = (e, t) => {
276
+ P(e) && e.then(void 0, (e) => t.error(e));
277
+ };
278
+ function I() {
279
+ let e = typeof document < "u" && typeof window < "u";
280
+ return {
281
+ hasDom: e,
282
+ reducedMotion: e ? a(window).matches === !0 : !1
283
+ };
284
+ }
285
+ function L(e, t, n) {
286
+ if (e === !1) return null;
287
+ let r = e;
288
+ return typeof e == "function" && (r = e(t)), r ?? n();
289
+ }
290
+ function R(e, t) {
291
+ let n = `dopamine_plugin_${t}:`;
292
+ return {
293
+ getItem: (t) => e.getItem(n + t),
294
+ setItem: (t, r) => e.setItem(n + t, r),
295
+ removeItem: (t) => e.removeItem(n + t)
296
+ };
297
+ }
298
+ function z(a = {}) {
299
+ let c = a || {}, l = I(), u = {
300
+ debug: () => {},
301
+ info: () => {},
302
+ warn: (...e) => console.warn(...e),
303
+ error: (...e) => console.error(...e),
304
+ ...c.log || {}
305
+ }, d = c.storage || s(), f = c.clock || e, p = {
306
+ ui: null,
307
+ particles: null,
308
+ sound: null,
309
+ haptics: null
310
+ }, m = {};
311
+ for (let e of N) Object.defineProperty(m, e, {
312
+ enumerable: !0,
313
+ get: () => p[e]
314
+ });
315
+ Object.freeze(m);
316
+ let h = {
317
+ ...l,
318
+ parts: m,
319
+ storage: d,
320
+ clock: f
321
+ }, g = L(c.progress, h, () => new t(new r({ storage: d }), {
322
+ clock: f,
323
+ streakDays: c.streakDays,
324
+ builtinAchievements: c.builtinAchievements,
325
+ loadRetryMs: c.loadRetryMs
326
+ }));
327
+ if (typeof g?.on != "function" || typeof g?.off != "function") throw new n("invalid_progress", "progress needs on() and off()");
328
+ p.particles = L(c.particles, h, () => l.hasDom ? new i() : null), p.sound = L(c.sound, h, () => new o({ storage: d })), p.haptics = L(c.haptics, h, () => j());
329
+ try {
330
+ p.ui = L(c.ui, h, () => l.hasDom ? new A(m) : null);
331
+ } catch (e) {
332
+ throw _(), e;
333
+ }
334
+ function _() {
335
+ for (let e of N) try {
336
+ p[e]?.destroy?.();
337
+ } catch (e) {
338
+ u.error(e);
339
+ }
340
+ }
341
+ let v = g, y = [], b = !1, x = (e) => (t) => {
342
+ try {
343
+ F(e(t), u);
344
+ } catch (e) {
345
+ u.error(e);
346
+ }
347
+ }, S = () => {
348
+ let e = p.ui;
349
+ if (!e || typeof g.snapshot != "function" || typeof g.getXPForNextLevel != "function") return;
350
+ let t = g.snapshot(), { total: n, progress: r } = g.getXPForNextLevel();
351
+ e.hud({
352
+ xp: t.xp,
353
+ level: t.level,
354
+ progress: r,
355
+ streak: t.streak.current,
356
+ next: n
357
+ });
358
+ };
359
+ y.push(v.on("xp_gained", x((e) => {
360
+ S(), e.leveledUp || p.sound?.play("xp");
361
+ })), v.on("level_up", x((e) => {
362
+ S(), p.ui?.popup({
363
+ kind: "level",
364
+ title: "",
365
+ body: String(e.newLevel)
366
+ }), p.sound?.play("level_up");
367
+ })), v.on("achievement_unlocked", x((e) => {
368
+ p.ui?.popup({
369
+ kind: "achievement",
370
+ title: e.name,
371
+ body: e.description,
372
+ icon: e.icon,
373
+ meta: `+${e.xp ?? 0} XP`
374
+ }), p.sound?.play("achievement");
375
+ })), v.on("streak_updated", x(S)), v.on("player_reset", x(S)), v.on("load_recovered", x(S)), v.on("personal_best", x((e) => {
376
+ p.ui?.popup({
377
+ kind: "notice",
378
+ title: `New High Score: ${e.score}!`,
379
+ tier: "legendary"
380
+ }), p.sound?.play("personal_best");
381
+ })));
382
+ let C = /* @__PURE__ */ new Map(), w = [];
383
+ function T(e) {
384
+ if (typeof e != "object" || !e || typeof e.name != "string" || !/^[a-z0-9-]+$/.test(e.name) || typeof e.install != "function") throw new n("plugin_invalid", "a plugin needs a name (a-z, 0-9 and -) and an install function");
385
+ if (e.api !== 3) throw new n("plugin_api", `${e.name} was built for api ${e.api}, this host is api 3`);
386
+ if (C.has(e.name)) throw new n("plugin_duplicate", `${e.name} is already installed`);
387
+ for (let t of e.after || []) if (!C.has(t) || !C.get(t).done) throw new n("plugin_order", `${e.name} must come after ${t}`);
388
+ for (let t of e.requires || []) if (!N.includes(t) || p[t] === null) throw new n("plugin_requires", `${e.name} requires the ${t} part, which is not set`);
389
+ }
390
+ function E(e) {
391
+ for (let t of e.offs) t();
392
+ e.offs.clear(), C.delete(e.name);
393
+ let t = w.indexOf(e);
394
+ t > -1 && w.splice(t, 1);
395
+ }
396
+ function D(e) {
397
+ if (e.removed) return;
398
+ e.removed = !0;
399
+ let t = e.disposer;
400
+ e.disposer = null;
401
+ try {
402
+ t?.();
403
+ } catch (e) {
404
+ u.error(e);
405
+ }
406
+ E(e);
407
+ }
408
+ function O(e) {
409
+ let { name: t } = e;
410
+ return {
411
+ progress: g,
412
+ parts: m,
413
+ events: {
414
+ on(t, n) {
415
+ let r = v.on(t, n), i = () => {
416
+ r(), e.offs.delete(i);
417
+ };
418
+ return e.offs.add(i), i;
419
+ },
420
+ off: (e, t) => v.off(e, t),
421
+ emit(e, r) {
422
+ if (typeof e != "string" || !e.startsWith(`${t}:`)) throw new n("plugin_event", `${t} may only emit events named ${t}:<event>`);
423
+ v.emit(e, r);
424
+ }
425
+ },
426
+ storage: R(d, t),
427
+ clock: f,
428
+ log: u,
429
+ env: {
430
+ hasDom: l.hasDom,
431
+ reducedMotion: l.reducedMotion
432
+ },
433
+ plugin: (e) => C.has(e) && C.get(e).done ? C.get(e).handle : null,
434
+ expose: (t) => {
435
+ e.handle = t;
436
+ }
437
+ };
438
+ }
439
+ function k(e) {
440
+ if (b) throw new n("disposed", "the host was disposed");
441
+ T(e);
442
+ let t = {
443
+ name: e.name,
444
+ done: !1,
445
+ removed: !1,
446
+ disposer: null,
447
+ handle: null,
448
+ offs: /* @__PURE__ */ new Set()
449
+ };
450
+ C.set(e.name, t);
451
+ let r = (e) => (t.done = !0, typeof e == "function" && (t.disposer = e), t.removed || b ? (t.removed = !1, D(t), t) : (w.push(t), t)), i = (e) => {
452
+ throw E(t), e;
453
+ }, a;
454
+ try {
455
+ a = e.install(O(t));
456
+ } catch (e) {
457
+ return i(e);
458
+ }
459
+ return P(a) ? a.then(r, i) : r(a);
460
+ }
461
+ let M = null;
462
+ function z(e) {
463
+ if (b) throw new n("disposed", "the host was disposed");
464
+ if (M === null) {
465
+ let t = k(e);
466
+ if (P(t)) {
467
+ let e = t.then((e) => e, (e) => {
468
+ throw e;
469
+ });
470
+ return M = e.then(() => {
471
+ M = null;
472
+ }, () => {
473
+ M = null;
474
+ }), {
475
+ record: null,
476
+ done: e
477
+ };
478
+ }
479
+ return {
480
+ record: t,
481
+ done: Promise.resolve(t)
482
+ };
483
+ }
484
+ let t = M.then(() => k(e));
485
+ return M = t.then(() => {
486
+ M = null;
487
+ }, () => {
488
+ M = null;
489
+ }), {
490
+ record: null,
491
+ done: t
492
+ };
493
+ }
494
+ function B(e) {
495
+ let { record: t, done: n } = z(e);
496
+ if (t) return () => D(t);
497
+ let r = null, i = !1;
498
+ return n.then((e) => {
499
+ r = e, i && D(e);
500
+ }, (e) => u.error(e)), () => {
501
+ r ? D(r) : i = !0;
502
+ };
503
+ }
504
+ let V = Promise.resolve();
505
+ try {
506
+ for (let e of c.plugins || []) {
507
+ let { done: t } = z(e);
508
+ V = V.then(() => t);
509
+ }
510
+ } catch (e) {
511
+ throw H(), e;
512
+ }
513
+ V = V.catch((e) => {
514
+ throw H(), e;
515
+ });
516
+ function H() {
517
+ if (!b) {
518
+ b = !0;
519
+ for (let e of [...w].reverse()) D(e);
520
+ for (let e of [...C.values()]) D(e);
521
+ for (let e of y) e();
522
+ y.length = 0, _(), g.clear?.();
523
+ }
524
+ }
525
+ let U = V.then(() => typeof g.init == "function" ? g.init() : void 0).then(() => (b || S(), W));
526
+ U.catch(() => {});
527
+ let W = {
528
+ progress: g,
529
+ parts: m,
530
+ events: v,
531
+ ready: U,
532
+ use: B,
533
+ dispose: H
534
+ };
535
+ return W;
536
+ }
537
+ export { A as i, z as n, j as r, M as t };
@@ -0,0 +1,37 @@
1
+ const e=require("./DataService-DKCk0nOu.cjs"),t=require("./SoundManager-DBGDYIkz.cjs"),n=require("./storage-B6z-zaBe.cjs");var r=`#game-ui-overlay,.game-ui-overlay{pointer-events:none;z-index:1000;width:100%;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;position:fixed;top:0;left:0}.game-ui-top-bar{-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#0000004d;align-items:center;gap:12px;padding:12px 16px;display:flex}.level-badge{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:12px;flex-direction:column;align-items:center;min-width:60px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #667eea66}.level-label{color:#fffc;letter-spacing:.5px;font-size:10px;font-weight:600}.level-number{color:#fff;font-size:24px;font-weight:800;line-height:1}.xp-container{flex-direction:column;flex:1;gap:4px;display:flex}.xp-bar-bg{background:#fff3;border-radius:6px;height:12px;overflow:hidden;box-shadow:inset 0 2px 4px #0003}.xp-bar-fill{background:linear-gradient(90deg,#4facfe 0%,#00f2fe 100%);border-radius:6px;height:100%;transition:width .5s ease-out;box-shadow:0 0 10px #4facfe99}.xp-text{color:#fff;text-align:center;text-shadow:0 1px 2px #00000080;font-size:11px;font-weight:600}.streak-badge{background:linear-gradient(135deg,#f80 0%,#f40 100%);border-radius:12px;align-items:center;gap:6px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #f806}.streak-icon{font-size:20px;animation:2s infinite flicker}.streak-number{color:#fff;font-size:18px;font-weight:800}.achievement-popup{top:calc(var(--dopamine-toast-top,80px) + env(safe-area-inset-top,0px));right:var(--dopamine-toast-right,20px);left:var(--dopamine-toast-left,auto);background:var(--dopamine-toast-bg,linear-gradient(135deg, #667eea 0%, #764ba2 100%));border-radius:var(--dopamine-toast-radius,16px);box-shadow:var(--dopamine-toast-shadow,0 8px 32px #0006);z-index:10000;max-width:var(--dopamine-toast-max-width,320px);padding:16px;animation:.5s cubic-bezier(.68,-.55,.265,1.55) slideIn;position:fixed;overflow:hidden}.achievement-shine{background:linear-gradient(90deg,#0000,#ffffff4d,#0000);width:100%;height:100%;animation:2s infinite shine;position:absolute;top:0;left:-100%}.achievement-content{align-items:center;gap:12px;display:flex;position:relative}.achievement-icon{font-size:48px;animation:.6s ease-out bounce}.achievement-info{flex:1}.achievement-title{color:var(--dopamine-toast-muted,#ffffffe6);text-transform:uppercase;letter-spacing:.5px;font-size:12px;font-weight:600}.achievement-name{color:var(--dopamine-toast-text,white);margin:2px 0;font-size:18px;font-weight:800}.achievement-desc{color:var(--dopamine-toast-muted,#fffc);margin-bottom:4px;font-size:13px}.achievement-xp{color:var(--dopamine-toast-accent,gold);background:#fff3;border-radius:8px;padding:4px 8px;font-size:12px;font-weight:700;display:inline-block}.level-up-overlay{z-index:10001;background:#000000d9;justify-content:center;align-items:center;width:100%;height:100%;animation:.3s ease-out fadeIn;display:flex;position:fixed;top:0;left:0}.level-up-content{text-align:center;animation:.5s cubic-bezier(.68,-.55,.265,1.55) scaleIn}.level-up-title{background:linear-gradient(135deg,gold 0%,#ffed4e 100%);-webkit-text-fill-color:transparent;text-transform:uppercase;letter-spacing:4px;-webkit-background-clip:text;background-clip:text;margin-bottom:16px;font-size:32px;font-weight:800}.level-up-number{color:#fff;text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066;font-size:120px;font-weight:900;animation:1s ease-in-out infinite alternate glow}.level-up-subtitle{color:#fffc;margin-top:16px;font-size:24px;font-weight:600}.floating-text{text-shadow:2px 2px #000,-1px -1px #000,1px -1px #000,-1px 1px #000;pointer-events:none;z-index:9998;font-weight:800;animation:2s ease-out forwards floatUp;position:fixed}@keyframes slideIn{0%{opacity:0;transform:translate(400px)}to{opacity:1;transform:translate(0)}}@keyframes slideOut{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(400px)}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes scaleIn{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes glow{0%{text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066}to{text-shadow:0 0 30px gold,0 0 60px #ffd700cc,0 0 90px #ffd70099}}@keyframes shine{0%{left:-100%}30%{left:100%}to{left:100%}}@keyframes flicker{0%,to{opacity:1}50%{opacity:.8}}@keyframes floatUp{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100px)}}@keyframes xp-pulse{0%{transform:scaleY(1)}50%{transform:scaleY(1.2)}to{transform:scaleY(1)}}@keyframes level-pulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@media (width<=480px){.game-ui-top-bar{gap:8px;padding:10px 12px}.level-badge{min-width:50px;padding:6px 10px}.level-number{font-size:20px}.xp-bar-bg{height:10px}.xp-text{font-size:10px}.achievement-popup{right:var(--dopamine-toast-right,12px);max-width:min(var(--dopamine-toast-max-width,320px), calc(100% - 24px))}.level-up-number{font-size:80px}}@media (prefers-reduced-motion:reduce){.game-ui-overlay *,.achievement-popup,.achievement-popup *,.level-up-overlay,.level-up-overlay *{transition:none!important;animation:none!important}.floating-text{animation:none!important}}`,i=`game-ui-overlay`,a={levelUp:`LEVEL UP!`,achievementUnlocked:`Achievement Unlocked!`},o=`dopamine-reward-ui-css`,s=`🔥`,c=e=>e==null?``:String(e),l=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),u=(e,t)=>typeof e==`object`&&e&&l(e,t)?e[t]:void 0,d=`http://www.w3.org/2000/svg`,f=new Set([`svg`,`g`,`path`,`circle`,`ellipse`,`rect`,`line`,`polyline`,`polygon`,`text`,`tspan`,`title`,`desc`,`defs`,`linearGradient`,`radialGradient`,`stop`,`clipPath`,`mask`]),p=new Set(`viewBox.width.height.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.d.points.transform.fill.fill-opacity.fill-rule.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-opacity.opacity.offset.stop-color.stop-opacity.gradientUnits.gradientTransform.clip-path.mask.clip-rule.font-size.font-family.font-weight.text-anchor.id.aria-hidden.aria-label.role`.split(`.`)),m=new Set([`fill`,`stroke`,`clip-path`,`mask`]),h=new Set([`transform`,`gradientTransform`]),g=/^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/,_=/^[#a-zA-Z0-9(),.%\s-]+$/,v=/^[a-zA-Z0-9(),.\s-]+$/,y=/^[A-Za-z][\w.:-]*$/,b=0;function x(e,t){if(e.nodeType!==1||e.namespaceURI!==d||!f.has(e.localName))return;let n=e.getAttribute(`id`);n&&y.test(n)&&t.add(n);for(let n of Array.from(e.childNodes))x(n,t)}function S(e,t,n){if(t.includes(`\\`))return null;let r=t.trim();if(e===`id`)return y.test(r)?n.prefix+r:null;if(m.has(e)){let e=g.exec(r);return e?n.ids.has(e[1])?`url(#${n.prefix}${e[1]})`:null:_.test(r)&&!/url/i.test(r)?r:null}return h.has(e)?v.test(r)&&!/url/i.test(r)?r:null:t.includes(`(`)?e===`stop-color`&&_.test(r)&&!/url/i.test(r)?r:null:t}function C(e,t){if(e.nodeType===3||e.nodeType===4)return document.createTextNode(e.data);if(e.nodeType!==1||e.namespaceURI!==d||!f.has(e.localName))return null;let n=document.createElementNS(d,e.localName);for(let r of Array.from(e.attributes)){if(r.namespaceURI!==null||!p.has(r.name))continue;let e=S(r.name,r.value,t);e!==null&&n.setAttribute(r.name,e)}for(let r of Array.from(e.childNodes)){let e=C(r,t);e&&n.appendChild(e)}return n}function w(e){let t,n=/^\s*<svg[\s>]/.test(e)&&!/^\s*<svg\b[^>]*\sxmlns\s*=/.test(e)?e.replace(/^(\s*<svg)/,`$1 xmlns="${d}"`):e;try{t=new DOMParser().parseFromString(n,`image/svg+xml`)}catch{return null}let r=t.documentElement;if(!r||r.localName!==`svg`||t.getElementsByTagName(`parsererror`).length>0)return null;let i=new Set;return x(r,i),C(r,{ids:i,prefix:`dj-icon-${++b}-`})}var T=class{constructor(e={},t={}){this.parts=e||{};let n=u(t,`text`);this.strings={...a};for(let e of Object.keys(a)){let t=u(n,e);typeof t==`string`&&(this.strings[e]=t)}this.safeIcons=u(t,`safeIcons`)!==!1,this._streakIcon=u(u(t,`icons`),`streak`)??s,this._injectCss=u(t,`injectCss`),this.container=null,this.xpBar=null,this.levelDisplay=null,this.streakDisplay=null,this._style=null,this._xp=null,this._level=null,this._timers=new Set,this._detached=[],this._cardQueue=[],this._cardActive=!1,this._build()}get root(){return this.container}_build(){this._injectCss&&this._addStyles(),this.container=document.createElement(`div`),this.container.className=`game-ui-overlay`,document.getElementById(i)||(this.container.id=i),this.container.innerHTML=`
2
+ <div class="game-ui-top-bar">
3
+ <div class="level-badge">
4
+ <span class="level-label">LVL</span>
5
+ <span class="level-number">1</span>
6
+ </div>
7
+
8
+ <div class="xp-container">
9
+ <div class="xp-bar-bg">
10
+ <div class="xp-bar-fill" style="width: 0%"></div>
11
+ </div>
12
+ <div class="xp-text">0 / 100 XP</div>
13
+ </div>
14
+
15
+ <div class="streak-badge">
16
+ <span class="streak-icon"></span>
17
+ <span class="streak-number">1</span>
18
+ </div>
19
+ </div>
20
+ `,this.liveRegion=document.createElement(`div`),this.liveRegion.className=`dopamine-live-region`,this.liveRegion.setAttribute(`aria-live`,`polite`),this.liveRegion.setAttribute(`role`,`status`),Object.assign(this.liveRegion.style,{position:`absolute`,width:`1px`,height:`1px`,overflow:`hidden`,clipPath:`inset(50%)`,whiteSpace:`nowrap`}),this.container.appendChild(this.liveRegion),document.body.appendChild(this.container),this.levelBadge=this.container.querySelector(`.level-badge`),this.streakBadge=this.container.querySelector(`.streak-badge`),this.xpBar=this.container.querySelector(`.xp-bar-fill`),this.xpText=this.container.querySelector(`.xp-text`),this.levelDisplay=this.container.querySelector(`.level-number`),this.streakDisplay=this.container.querySelector(`.streak-number`),this._setIcon(this.container.querySelector(`.streak-icon`),this._streakIcon)}_addStyles(){if(document.getElementById(o))return;let e=typeof this._injectCss==`string`?this._injectCss:r;this._style=document.createElement(`style`),this._style.id=o,this._style.textContent=e,document.head.appendChild(this._style)}_setIcon(e,t){if(e.textContent=``,typeof Node<`u`&&t instanceof Node)e.appendChild(t);else if(typeof t!=`string`)return;else if(!this.safeIcons)e.innerHTML=t;else{let n=w(t);n?e.appendChild(n):e.textContent=t}}_defer(e,t){let n=setTimeout(()=>{this._timers.delete(n),e()},t);return this._timers.add(n),n}_mount(e){return document.body.appendChild(e),this._detached.push(e),e}_announce(e){this.liveRegion&&(this.liveRegion.textContent=e)}_burst(e,t,n){this.parts.particles?.burst?.(e,t,n)}_replayAnimation(e,t){e&&(e.style.animation=`none`,this._defer(()=>{e.style.animation=t},10))}hud(e){if(!this.container||!e)return;let{xp:t,level:n,progress:r,streak:i,next:a}=e,o=Number.isFinite(r)?r:a>0?t/a:0;this.xpBar.style.width=`${Math.max(0,Math.min(100,o*100))}%`,this.xpText.textContent=Number.isFinite(a)?`${t} / ${a} XP`:`${t} XP`,t!==this._xp&&this._replayAnimation(this.xpBar,`xp-pulse 0.3s ease-out`),this._xp=t,this.levelDisplay.textContent=n,n!==this._level&&this._replayAnimation(this.levelBadge,`level-pulse 0.5s ease-out`),this._level=n,this.streakDisplay.textContent=i,i>=7?this.streakBadge.style.background=`linear-gradient(135deg, #ff6b00 0%, #ff4400 100%)`:i>=3?this.streakBadge.style.background=`linear-gradient(135deg, #ff8800 0%, #ff6b00 100%)`:this.streakBadge.style.background=``}popup(e){if(!this.container||!e||typeof e!=`object`)return;let t=u(e,`kind`);t===`level`?this._levelPopup(e):t===`notice`?this._notice(e):this._card(e,t===`achievement`)}_card(e,t){let{title:n,body:r,meta:i,icon:a}=e;this._cardQueue.push([{title:n,body:r,meta:i,icon:a,burst:u(e,`burst`)},t]),this._nextCard()}_nextCard(){if(this._cardActive)return;let e=this._cardQueue.shift();if(e){this._cardActive=!0;try{this._showCard(e[0],e[1])}catch(e){throw this._cardActive=!1,this._nextCard(),e}}}_showCard(e,t){let n=document.createElement(`div`);n.className=`achievement-popup`,n.innerHTML=`
21
+ <div class="achievement-shine"></div>
22
+ <div class="achievement-content">
23
+ <div class="achievement-icon"></div>
24
+ <div class="achievement-info">
25
+ <div class="achievement-title"></div>
26
+ <div class="achievement-name"></div>
27
+ <div class="achievement-desc"></div>
28
+ <div class="achievement-xp"></div>
29
+ </div>
30
+ </div>
31
+ `;let r=c(e.title);n.querySelector(`.achievement-title`).textContent=t?this.strings.achievementUnlocked:``,this._setIcon(n.querySelector(`.achievement-icon`),e.icon),n.querySelector(`.achievement-name`).textContent=r,n.querySelector(`.achievement-desc`).textContent=c(e.body),n.querySelector(`.achievement-xp`).textContent=c(e.meta),this._mount(n),this._announce(t?`${this.strings.achievementUnlocked}: ${r}`:r),e.burst!==!1&&this._defer(()=>{let e=n.getBoundingClientRect();this._burst(`confetti`,{x:e.left+e.width/2,y:e.top+e.height/2},{count:40})},300),this._defer(()=>{n.style.animation=`slideOut 0.3s ease-in forwards`,this._defer(()=>{this._remove(n),this._cardActive=!1,this._nextCard()},300)},4e3)}_levelPopup(e){let t=typeof e.title==`string`&&e.title!==``?e.title:this.strings.levelUp,n=c(e.body),r=document.createElement(`div`);r.className=`level-up-overlay`,r.innerHTML=`
32
+ <div class="level-up-content">
33
+ <div class="level-up-title"></div>
34
+ <div class="level-up-number"></div>
35
+ <div class="level-up-subtitle">Amazing progress!</div>
36
+ </div>
37
+ `,r.querySelector(`.level-up-title`).textContent=t,r.querySelector(`.level-up-number`).textContent=n,this._mount(r),this._announce(`Level up: ${n}`),this._defer(()=>{for(let e=0;e<5;e++)this._defer(()=>{this._burst(`confetti`,{x:Math.random()*window.innerWidth,y:Math.random()*window.innerHeight*.6},{count:30})},e*200)},300),this._defer(()=>{r.style.opacity=`0`,this._defer(()=>this._remove(r),500)},2500)}_notice(e){let t=window.innerWidth/2,n=window.innerHeight/3,r=c(e.title);e.tier===`legendary`?(this._floatText({text:r,x:t,y:n,color:`#ffd700`,size:`36px`}),this._burst(`stars`,{x:t,y:n},{count:12}),this._burst(`confetti`,{x:t,y:n},{count:25})):e.tier===`rare`?(this._floatText({text:r,x:t,y:n,color:`#ff6b6b`,size:`32px`}),this._burst(`fire`,{x:t,y:n},{count:20})):this._floatText({text:r,x:t,y:n,color:`#fff`,size:`24px`}),this._announce(r)}text(e){this._floatText({...e})}_floatText({text:e,x:t,y:n,color:r=`#ffd700`,size:i=`24px`}){if(!this.container)return;let a=document.createElement(`div`);a.className=`floating-text`,a.textContent=c(e),a.style.left=(Number.isFinite(t)?t:window.innerWidth/2)+`px`,a.style.top=(Number.isFinite(n)?n:window.innerHeight/3)+`px`,a.style.color=r,a.style.fontSize=i,this._mount(a),this._defer(()=>this._remove(a),2e3)}_remove(e){e.remove();let t=this._detached.indexOf(e);t>-1&&this._detached.splice(t,1)}destroy(){for(let e of this._timers)clearTimeout(e);this._timers.clear(),this._cardQueue=[],this._cardActive=!1;for(let e of this._detached)e.remove();this._detached=[],this.container?.remove(),this._style?.remove(),this._style=null,this.container=null,this.liveRegion=null,this.xpBar=null,this.xpText=null,this.levelBadge=null,this.streakBadge=null,this.levelDisplay=null,this.streakDisplay=null,this._streakIcon=null}};function E({nav:e=globalThis.navigator,enabled:t=!0}={}){let n=!!t,r=t=>{if(n)try{e.vibrate(t)}catch{}};return{tap:()=>r(10),double:()=>r([10,40,10]),setEnabled(e){n=!!e}}}var D=3,O=[`ui`,`particles`,`sound`,`haptics`],k=e=>typeof e==`object`&&!!e&&typeof e.then==`function`,A=(e,t)=>{k(e)&&e.then(void 0,e=>t.error(e))};function j(){let e=typeof document<`u`&&typeof window<`u`;return{hasDom:e,reducedMotion:e?t.r(window).matches===!0:!1}}function M(e,t,n){if(e===!1)return null;let r=e;return typeof e==`function`&&(r=e(t)),r??n()}function N(e,t){let n=`dopamine_plugin_${t}:`;return{getItem:t=>e.getItem(n+t),setItem:(t,r)=>e.setItem(n+t,r),removeItem:t=>e.removeItem(n+t)}}function P(r={}){let i=r||{},a=j(),o={debug:()=>{},info:()=>{},warn:(...e)=>console.warn(...e),error:(...e)=>console.error(...e),...i.log||{}},s=i.storage||n.n(),c=i.clock||e.a,l={ui:null,particles:null,sound:null,haptics:null},u={};for(let e of O)Object.defineProperty(u,e,{enumerable:!0,get:()=>l[e]});Object.freeze(u);let d={...a,parts:u,storage:s,clock:c},f=M(i.progress,d,()=>new e.n(new e.t({storage:s}),{clock:c,streakDays:i.streakDays,builtinAchievements:i.builtinAchievements,loadRetryMs:i.loadRetryMs}));if(typeof f?.on!=`function`||typeof f?.off!=`function`)throw new e.o(`invalid_progress`,`progress needs on() and off()`);l.particles=M(i.particles,d,()=>a.hasDom?new t.n:null),l.sound=M(i.sound,d,()=>new t.t({storage:s})),l.haptics=M(i.haptics,d,()=>E());try{l.ui=M(i.ui,d,()=>a.hasDom?new T(u):null)}catch(e){throw p(),e}function p(){for(let e of O)try{l[e]?.destroy?.()}catch(e){o.error(e)}}let m=f,h=[],g=!1,_=e=>t=>{try{A(e(t),o)}catch(e){o.error(e)}},v=()=>{let e=l.ui;if(!e||typeof f.snapshot!=`function`||typeof f.getXPForNextLevel!=`function`)return;let t=f.snapshot(),{total:n,progress:r}=f.getXPForNextLevel();e.hud({xp:t.xp,level:t.level,progress:r,streak:t.streak.current,next:n})};h.push(m.on(`xp_gained`,_(e=>{v(),e.leveledUp||l.sound?.play(`xp`)})),m.on(`level_up`,_(e=>{v(),l.ui?.popup({kind:`level`,title:``,body:String(e.newLevel)}),l.sound?.play(`level_up`)})),m.on(`achievement_unlocked`,_(e=>{l.ui?.popup({kind:`achievement`,title:e.name,body:e.description,icon:e.icon,meta:`+${e.xp??0} XP`}),l.sound?.play(`achievement`)})),m.on(`streak_updated`,_(v)),m.on(`player_reset`,_(v)),m.on(`load_recovered`,_(v)),m.on(`personal_best`,_(e=>{l.ui?.popup({kind:`notice`,title:`New High Score: ${e.score}!`,tier:`legendary`}),l.sound?.play(`personal_best`)})));let y=new Map,b=[];function x(t){if(typeof t!=`object`||!t||typeof t.name!=`string`||!/^[a-z0-9-]+$/.test(t.name)||typeof t.install!=`function`)throw new e.o(`plugin_invalid`,`a plugin needs a name (a-z, 0-9 and -) and an install function`);if(t.api!==3)throw new e.o(`plugin_api`,`${t.name} was built for api ${t.api}, this host is api 3`);if(y.has(t.name))throw new e.o(`plugin_duplicate`,`${t.name} is already installed`);for(let n of t.after||[])if(!y.has(n)||!y.get(n).done)throw new e.o(`plugin_order`,`${t.name} must come after ${n}`);for(let n of t.requires||[])if(!O.includes(n)||l[n]===null)throw new e.o(`plugin_requires`,`${t.name} requires the ${n} part, which is not set`)}function S(e){for(let t of e.offs)t();e.offs.clear(),y.delete(e.name);let t=b.indexOf(e);t>-1&&b.splice(t,1)}function C(e){if(e.removed)return;e.removed=!0;let t=e.disposer;e.disposer=null;try{t?.()}catch(e){o.error(e)}S(e)}function w(t){let{name:n}=t;return{progress:f,parts:u,events:{on(e,n){let r=m.on(e,n),i=()=>{r(),t.offs.delete(i)};return t.offs.add(i),i},off:(e,t)=>m.off(e,t),emit(t,r){if(typeof t!=`string`||!t.startsWith(`${n}:`))throw new e.o(`plugin_event`,`${n} may only emit events named ${n}:<event>`);m.emit(t,r)}},storage:N(s,n),clock:c,log:o,env:{hasDom:a.hasDom,reducedMotion:a.reducedMotion},plugin:e=>y.has(e)&&y.get(e).done?y.get(e).handle:null,expose:e=>{t.handle=e}}}function D(t){if(g)throw new e.o(`disposed`,`the host was disposed`);x(t);let n={name:t.name,done:!1,removed:!1,disposer:null,handle:null,offs:new Set};y.set(t.name,n);let r=e=>(n.done=!0,typeof e==`function`&&(n.disposer=e),n.removed||g?(n.removed=!1,C(n),n):(b.push(n),n)),i=e=>{throw S(n),e},a;try{a=t.install(w(n))}catch(e){return i(e)}return k(a)?a.then(r,i):r(a)}let P=null;function F(t){if(g)throw new e.o(`disposed`,`the host was disposed`);if(P===null){let e=D(t);if(k(e)){let t=e.then(e=>e,e=>{throw e});return P=t.then(()=>{P=null},()=>{P=null}),{record:null,done:t}}return{record:e,done:Promise.resolve(e)}}let n=P.then(()=>D(t));return P=n.then(()=>{P=null},()=>{P=null}),{record:null,done:n}}function I(e){let{record:t,done:n}=F(e);if(t)return()=>C(t);let r=null,i=!1;return n.then(e=>{r=e,i&&C(e)},e=>o.error(e)),()=>{r?C(r):i=!0}}let L=Promise.resolve();try{for(let e of i.plugins||[]){let{done:t}=F(e);L=L.then(()=>t)}}catch(e){throw R(),e}L=L.catch(e=>{throw R(),e});function R(){if(!g){g=!0;for(let e of[...b].reverse())C(e);for(let e of[...y.values()])C(e);for(let e of h)e();h.length=0,p(),f.clear?.()}}let z=L.then(()=>typeof f.init==`function`?f.init():void 0).then(()=>(g||v(),B));z.catch(()=>{});let B={progress:f,parts:u,events:m,ready:z,use:I,dispose:R};return B}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return D}});
@@ -0,0 +1 @@
1
+ function e(){let e=new Map;return{getItem:t=>e.has(t)?e.get(t):null,setItem:(t,n)=>{e.set(t,String(n))},removeItem:t=>{e.delete(t)},clear:()=>{e.clear()}}}function t(){try{if(typeof localStorage>`u`)return e();let t=`__dopamine_probe__`;return localStorage.setItem(t,`1`),localStorage.removeItem(t),localStorage}catch{return e()}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return e}});
@@ -0,0 +1,26 @@
1
+ // src/dopamine/utils/storage.js
2
+ function e() {
3
+ let e = /* @__PURE__ */ new Map();
4
+ return {
5
+ getItem: (t) => e.has(t) ? e.get(t) : null,
6
+ setItem: (t, n) => {
7
+ e.set(t, String(n));
8
+ },
9
+ removeItem: (t) => {
10
+ e.delete(t);
11
+ },
12
+ clear: () => {
13
+ e.clear();
14
+ }
15
+ };
16
+ }
17
+ function t() {
18
+ try {
19
+ if (typeof localStorage > "u") return e();
20
+ let t = "__dopamine_probe__";
21
+ return localStorage.setItem(t, "1"), localStorage.removeItem(t), localStorage;
22
+ } catch {
23
+ return e();
24
+ }
25
+ }
26
+ export { t as n, e as t };