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.
Files changed (77) hide show
  1. package/.github/workflows/ci.yml +50 -44
  2. package/.github/workflows/vitepress.yml +69 -0
  3. package/.prettierignore +1 -0
  4. package/.prettierrc +10 -10
  5. package/LICENSE +21 -0
  6. package/README.md +14 -41
  7. package/bun.lockb +0 -0
  8. package/coverage/DomUtilities.ts.html +568 -0
  9. package/coverage/Service.ts.html +718 -0
  10. package/coverage/Splash.ts.html +448 -0
  11. package/coverage/SplashQueue.ts.html +232 -0
  12. package/coverage/base.css +224 -0
  13. package/coverage/block-navigation.js +87 -0
  14. package/coverage/clover.xml +560 -0
  15. package/coverage/coverage-final.json +5 -0
  16. package/coverage/favicon.png +0 -0
  17. package/coverage/index.html +161 -0
  18. package/coverage/prettify.css +1 -0
  19. package/coverage/prettify.js +2 -0
  20. package/coverage/sort-arrow-sprite.png +0 -0
  21. package/coverage/sorter.js +196 -0
  22. package/dist/cjs/ns.cjs +2 -0
  23. package/dist/es/ns.js +342 -0
  24. package/dist/iife/ns.iife.js +2 -0
  25. package/docs/.vitepress/config.ts +75 -0
  26. package/docs/.vitepress/theme/css/style.css +157 -0
  27. package/docs/.vitepress/theme/index.ts +16 -0
  28. package/docs/.vitepress/theme/vue/Card.vue +31 -0
  29. package/docs/.vitepress/theme/vue/CardGrid.vue +17 -0
  30. package/docs/.vitepress/theme/vue/Exe.vue +86 -0
  31. package/docs/.vitepress/theme/vue/PlayGround.vue +50 -0
  32. package/docs/api/doc/hide.md +69 -0
  33. package/docs/api/doc/show.md +47 -0
  34. package/docs/api/start/features.md +17 -0
  35. package/docs/api/start/install.md +53 -0
  36. package/docs/api/start/playground.md +11 -0
  37. package/docs/api/start/usage.md +25 -0
  38. package/docs/index.md +30 -0
  39. package/package.json +86 -66
  40. package/src/style/ns.sass +95 -0
  41. package/src/ts/core/DomUtilities.ts +161 -0
  42. package/src/ts/core/Service.ts +211 -0
  43. package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +18 -10
  44. package/src/ts/core/Splash.ts +121 -0
  45. package/src/ts/core/SplashInterface.ts +46 -0
  46. package/src/ts/core/SplashQueue.ts +49 -0
  47. package/src/ts/main.ts +9 -0
  48. package/src/ts/types/Types.ts +3 -0
  49. package/src/ts/types/global.d.ts +14 -0
  50. package/src/vite-env.d.ts +0 -8
  51. package/tests/DomUtilities.spec.ts +117 -0
  52. package/tests/Guid.spec.ts +5 -5
  53. package/tests/Service.spec.ts +198 -0
  54. package/tests/Splash.spec.ts +64 -0
  55. package/tests/TestUtilities.ts +48 -0
  56. package/tsconfig.json +21 -20
  57. package/vite.config.ts +14 -22
  58. package/dist/main.css +0 -1
  59. package/dist/ns.cjs.js +0 -1
  60. package/dist/ns.es.js +0 -330
  61. package/dist/ns.iife.js +0 -2
  62. package/index.html +0 -52
  63. package/src/main.ts +0 -8
  64. package/src/sass/ns.sass +0 -86
  65. package/src/ts/core/Nanosplash/Nanosplash.ts +0 -97
  66. package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +0 -42
  67. package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +0 -178
  68. package/src/ts/core/Nanosplash/services/NanosplashService.ts +0 -222
  69. package/src/ts/types/Alias.d.ts +0 -1
  70. package/src/ts/types/Nanosplash.d.ts +0 -18
  71. package/src/ts/types/NanosplashService.d.ts +0 -1
  72. package/src/ts/util/Guid.ts +0 -13
  73. package/src/ts/util/Stack.ts +0 -73
  74. package/tests/Nanosplash.spec.ts +0 -64
  75. package/tests/NanosplashRepository.spec.ts +0 -91
  76. package/tests/NanosplashService.spec.ts +0 -119
  77. package/tests/Stack.spec.ts +0 -56
