@wolsok/thanos 17.0.37 → 18.0.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.
Files changed (48) hide show
  1. package/README.md +73 -12
  2. package/esm2022/lib/canvas-particle-renderer.js +98 -0
  3. package/esm2022/lib/canvas-particle-renderer.js.map +1 -0
  4. package/esm2022/lib/capture-scale.js +13 -0
  5. package/esm2022/lib/capture-scale.js.map +1 -0
  6. package/esm2022/lib/choose-particle-renderer.js +78 -0
  7. package/esm2022/lib/choose-particle-renderer.js.map +1 -0
  8. package/esm2022/lib/create-ws-thanos-options.js +4 -1
  9. package/esm2022/lib/create-ws-thanos-options.js.map +1 -1
  10. package/esm2022/lib/crumble-shape.js +24 -0
  11. package/esm2022/lib/crumble-shape.js.map +1 -0
  12. package/esm2022/lib/particle-renderer.js +1 -0
  13. package/esm2022/lib/particle-renderer.js.map +1 -0
  14. package/esm2022/lib/particles.js +84 -0
  15. package/esm2022/lib/particles.js.map +1 -0
  16. package/esm2022/lib/snap-sound-envelopes.js +38 -0
  17. package/esm2022/lib/snap-sound-envelopes.js.map +1 -0
  18. package/esm2022/lib/snap-sound.service.js +287 -0
  19. package/esm2022/lib/snap-sound.service.js.map +1 -0
  20. package/esm2022/lib/vaporizing-front.js +48 -0
  21. package/esm2022/lib/vaporizing-front.js.map +1 -0
  22. package/esm2022/lib/webgl/simplex-noise.glsl.js +69 -0
  23. package/esm2022/lib/webgl/simplex-noise.glsl.js.map +1 -0
  24. package/esm2022/lib/webgl/webgl-particle-renderer.js +308 -0
  25. package/esm2022/lib/webgl/webgl-particle-renderer.js.map +1 -0
  26. package/esm2022/lib/webgl/webgl-shaders.js +323 -0
  27. package/esm2022/lib/webgl/webgl-shaders.js.map +1 -0
  28. package/esm2022/lib/ws-thanos.directive.js +8 -6
  29. package/esm2022/lib/ws-thanos.directive.js.map +1 -1
  30. package/esm2022/lib/ws-thanos.options.js.map +1 -1
  31. package/esm2022/lib/ws-thanos.service.js +103 -220
  32. package/esm2022/lib/ws-thanos.service.js.map +1 -1
  33. package/lib/canvas-particle-renderer.d.ts +29 -0
  34. package/lib/capture-scale.d.ts +14 -0
  35. package/lib/choose-particle-renderer.d.ts +31 -0
  36. package/lib/crumble-shape.d.ts +11 -0
  37. package/lib/particle-renderer.d.ts +26 -0
  38. package/lib/particles.d.ts +35 -0
  39. package/lib/snap-sound-envelopes.d.ts +15 -0
  40. package/lib/snap-sound.service.d.ts +27 -0
  41. package/lib/vaporizing-front.d.ts +34 -0
  42. package/lib/webgl/simplex-noise.glsl.d.ts +5 -0
  43. package/lib/webgl/webgl-particle-renderer.d.ts +46 -0
  44. package/lib/webgl/webgl-shaders.d.ts +27 -0
  45. package/lib/ws-thanos.directive.d.ts +4 -2
  46. package/lib/ws-thanos.options.d.ts +14 -0
  47. package/lib/ws-thanos.service.d.ts +11 -8
  48. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The vaporizing front sweeps from the top right to the bottom left of the element.
