Skip to content

Commit 9b8b9f6

Browse files
committed
release: v2.1.4
2 parents 837884b + ec98bbf commit 9b8b9f6

7 files changed

Lines changed: 57 additions & 48 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## 更新日志
22

3+
### 2.1.4
4+
5+
*2024-09-10*
6+
7+
#### Feat ✨
8+
9+
- 支持自定义浏览器缓存字的键名
10+
311
### 2.1.3
412

513
*2024-07-15*

README.en.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ The solution is very simple. Add a script to the `head` in the `html`, which rea
143143
```html
144144
<script src="https://unpkg.com/element-theme-darkplus/utils/dark-mode.js"></script>
145145
```
146+
147+
Support custom browser cache word key name.
148+
149+
```html
150+
<script src="https://unpkg.com/element-theme-darkplus/utils/dark-mode.js" storage-key="custom-theme-appearance"></script>
151+
```

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ Vue.component(Rate.name, Darken(Rate))
143143
```html
144144
<script src="https://unpkg.com/element-theme-darkplus/utils/dark-mode.js"></script>
145145
```
146+
147+
支持自定义浏览器缓存字的键名。
148+
149+
```html
150+
<script src="https://unpkg.com/element-theme-darkplus/utils/dark-mode.js" storage-key="custom-theme-appearance"></script>
151+
```

docs/components/ThemeToggle/index.vue

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<template>
2-
<div class="theme-toggle" @click.stop="switchTheme" @keydown.enter.stop="resolve(true)">
3-
<theme-switch v-model="isDark" :before-change="beforeChange" />
4-
</div>
2+
<theme-switch ref="switch" v-model="isDark" class="theme-toggle" :before-change="beforeChange" />
53
</template>
64

75
<script>
@@ -13,55 +11,44 @@ export default {
1311
name: 'ThemeToggle',
1412
components: { ThemeSwitch },
1513
mixins: [dark],
16-
data() {
17-
return {
18-
resolve: null,
19-
beforeChange: () =>
20-
new Promise(resolve => {
21-
this.resolve = resolve
22-
}),
23-
}
24-
},
2514
methods: {
26-
switchTheme(event) {
27-
if (!document.startViewTransition) {
28-
return this.resolve(true)
29-
}
30-
31-
const x = event.clientX
32-
const y = event.clientY
33-
const endRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y))
34-
35-
const transition = document.startViewTransition(async () => {
36-
this.resolve(true)
37-
await this.$nextTick()
38-
})
39-
40-
transition.ready.then(() => {
41-
const clipPath = [`circle(0px at ${x}px ${y}px)`, `circle(${endRadius}px at ${x}px ${y}px)`]
42-
43-
document.documentElement.animate(
44-
{
45-
clipPath: this.isDark ? [...clipPath].reverse() : clipPath,
46-
},
47-
{
48-
duration: 400,
49-
easing: 'ease-in',
50-
pseudoElement: this.isDark ? '::view-transition-old(root)' : '::view-transition-new(root)',
51-
}
52-
)
15+
beforeChange() {
16+
return new Promise(resolve => {
17+
if (!document.startViewTransition) {
18+
return resolve(true)
19+
}
20+
21+
const switchElement = this.$refs.switch?.$el
22+
const rect = switchElement.getBoundingClientRect()
23+
const x = rect.left + rect.width / 2
24+
const y = rect.top + rect.height / 2
25+
const endRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y))
26+
27+
const transition = document.startViewTransition(async () => {
28+
resolve(true)
29+
await this.$nextTick()
30+
})
31+
32+
transition.ready.then(() => {
33+
const clipPath = [`circle(0px at ${x}px ${y}px)`, `circle(${endRadius}px at ${x}px ${y}px)`]
34+
35+
document.documentElement.animate(
36+
{
37+
clipPath: this.isDark ? [...clipPath].reverse() : clipPath,
38+
},
39+
{
40+
duration: 400,
41+
easing: 'ease-in',
42+
pseudoElement: this.isDark ? '::view-transition-old(root)' : '::view-transition-new(root)',
43+
}
44+
)
45+
})
5346
})
5447
},
5548
},
5649
}
5750
</script>
5851
59-
<style scoped>
60-
.theme-toggle {
61-
display: inline-block;
62-
}
63-
</style>
64-
6552
<style>
6653
::view-transition-new(root),
6754
::view-transition-old(root) {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "element-theme-darkplus",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "Element component dark theme base on the latest version 2.15.14.",
55
"main": "lib/index.css",
66
"style": "lib/index.css",
@@ -10,6 +10,7 @@
1010
"EXAMPLE.md"
1111
],
1212
"scripts": {
13+
"dev": "live-server docs",
1314
"build:css": "gulp build",
1415
"build:scripts": "rollup -c scripts/rollup.config.js"
1516
},
@@ -45,6 +46,7 @@
4546
"gulp-rename": "^2.0.0",
4647
"gulp-sass": "^5.1.0",
4748
"gulp-util": "^3.0.8",
49+
"live-server": "^1.2.2",
4850
"prettier": "^2.8.8",
4951
"rollup": "^4.18.0",
5052
"sass": "1.32.13",

scripts/dark-mode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { scripts } from '../theme.config'
22

3-
const { storageKey } = scripts
3+
const storageKey = document.currentScript?.getAttribute('storage-key') || scripts.storageKey
44
const store = localStorage.getItem(`${storageKey}`)
55
const mediaQuery = window.matchMedia?.('(prefers-color-scheme: dark)')
66
const preferredDark = mediaQuery?.matches || false

utils/dark-mode.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)