vite-plugin-refresh-guard 0.1.1 → 0.1.3
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/CHANGELOG.md +15 -0
- package/README.en.md +45 -2
- package/README.md +43 -2
- package/dist/react/UpdatePrompt.d.ts +8 -1
- package/dist/react/UpdatePrompt.js +27 -20
- package/dist/vue/UpdatePrompt.vue +42 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v0.1.3 (2026-08-09)
|
|
4
|
+
|
|
5
|
+
`UpdatePrompt` 默认样式全部改成 `var(--rg-*, 默认值)` 的写法,颜色/圆角都能被外部 CSS 变量覆盖,不用改包源码就能换成自己的品牌色(README 新增"样式定制"一节说明全部变量)。默认样式本身也精修了一版(更大的圆角、更细腻的阴影分层、按钮 hover/active 反馈、标题加了个 ✨),不设置任何变量也比之前顺眼。
|
|
6
|
+
|
|
7
|
+
## v0.1.2 (2026-08-09)
|
|
8
|
+
|
|
9
|
+
修 `UpdatePrompt` 两个实测踩到的问题(在一个真实项目里第一次接入后暴露的):
|
|
10
|
+
|
|
11
|
+
- **弹窗只显示 git hash,看不出更新了什么**:`modal-blocking` 弹窗现在建议配合 `changelog-html`
|
|
12
|
+
prop 传入 `virtual:refresh-guard-changelog` 的内容——之前这个 prop 就存在但接入时容易漏传,
|
|
13
|
+
这版把它在 README/SKILL.md 里的位置提得更显眼。
|
|
14
|
+
- **弹窗颜色跟着访问者系统的深色模式走,不跟着网站自己的主题开关走**:Vue/React 版都加了 `dark`
|
|
15
|
+
prop,显式传入你自己的主题状态(如 `isDark.value`)就能让弹窗配色跟着网站自己的主题走,不传
|
|
16
|
+
则维持原来的 `prefers-color-scheme` 兜底行为。
|
|
17
|
+
|
|
3
18
|
## v0.1.1 (2026-08-09)
|
|
4
19
|
|
|
5
20
|
- README 改为中文正文 + 英文版(`README.en.md`),CHANGELOG/package.json 描述同步改中文为主
|
package/README.en.md
CHANGED
|
@@ -52,6 +52,8 @@ This does two things at build time:
|
|
|
52
52
|
<script setup lang="ts">
|
|
53
53
|
import { useVersionCheck } from 'vite-plugin-refresh-guard/vue'
|
|
54
54
|
import UpdatePrompt from 'vite-plugin-refresh-guard/vue/UpdatePrompt.vue'
|
|
55
|
+
import { latestContent } from 'virtual:refresh-guard-changelog'
|
|
56
|
+
// import { isDark } from './your-theme-state' — pass this too if your site has a theme toggle
|
|
55
57
|
|
|
56
58
|
const { hasUpdate, latestInfo, applyUpdate, mode } = useVersionCheck(__REFRESH_GUARD_VERSION__, {
|
|
57
59
|
mode: 'toast-auto', // 'silent' | 'toast-auto' | 'modal-blocking'
|
|
@@ -59,21 +61,39 @@ const { hasUpdate, latestInfo, applyUpdate, mode } = useVersionCheck(__REFRESH_G
|
|
|
59
61
|
</script>
|
|
60
62
|
|
|
61
63
|
<template>
|
|
62
|
-
<UpdatePrompt
|
|
64
|
+
<UpdatePrompt
|
|
65
|
+
:visible="hasUpdate" :mode="mode" :version="latestInfo?.version"
|
|
66
|
+
:changelog-html="latestContent"
|
|
67
|
+
@refresh="applyUpdate"
|
|
68
|
+
/>
|
|
63
69
|
</template>
|
|
64
70
|
```
|
|
65
71
|
|
|
72
|
+
> Don't skip `:changelog-html` — without it, the `modal-blocking` prompt only shows a git hash and
|
|
73
|
+
> the user has no idea what actually changed. If your site has a dark mode, pass your theme state
|
|
74
|
+
> to `:dark` (e.g. `:dark="isDark"`) so the modal follows your site's own theme — otherwise it only
|
|
75
|
+
> follows the visitor's OS dark-mode setting, which can look broken (a light site with a dark modal).
|
|
76
|
+
|
|
66
77
|
**React**
|
|
67
78
|
|
|
68
79
|
```tsx
|
|
69
80
|
import { useVersionCheck } from 'vite-plugin-refresh-guard/react'
|
|
70
81
|
import { UpdatePrompt } from 'vite-plugin-refresh-guard/react/UpdatePrompt'
|
|
82
|
+
// import { latestContent } from 'virtual:refresh-guard-changelog' — wire this up however your React setup handles virtual modules
|
|
71
83
|
|
|
72
84
|
function App() {
|
|
73
85
|
const { hasUpdate, latestInfo, applyUpdate, mode } = useVersionCheck(__REFRESH_GUARD_VERSION__, {
|
|
74
86
|
mode: 'modal-blocking',
|
|
75
87
|
})
|
|
76
|
-
return
|
|
88
|
+
return (
|
|
89
|
+
<UpdatePrompt
|
|
90
|
+
visible={hasUpdate} mode={mode} version={latestInfo?.version}
|
|
91
|
+
changelogHtml={latestContent}
|
|
92
|
+
dark={isDarkMode /* pass your own theme state; omitting it always renders light */}
|
|
93
|
+
onRefresh={applyUpdate}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
77
97
|
}
|
|
78
98
|
```
|
|
79
99
|
|
|
@@ -137,6 +157,29 @@ deciding "when do we reload" are different product decisions, and coupling them
|
|
|
137
157
|
of the projects this package was extracted from originally did) is how you end up with two
|
|
138
158
|
mechanisms fighting each other.
|
|
139
159
|
|
|
160
|
+
## Styling
|
|
161
|
+
|
|
162
|
+
`UpdatePrompt` ships with a generic blue-on-white look and doesn't assume your brand colors. Every color/radius reads a `--rg-*` CSS custom property first, falling back to a default — set these anywhere in your own global styles (`:root` or any ancestor) to make the modal match your product without touching the package source:
|
|
163
|
+
|
|
164
|
+
```css
|
|
165
|
+
:root {
|
|
166
|
+
--rg-accent: var(--brand); /* primary button color, default #2563eb */
|
|
167
|
+
--rg-accent-fg: #fff; /* primary button text color */
|
|
168
|
+
--rg-radius: 16px; /* modal/toast corner radius */
|
|
169
|
+
--rg-modal-bg: #fff; /* modal background (light) */
|
|
170
|
+
--rg-modal-fg: #111827; /* modal text (light) */
|
|
171
|
+
--rg-modal-bg-dark: #1f2937; /* modal background (dark, paired with :dark or OS dark mode) */
|
|
172
|
+
--rg-modal-fg-dark: #f3f4f6;
|
|
173
|
+
--rg-body-fg: #4b5563; /* body text color */
|
|
174
|
+
--rg-body-fg-dark: #d1d5db;
|
|
175
|
+
--rg-overlay-bg: rgba(15, 15, 20, 0.55); /* backdrop behind the modal */
|
|
176
|
+
--rg-toast-bg: #1f2937; /* toast-auto mode's notice bar */
|
|
177
|
+
--rg-toast-fg: #fff;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
You don't need to set all of them — override just `--rg-accent` for a quick brand match and leave the rest at their defaults.
|
|
182
|
+
|
|
140
183
|
## Why not just service workers?
|
|
141
184
|
|
|
142
185
|
`vite-plugin-pwa`'s `autoUpdate` mode is a perfectly good `silent` implementation if you're
|
package/README.md
CHANGED
|
@@ -50,6 +50,8 @@ export default defineConfig({
|
|
|
50
50
|
<script setup lang="ts">
|
|
51
51
|
import { useVersionCheck } from 'vite-plugin-refresh-guard/vue'
|
|
52
52
|
import UpdatePrompt from 'vite-plugin-refresh-guard/vue/UpdatePrompt.vue'
|
|
53
|
+
import { latestContent } from 'virtual:refresh-guard-changelog'
|
|
54
|
+
// import { isDark } from './your-theme-state' —— 有主题切换的话把这个也传进去
|
|
53
55
|
|
|
54
56
|
const { hasUpdate, latestInfo, applyUpdate, mode } = useVersionCheck(__REFRESH_GUARD_VERSION__, {
|
|
55
57
|
mode: 'toast-auto', // 'silent' | 'toast-auto' | 'modal-blocking'
|
|
@@ -57,21 +59,37 @@ const { hasUpdate, latestInfo, applyUpdate, mode } = useVersionCheck(__REFRESH_G
|
|
|
57
59
|
</script>
|
|
58
60
|
|
|
59
61
|
<template>
|
|
60
|
-
<UpdatePrompt
|
|
62
|
+
<UpdatePrompt
|
|
63
|
+
:visible="hasUpdate" :mode="mode" :version="latestInfo?.version"
|
|
64
|
+
:changelog-html="latestContent"
|
|
65
|
+
@refresh="applyUpdate"
|
|
66
|
+
/>
|
|
61
67
|
</template>
|
|
62
68
|
```
|
|
63
69
|
|
|
70
|
+
> `:changelog-html` 别漏了——不传的话 `modal-blocking` 弹窗只会显示一个 git hash,用户不知道更新了什么。
|
|
71
|
+
> 站点自己有深色模式的话,把主题状态传给 `:dark`(比如 `:dark="isDark"`),弹窗才会跟着网站主题走,
|
|
72
|
+
> 不然默认只跟着访问者系统的深色模式走,容易出现"网站是浅色、弹窗却是暗的"这种违和场面。
|
|
73
|
+
|
|
64
74
|
**React**
|
|
65
75
|
|
|
66
76
|
```tsx
|
|
67
77
|
import { useVersionCheck } from 'vite-plugin-refresh-guard/react'
|
|
68
78
|
import { UpdatePrompt } from 'vite-plugin-refresh-guard/react/UpdatePrompt'
|
|
79
|
+
// import { latestContent } from 'virtual:refresh-guard-changelog' —— React 项目按各自 loader 处理虚拟模块的方式引入
|
|
69
80
|
|
|
70
81
|
function App() {
|
|
71
82
|
const { hasUpdate, latestInfo, applyUpdate, mode } = useVersionCheck(__REFRESH_GUARD_VERSION__, {
|
|
72
83
|
mode: 'modal-blocking',
|
|
73
84
|
})
|
|
74
|
-
return
|
|
85
|
+
return (
|
|
86
|
+
<UpdatePrompt
|
|
87
|
+
visible={hasUpdate} mode={mode} version={latestInfo?.version}
|
|
88
|
+
changelogHtml={latestContent}
|
|
89
|
+
dark={isDarkMode /* 传你自己的主题状态,不传则始终按浅色渲染 */}
|
|
90
|
+
onRefresh={applyUpdate}
|
|
91
|
+
/>
|
|
92
|
+
)
|
|
75
93
|
}
|
|
76
94
|
```
|
|
77
95
|
|
|
@@ -128,6 +146,29 @@ import { latestVersion, latestContent } from 'virtual:refresh-guard-changelog'
|
|
|
128
146
|
|
|
129
147
|
从你的 `CHANGELOG.md` 里解析 `## vX.Y.Z (date)` 这种格式的标题(跟 Keep a Changelog 及大多数自动生成的更新日志一致),暴露最新一条的版本号和 markdown 正文。这个功能故意跟"什么时候刷新"的逻辑解耦——"展示更新了什么"和"什么时候该刷新"是两个不同的产品决策,本包最初就是从几个把这两件事强行绑死在一起的项目里抽出来的,绑死的下场就是两套机制互相打架。
|
|
130
148
|
|
|
149
|
+
## 样式定制
|
|
150
|
+
|
|
151
|
+
`UpdatePrompt` 默认是通用蓝白配色,不假设你的品牌色。所有颜色/圆角都先读一个 `--rg-*` CSS 变量,读不到才用默认值——在你自己项目的全局样式里(`:root` 或任意祖先节点)设置这些变量,就能让弹窗跟你的产品长一个样,不用改包的源码:
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
:root {
|
|
155
|
+
--rg-accent: var(--brand); /* 主按钮颜色,默认 #2563eb */
|
|
156
|
+
--rg-accent-fg: #fff; /* 主按钮文字颜色 */
|
|
157
|
+
--rg-radius: 16px; /* 弹窗/toast 圆角 */
|
|
158
|
+
--rg-modal-bg: #fff; /* 弹窗背景(浅色) */
|
|
159
|
+
--rg-modal-fg: #111827; /* 弹窗文字(浅色) */
|
|
160
|
+
--rg-modal-bg-dark: #1f2937; /* 弹窗背景(深色,配合 :dark 或系统深色模式) */
|
|
161
|
+
--rg-modal-fg-dark: #f3f4f6;
|
|
162
|
+
--rg-body-fg: #4b5563; /* 正文文字颜色 */
|
|
163
|
+
--rg-body-fg-dark: #d1d5db;
|
|
164
|
+
--rg-overlay-bg: rgba(15, 15, 20, 0.55); /* 弹窗背后的遮罩 */
|
|
165
|
+
--rg-toast-bg: #1f2937; /* toast-auto 模式的提示条 */
|
|
166
|
+
--rg-toast-fg: #fff;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
不需要全套都设,只想换主按钮颜色就只设 `--rg-accent` 即可,其余保持默认。
|
|
171
|
+
|
|
131
172
|
## 为什么不干脆只用 service worker
|
|
132
173
|
|
|
133
174
|
如果你已经在跑 service worker,`vite-plugin-pwa` 的 `autoUpdate` 模式本身就是一个很好的 `silent` 实现——本包不是要替代它。本包补的是:一套统一的方式,能拿到 `toast-auto` 或 `modal-blocking` 的体验(裸 service worker 想要这个得自己手写这整套管线);一个不需要 service worker 的、纯靠轮询 `version.json` 的兜底方案;以及独立的更新日志展示层。哪块需要用哪块,互相不绑定。
|
|
@@ -8,8 +8,15 @@ interface UpdatePromptProps {
|
|
|
8
8
|
version?: string | null;
|
|
9
9
|
/** Optional: e.g. `latestContent` from `virtual:refresh-guard-changelog`, rendered via dangerouslySetInnerHTML — pre-sanitize if it isn't your own trusted file. */
|
|
10
10
|
changelogHtml?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Explicitly light/dark instead of always rendering light. Pass your app's own theme state
|
|
13
|
+
* here (e.g. a `useDarkMode()` hook's value) so this modal matches your site's actual theme
|
|
14
|
+
* toggle. Inline styles can't follow the OS `prefers-color-scheme` on their own, so leaving
|
|
15
|
+
* this unset always renders light — pass it explicitly if your app supports dark mode.
|
|
16
|
+
*/
|
|
17
|
+
dark?: boolean;
|
|
11
18
|
onRefresh: () => void;
|
|
12
19
|
}
|
|
13
|
-
declare function UpdatePrompt({ visible, mode, version, changelogHtml, onRefresh }: UpdatePromptProps): react.ReactPortal | null;
|
|
20
|
+
declare function UpdatePrompt({ visible, mode, version, changelogHtml, dark, onRefresh }: UpdatePromptProps): react.ReactPortal | null;
|
|
14
21
|
|
|
15
22
|
export { UpdatePrompt, type UpdatePromptProps };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/react/UpdatePrompt.tsx
|
|
2
2
|
import { createPortal } from "react-dom";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
function UpdatePrompt({ visible, mode = "toast-auto", version = null, changelogHtml = "", onRefresh }) {
|
|
4
|
+
function UpdatePrompt({ visible, mode = "toast-auto", version = null, changelogHtml = "", dark = false, onRefresh }) {
|
|
5
5
|
if (!visible || mode === "silent" || typeof document === "undefined") return null;
|
|
6
6
|
if (mode === "toast-auto") {
|
|
7
7
|
return createPortal(
|
|
@@ -16,13 +16,15 @@ function UpdatePrompt({ visible, mode = "toast-auto", version = null, changelogH
|
|
|
16
16
|
document.body
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
+
const modalStyle = dark ? { ...styles.modal, ...styles.modalDark } : styles.modal;
|
|
20
|
+
const bodyStyle = dark ? { ...styles.body, ...styles.bodyDark } : styles.body;
|
|
19
21
|
return createPortal(
|
|
20
|
-
/* @__PURE__ */ jsx("div", { style: styles.overlay, role: "alertdialog", "aria-modal": "true", children: /* @__PURE__ */ jsxs("div", { style:
|
|
22
|
+
/* @__PURE__ */ jsx("div", { style: styles.overlay, role: "alertdialog", "aria-modal": "true", children: /* @__PURE__ */ jsxs("div", { style: modalStyle, children: [
|
|
21
23
|
/* @__PURE__ */ jsxs("h3", { style: styles.title, children: [
|
|
22
|
-
"\u6709\u65B0\u7248\u672C\u53EF\u7528",
|
|
24
|
+
"\u2728 \u6709\u65B0\u7248\u672C\u53EF\u7528",
|
|
23
25
|
version ? `\uFF1A${version}` : ""
|
|
24
26
|
] }),
|
|
25
|
-
changelogHtml ? /* @__PURE__ */ jsx("div", { style:
|
|
27
|
+
changelogHtml ? /* @__PURE__ */ jsx("div", { style: bodyStyle, dangerouslySetInnerHTML: { __html: changelogHtml } }) : /* @__PURE__ */ jsx("p", { style: { ...bodyStyle, color: dark ? "var(--rg-body-fg-dark, #9ca3af)" : "var(--rg-body-fg, #6b7280)" }, children: "\u5237\u65B0\u9875\u9762\u5373\u53EF\u4F7F\u7528\u6700\u65B0\u7248\u672C\u3002" }),
|
|
26
28
|
/* @__PURE__ */ jsx("button", { type: "button", style: styles.primaryBtn, onClick: onRefresh, children: "\u7ACB\u5373\u66F4\u65B0" })
|
|
27
29
|
] }) }),
|
|
28
30
|
document.body
|
|
@@ -38,9 +40,9 @@ var styles = {
|
|
|
38
40
|
alignItems: "center",
|
|
39
41
|
gap: 12,
|
|
40
42
|
padding: "10px 16px",
|
|
41
|
-
borderRadius:
|
|
42
|
-
background: "#1f2937",
|
|
43
|
-
color: "#fff",
|
|
43
|
+
borderRadius: "var(--rg-radius, 10px)",
|
|
44
|
+
background: "var(--rg-toast-bg, #1f2937)",
|
|
45
|
+
color: "var(--rg-toast-fg, #fff)",
|
|
44
46
|
fontSize: 13,
|
|
45
47
|
boxShadow: "0 4px 16px rgba(0,0,0,0.2)"
|
|
46
48
|
},
|
|
@@ -50,7 +52,7 @@ var styles = {
|
|
|
50
52
|
borderRadius: 6,
|
|
51
53
|
border: "1px solid rgba(255,255,255,0.3)",
|
|
52
54
|
background: "transparent",
|
|
53
|
-
color: "
|
|
55
|
+
color: "inherit",
|
|
54
56
|
fontSize: 12,
|
|
55
57
|
cursor: "pointer"
|
|
56
58
|
},
|
|
@@ -61,26 +63,31 @@ var styles = {
|
|
|
61
63
|
display: "flex",
|
|
62
64
|
alignItems: "center",
|
|
63
65
|
justifyContent: "center",
|
|
64
|
-
background: "rgba(
|
|
66
|
+
background: "var(--rg-overlay-bg, rgba(15,15,20,0.55))"
|
|
65
67
|
},
|
|
66
68
|
modal: {
|
|
67
69
|
width: "90vw",
|
|
68
70
|
maxWidth: 420,
|
|
69
|
-
padding:
|
|
70
|
-
borderRadius:
|
|
71
|
-
background: "#fff",
|
|
72
|
-
color: "#111827",
|
|
73
|
-
boxShadow: "0
|
|
71
|
+
padding: 28,
|
|
72
|
+
borderRadius: "var(--rg-radius, 16px)",
|
|
73
|
+
background: "var(--rg-modal-bg, #fff)",
|
|
74
|
+
color: "var(--rg-modal-fg, #111827)",
|
|
75
|
+
boxShadow: "0 20px 50px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.08)"
|
|
74
76
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
modalDark: {
|
|
78
|
+
background: "var(--rg-modal-bg-dark, #1f2937)",
|
|
79
|
+
color: "var(--rg-modal-fg-dark, #f3f4f6)"
|
|
80
|
+
},
|
|
81
|
+
title: { margin: "0 0 14px", fontSize: 17, fontWeight: 700, letterSpacing: "-0.01em" },
|
|
82
|
+
body: { margin: "0 0 22px", fontSize: 13.5, lineHeight: 1.7, color: "var(--rg-body-fg, #4b5563)", maxHeight: "40vh", overflowY: "auto" },
|
|
83
|
+
bodyDark: { color: "var(--rg-body-fg-dark, #d1d5db)" },
|
|
77
84
|
primaryBtn: {
|
|
78
85
|
width: "100%",
|
|
79
|
-
padding:
|
|
86
|
+
padding: 11,
|
|
80
87
|
border: "none",
|
|
81
|
-
borderRadius:
|
|
82
|
-
background: "#2563eb",
|
|
83
|
-
color: "#fff",
|
|
88
|
+
borderRadius: "var(--rg-btn-radius, 10px)",
|
|
89
|
+
background: "var(--rg-accent, #2563eb)",
|
|
90
|
+
color: "var(--rg-accent-fg, #fff)",
|
|
84
91
|
fontSize: 14,
|
|
85
92
|
fontWeight: 600,
|
|
86
93
|
cursor: "pointer"
|
|
@@ -9,10 +9,19 @@ const props = withDefaults(defineProps<{
|
|
|
9
9
|
version?: string | null
|
|
10
10
|
/** Optional: e.g. `latestContent` from `virtual:refresh-guard-changelog`, rendered as-is via v-html — pre-sanitize if it isn't your own trusted file. */
|
|
11
11
|
changelogHtml?: string
|
|
12
|
+
/**
|
|
13
|
+
* Explicitly light/dark instead of following the OS `prefers-color-scheme`. Pass your app's
|
|
14
|
+
* own theme state here (e.g. `isDark.value`) so this modal matches your site's actual theme
|
|
15
|
+
* toggle instead of the visitor's OS setting — leaving this unset means a site in light mode
|
|
16
|
+
* can render a dark modal just because the OS is dark, which looks broken. Default: unset
|
|
17
|
+
* (falls back to `prefers-color-scheme`).
|
|
18
|
+
*/
|
|
19
|
+
dark?: boolean | null
|
|
12
20
|
}>(), {
|
|
13
21
|
mode: 'toast-auto',
|
|
14
22
|
version: null,
|
|
15
23
|
changelogHtml: '',
|
|
24
|
+
dark: null,
|
|
16
25
|
})
|
|
17
26
|
|
|
18
27
|
const emit = defineEmits<{ refresh: [] }>()
|
|
@@ -29,8 +38,8 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
29
38
|
</div>
|
|
30
39
|
|
|
31
40
|
<div v-if="shown && mode === 'modal-blocking'" class="rg-overlay" role="alertdialog" aria-modal="true">
|
|
32
|
-
<div class="rg-modal">
|
|
33
|
-
<h3 class="rg-title"
|
|
41
|
+
<div class="rg-modal" :class="{ 'rg-dark': dark === true, 'rg-light': dark === false }">
|
|
42
|
+
<h3 class="rg-title">✨ 有新版本可用{{ version ? `:${version}` : '' }}</h3>
|
|
34
43
|
<div v-if="changelogHtml" class="rg-body" v-html="changelogHtml" />
|
|
35
44
|
<p v-else class="rg-body rg-body-empty">刷新页面即可使用最新版本。</p>
|
|
36
45
|
<button type="button" class="rg-primary-btn" @click="emit('refresh')">立即更新</button>
|
|
@@ -40,6 +49,11 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
40
49
|
</template>
|
|
41
50
|
|
|
42
51
|
<style scoped>
|
|
52
|
+
/*
|
|
53
|
+
* Every color/radius here reads from a --rg-* custom property first, falling back to a
|
|
54
|
+
* reasonable default — set these on :root (or any ancestor) in your own app to re-skin the
|
|
55
|
+
* component to your brand instead of living with generic blue-on-white. See README "Styling".
|
|
56
|
+
*/
|
|
43
57
|
.rg-toast {
|
|
44
58
|
position: fixed;
|
|
45
59
|
right: 16px;
|
|
@@ -49,9 +63,9 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
49
63
|
align-items: center;
|
|
50
64
|
gap: 12px;
|
|
51
65
|
padding: 10px 16px;
|
|
52
|
-
border-radius:
|
|
53
|
-
background: #1f2937;
|
|
54
|
-
color: #fff;
|
|
66
|
+
border-radius: var(--rg-radius, 10px);
|
|
67
|
+
background: var(--rg-toast-bg, #1f2937);
|
|
68
|
+
color: var(--rg-toast-fg, #fff);
|
|
55
69
|
font-size: 13px;
|
|
56
70
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
57
71
|
}
|
|
@@ -61,11 +75,12 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
61
75
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
62
76
|
border-radius: 6px;
|
|
63
77
|
background: transparent;
|
|
64
|
-
color:
|
|
78
|
+
color: inherit;
|
|
65
79
|
font-size: 12px;
|
|
66
80
|
cursor: pointer;
|
|
81
|
+
transition: background 0.15s ease;
|
|
67
82
|
}
|
|
68
|
-
.rg-toast-btn:hover { background: rgba(255, 255, 255, 0.
|
|
83
|
+
.rg-toast-btn:hover { background: rgba(255, 255, 255, 0.12); }
|
|
69
84
|
|
|
70
85
|
.rg-overlay {
|
|
71
86
|
position: fixed;
|
|
@@ -74,35 +89,39 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
74
89
|
display: flex;
|
|
75
90
|
align-items: center;
|
|
76
91
|
justify-content: center;
|
|
77
|
-
background: rgba(
|
|
92
|
+
background: var(--rg-overlay-bg, rgba(15, 15, 20, 0.55));
|
|
78
93
|
}
|
|
79
94
|
.rg-modal {
|
|
80
95
|
width: 90vw;
|
|
81
96
|
max-width: 420px;
|
|
82
|
-
padding:
|
|
83
|
-
border-radius:
|
|
84
|
-
background: #fff;
|
|
85
|
-
color: #111827;
|
|
86
|
-
box-shadow: 0
|
|
97
|
+
padding: 28px;
|
|
98
|
+
border-radius: var(--rg-radius, 16px);
|
|
99
|
+
background: var(--rg-modal-bg, #fff);
|
|
100
|
+
color: var(--rg-modal-fg, #111827);
|
|
101
|
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
87
102
|
}
|
|
88
|
-
.rg-title { margin: 0 0
|
|
89
|
-
.rg-body { margin: 0 0
|
|
90
|
-
.rg-body-empty { color: #6b7280; }
|
|
103
|
+
.rg-title { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
|
|
104
|
+
.rg-body { margin: 0 0 22px; font-size: 13.5px; line-height: 1.7; color: var(--rg-body-fg, #4b5563); max-height: 40vh; overflow-y: auto; }
|
|
105
|
+
.rg-body-empty { color: var(--rg-body-fg, #6b7280); }
|
|
91
106
|
.rg-primary-btn {
|
|
92
107
|
width: 100%;
|
|
93
|
-
padding:
|
|
108
|
+
padding: 11px;
|
|
94
109
|
border: none;
|
|
95
|
-
border-radius:
|
|
96
|
-
background: #2563eb;
|
|
97
|
-
color: #fff;
|
|
110
|
+
border-radius: var(--rg-btn-radius, 10px);
|
|
111
|
+
background: var(--rg-accent, #2563eb);
|
|
112
|
+
color: var(--rg-accent-fg, #fff);
|
|
98
113
|
font-size: 14px;
|
|
99
114
|
font-weight: 600;
|
|
100
115
|
cursor: pointer;
|
|
116
|
+
transition: filter 0.15s ease, transform 0.05s ease;
|
|
101
117
|
}
|
|
102
|
-
.rg-primary-btn:hover {
|
|
118
|
+
.rg-primary-btn:hover { filter: brightness(0.92); }
|
|
119
|
+
.rg-primary-btn:active { transform: scale(0.99); }
|
|
103
120
|
|
|
121
|
+
.rg-modal.rg-dark { background: var(--rg-modal-bg-dark, #1f2937); color: var(--rg-modal-fg-dark, #f3f4f6); }
|
|
122
|
+
.rg-modal.rg-dark .rg-body { color: var(--rg-body-fg-dark, #d1d5db); }
|
|
104
123
|
@media (prefers-color-scheme: dark) {
|
|
105
|
-
.rg-modal { background: #1f2937; color: #f3f4f6; }
|
|
106
|
-
.rg-body { color: #d1d5db; }
|
|
124
|
+
.rg-modal:not(.rg-light) { background: var(--rg-modal-bg-dark, #1f2937); color: var(--rg-modal-fg-dark, #f3f4f6); }
|
|
125
|
+
.rg-modal:not(.rg-light) .rg-body { color: var(--rg-body-fg-dark, #d1d5db); }
|
|
107
126
|
}
|
|
108
127
|
</style>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-refresh-guard",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Vite 应用的可配置版本更新检测+刷新方案:静默自动刷新 / 提示后自动刷新 / 弹窗阻断,按产品需要选档位,核心逻辑框架无关,附 Vue/React 适配层。Configurable new-version detection + refresh for Vite apps — silent / toast-auto / modal-blocking, framework-agnostic core with Vue and React adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|