kodeui 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +30 -2
- package/bin/kodeui.mjs +89 -0
- package/package.json +37 -4
- package/skill/kodeui/SKILL.md +105 -0
- package/skill/kodeui/assets/tokens.css +40 -0
- package/skill/kodeui/components/aurora-input/AuroraInput.tsx +153 -0
- package/skill/kodeui/components/aurora-input/aurora-input.css +218 -0
- package/skill/kodeui/components/aurora-input/index.ts +2 -0
- package/skill/kodeui/components/bloom-wall/BloomWall.tsx +90 -0
- package/skill/kodeui/components/bloom-wall/bloom-wall.css +10 -0
- package/skill/kodeui/components/bloom-wall/engine.ts +1022 -0
- package/skill/kodeui/components/bloom-wall/icons/icons-a.ts +818 -0
- package/skill/kodeui/components/bloom-wall/icons/icons-b.ts +827 -0
- package/skill/kodeui/components/bloom-wall/icons/index.ts +25 -0
- package/skill/kodeui/components/bloom-wall/icons/types.ts +8 -0
- package/skill/kodeui/components/bloom-wall/index.ts +12 -0
- package/skill/kodeui/components/bloom-wall/paint.ts +113 -0
- package/skill/kodeui/components/bloom-wall/palettes.ts +32 -0
- package/skill/kodeui/components/blur-in-text/BlurInText.tsx +53 -0
- package/skill/kodeui/components/blur-in-text/blur-in-text.css +14 -0
- package/skill/kodeui/components/blur-in-text/index.ts +2 -0
- package/skill/kodeui/components/glass-reveal/GlassReveal.tsx +108 -0
- package/skill/kodeui/components/glass-reveal/glass-reveal.css +126 -0
- package/skill/kodeui/components/glass-reveal/index.ts +2 -0
- package/skill/kodeui/components/glow-card/GlowCard.tsx +67 -0
- package/skill/kodeui/components/glow-card/glow-card.css +134 -0
- package/skill/kodeui/components/glow-card/index.ts +2 -0
- package/skill/kodeui/components/launch-chip/LaunchChip.tsx +180 -0
- package/skill/kodeui/components/launch-chip/icons.tsx +119 -0
- package/skill/kodeui/components/launch-chip/index.ts +3 -0
- package/skill/kodeui/components/launch-chip/launch-chip.css +345 -0
- package/skill/kodeui/components/ring-reveal/RingReveal.tsx +84 -0
- package/skill/kodeui/components/ring-reveal/index.ts +4 -0
- package/skill/kodeui/components/ring-reveal/ring-reveal.css +10 -0
- package/skill/kodeui/components/ring-reveal/ring.ts +298 -0
- package/skill/kodeui/components/rolling-text/RollingText.tsx +121 -0
- package/skill/kodeui/components/rolling-text/index.ts +4 -0
- package/skill/kodeui/components/rolling-text/roll.ts +94 -0
- package/skill/kodeui/components/rolling-text/rolling-text.css +43 -0
- package/skill/kodeui/components/use-live-transcript/index.ts +2 -0
- package/skill/kodeui/components/use-live-transcript/useLiveTranscript.ts +215 -0
- package/skill/kodeui/components/voice-input/VoiceInput.tsx +273 -0
- package/skill/kodeui/components/voice-input/icons.tsx +27 -0
- package/skill/kodeui/components/voice-input/index.ts +4 -0
- package/skill/kodeui/components/voice-input/useVoiceRecorder.ts +289 -0
- package/skill/kodeui/components/voice-input/voice-input.css +34 -0
- package/skill/kodeui/components/voice-note/VoiceNote.tsx +170 -0
- package/skill/kodeui/components/voice-note/index.ts +3 -0
- package/skill/kodeui/components/voice-note/noteFile.ts +25 -0
- package/skill/kodeui/components/voice-note/voice-note.css +45 -0
- package/skill/kodeui/references/aurora-input.md +44 -0
- package/skill/kodeui/references/bloom-wall.md +59 -0
- package/skill/kodeui/references/blur-in-text.md +17 -0
- package/skill/kodeui/references/frameworks.md +46 -0
- package/skill/kodeui/references/glass-reveal.md +40 -0
- package/skill/kodeui/references/glow-card.md +48 -0
- package/skill/kodeui/references/launch-chip.md +37 -0
- package/skill/kodeui/references/recipes.md +77 -0
- package/skill/kodeui/references/ring-reveal.md +35 -0
- package/skill/kodeui/references/rolling-text.md +19 -0
- package/skill/kodeui/references/theming.md +45 -0
- package/skill/kodeui/references/use-live-transcript.md +28 -0
- package/skill/kodeui/references/voice-input.md +60 -0
- package/skill/kodeui/references/voice-note.md +22 -0
- package/skill/kodeui/scripts/add.mjs +192 -0
- package/skill/kodeui/scripts/manifest.json +92 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The 16 Bloom Wall icons, in the order the wall picks them.
|
|
3
|
+
* Family: 0 = line art, 1 = pattern, 2 = solid (the wall uses it to pick which tiles linger).
|
|
4
|
+
*/
|
|
5
|
+
import { iconsA } from './icons-a';
|
|
6
|
+
import { iconsB } from './icons-b';
|
|
7
|
+
import type { IconDraw } from './types';
|
|
8
|
+
|
|
9
|
+
export type { IconDraw } from './types';
|
|
10
|
+
|
|
11
|
+
export const ICON_KINDS = [
|
|
12
|
+
'daisy', 'tree_rings', 'fireflies', 'nautilus',
|
|
13
|
+
'dandelion', 'wave', 'honeycomb', 'clover',
|
|
14
|
+
'sun', 'rain', 'crystal', 'moon',
|
|
15
|
+
'pinecone', 'ripples', 'mushroom', 'leaf',
|
|
16
|
+
] as const;
|
|
17
|
+
export type IconKind = (typeof ICON_KINDS)[number];
|
|
18
|
+
|
|
19
|
+
export const ICON_FAMILY: Record<IconKind, 0 | 1 | 2> = {
|
|
20
|
+
daisy: 0, fireflies: 0, dandelion: 0, clover: 0, sun: 0, crystal: 0,
|
|
21
|
+
tree_rings: 1, nautilus: 1, wave: 1, honeycomb: 1, rain: 1, pinecone: 1, ripples: 1, leaf: 1,
|
|
22
|
+
moon: 2, mushroom: 2,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const ICONS: Record<IconKind, IconDraw> = { ...iconsA, ...iconsB };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Tint } from '../paint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One Bloom Wall icon. Draw around (0, 0) inside radius `r`.
|
|
5
|
+
* `time` is seconds with the tile's own phase already added.
|
|
6
|
+
* `k` is the shimmer, 0..1. `t` is the palette tinted by how awake the tile is.
|
|
7
|
+
*/
|
|
8
|
+
export type IconDraw = (ctx: CanvasRenderingContext2D, r: number, time: number, k: number, t: Tint) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { BloomWall, resolveOrigin } from './BloomWall';
|
|
2
|
+
export type { BloomWallProps, BloomWallHandle, BloomOrigin } from './BloomWall';
|
|
3
|
+
export {
|
|
4
|
+
BloomEngine, NIGHT_THEME, buildLayout, packCells, pickSwellTiles, pickStragglers, swellsAt, flexBands, bandEdges,
|
|
5
|
+
shimmerAt, wakeAt, calmAt, swellEnvelope, ringCover, foldCover, quietFade, readTable, popIn, foldOut, restingMotion,
|
|
6
|
+
CELL_PX, SWELL_PX, SWELL_SECONDS, RING_SECONDS, RING_SECONDS_AGAIN, POP_SECONDS, POP_SPREAD, FOLD_SECONDS,
|
|
7
|
+
} from './engine';
|
|
8
|
+
export type { BloomEngineOptions, BloomState, BloomTheme, Layout, Tile, Block, TileMotion, Swell } from './engine';
|
|
9
|
+
export { NATURE_PALETTES, SLEEP_GREY } from './palettes';
|
|
10
|
+
export type { Palette } from './palettes';
|
|
11
|
+
export { ICONS, ICON_KINDS, ICON_FAMILY } from './icons';
|
|
12
|
+
export type { IconKind, IconDraw } from './icons';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Maths and colour helpers shared by the Bloom Wall engine and its 16 icons.
|
|
3
|
+
*
|
|
4
|
+
* The easing curves and the two hash functions are fixed on purpose: the hashes
|
|
5
|
+
* decide where every tile goes, so the same canvas size always gives the same wall.
|
|
6
|
+
*/
|
|
7
|
+
import type { Palette, RGB } from './palettes';
|
|
8
|
+
|
|
9
|
+
export const TAU = Math.PI * 2;
|
|
10
|
+
export const clamp = (v: number, lo: number, hi: number) => (v < lo ? lo : v > hi ? hi : v);
|
|
11
|
+
export const clamp01 = (v: number) => clamp(v, 0, 1);
|
|
12
|
+
export const smoothstep = (e0: number, e1: number, x: number) => {
|
|
13
|
+
const t = clamp01((x - e0) / (e1 - e0));
|
|
14
|
+
return t * t * (3 - 2 * t);
|
|
15
|
+
};
|
|
16
|
+
export const smootherstep = (x: number) => {
|
|
17
|
+
const t = clamp01(x);
|
|
18
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
19
|
+
};
|
|
20
|
+
export const easeOutCubic = (x: number) => 1 - Math.pow(1 - clamp01(x), 3);
|
|
21
|
+
export const easeInOutCubic = (x: number) => {
|
|
22
|
+
const t = clamp01(x);
|
|
23
|
+
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
24
|
+
};
|
|
25
|
+
export const easeInOutQuart = (x: number) => {
|
|
26
|
+
const t = clamp01(x);
|
|
27
|
+
return t < 0.5 ? 8 * t * t * t * t : 1 - Math.pow(-2 * t + 2, 4) / 2;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Two cheap deterministic hashes, 0..1. */
|
|
31
|
+
export const hashA = (x: number) => { const v = Math.sin(x * 12.9898 + 78.233) * 43758.5453; return v - Math.floor(v); };
|
|
32
|
+
export const hashB = (x: number) => { const v = Math.sin(x * 127.1 + 311.7) * 43758.5453123; return v - Math.floor(v); };
|
|
33
|
+
|
|
34
|
+
export const hexRGB = (h: string): RGB => { const n = parseInt(h.slice(1), 16); return [(n >> 16) & 255, (n >> 8) & 255, n & 255]; };
|
|
35
|
+
export const rgbHex = (c: RGB) => '#' + ((1 << 24) | (c[0] << 16) | (c[1] << 8) | c[2]).toString(16).slice(1);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A palette tinted by how awake a tile is: 0 = the sleeping grey, 1 = full colour.
|
|
39
|
+
* `ramp` holds 6 colours: 0..4 run primary -> secondary, 5 is the glow colour.
|
|
40
|
+
*/
|
|
41
|
+
export interface Tint {
|
|
42
|
+
colors: { primary: string; secondary: string; accent: string };
|
|
43
|
+
/** 0..1, how strong the halo behind an icon may be */
|
|
44
|
+
haloStrength: number;
|
|
45
|
+
ramp: RGB[];
|
|
46
|
+
/** rgba() strings, cached per ramp index and alpha step */
|
|
47
|
+
cache: (string | undefined)[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Tinter {
|
|
51
|
+
(paletteIndex: number, saturation: number): Tint;
|
|
52
|
+
palettes: readonly Palette[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Makes a tint lookup for a set of palettes. 13 saturation steps, cached. */
|
|
56
|
+
export function createTinter(palettes: readonly Palette[], grey: Palette): Tinter {
|
|
57
|
+
const cache: Tint[] = [];
|
|
58
|
+
const g = { p: hexRGB(grey.primary), s: hexRGB(grey.secondary), a: hexRGB(grey.accent), glow: hexRGB(grey.glow) };
|
|
59
|
+
const rgb = palettes.map((p) => ({ p: hexRGB(p.primary), s: hexRGB(p.secondary), a: hexRGB(p.accent), glow: hexRGB(p.glow) }));
|
|
60
|
+
const tint = ((paletteIndex: number, saturation: number) => {
|
|
61
|
+
const step = Math.round(clamp01(saturation) * 12);
|
|
62
|
+
const key = paletteIndex * 13 + step;
|
|
63
|
+
const hit = cache[key];
|
|
64
|
+
if (hit) return hit;
|
|
65
|
+
const c = rgb[paletteIndex];
|
|
66
|
+
const u = step / 12;
|
|
67
|
+
const mix = (from: RGB, to: RGB): RGB => [0, 1, 2].map((i) => Math.round(to[i] + (from[i] - to[i]) * u)) as RGB;
|
|
68
|
+
const prim = mix(c.p, g.p);
|
|
69
|
+
const sec = mix(c.s, g.s);
|
|
70
|
+
const acc = mix(c.a, g.a);
|
|
71
|
+
const glow = mix(c.glow, g.glow);
|
|
72
|
+
const p = palettes[paletteIndex];
|
|
73
|
+
const colors = u >= 1
|
|
74
|
+
? { primary: p.primary, secondary: p.secondary, accent: p.accent }
|
|
75
|
+
: { primary: rgbHex(prim), secondary: rgbHex(sec), accent: rgbHex(acc) };
|
|
76
|
+
const ramp: RGB[] = [];
|
|
77
|
+
for (let i = 0; i < 6; i++) {
|
|
78
|
+
ramp.push(i === 5 ? glow : ([0, 1, 2].map((k) => Math.round(prim[k] + (sec[k] - prim[k]) * (i / 4))) as RGB));
|
|
79
|
+
}
|
|
80
|
+
return (cache[key] = { colors, haloStrength: u * u, ramp, cache: new Array(6 * 33) });
|
|
81
|
+
}) as Tinter;
|
|
82
|
+
tint.palettes = palettes;
|
|
83
|
+
return tint;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Ramp colour `index` (0..5) at `alpha`, as a cached rgba() string. */
|
|
87
|
+
export function rampColor(t: Tint, index: number, alpha: number): string {
|
|
88
|
+
const a = Math.round(clamp01(alpha) * 32);
|
|
89
|
+
const key = index * 33 + a;
|
|
90
|
+
const hit = t.cache[key];
|
|
91
|
+
if (hit !== undefined) return hit;
|
|
92
|
+
const c = t.ramp[index];
|
|
93
|
+
return (t.cache[key] = `rgba(${c[0]},${c[1]},${c[2]},${(a / 32).toFixed(4)})`);
|
|
94
|
+
}
|
|
95
|
+
/** Colour along the primary -> secondary ramp, pos 0..1. */
|
|
96
|
+
export const grad = (t: Tint, pos: number, alpha: number) => rampColor(t, Math.round(clamp01(pos) * 4), alpha);
|
|
97
|
+
/** Draw in 4 alpha bands (4 strokes) instead of hundreds of separate ones. */
|
|
98
|
+
export const bucket = (v: number) => Math.min(3, Math.floor(clamp01(v) * 4));
|
|
99
|
+
|
|
100
|
+
/** The soft glow disc behind an icon. Scales with how awake the tile is. */
|
|
101
|
+
export function halo(ctx: CanvasRenderingContext2D, r: number, t: Tint, k: number, strength = 0.24) {
|
|
102
|
+
const e = strength * t.haloStrength;
|
|
103
|
+
if (e < 0.01) return;
|
|
104
|
+
const outer = r * (1.28 + 0.1 * k);
|
|
105
|
+
const g = ctx.createRadialGradient(0, 0, r * 0.08, 0, 0, outer);
|
|
106
|
+
g.addColorStop(0, rampColor(t, 5, e * (0.78 + 0.34 * k)));
|
|
107
|
+
g.addColorStop(0.55, grad(t, 1, e * 0.36 * (0.8 + 0.25 * k)));
|
|
108
|
+
g.addColorStop(1, rampColor(t, 5, 0));
|
|
109
|
+
ctx.fillStyle = g;
|
|
110
|
+
ctx.beginPath();
|
|
111
|
+
ctx.arc(0, 0, outer, 0, TAU);
|
|
112
|
+
ctx.fill();
|
|
113
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The six Bloom Wall palettes: lights you find in nature at night.
|
|
3
|
+
* Each tile gets one, never the same as its neighbour.
|
|
4
|
+
*/
|
|
5
|
+
export type RGB = [number, number, number];
|
|
6
|
+
|
|
7
|
+
export interface Palette {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
/** main line / fill colour */
|
|
11
|
+
primary: string;
|
|
12
|
+
/** the colour the ramp runs to */
|
|
13
|
+
secondary: string;
|
|
14
|
+
/** small details */
|
|
15
|
+
accent: string;
|
|
16
|
+
/** the halo and outline glow */
|
|
17
|
+
glow: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const NATURE_PALETTES: readonly Palette[] = [
|
|
21
|
+
{ id: 'firefly', name: 'Firefly', primary: '#e4f56a', secondary: '#7df09a', accent: '#ffb547', glow: '#dcf266' },
|
|
22
|
+
{ id: 'plankton', name: 'Plankton', primary: '#4df0e0', secondary: '#3a8dff', accent: '#7a86ff', glow: '#48e6e0' },
|
|
23
|
+
{ id: 'aurora', name: 'Aurora', primary: '#6bffb0', secondary: '#9b87f5', accent: '#4dd8ff', glow: '#66f7ae' },
|
|
24
|
+
{ id: 'coral-reef', name: 'Coral reef', primary: '#ff6b6b', secondary: '#ffb48a', accent: '#ff5fa2', glow: '#ff7a72' },
|
|
25
|
+
{ id: 'foxfire', name: 'Foxfire', primary: '#a6ff5c', secondary: '#33ddbf', accent: '#e8ff7a', glow: '#9ef95a' },
|
|
26
|
+
{ id: 'dusk-bloom', name: 'Dusk bloom', primary: '#ff8fc8', secondary: '#ffd27a', accent: '#8f7bff', glow: '#ff96c6' },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/** What a sleeping tile fades to: a moss grey. */
|
|
30
|
+
export const SLEEP_GREY: Palette = {
|
|
31
|
+
id: 'moss-grey', name: 'Moss grey', primary: '#d2d6d3', secondary: '#9aa09c', accent: '#5c625e', glow: '#bac0bc',
|
|
32
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { forwardRef, type CSSProperties, type ElementType, type HTMLAttributes } from 'react';
|
|
2
|
+
import './blur-in-text.css';
|
|
3
|
+
|
|
4
|
+
export interface BlurInTextProps extends Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
5
|
+
/** The words to show. Split on whitespace; each word fades in on its own. */
|
|
6
|
+
text: string;
|
|
7
|
+
/** Element to render, e.g. 'h1' or 'h2'. Default 'span'. */
|
|
8
|
+
as?: ElementType;
|
|
9
|
+
/** Seconds between one word and the next. Default 0.08. */
|
|
10
|
+
stagger?: number;
|
|
11
|
+
/** Seconds each word takes to arrive. Default 0.5. */
|
|
12
|
+
duration?: number;
|
|
13
|
+
/** Starting blur in px. Default 10. */
|
|
14
|
+
blur?: number;
|
|
15
|
+
/** Seconds before the first word starts. Default 0. */
|
|
16
|
+
delay?: number;
|
|
17
|
+
className?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Vars = CSSProperties & Record<`--${string}`, string>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A line of text whose words arrive one after another, each fading up out of a blur.
|
|
25
|
+
* Pure CSS: the animation runs once on mount, so remount it (change its `key`) to play it again.
|
|
26
|
+
* With "reduce motion" on, the text is simply there.
|
|
27
|
+
*/
|
|
28
|
+
export const BlurInText = forwardRef<HTMLElement, BlurInTextProps>(function BlurInText(
|
|
29
|
+
{ text, as, stagger = 0.08, duration = 0.5, blur = 10, delay = 0, className, style, ...rest },
|
|
30
|
+
ref,
|
|
31
|
+
) {
|
|
32
|
+
const Tag: ElementType = as ?? 'span';
|
|
33
|
+
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
34
|
+
const vars: Vars = {
|
|
35
|
+
...style,
|
|
36
|
+
'--ku-blur-in-blur': `${blur}px`,
|
|
37
|
+
'--ku-blur-in-duration': `${duration}s`,
|
|
38
|
+
};
|
|
39
|
+
return (
|
|
40
|
+
<Tag ref={ref} className={className ? `ku-blur-in ${className}` : 'ku-blur-in'} style={vars} {...rest}>
|
|
41
|
+
{words.map((word, i) => (
|
|
42
|
+
<span key={i} className="ku-blur-in__word" style={{ animationDelay: `${round(delay + i * stagger)}s` }}>
|
|
43
|
+
{i < words.length - 1 ? `${word} ` : word}
|
|
44
|
+
</span>
|
|
45
|
+
))}
|
|
46
|
+
</Tag>
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** Keep delays tidy (0.24 instead of 0.24000000000000002). */
|
|
51
|
+
function round(n: number) {
|
|
52
|
+
return Math.round(n * 10000) / 10000;
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* Blur-in Text: each word fades up out of a blur, one after another. */
|
|
2
|
+
.ku-blur-in__word {
|
|
3
|
+
opacity: 0;
|
|
4
|
+
animation: ku-blur-in-word var(--ku-blur-in-duration, .5s) ease-out forwards;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
@keyframes ku-blur-in-word {
|
|
8
|
+
from { opacity: 0; filter: blur(var(--ku-blur-in-blur, 10px)); }
|
|
9
|
+
to { opacity: 1; filter: blur(0); }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@media (prefers-reduced-motion: reduce) {
|
|
13
|
+
.ku-blur-in__word { opacity: 1; filter: none; animation: none; }
|
|
14
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createElement,
|
|
3
|
+
forwardRef,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
type CSSProperties,
|
|
8
|
+
type ElementType,
|
|
9
|
+
type ForwardRefExoticComponent,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
type RefAttributes,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import './glass-reveal.css';
|
|
14
|
+
|
|
15
|
+
export type GlassMode = 'active' | 'fading' | 'off';
|
|
16
|
+
|
|
17
|
+
/** Seconds the wrapper stays "fading" after `active` turns false (the slowest layer ends at 2.5 s). */
|
|
18
|
+
export const GLASS_FADE_SECONDS = 2.65;
|
|
19
|
+
|
|
20
|
+
export interface GlassRevealProps {
|
|
21
|
+
/** true = every Glass inside turns to frosted glass; false = it settles back slowly. */
|
|
22
|
+
active: boolean;
|
|
23
|
+
/** 1 = real time. Scales the fading timer (CSS transitions are slowed by playbackRate). */
|
|
24
|
+
timeScale?: number;
|
|
25
|
+
as?: ElementType;
|
|
26
|
+
className?: string;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
/** Called after the wrapper switches between 'active', 'fading' and 'off'. */
|
|
30
|
+
onModeChange?: (mode: GlassMode) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Wraps a piece of UI that should turn to glass while something glows behind it.
|
|
35
|
+
* Sets data-glass="active" | "fading" | "off" and the stagger timings for the Glass
|
|
36
|
+
* surfaces inside it. Put the moving background behind this wrapper.
|
|
37
|
+
*/
|
|
38
|
+
export const GlassReveal = forwardRef<HTMLElement, GlassRevealProps>(function GlassReveal(
|
|
39
|
+
{ active, timeScale = 1, as = 'div', className, style, children, onModeChange },
|
|
40
|
+
ref,
|
|
41
|
+
) {
|
|
42
|
+
// "fading" starts the moment active turns false, in the same render
|
|
43
|
+
const [fading, setFading] = useState(false);
|
|
44
|
+
const [wasActive, setWasActive] = useState(active);
|
|
45
|
+
if (wasActive !== active) {
|
|
46
|
+
setWasActive(active);
|
|
47
|
+
setFading(!active);
|
|
48
|
+
}
|
|
49
|
+
const mode: GlassMode = active ? 'active' : fading ? 'fading' : 'off';
|
|
50
|
+
|
|
51
|
+
// the fade clock counts study seconds, so a speed change mid-fade keeps its place
|
|
52
|
+
const fadeDone = useRef(0);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (mode !== 'fading') {
|
|
55
|
+
fadeDone.current = 0;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const scale = timeScale > 0 ? timeScale : 1;
|
|
59
|
+
const startedAt = performance.now();
|
|
60
|
+
const left = Math.max(0, GLASS_FADE_SECONDS - fadeDone.current) * 1000 / scale;
|
|
61
|
+
const timer = window.setTimeout(() => setFading(false), left);
|
|
62
|
+
return () => {
|
|
63
|
+
window.clearTimeout(timer);
|
|
64
|
+
fadeDone.current += ((performance.now() - startedAt) / 1000) * scale;
|
|
65
|
+
};
|
|
66
|
+
}, [mode, timeScale]);
|
|
67
|
+
|
|
68
|
+
const onMode = useRef(onModeChange);
|
|
69
|
+
onMode.current = onModeChange;
|
|
70
|
+
const firstMode = useRef(true);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (firstMode.current) { firstMode.current = false; return; }
|
|
73
|
+
onMode.current?.(mode);
|
|
74
|
+
}, [mode]);
|
|
75
|
+
|
|
76
|
+
return createElement(
|
|
77
|
+
as,
|
|
78
|
+
{ ref, className: className ? `ku-glass-reveal ${className}` : 'ku-glass-reveal', 'data-glass': mode, style },
|
|
79
|
+
children,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The look a surface takes on as glass:
|
|
85
|
+
* chip (blur 20), button (blur 18), pill (blur 16), panel (blur 22), link (blur 14) are frosted surfaces;
|
|
86
|
+
* tile only tints; text and heading only change ink and gain a dark halo.
|
|
87
|
+
*/
|
|
88
|
+
export type GlassKind = 'chip' | 'button' | 'pill' | 'panel' | 'link' | 'tile' | 'text' | 'heading';
|
|
89
|
+
|
|
90
|
+
const DEFAULT_KIND: Record<1 | 2 | 3 | 4, GlassKind> = { 1: 'chip', 2: 'pill', 3: 'pill', 4: 'panel' };
|
|
91
|
+
|
|
92
|
+
export type GlassProps = {
|
|
93
|
+
/** Which stagger slot: 1 turns first (0.40 s in, 1.1 s back) ... 4 last (0.56 s in, 2.5 s back). */
|
|
94
|
+
step: 1 | 2 | 3 | 4;
|
|
95
|
+
/** The glass recipe. Default by step: 1 chip, 2 pill, 3 pill, 4 panel. */
|
|
96
|
+
kind?: GlassKind;
|
|
97
|
+
as?: ElementType;
|
|
98
|
+
className?: string;
|
|
99
|
+
children?: ReactNode;
|
|
100
|
+
} & Record<string, unknown>;
|
|
101
|
+
|
|
102
|
+
/** A surface inside a GlassReveal. Every other prop goes on the element (or the component in `as`). */
|
|
103
|
+
export const Glass = forwardRef<HTMLElement, GlassProps>(function Glass(props, ref) {
|
|
104
|
+
const { step, kind, as = 'div', className, children, ...rest } = props as GlassProps;
|
|
105
|
+
const k = kind ?? DEFAULT_KIND[step] ?? 'pill';
|
|
106
|
+
const cls = `ku-glass ku-glass--${k} ku-glass--t${step}` + (className ? ` ${className}` : '');
|
|
107
|
+
return createElement(as, { ...rest, ref, className: cls }, children as ReactNode);
|
|
108
|
+
}) as ForwardRefExoticComponent<GlassProps & RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* KodeUI Glass Reveal
|
|
3
|
+
* data-glass="active": every Glass surface turns to frosted glass, one stagger slot after
|
|
4
|
+
* another (t1 .40 s, t2 .46 s, t3 .52 s, t4 .56 s), its text brightening a moment later.
|
|
5
|
+
* data-glass="fading" (2.65 s after active ends): the same, slowly back (t1 1.1 s ... t4 2.5 s).
|
|
6
|
+
* data-glass="off": the surfaces' own look, untouched.
|
|
7
|
+
* The starting look is the element's own background-color, border-color, box-shadow and color.
|
|
8
|
+
*/
|
|
9
|
+
.ku-glass-reveal { --ku-glass-ease: var(--ku-ease-out, cubic-bezier(.22, 1, .36, 1)); }
|
|
10
|
+
|
|
11
|
+
.ku-glass-reveal[data-glass='active'] {
|
|
12
|
+
--ku-glass-t1: .4s; --ku-glass-t2: .46s; --ku-glass-t3: .52s; --ku-glass-t4: .56s;
|
|
13
|
+
--ku-glass-halo-delay: 0s; --ku-glass-halo-dur: .45s;
|
|
14
|
+
--ku-glass-ink-t1: .08s; --ku-glass-ink-t2: .1s; --ku-glass-ink-t3: .12s; --ku-glass-ink-t4: .14s;
|
|
15
|
+
--ku-glass-prompt-ink-delay: 0s; --ku-glass-prompt-ink-dur: .42s;
|
|
16
|
+
|
|
17
|
+
/* the page's ink brightens while the glass is up */
|
|
18
|
+
--ku-text: #f4f8f5;
|
|
19
|
+
--ku-text-2: rgba(222, 234, 227, .78);
|
|
20
|
+
--ku-link: #a6f5cf;
|
|
21
|
+
--ku-outline: rgba(255, 255, 255, .08);
|
|
22
|
+
}
|
|
23
|
+
.ku-glass-reveal[data-glass='fading'] {
|
|
24
|
+
--ku-glass-t1: 1.1s; --ku-glass-t2: 1.6s; --ku-glass-t3: 2.1s; --ku-glass-t4: 2.5s;
|
|
25
|
+
--ku-glass-halo-delay: .55s; --ku-glass-halo-dur: 1.8s;
|
|
26
|
+
--ku-glass-ink-t1: .5s; --ku-glass-ink-t2: .72s; --ku-glass-ink-t3: .95s; --ku-glass-ink-t4: 1.225s;
|
|
27
|
+
--ku-glass-prompt-ink-delay: .25s; --ku-glass-prompt-ink-dur: 1.35s;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* which stagger slot a surface uses */
|
|
31
|
+
.ku-glass--t1 { --ku-glass-t: var(--ku-glass-t1); --ku-glass-ink: var(--ku-glass-ink-t1); }
|
|
32
|
+
.ku-glass--t2 { --ku-glass-t: var(--ku-glass-t2); --ku-glass-ink: var(--ku-glass-ink-t2); }
|
|
33
|
+
.ku-glass--t3 { --ku-glass-t: var(--ku-glass-t3); --ku-glass-ink: var(--ku-glass-ink-t3); }
|
|
34
|
+
.ku-glass--t4 { --ku-glass-t: var(--ku-glass-t4); --ku-glass-ink: var(--ku-glass-ink-t4); }
|
|
35
|
+
|
|
36
|
+
/* ---------------------------------------------------------------- while active or fading */
|
|
37
|
+
.ku-glass-reveal:is([data-glass='active'], [data-glass='fading']) :is(.ku-glass--chip, .ku-glass--button, .ku-glass--pill, .ku-glass--panel, .ku-glass--link) {
|
|
38
|
+
background-image: linear-gradient(155deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .03) 45%, rgba(255, 255, 255, .01));
|
|
39
|
+
-webkit-backdrop-filter: blur(0) saturate(100%);
|
|
40
|
+
backdrop-filter: blur(0) saturate(100%);
|
|
41
|
+
}
|
|
42
|
+
.ku-glass-reveal:is([data-glass='active'], [data-glass='fading']) :is(.ku-glass--chip, .ku-glass--button, .ku-glass--pill) {
|
|
43
|
+
transition:
|
|
44
|
+
background-color var(--ku-glass-t) var(--ku-glass-ease), border-color var(--ku-glass-t) var(--ku-glass-ease),
|
|
45
|
+
box-shadow var(--ku-glass-t) var(--ku-glass-ease), color .22s var(--ku-glass-ease) var(--ku-glass-ink),
|
|
46
|
+
backdrop-filter var(--ku-glass-t) var(--ku-glass-ease), -webkit-backdrop-filter var(--ku-glass-t) var(--ku-glass-ease);
|
|
47
|
+
}
|
|
48
|
+
.ku-glass-reveal:is([data-glass='active'], [data-glass='fading']) .ku-glass--panel {
|
|
49
|
+
transition:
|
|
50
|
+
background-color var(--ku-glass-t) var(--ku-glass-ease), border-color var(--ku-glass-t) var(--ku-glass-ease),
|
|
51
|
+
box-shadow var(--ku-glass-t) var(--ku-glass-ease),
|
|
52
|
+
backdrop-filter var(--ku-glass-t) var(--ku-glass-ease), -webkit-backdrop-filter var(--ku-glass-t) var(--ku-glass-ease);
|
|
53
|
+
}
|
|
54
|
+
.ku-glass-reveal:is([data-glass='active'], [data-glass='fading']) .ku-glass--link {
|
|
55
|
+
transition:
|
|
56
|
+
background-color var(--ku-glass-t) var(--ku-glass-ease), border-color var(--ku-glass-t) var(--ku-glass-ease),
|
|
57
|
+
color .22s var(--ku-glass-ease) var(--ku-glass-ink),
|
|
58
|
+
backdrop-filter var(--ku-glass-t) var(--ku-glass-ease), -webkit-backdrop-filter var(--ku-glass-t) var(--ku-glass-ease);
|
|
59
|
+
}
|
|
60
|
+
.ku-glass-reveal:is([data-glass='active'], [data-glass='fading']) .ku-glass--tile {
|
|
61
|
+
transition: background-color var(--ku-glass-t) var(--ku-glass-ease), border-color var(--ku-glass-t) var(--ku-glass-ease);
|
|
62
|
+
}
|
|
63
|
+
.ku-glass-reveal:is([data-glass='active'], [data-glass='fading']) :is(.ku-glass--text, .ku-glass--heading) {
|
|
64
|
+
transition: color .22s var(--ku-glass-ease) var(--ku-glass-ink), text-shadow .22s var(--ku-glass-ease) var(--ku-glass-ink);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* ---------------------------------------------------------------- the glass itself (active only) */
|
|
68
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--chip {
|
|
69
|
+
-webkit-backdrop-filter: blur(20px) saturate(145%);
|
|
70
|
+
backdrop-filter: blur(20px) saturate(145%);
|
|
71
|
+
background-color: rgba(25, 38, 32, .74);
|
|
72
|
+
border-color: rgba(255, 255, 255, .1);
|
|
73
|
+
color: #f6faf7;
|
|
74
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .32), inset 1px 0 0 rgba(255, 255, 255, .05), inset 0 -1px 0 rgba(0, 0, 0, .26), 0 12px 32px -6px rgba(0, 0, 0, .56);
|
|
75
|
+
}
|
|
76
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--chip:hover { background-color: rgba(37, 52, 45, .82); }
|
|
77
|
+
|
|
78
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--button {
|
|
79
|
+
-webkit-backdrop-filter: blur(18px) saturate(140%);
|
|
80
|
+
backdrop-filter: blur(18px) saturate(140%);
|
|
81
|
+
background-color: rgba(33, 48, 41, .68);
|
|
82
|
+
border-color: rgba(255, 255, 255, .1);
|
|
83
|
+
color: #f4f8f5;
|
|
84
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .32), inset 1px 0 0 rgba(255, 255, 255, .05), inset 0 -1px 0 rgba(0, 0, 0, .26), 0 12px 36px rgba(0, 0, 0, .44);
|
|
85
|
+
}
|
|
86
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--button:hover { background-color: rgba(47, 63, 56, .78); border-color: rgba(255, 255, 255, .18); }
|
|
87
|
+
|
|
88
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--pill {
|
|
89
|
+
-webkit-backdrop-filter: blur(16px) saturate(140%);
|
|
90
|
+
backdrop-filter: blur(16px) saturate(140%);
|
|
91
|
+
background-color: rgba(35, 50, 43, .84);
|
|
92
|
+
border-color: rgba(255, 255, 255, .09);
|
|
93
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), inset 1px 0 0 rgba(255, 255, 255, .05), inset 0 18px 22px -16px rgba(255, 255, 255, .09), inset 0 -1px 0 rgba(0, 0, 0, .26), 0 10px 28px rgba(0, 0, 0, .42);
|
|
94
|
+
}
|
|
95
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--pill:hover { background-color: rgba(49, 65, 58, .9); border-color: rgba(255, 255, 255, .18); }
|
|
96
|
+
|
|
97
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--panel {
|
|
98
|
+
-webkit-backdrop-filter: blur(22px) saturate(140%);
|
|
99
|
+
backdrop-filter: blur(22px) saturate(140%);
|
|
100
|
+
background-color: rgba(21, 32, 26, .76);
|
|
101
|
+
border-color: rgba(255, 255, 255, .08);
|
|
102
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), inset 1px 0 0 rgba(255, 255, 255, .04), inset 0 -1px 0 rgba(0, 0, 0, .26), 0 12px 36px rgba(0, 0, 0, .44);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--link {
|
|
106
|
+
-webkit-backdrop-filter: blur(14px) saturate(140%);
|
|
107
|
+
backdrop-filter: blur(14px) saturate(140%);
|
|
108
|
+
background-color: rgba(255, 255, 255, .09);
|
|
109
|
+
border-color: rgba(255, 255, 255, .1);
|
|
110
|
+
color: #f4f8f5;
|
|
111
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), inset 0 -1px 0 rgba(0, 0, 0, .24);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--tile {
|
|
115
|
+
background-color: rgba(29, 42, 36, .44);
|
|
116
|
+
border-color: rgba(255, 255, 255, .06);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--text {
|
|
120
|
+
color: #f4f8f5;
|
|
121
|
+
text-shadow: 0 2px 18px rgba(0, 0, 0, .88), 0 0 36px rgba(0, 0, 0, .74), 0 0 1px rgba(255, 255, 255, .22);
|
|
122
|
+
}
|
|
123
|
+
.ku-glass-reveal[data-glass='active'] .ku-glass--heading {
|
|
124
|
+
color: #f4f8f5;
|
|
125
|
+
text-shadow: 0 1px 12px rgba(0, 0, 0, .72);
|
|
126
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createElement, forwardRef, type CSSProperties, type ForwardRefExoticComponent, type ReactNode, type RefAttributes } from 'react';
|
|
2
|
+
import './glow-card.css';
|
|
3
|
+
|
|
4
|
+
export type GlowCardColors = [string, string, string, string];
|
|
5
|
+
|
|
6
|
+
export interface GlowCardProps {
|
|
7
|
+
/** The clickable element inside the glowing frame. Default 'button'. */
|
|
8
|
+
as?: 'button' | 'a' | 'div';
|
|
9
|
+
/** The four lights, in the order they run round the border. Default lagoon, fern, amber, coral. */
|
|
10
|
+
colors?: GlowCardColors;
|
|
11
|
+
/** Seconds per turn at rest. Default 40. */
|
|
12
|
+
spin?: number;
|
|
13
|
+
/** Seconds per turn while hovered. Default 8. */
|
|
14
|
+
hoverSpin?: number;
|
|
15
|
+
/** Outer corner radius in px. Default 16 (the body gets radius - 1). */
|
|
16
|
+
radius?: number;
|
|
17
|
+
/** Show the hover look without a pointer (screenshots, a selected card). */
|
|
18
|
+
hovered?: boolean;
|
|
19
|
+
/** Goes on the outer frame. */
|
|
20
|
+
className?: string;
|
|
21
|
+
/** Goes on the outer frame. */
|
|
22
|
+
style?: CSSProperties;
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
/** Every other attribute (onClick, href, aria-*, type...) goes on the inner element. */
|
|
25
|
+
[attr: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A card with a slow light running round its 1 px border and a soft glow of the same
|
|
30
|
+
* light behind it. On hover the lights go from half to full strength (0.6 s), the glow
|
|
31
|
+
* grows, and the light spins five times faster.
|
|
32
|
+
*
|
|
33
|
+
* The ref points at the inner element (the button, link or div).
|
|
34
|
+
*/
|
|
35
|
+
export const GlowCard = forwardRef<HTMLElement, GlowCardProps>(function GlowCard(props, ref) {
|
|
36
|
+
// (forwardRef's prop type drops named props when there is an index signature, so read them as declared)
|
|
37
|
+
const { as = 'button', colors, spin, hoverSpin, radius, hovered, className, style, children, ...rest } = props as GlowCardProps;
|
|
38
|
+
|
|
39
|
+
const vars: Record<string, string> = {};
|
|
40
|
+
if (colors) colors.forEach((c, i) => { vars[`--ku-glow-card-${i + 1}`] = c; });
|
|
41
|
+
if (spin != null && spin > 0) vars['--ku-glow-card-spin'] = `${spin}s`;
|
|
42
|
+
if (hoverSpin != null && hoverSpin > 0) vars['--ku-glow-card-hover-spin'] = `${hoverSpin}s`;
|
|
43
|
+
if (radius != null) vars['--ku-glow-card-radius'] = `${radius}px`;
|
|
44
|
+
|
|
45
|
+
const inner: Record<string, unknown> = { ...rest, ref, className: 'ku-glow-card__body' };
|
|
46
|
+
if (as === 'button' && inner.type == null) inner.type = 'button';
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div
|
|
50
|
+
className={className ? `ku-glow-card ${className}` : 'ku-glow-card'}
|
|
51
|
+
data-hover={hovered ? '' : undefined}
|
|
52
|
+
style={{ ...(vars as CSSProperties), ...style }}
|
|
53
|
+
>
|
|
54
|
+
{createElement(as, inner, children)}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}) as ForwardRefExoticComponent<GlowCardProps & RefAttributes<HTMLElement>>;
|
|
58
|
+
|
|
59
|
+
/** The card's first line: 12 px, medium. */
|
|
60
|
+
export function GlowCardTitle({ children, className }: { children?: ReactNode; className?: string }) {
|
|
61
|
+
return <span className={className ? `ku-glow-card__title ${className}` : 'ku-glow-card__title'}>{children}</span>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The card's quieter line under the title. */
|
|
65
|
+
export function GlowCardText({ children, className }: { children?: ReactNode; className?: string }) {
|
|
66
|
+
return <span className={className ? `ku-glow-card__text ${className}` : 'ku-glow-card__text'}>{children}</span>;
|
|
67
|
+
}
|