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
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# dopaminejs
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Gamification for any website. XP, levels, achievements and timezone-correct daily streaks, with confetti, particles and sound.
|
|
4
4
|
|
|
5
|
-
Zero runtime dependencies. Works with any framework.
|
|
5
|
+
Zero runtime dependencies. Works with any framework, or with no build step through the script tag build (3.4.0 and later, see the repository README).
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install dopaminejs
|
|
@@ -124,6 +124,56 @@ To put the card on the left, set `--dopamine-toast-right: auto` as well. With bo
|
|
|
124
124
|
|
|
125
125
|
Cards show one at a time. A second unlock waits until the first has left, so its announcement and confetti come later too.
|
|
126
126
|
|
|
127
|
+
## Celebrate a moment
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
import { celebrate } from 'dopaminejs/celebrate';
|
|
131
|
+
|
|
132
|
+
celebrate('complete', { title: 'Lesson 3 done', target: button });
|
|
133
|
+
celebrate('certificate', { parts: dopamine.parts }); // through a host
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Shows a toast, fires confetti and plays a sound, with or without `createDopamine()`. Presets: `complete`, `milestone`, `streak`, `certificate`. Options: `title`, `body`, `icon`, `target` (confetti starts at its centre), `sound` (a key, or `false`) and `parts`. With reduced motion on there is no confetti. A part the host does not have is skipped, with no standalone fallback. `destroyCelebrations()` removes what the standalone route made. Not in the script tag build.
|
|
137
|
+
|
|
138
|
+
## Completion certificate
|
|
139
|
+
|
|
140
|
+
A modal card the visitor can download as a PNG or print. This one opens when a video ends:
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
import { showCertificate } from 'dopaminejs/certificate';
|
|
144
|
+
|
|
145
|
+
const logo = new Image();
|
|
146
|
+
logo.src = '/img/acme.png';
|
|
147
|
+
|
|
148
|
+
video.addEventListener('ended', () => {
|
|
149
|
+
showCertificate({
|
|
150
|
+
title: 'Intro to Gardening',
|
|
151
|
+
recipient: 'Ana Reyes',
|
|
152
|
+
date: 'Nov 25, 2026',
|
|
153
|
+
issuer: 'Acme Academy',
|
|
154
|
+
logo
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`celebrate` can open it after the confetti. The certificate code loads on demand, so a page that never shows one does not download it:
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
import { celebrate } from 'dopaminejs/celebrate';
|
|
163
|
+
|
|
164
|
+
celebrate('certificate', { certificate: { title: 'Intro to Gardening', recipient: 'Ana Reyes' } });
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- `title`, `recipient`, `date` and `issuer` are set as text, so a name from a CMS cannot inject HTML. Long text wraps, and past a few lines it ends with an ellipsis, in the card and in the PNG.
|
|
168
|
+
- `logo` is a string or an image. A string follows `safeIcons` as an achievement icon does: text or allowlisted SVG by default, HTML only with `showCertificate(fields, { safeIcons: false })`. An `HTMLImageElement` is moved in, never parsed, and goes back to its place in the page, with its own style, when the certificate closes.
|
|
169
|
+
- Download draws the card on a canvas and saves `certificate.png`. If the logo is from another origin the canvas cannot be exported, so the PNG is saved without the logo and `console.warn` says so once. A logo that has not loaded is dropped from the PNG the same way.
|
|
170
|
+
- The PNG takes a plain colour from `--dopamine-toast-bg` (anything the canvas accepts as a colour) and draws a gradient as its default purple background.
|
|
171
|
+
- `fields` must be an object; anything else logs a warning and opens nothing.
|
|
172
|
+
- Print calls `window.print()` with a print style that shows only the certificate.
|
|
173
|
+
- It is a dialog (`role="dialog"`, `aria-modal`, labelled by the title) with focus kept inside. Escape, Close or a click outside closes it and focus goes back to where it was. One certificate is open at a time. `destroyCertificate()` closes it and removes its DOM, print style and listeners. `destroyCelebrations()` does not.
|
|
174
|
+
- Colours come from the `--dopamine-toast-*` variables (`bg`, `text`, `muted`, `accent`, `radius`, `shadow`). The PNG reads them too; a gradient `bg` is drawn as the default purple gradient.
|
|
175
|
+
- Not in the script tag build.
|
|
176
|
+
|
|
127
177
|
## Cleanup
|
|
128
178
|
|
|
129
179
|
Everything that touches the DOM can be torn down:
|