nanosplash 2.5.2 → 3.0.0

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 (80) hide show
  1. package/.github/workflows/ci.yml +48 -0
  2. package/.prettierrc +10 -9
  3. package/README.md +22 -89
  4. package/dist/main.css +1 -0
  5. package/dist/ns.cjs.js +1 -0
  6. package/dist/ns.es.js +330 -0
  7. package/dist/ns.iife.js +2 -0
  8. package/index.html +41 -122
  9. package/package.json +27 -34
  10. package/src/main.ts +8 -5
  11. package/src/sass/ns.sass +86 -0
  12. package/src/ts/core/Nanosplash/Nanosplash.ts +97 -0
  13. package/src/ts/core/Nanosplash/interfaces/NanosplashAPI.ts +50 -0
  14. package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +42 -0
  15. package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +178 -0
  16. package/src/ts/core/Nanosplash/services/NanosplashService.ts +222 -0
  17. package/src/ts/types/Alias.d.ts +1 -0
  18. package/src/ts/types/Nanosplash.d.ts +18 -0
  19. package/src/ts/types/NanosplashService.d.ts +1 -0
  20. package/src/ts/util/Guid.ts +13 -0
  21. package/src/ts/util/Stack.ts +73 -0
  22. package/src/vite-env.d.ts +8 -0
  23. package/tests/Guid.spec.ts +21 -0
  24. package/tests/Nanosplash.spec.ts +64 -0
  25. package/tests/NanosplashRepository.spec.ts +91 -0
  26. package/tests/NanosplashService.spec.ts +119 -0
  27. package/tests/Stack.spec.ts +56 -0
  28. package/tsconfig.json +9 -5
  29. package/vite.config.ts +22 -14
  30. package/.github/workflows/production.yml +0 -60
  31. package/.github/workflows/release.yml +0 -61
  32. package/LICENSE +0 -21
  33. package/_config.yml +0 -1
  34. package/dist/iife/manifest.json +0 -7
  35. package/dist/iife/nanosplash.iife.js +0 -1
  36. package/dist/module/manifest.json +0 -7
  37. package/dist/module/nanosplash.cjs.js +0 -1
  38. package/dist/module/nanosplash.es.js +0 -371
  39. package/dist/module/style.css +0 -1
  40. package/docs/index.html +0 -131
  41. package/docs/nanosplash.iife.js +0 -6
  42. package/docs/style.css +0 -1
  43. package/docs/typedoc/.nojekyll +0 -1
  44. package/docs/typedoc/assets/highlight.css +0 -22
  45. package/docs/typedoc/assets/icons.css +0 -1043
  46. package/docs/typedoc/assets/icons.png +0 -0
  47. package/docs/typedoc/assets/icons@2x.png +0 -0
  48. package/docs/typedoc/assets/main.js +0 -52
  49. package/docs/typedoc/assets/search.js +0 -1
  50. package/docs/typedoc/assets/style.css +0 -1414
  51. package/docs/typedoc/assets/widgets.png +0 -0
  52. package/docs/typedoc/assets/widgets@2x.png +0 -0
  53. package/docs/typedoc/classes/Core_Nanosplash.default.html +0 -133
  54. package/docs/typedoc/index.html +0 -1
  55. package/docs/typedoc/modules/Core_Nanosplash.html +0 -1
  56. package/docs/typedoc/modules/types.html +0 -1
  57. package/favicon.svg +0 -15
  58. package/postcss.config.js +0 -8
  59. package/src/Core/Nanosplash.ts +0 -257
  60. package/src/Core/SplashInstance.ts +0 -298
  61. package/src/Exceptions/DestinationException.ts +0 -13
  62. package/src/Exceptions/Exception.ts +0 -9
  63. package/src/Exceptions/IllegalArgumentException.ts +0 -11
  64. package/src/Factory/NanosplashFactory.ts +0 -93
  65. package/src/Interfaces/ContextualAPIInterface.ts +0 -8
  66. package/src/Interfaces/IdentityInterface.ts +0 -3
  67. package/src/Interfaces/InsideInterface.ts +0 -5
  68. package/src/Interfaces/NanosplashInterface.ts +0 -8
  69. package/src/Interfaces/ProgressInterface.ts +0 -5
  70. package/src/Interfaces/ShowInterface.ts +0 -5
  71. package/src/Interfaces/WhileInterface.ts +0 -5
  72. package/src/Repositories/NanosplashRepository.ts +0 -82
  73. package/src/Tests/dom.spec.ts +0 -72
  74. package/src/Utilities/dom.ts +0 -49
  75. package/src/style.sass +0 -88
  76. package/src/types.d.ts +0 -59
  77. package/update-all.sh +0 -3
  78. package/vite.iife.config.js +0 -72
  79. package/vite.mod.config.js +0 -71
  80. package/vite.site.config.js +0 -22
