nanosplash 4.0.2 → 4.0.4

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 (67) hide show
  1. package/.github/workflows/ci.prod.yml +68 -0
  2. package/.prettierrc +9 -10
  3. package/README.md +118 -51
  4. package/bun.lock +635 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +176 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  12. package/coverage/lcov-report/sorter.js +196 -0
  13. package/coverage/lcov-report/src/composables/index.html +116 -0
  14. package/coverage/lcov-report/src/composables/ns.ts.html +547 -0
  15. package/coverage/lcov-report/src/constants/index.html +116 -0
  16. package/coverage/lcov-report/src/constants/ns.ts.html +124 -0
  17. package/coverage/lcov-report/src/iife.ts.html +100 -0
  18. package/coverage/lcov-report/src/index.html +116 -0
  19. package/coverage/lcov-report/src/interfaces/INSElement.ts.html +100 -0
  20. package/coverage/lcov-report/src/interfaces/INanosplash.ts.html +304 -0
  21. package/coverage/lcov-report/src/interfaces/index.html +131 -0
  22. package/coverage/lcov-report/src/utils/dom-utils.ts.html +289 -0
  23. package/coverage/lcov-report/src/utils/index.html +116 -0
  24. package/coverage/lcov.info +271 -0
  25. package/eslint.config.js +7 -2
  26. package/package.json +74 -88
  27. package/src/composables/ns.ts +154 -0
  28. package/src/constants/ns.ts +13 -0
  29. package/src/iife.ts +5 -0
  30. package/src/interfaces/INSElement.ts +5 -0
  31. package/src/interfaces/INanosplash.ts +73 -0
  32. package/src/style/ns.css +134 -0
  33. package/src/types/dom.d.ts +3 -0
  34. package/src/types/generic/function.d.ts +1 -0
  35. package/src/types/global.d.ts +26 -0
  36. package/src/types/semantic/number.d.ts +1 -0
  37. package/src/types/semantic/string.d.ts +2 -0
  38. package/src/utils/dom-utils.ts +68 -0
  39. package/tests/ns.spec.ts +124 -0
  40. package/tsconfig.json +29 -21
  41. package/vite.config.ts +18 -10
  42. package/vitest.config.ts +20 -0
  43. package/.github/workflows/ci.yml +0 -62
  44. package/.github/workflows/vitepress.yml +0 -68
  45. package/LICENSE +0 -21
  46. package/docs/.vitepress/config.ts +0 -78
  47. package/docs/.vitepress/theme/css/style.css +0 -258
  48. package/docs/.vitepress/theme/index.ts +0 -16
  49. package/docs/.vitepress/theme/vue/Card.vue +0 -31
  50. package/docs/.vitepress/theme/vue/CardGrid.vue +0 -17
  51. package/docs/.vitepress/theme/vue/PlayGround.vue +0 -36
  52. package/docs/api/doc/hide.md +0 -48
  53. package/docs/api/doc/show.md +0 -46
  54. package/docs/api/start/customize.md +0 -30
  55. package/docs/api/start/features.md +0 -17
  56. package/docs/api/start/install.md +0 -61
  57. package/docs/api/start/playground.md +0 -16
  58. package/docs/api/start/usage.md +0 -22
  59. package/docs/index.md +0 -33
  60. package/docs/public/macos.jpg +0 -0
  61. package/src/style/ns.sass +0 -120
  62. package/src/ts/Nanosplash.ts +0 -177
  63. package/src/ts/main.ts +0 -5
  64. package/src/ts/types/NanosplashInterface.ts +0 -26
  65. package/src/ts/types/Types.ts +0 -16
  66. package/src/ts/types/global.d.ts +0 -14
  67. package/tests/Nanosplash.spec.ts +0 -25
