dopaminejs 2.5.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +55 -50
  2. package/dist/DataService-D1uL6E8R.cjs +1 -0
  3. package/dist/DataService-DN6xwvXU.js +745 -0
  4. package/dist/core.cjs +1 -1
  5. package/dist/core.js +2 -2
  6. package/dist/dopamine.cjs +1 -37
  7. package/dist/dopamine.js +3 -635
  8. package/dist/games.cjs +1 -0
  9. package/dist/games.js +82 -0
  10. package/dist/host-7FzZ-yO7.cjs +37 -0
  11. package/dist/host-CdjhXPy-.js +815 -0
  12. package/dist/style.css +395 -2
  13. package/dist/testing.cjs +1 -0
  14. package/dist/testing.js +475 -0
  15. package/package.json +24 -9
  16. package/spec/README.md +228 -0
  17. package/spec/VERSION +1 -0
  18. package/spec/fixtures/achievements.json +611 -0
  19. package/spec/fixtures/levels.json +421 -0
  20. package/spec/fixtures/merge.json +1739 -0
  21. package/spec/fixtures/migrate.json +957 -0
  22. package/spec/fixtures/scores.json +755 -0
  23. package/spec/fixtures/streaks.json +967 -0
  24. package/spec/schema.json +61 -0
  25. package/src/dopamine/audio/SoundManager.js +54 -24
  26. package/src/dopamine/core/DopamineError.js +7 -0
  27. package/src/dopamine/core/RewardSystem.js +359 -374
  28. package/src/dopamine/core/achievements.js +49 -0
  29. package/src/dopamine/core/clock.js +11 -0
  30. package/src/dopamine/core/levels.js +4 -0
  31. package/src/dopamine/core/merge.js +68 -0
  32. package/src/dopamine/core/middleware.js +58 -0
  33. package/src/dopamine/core/store.js +261 -0
  34. package/src/dopamine/core/streaks.js +55 -0
  35. package/src/dopamine/effects/ParticleSystem.js +30 -0
  36. package/src/dopamine/host.js +360 -0
  37. package/src/dopamine/ui/{GameUI.js → RewardUI.js} +166 -202
  38. package/src/games.js +138 -0
  39. package/src/index.js +11 -34
  40. package/src/progression.js +3 -0
  41. package/src/testing.js +490 -0
  42. package/types/core.d.ts +9 -1
  43. package/types/games.d.ts +46 -0
  44. package/types/index.d.ts +311 -385
  45. package/types/testing.d.ts +96 -0
  46. package/dist/DataService-BPXCldpo.cjs +0 -1
  47. package/dist/DataService-CH9_gv_8.js +0 -398
  48. package/dist/ScreenShake-9jgNXPS6.cjs +0 -1
  49. package/dist/ScreenShake-CLvO1wx4.js +0 -827
  50. package/dist/engine.cjs +0 -1
  51. package/dist/engine.js +0 -2
  52. package/src/core/Animator.js +0 -62
  53. package/src/core/Collider.js +0 -86
  54. package/src/core/Component.js +0 -38
  55. package/src/core/DopamineKernel.js +0 -170
  56. package/src/core/EventBus.js +0 -206
  57. package/src/core/Game.js +0 -90
  58. package/src/core/GameObject.js +0 -99
  59. package/src/core/PluginRegistry.js +0 -359
  60. package/src/core/Scene.js +0 -107
  61. package/src/core/Sprite.js +0 -51
  62. package/src/core/SystemRegistry.js +0 -263
  63. package/src/core/Vector2.js +0 -50
  64. package/src/dopamine/components/ParticleEmitter.js +0 -50
  65. package/src/dopamine/components/ScreenShake.js +0 -50
  66. package/src/dopamine/components/index.js +0 -2
  67. package/src/dopamine/index.js +0 -93
  68. package/src/dopamine/utils/TextureGenerator.js +0 -90
  69. package/src/engine.js +0 -38
  70. package/src/interfaces/IAudioSystem.js +0 -58
  71. package/src/interfaces/IParticleSystem.js +0 -51
  72. package/src/interfaces/IPhysicsSystem.js +0 -52
  73. package/src/interfaces/ISystem.js +0 -48
  74. package/src/interfaces/index.js +0 -7
  75. package/src/renderer/Renderer.js +0 -45
  76. package/src/systems/Director.js +0 -34
  77. package/src/systems/Input.js +0 -81
  78. package/src/systems/Loader.js +0 -48
  79. package/src/systems/Physics.js +0 -210
  80. package/src/systems/Ticker.js +0 -91
  81. package/src/systems/deprecate.js +0 -38
