1 | ;
|
2 | var __values = (this && this.__values) || function(o) {
|
3 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
4 | if (m) return m.call(o);
|
5 | if (o && typeof o.length === "number") return {
|
6 | next: function () {
|
7 | if (o && i >= o.length) o = void 0;
|
8 | return { value: o && o[i++], done: !o };
|
9 | }
|
10 | };
|
11 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
12 | };
|
13 | var __read = (this && this.__read) || function (o, n) {
|
14 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
15 | if (!m) return o;
|
16 | var i = m.call(o), r, ar = [], e;
|
17 | try {
|
18 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
19 | }
|
20 | catch (error) { e = { error: error }; }
|
21 | finally {
|
22 | try {
|
23 | if (r && !r.done && (m = i["return"])) m.call(i);
|
24 | }
|
25 | finally { if (e) throw e.error; }
|
26 | }
|
27 | return ar;
|
28 | };
|
29 | Object.defineProperty(exports, "__esModule", { value: true });
|
30 | exports.Falert = void 0;
|
31 | var CDN_BASE = 'https://unpkg.com/@code_monk/falert@latest/dist/';
|
32 | var Falert = /** @class */ (function () {
|
33 | function Falert(head, body, type) {
|
34 | var e_1, _a;
|
35 | if (type === void 0) { type = "notice"; }
|
36 | var t = document.createElement('template');
|
37 | t.innerHTML = Falert.html.trim();
|
38 | var domNode = t.content.firstChild;
|
39 | domNode.style.zIndex = (Falert.getHighestZindex() + 1).toString(10);
|
40 | // get a new "top" value to push this node down the page
|
41 | var newTop = 35;
|
42 | try {
|
43 | for (var _b = __values(Falert.instances), _c = _b.next(); !_c.done; _c = _b.next()) {
|
44 | var i = _c.value;
|
45 | newTop += i.offsetHeight;
|
46 | }
|
47 | }
|
48 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
49 | finally {
|
50 | try {
|
51 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
52 | }
|
53 | finally { if (e_1) throw e_1.error; }
|
54 | }
|
55 | domNode.style.top = newTop + 'px';
|
56 | domNode.querySelector('.body').classList.add(type);
|
57 | domNode.addEventListener("animationend", function (ev) {
|
58 | domNode.classList.remove('flyin');
|
59 | domNode.classList.add('swaying');
|
60 | });
|
61 | domNode.addEventListener('click', function (ev) {
|
62 | Falert.instances.delete(domNode);
|
63 | domNode.remove();
|
64 | });
|
65 | domNode.querySelector('.body h2').innerHTML = head;
|
66 | domNode.querySelector('.body p').innerHTML = body;
|
67 | domNode.classList.add(type);
|
68 | document.body.appendChild(domNode);
|
69 | Falert.instances.add(domNode);
|
70 | Falert.settings.sounds[type].play();
|
71 | }
|
72 | ;
|
73 | Falert.getHighestZindex = function () {
|
74 | var e_2, _a;
|
75 | var z = 0;
|
76 | try {
|
77 | for (var _b = __values(Falert.instances), _c = _b.next(); !_c.done; _c = _b.next()) {
|
78 | var f = _c.value;
|
79 | var i = Number(f.style.zIndex);
|
80 | if (i > z) {
|
81 | z = i;
|
82 | }
|
83 | }
|
84 | }
|
85 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
86 | finally {
|
87 | try {
|
88 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
89 | }
|
90 | finally { if (e_2) throw e_2.error; }
|
91 | }
|
92 | return z;
|
93 | };
|
94 | Falert.instances = new Set();
|
95 | Falert.settings = {
|
96 | insertionNode: document.body,
|
97 | audio: {
|
98 | volume: 0.25
|
99 | },
|
100 | sounds: {}
|
101 | };
|
102 | (function () {
|
103 | var e_3, _a;
|
104 | // preload audio
|
105 | var sounds = {
|
106 | fatal: CDN_BASE + 'assets/sounds/dramatic.mp3',
|
107 | warning: CDN_BASE + 'assets/sounds/concerning.mp3',
|
108 | notice: CDN_BASE + 'assets/sounds/noteworthy.mp3'
|
109 | };
|
110 | try {
|
111 | for (var _b = __values(Object.entries(sounds)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
112 | var _d = __read(_c.value, 2), k = _d[0], url = _d[1];
|
113 | var a = new Audio();
|
114 | a.addEventListener("error", console.error);
|
115 | a.volume = Falert.settings.audio.volume;
|
116 | a.src = url;
|
117 | Falert.settings.sounds[k] = a;
|
118 | }
|
119 | }
|
120 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
121 | finally {
|
122 | try {
|
123 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
124 | }
|
125 | finally { if (e_3) throw e_3.error; }
|
126 | }
|
127 | })();
|
128 | Falert.html = "\n\t<div class=\"falert container flyin\">\n\t\t<div class=\"falert body breathing\">\n\t\t\t<h2>Alert!</h2>\n\t\t\t<p>You can't put your finger in the socket</p>\n\t\t</div>\n\t</div>\n\t";
|
129 | return Falert;
|
130 | }());
|
131 | exports.Falert = Falert;
|
132 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFsZXJ0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3RzL2ZhbGVydC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSxJQUFNLFFBQVEsR0FBRyxrREFBa0QsQ0FBQztBQUVwRTtJQWlDQyxnQkFBWSxJQUFZLEVBQUUsSUFBWSxFQUFFLElBQXVCOztRQUF2QixxQkFBQSxFQUFBLGVBQXVCO1FBQzlELElBQU0sQ0FBQyxHQUFHLFFBQVEsQ0FBQyxhQUFhLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDN0MsQ0FBQyxDQUFDLFNBQVMsR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksRUFBRSxDQUFDO1FBQ2pDLElBQU0sT0FBTyxHQUFtQixDQUFDLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQztRQUNyRCxPQUFPLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxDQUFDLE1BQU0sQ0FBQyxnQkFBZ0IsRUFBRSxHQUFHLEN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