Skip to content

Commit f88b8f0

Browse files
committed
feat: add CyberpunkGlitch component
1 parent 6f15a9c commit f88b8f0

File tree

8 files changed

+181
-7
lines changed

8 files changed

+181
-7
lines changed

docs/.vitepress/config/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mergeConfig } from 'vitepress'
22

3-
import shared from './shared'
43
import { zh } from './locales/zh'
4+
import shared from './shared'
55

66
export default mergeConfig(shared, {
77
locales: {

docs/.vitepress/config/locales/zh.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ function sidebarComponents(): DefaultTheme.SidebarItem[] {
8080
{
8181
text: '组件',
8282
items: [
83-
{ text: '图标文字', link: '/components/icon-text' }
83+
{ text: '图标文字', link: '/components/icon-text' },
84+
{
85+
text: '赛博朋克故障效果',
86+
link: '/components/cyberpunk-glitch'
87+
}
8488
]
8589
}
8690
]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# IxCyberpunkGlitch
2+
3+
赛博朋克故障效果组件
4+
5+
## 文字
6+
7+
<div p-4 rounded-md bg-slate-950>
8+
<IxCyberpunkGlitch text-white>Cyberpunk Glitch</IxCyberpunkGlitch>
9+
</div>
10+
11+
```vue
12+
<template>
13+
<IxCyberpunkGlitch text-white>
14+
Cyberpunk Glitch
15+
</IxCyberpunkGlitch>
16+
</template>
17+
```
18+
19+
## 图片
20+
21+
<div>
22+
<IxCyberpunkGlitch>
23+
<img src="/images/favicon.png" size-20 rounded-md />
24+
</IxCyberpunkGlitch>
25+
</div>
26+
27+
```vue
28+
<template>
29+
<IxCyberpunkGlitch>
30+
<img src="/images/favicon.png" size-20 rounded-md>
31+
</IxCyberpunkGlitch>
32+
</template>
33+
```
34+
35+
## 元素
36+
37+
<div>
38+
<IxCyberpunkGlitch>
39+
<div size-20 bg-lime-6 rounded-md />
40+
</IxCyberpunkGlitch>
41+
</div>
42+
43+
```vue
44+
<template>
45+
<IxCyberpunkGlitch>
46+
<div size-20 bg-lime-6 rounded-md />
47+
</IxCyberpunkGlitch>
48+
</template>
49+
```

docs/guide/integrations/auto-import-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ pnpm add unplugin-vue-components -D
1313
以 Vite 为例
1414

1515
```ts
16-
import { defineConfig } from 'vite'
16+
import IntroxdResolver from '@introxd/components/resolver'
1717

1818
import components from 'unplugin-vue-components/vite'
19-
import IntroxdResolver from '@introxd/components/resolver'
19+
import { defineConfig } from 'vite'
2020

2121
export default defineConfig({
2222
plugins: [

docs/vite.config.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { URL, fileURLToPath } from 'node:url'
1+
import { fileURLToPath, URL } from 'node:url'
22

3-
import { defineConfig } from 'vite'
3+
import IntroxdResolver from '@introxd/components/resolver'
44

55
import unocss from 'unocss/vite'
66
import autoImport from 'unplugin-auto-import/vite'
77
import components from 'unplugin-vue-components/vite'
88

9-
import IntroxdResolver from '@introxd/components/resolver'
9+
import { defineConfig } from 'vite'
1010

1111
const r = (path: string) => fileURLToPath(new URL(path, import.meta.url))
1212

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as IxCyberpunkGlitch } from './src/index.vue'
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<style lang="scss" scoped>
2+
.text-container {
3+
--slice-0: inset(50% 50% 50% 50%);
4+
--slice-1: inset(15% 0 65% 0);
5+
--slice-2: inset(30% 0 50% 0);
6+
--slice-3: inset(50% 0 35% 0);
7+
--slice-4: inset(60% 0 20% 0);
8+
--slice-5: inset(80% 0 10% 0);
9+
10+
--slice-shadow-1: -1px -1px 0 #F8F005, 1px 1px 0 #00E6F6;
11+
--slice-shadow-2: -2px -2px 0 #F8F005, 2px 2px 0 #00E6F6;
12+
13+
.text {
14+
15+
&>.text-before,
16+
&>.text-after {
17+
--uno: pa top-0 right-0 bottom-0 left-0;
18+
text-shadow: var(--slice-shadow-1);
19+
clip-path: var(--slice-0);
20+
}
21+
22+
&>.text-after {
23+
--uno: blur-2;
24+
}
25+
26+
&.animate-glitch {
27+
28+
&>.text-before,
29+
&>.text-after {
30+
animation: glitch .3s infinite steps(1, end);
31+
}
32+
}
33+
}
34+
}
35+
36+
@keyframes glitch {
37+
0% {
38+
clip-path: var(--slice-1);
39+
transform: translate(0, -5px);
40+
}
41+
42+
20% {
43+
clip-path: var(--slice-5);
44+
transform: translate(10px, -5px);
45+
}
46+
47+
40% {
48+
clip-path: var(--slice-2);
49+
transform: translate(0, 0);
50+
}
51+
52+
60% {
53+
clip-path: var(--slice-5);
54+
transform: translate(-10px, 5px);
55+
text-shadow: var(--slice-shadow-2);
56+
}
57+
58+
80% {
59+
clip-path: var(--slice-3);
60+
transform: translate(3px, 0);
61+
}
62+
63+
100% {
64+
clip-path: var(--slice-4);
65+
transform: translate(10px, 0);
66+
text-shadow: var(--slice-shadow-2);
67+
}
68+
}
69+
</style>
70+
71+
<template>
72+
<div class="text-container" pr text-8>
73+
<div
74+
pr class="text"
75+
:class="isPlaying ? 'animate-glitch animate-flash animate-duration-300 animate-count-infinite' : ''"
76+
>
77+
<slot :class="props.contentClass" />
78+
<div class="text-before" :class="props.contentClass">
79+
<slot />
80+
</div>
81+
<div class="text-after" :class="props.contentClass">
82+
<slot />
83+
</div>
84+
</div>
85+
<slot name="background" :is-playing />
86+
</div>
87+
</template>
88+
89+
<script lang="ts" setup>
90+
const props = withDefaults(defineProps<{
91+
contentClass?: string
92+
}>(), {
93+
94+
})
95+
96+
const isPlaying = ref(false)
97+
98+
onMounted(() => {
99+
playAnimate()
100+
})
101+
102+
async function playAnimate() {
103+
isPlaying.value = true
104+
105+
const playTime = _random(200, 1200)
106+
107+
await new Promise((resolve) => {
108+
setTimeout(() => {
109+
isPlaying.value = false
110+
resolve(null)
111+
}, playTime)
112+
})
113+
114+
const interval = _random(2000, 5000)
115+
setTimeout(() => {
116+
playAnimate()
117+
}, interval)
118+
}
119+
</script>

packages/components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import 'virtual:uno.css'
22

3+
export * from './components/CyberpunkGlitch'
34
export * from './components/IconText'

0 commit comments

Comments
 (0)