nanosplash 4.0.3 → 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 (68) hide show
  1. package/.github/workflows/ci.prod.yml +43 -34
  2. package/.prettierrc +9 -10
  3. package/README.md +118 -52
  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 -90
  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 +16 -25
  42. package/vitest.config.ts +20 -0
  43. package/.env +0 -1
  44. package/.github/workflows/ci.test.yml +0 -48
  45. package/.github/workflows/vitepress.prod.yml +0 -69
  46. package/LICENSE +0 -21
  47. package/docs/.vitepress/config.ts +0 -78
  48. package/docs/.vitepress/theme/css/style.css +0 -258
  49. package/docs/.vitepress/theme/index.ts +0 -16
  50. package/docs/.vitepress/theme/vue/Card.vue +0 -31
  51. package/docs/.vitepress/theme/vue/CardGrid.vue +0 -17
  52. package/docs/.vitepress/theme/vue/PlayGround.vue +0 -36
  53. package/docs/api/doc/hide.md +0 -48
  54. package/docs/api/doc/show.md +0 -46
  55. package/docs/api/start/customize.md +0 -30
  56. package/docs/api/start/features.md +0 -17
  57. package/docs/api/start/install.md +0 -61
  58. package/docs/api/start/playground.md +0 -16
  59. package/docs/api/start/usage.md +0 -22
  60. package/docs/index.md +0 -33
  61. package/docs/public/macos.jpg +0 -0
  62. package/src/style/ns.sass +0 -120
  63. package/src/ts/Nanosplash.ts +0 -176
  64. package/src/ts/main.ts +0 -5
  65. package/src/ts/types/NanosplashInterface.ts +0 -29
  66. package/src/ts/types/Types.ts +0 -16
  67. package/src/ts/types/global.d.ts +0 -14
  68. package/tests/Nanosplash.spec.ts +0 -207
@@ -0,0 +1,124 @@
1
+ /// <reference types="vitest" />
2
+ import { describe, it, expect, beforeEach } from 'vitest'
3
+ import {useNs} from "@/composables/ns";
4
+ import type {INSElement} from "@/interfaces/INSElement";
5
+ import {Selectors} from "@/constants/ns";
6
+
7
+ const get = (selector: string) => document.querySelector(selector)
8
+ const getAll = (selector: string) => document.querySelectorAll(selector)
9
+ const div = (id?: string) => {
10
+ const element: HTMLDivElement = document.createElement("div")
11
+ if (id) {
12
+ element.id = id
13
+ }
14
+ return element
15
+ }
16
+
17
+ describe('useNs', () => {
18
+ let ns: ReturnType<typeof useNs>
19
+
20
+ beforeEach(() => {
21
+ // Reset DOM
22
+ document.body.innerHTML = ''
23
+ ns = useNs()
24
+ })
25
+
26
+ describe('show', () => {
27
+ it('creates a new Nanosplash with text', () => {
28
+ const id = ns.show('Loading...')
29
+ const nsElement = get(Selectors.ns)
30
+ const textElement = nsElement?.querySelector(Selectors.nsText)
31
+ const spinnerElement = nsElement?.querySelector(Selectors.nsSpinner)
32
+
33
+ expect(nsElement).toBeTruthy()
34
+ expect(textElement?.textContent).toBe('Loading...')
35
+ expect(spinnerElement).toBeTruthy()
36
+ expect(typeof id).toBe('number')
37
+ })
38
+
39
+ it('creates a new Nanosplash without text', () => {
40
+ const id = ns.show()
41
+ const nsElement = get(Selectors.ns)
42
+ const textElement = nsElement?.querySelector(Selectors.nsText)
43
+ expect(nsElement).toBeTruthy()
44
+ expect(textElement?.textContent).toBe(undefined)
45
+ expect(typeof id).toBe('number')
46
+ })
47
+
48
+ it('places Nanosplash inside a specified element', () => {
49
+ const container = div('container')
50
+ document.body.append(container)
51
+
52
+ ns.show('Inside', '#container')
53
+ const hostElement = container.querySelector(Selectors.ns)
54
+ expect(hostElement).toBeTruthy()
55
+ })
56
+
57
+ it('reuses an existing Nanosplash in the same container', () => {
58
+ ns.show('A')
59
+ const firstElement = get(Selectors.ns) as INSElement
60
+ const firstId = firstElement.nsId
61
+
62
+ ns.show('B')
63
+ const secondElement = get(Selectors.ns) as INSElement
64
+ const secondId = secondElement.nsId
65
+
66
+ const nsElements = getAll(Selectors.ns)
67
+ expect(firstId).toBe(secondId)
68
+ expect(nsElements.length).toBe(1)
69
+ })
70
+ })
71
+
72
+ describe('hide', () => {
73
+ it('removes the oldest Nanosplash element (FIFO)', () => {
74
+ document.body.append(div('a'), div('b'))
75
+ ns.show('A', '#a')
76
+ ns.show('B', '#b')
77
+ expect(getAll(Selectors.ns).length).toBe(2)
78
+ ns.hide()
79
+ expect(getAll(Selectors.ns).length).toBe(1)
80
+ expect(get(Selectors.nsText)?.textContent).toBe('B')
81
+ })
82
+
83
+ it('removes a specific Nanosplash by ID', () => {
84
+ document.body.append(div('a'), div('b'))
85
+ const idA = ns.show('A', '#a') as number
86
+ ns.show('B', '#b')
87
+ expect(getAll(Selectors.ns).length).toBe(2)
88
+ ns.hide(idA)
89
+ expect(getAll(Selectors.ns).length).toBe(1)
90
+ expect(get(Selectors.nsText)?.textContent).toBe('B')
91
+ })
92
+
93
+ it('removes all Nanosplash elements when given "*"', () => {
94
+ ns.show('One')
95
+ ns.show('Two')
96
+ ns.hide('*')
97
+ expect(getAll(Selectors.ns).length).toBe(0)
98
+ })
99
+ })
100
+
101
+ describe('style injection', () => {
102
+ it('injects the style element into the document', () => {
103
+ const styleElement = get('style#ns')
104
+ expect(styleElement).toBeTruthy()
105
+ expect(styleElement).toBeInstanceOf(HTMLStyleElement)
106
+ })
107
+
108
+ it('replaces an existing style element when re-invoked', () => {
109
+ const oldStyleElement = get('style#ns') as HTMLElement
110
+ useNs()
111
+ const newStyleElement = get('style#ns') as HTMLElement
112
+
113
+ expect(newStyleElement).toBeTruthy()
114
+ expect(newStyleElement).not.toBe(oldStyleElement)
115
+ })
116
+ })
117
+
118
+ describe('version', () => {
119
+ it('exposes the version from package.json', () => {
120
+ expect(typeof ns.version).toBe('string')
121
+ expect(ns.version).toMatch(/^\d+\.\d+\.\d+/)
122
+ })
123
+ })
124
+ })
package/tsconfig.json CHANGED
@@ -1,23 +1,31 @@
1
1
  {
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"]
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "verbatimModuleSyntax": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "erasableSyntaxOnly": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "noUncheckedSideEffectImports": true,
23
+ "baseUrl": ".",
24
+ "paths": {
25
+ "@/*": [
26
+ "./src/*"
27
+ ]
28
+ }
29
+ },
30
+ "include": ["src"]
23
31
  }