@@ -0,0 +1,48 @@
1
+ import { JSDOM } from 'jsdom'
2
+ import { Service } from '../src/ts/core/Service'
3
+
4
+ export function resetDOM() {
5
+ const dom = new JSDOM()
6
+ // @ts-ignore
7
+ globalThis.window = dom.window
8
+ globalThis.document = dom.window.document
9
+ globalThis.DOMParser = dom.window.DOMParser
10
+ globalThis.Node = dom.window.Node
11
+ globalThis.Element = dom.window.Element
12
+ globalThis.HTMLElement = dom.window.HTMLElement
13
+ globalThis.HTMLDivElement = dom.window.HTMLDivElement
14
+ Service.getInstance().hideAll()
15
+ }
16
+
17
+ export function div(id: string): HTMLDivElement {
18
+ const div = document.createElement('div')
19
+ div.id = id
20
+ return div
21
+ }
22
+
23
+ export const ExpectedParsedValues = {
24
+ numValues: {
25
+ raw: 123,
26
+ parsed: '123',
27
+ },
28
+ arrValues: {
29
+ raw: [1, 2, 3],
30
+ parsed: '1,2,3',
31
+ },
32
+ objValues: {
33
+ raw: {},
34
+ parsed: '[object Object]',
35
+ },
36
+ boolValues: {
37
+ raw: true,
38
+ parsed: 'true',
39
+ },
40
+ nullValues: {
41
+ raw: null,
42
+ parsed: '',
43
+ },
44
+ undefValues: {
45
+ raw: undefined,
46
+ parsed: '',
47
+ },
48
+ }
package/tsconfig.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ESNext", "DOM"],
7
- "moduleResolution": "Node",
8
- "strict": true,
9
- "resolveJsonModule": true,
10
- "isolatedModules": true,
11
- "esModuleInterop": true,
12
- "noEmit": true,
13
- "noUnusedLocals": true,
14
- "noUnusedParameters": true,
15
- "noImplicitReturns": true,
16
- "skipLibCheck": true
17
- },
18
- "include": [
19
- "src",
20
- "tests"
21
- ]
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ESNext", "DOM"],
7
+ "moduleResolution": "Node",
8
+ "strict": true,
9
+ "alwaysStrict": true,
10
+ "resolveJsonModule": true,
11
+ "isolatedModules": true,
12
+ "esModuleInterop": true,
13
+ "noEmit": true,
14
+ "noUnusedLocals": true,
15
+ "noUnusedParameters": true,
16
+ "noImplicitReturns": true,
17
+ "skipLibCheck": true,
18
+ "declaration": true,
19
+ "declarationDir": "dist/types",
20
+ "types": ["vite/client"]
21
+ },
22
+ "include": ["src/ts/**/*.ts"]
22
23
  }
package/vite.config.ts CHANGED
@@ -1,24 +1,16 @@
1
- import { defineConfig } from 'vite'
1
+ import { LibraryFormats, defineConfig } from 'vite'
2
2
 
