@fdm-monster/client-next 2.0.1 → 2.1.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.
package/plugins/plugin.ts DELETED
@@ -1,125 +0,0 @@
1
- import fs from "node:fs";
2
- import { resolve } from "node:path";
3
- import type { PluginOption, ResolvedConfig } from "vite";
4
-
5
- /**
6
- * A copy of the plugin vite-plugin-splash-screen
7
- * https://github.com/Temzasse/vite-plugin-splash-screen/commit/2982d266cf8a7e64b62befb187347058d72ff56a
8
- */
9
- type LoaderType = "line" | "dots" | "none";
10
-
11
- type PluginOptions = {
12
- logoSrc: string;
13
- splashBg?: string;
14
- loaderBg?: string;
15
- loaderType?: LoaderType;
16
- minDurationMs?: number;
17
- // Add this to allow specifying where the plugin assets are located
18
- pluginAssetsPath?: string;
19
- };
20
-
21
- export function splashScreen(options: PluginOptions) {
22
- if (!options.logoSrc) {
23
- throw new Error(
24
- "The `logoSrc` option is required for vite-plugin-splash-screen!"
25
- );
26
- }
27
-
28
- const {
29
- logoSrc,
30
- minDurationMs,
31
- loaderType = "line",
32
- loaderBg = "#1eb6c3",
33
- splashBg = "#ffffff",
34
- pluginAssetsPath = "src/plugins/dev-splashscreen",
35
- } = options;
36
-
37
- let config: ResolvedConfig;
38
-
39
- return {
40
- name: "vite-plugin-splash-screen",
41
- configResolved(resolvedConfig: any) {
42
- config = resolvedConfig;
43
- },
44
- transformIndexHtml(html: string) {
45
- const baseStyles = readPluginFile("styles.css", pluginAssetsPath, config.root);
46
-
47
- let loaderStyles = "";
48
-
49
- if (loaderType === "line") {
50
- loaderStyles = readPluginFile("loaders/line.css", pluginAssetsPath, config.root);
51
- } else if (loaderType === "dots") {
52
- loaderStyles = readPluginFile("loaders/dots.css", pluginAssetsPath, config.root);
53
- }
54
-
55
- const logoHtml = fs.readFileSync(
56
- resolve(config.publicDir, logoSrc),
57
- "utf8"
58
- );
59
-
60
- const splash = splashTemplate({
61
- logoHtml,
62
- loaderType,
63
- minDurationMs,
64
- pluginAssetsPath,
65
- projectRoot: config.root,
66
- });
67
-
68
- const styles = `
69
- <style id="vpss-style">
70
- ${ baseStyles.replace("/*BG_SPLASH*/", splashBg) }
71
- ${ loaderStyles.replace("/*BG_LOADER*/", loaderBg) }
72
- </style>
73
- `;
74
-
75
- return (
76
- html
77
- // Add styles to end of head
78
- .replace("</head>", `${ styles }</head>`)
79
- // Add splash screen to end of body
80
- .replace("</body>", `${ splash }</body>`)
81
- );
82
- },
83
- } satisfies PluginOption;
84
- }
85
-
86
- function splashTemplate({
87
- logoHtml,
88
- loaderType,
89
- minDurationMs,
90
- pluginAssetsPath,
91
- projectRoot,
92
- }: {
93
- logoHtml: string;
94
- loaderType: LoaderType;
95
- minDurationMs?: number;
96
- pluginAssetsPath: string;
97
- projectRoot: string;
98
- }) {
99
- let loaderHtml = "";
100
-
101
- if (loaderType === "line") {
102
- loaderHtml = readPluginFile("loaders/line.html", pluginAssetsPath, projectRoot);
103
- } else if (loaderType === "dots") {
104
- loaderHtml = readPluginFile("loaders/dots.html", pluginAssetsPath, projectRoot);
105
- }
106
-
107
- return /*html*/ `
108
- <div id="vpss">
109
- <div class="vpss-logo">${ logoHtml }</div>
110
- ${ loaderHtml }
111
- </div>
112
- <script>
113
- (function () {
114
- window.__VPSS__ = {
115
- renderedAt: new Date().getTime(),
116
- minDurationMs: ${ minDurationMs || 0 },
117
- };
118
- })();
119
- </script>
120
- `;
121
- }
122
-
123
- function readPluginFile(filePath: string, pluginAssetsPath: string, projectRoot: string) {
124
- return fs.readFileSync(resolve(projectRoot, pluginAssetsPath, filePath), "utf8");
125
- }