package/vite.config.ts CHANGED
@@ -1,33 +1,24 @@
1
- import { LibraryFormats, defineConfig } from 'vite'
2
- import { codecovVitePlugin } from '@codecov/vite-plugin'
1
+ import { defineConfig, type LibraryFormats } from 'vite'
2
+ import path from 'node:path'
3
3
  import { config } from 'dotenv'
4
4
  config()
5
5
 
6
+ const name = 'ns'
6
7
  const format = (process.env?.format ?? '') as LibraryFormats
7
8
  const entry = (process.env?.entry ?? '') as string
8
9
 
9
10
  export default defineConfig({
10
- build: {
11
- outDir: `dist/${format}`,
12
- lib: {
13
- entry,
14
- name: 'Nanosplash',
15
- formats: [format] as LibraryFormats[],
16
- fileName: 'ns',
17
- },
18
- },
19
- test: {
20
- environment: 'jsdom',
21
- globals: true,
22
- coverage: {
23
- reporter: ['text', 'json', 'html', 'lcov'],
24
- },
25
- },
26
- plugins: [
27
- codecovVitePlugin({
28
- enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
29
- bundleName: 'nanosplash',
30
- uploadToken: process.env.CODECOV_TOKEN,
31
- }),
32
- ],
11
+ build: {
12
+ lib: {
13
+ entry: entry, // Path to your library's entry point
14
+ name: name,
15
+ formats: [format], // ESM, CommonJS, IIFE
16
+ fileName: format => `${name}.${format}.js`,
17
+ },
18
+ },
19
+ resolve: {
20
+ alias: {
21
+ '@': path.resolve(__dirname, './src'),
22
+ },
23
+ },
33
24
  })