package/dist/games.js ADDED
@@ -0,0 +1,82 @@
1
+ //#region src/games.js
2
+ var e = {
3
+ combo: "{n}× COMBO!",
4
+ nearMiss: "CLOSE CALL!",
5
+ luckyMoment: "LUCKY {n}×!",
6
+ gameOver: "Game Over",
7
+ playAgain: "Play Again",
8
+ exit: "Exit"
9
+ }, t = (e, t) => Object.prototype.hasOwnProperty.call(e, t), n = {
10
+ jump: (e) => e.playTone(400, .1, "square", .2),
11
+ score: (e, t) => {
12
+ e.playTone(800, .15, "sine", .25), t(() => e.playTone(1e3, .15, "sine", .25), 50);
13
+ },
14
+ gameover: (e, t) => {
15
+ e.playTone(300, .2, "sawtooth", .3), t(() => e.playTone(200, .2, "sawtooth", .3), 100), t(() => e.playTone(150, .3, "sawtooth", .3), 200);
16
+ }
17
+ }, r = (e, t, n) => {
18
+ let r = document.createElement(e);
19
+ return t !== void 0 && (r.textContent = t), n && (r.style.cssText = n), r;
20
+ };
21
+ function i(i) {
22
+ let a = { ...e }, o = typeof i == "object" && i && t(i, "text") ? i.text : null;
23
+ for (let n of Object.keys(e)) typeof o == "object" && o && t(o, n) && typeof o[n] == "string" && (a[n] = o[n]);
24
+ let s = null, c = /* @__PURE__ */ new Set(), l = (e, t, n, r, i, o) => {
25
+ let c = a[e].replace("{n}", () => String(t));
26
+ c !== "" && s.parts.ui.text({
27
+ text: c,
28
+ x: n,
29
+ y: r,
30
+ color: i,
31
+ size: o
32
+ });
33
+ }, u = (e, t, n, r) => s.parts.particles?.burst(e, {
34
+ x: t,
35
+ y: n
36
+ }, r), d = {
37
+ name: "games",
38
+ version: "1.0.0",
39
+ api: 3,
40
+ requires: ["ui"],
41
+ combo(e, t, n) {
42
+ s && (l("combo", e, t, n, "#ff6b6b", "32px"), u("fire", t, n, { count: 20 }));
43
+ },
44
+ nearMiss(e, t) {
45
+ s && (l("nearMiss", "", e, t, "#45b7d1", "20px"), u("sparkle", e, t, {
46
+ count: 15,
47
+ color: "#45b7d1"
48
+ }));
49
+ },
50
+ luckyMoment(e, t, n) {
51
+ s && (l("luckyMoment", e, t, n, "#ffd700", "36px"), u("stars", t, n, { count: 12 }), u("confetti", t, n, { count: 25 }));
52
+ },
53
+ summary(e) {
54
+ if (!s || !s.env.hasDom || typeof e != "object" || !e) return null;
55
+ let t = r("div", void 0, "display:flex;flex-direction:column;align-items:center;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:1000");
56
+ t.className = "message-box", a.gameOver !== "" && t.append(r("h1", a.gameOver)), t.append(r("div", e.score, "font-size:3rem;font-weight:bold;color:#e06020;margin:10px 0"));
57
+ let n = r("div", void 0, "width:100%;margin-bottom:20px"), i = e.metrics !== null && typeof e.metrics == "object" ? e.metrics : {};
58
+ for (let [e, t] of Object.entries(i)) {
59
+ let i = r("div", void 0, "display:flex;justify-content:space-between;width:100%");
60
+ i.append(r("span", `${e}:`), r("strong", t)), n.append(i);
61
+ }
62
+ t.append(n);
63
+ let o = (e, n) => {
64
+ let i = r("button", e);
65
+ i.className = "btn", i.addEventListener("click", n), t.append(i);
66
+ };
67
+ return a.playAgain !== "" && o(a.playAgain, typeof e.onReplay == "function" ? e.onReplay : () => window.location.reload()), typeof e.onExit == "function" && a.exit !== "" && o(a.exit, e.onExit), document.body.append(t), c.add(t), t;
68
+ },
69
+ install(e) {
70
+ s = e;
71
+ let t = Object.keys(n).map((e) => s.parts.sound?.register?.(e, n[e]));
72
+ return e.expose(d), () => {
73
+ for (let e of t) e?.();
74
+ for (let e of c) e.remove();
75
+ c.clear(), s = null;
76
+ };
77
+ }
78
+ };
79
+ return d;
80
+ }
81
+ //#endregion
82
+ export { i as gameFeedback };
@@ -0,0 +1,37 @@
1
+ const e=require("./DataService-D1uL6E8R.cjs");var t=`#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{z-index:10000;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:16px;max-width:320px;padding:16px;animation:.5s cubic-bezier(.68,-.55,.265,1.55) slideIn;position:fixed;top:80px;right:20px;overflow:hidden;box-shadow:0 8px 32px #0006}.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:#ffffffe6;text-transform:uppercase;letter-spacing:.5px;font-size:12px;font-weight:600}.achievement-name{color:#fff;margin:2px 0;font-size:18px;font-weight:800}.achievement-desc{color:#fffc;margin-bottom:4px;font-size:13px}.achievement-xp{color: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{max-width:calc(100% - 24px);right:12px}.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}}`,n=`game-ui-overlay`,r={levelUp:`LEVEL UP!`,achievementUnlocked:`Achievement Unlocked!`},i=`dopamine-reward-ui-css`,a=`🔥`,o=e=>e==null?``:String(e),s=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),c=(e,t)=>typeof e==`object`&&e&&s(e,t)?e[t]:void 0,l=`http://www.w3.org/2000/svg`,u=new Set([`svg`,`g`,`path`,`circle`,`ellipse`,`rect`,`line`,`polyline`,`polygon`,`text`,`tspan`,`title`,`desc`,`defs`,`linearGradient`,`radialGradient`,`stop`,`clipPath`,`mask`]),d=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(`.`)),f=new Set([`fill`,`stroke`,`clip-path`,`mask`]),p=new Set([`transform`,`gradientTransform`]),m=/^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/,h=/^[#a-zA-Z0-9(),.%\s-]+$/,g=/^[a-zA-Z0-9(),.\s-]+$/,_=/^[A-Za-z][\w.:-]*$/,v=0;function y(e,t){if(e.nodeType!==1||e.namespaceURI!==l||!u.has(e.localName))return;let n=e.getAttribute(`id`);n&&_.test(n)&&t.add(n);for(let n of Array.from(e.childNodes))y(n,t)}function b(e,t,n){if(t.includes(`\\`))return null;let r=t.trim();if(e===`id`)return _.test(r)?n.prefix+r:null;if(f.has(e)){let e=m.exec(r);return e?n.ids.has(e[1])?`url(#${n.prefix}${e[1]})`:null:h.test(r)&&!/url/i.test(r)?r:null}return p.has(e)?g.test(r)&&!/url/i.test(r)?r:null:t.includes(`(`)?e===`stop-color`&&h.test(r)&&!/url/i.test(r)?r:null:t}function x(e,t){if(e.nodeType===3||e.nodeType===4)return document.createTextNode(e.data);if(e.nodeType!==1||e.namespaceURI!==l||!u.has(e.localName))return null;let n=document.createElementNS(l,e.localName);for(let r of Array.from(e.attributes)){if(r.namespaceURI!==null||!d.has(r.name))continue;let e=b(r.name,r.value,t);e!==null&&n.setAttribute(r.name,e)}for(let r of Array.from(e.childNodes)){let e=x(r,t);e&&n.appendChild(e)}return n}function S(e){let t,n=/^\s*<svg[\s>]/.test(e)&&!/^\s*<svg\b[^>]*\sxmlns\s*=/.test(e)?e.replace(/^(\s*<svg)/,`$1 xmlns="${l}"`):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 y(r,i),x(r,{ids:i,prefix:`dj-icon-${++v}-`})}var C=class{constructor(e={},t={}){this.parts=e||{};let n=c(t,`text`);this.strings={...r};for(let e of Object.keys(r)){let t=c(n,e);typeof t==`string`&&(this.strings[e]=t)}this.safeIcons=c(t,`safeIcons`)!==!1,this._streakIcon=c(c(t,`icons`),`streak`)??a,this._injectCss=c(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._build()}get root(){return this.container}_build(){this._injectCss&&this._addStyles(),this.container=document.createElement(`div`),this.container.className=`game-ui-overlay`,document.getElementById(n)||(this.container.id=n),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(i))return;let e=typeof this._injectCss==`string`?this._injectCss:t;this._style=document.createElement(`style`),this._style.id=i,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=S(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=c(e,`kind`);t===`level`?this._levelPopup(e):t===`notice`?this._notice(e):this._card(e,t===`achievement`)}_card(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=o(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=o(e.body),n.querySelector(`.achievement-xp`).textContent=o(e.meta),this._mount(n),this._announce(t?`${this.strings.achievementUnlocked}: ${r}`:r),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),300)},4e3)}_levelPopup(e){let t=typeof e.title==`string`&&e.title!==``?e.title:this.strings.levelUp,n=o(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=o(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=o(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();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}},w=Object.freeze({matches:!1});function T(e=globalThis.window){return typeof e?.matchMedia==`function`&&e.matchMedia(`(prefers-reduced-motion: reduce)`)||w}var E=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),D={confetti:(e,t,n,r)=>e.confetti(t,n,r),sparkle:(e,t,n,r,i)=>e.sparkle(t,n,r,i),fire:(e,t,n,r)=>e.fire(t,n,r),stars:(e,t,n,r)=>e.starBurst(t,n,r),coins:(e,t,n,r)=>e.coinShower(t,n,r)},O=class{constructor(e={}){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:T(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=new Map,this.customEffects=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)}_resize(){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;this.width=e,this.height=t,this.canvas.width=Math.round(e*n),this.canvas.height=Math.round(t*n),this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.ctx.setTransform(n,0,0,n,0,0)}registerSprite(e,t){let n=new Image;n.src=t,this.sprites.set(e,n)}registerEffect(e,t){this.customEffects.set(e,t)}play(e,t,n,...r){typeof t==`object`&&t&&(r=n===void 0?[]:[n,...r],{x:t,y:n}=t);let i=this.customEffects.get(e);i?i(t,n,...r):console.warn(`[DopamineJS] Effect '${e}' not found.`)}emit(e){let{x:t,y:n,count:r=10,speed:i=5,gravity:a=.1,decay:o=.02,life:s=1,color:c=`#ffd700`,sprite:l=null,spread:u=Math.PI*2,angle:d=0,size:f=5,type:p=null}=e,m=this._allowed(r);for(let e=0;e<m;e++){let e=this._getParticle(),r=d+(Math.random()-.5)*u,m=Math.random()*i;e.x=t,e.y=n,e.vx=Math.cos(r)*m,e.vy=Math.sin(r)*m,e.life=s,e.decay=o*(.8+Math.random()*.4),e.gravity=a,e.color=Array.isArray(c)?c[Math.floor(Math.random()*c.length)]:c,e.size=f*(.8+Math.random()*.4),e.sprite=l,e.type=p,e.rotation=Math.random()*Math.PI*2,e.rotationSpeed=(Math.random()-.5)*.2,this.particles.push(e)}m>0&&this._startAnimation()}_allowed(e){if(this._reducedMotion?.matches||!Number.isFinite(e))return 0;let t=this.maxParticles-this.particles.length;return Math.max(0,Math.min(Math.floor(e),t))}_getParticle(){return this.pool.length>0?this.pool.pop():{}}_recycleParticle(e){this.pool.push(e)}burst(e,t,n){if(typeof e!=`string`||!E(D,e))return;let r=Number.isFinite(t?.x)?t.x:this.width/2,i=Number.isFinite(t?.y)?t.y:this.height/2,a=Number.isFinite(n?.count)?n.count:void 0;D[e](this,r,i,a,n?.color)}confetti(e,t,n=50){this.emit({x:e,y:t,count:n,color:[`#ff6b6b`,`#4ecdc4`,`#45b7d1`,`#f7dc6f`,`#c06c84`,`#6c5ce7`],speed:10,gravity:.3,decay:.015,size:8,spread:Math.PI*2})}coinShower(e,t,n=10){this.emit({x:e,y:t,count:n,color:`#ffd700`,speed:4,gravity:.4,decay:.012,size:12,angle:-Math.PI/2,spread:Math.PI/2})}sparkle(e,t,n=20,r=`#ffd700`){this.emit({x:e,y:t,count:n,color:r,speed:3,gravity:-.05,decay:.03,size:3})}fire(e,t,n=15){this.emit({x:e,y:t,count:n,color:[`#ff6b00`,`#ff8800`,`#ffaa00`,`#ff4400`],speed:3,gravity:-.2,decay:.04,size:5,angle:-Math.PI/2,spread:Math.PI/4})}starBurst(e,t,n=8){let r=this._allowed(n);for(let n=0;n<r;n++){let i=this._getParticle(),a=Math.PI*2/r*n;i.x=e,i.y=t,i.vx=Math.cos(a)*4,i.vy=Math.sin(a)*4,i.life=1,i.decay=.03,i.gravity=0,i.color=`#ffffff`,i.size=15,i.sprite=null,i.type=`star`,i.rotation=a,i.rotationSpeed=0,this.particles.push(i)}r>0&&this._startAnimation()}_startAnimation(){this.isAnimating||(this.isAnimating=!0,this._lastFrameTime=null,this._animate())}_animate(e){this._frameHandle=null,this.ctx.clearRect(0,0,this.width,this.height);let t=1;Number.isFinite(e)&&(this._lastFrameTime!==null&&(t=Math.max(0,Math.min(3,(e-this._lastFrameTime)/(1e3/60)))),this._lastFrameTime=e);for(let e=this.particles.length-1;e>=0;e--){let n=this.particles[e];if(n.vy+=n.gravity*t,n.x+=n.vx*t,n.y+=n.vy*t,n.life-=n.decay*t,n.rotationSpeed&&(n.rotation+=n.rotationSpeed*t),n.life<=0){this._recycleParticle(n);let t=this.particles.pop();e<this.particles.length&&(this.particles[e]=t);continue}if(this.ctx.save(),this.ctx.globalAlpha=n.life,this.ctx.translate(n.x,n.y),this.ctx.rotate(n.rotation),n.sprite&&this.sprites.has(n.sprite)){let e=this.sprites.get(n.sprite);e.complete&&this.ctx.drawImage(e,-n.size/2,-n.size/2,n.size,n.size)}else n.type===`star`?(this.ctx.fillStyle=n.color,this._drawStarPath(0,0,5,n.size,n.size/2),this.ctx.fill()):(this.ctx.fillStyle=n.color,this.ctx.beginPath(),this.ctx.arc(0,0,n.size,0,Math.PI*2),this.ctx.fill());this.ctx.restore()}this.particles.length>0?this._frameHandle=requestAnimationFrame(e=>this._animate(e)):this.isAnimating=!1}_drawStarPath(e,t,n,r,i){let a=Math.PI/2*3,o=e,s=t,c=Math.PI/n;this.ctx.beginPath(),this.ctx.moveTo(e,t-r);for(let l=0;l<n;l++)o=e+Math.cos(a)*r,s=t+Math.sin(a)*r,this.ctx.lineTo(o,s),a+=c,o=e+Math.cos(a)*i,s=t+Math.sin(a)*i,this.ctx.lineTo(o,s),a+=c;this.ctx.lineTo(e,t-r),this.ctx.closePath()}clear(){this.particles.forEach(e=>this._recycleParticle(e)),this.particles=[],this.ctx.clearRect(0,0,this.width,this.height)}destroy(){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=[]}},k=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),A=class{constructor(t={}){this.audioContext=null,this.storageKey=t.storageKey||`dopamineSoundsMuted`,this.storage=t.storage||e.r(),this.muted=this.storage.getItem(this.storageKey)===`true`,this.assets=new Map,this.customSounds=t.customSounds||{},this.masterGain=null,this._volume=1,this.setVolume(t.volume??1),this._loading=new Map,this._timers=new Set,this._synths=new Map,this._unlocks=new Set}unlockOn(e,t=[`pointerup`,`touchend`,`keydown`]){let n=()=>{for(let n of t)e.removeEventListener(n,r);this._unlocks.delete(n)},r=()=>{n(),this.initAudio()};for(let n of t)e.addEventListener(n,r);return this._unlocks.add(n),n}_later(e,t){let n=setTimeout(()=>{this._timers.delete(n),e()},t);this._timers.add(n)}initAudio(){if(!this.audioContext){let e=typeof window<`u`?window.AudioContext||window.webkitAudioContext:void 0;if(!e)return!1;this.audioContext=new e,this.masterGain=this.audioContext.createGain(),this.masterGain.gain.value=this._volume,this.masterGain.connect(this.audioContext.destination),this.preloadSounds(this.customSounds)}return this.audioContext.state===`suspended`&&this.audioContext.resume(),!0}setVolume(e){return Number.isFinite(e)?(this._volume=Math.max(0,Math.min(1,e)),this.masterGain&&(this.masterGain.gain.value=this._volume),this._volume):this._volume}getVolume(){return this._volume}_output(){return this.masterGain||this.audioContext.destination}toggleMute(){return this.muted=!this.muted,this.storage.setItem(this.storageKey,this.muted),this.muted}registerSound(e,t){this.customSounds[e]=t,this.audioContext&&this.loadSound(e,t)}register(e,t){return typeof e!=`string`||e===``?()=>{}:typeof t==`string`?(this.registerSound(e,t),()=>{this.customSounds[e]===t&&delete this.customSounds[e],this.assets.delete(e)}):typeof t==`function`?(this._synths.set(e,t),()=>{this._synths.get(e)===t&&this._synths.delete(e)}):()=>{}}async preloadSounds(e){let t=Object.entries(e).map(([e,t])=>(this.customSounds[e]=t,this.loadSound(e,t)));await Promise.allSettled(t)}async loadSound(e,t){if(!this.audioContext)return;if(this._loading.has(e))return this._loading.get(e);let n=this._load(e,t).finally(()=>this._loading.delete(e));return this._loading.set(e,n),n}async _load(e,t){try{let n=this.audioContext,r=await fetch(t);if(r.ok===!1)throw Error(`HTTP ${r.status}`);let i=await r.arrayBuffer(),a=await n.decodeAudioData(i);this.audioContext===n&&this.assets.set(e,a)}catch(t){console.warn(`[DopamineJS] Failed to load sound '${e}':`,t)}}async play(e){if(this.muted||!this.initAudio())return;if(this.assets.has(e)){this._playBuffer(this.assets.get(e));return}if(k(this.customSounds,e)&&!this.assets.has(e)){let t=this.audioContext;if(await this.loadSound(e,this.customSounds[e]),this.audioContext!==t)return;if(this.assets.has(e)){this._playBuffer(this.assets.get(e));return}}let t={xp:()=>this.playXP(!0),level_up:()=>this.playLevelUp(!0),achievement:()=>this.playAchievement(!0),personal_best:()=>this.playPersonalBest(!0),click:()=>this.playClick(!0),error:()=>this.playError(!0)};this._synths.has(e)?this._synths.get(e)(this,(e,t)=>this._later(e,t)):k(t,e)&&t[e]()}_playBuffer(e){let t=this.audioContext.createBufferSource();t.buffer=e,t.connect(this._output()),t.start(0)}playTone(e,t,n=`sine`,r=.3){if(this.muted||!this.initAudio())return;let i=this.audioContext.createOscillator(),a=this.audioContext.createGain();i.connect(a),a.connect(this._output()),i.frequency.value=e,i.type=n;let o=Math.max(1e-4,r);a.gain.setValueAtTime(o,this.audioContext.currentTime),a.gain.exponentialRampToValueAtTime(.01,this.audioContext.currentTime+t),i.start(this.audioContext.currentTime),i.stop(this.audioContext.currentTime+t)}playClick(e=!1){if(!e&&this.assets.has(`click`))return this.play(`click`);this.playTone(600,.05,`sine`,.1)}playXP(e=!1){if(!e&&this.assets.has(`xp`))return this.play(`xp`);this.playTone(700,.06,`sine`,.12)}playLevelUp(e=!1){if(!e&&this.assets.has(`level_up`))return this.play(`level_up`);this.playTone(500,.12,`sine`,.2),this._later(()=>this.playTone(700,.12,`sine`,.2),110),this._later(()=>this.playTone(900,.25,`sine`,.2),220)}playAchievement(e=!1){if(!e&&this.assets.has(`achievement`))return this.play(`achievement`);this.playTone(660,.1,`triangle`,.2),this._later(()=>this.playTone(990,.25,`triangle`,.2),100)}playPersonalBest(e=!1){if(!e&&this.assets.has(`personal_best`))return this.play(`personal_best`);this.playTone(600,.1,`sine`,.2),this._later(()=>this.playTone(800,.2,`sine`,.2),100)}playError(e=!1){if(!e&&this.assets.has(`error`))return this.play(`error`);this.playTone(200,.2,`sawtooth`,.3)}destroy(){for(let e of[...this._unlocks])e();for(let e of this._timers)clearTimeout(e);this._timers.clear(),this.audioContext&&(this.audioContext.close?.())?.catch?.(()=>{}),this.audioContext=null,this.masterGain=null,this.assets.clear(),this._loading.clear(),this._synths.clear()}};function j({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 M=3,N=[`ui`,`particles`,`sound`,`haptics`],P=e=>typeof e==`object`&&!!e&&typeof e.then==`function`,F=(e,t)=>{P(e)&&e.then(void 0,e=>t.error(e))};function I(){let e=typeof document<`u`&&typeof window<`u`;return{hasDom:e,reducedMotion:e?T(window).matches===!0:!1}}function L(e,t,n){if(e===!1)return null;let r=e;return typeof e==`function`&&(r=e(t)),r??n()}function R(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 z(t={}){let n=t||{},r=I(),i={debug:()=>{},info:()=>{},warn:(...e)=>console.warn(...e),error:(...e)=>console.error(...e),...n.log||{}},a=n.storage||e.r(),o=n.clock||e.s,s={ui:null,particles:null,sound:null,haptics:null},c={};for(let e of N)Object.defineProperty(c,e,{enumerable:!0,get:()=>s[e]});Object.freeze(c);let l={...r,parts:c,storage:a,clock:o},u=L(n.progress,l,()=>new e.i(new e.t({storage:a}),{clock:o,streakDays:n.streakDays,builtinAchievements:n.builtinAchievements}));if(typeof u?.on!=`function`||typeof u?.off!=`function`)throw new e.c(`invalid_progress`,`progress needs on() and off()`);s.particles=L(n.particles,l,()=>r.hasDom?new O:null),s.sound=L(n.sound,l,()=>new A({storage:a})),s.haptics=L(n.haptics,l,()=>j());try{s.ui=L(n.ui,l,()=>r.hasDom?new C(c):null)}catch(e){throw d(),e}function d(){for(let e of N)try{s[e]?.destroy?.()}catch(e){i.error(e)}}let f=u,p=[],m=!1,h=e=>t=>{try{F(e(t),i)}catch(e){i.error(e)}},g=()=>{let e=s.ui;if(!e||typeof u.snapshot!=`function`||typeof u.getXPForNextLevel!=`function`)return;let t=u.snapshot(),{total:n,progress:r}=u.getXPForNextLevel();e.hud({xp:t.xp,level:t.level,progress:r,streak:t.streak.current,next:n})};p.push(f.on(`xp_gained`,h(e=>{g(),e.leveledUp||s.sound?.play(`xp`)})),f.on(`level_up`,h(e=>{g(),s.ui?.popup({kind:`level`,title:``,body:String(e.newLevel)}),s.sound?.play(`level_up`)})),f.on(`achievement_unlocked`,h(e=>{s.ui?.popup({kind:`achievement`,title:e.name,body:e.description,icon:e.icon,meta:`+${e.xp??0} XP`}),s.sound?.play(`achievement`)})),f.on(`streak_updated`,h(g)),f.on(`player_reset`,h(g)),f.on(`personal_best`,h(e=>{s.ui?.popup({kind:`notice`,title:`New High Score: ${e.score}!`,tier:`legendary`}),s.sound?.play(`personal_best`)})));let _=new Map,v=[];function y(t){if(typeof t!=`object`||!t||typeof t.name!=`string`||!/^[a-z0-9-]+$/.test(t.name)||typeof t.install!=`function`)throw new e.c(`plugin_invalid`,`a plugin needs a name (a-z, 0-9 and -) and an install function`);if(t.api!==3)throw new e.c(`plugin_api`,`${t.name} was built for api ${t.api}, this host is api 3`);if(_.has(t.name))throw new e.c(`plugin_duplicate`,`${t.name} is already installed`);for(let n of t.after||[])if(!_.has(n)||!_.get(n).done)throw new e.c(`plugin_order`,`${t.name} must come after ${n}`);for(let n of t.requires||[])if(!N.includes(n)||s[n]===null)throw new e.c(`plugin_requires`,`${t.name} requires the ${n} part, which is not set`)}function b(e){for(let t of e.offs)t();e.offs.clear(),_.delete(e.name);let t=v.indexOf(e);t>-1&&v.splice(t,1)}function x(e){if(e.removed)return;e.removed=!0;let t=e.disposer;e.disposer=null;try{t?.()}catch(e){i.error(e)}b(e)}function S(t){let{name:n}=t;return{progress:u,parts:c,events:{on(e,n){let r=f.on(e,n),i=()=>{r(),t.offs.delete(i)};return t.offs.add(i),i},off:(e,t)=>f.off(e,t),emit(t,r){if(typeof t!=`string`||!t.startsWith(`${n}:`))throw new e.c(`plugin_event`,`${n} may only emit events named ${n}:<event>`);f.emit(t,r)}},storage:R(a,n),clock:o,log:i,env:{hasDom:r.hasDom,reducedMotion:r.reducedMotion},plugin:e=>_.has(e)&&_.get(e).done?_.get(e).handle:null,expose:e=>{t.handle=e}}}function w(t){if(m)throw new e.c(`disposed`,`the host was disposed`);y(t);let n={name:t.name,done:!1,removed:!1,disposer:null,handle:null,offs:new Set};_.set(t.name,n);let r=e=>(n.done=!0,typeof e==`function`&&(n.disposer=e),n.removed||m?(n.removed=!1,x(n),n):(v.push(n),n)),i=e=>{throw b(n),e},a;try{a=t.install(S(n))}catch(e){return i(e)}return P(a)?a.then(r,i):r(a)}let T=null;function E(t){if(m)throw new e.c(`disposed`,`the host was disposed`);if(T===null){let e=w(t);if(P(e)){let t=e.then(e=>e,e=>{throw e});return T=t.then(()=>{T=null},()=>{T=null}),{record:null,done:t}}return{record:e,done:Promise.resolve(e)}}let n=T.then(()=>w(t));return T=n.then(()=>{T=null},()=>{T=null}),{record:null,done:n}}function D(e){let{record:t,done:n}=E(e);if(t)return()=>x(t);let r=null,a=!1;return n.then(e=>{r=e,a&&x(e)},e=>i.error(e)),()=>{r?x(r):a=!0}}let k=Promise.resolve();try{for(let e of n.plugins||[]){let{done:t}=E(e);k=k.then(()=>t)}}catch(e){throw M(),e}k=k.catch(e=>{throw M(),e});function M(){if(!m){m=!0;for(let e of[...v].reverse())x(e);for(let e of[..._.values()])x(e);for(let e of p)e();p.length=0,d(),u.clear?.()}}let z=k.then(()=>typeof u.init==`function`?u.init():void 0).then(()=>(m||g(),B));z.catch(()=>{});let B={progress:u,parts:c,events:f,ready:z,use:D,dispose:M};return B}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return M}});