@wolsok/loading-wave 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +95 -2
- package/esm2022/index.js +6 -0
- package/esm2022/index.js.map +1 -0
- package/esm2022/lib/canvas-wave-renderer.js +103 -0
- package/esm2022/lib/canvas-wave-renderer.js.map +1 -0
- package/esm2022/lib/choose-wave-renderer.js +61 -0
- package/esm2022/lib/choose-wave-renderer.js.map +1 -0
- package/esm2022/lib/dot-color.js +63 -0
- package/esm2022/lib/dot-color.js.map +1 -0
- package/esm2022/lib/loading-wave-options.js +34 -0
- package/esm2022/lib/loading-wave-options.js.map +1 -0
- package/esm2022/lib/loading-wave.directive.js +74 -0
- package/esm2022/lib/loading-wave.directive.js.map +1 -0
- package/esm2022/lib/loading-wave.js +230 -0
- package/esm2022/lib/loading-wave.js.map +1 -0
- package/esm2022/lib/renderer.js +18 -0
- package/esm2022/lib/renderer.js.map +1 -0
- package/esm2022/lib/wave-environment.js +59 -0
- package/esm2022/lib/wave-environment.js.map +1 -0
- package/esm2022/lib/wave-model.js +147 -0
- package/esm2022/lib/wave-model.js.map +1 -0
- package/esm2022/lib/wave-timeline.js +61 -0
- package/esm2022/lib/wave-timeline.js.map +1 -0
- package/esm2022/lib/webgl/wave-shaders.js +114 -0
- package/esm2022/lib/webgl/wave-shaders.js.map +1 -0
- package/esm2022/lib/webgl/webgl-wave-renderer.js +172 -0
- package/esm2022/lib/webgl/webgl-wave-renderer.js.map +1 -0
- package/esm2022/wolsok-loading-wave.js +5 -0
- package/esm2022/wolsok-loading-wave.js.map +1 -0
- package/index.d.ts +4 -0
- package/lib/canvas-wave-renderer.d.ts +27 -0
- package/lib/choose-wave-renderer.d.ts +28 -0
- package/lib/dot-color.d.ts +15 -0
- package/lib/loading-wave-options.d.ts +35 -0
- package/lib/loading-wave.d.ts +55 -0
- package/lib/loading-wave.directive.d.ts +29 -0
- package/lib/renderer.d.ts +49 -0
- package/lib/wave-environment.d.ts +23 -0
- package/lib/wave-model.d.ts +74 -0
- package/lib/wave-timeline.d.ts +33 -0
- package/lib/webgl/wave-shaders.d.ts +14 -0
- package/lib/webgl/webgl-wave-renderer.d.ts +47 -0
- package/package.json +44 -3
- package/wolsok-loading-wave.d.ts +5 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The loading wave as pure math, shared by the 2D canvas renderer and
|
|
3
|
+
* mirrored by the WebGL shader (`webgl/wave-shaders.ts`).
|
|
4
|
+
*
|
|
5
|
+
* The wave front is an arc of a circle whose centre lies far left of the
|
|
6
|
+
* element, at mid-height: a ripple from off-screen. Its radius grows at an
|
|
7
|
+
* even speed, so the front sweeps from the left edge until the lit tail
|
|
8
|
+
* behind it has left the element at every row, then starts again.
|
|
9
|
+
* Every length is in CSS pixels, every time in milliseconds.
|
|
10
|
+
*/
|
|
11
|
+
/** how lit a dot stays once the front passed it, as in the video */
|
|
12
|
+
export declare const AFTERGLOW = 0.45;
|
|
13
|
+
/** share of a sweep after which a passed dot's afterglow starts to fade */
|
|
14
|
+
export declare const AFTERGLOW_FADE_START = 0.45;
|
|
15
|
+
/**
|
|
16
|
+
* The most dots a grid holds: a tiny spacing on a large host is widened
|
|
17
|
+
* rather than creating millions of dots each frame.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAX_DOTS = 20000;
|
|
20
|
+
export interface WaveGeometry {
|
|
21
|
+
readonly width: number;
|
|
22
|
+
readonly height: number;
|
|
23
|
+
readonly dotSpacing: number;
|
|
24
|
+
readonly sweepMs: number;
|
|
25
|
+
readonly centerX: number;
|
|
26
|
+
readonly centerY: number;
|
|
27
|
+
/** the front's radius at the start of a sweep: it touches the left edge */
|
|
28
|
+
readonly startRadius: number;
|
|
29
|
+
/** the front's radius at the end of a sweep: the tail left every row */
|
|
30
|
+
readonly endRadius: number;
|
|
31
|
+
/** how far the front's radius grows in one sweep */
|
|
32
|
+
readonly travel: number;
|
|
33
|
+
/** distance behind the front over which a dot dims to 1/e */
|
|
34
|
+
readonly falloff: number;
|
|
35
|
+
/** distance ahead of the front over which a dot lights up */
|
|
36
|
+
readonly rise: number;
|
|
37
|
+
/** length of the lit tail behind the front */
|
|
38
|
+
readonly tail: number;
|
|
39
|
+
/** the farthest a lit dot is pushed along the wave */
|
|
40
|
+
readonly maxPush: number;
|
|
41
|
+
}
|
|
42
|
+
export interface WaveGeometryOptions {
|
|
43
|
+
readonly dotSpacing: number;
|
|
44
|
+
readonly sweepMs: number;
|
|
45
|
+
}
|
|
46
|
+
export interface Point {
|
|
47
|
+
readonly x: number;
|
|
48
|
+
readonly y: number;
|
|
49
|
+
}
|
|
50
|
+
export interface Displacement {
|
|
51
|
+
readonly dx: number;
|
|
52
|
+
readonly dy: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function waveGeometry(width: number, height: number, { dotSpacing: askedSpacing, sweepMs }: WaveGeometryOptions): WaveGeometry;
|
|
55
|
+
/** the share of the current sweep that has passed, 0 up to (not including) 1 */
|
|
56
|
+
export declare function sweepPhase(geometry: WaveGeometry, elapsedMs: number): number;
|
|
57
|
+
/** the front's radius at the time `elapsedMs` */
|
|
58
|
+
export declare function frontRadius(geometry: WaveGeometry, elapsedMs: number): number;
|
|
59
|
+
/** whether a sweep went before this one, whose afterglow and echo show */
|
|
60
|
+
export declare function hasPreviousSweep(geometry: WaveGeometry, elapsedMs: number): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* How much the wave lights the dot at `(x, y)`: 1 right behind the front,
|
|
63
|
+
* dimming over a few spacings to the afterglow of the dots it passed, which
|
|
64
|
+
* fades out again until the next front comes. On the first sweep nothing
|
|
65
|
+
* ahead of the front is lit.
|
|
66
|
+
*/
|
|
67
|
+
export declare function waveIntensity(x: number, y: number, elapsedMs: number, geometry: WaveGeometry): number;
|
|
68
|
+
/**
|
|
69
|
+
* How far the wave pushes the dot at `(x, y)` away from the circle's centre:
|
|
70
|
+
* nothing at rest, most at one falloff behind the front.
|
|
71
|
+
*/
|
|
72
|
+
export declare function dotDisplacement(x: number, y: number, elapsedMs: number, geometry: WaveGeometry): Displacement;
|
|
73
|
+
/** the centres of the grid's dots, row by row, each centred in its cell */
|
|
74
|
+
export declare function dotCenters({ width, height, dotSpacing, }: Pick<WaveGeometry, 'width' | 'height' | 'dotSpacing'>): Point[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AfterLoading } from './loading-wave-options';
|
|
2
|
+
import type { WaveFrame } from './renderer';
|
|
3
|
+
/** how long the wave and the dots take to fade in or out */
|
|
4
|
+
export declare const FADE_MS = 400;
|
|
5
|
+
export interface TimelineFrame {
|
|
6
|
+
readonly frame: WaveFrame;
|
|
7
|
+
/** frames stay the same from now on until loading changes again */
|
|
8
|
+
readonly settled: boolean;
|
|
9
|
+
/** `'hide'` faded out completely: the effect can go */
|
|
10
|
+
readonly finished: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What the effect shows over time, as loading starts and stops: the wave
|
|
14
|
+
* sweeps from the left edge each time loading starts; wave and dots fade in
|
|
15
|
+
* and out over `FADE_MS`, starting from where they are. Without motion
|
|
16
|
+
* (`prefers-reduced-motion`) the wave never shows.
|
|
17
|
+
*/
|
|
18
|
+
export declare class WaveTimeline {
|
|
19
|
+
private readonly afterLoading;
|
|
20
|
+
private readonly motion;
|
|
21
|
+
private loading;
|
|
22
|
+
private sweepStartedAt;
|
|
23
|
+
private wave;
|
|
24
|
+
private dots;
|
|
25
|
+
/**
|
|
26
|
+
* @param restingDots opacity the dots start with before loading: 1 to show
|
|
27
|
+
* the dots `'keep'` left, say after the options changed
|
|
28
|
+
*/
|
|
29
|
+
constructor(afterLoading: AfterLoading, motion: boolean, restingDots?: number);
|
|
30
|
+
start(now: number): void;
|
|
31
|
+
stop(now: number): void;
|
|
32
|
+
frameAt(now: number): TimelineFrame;
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** strength of the echo ripple trailing the front, times the main front's */
|
|
2
|
+
export declare const ECHO_STRENGTH = 0.4;
|
|
3
|
+
/** the echo trails the front by this share of a sweep */
|
|
4
|
+
export declare const ECHO_LAG: number;
|
|
5
|
+
/** one triangle that covers the whole canvas, no vertex buffer needed */
|
|
6
|
+
export declare const WAVE_VERTEX_SHADER = "#version 300 es\nvoid main() {\n vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);\n}\n";
|
|
7
|
+
/**
|
|
8
|
+
* The wave model of `wave-model.ts` (front glow, afterglow, push) per pixel, for every dot of the 3 × 3
|
|
9
|
+
* cells around it: brightness, growth and push behind the front, plus what
|
|
10
|
+
* the 2D canvas cannot afford: a glow around lit dots and an echo ripple
|
|
11
|
+
* trailing the front. Lengths are in CSS pixels, y grows downwards as in CSS.
|
|
12
|
+
* A negative `u_echoRadius` shows no echo, as before the echo's first sweep.
|
|
13
|
+
*/
|
|
14
|
+
export declare const WAVE_FRAGMENT_SHADER: string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { WaveFrame, WaveLook, WaveRenderer } from '../renderer';
|
|
2
|
+
import { WaveGeometry } from '../wave-model';
|
|
3
|
+
/** the shaders did not compile or link on this GPU */
|
|
4
|
+
export declare class WaveShaderError extends Error {
|
|
5
|
+
readonly name = "WaveShaderError";
|
|
6
|
+
}
|
|
7
|
+
export interface WebGlWaveRendererHooks {
|
|
8
|
+
/** the browser took the GPU context away; the renderer draws no more */
|
|
9
|
+
readonly onContextLost: () => void;
|
|
10
|
+
/** called once by dispose(), after the context was freed */
|
|
11
|
+
readonly onDispose?: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Draws the wave with a WebGL2 fragment shader: the 2D canvas's look plus a
|
|
15
|
+
* glow around lit dots and an echo ripple trailing the front.
|
|
16
|
+
*/
|
|
17
|
+
export declare class WebGlWaveRenderer implements WaveRenderer {
|
|
18
|
+
readonly canvas: HTMLCanvasElement;
|
|
19
|
+
private readonly gl;
|
|
20
|
+
private look;
|
|
21
|
+
private readonly hooks;
|
|
22
|
+
readonly kind = "webgl";
|
|
23
|
+
private readonly program;
|
|
24
|
+
private readonly uniforms;
|
|
25
|
+
private geometry?;
|
|
26
|
+
private lost;
|
|
27
|
+
private disposed;
|
|
28
|
+
private readonly handleContextLost;
|
|
29
|
+
/** @throws WaveShaderError when the shaders fail on this GPU */
|
|
30
|
+
constructor(canvas: HTMLCanvasElement, gl: WebGL2RenderingContext, look: WaveLook, hooks: WebGlWaveRendererHooks);
|
|
31
|
+
/**
|
|
32
|
+
* A WebGL2 context, or `null` where the browser offers none. With
|
|
33
|
+
* `hardwareOnly` also `null` where it would render on the CPU (no GPU, a
|
|
34
|
+
* blocked driver, a software renderer).
|
|
35
|
+
*/
|
|
36
|
+
static createContext(canvas: HTMLCanvasElement, hardwareOnly?: boolean): WebGL2RenderingContext | null;
|
|
37
|
+
resize(geometry: WaveGeometry, pixelRatio: number): void;
|
|
38
|
+
draw(frame: WaveFrame): void;
|
|
39
|
+
setLook(look: WaveLook): void;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
private setUniforms;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The echo's radius, trailing the front by `ECHO_LAG` of a sweep; negative,
|
|
45
|
+
* so no echo shows, until the front has run that far.
|
|
46
|
+
*/
|
|
47
|
+
export declare function echoRadius(geometry: WaveGeometry, elapsedMs: number): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wolsok/loading-wave",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "An Angular directive that lays a calm loading wave of lit dots behind any element, on the GPU with a 2D canvas fallback",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/WolfSoko/wol-sok-mono/issues"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://angularexamples.wolsok.de/loadingWavePlayground",
|
|
9
|
+
"repository": "https://github.com/WolfSoko/wol-sok-mono/tree/main/libs/public/ws-loading-wave",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"wolf soko",
|
|
13
|
+
"wolsok",
|
|
14
|
+
"angular",
|
|
15
|
+
"angular-lib",
|
|
16
|
+
"directive",
|
|
17
|
+
"loading",
|
|
18
|
+
"loading-indicator",
|
|
19
|
+
"animation",
|
|
20
|
+
"webgl",
|
|
21
|
+
"shader",
|
|
22
|
+
"dots",
|
|
23
|
+
"wave"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@angular/core": "^22.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"tslib": "^2.3.0"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"module": "esm2022/wolsok-loading-wave.js",
|
|
35
|
+
"typings": "wolsok-loading-wave.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": {
|
|
38
|
+
"default": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./wolsok-loading-wave.d.ts",
|
|
42
|
+
"default": "./esm2022/wolsok-loading-wave.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"type": "module"
|
|
6
47
|
}
|