nanosplash 2.3.3 → 2.5.1

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 (40) hide show
  1. package/.github/workflows/production.yml +5 -2
  2. package/README.md +38 -42
  3. package/dist/iife/nanosplash.iife.js +1 -1
  4. package/dist/module/manifest.json +1 -4
  5. package/dist/module/nanosplash.cjs.js +1 -1
  6. package/dist/module/nanosplash.es.js +132 -74
  7. package/dist/module/style.css +1 -0
  8. package/docs/index.html +73 -19
  9. package/docs/nanosplash.iife.js +6 -1
  10. package/docs/style.css +1 -1
  11. package/docs/typedoc/assets/main.js +2 -2
  12. package/docs/typedoc/assets/search.js +1 -1
  13. package/docs/typedoc/classes/Core_Nanosplash.default.html +133 -0
  14. package/docs/typedoc/index.html +1 -1
  15. package/docs/typedoc/modules/Core_Nanosplash.html +1 -0
  16. package/docs/typedoc/modules/types.html +1 -0
  17. package/index.html +72 -22
  18. package/package.json +16 -15
  19. package/src/Core/Nanosplash.ts +188 -31
  20. package/src/Core/SplashInstance.ts +137 -21
  21. package/src/Exceptions/DestinationException.ts +13 -0
  22. package/src/Exceptions/Exception.ts +9 -0
  23. package/src/Exceptions/IllegalArgumentException.ts +11 -0
  24. package/src/Factory/NanosplashFactory.ts +37 -17
  25. package/src/Interfaces/NanosplashInterface.ts +6 -2
  26. package/src/Repositories/NanosplashRepository.ts +82 -0
  27. package/src/{utilities → Tests}/dom.spec.ts +7 -5
  28. package/src/Utilities/dom.ts +49 -0
  29. package/src/main.ts +5 -2
  30. package/src/style.sass +47 -17
  31. package/src/types.d.ts +23 -14
  32. package/tsconfig.json +1 -0
  33. package/update-all.sh +2 -2
  34. package/vite.config.ts +16 -0
  35. package/vite.mod.config.js +10 -11
  36. package/dist/module/Nanosplash.css +0 -1
  37. package/jest.config.ts +0 -194
  38. package/src/Interfaces/ImageInterface.ts +0 -5
  39. package/src/repositories/NanosplashRepository.ts +0 -39
  40. package/src/utilities/dom.ts +0 -26
package/src/style.sass CHANGED
@@ -1,14 +1,17 @@
1
1
  $z-index-regular: 1
2
2
  $z-index-fullscreen: 2
3
+ $text-color: #5a6685
3
4
  $bg-color: rgba(White, 0.8)
4
5
 
5
6
  %blur
6
7
  overflow: hidden
7
8
  filter: blur(5px)
8
9
 
10
+ // Wraps the content replaced by Nanosplash
9
11
  .ns-wrapper
10
12
  position: relative
11
13
 
14
+ // Only active while in fullscreen mode
12
15
  .ns-fs
13
16
  top: 0
14
17
  left: 0
@@ -17,10 +20,11 @@ $bg-color: rgba(White, 0.8)
17
20
  min-height: 100vh
18
21
  z-index: $z-index-fullscreen
19
22
 
20
- // Fullscreen content blur
23
+ // Blurs the wrapped content
21
24
  body .ns-fs ~ *, .ns-blur
22
25
  @extend %blur
23
26
 
27
+ // Nanosplash window containing image and text
24
28
  .ns-window
25
29
  top: 0
26
30
  left: 0
@@ -33,26 +37,52 @@ body .ns-fs ~ *, .ns-blur
33
37
  z-index: $z-index-regular
34
38
  background-color: $bg-color
35
39
 
40
+ // Image
36
41
  .ns-img
37
- max-width: 9rem
42
+ width: 9rem
38
43
  max-height: 9rem
39
- margin-bottom: 1rem
44
+ margin-bottom: 2em
40
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
41
53
  .ns-text
42
- color: #333
43
54
  display: flex
44
- text-align: center
45
- &::after
46
- margin-left: 0.25em
47
- content: '\00a0\00a0\00a0'
48
- animation: anim 1s infinite
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
49
74
 
50
- @keyframes anim
75
+ // Spinner animations:
76
+ @keyframes Rotate
77
+ 100%
78
+ transform: rotate(360deg)
79
+ @keyframes Dash
51
80
  0%
52
- content: '\00a0\00a0\00a0'
53
- 30%
54
- content: '.\00a0\00a0'
55
- 60%
56
- content: '..\00a0'
57
- 90%
58
- content: '...'
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 CHANGED
@@ -1,38 +1,42 @@
1
- import {Nanosplash} from "./Core/Nanosplash";
1
+ import Nanosplash from "./Core/Nanosplash";
2
2
  import {SplashInstance} from "./Core/SplashInstance";
