dopaminejs 3.5.0 → 3.7.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/README.md +52 -2
- package/dist/{DataService-QQBNqJtN.js → DataService-B5noGvMr.js} +228 -254
- package/dist/DataService-DKCk0nOu.cjs +1 -0
- package/dist/SoundManager-C6VdZEFo.js +308 -0
- package/dist/SoundManager-DBGDYIkz.cjs +1 -0
- package/dist/celebrate.cjs +1 -0
- package/dist/celebrate.js +103 -0
- package/dist/certificate.cjs +1 -0
- package/dist/certificate.js +234 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +3 -1
- package/dist/dopamine.cjs +1 -1
- package/dist/dopamine.global.js +4 -4
- package/dist/dopamine.js +5 -3
- package/dist/host-BWKiYtjY.cjs +37 -0
- package/dist/host-Bhf9EqSk.js +457 -0
- package/dist/icon-BakWSiz_.js +89 -0
- package/dist/icon-gkpxMw48.cjs +1 -0
- package/dist/storage-B6z-zaBe.cjs +1 -0
- package/dist/storage-C2s4Da9b.js +26 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.js +3 -2
- package/package.json +15 -3
- package/src/celebrate.js +213 -0
- package/src/certificate.js +391 -0
- package/src/dopamine/effects/ParticleSystem.js +5 -1
- package/src/dopamine/ui/RewardUI.js +13 -154
- package/src/dopamine/ui/icon.js +157 -0
- package/types/celebrate.d.ts +39 -0
- package/types/certificate.d.ts +30 -0
- package/types/index.d.ts +2 -0
- package/dist/DataService-Xk7egYXe.cjs +0 -1
- package/dist/host-1c7QSAKI.cjs +0 -37
- package/dist/host-_essSMef.js +0 -835
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const e=require("./DataService-DKCk0nOu.cjs"),t=require("./icon-gkpxMw48.cjs"),n=require("./SoundManager-DBGDYIkz.cjs"),r=require("./storage-B6z-zaBe.cjs");var i=`#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}}`,a=`game-ui-overlay`,o={levelUp:`LEVEL UP!`,achievementUnlocked:`Achievement Unlocked!`},s=`dopamine-reward-ui-css`,c=`🔥`,l=e=>e==null?``:String(e),u=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),d=(e,t)=>typeof e==`object`&&e&&u(e,t)?e[t]:void 0,f=class{constructor(e={},t={}){this.parts=e||{};let n=d(t,`text`);this.strings={...o};for(let e of Object.keys(o)){let t=d(n,e);typeof t==`string`&&(this.strings[e]=t)}this.safeIcons=d(t,`safeIcons`)!==!1,this._streakIcon=d(d(t,`icons`),`streak`)??c,this._injectCss=d(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(a)||(this.container.id=a),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`),t.n(this.container.querySelector(`.streak-icon`),this._streakIcon,this.safeIcons)}_addStyles(){if(document.getElementById(s))return;let e=typeof this._injectCss==`string`?this._injectCss:i;this._style=document.createElement(`style`),this._style.id=s,this._style.textContent=e,document.head.appendChild(this._style)}_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=d(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:d(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,n){let r=document.createElement(`div`);r.className=`achievement-popup`,r.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 i=l(e.title);r.querySelector(`.achievement-title`).textContent=n?this.strings.achievementUnlocked:``,t.n(r.querySelector(`.achievement-icon`),e.icon,this.safeIcons),r.querySelector(`.achievement-name`).textContent=i,r.querySelector(`.achievement-desc`).textContent=l(e.body),r.querySelector(`.achievement-xp`).textContent=l(e.meta),this._mount(r),this._announce(n?`${this.strings.achievementUnlocked}: ${i}`:i),e.burst!==!1&&this._defer(()=>{let e=r.getBoundingClientRect();this._burst(`confetti`,{x:e.left+e.width/2,y:e.top+e.height/2},{count:40})},300),this._defer(()=>{r.style.animation=`slideOut 0.3s ease-in forwards`,this._defer(()=>{this._remove(r),this._cardActive=!1,this._nextCard()},300)},4e3)}_levelPopup(e){let t=typeof e.title==`string`&&e.title!==``?e.title:this.strings.levelUp,n=l(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=l(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=l(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 p({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,h=[`ui`,`particles`,`sound`,`haptics`],g=e=>typeof e==`object`&&!!e&&typeof e.then==`function`,_=(e,t)=>{g(e)&&e.then(void 0,e=>t.error(e))};function v(){let e=typeof document<`u`&&typeof window<`u`;return{hasDom:e,reducedMotion:e?n.r(window).matches===!0:!1}}function y(e,t,n){if(e===!1)return null;let r=e;return typeof e==`function`&&(r=e(t)),r??n()}function b(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 x(t={}){let i=t||{},a=v(),o={debug:()=>{},info:()=>{},warn:(...e)=>console.warn(...e),error:(...e)=>console.error(...e),...i.log||{}},s=i.storage||r.n(),c=i.clock||e.a,l={ui:null,particles:null,sound:null,haptics:null},u={};for(let e of h)Object.defineProperty(u,e,{enumerable:!0,get:()=>l[e]});Object.freeze(u);let d={...a,parts:u,storage:s,clock:c},m=y(i.progress,d,()=>new e.n(new e.t({storage:s}),{clock:c,streakDays:i.streakDays,builtinAchievements:i.builtinAchievements,loadRetryMs:i.loadRetryMs}));if(typeof m?.on!=`function`||typeof m?.off!=`function`)throw new e.o(`invalid_progress`,`progress needs on() and off()`);l.particles=y(i.particles,d,()=>a.hasDom?new n.n:null),l.sound=y(i.sound,d,()=>new n.t({storage:s})),l.haptics=y(i.haptics,d,()=>p());try{l.ui=y(i.ui,d,()=>a.hasDom?new f(u):null)}catch(e){throw x(),e}function x(){for(let e of h)try{l[e]?.destroy?.()}catch(e){o.error(e)}}let S=m,C=[],w=!1,T=e=>t=>{try{_(e(t),o)}catch(e){o.error(e)}},E=()=>{let e=l.ui;if(!e||typeof m.snapshot!=`function`||typeof m.getXPForNextLevel!=`function`)return;let t=m.snapshot(),{total:n,progress:r}=m.getXPForNextLevel();e.hud({xp:t.xp,level:t.level,progress:r,streak:t.streak.current,next:n})};C.push(S.on(`xp_gained`,T(e=>{E(),e.leveledUp||l.sound?.play(`xp`)})),S.on(`level_up`,T(e=>{E(),l.ui?.popup({kind:`level`,title:``,body:String(e.newLevel)}),l.sound?.play(`level_up`)})),S.on(`achievement_unlocked`,T(e=>{l.ui?.popup({kind:`achievement`,title:e.name,body:e.description,icon:e.icon,meta:`+${e.xp??0} XP`}),l.sound?.play(`achievement`)})),S.on(`streak_updated`,T(E)),S.on(`player_reset`,T(E)),S.on(`load_recovered`,T(E)),S.on(`personal_best`,T(e=>{l.ui?.popup({kind:`notice`,title:`New High Score: ${e.score}!`,tier:`legendary`}),l.sound?.play(`personal_best`)})));let D=new Map,O=[];function k(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(D.has(t.name))throw new e.o(`plugin_duplicate`,`${t.name} is already installed`);for(let n of t.after||[])if(!D.has(n)||!D.get(n).done)throw new e.o(`plugin_order`,`${t.name} must come after ${n}`);for(let n of t.requires||[])if(!h.includes(n)||l[n]===null)throw new e.o(`plugin_requires`,`${t.name} requires the ${n} part, which is not set`)}function A(e){for(let t of e.offs)t();e.offs.clear(),D.delete(e.name);let t=O.indexOf(e);t>-1&&O.splice(t,1)}function j(e){if(e.removed)return;e.removed=!0;let t=e.disposer;e.disposer=null;try{t?.()}catch(e){o.error(e)}A(e)}function M(t){let{name:n}=t;return{progress:m,parts:u,events:{on(e,n){let r=S.on(e,n),i=()=>{r(),t.offs.delete(i)};return t.offs.add(i),i},off:(e,t)=>S.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>`);S.emit(t,r)}},storage:b(s,n),clock:c,log:o,env:{hasDom:a.hasDom,reducedMotion:a.reducedMotion},plugin:e=>D.has(e)&&D.get(e).done?D.get(e).handle:null,expose:e=>{t.handle=e}}}function N(t){if(w)throw new e.o(`disposed`,`the host was disposed`);k(t);let n={name:t.name,done:!1,removed:!1,disposer:null,handle:null,offs:new Set};D.set(t.name,n);let r=e=>(n.done=!0,typeof e==`function`&&(n.disposer=e),n.removed||w?(n.removed=!1,j(n),n):(O.push(n),n)),i=e=>{throw A(n),e},a;try{a=t.install(M(n))}catch(e){return i(e)}return g(a)?a.then(r,i):r(a)}let P=null;function F(t){if(w)throw new e.o(`disposed`,`the host was disposed`);if(P===null){let e=N(t);if(g(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(()=>N(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()=>j(t);let r=null,i=!1;return n.then(e=>{r=e,i&&j(e)},e=>o.error(e)),()=>{r?j(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(!w){w=!0;for(let e of[...O].reverse())j(e);for(let e of[...D.values()])j(e);for(let e of C)e();C.length=0,x(),m.clear?.()}}let z=L.then(()=>typeof m.init==`function`?m.init():void 0).then(()=>(w||E(),B));z.catch(()=>{});let B={progress:m,parts:u,events:S,ready:z,use:I,dispose:R};return B}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return m}});
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { a as e, n as t, o as n, t as r } from "./DataService-B5noGvMr.js";
|
|
2
|
+
import { n as i } from "./icon-BakWSiz_.js";
|
|
3
|
+
import { n as a, r as o, t as s } from "./SoundManager-C6VdZEFo.js";
|
|
4
|
+
import { n as c } from "./storage-C2s4Da9b.js";
|
|
5
|
+
// src/dopamine/ui/dopamine.css?inline
|
|
6
|
+
var l = "#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}}", u = "game-ui-overlay", d = {
|
|
7
|
+
levelUp: "LEVEL UP!",
|
|
8
|
+
achievementUnlocked: "Achievement Unlocked!"
|
|
9
|
+
}, f = "dopamine-reward-ui-css", p = "🔥", m = (e) => e == null ? "" : String(e), h = (e, t) => Object.prototype.hasOwnProperty.call(e, t), g = (e, t) => typeof e == "object" && e && h(e, t) ? e[t] : void 0, _ = class {
|
|
10
|
+
constructor(e = {}, t = {}) {
|
|
11
|
+
this.parts = e || {};
|
|
12
|
+
let n = g(t, "text");
|
|
13
|
+
this.strings = { ...d };
|
|
14
|
+
for (let e of Object.keys(d)) {
|
|
15
|
+
let t = g(n, e);
|
|
16
|
+
typeof t == "string" && (this.strings[e] = t);
|
|
17
|
+
}
|
|
18
|
+
this.safeIcons = g(t, "safeIcons") !== !1, this._streakIcon = g(g(t, "icons"), "streak") ?? p, this._injectCss = g(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();
|
|
19
|
+
}
|
|
20
|
+
get root() {
|
|
21
|
+
return this.container;
|
|
22
|
+
}
|
|
23
|
+
_build() {
|
|
24
|
+
this._injectCss && this._addStyles(), this.container = document.createElement("div"), this.container.className = "game-ui-overlay", document.getElementById(u) || (this.container.id = u), 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, {
|
|
25
|
+
position: "absolute",
|
|
26
|
+
width: "1px",
|
|
27
|
+
height: "1px",
|
|
28
|
+
overflow: "hidden",
|
|
29
|
+
clipPath: "inset(50%)",
|
|
30
|
+
whiteSpace: "nowrap"
|
|
31
|
+
}), 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"), i(this.container.querySelector(".streak-icon"), this._streakIcon, this.safeIcons);
|
|
32
|
+
}
|
|
33
|
+
_addStyles() {
|
|
34
|
+
if (document.getElementById(f)) return;
|
|
35
|
+
let e = typeof this._injectCss == "string" ? this._injectCss : l;
|
|
36
|
+
this._style = document.createElement("style"), this._style.id = f, this._style.textContent = e, document.head.appendChild(this._style);
|
|
37
|
+
}
|
|
38
|
+
_defer(e, t) {
|
|
39
|
+
let n = setTimeout(() => {
|
|
40
|
+
this._timers.delete(n), e();
|
|
41
|
+
}, t);
|
|
42
|
+
return this._timers.add(n), n;
|
|
43
|
+
}
|
|
44
|
+
_mount(e) {
|
|
45
|
+
return document.body.appendChild(e), this._detached.push(e), e;
|
|
46
|
+
}
|
|
47
|
+
_announce(e) {
|
|
48
|
+
this.liveRegion && (this.liveRegion.textContent = e);
|
|
49
|
+
}
|
|
50
|
+
_burst(e, t, n) {
|
|
51
|
+
this.parts.particles?.burst?.(e, t, n);
|
|
52
|
+
}
|
|
53
|
+
_replayAnimation(e, t) {
|
|
54
|
+
e && (e.style.animation = "none", this._defer(() => {
|
|
55
|
+
e.style.animation = t;
|
|
56
|
+
}, 10));
|
|
57
|
+
}
|
|
58
|
+
hud(e) {
|
|
59
|
+
if (!this.container || !e) return;
|
|
60
|
+
let { xp: t, level: n, progress: r, streak: i, next: a } = e, o = Number.isFinite(r) ? r : a > 0 ? t / a : 0;
|
|
61
|
+
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 = "";
|
|
62
|
+
}
|
|
63
|
+
popup(e) {
|
|
64
|
+
if (!this.container || !e || typeof e != "object") return;
|
|
65
|
+
let t = g(e, "kind");
|
|
66
|
+
t === "level" ? this._levelPopup(e) : t === "notice" ? this._notice(e) : this._card(e, t === "achievement");
|
|
67
|
+
}
|
|
68
|
+
_card(e, t) {
|
|
69
|
+
let { title: n, body: r, meta: i, icon: a } = e;
|
|
70
|
+
this._cardQueue.push([{
|
|
71
|
+
title: n,
|
|
72
|
+
body: r,
|
|
73
|
+
meta: i,
|
|
74
|
+
icon: a,
|
|
75
|
+
burst: g(e, "burst")
|
|
76
|
+
}, t]), this._nextCard();
|
|
77
|
+
}
|
|
78
|
+
_nextCard() {
|
|
79
|
+
if (this._cardActive) return;
|
|
80
|
+
let e = this._cardQueue.shift();
|
|
81
|
+
if (e) {
|
|
82
|
+
this._cardActive = !0;
|
|
83
|
+
try {
|
|
84
|
+
this._showCard(e[0], e[1]);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
throw this._cardActive = !1, this._nextCard(), e;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
_showCard(e, t) {
|
|
91
|
+
let n = document.createElement("div");
|
|
92
|
+
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 ";
|
|
93
|
+
let r = m(e.title);
|
|
94
|
+
n.querySelector(".achievement-title").textContent = t ? this.strings.achievementUnlocked : "", i(n.querySelector(".achievement-icon"), e.icon, this.safeIcons), n.querySelector(".achievement-name").textContent = r, n.querySelector(".achievement-desc").textContent = m(e.body), n.querySelector(".achievement-xp").textContent = m(e.meta), this._mount(n), this._announce(t ? `${this.strings.achievementUnlocked}: ${r}` : r), e.burst !== !1 && this._defer(() => {
|
|
95
|
+
let e = n.getBoundingClientRect();
|
|
96
|
+
this._burst("confetti", {
|
|
97
|
+
x: e.left + e.width / 2,
|
|
98
|
+
y: e.top + e.height / 2
|
|
99
|
+
}, { count: 40 });
|
|
100
|
+
}, 300), this._defer(() => {
|
|
101
|
+
n.style.animation = "slideOut 0.3s ease-in forwards", this._defer(() => {
|
|
102
|
+
this._remove(n), this._cardActive = !1, this._nextCard();
|
|
103
|
+
}, 300);
|
|
104
|
+
}, 4e3);
|
|
105
|
+
}
|
|
106
|
+
_levelPopup(e) {
|
|
107
|
+
let t = typeof e.title == "string" && e.title !== "" ? e.title : this.strings.levelUp, n = m(e.body), r = document.createElement("div");
|
|
108
|
+
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(() => {
|
|
109
|
+
for (let e = 0; e < 5; e++) this._defer(() => {
|
|
110
|
+
this._burst("confetti", {
|
|
111
|
+
x: Math.random() * window.innerWidth,
|
|
112
|
+
y: Math.random() * window.innerHeight * .6
|
|
113
|
+
}, { count: 30 });
|
|
114
|
+
}, e * 200);
|
|
115
|
+
}, 300), this._defer(() => {
|
|
116
|
+
r.style.opacity = "0", this._defer(() => this._remove(r), 500);
|
|
117
|
+
}, 2500);
|
|
118
|
+
}
|
|
119
|
+
_notice(e) {
|
|
120
|
+
let t = window.innerWidth / 2, n = window.innerHeight / 3, r = m(e.title);
|
|
121
|
+
e.tier === "legendary" ? (this._floatText({
|
|
122
|
+
text: r,
|
|
123
|
+
x: t,
|
|
124
|
+
y: n,
|
|
125
|
+
color: "#ffd700",
|
|
126
|
+
size: "36px"
|
|
127
|
+
}), this._burst("stars", {
|
|
128
|
+
x: t,
|
|
129
|
+
y: n
|
|
130
|
+
}, { count: 12 }), this._burst("confetti", {
|
|
131
|
+
x: t,
|
|
132
|
+
y: n
|
|
133
|
+
}, { count: 25 })) : e.tier === "rare" ? (this._floatText({
|
|
134
|
+
text: r,
|
|
135
|
+
x: t,
|
|
136
|
+
y: n,
|
|
137
|
+
color: "#ff6b6b",
|
|
138
|
+
size: "32px"
|
|
139
|
+
}), this._burst("fire", {
|
|
140
|
+
x: t,
|
|
141
|
+
y: n
|
|
142
|
+
}, { count: 20 })) : this._floatText({
|
|
143
|
+
text: r,
|
|
144
|
+
x: t,
|
|
145
|
+
y: n,
|
|
146
|
+
color: "#fff",
|
|
147
|
+
size: "24px"
|
|
148
|
+
}), this._announce(r);
|
|
149
|
+
}
|
|
150
|
+
text(e) {
|
|
151
|
+
this._floatText({ ...e });
|
|
152
|
+
}
|
|
153
|
+
_floatText({ text: e, x: t, y: n, color: r = "#ffd700", size: i = "24px" }) {
|
|
154
|
+
if (!this.container) return;
|
|
155
|
+
let a = document.createElement("div");
|
|
156
|
+
a.className = "floating-text", a.textContent = m(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);
|
|
157
|
+
}
|
|
158
|
+
_remove(e) {
|
|
159
|
+
e.remove();
|
|
160
|
+
let t = this._detached.indexOf(e);
|
|
161
|
+
t > -1 && this._detached.splice(t, 1);
|
|
162
|
+
}
|
|
163
|
+
destroy() {
|
|
164
|
+
for (let e of this._timers) clearTimeout(e);
|
|
165
|
+
this._timers.clear(), this._cardQueue = [], this._cardActive = !1;
|
|
166
|
+
for (let e of this._detached) e.remove();
|
|
167
|
+
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;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
// src/dopamine/feel/haptics.js
|
|
171
|
+
function v({ nav: e = globalThis.navigator, enabled: t = !0 } = {}) {
|
|
172
|
+
let n = !!t, r = (t) => {
|
|
173
|
+
if (n) try {
|
|
174
|
+
e.vibrate(t);
|
|
175
|
+
} catch {}
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
tap: () => r(10),
|
|
179
|
+
double: () => r([
|
|
180
|
+
10,
|
|
181
|
+
40,
|
|
182
|
+
10
|
|
183
|
+
]),
|
|
184
|
+
setEnabled(e) {
|
|
185
|
+
n = !!e;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
// src/dopamine/host.js
|
|
190
|
+
var y = 3, b = [
|
|
191
|
+
"ui",
|
|
192
|
+
"particles",
|
|
193
|
+
"sound",
|
|
194
|
+
"haptics"
|
|
195
|
+
], x = (e) => typeof e == "object" && !!e && typeof e.then == "function", S = (e, t) => {
|
|
196
|
+
x(e) && e.then(void 0, (e) => t.error(e));
|
|
197
|
+
};
|
|
198
|
+
function C() {
|
|
199
|
+
let e = typeof document < "u" && typeof window < "u";
|
|
200
|
+
return {
|
|
201
|
+
hasDom: e,
|
|
202
|
+
reducedMotion: e ? o(window).matches === !0 : !1
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function w(e, t, n) {
|
|
206
|
+
if (e === !1) return null;
|
|
207
|
+
let r = e;
|
|
208
|
+
return typeof e == "function" && (r = e(t)), r ?? n();
|
|
209
|
+
}
|
|
210
|
+
function T(e, t) {
|
|
211
|
+
let n = `dopamine_plugin_${t}:`;
|
|
212
|
+
return {
|
|
213
|
+
getItem: (t) => e.getItem(n + t),
|
|
214
|
+
setItem: (t, r) => e.setItem(n + t, r),
|
|
215
|
+
removeItem: (t) => e.removeItem(n + t)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function E(i = {}) {
|
|
219
|
+
let o = i || {}, l = C(), u = {
|
|
220
|
+
debug: () => {},
|
|
221
|
+
info: () => {},
|
|
222
|
+
warn: (...e) => console.warn(...e),
|
|
223
|
+
error: (...e) => console.error(...e),
|
|
224
|
+
...o.log || {}
|
|
225
|
+
}, d = o.storage || c(), f = o.clock || e, p = {
|
|
226
|
+
ui: null,
|
|
227
|
+
particles: null,
|
|
228
|
+
sound: null,
|
|
229
|
+
haptics: null
|
|
230
|
+
}, m = {};
|
|
231
|
+
for (let e of b) Object.defineProperty(m, e, {
|
|
232
|
+
enumerable: !0,
|
|
233
|
+
get: () => p[e]
|
|
234
|
+
});
|
|
235
|
+
Object.freeze(m);
|
|
236
|
+
let h = {
|
|
237
|
+
...l,
|
|
238
|
+
parts: m,
|
|
239
|
+
storage: d,
|
|
240
|
+
clock: f
|
|
241
|
+
}, g = w(o.progress, h, () => new t(new r({ storage: d }), {
|
|
242
|
+
clock: f,
|
|
243
|
+
streakDays: o.streakDays,
|
|
244
|
+
builtinAchievements: o.builtinAchievements,
|
|
245
|
+
loadRetryMs: o.loadRetryMs
|
|
246
|
+
}));
|
|
247
|
+
if (typeof g?.on != "function" || typeof g?.off != "function") throw new n("invalid_progress", "progress needs on() and off()");
|
|
248
|
+
p.particles = w(o.particles, h, () => l.hasDom ? new a() : null), p.sound = w(o.sound, h, () => new s({ storage: d })), p.haptics = w(o.haptics, h, () => v());
|
|
249
|
+
try {
|
|
250
|
+
p.ui = w(o.ui, h, () => l.hasDom ? new _(m) : null);
|
|
251
|
+
} catch (e) {
|
|
252
|
+
throw y(), e;
|
|
253
|
+
}
|
|
254
|
+
function y() {
|
|
255
|
+
for (let e of b) try {
|
|
256
|
+
p[e]?.destroy?.();
|
|
257
|
+
} catch (e) {
|
|
258
|
+
u.error(e);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
let E = g, D = [], O = !1, k = (e) => (t) => {
|
|
262
|
+
try {
|
|
263
|
+
S(e(t), u);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
u.error(e);
|
|
266
|
+
}
|
|
267
|
+
}, A = () => {
|
|
268
|
+
let e = p.ui;
|
|
269
|
+
if (!e || typeof g.snapshot != "function" || typeof g.getXPForNextLevel != "function") return;
|
|
270
|
+
let t = g.snapshot(), { total: n, progress: r } = g.getXPForNextLevel();
|
|
271
|
+
e.hud({
|
|
272
|
+
xp: t.xp,
|
|
273
|
+
level: t.level,
|
|
274
|
+
progress: r,
|
|
275
|
+
streak: t.streak.current,
|
|
276
|
+
next: n
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
D.push(E.on("xp_gained", k((e) => {
|
|
280
|
+
A(), e.leveledUp || p.sound?.play("xp");
|
|
281
|
+
})), E.on("level_up", k((e) => {
|
|
282
|
+
A(), p.ui?.popup({
|
|
283
|
+
kind: "level",
|
|
284
|
+
title: "",
|
|
285
|
+
body: String(e.newLevel)
|
|
286
|
+
}), p.sound?.play("level_up");
|
|
287
|
+
})), E.on("achievement_unlocked", k((e) => {
|
|
288
|
+
p.ui?.popup({
|
|
289
|
+
kind: "achievement",
|
|
290
|
+
title: e.name,
|
|
291
|
+
body: e.description,
|
|
292
|
+
icon: e.icon,
|
|
293
|
+
meta: `+${e.xp ?? 0} XP`
|
|
294
|
+
}), p.sound?.play("achievement");
|
|
295
|
+
})), E.on("streak_updated", k(A)), E.on("player_reset", k(A)), E.on("load_recovered", k(A)), E.on("personal_best", k((e) => {
|
|
296
|
+
p.ui?.popup({
|
|
297
|
+
kind: "notice",
|
|
298
|
+
title: `New High Score: ${e.score}!`,
|
|
299
|
+
tier: "legendary"
|
|
300
|
+
}), p.sound?.play("personal_best");
|
|
301
|
+
})));
|
|
302
|
+
let j = /* @__PURE__ */ new Map(), M = [];
|
|
303
|
+
function N(e) {
|
|
304
|
+
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");
|
|
305
|
+
if (e.api !== 3) throw new n("plugin_api", `${e.name} was built for api ${e.api}, this host is api 3`);
|
|
306
|
+
if (j.has(e.name)) throw new n("plugin_duplicate", `${e.name} is already installed`);
|
|
307
|
+
for (let t of e.after || []) if (!j.has(t) || !j.get(t).done) throw new n("plugin_order", `${e.name} must come after ${t}`);
|
|
308
|
+
for (let t of e.requires || []) if (!b.includes(t) || p[t] === null) throw new n("plugin_requires", `${e.name} requires the ${t} part, which is not set`);
|
|
309
|
+
}
|
|
310
|
+
function P(e) {
|
|
311
|
+
for (let t of e.offs) t();
|
|
312
|
+
e.offs.clear(), j.delete(e.name);
|
|
313
|
+
let t = M.indexOf(e);
|
|
314
|
+
t > -1 && M.splice(t, 1);
|
|
315
|
+
}
|
|
316
|
+
function F(e) {
|
|
317
|
+
if (e.removed) return;
|
|
318
|
+
e.removed = !0;
|
|
319
|
+
let t = e.disposer;
|
|
320
|
+
e.disposer = null;
|
|
321
|
+
try {
|
|
322
|
+
t?.();
|
|
323
|
+
} catch (e) {
|
|
324
|
+
u.error(e);
|
|
325
|
+
}
|
|
326
|
+
P(e);
|
|
327
|
+
}
|
|
328
|
+
function I(e) {
|
|
329
|
+
let { name: t } = e;
|
|
330
|
+
return {
|
|
331
|
+
progress: g,
|
|
332
|
+
parts: m,
|
|
333
|
+
events: {
|
|
334
|
+
on(t, n) {
|
|
335
|
+
let r = E.on(t, n), i = () => {
|
|
336
|
+
r(), e.offs.delete(i);
|
|
337
|
+
};
|
|
338
|
+
return e.offs.add(i), i;
|
|
339
|
+
},
|
|
340
|
+
off: (e, t) => E.off(e, t),
|
|
341
|
+
emit(e, r) {
|
|
342
|
+
if (typeof e != "string" || !e.startsWith(`${t}:`)) throw new n("plugin_event", `${t} may only emit events named ${t}:<event>`);
|
|
343
|
+
E.emit(e, r);
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
storage: T(d, t),
|
|
347
|
+
clock: f,
|
|
348
|
+
log: u,
|
|
349
|
+
env: {
|
|
350
|
+
hasDom: l.hasDom,
|
|
351
|
+
reducedMotion: l.reducedMotion
|
|
352
|
+
},
|
|
353
|
+
plugin: (e) => j.has(e) && j.get(e).done ? j.get(e).handle : null,
|
|
354
|
+
expose: (t) => {
|
|
355
|
+
e.handle = t;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function L(e) {
|
|
360
|
+
if (O) throw new n("disposed", "the host was disposed");
|
|
361
|
+
N(e);
|
|
362
|
+
let t = {
|
|
363
|
+
name: e.name,
|
|
364
|
+
done: !1,
|
|
365
|
+
removed: !1,
|
|
366
|
+
disposer: null,
|
|
367
|
+
handle: null,
|
|
368
|
+
offs: /* @__PURE__ */ new Set()
|
|
369
|
+
};
|
|
370
|
+
j.set(e.name, t);
|
|
371
|
+
let r = (e) => (t.done = !0, typeof e == "function" && (t.disposer = e), t.removed || O ? (t.removed = !1, F(t), t) : (M.push(t), t)), i = (e) => {
|
|
372
|
+
throw P(t), e;
|
|
373
|
+
}, a;
|
|
374
|
+
try {
|
|
375
|
+
a = e.install(I(t));
|
|
376
|
+
} catch (e) {
|
|
377
|
+
return i(e);
|
|
378
|
+
}
|
|
379
|
+
return x(a) ? a.then(r, i) : r(a);
|
|
380
|
+
}
|
|
381
|
+
let R = null;
|
|
382
|
+
function z(e) {
|
|
383
|
+
if (O) throw new n("disposed", "the host was disposed");
|
|
384
|
+
if (R === null) {
|
|
385
|
+
let t = L(e);
|
|
386
|
+
if (x(t)) {
|
|
387
|
+
let e = t.then((e) => e, (e) => {
|
|
388
|
+
throw e;
|
|
389
|
+
});
|
|
390
|
+
return R = e.then(() => {
|
|
391
|
+
R = null;
|
|
392
|
+
}, () => {
|
|
393
|
+
R = null;
|
|
394
|
+
}), {
|
|
395
|
+
record: null,
|
|
396
|
+
done: e
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
record: t,
|
|
401
|
+
done: Promise.resolve(t)
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
let t = R.then(() => L(e));
|
|
405
|
+
return R = t.then(() => {
|
|
406
|
+
R = null;
|
|
407
|
+
}, () => {
|
|
408
|
+
R = null;
|
|
409
|
+
}), {
|
|
410
|
+
record: null,
|
|
411
|
+
done: t
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function B(e) {
|
|
415
|
+
let { record: t, done: n } = z(e);
|
|
416
|
+
if (t) return () => F(t);
|
|
417
|
+
let r = null, i = !1;
|
|
418
|
+
return n.then((e) => {
|
|
419
|
+
r = e, i && F(e);
|
|
420
|
+
}, (e) => u.error(e)), () => {
|
|
421
|
+
r ? F(r) : i = !0;
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
let V = Promise.resolve();
|
|
425
|
+
try {
|
|
426
|
+
for (let e of o.plugins || []) {
|
|
427
|
+
let { done: t } = z(e);
|
|
428
|
+
V = V.then(() => t);
|
|
429
|
+
}
|
|
430
|
+
} catch (e) {
|
|
431
|
+
throw H(), e;
|
|
432
|
+
}
|
|
433
|
+
V = V.catch((e) => {
|
|
434
|
+
throw H(), e;
|
|
435
|
+
});
|
|
436
|
+
function H() {
|
|
437
|
+
if (!O) {
|
|
438
|
+
O = !0;
|
|
439
|
+
for (let e of [...M].reverse()) F(e);
|
|
440
|
+
for (let e of [...j.values()]) F(e);
|
|
441
|
+
for (let e of D) e();
|
|
442
|
+
D.length = 0, y(), g.clear?.();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
let U = V.then(() => typeof g.init == "function" ? g.init() : void 0).then(() => (O || A(), W));
|
|
446
|
+
U.catch(() => {});
|
|
447
|
+
let W = {
|
|
448
|
+
progress: g,
|
|
449
|
+
parts: m,
|
|
450
|
+
events: E,
|
|
451
|
+
ready: U,
|
|
452
|
+
use: B,
|
|
453
|
+
dispose: H
|
|
454
|
+
};
|
|
455
|
+
return W;
|
|
456
|
+
}
|
|
457
|
+
export { _ as i, E as n, v as r, y as t };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/dopamine/ui/icon.js
|
|
2
|
+
var e = "http://www.w3.org/2000/svg", t = /* @__PURE__ */ new Set([
|
|
3
|
+
"svg",
|
|
4
|
+
"g",
|
|
5
|
+
"path",
|
|
6
|
+
"circle",
|
|
7
|
+
"ellipse",
|
|
8
|
+
"rect",
|
|
9
|
+
"line",
|
|
10
|
+
"polyline",
|
|
11
|
+
"polygon",
|
|
12
|
+
"text",
|
|
13
|
+
"tspan",
|
|
14
|
+
"title",
|
|
15
|
+
"desc",
|
|
16
|
+
"defs",
|
|
17
|
+
"linearGradient",
|
|
18
|
+
"radialGradient",
|
|
19
|
+
"stop",
|
|
20
|
+
"clipPath",
|
|
21
|
+
"mask"
|
|
22
|
+
]), 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(".")), r = /* @__PURE__ */ new Set([
|
|
23
|
+
"fill",
|
|
24
|
+
"stroke",
|
|
25
|
+
"clip-path",
|
|
26
|
+
"mask"
|
|
27
|
+
]), i = /* @__PURE__ */ new Set(["transform", "gradientTransform"]), a = /^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/, o = /^[#a-zA-Z0-9(),.%\s-]+$/, s = /^[a-zA-Z0-9(),.\s-]+$/, c = /^[A-Za-z][\w.:-]*$/, l = 0;
|
|
28
|
+
function u(n, r) {
|
|
29
|
+
if (n.nodeType !== 1 || n.namespaceURI !== e || !t.has(n.localName)) return;
|
|
30
|
+
let i = n.getAttribute("id");
|
|
31
|
+
i && c.test(i) && r.add(i);
|
|
32
|
+
for (let e of Array.from(n.childNodes)) u(e, r);
|
|
33
|
+
}
|
|
34
|
+
function d(e, t, n) {
|
|
35
|
+
if (t.includes("\\")) return null;
|
|
36
|
+
let l = t.trim();
|
|
37
|
+
if (e === "id") return c.test(l) ? n.prefix + l : null;
|
|
38
|
+
if (r.has(e)) {
|
|
39
|
+
let e = a.exec(l);
|
|
40
|
+
return e ? n.ids.has(e[1]) ? `url(#${n.prefix}${e[1]})` : null : o.test(l) && !/url/i.test(l) ? l : null;
|
|
41
|
+
}
|
|
42
|
+
return i.has(e) ? s.test(l) && !/url/i.test(l) ? l : null : t.includes("(") ? e === "stop-color" && o.test(l) && !/url/i.test(l) ? l : null : t;
|
|
43
|
+
}
|
|
44
|
+
function f(r, i) {
|
|
45
|
+
if (r.nodeType === 3 || r.nodeType === 4) return document.createTextNode(r.data);
|
|
46
|
+
if (r.nodeType !== 1 || r.namespaceURI !== e || !t.has(r.localName)) return null;
|
|
47
|
+
let a = document.createElementNS(e, r.localName);
|
|
48
|
+
for (let e of Array.from(r.attributes)) {
|
|
49
|
+
if (e.namespaceURI !== null || !n.has(e.name)) continue;
|
|
50
|
+
let t = d(e.name, e.value, i);
|
|
51
|
+
t !== null && a.setAttribute(e.name, t);
|
|
52
|
+
}
|
|
53
|
+
for (let e of Array.from(r.childNodes)) {
|
|
54
|
+
let t = f(e, i);
|
|
55
|
+
t && a.appendChild(t);
|
|
56
|
+
}
|
|
57
|
+
return a;
|
|
58
|
+
}
|
|
59
|
+
function p(t) {
|
|
60
|
+
let n, r = /^\s*<svg[\s>]/.test(t) && !/^\s*<svg\b[^>]*\sxmlns\s*=/.test(t) ? t.replace(/^(\s*<svg)/, `$1 xmlns="${e}"`) : t;
|
|
61
|
+
try {
|
|
62
|
+
n = new DOMParser().parseFromString(r, "image/svg+xml");
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
let i = n.documentElement;
|
|
67
|
+
if (!i || i.localName !== "svg" || n.getElementsByTagName("parsererror").length > 0) return null;
|
|
68
|
+
let a = /* @__PURE__ */ new Set();
|
|
69
|
+
return u(i, a), f(i, {
|
|
70
|
+
ids: a,
|
|
71
|
+
prefix: `dj-icon-${++l}-`
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function m(e) {
|
|
75
|
+
if (typeof e != "object" || !e) return !1;
|
|
76
|
+
if (typeof Node < "u" && e instanceof Node) return !0;
|
|
77
|
+
let t = e.ownerDocument?.defaultView?.Node;
|
|
78
|
+
return typeof t == "function" && e instanceof t;
|
|
79
|
+
}
|
|
80
|
+
function h(e, t, n) {
|
|
81
|
+
if (e.textContent = "", m(t)) e.appendChild(t);
|
|
82
|
+
else if (typeof t != "string") return;
|
|
83
|
+
else if (!n) e.innerHTML = t;
|
|
84
|
+
else {
|
|
85
|
+
let n = p(t);
|
|
86
|
+
n ? e.appendChild(n) : e.textContent = t;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export { h as n, m as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`http://www.w3.org/2000/svg`,t=new Set([`svg`,`g`,`path`,`circle`,`ellipse`,`rect`,`line`,`polyline`,`polygon`,`text`,`tspan`,`title`,`desc`,`defs`,`linearGradient`,`radialGradient`,`stop`,`clipPath`,`mask`]),n=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(`.`)),r=new Set([`fill`,`stroke`,`clip-path`,`mask`]),i=new Set([`transform`,`gradientTransform`]),a=/^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/,o=/^[#a-zA-Z0-9(),.%\s-]+$/,s=/^[a-zA-Z0-9(),.\s-]+$/,c=/^[A-Za-z][\w.:-]*$/,l=0;function u(n,r){if(n.nodeType!==1||n.namespaceURI!==e||!t.has(n.localName))return;let i=n.getAttribute(`id`);i&&c.test(i)&&r.add(i);for(let e of Array.from(n.childNodes))u(e,r)}function d(e,t,n){if(t.includes(`\\`))return null;let l=t.trim();if(e===`id`)return c.test(l)?n.prefix+l:null;if(r.has(e)){let e=a.exec(l);return e?n.ids.has(e[1])?`url(#${n.prefix}${e[1]})`:null:o.test(l)&&!/url/i.test(l)?l:null}return i.has(e)?s.test(l)&&!/url/i.test(l)?l:null:t.includes(`(`)?e===`stop-color`&&o.test(l)&&!/url/i.test(l)?l:null:t}function f(r,i){if(r.nodeType===3||r.nodeType===4)return document.createTextNode(r.data);if(r.nodeType!==1||r.namespaceURI!==e||!t.has(r.localName))return null;let a=document.createElementNS(e,r.localName);for(let e of Array.from(r.attributes)){if(e.namespaceURI!==null||!n.has(e.name))continue;let t=d(e.name,e.value,i);t!==null&&a.setAttribute(e.name,t)}for(let e of Array.from(r.childNodes)){let t=f(e,i);t&&a.appendChild(t)}return a}function p(t){let n,r=/^\s*<svg[\s>]/.test(t)&&!/^\s*<svg\b[^>]*\sxmlns\s*=/.test(t)?t.replace(/^(\s*<svg)/,`$1 xmlns="${e}"`):t;try{n=new DOMParser().parseFromString(r,`image/svg+xml`)}catch{return null}let i=n.documentElement;if(!i||i.localName!==`svg`||n.getElementsByTagName(`parsererror`).length>0)return null;let a=new Set;return u(i,a),f(i,{ids:a,prefix:`dj-icon-${++l}-`})}function m(e){if(typeof e!=`object`||!e)return!1;if(typeof Node<`u`&&e instanceof Node)return!0;let t=e.ownerDocument?.defaultView?.Node;return typeof t==`function`&&e instanceof t}function h(e,t,n){if(e.textContent=``,m(t))e.appendChild(t);else if(typeof t!=`string`)return;else if(!n)e.innerHTML=t;else{let n=p(t);n?e.appendChild(n):e.textContent=t}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return m}});
|
|
@@ -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 };
|