@crossworks/share-ui 0.300.143 → 0.400.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/package.json +8 -7
- package/src/app-frame-html.test.ts +4 -7
- package/src/app-frame-html.ts +16 -13
- package/src/appearance-fresh-look.test.ts +4 -4
- package/src/appearance.ts +4 -4
- package/src/canvas-frame-html.test.ts +207 -0
- package/src/canvas-frame-html.ts +257 -0
- package/src/canvas-sandbox.tsx +264 -0
- package/src/drift/color.ts +112 -0
- package/src/drift/drift.test.ts +243 -0
- package/src/drift/engine.test.ts +200 -0
- package/src/drift/engine.ts +783 -0
- package/src/drift/index.ts +32 -0
- package/src/drift/options.ts +160 -0
- package/src/drift/shaders.ts +350 -0
- package/src/drift/spec.ts +77 -0
- package/src/drift/theme.ts +152 -0
- package/src/drift-mount.ts +77 -0
- package/src/help-topics.ts +1 -0
- package/src/nav-items.ts +2 -0
- package/src/note-presenter.test.ts +20 -0
- package/src/note-presenter.tsx +15 -4
- package/src/neat-background.test.ts +0 -58
- package/src/neat-background.ts +0 -249
- package/src/neat-mount.ts +0 -82
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { TIME_FOLD, createDrift, foldTime, type DriftHandle, type DriftStats } from './engine';
|
|
2
|
+
export {
|
|
3
|
+
DRIFT_DEFAULTS,
|
|
4
|
+
DRIFT_MAX_COLORS,
|
|
5
|
+
DRIFT_STYLES,
|
|
6
|
+
DRIFT_STYLE_RESOLUTION,
|
|
7
|
+
normalizeDriftOptions,
|
|
8
|
+
type DriftColor,
|
|
9
|
+
type DriftOptions,
|
|
10
|
+
type DriftStyle,
|
|
11
|
+
} from './options';
|
|
12
|
+
export {
|
|
13
|
+
DRIFT_SPEC_DEFAULTS,
|
|
14
|
+
DRIFT_SPEC_MAX,
|
|
15
|
+
DRIFT_SPEED_MAX,
|
|
16
|
+
decodeDriftSpec,
|
|
17
|
+
driftOptionsFromSpec,
|
|
18
|
+
encodeDriftSpec,
|
|
19
|
+
randomDriftSpec,
|
|
20
|
+
readDriftSurface,
|
|
21
|
+
type DriftSpec,
|
|
22
|
+
type DriftSurface,
|
|
23
|
+
} from './spec';
|
|
24
|
+
export {
|
|
25
|
+
DRIFT_TEXT_FLOOR,
|
|
26
|
+
contrastRatio,
|
|
27
|
+
driftPaletteFromTheme,
|
|
28
|
+
readDriftThemeTokens,
|
|
29
|
+
type DriftPaletteSource,
|
|
30
|
+
type DriftThemeTokens,
|
|
31
|
+
type DriftTone,
|
|
32
|
+
} from './theme';
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drift's option contract — everything a caller can say about a background,
|
|
3
|
+
* with the ranges and defaults in one place so the engine, the React shell,
|
|
4
|
+
* a settings UI and a stored spec all clamp the same way.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** The shape family and its list live with the stored spec
|
|
8
|
+
* (@mantle/content-core/drift-spec); re-exported for engine callers. */
|
|
9
|
+
import { DRIFT_STYLES, type DriftStyle } from '@mantle/content-core/drift-spec';
|
|
10
|
+
|
|
11
|
+
export { DRIFT_STYLES, type DriftStyle };
|
|
12
|
+
|
|
13
|
+
/** The most colours a shader takes. More than this turns to mud anyway. */
|
|
14
|
+
export const DRIFT_MAX_COLORS = 6;
|
|
15
|
+
|
|
16
|
+
export type DriftColor = {
|
|
17
|
+
/** Any CSS colour. */
|
|
18
|
+
color: string;
|
|
19
|
+
/** Territory this colour claims, 0–2. 0 hides it without removing it. */
|
|
20
|
+
weight?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type DriftOptions = {
|
|
24
|
+
style: DriftStyle;
|
|
25
|
+
/** The ground everything sits on (and what the vignette fades into). */
|
|
26
|
+
background: string;
|
|
27
|
+
/** 1–6 colours, painted over the ground. */
|
|
28
|
+
colors: ReadonlyArray<string | DriftColor>;
|
|
29
|
+
/** Seeds every position and phase — same seed, same picture. */
|
|
30
|
+
seed: number;
|
|
31
|
+
/** Animation rate. 0 renders one still frame and never schedules another. */
|
|
32
|
+
speed: number;
|
|
33
|
+
/** Zoom. Above 1 shows more, smaller features; below 1 fewer, larger ones. */
|
|
34
|
+
scale: number;
|
|
35
|
+
/** Turbulence, 0–1: how far the shapes are pushed off their clean forms. */
|
|
36
|
+
warp: number;
|
|
37
|
+
/** Edge softness, 0–1: crisp bands at 0, fully melted at 1. */
|
|
38
|
+
softness: number;
|
|
39
|
+
/** Depth, 0–1: shading and highlights (silk, dunes, marble). */
|
|
40
|
+
lighting: number;
|
|
41
|
+
/** Chroma multiplier, 0–2, applied in OKLab so lightness never shifts. */
|
|
42
|
+
saturation: number;
|
|
43
|
+
/** Film grain, 0–1. Static — it never re-rolls per frame. */
|
|
44
|
+
grain: number;
|
|
45
|
+
/** Edge fade into the background, 0–1. */
|
|
46
|
+
vignette: number;
|
|
47
|
+
/** Rotation of the whole field, degrees. */
|
|
48
|
+
angle: number;
|
|
49
|
+
/** How much the field leans toward the pointer, 0–1. 0 adds no listener. */
|
|
50
|
+
pointer: number;
|
|
51
|
+
|
|
52
|
+
// ---- performance -----------------------------------------------------
|
|
53
|
+
/**
|
|
54
|
+
* Field resolution as a fraction of CSS pixels, 0.1–1; 0 picks the style's
|
|
55
|
+
* own (see {@link DRIFT_STYLE_RESOLUTION}). The gradient is low-frequency by
|
|
56
|
+
* nature, so it is computed small and filtered up; the dither and grain are
|
|
57
|
+
* applied at full size afterwards.
|
|
58
|
+
*/
|
|
59
|
+
resolution: number;
|
|
60
|
+
/** Frame cap. Slow ambient motion reads smooth at 30. */
|
|
61
|
+
maxFps: number;
|
|
62
|
+
/** Device-pixel-ratio cap for the output canvas. The output is only a
|
|
63
|
+
* filter-up plus dither, so 1 is plenty even on retina. */
|
|
64
|
+
maxDpr: number;
|
|
65
|
+
/** Lower `resolution` automatically while frames run late. */
|
|
66
|
+
adaptive: boolean;
|
|
67
|
+
/** Honour prefers-reduced-motion by rendering a still frame. */
|
|
68
|
+
respectReducedMotion: boolean;
|
|
69
|
+
/** Fade the canvas in over this many ms once the first frame lands. */
|
|
70
|
+
fadeIn: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The lowest field resolution at which each style is indistinguishable from
|
|
75
|
+
* full size, measured side by side. Mesh has no edges at all, so it can go
|
|
76
|
+
* lowest; the styles with crisp seams (silk rims, marble veins, dune ridges)
|
|
77
|
+
* start to staircase below ~0.3.
|
|
78
|
+
*/
|
|
79
|
+
export const DRIFT_STYLE_RESOLUTION: Record<DriftStyle, number> = {
|
|
80
|
+
mesh: 0.2,
|
|
81
|
+
aurora: 0.3,
|
|
82
|
+
silk: 0.35,
|
|
83
|
+
dunes: 0.35,
|
|
84
|
+
marble: 0.35,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const DRIFT_DEFAULTS: DriftOptions = {
|
|
88
|
+
style: 'mesh',
|
|
89
|
+
background: '#0b0d12',
|
|
90
|
+
colors: ['#3b5bdb', '#7048e8', '#0ca678', '#f08c00'],
|
|
91
|
+
seed: 1,
|
|
92
|
+
speed: 1,
|
|
93
|
+
scale: 1,
|
|
94
|
+
warp: 0.5,
|
|
95
|
+
softness: 0.6,
|
|
96
|
+
lighting: 0.5,
|
|
97
|
+
saturation: 1,
|
|
98
|
+
grain: 0.15,
|
|
99
|
+
vignette: 0,
|
|
100
|
+
angle: 0,
|
|
101
|
+
pointer: 0,
|
|
102
|
+
resolution: 0,
|
|
103
|
+
maxFps: 30,
|
|
104
|
+
maxDpr: 1,
|
|
105
|
+
adaptive: true,
|
|
106
|
+
respectReducedMotion: true,
|
|
107
|
+
fadeIn: 600,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const clamp = (v: unknown, lo: number, hi: number, fallback: number) =>
|
|
111
|
+
typeof v === 'number' && Number.isFinite(v) ? Math.min(hi, Math.max(lo, v)) : fallback;
|
|
112
|
+
|
|
113
|
+
/** Defaults filled, every number clamped to its documented range. */
|
|
114
|
+
export function normalizeDriftOptions(input: Partial<DriftOptions>): DriftOptions {
|
|
115
|
+
const d = DRIFT_DEFAULTS;
|
|
116
|
+
const style = DRIFT_STYLES.includes(input.style as DriftStyle)
|
|
117
|
+
? (input.style as DriftStyle)
|
|
118
|
+
: d.style;
|
|
119
|
+
const colors = (input.colors ?? d.colors).slice(0, DRIFT_MAX_COLORS);
|
|
120
|
+
return {
|
|
121
|
+
style,
|
|
122
|
+
background: typeof input.background === 'string' ? input.background : d.background,
|
|
123
|
+
// Omitted takes the defaults; an explicit empty list stays empty, and the
|
|
124
|
+
// engine then paints nothing (a theme it could not read is not a reason
|
|
125
|
+
// to paint someone else's colours).
|
|
126
|
+
colors: input.colors === undefined ? d.colors : colors,
|
|
127
|
+
seed: Math.floor(clamp(input.seed, 0, 0xffffffff, d.seed)),
|
|
128
|
+
speed: clamp(input.speed, 0, 10, d.speed),
|
|
129
|
+
scale: clamp(input.scale, 0.25, 4, d.scale),
|
|
130
|
+
warp: clamp(input.warp, 0, 1, d.warp),
|
|
131
|
+
softness: clamp(input.softness, 0, 1, d.softness),
|
|
132
|
+
lighting: clamp(input.lighting, 0, 1, d.lighting),
|
|
133
|
+
saturation: clamp(input.saturation, 0, 2, d.saturation),
|
|
134
|
+
grain: clamp(input.grain, 0, 1, d.grain),
|
|
135
|
+
vignette: clamp(input.vignette, 0, 1, d.vignette),
|
|
136
|
+
angle: clamp(input.angle, -360, 360, d.angle),
|
|
137
|
+
pointer: clamp(input.pointer, 0, 1, d.pointer),
|
|
138
|
+
resolution: input.resolution === 0 ? 0 : clamp(input.resolution, 0.1, 1, d.resolution),
|
|
139
|
+
maxFps: clamp(input.maxFps, 1, 240, d.maxFps),
|
|
140
|
+
maxDpr: clamp(input.maxDpr, 0.5, 4, d.maxDpr),
|
|
141
|
+
adaptive: typeof input.adaptive === 'boolean' ? input.adaptive : d.adaptive,
|
|
142
|
+
respectReducedMotion:
|
|
143
|
+
typeof input.respectReducedMotion === 'boolean'
|
|
144
|
+
? input.respectReducedMotion
|
|
145
|
+
: d.respectReducedMotion,
|
|
146
|
+
fadeIn: clamp(input.fadeIn, 0, 5000, d.fadeIn),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Deterministic PRNG (mulberry32) — same seed, same background, forever. */
|
|
151
|
+
export function mulberry32(seed: number): () => number {
|
|
152
|
+
let a = seed >>> 0;
|
|
153
|
+
return () => {
|
|
154
|
+
a |= 0;
|
|
155
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
156
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
157
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
158
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import type { DriftStyle } from './options';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Drift's shaders. GLSL ES 1.00 so the same source runs on a WebGL2 context
|
|
5
|
+
* (preferred) and the WebGL1 fallback.
|
|
6
|
+
*
|
|
7
|
+
* Two passes:
|
|
8
|
+
*
|
|
9
|
+
* 1. FIELD — one fullscreen triangle into a small offscreen texture (a
|
|
10
|
+
* fraction of the CSS size). Every style is analytic: no geometry, no
|
|
11
|
+
* mesh, no texture reads, just a function of (position, time). Colours
|
|
12
|
+
* arrive and blend in OKLab; the pass writes display sRGB.
|
|
13
|
+
* 2. COMPOSITE — the field filtered up to the canvas, then vignette, static
|
|
14
|
+
* film grain and a triangular dither. The dither is what lets a dark,
|
|
15
|
+
* slow gradient stay band-free on an 8-bit panel; it costs two hashes.
|
|
16
|
+
*
|
|
17
|
+
* Original work. Noise is classic gradient noise with a quintic fade; the
|
|
18
|
+
* lattice hash follows Dave Hoskins' sine-free "hash without sine" (MIT).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const VERTEX_SHADER = `
|
|
22
|
+
attribute vec2 a_pos;
|
|
23
|
+
void main() { gl_Position = vec4(a_pos, 0.0, 1.0); }
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const FIELD_HEADER = `
|
|
27
|
+
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
28
|
+
precision highp float;
|
|
29
|
+
#else
|
|
30
|
+
precision mediump float;
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
uniform vec2 u_res; // field buffer size, px
|
|
34
|
+
uniform float u_time; // seconds x speed, offset by the seed
|
|
35
|
+
uniform float u_scale;
|
|
36
|
+
uniform float u_warp;
|
|
37
|
+
uniform float u_soft;
|
|
38
|
+
uniform float u_light;
|
|
39
|
+
uniform float u_sat;
|
|
40
|
+
uniform vec2 u_rot; // cos, sin of the field angle
|
|
41
|
+
uniform vec3 u_ptr; // pointer uv (0..1) + strength
|
|
42
|
+
uniform vec3 u_bg; // OKLab
|
|
43
|
+
uniform vec3 u_col[6]; // OKLab
|
|
44
|
+
uniform float u_w[6]; // territory weight; 0 = off
|
|
45
|
+
uniform float u_stop[6]; // band centre along 0..1, from cumulative weights
|
|
46
|
+
uniform vec4 u_ph[6]; // seeded per-colour phases
|
|
47
|
+
|
|
48
|
+
vec2 hash22(vec2 p) {
|
|
49
|
+
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
|
|
50
|
+
p3 += dot(p3, p3.yzx + 33.33);
|
|
51
|
+
return fract((p3.xx + p3.yz) * p3.zy) * 2.0 - 1.0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
float gnoise(vec2 p) {
|
|
55
|
+
vec2 i = floor(p);
|
|
56
|
+
vec2 f = fract(p);
|
|
57
|
+
vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
|
58
|
+
float a = dot(hash22(i), f);
|
|
59
|
+
float b = dot(hash22(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0));
|
|
60
|
+
float c = dot(hash22(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0));
|
|
61
|
+
float d = dot(hash22(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0));
|
|
62
|
+
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const mat2 OCT = mat2(1.6, 1.2, -1.2, 1.6);
|
|
66
|
+
|
|
67
|
+
float fbm(vec2 p) {
|
|
68
|
+
float s = 0.0;
|
|
69
|
+
float a = 0.5;
|
|
70
|
+
for (int i = 0; i < 4; i++) {
|
|
71
|
+
s += a * gnoise(p);
|
|
72
|
+
p = OCT * p;
|
|
73
|
+
a *= 0.5;
|
|
74
|
+
}
|
|
75
|
+
return s;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Three octaves for the inner warp layers: their fine detail is smeared by
|
|
79
|
+
// the next layer anyway, so the fourth octave is pure cost.
|
|
80
|
+
float fbm3(vec2 p) {
|
|
81
|
+
float s = 0.5 * gnoise(p);
|
|
82
|
+
p = OCT * p;
|
|
83
|
+
s += 0.25 * gnoise(p);
|
|
84
|
+
p = OCT * p;
|
|
85
|
+
return s + 0.125 * gnoise(p);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Chroma-preserving resolve of an OKLab weighted sum. A plain average of two
|
|
89
|
+
// opposite hues cancels to grey; restoring the weighted mean chroma makes a
|
|
90
|
+
// blend pass THROUGH colour instead of through mud.
|
|
91
|
+
vec3 resolve(vec3 acc, float chroma, float ws) {
|
|
92
|
+
vec3 lab = acc / ws;
|
|
93
|
+
float c = length(lab.yz);
|
|
94
|
+
lab.yz *= min((chroma / ws) / max(c, 1e-4), 2.5);
|
|
95
|
+
return lab;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 1-D palette: inverse-distance blend of the colours around their band
|
|
99
|
+
// centres. Softness is the falloff exponent — high is crisp Voronoi bands,
|
|
100
|
+
// low melts every colour into its neighbours. Never underflows to nothing.
|
|
101
|
+
vec3 ramp(float s) {
|
|
102
|
+
float k = mix(4.0, 0.8, u_soft);
|
|
103
|
+
vec3 acc = vec3(0.0);
|
|
104
|
+
float cs = 0.0;
|
|
105
|
+
float ws = 0.0;
|
|
106
|
+
for (int i = 0; i < 6; i++) {
|
|
107
|
+
if (u_w[i] <= 0.0) continue;
|
|
108
|
+
float d = s - u_stop[i];
|
|
109
|
+
float w = u_w[i] / pow(d * d + 1e-4, k);
|
|
110
|
+
acc += u_col[i] * w;
|
|
111
|
+
cs += length(u_col[i].yz) * w;
|
|
112
|
+
ws += w;
|
|
113
|
+
}
|
|
114
|
+
return ws > 0.0 ? resolve(acc, cs, ws) : u_bg;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
vec3 oklabToLinear(vec3 c) {
|
|
118
|
+
float l = c.x + 0.3963377774 * c.y + 0.2158037573 * c.z;
|
|
119
|
+
float m = c.x - 0.1055613458 * c.y - 0.0638541728 * c.z;
|
|
120
|
+
float s = c.x - 0.0894841775 * c.y - 1.2914855480 * c.z;
|
|
121
|
+
l = l * l * l; m = m * m * m; s = s * s * s;
|
|
122
|
+
return vec3(
|
|
123
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
124
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
125
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
vec3 linearToSrgb(vec3 c) {
|
|
129
|
+
c = clamp(c, 0.0, 1.0);
|
|
130
|
+
vec3 lo = c * 12.92;
|
|
131
|
+
vec3 hi = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
|
|
132
|
+
return mix(lo, hi, step(vec3(0.0031308), c));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Centred, aspect-correct, rotated. Units: one field height = 1.
|
|
136
|
+
vec2 place(vec2 uv) {
|
|
137
|
+
vec2 p = (uv - 0.5) * vec2(u_res.x / u_res.y, 1.0);
|
|
138
|
+
return mat2(u_rot.x, u_rot.y, -u_rot.y, u_rot.x) * p;
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
/*
|
|
143
|
+
* Each style defines `vec3 field(vec2 p, vec2 pu, float aspect)`:
|
|
144
|
+
* p — placed and zoomed by u_scale (features)
|
|
145
|
+
* pu — placed, not zoomed (layout: where things sit on screen)
|
|
146
|
+
* and returns OKLab.
|
|
147
|
+
*/
|
|
148
|
+
const STYLES: Record<DriftStyle, string> = {
|
|
149
|
+
mesh: `
|
|
150
|
+
vec3 field(vec2 p, vec2 pu, float aspect) {
|
|
151
|
+
float t = u_time;
|
|
152
|
+
// Organic, not circular: the sample point is nudged by slow noise.
|
|
153
|
+
vec2 q = pu + u_warp * 0.28 * vec2(
|
|
154
|
+
gnoise(pu * 1.4 + vec2(0.0, t * 0.11)),
|
|
155
|
+
gnoise(pu * 1.4 + vec2(7.3, -t * 0.09)));
|
|
156
|
+
float sig = mix(0.018, 0.16, u_soft) / (u_scale * u_scale);
|
|
157
|
+
float ground = 0.12;
|
|
158
|
+
vec3 acc = u_bg * ground;
|
|
159
|
+
float cs = length(u_bg.yz) * ground;
|
|
160
|
+
float ws = ground;
|
|
161
|
+
for (int i = 0; i < 6; i++) {
|
|
162
|
+
if (u_w[i] <= 0.0) continue;
|
|
163
|
+
vec4 h = u_ph[i];
|
|
164
|
+
vec2 c = h.xy * vec2(0.5 * aspect, 0.5)
|
|
165
|
+
+ vec2(0.24 * aspect, 0.2) * vec2(
|
|
166
|
+
sin(t * (0.11 + 0.08 * h.z) + h.w * 6.2832),
|
|
167
|
+
cos(t * (0.09 + 0.07 * h.w) + h.z * 6.2832));
|
|
168
|
+
vec2 d = q - c;
|
|
169
|
+
float w = u_w[i] * exp(-dot(d, d) / sig);
|
|
170
|
+
acc += u_col[i] * w;
|
|
171
|
+
cs += length(u_col[i].yz) * w;
|
|
172
|
+
ws += w;
|
|
173
|
+
}
|
|
174
|
+
vec3 col = resolve(acc, cs, ws);
|
|
175
|
+
// A whisper of depth: concentrated colour lifts, thin colour settles.
|
|
176
|
+
col.x += u_light * 0.05 * (min(ws - ground, 1.5) - 0.5);
|
|
177
|
+
return col;
|
|
178
|
+
}
|
|
179
|
+
`,
|
|
180
|
+
silk: `
|
|
181
|
+
// The warp moves slowly across space, so it is computed once per pixel and
|
|
182
|
+
// shared by the three height taps the normal needs: 5 noise calls, not 9.
|
|
183
|
+
vec2 silkWarp(vec2 p, float t) {
|
|
184
|
+
return u_warp * 0.7 * vec2(
|
|
185
|
+
gnoise(p * 0.55 + vec2(0.0, t * 0.05)),
|
|
186
|
+
gnoise(p * 0.55 + vec2(4.7, -t * 0.04)));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
float height(vec2 q, float t) {
|
|
190
|
+
return sin(dot(q, vec2(4.2, 1.8)) + t * 0.26 + u_ph[0].w * 6.2832) * 0.45
|
|
191
|
+
+ sin(dot(q, vec2(-1.9, 4.4)) - t * 0.2 + u_ph[1].w * 6.2832) * 0.3
|
|
192
|
+
+ gnoise(q * 2.0 + vec2(t * 0.04, u_ph[2].w * 9.0)) * 0.55;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
vec3 field(vec2 p, vec2 pu, float aspect) {
|
|
196
|
+
float t = u_time;
|
|
197
|
+
// Anisotropic: folds run long and lie down, like cloth, not like contours.
|
|
198
|
+
p *= vec2(0.6, 1.25);
|
|
199
|
+
vec2 q = p + silkWarp(p, t);
|
|
200
|
+
float e = 0.01;
|
|
201
|
+
float h = height(q, t);
|
|
202
|
+
float hx = height(q + vec2(e, 0.0), t);
|
|
203
|
+
float hy = height(q + vec2(0.0, e), t);
|
|
204
|
+
vec3 n = normalize(vec3(-(hx - h) / e, -(hy - h) / e, mix(7.0, 1.8, u_light)));
|
|
205
|
+
// Colour follows the folds (height), with a slow drift across the screen
|
|
206
|
+
// so one end of the sheet can differ from the other.
|
|
207
|
+
vec3 col = ramp(clamp(0.5 + h * 0.5 + dot(pu, vec2(0.18, 0.1)), 0.0, 1.0));
|
|
208
|
+
vec3 L = normalize(vec3(-0.45, 0.55, 0.7));
|
|
209
|
+
float diff = dot(n, L);
|
|
210
|
+
float spec = pow(max(dot(reflect(-L, n), vec3(0.0, 0.0, 1.0)), 0.0), 24.0);
|
|
211
|
+
col.x += u_light * ((diff - 0.8) * 0.45 + spec * 0.18);
|
|
212
|
+
return col;
|
|
213
|
+
}
|
|
214
|
+
`,
|
|
215
|
+
aurora: `
|
|
216
|
+
vec3 field(vec2 p, vec2 pu, float aspect) {
|
|
217
|
+
float t = u_time;
|
|
218
|
+
float edge = mix(0.0008, 0.008, u_soft);
|
|
219
|
+
float tail = mix(0.008, 0.06, u_soft);
|
|
220
|
+
vec3 col = u_bg;
|
|
221
|
+
// Back to front: each curtain is laid OVER the sky, so the sky survives
|
|
222
|
+
// between curtains — light on dark, not stripes edge to edge.
|
|
223
|
+
for (int i = 0; i < 6; i++) {
|
|
224
|
+
if (u_w[i] <= 0.0) continue;
|
|
225
|
+
vec4 h = u_ph[i];
|
|
226
|
+
float x = p.x;
|
|
227
|
+
float lane = (u_stop[i] - 0.5) * 0.6 - 0.1;
|
|
228
|
+
float y0 = lane
|
|
229
|
+
+ 0.12 * sin(x * (1.0 + 1.1 * h.z) + t * (0.1 + 0.08 * h.w) + h.x * 6.2832)
|
|
230
|
+
+ u_warp * 0.18 * gnoise(vec2(x * 0.9 + h.y * 13.0, t * 0.05 + h.z * 7.0));
|
|
231
|
+
float dy = pu.y - y0;
|
|
232
|
+
// Hard foot, long soft tail upward: a curtain, not a stripe.
|
|
233
|
+
float w = dy > 0.0 ? exp(-dy * dy / tail) : exp(-dy * dy / edge);
|
|
234
|
+
// Rays: vertical striation drifting along the curtain. Kept below the
|
|
235
|
+
// field's Nyquist at the lowest resolution, or it aliases into a fence.
|
|
236
|
+
float ray = gnoise(vec2(x * 6.5 + h.x * 21.0 - t * 0.12, h.y * 5.0));
|
|
237
|
+
w *= 1.0 + u_warp * 1.1 * ray;
|
|
238
|
+
w = clamp(w * min(u_w[i], 1.0) * 0.85, 0.0, 1.0);
|
|
239
|
+
vec3 c = u_col[i];
|
|
240
|
+
c.x += u_light * 0.1 * w; // the foot glows
|
|
241
|
+
col = mix(col, c, w);
|
|
242
|
+
}
|
|
243
|
+
return col;
|
|
244
|
+
}
|
|
245
|
+
`,
|
|
246
|
+
dunes: `
|
|
247
|
+
vec3 field(vec2 p, vec2 pu, float aspect) {
|
|
248
|
+
float t = u_time;
|
|
249
|
+
float edge = mix(0.0015, 0.045, u_soft);
|
|
250
|
+
vec3 col = u_bg;
|
|
251
|
+
for (int i = 0; i < 6; i++) {
|
|
252
|
+
if (u_w[i] <= 0.0) continue;
|
|
253
|
+
vec4 h = u_ph[i];
|
|
254
|
+
float x = p.x;
|
|
255
|
+
float y = 0.44 - u_stop[i] * 0.95
|
|
256
|
+
+ 0.07 * sin(x * (1.2 + 1.3 * h.z) + t * (0.08 + 0.06 * h.w) + h.x * 6.2832)
|
|
257
|
+
+ 0.03 * sin(x * (3.0 + 2.0 * h.w) - t * (0.11 + 0.05 * h.z) + h.y * 6.2832)
|
|
258
|
+
+ u_warp * 0.09 * gnoise(vec2(x * 1.1 + h.y * 17.0, t * 0.04 + float(i) * 3.1));
|
|
259
|
+
float dy = y - pu.y; // > 0 inside this layer
|
|
260
|
+
float inside = smoothstep(-edge, edge, dy);
|
|
261
|
+
// The layer casts a soft shadow onto whatever lies behind it...
|
|
262
|
+
col.x -= u_light * 0.1 * exp(-max(-dy, 0.0) * 14.0) * (1.0 - inside);
|
|
263
|
+
vec3 layer = u_col[i];
|
|
264
|
+
// ...and its own face falls off with depth below the ridge.
|
|
265
|
+
layer.x -= u_light * 0.05 * clamp(dy * 2.5, 0.0, 1.0);
|
|
266
|
+
col = mix(col, layer, inside);
|
|
267
|
+
// A rim of light right on the ridge.
|
|
268
|
+
col.x += u_light * 0.035 * exp(-max(dy, 0.0) * 45.0) * inside;
|
|
269
|
+
}
|
|
270
|
+
return col;
|
|
271
|
+
}
|
|
272
|
+
`,
|
|
273
|
+
marble: `
|
|
274
|
+
vec3 field(vec2 p, vec2 pu, float aspect) {
|
|
275
|
+
float t = u_time;
|
|
276
|
+
p *= 0.55;
|
|
277
|
+
float k = 1.2 + 2.8 * u_warp;
|
|
278
|
+
vec2 o = u_ph[0].xy * 10.0;
|
|
279
|
+
vec2 q = vec2(
|
|
280
|
+
fbm3(p + o + vec2(0.0, t * 0.03)),
|
|
281
|
+
fbm3(p + o + vec2(5.2, 1.3) - vec2(t * 0.025, 0.0)));
|
|
282
|
+
vec2 r = vec2(
|
|
283
|
+
fbm3(p + k * q + vec2(1.7, 9.2) + t * 0.035),
|
|
284
|
+
fbm3(p + k * q + vec2(8.3, 2.8) - t * 0.03));
|
|
285
|
+
float f = fbm(p + k * r);
|
|
286
|
+
vec3 col = ramp(clamp(0.5 + f * 1.1 + q.x * 0.6 - r.y * 0.3, 0.0, 1.0));
|
|
287
|
+
col.x += u_light * (dot(r, r) * 0.5 + f * 0.12 - 0.04);
|
|
288
|
+
return col;
|
|
289
|
+
}
|
|
290
|
+
`,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const FIELD_MAIN = `
|
|
294
|
+
void main() {
|
|
295
|
+
vec2 uv = gl_FragCoord.xy / u_res;
|
|
296
|
+
float aspect = u_res.x / u_res.y;
|
|
297
|
+
vec2 pu = place(uv);
|
|
298
|
+
if (u_ptr.z > 0.0) {
|
|
299
|
+
// The field leans toward the pointer: a soft lens, not a cursor blob.
|
|
300
|
+
vec2 d = pu - place(u_ptr.xy);
|
|
301
|
+
pu -= d * u_ptr.z * 0.3 * exp(-dot(d, d) * 5.0);
|
|
302
|
+
}
|
|
303
|
+
vec3 lab = field(pu * u_scale, pu, aspect);
|
|
304
|
+
lab.yz *= u_sat;
|
|
305
|
+
gl_FragColor = vec4(linearToSrgb(oklabToLinear(lab)), 1.0);
|
|
306
|
+
}
|
|
307
|
+
`;
|
|
308
|
+
|
|
309
|
+
export function fieldShader(style: DriftStyle): string {
|
|
310
|
+
return FIELD_HEADER + STYLES[style] + FIELD_MAIN;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export const COMPOSITE_SHADER = `
|
|
314
|
+
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
315
|
+
precision highp float;
|
|
316
|
+
#else
|
|
317
|
+
precision mediump float;
|
|
318
|
+
#endif
|
|
319
|
+
|
|
320
|
+
uniform sampler2D u_tex;
|
|
321
|
+
uniform vec2 u_out; // canvas size, px
|
|
322
|
+
uniform float u_px; // device px per CSS px — grain is sized in CSS px
|
|
323
|
+
uniform float u_grain;
|
|
324
|
+
uniform float u_gseed;
|
|
325
|
+
uniform float u_vig;
|
|
326
|
+
uniform vec3 u_bgs; // background, display sRGB
|
|
327
|
+
|
|
328
|
+
float hash12(vec2 p) {
|
|
329
|
+
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
|
|
330
|
+
p3 += dot(p3, p3.yzx + 33.33);
|
|
331
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
void main() {
|
|
335
|
+
vec2 uv = gl_FragCoord.xy / u_out;
|
|
336
|
+
vec3 c = texture2D(u_tex, uv).rgb;
|
|
337
|
+
if (u_vig > 0.0) {
|
|
338
|
+
vec2 d = (uv - 0.5) * 2.0;
|
|
339
|
+
float v = smoothstep(0.35, 1.45, length(d * vec2(0.9, 1.0)));
|
|
340
|
+
c = mix(c, u_bgs, v * u_vig);
|
|
341
|
+
}
|
|
342
|
+
if (u_grain > 0.0) {
|
|
343
|
+
float g = hash12(floor(gl_FragCoord.xy / u_px) + u_gseed) - 0.5;
|
|
344
|
+
// Strongest in the mid-tones, where grain reads as texture, not dirt.
|
|
345
|
+
c += g * u_grain * 0.11 * (0.35 + c * (1.0 - c) * 2.6);
|
|
346
|
+
}
|
|
347
|
+
float dither = hash12(gl_FragCoord.xy + 71.3) + hash12(gl_FragCoord.xy * 1.13 + 19.7) - 1.0;
|
|
348
|
+
gl_FragColor = vec4(c + dither / 255.0, 1.0);
|
|
349
|
+
}
|
|
350
|
+
`;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { DriftOptions } from './options';
|
|
2
|
+
import type { DriftSpec } from '@mantle/content-core/drift-spec';
|
|
3
|
+
import { DRIFT_TEXT_FLOOR, driftPaletteFromTheme, type DriftThemeTokens } from './theme';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The stored spec and its codec live in @mantle/content-core/drift-spec, the
|
|
7
|
+
* one codec the brain validates with and every renderer decodes with. This
|
|
8
|
+
* module adds the step only a renderer needs: spec + live tokens + mode, to
|
|
9
|
+
* engine options.
|
|
10
|
+
*/
|
|
11
|
+
export {
|
|
12
|
+
DRIFT_SPEC_DEFAULTS,
|
|
13
|
+
DRIFT_SPEC_MAX,
|
|
14
|
+
DRIFT_SPEED_MAX,
|
|
15
|
+
decodeDriftSpec,
|
|
16
|
+
encodeDriftSpec,
|
|
17
|
+
randomDriftSpec,
|
|
18
|
+
type DriftSpec,
|
|
19
|
+
} from '@mantle/content-core/drift-spec';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Where a background paints, the one switch between its two looks (owner
|
|
23
|
+
* decision 2026-10-24):
|
|
24
|
+
* - 'app': inside the signed-in shell, and every frame whose own text sits
|
|
25
|
+
* on the gradient (mini apps, owner or shared). The palette holds the
|
|
26
|
+
* legibility floor, so muted text reads at AA on every colour painted.
|
|
27
|
+
* - 'public': the sign-in, invite and /s reader pages. The full colour the
|
|
28
|
+
* spec asks for, no floor: these pages put no text directly on the
|
|
29
|
+
* gradient (their content sits on an opaque card or sheet), which is what
|
|
30
|
+
* makes dropping the floor safe. A new public surface keeps that rule.
|
|
31
|
+
*/
|
|
32
|
+
export type DriftSurface = 'public' | 'app';
|
|
33
|
+
|
|
34
|
+
/** A surface named by markup (a host div's `data-drift-surface`): only the
|
|
35
|
+
* exact 'public' gets the full-colour look; anything else is the floored
|
|
36
|
+
* 'app' one, so a missing or garbled attribute can never drop the floor. */
|
|
37
|
+
export function readDriftSurface(raw: string | null | undefined): DriftSurface {
|
|
38
|
+
return raw === 'public' ? 'public' : 'app';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Spec + live tokens + mode + surface, to engine options. Pure: the
|
|
42
|
+
* settings preview and every real surface derive the same picture from the
|
|
43
|
+
* same inputs. The 'app' surface holds the legibility floor
|
|
44
|
+
* (DRIFT_TEXT_FLOOR against --muted-foreground), so no strength makes
|
|
45
|
+
* content text unreadable; 'public' paints the spec's full colour (see
|
|
46
|
+
* DriftSurface). Pointer lean is never set here: real surfaces keep it off. */
|
|
47
|
+
export function driftOptionsFromSpec(
|
|
48
|
+
spec: DriftSpec,
|
|
49
|
+
tokens: DriftThemeTokens,
|
|
50
|
+
mode: 'light' | 'dark',
|
|
51
|
+
surface: DriftSurface,
|
|
52
|
+
): Partial<DriftOptions> {
|
|
53
|
+
const palette = driftPaletteFromTheme(tokens, {
|
|
54
|
+
seed: spec.seed,
|
|
55
|
+
tone: spec.tone,
|
|
56
|
+
mode,
|
|
57
|
+
source: spec.pal,
|
|
58
|
+
strength: spec.str,
|
|
59
|
+
// Fail closed: only the exact 'public' drops the floor, as readDriftSurface.
|
|
60
|
+
textFloor: surface === 'public' ? undefined : DRIFT_TEXT_FLOOR,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
style: spec.style,
|
|
64
|
+
seed: spec.seed,
|
|
65
|
+
background: palette.background,
|
|
66
|
+
colors: palette.colors,
|
|
67
|
+
// The stored range is the Neat spec's 0 to 6 (default 2); the engine's
|
|
68
|
+
// natural pace is 1.
|
|
69
|
+
speed: spec.speed / 2,
|
|
70
|
+
scale: spec.scale,
|
|
71
|
+
warp: spec.warp,
|
|
72
|
+
softness: spec.soft,
|
|
73
|
+
lighting: spec.light,
|
|
74
|
+
grain: spec.grain,
|
|
75
|
+
angle: spec.angle,
|
|
76
|
+
};
|
|
77
|
+
}
|