3
+ * Shared by the CPU and the GPU simulation, the GPU gets the values below as uniforms
4
+ * and the constants interpolated into its shader.
5
+ */
6
+ /** some random looking waves give the front a frayed edge */
7
+ export declare const FRONT_FRAY: {
8
+ readonly xWave: 30;
9
+ readonly xPhase: 723.394;
10
+ readonly xSeed: 12.5;
11
+ readonly xAmplitude: 11;
12
+ readonly yWave: 100;
13
+ readonly yPhase: 2323.234;
14
+ readonly ySeed: 456.1;
15
+ readonly yAmplitude: 23;
16
+ };
17
+ /** the noise field released particles flow along */
18
+ export declare const FLOW_FIELD: {
19
+ readonly frequency: 0.01;
20
+ readonly xSeedOffset: 33.23;
21
+ readonly ySeedDivisor: 13.23;
22
+ };
23
+ export interface VaporizingFront {
24
+ /** drives the fray waves */
25
+ time: number;
26
+ /** particles further than this (squared) from the bottom left corner break off */
27
+ radiusPow: number;
28
+ /** alpha factor that fades the particles out very late */
29
+ fade: number;
30
+ }
31
+ /** where the front is at the given animation progress */
32
+ export declare function vaporizingFront(animationT: number, maxParticleX: number, minParticleY: number, height: number): VaporizingFront;
33
+ /** has the front passed the particle at x, y. No tan() waves: their poles break off whole rows */
34
+ export declare function isBehindFront(x: number, y: number, height: number, deltaTSec: number, seed: number, { time, radiusPow }: VaporizingFront): boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 3D simplex noise by Ian McEwan, Ashima Arts (MIT License)
3
+ * https://github.com/ashima/webgl-noise
4
+ */
5
+ export declare const SIMPLEX_NOISE_3D = "\nvec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec4 permute(vec4 x) { return mod289(((x * 34.0) + 10.0) * x); }\nvec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }\n\nfloat snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n\n i = mod289(i);\n vec4 p = permute(permute(permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n\n vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n vec4 m = max(0.5 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 105.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\n";
@@ -0,0 +1,46 @@
1
+ import { AnimationState } from '../animation.state';
2
+ import { ParticleRenderer, ParticleRendererParams } from '../particle-renderer';
3
+ import { Particles } from '../particles';
4
+ import { WsThanosCrumble } from '../ws-thanos.options';
5
+ /**
6
+ * Simulates and draws the particles on the GPU.
7
+ * The particle state lives in two buffers: every frame the update program reads
8
+ * one and writes the other via transform feedback, then the draw program renders it.
9
+ * Once at the start the crack program computes the shard and crack distances of every particle.
10
+ */
11
+ export declare class WebGlParticleRenderer implements ParticleRenderer {
12
+ readonly canvas: HTMLCanvasElement;
13
+ private readonly gl;
14
+ private readonly params;
15
+ readonly kind = "webgl";
16
+ readonly crumble: WsThanosCrumble;
17
+ private readonly count;
18
+ private readonly maxParticleX;
19
+ private readonly minParticleY;
20
+ private readonly updateProgram;
21
+ private readonly drawProgram;
22
+ private readonly buffers;
23
+ private readonly stateBuffers;
24
+ private readonly updateVaos;
25
+ private readonly drawVaos;
26
+ private readonly updateUniforms;
27
+ private readonly drawUniforms;
28
+ private current;
29
+ /** get a WebGL2 context for the canvas or null if the browser can't */
30
+ static createContext(canvas: HTMLCanvasElement): WebGL2RenderingContext | null;
31
+ /** the largest canvas size the GPU can render into */
32
+ static maxCanvasSize(gl: WebGL2RenderingContext): number;
33
+ constructor(canvas: HTMLCanvasElement, gl: WebGL2RenderingContext, particles: Particles, params: ParticleRendererParams);
34
+ render({ deltaTSec, animationT }: AnimationState): void;
35
+ dispose(): void;
36
+ /** run the bound vertex array through the bound program into the target buffer */
37
+ private runTransformFeedback;
38
+ /** run the crack program once: shard center and crack distances per particle */
39
+ private createCracks;
40
+ private uniformLocations;
41
+ private createProgram;
42
+ private compileShader;
43
+ /** a buffer with the given data, or of the given byte size when it is filled on the GPU */
44
+ private createBuffer;
45
+ private createVao;
46
+ }
@@ -0,0 +1,27 @@
1
+ import { WsThanosCrumble } from '../ws-thanos.options';
2
+ /** attribute locations shared by all programs */
3
+ export declare const AttributeLocation: {
4
+ readonly POSITION: 0;
5
+ readonly VELOCITY: 1;
6
+ readonly ACCELERATION: 2;
7
+ readonly ALPHA: 3;
8
+ readonly COLOR: 4;
9
+ readonly RELEASED_AT: 5;
10
+ readonly CRACK: 6;
11
+ readonly CELL_RANDOM: 7;
12
+ };
13
+ /** crumble mode as passed to the shaders */
14
+ export declare const CRUMBLE_MODE: Record<WsThanosCrumble, number>;
15
+ export declare const UPDATE_FEEDBACK_VARYINGS: string[];
16
+ export declare const CRACK_FEEDBACK_VARYINGS: string[];
17
+ /** floats per particle written by the crack program */
18
+ export declare const CRACK_LENGTH = 5;
19
+ /** runs once: which shard each particle belongs to and how far it is from the next crack */
20
+ export declare const CRACK_VERTEX_SHADER: string;
21
+ /** moves the particles, the GPU port of updateParticlesOnCpu plus the crumble modes */
22
+ export declare const UPDATE_VERTEX_SHADER: string;
23
+ /** transform feedback only, nothing is rasterized */
24
+ export declare const FEEDBACK_FRAGMENT_SHADER = "#version 300 es\nprecision mediump float;\nout vec4 outColor;\nvoid main() {\n outColor = vec4(0.0);\n}\n";
25
+ /** draws every particle as one device pixel */
26
+ export declare const DRAW_VERTEX_SHADER: string;
27
+ export declare const DRAW_FRAGMENT_SHADER = "#version 300 es\nprecision mediump float;\nin vec4 vColor;\nout vec4 outColor;\nvoid main() {\n outColor = vColor;\n}\n";
@@ -1,11 +1,13 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { AnimationState } from './animation.state';
3
+ import type { WsThanosOptions } from './ws-thanos.options';
3
4
  import * as i0 from "@angular/core";
