@tsparticles/plugin-themes 4.0.0-alpha.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.
- package/52.min.js +2 -0
- package/52.min.js.LICENSE.txt +1 -0
- package/995.min.js +2 -0
- package/995.min.js.LICENSE.txt +1 -0
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/browser/Options/Classes/Theme.js +20 -0
- package/browser/Options/Classes/ThemeDefault.js +23 -0
- package/browser/Options/Interfaces/ITheme.js +1 -0
- package/browser/Options/Interfaces/IThemeDefault.js +1 -0
- package/browser/ThemeMode.js +6 -0
- package/browser/ThemesPlugin.js +64 -0
- package/browser/ThemesPluginInstance.js +59 -0
- package/browser/index.js +7 -0
- package/browser/package.json +1 -0
- package/browser/types.js +1 -0
- package/cjs/Options/Classes/Theme.js +20 -0
- package/cjs/Options/Classes/ThemeDefault.js +23 -0
- package/cjs/Options/Interfaces/ITheme.js +1 -0
- package/cjs/Options/Interfaces/IThemeDefault.js +1 -0
- package/cjs/ThemeMode.js +6 -0
- package/cjs/ThemesPlugin.js +64 -0
- package/cjs/ThemesPluginInstance.js +59 -0
- package/cjs/index.js +7 -0
- package/cjs/package.json +1 -0
- package/cjs/types.js +1 -0
- package/dist_browser_ThemesPluginInstance_js.js +30 -0
- package/dist_browser_ThemesPlugin_js.js +60 -0
- package/esm/Options/Classes/Theme.js +20 -0
- package/esm/Options/Classes/ThemeDefault.js +23 -0
- package/esm/Options/Interfaces/ITheme.js +1 -0
- package/esm/Options/Interfaces/IThemeDefault.js +1 -0
- package/esm/ThemeMode.js +6 -0
- package/esm/ThemesPlugin.js +64 -0
- package/esm/ThemesPluginInstance.js +59 -0
- package/esm/index.js +7 -0
- package/esm/package.json +1 -0
- package/esm/types.js +1 -0
- package/package.json +95 -0
- package/report.html +40 -0
- package/tsparticles.plugin.themes.js +305 -0
- package/tsparticles.plugin.themes.min.js +2 -0
- package/tsparticles.plugin.themes.min.js.LICENSE.txt +1 -0
- package/types/Options/Classes/Theme.d.ts +10 -0
- package/types/Options/Classes/ThemeDefault.d.ts +10 -0
- package/types/Options/Interfaces/ITheme.d.ts +7 -0
- package/types/Options/Interfaces/IThemeDefault.d.ts +6 -0
- package/types/ThemeMode.d.ts +5 -0
- package/types/ThemesPlugin.d.ts +9 -0
- package/types/ThemesPluginInstance.d.ts +12 -0
- package/types/index.d.ts +2 -0
- package/types/types.d.ts +26 -0
- package/umd/Options/Classes/Theme.js +34 -0
- package/umd/Options/Classes/ThemeDefault.js +37 -0
- package/umd/Options/Interfaces/ITheme.js +12 -0
- package/umd/Options/Interfaces/IThemeDefault.js +12 -0
- package/umd/ThemeMode.js +19 -0
- package/umd/ThemesPlugin.js +112 -0
- package/umd/ThemesPluginInstance.js +73 -0
- package/umd/index.js +54 -0
- package/umd/types.js +12 -0
package/52.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 52.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_themes=this.webpackChunk_tsparticles_plugin_themes||[]).push([[52],{52(e,a,t){t.d(a,{ThemesPluginInstance:()=>n});var s=t(303);class n{constructor(e){this._handleThemeChange=e=>{const a=e,t=this._container,s=t.options,n=s.defaultThemes,h=a.matches?n.dark:n.light,i=s.themes?.find((e=>e.name===h));i?.default.auto&&t.loadTheme?.(h)},this._container=e}async init(){const e=this._container;e.themeMatchMedia=(0,s.safeMatchMedia)("(prefers-color-scheme: dark)");e.themeHandlers={themeChange:e=>{this._handleThemeChange(e)},oldThemeChange:e=>{this._handleThemeChange(e)}},e.manageMediaMatch=a=>{const t=e.themeHandlers;t&&e.themeMatchMedia&&(0,s.manageListener)(e.themeMatchMedia,"change",t.themeChange,a)},e.loadTheme=async a=>{e.destroyed||(e.currentTheme=a,await e.refresh())},await Promise.resolve()}manageListeners(e){const a=this._container;a.manageMediaMatch?.(e)}async start(){this.manageListeners(!0),await Promise.resolve()}stop(){this.manageListeners(!1)}updateActualOptions(){const e=this._container;return e.actualOptions.setTheme?.(e.currentTheme),!1}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Themes Plugin v4.0.0-alpha.4 by Matteo Bruni */
|
package/995.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 995.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_themes=this.webpackChunk_tsparticles_plugin_themes||[]).push([[995],{995(e,t,s){s.d(t,{ThemesPlugin:()=>h});var n,a=s(303);!function(e){e.any="any",e.dark="dark",e.light="light"}(n||(n={}));class i{constructor(){this.auto=!1,this.mode=n.any,this.value=!1}load(e){(0,a.isNull)(e)||(void 0!==e.auto&&(this.auto=e.auto),void 0!==e.mode&&(this.mode=e.mode),void 0!==e.value&&(this.value=e.value))}}class o{constructor(){this.name="",this.default=new i}load(e){(0,a.isNull)(e)||(void 0!==e.name&&(this.name=e.name),this.default.load(e.default),void 0!==e.options&&(this.options=(0,a.deepExtend)({},e.options)))}}class h{constructor(){this.id="theme"}async getPlugin(e){const{ThemesPluginInstance:t}=await s.e(52).then(s.bind(s,52));return new t(e)}loadOptions(e,t,s){if(!this.needsPlugin(t)&&!this.needsPlugin(s))return;const i=e=>{if(t.themes)return t.themes.find((t=>t.default.value&&t.default.mode===e))??t.themes.find((e=>e.default.value&&e.default.mode===n.any))};if(t.findDefaultTheme=i,t.setTheme=e=>{if(t.themes)if(e){const s=t.themes.find((t=>t.name===e));s&&t.load(s.options)}else{const e=(0,a.safeMatchMedia)("(prefers-color-scheme: dark)"),s=e?.matches,o=i(s?n.dark:n.light);o&&t.load(o.options)}},t.themes??=[],void 0!==s?.themes)for(const e of s.themes){if(!e)continue;const s=t.themes.find((t=>t.name===e.name));if(s)s.load(e);else{const s=new o;s.load(e),t.themes.push(s)}}t.defaultThemes.dark=i(n.dark)?.name,t.defaultThemes.light=i(n.light)?.name}needsPlugin(e){return!!e?.themes?.length}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Themes Plugin v4.0.0-alpha.4 by Matteo Bruni */
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Themes Plugin
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-themes)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-themes)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-themes) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/tsparticles/tsparticles) plugin for handling themes feature.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.plugin.themes.min.js` file will export the function to load the plugin:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadThemesPlugin;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadThemesPlugin(tsParticles);
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install @tsparticles/plugin-themes
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add @tsparticles/plugin-themes
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
|
+
const { loadThemesPlugin } = require("@tsparticles/plugin-themes");
|
|
59
|
+
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadThemesPlugin(tsParticles);
|
|
62
|
+
})();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
or
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadThemesPlugin } from "@tsparticles/plugin-themes";
|
|
70
|
+
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadThemesPlugin(tsParticles);
|
|
73
|
+
})();
|
|
74
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { deepExtend, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { ThemeDefault } from "./ThemeDefault.js";
|
|
3
|
+
export class Theme {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "";
|
|
6
|
+
this.default = new ThemeDefault();
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (isNull(data)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.name !== undefined) {
|
|
13
|
+
this.name = data.name;
|
|
14
|
+
}
|
|
15
|
+
this.default.load(data.default);
|
|
16
|
+
if (data.options !== undefined) {
|
|
17
|
+
this.options = deepExtend({}, data.options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { ThemeMode } from "../../ThemeMode.js";
|
|
3
|
+
export class ThemeDefault {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.auto = false;
|
|
6
|
+
this.mode = ThemeMode.any;
|
|
7
|
+
this.value = false;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (isNull(data)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.auto !== undefined) {
|
|
14
|
+
this.auto = data.auto;
|
|
15
|
+
}
|
|
16
|
+
if (data.mode !== undefined) {
|
|
17
|
+
this.mode = data.mode;
|
|
18
|
+
}
|
|
19
|
+
if (data.value !== undefined) {
|
|
20
|
+
this.value = data.value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { safeMatchMedia, } from "@tsparticles/engine";
|
|
2
|
+
import { Theme } from "./Options/Classes/Theme.js";
|
|
3
|
+
import { ThemeMode } from "./ThemeMode.js";
|
|
4
|
+
export class ThemesPlugin {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.id = "theme";
|
|
7
|
+
}
|
|
8
|
+
async getPlugin(container) {
|
|
9
|
+
const { ThemesPluginInstance } = await import("./ThemesPluginInstance.js");
|
|
10
|
+
return new ThemesPluginInstance(container);
|
|
11
|
+
}
|
|
12
|
+
loadOptions(_container, options, source) {
|
|
13
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const findDefaultTheme = (mode) => {
|
|
17
|
+
if (!options.themes) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
return (options.themes.find(theme => theme.default.value && theme.default.mode === mode) ??
|
|
21
|
+
options.themes.find(theme => theme.default.value && theme.default.mode === ThemeMode.any));
|
|
22
|
+
}, setTheme = (name) => {
|
|
23
|
+
if (!options.themes) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (name) {
|
|
27
|
+
const chosenTheme = options.themes.find(theme => theme.name === name);
|
|
28
|
+
if (chosenTheme) {
|
|
29
|
+
options.load(chosenTheme.options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const mediaMatch = safeMatchMedia("(prefers-color-scheme: dark)"), clientDarkMode = mediaMatch?.matches, defaultTheme = findDefaultTheme(clientDarkMode ? ThemeMode.dark : ThemeMode.light);
|
|
34
|
+
if (defaultTheme) {
|
|
35
|
+
options.load(defaultTheme.options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
options.findDefaultTheme = findDefaultTheme;
|
|
40
|
+
options.setTheme = setTheme;
|
|
41
|
+
options.themes ??= [];
|
|
42
|
+
if (source?.themes !== undefined) {
|
|
43
|
+
for (const theme of source.themes) {
|
|
44
|
+
if (!theme) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const existingTheme = options.themes.find(t => t.name === theme.name);
|
|
48
|
+
if (existingTheme) {
|
|
49
|
+
existingTheme.load(theme);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const optTheme = new Theme();
|
|
53
|
+
optTheme.load(theme);
|
|
54
|
+
options.themes.push(optTheme);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
options.defaultThemes.dark = findDefaultTheme(ThemeMode.dark)?.name;
|
|
59
|
+
options.defaultThemes.light = findDefaultTheme(ThemeMode.light)?.name;
|
|
60
|
+
}
|
|
61
|
+
needsPlugin(options) {
|
|
62
|
+
return !!options?.themes?.length;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { manageListener, safeMatchMedia } from "@tsparticles/engine";
|
|
2
|
+
export class ThemesPluginInstance {
|
|
3
|
+
constructor(container) {
|
|
4
|
+
this._handleThemeChange = (e) => {
|
|
5
|
+
const mediaEvent = e, container = this._container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes?.find(theme => theme.name === themeName);
|
|
6
|
+
if (theme?.default.auto) {
|
|
7
|
+
void container.loadTheme?.(themeName);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
this._container = container;
|
|
11
|
+
}
|
|
12
|
+
async init() {
|
|
13
|
+
const container = this._container;
|
|
14
|
+
container.themeMatchMedia = safeMatchMedia("(prefers-color-scheme: dark)");
|
|
15
|
+
const loadTheme = async (name) => {
|
|
16
|
+
if (container.destroyed) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
container.currentTheme = name;
|
|
20
|
+
await container.refresh();
|
|
21
|
+
};
|
|
22
|
+
container.themeHandlers = {
|
|
23
|
+
themeChange: (e) => {
|
|
24
|
+
this._handleThemeChange(e);
|
|
25
|
+
},
|
|
26
|
+
oldThemeChange: (e) => {
|
|
27
|
+
this._handleThemeChange(e);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
container.manageMediaMatch = (add) => {
|
|
31
|
+
const handlers = container.themeHandlers;
|
|
32
|
+
if (!handlers) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!container.themeMatchMedia) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
manageListener(container.themeMatchMedia, "change", handlers.themeChange, add);
|
|
39
|
+
};
|
|
40
|
+
container.loadTheme = loadTheme;
|
|
41
|
+
await Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
manageListeners(add) {
|
|
44
|
+
const container = this._container;
|
|
45
|
+
container.manageMediaMatch?.(add);
|
|
46
|
+
}
|
|
47
|
+
async start() {
|
|
48
|
+
this.manageListeners(true);
|
|
49
|
+
await Promise.resolve();
|
|
50
|
+
}
|
|
51
|
+
stop() {
|
|
52
|
+
this.manageListeners(false);
|
|
53
|
+
}
|
|
54
|
+
updateActualOptions() {
|
|
55
|
+
const container = this._container;
|
|
56
|
+
container.actualOptions.setTheme?.(container.currentTheme);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/browser/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { deepExtend, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { ThemeDefault } from "./ThemeDefault.js";
|
|
3
|
+
export class Theme {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "";
|
|
6
|
+
this.default = new ThemeDefault();
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (isNull(data)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.name !== undefined) {
|
|
13
|
+
this.name = data.name;
|
|
14
|
+
}
|
|
15
|
+
this.default.load(data.default);
|
|
16
|
+
if (data.options !== undefined) {
|
|
17
|
+
this.options = deepExtend({}, data.options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { ThemeMode } from "../../ThemeMode.js";
|
|
3
|
+
export class ThemeDefault {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.auto = false;
|
|
6
|
+
this.mode = ThemeMode.any;
|
|
7
|
+
this.value = false;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (isNull(data)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.auto !== undefined) {
|
|
14
|
+
this.auto = data.auto;
|
|
15
|
+
}
|
|
16
|
+
if (data.mode !== undefined) {
|
|
17
|
+
this.mode = data.mode;
|
|
18
|
+
}
|
|
19
|
+
if (data.value !== undefined) {
|
|
20
|
+
this.value = data.value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/cjs/ThemeMode.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { safeMatchMedia, } from "@tsparticles/engine";
|
|
2
|
+
import { Theme } from "./Options/Classes/Theme.js";
|
|
3
|
+
import { ThemeMode } from "./ThemeMode.js";
|
|
4
|
+
export class ThemesPlugin {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.id = "theme";
|
|
7
|
+
}
|
|
8
|
+
async getPlugin(container) {
|
|
9
|
+
const { ThemesPluginInstance } = await import("./ThemesPluginInstance.js");
|
|
10
|
+
return new ThemesPluginInstance(container);
|
|
11
|
+
}
|
|
12
|
+
loadOptions(_container, options, source) {
|
|
13
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const findDefaultTheme = (mode) => {
|
|
17
|
+
if (!options.themes) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
return (options.themes.find(theme => theme.default.value && theme.default.mode === mode) ??
|
|
21
|
+
options.themes.find(theme => theme.default.value && theme.default.mode === ThemeMode.any));
|
|
22
|
+
}, setTheme = (name) => {
|
|
23
|
+
if (!options.themes) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (name) {
|
|
27
|
+
const chosenTheme = options.themes.find(theme => theme.name === name);
|
|
28
|
+
if (chosenTheme) {
|
|
29
|
+
options.load(chosenTheme.options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const mediaMatch = safeMatchMedia("(prefers-color-scheme: dark)"), clientDarkMode = mediaMatch?.matches, defaultTheme = findDefaultTheme(clientDarkMode ? ThemeMode.dark : ThemeMode.light);
|
|
34
|
+
if (defaultTheme) {
|
|
35
|
+
options.load(defaultTheme.options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
options.findDefaultTheme = findDefaultTheme;
|
|
40
|
+
options.setTheme = setTheme;
|
|
41
|
+
options.themes ??= [];
|
|
42
|
+
if (source?.themes !== undefined) {
|
|
43
|
+
for (const theme of source.themes) {
|
|
44
|
+
if (!theme) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const existingTheme = options.themes.find(t => t.name === theme.name);
|
|
48
|
+
if (existingTheme) {
|
|
49
|
+
existingTheme.load(theme);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const optTheme = new Theme();
|
|
53
|
+
optTheme.load(theme);
|
|
54
|
+
options.themes.push(optTheme);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
options.defaultThemes.dark = findDefaultTheme(ThemeMode.dark)?.name;
|
|
59
|
+
options.defaultThemes.light = findDefaultTheme(ThemeMode.light)?.name;
|
|
60
|
+
}
|
|
61
|
+
needsPlugin(options) {
|
|
62
|
+
return !!options?.themes?.length;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { manageListener, safeMatchMedia } from "@tsparticles/engine";
|
|
2
|
+
export class ThemesPluginInstance {
|
|
3
|
+
constructor(container) {
|
|
4
|
+
this._handleThemeChange = (e) => {
|
|
5
|
+
const mediaEvent = e, container = this._container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes?.find(theme => theme.name === themeName);
|
|
6
|
+
if (theme?.default.auto) {
|
|
7
|
+
void container.loadTheme?.(themeName);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
this._container = container;
|
|
11
|
+
}
|
|
12
|
+
async init() {
|
|
13
|
+
const container = this._container;
|
|
14
|
+
container.themeMatchMedia = safeMatchMedia("(prefers-color-scheme: dark)");
|
|
15
|
+
const loadTheme = async (name) => {
|
|
16
|
+
if (container.destroyed) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
container.currentTheme = name;
|
|
20
|
+
await container.refresh();
|
|
21
|
+
};
|
|
22
|
+
container.themeHandlers = {
|
|
23
|
+
themeChange: (e) => {
|
|
24
|
+
this._handleThemeChange(e);
|
|
25
|
+
},
|
|
26
|
+
oldThemeChange: (e) => {
|
|
27
|
+
this._handleThemeChange(e);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
container.manageMediaMatch = (add) => {
|
|
31
|
+
const handlers = container.themeHandlers;
|
|
32
|
+
if (!handlers) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!container.themeMatchMedia) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
manageListener(container.themeMatchMedia, "change", handlers.themeChange, add);
|
|
39
|
+
};
|
|
40
|
+
container.loadTheme = loadTheme;
|
|
41
|
+
await Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
manageListeners(add) {
|
|
44
|
+
const container = this._container;
|
|
45
|
+
container.manageMediaMatch?.(add);
|
|
46
|
+
}
|
|
47
|
+
async start() {
|
|
48
|
+
this.manageListeners(true);
|
|
49
|
+
await Promise.resolve();
|
|
50
|
+
}
|
|
51
|
+
stop() {
|
|
52
|
+
this.manageListeners(false);
|
|
53
|
+
}
|
|
54
|
+
updateActualOptions() {
|
|
55
|
+
const container = this._container;
|
|
56
|
+
container.actualOptions.setTheme?.(container.currentTheme);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/cjs/index.js
ADDED
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/cjs/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.4
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_themes"] = this["webpackChunk_tsparticles_plugin_themes"] || []).push([["dist_browser_ThemesPluginInstance_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/ThemesPluginInstance.js"
|
|
21
|
+
/*!**********************************************!*\
|
|
22
|
+
!*** ./dist/browser/ThemesPluginInstance.js ***!
|
|
23
|
+
\**********************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ThemesPluginInstance: () => (/* binding */ ThemesPluginInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass ThemesPluginInstance {\n constructor(container) {\n this._handleThemeChange = e => {\n const mediaEvent = e,\n container = this._container,\n options = container.options,\n defaultThemes = options.defaultThemes,\n themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light,\n theme = options.themes?.find(theme => theme.name === themeName);\n if (theme?.default.auto) {\n void container.loadTheme?.(themeName);\n }\n };\n this._container = container;\n }\n async init() {\n const container = this._container;\n container.themeMatchMedia = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeMatchMedia)(\"(prefers-color-scheme: dark)\");\n const loadTheme = async name => {\n if (container.destroyed) {\n return;\n }\n container.currentTheme = name;\n await container.refresh();\n };\n container.themeHandlers = {\n themeChange: e => {\n this._handleThemeChange(e);\n },\n oldThemeChange: e => {\n this._handleThemeChange(e);\n }\n };\n container.manageMediaMatch = add => {\n const handlers = container.themeHandlers;\n if (!handlers) {\n return;\n }\n if (!container.themeMatchMedia) {\n return;\n }\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.manageListener)(container.themeMatchMedia, \"change\", handlers.themeChange, add);\n };\n container.loadTheme = loadTheme;\n await Promise.resolve();\n }\n manageListeners(add) {\n const container = this._container;\n container.manageMediaMatch?.(add);\n }\n async start() {\n this.manageListeners(true);\n await Promise.resolve();\n }\n stop() {\n this.manageListeners(false);\n }\n updateActualOptions() {\n const container = this._container;\n container.actualOptions.setTheme?.(container.currentTheme);\n return false;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-themes/./dist/browser/ThemesPluginInstance.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ }
|
|
29
|
+
|
|
30
|
+
}]);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.4
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_themes"] = this["webpackChunk_tsparticles_plugin_themes"] || []).push([["dist_browser_ThemesPlugin_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/Options/Classes/Theme.js"
|
|
21
|
+
/*!***********************************************!*\
|
|
22
|
+
!*** ./dist/browser/Options/Classes/Theme.js ***!
|
|
23
|
+
\***********************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Theme: () => (/* binding */ Theme)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _ThemeDefault_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ThemeDefault.js */ \"./dist/browser/Options/Classes/ThemeDefault.js\");\n\n\nclass Theme {\n constructor() {\n this.name = \"\";\n this.default = new _ThemeDefault_js__WEBPACK_IMPORTED_MODULE_1__.ThemeDefault();\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.name !== undefined) {\n this.name = data.name;\n }\n this.default.load(data.default);\n if (data.options !== undefined) {\n this.options = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, data.options);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-themes/./dist/browser/Options/Classes/Theme.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ },
|
|
29
|
+
|
|
30
|
+
/***/ "./dist/browser/Options/Classes/ThemeDefault.js"
|
|
31
|
+
/*!******************************************************!*\
|
|
32
|
+
!*** ./dist/browser/Options/Classes/ThemeDefault.js ***!
|
|
33
|
+
\******************************************************/
|
|
34
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
|
+
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ThemeDefault: () => (/* binding */ ThemeDefault)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _ThemeMode_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../ThemeMode.js */ \"./dist/browser/ThemeMode.js\");\n\n\nclass ThemeDefault {\n constructor() {\n this.auto = false;\n this.mode = _ThemeMode_js__WEBPACK_IMPORTED_MODULE_1__.ThemeMode.any;\n this.value = false;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.auto !== undefined) {\n this.auto = data.auto;\n }\n if (data.mode !== undefined) {\n this.mode = data.mode;\n }\n if (data.value !== undefined) {\n this.value = data.value;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-themes/./dist/browser/Options/Classes/ThemeDefault.js?\n}");
|
|
37
|
+
|
|
38
|
+
/***/ },
|
|
39
|
+
|
|
40
|
+
/***/ "./dist/browser/ThemeMode.js"
|
|
41
|
+
/*!***********************************!*\
|
|
42
|
+
!*** ./dist/browser/ThemeMode.js ***!
|
|
43
|
+
\***********************************/
|
|
44
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
45
|
+
|
|
46
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ThemeMode: () => (/* binding */ ThemeMode)\n/* harmony export */ });\nvar ThemeMode;\n(function (ThemeMode) {\n ThemeMode[\"any\"] = \"any\";\n ThemeMode[\"dark\"] = \"dark\";\n ThemeMode[\"light\"] = \"light\";\n})(ThemeMode || (ThemeMode = {}));\n\n//# sourceURL=webpack://@tsparticles/plugin-themes/./dist/browser/ThemeMode.js?\n}");
|
|
47
|
+
|
|
48
|
+
/***/ },
|
|
49
|
+
|
|
50
|
+
/***/ "./dist/browser/ThemesPlugin.js"
|
|
51
|
+
/*!**************************************!*\
|
|
52
|
+
!*** ./dist/browser/ThemesPlugin.js ***!
|
|
53
|
+
\**************************************/
|
|
54
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
55
|
+
|
|
56
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ThemesPlugin: () => (/* binding */ ThemesPlugin)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Theme_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Theme.js */ \"./dist/browser/Options/Classes/Theme.js\");\n/* harmony import */ var _ThemeMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ThemeMode.js */ \"./dist/browser/ThemeMode.js\");\n\n\n\nclass ThemesPlugin {\n constructor() {\n this.id = \"theme\";\n }\n async getPlugin(container) {\n const {\n ThemesPluginInstance\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_ThemesPluginInstance_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./ThemesPluginInstance.js */ \"./dist/browser/ThemesPluginInstance.js\"));\n return new ThemesPluginInstance(container);\n }\n loadOptions(_container, options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n const findDefaultTheme = mode => {\n if (!options.themes) {\n return;\n }\n return options.themes.find(theme => theme.default.value && theme.default.mode === mode) ?? options.themes.find(theme => theme.default.value && theme.default.mode === _ThemeMode_js__WEBPACK_IMPORTED_MODULE_2__.ThemeMode.any);\n },\n setTheme = name => {\n if (!options.themes) {\n return;\n }\n if (name) {\n const chosenTheme = options.themes.find(theme => theme.name === name);\n if (chosenTheme) {\n options.load(chosenTheme.options);\n }\n } else {\n const mediaMatch = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeMatchMedia)(\"(prefers-color-scheme: dark)\"),\n clientDarkMode = mediaMatch?.matches,\n defaultTheme = findDefaultTheme(clientDarkMode ? _ThemeMode_js__WEBPACK_IMPORTED_MODULE_2__.ThemeMode.dark : _ThemeMode_js__WEBPACK_IMPORTED_MODULE_2__.ThemeMode.light);\n if (defaultTheme) {\n options.load(defaultTheme.options);\n }\n }\n };\n options.findDefaultTheme = findDefaultTheme;\n options.setTheme = setTheme;\n options.themes ??= [];\n if (source?.themes !== undefined) {\n for (const theme of source.themes) {\n if (!theme) {\n continue;\n }\n const existingTheme = options.themes.find(t => t.name === theme.name);\n if (existingTheme) {\n existingTheme.load(theme);\n } else {\n const optTheme = new _Options_Classes_Theme_js__WEBPACK_IMPORTED_MODULE_1__.Theme();\n optTheme.load(theme);\n options.themes.push(optTheme);\n }\n }\n }\n options.defaultThemes.dark = findDefaultTheme(_ThemeMode_js__WEBPACK_IMPORTED_MODULE_2__.ThemeMode.dark)?.name;\n options.defaultThemes.light = findDefaultTheme(_ThemeMode_js__WEBPACK_IMPORTED_MODULE_2__.ThemeMode.light)?.name;\n }\n needsPlugin(options) {\n return !!options?.themes?.length;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-themes/./dist/browser/ThemesPlugin.js?\n}");
|
|
57
|
+
|
|
58
|
+
/***/ }
|
|
59
|
+
|
|
60
|
+
}]);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { deepExtend, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { ThemeDefault } from "./ThemeDefault.js";
|
|
3
|
+
export class Theme {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "";
|
|
6
|
+
this.default = new ThemeDefault();
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (isNull(data)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.name !== undefined) {
|
|
13
|
+
this.name = data.name;
|
|
14
|
+
}
|
|
15
|
+
this.default.load(data.default);
|
|
16
|
+
if (data.options !== undefined) {
|
|
17
|
+
this.options = deepExtend({}, data.options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|