@tsparticles/plugin-themes 4.0.0-alpha.14

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 (58) hide show
  1. package/25.min.js +1 -0
  2. package/509.min.js +1 -0
  3. package/LICENSE +21 -0
  4. package/README.md +74 -0
  5. package/browser/Options/Classes/Theme.js +23 -0
  6. package/browser/Options/Classes/ThemeDefault.js +26 -0
  7. package/browser/Options/Interfaces/ITheme.js +1 -0
  8. package/browser/Options/Interfaces/IThemeDefault.js +1 -0
  9. package/browser/ThemeMode.js +6 -0
  10. package/browser/ThemesPlugin.js +62 -0
  11. package/browser/ThemesPluginInstance.js +60 -0
  12. package/browser/index.js +7 -0
  13. package/browser/package.json +1 -0
  14. package/browser/types.js +1 -0
  15. package/cjs/Options/Classes/Theme.js +23 -0
  16. package/cjs/Options/Classes/ThemeDefault.js +26 -0
  17. package/cjs/Options/Interfaces/ITheme.js +1 -0
  18. package/cjs/Options/Interfaces/IThemeDefault.js +1 -0
  19. package/cjs/ThemeMode.js +6 -0
  20. package/cjs/ThemesPlugin.js +62 -0
  21. package/cjs/ThemesPluginInstance.js +60 -0
  22. package/cjs/index.js +7 -0
  23. package/cjs/package.json +1 -0
  24. package/cjs/types.js +1 -0
  25. package/dist_browser_ThemesPluginInstance_js.js +30 -0
  26. package/dist_browser_ThemesPlugin_js.js +60 -0
  27. package/esm/Options/Classes/Theme.js +23 -0
  28. package/esm/Options/Classes/ThemeDefault.js +26 -0
  29. package/esm/Options/Interfaces/ITheme.js +1 -0
  30. package/esm/Options/Interfaces/IThemeDefault.js +1 -0
  31. package/esm/ThemeMode.js +6 -0
  32. package/esm/ThemesPlugin.js +62 -0
  33. package/esm/ThemesPluginInstance.js +60 -0
  34. package/esm/index.js +7 -0
  35. package/esm/package.json +1 -0
  36. package/esm/types.js +1 -0
  37. package/package.json +95 -0
  38. package/report.html +40 -0
  39. package/tsparticles.plugin.themes.js +317 -0
  40. package/tsparticles.plugin.themes.min.js +2 -0
  41. package/types/Options/Classes/Theme.d.ts +10 -0
  42. package/types/Options/Classes/ThemeDefault.d.ts +10 -0
  43. package/types/Options/Interfaces/ITheme.d.ts +7 -0
  44. package/types/Options/Interfaces/IThemeDefault.d.ts +6 -0
  45. package/types/ThemeMode.d.ts +5 -0
  46. package/types/ThemesPlugin.d.ts +8 -0
  47. package/types/ThemesPluginInstance.d.ts +12 -0
  48. package/types/index.d.ts +2 -0
  49. package/types/types.d.ts +26 -0
  50. package/umd/Options/Classes/Theme.js +37 -0
  51. package/umd/Options/Classes/ThemeDefault.js +40 -0
  52. package/umd/Options/Interfaces/ITheme.js +12 -0
  53. package/umd/Options/Interfaces/IThemeDefault.js +12 -0
  54. package/umd/ThemeMode.js +19 -0
  55. package/umd/ThemesPlugin.js +110 -0
  56. package/umd/ThemesPluginInstance.js +74 -0
  57. package/umd/index.js +54 -0
  58. package/umd/types.js +12 -0
