nanosplash 2.2.4 → 2.3.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.
Files changed (53) hide show
  1. package/.github/workflows/production.yml +57 -0
  2. package/.github/workflows/release.yml +61 -0
  3. package/README.md +17 -15
  4. package/dist/iife/nanosplash.iife.js +1 -1
  5. package/dist/module/Nanosplash.css +1 -0
  6. package/dist/module/manifest.json +6 -3
  7. package/dist/module/nanosplash.cjs.js +1 -1
  8. package/dist/module/nanosplash.es.js +244 -330
  9. package/docs/index.html +54 -430
  10. package/docs/nanosplash.iife.js +1 -1
  11. package/docs/style.css +1 -1
  12. package/docs/typedoc/assets/highlight.css +1 -50
  13. package/docs/typedoc/assets/main.js +2 -2
  14. package/docs/typedoc/assets/search.js +1 -1
  15. package/docs/typedoc/assets/style.css +32 -2
  16. package/docs/typedoc/classes/Core_Nanosplash.Nanosplash.html +1 -0
  17. package/docs/typedoc/index.html +1 -1
  18. package/docs/typedoc/modules/Core_Nanosplash.html +1 -0
  19. package/docs/typedoc/modules/types.html +1 -1
  20. package/index.html +51 -412
  21. package/jest.config.ts +194 -0
  22. package/package.json +70 -65
  23. package/src/Core/Nanosplash.ts +74 -0
  24. package/src/Core/SplashInstance.ts +154 -0
  25. package/src/Factory/NanosplashFactory.ts +73 -0
  26. package/src/Interfaces/ContextualAPIInterface.ts +8 -0
  27. package/src/Interfaces/IdentityInterface.ts +3 -0
  28. package/src/Interfaces/ImageInterface.ts +5 -0
  29. package/src/Interfaces/InsideInterface.ts +5 -0
  30. package/src/Interfaces/NanosplashInterface.ts +4 -0
  31. package/src/Interfaces/ProgressInterface.ts +5 -0
  32. package/src/Interfaces/ShowInterface.ts +5 -0
  33. package/src/Interfaces/WhileInterface.ts +5 -0
  34. package/src/main.ts +2 -6
  35. package/src/repositories/NanosplashRepository.ts +34 -55
  36. package/src/style.sass +51 -61
  37. package/src/types.d.ts +45 -200
  38. package/src/utilities/dom.spec.ts +70 -0
  39. package/src/utilities/dom.ts +17 -256
  40. package/update-all.sh +3 -0
  41. package/vite.iife.config.js +46 -18
  42. package/vite.mod.config.js +48 -12
  43. package/vite.site.config.js +0 -3
  44. package/dist/module/style.css +0 -1
  45. package/docs/typedoc/classes/Nanosplash.Nanosplash-1.html +0 -56
  46. package/docs/typedoc/classes/types.Nanosplash.html +0 -56
  47. package/docs/typedoc/modules/Nanosplash.html +0 -1
  48. package/src/Exceptions/Exception.ts +0 -12
  49. package/src/Exceptions/IllegalArgumentException.ts +0 -9
  50. package/src/Exceptions/InvalidDestinationException.ts +0 -9
  51. package/src/Exceptions/MissingResourceException.ts +0 -9
  52. package/src/Nanosplash.ts +0 -484
  53. package/update-latest.sh +0 -21
