nanosplash 4.0.1 → 4.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.
@@ -6,9 +6,6 @@ export default defineConfig({
6
6
  description: 'The tiny loading screen for web artisans',
7
7
  base: '/nanosplash/',
8
8
  appearance: 'dark',
9
- head: [
10
- ['script', { src: 'https://unpkg.com/nanosplash/dist/iife/ns.iife.js' }],
11
- ],
12
9
  themeConfig: {
13
10
  nav: [
14
11
  { text: 'Home', link: '/' },
@@ -1,6 +1,10 @@
1
1
  <script setup>
2
2
  import CardGrid from './CardGrid.vue'
3
3
  import Card from './Card.vue'
4
+ import { useNs } from '../../../../dist/es/ns'
5
+ if (window) {
6
+ window.ns = useNs(window)
7
+ }
4
8
  </script>
5
9
 
6
10
  <template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanosplash",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "author": {
5
5
  "name": "Isak K. Hauge",
6
6
  "email": "isakhauge@icloud.com",
@@ -12,8 +12,8 @@ import { version } from '../../package.json'
12
12
  export const useNs = (
13
13
  win?: (Window | (Window & typeof globalThis)) | DOMWindow
14
14
  ): NanosplashInterface => {
15
- const doc = () => (win ?? window).document
16
- const bod = () => doc().body
15
+ const doc = (win ?? window).document
16
+ const bod = doc.body
17
17
 
18
18
  const all = (node: ParentNode, ref: string) =>
19
19
  Array.from(node.querySelectorAll(ref))
@@ -23,7 +23,7 @@ export const useNs = (
23
23
  * # Get All Nanosplashes
24
24
  * @returns An array of all Nanosplash elements in the DOM.
25
25
  */
26
- const getAllNs = (): NSElement[] => all(doc(), '.ns') as NSElement[]
26
+ const getAllNs = (): NSElement[] => all(doc, '.ns') as NSElement[]
27
27
 
28
28
  /**
29
29
  * # Parse Ref
@@ -31,7 +31,7 @@ export const useNs = (
31
31
  * @returns The Element node or null.
32
32
  */
33
33
  const parseRef = (ref: ElementReference): Element | null =>
34
- ref instanceof Element ? ref : first(doc(), ref)
34
+ ref instanceof Element ? ref : first(doc, ref)
35
35
 
36
36
  /**
37
37
  * # Create HTMLDivElement
@@ -43,7 +43,7 @@ export const useNs = (
43
43
  className?: string,
44
44
  ...children: (Node | string)[]
45
45
  ): HTMLDivElement => {
46
- const node: HTMLDivElement = doc().createElement('div')
46
+ const node: HTMLDivElement = doc.createElement('div')
47
47
  if (className) node.classList.add(className)
48
48
  node.append(...children)
49
49
  return node
@@ -65,7 +65,7 @@ export const useNs = (
65
65
  * @returns Nanpslash DOM element.
66
66
  */
67
67
  const makeNs = (): NSElement => {
68
- const circle: string = '<circle class=path cx=25 cy=25 r=20 fill=none/>'
68
+ const circle: string = '<circle class=path cx=25 cy=25 r=20 fill=none />'
69
69
  const svg = parse(`<svg viewBox="0 0 50 50">${circle}</svg>`) as Element
70
70
  const node = div('ns', div('nst'), div('nss', svg)) as NSElement
71
71
  node.nsId = Date.now()
@@ -125,7 +125,7 @@ export const useNs = (
125
125
  inside ? parseRef(inside) : bod
126
126
  ) as Element | null
127
127
  let ns: NSElement
128
- const recycledNs = first(parent ?? bod(), '& > .ns')
128
+ const recycledNs = first(parent ?? bod, '& > .ns')
129
129
  if (recycledNs) {
130
130
  ns = recycledNs as NSElement
131
131
  } else {
@@ -134,7 +134,7 @@ export const useNs = (
134
134
  }
135
135
  setNsText(ns, text ?? '')
136
136
  const top: string = scrollY + 'px'
137
- bod().style.setProperty('--ns-top', top)
137
+ bod.style.setProperty('--ns-top', top)
138
138
  return ns.nsId
139
139
  }
140
140
 
@@ -161,13 +161,13 @@ export const useNs = (
161
161
  * @param id Optional ID of a Nanosplash element or '*' .
162
162
  */
163
163
  const hide = (id?: number | '*'): void => {
164
- if (id === '*') all(doc(), '.ns').forEach(removeNs)
164
+ if (id === '*') all(doc, '.ns').forEach(removeNs)
165
165
  else removeNs(typeof id === 'number' ? findNs(id) : peekNsQueue())
166
166
  }
167
167
 
168
168
  // Add CSS to window
169
- first(doc(), '#ns')?.remove()
170
- bod().append(parse(`<style id="ns">${style}</style>`))
169
+ first(doc, '#ns')?.remove()
170
+ bod.append(parse(`<style id="ns">${style}</style>`))
171
171
 
172
172
  return {
173
173
  show,