@@ -1,8 +0,0 @@
1
- import {StrategyObject} from "../types";
2
- import {SplashInstance} from "../Core/SplashInstance";
3
-
4
- export interface NanosplashInterface extends StrategyObject {
5
- delete(splashInstance: SplashInstance): void
6
- hideAll(): void
7
- hide(id?: string): void
8
- }
@@ -1,5 +0,0 @@
1
- import {ProgressFunction} from "../types";
2
-
3
- export interface ProgressInterface {
4
- progress: ProgressFunction
5
- }
@@ -1,5 +0,0 @@
1
- import {ShowFunction} from "../types";
2
-
3
- export interface ShowInterface {
4
- show: ShowFunction
5
- }
@@ -1,5 +0,0 @@
1
- import {WhileFunction} from "../types";
2
-
3
- export interface WhileInterface {
4
- while: WhileFunction
5
- }
@@ -1,82 +0,0 @@
1
- import Exception from "../Exceptions/Exception";
2
- import {addClass, get, mk} from "../Utilities/dom";
3
- import {SplashInstance} from "../Core/SplashInstance";
4
- import {ContextualAPIObject, Destination} from "../types";
5
- import DestinationException from "../Exceptions/DestinationException";
6
- import IllegalArgumentException from "../Exceptions/IllegalArgumentException";
7
-
8
- export class NanosplashRepository {
9
- /**
10
- * # Destination To Node
11
- * Converts a Destination type into an HTMLElement.
12
- * @param {Destination} destination Either a node or a CSS selector.
13
- * @throws DestinationException
14
- * @throws IllegalArgumentException
15
- */
16
- public static destinationToNode(destination: Destination): HTMLElement
17
- {
18
- if (typeof destination === 'string') {
19
- try {
20
- const element = get<HTMLElement>(destination)
21
- if (!element) {
22
- throw new Exception(`No DOM match with ${destination}`)
23
- }
24
- return element
25
- } catch (e) {
26
- throw new DestinationException(
27
- `Destination (${destination}) is either invalid or non-existing in DOM`,
28
- destination,
29
- e as Exception
30
- )
31
- }
32
- } else if (destination instanceof Node) {
33
- return destination as HTMLElement
34
- }
35
-
36
- throw new IllegalArgumentException(
37
- `Destination (${destination}) must be either a Node or a CSS selector`,
38
- destination
39
- )
40
- }
41
-
42
- /**
43
- * # Create Contextual API Object
44
- * Creates an object containing props that adhere to the ns API.
45
- * @param {SplashInstance} splash
46
- */
47
- public static createContextualApiObject(splash: SplashInstance): ContextualAPIObject
48
- {
49
- const ctx = {
50
- getId: () => splash.getId(),
51
- remove: () => splash.delete(),
52
- moveTo: (selector: string) => splash.moveTo(selector),
53
- getText: () => splash.getText(),
54
- setText: (text: string) => splash.setText(text),
55
- getImgSrc: () => splash.getImgSrc(),
56
- setImgSrc: (src?: string) => splash.setImgSrc(src)
57
- }
58
- return {
59
- ...ctx,
60
- inside: (selector: string) => {
61
- splash.moveTo(selector)
62
- return ctx
63
- },
64
- }
65
- }
66
-
67
- /**
68
- * # Create Nanosplash Spinner Element
69
- * Returns a DIV element wrapping an SVG element.
70
- */
71
- public static createNanosplashSpinnerElement(): HTMLDivElement
72
- {
73
- const div = mk('div') as HTMLDivElement
74
- addClass(div, 'ns-spinner')
75
- div.innerHTML = `
76
- <svg viewBox="0 0 50 50">
77
- <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
78
- </svg>
79
- `
80
- return div
81
- }
82
- }
@@ -1,72 +0,0 @@
1
- import {test} from "vitest"
2
- import {addClass, get, mk, move, setAttr} from "../Utilities/dom"
3
-
4
- const resetDOM = () => document.body.innerHTML = ''
5
-
6
- test('Get DOM element function', () => {
7
- const element = document.createElement('div')
8
- element.id = 'a'
9
- element.classList.add('b')
10
- element.setAttribute('data-ref', 'c')
11
- document.body.append(element)
12
-
13
- const selector = 'div#a.b[data-ref="c"]'
14
- const refElement = get<HTMLDivElement>(selector)
15
-
16
- expect(refElement?.outerHTML).toBe(element.outerHTML)
17
-
18
- resetDOM()
19
- })
20
-
21
- test('Move Element from origin to destination', () => {
22
- const html = `
23
- <div id="main">
24
- <div id="a">
25
- <div id="b">
26
- <div id="c">
27
- <div id="first"></div>
28
- </div>
29
- </div>
30
- </div>
31
- </div>
32
- `
33
- document.body.innerHTML = html
34
-
35
- const main = get('#main') as HTMLDivElement
36
- const first = get('#first') as HTMLDivElement
37
- const b = get('#b') as HTMLDivElement
38
- const c = get('#c') as HTMLDivElement
39
-
40
- move(b, main)
41
- move(c, main)
42
- move(first, main, true)
43
-
44
- const ids = Array.from(main.children).map((v => v.id))
45
-
46
- expect(ids.join(',')).toBe('first,a,b,c')
47
-
48
- resetDOM()
49
- })
50
-
51
- test('Make HTML Element', () => {
52
- const span = mk('span')
53
- document.body.appendChild(span)
54
- const spanFromDom = document.body.children.item(0) as Node
55
- expect(spanFromDom instanceof HTMLSpanElement).toBe(true)
56
- resetDOM()
57
- })
58
-
59
- test('Add CSS classes', () => {
60
- const div = mk('div')
61
- addClass(div, 'ns-1', 'ns-2', 'ns-3')
62
- expect(div.classList.toString()).toBe('ns-1 ns-2 ns-3')
63
- resetDOM()
64
- })
65
-
66
- test('Set Node attribute', () => {
67
- const div = mk('div')
68
- const attr = {name: 'data-test', value: 'success'}
69
- setAttr(div, attr.name, attr.value)
70
- expect(div.getAttribute(attr.name)).toBe(attr.value)
71
- resetDOM()
72
- })
@@ -1,49 +0,0 @@
1
- import {ElementTag} from "../types";
2
-
3
- /**
4
- * # Get
5
- * Helper function to get Elements from the DOM using CSS selector.
6
- * @param {string} selector CSS Selector.
7
- */
8
- export function get<T>(selector: string): HTMLElement | T | null {
9
- return document.querySelector(selector) as HTMLElement | T | null
10
- }
11
-
12
- /**
13
- * # Move
14
- * Helper function that can move a node inside another node.
15
- * @param {Node} source The node to be moved.
16
- * @param {Node} destination The destination node.
17
- * @param {boolean} asFirstChild Append or prepend the new node inside the child list.
18
- */
19
- export function move(source: Node, destination: Node, asFirstChild: boolean = false): void
20
- {
21
- if (source && destination) {
22
- (destination.hasChildNodes() && asFirstChild)
23
- ? destination.insertBefore(source, destination.firstChild)
24
- : destination.appendChild(source)
25
- }
26
- }
27
-
28
- /**
29
- * # Make
30
- * Short hand helper function that creates Nodes.
31
- * @param {ElementTag} tag
32
- */
33
- export const mk = (tag: ElementTag) => document.createElement(tag)
34
-
35
- /**
36
- * # Add Class
37
- * Helper class that easily adds classes to an element.
38
- * @param {HTMLElement} node The node
39
- * @param {...string[]} classes
40
- */
41
- export function addClass(node: HTMLElement, ...classes: string[]): void
42
- {
43
- node.classList.add(...classes)
44
- }
45
-
46
- export function setAttr(node: HTMLElement, attribute: string, value: string): void
47
- {
48
- node.setAttribute(attribute, value)
49
- }
package/src/style.sass DELETED
@@ -1,88 +0,0 @@
1
- $z-index-regular: 1
2
- $z-index-fullscreen: 2
3
- $text-color: #5a6685
4
- $bg-color: rgba(White, 0.8)
5
-
6
- %blur
7
- overflow: hidden
8
- filter: blur(5px)
9
-
10
- // Wraps the content replaced by Nanosplash
11
- .ns-wrapper
12
- position: relative
13
-
14
- // Only active while in fullscreen mode
15
- .ns-fs
16
- top: 0
17
- left: 0
18
- position: fixed
19
- min-width: 100%
20
- min-height: 100vh
21
- z-index: $z-index-fullscreen
22
-
23
- // Blurs the wrapped content
24
- body .ns-fs ~ *, .ns-blur
25
- @extend %blur
26
-
27
- // Nanosplash window containing image and text
28
- .ns-window
29
- top: 0
30
- left: 0
31
- width: 100%
32
- height: 100%
33
- display: flex
34
- position: absolute
35
- align-items: center
36
- justify-content: center
37
- z-index: $z-index-regular
38
- background-color: $bg-color
39
-
40
- // Image
41
- .ns-img
42
- width: 9rem
43
- max-height: 9rem
44
- margin-bottom: 2em
45
-
46
- // Text container containing text and spinner
47
- .ns-text-container
48
- display: flex
49
- justify-content: center
50
- align-items: center
51
-
52
- // Text node
53
- .ns-text
54
- display: flex
55
- justify-content: center
56
- color: $text-color
57
-
58
- // Spinner node
59
- .ns-spinner
60
- display: flex
61
- margin-left: 1em
62
- width: 1em
63
- height: 1em
64
- & > svg
65
- animation: Rotate 2s linear infinite
66
- position: relative
67
- width: inherit
68
- height: inherit
69
- stroke-width: 8
70
- & .path
71
- stroke: $text-color
72
- stroke-linecap: round
73
- animation: Dash 1.5s ease-in-out infinite
74
-
75
- // Spinner animations:
76
- @keyframes Rotate
77
- 100%
78
- transform: rotate(360deg)
79
- @keyframes Dash
80
- 0%
81
- stroke-dasharray: 1, 150
82
- stroke-dashoffset: 0
83
- 50%
84
- stroke-dasharray: 90, 150
85
- stroke-dashoffset: -35
86
- 100%
87
- stroke-dasharray: 90, 150
88
- stroke-dashoffset: -124
package/src/types.d.ts DELETED
@@ -1,59 +0,0 @@
1
- import Nanosplash from "./Core/Nanosplash";
2
- import {SplashInstance} from "./Core/SplashInstance";
3
- import {ShowInterface} from "./Interfaces/ShowInterface";
4
- import {ContextualAPIInterface} from "./Interfaces/ContextualAPIInterface";
5
- import {NanosplashInterface} from "./Interfaces/NanosplashInterface";
6
-
7
- declare global {
8
- interface Window {
9
- Nanosplash: typeof Nanosplash
10
- installNanosplash: (options?: NanosplashOptions) => void
11
- ns: Nanosplash
12
- }
13
- }
14
-
15
- export type Destination = Node | string
16
- export type SplashJob = [Promise<any>, string]
17
-
18
- /**
19
- * @internal
20
- */
21
- export type ElementTag = keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap
22
-
23
- /**
24
- * @internal
25
- */
26
- type CSSProperty = keyof CSSStyleDeclaration
27
-
28
- export type ShowFunction = (text: string) => ContextualAPIObject
29
- export type ProgressFunction = (...[]: SplashJob[]) => ContextualAPIObject
30
- export type WhileFunction = (asyncTask: Promise<any>) => ShowInterface
31
- export type StrategyObject = {
32
- show: ShowFunction,
33
- progress: ProgressFunction,
34
- while: WhileFunction
35
- }
36
-
37
- export type InsideFunction = (selector: string) => ContextualAPIInterface
38
-
39
- export type ContextualAPIObject = {
40
- getId: () => string,
41
- inside?: InsideFunction,
42
- remove: () => void
43
- moveTo: (selector: string) => void,
44
- getText: () => string,
45
- setText: (text: string) => SplashInstance,
46
- getImgSrc: () => string | undefined,
47
- setImgSrc: (src?: string) => SplashInstance
48
- }
49
-
50
- export type InstanceIterationCallback = (id: string, splashInstance: SplashInstance, i: number) => boolean
51
-
52
- export type NanosplashOptions = {
53
- imgSrc?: string,
54
- spinner?: boolean,
55
- fontSize?: string,
56
- debug?: boolean
57
- }
58
-
59
- export default Nanosplash
package/update-all.sh DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env bash
2
- yarn remove @types/jsdom autoprefixer cssnano jsdom postcss sass ts-jest ts-node typedoc typescript vite vitest
3
- yarn add -D @types/jsdom autoprefixer cssnano jsdom postcss sass ts-jest ts-node typedoc typescript vite vitest
@@ -1,72 +0,0 @@
1
- import { defineConfig } from 'vite'
2
-
3
- export default defineConfig({
4
- mode: 'production',
5
- build: {
6
- lib: {
7
- entry: 'src/main.ts',
8
- name: 'Nanosplash',
9
- fileName: 'nanosplash',
10
- formats: ['iife'],
11
- },
12
- outDir: 'dist/iife',
13
- cssCodeSplit: true,
14
- minify: 'terser',
15
- terserOptions: {
16
- parse: {
17
- bare_returns: true,
18
- },
19
- compress: {
20
- keep_fargs: false,
21
- keep_fnames: false,
22
- keep_classnames: false,
23
- module: true,
24
- passes: 3,
25
- toplevel: true,
26
- unsafe_arrows: true,
27
- },
28
- mangle: {
29
- toplevel: true,
30
- // Reserved class names
31
- reserved: [],
32
- properties: {
33
- reserved: [
34
- 'ns',
35
- 'getId',
36
- 'getText',
37
- 'setText',
38
- 'getImgSrc',
39
- 'setImgSrc',
40
- 'moveTo',
41
- 'delete',
42
- 'img',
43
- 'show',
44
- 'inside',
45
- 'remove',
46
- 'progress',
47
- 'while',
48
- 'delete',
49
- 'hideAll',
50
- 'hide',
51
- ],
52
- }
53
- },
54
- format: {
55
- // wrap_iife: true
56
- },
57
- sourceMap: {
58
- // source map options
59
- },
60
- ecma: 2015, // specify one of: 5, 2015, 2016, etc.
61
- keep_classnames: false,
62
- keep_fnames: false,
63
- ie8: false,
64
- module: true,
65
- nameCache: null, // or specify a name cache object
66
- safari10: false,
67
- toplevel: true,
68
- },
69
- // keep_classnames: false,
70
- manifest: true,
71
- },
72
- })
@@ -1,71 +0,0 @@
1
- import { defineConfig } from 'vite'
2
-
3
- export default defineConfig({
4
- mode: 'production',
5
- build: {
6
- lib: {
7
- entry: 'src/Core/Nanosplash.ts',
8
- name: 'Nanosplash',
9
- fileName: 'nanosplash',
10
- formats: ['es', 'cjs'],
11
- },
12
- outDir: 'dist/module',
13
- cssCodeSplit: false,
14
- minify: 'terser',
15
- terserOptions: {
16
- parse: {
17
- bare_returns: false,
18
- },
19
- compress: {
20
- keep_fargs: false,
21
- keep_fnames: false,
22
- keep_classnames: true,
23
- module: true,
24
- passes: 3,
25
- toplevel: true,
26
- unsafe_arrows: true,
27
- },
28
- mangle: {
29
- toplevel: true,
30
- // Reserved class names
31
- reserved: [],
32
- properties: {
33
- reserved: [
34
- 'ns',
35
- 'getId',
36
- 'getText',
37
- 'setText',
38
- 'getImgSrc',
39
- 'setImgSrc',
40
- 'showSpinner',
41
- 'setFontSize',
42
- 'getFontSize',
43
- 'spinnerIsVisible',
44
- 'moveTo',
45
- 'delete',
46
- 'show',
47
- 'inside',
48
- 'remove',
49
- 'progress',
50
- 'while',
51
- 'delete',
52
- 'hideAll',
53
- 'hide',
54
- 'getFromDestinationNode',
55
- 'getDestination'
56
- ],
57
- }
58
- },
59
- ecma: 2015, // specify one of: 5, 2015, 2016, etc.
60
- keep_classnames: true,
61
- keep_fnames: false,
62
- ie8: false,
63
- module: true,
64
- nameCache: null, // or specify a name cache object
65
- safari10: false,
66
- toplevel: true,
67
- },
68
- // keep_classnames: false,
69
- manifest: true,
70
- },
71
- })
@@ -1,22 +0,0 @@
1
- import { defineConfig } from 'vite'
2
-
3
- export default defineConfig({
4
- mode: 'production',
5
- build: {
6
- lib: {
7
- entry: 'index.html',
8
- name: 'Nanosplash',
9
- fileName: 'nanosplash',
10
- formats: ['iife'],
11
- },
12
- outDir: 'docs',
13
- cssCodeSplit: false,
14
- assetsInlineLimit: 100000000,
15
- rollupOptions: {
16
- outputOptions: {
17
- inlineDynamicImports: true,
18
- manualChunks: () => 'main.js',
19
- },
20
- },
21
- },
22
- })