package/package.json CHANGED
@@ -1,68 +1,73 @@
1
1
  {
2
- "name": "nanosplash",
3
- "description": "The simple, 2KB loading screen",
4
- "version": "2.2.4",
5
- "author": {
6
- "name": "Isak K. Hauge",
7
- "email": "isakhauge@gmail.com",
8
- "url": "https://no.linkedin.com/in/isakhauge"
9
- },
10
- "keywords": [
11
- "loading",
12
- "loader",
13
- "screen",
14
- "splash",
15
- "nano",
16
- "nanosplash",
17
- "small",
18
- "tiny",
19
- "es",
20
- "esm",
21
- "ts",
22
- "typescript",
23
- "iife",
24
- "cdn",
25
- "vite"
26
- ],
27
- "homepage": "https://isakhauge.github.io/nanosplash",
28
- "repository": {
29
- "type": "git",
30
- "url": "https://github.com/isakhauge/nanosplash.git"
31
- },
32
- "license": "MIT",
33
- "main": "./dist/module/nanosplash.es.js",
34
- "module": "./dist/module/nanosplash.es.js",
35
- "source": "./src/Nanosplash.ts",
36
- "unpkg": "./dist/iife/nanosplash.iife.js",
37
- "style": "./dist/module/style.css",
38
- "exports": {
39
- ".": {
2
+ "name": "nanosplash",
3
+ "description": "The simple, 2KB loading screen",
4
+ "version": "2.3.2",
5
+ "author": {
6
+ "name": "Isak K. Hauge",
7
+ "email": "isakhauge@gmail.com",
8
+ "url": "https://no.linkedin.com/in/isakhauge"
9
+ },
10
+ "keywords": [
11
+ "loading",
12
+ "loader",
13
+ "screen",
14
+ "splash",
15
+ "nano",
16
+ "nanosplash",
17
+ "small",
18
+ "tiny",
19
+ "es",
20
+ "esm",
21
+ "ts",
22
+ "typescript",
23
+ "iife",
24
+ "cdn",
25
+ "vite"
26
+ ],
27
+ "homepage": "https://isakhauge.github.io/nanosplash",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/isakhauge/nanosplash.git"
31
+ },
32
+ "license": "MIT",
33
+ "main": "./dist/module/nanosplash.es.js",
34
+ "module": "./dist/module/nanosplash.es.js",
35
+ "source": "./src/Nanosplash.ts",
36
+ "unpkg": "./dist/iife/nanosplash.iife.js",
37
+ "style": "./dist/module/style.css",
38
+ "exports": {
39
+ ".": {
40
40
  "import": "./dist/module/nanosplash.es.js",
41
- "require": "./dist/module/nanosplash.cjs.js",
42
- "default": "./dist/module/nanosplash.es.js"
43
- }
44
- },
45
- "types": "./src/types.d.ts",
46
- "scripts": {
47
- "dev": "vite --host",
48
- "build.iife": "vite build -c vite.iife.config.js",
49
- "build.mod": "vite build -c vite.mod.config.js",
50
- "build.site": "vite build -c vite.site.config.js",
51
- "build": "tsc && yarn build.iife && yarn build.mod && yarn build.site && yarn doc",
52
- "doc": "typedoc --readme none --excludePrivate --excludeInternal --out docs/typedoc --entryPoints src/Nanosplash.ts src/types.d.ts",
53
- "doc.watch": "yarn doc --watch",
54
- "serve": "vite preview"
55
- },
56
- "devDependencies": {
57
- "@vitejs/plugin-vue": "^1.9.2",
58
- "@vue/compiler-sfc": "^3.2.19",
59
- "autoprefixer": "^10.3.6",
60
- "cssnano": "^5.0.8",
61
- "postcss": "^8.3.8",
62
- "sass": "^1.42.1",
63
- "typedoc": "^0.22.5",
64
- "typescript": "^4.4.3",
65
- "vite": "^2.6.2",
66
- "vite-plugin-singlefile": "^0.5.1"
67
- }
41
+ "require": "./dist/module/nanosplash.cjs.js",
42
+ "default": "./dist/module/nanosplash.es.js"
43
+ }
44
+ },
45
+ "types": "./src/types.d.ts",
46
+ "scripts": {
47
+ "dev": "vite --host",
48
+ "build.iife": "vite build -c vite.iife.config.js",
49
+ "build.mod": "vite build -c vite.mod.config.js",
50
+ "build.site": "vite build -c vite.site.config.js",
51
+ "build": "tsc && yarn build.iife && yarn build.mod && yarn build.site && yarn doc",
52
+ "doc": "typedoc --readme none --excludePrivate --excludeInternal --out docs/typedoc --entryPoints src/Core/Nanosplash.ts src/types.d.ts",
53
+ "doc.watch": "yarn doc --watch",
54
+ "serve": "vite preview",
55
+ "test": "jest"
56
+ },
57
+ "devDependencies": {
58
+ "@types/jest": "^27.5.0",
59
+ "@types/jsdom": "^16.2.14",
60
+ "autoprefixer": "^10.4.7",
61
+ "cssnano": "^5.1.7",
62
+ "jest": "^28.1.0",
63
+ "jest-environment-jsdom": "^28.1.0",
64
+ "jsdom": "^19.0.0",
65
+ "postcss": "^8.4.13",
66
+ "sass": "^1.51.0",
67
+ "ts-jest": "^28.0.2",
68
+ "ts-node": "^10.7.0",
69
+ "typedoc": "^0.22.15",
70
+ "typescript": "^4.6.4",
71
+ "vite": "^2.9.8"
72
+ }
68
73
  }