3
3
  import {ShowInterface} from "./Interfaces/ShowInterface";
4
4
  import {ContextualAPIInterface} from "./Interfaces/ContextualAPIInterface";
5
+ import {NanosplashInterface} from "./Interfaces/NanosplashInterface";
5
6
 
6
7
  declare global {
7
8
  interface Window {
9
+ Nanosplash: typeof Nanosplash
10
+ installNanosplash: (options?: NanosplashOptions) => void
8
11
  ns: Nanosplash
9
12
  }
10
13
  }
11
14
 
12
- type Destination = Node | string
13
- type SplashJob = [Promise<any>, string]
15
+ export type Destination = Node | string
16
+ export type SplashJob = [Promise<any>, string]
14
17
 
15
18
  /**
16
19
  * @internal
17
20
  */
18
- export type HTMLElementTag = keyof HTMLElementTagNameMap
21
+ export type ElementTag = keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap
19
22
 
20
23
  /**
21
24
  * @internal
22
25
  */
23
26
  type CSSProperty = keyof CSSStyleDeclaration
24
27
 
25
- type ShowFunction = (text: string) => ContextualAPIInterface
26
- type ProgressFunction = (...[]: SplashJob[]) => ContextualAPIInterface
27
- type WhileFunction = (asyncTask: Promise<any>) => ShowInterface
28
- type StrategyObject = {
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 = {
29
32
  show: ShowFunction,
30
33
  progress: ProgressFunction,
31
34
  while: WhileFunction
32
35
  }
33
- type ImgFunction = (src: string) => StrategyObject
34
- type InsideFunction = (selector: string) => ContextualAPIInterface
35
- type ContextualAPIObject = {
36
+
37
+ export type InsideFunction = (selector: string) => ContextualAPIInterface
38
+
39
+ export type ContextualAPIObject = {
36
40
  getId: () => string,
37
41
  inside?: InsideFunction,
38
42
  remove: () => void
@@ -43,7 +47,12 @@ type ContextualAPIObject = {
43
47
  setImgSrc: (src?: string) => SplashInstance
44
48
  }
45
49
 
46
- declare module 'nanosplash' {
47
- class Nanosplash {}
48
- class SplashInstance {}
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
49
56
  }
57
+
58
+ export default Nanosplash
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es6",
4
+ "types": ["vitest/globals"],
4
5
  "module": "ESNext",
5
6
  "lib": ["ESNext", "DOM"],
6
7
  "moduleResolution": "Node",
package/update-all.sh CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env bash
2
- yarn remove @types/jest @types/jsdom autoprefixer cssnano jest jsdom jest-environment-jsdom postcss sass ts-jest ts-node typedoc typescript vite
3
- yarn add -D @types/jest @types/jsdom autoprefixer cssnano jest jsdom jest-environment-jsdom postcss sass ts-jest ts-node typedoc typescript vite
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
package/vite.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'jsdom',
7
+ coverage: {
8
+ reporter: ['text', 'html'],
9
+ exclude: [
10
+ 'node_modules/',
11
+ 'dist/',
12
+ 'docs/',
13
+ ],
14
+ },
15
+ }
16
+ })
@@ -10,16 +10,16 @@ export default defineConfig({
10
10
  formats: ['es', 'cjs'],
11
11
  },
12
12
  outDir: 'dist/module',
13
- cssCodeSplit: true,
13
+ cssCodeSplit: false,
14
14
  minify: 'terser',
15
15
  terserOptions: {
16
16
  parse: {
17
- bare_returns: true,
17
+ bare_returns: false,
18
18
  },
19
19
  compress: {
20
20
  keep_fargs: false,
21
21
  keep_fnames: false,
22
- keep_classnames: false,
22
+ keep_classnames: true,
23
23
  module: true,
24
24
  passes: 3,
25
25
  toplevel: true,
@@ -37,9 +37,12 @@ export default defineConfig({
37
37
  'setText',
38
38
  'getImgSrc',
39
39
  'setImgSrc',
40
+ 'showSpinner',
41
+ 'setFontSize',
42
+ 'getFontSize',
43
+ 'spinnerIsVisible',
40
44
  'moveTo',
41
45
  'delete',
42
- 'img',
43
46
  'show',
44
47
  'inside',
45
48
  'remove',
@@ -48,17 +51,13 @@ export default defineConfig({
48
51
  'delete',
49
52
  'hideAll',
50
53
  'hide',
54
+ 'getFromDestinationNode',
55
+ 'getDestination'
51
56
  ],
52
57
  }
53
58
  },
54
- format: {
55
- // wrap_iife: true
56
- },
57
- sourceMap: {
58
- // source map options
59
- },
60
59
  ecma: 2015, // specify one of: 5, 2015, 2016, etc.
61
- keep_classnames: false,
60
+ keep_classnames: true,
62
61
  keep_fnames: false,
63
62
  ie8: false,
64
63
  module: true,
@@ -1 +0,0 @@
1
- @charset "UTF-8";.ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:1rem;max-height:9rem;max-width:9rem}.ns-text{color:#333;display:flex;text-align:center}.ns-text:after{-webkit-animation:anim 1s infinite;animation:anim 1s infinite;content:"\a0\a0\a0";margin-left:.25em}@-webkit-keyframes anim{0%{content:"\a0\a0\a0"}30%{content:".\a0\a0"}60%{content:"..\a0"}90%{content:"..."}}@keyframes anim{0%{content:"\a0\a0\a0"}30%{content:".\a0\a0"}60%{content:"..\a0"}90%{content:"..."}}
package/jest.config.ts DELETED
@@ -1,194 +0,0 @@
1
- /*
2
- * For a detailed explanation regarding each configuration property and type check, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
-
6
- export default {
7
- // All imported modules in your tests should be mocked automatically
8
- // automock: false,
9
-
10
- // Stop running tests after `n` failures
11
- // bail: 0,
12
-
13
- // The directory where Jest should store its cached dependency information
14
- // cacheDirectory: "/private/var/folders/zc/vybtlxpn4dn4wr85nb3sh7lh0000gn/T/jest_dx",
15
-
16
- // Automatically clear mock calls and instances between every test
17
- clearMocks: true,
18
-
19
- // Indicates whether the coverage information should be collected while executing the test
20
- collectCoverage: true,
21
-
22
- // An array of glob patterns indicating a set of files for which coverage information should be collected
23
- // collectCoverageFrom: undefined,
24
-
25
- // The directory where Jest should output its coverage files
26
- coverageDirectory: 'coverage',
27
-
28
- // An array of regexp pattern strings used to skip coverage collection
29
- // coveragePathIgnorePatterns: [
30
- // "/node_modules/"
31
- // ],
32
-
33
- // Indicates which provider should be used to instrument code for coverage
34
- coverageProvider: 'v8',
35
-
36
- // A list of reporter names that Jest uses when writing coverage reports
37
- // coverageReporters: [
38
- // "json",
39
- // "text",
40
- // "lcov",
41
- // "clover"
42
- // ],
43
-
44
- // An object that configures minimum threshold enforcement for coverage results
45
- // coverageThreshold: undefined,
46
-
47
- // A path to a custom dependency extractor
48
- // dependencyExtractor: undefined,
49
-
50
- // Make calling deprecated APIs throw helpful error messages
51
- // errorOnDeprecated: false,
52
-
53
- // Force coverage collection from ignored files using an array of glob patterns
54
- // forceCoverageMatch: [],
55
-
56
- // A path to a module which exports an async function that is triggered once before all test suites
57
- // globalSetup: undefined,
58
-
59
- // A path to a module which exports an async function that is triggered once after all test suites
60
- // globalTeardown: undefined,
61
-
62
- // A set of global variables that need to be available in all test environments
63
- // globals: {},
64
-
65
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66
- // maxWorkers: "50%",
67
-
68
- // An array of directory names to be searched recursively up from the requiring module's location
69
- // moduleDirectories: [
70
- // "node_modules"
71
- // ],
72
-
73
- // An array of file extensions your modules use
74
- // moduleFileExtensions: [
75
- // "js",
76
- // "jsx",
77
- // "ts",
78
- // "tsx",
79
- // "json",
80
- // "node"
81
- // ],
82
-
83
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84
- // moduleNameMapper: {},
85
-
86
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87
- // modulePathIgnorePatterns: [],
88
-
89
- // Activates notifications for test results
90
- // notify: false,
91
-
92
- // An enum that specifies notification mode. Requires { notify: true }
93
- // notifyMode: "failure-change",
94
-
95
- // A preset that is used as a base for Jest's configuration
96
- preset: 'ts-jest',
97
-
98
- // Run tests from one or more projects
99
- // projects: undefined,
100
-
101
- // Use this configuration option to add custom reporters to Jest
102
- // reporters: undefined,
103
-
104
- // Automatically reset mock state between every test
105
- // resetMocks: false,
106
-
107
- // Reset the module registry before running each individual test
108
- // resetModules: false,
109
-
110
- // A path to a custom resolver
111
- // resolver: undefined,
112
-
113
- // Automatically restore mock state between every test
114
- // restoreMocks: false,
115
-
116
- // The root directory that Jest should scan for tests and modules within
117
- // rootDir: undefined,
118
-
119
- // A list of paths to directories that Jest should use to search for files in
120
- // roots: [
121
- // "<rootDir>"
122
- // ],
123
-
124
- // Allows you to use a custom runner instead of Jest's default test runner
125
- // runner: "jest-runner",
126
-
127
- // The paths to modules that run some code to configure or set up the testing environment before each test
128
- // setupFiles: [],
129
-
130
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
131
- // setupFilesAfterEnv: [],
132
-
133
- // The number of seconds after which a test is considered as slow and reported as such in the results.
134
- // slowTestThreshold: 5,
135
-
136
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
137
- // snapshotSerializers: [],
138
-
139
- // The test environment that will be used for testing
140
- testEnvironment: 'jsdom',
141
-
142
- // Options that will be passed to the testEnvironment
143
- // testEnvironmentOptions: {},
144
-
145
- // Adds a location field to test results
146
- // testLocationInResults: false,
147
-
148
- // The glob patterns Jest uses to detect test files
149
- // testMatch: [
150
- // "**/__tests__/**/*.[jt]s?(x)",
151
- // "**/?(*.)+(spec|test).[tj]s?(x)"
152
- // ],
153
-
154
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
155
- // testPathIgnorePatterns: [
156
- // "/node_modules/"
157
- // ],
158
-
159
- // The regexp pattern or array of patterns that Jest uses to detect test files
160
- // testRegex: [],
161
-
162
- // This option allows the use of a custom results processor
163
- // testResultsProcessor: undefined,
164
-
165
- // This option allows use of a custom test runner
166
- // testRunner: "jest-circus/runner",
167
-
168
- // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169
- // testURL: "http://localhost",
170
-
171
- // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172
- // timers: "real",
173
-
174
- // A map from regular expressions to paths to transformers
175
- // transform: undefined,
176
-
177
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178
- // transformIgnorePatterns: [
179
- // "/node_modules/",
180
- // "\\.pnp\\.[^\\/]+$"
181
- // ],
182
-
183
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184
- // unmockedModulePathPatterns: undefined,
185
-
186
- // Indicates whether each individual test should be reported during the run
187
- // verbose: undefined,
188
-
189
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190
- // watchPathIgnorePatterns: [],
191
-
192
- // Whether to use watchman for file crawling
193
- // watchman: true,
194
- }
@@ -1,5 +0,0 @@
1
- import {ImgFunction} from "../types";
2
-
3
- export interface ImageInterface {
4
- img: ImgFunction
5
- }
@@ -1,39 +0,0 @@
1
- import {get} from "../utilities/dom";
2
- import {SplashInstance} from "../Core/SplashInstance";
3
- import {ContextualAPIObject, Destination} from "../types";
4
-
5
- export class NanosplashRepository {
6
- public static destinationToNode(destination: Destination): HTMLElement
7
- {
8
- if (typeof destination === 'string') {
9
- const element = get<HTMLElement>(destination)
10
- if (!element) {
11
- throw new Error(`No match with ${destination}`)
12
- }
13
- return element
14
- } else if (destination instanceof Node) {
15
- return destination as HTMLElement
16
- }
17
- throw new Error('Destination argument must string or Node')
18
- }
19
-
20
- public static createContextualApiObject(splash: SplashInstance): ContextualAPIObject
21
- {
22
- const ctx = {
23
- getId: () => splash.getId(),
24
- remove: () => splash.delete(),
25
- moveTo: (selector: string) => splash.moveTo(selector),
26
- getText: () => splash.getText(),
27
- setText: (text: string) => splash.setText(text),
28
- getImgSrc: () => splash.getImgSrc(),
29
- setImgSrc: (src?: string) => splash.setImgSrc(src)
30
- }
31
- return {
32
- ...ctx,
33
- inside: (selector: string) => {
34
- splash.moveTo(selector)
35
- return ctx
36
- },
37
- }
38
- }
39
- }
@@ -1,26 +0,0 @@
1
- import {HTMLElementTag} from "../types";
2
-
3
- export function get<T>(selector: string): HTMLElement | T | null {
4
- return document.querySelector(selector) as HTMLElement | T | null
5
- }
6
-
7
- export function move(source: Node, destination: Node, asFirstChild: boolean = false): void
8
- {
9
- if (source && destination) {
10
- (destination.hasChildNodes() && asFirstChild)
11
- ? destination.insertBefore(source, destination.firstChild)
12
- : destination.appendChild(source)
13
- }
14
- }
15
-
16
- export const mk = (tag: HTMLElementTag) => document.createElement(tag)
17
-
18
- export function addClass(node: HTMLElement, ...classes: string[]): void
19
- {
20
- node.classList.add(...classes)
21
- }
22
-
23
- export function setAttr(node: HTMLElement, attribute: string, value: string): void
24
- {
25
- node.setAttribute(attribute, value)
26
- }