nuxt-ui-elements 0.1.2 → 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/dist/module.json +1 -1
- package/dist/runtime/components/background/FlickeringGrid.d.vue.ts +27 -12
- package/dist/runtime/components/background/FlickeringGrid.vue +33 -29
- package/dist/runtime/components/background/FlickeringGrid.vue.d.ts +27 -12
- package/dist/runtime/composables/useThemeColors.d.ts +7 -0
- package/dist/runtime/composables/useThemeColors.js +10 -0
- package/package.json +2 -2
package/dist/module.json
CHANGED
|
@@ -35,28 +35,43 @@ export interface FlickeringGridProps {
|
|
|
35
35
|
* - Tailwind colors: 'blue-500', 'red-600', 'slate-200', etc.
|
|
36
36
|
* - Direct values: '#3b82f6', 'oklch(0.6 0.15 250)', 'rgb(59, 130, 246)'
|
|
37
37
|
*
|
|
38
|
+
* Choose lighter shades (e.g., 'blue-200') for subtle backgrounds or darker shades (e.g., 'blue-600') for bolder effects.
|
|
39
|
+
*
|
|
38
40
|
* @example 'primary' - Nuxt UI semantic color
|
|
39
|
-
* @example 'blue-
|
|
40
|
-
* @example '
|
|
41
|
+
* @example 'blue-200' - Light Tailwind color for subtle effect
|
|
42
|
+
* @example 'blue-600' - Dark Tailwind color for bold effect
|
|
43
|
+
* @example '#e0f2fe' - Direct hex color value (light blue)
|
|
41
44
|
*
|
|
42
45
|
* @default 'neutral'
|
|
43
46
|
*/
|
|
44
47
|
color?: ColorInput;
|
|
45
48
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
49
|
+
* Opacity/visibility of the grid squares.
|
|
50
|
+
* Controls how transparent the grid appears.
|
|
51
|
+
*
|
|
52
|
+
* - 0: Completely invisible
|
|
53
|
+
* - 0.3: Subtle, background texture
|
|
54
|
+
* - 0.5: Medium visibility
|
|
55
|
+
* - 0.8: Bold, prominent
|
|
56
|
+
* - 1: Fully opaque
|
|
53
57
|
*
|
|
54
|
-
*
|
|
58
|
+
* Range: 0-1
|
|
59
|
+
*
|
|
60
|
+
* @default 0.5
|
|
55
61
|
*/
|
|
62
|
+
opacity?: number;
|
|
56
63
|
/**
|
|
57
|
-
*
|
|
64
|
+
* Dark mode overrides for color and opacity.
|
|
65
|
+
*
|
|
66
|
+
* Allows you to customize the grid appearance specifically for dark mode.
|
|
67
|
+
* Any property not specified will use the default light mode value.
|
|
68
|
+
*
|
|
69
|
+
* @example { color: 'blue-300', opacity: 0.3 }
|
|
58
70
|
*/
|
|
59
|
-
|
|
71
|
+
dark?: {
|
|
72
|
+
color?: ColorInput;
|
|
73
|
+
opacity?: number;
|
|
74
|
+
};
|
|
60
75
|
/**
|
|
61
76
|
* UI slot customization
|
|
62
77
|
*/
|
|
@@ -7,7 +7,7 @@ import { ref, computed, onMounted, onBeforeUnmount, watch } from "vue";
|
|
|
7
7
|
import { useColorMode } from "#imports";
|
|
8
8
|
import { tv } from "../../utils/tv";
|
|
9
9
|
import theme from "../../themes/background-flickering-grid";
|
|
10
|
-
import {
|
|
10
|
+
import { darkenColor, oklchToRgb } from "../../composables/useThemeColors";
|
|
11
11
|
import {
|
|
12
12
|
resolveColor
|
|
13
13
|
} from "../../composables/useColorResolver";
|
|
@@ -16,7 +16,7 @@ const {
|
|
|
16
16
|
gap = 9,
|
|
17
17
|
speed = 5,
|
|
18
18
|
color = "neutral",
|
|
19
|
-
|
|
19
|
+
opacity = 0.5,
|
|
20
20
|
...props
|
|
21
21
|
} = defineProps({
|
|
22
22
|
size: { type: Number, required: false },
|
|
@@ -24,32 +24,27 @@ const {
|
|
|
24
24
|
speed: { type: Number, required: false },
|
|
25
25
|
fade: { type: String, required: false },
|
|
26
26
|
color: { type: null, required: false },
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
opacity: { type: Number, required: false },
|
|
28
|
+
dark: { type: Object, required: false },
|
|
29
29
|
ui: { type: null, required: false }
|
|
30
30
|
});
|
|
31
31
|
const colorMode = useColorMode();
|
|
32
32
|
const isDark = computed(() => colorMode.value === "dark");
|
|
33
33
|
const effectiveColor = computed(() => {
|
|
34
|
-
if (isDark.value && props.
|
|
35
|
-
return props.
|
|
34
|
+
if (isDark.value && props.dark?.color) {
|
|
35
|
+
return props.dark.color;
|
|
36
36
|
}
|
|
37
37
|
return color;
|
|
38
38
|
});
|
|
39
|
+
const effectiveOpacity = computed(() => {
|
|
40
|
+
if (isDark.value && props.dark?.opacity !== void 0) {
|
|
41
|
+
return props.dark.opacity;
|
|
42
|
+
}
|
|
43
|
+
return opacity;
|
|
44
|
+
});
|
|
39
45
|
const internalSpeed = computed(() => {
|
|
40
46
|
return speed * 0.01;
|
|
41
47
|
});
|
|
42
|
-
const effectiveOpacity = computed(() => {
|
|
43
|
-
const minLightness = 70;
|
|
44
|
-
const maxLightness = 100;
|
|
45
|
-
const maxOpacity = 0.8;
|
|
46
|
-
const minOpacity = 0.15;
|
|
47
|
-
const t = Math.max(
|
|
48
|
-
0,
|
|
49
|
-
Math.min(1, (lightness - minLightness) / (maxLightness - minLightness))
|
|
50
|
-
);
|
|
51
|
-
return maxOpacity - t * (maxOpacity - minOpacity);
|
|
52
|
-
});
|
|
53
48
|
defineSlots();
|
|
54
49
|
const ui = computed(() => tv(theme)());
|
|
55
50
|
const maskStyle = computed(() => {
|
|
@@ -93,10 +88,9 @@ function parseColor(color2) {
|
|
|
93
88
|
}
|
|
94
89
|
const gridColors = computed(() => {
|
|
95
90
|
const baseColor = resolveColor(effectiveColor.value);
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
const flickerRgb = oklchToRgb(adjustLightness(baseColor, lightnessFlicker));
|
|
91
|
+
const baseRgb = oklchToRgb(baseColor);
|
|
92
|
+
const darkerColor = darkenColor(baseColor, 10);
|
|
93
|
+
const flickerRgb = oklchToRgb(darkerColor);
|
|
100
94
|
return {
|
|
101
95
|
base: parseColor(baseRgb),
|
|
102
96
|
flicker: parseColor(flickerRgb)
|
|
@@ -146,13 +140,13 @@ function drawGrid(ctx, canvasWidth, canvasHeight, cols, rows, squares, dpr) {
|
|
|
146
140
|
for (let i = 0; i < cols; i++) {
|
|
147
141
|
for (let j = 0; j < rows; j++) {
|
|
148
142
|
const idx = i * rows + j;
|
|
149
|
-
const
|
|
143
|
+
const opacity2 = squares[idx] ?? 0;
|
|
150
144
|
let cellColor = colors.base;
|
|
151
|
-
let cellAlpha =
|
|
152
|
-
if (
|
|
153
|
-
const blendT = (
|
|
145
|
+
let cellAlpha = opacity2;
|
|
146
|
+
if (opacity2 > 0.5 * effectiveOpacity.value) {
|
|
147
|
+
const blendT = (opacity2 - 0.5 * effectiveOpacity.value) / (0.5 * effectiveOpacity.value);
|
|
154
148
|
cellColor = lerpColor(colors.base, colors.flicker, blendT);
|
|
155
|
-
cellAlpha = Math.min(1,
|
|
149
|
+
cellAlpha = Math.min(1, opacity2 + 0.2);
|
|
156
150
|
}
|
|
157
151
|
ctx.fillStyle = rgbToString(cellColor, cellAlpha);
|
|
158
152
|
ctx.fillRect(
|
|
@@ -219,9 +213,19 @@ onBeforeUnmount(() => {
|
|
|
219
213
|
resizeObserver?.disconnect();
|
|
220
214
|
intersectionObserver?.disconnect();
|
|
221
215
|
});
|
|
222
|
-
watch(
|
|
223
|
-
|
|
224
|
-
|
|
216
|
+
watch(
|
|
217
|
+
[
|
|
218
|
+
() => size,
|
|
219
|
+
() => gap,
|
|
220
|
+
() => color,
|
|
221
|
+
() => opacity,
|
|
222
|
+
() => props.dark?.color,
|
|
223
|
+
() => props.dark?.opacity
|
|
224
|
+
],
|
|
225
|
+
() => {
|
|
226
|
+
updateCanvasSize();
|
|
227
|
+
}
|
|
228
|
+
);
|
|
225
229
|
</script>
|
|
226
230
|
|
|
227
231
|
<template>
|
|
@@ -35,28 +35,43 @@ export interface FlickeringGridProps {
|
|
|
35
35
|
* - Tailwind colors: 'blue-500', 'red-600', 'slate-200', etc.
|
|
36
36
|
* - Direct values: '#3b82f6', 'oklch(0.6 0.15 250)', 'rgb(59, 130, 246)'
|
|
37
37
|
*
|
|
38
|
+
* Choose lighter shades (e.g., 'blue-200') for subtle backgrounds or darker shades (e.g., 'blue-600') for bolder effects.
|
|
39
|
+
*
|
|
38
40
|
* @example 'primary' - Nuxt UI semantic color
|
|
39
|
-
* @example 'blue-
|
|
40
|
-
* @example '
|
|
41
|
+
* @example 'blue-200' - Light Tailwind color for subtle effect
|
|
42
|
+
* @example 'blue-600' - Dark Tailwind color for bold effect
|
|
43
|
+
* @example '#e0f2fe' - Direct hex color value (light blue)
|
|
41
44
|
*
|
|
42
45
|
* @default 'neutral'
|
|
43
46
|
*/
|
|
44
47
|
color?: ColorInput;
|
|
45
48
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
49
|
+
* Opacity/visibility of the grid squares.
|
|
50
|
+
* Controls how transparent the grid appears.
|
|
51
|
+
*
|
|
52
|
+
* - 0: Completely invisible
|
|
53
|
+
* - 0.3: Subtle, background texture
|
|
54
|
+
* - 0.5: Medium visibility
|
|
55
|
+
* - 0.8: Bold, prominent
|
|
56
|
+
* - 1: Fully opaque
|
|
53
57
|
*
|
|
54
|
-
*
|
|
58
|
+
* Range: 0-1
|
|
59
|
+
*
|
|
60
|
+
* @default 0.5
|
|
55
61
|
*/
|
|
62
|
+
opacity?: number;
|
|
56
63
|
/**
|
|
57
|
-
*
|
|
64
|
+
* Dark mode overrides for color and opacity.
|
|
65
|
+
*
|
|
66
|
+
* Allows you to customize the grid appearance specifically for dark mode.
|
|
67
|
+
* Any property not specified will use the default light mode value.
|
|
68
|
+
*
|
|
69
|
+
* @example { color: 'blue-300', opacity: 0.3 }
|
|
58
70
|
*/
|
|
59
|
-
|
|
71
|
+
dark?: {
|
|
72
|
+
color?: ColorInput;
|
|
73
|
+
opacity?: number;
|
|
74
|
+
};
|
|
60
75
|
/**
|
|
61
76
|
* UI slot customization
|
|
62
77
|
*/
|
|
@@ -16,6 +16,13 @@ export declare function createOklch(l: number, c: number, h: number): string;
|
|
|
16
16
|
* Accepts any valid CSS color string
|
|
17
17
|
*/
|
|
18
18
|
export declare function adjustLightness(colorStr: string, targetLightness: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Darken a color by reducing its lightness
|
|
21
|
+
* @param colorStr - Any valid CSS color string
|
|
22
|
+
* @param amount - Amount to reduce lightness by (in percentage points, 0-100)
|
|
23
|
+
* @returns Darkened color string
|
|
24
|
+
*/
|
|
25
|
+
export declare function darkenColor(colorStr: string, amount?: number): string;
|
|
19
26
|
/**
|
|
20
27
|
* Adjust the chroma (saturation) of a color while preserving lightness and hue
|
|
21
28
|
*/
|
|
@@ -24,6 +24,16 @@ export function adjustLightness(colorStr, targetLightness) {
|
|
|
24
24
|
oklch.l = targetLightness / 100;
|
|
25
25
|
return formatCss(oklch);
|
|
26
26
|
}
|
|
27
|
+
export function darkenColor(colorStr, amount = 10) {
|
|
28
|
+
const parsed = parse(colorStr);
|
|
29
|
+
if (!parsed) return colorStr;
|
|
30
|
+
const oklch = toOklch(parsed);
|
|
31
|
+
if (!oklch || oklch.l === void 0) return colorStr;
|
|
32
|
+
const currentLightness = oklch.l * 100;
|
|
33
|
+
const newLightness = Math.max(0, currentLightness - amount);
|
|
34
|
+
oklch.l = newLightness / 100;
|
|
35
|
+
return formatCss(oklch);
|
|
36
|
+
}
|
|
27
37
|
export function adjustChroma(colorStr, targetChroma) {
|
|
28
38
|
const parsed = parse(colorStr);
|
|
29
39
|
if (!parsed) return colorStr;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-ui-elements",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A collection of beautiful, animated UI components for Nuxt applications",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/genu/nuxt-ui-elements.git",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"lint:fix": "oxlint --fix --type-aware",
|
|
56
56
|
"format": "oxfmt --write",
|
|
57
57
|
"format:check": "oxfmt --check",
|
|
58
|
-
"release": "pnpm lint && pnpm test && pnpm prepack && changelogen --release
|
|
58
|
+
"release": "pnpm lint && pnpm test && pnpm prepack && changelogen --release",
|
|
59
59
|
"test": "vitest run",
|
|
60
60
|
"test:watch": "vitest watch",
|
|
61
61
|
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|