nanosplash 3.0.0 → 3.0.2
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/.github/workflows/ci.yml +50 -44
- package/.github/workflows/vitepress.yml +69 -0
- package/.prettierignore +1 -0
- package/.prettierrc +10 -10
- package/LICENSE +21 -0
- package/README.md +14 -41
- package/bun.lockb +0 -0
- package/coverage/DomUtilities.ts.html +568 -0
- package/coverage/Service.ts.html +718 -0
- package/coverage/Splash.ts.html +448 -0
- package/coverage/SplashQueue.ts.html +232 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +560 -0
- package/coverage/coverage-final.json +5 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +161 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/dist/cjs/ns.cjs +2 -0
- package/dist/es/ns.js +342 -0
- package/dist/iife/ns.iife.js +2 -0
- package/docs/.vitepress/config.ts +75 -0
- package/docs/.vitepress/theme/css/style.css +157 -0
- package/docs/.vitepress/theme/index.ts +16 -0
- package/docs/.vitepress/theme/vue/Card.vue +31 -0
- package/docs/.vitepress/theme/vue/CardGrid.vue +17 -0
- package/docs/.vitepress/theme/vue/Exe.vue +86 -0
- package/docs/.vitepress/theme/vue/PlayGround.vue +50 -0
- package/docs/api/doc/hide.md +69 -0
- package/docs/api/doc/show.md +47 -0
- package/docs/api/start/features.md +17 -0
- package/docs/api/start/install.md +53 -0
- package/docs/api/start/playground.md +11 -0
- package/docs/api/start/usage.md +25 -0
- package/docs/index.md +30 -0
- package/package.json +86 -66
- package/src/style/ns.sass +95 -0
- package/src/ts/core/DomUtilities.ts +161 -0
- package/src/ts/core/Service.ts +211 -0
- package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +18 -10
- package/src/ts/core/Splash.ts +121 -0
- package/src/ts/core/SplashInterface.ts +46 -0
- package/src/ts/core/SplashQueue.ts +49 -0
- package/src/ts/main.ts +9 -0
- package/src/ts/types/Types.ts +3 -0
- package/src/ts/types/global.d.ts +14 -0
- package/src/vite-env.d.ts +0 -8
- package/tests/DomUtilities.spec.ts +117 -0
- package/tests/Guid.spec.ts +5 -5
- package/tests/Service.spec.ts +198 -0
- package/tests/Splash.spec.ts +64 -0
- package/tests/TestUtilities.ts +48 -0
- package/tsconfig.json +21 -20
- package/vite.config.ts +14 -22
- package/dist/main.css +0 -1
- package/dist/ns.cjs.js +0 -1
- package/dist/ns.es.js +0 -330
- package/dist/ns.iife.js +0 -2
- package/index.html +0 -52
- package/src/main.ts +0 -8
- package/src/sass/ns.sass +0 -86
- package/src/ts/core/Nanosplash/Nanosplash.ts +0 -97
- package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +0 -42
- package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +0 -178
- package/src/ts/core/Nanosplash/services/NanosplashService.ts +0 -222
- package/src/ts/types/Alias.d.ts +0 -1
- package/src/ts/types/Nanosplash.d.ts +0 -18
- package/src/ts/types/NanosplashService.d.ts +0 -1
- package/src/ts/util/Guid.ts +0 -13
- package/src/ts/util/Stack.ts +0 -73
- package/tests/Nanosplash.spec.ts +0 -64
- package/tests/NanosplashRepository.spec.ts +0 -91
- package/tests/NanosplashService.spec.ts +0 -119
- package/tests/Stack.spec.ts +0 -56
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var addSorting = (function() {
|
|
3
|
+
'use strict';
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector('.coverage-summary');
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector('thead tr');
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector('tbody');
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onFilterInput() {
|
|
28
|
+
const searchValue = document.getElementById('fileSearch').value;
|
|
29
|
+
const rows = document.getElementsByTagName('tbody')[0].children;
|
|
30
|
+
for (let i = 0; i < rows.length; i++) {
|
|
31
|
+
const row = rows[i];
|
|
32
|
+
if (
|
|
33
|
+
row.textContent
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.includes(searchValue.toLowerCase())
|
|
36
|
+
) {
|
|
37
|
+
row.style.display = '';
|
|
38
|
+
} else {
|
|
39
|
+
row.style.display = 'none';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// loads the search box
|
|
45
|
+
function addSearchBox() {
|
|
46
|
+
var template = document.getElementById('filterTemplate');
|
|
47
|
+
var templateClone = template.content.cloneNode(true);
|
|
48
|
+
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
49
|
+
template.parentElement.appendChild(templateClone);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// loads all columns
|
|
53
|
+
function loadColumns() {
|
|
54
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
55
|
+
colNode,
|
|
56
|
+
cols = [],
|
|
57
|
+
col,
|
|
58
|
+
i;
|
|
59
|
+
|
|
60
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
61
|
+
colNode = colNodes[i];
|
|
62
|
+
col = {
|
|
63
|
+
key: colNode.getAttribute('data-col'),
|
|
64
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
65
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
66
|
+
};
|
|
67
|
+
cols.push(col);
|
|
68
|
+
if (col.sortable) {
|
|
69
|
+
col.defaultDescSort = col.type === 'number';
|
|
70
|
+
colNode.innerHTML =
|
|
71
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return cols;
|
|
75
|
+
}
|
|
76
|
+
// attaches a data attribute to every tr element with an object
|
|
77
|
+
// of data values keyed by column name
|
|
78
|
+
function loadRowData(tableRow) {
|
|
79
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
|
80
|
+
colNode,
|
|
81
|
+
col,
|
|
82
|
+
data = {},
|
|
83
|
+
i,
|
|
84
|
+
val;
|
|
85
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
86
|
+
colNode = tableCols[i];
|
|
87
|
+
col = cols[i];
|
|
88
|
+
val = colNode.getAttribute('data-value');
|
|
89
|
+
if (col.type === 'number') {
|
|
90
|
+
val = Number(val);
|
|
91
|
+
}
|
|
92
|
+
data[col.key] = val;
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
// loads all row data
|
|
97
|
+
function loadData() {
|
|
98
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
|
99
|
+
i;
|
|
100
|
+
|
|
101
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
102
|
+
rows[i].data = loadRowData(rows[i]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// sorts the table using the data for the ith column
|
|
106
|
+
function sortByIndex(index, desc) {
|
|
107
|
+
var key = cols[index].key,
|
|
108
|
+
sorter = function(a, b) {
|
|
109
|
+
a = a.data[key];
|
|
110
|
+
b = b.data[key];
|
|
111
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
112
|
+
},
|
|
113
|
+
finalSorter = sorter,
|
|
114
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
115
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
|
116
|
+
rows = [],
|
|
117
|
+
i;
|
|
118
|
+
|
|
119
|
+
if (desc) {
|
|
120
|
+
finalSorter = function(a, b) {
|
|
121
|
+
return -1 * sorter(a, b);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
126
|
+
rows.push(rowNodes[i]);
|
|
127
|
+
tableBody.removeChild(rowNodes[i]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
rows.sort(finalSorter);
|
|
131
|
+
|
|
132
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
133
|
+
tableBody.appendChild(rows[i]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// removes sort indicators for current column being sorted
|
|
137
|
+
function removeSortIndicators() {
|
|
138
|
+
var col = getNthColumn(currentSort.index),
|
|
139
|
+
cls = col.className;
|
|
140
|
+
|
|
141
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
142
|
+
col.className = cls;
|
|
143
|
+
}
|
|
144
|
+
// adds sort indicators for current column being sorted
|
|
145
|
+
function addSortIndicators() {
|
|
146
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
147
|
+
? ' sorted-desc'
|
|
148
|
+
: ' sorted';
|
|
149
|
+
}
|
|
150
|
+
// adds event listeners for all sorter widgets
|
|
151
|
+
function enableUI() {
|
|
152
|
+
var i,
|
|
153
|
+
el,
|
|
154
|
+
ithSorter = function ithSorter(i) {
|
|
155
|
+
var col = cols[i];
|
|
156
|
+
|
|
157
|
+
return function() {
|
|
158
|
+
var desc = col.defaultDescSort;
|
|
159
|
+
|
|
160
|
+
if (currentSort.index === i) {
|
|
161
|
+
desc = !currentSort.desc;
|
|
162
|
+
}
|
|
163
|
+
sortByIndex(i, desc);
|
|
164
|
+
removeSortIndicators();
|
|
165
|
+
currentSort.index = i;
|
|
166
|
+
currentSort.desc = desc;
|
|
167
|
+
addSortIndicators();
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
171
|
+
if (cols[i].sortable) {
|
|
172
|
+
// add the click event handler on the th so users
|
|
173
|
+
// dont have to click on those tiny arrows
|
|
174
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
175
|
+
if (el.addEventListener) {
|
|
176
|
+
el.addEventListener('click', ithSorter(i));
|
|
177
|
+
} else {
|
|
178
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// adds sorting functionality to the UI
|
|
184
|
+
return function() {
|
|
185
|
+
if (!getTable()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
cols = loadColumns();
|
|
189
|
+
loadData();
|
|
190
|
+
addSearchBox();
|
|
191
|
+
addSortIndicators();
|
|
192
|
+
enableUI();
|
|
193
|
+
};
|
|
194
|
+
})();
|
|
195
|
+
|
|
196
|
+
window.addEventListener('load', addSorting);
|
package/dist/cjs/ns.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var v=(s,e,t)=>e in s?m(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var r=(s,e,t)=>(v(s,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const y="3.0.1",a=class a{constructor(){r(this,"id");r(this,"element");this.element=w(),this.element.id=this.id=a.generateGUID()}static generateGUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}getId(){return this.id}getElement(){return this.element}getTextElement(){var e,t;return((t=(e=this.getElement())==null?void 0:e.firstElementChild)==null?void 0:t.firstElementChild)??null}setText(e){return this.getTextElement().innerText=e,e.length>0?this.showText():this.hideText(),this}showText(){return S(this.getTextElement()),this}hideText(){return I(this.getTextElement()),this}delete(){return this.id=null,this.element!==null&&(this.element.innerHTML="",this.element.remove(),this.element=null),this.element===null}};r(a,"NSClass","ns"),r(a,"NSHostClass","nsh");let o=a;function x(s){return(e=>(()=>e.firstChild)(e.innerHTML=s))(document.createElement("div"))}function w(){return x('<div class=ns><div class=nsc><div class=nst></div><div class=nss><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>')}function b(s,e){e.children.length>0?e.insertBefore(s,e.children.item(0)):e.append(s)}function p(s){s==null||s.classList.add(o.NSHostClass)}function g(s){s==null||s.classList.remove(o.NSHostClass)}function S(s){s.style.display="flex"}function I(s){s.style.display="none"}function h(s){switch(typeof s){case"object":const e=s===document.body,t=s instanceof Element;if(e||t)return s;throw new Error("Reference is an object but not an Element instance.");case"string":return document.querySelector(s);default:throw new Error("Reference is not an object or a string.")}}function k(s,e){g(s.parentElement),p(e),b(s,e)}function f(s){const e=Array.from(s.children||[]),t=c.getInstance();let n=null;const d=e.length;for(let l=0;l<d;l++){const u=e[l];if(u.classList.contains(o.NSClass)){n=t.nsQueue.get(u.id)??null;break}}return n}const T=`.ns,.nsh:before{width:100%;height:100%}.ns,.nsh:before{top:0;left:0}.nsc,.ns{display:flex;justify-content:center;align-items:center}.nsh{--color: DarkSlateGray;--size: 20px;--relSize: calc(var(--size) * .9);--font: "Helvetica", "Arial", sans-serif;--weight: 400;--bg: rgba(255, 255, 255, .8);--zIdx: 999999999;--blur: blur(10px)}.nsh{position:relative;z-index:var(--zIdx)}.nsh:before{position:absolute;background-color:var(--bg);content:"";backdrop-filter:var(--blur);-webkit-backdrop-filter:var(--blur);z-index:calc(var(--zIdx) + 1);border-radius:inherit}body.nsh{height:100vh}.ns{position:absolute;z-index:calc(var(--zIdx) + 2)}.nsc{filter:drop-shadow(0 0 .1rem rgba(211,211,211,.5))}.nst{color:var(--color);font-size:var(--size);font-family:var(--font);font-weight:var(--weight);margin-right:var(--relSize);text-shadow:0 0 .06rem rgba(47,79,79,.25)}.nss{display:block;width:var(--relSize);height:var(--relSize)}.nss>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.nss .path{stroke:var(--color);stroke-linecap:round;animation:Dash 1.5s ease-in-out infinite}@keyframes Rotate{to{transform:rotate(360deg)}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}
|
|
2
|
+
`;class E{constructor(){r(this,"queue");this.queue=[]}enqueue(e){return this.queue.push(e),this}dequeue(){return this.queue.shift()}get(e){return this.queue.find(t=>t.getId()===e)}delete(e){const t=this.queue.findIndex(n=>n.getId()===e);if(t!==-1)return this.queue.splice(t,1)[0]}}const i=class i{constructor(){r(this,"version");r(this,"nsQueue");this.version=y,this.nsQueue=new E,i.addStyle()}static addStyle(){const e=x(`<style>${T}</style>`);document.body.append(e)}static getInstance(){return i.instance||(i.instance=new i),i.instance}static assignToWindow(){Object.defineProperty(window,i.WindowAccessorKey,{value:i.getInstance(),writable:!1})}static start(){window[i.WindowAccessorKey]||i.assignToWindow()}createNS(e){const t=new o().setText(e||"");return this.nsQueue.enqueue(t),t}cleanAndRemoveFromDOM(e){var t;return e?(g(((t=e.getElement())==null?void 0:t.parentElement)??null),e.delete()):!1}deleteNS(e){return this.cleanAndRemoveFromDOM(this.nsQueue.delete(e)??null)}show(e){return this.showInside(document.body,e)}showInside(e,t){try{const n=h(e),d=f(n)??this.createNS();k(d.getElement(),n);const l=t?String(t):"";return d.setText(l).getId()}catch(n){return console.error(n),null}}hide(){const e=this.nsQueue.dequeue();return e?(this.cleanAndRemoveFromDOM(e),e.getId()):null}hideAll(){let e=this.nsQueue.dequeue();for(;e;)this.cleanAndRemoveFromDOM(e),e=this.nsQueue.dequeue()}hideId(e){return this.deleteNS(e)?e:null}hideInside(e){try{const t=f(h(e)),n=(t==null?void 0:t.getId())??"";return this.deleteNS(n??"")?n:null}catch(t){return console.error(t),null}}};r(i,"WindowAccessorKey","ns"),r(i,"instance");let c=i;const z={Service:c};exports.Service=c;exports.default=z;
|
package/dist/es/ns.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
var m = Object.defineProperty;
|
|
2
|
+
var v = (s, e, t) => e in s ? m(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var r = (s, e, t) => (v(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
const y = "3.0.1", a = class a {
|
|
5
|
+
/**
|
|
6
|
+
* # Constructor
|
|
7
|
+
* Creates a new Nanosplash instance.
|
|
8
|
+
*/
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
* # ID
|
|
12
|
+
* Each Nanosplash instance is given a unique GUID.
|
|
13
|
+
*/
|
|
14
|
+
r(this, "id");
|
|
15
|
+
/**
|
|
16
|
+
* # Element
|
|
17
|
+
* The root element of the Nanosplash component.
|
|
18
|
+
*/
|
|
19
|
+
r(this, "element");
|
|
20
|
+
this.element = w(), this.element.id = this.id = a.generateGUID();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* # Generate GUID
|
|
24
|
+
* @returns {GUIDString} A GUID string.
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
static generateGUID() {
|
|
28
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
29
|
+
const t = Math.random() * 16 | 0;
|
|
30
|
+
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @inheritdoc
|
|
35
|
+
*/
|
|
36
|
+
getId() {
|
|
37
|
+
return this.id;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritdoc
|
|
41
|
+
*/
|
|
42
|
+
getElement() {
|
|
43
|
+
return this.element;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @inheritdoc
|
|
47
|
+
*/
|
|
48
|
+
getTextElement() {
|
|
49
|
+
var e, t;
|
|
50
|
+
return ((t = (e = this.getElement()) == null ? void 0 : e.firstElementChild) == null ? void 0 : t.firstElementChild) ?? null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @inheritdoc
|
|
54
|
+
*/
|
|
55
|
+
setText(e) {
|
|
56
|
+
return this.getTextElement().innerText = e, e.length > 0 ? this.showText() : this.hideText(), this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @inheritdoc
|
|
60
|
+
*/
|
|
61
|
+
showText() {
|
|
62
|
+
return I(this.getTextElement()), this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @inheritdoc
|
|
66
|
+
*/
|
|
67
|
+
hideText() {
|
|
68
|
+
return S(this.getTextElement()), this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @inheritdoc
|
|
72
|
+
*/
|
|
73
|
+
delete() {
|
|
74
|
+
return this.id = null, this.element !== null && (this.element.innerHTML = "", this.element.remove(), this.element = null), this.element === null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* # CSS Class Name
|
|
79
|
+
* The main CSS class name of the root element of a Nanosplash component.
|
|
80
|
+
*/
|
|
81
|
+
r(a, "NSClass", "ns"), /**
|
|
82
|
+
* # Host CSS Class Name
|
|
83
|
+
* The CSS class name of the host element of a Nanosplash component.
|
|
84
|
+
* The host element is the element that the Nanosplash is attached to.
|
|
85
|
+
*/
|
|
86
|
+
r(a, "NSHostClass", "nsh");
|
|
87
|
+
let o = a;
|
|
88
|
+
function x(s) {
|
|
89
|
+
return ((e) => (
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
(() => e.firstChild)(e.innerHTML = s)
|
|
92
|
+
))(
|
|
93
|
+
document.createElement("div")
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
function w() {
|
|
97
|
+
return x(
|
|
98
|
+
'<div class=ns><div class=nsc><div class=nst></div><div class=nss><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>'
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
function b(s, e) {
|
|
102
|
+
e.children.length > 0 ? e.insertBefore(s, e.children.item(0)) : e.append(s);
|
|
103
|
+
}
|
|
104
|
+
function p(s) {
|
|
105
|
+
s == null || s.classList.add(o.NSHostClass);
|
|
106
|
+
}
|
|
107
|
+
function g(s) {
|
|
108
|
+
s == null || s.classList.remove(o.NSHostClass);
|
|
109
|
+
}
|
|
110
|
+
function I(s) {
|
|
111
|
+
s.style.display = "flex";
|
|
112
|
+
}
|
|
113
|
+
function S(s) {
|
|
114
|
+
s.style.display = "none";
|
|
115
|
+
}
|
|
116
|
+
function h(s) {
|
|
117
|
+
switch (typeof s) {
|
|
118
|
+
case "object":
|
|
119
|
+
const e = s === document.body, t = s instanceof Element;
|
|
120
|
+
if (e || t)
|
|
121
|
+
return s;
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Reference is an object but not an Element instance."
|
|
124
|
+
);
|
|
125
|
+
case "string":
|
|
126
|
+
return document.querySelector(s);
|
|
127
|
+
default:
|
|
128
|
+
throw new Error("Reference is not an object or a string.");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function k(s, e) {
|
|
132
|
+
g(s.parentElement), p(e), b(s, e);
|
|
133
|
+
}
|
|
134
|
+
function f(s) {
|
|
135
|
+
const e = Array.from(s.children || []), t = d.getInstance();
|
|
136
|
+
let n = null;
|
|
137
|
+
const c = e.length;
|
|
138
|
+
for (let l = 0; l < c; l++) {
|
|
139
|
+
const u = e[l];
|
|
140
|
+
if (u.classList.contains(o.NSClass)) {
|
|
141
|
+
n = t.nsQueue.get(u.id) ?? null;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return n;
|
|
146
|
+
}
|
|
147
|
+
const E = `.ns,.nsh:before{width:100%;height:100%}.ns,.nsh:before{top:0;left:0}.nsc,.ns{display:flex;justify-content:center;align-items:center}.nsh{--color: DarkSlateGray;--size: 20px;--relSize: calc(var(--size) * .9);--font: "Helvetica", "Arial", sans-serif;--weight: 400;--bg: rgba(255, 255, 255, .8);--zIdx: 999999999;--blur: blur(10px)}.nsh{position:relative;z-index:var(--zIdx)}.nsh:before{position:absolute;background-color:var(--bg);content:"";backdrop-filter:var(--blur);-webkit-backdrop-filter:var(--blur);z-index:calc(var(--zIdx) + 1);border-radius:inherit}body.nsh{height:100vh}.ns{position:absolute;z-index:calc(var(--zIdx) + 2)}.nsc{filter:drop-shadow(0 0 .1rem rgba(211,211,211,.5))}.nst{color:var(--color);font-size:var(--size);font-family:var(--font);font-weight:var(--weight);margin-right:var(--relSize);text-shadow:0 0 .06rem rgba(47,79,79,.25)}.nss{display:block;width:var(--relSize);height:var(--relSize)}.nss>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.nss .path{stroke:var(--color);stroke-linecap:round;animation:Dash 1.5s ease-in-out infinite}@keyframes Rotate{to{transform:rotate(360deg)}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}
|
|
148
|
+
`;
|
|
149
|
+
class T {
|
|
150
|
+
constructor() {
|
|
151
|
+
r(this, "queue");
|
|
152
|
+
this.queue = [];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* # Enqueue
|
|
156
|
+
* Add a new item to the queue.
|
|
157
|
+
* @param item The item to add to the queue.
|
|
158
|
+
*/
|
|
159
|
+
enqueue(e) {
|
|
160
|
+
return this.queue.push(e), this;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* # Dequeue
|
|
164
|
+
* Remove the first item from the queue.
|
|
165
|
+
* @returns The first item from the queue.
|
|
166
|
+
*/
|
|
167
|
+
dequeue() {
|
|
168
|
+
return this.queue.shift();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* # Get
|
|
172
|
+
* @param id The GUID of the Nanosplash to get.
|
|
173
|
+
* @returns The Nanosplash with the given GUID.
|
|
174
|
+
*/
|
|
175
|
+
get(e) {
|
|
176
|
+
return this.queue.find((t) => t.getId() === e);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* # Delete
|
|
180
|
+
* @param id The GUID of the Nanosplash to delete.
|
|
181
|
+
* @returns The deleted Nanosplash.
|
|
182
|
+
*/
|
|
183
|
+
delete(e) {
|
|
184
|
+
const t = this.queue.findIndex((n) => n.getId() === e);
|
|
185
|
+
if (t !== -1)
|
|
186
|
+
return this.queue.splice(t, 1)[0];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const i = class i {
|
|
190
|
+
/**
|
|
191
|
+
* # Constructor
|
|
192
|
+
* Private constructor to prevent multiple instances.
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
constructor() {
|
|
196
|
+
/**
|
|
197
|
+
* # Version
|
|
198
|
+
*/
|
|
199
|
+
r(this, "version");
|
|
200
|
+
/**
|
|
201
|
+
* @inheritdoc
|
|
202
|
+
*/
|
|
203
|
+
r(this, "nsQueue");
|
|
204
|
+
this.version = y, this.nsQueue = new T(), i.addStyle();
|
|
205
|
+
}
|
|
206
|
+
/**e
|
|
207
|
+
* # Add Style
|
|
208
|
+
* Add Nanosplash CSS to the DOM.
|
|
209
|
+
*/
|
|
210
|
+
static addStyle() {
|
|
211
|
+
const e = x(`<style>${E}</style>`);
|
|
212
|
+
document.body.append(e);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* # Get Instance
|
|
216
|
+
* Singleton instance accessor
|
|
217
|
+
* @returns {Service} NanosplashService instance
|
|
218
|
+
*/
|
|
219
|
+
static getInstance() {
|
|
220
|
+
return i.instance || (i.instance = new i()), i.instance;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* # Assign To Window
|
|
224
|
+
* Assign a NanosplashService instance to the Window object.
|
|
225
|
+
* The NanosplashService instance can be accessed in the window object
|
|
226
|
+
* using the key window accessor key.
|
|
227
|
+
* @see WindowAccessorKey
|
|
228
|
+
* @private
|
|
229
|
+
*/
|
|
230
|
+
static assignToWindow() {
|
|
231
|
+
Object.defineProperty(window, i.WindowAccessorKey, {
|
|
232
|
+
value: i.getInstance(),
|
|
233
|
+
writable: !1
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* # Start
|
|
238
|
+
* Initialize and attach a Nanosplash Service instance to the Window object.
|
|
239
|
+
*/
|
|
240
|
+
static start() {
|
|
241
|
+
window[i.WindowAccessorKey] || i.assignToWindow();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* # Create Nanosplash
|
|
245
|
+
* Return new Nanosplash instance and push it to the stack.
|
|
246
|
+
* @param text Text to display.
|
|
247
|
+
* @returns {Splash} Nanosplash instance.
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
createNS(e) {
|
|
251
|
+
const t = new o().setText(e || "");
|
|
252
|
+
return this.nsQueue.enqueue(t), t;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* # Clean And Remove From DOM
|
|
256
|
+
* Remove Nanosplash from DOM and clean its parent.
|
|
257
|
+
* @param ns Nanosplash instance.
|
|
258
|
+
* @returns True if Nanosplash was removed from DOM.
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
cleanAndRemoveFromDOM(e) {
|
|
262
|
+
var t;
|
|
263
|
+
return e ? (g(((t = e.getElement()) == null ? void 0 : t.parentElement) ?? null), e.delete()) : !1;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* # Delete NS
|
|
267
|
+
* Remove Nanosplash instance from both the stack and the
|
|
268
|
+
* @param guid Nanosplash ID.
|
|
269
|
+
* @returns True if Nanosplash was removed from DOM.
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
deleteNS(e) {
|
|
273
|
+
return this.cleanAndRemoveFromDOM(this.nsQueue.delete(e) ?? null);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @inheritdoc
|
|
277
|
+
*/
|
|
278
|
+
show(e) {
|
|
279
|
+
return this.showInside(document.body, e);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @inheritdoc
|
|
283
|
+
*/
|
|
284
|
+
showInside(e, t) {
|
|
285
|
+
try {
|
|
286
|
+
const n = h(e), c = f(n) ?? this.createNS();
|
|
287
|
+
k(c.getElement(), n);
|
|
288
|
+
const l = t ? String(t) : "";
|
|
289
|
+
return c.setText(l).getId();
|
|
290
|
+
} catch (n) {
|
|
291
|
+
return console.error(n), null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @inheritdoc
|
|
296
|
+
*/
|
|
297
|
+
hide() {
|
|
298
|
+
const e = this.nsQueue.dequeue();
|
|
299
|
+
return e ? (this.cleanAndRemoveFromDOM(e), e.getId()) : null;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* @inheritdoc
|
|
303
|
+
*/
|
|
304
|
+
hideAll() {
|
|
305
|
+
let e = this.nsQueue.dequeue();
|
|
306
|
+
for (; e; )
|
|
307
|
+
this.cleanAndRemoveFromDOM(e), e = this.nsQueue.dequeue();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* @inheritdoc
|
|
311
|
+
*/
|
|
312
|
+
hideId(e) {
|
|
313
|
+
return this.deleteNS(e) ? e : null;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @inheritdoc
|
|
317
|
+
*/
|
|
318
|
+
hideInside(e) {
|
|
319
|
+
try {
|
|
320
|
+
const t = f(h(e)), n = (t == null ? void 0 : t.getId()) ?? "";
|
|
321
|
+
return this.deleteNS(n ?? "") ? n : null;
|
|
322
|
+
} catch (t) {
|
|
323
|
+
return console.error(t), null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* # Window Accessor Key
|
|
329
|
+
* Key to access NanosplashService instance in the Window object.
|
|
330
|
+
*/
|
|
331
|
+
r(i, "WindowAccessorKey", "ns"), /**
|
|
332
|
+
* # Instance
|
|
333
|
+
* Singleton instance of NanosplashService.
|
|
334
|
+
* @private
|
|
335
|
+
*/
|
|
336
|
+
r(i, "instance");
|
|
337
|
+
let d = i;
|
|
338
|
+
const q = { Service: d };
|
|
339
|
+
export {
|
|
340
|
+
d as Service,
|
|
341
|
+
q as default
|
|
342
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E=Object.defineProperty;var T=(l,s,a)=>s in l?E(l,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):l[s]=a;var o=(l,s,a)=>(T(l,typeof s!="symbol"?s+"":s,a),a);(function(){"use strict";const l="3.0.1",c=class c{constructor(){o(this,"id");o(this,"element");this.element=v(),this.element.id=this.id=c.generateGUID()}static generateGUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}getId(){return this.id}getElement(){return this.element}getTextElement(){var e,n;return((n=(e=this.getElement())==null?void 0:e.firstElementChild)==null?void 0:n.firstElementChild)??null}setText(e){return this.getTextElement().innerText=e,e.length>0?this.showText():this.hideText(),this}showText(){return b(this.getTextElement()),this}hideText(){return p(this.getTextElement()),this}delete(){return this.id=null,this.element!==null&&(this.element.innerHTML="",this.element.remove(),this.element=null),this.element===null}};o(c,"NSClass","ns"),o(c,"NSHostClass","nsh");let s=c;function a(t){return(e=>(()=>e.firstChild)(e.innerHTML=t))(document.createElement("div"))}function v(){return a('<div class=ns><div class=nsc><div class=nst></div><div class=nss><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>')}function y(t,e){e.children.length>0?e.insertBefore(t,e.children.item(0)):e.append(t)}function w(t){t==null||t.classList.add(s.NSHostClass)}function f(t){t==null||t.classList.remove(s.NSHostClass)}function b(t){t.style.display="flex"}function p(t){t.style.display="none"}function x(t){switch(typeof t){case"object":const e=t===document.body,n=t instanceof Element;if(e||n)return t;throw new Error("Reference is an object but not an Element instance.");case"string":return document.querySelector(t);default:throw new Error("Reference is not an object or a string.")}}function I(t,e){f(t.parentElement),w(e),y(t,e)}function g(t){const e=Array.from(t.children||[]),n=u.getInstance();let r=null;const h=e.length;for(let d=0;d<h;d++){const m=e[d];if(m.classList.contains(s.NSClass)){r=n.nsQueue.get(m.id)??null;break}}return r}const k=`.ns,.nsh:before{width:100%;height:100%}.ns,.nsh:before{top:0;left:0}.nsc,.ns{display:flex;justify-content:center;align-items:center}.nsh{--color: DarkSlateGray;--size: 20px;--relSize: calc(var(--size) * .9);--font: "Helvetica", "Arial", sans-serif;--weight: 400;--bg: rgba(255, 255, 255, .8);--zIdx: 999999999;--blur: blur(10px)}.nsh{position:relative;z-index:var(--zIdx)}.nsh:before{position:absolute;background-color:var(--bg);content:"";backdrop-filter:var(--blur);-webkit-backdrop-filter:var(--blur);z-index:calc(var(--zIdx) + 1);border-radius:inherit}body.nsh{height:100vh}.ns{position:absolute;z-index:calc(var(--zIdx) + 2)}.nsc{filter:drop-shadow(0 0 .1rem rgba(211,211,211,.5))}.nst{color:var(--color);font-size:var(--size);font-family:var(--font);font-weight:var(--weight);margin-right:var(--relSize);text-shadow:0 0 .06rem rgba(47,79,79,.25)}.nss{display:block;width:var(--relSize);height:var(--relSize)}.nss>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.nss .path{stroke:var(--color);stroke-linecap:round;animation:Dash 1.5s ease-in-out infinite}@keyframes Rotate{to{transform:rotate(360deg)}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}
|
|
2
|
+
`;class S{constructor(){o(this,"queue");this.queue=[]}enqueue(e){return this.queue.push(e),this}dequeue(){return this.queue.shift()}get(e){return this.queue.find(n=>n.getId()===e)}delete(e){const n=this.queue.findIndex(r=>r.getId()===e);if(n!==-1)return this.queue.splice(n,1)[0]}}const i=class i{constructor(){o(this,"version");o(this,"nsQueue");this.version=l,this.nsQueue=new S,i.addStyle()}static addStyle(){const e=a(`<style>${k}</style>`);document.body.append(e)}static getInstance(){return i.instance||(i.instance=new i),i.instance}static assignToWindow(){Object.defineProperty(window,i.WindowAccessorKey,{value:i.getInstance(),writable:!1})}static start(){window[i.WindowAccessorKey]||i.assignToWindow()}createNS(e){const n=new s().setText(e||"");return this.nsQueue.enqueue(n),n}cleanAndRemoveFromDOM(e){var n;return e?(f(((n=e.getElement())==null?void 0:n.parentElement)??null),e.delete()):!1}deleteNS(e){return this.cleanAndRemoveFromDOM(this.nsQueue.delete(e)??null)}show(e){return this.showInside(document.body,e)}showInside(e,n){try{const r=x(e),h=g(r)??this.createNS();I(h.getElement(),r);const d=n?String(n):"";return h.setText(d).getId()}catch(r){return console.error(r),null}}hide(){const e=this.nsQueue.dequeue();return e?(this.cleanAndRemoveFromDOM(e),e.getId()):null}hideAll(){let e=this.nsQueue.dequeue();for(;e;)this.cleanAndRemoveFromDOM(e),e=this.nsQueue.dequeue()}hideId(e){return this.deleteNS(e)?e:null}hideInside(e){try{const n=g(x(e)),r=(n==null?void 0:n.getId())??"";return this.deleteNS(r??"")?r:null}catch(n){return console.error(n),null}}};o(i,"WindowAccessorKey","ns"),o(i,"instance");let u=i;try{u.start()}catch(t){console.warn(t)}})();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineConfig } from 'vitepress'
|
|
2
|
+
|
|
3
|
+
// https://vitepress.dev/reference/site-config
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
title: 'Nanosplash',
|
|
6
|
+
description: 'The tiny loading screen for web artisans',
|
|
7
|
+
base: '/nanosplash/',
|
|
8
|
+
themeConfig: {
|
|
9
|
+
nav: [
|
|
10
|
+
{ text: 'Home', link: '/' },
|
|
11
|
+
{ text: 'Get started', link: '/api/start/install' },
|
|
12
|
+
{ text: 'Playground', link: '/api/start/playground' },
|
|
13
|
+
{ text: 'API documentation', link: '/api/doc/show' },
|
|
14
|
+
],
|
|
15
|
+
|
|
16
|
+
sidebar: {
|
|
17
|
+
'/api/': [
|
|
18
|
+
{
|
|
19
|
+
text: 'Get started',
|
|
20
|
+
items: [
|
|
21
|
+
{
|
|
22
|
+
text: 'Installation',
|
|
23
|
+
link: '/api/start/install',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
text: 'Usage',
|
|
27
|
+
link: '/api/start/usage',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
text: 'Playground',
|
|
31
|
+
link: '/api/start/playground',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
text: 'API Documentation',
|
|
37
|
+
items: [
|
|
38
|
+
{
|
|
39
|
+
text: 'Methods',
|
|
40
|
+
items: [
|
|
41
|
+
{
|
|
42
|
+
text: 'Show',
|
|
43
|
+
link: '/api/doc/show',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
text: 'Hide',
|
|
47
|
+
link: '/api/doc/hide',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
text: 'Features',
|
|
55
|
+
link: '/api/start/features',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
socialLinks: [
|
|
61
|
+
{ icon: 'github', link: 'https://github.com/isakhauge/nanosplash' },
|
|
62
|
+
{ icon: 'twitter', link: 'https://twitter.com/isakhauge' },
|
|
63
|
+
{ icon: 'linkedin', link: 'https://www.linkedin.com/in/isakhauge' },
|
|
64
|
+
],
|
|
65
|
+
|
|
66
|
+
search: {
|
|
67
|
+
provider: 'local',
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
footer: {
|
|
71
|
+
message:
|
|
72
|
+
'Made with 🤍 by <a href="https://twitter.com/isakhauge">Isak Hauge</a>',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
})
|