@@ -0,0 +1,20 @@
1
+ // vitest.config.ts
2
+ import { defineConfig } from 'vitest/config'
3
+ import path from "node:path";
4
+
5
+ export default defineConfig({
6
+ test: {
7
+ environment: 'jsdom',
8
+ coverage: {
9
+ enabled: true, // Enable coverage collection
10
+ provider: 'v8', // Use 'v8' (default) or 'istanbul' provider
11
+ reporter: ['lcov'], // Output coverage in LCOV format
12
+ reportsDirectory: './coverage', // Directory for coverage reports
13
+ },
14
+ },
15
+ resolve: {
16
+ alias: {
17
+ '@': path.resolve(__dirname, './src'),
18
+ },
19
+ },
20
+ })
package/.env DELETED
@@ -1 +0,0 @@
1
- CODECOV_TOKEN=4e686913-a962-407a-a847-7837e4f61be4
@@ -1,48 +0,0 @@
1
- name: CI Test - Build, Test
2
-
3
- on:
4
- pull_request:
5
- branches:
6
- - test
7
-
8
- jobs:
9
- build-and-test:
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - name: Install Node.js
14
- uses: actions/setup-node@v3
15
- with:
16
- node-version: 20
17
- registry-url: 'https://registry.npmjs.org'
18
-
19
- - name: Install PNPM
20
- uses: pnpm/action-setup@v3
21
- with:
22
- version: 8
23
-
24
- - name: Checkout
25
- uses: actions/checkout@v3
26
-
27
- - name: Set up Git and update production branch
28
- run: |
29
- git config --global user.name "GitHub Actions"
30
- git config --global user.email "actions@github.com"
31
- git fetch
32
- git checkout test
33
- git pull --no-rebase
34
-
35
- - name: Setup GitHub Pages
36
- uses: actions/configure-pages@v3
37
-
38
- - name: Install dependencies
39
- run: pnpm install --no-frozen-lockfile
40
-
41
- - name: Build
42
- run: pnpm build
43
-
44
- - name: Test
45
- run: pnpm test
46
-
47
- - name: Generate Code Coverage
48
- run: pnpm coverage
@@ -1,69 +0,0 @@
1
- # Sample workflow for building and deploying a VitePress site to GitHub Pages
2
- #
3
- name: Deploy VitePress site to Pages
4
-
5
- on:
6
- # Runs on pushes targeting the `main` branch. Change this to `master` if you're
7
- # using the `master` branch as the default branch.
8
- push:
9
- branches: [production]
10
- pull_request:
11
- branches: [production]
12
-
13
- # Allows you to run this workflow manually from the Actions tab
14
- workflow_dispatch:
15
-
16
- # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
17
- permissions:
18
- contents: read
19
- pages: write
20
- id-token: write
21
-
22
- # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
23
- # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
24
- concurrency:
25
- group: pages
26
- cancel-in-progress: false
27
-
28
- jobs:
29
- # Build job
30
- build:
31
- runs-on: ubuntu-latest
32
- steps:
33
- - name: Checkout
34
- uses: actions/checkout@v3
35
- with:
36
- fetch-depth: 0 # Not needed if lastUpdated is not enabled
37
- - uses: pnpm/action-setup@v3
38
- with:
39
- version: 8
40
- - name: Setup Node
41
- uses: actions/setup-node@v3
42
- with:
43
- node-version: 20
44
- - name: Setup GitHub Pages
45
- uses: actions/configure-pages@v3
46
- - name: Install dependencies
47
- run: pnpm install --no-frozen-lockfile
48
- - name: Build with VitePress
49
- run: |
50
- pnpm build:es
51
- pnpm docs:build
52
- touch docs/.vitepress/dist/.nojekyll
53
- - name: Upload artifact
54
- uses: actions/upload-pages-artifact@v3
55
- with:
56
- path: docs/.vitepress/dist
57
-
58
- # Deployment job
59
- deploy:
60
- environment:
61
- name: github-pages
62
- url: ${{ steps.deployment.outputs.page_url }}
63
- needs: build
64
- runs-on: ubuntu-latest
65
- name: Deploy
66
- steps:
67
- - name: Deploy to GitHub Pages
68
- id: deployment
69
- uses: actions/deploy-pages@v4
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Isak Hauge
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,78 +0,0 @@
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
- appearance: 'dark',
9
- themeConfig: {
10
- nav: [
11
- { text: 'Home', link: '/' },
12
- { text: 'Get started', link: '/api/start/install' },
13
- { text: 'Playground', link: '/api/start/playground' },
14
- { text: 'API documentation', link: '/api/doc/show' },
15
- ],
16
-
17
- sidebar: [
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
- text: 'Customize',
35
- link: '/api/start/customize',
36
- },
37
- ],
38
- },
39
- {
40
- text: 'API Documentation',
41
- items: [
42
- {
43
- text: 'Methods',
44
- items: [
45
- {
46
- text: 'Show',
47
- link: '/api/doc/show',
48
- },
49
- {
50
- text: 'Hide',
51
- link: '/api/doc/hide',
52
- },
53
- ],
54
- },
55
- ],
56
- },
57
- {
58
- text: 'Features',
59
- link: '/api/start/features',
60
- },
61
- ],
62
-
63
- socialLinks: [
64
- { icon: 'github', link: 'https://github.com/isakhauge/nanosplash' },
65
- { icon: 'twitter', link: 'https://twitter.com/isakhauge' },
66
- { icon: 'linkedin', link: 'https://www.linkedin.com/in/isakhauge' },
67
- ],
68
-
69
- search: {
70
- provider: 'local',
71
- },
72
-
73
- footer: {
74
- message:
75
- 'Made with 💖 by <a href="https://twitter.com/isakhauge">Isak Hauge</a>',
76
- },
77
- },
78
- })