3
- export default defineConfig(({ command, mode, ssrBuild }) => {
4
- if (command === 'serve') {
5
- return {
6
- // dev specific config
7
- }
8
- } else {
9
- // command === 'build'
10
- return {
11
- build: {
12
- lib: {
13
- entry: './src/main.ts',
14
- name: 'Nanosplash',
15
- formats: ['iife', 'es', 'cjs'],
16
- fileName: module => {
17
- return `ns.${module}.js`
18
- },
19
- },
20
- cssCodeSplit: true,
21
- },
22
- }
23
- }
3
+ const format = (process.env?.format ?? '') as LibraryFormats
4
+ const entry = (process.env?.entry ?? '') as string
5
+
6
+ export default defineConfig({
7
+ build: {
8
+ outDir: `dist/${format}`,
9
+ lib: {
10
+ entry,
11
+ name: 'Nanosplash',
12
+ formats: [format] as LibraryFormats[],
13
+ fileName: 'ns',
14
+ },
15
+ },
24
16
  })
package/dist/main.css DELETED
@@ -1 +0,0 @@
1
- .ns,.ns-host:before{width:100%;height:100%}.ns,.ns-host:before{top:0;left:0}.ns-content,.ns{display:flex;justify-content:center;align-items:center}.ns-host{--text-color: DarkSlateGray;--font-size: 20px;--proportional-size: calc(var(--font-size) * .9);--font-family: "Helvetica", "Arial", sans-serif;--font-weight: 400;--background: rgba(255, 255, 255, .8);--z-index: 999999999;--blur-filter: blur(10px)}.ns-host{position:relative;z-index:var(--z-index)}.ns-host:before{position:absolute;background-color:var(--background);content:"";backdrop-filter:var(--blur-filter);-webkit-backdrop-filter:var(--blur-filter);z-index:calc(var(--z-index) + 1)}body.ns-host{height:100vh}.ns{position:absolute;z-index:calc(var(--z-index) + 2)}.ns-text{color:var(--text-color);font-size:var(--font-size);font-family:var(--font-family);font-weight:var(--font-weight);margin-right:var(--proportional-size)}.ns-spinner{display:block;width:var(--proportional-size);height:var(--proportional-size)}.ns-spinner>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.ns-spinner .path{stroke:var(--text-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}}
package/dist/ns.cjs.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var g=Object.defineProperty;var S=(e,t,n)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var i=(e,t,n)=>(S(e,typeof t!="symbol"?t+"":t,n),n);function N(){return new DOMParser().parseFromString('<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><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 w(e,t){t.children.length>0?t.insertBefore(e,t.children.item(0)):t.append(e)}function o(e,t){e==null||e.classList[t](l.nsHostClassName)}function E(e){o(e.getNSElement().parentElement,"remove")}function v(e){e.style.display="flex"}function y(e){e.style.display="none"}function a(e){let t;if(typeof e=="string")t=document.querySelector(e);else{if(e instanceof Node)return e;if(typeof e=="function"){if(t=e(),!(t instanceof Node))return null}else t=null}return t}function p(e){var t;return(t=e==null?void 0:e.classList)==null?void 0:t.contains("ns")}function u(e,t){o(e.parentElement,"remove"),o(t,"add"),w(e,t)}function m(e){const t=a(e);if(!t)return null;const n=t.firstChild;if(n!==null&&p(n)){const x=n.id;return d.getInstance().nsStack.items.find(f=>f.getId()===x)??null}return null}function I(){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)})}const h=class{constructor(){i(this,"id");i(this,"element");this.element=N(),this.element.id=this.id=I()}getId(){return this.id}getNSElement(){return this.element}getNSContentElement(){return this.getNSElement().firstElementChild}getNSTextElement(){return this.getNSContentElement().firstElementChild}hideText(){return y(this.getNSTextElement()),this}setText(t){return this.getNSTextElement().innerText=t,t.length>0?this.showText():this.hideText(),this}showText(){return v(this.getNSTextElement()),this}remove(){var t;this.element&&((t=this.element.parentElement)==null||t.removeChild(this.element),delete this.element)}};let l=h;i(l,"nsClassName","ns"),i(l,"nsHostClassName",h.nsClassName+"-host");class C{constructor(){i(this,"_items");this._items=[]}get items(){return this._items}push(t){this._items.push(t)}pop(){return this._items.pop()}peek(){return this._items[this._items.length-1]}isEmpty(){return this._items.length===0}size(){return this._items.length}clear(){this._items=[]}}const s=class{constructor(){i(this,"nsStack");this.nsStack=new C}findIndex(t){return this.nsStack.items.findIndex(t)}find(t){return this.nsStack.items.find(t)}static getInstance(){return s.instance||(s.instance=new s),s.instance}static assignToWindow(){Object.defineProperty(window,s.WindowAccessorKey,{value:s.getInstance(),writable:!1})}static start(){s.assignToWindow(),window.addEventListener("load",()=>{window[s.WindowAccessorKey]instanceof s||s.assignToWindow()})}createNS(t){const n=new l;return n.setText(t||""),this.nsStack.push(n),n}cleanAndRemove(t){return E(t),t.remove(),t.getId()}stackDelete(t){let n=this.findIndex(r=>r.getId()===t.getId());return n<0?null:(this.nsStack.items.splice(n,1),t.getId())}deleteNS(t){const n=this.find(t);return n?(this.cleanAndRemove(n),this.stackDelete(n)):null}show(t){let n=m(document.body);return n||(n=this.createNS(),u(n.getNSElement(),document.body)),n.setText(t||""),n.getId()}showInside(t,n){const r=a(t);if(r){let c=m(r);return c||(c=this.createNS()),c.setText(n||""),u(c.getNSElement(),r),c.getId()}return null}hideAll(){this.nsStack.items.forEach(t=>{this.cleanAndRemove(t)}),this.nsStack.clear()}hide(){const t=this.nsStack.pop();return t?this.cleanAndRemove(t):null}hideId(t){return this.deleteNS(n=>n.getId()===t)}hideInside(t){const n=a(t),r=c=>c.getNSElement().parentElement===n;return n?this.deleteNS(r):null}};let d=s;i(d,"WindowAccessorKey","ns"),i(d,"instance");try{d.start()}catch(e){console.warn(e)}
package/dist/ns.es.js DELETED
@@ -1,330 +0,0 @@
1
- var g = Object.defineProperty;
2
- var S = (e, t, n) => t in e ? g(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var i = (e, t, n) => (S(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- function N() {
5
- return new DOMParser().parseFromString(
6
- '<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>',
7
- "text/html"
8
- ).body.firstChild;
9
- }
10
- function w(e, t) {
11
- t.children.length > 0 ? t.insertBefore(e, t.children.item(0)) : t.append(e);
12
- }
13
- function o(e, t) {
14
- e == null || e.classList[t](l.nsHostClassName);
15
- }
16
- function E(e) {
17
- o(e.getNSElement().parentElement, "remove");
18
- }
19
- function v(e) {
20
- e.style.display = "flex";
21
- }
22
- function y(e) {
23
- e.style.display = "none";
24
- }
25
- function a(e) {
26
- let t;
27
- if (typeof e == "string")
28
- t = document.querySelector(e);
29
- else {
30
- if (e instanceof Node)
31
- return e;
32
- if (typeof e == "function") {
33
- if (t = e(), !(t instanceof Node))
34
- return null;
35
- } else
36
- t = null;
37
- }
38
- return t;
39
- }
40
- function p(e) {
41
- var t;
42
- return (t = e == null ? void 0 : e.classList) == null ? void 0 : t.contains("ns");
43
- }
44
- function u(e, t) {
45
- o(e.parentElement, "remove"), o(t, "add"), w(e, t);
46
- }
47
- function m(e) {
48
- const t = a(e);
49
- if (!t)
50
- return null;
51
- const n = t.firstChild;
52
- if (n !== null && p(n)) {
53
- const x = n.id;
54
- return d.getInstance().nsStack.items.find((f) => f.getId() === x) ?? null;
55
- }
56
- return null;
57
- }
58
- function I() {
59
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
60
- const t = Math.random() * 16 | 0;
61
- return (e === "x" ? t : t & 3 | 8).toString(16);
62
- });
63
- }
64
- const h = class {
65
- constructor() {
66
- i(this, "id");
67
- i(this, "element");
68
- this.element = N(), this.element.id = this.id = I();
69
- }
70
- /**
71
- * @inheritDoc
72
- */
73
- getId() {
74
- return this.id;
75
- }
76
- /**
77
- * @inheritDoc
78
- */
79
- getNSElement() {
80
- return this.element;
81
- }
82
- /**
83
- * # Get NS Content Element
84
- * Returns the content element of the Nanosplash.
85
- */
86
- getNSContentElement() {
87
- return this.getNSElement().firstElementChild;
88
- }
89
- /**
90
- * # Get NS Text Element
91
- * Returns the text element of the Nanosplash.
92
- */
93
- getNSTextElement() {
94
- return this.getNSContentElement().firstElementChild;
95
- }
96
- /**
97
- * @inheritDoc
98
- */
99
- hideText() {
100
- return y(this.getNSTextElement()), this;
101
- }
102
- /**
103
- * @inheritDoc
104
- */
105
- setText(t) {
106
- return this.getNSTextElement().innerText = t, t.length > 0 ? this.showText() : this.hideText(), this;
107
- }
108
- /**
109
- * @inheritDoc
110
- */
111
- showText() {
112
- return v(this.getNSTextElement()), this;
113
- }
114
- /**
115
- * @inheritDoc
116
- */
117
- remove() {
118
- var t;
119
- this.element && ((t = this.element.parentElement) == null || t.removeChild(this.element), delete this.element);
120
- }
121
- };
122
- let l = h;
123
- i(l, "nsClassName", "ns"), i(l, "nsHostClassName", h.nsClassName + "-host");
124
- class C {
125
- /**
126
- * Constructs a new stack.
127
- */
128
- constructor() {
129
- i(this, "_items");
130
- this._items = [];
131
- }
132
- /**
133
- * Returns the items in the stack.
134
- */
135
- get items() {
136
- return this._items;
137
- }
138
- /**
139
- * Adds an item to the top of the stack.
140
- * @param item The item to add to the stack.
141
- */
142
- push(t) {
143
- this._items.push(t);
144
- }
145
- /**
146
- * Removes and returns the item at the top of the stack.
147
- * @returns The item at the top of the stack, or undefined if the stack is empty.
148
- */
149
- pop() {
150
- return this._items.pop();
151
- }
152
- /**
153
- * Returns the item at the top of the stack without removing it.
154
- * @returns The item at the top of the stack, or undefined if the stack is empty.
155
- */
156
- peek() {
157
- return this._items[this._items.length - 1];
158
- }
159
- /**
160
- * Returns true if the stack is empty, false otherwise.
161
- * @returns True if the stack is empty, false otherwise.
162
- */
163
- isEmpty() {
164
- return this._items.length === 0;
165
- }
166
- /**
167
- * Returns the number of items in the stack.
168
- * @returns The number of items in the stack.
169
- */
170
- size() {
171
- return this._items.length;
172
- }
173
- /**
174
- * Removes all items from the stack.
175
- */
176
- clear() {
177
- this._items = [];
178
- }
179
- }
180
- const s = class {
181
- /**
182
- * # Constructor
183
- * Private constructor to prevent multiple instances.
184
- * @private
185
- */
186
- constructor() {
187
- i(this, "nsStack");
188
- this.nsStack = new C();
189
- }
190
- /**
191
- * # Find Index
192
- * Find Nanosplash stack index by callback.
193
- * @param callback Callback function that returns a boolean.
194
- * @returns {number} Index of Nanosplash instance in the stack or -1.
195
- */
196
- findIndex(t) {
197
- return this.nsStack.items.findIndex(t);
198
- }
199
- /**
200
- * # Find
201
- * Find Nanosplash in the stack by callback.
202
- * @param callback Callback function that returns a boolean.
203
- * @returns {Nanosplash | undefined} Nanosplash instance or undefined
204
- */
205
- find(t) {
206
- return this.nsStack.items.find(t);
207
- }
208
- /**
209
- * # Get Instance
210
- * Singleton instance accessor
211
- * @returns {NanosplashService} NanosplashService instance
212
- */
213
- static getInstance() {
214
- return s.instance || (s.instance = new s()), s.instance;
215
- }
216
- /**
217
- * # Assign To Window
218
- * Assign Nanosplash service instance to Window object.
219
- * The NanosplashService instance can be accessed in the window object
220
- * using the key window accessor key.
221
- * @see WindowAccessorKey
222
- */
223
- static assignToWindow() {
224
- Object.defineProperty(window, s.WindowAccessorKey, {
225
- value: s.getInstance(),
226
- writable: !1
227
- });
228
- }
229
- /**
230
- * # Start
231
- * Initialize Nanosplash Service instance in Window when it's loaded.
232
- */
233
- static start() {
234
- s.assignToWindow(), window.addEventListener("load", () => {
235
- window[s.WindowAccessorKey] instanceof s || s.assignToWindow();
236
- });
237
- }
238
- /**
239
- * # Create Nanosplash
240
- * Return new Nanosplash instance and push it to the stack.
241
- * @param text Text to display.
242
- * @returns {Nanosplash} Nanosplash instance.
243
- */
244
- createNS(t) {
245
- const n = new l();
246
- return n.setText(t || ""), this.nsStack.push(n), n;
247
- }
248
- /**
249
- * # Clean And Remove
250
- * Remove Nanosplash from DOM and clean its parent.
251
- * @param ns Nanosplash instance.
252
- * @returns {GUIDString} Nanosplash ID.
253
- */
254
- cleanAndRemove(t) {
255
- return E(t), t.remove(), t.getId();
256
- }
257
- /**
258
- * # Stack Delete At
259
- * Remove Nanosplash instance from the stack.
260
- * @param ns Nanosplash instance.
261
- * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
262
- */
263
- stackDelete(t) {
264
- let n = this.findIndex((r) => r.getId() === t.getId());
265
- return n < 0 ? null : (this.nsStack.items.splice(n, 1), t.getId());
266
- }
267
- /**
268
- * # Delete NS
269
- * Remove Nanosplash instance from both the stack and the DOM.
270
- * @param callback Callback function.
271
- * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
272
- */
273
- deleteNS(t) {
274
- const n = this.find(t);
275
- return n ? (this.cleanAndRemove(n), this.stackDelete(n)) : null;
276
- }
277
- /**
278
- * @inheritDoc
279
- */
280
- show(t) {
281
- let n = m(document.body);
282
- return n || (n = this.createNS(), u(n.getNSElement(), document.body)), n.setText(t || ""), n.getId();
283
- }
284
- /**
285
- * @inheritDoc
286
- */
287
- showInside(t, n) {
288
- const r = a(t);
289
- if (r) {
290
- let c = m(r);
291
- return c || (c = this.createNS()), c.setText(n || ""), u(c.getNSElement(), r), c.getId();
292
- }
293
- return null;
294
- }
295
- /**
296
- * @inheritDoc
297
- */
298
- hideAll() {
299
- this.nsStack.items.forEach((t) => {
300
- this.cleanAndRemove(t);
301
- }), this.nsStack.clear();
302
- }
303
- /**
304
- * @inheritDoc
305
- */
306
- hide() {
307
- const t = this.nsStack.pop();
308
- return t ? this.cleanAndRemove(t) : null;
309
- }
310
- /**
311
- * @inheritDoc
312
- */
313
- hideId(t) {
314
- return this.deleteNS((n) => n.getId() === t);
315
- }
316
- /**
317
- * @inheritDoc
318
- */
319
- hideInside(t) {
320
- const n = a(t), r = (c) => c.getNSElement().parentElement === n;
321
- return n ? this.deleteNS(r) : null;
322
- }
323
- };
324
- let d = s;
325
- i(d, "WindowAccessorKey", "ns"), i(d, "instance");
326
- try {
327
- d.start();
328
- } catch (e) {
329
- console.warn(e);
330
- }
package/dist/ns.iife.js DELETED
@@ -1,2 +0,0 @@
1
- var C=Object.defineProperty;var I=(r,o,c)=>o in r?C(r,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):r[o]=c;var i=(r,o,c)=>(I(r,typeof o!="symbol"?o+"":o,c),c);(function(){var r=document.createElement("style");r.textContent=`.ns,.ns-host:before{width:100%;height:100%}.ns,.ns-host:before{top:0;left:0}.ns-content,.ns{display:flex;justify-content:center;align-items:center}.ns-host{--text-color: DarkSlateGray;--font-size: 20px;--proportional-size: calc(var(--font-size) * .9);--font-family: "Helvetica", "Arial", sans-serif;--font-weight: 400;--background: rgba(255, 255, 255, .8);--z-index: 999999999;--blur-filter: blur(10px)}.ns-host{position:relative;z-index:var(--z-index)}.ns-host:before{position:absolute;background-color:var(--background);content:"";backdrop-filter:var(--blur-filter);-webkit-backdrop-filter:var(--blur-filter);z-index:calc(var(--z-index) + 1)}body.ns-host{height:100vh}.ns{position:absolute;z-index:calc(var(--z-index) + 2)}.ns-text{color:var(--text-color);font-size:var(--font-size);font-family:var(--font-family);font-weight:var(--font-weight);margin-right:var(--proportional-size)}.ns-spinner{display:block;width:var(--proportional-size);height:var(--proportional-size)}.ns-spinner>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.ns-spinner .path{stroke:var(--text-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
- `,document.head.appendChild(r);const o="";function c(){return new DOMParser().parseFromString('<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><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 p(e,t){t.children.length>0?t.insertBefore(e,t.children.item(0)):t.append(e)}function u(e,t){e==null||e.classList[t](d.nsHostClassName)}function v(e){u(e.getNSElement().parentElement,"remove")}function y(e){e.style.display="flex"}function S(e){e.style.display="none"}function f(e){let t;if(typeof e=="string")t=document.querySelector(e);else{if(e instanceof Node)return e;if(typeof e=="function"){if(t=e(),!(t instanceof Node))return null}else t=null}return t}function k(e){var t;return(t=e==null?void 0:e.classList)==null?void 0:t.contains("ns")}function x(e,t){u(e.parentElement,"remove"),u(t,"add"),p(e,t)}function g(e){const t=f(e);if(!t)return null;const n=t.firstChild;if(n!==null&&k(n)){const b=n.id;return h.getInstance().nsStack.items.find(E=>E.getId()===b)??null}return null}function w(){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)})}const m=class{constructor(){i(this,"id");i(this,"element");this.element=c(),this.element.id=this.id=w()}getId(){return this.id}getNSElement(){return this.element}getNSContentElement(){return this.getNSElement().firstElementChild}getNSTextElement(){return this.getNSContentElement().firstElementChild}hideText(){return S(this.getNSTextElement()),this}setText(t){return this.getNSTextElement().innerText=t,t.length>0?this.showText():this.hideText(),this}showText(){return y(this.getNSTextElement()),this}remove(){var t;this.element&&((t=this.element.parentElement)==null||t.removeChild(this.element),delete this.element)}};let d=m;i(d,"nsClassName","ns"),i(d,"nsHostClassName",m.nsClassName+"-host");class N{constructor(){i(this,"_items");this._items=[]}get items(){return this._items}push(t){this._items.push(t)}pop(){return this._items.pop()}peek(){return this._items[this._items.length-1]}isEmpty(){return this._items.length===0}size(){return this._items.length}clear(){this._items=[]}}const s=class{constructor(){i(this,"nsStack");this.nsStack=new N}findIndex(t){return this.nsStack.items.findIndex(t)}find(t){return this.nsStack.items.find(t)}static getInstance(){return s.instance||(s.instance=new s),s.instance}static assignToWindow(){Object.defineProperty(window,s.WindowAccessorKey,{value:s.getInstance(),writable:!1})}static start(){s.assignToWindow(),window.addEventListener("load",()=>{window[s.WindowAccessorKey]instanceof s||s.assignToWindow()})}createNS(t){const n=new d;return n.setText(t||""),this.nsStack.push(n),n}cleanAndRemove(t){return v(t),t.remove(),t.getId()}stackDelete(t){let n=this.findIndex(a=>a.getId()===t.getId());return n<0?null:(this.nsStack.items.splice(n,1),t.getId())}deleteNS(t){const n=this.find(t);return n?(this.cleanAndRemove(n),this.stackDelete(n)):null}show(t){let n=g(document.body);return n||(n=this.createNS(),x(n.getNSElement(),document.body)),n.setText(t||""),n.getId()}showInside(t,n){const a=f(t);if(a){let l=g(a);return l||(l=this.createNS()),l.setText(n||""),x(l.getNSElement(),a),l.getId()}return null}hideAll(){this.nsStack.items.forEach(t=>{this.cleanAndRemove(t)}),this.nsStack.clear()}hide(){const t=this.nsStack.pop();return t?this.cleanAndRemove(t):null}hideId(t){return this.deleteNS(n=>n.getId()===t)}hideInside(t){const n=f(t),a=l=>l.getNSElement().parentElement===n;return n?this.deleteNS(a):null}};let h=s;i(h,"WindowAccessorKey","ns"),i(h,"instance");try{h.start()}catch(e){console.warn(e)}})();
package/index.html DELETED
@@ -1,52 +0,0 @@
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 3</title>
7
- <script src="https://cdn.tailwindcss.com"></script>
8
- </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>
20
- <div
21
- id="wrapper"
22
- class="relative mt-20 flex gap-x-5 justify-center items-center bg-slate-200 p-20 border border-4 border-black/10 rounded shadow-xl">
23
- <div class="absolute top-2 left-2 font-mono text-slate-500 px-1 bg-white rounded">Element ID: #wrapper</div>
24
- <div
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>
29
- </div>
30
- <div
31
- id="b"
32
- class="relative bg-slate-400 p-20 border border-4 border-black/10 rounded shadow-2xl">
33
- <div class="absolute top-2 left-2 font-mono text-slate-500 px-1 bg-white rounded">Element ID: #b</div>
34
- <div class="text-white text-2xl font-medium">This is element B</div>
35
- </div>
36
- <div
37
- id="c"
38
- class="relative bg-slate-400 p-20 border border-4 border-black/10 rounded shadow-2xl">
39
- <div class="absolute top-2 left-2 font-mono text-slate-500 px-1 bg-white rounded">Element ID: #c</div>
40
- <div class="text-white text-2xl font-medium">This is element C</div>
41
- </div>
42
- </div>
43
- </div>
44
- <script type="module" src="/src/main.ts"></script>
45
- <script>
46
- const ref = id => document.getElementById(id)
47
- const code = ref('code')
48
- const run = ref('run')
49
- run.onclick = () => eval(code.value)
50
- </script>
51
- </body>
52
- </html>
package/src/main.ts DELETED
@@ -1,8 +0,0 @@
1
- // @ts-strict
2
-
3
- import NanosplashService from './ts/core/Nanosplash/services/NanosplashService'
4
- try {
5
- NanosplashService.start()
6
- } catch (e) {
7
- console.warn(e)
8
- }
package/src/sass/ns.sass DELETED
@@ -1,86 +0,0 @@
1
- %maximize
2
- width: 100%
3
- height: 100%
4
-
5
- %upper-left
6
- top: 0
7
- left: 0
8
-
9
- %flex-center-xy
10
- display: flex
11
- justify-content: center
12
- align-items: center
13
-
14
- .ns-host
15
- --text-color: DarkSlateGray
16
- --font-size: 20px
17
- --proportional-size: calc(var(--font-size) * 0.9)
18
- --font-family: 'Helvetica', 'Arial', sans-serif
19
- --font-weight: 400
20
- --background: rgba(255, 255, 255, 0.8)
21
- --z-index: 999999999
22
- --blur-filter: blur(10px)
23
-
24
- .ns-host
25
- position: relative
26
- z-index: var(--z-index)
27
- &::before
28
- @extend %maximize
29
- @extend %upper-left
30
- position: absolute
31
- background-color: var(--background)
32
- content: ''
33
- backdrop-filter: var(--blur-filter)
34
- -webkit-backdrop-filter: var(--blur-filter)
35
- z-index: calc(var(--z-index) + 1)
36
-
37
- body.ns-host
38
- height: 100vh
39
-
40
- .ns
41
- @extend %maximize
42
- @extend %upper-left
43
- @extend %flex-center-xy
44
- position: absolute
45
- z-index: calc(var(--z-index) + 2)
46
-
47
- .ns-content
48
- @extend %flex-center-xy
49
-
50
- .ns-text
51
- color: var(--text-color)
52
- font-size: var(--font-size)
53
- font-family: var(--font-family)
54
- font-weight: var(--font-weight)
55
- margin-right: var(--proportional-size)
56
-
57
- // Spinner node
58
- .ns-spinner
59
- display: block
60
- width: var(--proportional-size)
61
- height: var(--proportional-size)
62
- & > svg
63
- animation: Rotate 2s linear infinite
64
- position: relative
65
- width: inherit
66
- height: inherit
67
- stroke-width: 8
68
- & .path
69
- stroke: var(--text-color)
70
- stroke-linecap: round
71
- animation: Dash 1.5s ease-in-out infinite
72
-
73
- // Spinner animations:
74
- @keyframes Rotate
75
- 100%
76
- transform: rotate(360deg)
77
- @keyframes Dash
78
- 0%
79
- stroke-dasharray: 1, 150
80
- stroke-dashoffset: 0
81
- 50%
82
- stroke-dasharray: 90, 150
83
- stroke-dashoffset: -35
84
- 100%
85
- stroke-dasharray: 90, 150
86
- stroke-dashoffset: -124