nanosplash 3.0.0 → 3.0.1
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/LICENSE +21 -0
- package/README.md +151 -17
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +555 -0
- package/coverage/core/Dom.ts.html +565 -0
- package/coverage/core/Service.ts.html +790 -0
- package/coverage/core/Splash.ts.html +457 -0
- package/coverage/core/index.html +146 -0
- package/coverage/coverage-final.json +9043 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -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/coverage/types/Types.ts.html +121 -0
- package/coverage/types/index.html +116 -0
- package/dist/latest/cjs/ns.cjs +1 -0
- package/dist/latest/cjs/style.css +1 -0
- package/dist/latest/es/ns.js +306 -0
- package/dist/latest/es/style.css +1 -0
- package/dist/latest/iife/ns.iife.js +4 -0
- package/dist/versioned/3.0.1/cjs/ns.cjs +1 -0
- package/dist/versioned/3.0.1/cjs/style.css +1 -0
- package/dist/versioned/3.0.1/es/ns.js +306 -0
- package/dist/versioned/3.0.1/es/style.css +1 -0
- package/dist/versioned/3.0.1/iife/ns.iife.js +2 -0
- package/docs/index.6d66a821.js +1 -0
- package/docs/index.74dbd99e.css +1 -0
- package/docs/index.f34144dc.js +1 -0
- package/docs/index.html +107 -0
- package/index.html +90 -37
- package/package.json +41 -20
- package/src/sass/ns.sass +38 -29
- package/src/ts/core/Dom.ts +160 -0
- package/src/ts/core/Service.ts +235 -0
- package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +17 -7
- package/src/ts/core/Splash.ts +124 -0
- package/src/ts/core/SplashInterface.ts +54 -0
- package/src/ts/main.ts +9 -0
- package/src/ts/types/Types.ts +12 -0
- package/src/ts/types/global.d.ts +14 -0
- package/src/vite-env.d.ts +0 -8
- package/tests/Dom.spec.ts +127 -0
- package/tests/Guid.spec.ts +2 -2
- package/tests/{NanosplashService.spec.ts → Service.spec.ts} +18 -18
- package/tests/{Nanosplash.spec.ts → Splash.spec.ts} +9 -9
- package/tsconfig.json +20 -20
- package/vite.config.ts +28 -22
- package/vite.demo.config.ts +16 -0
- 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/src/main.ts +0 -8
- 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/NanosplashRepository.spec.ts +0 -91
- package/tests/Stack.spec.ts +0 -56
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var S=Object.defineProperty;var N=(t,e,n)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var c=(t,e,n)=>(N(t,typeof e!="symbol"?e+"":e,n),n);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();const v="3.0.1";var u=(t=>(t.Add="add",t.Remove="remove",t))(u||{});const d=class d{constructor(){c(this,"id");c(this,"element");this.element=p(),this.element.id=this.id=d.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)})}getNSContentElement(){return this.getNSElement().firstElementChild}getNSTextElement(){return this.getNSContentElement().firstElementChild}getId(){return this.id}getNSElement(){return this.element}setText(e){return this.getNSTextElement().innerText=e,e.length>0?this.showText():this.hideText(),this}showText(){return E(this.getNSTextElement()),this}hideText(){return I(this.getNSTextElement()),this}remove(){var e;return this.element&&((e=this.element.parentElement)==null||e.removeChild(this.element),delete this.element),this}};c(d,"NSClass","ns"),c(d,"NSHostClass","nsh");let a=d;function p(){return new DOMParser().parseFromString('<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>',"text/html").body.firstChild}function y(t,e){e.children.length>0?e.insertBefore(t,e.children.item(0)):e.append(t)}function f(t,e){t==null||t.classList[e](a.NSHostClass)}function w(t){f(t.getNSElement().parentElement,u.Remove)}function E(t){t.style.display="flex"}function I(t){t.style.display="none"}function x(t){return t instanceof Element?t:document.querySelector(t||"")}function C(t){var e;return((e=t==null?void 0:t.classList)==null?void 0:e.contains(a.NSClass))??!1}function m(t,e){f(t.parentElement,u.Remove),f(e,u.Add),y(t,e)}function g(t){const e=t.firstElementChild;if(e!==null&&C(e)){const s=e.id;return h.getInstance().nsStack.find(l=>l.getId()===s)??null}return null}const i=class i{constructor(){c(this,"version");c(this,"nsStack");this.version=v,this.nsStack=[]}findIndex(e){return this.nsStack.findIndex(e)}find(e){return this.nsStack.find(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(){i.assignToWindow(),window.addEventListener("load",()=>{window[i.WindowAccessorKey]instanceof i||i.assignToWindow()})}createNS(e){const n=new a;return n.setText(e||""),this.nsStack.push(n),n}cleanAndRemove(e){return w(e),e.remove().getId()}stackDelete(e){let n=this.findIndex(r=>r.getId()===e.getId());return n<0?null:(this.nsStack.splice(n,1),e.getId())}deleteNS(e){const n=this.find(e);return n?(this.cleanAndRemove(n),this.stackDelete(n)):null}show(e){let n=g(document.body);return n||(n=this.createNS(),m(n.getNSElement(),document.body)),n.setText(e||"").getId()}showInside(e,n){const r=x(e);if(r){let s=g(r);return s||(s=this.createNS()),m(s.getNSElement(),r),s.setText(n||"").getId()}return null}hide(){const e=this.nsStack.pop();return e?this.cleanAndRemove(e):null}hideAll(){this.nsStack.forEach(this.cleanAndRemove),this.nsStack.splice(0,this.nsStack.length)}hideId(e){return this.deleteNS(n=>n.getId()===e)}hideInside(e){const n=x(e),r=s=>s.getNSElement().parentElement===n;return n?this.deleteNS(r):null}};c(i,"WindowAccessorKey","ns"),c(i,"instance");let h=i;try{h.start()}catch(t){console.warn(t)}
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Nanosplash</title>
|
|
7
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
8
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" />
|
|
9
|
+
<script type="module" crossorigin src="/nanosplash/index.f34144dc.js"></script>
|
|
10
|
+
<link rel="stylesheet" href="/nanosplash/index.74dbd99e.css">
|
|
11
|
+
</head>
|
|
12
|
+
<body class="bg-slate-50 min-w-full min-h-screen">
|
|
13
|
+
<div
|
|
14
|
+
id="main"
|
|
15
|
+
class="min-h-screen flex flex-col justify-center items-center p-5 overflow-hidden">
|
|
16
|
+
<div class="text-slate-700 font-medium text-4xl md:text-4xl xl:text-5xl drop-shadow-md tracking-wide">
|
|
17
|
+
Nanosplash
|
|
18
|
+
</div>
|
|
19
|
+
<div class="mt-5 md:mt-10 flex max-w-md justify-center flex-wrap gap-x-1 gap-y-1 drop-shadow-md">
|
|
20
|
+
<img loading="lazy" src="https://badgen.net/npm/v/nanosplash" alt="Version">
|
|
21
|
+
<img loading="lazy" src="https://badgen.net/npm/license/nanosplash" alt="License">
|
|
22
|
+
<img loading="lazy" src="https://badgen.net/npm/types/nanosplash" alt="Types">
|
|
23
|
+
<img loading="lazy" src="https://badgen.net/bundlephobia/minzip/nanosplash" alt="Minzipped size">
|
|
24
|
+
<img loading="lazy" src="https://badgen.net/bundlephobia/dependency-count/nanosplash" alt="Dependency count">
|
|
25
|
+
<img loading="lazy" src="https://badgen.net/bundlephobia/tree-shaking/nanosplash" alt="Tree shaking">
|
|
26
|
+
</div>
|
|
27
|
+
<div class="mt-5 md:mt-10 flex gap-x-3 w-full max-w-[500px] justify-center">
|
|
28
|
+
<button
|
|
29
|
+
id="run"
|
|
30
|
+
type="button"
|
|
31
|
+
class="py-2 px-3 bg-white text-slate-700 rounded-xl shadow flex items-center gap-x-2 ease-in-out duration-300 shadow-md hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
32
|
+
<span class="material-symbols-outlined">magic_button</span>
|
|
33
|
+
Run demo
|
|
34
|
+
</button>
|
|
35
|
+
<a
|
|
36
|
+
id="doc"
|
|
37
|
+
href="https://github.com/isakhauge/nanosplash"
|
|
38
|
+
type="button"
|
|
39
|
+
class="py-2 px-3 bg-white text-slate-700 rounded-xl shadow flex items-center gap-x-2 ease-in-out duration-300 shadow-md hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
40
|
+
<span class="material-symbols-outlined">menu_book</span>
|
|
41
|
+
Documentation
|
|
42
|
+
</a>
|
|
43
|
+
</div>
|
|
44
|
+
<div
|
|
45
|
+
id="wrapper"
|
|
46
|
+
class="relative min-w-[300px] mt-5 md:mt-20 flex flex-col md:flex-row gap-y-5 md:gap-y-0 md:gap-x-5 justify-stretch items-stretch bg-white 00 p-10 md:p-10 xl:p-20 rounded-xl ease-in-out duration-500 shadow-md hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
47
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#wrapper</div>
|
|
48
|
+
<div
|
|
49
|
+
id="a"
|
|
50
|
+
class="relative bg-white p-8 md:p-10 xl:p-20 rounded-xl shadow-md ease-in-out duration-500 hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
51
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#a</div>
|
|
52
|
+
<div class="text-slate-500 text-base md:text-xl xl:text-2xl font-medium cursor-default">Element A</div>
|
|
53
|
+
</div>
|
|
54
|
+
<div
|
|
55
|
+
id="b"
|
|
56
|
+
class="relative bg-white p-8 md:p-10 xl:p-20 rounded-xl shadow-md ease-in-out duration-500 hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
57
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#b</div>
|
|
58
|
+
<div class="text-slate-500 text-base md:text-xl xl:text-2xl font-medium cursor-default">Element B</div>
|
|
59
|
+
</div>
|
|
60
|
+
<div
|
|
61
|
+
id="c"
|
|
62
|
+
class="relative bg-white p-8 md:p-10 xl:p-20 rounded-xl shadow-md ease-in-out duration-500 hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
63
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#c</div>
|
|
64
|
+
<div class="text-slate-500 text-base md:text-xl xl:text-2xl font-medium cursor-default">Element C</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<script>
|
|
70
|
+
const wait = (ms) => new Promise(r => setTimeout(r, ms))
|
|
71
|
+
const ref = (selector) => document.querySelector(selector)
|
|
72
|
+
const run = ref('#run')
|
|
73
|
+
run.onclick = async () => {
|
|
74
|
+
console.log('Running demo')
|
|
75
|
+
const sec = (n) => n * 1000
|
|
76
|
+
ns.show('Nanosplash')
|
|
77
|
+
await wait(sec(2))
|
|
78
|
+
ns.show('Tiny loading screen')
|
|
79
|
+
await wait(sec(2))
|
|
80
|
+
ns.show('For web artisans')
|
|
81
|
+
await wait(sec(2))
|
|
82
|
+
ns.hide()
|
|
83
|
+
ns.showInside('#wrapper', 'Display over elements')
|
|
84
|
+
await wait(sec(2.25))
|
|
85
|
+
ns.hide()
|
|
86
|
+
ns.showInside('#a', 'Like this')
|
|
87
|
+
await wait(sec(0.5))
|
|
88
|
+
ns.showInside('#b', 'This')
|
|
89
|
+
await wait(sec(0.5))
|
|
90
|
+
ns.showInside('#c', 'Or this')
|
|
91
|
+
await wait(sec(1))
|
|
92
|
+
ns.hideAll()
|
|
93
|
+
ns.show('Simple API')
|
|
94
|
+
await wait(sec(1.5))
|
|
95
|
+
ns.show('1.5kb minzipped')
|
|
96
|
+
await wait(sec(1.5))
|
|
97
|
+
ns.show('No dependencies')
|
|
98
|
+
await wait(sec(1.5))
|
|
99
|
+
ns.show('99% test coverage')
|
|
100
|
+
await wait(sec(1.5))
|
|
101
|
+
ns.show('Nanosplash')
|
|
102
|
+
await wait(sec(2))
|
|
103
|
+
ns.hide()
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
</body>
|
|
107
|
+
</html>
|
package/index.html
CHANGED
|
@@ -3,50 +3,103 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Nanosplash
|
|
6
|
+
<title>Nanosplash</title>
|
|
7
7
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
8
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" />
|
|
8
9
|
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div
|
|
11
|
-
id="main"
|
|
12
|
-
class="bg-slate-50 h-screen flex flex-col justify-center items-center">
|
|
13
|
-
<div class="text-slate-700 text-5xl">Nanosplash</div>
|
|
14
|
-
<div class="text-slate-400 text-xl mt-5">Demo of v3.0.0</div>
|
|
15
|
-
<div class="mt-20 mb-10 text-lg font-mono text-slate-500">ns.showInside(<span class="text-slate-700 font-bold">selectorOrElement</span>, <span class="text-slate-700 font-bold">text</span>)</div>
|
|
16
|
-
<div class="flex gap-x-3">
|
|
17
|
-
<input id="code" type="text" class="appearance-none w-[500px] box-content flex p-4 bg-slate-700 font-mono text-white rounded shadow-xl" placeholder="Write JS code here">
|
|
18
|
-
<button id="run" type="button" class="p-4 bg-slate-500 text-white rounded shadow-xl">Run code</button>
|
|
19
|
-
</div>
|
|
10
|
+
<body class="bg-slate-50 min-w-full min-h-screen">
|
|
20
11
|
<div
|
|
21
|
-
id="
|
|
22
|
-
class="
|
|
23
|
-
<div class="
|
|
24
|
-
|
|
25
|
-
id="a"
|
|
26
|
-
class="relative bg-slate-400 p-20 border border-4 border-black/10 rounded shadow-2xl">
|
|
27
|
-
<div class="absolute top-2 left-2 font-mono text-slate-500 px-1 bg-white rounded">Element ID: #a</div>
|
|
28
|
-
<div class="text-white text-2xl font-medium">This is element A</div>
|
|
12
|
+
id="main"
|
|
13
|
+
class="min-h-screen flex flex-col justify-center items-center p-5 overflow-hidden">
|
|
14
|
+
<div class="text-slate-700 font-medium text-4xl md:text-4xl xl:text-5xl drop-shadow-md tracking-wide">
|
|
15
|
+
Nanosplash
|
|
29
16
|
</div>
|
|
30
|
-
<div
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
<
|
|
17
|
+
<div class="mt-5 md:mt-10 flex max-w-md justify-center flex-wrap gap-x-1 gap-y-1 drop-shadow-md">
|
|
18
|
+
<img loading="lazy" src="https://badgen.net/npm/v/nanosplash" alt="Version">
|
|
19
|
+
<img loading="lazy" src="https://badgen.net/npm/license/nanosplash" alt="License">
|
|
20
|
+
<img loading="lazy" src="https://badgen.net/npm/types/nanosplash" alt="Types">
|
|
21
|
+
<img loading="lazy" src="https://badgen.net/bundlephobia/minzip/nanosplash" alt="Minzipped size">
|
|
22
|
+
<img loading="lazy" src="https://badgen.net/bundlephobia/dependency-count/nanosplash" alt="Dependency count">
|
|
23
|
+
<img loading="lazy" src="https://badgen.net/bundlephobia/tree-shaking/nanosplash" alt="Tree shaking">
|
|
24
|
+
</div>
|
|
25
|
+
<div class="mt-5 md:mt-10 flex gap-x-3 w-full max-w-[500px] justify-center">
|
|
26
|
+
<button
|
|
27
|
+
id="run"
|
|
28
|
+
type="button"
|
|
29
|
+
class="py-2 px-3 bg-white text-slate-700 rounded-xl shadow flex items-center gap-x-2 ease-in-out duration-300 shadow-md hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
30
|
+
<span class="material-symbols-outlined">magic_button</span>
|
|
31
|
+
Run demo
|
|
32
|
+
</button>
|
|
33
|
+
<a
|
|
34
|
+
id="doc"
|
|
35
|
+
href="https://github.com/isakhauge/nanosplash"
|
|
36
|
+
type="button"
|
|
37
|
+
class="py-2 px-3 bg-white text-slate-700 rounded-xl shadow flex items-center gap-x-2 ease-in-out duration-300 shadow-md hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
38
|
+
<span class="material-symbols-outlined">menu_book</span>
|
|
39
|
+
Documentation
|
|
40
|
+
</a>
|
|
35
41
|
</div>
|
|
36
42
|
<div
|
|
37
|
-
id="
|
|
38
|
-
class="relative
|
|
39
|
-
<div class="absolute top-2 left-2 font-mono text-
|
|
40
|
-
<div
|
|
43
|
+
id="wrapper"
|
|
44
|
+
class="relative min-w-[300px] mt-5 md:mt-20 flex flex-col md:flex-row gap-y-5 md:gap-y-0 md:gap-x-5 justify-stretch items-stretch bg-white 00 p-10 md:p-10 xl:p-20 rounded-xl ease-in-out duration-500 shadow-md hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
45
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#wrapper</div>
|
|
46
|
+
<div
|
|
47
|
+
id="a"
|
|
48
|
+
class="relative bg-white p-8 md:p-10 xl:p-20 rounded-xl shadow-md ease-in-out duration-500 hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
49
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#a</div>
|
|
50
|
+
<div class="text-slate-500 text-base md:text-xl xl:text-2xl font-medium cursor-default">Element A</div>
|
|
51
|
+
</div>
|
|
52
|
+
<div
|
|
53
|
+
id="b"
|
|
54
|
+
class="relative bg-white p-8 md:p-10 xl:p-20 rounded-xl shadow-md ease-in-out duration-500 hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
55
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#b</div>
|
|
56
|
+
<div class="text-slate-500 text-base md:text-xl xl:text-2xl font-medium cursor-default">Element B</div>
|
|
57
|
+
</div>
|
|
58
|
+
<div
|
|
59
|
+
id="c"
|
|
60
|
+
class="relative bg-white p-8 md:p-10 xl:p-20 rounded-xl shadow-md ease-in-out duration-500 hover:shadow-2xl hover:translate-y-[-2px] border border-[rgba(0,0,0,0.02)]">
|
|
61
|
+
<div class="absolute top-2 left-2 font-mono text-xs md:text-sm xl:text-base text-slate-500 cursor-default">#c</div>
|
|
62
|
+
<div class="text-slate-500 text-base md:text-xl xl:text-2xl font-medium cursor-default">Element C</div>
|
|
63
|
+
</div>
|
|
41
64
|
</div>
|
|
42
65
|
</div>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
<script type="module" src="src/ts/main.ts"></script>
|
|
67
|
+
<script>
|
|
68
|
+
const wait = (ms) => new Promise(r => setTimeout(r, ms))
|
|
69
|
+
const ref = (selector) => document.querySelector(selector)
|
|
70
|
+
const run = ref('#run')
|
|
71
|
+
run.onclick = async () => {
|
|
72
|
+
console.log('Running demo')
|
|
73
|
+
const sec = (n) => n * 1000
|
|
74
|
+
ns.show('Nanosplash')
|
|
75
|
+
await wait(sec(2))
|
|
76
|
+
ns.show('Tiny loading screen')
|
|
77
|
+
await wait(sec(2))
|
|
78
|
+
ns.show('For web artisans')
|
|
79
|
+
await wait(sec(2))
|
|
80
|
+
ns.hide()
|
|
81
|
+
ns.showInside('#wrapper', 'Display over elements')
|
|
82
|
+
await wait(sec(2.25))
|
|
83
|
+
ns.hide()
|
|
84
|
+
ns.showInside('#a', 'Like this')
|
|
85
|
+
await wait(sec(0.5))
|
|
86
|
+
ns.showInside('#b', 'This')
|
|
87
|
+
await wait(sec(0.5))
|
|
88
|
+
ns.showInside('#c', 'Or this')
|
|
89
|
+
await wait(sec(1))
|
|
90
|
+
ns.hideAll()
|
|
91
|
+
ns.show('Simple API')
|
|
92
|
+
await wait(sec(1.5))
|
|
93
|
+
ns.show('1.5kb minzipped')
|
|
94
|
+
await wait(sec(1.5))
|
|
95
|
+
ns.show('No dependencies')
|
|
96
|
+
await wait(sec(1.5))
|
|
97
|
+
ns.show('99% test coverage')
|
|
98
|
+
await wait(sec(1.5))
|
|
99
|
+
ns.show('Nanosplash')
|
|
100
|
+
await wait(sec(2))
|
|
101
|
+
ns.hide()
|
|
102
|
+
}
|
|
103
|
+
</script>
|
|
51
104
|
</body>
|
|
52
105
|
</html>
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "nanosplash",
|
|
3
3
|
"description": "The tiny loading screen for web artisans",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "3.0.
|
|
5
|
+
"version": "3.0.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Isak K. Hauge",
|
|
@@ -32,36 +32,57 @@
|
|
|
32
32
|
"url": "https://github.com/isakhauge/nanosplash.git"
|
|
33
33
|
},
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"main": "./dist/ns.js",
|
|
36
|
-
"module": "./dist/ns.
|
|
37
|
-
"source": "./src/
|
|
38
|
-
"unpkg": "./dist/ns.iife.js",
|
|
39
|
-
"style": "./dist/
|
|
35
|
+
"main": "./dist/latest/es/ns.js",
|
|
36
|
+
"module": "./dist/latest/es/ns.js",
|
|
37
|
+
"source": "./src/main.ts",
|
|
38
|
+
"unpkg": "./dist/latest/iife/ns.iife.js",
|
|
39
|
+
"style": "./dist/latest/es/style.css",
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
"types": {
|
|
43
|
+
"require": "./src/ts/types/global.d.ts",
|
|
44
|
+
"default": "./src/ts/types/global.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"browser": {
|
|
47
|
+
"require": "./dist/latest/cjs/ns.cjs",
|
|
48
|
+
"default": "./dist/latest/es/ns.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"require": "./dist/latest/cjs/ns.cjs",
|
|
52
|
+
"default": "./dist/latest/es/ns.js"
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
},
|
|
47
|
-
"types": "./src/ts/types",
|
|
56
|
+
"types": "./src/ts/types/global.d.ts",
|
|
48
57
|
"scripts": {
|
|
49
58
|
"dev": "vite",
|
|
50
|
-
"build": "
|
|
59
|
+
"build": "yarn build:all && yarn build:all:versioned && yarn build:demo",
|
|
60
|
+
"build:es": "tsc && cross-env entry=./src/ts/core/Service.ts format=es yarn vite build -m production --c vite.config.ts",
|
|
61
|
+
"build:cjs": "tsc && cross-env entry=./src/ts/core/Service.ts format=cjs yarn vite build -m production --c vite.config.ts",
|
|
62
|
+
"build:iife": "tsc && cross-env entry=./src/ts/main.ts format=iife yarn vite build -m production --c vite.config.ts",
|
|
63
|
+
"build:es:ver": "tsc && cross-env versioned=true entry=./src/ts/core/Service.ts format=es yarn vite build -m production --c vite.config.ts",
|
|
64
|
+
"build:cjs:ver": "tsc && cross-env versioned=true entry=./src/ts/core/Service.ts format=cjs yarn vite build -m production --c vite.config.ts",
|
|
65
|
+
"build:iife:ver": "tsc && cross-env versioned=true entry=./src/ts/main.ts format=iife yarn vite build -m production --c vite.config.ts",
|
|
66
|
+
"build:all": "yarn build:es && yarn build:cjs && yarn build:iife",
|
|
67
|
+
"build:all:versioned": "yarn build:es:ver && yarn build:cjs:ver && yarn build:iife:ver",
|
|
68
|
+
"build:demo": "tsc && vite build -m production --c vite.demo.config.ts",
|
|
51
69
|
"preview": "vite preview",
|
|
52
70
|
"test": "vitest",
|
|
53
71
|
"test:ui": "vitest --ui",
|
|
54
|
-
"coverage": "vitest
|
|
72
|
+
"coverage": "vitest --coverage"
|
|
55
73
|
},
|
|
56
74
|
"devDependencies": {
|
|
57
|
-
"@types/jsdom": "^21.1.
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
75
|
+
"@types/jsdom": "^21.1.2",
|
|
76
|
+
"@types/node": "^20.5.9",
|
|
77
|
+
"@types/rollup": "^0.54.0",
|
|
78
|
+
"@vitest/coverage-v8": "^0.34.3",
|
|
79
|
+
"@vitest/ui": "^0.34.3",
|
|
80
|
+
"cross-env": "^7.0.3",
|
|
60
81
|
"jsdom": "^22.1.0",
|
|
61
|
-
"sass": "^1.
|
|
62
|
-
"terser": "^5.
|
|
63
|
-
"typescript": "^5.
|
|
64
|
-
"vite": "^4.
|
|
65
|
-
"vitest": "^0.
|
|
82
|
+
"sass": "^1.66.1",
|
|
83
|
+
"terser": "^5.19.3",
|
|
84
|
+
"typescript": "^5.2.2",
|
|
85
|
+
"vite": "^4.4.9",
|
|
86
|
+
"vitest": "^0.34.3"
|
|
66
87
|
}
|
|
67
88
|
}
|
package/src/sass/ns.sass
CHANGED
|
@@ -11,54 +11,63 @@
|
|
|
11
11
|
justify-content: center
|
|
12
12
|
align-items: center
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
--
|
|
17
|
-
--
|
|
18
|
-
--
|
|
19
|
-
--font
|
|
20
|
-
--
|
|
21
|
-
--
|
|
22
|
-
--
|
|
14
|
+
// Nanosplash host scoped varibles
|
|
15
|
+
.nsh
|
|
16
|
+
--color: DarkSlateGray
|
|
17
|
+
--size: 20px
|
|
18
|
+
--relSize: calc(var(--size) * 0.9)
|
|
19
|
+
--font: 'Helvetica', 'Arial', sans-serif
|
|
20
|
+
--weight: 400
|
|
21
|
+
--bg: #{ rgba(White, 0.8) }
|
|
22
|
+
--zIdx: 999999999
|
|
23
|
+
--blur: blur(10px)
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
// Nanosplash host
|
|
26
|
+
.nsh
|
|
25
27
|
position: relative
|
|
26
|
-
z-index: var(--
|
|
28
|
+
z-index: var(--zIdx)
|
|
27
29
|
&::before
|
|
28
30
|
@extend %maximize
|
|
29
31
|
@extend %upper-left
|
|
30
32
|
position: absolute
|
|
31
|
-
background-color: var(--
|
|
33
|
+
background-color: var(--bg)
|
|
32
34
|
content: ''
|
|
33
|
-
backdrop-filter: var(--blur
|
|
34
|
-
-webkit-backdrop-filter: var(--blur
|
|
35
|
-
z-index: calc(var(--
|
|
35
|
+
backdrop-filter: var(--blur)
|
|
36
|
+
-webkit-backdrop-filter: var(--blur)
|
|
37
|
+
z-index: calc(var(--zIdx) + 1)
|
|
38
|
+
border-radius: inherit
|
|
36
39
|
|
|
37
|
-
body
|
|
40
|
+
// When Nanosplash host is the document body
|
|
41
|
+
body.nsh
|
|
38
42
|
height: 100vh
|
|
39
43
|
|
|
44
|
+
// Nanosplash (main element)
|
|
40
45
|
.ns
|
|
41
46
|
@extend %maximize
|
|
42
47
|
@extend %upper-left
|
|
43
48
|
@extend %flex-center-xy
|
|
44
49
|
position: absolute
|
|
45
|
-
z-index: calc(var(--
|
|
50
|
+
z-index: calc(var(--zIdx) + 2)
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
// Nanosplash container
|
|
53
|
+
.nsc
|
|
48
54
|
@extend %flex-center-xy
|
|
55
|
+
filter: drop-shadow(0 0 0.1rem #{ rgba(LightGray, 0.5) })
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
font-
|
|
54
|
-
font-
|
|
55
|
-
|
|
57
|
+
// Nanosplash text
|
|
58
|
+
.nst
|
|
59
|
+
color: var(--color)
|
|
60
|
+
font-size: var(--size)
|
|
61
|
+
font-family: var(--font)
|
|
62
|
+
font-weight: var(--weight)
|
|
63
|
+
margin-right: var(--relSize)
|
|
64
|
+
text-shadow: 0 0 0.06rem #{ rgba(DarkSlateGray, .25) }
|
|
56
65
|
|
|
57
|
-
//
|
|
58
|
-
.
|
|
66
|
+
// Nanosplash spinner
|
|
67
|
+
.nss
|
|
59
68
|
display: block
|
|
60
|
-
width: var(--
|
|
61
|
-
height: var(--
|
|
69
|
+
width: var(--relSize)
|
|
70
|
+
height: var(--relSize)
|
|
62
71
|
& > svg
|
|
63
72
|
animation: Rotate 2s linear infinite
|
|
64
73
|
position: relative
|
|
@@ -66,7 +75,7 @@ body.ns-host
|
|
|
66
75
|
height: inherit
|
|
67
76
|
stroke-width: 8
|
|
68
77
|
& .path
|
|
69
|
-
stroke: var(--
|
|
78
|
+
stroke: var(--color)
|
|
70
79
|
stroke-linecap: round
|
|
71
80
|
animation: Dash 1.5s ease-in-out infinite
|
|
72
81
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// @ts-strict
|
|
2
|
+
|
|
3
|
+
import { Reference, GUIDString, ClassListAction } from '../types/Types'
|
|
4
|
+
import { Service } from './Service'
|
|
5
|
+
import { Splash } from './Splash'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* # DOM Utilities
|
|
9
|
+
* A collection of functions that are used by the Nanosplash classes.
|
|
10
|
+
* @see Splash
|
|
11
|
+
* @see Service
|
|
12
|
+
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* # Create Element
|
|
17
|
+
* Return the main Nanosplash element.
|
|
18
|
+
*/
|
|
19
|
+
export function createElement(): HTMLDivElement {
|
|
20
|
+
return new DOMParser().parseFromString(
|
|
21
|
+
'<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>',
|
|
22
|
+
'text/html'
|
|
23
|
+
).body.firstChild as HTMLDivElement
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* # Inject as First Child
|
|
28
|
+
* Insert element into the target element as its first child.
|
|
29
|
+
* @param element Element to inject.
|
|
30
|
+
* @param targetElement Element in which the first element is to be injected.
|
|
31
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/children
|
|
32
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
|
|
33
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
|
|
34
|
+
* @see https://developer.mozilla.org/docs/Web/API/NodeList/item
|
|
35
|
+
*/
|
|
36
|
+
export function injectAsFirstChild(
|
|
37
|
+
element: Element,
|
|
38
|
+
targetElement: Element
|
|
39
|
+
): void {
|
|
40
|
+
const targetHasChild = targetElement.children.length > 0
|
|
41
|
+
if (targetHasChild) {
|
|
42
|
+
targetElement.insertBefore(element, targetElement.children.item(0))
|
|
43
|
+
} else {
|
|
44
|
+
targetElement.append(element)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* # Set NS Host Class
|
|
50
|
+
* Add or remove the `nsHostClassName` class to the `element`.
|
|
51
|
+
* @param element Element to which the `nsHostClassName` class will be added or removed.
|
|
52
|
+
* @param action Action to perform ('add' or 'remove').
|
|
53
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
|
|
54
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add
|
|
55
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove
|
|
56
|
+
*/
|
|
57
|
+
export function setNSHostClass(
|
|
58
|
+
element: Element | null,
|
|
59
|
+
action: ClassListAction
|
|
60
|
+
): void {
|
|
61
|
+
element?.classList[action](Splash.NSHostClass)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* # Prepare Parent Of
|
|
66
|
+
* Add the `nsHostClassName` class to the parent of the `ns` element.
|
|
67
|
+
* @param ns Nanosplash instance.
|
|
68
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/parentElement
|
|
69
|
+
*/
|
|
70
|
+
export function prepareParentOf(ns: Splash): void {
|
|
71
|
+
setNSHostClass(ns.getNSElement().parentElement, ClassListAction.Add)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* # Clean NS Parent Of
|
|
76
|
+
* Remove the `nsHostClassName` class from the parent of the `ns` element.
|
|
77
|
+
* @param ns Nanosplash instance.
|
|
78
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/parentElement
|
|
79
|
+
*/
|
|
80
|
+
export function cleanNSParentOf(ns: Splash): void {
|
|
81
|
+
setNSHostClass(ns.getNSElement().parentElement, ClassListAction.Remove)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* # Show Element
|
|
86
|
+
* Set the `display` property of the `element` to `flex`.
|
|
87
|
+
* @param element Element to show.
|
|
88
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
|
|
89
|
+
*/
|
|
90
|
+
export function showElement(element: HTMLElement): void {
|
|
91
|
+
element.style.display = 'flex'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* # Hide Element
|
|
96
|
+
* Set the `display` property of the `element` to `none`.
|
|
97
|
+
* @param element Element to hide.
|
|
98
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
|
|
99
|
+
*/
|
|
100
|
+
export function hideElement(element: HTMLElement): void {
|
|
101
|
+
element.style.display = 'none'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* # Element From
|
|
106
|
+
* Convert the element reference to an element.
|
|
107
|
+
* @param ref Reference to an element.
|
|
108
|
+
* @returns { Element | null } Element or null.
|
|
109
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
|
110
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
111
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
|
112
|
+
*/
|
|
113
|
+
export function elementFrom(ref: Reference): Element | null {
|
|
114
|
+
return ref instanceof Element ? ref : document.querySelector(ref || '')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* # Element Is NS
|
|
119
|
+
* Check if the element is a Nanosplash element.
|
|
120
|
+
* This is determined by the presence of the `ns` class on the element.
|
|
121
|
+
* @param element Element to check.
|
|
122
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains
|
|
123
|
+
*/
|
|
124
|
+
export function elementIsNS(element: Element): boolean {
|
|
125
|
+
return element?.classList?.contains(Splash.NSClass) ?? false
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* # Move
|
|
130
|
+
* Move an Element to another Element.
|
|
131
|
+
* @param element Element to move
|
|
132
|
+
* @param targetElement Target element
|
|
133
|
+
*/
|
|
134
|
+
export function move(element: Element, targetElement: Element): void {
|
|
135
|
+
// Clean the current NS host element.
|
|
136
|
+
setNSHostClass(element.parentElement, ClassListAction.Remove)
|
|
137
|
+
// Assign new NS host element.
|
|
138
|
+
setNSHostClass(targetElement, ClassListAction.Add)
|
|
139
|
+
injectAsFirstChild(element, targetElement)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* # Get Recycled NS
|
|
144
|
+
* Return the Nanosplash instance inside the target element if it exists.
|
|
145
|
+
* @param targetElement Element wherein the Nanosplash instance is to reside.
|
|
146
|
+
* @returns { Nanosplash | null } Nanosplash instance or null.
|
|
147
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/firstElementChild
|
|
148
|
+
*/
|
|
149
|
+
export function getRecycledNS(targetElement: Element): Splash | null {
|
|
150
|
+
const firstChild = targetElement.firstElementChild
|
|
151
|
+
const hasChild = firstChild !== null
|
|
152
|
+
const targetAlreadyHasNS = hasChild && elementIsNS(firstChild)
|
|
153
|
+
if (targetAlreadyHasNS) {
|
|
154
|
+
const id: GUIDString = firstChild.id
|
|
155
|
+
const nss = Service.getInstance()
|
|
156
|
+
return nss.nsStack.find((ns: Splash) => ns.getId() === id) ?? null
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return null
|
|
160
|
+
}
|