@@ -0,0 +1,26 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { ThemeMode } from "../../ThemeMode.js";
3
+ export class ThemeDefault {
4
+ auto;
5
+ mode;
6
+ value;
7
+ constructor() {
8
+ this.auto = false;
9
+ this.mode = ThemeMode.any;
10
+ this.value = false;
11
+ }
12
+ load(data) {
13
+ if (isNull(data)) {
14
+ return;
15
+ }
16
+ if (data.auto !== undefined) {
17
+ this.auto = data.auto;
18
+ }
19
+ if (data.mode !== undefined) {
20
+ this.mode = data.mode;
21
+ }
22
+ if (data.value !== undefined) {
23
+ this.value = data.value;
24
+ }
25
+ }
26
+ }
@@ -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,62 @@
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
+ id = "theme";
6
+ async getPlugin(container) {
7
+ const { ThemesPluginInstance } = await import("./ThemesPluginInstance.js");
8
+ return new ThemesPluginInstance(container);
9
+ }
10
+ loadOptions(_container, options, source) {
11
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
12
+ return;
13
+ }
14
+ const findDefaultTheme = (mode) => {
15
+ if (!options.themes) {
16
+ return;
17
+ }
18
+ return (options.themes.find(theme => theme.default.value && theme.default.mode === mode) ??
19
+ options.themes.find(theme => theme.default.value && theme.default.mode === ThemeMode.any));
20
+ }, setTheme = (name) => {
21
+ if (!options.themes) {
22
+ return;
23
+ }
24
+ if (name) {
25
+ const chosenTheme = options.themes.find(theme => theme.name === name);
26
+ if (chosenTheme) {
27
+ options.load(chosenTheme.options);
28
+ }
29
+ }
30
+ else {
31
+ const mediaMatch = safeMatchMedia("(prefers-color-scheme: dark)"), clientDarkMode = mediaMatch?.matches, defaultTheme = findDefaultTheme(clientDarkMode ? ThemeMode.dark : ThemeMode.light);
32
+ if (defaultTheme) {
33
+ options.load(defaultTheme.options);
34
+ }
35
+ }
36
+ };
37
+ options.findDefaultTheme = findDefaultTheme;
38
+ options.setTheme = setTheme;
39
+ options.themes ??= [];
40
+ if (source?.themes !== undefined) {
41
+ for (const theme of source.themes) {
42
+ if (!theme) {
43
+ continue;
44
+ }
45
+ const existingTheme = options.themes.find(t => t.name === theme.name);
46
+ if (existingTheme) {
47
+ existingTheme.load(theme);
48
+ }
49
+ else {
50
+ const optTheme = new Theme();
51
+ optTheme.load(theme);
52
+ options.themes.push(optTheme);
53
+ }
54
+ }
55
+ }
56
+ options.defaultThemes.dark = findDefaultTheme(ThemeMode.dark)?.name;
57
+ options.defaultThemes.light = findDefaultTheme(ThemeMode.light)?.name;
58
+ }
59
+ needsPlugin(options) {
60
+ return !!options?.themes?.length;
61
+ }
62
+ }
@@ -0,0 +1,60 @@
1
+ import { manageListener, safeMatchMedia } from "@tsparticles/engine";
2
+ export class ThemesPluginInstance {
3
+ _container;
4
+ constructor(container) {
5
+ this._container = container;
6
+ }
7
+ async init() {
8
+ const container = this._container;
9
+ container.themeMatchMedia = safeMatchMedia("(prefers-color-scheme: dark)");
10
+ const loadTheme = async (name) => {
11
+ if (container.destroyed) {
12
+ return;
13
+ }
14
+ container.currentTheme = name;
15
+ await container.refresh();
16
+ };
17
+ container.themeHandlers = {
18
+ themeChange: (e) => {
19
+ this._handleThemeChange(e);
20
+ },
21
+ oldThemeChange: (e) => {
22
+ this._handleThemeChange(e);
23
+ },
24
+ };
25
+ container.manageMediaMatch = (add) => {
26
+ const handlers = container.themeHandlers;
27
+ if (!handlers) {
28
+ return;
29
+ }
30
+ if (!container.themeMatchMedia) {
31
+ return;
32
+ }
33
+ manageListener(container.themeMatchMedia, "change", handlers.themeChange, add);
34
+ };
35
+ container.loadTheme = loadTheme;
36
+ await Promise.resolve();
37
+ }
38
+ manageListeners(add) {
39
+ const container = this._container;
40
+ container.manageMediaMatch?.(add);
41
+ }
42
+ async start() {
43
+ this.manageListeners(true);
44
+ await Promise.resolve();
45
+ }
46
+ stop() {
47
+ this.manageListeners(false);
48
+ }
49
+ updateActualOptions() {
50
+ const container = this._container;
51
+ container.actualOptions.setTheme?.(container.currentTheme);
52
+ return false;
53
+ }
54
+ _handleThemeChange = (e) => {
55
+ 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);
56
+ if (theme?.default.auto) {
57
+ void container.loadTheme?.(themeName);
58
+ }
59
+ };
60
+ }
package/esm/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export async function loadThemesPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.14");
3
+ await 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.14",
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.14"
90
+ },
91
+ "publishConfig": {
92
+ "access": "public"
93
+ },
94
+ "type": "module"
95
+ }