@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.
Files changed (61) hide show
  1. package/52.min.js +2 -0
  2. package/52.min.js.LICENSE.txt +1 -0
  3. package/995.min.js +2 -0
  4. package/995.min.js.LICENSE.txt +1 -0
  5. package/LICENSE +21 -0
  6. package/README.md +74 -0
  7. package/browser/Options/Classes/Theme.js +20 -0
  8. package/browser/Options/Classes/ThemeDefault.js +23 -0
  9. package/browser/Options/Interfaces/ITheme.js +1 -0
  10. package/browser/Options/Interfaces/IThemeDefault.js +1 -0
  11. package/browser/ThemeMode.js +6 -0
  12. package/browser/ThemesPlugin.js +64 -0
  13. package/browser/ThemesPluginInstance.js +59 -0
  14. package/browser/index.js +7 -0
  15. package/browser/package.json +1 -0
  16. package/browser/types.js +1 -0
  17. package/cjs/Options/Classes/Theme.js +20 -0
  18. package/cjs/Options/Classes/ThemeDefault.js +23 -0
  19. package/cjs/Options/Interfaces/ITheme.js +1 -0
  20. package/cjs/Options/Interfaces/IThemeDefault.js +1 -0
  21. package/cjs/ThemeMode.js +6 -0
  22. package/cjs/ThemesPlugin.js +64 -0
  23. package/cjs/ThemesPluginInstance.js +59 -0
  24. package/cjs/index.js +7 -0
  25. package/cjs/package.json +1 -0
  26. package/cjs/types.js +1 -0
  27. package/dist_browser_ThemesPluginInstance_js.js +30 -0
  28. package/dist_browser_ThemesPlugin_js.js +60 -0
  29. package/esm/Options/Classes/Theme.js +20 -0
  30. package/esm/Options/Classes/ThemeDefault.js +23 -0
  31. package/esm/Options/Interfaces/ITheme.js +1 -0
  32. package/esm/Options/Interfaces/IThemeDefault.js +1 -0
  33. package/esm/ThemeMode.js +6 -0
  34. package/esm/ThemesPlugin.js +64 -0
  35. package/esm/ThemesPluginInstance.js +59 -0
  36. package/esm/index.js +7 -0
  37. package/esm/package.json +1 -0
  38. package/esm/types.js +1 -0
  39. package/package.json +95 -0
  40. package/report.html +40 -0
  41. package/tsparticles.plugin.themes.js +305 -0
  42. package/tsparticles.plugin.themes.min.js +2 -0
  43. package/tsparticles.plugin.themes.min.js.LICENSE.txt +1 -0
  44. package/types/Options/Classes/Theme.d.ts +10 -0
  45. package/types/Options/Classes/ThemeDefault.d.ts +10 -0
  46. package/types/Options/Interfaces/ITheme.d.ts +7 -0
  47. package/types/Options/Interfaces/IThemeDefault.d.ts +6 -0
  48. package/types/ThemeMode.d.ts +5 -0
  49. package/types/ThemesPlugin.d.ts +9 -0
  50. package/types/ThemesPluginInstance.d.ts +12 -0
  51. package/types/index.d.ts +2 -0
  52. package/types/types.d.ts +26 -0
  53. package/umd/Options/Classes/Theme.js +34 -0
  54. package/umd/Options/Classes/ThemeDefault.js +37 -0
  55. package/umd/Options/Interfaces/ITheme.js +12 -0
  56. package/umd/Options/Interfaces/IThemeDefault.js +12 -0
  57. package/umd/ThemeMode.js +19 -0
  58. package/umd/ThemesPlugin.js +112 -0
  59. package/umd/ThemesPluginInstance.js +73 -0
  60. package/umd/index.js +54 -0
  61. package/umd/types.js +12 -0
@@ -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,6 @@
1
+ export var ThemeMode;
2
+ (function (ThemeMode) {
3
+ ThemeMode["any"] = "any";
4
+ ThemeMode["dark"] = "dark";
5
+ ThemeMode["light"] = "light";
6
+ })(ThemeMode || (ThemeMode = {}));
@@ -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/esm/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export function loadThemesPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.4");
3
+ engine.register(async (e) => {
4
+ const { ThemesPlugin } = await import("./ThemesPlugin.js");
5
+ e.addPlugin(new ThemesPlugin());
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@tsparticles/plugin-themes",
3
+ "version": "4.0.0-alpha.4",
4
+ "description": "tsParticles themes plugin",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/tsparticles/tsparticles.git",
9
+ "directory": "plugins/themes"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "tsparticles-plugin"
64
+ ],
65
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
66
+ "license": "MIT",
67
+ "bugs": {
68
+ "url": "https://github.com/tsparticles/tsparticles/issues"
69
+ },
70
+ "sideEffects": false,
71
+ "jsdelivr": "tsparticles.plugin.themes.min.js",
72
+ "unpkg": "tsparticles.plugin.themes.min.js",
73
+ "browser": "browser/index.js",
74
+ "main": "cjs/index.js",
75
+ "module": "esm/index.js",
76
+ "types": "types/index.d.ts",
77
+ "exports": {
78
+ ".": {
79
+ "types": "./types/index.d.ts",
80
+ "browser": "./browser/index.js",
81
+ "import": "./esm/index.js",
82
+ "require": "./cjs/index.js",
83
+ "umd": "./umd/index.js",
84
+ "default": "./cjs/index.js"
85
+ },
86
+ "./package.json": "./package.json"
87
+ },
88
+ "dependencies": {
89
+ "@tsparticles/engine": "4.0.0-alpha.4"
90
+ },
91
+ "publishConfig": {
92
+ "access": "public"
93
+ },
94
+ "type": "module"
95
+ }