dopaminejs 2.4.0 → 2.5.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/dist/dopamine.js CHANGED
@@ -1,378 +1,111 @@
1
- import { C as e, S as t, _ as n, a as r, b as i, c as a, d as o, f as s, g as c, h as l, i as u, l as d, m as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y, v as b, x, y as S } from "./ScreenShake-CLvO1wx4.js";
2
- //#region src/dopamine/core/EventEmitter.js
3
- var C = class {
4
- constructor() {
5
- this.listeners = /* @__PURE__ */ new Map();
6
- }
7
- on(e, t) {
8
- return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), () => this.off(e, t);
9
- }
10
- off(e, t) {
11
- this.listeners.has(e) && this.listeners.get(e).delete(t);
12
- }
13
- emit(e, t) {
14
- this.listeners.has(e) && this.listeners.get(e).forEach((n) => {
15
- try {
16
- n(t);
17
- } catch (t) {
18
- console.error(`Error in listener for event '${e}':`, t);
19
- }
20
- });
21
- }
22
- clear() {
23
- this.listeners.clear();
24
- }
25
- }, w = /* @__PURE__ */ new Set([
26
- "__proto__",
27
- "constructor",
28
- "prototype"
29
- ]), T = (e) => typeof e == "string" && e.length > 0 && !w.has(e), E = (e, t) => Object.prototype.hasOwnProperty.call(e, t), D = (e) => typeof e == "object" && !!e && !Array.isArray(e), O = (e, t, n = 0) => {
30
- let r = Number(e);
31
- return Number.isInteger(r) && r >= n ? r : t;
32
- }, k = class extends C {
33
- constructor(e, t = {}) {
34
- super(), this.dataService = e, this.player = null, this.achievements = {
35
- ...this._initAchievements(),
36
- ...t.achievements || {}
37
- }, this.events = t.events || t.kernel?.events || null, this._batchDepth = 0, this._pendingSave = !1;
38
- }
39
- _publish(e, t) {
40
- this.emit(e, t), this.events && this.events.emit(e, t);
41
- }
42
- async _batch(e) {
43
- this._batchDepth++;
44
- try {
45
- return await e();
46
- } finally {
47
- this._batchDepth--, this._batchDepth === 0 && this._pendingSave && (this._pendingSave = !1, await this._write());
48
- }
49
- }
50
- async init() {
51
- let e = await this.dataService.load("player", null);
52
- this.player = this._migrate(e);
53
- let t = this._updateDailyStreak();
54
- return await this.save(), t && this._publishStreak(), this.player;
55
- }
56
- _requirePlayer() {
57
- if (!this.player) throw Error("[DopamineJS] RewardSystem.init() must be awaited before use");
58
- }
59
- _publishStreak() {
60
- let { current: e, longest: t } = this.player.streak;
61
- this._publish("streak_updated", {
62
- current: e,
63
- longest: t
64
- });
65
- }
66
- _getDefaultPlayer() {
67
- return {
68
- name: "Player",
69
- xp: 0,
70
- level: 1,
71
- totalGamesPlayed: 0,
72
- createdAt: Date.now(),
73
- lastPlayedAt: Date.now(),
74
- streak: {
75
- current: 1,
76
- longest: 1,
77
- lastPlayDate: this._getTodayDateString()
78
- },
79
- achievements: {},
80
- stats: {}
81
- };
82
- }
83
- _migrate(e) {
84
- let t = this._getDefaultPlayer();
85
- if (!D(e)) return t;
86
- let n = Number(e.xp), r = Number.isFinite(n) && n >= 0 ? n : 0, i = this._calculateLevel(r), a = D(e.streak) ? e.streak : {}, o = O(a.current, 1, 1), s = typeof a.lastPlayDate == "string" && /^\d{4}-\d{2}-\d{2}$/.test(a.lastPlayDate) ? a.lastPlayDate : t.streak.lastPlayDate;
87
- return {
88
- ...t,
89
- ...e,
90
- name: typeof e.name == "string" ? e.name : t.name,
91
- xp: r,
92
- level: Math.max(i, O(e.level, i, 1)),
93
- totalGamesPlayed: O(e.totalGamesPlayed, 0),
94
- createdAt: Number.isFinite(e.createdAt) ? e.createdAt : t.createdAt,
95
- lastPlayedAt: Number.isFinite(e.lastPlayedAt) ? e.lastPlayedAt : t.lastPlayedAt,
96
- streak: {
97
- current: o,
98
- longest: Math.max(o, O(a.longest, o, 1)),
99
- lastPlayDate: s
100
- },
101
- achievements: this._migrateAchievements(e.achievements),
102
- stats: this._migrateStats(e.stats)
103
- };
104
- }
105
- _migrateAchievements(e) {
106
- let t = {};
107
- if (!D(e)) return t;
108
- for (let n of Object.keys(e)) {
109
- let r = e[n];
110
- T(n) && D(r) && (t[n] = {
111
- unlockedAt: Number.isFinite(r.unlockedAt) ? r.unlockedAt : Date.now(),
112
- seen: r.seen === !0
113
- });
114
- }
115
- return t;
116
- }
117
- _migrateStats(e) {
118
- let t = {};
119
- if (!D(e)) return t;
120
- for (let n of Object.keys(e)) {
121
- let r = e[n];
122
- if (!T(n) || !D(r)) continue;
123
- let i = {};
124
- for (let e of Object.keys(r)) T(e) && Number.isFinite(r[e]) && (i[e] = r[e]);
125
- i.totalPlays = O(r.totalPlays, 0), i.highScore = Number.isFinite(r.highScore) ? r.highScore : 0, t[n] = i;
126
- }
127
- return t;
128
- }
129
- async save() {
130
- if (this.player) {
131
- if (this._batchDepth > 0) {
132
- this._pendingSave = !0;
133
- return;
134
- }
135
- await this._write();
136
- }
137
- }
138
- async _write() {
139
- this.player.lastPlayedAt = Date.now(), await this.dataService.save("player", this.player) === !1 && this._publish("save_failed", { key: "player" });
140
- }
141
- async addXP(e, t = "") {
142
- if (!Number.isFinite(e)) throw TypeError(`[DopamineJS] addXP expects a finite number, received ${e}`);
143
- this._requirePlayer();
144
- let n = this.player.level;
145
- e = Math.max(e, -this.player.xp), this.player.xp += e;
146
- let r = Math.max(n, this._calculateLevel(this.player.xp)), i = r > n;
147
- i && (this.player.level = r), await this.save();
148
- let a = this.player.xp;
149
- return this._publish("xp_gained", {
150
- amount: e,
151
- reason: t,
152
- leveledUp: i,
153
- newLevel: r,
154
- total: a
155
- }), i && this._publish("level_up", {
156
- oldLevel: n,
157
- newLevel: r,
158
- totalXP: a
159
- }), {
160
- leveledUp: i,
161
- newLevel: r,
162
- xpGained: e
163
- };
164
- }
165
- _calculateLevel(e) {
166
- if (!(e > 0)) return 1;
167
- let t = Math.floor((1 + Math.sqrt(1 + 4 * e / 50)) / 2);
168
- return Math.max(1, t);
169
- }
170
- getXPForNextLevel() {
171
- this._requirePlayer();
172
- let e = this.player.level + 1, t = 50 * e * (e - 1), n = 50 * this.player.level * (this.player.level - 1), r = t - n, i = r > 0 ? Math.max(0, Math.min(1, (this.player.xp - n) / r)) : 0;
173
- return {
174
- total: t,
175
- needed: Math.max(0, t - this.player.xp),
176
- progress: i
177
- };
178
- }
179
- async recordGame(e, t = {}) {
180
- if (this._requirePlayer(), !T(e)) throw TypeError(`[DopamineJS] recordGame expects a game name, received ${String(e)}`);
181
- if (!D(t)) throw TypeError("[DopamineJS] recordGame expects a result object");
182
- if (t.score !== void 0 && !Number.isFinite(t.score)) throw TypeError(`[DopamineJS] recordGame expects a finite score, received ${String(t.score)}`);
183
- return this._batch(() => this._recordGame(e, t));
184
- }
185
- async _recordGame(e, t) {
186
- this._updateDailyStreak() && this._publishStreak(), E(this.player.stats, e) || (this.player.stats[e] = {
187
- totalPlays: 0,
188
- highScore: 0
189
- });
190
- let n = this.player.stats[e];
191
- n.totalPlays++, this.player.totalGamesPlayed++, t.score !== void 0 && t.score > n.highScore && (n.highScore = t.score, this._publish("new_high_score", {
192
- gameName: e,
193
- score: t.score
194
- })), Object.keys(t).forEach((e) => {
195
- if (e !== "score" && T(e)) {
196
- let r = E(n, e) && Number.isFinite(n[e]) ? n[e] : 0;
197
- n[e] = r + (Number.isFinite(t[e]) ? t[e] : 0);
198
- }
199
- });
200
- let r = 10;
201
- t.score && (r += Math.max(0, Math.floor(t.score / 5))), r = Math.floor(r * this.getStreakMultiplier()), await this.addXP(r, `Played ${e}`), await this.checkAchievements(e, t), await this.save();
202
- }
203
- async checkAchievements(e, t) {
204
- let n = [];
205
- for (let [r, i] of Object.entries(this.achievements)) {
206
- if (E(this.player.achievements, r)) continue;
207
- let a = !1;
208
- try {
209
- a = i.check(this.player, e, t);
210
- } catch (e) {
211
- console.error(`[DopamineJS] Achievement "${r}" check threw:`, e);
212
- continue;
213
- }
214
- a && await this.unlockAchievement(r) && n.push(i);
215
- }
216
- return n;
217
- }
218
- async unlockAchievement(e) {
219
- if (this._requirePlayer(), !T(e) || !E(this.achievements, e) || E(this.player.achievements, e)) return !1;
220
- let t = this.achievements[e];
221
- return t ? (this.player.achievements[e] = {
222
- unlockedAt: Date.now(),
223
- seen: !1
224
- }, await this.addXP(Number.isFinite(t.xp) ? t.xp : 0, `Achievement: ${t.name}`), this._publish("achievement_unlocked", {
225
- ...t,
226
- id: e
227
- }), await this.save(), !0) : !1;
228
- }
229
- getUnlockedAchievements() {
230
- return Object.entries(this.player.achievements).map(([e, t]) => ({
231
- ...this.achievements[e],
232
- id: e,
233
- ...t
234
- }));
235
- }
236
- getUnseenAchievements() {
237
- return this.getUnlockedAchievements().filter((e) => !e.seen);
238
- }
239
- async markAchievementsSeen(e) {
240
- for (let t of e) E(this.player.achievements, t) && (this.player.achievements[t].seen = !0);
241
- await this.save();
242
- }
243
- _updateDailyStreak() {
244
- let e = this._getTodayDateString(), t = this.player.streak.lastPlayDate;
245
- return t !== e && (t === this._getYesterdayDateString() ? (this.player.streak.current++, this.player.streak.current > this.player.streak.longest && (this.player.streak.longest = this.player.streak.current)) : this.player.streak.current = 1, this.player.streak.lastPlayDate = e, !0);
246
- }
247
- getStreakMultiplier() {
248
- let e = this.player.streak.current;
249
- return e >= 7 ? 2 : e >= 5 ? 1.5 : e >= 3 ? 1.25 : 1;
250
- }
251
- _toLocalDateString(e) {
252
- return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
253
- }
254
- _getTodayDateString() {
255
- return this._toLocalDateString(/* @__PURE__ */ new Date());
256
- }
257
- _getYesterdayDateString() {
258
- let e = /* @__PURE__ */ new Date();
259
- return e.setDate(e.getDate() - 1), this._toLocalDateString(e);
260
- }
261
- _initAchievements() {
262
- return {
263
- first_game: {
264
- name: "First Steps",
265
- description: "Play your first game",
266
- icon: "🎮",
267
- xp: 50,
268
- check: (e) => e.totalGamesPlayed >= 1
269
- },
270
- level_5: {
271
- name: "Rising Star",
272
- description: "Reach level 5",
273
- icon: "⭐",
274
- xp: 100,
275
- check: (e) => e.level >= 5
276
- },
277
- level_10: {
278
- name: "Expert Player",
279
- description: "Reach level 10",
280
- icon: "🏆",
281
- xp: 250,
282
- check: (e) => e.level >= 10
283
- },
284
- streak_3: {
285
- name: "Dedicated",
286
- description: "Play 3 days in a row",
287
- icon: "🔥",
288
- xp: 100,
289
- check: (e) => e.streak.current >= 3
290
- },
291
- streak_7: {
292
- name: "Unstoppable",
293
- description: "Play 7 days in a row",
294
- icon: "💥",
295
- xp: 300,
296
- check: (e) => e.streak.current >= 7
297
- }
298
- };
299
- }
300
- };
301
- //#endregion
302
- //#region src/dopamine/utils/storage.js
303
- function A() {
304
- let e = /* @__PURE__ */ new Map();
305
- return {
306
- getItem: (t) => e.has(t) ? e.get(t) : null,
307
- setItem: (t, n) => {
308
- e.set(t, String(n));
309
- },
310
- removeItem: (t) => {
311
- e.delete(t);
312
- },
313
- clear: () => {
314
- e.clear();
315
- }
316
- };
1
+ import { a as e, i as t, n, r, t as i } from "./DataService-CH9_gv_8.js";
2
+ import { C as a, S as o, _ as s, a as c, b as l, c as u, d, f, g as p, h as m, i as ee, l as h, m as g, n as _, o as v, p as y, r as b, s as x, t as S, u as C, v as w, x as T, y as E } from "./ScreenShake-CLvO1wx4.js";
3
+ //#region src/dopamine/ui/GameUI.js
4
+ var D = "game-ui-overlay", O = {
5
+ levelUp: "LEVEL UP!",
6
+ achievementUnlocked: "Achievement Unlocked!",
7
+ nearMiss: "CLOSE CALL!"
8
+ }, k = "🔥", te = (e, t) => Object.prototype.hasOwnProperty.call(e, t), A = (e, t) => typeof e == "object" && e && te(e, t) ? e[t] : void 0, j = "http://www.w3.org/2000/svg", M = /* @__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
+ ]), N = /* @__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(".")), P = /* @__PURE__ */ new Set([
29
+ "fill",
30
+ "stroke",
31
+ "clip-path",
32
+ "mask"
33
+ ]), F = /* @__PURE__ */ new Set(["transform", "gradientTransform"]), I = /^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/, L = /^[#a-zA-Z0-9(),.%\s-]+$/, R = /^[a-zA-Z0-9(),.\s-]+$/, z = /^[A-Za-z][\w.:-]*$/, B = 0;
34
+ function V(e, t) {
35
+ if (e.nodeType !== 1 || e.namespaceURI !== j || !M.has(e.localName)) return;
36
+ let n = e.getAttribute("id");
37
+ n && z.test(n) && t.add(n);
38
+ for (let n of Array.from(e.childNodes)) V(n, t);
39
+ }
40
+ function H(e, t, n) {
41
+ if (t.includes("\\")) return null;
42
+ let r = t.trim();
43
+ if (e === "id") return z.test(r) ? n.prefix + r : null;
44
+ if (P.has(e)) {
45
+ let e = I.exec(r);
46
+ return e ? n.ids.has(e[1]) ? `url(#${n.prefix}${e[1]})` : null : L.test(r) && !/url/i.test(r) ? r : null;
47
+ }
48
+ return F.has(e) ? R.test(r) && !/url/i.test(r) ? r : null : t.includes("(") ? e === "stop-color" && L.test(r) && !/url/i.test(r) ? r : null : t;
49
+ }
50
+ function U(e, t) {
51
+ if (e.nodeType === 3 || e.nodeType === 4) return document.createTextNode(e.data);
52
+ if (e.nodeType !== 1 || e.namespaceURI !== j || !M.has(e.localName)) return null;
53
+ let n = document.createElementNS(j, e.localName);
54
+ for (let r of Array.from(e.attributes)) {
55
+ if (r.namespaceURI !== null || !N.has(r.name)) continue;
56
+ let e = H(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 = U(r, t);
61
+ e && n.appendChild(e);
62
+ }
63
+ return n;
317
64
  }
318
- function j() {
65
+ function W(e) {
66
+ let t, n = /^\s*<svg[\s>]/.test(e) && !/^\s*<svg\b[^>]*\sxmlns\s*=/.test(e) ? e.replace(/^(\s*<svg)/, `$1 xmlns="${j}"`) : e;
319
67
  try {
320
- if (typeof localStorage > "u") return A();
321
- let e = "__dopamine_probe__";
322
- return localStorage.setItem(e, "1"), localStorage.removeItem(e), localStorage;
68
+ t = new DOMParser().parseFromString(n, "image/svg+xml");
323
69
  } catch {
324
- return A();
325
- }
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 V(r, i), U(r, {
76
+ ids: i,
77
+ prefix: `dj-icon-${++B}-`
78
+ });
326
79
  }
327
- //#endregion
328
- //#region src/dopamine/core/DataService.js
329
- var M = class {
330
- constructor(e = {}) {
331
- this.storage = e.storage || j(), this.prefix = e.prefix || "dopamine_", this._tail = null;
332
- }
333
- _write(e) {
334
- let t = this._tail ? this._tail.then(e) : e();
335
- if (typeof t?.then == "function") {
336
- let e = Promise.resolve(t).catch(() => {}).then(() => {
337
- this._tail === e && (this._tail = null);
338
- });
339
- this._tail = e;
340
- }
341
- return t;
342
- }
343
- async save(e, t) {
344
- try {
345
- let n = JSON.stringify(t);
346
- return await this._write(() => this.storage.setItem(this.prefix + e, n)), !0;
347
- } catch (e) {
348
- return console.error("Error saving data:", e), !1;
349
- }
350
- }
351
- async load(e, t = null) {
352
- try {
353
- await this._tail;
354
- let n = await this.storage.getItem(this.prefix + e);
355
- return n ? JSON.parse(n) : t;
356
- } catch (e) {
357
- return console.error("Error loading data:", e), t;
80
+ var G = class {
81
+ constructor(e, t = {}) {
82
+ this.particleSystem = e;
83
+ let n = A(t, "text");
84
+ this.text = { ...O };
85
+ for (let e of Object.keys(O)) {
86
+ let t = A(n, e);
87
+ typeof t == "string" && (this.text[e] = t);
358
88
  }
359
- }
360
- async clear(e) {
361
- await this._write(() => this.storage.removeItem(this.prefix + e));
362
- }
363
- }, N = "game-ui-overlay", P = class {
364
- constructor(e) {
365
- this.particleSystem = e, this.container = null, this.xpBar = null, this.levelDisplay = null, this.streakDisplay = null, this._timers = /* @__PURE__ */ new Set(), this._detached = [], this.init();
89
+ this.safeIcons = A(t, "safeIcons") === !0, this._streakIcon = A(A(t, "icons"), "streak") ?? k, this.container = null, this.xpBar = null, this.levelDisplay = null, this.streakDisplay = null, this._timers = /* @__PURE__ */ new Set(), this._detached = [], this.init();
366
90
  }
367
91
  init() {
368
- this.container = document.createElement("div"), this.container.className = "game-ui-overlay", document.getElementById(N) || (this.container.id = N), 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, {
92
+ this.container = document.createElement("div"), this.container.className = "game-ui-overlay", document.getElementById(D) || (this.container.id = D), 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, {
369
93
  position: "absolute",
370
94
  width: "1px",
371
95
  height: "1px",
372
96
  overflow: "hidden",
373
97
  clipPath: "inset(50%)",
374
98
  whiteSpace: "nowrap"
375
- }), 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");
99
+ }), 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);
100
+ }
101
+ _setIcon(e, t) {
102
+ if (e.textContent = "", typeof Node < "u" && t instanceof Node) e.appendChild(t);
103
+ else if (typeof t != "string") return;
104
+ else if (!this.safeIcons) e.innerHTML = t;
105
+ else {
106
+ let n = W(t);
107
+ n ? e.appendChild(n) : e.textContent = t;
108
+ }
376
109
  }
377
110
  _defer(e, t) {
378
111
  let n = setTimeout(() => {
@@ -403,7 +136,7 @@ var M = class {
403
136
  }
404
137
  showAchievement(e) {
405
138
  let t = document.createElement("div");
406
- t.className = "achievement-popup", t.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\">Achievement Unlocked!</div>\n <div class=\"achievement-name\"></div>\n <div class=\"achievement-desc\"></div>\n <div class=\"achievement-xp\"></div>\n </div>\n </div>\n ", t.querySelector(".achievement-icon").innerHTML = e.icon ?? "", t.querySelector(".achievement-name").textContent = e.name ?? "", t.querySelector(".achievement-desc").textContent = e.description ?? "", t.querySelector(".achievement-xp").textContent = `+${e.xp ?? 0} XP`, this._mount(t), this._announce(`Achievement unlocked: ${e.name ?? ""}`), this._defer(() => {
139
+ t.className = "achievement-popup", t.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 ", t.querySelector(".achievement-title").textContent = this.text.achievementUnlocked, this._setIcon(t.querySelector(".achievement-icon"), e.icon), t.querySelector(".achievement-name").textContent = e.name ?? "", t.querySelector(".achievement-desc").textContent = e.description ?? "", t.querySelector(".achievement-xp").textContent = `+${e.xp ?? 0} XP`, this._mount(t), this._announce(`Achievement unlocked: ${e.name ?? ""}`), this._defer(() => {
407
140
  let e = t.getBoundingClientRect();
408
141
  this.particleSystem.confetti(e.left + e.width / 2, e.top + e.height / 2, 40);
409
142
  }, 300), this._defer(() => {
@@ -412,7 +145,7 @@ var M = class {
412
145
  }
413
146
  showLevelUp(e, t) {
414
147
  let n = document.createElement("div");
415
- n.className = "level-up-overlay", n.innerHTML = "\n <div class=\"level-up-content\">\n <div class=\"level-up-title\">LEVEL UP!</div>\n <div class=\"level-up-number\"></div>\n <div class=\"level-up-subtitle\">Amazing progress!</div>\n </div>\n ", n.querySelector(".level-up-number").textContent = t, this._mount(n), this._announce(`Level up: ${t}`), this._defer(() => {
148
+ n.className = "level-up-overlay", n.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 ", n.querySelector(".level-up-title").textContent = this.text.levelUp, n.querySelector(".level-up-number").textContent = t, this._mount(n), this._announce(`Level up: ${t}`), this._defer(() => {
416
149
  for (let e = 0; e < 5; e++) this._defer(() => {
417
150
  let e = Math.random() * window.innerWidth, t = Math.random() * window.innerHeight * .6;
418
151
  this.particleSystem.confetti(e, t, 30);
@@ -429,7 +162,7 @@ var M = class {
429
162
  this.showFloatingText(`${e}× COMBO!`, t, n, "#ff6b6b", "32px"), this.particleSystem.fire(t, n, 20);
430
163
  }
431
164
  showNearMiss(e, t) {
432
- this.showFloatingText("CLOSE CALL!", e, t, "#45b7d1", "20px"), this.particleSystem.sparkle(e, t, 15, "#45b7d1");
165
+ this.showFloatingText(this.text.nearMiss, e, t, "#45b7d1", "20px"), this.particleSystem.sparkle(e, t, 15, "#45b7d1");
433
166
  }
434
167
  showLuckyMoment(e, t, n) {
435
168
  this.showFloatingText(`LUCKY ${e}×!`, t, n, "#ffd700", "36px"), this.particleSystem.starBurst(t, n, 12), this.particleSystem.confetti(t, n, 25);
@@ -472,11 +205,17 @@ var M = class {
472
205
  for (let e of this._timers) clearTimeout(e);
473
206
  this._timers.clear();
474
207
  for (let e of this._detached) e.remove();
475
- this._detached = [], this.container?.remove(), this.container = null, this.liveRegion = null, this.xpBar = null, this.xpText = null, this.levelBadge = null, this.streakBadge = null, this.levelDisplay = null, this.streakDisplay = null;
208
+ this._detached = [], this.container?.remove(), 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;
476
209
  }
477
- }, F = class {
210
+ }, K = Object.freeze({ matches: !1 });
211
+ function q(e = globalThis.window) {
212
+ return typeof e?.matchMedia == "function" && e.matchMedia("(prefers-reduced-motion: reduce)") || K;
213
+ }
214
+ //#endregion
215
+ //#region src/dopamine/effects/ParticleSystem.js
216
+ var J = class {
478
217
  constructor(e = {}) {
479
- this.container = e.container ? typeof e.container == "string" ? document.querySelector(e.container) : e.container : document.body, this.container ||= (console.warn(`[DopamineJS] Particle container '${e.container}' not found. Using document.body.`), document.body), this.maxParticles = Number.isFinite(e.maxParticles) ? Math.max(0, Math.floor(e.maxParticles)) : 5e3, this._reducedMotion = e.respectReducedMotion !== !1 && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)") : null, this.canvasId = e.canvasId || "dopamine-particle-canvas", this.canvas = document.createElement("canvas"), this.canvas.classList.add("dopamine-particle-canvas"), document.getElementById(this.canvasId) || (this.canvas.id = this.canvasId), this.canvas.style.pointerEvents = "none", this.canvas.style.zIndex = e.zIndex || "9999", this.container === document.body ? (this.canvas.style.position = "fixed", this.canvas.style.top = "0", this.canvas.style.left = "0") : (this.canvas.style.position = "absolute", this.canvas.style.top = "0", this.canvas.style.left = "0", window.getComputedStyle(this.container).position === "static" && (this.container.style.position = "relative")), this.container.appendChild(this.canvas), this.ctx = this.canvas.getContext("2d"), this.particles = [], this.pool = [], this.sprites = /* @__PURE__ */ new Map(), this.customEffects = /* @__PURE__ */ new Map(), this.isAnimating = !1, this._onResize = () => this._resize(), this._resizeObserver = null, this._frameHandle = null, this._lastFrameTime = null, this._resize(), window.ResizeObserver && this.container !== document.body ? (this._resizeObserver = new ResizeObserver(this._onResize), this._resizeObserver.observe(this.container)) : window.addEventListener("resize", this._onResize);
218
+ this.container = e.container ? typeof e.container == "string" ? document.querySelector(e.container) : e.container : document.body, this.container ||= (console.warn(`[DopamineJS] Particle container '${e.container}' not found. Using document.body.`), document.body), this.maxParticles = Number.isFinite(e.maxParticles) ? Math.max(0, Math.floor(e.maxParticles)) : 5e3, this._reducedMotion = e.respectReducedMotion === !1 ? null : q(window), this.canvasId = e.canvasId || "dopamine-particle-canvas", this.canvas = document.createElement("canvas"), this.canvas.classList.add("dopamine-particle-canvas"), document.getElementById(this.canvasId) || (this.canvas.id = this.canvasId), this.canvas.style.pointerEvents = "none", this.canvas.style.zIndex = e.zIndex || "9999", this.container === document.body ? (this.canvas.style.position = "fixed", this.canvas.style.top = "0", this.canvas.style.left = "0") : (this.canvas.style.position = "absolute", this.canvas.style.top = "0", this.canvas.style.left = "0", window.getComputedStyle(this.container).position === "static" && (this.container.style.position = "relative")), this.container.appendChild(this.canvas), this.ctx = this.canvas.getContext("2d"), this.particles = [], this.pool = [], this.sprites = /* @__PURE__ */ new Map(), this.customEffects = /* @__PURE__ */ new Map(), this.isAnimating = !1, this._onResize = () => this._resize(), this._resizeObserver = null, this._frameHandle = null, this._lastFrameTime = null, this._resize(), window.ResizeObserver && this.container !== document.body ? (this._resizeObserver = new ResizeObserver(this._onResize), this._resizeObserver.observe(this.container)) : window.addEventListener("resize", this._onResize);
480
219
  }
481
220
  _resize() {
482
221
  let e = this.container === document.body ? window.innerWidth : this.container.clientWidth, t = this.container === document.body ? window.innerHeight : this.container.clientHeight, n = window.devicePixelRatio || 1;
@@ -620,9 +359,23 @@ var M = class {
620
359
  destroy() {
621
360
  this.clear(), this.isAnimating = !1, this._frameHandle !== null && (cancelAnimationFrame(this._frameHandle), this._frameHandle = null), this._resizeObserver &&= (this._resizeObserver.disconnect(), null), window.removeEventListener("resize", this._onResize), this.canvas.remove(), this.sprites.clear(), this.customEffects.clear(), this.pool = [];
622
361
  }
623
- }, I = (e, t) => Object.prototype.hasOwnProperty.call(e, t), L = class {
362
+ }, Y = (e, t) => Object.prototype.hasOwnProperty.call(e, t), X = class {
624
363
  constructor(e = {}) {
625
- this.audioContext = null, this.storageKey = e.storageKey || "dopamineSoundsMuted", this.storage = e.storage || j(), this.muted = this.storage.getItem(this.storageKey) === "true", this.assets = /* @__PURE__ */ new Map(), this.customSounds = e.customSounds || {}, this.masterGain = null, this._volume = 1, this.setVolume(e.volume ?? 1), this._loading = /* @__PURE__ */ new Map(), this._timers = /* @__PURE__ */ new Set();
364
+ this.audioContext = null, this.storageKey = e.storageKey || "dopamineSoundsMuted", this.storage = e.storage || r(), this.muted = this.storage.getItem(this.storageKey) === "true", this.assets = /* @__PURE__ */ new Map(), this.customSounds = e.customSounds || {}, this.masterGain = null, this._volume = 1, this.setVolume(e.volume ?? 1), this._loading = /* @__PURE__ */ new Map(), this._timers = /* @__PURE__ */ new Set(), this._unlocks = /* @__PURE__ */ new Set();
365
+ }
366
+ unlockOn(e, t = [
367
+ "pointerup",
368
+ "touchend",
369
+ "keydown"
370
+ ]) {
371
+ let n = () => {
372
+ for (let n of t) e.removeEventListener(n, r);
373
+ this._unlocks.delete(n);
374
+ }, r = () => {
375
+ n(), this.initAudio();
376
+ };
377
+ for (let n of t) e.addEventListener(n, r);
378
+ return this._unlocks.add(n), n;
626
379
  }
627
380
  _later(e, t) {
628
381
  let n = setTimeout(() => {
@@ -679,7 +432,7 @@ var M = class {
679
432
  this._playBuffer(this.assets.get(e));
680
433
  return;
681
434
  }
682
- if (I(this.customSounds, e) && !this.assets.has(e)) {
435
+ if (Y(this.customSounds, e) && !this.assets.has(e)) {
683
436
  let t = this.audioContext;
684
437
  if (await this.loadSound(e, this.customSounds[e]), this.audioContext !== t) return;
685
438
  if (this.assets.has(e)) {
@@ -695,7 +448,7 @@ var M = class {
695
448
  error: () => this.playError(!0),
696
449
  gameover: () => this.playGameOver(!0)
697
450
  };
698
- I(t, e) && t[e]();
451
+ Y(t, e) && t[e]();
699
452
  }
700
453
  _playBuffer(e) {
701
454
  let t = this.audioContext.createBufferSource();
@@ -733,12 +486,13 @@ var M = class {
733
486
  this.playTone(200, .2, "sawtooth", .3);
734
487
  }
735
488
  destroy() {
489
+ for (let e of [...this._unlocks]) e();
736
490
  for (let e of this._timers) clearTimeout(e);
737
491
  this._timers.clear(), this.audioContext && (this.audioContext.close?.())?.catch?.(() => {}), this.audioContext = null, this.masterGain = null, this.assets.clear(), this._loading.clear();
738
492
  }
739
- }, R = class {
493
+ }, Z = class {
740
494
  constructor(e = {}) {
741
- this.config = e, this.dataService = new M(e.data || {}), this.rewardSystem = new k(this.dataService, e.rewards || {}), this.soundManager = new L(e.sound || {}), this.particleSystem = new F(e.particles || {}), this.gameUI = new P(this.particleSystem), this._bindEvents();
495
+ this.config = e, this.dataService = new i(e.data || {}), this.rewardSystem = new t(this.dataService, e.rewards || {}), this.soundManager = new X(e.sound || {}), this.particleSystem = new J(e.particles || {}), this.gameUI = new G(this.particleSystem), this._bindEvents();
742
496
  }
743
497
  async init() {
744
498
  return await this.rewardSystem.init(), this._syncUI(), {
@@ -777,12 +531,12 @@ var M = class {
777
531
  for (let e of this._unsubscribe) e();
778
532
  this._unsubscribe = [], this.gameUI.destroy(), this.particleSystem.destroy(), this.soundManager.destroy();
779
533
  }
780
- }, z = {
534
+ }, Q = {
781
535
  init(e) {},
782
536
  update(e) {},
783
537
  fixedUpdate(e) {},
784
538
  destroy() {}
785
- }, B = class {
539
+ }, ne = class {
786
540
  constructor() {
787
541
  this.kernel = null;
788
542
  }
@@ -792,16 +546,16 @@ var M = class {
792
546
  update(e) {}
793
547
  fixedUpdate(e) {}
794
548
  destroy() {}
795
- }, V = {
796
- ...z,
549
+ }, re = {
550
+ ...Q,
797
551
  addBody(e) {},
798
552
  removeBody(e) {},
799
553
  checkCollision(e, t) {},
800
554
  raycast(e, t, n) {},
801
555
  setGravity(e, t) {},
802
556
  step(e) {}
803
- }, H = {
804
- ...z,
557
+ }, $ = {
558
+ ...Q,
805
559
  registerSound(e, t) {},
806
560
  preloadSounds(e) {},
807
561
  play(e, t) {},
@@ -809,8 +563,8 @@ var M = class {
809
563
  stop(e) {},
810
564
  toggleMute() {},
811
565
  setVolume(e) {}
812
- }, U = {
813
- ...z,
566
+ }, ie = {
567
+ ...Q,
814
568
  registerSprite(e, t) {},
815
569
  registerEffect(e, t) {},
816
570
  play(e, t, n, ...r) {},
@@ -821,7 +575,30 @@ var M = class {
821
575
  sparkle(e, t, n, r) {},
822
576
  fire(e, t, n) {},
823
577
  starBurst(e, t, n) {}
824
- }, W = class {
578
+ };
579
+ //#endregion
580
+ //#region src/dopamine/feel/haptics.js
581
+ function ae({ nav: e = globalThis.navigator, enabled: t = !0 } = {}) {
582
+ let n = !!t, r = (t) => {
583
+ if (n) try {
584
+ e.vibrate(t);
585
+ } catch {}
586
+ };
587
+ return {
588
+ tap: () => r(10),
589
+ double: () => r([
590
+ 10,
591
+ 40,
592
+ 10
593
+ ]),
594
+ setEnabled(e) {
595
+ n = !!e;
596
+ }
597
+ };
598
+ }
599
+ //#endregion
600
+ //#region src/dopamine/utils/TextureGenerator.js
601
+ var oe = class {
825
602
  static createGround(e, t, n = "#333") {
826
603
  let r = document.createElement("canvas");
827
604
  r.width = e, r.height = t;
@@ -843,16 +620,16 @@ var M = class {
843
620
  let r = n.getContext("2d");
844
621
  for (let n = 0; n < 4; n++) {
845
622
  let i = n * 64 + 32, a = n % 2 == 0 ? 0 : -2, o = n === 1 ? 5 : n === 3 ? -5 : 0;
846
- r.fillStyle = e, r.beginPath(), r.arc(i, 32 + a, 20, 0, Math.PI * 2), r.fill(), r.fillStyle = t, r.beginPath(), r.arc(i - 15, 32 + a + o, 8, 0, Math.PI * 2), r.arc(i + 15, 32 + a - o, 8, 0, Math.PI * 2), r.fill(), r.fillStyle = G(e, -20), r.beginPath(), r.arc(i, 32 + a, 15, 0, Math.PI * 2), r.fill(), t === "#333" && (r.fillStyle = "#000", r.fillRect(i + 10, 32 + a - 5, 25, 6));
623
+ r.fillStyle = e, r.beginPath(), r.arc(i, 32 + a, 20, 0, Math.PI * 2), r.fill(), r.fillStyle = t, r.beginPath(), r.arc(i - 15, 32 + a + o, 8, 0, Math.PI * 2), r.arc(i + 15, 32 + a - o, 8, 0, Math.PI * 2), r.fill(), r.fillStyle = se(e, -20), r.beginPath(), r.arc(i, 32 + a, 15, 0, Math.PI * 2), r.fill(), t === "#333" && (r.fillStyle = "#000", r.fillRect(i + 10, 32 + a - 5, 25, 6));
847
624
  }
848
625
  return n;
849
626
  }
850
627
  };
851
- function G(e, t) {
628
+ function se(e, t) {
852
629
  return e;
853
630
  }
854
631
  //#endregion
855
632
  //#region src/index.js
856
- var K = R;
633
+ var ce = Z;
857
634
  //#endregion
858
- export { g as Animator, n as Collider, b as Component, M as DataService, a as Director, y as DopamineKernel, e as EventBus, C as EventEmitter, _ as Game, m as GameObject, P as GameUI, h as GlobalInput, o as GlobalLoader, l as GlobalPhysics, H as IAudioSystem, U as IParticleSystem, V as IPhysicsSystem, z as ISystem, f as Input, s as Loader, p as ParticleEmitter, F as ParticleSystem, c as Physics, x as PluginRegistry, i as Renderer, k as RewardSystem, d as Scene, v as ScreenShake, L as SoundManager, u as Sprite, B as System, t as SystemRegistry, W as TextureGenerator, S as Ticker, r as Vector2, A as createMemoryStorage, K as default, j as resolveStorage };
635
+ export { b as Animator, s as Collider, w as Component, i as DataService, u as Director, C as DopamineKernel, a as EventBus, e as EventEmitter, x as Game, v as GameObject, G as GameUI, y as GlobalInput, d as GlobalLoader, m as GlobalPhysics, $ as IAudioSystem, ie as IParticleSystem, re as IPhysicsSystem, Q as ISystem, g as Input, f as Loader, _ as ParticleEmitter, J as ParticleSystem, p as Physics, T as PluginRegistry, l as Renderer, t as RewardSystem, h as Scene, S as ScreenShake, X as SoundManager, ee as Sprite, ne as System, o as SystemRegistry, oe as TextureGenerator, E as Ticker, c as Vector2, ae as createHaptics, n as createMemoryStorage, ce as default, q as prefersReducedMotion, r as resolveStorage };