@@ -0,0 +1,74 @@
1
+ import '../style.sass'
2
+ import {SplashInstance} from "./SplashInstance";
3
+ import {SplashJob, StrategyObject} from "../types";
4
+ import {ShowInterface} from "../Interfaces/ShowInterface";
5
+ import {NanosplashFactory} from "../Factory/NanosplashFactory";
6
+ import {NanosplashInterface} from "../Interfaces/NanosplashInterface";
7
+ import {ContextualAPIInterface} from "../Interfaces/ContextualAPIInterface";
8
+
9
+ export class Nanosplash implements NanosplashInterface {
10
+ public static APP_NAME = 'Nanosplash'
11
+ public readonly instances: Map<string, SplashInstance>
12
+
13
+ public constructor() {
14
+ this.instances = new Map<string, SplashInstance>()
15
+ }
16
+
17
+ public img(src: string): StrategyObject {
18
+ return NanosplashFactory.createImgFunction(this, new SplashInstance(this, '', src))(src)
19
+ }
20
+
21
+ public show(text: string): ContextualAPIInterface {
22
+ return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text))(text)
23
+ }
24
+
25
+ public progress(...jobs: SplashJob[]): ContextualAPIInterface {
26
+ return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, ''))(...jobs)
27
+ }
28
+
29
+ public while(asyncTask: Promise<any>): ShowInterface {
30
+ return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, ''))(asyncTask)
31
+ }
32
+
33
+ private fifoIterate(callback: (id: string, splashInstance: SplashInstance, i: number) => boolean): void {
34
+ let i = 0
35
+ const instanceEntries = this.instances.entries()
36
+ for (const [id, splashInstance] of instanceEntries) {
37
+ if (!callback(id, splashInstance, i++)) {
38
+ break
39
+ }
40
+ }
41
+ }
42
+
43
+ public delete(splashInstance: SplashInstance): void {
44
+ this.instances.delete(splashInstance.getId())
45
+ }
46
+
47
+ public hideAll(): void
48
+ {
49
+ this.instances.forEach(
50
+ (instance: SplashInstance) => instance.delete()
51
+ )
52
+ }
53
+
54
+ public hide(id?: string): void {
55
+ if (id) {
56
+ const splashInstance = this.instances.get(id)
57
+ if (splashInstance) {
58
+ splashInstance.delete()
59
+ } else {
60
+ throw new Error(
61
+ `Could not find element with id: ${id}`
62
+ )
63
+ }
64
+ } else {
65
+ this.fifoIterate((_: string, splashInstance: SplashInstance, i: number) => {
66
+ const remove = i === 0
67
+ if (remove) {
68
+ splashInstance.delete()
69
+ }
70
+ return remove
71
+ })
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,154 @@
1
+ import {Destination} from "../types";
2
+ import {Nanosplash} from "./Nanosplash";
3
+ import {addClass, mk, move, setAttr} from "../utilities/dom";
4
+ import {NanosplashRepository} from "../repositories/NanosplashRepository";
5
+ import {IdentityInterface} from "../Interfaces/IdentityInterface";
6
+
7
+ export class SplashInstance implements IdentityInterface {
8
+ private readonly id: string
9
+ private imgSrc: string | undefined
10
+ private readonly nsInstance: Nanosplash
11
+ private readonly nsRootElement: HTMLDivElement = mk('div') as HTMLDivElement
12
+ private readonly nsWrapperElement: HTMLDivElement = mk('div') as HTMLDivElement
13
+ private readonly nsWindowElement: HTMLDivElement = mk('div') as HTMLDivElement
14
+ private readonly nsContentElement: HTMLDivElement = mk('div') as HTMLDivElement
15
+ private readonly nsImageElement: HTMLImageElement = mk('img') as HTMLImageElement
16
+ private readonly nsTextElement: HTMLDivElement = mk('div') as HTMLDivElement
17
+
18
+ public constructor(ns: Nanosplash, text: string, imgSrc?: string) {
19
+ this.id = Math.random().toString(36).substring(2)
20
+ this.nsInstance = ns
21
+ this.nsTextElement.innerText = text
22
+
23
+ this.imgSrc = imgSrc
24
+ this.nsImageElement.src = this.imgSrc ?? ''
25
+ this.nsImageElement.alt = Nanosplash.APP_NAME
26
+
27
+ this.assembleNSComponent()
28
+ this.setImgSrc(imgSrc)
29
+ }
30
+
31
+ private assignCSSClasses(): void
32
+ {
33
+ addClass(this.nsContentElement, 'ns-container')
34
+ addClass(this.nsWrapperElement, 'ns-blur')
35
+ addClass(this.nsImageElement, 'ns-img')
36
+ addClass(this.nsTextElement, 'ns-text')
37
+ addClass(this.nsWindowElement, 'ns', 'ns-window')
38
+ addClass(this.nsRootElement, 'ns-wrapper')
39
+ }
40
+
41
+ private assembleElementStructure(): void
42
+ {
43
+ this.nsContentElement.append(this.nsImageElement, this.nsTextElement)
44
+ this.nsWindowElement.append(this.nsContentElement)
45
+ this.nsRootElement.append(this.nsWrapperElement, this.nsWindowElement)
46
+ }
47
+
48
+ private assembleNSComponent(): void {
49
+ this.nsRootElement.id = this.getId()
50
+ setAttr(this.nsRootElement, 'data-ctx', 'nanosplash')
51
+ this.assembleElementStructure()
52
+ this.assignCSSClasses()
53
+ }
54
+
55
+ public getId(): string
56
+ {
57
+ return this.id
58
+ }
59
+
60
+ public getText(): string
61
+ {
62
+ return this.nsTextElement.innerText
63
+ }
64
+
65
+ public setText(text: string): SplashInstance {
66
+ this.nsTextElement.innerText = text
67
+ return this
68
+ }
69
+
70
+ public getImgSrc(): string | undefined
71
+ {
72
+ return this.imgSrc
73
+ }
74
+
75
+ public setImgSrc(src?: string): SplashInstance
76
+ {
77
+ this.nsImageElement.src = src ?? ''
78
+ this.nsImageElement.style.display = src ? 'block' : 'none'
79
+ this.assembleElementStructure()
80
+ return this
81
+ }
82
+
83
+ private cleanup(): void
84
+ {
85
+ const currentParent = this.nsRootElement.parentElement
86
+ if (currentParent) {
87
+ this.restoreDOMStructure(currentParent)
88
+ }
89
+ }
90
+
91
+ private resetFullscreenAttributes(): void
92
+ {
93
+ setAttr(this.nsRootElement, 'style', '')
94
+ this.nsRootElement.classList.remove('ns-fs')
95
+ }
96
+
97
+ private moveWithRegularStrategy(targetNode: Node): void
98
+ {
99
+ const targetParentNode = targetNode.parentNode
100
+ if (targetParentNode) {
101
+ this.restoreDOMStructure(targetParentNode)
102
+ targetParentNode.replaceChild(this.nsRootElement, targetNode)
103
+ this.nsWrapperElement.appendChild(targetNode)
104
+ }
105
+ }
106
+
107
+ private moveWithFullscreenStrategy(): void
108
+ {
109
+ this.nsRootElement.classList.add('ns-fs')
110
+ move(this.nsRootElement, document.body, true)
111
+ }
112
+
113
+ public moveTo(destination: Destination): void
114
+ {
115
+ this.cleanup()
116
+ const targetNode = NanosplashRepository.destinationToNode(destination)
117
+ const targetIsBody = targetNode === document.body
118
+ if (targetIsBody) {
119
+ this.moveWithFullscreenStrategy()
120
+ } else {
121
+ this.resetFullscreenAttributes()
122
+ this.moveWithRegularStrategy(targetNode)
123
+ }
124
+ this.assembleNSComponent()
125
+ }
126
+
127
+ private forEachWrappedNode(callback: (node: Node) => void): void
128
+ {
129
+ Array.from(this.nsWrapperElement.childNodes).forEach(callback)
130
+ }
131
+
132
+ private restoreDOMStructure(parentNode: Node): void
133
+ {
134
+ this.forEachWrappedNode((child: Node) => parentNode.insertBefore(child, this.nsRootElement))
135
+ }
136
+
137
+ private removeElementsFromDOM(): void
138
+ {
139
+ [
140
+ this.nsTextElement,
141
+ this.nsImageElement,
142
+ this.nsContentElement,
143
+ this.nsWrapperElement,
144
+ this.nsWindowElement,
145
+ this.nsRootElement
146
+ ].forEach(v => v.remove())
147
+ }
148
+
149
+ public delete(): void {
150
+ this.cleanup()
151
+ this.removeElementsFromDOM()
152
+ this.nsInstance.delete(this)
153
+ }
154
+ }
@@ -0,0 +1,73 @@
1
+ import {ImgFunction, ProgressFunction, ShowFunction, SplashJob, WhileFunction} from "../types";
2
+ import {Nanosplash} from "../Core/Nanosplash";
3
+ import {SplashInstance} from "../Core/SplashInstance";
4
+ import {NanosplashRepository} from "../repositories/NanosplashRepository";
5
+
6
+ export class NanosplashFactory {
7
+ private static ensureInstance(
8
+ splash: SplashInstance | null,
9
+ ns: Nanosplash,
10
+ text: string,
11
+ imgSrc?: string
12
+ ): SplashInstance
13
+ {
14
+ if (!splash) {
15
+ splash = new SplashInstance(ns, text, imgSrc)
16
+ }
17
+ return splash.setText(text).setImgSrc(splash.getImgSrc() ?? imgSrc)
18
+ }
19
+
20
+ public static createImgFunction(ns: Nanosplash, splash: SplashInstance | null): ImgFunction
21
+ {
22
+ return (src: string) => {
23
+ splash = NanosplashFactory.ensureInstance(splash, ns, '', src)
24
+ return {
25
+ show: NanosplashFactory.createShowFunction(ns, splash),
26
+ progress: NanosplashFactory.createProgressFunction(ns, splash),
27
+ while: NanosplashFactory.createWhileFunction(ns, splash)
28
+ }
29
+ }
30
+ }
31
+
32
+ public static createShowFunction(ns: Nanosplash, splash: SplashInstance | null): ShowFunction
33
+ {
34
+ return (text: string) => {
35
+ splash = NanosplashFactory.ensureInstance(splash, ns, text)
36
+ ns.instances.set(splash.getId(), splash)
37
+ splash.moveTo(document.body)
38
+ return NanosplashRepository.createContextualApiObject(splash)
39
+ }
40
+ }
41
+
42
+ public static createProgressFunction(ns: Nanosplash, splash: SplashInstance | null): ProgressFunction
43
+ {
44
+ return (...jobs: SplashJob[]) => {
45
+ splash = NanosplashFactory.ensureInstance(splash, ns, '')
46
+ splash.moveTo(document.body)
47
+ ;(async () => {
48
+ for (const [_, [job, text]] of jobs.entries()) {
49
+ splash.setText(text)
50
+ await job
51
+ }
52
+ splash.delete()
53
+ })()
54
+ return NanosplashRepository.createContextualApiObject(splash)
55
+ }
56
+ }
57
+
58
+ public static createWhileFunction(ns: Nanosplash, splash: SplashInstance): WhileFunction
59
+ {
60
+ return (asyncTask: Promise<any>) => {
61
+ splash = NanosplashFactory.ensureInstance(splash, ns, '')
62
+ return {
63
+ show(text: string) {
64
+ ns.instances.set(splash.getId(), splash)
65
+ splash.moveTo(document.body)
66
+ splash.setText(text)
67
+ asyncTask.finally(() => (splash as SplashInstance).delete())
68
+ return NanosplashRepository.createContextualApiObject(splash)
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,8 @@
1
+ import {SplashInstance} from "../Core/SplashInstance";
2
+
3
+ export interface ContextualAPIInterface {
4
+ getId: () => string
5
+ remove: () => void
6
+ moveTo: (selector: string) => void,
7
+ setText: (text: string) => SplashInstance
8
+ }
@@ -0,0 +1,3 @@
1
+ export interface IdentityInterface {
2
+ getId: () => string
3
+ }
@@ -0,0 +1,5 @@
1
+ import {ImgFunction} from "../types";
2
+
3
+ export interface ImageInterface {
4
+ img: ImgFunction
5
+ }
@@ -0,0 +1,5 @@
1
+ import {ContextualAPIInterface} from "./ContextualAPIInterface";
2
+
3
+ export interface InsideInterface extends ContextualAPIInterface {
4
+ inside: (selector: string) => ContextualAPIInterface
5
+ }
@@ -0,0 +1,4 @@
1
+ import {StrategyObject} from "../types";
2
+ import {ImageInterface} from "./ImageInterface";
3
+
4
+ export interface NanosplashInterface extends StrategyObject, ImageInterface {}
@@ -0,0 +1,5 @@
1
+ import {ProgressFunction} from "../types";
2
+
3
+ export interface ProgressInterface {
4
+ progress: ProgressFunction
5
+ }
@@ -0,0 +1,5 @@
1
+ import {ShowFunction} from "../types";
2
+
3
+ export interface ShowInterface {
4
+ show: ShowFunction
5
+ }
@@ -0,0 +1,5 @@
1
+ import {WhileFunction} from "../types";
2
+
3
+ export interface WhileInterface {
4
+ while: WhileFunction
5
+ }
package/src/main.ts CHANGED
@@ -1,6 +1,2 @@
1
- import { Nanosplash } from './Nanosplash'
2
-
3
- const windowExists = window && window instanceof Window
4
- if (windowExists) {
5
- new Nanosplash().install()
6
- }
1
+ import {Nanosplash} from "./Core/Nanosplash";
2
+ window.addEventListener('load', () => window.ns = new Nanosplash())
@@ -1,59 +1,38 @@
1
- import { BlurMode, SplashAnimation } from 'nanosplash'
2
- import { create } from '../utilities/dom'
1
+ import {get} from "../utilities/dom";
2
+ import {SplashInstance} from "../Core/SplashInstance";
3
+ import {ContextualAPIObject, Destination} from "../types";
3
4
 
4
5
  export class NanosplashRepository {
5
- public static readonly DEFAULT = {
6
- DESTINATION_NODE: document.body,
7
- TEXT: 'Loading ...',
8
- TEXT_FONT: '"Arial", sans-serif',
9
- TEXT_WEIGHT: 'medium',
10
- TEXT_COLOR: '#555',
11
- TEXT_SIZE: '26px',
12
- SPLASH_WIDTH: '100px',
13
- SPLASH_HEIGHT: 'auto',
14
- SPLASH_ANIMATION: 'pulse' as SplashAnimation,
15
- BACKGROUND_COLOR: 'rgba(255, 255, 255, 0.90)',
16
- BACKGROUND_BLUR: 'light' as BlurMode,
17
- }
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
+ }
18
19
 
19
- /**
20
- * Make Main Element
21
- */
22
- public static makeMainElement(): HTMLDivElement {
23
- const mainElement = create('div', {
24
- className: 'nanosplash-container',
25
- attributes: [
26
- {
27
- key: 'data-splash-animation',
28
- value: this.DEFAULT.SPLASH_ANIMATION,
29
- },
30
- ],
31
- }) as HTMLDivElement
32
- mainElement.style.backgroundColor = this.DEFAULT.BACKGROUND_COLOR
33
- return mainElement
34
- }
35
-
36
- /**
37
- * Make Splash Element
38
- */
39
- public static makeSplashElement(): HTMLImageElement {
40
- const splashElement = create('img', {
41
- className: 'nanosplash-img',
42
- attributes: [
43
- { key: 'src', value: null },
44
- { key: 'alt', value: 'Nanosplash indicator' },
45
- ],
46
- }) as HTMLImageElement
47
- return splashElement
48
- }
49
-
50
- /**
51
- * Make Text Element
52
- */
53
- public static makeTextElement(): HTMLDivElement {
54
- return create('div', {
55
- className: 'nanosplash-text',
56
- content: this.DEFAULT.TEXT,
57
- }) as HTMLDivElement
58
- }
20
+ public static createContextualApiObject(splash: SplashInstance): ContextualAPIObject {
21
+ const ctx = {
22
+ getId: () => splash.getId(),
23
+ remove: () => splash.delete(),
24
+ moveTo: (selector: string) => splash.moveTo(selector),
25
+ getText: () => splash.getText(),
26
+ setText: (text: string) => splash.setText(text),
27
+ getImgSrc: () => splash.getImgSrc(),
28
+ setImgSrc: (src?: string) => splash.setImgSrc(src)
29
+ }
30
+ return {
31
+ ...ctx,
32
+ inside: (selector: string) => {
33
+ splash.moveTo(selector)
34
+ return ctx
35
+ },
36
+ }
37
+ }
59
38
  }