@bg-effects/grainient 1.0.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/README.md +359 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
# @bg-effects/grainient
|
|
2
|
+
|
|
3
|
+
β¨ Beautiful noise-based gradient particle background effect for Vue 3.
|
|
4
|
+
|
|
5
|
+
  
|
|
6
|
+
|
|
7
|
+
## β¨ Features
|
|
8
|
+
|
|
9
|
+
- π **High Performance** - WebGL 2.0 based rendering, GPU accelerated
|
|
10
|
+
- π¨ **Rich Visuals** - Noise-based gradient with grain texture
|
|
11
|
+
- π **Color Palette** - Support for 3-color gradients with 10+ presets
|
|
12
|
+
- ποΈ **Highly Customizable** - 10+ adjustable parameters
|
|
13
|
+
- π§ **Debug Panel** - Built-in real-time configuration panel
|
|
14
|
+
- π **i18n Support** - Dual-language (Chinese/English) interface
|
|
15
|
+
- π¦ **4 Built-in Presets** - Ready-to-use color schemes
|
|
16
|
+
- π¬ **Animation Control** - Adjustable speed (0.1x-5x)
|
|
17
|
+
|
|
18
|
+
## π¦ Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# pnpm
|
|
22
|
+
pnpm add @bg-effects/grainient
|
|
23
|
+
|
|
24
|
+
# npm
|
|
25
|
+
npm install @bg-effects/grainient
|
|
26
|
+
|
|
27
|
+
# yarn
|
|
28
|
+
yarn add @bg-effects/grainient
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## π Quick Start
|
|
32
|
+
|
|
33
|
+
### Basic Usage
|
|
34
|
+
|
|
35
|
+
```vue
|
|
36
|
+
<script setup>
|
|
37
|
+
import { Grainient } from '@bg-effects/grainient'
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<div class="container">
|
|
42
|
+
<Grainient />
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<style scoped>
|
|
47
|
+
.container {
|
|
48
|
+
width: 100vw;
|
|
49
|
+
height: 100vh;
|
|
50
|
+
position: relative;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With Debug Panel
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<template>
|
|
59
|
+
<Grainient debug lang="en" />
|
|
60
|
+
</template>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Custom Configuration
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<script setup>
|
|
67
|
+
import { Grainient } from '@bg-effects/grainient'
|
|
68
|
+
|
|
69
|
+
const config = {
|
|
70
|
+
color1: '#FF9FFC',
|
|
71
|
+
color2: '#5227FF',
|
|
72
|
+
color3: '#B19EEF',
|
|
73
|
+
timeSpeed: 0.8,
|
|
74
|
+
grainAmount: 0.06,
|
|
75
|
+
contrast: 1.2,
|
|
76
|
+
zoom: 0.9
|
|
77
|
+
}
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<template>
|
|
81
|
+
<Grainient v-bind="config" />
|
|
82
|
+
</template>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## π API Reference
|
|
86
|
+
|
|
87
|
+
### Props
|
|
88
|
+
|
|
89
|
+
#### Basic Settings
|
|
90
|
+
|
|
91
|
+
| Prop | Type | Default | Range | Description |
|
|
92
|
+
|------|------|---------|-------|-------------|
|
|
93
|
+
| `timeSpeed` | `number` | `0.6` | 0.1-5.0 | Animation speed multiplier |
|
|
94
|
+
| `grainAmount` | `number` | `0.05` | 0-0.15 | Grain texture intensity |
|
|
95
|
+
| `zoom` | `number` | `0.9` | 0.5-1.5 | Zoom level of the gradient |
|
|
96
|
+
|
|
97
|
+
#### Color Settings
|
|
98
|
+
|
|
99
|
+
| Prop | Type | Default | Description |
|
|
100
|
+
|------|------|---------|-------------|
|
|
101
|
+
| `color1` | `string` | `'#7aa2f7'` | Primary color (hex format) |
|
|
102
|
+
| `color2` | `string` | `'#020617'` | Secondary color (hex format) |
|
|
103
|
+
| `color3` | `string` | `'#bb9af7'` | Tertiary color (hex format) |
|
|
104
|
+
|
|
105
|
+
#### Visual Effects
|
|
106
|
+
|
|
107
|
+
| Prop | Type | Default | Range | Description |
|
|
108
|
+
|------|------|---------|-------|-------------|
|
|
109
|
+
| `contrast` | `number` | `1.3` | 0.8-2.0 | Color contrast |
|
|
110
|
+
| `gamma` | `number` | `1.0` | 0.5-2.0 | Gamma correction |
|
|
111
|
+
| `saturation` | `number` | `1.0` | 0.5-1.5 | Color saturation |
|
|
112
|
+
| `rotation` | `number` | `0` | 0-360 | Rotation angle in degrees |
|
|
113
|
+
| `blur` | `number` | `0` | 0-3.0 | Blur intensity for dreamy effect |
|
|
114
|
+
|
|
115
|
+
#### Performance Settings
|
|
116
|
+
|
|
117
|
+
| Prop | Type | Default | Range | Description |
|
|
118
|
+
|------|------|---------|-------|-------------|
|
|
119
|
+
| `quality` | `number` | `0.75` | 0.5-2.0 | Render quality (DPR multiplier) |
|
|
120
|
+
| `maxFps` | `number` | `60` | 30/60 | Maximum frame rate limit |
|
|
121
|
+
|
|
122
|
+
#### Advanced Settings (Internal)
|
|
123
|
+
|
|
124
|
+
| Prop | Type | Default | Description |
|
|
125
|
+
|------|------|---------|-------------|
|
|
126
|
+
| `noiseScale` | `number` | `2.0` | Noise pattern scale |
|
|
127
|
+
| `grainScale` | `number` | `2.0` | Grain particle scale |
|
|
128
|
+
| `grainAnimated` | `boolean` | `true` | Enable grain animation |
|
|
129
|
+
| `centerX` | `number` | `0` | Horizontal center offset (-1 to 1) |
|
|
130
|
+
| `centerY` | `number` | `0` | Vertical center offset (-1 to 1) |
|
|
131
|
+
| `colorBalance` | `number` | `0` | Balance between color regions |
|
|
132
|
+
| `warpStrength` | `number` | `0.5` | Warp distortion strength |
|
|
133
|
+
| `warpFrequency` | `number` | `3` | Warp wave frequency |
|
|
134
|
+
| `warpSpeed` | `number` | `1` | Warp animation speed |
|
|
135
|
+
| `warpAmplitude` | `number` | `50` | Warp effect amplitude |
|
|
136
|
+
| `rotationAmount` | `number` | `0` | Dynamic rotation amount |
|
|
137
|
+
| `blendAngle` | `number` | `45` | Color blend angle |
|
|
138
|
+
| `blendSoftness` | `number` | `0.1` | Color transition softness |
|
|
139
|
+
|
|
140
|
+
#### System Props
|
|
141
|
+
|
|
142
|
+
| Prop | Type | Default | Description |
|
|
143
|
+
|------|------|---------|-------------|
|
|
144
|
+
| `debug` | `boolean` | `false` | Enable debug panel |
|
|
145
|
+
| `lang` | `string` | `'zh-CN'` | Debug panel language (`'zh-CN'` or `'en'`) |
|
|
146
|
+
| `className` | `string` | - | Custom CSS class |
|
|
147
|
+
|
|
148
|
+
## π¨ Presets
|
|
149
|
+
|
|
150
|
+
Four beautiful built-in presets are included:
|
|
151
|
+
|
|
152
|
+
### Vibrant (ζ΄»εεε°)
|
|
153
|
+
Energetic blend of purple and gold tones with high contrast.
|
|
154
|
+
```vue
|
|
155
|
+
<Grainient
|
|
156
|
+
color1="#9a4c78"
|
|
157
|
+
color2="#f5cc36"
|
|
158
|
+
color3="#d2d283"
|
|
159
|
+
:timeSpeed="0.8"
|
|
160
|
+
:grainAmount="0.06"
|
|
161
|
+
:contrast="1.2"
|
|
162
|
+
/>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Purple Gold (η΄«ιδΊ€θΎ)
|
|
166
|
+
Luxurious purple and gold combination with warm glow.
|
|
167
|
+
```vue
|
|
168
|
+
<Grainient
|
|
169
|
+
color1="#f4cb37"
|
|
170
|
+
color2="#5a3f5f"
|
|
171
|
+
color3="#f5cc36"
|
|
172
|
+
:timeSpeed="0.7"
|
|
173
|
+
:grainAmount="0.05"
|
|
174
|
+
:contrast="1.25"
|
|
175
|
+
/>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Blue (ζ·±ζ΅·θι΅)
|
|
179
|
+
Deep ocean-inspired blue gradient with cool tones.
|
|
180
|
+
```vue
|
|
181
|
+
<Grainient
|
|
182
|
+
color1="#020617"
|
|
183
|
+
color2="#1e293b"
|
|
184
|
+
color3="#3b82f6"
|
|
185
|
+
:timeSpeed="0.6"
|
|
186
|
+
:grainAmount="0.04"
|
|
187
|
+
/>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Pink (η²θ²ζ’¦ε’)
|
|
191
|
+
Soft pink dreamlike gradient with vibrant accents.
|
|
192
|
+
```vue
|
|
193
|
+
<Grainient
|
|
194
|
+
color1="#ff5f6d"
|
|
195
|
+
color2="#ffc371"
|
|
196
|
+
color3="#2193b0"
|
|
197
|
+
:timeSpeed="0.5"
|
|
198
|
+
:grainAmount="0.05"
|
|
199
|
+
/>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## π― Usage Tips
|
|
203
|
+
|
|
204
|
+
### Performance Optimization
|
|
205
|
+
|
|
206
|
+
#### Low-Power Mode (Mobile Devices)
|
|
207
|
+
```vue
|
|
208
|
+
<Grainient
|
|
209
|
+
:quality="0.5"
|
|
210
|
+
:maxFps="30"
|
|
211
|
+
:grainAnimated="false"
|
|
212
|
+
:grainAmount="0.03"
|
|
213
|
+
/>
|
|
214
|
+
```
|
|
215
|
+
**Expected FPS**: 30-60, significantly reduced battery consumption
|
|
216
|
+
|
|
217
|
+
#### Balanced Mode (Default)
|
|
218
|
+
```vue
|
|
219
|
+
<Grainient
|
|
220
|
+
:quality="0.75"
|
|
221
|
+
:maxFps="60"
|
|
222
|
+
/>
|
|
223
|
+
```
|
|
224
|
+
**Expected FPS**: 50-60, balanced performance and quality
|
|
225
|
+
|
|
226
|
+
#### High Quality Mode (Desktop)
|
|
227
|
+
```vue
|
|
228
|
+
<Grainient
|
|
229
|
+
:quality="1.5"
|
|
230
|
+
:maxFps="60"
|
|
231
|
+
:grainAnimated="true"
|
|
232
|
+
/>
|
|
233
|
+
```
|
|
234
|
+
**Expected FPS**: 40-60, best visual quality
|
|
235
|
+
|
|
236
|
+
**Quality Parameter Guide:**
|
|
237
|
+
- `0.5` - Low quality, 25% pixel count, best performance
|
|
238
|
+
- `0.75` - Default, 56% pixel count, balanced
|
|
239
|
+
- `1.0` - Native resolution, 100% pixel count
|
|
240
|
+
- `1.5` - Enhanced, 225% pixel count
|
|
241
|
+
- `2.0` - Ultra, 400% pixel count (high-end devices only)
|
|
242
|
+
|
|
243
|
+
### Responsive Design
|
|
244
|
+
|
|
245
|
+
```vue
|
|
246
|
+
<script setup>
|
|
247
|
+
import { computed } from 'vue'
|
|
248
|
+
import { Grainient } from '@bg-effects/grainient'
|
|
249
|
+
|
|
250
|
+
const isMobile = computed(() => window.innerWidth < 768)
|
|
251
|
+
|
|
252
|
+
const responsiveConfig = computed(() => ({
|
|
253
|
+
grainAmount: isMobile.value ? 0.03 : 0.06,
|
|
254
|
+
timeSpeed: isMobile.value ? 0.4 : 0.8
|
|
255
|
+
}))
|
|
256
|
+
</script>
|
|
257
|
+
|
|
258
|
+
<template>
|
|
259
|
+
<Grainient v-bind="responsiveConfig" />
|
|
260
|
+
</template>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Dynamic Color Themes
|
|
264
|
+
|
|
265
|
+
```vue
|
|
266
|
+
<script setup>
|
|
267
|
+
import { ref, watch } from 'vue'
|
|
268
|
+
import { Grainient } from '@bg-effects/grainient'
|
|
269
|
+
|
|
270
|
+
const isDark = ref(true)
|
|
271
|
+
|
|
272
|
+
const colors = computed(() =>
|
|
273
|
+
isDark.value
|
|
274
|
+
? { color1: '#020617', color2: '#1e293b', color3: '#3b82f6' }
|
|
275
|
+
: { color1: '#ff9ffc', color2: '#5227ff', color3: '#b19eef' }
|
|
276
|
+
)
|
|
277
|
+
</script>
|
|
278
|
+
|
|
279
|
+
<template>
|
|
280
|
+
<Grainient v-bind="colors" />
|
|
281
|
+
<button @click="isDark = !isDark">Toggle Theme</button>
|
|
282
|
+
</template>
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Animation Control
|
|
286
|
+
|
|
287
|
+
```vue
|
|
288
|
+
<script setup>
|
|
289
|
+
import { ref } from 'vue'
|
|
290
|
+
|
|
291
|
+
const speed = ref(0.6)
|
|
292
|
+
|
|
293
|
+
function pause() {
|
|
294
|
+
speed.value = 0
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function play() {
|
|
298
|
+
speed.value = 0.6
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function speedUp() {
|
|
302
|
+
speed.value = Math.min(speed.value + 0.2, 5)
|
|
303
|
+
}
|
|
304
|
+
</script>
|
|
305
|
+
|
|
306
|
+
<template>
|
|
307
|
+
<Grainient :timeSpeed="speed" />
|
|
308
|
+
<button @click="pause">βΈοΈ</button>
|
|
309
|
+
<button @click="play">βΆοΈ</button>
|
|
310
|
+
<button @click="speedUp">β©</button>
|
|
311
|
+
</template>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## π§ Development
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# Install dependencies
|
|
318
|
+
pnpm install
|
|
319
|
+
|
|
320
|
+
# Build the package
|
|
321
|
+
pnpm -F @bg-effects/grainient build
|
|
322
|
+
|
|
323
|
+
# Watch mode
|
|
324
|
+
pnpm -F @bg-effects/grainient dev
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## π¨ Color Randomization
|
|
328
|
+
|
|
329
|
+
The effect uses a sophisticated color generation system:
|
|
330
|
+
|
|
331
|
+
- **30% chance** - Select from 10 curated color palettes
|
|
332
|
+
- **70% chance** - Generate harmonious colors using HSL color theory
|
|
333
|
+
|
|
334
|
+
This ensures both consistency and variety in the visual output.
|
|
335
|
+
|
|
336
|
+
## β‘ Performance Notes
|
|
337
|
+
|
|
338
|
+
- **WebGL 2.0 based** - GPU accelerated rendering
|
|
339
|
+
- **Responsive** - Automatically adapts to container size changes
|
|
340
|
+
- **Device pixel ratio** - Capped at 2x for optimal performance
|
|
341
|
+
- **Real-time updates** - All parameters update dynamically
|
|
342
|
+
|
|
343
|
+
## π License
|
|
344
|
+
|
|
345
|
+
MIT License
|
|
346
|
+
|
|
347
|
+
## π€ Contributing
|
|
348
|
+
|
|
349
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
350
|
+
|
|
351
|
+
## π Links
|
|
352
|
+
|
|
353
|
+
- [Documentation](../../apps/docs/docs/effects/grainient.md)
|
|
354
|
+
- [Playground Demo](../../apps/playground)
|
|
355
|
+
- [GitHub Repository](https://github.com/yourusername/bg-effects)
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
Made with β€οΈ using Vue 3 + WebGL 2.0
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bg-effects/grainient",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"vue": "^3.3.0",
|
|
13
|
+
"ogl": "^1.0.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"vite": "^5.0.0",
|
|
17
|
+
"ogl": "^1.0.11",
|
|
18
|
+
"unocss": "^65.4.0",
|
|
19
|
+
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
20
|
+
"vite-plugin-dts": "^4.5.1",
|
|
21
|
+
"@bg-effects/configs": "1.0.0",
|
|
22
|
+
"@bg-effects/core": "1.0.0",
|
|
23
|
+
"@bg-effects/shared": "1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@bg-effects/debug-ui": "1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "vite build",
|
|
30
|
+
"dev": "vite build --watch"
|
|
31
|
+
}
|
|
32
|
+
}
|