4
5
  export declare class WsThanosDirective {
5
6
  private wsThanosCompleteSubject;
6
7
  private untilDestroyed;
8
+ /** override the provided options for this element */
9
+ readonly wsThanosOptions: import("@angular/core").InputSignal<Partial<WsThanosOptions> | undefined>;
7
10
  wsThanosComplete: Observable<void>;
8
- private subscriptions;
9
11
  private readonly vaporizeDomElem;
10
12
  private readonly thanosService;
11
13
  private readonly thanosOptions;
@@ -25,5 +27,5 @@ export declare class WsThanosDirective {
25
27
  */
26
28
  vaporize(removeElem?: boolean): Observable<void>;
27
29
  static ɵfac: i0.ɵɵFactoryDeclaration<WsThanosDirective, never>;
28
- static ɵdir: i0.ɵɵDirectiveDeclaration<WsThanosDirective, "[wsThanos], ws-thanos", ["thanos"], {}, { "wsThanosComplete": "wsThanosComplete"; }, never, never, true, never>;
30
+ static ɵdir: i0.ɵɵDirectiveDeclaration<WsThanosDirective, "[wsThanos], ws-thanos", ["thanos"], { "wsThanosOptions": { "alias": "wsThanosOptions"; "required": false; "isSignal": true; }; }, { "wsThanosComplete": "wsThanosComplete"; }, never, never, true, never>;
29
31
  }
@@ -1,5 +1,19 @@
1
+ /**
2
+ * How the element breaks apart (needs WebGL2, the canvas fallback always uses 'dust'):
3
+ * - dust: particles blow away along the vaporizing front
4
+ * - cracks: cracks spread through the element before it turns to dust
5
+ * - shards: cracks split the element into shards that shift and tilt before they turn to dust
6
+ * - chunks: whole chunks break off, jump away and then crumble to dust
7
+ */
8
+ export type WsThanosCrumble = 'dust' | 'cracks' | 'shards' | 'chunks';
1
9
  export interface WsThanosOptions {
2
10
  animationLength: number;
3
11
  maxParticleCount: number;
4
12
  particleAcceleration: number;
13
+ /** play a windy, sandy sound while vaporizing */
14
+ sound: boolean;
15
+ /** volume of the snap sound between 0 and 1 */
16
+ soundVolume: number;
17
+ /** how the element breaks apart */
18
+ crumble: WsThanosCrumble;
5
19
  }
@@ -1,20 +1,23 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { AnimationState } from './animation.state';
3
+ import type { WsThanosOptions } from './ws-thanos.options';
3
4
  import * as i0 from "@angular/core";
4
5
  export declare class WsThanosService {
5
6
  private readonly thanosOptions;
6
- private static getParticleIndicesForBase;
7
- private static getColorIndicesForCoord;
8
- private static updateParticles;
9
- private static drawParticles;
10
- private static prepareCanvasForVaporize;
11
- private static createParticlesForImageData;
12
- private static getXYFromFlowField;
7
+ private readonly document;
8
+ private readonly snapSound;
9
+ /** shared by all effects, browsers only allow a few WebGL contexts */
10
+ private readonly gpuBudget;
13
11
  /**
14
12
  * start the vaporize-effect.
13
+ * @param options override the provided options for this element
15
14
  */
16
- vaporize(elem: HTMLElement): Observable<AnimationState>;
15
+ vaporize(elem: HTMLElement, options?: Partial<WsThanosOptions>): Observable<AnimationState>;
17
16
  private vaporizeIntern;
17
+ /** the element sits at the bottom left of the larger effect canvas */
18
+ private placeEffectCanvas;
19
+ /** position of the element inside its parent, where absolute children are placed */
20
+ private offsetInParent;
18
21
  static ɵfac: i0.ɵɵFactoryDeclaration<WsThanosService, never>;
19
22
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
20
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolsok/thanos",
3
- "version": "17.0.37",
3
+ "version": "18.0.0",
4
4
  "description": "Wolf Soko's implementation of a cool Thanos snapping vaporizing effect for destroying dom elements",
5
5
  "bugs": {
6
6
  "url": "https://github.com/WolfSoko/wol-sok-mono/issues"