dopaminejs 3.6.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 +39 -0
- package/dist/celebrate.cjs +1 -1
- package/dist/celebrate.js +6 -3
- package/dist/certificate.cjs +1 -0
- package/dist/certificate.js +234 -0
- package/dist/dopamine.cjs +1 -1
- package/dist/dopamine.global.js +4 -4
- package/dist/dopamine.js +1 -1
- package/dist/host-BWKiYtjY.cjs +37 -0
- package/dist/{host-B-Gn-Zg_.js → host-Bhf9EqSk.js} +103 -183
- package/dist/icon-BakWSiz_.js +89 -0
- package/dist/icon-gkpxMw48.cjs +1 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.js +1 -1
- package/package.json +6 -1
- package/src/celebrate.js +11 -6
- package/src/certificate.js +391 -0
- package/src/dopamine/ui/RewardUI.js +3 -148
- package/src/dopamine/ui/icon.js +157 -0
- package/types/celebrate.d.ts +8 -0
- package/types/certificate.d.ts +30 -0
- package/dist/host-D6suk7Ci.cjs +0 -37
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import DEFAULT_CSS from './dopamine.css?inline';
|
|
7
|
+
import { setIcon } from './icon.js';
|
|
7
8
|
|
|
8
9
|
const OVERLAY_ID = 'game-ui-overlay';
|
|
9
10
|
|
|
@@ -24,128 +25,6 @@ const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key
|
|
|
24
25
|
const ownValue = (object, key) =>
|
|
25
26
|
(object !== null && typeof object === 'object' && hasOwn(object, key) ? object[key] : undefined);
|
|
26
27
|
|
|
27
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
28
|
-
|
|
29
|
-
const SVG_ELEMENTS = new Set([
|
|
30
|
-
'svg', 'g', 'path', 'circle', 'ellipse', 'rect', 'line', 'polyline',
|
|
31
|
-
'polygon', 'text', 'tspan', 'title', 'desc', 'defs', 'linearGradient',
|
|
32
|
-
'radialGradient', 'stop', 'clipPath', 'mask'
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
// No style, no href, no event handlers: only geometry and paint.
|
|
36
|
-
const SVG_ATTRIBUTES = new Set([
|
|
37
|
-
'viewBox', 'width', 'height', 'x', 'y', 'x1', 'y1', 'x2', 'y2', 'cx', 'cy',
|
|
38
|
-
'r', 'rx', 'ry', 'd', 'points', 'transform', 'fill', 'fill-opacity',
|
|
39
|
-
'fill-rule', 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
|
|
40
|
-
'stroke-opacity', 'opacity', 'offset', 'stop-color', 'stop-opacity',
|
|
41
|
-
'gradientUnits', 'gradientTransform', 'clip-path', 'mask', 'clip-rule',
|
|
42
|
-
'font-size', 'font-family', 'font-weight', 'text-anchor', 'id',
|
|
43
|
-
'aria-hidden', 'aria-label', 'role'
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
// Attributes that may point at a gradient, clip path or mask in the same icon.
|
|
47
|
-
const REFERENCE_ATTRIBUTES = new Set(['fill', 'stroke', 'clip-path', 'mask']);
|
|
48
|
-
const TRANSFORM_ATTRIBUTES = new Set(['transform', 'gradientTransform']);
|
|
49
|
-
|
|
50
|
-
const SINGLE_FRAGMENT_URL = /^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/;
|
|
51
|
-
const PLAIN_COLOUR = /^[#a-zA-Z0-9(),.%\s-]+$/;
|
|
52
|
-
const PLAIN_TRANSFORM = /^[a-zA-Z0-9(),.\s-]+$/;
|
|
53
|
-
const SAFE_ID = /^[A-Za-z][\w.:-]*$/;
|
|
54
|
-
|
|
55
|
-
// Ids inside an icon are page-global (window.<id>, getElementById), so every
|
|
56
|
-
// render gets its own prefix.
|
|
57
|
-
let iconCounter = 0;
|
|
58
|
-
|
|
59
|
-
function collectIds(node, ids) {
|
|
60
|
-
if (node.nodeType !== 1 || node.namespaceURI !== SVG_NS || !SVG_ELEMENTS.has(node.localName)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const id = node.getAttribute('id');
|
|
64
|
-
if (id && SAFE_ID.test(id)) ids.add(id);
|
|
65
|
-
for (const child of Array.from(node.childNodes)) collectIds(child, ids);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Returns the value to write, or null to drop the attribute.
|
|
70
|
-
*/
|
|
71
|
-
function cleanValue(name, value, ctx) {
|
|
72
|
-
if (value.includes('\\')) return null;
|
|
73
|
-
const trimmed = value.trim();
|
|
74
|
-
|
|
75
|
-
if (name === 'id') {
|
|
76
|
-
return SAFE_ID.test(trimmed) ? ctx.prefix + trimmed : null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (REFERENCE_ATTRIBUTES.has(name)) {
|
|
80
|
-
const ref = SINGLE_FRAGMENT_URL.exec(trimmed);
|
|
81
|
-
if (ref) {
|
|
82
|
-
return ctx.ids.has(ref[1]) ? `url(#${ctx.prefix}${ref[1]})` : null;
|
|
83
|
-
}
|
|
84
|
-
return PLAIN_COLOUR.test(trimmed) && !/url/i.test(trimmed) ? trimmed : null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (TRANSFORM_ATTRIBUTES.has(name)) {
|
|
88
|
-
return PLAIN_TRANSFORM.test(trimmed) && !/url/i.test(trimmed) ? trimmed : null;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (value.includes('(')) {
|
|
92
|
-
// Only a plain colour such as rgb() or hsl() is acceptable here.
|
|
93
|
-
return name === 'stop-color' && PLAIN_COLOUR.test(trimmed) && !/url/i.test(trimmed)
|
|
94
|
-
? trimmed
|
|
95
|
-
: null;
|
|
96
|
-
}
|
|
97
|
-
return value;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function cleanNode(source, ctx) {
|
|
101
|
-
// 3 is text, 4 is CDATA.
|
|
102
|
-
if (source.nodeType === 3 || source.nodeType === 4) {
|
|
103
|
-
return document.createTextNode(source.data);
|
|
104
|
-
}
|
|
105
|
-
if (source.nodeType !== 1
|
|
106
|
-
|| source.namespaceURI !== SVG_NS
|
|
107
|
-
|| !SVG_ELEMENTS.has(source.localName)) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const clean = document.createElementNS(SVG_NS, source.localName);
|
|
112
|
-
for (const attr of Array.from(source.attributes)) {
|
|
113
|
-
if (attr.namespaceURI !== null || !SVG_ATTRIBUTES.has(attr.name)) continue;
|
|
114
|
-
const value = cleanValue(attr.name, attr.value, ctx);
|
|
115
|
-
if (value !== null) clean.setAttribute(attr.name, value);
|
|
116
|
-
}
|
|
117
|
-
for (const child of Array.from(source.childNodes)) {
|
|
118
|
-
const kept = cleanNode(child, ctx);
|
|
119
|
-
if (kept) clean.appendChild(kept);
|
|
120
|
-
}
|
|
121
|
-
return clean;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Parse a string as SVG and rebuild it from an allowlist of elements and
|
|
126
|
-
* attributes, so nothing that can run script or load a resource survives.
|
|
127
|
-
* Returns null unless the whole string is one valid <svg> document.
|
|
128
|
-
*/
|
|
129
|
-
function parseSafeSvg(markup) {
|
|
130
|
-
let doc;
|
|
131
|
-
// Inline HTML SVG usually has no xmlns, which the XML parser rejects.
|
|
132
|
-
const source = /^\s*<svg[\s>]/.test(markup) && !/^\s*<svg\b[^>]*\sxmlns\s*=/.test(markup)
|
|
133
|
-
? markup.replace(/^(\s*<svg)/, `$1 xmlns="${SVG_NS}"`)
|
|
134
|
-
: markup;
|
|
135
|
-
try {
|
|
136
|
-
doc = new DOMParser().parseFromString(source,'image/svg+xml');
|
|
137
|
-
} catch {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const root = doc.documentElement;
|
|
141
|
-
if (!root || root.localName !== 'svg' || doc.getElementsByTagName('parsererror').length > 0) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
const ids = new Set();
|
|
145
|
-
collectIds(root, ids);
|
|
146
|
-
return cleanNode(root, { ids, prefix: `dj-icon-${++iconCounter}-` });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
28
|
export class RewardUI {
|
|
150
29
|
/**
|
|
151
30
|
* @param {{ particles?: Object|null }} [parts] - Read at call time, so a
|
|
@@ -263,7 +142,7 @@ export class RewardUI {
|
|
|
263
142
|
this.xpText = this.container.querySelector('.xp-text');
|
|
264
143
|
this.levelDisplay = this.container.querySelector('.level-number');
|
|
265
144
|
this.streakDisplay = this.container.querySelector('.streak-number');
|
|
266
|
-
|
|
145
|
+
setIcon(this.container.querySelector('.streak-icon'), this._streakIcon, this.safeIcons);
|
|
267
146
|
}
|
|
268
147
|
|
|
269
148
|
/**
|
|
@@ -280,30 +159,6 @@ export class RewardUI {
|
|
|
280
159
|
document.head.appendChild(this._style);
|
|
281
160
|
}
|
|
282
161
|
|
|
283
|
-
/**
|
|
284
|
-
* Single place where icons reach the DOM. A Node is appended. A string is
|
|
285
|
-
* a sanitised SVG or plain text unless safeIcons is off; then it is HTML
|
|
286
|
-
* (see SECURITY.md).
|
|
287
|
-
* @private
|
|
288
|
-
*/
|
|
289
|
-
_setIcon(el, icon) {
|
|
290
|
-
el.textContent = '';
|
|
291
|
-
if (typeof Node !== 'undefined' && icon instanceof Node) {
|
|
292
|
-
el.appendChild(icon);
|
|
293
|
-
} else if (typeof icon !== 'string') {
|
|
294
|
-
return;
|
|
295
|
-
} else if (!this.safeIcons) {
|
|
296
|
-
el.innerHTML = icon;
|
|
297
|
-
} else {
|
|
298
|
-
const svg = parseSafeSvg(icon);
|
|
299
|
-
if (svg) {
|
|
300
|
-
el.appendChild(svg);
|
|
301
|
-
} else {
|
|
302
|
-
el.textContent = icon;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
162
|
/**
|
|
308
163
|
* setTimeout that destroy() can cancel.
|
|
309
164
|
* @private
|
|
@@ -467,7 +322,7 @@ export class RewardUI {
|
|
|
467
322
|
|
|
468
323
|
const title = textOf(popup.title);
|
|
469
324
|
card.querySelector('.achievement-title').textContent = withHeading ? this.strings.achievementUnlocked : '';
|
|
470
|
-
|
|
325
|
+
setIcon(card.querySelector('.achievement-icon'), popup.icon, this.safeIcons);
|
|
471
326
|
card.querySelector('.achievement-name').textContent = title;
|
|
472
327
|
card.querySelector('.achievement-desc').textContent = textOf(popup.body);
|
|
473
328
|
card.querySelector('.achievement-xp').textContent = textOf(popup.meta);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Puts an icon into an element. Shared by RewardUI and the certificate, so the
|
|
3
|
+
* sanitiser is one copy. Nothing here runs at import time.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
7
|
+
|
|
8
|
+
const SVG_ELEMENTS = new Set([
|
|
9
|
+
'svg', 'g', 'path', 'circle', 'ellipse', 'rect', 'line', 'polyline',
|
|
10
|
+
'polygon', 'text', 'tspan', 'title', 'desc', 'defs', 'linearGradient',
|
|
11
|
+
'radialGradient', 'stop', 'clipPath', 'mask'
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
// No style, no href, no event handlers: only geometry and paint.
|
|
15
|
+
const SVG_ATTRIBUTES = new Set([
|
|
16
|
+
'viewBox', 'width', 'height', 'x', 'y', 'x1', 'y1', 'x2', 'y2', 'cx', 'cy',
|
|
17
|
+
'r', 'rx', 'ry', 'd', 'points', 'transform', 'fill', 'fill-opacity',
|
|
18
|
+
'fill-rule', 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
|
|
19
|
+
'stroke-opacity', 'opacity', 'offset', 'stop-color', 'stop-opacity',
|
|
20
|
+
'gradientUnits', 'gradientTransform', 'clip-path', 'mask', 'clip-rule',
|
|
21
|
+
'font-size', 'font-family', 'font-weight', 'text-anchor', 'id',
|
|
22
|
+
'aria-hidden', 'aria-label', 'role'
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
// Attributes that may point at a gradient, clip path or mask in the same icon.
|
|
26
|
+
const REFERENCE_ATTRIBUTES = new Set(['fill', 'stroke', 'clip-path', 'mask']);
|
|
27
|
+
const TRANSFORM_ATTRIBUTES = new Set(['transform', 'gradientTransform']);
|
|
28
|
+
|
|
29
|
+
const SINGLE_FRAGMENT_URL = /^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/;
|
|
30
|
+
const PLAIN_COLOUR = /^[#a-zA-Z0-9(),.%\s-]+$/;
|
|
31
|
+
const PLAIN_TRANSFORM = /^[a-zA-Z0-9(),.\s-]+$/;
|
|
32
|
+
const SAFE_ID = /^[A-Za-z][\w.:-]*$/;
|
|
33
|
+
|
|
34
|
+
// Ids inside an icon are page-global (window.<id>, getElementById), so every
|
|
35
|
+
// render gets its own prefix.
|
|
36
|
+
let iconCounter = 0;
|
|
37
|
+
|
|
38
|
+
function collectIds(node, ids) {
|
|
39
|
+
if (node.nodeType !== 1 || node.namespaceURI !== SVG_NS || !SVG_ELEMENTS.has(node.localName)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const id = node.getAttribute('id');
|
|
43
|
+
if (id && SAFE_ID.test(id)) ids.add(id);
|
|
44
|
+
for (const child of Array.from(node.childNodes)) collectIds(child, ids);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the value to write, or null to drop the attribute.
|
|
49
|
+
*/
|
|
50
|
+
function cleanValue(name, value, ctx) {
|
|
51
|
+
if (value.includes('\\')) return null;
|
|
52
|
+
const trimmed = value.trim();
|
|
53
|
+
|
|
54
|
+
if (name === 'id') {
|
|
55
|
+
return SAFE_ID.test(trimmed) ? ctx.prefix + trimmed : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (REFERENCE_ATTRIBUTES.has(name)) {
|
|
59
|
+
const ref = SINGLE_FRAGMENT_URL.exec(trimmed);
|
|
60
|
+
if (ref) {
|
|
61
|
+
return ctx.ids.has(ref[1]) ? `url(#${ctx.prefix}${ref[1]})` : null;
|
|
62
|
+
}
|
|
63
|
+
return PLAIN_COLOUR.test(trimmed) && !/url/i.test(trimmed) ? trimmed : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (TRANSFORM_ATTRIBUTES.has(name)) {
|
|
67
|
+
return PLAIN_TRANSFORM.test(trimmed) && !/url/i.test(trimmed) ? trimmed : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (value.includes('(')) {
|
|
71
|
+
// Only a plain colour such as rgb() or hsl() is acceptable here.
|
|
72
|
+
return name === 'stop-color' && PLAIN_COLOUR.test(trimmed) && !/url/i.test(trimmed)
|
|
73
|
+
? trimmed
|
|
74
|
+
: null;
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function cleanNode(source, ctx) {
|
|
80
|
+
// 3 is text, 4 is CDATA.
|
|
81
|
+
if (source.nodeType === 3 || source.nodeType === 4) {
|
|
82
|
+
return document.createTextNode(source.data);
|
|
83
|
+
}
|
|
84
|
+
if (source.nodeType !== 1
|
|
85
|
+
|| source.namespaceURI !== SVG_NS
|
|
86
|
+
|| !SVG_ELEMENTS.has(source.localName)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const clean = document.createElementNS(SVG_NS, source.localName);
|
|
91
|
+
for (const attr of Array.from(source.attributes)) {
|
|
92
|
+
if (attr.namespaceURI !== null || !SVG_ATTRIBUTES.has(attr.name)) continue;
|
|
93
|
+
const value = cleanValue(attr.name, attr.value, ctx);
|
|
94
|
+
if (value !== null) clean.setAttribute(attr.name, value);
|
|
95
|
+
}
|
|
96
|
+
for (const child of Array.from(source.childNodes)) {
|
|
97
|
+
const kept = cleanNode(child, ctx);
|
|
98
|
+
if (kept) clean.appendChild(kept);
|
|
99
|
+
}
|
|
100
|
+
return clean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Parse a string as SVG and rebuild it from an allowlist of elements and
|
|
105
|
+
* attributes, so nothing that can run script or load a resource survives.
|
|
106
|
+
* Returns null unless the whole string is one valid <svg> document.
|
|
107
|
+
*/
|
|
108
|
+
function parseSafeSvg(markup) {
|
|
109
|
+
let doc;
|
|
110
|
+
// Inline HTML SVG usually has no xmlns, which the XML parser rejects.
|
|
111
|
+
const source = /^\s*<svg[\s>]/.test(markup) && !/^\s*<svg\b[^>]*\sxmlns\s*=/.test(markup)
|
|
112
|
+
? markup.replace(/^(\s*<svg)/, `$1 xmlns="${SVG_NS}"`)
|
|
113
|
+
: markup;
|
|
114
|
+
try {
|
|
115
|
+
doc = new DOMParser().parseFromString(source,'image/svg+xml');
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const root = doc.documentElement;
|
|
120
|
+
if (!root || root.localName !== 'svg' || doc.getElementsByTagName('parsererror').length > 0) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const ids = new Set();
|
|
124
|
+
collectIds(root, ids);
|
|
125
|
+
return cleanNode(root, { ids, prefix: `dj-icon-${++iconCounter}-` });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A DOM node, including one made in another same-origin window, which fails `instanceof Node`. */
|
|
129
|
+
export function isNode(value) {
|
|
130
|
+
if (value === null || typeof value !== 'object') return false;
|
|
131
|
+
if (typeof Node !== 'undefined' && value instanceof Node) return true;
|
|
132
|
+
const Foreign = value.ownerDocument?.defaultView?.Node;
|
|
133
|
+
return typeof Foreign === 'function' && value instanceof Foreign;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Single place where icons reach the DOM. A Node is appended. A string is a
|
|
138
|
+
* sanitised SVG or plain text unless safeIcons is off; then it is HTML (see
|
|
139
|
+
* SECURITY.md).
|
|
140
|
+
*/
|
|
141
|
+
export function setIcon(el, icon, safeIcons) {
|
|
142
|
+
el.textContent = '';
|
|
143
|
+
if (isNode(icon)) {
|
|
144
|
+
el.appendChild(icon);
|
|
145
|
+
} else if (typeof icon !== 'string') {
|
|
146
|
+
return;
|
|
147
|
+
} else if (!safeIcons) {
|
|
148
|
+
el.innerHTML = icon;
|
|
149
|
+
} else {
|
|
150
|
+
const svg = parseSafeSvg(icon);
|
|
151
|
+
if (svg) {
|
|
152
|
+
el.appendChild(svg);
|
|
153
|
+
} else {
|
|
154
|
+
el.textContent = icon;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
package/types/celebrate.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Parts } from './index';
|
|
2
|
+
import type { CertificateFields } from './certificate';
|
|
2
3
|
|
|
3
4
|
export type CelebratePreset = 'complete' | 'milestone' | 'streak' | 'certificate';
|
|
4
5
|
|
|
@@ -18,6 +19,13 @@ export interface CelebrateOptions {
|
|
|
18
19
|
* A part the host does not have is skipped, with no standalone fallback.
|
|
19
20
|
*/
|
|
20
21
|
parts?: Partial<Parts>;
|
|
22
|
+
/**
|
|
23
|
+
* Open this certificate after the confetti, as the `certificate` preset does.
|
|
24
|
+
* It is loaded on demand from `dopaminejs/certificate`, so a call without it
|
|
25
|
+
* downloads nothing extra. `destroyCelebrations()` does not close it; call
|
|
26
|
+
* `destroyCertificate()`.
|
|
27
|
+
*/
|
|
28
|
+
certificate?: CertificateFields;
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface CertificateFields {
|
|
2
|
+
/** The heading. Rendered as text. The dialog is labelled by it. */
|
|
3
|
+
title?: string;
|
|
4
|
+
/** Who earned it. Rendered as text. */
|
|
5
|
+
recipient?: string;
|
|
6
|
+
/** Rendered as text, as given. */
|
|
7
|
+
date?: string;
|
|
8
|
+
/** Who awarded it. Rendered as text. */
|
|
9
|
+
issuer?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A string follows `safeIcons`: text or allowlisted SVG by default, HTML only
|
|
12
|
+
* with `safeIcons: false`. An image or other Node is moved in, never parsed.
|
|
13
|
+
*/
|
|
14
|
+
logo?: string | Node;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CertificateOptions {
|
|
18
|
+
/** Default true. Same meaning as in `RewardUI`. */
|
|
19
|
+
safeIcons?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Open a completion certificate in a modal with Download (PNG), Print and Close.
|
|
24
|
+
* Only one is open at a time, and a second call closes the first. Closing
|
|
25
|
+
* returns focus to the element that had it. Never throws.
|
|
26
|
+
*/
|
|
27
|
+
export function showCertificate(fields: CertificateFields, options?: CertificateOptions): void;
|
|
28
|
+
|
|
29
|
+
/** Close the open certificate and remove its DOM, print style and listeners. */
|
|
30
|
+
export function destroyCertificate(): void;
|
package/dist/host-D6suk7Ci.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const e=require("./DataService-DKCk0nOu.cjs"),t=require("./SoundManager-DBGDYIkz.cjs"),n=require("./storage-B6z-zaBe.cjs");var r=`#game-ui-overlay,.game-ui-overlay{pointer-events:none;z-index:1000;width:100%;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;position:fixed;top:0;left:0}.game-ui-top-bar{-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#0000004d;align-items:center;gap:12px;padding:12px 16px;display:flex}.level-badge{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:12px;flex-direction:column;align-items:center;min-width:60px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #667eea66}.level-label{color:#fffc;letter-spacing:.5px;font-size:10px;font-weight:600}.level-number{color:#fff;font-size:24px;font-weight:800;line-height:1}.xp-container{flex-direction:column;flex:1;gap:4px;display:flex}.xp-bar-bg{background:#fff3;border-radius:6px;height:12px;overflow:hidden;box-shadow:inset 0 2px 4px #0003}.xp-bar-fill{background:linear-gradient(90deg,#4facfe 0%,#00f2fe 100%);border-radius:6px;height:100%;transition:width .5s ease-out;box-shadow:0 0 10px #4facfe99}.xp-text{color:#fff;text-align:center;text-shadow:0 1px 2px #00000080;font-size:11px;font-weight:600}.streak-badge{background:linear-gradient(135deg,#f80 0%,#f40 100%);border-radius:12px;align-items:center;gap:6px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #f806}.streak-icon{font-size:20px;animation:2s infinite flicker}.streak-number{color:#fff;font-size:18px;font-weight:800}.achievement-popup{top:calc(var(--dopamine-toast-top,80px) + env(safe-area-inset-top,0px));right:var(--dopamine-toast-right,20px);left:var(--dopamine-toast-left,auto);background:var(--dopamine-toast-bg,linear-gradient(135deg, #667eea 0%, #764ba2 100%));border-radius:var(--dopamine-toast-radius,16px);box-shadow:var(--dopamine-toast-shadow,0 8px 32px #0006);z-index:10000;max-width:var(--dopamine-toast-max-width,320px);padding:16px;animation:.5s cubic-bezier(.68,-.55,.265,1.55) slideIn;position:fixed;overflow:hidden}.achievement-shine{background:linear-gradient(90deg,#0000,#ffffff4d,#0000);width:100%;height:100%;animation:2s infinite shine;position:absolute;top:0;left:-100%}.achievement-content{align-items:center;gap:12px;display:flex;position:relative}.achievement-icon{font-size:48px;animation:.6s ease-out bounce}.achievement-info{flex:1}.achievement-title{color:var(--dopamine-toast-muted,#ffffffe6);text-transform:uppercase;letter-spacing:.5px;font-size:12px;font-weight:600}.achievement-name{color:var(--dopamine-toast-text,white);margin:2px 0;font-size:18px;font-weight:800}.achievement-desc{color:var(--dopamine-toast-muted,#fffc);margin-bottom:4px;font-size:13px}.achievement-xp{color:var(--dopamine-toast-accent,gold);background:#fff3;border-radius:8px;padding:4px 8px;font-size:12px;font-weight:700;display:inline-block}.level-up-overlay{z-index:10001;background:#000000d9;justify-content:center;align-items:center;width:100%;height:100%;animation:.3s ease-out fadeIn;display:flex;position:fixed;top:0;left:0}.level-up-content{text-align:center;animation:.5s cubic-bezier(.68,-.55,.265,1.55) scaleIn}.level-up-title{background:linear-gradient(135deg,gold 0%,#ffed4e 100%);-webkit-text-fill-color:transparent;text-transform:uppercase;letter-spacing:4px;-webkit-background-clip:text;background-clip:text;margin-bottom:16px;font-size:32px;font-weight:800}.level-up-number{color:#fff;text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066;font-size:120px;font-weight:900;animation:1s ease-in-out infinite alternate glow}.level-up-subtitle{color:#fffc;margin-top:16px;font-size:24px;font-weight:600}.floating-text{text-shadow:2px 2px #000,-1px -1px #000,1px -1px #000,-1px 1px #000;pointer-events:none;z-index:9998;font-weight:800;animation:2s ease-out forwards floatUp;position:fixed}@keyframes slideIn{0%{opacity:0;transform:translate(400px)}to{opacity:1;transform:translate(0)}}@keyframes slideOut{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(400px)}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes scaleIn{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes glow{0%{text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066}to{text-shadow:0 0 30px gold,0 0 60px #ffd700cc,0 0 90px #ffd70099}}@keyframes shine{0%{left:-100%}30%{left:100%}to{left:100%}}@keyframes flicker{0%,to{opacity:1}50%{opacity:.8}}@keyframes floatUp{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100px)}}@keyframes xp-pulse{0%{transform:scaleY(1)}50%{transform:scaleY(1.2)}to{transform:scaleY(1)}}@keyframes level-pulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@media (width<=480px){.game-ui-top-bar{gap:8px;padding:10px 12px}.level-badge{min-width:50px;padding:6px 10px}.level-number{font-size:20px}.xp-bar-bg{height:10px}.xp-text{font-size:10px}.achievement-popup{right:var(--dopamine-toast-right,12px);max-width:min(var(--dopamine-toast-max-width,320px), calc(100% - 24px))}.level-up-number{font-size:80px}}@media (prefers-reduced-motion:reduce){.game-ui-overlay *,.achievement-popup,.achievement-popup *,.level-up-overlay,.level-up-overlay *{transition:none!important;animation:none!important}.floating-text{animation:none!important}}`,i=`game-ui-overlay`,a={levelUp:`LEVEL UP!`,achievementUnlocked:`Achievement Unlocked!`},o=`dopamine-reward-ui-css`,s=`🔥`,c=e=>e==null?``:String(e),l=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),u=(e,t)=>typeof e==`object`&&e&&l(e,t)?e[t]:void 0,d=`http://www.w3.org/2000/svg`,f=new Set([`svg`,`g`,`path`,`circle`,`ellipse`,`rect`,`line`,`polyline`,`polygon`,`text`,`tspan`,`title`,`desc`,`defs`,`linearGradient`,`radialGradient`,`stop`,`clipPath`,`mask`]),p=new Set(`viewBox.width.height.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.d.points.transform.fill.fill-opacity.fill-rule.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-opacity.opacity.offset.stop-color.stop-opacity.gradientUnits.gradientTransform.clip-path.mask.clip-rule.font-size.font-family.font-weight.text-anchor.id.aria-hidden.aria-label.role`.split(`.`)),m=new Set([`fill`,`stroke`,`clip-path`,`mask`]),h=new Set([`transform`,`gradientTransform`]),g=/^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/,_=/^[#a-zA-Z0-9(),.%\s-]+$/,v=/^[a-zA-Z0-9(),.\s-]+$/,y=/^[A-Za-z][\w.:-]*$/,b=0;function x(e,t){if(e.nodeType!==1||e.namespaceURI!==d||!f.has(e.localName))return;let n=e.getAttribute(`id`);n&&y.test(n)&&t.add(n);for(let n of Array.from(e.childNodes))x(n,t)}function S(e,t,n){if(t.includes(`\\`))return null;let r=t.trim();if(e===`id`)return y.test(r)?n.prefix+r:null;if(m.has(e)){let e=g.exec(r);return e?n.ids.has(e[1])?`url(#${n.prefix}${e[1]})`:null:_.test(r)&&!/url/i.test(r)?r:null}return h.has(e)?v.test(r)&&!/url/i.test(r)?r:null:t.includes(`(`)?e===`stop-color`&&_.test(r)&&!/url/i.test(r)?r:null:t}function C(e,t){if(e.nodeType===3||e.nodeType===4)return document.createTextNode(e.data);if(e.nodeType!==1||e.namespaceURI!==d||!f.has(e.localName))return null;let n=document.createElementNS(d,e.localName);for(let r of Array.from(e.attributes)){if(r.namespaceURI!==null||!p.has(r.name))continue;let e=S(r.name,r.value,t);e!==null&&n.setAttribute(r.name,e)}for(let r of Array.from(e.childNodes)){let e=C(r,t);e&&n.appendChild(e)}return n}function w(e){let t,n=/^\s*<svg[\s>]/.test(e)&&!/^\s*<svg\b[^>]*\sxmlns\s*=/.test(e)?e.replace(/^(\s*<svg)/,`$1 xmlns="${d}"`):e;try{t=new DOMParser().parseFromString(n,`image/svg+xml`)}catch{return null}let r=t.documentElement;if(!r||r.localName!==`svg`||t.getElementsByTagName(`parsererror`).length>0)return null;let i=new Set;return x(r,i),C(r,{ids:i,prefix:`dj-icon-${++b}-`})}var T=class{constructor(e={},t={}){this.parts=e||{};let n=u(t,`text`);this.strings={...a};for(let e of Object.keys(a)){let t=u(n,e);typeof t==`string`&&(this.strings[e]=t)}this.safeIcons=u(t,`safeIcons`)!==!1,this._streakIcon=u(u(t,`icons`),`streak`)??s,this._injectCss=u(t,`injectCss`),this.container=null,this.xpBar=null,this.levelDisplay=null,this.streakDisplay=null,this._style=null,this._xp=null,this._level=null,this._timers=new Set,this._detached=[],this._cardQueue=[],this._cardActive=!1,this._build()}get root(){return this.container}_build(){this._injectCss&&this._addStyles(),this.container=document.createElement(`div`),this.container.className=`game-ui-overlay`,document.getElementById(i)||(this.container.id=i),this.container.innerHTML=`
|
|
2
|
-
<div class="game-ui-top-bar">
|
|
3
|
-
<div class="level-badge">
|
|
4
|
-
<span class="level-label">LVL</span>
|
|
5
|
-
<span class="level-number">1</span>
|
|
6
|
-
</div>
|
|
7
|
-
|
|
8
|
-
<div class="xp-container">
|
|
9
|
-
<div class="xp-bar-bg">
|
|
10
|
-
<div class="xp-bar-fill" style="width: 0%"></div>
|
|
11
|
-
</div>
|
|
12
|
-
<div class="xp-text">0 / 100 XP</div>
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
<div class="streak-badge">
|
|
16
|
-
<span class="streak-icon"></span>
|
|
17
|
-
<span class="streak-number">1</span>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
`,this.liveRegion=document.createElement(`div`),this.liveRegion.className=`dopamine-live-region`,this.liveRegion.setAttribute(`aria-live`,`polite`),this.liveRegion.setAttribute(`role`,`status`),Object.assign(this.liveRegion.style,{position:`absolute`,width:`1px`,height:`1px`,overflow:`hidden`,clipPath:`inset(50%)`,whiteSpace:`nowrap`}),this.container.appendChild(this.liveRegion),document.body.appendChild(this.container),this.levelBadge=this.container.querySelector(`.level-badge`),this.streakBadge=this.container.querySelector(`.streak-badge`),this.xpBar=this.container.querySelector(`.xp-bar-fill`),this.xpText=this.container.querySelector(`.xp-text`),this.levelDisplay=this.container.querySelector(`.level-number`),this.streakDisplay=this.container.querySelector(`.streak-number`),this._setIcon(this.container.querySelector(`.streak-icon`),this._streakIcon)}_addStyles(){if(document.getElementById(o))return;let e=typeof this._injectCss==`string`?this._injectCss:r;this._style=document.createElement(`style`),this._style.id=o,this._style.textContent=e,document.head.appendChild(this._style)}_setIcon(e,t){if(e.textContent=``,typeof Node<`u`&&t instanceof Node)e.appendChild(t);else if(typeof t!=`string`)return;else if(!this.safeIcons)e.innerHTML=t;else{let n=w(t);n?e.appendChild(n):e.textContent=t}}_defer(e,t){let n=setTimeout(()=>{this._timers.delete(n),e()},t);return this._timers.add(n),n}_mount(e){return document.body.appendChild(e),this._detached.push(e),e}_announce(e){this.liveRegion&&(this.liveRegion.textContent=e)}_burst(e,t,n){this.parts.particles?.burst?.(e,t,n)}_replayAnimation(e,t){e&&(e.style.animation=`none`,this._defer(()=>{e.style.animation=t},10))}hud(e){if(!this.container||!e)return;let{xp:t,level:n,progress:r,streak:i,next:a}=e,o=Number.isFinite(r)?r:a>0?t/a:0;this.xpBar.style.width=`${Math.max(0,Math.min(100,o*100))}%`,this.xpText.textContent=Number.isFinite(a)?`${t} / ${a} XP`:`${t} XP`,t!==this._xp&&this._replayAnimation(this.xpBar,`xp-pulse 0.3s ease-out`),this._xp=t,this.levelDisplay.textContent=n,n!==this._level&&this._replayAnimation(this.levelBadge,`level-pulse 0.5s ease-out`),this._level=n,this.streakDisplay.textContent=i,i>=7?this.streakBadge.style.background=`linear-gradient(135deg, #ff6b00 0%, #ff4400 100%)`:i>=3?this.streakBadge.style.background=`linear-gradient(135deg, #ff8800 0%, #ff6b00 100%)`:this.streakBadge.style.background=``}popup(e){if(!this.container||!e||typeof e!=`object`)return;let t=u(e,`kind`);t===`level`?this._levelPopup(e):t===`notice`?this._notice(e):this._card(e,t===`achievement`)}_card(e,t){let{title:n,body:r,meta:i,icon:a}=e;this._cardQueue.push([{title:n,body:r,meta:i,icon:a,burst:u(e,`burst`)},t]),this._nextCard()}_nextCard(){if(this._cardActive)return;let e=this._cardQueue.shift();if(e){this._cardActive=!0;try{this._showCard(e[0],e[1])}catch(e){throw this._cardActive=!1,this._nextCard(),e}}}_showCard(e,t){let n=document.createElement(`div`);n.className=`achievement-popup`,n.innerHTML=`
|
|
21
|
-
<div class="achievement-shine"></div>
|
|
22
|
-
<div class="achievement-content">
|
|
23
|
-
<div class="achievement-icon"></div>
|
|
24
|
-
<div class="achievement-info">
|
|
25
|
-
<div class="achievement-title"></div>
|
|
26
|
-
<div class="achievement-name"></div>
|
|
27
|
-
<div class="achievement-desc"></div>
|
|
28
|
-
<div class="achievement-xp"></div>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
`;let r=c(e.title);n.querySelector(`.achievement-title`).textContent=t?this.strings.achievementUnlocked:``,this._setIcon(n.querySelector(`.achievement-icon`),e.icon),n.querySelector(`.achievement-name`).textContent=r,n.querySelector(`.achievement-desc`).textContent=c(e.body),n.querySelector(`.achievement-xp`).textContent=c(e.meta),this._mount(n),this._announce(t?`${this.strings.achievementUnlocked}: ${r}`:r),e.burst!==!1&&this._defer(()=>{let e=n.getBoundingClientRect();this._burst(`confetti`,{x:e.left+e.width/2,y:e.top+e.height/2},{count:40})},300),this._defer(()=>{n.style.animation=`slideOut 0.3s ease-in forwards`,this._defer(()=>{this._remove(n),this._cardActive=!1,this._nextCard()},300)},4e3)}_levelPopup(e){let t=typeof e.title==`string`&&e.title!==``?e.title:this.strings.levelUp,n=c(e.body),r=document.createElement(`div`);r.className=`level-up-overlay`,r.innerHTML=`
|
|
32
|
-
<div class="level-up-content">
|
|
33
|
-
<div class="level-up-title"></div>
|
|
34
|
-
<div class="level-up-number"></div>
|
|
35
|
-
<div class="level-up-subtitle">Amazing progress!</div>
|
|
36
|
-
</div>
|
|
37
|
-
`,r.querySelector(`.level-up-title`).textContent=t,r.querySelector(`.level-up-number`).textContent=n,this._mount(r),this._announce(`Level up: ${n}`),this._defer(()=>{for(let e=0;e<5;e++)this._defer(()=>{this._burst(`confetti`,{x:Math.random()*window.innerWidth,y:Math.random()*window.innerHeight*.6},{count:30})},e*200)},300),this._defer(()=>{r.style.opacity=`0`,this._defer(()=>this._remove(r),500)},2500)}_notice(e){let t=window.innerWidth/2,n=window.innerHeight/3,r=c(e.title);e.tier===`legendary`?(this._floatText({text:r,x:t,y:n,color:`#ffd700`,size:`36px`}),this._burst(`stars`,{x:t,y:n},{count:12}),this._burst(`confetti`,{x:t,y:n},{count:25})):e.tier===`rare`?(this._floatText({text:r,x:t,y:n,color:`#ff6b6b`,size:`32px`}),this._burst(`fire`,{x:t,y:n},{count:20})):this._floatText({text:r,x:t,y:n,color:`#fff`,size:`24px`}),this._announce(r)}text(e){this._floatText({...e})}_floatText({text:e,x:t,y:n,color:r=`#ffd700`,size:i=`24px`}){if(!this.container)return;let a=document.createElement(`div`);a.className=`floating-text`,a.textContent=c(e),a.style.left=(Number.isFinite(t)?t:window.innerWidth/2)+`px`,a.style.top=(Number.isFinite(n)?n:window.innerHeight/3)+`px`,a.style.color=r,a.style.fontSize=i,this._mount(a),this._defer(()=>this._remove(a),2e3)}_remove(e){e.remove();let t=this._detached.indexOf(e);t>-1&&this._detached.splice(t,1)}destroy(){for(let e of this._timers)clearTimeout(e);this._timers.clear(),this._cardQueue=[],this._cardActive=!1;for(let e of this._detached)e.remove();this._detached=[],this.container?.remove(),this._style?.remove(),this._style=null,this.container=null,this.liveRegion=null,this.xpBar=null,this.xpText=null,this.levelBadge=null,this.streakBadge=null,this.levelDisplay=null,this.streakDisplay=null,this._streakIcon=null}};function E({nav:e=globalThis.navigator,enabled:t=!0}={}){let n=!!t,r=t=>{if(n)try{e.vibrate(t)}catch{}};return{tap:()=>r(10),double:()=>r([10,40,10]),setEnabled(e){n=!!e}}}var D=3,O=[`ui`,`particles`,`sound`,`haptics`],k=e=>typeof e==`object`&&!!e&&typeof e.then==`function`,A=(e,t)=>{k(e)&&e.then(void 0,e=>t.error(e))};function j(){let e=typeof document<`u`&&typeof window<`u`;return{hasDom:e,reducedMotion:e?t.r(window).matches===!0:!1}}function M(e,t,n){if(e===!1)return null;let r=e;return typeof e==`function`&&(r=e(t)),r??n()}function N(e,t){let n=`dopamine_plugin_${t}:`;return{getItem:t=>e.getItem(n+t),setItem:(t,r)=>e.setItem(n+t,r),removeItem:t=>e.removeItem(n+t)}}function P(r={}){let i=r||{},a=j(),o={debug:()=>{},info:()=>{},warn:(...e)=>console.warn(...e),error:(...e)=>console.error(...e),...i.log||{}},s=i.storage||n.n(),c=i.clock||e.a,l={ui:null,particles:null,sound:null,haptics:null},u={};for(let e of O)Object.defineProperty(u,e,{enumerable:!0,get:()=>l[e]});Object.freeze(u);let d={...a,parts:u,storage:s,clock:c},f=M(i.progress,d,()=>new e.n(new e.t({storage:s}),{clock:c,streakDays:i.streakDays,builtinAchievements:i.builtinAchievements,loadRetryMs:i.loadRetryMs}));if(typeof f?.on!=`function`||typeof f?.off!=`function`)throw new e.o(`invalid_progress`,`progress needs on() and off()`);l.particles=M(i.particles,d,()=>a.hasDom?new t.n:null),l.sound=M(i.sound,d,()=>new t.t({storage:s})),l.haptics=M(i.haptics,d,()=>E());try{l.ui=M(i.ui,d,()=>a.hasDom?new T(u):null)}catch(e){throw p(),e}function p(){for(let e of O)try{l[e]?.destroy?.()}catch(e){o.error(e)}}let m=f,h=[],g=!1,_=e=>t=>{try{A(e(t),o)}catch(e){o.error(e)}},v=()=>{let e=l.ui;if(!e||typeof f.snapshot!=`function`||typeof f.getXPForNextLevel!=`function`)return;let t=f.snapshot(),{total:n,progress:r}=f.getXPForNextLevel();e.hud({xp:t.xp,level:t.level,progress:r,streak:t.streak.current,next:n})};h.push(m.on(`xp_gained`,_(e=>{v(),e.leveledUp||l.sound?.play(`xp`)})),m.on(`level_up`,_(e=>{v(),l.ui?.popup({kind:`level`,title:``,body:String(e.newLevel)}),l.sound?.play(`level_up`)})),m.on(`achievement_unlocked`,_(e=>{l.ui?.popup({kind:`achievement`,title:e.name,body:e.description,icon:e.icon,meta:`+${e.xp??0} XP`}),l.sound?.play(`achievement`)})),m.on(`streak_updated`,_(v)),m.on(`player_reset`,_(v)),m.on(`load_recovered`,_(v)),m.on(`personal_best`,_(e=>{l.ui?.popup({kind:`notice`,title:`New High Score: ${e.score}!`,tier:`legendary`}),l.sound?.play(`personal_best`)})));let y=new Map,b=[];function x(t){if(typeof t!=`object`||!t||typeof t.name!=`string`||!/^[a-z0-9-]+$/.test(t.name)||typeof t.install!=`function`)throw new e.o(`plugin_invalid`,`a plugin needs a name (a-z, 0-9 and -) and an install function`);if(t.api!==3)throw new e.o(`plugin_api`,`${t.name} was built for api ${t.api}, this host is api 3`);if(y.has(t.name))throw new e.o(`plugin_duplicate`,`${t.name} is already installed`);for(let n of t.after||[])if(!y.has(n)||!y.get(n).done)throw new e.o(`plugin_order`,`${t.name} must come after ${n}`);for(let n of t.requires||[])if(!O.includes(n)||l[n]===null)throw new e.o(`plugin_requires`,`${t.name} requires the ${n} part, which is not set`)}function S(e){for(let t of e.offs)t();e.offs.clear(),y.delete(e.name);let t=b.indexOf(e);t>-1&&b.splice(t,1)}function C(e){if(e.removed)return;e.removed=!0;let t=e.disposer;e.disposer=null;try{t?.()}catch(e){o.error(e)}S(e)}function w(t){let{name:n}=t;return{progress:f,parts:u,events:{on(e,n){let r=m.on(e,n),i=()=>{r(),t.offs.delete(i)};return t.offs.add(i),i},off:(e,t)=>m.off(e,t),emit(t,r){if(typeof t!=`string`||!t.startsWith(`${n}:`))throw new e.o(`plugin_event`,`${n} may only emit events named ${n}:<event>`);m.emit(t,r)}},storage:N(s,n),clock:c,log:o,env:{hasDom:a.hasDom,reducedMotion:a.reducedMotion},plugin:e=>y.has(e)&&y.get(e).done?y.get(e).handle:null,expose:e=>{t.handle=e}}}function D(t){if(g)throw new e.o(`disposed`,`the host was disposed`);x(t);let n={name:t.name,done:!1,removed:!1,disposer:null,handle:null,offs:new Set};y.set(t.name,n);let r=e=>(n.done=!0,typeof e==`function`&&(n.disposer=e),n.removed||g?(n.removed=!1,C(n),n):(b.push(n),n)),i=e=>{throw S(n),e},a;try{a=t.install(w(n))}catch(e){return i(e)}return k(a)?a.then(r,i):r(a)}let P=null;function F(t){if(g)throw new e.o(`disposed`,`the host was disposed`);if(P===null){let e=D(t);if(k(e)){let t=e.then(e=>e,e=>{throw e});return P=t.then(()=>{P=null},()=>{P=null}),{record:null,done:t}}return{record:e,done:Promise.resolve(e)}}let n=P.then(()=>D(t));return P=n.then(()=>{P=null},()=>{P=null}),{record:null,done:n}}function I(e){let{record:t,done:n}=F(e);if(t)return()=>C(t);let r=null,i=!1;return n.then(e=>{r=e,i&&C(e)},e=>o.error(e)),()=>{r?C(r):i=!0}}let L=Promise.resolve();try{for(let e of i.plugins||[]){let{done:t}=F(e);L=L.then(()=>t)}}catch(e){throw R(),e}L=L.catch(e=>{throw R(),e});function R(){if(!g){g=!0;for(let e of[...b].reverse())C(e);for(let e of[...y.values()])C(e);for(let e of h)e();h.length=0,p(),f.clear?.()}}let z=L.then(()=>typeof f.init==`function`?f.init():void 0).then(()=>(g||v(),B));z.catch(()=>{});let B={progress:f,parts:u,events:m,ready:z,use:I,dispose:R};return B}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return D}});
|