package/src/style/ns.sass DELETED
@@ -1,120 +0,0 @@
1
- // Spinner animations:
2
- @keyframes nsRotate
3
- 100%
4
- transform: rotate(360deg)
5
-
6
- @keyframes nsDash
7
- 0%
8
- stroke-dasharray: 1, 150
9
- stroke-dashoffset: 0
10
- 50%
11
- stroke-dasharray: 90, 150
12
- stroke-dashoffset: -35
13
- 100%
14
- stroke-dasharray: 90, 150
15
- stroke-dashoffset: -124
16
-
17
- @keyframes nsFade
18
- from
19
- opacity: 0
20
- to
21
- opacity: 1
22
-
23
- @keyframes nsAscend
24
- from
25
- opacity: 0
26
- transform: translateY(13px)
27
- to
28
- opacity: 1
29
- transform: translateY(0)
30
-
31
- :root
32
- --ns-top: 0px
33
-
34
- %maximize
35
- width: 100%
36
- height: 100%
37
-
38
- %bottom-left
39
- bottom: 0
40
- right: 0
41
-
42
- %flex-center-xy
43
- display: flex
44
- justify-content: center
45
- align-items: center
46
-
47
- // Nanosplash host scoped varibles
48
- .nsh
49
- --color: DarkSlateGray
50
- --size: 20px
51
- --relSize: calc(var(--size) * 0.9)
52
- --font: 'Helvetica', 'Arial', sans-serif
53
- --weight: 400
54
- --bg: #{ rgba(White, 0.9) }
55
- --zIdx: 999999999
56
- --blur: blur(5px)
57
-
58
- // Nanosplash host
59
- .nsh
60
- position: relative
61
- z-index: var(--zIdx)
62
- &::before // The backdrop
63
- @extend %maximize
64
- @extend %bottom-left
65
- position: absolute
66
- background-color: var(--bg)
67
- content: ''
68
- backdrop-filter: var(--blur)
69
- -webkit-backdrop-filter: var(--blur)
70
- z-index: calc(var(--zIdx) + 1)
71
- border-radius: inherit
72
-
73
- // When Nanosplash host is the document body
74
- body.nsh
75
- &, &::before
76
- @extend %maximize
77
- position: fixed
78
- top: var(--ns-top)
79
- left: 0
80
-
81
- // Nanosplash (main element)
82
- .ns
83
- @extend %maximize
84
- @extend %bottom-left
85
- @extend %flex-center-xy
86
- position: absolute
87
- z-index: calc(var(--zIdx) + 2)
88
- animation: nsFade 2s
89
- gap: var(--relSize)
90
-
91
- // Nanosplash text
92
- .nst
93
- color: var(--color)
94
- font-size: var(--size)
95
- font-family: var(--font)
96
- font-weight: var(--weight)
97
- max-width: 80dvw
98
- white-space: nowrap
99
- text-overflow: ellipsis
100
- overflow: hidden
101
- text-shadow: 0 0 0.06rem #{ rgba(DarkSlateGray, .25) }
102
- filter: drop-shadow(0 0 0.07rem #{ rgba(Black, 0.25) })
103
- animation: nsAscend 0.5s
104
-
105
- // Nanosplash spinner
106
- .nss
107
- display: block
108
- width: var(--relSize)
109
- height: var(--relSize)
110
- animation: nsAscend 0.5s
111
- & > svg
112
- animation: nsRotate 2s linear infinite
113
- position: relative
114
- width: inherit
115
- height: inherit
116
- stroke-width: 8
117
- & .path
118
- stroke: var(--color)
119
- stroke-linecap: round
120
- animation: nsDash 1.5s ease-in-out infinite
@@ -1,177 +0,0 @@
1
- // @ts-strict
2
- import style from '../style/ns.sass?inline'
3
- import { NanosplashInterface } from './types/NanosplashInterface'
4
- import { ElementReference, NSElement } from './types/Types'
5
- import type { DOMWindow } from 'jsdom'
6
- import { version } from '../../package.json'
7
-
8
- /**
9
- * # Use Nanosplash
10
- * @returns Nanosplash API.
11
- */
12
- export const useNs = (
13
- win?: (Window | (Window & typeof globalThis)) | DOMWindow
14
- ): NanosplashInterface => {
15
- const doc = (win ?? window).document
16
- const bod = doc.body
17
-
18
- const all = (node: ParentNode, ref: string) =>
19
- Array.from(node.querySelectorAll(ref))
20
- const first = (node: ParentNode, ref: string) => all(node, ref)[0] ?? null
21
-
22
- /**
23
- * # Get All Nanosplashes
24
- * @returns An array of all Nanosplash elements in the DOM.
25
- */
26
- const getAllNs = (): NSElement[] => all(doc, '.ns') as NSElement[]
27
-
28
- /**
29
- * # Parse Ref
30
- * @param ref Element reference which could be a selector or an Element.
31
- * @returns The Element node or null.
32
- */
33
- const parseRef = (ref: ElementReference): Element | null =>
34
- ref instanceof Element ? ref : first(doc, ref)
35
-
36
- /**
37
- * # Create HTMLDivElement
38
- * @param className Optional string containing class names.
39
- * @param children Optional list of Nodes or strings.
40
- * @returns The newly created HTMLDivElement.
41
- */
42
- const div = (
43
- className?: string,
44
- ...children: (Node | string)[]
45
- ): HTMLDivElement => {
46
- const node: HTMLDivElement = doc.createElement('div')
47
- if (className) node.classList.add(className)
48
- node.append(...children)
49
- return node
50
- }
51
-
52
- /**
53
- * # Parse
54
- * @param html HTML string.
55
- * @returns Parsed node.
56
- */
57
- const parse = (html: string): Node => {
58
- const node: HTMLDivElement = div()
59
- node.innerHTML = html
60
- return node.firstChild as Node
61
- }
62
-
63
- /**
64
- * # Make Nanosplash Element
65
- * @returns Nanpslash DOM element.
66
- */
67
- const makeNs = (): NSElement => {
68
- const circle: string = '<circle class=path cx=25 cy=25 r=20 fill=none />'
69
- const svg = parse(`<svg viewBox="0 0 50 50">${circle}</svg>`) as Element
70
- const node = div('ns', div('nst'), div('nss', svg)) as NSElement
71
- node.nsId = Date.now()
72
- return node
73
- }
74
-
75
- /**
76
- * # Peek Nanosplash Queue
77
- * Collect all Nanosplash elements in the DOM, sort them by their NS ID
78
- * in ascending order, and return the first element.
79
- * @returns The front of the queue.
80
- */
81
- const peekNsQueue = (): NSElement | null =>
82
- getAllNs().sort((a: NSElement, b: NSElement) => a.nsId - b.nsId)[0] ?? null
83
-
84
- /**
85
- * # Set Nanosplash Text
86
- * Replace the text node to trigger the animation which in turn is invoked
87
- * by the connected callback in the DOM.
88
- * @param ns Nanosplash element.
89
- * @param text Text to display adjacent to spinner.
90
- */
91
- const setNsText = (ns: NSElement, text: string): void => {
92
- const oldNsText = first(ns, '.nst') as Element | null
93
- if (!text) return oldNsText?.remove()
94
- const newNsText = div('nst', text)
95
- if (oldNsText) {
96
- oldNsText.replaceWith(newNsText)
97
- } else {
98
- ns.insertBefore(newNsText, ns.firstChild)
99
- }
100
- }
101
-
102
- /**
103
- * # Set Nanosplash Parent
104
- * Define where inside the DOM to spawn the Nansoplash.
105
- * @param ns Nanosplash element.
106
- * @param parent NS element's parent to be.
107
- */
108
- const setNsParent = (ns: NSElement, parent: Element): void => {
109
- const child = parent.firstElementChild
110
- if (child) {
111
- parent.insertBefore(ns, child)
112
- }
113
- parent.append(ns)
114
- parent.classList.add('nsh')
115
- }
116
-
117
- /**
118
- * # Show Nanosplash
119
- * @param text Text to display adjacent to spinner.
120
- * @param inside Selector or element in which the NS element will be spawned.
121
- * @returns The ID if the NS element — which is a UTC integer.
122
- */
123
- const show = (text?: string, inside?: string | Element): number | null => {
124
- const parent: Element | null = (
125
- inside ? parseRef(inside) : bod
126
- ) as Element | null
127
- let ns: NSElement
128
- const recycledNs = first(parent ?? bod, '& > .ns')
129
- if (recycledNs) {
130
- ns = recycledNs as NSElement
131
- } else {
132
- ns = makeNs()
133
- setNsParent(ns, parent as Element)
134
- }
135
- setNsText(ns, text ?? '')
136
- const top: string = scrollY + 'px'
137
- bod.style.setProperty('--ns-top', top)
138
- return ns.nsId
139
- }
140
-
141
- /**
142
- * # Remove Nanosplash
143
- * @param ns Nanosplash elememnt.
144
- */
145
- const removeNs = (ns?: Element | null): void => {
146
- ns?.parentElement?.classList.remove('nsh')
147
- ns?.remove()
148
- }
149
-
150
- /**
151
- * # Find Nanosplash
152
- * @param id The UTC integer returned from the `show` function.
153
- * @returns Null or the corresponding Nanosplash element.
154
- */
155
- const findNs = (id: number) => getAllNs().find(v => v.nsId === id) ?? null
156
-
157
- /**
158
- * # Hide Nanosplash
159
- * Hide agnostically in FIFO order, specifically by ID, or all by the asterisk
160
- * which will delete all Nanosplashes.
161
- * @param id Optional ID of a Nanosplash element or '*' .
162
- */
163
- const hide = (id?: number | '*'): void => {
164
- if (id === '*') all(doc, '.ns').forEach(removeNs)
165
- else removeNs(typeof id === 'number' ? findNs(id) : peekNsQueue())
166
- }
167
-
168
- // Add CSS to window
169
- first(doc, '#ns')?.remove()
170
- bod.append(parse(`<style id="ns">${style}</style>`))
171
-
172
- return {
173
- show,
174
- hide,
175
- version,
176
- }
177
- }
package/src/ts/main.ts DELETED
@@ -1,5 +0,0 @@
1
- // @ts-strict
2
- import { useNs } from './Nanosplash'
3
- window.addEventListener('load', function () {
4
- this.ns = useNs(this)
5
- })
@@ -1,26 +0,0 @@
1
- import { DOMSelector, UTCInteger } from './Types'
2
-
3
- export interface NanosplashInterface {
4
- /**
5
- * # Show
6
- * Display Nanosplash inside the window.
7
- * @param {string | undefined} text Optional text
8
- * @param {string | Element | undefined} inside Optional element reference
9
- * @returns {number | null} The internal ID of the created Nanosplash.
10
- */
11
- show(text?: string, inside?: DOMSelector | HTMLElement): UTCInteger | null
12
- /**
13
- * # Hide
14
- * Remove Nanosplash in multiple ways depending on the passed argument.
15
- * - Pass ID: Remove specific.
16
- * - Pass '*': Remove all in window.
17
- * - Pass nothing: Remove in FIFO order.
18
- * @param id The internal ID, an asterisk, or nothing.
19
- */
20
- hide(id?: UTCInteger | '*'): void
21
- /**
22
- * # Version
23
- * The current version of Nanosplash.
24
- */
25
- version: string
26
- }
@@ -1,16 +0,0 @@
1
- import { NanosplashInterface } from './NanosplashInterface'
2
-
3
- export type Integer = number
4
- export type UTCInteger = Integer
5
- export type DOMSelector = string
6
- export type ElementReference = DOMSelector | Element
7
-
8
- export interface NSElement extends HTMLDivElement {
9
- nsId: number
10
- }
11
-
12
- declare global {
13
- interface Window {
14
- ns: NanosplashInterface
15
- }
16
- }
@@ -1,14 +0,0 @@
1
- import { NanosplashInterface } from './NanosplashInterface'
2
-
3
- interface IWindow {
4
- ns: NanosplashInterface
5
- }
6
-
7
- declare global {
8
- interface Window extends IWindow {}
9
- interface window extends IWindow {}
10
- interface globalThis extends globalThis {
11
- Window: IWindow
12
- window: IWindow
13
- }
14
- }
@@ -1,25 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest'
2
- import { JSDOM } from 'jsdom'
3
- import { useNs } from '../src/ts/Nanosplash'
4
-
5
- const dom = new JSDOM()
6
- var window = dom.window
7
- const ns = (window.ns = useNs(window))
8
-
9
- describe('Nanosplash API', () => {
10
- it('should be defined', () => {
11
- expect(window.ns).toBeDefined()
12
- })
13
-
14
- it('should have the "show" method', () => {
15
- expect(window.ns.show).toBeDefined()
16
- })
17
-
18
- it('should have the "hide" method', () => {
19
- expect(window.ns.hide).toBeDefined()
20
- })
21
-
22
- it('should have the global instance', () => {
23
- expect(window.ns).toBe(ns)
24
- })
25
- })