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
@@ -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,16 +1,24 @@
1
- import { LibraryFormats, defineConfig } from 'vite'
1
+ import { defineConfig, type LibraryFormats } from 'vite'
2
+ import path from 'node:path'
3
+ import { config } from 'dotenv'
4
+ config()
2
5
 
6
+ const name = 'ns'
3
7
  const format = (process.env?.format ?? '') as LibraryFormats
4
8
  const entry = (process.env?.entry ?? '') as string
5
9
 
6
10
  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
- },
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
+ },
16
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
+ })
@@ -1,62 +0,0 @@
1
- name: Build and Test
2
-
3
- on:
4
- push:
5
- branches:
6
- - production
7
- pull_request:
8
- branches:
9
- - production
10
-
11
- jobs:
12
- build-and-test:
13
- runs-on: ubuntu-latest
14
-
15
- steps:
16
- - name: Checkout
17
- uses: actions/checkout@v3
18
-
19
- - name: Install PNPM
20
- uses: pnpm/action-setup@v3
21
- with:
22
- version: 8
23
-
24
- - name: Setup Node.js
25
- uses: actions/setup-node@v3
26
- with:
27
- node-version: 20
28
- registry-url: 'https://registry.npmjs.org'
29
- - name: Set up Git and update production branch
30
- run: |
31
- git config --global user.name "GitHub Actions"
32
- git config --global user.email "actions@github.com"
33
- git fetch
34
- git checkout production
35
- git pull --no-rebase
36
-
37
- - name: Setup Pages
38
- uses: actions/configure-pages@v3
39
-
40
- - name: Install dependencies
41
- run: pnpm install --no-frozen-lockfile
42
-
43
- - name: Build (Vite)
44
- run: pnpm build
45
-
46
- - name: Test (Vitest)
47
- run: pnpm test
48
-
49
- - name: Generate Code Coverage (Vitest)
50
- run: pnpm coverage
51
-
52
- - name: Commit and push changes
53
- run: |
54
- git add .
55
- git add -f coverage/**/* dist/**/*
56
- git commit --allow-empty -m "Build, test, and coverage report"
57
- git push
58
-
59
- - name: Publish to NPM
60
- run: npm publish
61
- env:
62
- NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
@@ -1,68 +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 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 docs:build
51
- touch docs/.vitepress/dist/.nojekyll
52
- - name: Upload artifact
53
- uses: actions/upload-pages-artifact@v2
54
- with:
55
- path: docs/.vitepress/dist
56
-
57
- # Deployment job
58
- deploy:
59
- environment:
60
- name: github-pages
61
- url: ${{ steps.deployment.outputs.page_url }}
62
- needs: build
63
- runs-on: ubuntu-latest
64
- name: Deploy
65
- steps:
66
- - name: Deploy to GitHub Pages
67
- id: deployment
68
- uses: actions/deploy-pages@v2
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
- })