@ultimat3/effects 0.0.0-stage → 31.53.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/CATALOG.md +169 -0
- package/CLAUDE.md +29 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/package.json +56 -4
- package/src/_effect.scss +53 -0
- package/src/aurora/Aurora.module.scss +56 -0
- package/src/aurora/Aurora.tsx +35 -0
- package/src/aurora/aurora-view.ts +32 -0
- package/src/backend.ts +34 -0
- package/src/canvas-mount.ts +61 -0
- package/src/count-up/CountUp.tsx +51 -0
- package/src/count-up/count-up-run.ts +59 -0
- package/src/count-up/count-up-view.ts +56 -0
- package/src/css-pause.ts +50 -0
- package/src/effect-canvas/EffectCanvas.module.scss +23 -0
- package/src/effect-canvas/EffectCanvas.tsx +51 -0
- package/src/effect-canvas/effect-canvas-view.ts +33 -0
- package/src/effect-host.ts +54 -0
- package/src/effect-mount.ts +114 -0
- package/src/errors.ts +33 -0
- package/src/glass-surface/GlassSurface.module.scss +25 -0
- package/src/glass-surface/GlassSurface.tsx +29 -0
- package/src/glass-surface/glass-surface-view.ts +33 -0
- package/src/gradient-orbs/GradientOrbs.module.scss +49 -0
- package/src/gradient-orbs/GradientOrbs.tsx +41 -0
- package/src/gradient-orbs/gradient-orbs-view.ts +77 -0
- package/src/grid-glow/GridGlow.module.scss +50 -0
- package/src/grid-glow/GridGlow.tsx +39 -0
- package/src/grid-glow/grid-glow-view.ts +40 -0
- package/src/index.ts +45 -0
- package/src/marquee/Marquee.module.scss +52 -0
- package/src/marquee/Marquee.tsx +31 -0
- package/src/marquee/marquee-view.ts +25 -0
- package/src/mosaic-grid/MosaicGrid.module.scss +39 -0
- package/src/mosaic-grid/MosaicGrid.tsx +59 -0
- package/src/mosaic-grid/mosaic-grid-view.ts +96 -0
- package/src/motion-port.ts +22 -0
- package/src/noise/Noise.module.scss +22 -0
- package/src/noise/Noise.tsx +49 -0
- package/src/noise/noise-view.ts +38 -0
- package/src/palette.ts +41 -0
- package/src/pixel-budget.ts +42 -0
- package/src/props.ts +61 -0
- package/src/shader-background/ShaderBackground.module.scss +70 -0
- package/src/shader-background/ShaderBackground.tsx +60 -0
- package/src/shader-background/load-preset.ts +19 -0
- package/src/shader-background/presets/dots.ts +59 -0
- package/src/shader-background/presets/grain.ts +59 -0
- package/src/shader-background/presets/mesh.ts +78 -0
- package/src/shader-background/shader-background-canvas.ts +116 -0
- package/src/shader-background/shader-background-view.ts +98 -0
- package/src/shader-background/uniform-pack.ts +11 -0
- package/src/shader-load.ts +17 -0
- package/src/shader-mount.ts +197 -0
- package/src/shimmer/Shimmer.module.scss +23 -0
- package/src/shimmer/Shimmer.tsx +19 -0
- package/src/spotlight-card/SpotlightCard.module.scss +29 -0
- package/src/spotlight-card/SpotlightCard.tsx +28 -0
- package/src/spotlight-card/spotlight-card-view.ts +37 -0
- package/src/spotlight-card/spotlight-wire.ts +34 -0
- package/src/text-reveal/TextReveal.module.scss +47 -0
- package/src/text-reveal/TextReveal.tsx +48 -0
- package/src/text-reveal/text-reveal-view.ts +38 -0
- package/src/tilt/Tilt.module.scss +18 -0
- package/src/tilt/Tilt.tsx +30 -0
- package/src/tilt/tilt-view.ts +64 -0
- package/src/tilt/tilt-wire.ts +50 -0
- package/src/use-css-pause.ts +35 -0
- package/src/use-effect-mount.ts +35 -0
- package/src/visibility.ts +26 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Soft role-coloured orbs drifting behind a surface, moved on transform and opacity only. The
|
|
2
|
+
// server frame floats in CSS; in an island the drift also holds offscreen and in a hidden tab.
|
|
3
|
+
|
|
4
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
5
|
+
import { cx } from '@ultimat3/ui';
|
|
6
|
+
import type { JSX } from 'solid-js';
|
|
7
|
+
import { useCssPause } from '../use-css-pause';
|
|
8
|
+
import styles from './GradientOrbs.module.scss';
|
|
9
|
+
import { GRADIENT_ORBS_BACKEND, gradientOrbsView, orbVars } from './gradient-orbs-view';
|
|
10
|
+
|
|
11
|
+
export interface GradientOrbsProps {
|
|
12
|
+
/** One orb per role, 1..6. Default `['accent', 'info', 'chart-3']`. */
|
|
13
|
+
roles?: readonly ColorRole[] | undefined;
|
|
14
|
+
/** Drift speed multiplier, 0.25..4. Default 1. */
|
|
15
|
+
speed?: number | undefined;
|
|
16
|
+
/** Orb opacity, 0..1. Default 0.6. */
|
|
17
|
+
intensity?: number | undefined;
|
|
18
|
+
/** What the orbs sit behind. */
|
|
19
|
+
children?: JSX.Element | undefined;
|
|
20
|
+
class?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function GradientOrbs(props: GradientOrbsProps): JSX.Element {
|
|
24
|
+
const view = gradientOrbsView(props);
|
|
25
|
+
const fx = useCssPause(GRADIENT_ORBS_BACKEND);
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
ref={fx.root}
|
|
29
|
+
class={cx(styles['root'], props.class)}
|
|
30
|
+
style={view.vars}
|
|
31
|
+
data-effect-backend={fx.backend()}
|
|
32
|
+
>
|
|
33
|
+
<div class={styles['layer']} aria-hidden="true">
|
|
34
|
+
{view.orbs.map((orb) => (
|
|
35
|
+
<span class={styles['orb']} style={orbVars(orb)} />
|
|
36
|
+
))}
|
|
37
|
+
</div>
|
|
38
|
+
<div class={styles['content']}>{props.children}</div>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// GradientOrbs' rules: where each orb sits, how big it is and where in its cycle it starts, from
|
|
2
|
+
// the orb's index alone (a golden-angle walk), so the server and an island place them identically.
|
|
3
|
+
|
|
4
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
5
|
+
import type { EffectBackend } from '../backend';
|
|
6
|
+
import { rangeProp, rolesProp } from '../props';
|
|
7
|
+
|
|
8
|
+
/** The server frame animates in CSS; the island adds the offscreen and hidden-tab pause. */
|
|
9
|
+
export const GRADIENT_ORBS_BACKEND: EffectBackend = 'css';
|
|
10
|
+
|
|
11
|
+
export const GRADIENT_ORBS_ROLES: readonly ColorRole[] = ['accent', 'info', 'chart-3'];
|
|
12
|
+
|
|
13
|
+
export interface OrbPlacement {
|
|
14
|
+
readonly role: ColorRole;
|
|
15
|
+
/** Centre, percent of the box. */
|
|
16
|
+
readonly x: number;
|
|
17
|
+
readonly y: number;
|
|
18
|
+
/** Diameter, percent of the box's inline size. */
|
|
19
|
+
readonly size: number;
|
|
20
|
+
/** Where in the cycle the orb starts, 0..1. */
|
|
21
|
+
readonly phase: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const GOLDEN_TURN = 0.381_966;
|
|
25
|
+
|
|
26
|
+
const round = (value: number): number => Math.round(value * 100) / 100;
|
|
27
|
+
|
|
28
|
+
export function orbLayout(roles: readonly ColorRole[]): readonly OrbPlacement[] {
|
|
29
|
+
return roles.map((role, index) => {
|
|
30
|
+
const turn = (index * GOLDEN_TURN) % 1;
|
|
31
|
+
const angle = turn * Math.PI * 2;
|
|
32
|
+
const reach = 18 + ((index * 11) % 17);
|
|
33
|
+
return {
|
|
34
|
+
role,
|
|
35
|
+
x: round(50 + Math.cos(angle) * reach),
|
|
36
|
+
y: round(50 + Math.sin(angle) * reach * 0.8),
|
|
37
|
+
size: 34 + ((index * 13) % 22),
|
|
38
|
+
phase: round(turn),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface GradientOrbsInput {
|
|
44
|
+
readonly roles?: readonly ColorRole[] | undefined;
|
|
45
|
+
readonly speed?: number | undefined;
|
|
46
|
+
readonly intensity?: number | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface GradientOrbsView {
|
|
50
|
+
readonly orbs: readonly OrbPlacement[];
|
|
51
|
+
readonly vars: Record<string, string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function gradientOrbsView(input: GradientOrbsInput): GradientOrbsView {
|
|
55
|
+
const roles = rolesProp('GradientOrbs', input.roles, GRADIENT_ORBS_ROLES, { min: 1, max: 6 });
|
|
56
|
+
const speed = rangeProp('GradientOrbs', 'speed', input.speed, { min: 0.25, max: 4, fallback: 1 });
|
|
57
|
+
const intensity = rangeProp('GradientOrbs', 'intensity', input.intensity, {
|
|
58
|
+
min: 0,
|
|
59
|
+
max: 1,
|
|
60
|
+
fallback: 0.6,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
orbs: orbLayout(roles),
|
|
64
|
+
vars: { '--fx-speed': String(speed), '--fx-intensity': String(intensity) },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** One orb's inline custom properties: its role, place, size and phase. */
|
|
69
|
+
export function orbVars(orb: OrbPlacement): Record<string, string> {
|
|
70
|
+
return {
|
|
71
|
+
'--fx-c': `var(--color-${orb.role})`,
|
|
72
|
+
'--fx-x': `${orb.x}%`,
|
|
73
|
+
'--fx-y': `${orb.y}%`,
|
|
74
|
+
'--fx-size': `${orb.size}%`,
|
|
75
|
+
'--fx-phase': String(orb.phase),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@use '@ultimat3/ui/tokens' as t;
|
|
2
|
+
@use '../effect' as fx;
|
|
3
|
+
|
|
4
|
+
@keyframes grid-glow-sweep {
|
|
5
|
+
50% {
|
|
6
|
+
transform: translate3d(40%, 25%, 0);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
to {
|
|
10
|
+
transform: translate3d(-30%, 45%, 0);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.root {
|
|
15
|
+
@include fx.root;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.layer {
|
|
19
|
+
@include fx.layer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.content {
|
|
23
|
+
@include fx.content;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.grid {
|
|
27
|
+
@include t.grid-texture($scanlines: false);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.grid-scanlines {
|
|
31
|
+
@include t.grid-texture($scanlines: true);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.glow {
|
|
35
|
+
@include fx.pausable('.root');
|
|
36
|
+
position: absolute;
|
|
37
|
+
inset-block-start: -25%;
|
|
38
|
+
inset-inline-start: -10%;
|
|
39
|
+
inline-size: 70%;
|
|
40
|
+
aspect-ratio: 1;
|
|
41
|
+
border-radius: t.radius(full);
|
|
42
|
+
background: radial-gradient(circle, rgb(var(--fx-c0) / 0.28), rgb(var(--fx-c0) / 0) 65%);
|
|
43
|
+
animation: grid-glow-sweep calc(#{t.duration(slower)} * 28 / var(--fx-speed, 1)) t.easing(in-out)
|
|
44
|
+
infinite alternate;
|
|
45
|
+
will-change: transform;
|
|
46
|
+
|
|
47
|
+
@media (prefers-contrast: more), (forced-colors: active) {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The instrument-panel ground: ui's `grid-texture` with an accent glow drifting across it, in CSS
|
|
2
|
+
// alone. Both are withdrawn under `prefers-contrast: more` and `forced-colors`, where texture
|
|
3
|
+
// behind text is noise.
|
|
4
|
+
|
|
5
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
6
|
+
import { cx } from '@ultimat3/ui';
|
|
7
|
+
import type { JSX } from 'solid-js';
|
|
8
|
+
import styles from './GridGlow.module.scss';
|
|
9
|
+
import { GRID_GLOW_BACKEND, gridGlowView } from './grid-glow-view';
|
|
10
|
+
|
|
11
|
+
export interface GridGlowProps {
|
|
12
|
+
/** The glow's colour role. Default `'accent'`. */
|
|
13
|
+
role?: ColorRole | undefined;
|
|
14
|
+
/** Glow drift speed multiplier, 0.25..4. Default 1. */
|
|
15
|
+
speed?: number | undefined;
|
|
16
|
+
/** Horizontal scanlines over the grid. Default false. */
|
|
17
|
+
scanlines?: boolean | undefined;
|
|
18
|
+
/** The drifting glow. Default true; false leaves the still grid. */
|
|
19
|
+
glow?: boolean | undefined;
|
|
20
|
+
/** What the grid sits behind. */
|
|
21
|
+
children?: JSX.Element | undefined;
|
|
22
|
+
class?: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function GridGlow(props: GridGlowProps): JSX.Element {
|
|
26
|
+
const view = gridGlowView(props);
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
class={cx(styles['root'], props.class)}
|
|
30
|
+
style={view.vars}
|
|
31
|
+
data-effect-backend={GRID_GLOW_BACKEND}
|
|
32
|
+
>
|
|
33
|
+
<div class={cx(styles['layer'], styles[view.ground])} aria-hidden="true">
|
|
34
|
+
{view.glow ? <span class={styles['glow']} /> : null}
|
|
35
|
+
</div>
|
|
36
|
+
<div class={styles['content']}>{props.children}</div>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// GridGlow's rules: which grid ground the sheet draws (ui's `grid-texture`, with or without
|
|
2
|
+
// scanlines) and the glow's colour role and speed as custom properties.
|
|
3
|
+
|
|
4
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
5
|
+
import type { EffectBackend } from '../backend';
|
|
6
|
+
import { rangeProp, rolesProp, roleVars } from '../props';
|
|
7
|
+
|
|
8
|
+
/** CSS all the way: the glow drifts in the stylesheet and nothing mounts in an island. */
|
|
9
|
+
export const GRID_GLOW_BACKEND: EffectBackend = 'css';
|
|
10
|
+
|
|
11
|
+
export const GRID_GLOW_ROLES: readonly ColorRole[] = ['accent'];
|
|
12
|
+
|
|
13
|
+
export interface GridGlowInput {
|
|
14
|
+
readonly role?: ColorRole | undefined;
|
|
15
|
+
readonly speed?: number | undefined;
|
|
16
|
+
readonly scanlines?: boolean | undefined;
|
|
17
|
+
readonly glow?: boolean | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GridGlowView {
|
|
21
|
+
readonly vars: Record<string, string>;
|
|
22
|
+
/** The sheet's class for the ground: `grid` or `grid-scanlines`. */
|
|
23
|
+
readonly ground: 'grid' | 'grid-scanlines';
|
|
24
|
+
readonly glow: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function gridGlowView(input: GridGlowInput): GridGlowView {
|
|
28
|
+
const roles = rolesProp(
|
|
29
|
+
'GridGlow',
|
|
30
|
+
input.role === undefined ? undefined : [input.role],
|
|
31
|
+
GRID_GLOW_ROLES,
|
|
32
|
+
{ min: 1, max: 1 },
|
|
33
|
+
);
|
|
34
|
+
const speed = rangeProp('GridGlow', 'speed', input.speed, { min: 0.25, max: 4, fallback: 1 });
|
|
35
|
+
return {
|
|
36
|
+
vars: { ...roleVars(roles), '--fx-speed': String(speed) },
|
|
37
|
+
ground: input.scanlines === true ? 'grid-scanlines' : 'grid',
|
|
38
|
+
glow: input.glow !== false,
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Public API of @ultimat3/effects. Explicit re-exports only.
|
|
2
|
+
|
|
3
|
+
export type { AuroraProps } from './aurora/Aurora';
|
|
4
|
+
export { Aurora } from './aurora/Aurora';
|
|
5
|
+
export type { EffectBackend } from './backend';
|
|
6
|
+
export { EFFECT_BACKENDS } from './backend';
|
|
7
|
+
export type { CanvasDraw, CanvasFrame } from './canvas-mount';
|
|
8
|
+
export type { CountUpProps } from './count-up/CountUp';
|
|
9
|
+
export { CountUp } from './count-up/CountUp';
|
|
10
|
+
export type {
|
|
11
|
+
EffectCanvasDrawProps,
|
|
12
|
+
EffectCanvasProps,
|
|
13
|
+
EffectCanvasShaderProps,
|
|
14
|
+
} from './effect-canvas/EffectCanvas';
|
|
15
|
+
export { EffectCanvas } from './effect-canvas/EffectCanvas';
|
|
16
|
+
export type { EffectsErrorCode } from './errors';
|
|
17
|
+
export { EFFECTS_ERROR_CODES, EffectsInvalidValueError } from './errors';
|
|
18
|
+
export type { GlassSurfaceProps } from './glass-surface/GlassSurface';
|
|
19
|
+
export { GlassSurface } from './glass-surface/GlassSurface';
|
|
20
|
+
export type { GradientOrbsProps } from './gradient-orbs/GradientOrbs';
|
|
21
|
+
export { GradientOrbs } from './gradient-orbs/GradientOrbs';
|
|
22
|
+
export type { GridGlowProps } from './grid-glow/GridGlow';
|
|
23
|
+
export { GridGlow } from './grid-glow/GridGlow';
|
|
24
|
+
export type { MarqueeProps } from './marquee/Marquee';
|
|
25
|
+
export { Marquee } from './marquee/Marquee';
|
|
26
|
+
export type { MosaicGridProps } from './mosaic-grid/MosaicGrid';
|
|
27
|
+
export { MosaicGrid } from './mosaic-grid/MosaicGrid';
|
|
28
|
+
export type { NoiseProps } from './noise/Noise';
|
|
29
|
+
export { Noise } from './noise/Noise';
|
|
30
|
+
export type { Rgb } from './palette';
|
|
31
|
+
export type { PixelBudget } from './pixel-budget';
|
|
32
|
+
export { EFFECT_PIXELS } from './pixel-budget';
|
|
33
|
+
export type { ShaderBackgroundProps } from './shader-background/ShaderBackground';
|
|
34
|
+
export { ShaderBackground } from './shader-background/ShaderBackground';
|
|
35
|
+
export type { ShaderPreset } from './shader-background/shader-background-view';
|
|
36
|
+
export { SHADER_PRESETS } from './shader-background/shader-background-view';
|
|
37
|
+
export type { ShaderFrame, ShaderProgram, Uniform } from './shader-mount';
|
|
38
|
+
export type { ShimmerProps } from './shimmer/Shimmer';
|
|
39
|
+
export { Shimmer } from './shimmer/Shimmer';
|
|
40
|
+
export type { SpotlightCardProps } from './spotlight-card/SpotlightCard';
|
|
41
|
+
export { SpotlightCard } from './spotlight-card/SpotlightCard';
|
|
42
|
+
export type { TextRevealProps } from './text-reveal/TextReveal';
|
|
43
|
+
export { TextReveal } from './text-reveal/TextReveal';
|
|
44
|
+
export type { TiltProps } from './tilt/Tilt';
|
|
45
|
+
export { Tilt } from './tilt/Tilt';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
@use '@ultimat3/ui/tokens' as t;
|
|
2
|
+
|
|
3
|
+
@keyframes marquee-run {
|
|
4
|
+
to {
|
|
5
|
+
transform: translateX(calc(var(--marquee-sign, -1) * (100% + var(--marquee-gap))));
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.root {
|
|
10
|
+
--marquee-gap: #{t.space(6)};
|
|
11
|
+
--marquee-sign: -1;
|
|
12
|
+
display: flex;
|
|
13
|
+
gap: var(--marquee-gap);
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
// Logical: in a right-to-left page the strip starts at the right edge and travels right.
|
|
16
|
+
&:dir(rtl) {
|
|
17
|
+
--marquee-sign: 1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.track {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex: 0 0 auto;
|
|
24
|
+
min-inline-size: 100%;
|
|
25
|
+
gap: var(--marquee-gap);
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: space-around;
|
|
28
|
+
animation: marquee-run var(--marquee-seconds, 30s) linear infinite var(--marquee-direction, normal);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Hover, keyboard focus anywhere inside, and the MotionToggle (`html[data-motion='paused']`) all
|
|
32
|
+
// stop the strip; none of them needs script.
|
|
33
|
+
.root:hover .track,
|
|
34
|
+
.root:focus-within .track,
|
|
35
|
+
:global(html[data-motion='paused']) .track {
|
|
36
|
+
animation-play-state: paused;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Reduced motion: no travel at all, and the one real track scrolls by hand so nothing is clipped.
|
|
40
|
+
@media (prefers-reduced-motion: reduce) {
|
|
41
|
+
.root {
|
|
42
|
+
overflow-x: auto;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.track {
|
|
46
|
+
animation: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.clone {
|
|
50
|
+
display: none;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// An endless strip. The duplicate track is `aria-hidden` and `inert` (a link inside must not be
|
|
2
|
+
// tabbable twice); pausing and RTL are CSS, so the strip needs no script.
|
|
3
|
+
|
|
4
|
+
import { cx } from '@ultimat3/ui';
|
|
5
|
+
import type { JSX } from 'solid-js';
|
|
6
|
+
import styles from './Marquee.module.scss';
|
|
7
|
+
import { MARQUEE_BACKEND, marqueeVars } from './marquee-view';
|
|
8
|
+
|
|
9
|
+
export interface MarqueeProps {
|
|
10
|
+
/** Called once per track: a DOM node can only live in one place. */
|
|
11
|
+
children: () => JSX.Element;
|
|
12
|
+
/** Seconds for one loop. */
|
|
13
|
+
seconds?: number | undefined;
|
|
14
|
+
reverse?: boolean | undefined;
|
|
15
|
+
class?: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Marquee(props: MarqueeProps): JSX.Element {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
class={cx(styles['root'], props.class)}
|
|
22
|
+
data-effect-backend={MARQUEE_BACKEND}
|
|
23
|
+
style={marqueeVars(props.seconds, props.reverse === true)}
|
|
24
|
+
>
|
|
25
|
+
<div class={styles['track']}>{props.children()}</div>
|
|
26
|
+
<div class={cx(styles['track'], styles['clone'])} aria-hidden="true" inert>
|
|
27
|
+
{props.children()}
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Marquee's inputs, validated once: how long one loop takes and the gap between items. Everything
|
|
2
|
+
// else (pause on hover/focus/toggle, RTL) is CSS, so the strip works with no script at all.
|
|
3
|
+
|
|
4
|
+
import { EffectsInvalidValueError } from '../errors';
|
|
5
|
+
|
|
6
|
+
export const MARQUEE_BACKEND = 'css';
|
|
7
|
+
export const MARQUEE_DEFAULT_SECONDS = 30;
|
|
8
|
+
|
|
9
|
+
export function marqueeSeconds(requested: number | undefined): number {
|
|
10
|
+
if (requested === undefined) return MARQUEE_DEFAULT_SECONDS;
|
|
11
|
+
if (!Number.isFinite(requested) || requested <= 0) {
|
|
12
|
+
throw new EffectsInvalidValueError({
|
|
13
|
+
cause: `Marquee seconds must be a positive finite number, got ${String(requested)}.`,
|
|
14
|
+
fix: `<Marquee seconds={${MARQUEE_DEFAULT_SECONDS}}>{() => 'item'}</Marquee> // seconds > 0 for one loop, or omit seconds`,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return requested;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function marqueeVars(seconds: number | undefined, reverse: boolean): Record<string, string> {
|
|
21
|
+
return {
|
|
22
|
+
'--marquee-seconds': `${marqueeSeconds(seconds)}s`,
|
|
23
|
+
'--marquee-direction': reverse ? 'reverse' : 'normal',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
@use '@ultimat3/ui/tokens' as t;
|
|
2
|
+
@use '../effect' as fx;
|
|
3
|
+
|
|
4
|
+
.root {
|
|
5
|
+
@include fx.root;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.layer {
|
|
9
|
+
@include fx.layer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.content {
|
|
13
|
+
@include fx.content;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Frame 0 as real tiles: the same alpha and mix the canvas starts from, one custom property each.
|
|
17
|
+
.tiles {
|
|
18
|
+
@include fx.frame('.root');
|
|
19
|
+
display: grid;
|
|
20
|
+
grid-template-columns: repeat(var(--fx-cols, 16), 1fr);
|
|
21
|
+
grid-auto-rows: 1fr;
|
|
22
|
+
gap: t.stroke(hairline);
|
|
23
|
+
block-size: 100%;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.tile {
|
|
27
|
+
background: color-mix(in srgb, rgb(var(--fx-c1)) calc(var(--fx-m) * 100%), rgb(var(--fx-c0)));
|
|
28
|
+
opacity: var(--fx-a);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.canvas {
|
|
32
|
+
@include fx.canvas('.root');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@media (forced-colors: active) {
|
|
36
|
+
.layer {
|
|
37
|
+
display: none;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// A holographic tile wall: tiles shifting between two colour roles. The server renders frame 0 as
|
|
2
|
+
// real tiles (no blank canvas, no script needed); an island redraws the same function on a
|
|
3
|
+
// Canvas2D that `frameLoop` pauses offscreen, in a hidden tab and under reduced motion.
|
|
4
|
+
|
|
5
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
6
|
+
import { cx } from '@ultimat3/ui';
|
|
7
|
+
import type { JSX } from 'solid-js';
|
|
8
|
+
import { useEffectMount } from '../use-effect-mount';
|
|
9
|
+
import styles from './MosaicGrid.module.scss';
|
|
10
|
+
import { drawMosaic, MOSAIC_GRID_BACKEND, mosaicGridView } from './mosaic-grid-view';
|
|
11
|
+
|
|
12
|
+
export interface MosaicGridProps {
|
|
13
|
+
/** Tiles across, 4..32. Default 16. */
|
|
14
|
+
cols?: number | undefined;
|
|
15
|
+
/** Tiles down, 3..20. Default 9. */
|
|
16
|
+
rows?: number | undefined;
|
|
17
|
+
/** The two colour roles tiles shift between. Default `['accent', 'info']`. */
|
|
18
|
+
roles?: readonly ColorRole[] | undefined;
|
|
19
|
+
/** Shift speed multiplier, 0.25..4. Default 1. */
|
|
20
|
+
speed?: number | undefined;
|
|
21
|
+
/** What the mosaic sits behind. */
|
|
22
|
+
children?: JSX.Element | undefined;
|
|
23
|
+
class?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function MosaicGrid(props: MosaicGridProps): JSX.Element {
|
|
27
|
+
const view = mosaicGridView(props);
|
|
28
|
+
const fx = useEffectMount(
|
|
29
|
+
{
|
|
30
|
+
css: false,
|
|
31
|
+
wants: 'canvas',
|
|
32
|
+
speed: view.speed,
|
|
33
|
+
roles: view.roles,
|
|
34
|
+
draw2d: (colours) => drawMosaic(view.cols, view.rows, colours),
|
|
35
|
+
},
|
|
36
|
+
MOSAIC_GRID_BACKEND,
|
|
37
|
+
);
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
ref={fx.root}
|
|
41
|
+
class={cx(styles['root'], props.class)}
|
|
42
|
+
style={view.vars}
|
|
43
|
+
data-effect-backend={fx.backend()}
|
|
44
|
+
>
|
|
45
|
+
<div class={styles['layer']} aria-hidden="true">
|
|
46
|
+
<div class={styles['tiles']}>
|
|
47
|
+
{view.cells.map((cell) => (
|
|
48
|
+
<span
|
|
49
|
+
class={styles['tile']}
|
|
50
|
+
style={{ '--fx-a': String(cell.alpha), '--fx-m': String(cell.mix) }}
|
|
51
|
+
/>
|
|
52
|
+
))}
|
|
53
|
+
</div>
|
|
54
|
+
<canvas ref={fx.canvas} class={styles['canvas']} />
|
|
55
|
+
</div>
|
|
56
|
+
<div class={styles['content']}>{props.children}</div>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// MosaicGrid's rules: one function gives every tile's brightness and hue mix at any time, and the
|
|
2
|
+
// server's tiles (time 0) and every canvas frame are that function — the island's first frame is
|
|
3
|
+
// the page's, so the canvas never flashes in over a different picture.
|
|
4
|
+
|
|
5
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
6
|
+
import type { EffectBackend } from '../backend';
|
|
7
|
+
import type { CanvasDraw } from '../canvas-mount';
|
|
8
|
+
import { cssRgb, type Rgb } from '../palette';
|
|
9
|
+
import { rangeProp, rolesProp, roleVars } from '../props';
|
|
10
|
+
|
|
11
|
+
/** Server tiles do not animate: still until an island draws them on a canvas. */
|
|
12
|
+
export const MOSAIC_GRID_BACKEND: EffectBackend = 'static';
|
|
13
|
+
|
|
14
|
+
export const MOSAIC_GRID_ROLES: readonly ColorRole[] = ['accent', 'info'];
|
|
15
|
+
|
|
16
|
+
export interface MosaicCell {
|
|
17
|
+
/** Tile opacity, 0..1. */
|
|
18
|
+
readonly alpha: number;
|
|
19
|
+
/** How far from the first role toward the second, 0..1. */
|
|
20
|
+
readonly mix: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const round = (value: number): number => Math.round(value * 100) / 100;
|
|
24
|
+
|
|
25
|
+
/** Rounded to hundredths, so the server's custom properties and the canvas agree exactly. */
|
|
26
|
+
export function mosaicCell(col: number, row: number, time: number): MosaicCell {
|
|
27
|
+
const wave =
|
|
28
|
+
Math.sin(col * 0.55 + row * 0.9 + time * 1.2) * Math.cos(row * 0.35 - col * 0.2 - time * 0.7);
|
|
29
|
+
return {
|
|
30
|
+
alpha: round(0.18 + 0.62 * (0.5 + 0.5 * wave)),
|
|
31
|
+
mix: round(0.5 + 0.5 * Math.sin((col - row) * 0.4 + time * 0.5)),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MosaicGridInput {
|
|
36
|
+
readonly cols?: number | undefined;
|
|
37
|
+
readonly rows?: number | undefined;
|
|
38
|
+
readonly roles?: readonly ColorRole[] | undefined;
|
|
39
|
+
readonly speed?: number | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface MosaicGridView {
|
|
43
|
+
readonly cols: number;
|
|
44
|
+
readonly rows: number;
|
|
45
|
+
readonly roles: readonly ColorRole[];
|
|
46
|
+
readonly speed: number;
|
|
47
|
+
/** Frame 0, row-major. */
|
|
48
|
+
readonly cells: readonly MosaicCell[];
|
|
49
|
+
readonly vars: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function mosaicGridView(input: MosaicGridInput): MosaicGridView {
|
|
53
|
+
const cols = Math.round(
|
|
54
|
+
rangeProp('MosaicGrid', 'cols', input.cols, { min: 4, max: 32, fallback: 16 }),
|
|
55
|
+
);
|
|
56
|
+
const rows = Math.round(
|
|
57
|
+
rangeProp('MosaicGrid', 'rows', input.rows, { min: 3, max: 20, fallback: 9 }),
|
|
58
|
+
);
|
|
59
|
+
const roles = rolesProp('MosaicGrid', input.roles, MOSAIC_GRID_ROLES, { min: 2, max: 2 });
|
|
60
|
+
const speed = rangeProp('MosaicGrid', 'speed', input.speed, { min: 0.25, max: 4, fallback: 1 });
|
|
61
|
+
const cells: MosaicCell[] = [];
|
|
62
|
+
for (let row = 0; row < rows; row++) {
|
|
63
|
+
for (let col = 0; col < cols; col++) cells.push(mosaicCell(col, row, 0));
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
cols,
|
|
67
|
+
rows,
|
|
68
|
+
roles,
|
|
69
|
+
speed,
|
|
70
|
+
cells,
|
|
71
|
+
vars: { ...roleVars(roles), '--fx-cols': String(cols) },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const lerp = (a: Rgb, b: Rgb, t: number): Rgb => [
|
|
76
|
+
a[0] + (b[0] - a[0]) * t,
|
|
77
|
+
a[1] + (b[1] - a[1]) * t,
|
|
78
|
+
a[2] + (b[2] - a[2]) * t,
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
/** The canvas frame at `frame.time`: the same tiles `mosaicCell` gave the server, moving. */
|
|
82
|
+
export function drawMosaic(cols: number, rows: number, colours: () => readonly Rgb[]): CanvasDraw {
|
|
83
|
+
return (ctx, frame) => {
|
|
84
|
+
const [first, second] = colours();
|
|
85
|
+
if (first === undefined || second === undefined) return;
|
|
86
|
+
const width = frame.width / cols;
|
|
87
|
+
const height = frame.height / rows;
|
|
88
|
+
for (let row = 0; row < rows; row++) {
|
|
89
|
+
for (let col = 0; col < cols; col++) {
|
|
90
|
+
const cell = mosaicCell(col, row, frame.time);
|
|
91
|
+
ctx.fillStyle = cssRgb(lerp(first, second, cell.mix), cell.alpha);
|
|
92
|
+
ctx.fillRect(col * width, row * height, width - 1, height - 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The motion port every mount takes (`frameLoop`, `motionAllowed`, `onMotionChange`), so a test
|
|
2
|
+
// drives frames by hand and the four stop reasons (reduced motion, hidden tab, offscreen, the
|
|
3
|
+
// `MotionToggle` pause) stay `frameLoop`'s, never re-implemented here. A tick reads its own clock
|
|
4
|
+
// and a change re-reads `motionAllowed()`, so nothing here depends on what either callback carries.
|
|
5
|
+
|
|
6
|
+
import { frameLoop, motionAllowed, onMotionChange } from '@ultimat3/ui/motion';
|
|
7
|
+
|
|
8
|
+
export interface MotionPort {
|
|
9
|
+
/** Calls `tick` once per frame while `el` may animate; the answer stops it for good. */
|
|
10
|
+
readonly loop: (tick: () => void, el: Element) => () => void;
|
|
11
|
+
readonly allowed: () => boolean;
|
|
12
|
+
/** Calls `listener` when the answer of `allowed()` may have changed; the answer unsubscribes. */
|
|
13
|
+
readonly onChange: (listener: () => void) => () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function browserMotion(): MotionPort {
|
|
17
|
+
return {
|
|
18
|
+
loop: (tick, el) => frameLoop(() => tick(), { el }),
|
|
19
|
+
allowed: () => motionAllowed(),
|
|
20
|
+
onChange: (listener) => onMotionChange(() => listener()),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@use '@ultimat3/ui/tokens' as t;
|
|
2
|
+
@use '../effect' as fx;
|
|
3
|
+
|
|
4
|
+
.root {
|
|
5
|
+
@include fx.root;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.layer {
|
|
9
|
+
@include fx.layer;
|
|
10
|
+
inline-size: 100%;
|
|
11
|
+
block-size: 100%;
|
|
12
|
+
color: rgb(var(--fx-c0));
|
|
13
|
+
opacity: var(--fx-opacity, 0.12);
|
|
14
|
+
|
|
15
|
+
@media (prefers-contrast: more), (forced-colors: active) {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.content {
|
|
21
|
+
@include fx.content;
|
|
22
|
+
}
|