@wolsok/thanos 17.0.16 → 17.0.18

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 (54) hide show
  1. package/esm2022/index.js +10 -0
  2. package/esm2022/index.js.map +1 -0
  3. package/esm2022/lib/animation.state.js +2 -0
  4. package/esm2022/lib/animation.state.js.map +1 -0
  5. package/esm2022/lib/create-ws-thanos-options.js +9 -0
  6. package/esm2022/lib/create-ws-thanos-options.js.map +1 -0
  7. package/esm2022/lib/simplex-noise-options.js +2 -0
  8. package/esm2022/lib/simplex-noise-options.js.map +1 -0
  9. package/esm2022/lib/simplex-noise.js +199 -0
  10. package/esm2022/lib/simplex-noise.js.map +1 -0
  11. package/esm2022/lib/ws-thanos-options.token.js +13 -0
  12. package/esm2022/lib/ws-thanos-options.token.js.map +1 -0
  13. package/esm2022/lib/ws-thanos.directive.js +67 -0
  14. package/esm2022/lib/ws-thanos.directive.js.map +1 -0
  15. package/esm2022/lib/ws-thanos.options.js +2 -0
  16. package/esm2022/lib/ws-thanos.options.js.map +1 -0
  17. package/esm2022/lib/ws-thanos.service.js +252 -0
  18. package/esm2022/lib/ws-thanos.service.js.map +1 -0
  19. package/esm2022/wolsok-thanos.js +5 -0
  20. package/esm2022/wolsok-thanos.js.map +1 -0
  21. package/{src/index.ts → index.d.ts} +0 -3
  22. package/lib/animation.state.d.ts +6 -0
  23. package/lib/create-ws-thanos-options.d.ts +2 -0
  24. package/lib/simplex-noise-options.d.ts +9 -0
  25. package/lib/simplex-noise.d.ts +18 -0
  26. package/lib/ws-thanos-options.token.d.ts +4 -0
  27. package/lib/ws-thanos.directive.d.ts +29 -0
  28. package/lib/ws-thanos.options.d.ts +5 -0
  29. package/lib/ws-thanos.service.d.ts +20 -0
  30. package/package.json +18 -7
  31. package/wolsok-thanos.d.ts +5 -0
  32. package/CHANGELOG.md +0 -59
  33. package/eslint.config.mjs +0 -64
  34. package/jest.config.ts +0 -23
  35. package/ng-package.json +0 -8
  36. package/project.json +0 -40
  37. package/src/assets/how-to-be-funny.png.ts +0 -4
  38. package/src/lib/animation.state.ts +0 -6
  39. package/src/lib/create-ws-thanos-options.ts +0 -12
  40. package/src/lib/random-util.ts +0 -24
  41. package/src/lib/simplex-noise-options.ts +0 -9
  42. package/src/lib/simplex-noise.ts +0 -240
  43. package/src/lib/ws-thanos-options.token.spec.ts +0 -19
  44. package/src/lib/ws-thanos-options.token.ts +0 -20
  45. package/src/lib/ws-thanos.directive.spec.ts +0 -175
  46. package/src/lib/ws-thanos.directive.ts +0 -70
  47. package/src/lib/ws-thanos.options.ts +0 -5
  48. package/src/lib/ws-thanos.service.spec.ts +0 -9
  49. package/src/lib/ws-thanos.service.ts +0 -387
  50. package/src/test-setup.ts +0 -9
  51. package/tsconfig.json +0 -32
  52. package/tsconfig.lib.json +0 -15
  53. package/tsconfig.lib.prod.json +0 -10
  54. package/tsconfig.spec.json +0 -10
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Public API Surface of ws-thanos
3
+ */
4
+ export * from './lib/ws-thanos.service';
5
+ export * from './lib/ws-thanos.directive';
6
+ export * from './lib/ws-thanos-options.token';
7
+ export * from './lib/ws-thanos.options';
8
+ export * from './lib/create-ws-thanos-options';
9
+ export * from './lib/simplex-noise';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/public/ws-thanos/src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC","sourcesContent":["/*\n * Public API Surface of ws-thanos\n */\nexport * from './lib/ws-thanos.service';\nexport * from './lib/ws-thanos.directive';\nexport * from './lib/ws-thanos-options.token';\nexport * from './lib/ws-thanos.options';\nexport * from './lib/create-ws-thanos-options';\nexport * from './lib/simplex-noise';\nexport type { AnimationState } from './lib/animation.state';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=animation.state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation.state.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/animation.state.ts"],"names":[],"mappings":"","sourcesContent":["export interface AnimationState {\n deltaTSec: number;\n animationT: number;\n maxWidth: number;\n maxHeight: number;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ export function createWsThanosOptions(options) {
2
+ return {
3
+ animationLength: 5000,
4
+ maxParticleCount: 400000,
5
+ particleAcceleration: 30,
6
+ ...options,
7
+ };
8
+ }
9
+ //# sourceMappingURL=create-ws-thanos-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-ws-thanos-options.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/create-ws-thanos-options.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CACnC,OAAkC;IAElC,OAAO;QACL,eAAe,EAAE,IAAI;QACrB,gBAAgB,EAAE,MAAM;QACxB,oBAAoB,EAAE,EAAE;QACxB,GAAG,OAAO;KACX,CAAC;AACJ,CAAC","sourcesContent":["import { WsThanosOptions } from './ws-thanos.options';\n\nexport function createWsThanosOptions(\n options?: Partial<WsThanosOptions>\n): WsThanosOptions {\n return {\n animationLength: 5000,\n maxParticleCount: 400000,\n particleAcceleration: 30,\n ...options,\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=simplex-noise-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplex-noise-options.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/simplex-noise-options.ts"],"names":[],"mappings":"","sourcesContent":["export interface SimplexNoiseOptions {\n amplitude: number; // The base amplitude (default: 1.0)\n frequency: number; // The base frequency (default: 1.0)\n max: number; // The maximum scaled value to return (effective default: 1.0)\n min: number; // The minimum scaled value to return (effective default: -1.0)\n octaves: number; // Integer; the number of octaves to sum for noise generation (default: 1)\n persistence: number; // The persistence of amplitude per octave (default: 0.5)\n random: () => number; // A function that generates random values between 0 and 1 (default: Math.random)\n}\n"]}
@@ -0,0 +1,199 @@
1
+ export class SimplexNoise {
2
+ constructor(options) {
3
+ this.memScale3D = {};
4
+ const { min, max, random, amplitude, frequency, octaves, persistence } = createOptionsWithDefaults(options);
5
+ this.random = random;
6
+ this.amplitude = amplitude;
7
+ this.frequency = frequency;
8
+ this.octaves = octaves;
9
+ this.persistence = persistence;
10
+ this.scale =
11
+ min === -1 && max === 1
12
+ ? (value) => value
13
+ : (value) => min + ((value + 1) / 2) * (max - min);
14
+ const p = new Uint8Array(256);
15
+ for (let i = 0; i < 256; i++) {
16
+ p[i] = i;
17
+ }
18
+ let n;
19
+ let q;
20
+ for (let i = 255; i > 0; i--) {
21
+ n = Math.floor((i + 1) * this.random());
22
+ q = p[i];
23
+ p[i] = p[n];
24
+ p[n] = q;
25
+ }
26
+ this.perm = new Uint8Array(512);
27
+ this.permMod12 = new Uint8Array(512);
28
+ for (let i = 0; i < 512; i++) {
29
+ this.perm[i] = p[i & 255];
30
+ this.permMod12[i] = this.perm[i] % 12;
31
+ }
32
+ }
33
+ static { this.G3 = 1.0 / 6.0; }
34
+ static { this.GRAD3D = [
35
+ [1, 1, 0],
36
+ [-1, 1, 0],
37
+ [1, -1, 0],
38
+ [-1, -1, 0],
39
+ [1, 0, 1],
40
+ [-1, 0, 1],
41
+ [1, 0, -1],
42
+ [-1, 0, -1],
43
+ [0, 1, 1],
44
+ [0, -1, -1],
45
+ [0, 1, -1],
46
+ [0, -1, -1],
47
+ ]; }
48
+ dot(gs, coords) {
49
+ return gs
50
+ .slice(0, Math.min(gs.length, coords.length))
51
+ .reduce((total, g, i) => total + g * coords[i], 0);
52
+ }
53
+ raw3D(x, y, z) {
54
+ // Skew the input space to determine which simplex cell we're in
55
+ const s = (x + y + z) / 3.0; // Very nice and simple skew factor for 3D
56
+ const i = Math.floor(x + s);
57
+ const j = Math.floor(y + s);
58
+ const k = Math.floor(z + s);
59
+ const t = (i + j + k) * SimplexNoise.G3;
60
+ const X0 = i - t; // Unskew the cell origin back to (x,y,z) space
61
+ const Y0 = j - t;
62
+ const Z0 = k - t;
63
+ const x0 = x - X0; // The x,y,z distances from the cell origin
64
+ const y0 = y - Y0;
65
+ const z0 = z - Z0;
66
+ // Determine which simplex we are in
67
+ let i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
68
+ let i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
69
+ if (x0 >= y0) {
70
+ if (y0 >= z0) {
71
+ i1 = i2 = j2 = 1;
72
+ j1 = k1 = k2 = 0;
73
+ }
74
+ else if (x0 >= z0) {
75
+ i1 = i2 = k2 = 1;
76
+ j1 = k1 = j2 = 0;
77
+ }
78
+ else {
79
+ k1 = i2 = k2 = 1;
80
+ i1 = j1 = j2 = 0;
81
+ }
82
+ }
83
+ else {
84
+ if (y0 < z0) {
85
+ k1 = j2 = k2 = 1;
86
+ i1 = j1 = i2 = 0;
87
+ }
88
+ else if (x0 < z0) {
89
+ j1 = j2 = k2 = 1;
90
+ i1 = k1 = i2 = 0;
91
+ }
92
+ else {
93
+ j1 = i2 = j2 = 1;
94
+ i1 = k1 = k2 = 0;
95
+ }
96
+ }
97
+ const x1 = x0 - i1 + SimplexNoise.G3; // Offsets for second corner in (x,y,z) coords
98
+ const y1 = y0 - j1 + SimplexNoise.G3;
99
+ const z1 = z0 - k1 + SimplexNoise.G3;
100
+ const x2 = x0 - i2 + 2.0 * SimplexNoise.G3; // Offsets for third corner in (x,y,z) coords
101
+ const y2 = y0 - j2 + 2.0 * SimplexNoise.G3;
102
+ const z2 = z0 - k2 + 2.0 * SimplexNoise.G3;
103
+ const x3 = x0 - 1.0 + 3.0 * SimplexNoise.G3; // Offsets for last corner in (x,y,z) coords
104
+ const y3 = y0 - 1.0 + 3.0 * SimplexNoise.G3;
105
+ const z3 = z0 - 1.0 + 3.0 * SimplexNoise.G3;
106
+ // Work out the hashed gradient indices of the four simplex corners
107
+ const ii = i & 255;
108
+ const jj = j & 255;
109
+ const kk = k & 255;
110
+ const gi0 = this.permMod12[ii + this.perm[jj + this.perm[kk]]];
111
+ const gi1 = this.permMod12[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]];
112
+ const gi2 = this.permMod12[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]];
113
+ const gi3 = this.permMod12[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]];
114
+ // Calculate the contribution from the four corners
115
+ const t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
116
+ const n0 = t0 < 0
117
+ ? 0.0
118
+ : Math.pow(t0, 4) * this.dot(SimplexNoise.GRAD3D[gi0], [x0, y0, z0]);
119
+ const t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
120
+ const n1 = t1 < 0
121
+ ? 0.0
122
+ : Math.pow(t1, 4) * this.dot(SimplexNoise.GRAD3D[gi1], [x1, y1, z1]);
123
+ const t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
124
+ const n2 = t2 < 0
125
+ ? 0.0
126
+ : Math.pow(t2, 4) * this.dot(SimplexNoise.GRAD3D[gi2], [x2, y2, z2]);
127
+ const t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
128
+ const n3 = t3 < 0
129
+ ? 0.0
130
+ : Math.pow(t3, 4) * this.dot(SimplexNoise.GRAD3D[gi3], [x3, y3, z3]);
131
+ // Add contributions from each corner to get the final noise value.
132
+ // The result is scaled to stay just inside [-1,1]
133
+ return 94.68493150681972 * (n0 + n1 + n2 + n3);
134
+ }
135
+ scaled3D(x, y, z, resolution) {
136
+ const memIndex = `${Math.round(x * resolution)}${Math.round(y * resolution)}${Math.round(z * resolution)}`;
137
+ const memElem = this.memScale3D[memIndex];
138
+ if (memElem != null) {
139
+ return memElem;
140
+ }
141
+ let amplitude = this.amplitude;
142
+ let frequency = this.frequency;
143
+ let maxAmplitude = 0;
144
+ let noise = 0;
145
+ for (let i = 0; i < this.octaves; i++) {
146
+ noise +=
147
+ this.raw3D(x * frequency, y * frequency, z * frequency) * amplitude;
148
+ maxAmplitude += amplitude;
149
+ amplitude *= this.persistence;
150
+ frequency *= 2;
151
+ }
152
+ const result = this.scale(noise / maxAmplitude);
153
+ this.memScale3D[memIndex] = result;
154
+ return result;
155
+ }
156
+ }
157
+ function createOptionsWithDefaults(options) {
158
+ if (options != null) {
159
+ if (options['amplitude'] && typeof options.amplitude !== 'number') {
160
+ throw new Error('options.amplitude must be a number');
161
+ }
162
+ if (options['frequency'] && typeof options.frequency !== 'number') {
163
+ throw new Error('options.frequency must be a number');
164
+ }
165
+ if (options['octaves'] &&
166
+ (typeof options.octaves !== 'number' ||
167
+ !isFinite(options.octaves) ||
168
+ Math.floor(options.octaves) !== options.octaves)) {
169
+ throw new Error('options.octaves must be an integer');
170
+ }
171
+ if (options['persistence'] && typeof options.persistence !== 'number') {
172
+ throw new Error('options.persistence must be a number');
173
+ }
174
+ if (options['random'] && typeof options.random !== 'function') {
175
+ throw new Error('options.random must be a function');
176
+ }
177
+ if (options['min'] && typeof options.min !== 'number') {
178
+ throw new Error('options.min must be a number');
179
+ }
180
+ if (options['max'] && typeof options.max !== 'number') {
181
+ throw new Error('options.max must be a number');
182
+ }
183
+ }
184
+ const optionsResult = {
185
+ amplitude: 1.0,
186
+ frequency: 1.0,
187
+ max: 1.0,
188
+ min: -1.0,
189
+ octaves: 1,
190
+ persistence: 0.5,
191
+ random: Math.random,
192
+ ...options,
193
+ };
194
+ if (optionsResult.min > optionsResult.max) {
195
+ throw new Error('min must be smaller max');
196
+ }
197
+ return optionsResult;
198
+ }
199
+ //# sourceMappingURL=simplex-noise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplex-noise.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/simplex-noise.ts"],"names":[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,aAAa,CAAC,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,MAAM,aAAa,GAAG;QACpB,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,GAAG;QACd,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,CAAC,GAAG;QACT,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,GAAG;QAChB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,OAAO;KACX,CAAC;IACF,IAAI,aAAa,CAAC,GAAG,GAAG,aAAa,CAAC,GAAG,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { SimplexNoiseOptions } from './simplex-noise-options';\n\nexport class SimplexNoise {\n constructor(options?: Partial<SimplexNoiseOptions>) {\n const { min, max, random, amplitude, frequency, octaves, persistence } =\n createOptionsWithDefaults(options);\n\n this.random = random;\n this.amplitude = amplitude;\n this.frequency = frequency;\n this.octaves = octaves;\n this.persistence = persistence;\n\n this.scale =\n min === -1 && max === 1\n ? (value) => value\n : (value) => min + ((value + 1) / 2) * (max - min);\n\n const p = new Uint8Array(256);\n for (let i = 0; i < 256; i++) {\n p[i] = i;\n }\n\n let n: number;\n let q: number;\n for (let i = 255; i > 0; i--) {\n n = Math.floor((i + 1) * this.random());\n q = p[i];\n p[i] = p[n];\n p[n] = q;\n }\n\n this.perm = new Uint8Array(512);\n this.permMod12 = new Uint8Array(512);\n for (let i = 0; i < 512; i++) {\n this.perm[i] = p[i & 255];\n this.permMod12[i] = this.perm[i] % 12;\n }\n }\n\n static G3 = 1.0 / 6.0;\n\n static GRAD3D = [\n [1, 1, 0],\n [-1, 1, 0],\n [1, -1, 0],\n [-1, -1, 0],\n [1, 0, 1],\n [-1, 0, 1],\n [1, 0, -1],\n [-1, 0, -1],\n [0, 1, 1],\n [0, -1, -1],\n [0, 1, -1],\n [0, -1, -1],\n ];\n\n readonly amplitude: number;\n readonly frequency: number;\n readonly octaves: number;\n readonly perm: Uint8Array;\n readonly permMod12: Uint8Array;\n readonly persistence: number;\n readonly random: () => number;\n readonly scale: (value: number) => number;\n private memScale3D: { [key: string]: number } = {};\n\n dot(gs: number[], coords: number[]): number {\n return gs\n .slice(0, Math.min(gs.length, coords.length))\n .reduce((total, g, i) => total + g * coords[i], 0);\n }\n\n raw3D(x: number, y: number, z: number): number {\n // Skew the input space to determine which simplex cell we're in\n const s = (x + y + z) / 3.0; // Very nice and simple skew factor for 3D\n const i = Math.floor(x + s);\n const j = Math.floor(y + s);\n const k = Math.floor(z + s);\n const t = (i + j + k) * SimplexNoise.G3;\n const X0 = i - t; // Unskew the cell origin back to (x,y,z) space\n const Y0 = j - t;\n const Z0 = k - t;\n const x0 = x - X0; // The x,y,z distances from the cell origin\n const y0 = y - Y0;\n const z0 = z - Z0;\n\n // Determine which simplex we are in\n let i1: number, j1: number, k1: number; // Offsets for second corner of simplex in (i,j,k) coords\n let i2: number, j2: number, k2: number; // Offsets for third corner of simplex in (i,j,k) coords\n if (x0 >= y0) {\n if (y0 >= z0) {\n i1 = i2 = j2 = 1;\n j1 = k1 = k2 = 0;\n } else if (x0 >= z0) {\n i1 = i2 = k2 = 1;\n j1 = k1 = j2 = 0;\n } else {\n k1 = i2 = k2 = 1;\n i1 = j1 = j2 = 0;\n }\n } else {\n if (y0 < z0) {\n k1 = j2 = k2 = 1;\n i1 = j1 = i2 = 0;\n } else if (x0 < z0) {\n j1 = j2 = k2 = 1;\n i1 = k1 = i2 = 0;\n } else {\n j1 = i2 = j2 = 1;\n i1 = k1 = k2 = 0;\n }\n }\n\n const x1 = x0 - i1 + SimplexNoise.G3; // Offsets for second corner in (x,y,z) coords\n const y1 = y0 - j1 + SimplexNoise.G3;\n const z1 = z0 - k1 + SimplexNoise.G3;\n const x2 = x0 - i2 + 2.0 * SimplexNoise.G3; // Offsets for third corner in (x,y,z) coords\n const y2 = y0 - j2 + 2.0 * SimplexNoise.G3;\n const z2 = z0 - k2 + 2.0 * SimplexNoise.G3;\n const x3 = x0 - 1.0 + 3.0 * SimplexNoise.G3; // Offsets for last corner in (x,y,z) coords\n const y3 = y0 - 1.0 + 3.0 * SimplexNoise.G3;\n const z3 = z0 - 1.0 + 3.0 * SimplexNoise.G3;\n\n // Work out the hashed gradient indices of the four simplex corners\n const ii = i & 255;\n const jj = j & 255;\n const kk = k & 255;\n const gi0 = this.permMod12[ii + this.perm[jj + this.perm[kk]]];\n const gi1 =\n this.permMod12[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]];\n const gi2 =\n this.permMod12[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]];\n const gi3 = this.permMod12[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]];\n\n // Calculate the contribution from the four corners\n const t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;\n const n0 =\n t0 < 0\n ? 0.0\n : Math.pow(t0, 4) * this.dot(SimplexNoise.GRAD3D[gi0], [x0, y0, z0]);\n const t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;\n const n1 =\n t1 < 0\n ? 0.0\n : Math.pow(t1, 4) * this.dot(SimplexNoise.GRAD3D[gi1], [x1, y1, z1]);\n const t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;\n const n2 =\n t2 < 0\n ? 0.0\n : Math.pow(t2, 4) * this.dot(SimplexNoise.GRAD3D[gi2], [x2, y2, z2]);\n const t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;\n const n3 =\n t3 < 0\n ? 0.0\n : Math.pow(t3, 4) * this.dot(SimplexNoise.GRAD3D[gi3], [x3, y3, z3]);\n\n // Add contributions from each corner to get the final noise value.\n // The result is scaled to stay just inside [-1,1]\n return 94.68493150681972 * (n0 + n1 + n2 + n3);\n }\n\n scaled3D(x: number, y: number, z: number, resolution: number): number {\n const memIndex = `${Math.round(x * resolution)}${Math.round(\n y * resolution\n )}${Math.round(z * resolution)}`;\n const memElem = this.memScale3D[memIndex];\n if (memElem != null) {\n return memElem;\n }\n\n let amplitude = this.amplitude;\n let frequency = this.frequency;\n let maxAmplitude = 0;\n let noise = 0;\n\n for (let i = 0; i < this.octaves; i++) {\n noise +=\n this.raw3D(x * frequency, y * frequency, z * frequency) * amplitude;\n maxAmplitude += amplitude;\n amplitude *= this.persistence;\n frequency *= 2;\n }\n const result = this.scale(noise / maxAmplitude);\n this.memScale3D[memIndex] = result;\n return result;\n }\n}\n\nfunction createOptionsWithDefaults(options?: Partial<SimplexNoiseOptions>) {\n if (options != null) {\n if (options['amplitude'] && typeof options.amplitude !== 'number') {\n throw new Error('options.amplitude must be a number');\n }\n\n if (options['frequency'] && typeof options.frequency !== 'number') {\n throw new Error('options.frequency must be a number');\n }\n\n if (\n options['octaves'] &&\n (typeof options.octaves !== 'number' ||\n !isFinite(options.octaves) ||\n Math.floor(options.octaves) !== options.octaves)\n ) {\n throw new Error('options.octaves must be an integer');\n }\n\n if (options['persistence'] && typeof options.persistence !== 'number') {\n throw new Error('options.persistence must be a number');\n }\n\n if (options['random'] && typeof options.random !== 'function') {\n throw new Error('options.random must be a function');\n }\n\n if (options['min'] && typeof options.min !== 'number') {\n throw new Error('options.min must be a number');\n }\n\n if (options['max'] && typeof options.max !== 'number') {\n throw new Error('options.max must be a number');\n }\n }\n\n const optionsResult = {\n amplitude: 1.0,\n frequency: 1.0,\n max: 1.0,\n min: -1.0,\n octaves: 1,\n persistence: 0.5,\n random: Math.random,\n ...options,\n };\n if (optionsResult.min > optionsResult.max) {\n throw new Error('min must be smaller max');\n }\n return optionsResult;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import { createWsThanosOptions } from './create-ws-thanos-options';
3
+ export const WS_THANOS_OPTIONS_TOKEN = new InjectionToken('thanosOptions', {
4
+ providedIn: 'root',
5
+ factory: () => createWsThanosOptions(),
6
+ });
7
+ export function provideWsThanosOptions(options) {
8
+ return {
9
+ provide: WS_THANOS_OPTIONS_TOKEN,
10
+ useValue: createWsThanosOptions(options),
11
+ };
12
+ }
13
+ //# sourceMappingURL=ws-thanos-options.token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-thanos-options.token.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/ws-thanos-options.token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAY,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,cAAc,CACvD,eAAe,EACf;IACE,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,GAAG,EAAE,CAAC,qBAAqB,EAAE;CACvC,CACF,CAAC;AAEF,MAAM,UAAU,sBAAsB,CACpC,OAAkC;IAElC,OAAO;QACL,OAAO,EAAE,uBAAuB;QAChC,QAAQ,EAAE,qBAAqB,CAAC,OAAO,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import { InjectionToken, Provider } from '@angular/core';\nimport { createWsThanosOptions } from './create-ws-thanos-options';\nimport type { WsThanosOptions } from './ws-thanos.options';\n\nexport const WS_THANOS_OPTIONS_TOKEN = new InjectionToken<WsThanosOptions>(\n 'thanosOptions',\n {\n providedIn: 'root',\n factory: () => createWsThanosOptions(),\n }\n);\n\nexport function provideWsThanosOptions(\n options?: Partial<WsThanosOptions>\n): Provider {\n return {\n provide: WS_THANOS_OPTIONS_TOKEN,\n useValue: createWsThanosOptions(options),\n };\n}\n"]}
@@ -0,0 +1,67 @@
1
+ import { Directive, ElementRef, Output, inject } from '@angular/core';
2
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3
+ import { finalize, Subject, Subscription, take, tap } from 'rxjs';
4
+ import { WS_THANOS_OPTIONS_TOKEN } from './ws-thanos-options.token';
5
+ import { WsThanosService } from './ws-thanos.service';
6
+ import * as i0 from "@angular/core";
7
+ export class WsThanosDirective {
8
+ constructor() {
9
+ this.wsThanosCompleteSubject = new Subject();
10
+ this.untilDestroyed = takeUntilDestroyed();
11
+ this.wsThanosComplete = this.wsThanosCompleteSubject.asObservable();
12
+ this.subscriptions = new Subscription();
13
+ this.vaporizeDomElem = inject(ElementRef);
14
+ this.thanosService = inject(WsThanosService);
15
+ this.thanosOptions = inject(WS_THANOS_OPTIONS_TOKEN);
16
+ }
17
+ /**
18
+ *
19
+ * Vaporize the dom element of this directive
20
+ * @param removeElem remove the vaporized dom element or blend back in after a while
21
+ *
22
+ * Subscribe to the returned observable to start vaporization
23
+ *
24
+ */
25
+ vaporize$(removeElem = true) {
26
+ const elem = this.vaporizeDomElem.nativeElement;
27
+ return this.thanosService.vaporize(elem).pipe(tap({
28
+ error: (error) => {
29
+ console.error('Error vaporizing', error, {
30
+ elemTovaporize: elem,
31
+ removeElem,
32
+ });
33
+ },
34
+ }), finalize(() => {
35
+ if (removeElem) {
36
+ elem.remove();
37
+ }
38
+ else {
39
+ // make visible again
40
+ elem.style.transition = 'opacity 700ms';
41
+ elem.style.opacity = '1';
42
+ }
43
+ this.wsThanosCompleteSubject.next();
44
+ }));
45
+ }
46
+ /**
47
+ * Vaporize the dom element of this directive
48
+ * @param removeElem remove the vaporized dom element or blend back in after a while
49
+ *
50
+ */
51
+ vaporize(removeElem = true) {
52
+ this.vaporize$(removeElem).pipe(this.untilDestroyed).subscribe();
53
+ return this.wsThanosComplete.pipe(take(1));
54
+ }
55
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: WsThanosDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
56
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.7", type: WsThanosDirective, isStandalone: true, selector: "[wsThanos], ws-thanos", outputs: { wsThanosComplete: "wsThanosComplete" }, exportAs: ["thanos"], ngImport: i0 }); }
57
+ }
58
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: WsThanosDirective, decorators: [{
59
+ type: Directive,
60
+ args: [{
61
+ selector: '[wsThanos], ws-thanos',
62
+ exportAs: 'thanos',
63
+ }]
64
+ }], propDecorators: { wsThanosComplete: [{
65
+ type: Output
66
+ }] } });
67
+ //# sourceMappingURL=ws-thanos.directive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-thanos.directive.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/ws-thanos.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAc,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;;AAMtD,MA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AAI,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;8GAxDU,iBAAiB;kGAAjB,iBAAiB;;2FAAjB,iBAAiB;kBAJ7B,SAAS;mBAAC;oBACT,QAAQ,EAAE,uBAAuB;oBACjC,QAAQ,EAAE,QAAQ;iBACnB;;sBAKE,MAAM","sourcesContent":["import { Directive, ElementRef, Output, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { finalize, Observable, Subject, Subscription, take, tap } from 'rxjs';\nimport { AnimationState } from './animation.state';\nimport { WS_THANOS_OPTIONS_TOKEN } from './ws-thanos-options.token';\nimport type { WsThanosOptions } from './ws-thanos.options';\nimport { WsThanosService } from './ws-thanos.service';\n\n@Directive({\n selector: '[wsThanos], ws-thanos',\n exportAs: 'thanos',\n})\nexport class WsThanosDirective {\n private wsThanosCompleteSubject = new Subject<void>();\n private untilDestroyed = takeUntilDestroyed();\n\n @Output()\n public wsThanosComplete: Observable<void> =\n this.wsThanosCompleteSubject.asObservable();\n private subscriptions: Subscription = new Subscription();\n\n private readonly vaporizeDomElem: ElementRef<HTMLElement> =\n inject(ElementRef);\n private readonly thanosService: WsThanosService = inject(WsThanosService);\n private readonly thanosOptions: WsThanosOptions = inject(\n WS_THANOS_OPTIONS_TOKEN\n );\n\n /**\n *\n * Vaporize the dom element of this directive\n * @param removeElem remove the vaporized dom element or blend back in after a while\n *\n * Subscribe to the returned observable to start vaporization\n *\n */\n public vaporize$(removeElem = true): Observable<AnimationState> {\n const elem = this.vaporizeDomElem.nativeElement;\n return this.thanosService.vaporize(elem).pipe(\n tap({\n error: (error) => {\n console.error('Error vaporizing', error, {\n elemTovaporize: elem,\n removeElem,\n });\n },\n }),\n finalize(() => {\n if (removeElem) {\n elem.remove();\n } else {\n // make visible again\n elem.style.transition = 'opacity 700ms';\n elem.style.opacity = '1';\n }\n this.wsThanosCompleteSubject.next();\n })\n );\n }\n\n /**\n * Vaporize the dom element of this directive\n * @param removeElem remove the vaporized dom element or blend back in after a while\n *\n */\n public vaporize(removeElem = true): Observable<void> {\n this.vaporize$(removeElem).pipe(this.untilDestroyed).subscribe();\n return this.wsThanosComplete.pipe(take(1));\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ws-thanos.options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-thanos.options.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-thanos/src/lib/ws-thanos.options.ts"],"names":[],"mappings":"","sourcesContent":["export interface WsThanosOptions {\n animationLength: number;\n maxParticleCount: number;\n particleAcceleration: number;\n}\n"]}
@@ -0,0 +1,252 @@
1
+ import { Injectable, inject } from '@angular/core';
2
+ import { default as html2canvas } from 'html2canvas';
3
+ import { animationFrameScheduler, finalize, from, interval, map, switchMap, takeWhile, tap, timeInterval, } from 'rxjs';
4
+ import { SimplexNoise } from './simplex-noise';
5
+ import { WS_THANOS_OPTIONS_TOKEN } from './ws-thanos-options.token';
6
+ import * as i0 from "@angular/core";
7
+ const PARTICLE_BYTE_LENGTH = 10;
8
+ const MIN_PARTICLE_ALPHA = ~~(255 * 0.01);
9
+ const HEIGHT_SCALE = 5;
10
+ const WIDTH_SCALE = 2;
11
+ const FLOW_FIELD_RES = 0.05;
12
+ export class WsThanosService {
13
+ constructor() {
14
+ this.thanosOptions = inject(WS_THANOS_OPTIONS_TOKEN);
15
+ }
16
+ static getParticleIndicesForBase(base) {
17
+ return {
18
+ x: base,
19
+ y: base + 1,
20
+ dx: base + 2,
21
+ dy: base + 3,
22
+ ax: base + 4,
23
+ ay: base + 5,
24
+ r: base + 6,
25
+ g: base + 7,
26
+ b: base + 8,
27
+ a: base + 9,
28
+ };
29
+ }
30
+ static getColorIndicesForCoord(x, y, width) {
31
+ const red = y * (width * 4) + x * 4;
32
+ return { r: red, g: red + 1, b: red + 2, a: red + 3 };
33
+ }
34
+ static updateParticles({ seed, noise, particlesData, thanosOptions, animationState, }) {
35
+ const { deltaTSec, animationT, maxWidth, maxHeight } = animationState;
36
+ const { particleAcceleration } = thanosOptions;
37
+ const { particles, maxParticleX, minParticleY } = particlesData;
38
+ // the time is used to calculate the vaporization front.
39
+ const time = Math.sin(animationT * (Math.PI / 2)) * 1.1;
40
+ const startAccelerateX = maxParticleX - time * maxParticleX;
41
+ const startAccelerateY = time * (maxHeight - minParticleY) + minParticleY;
42
+ const lengthY = maxHeight - startAccelerateY;
43
+ const accelerateRadiusPow = startAccelerateX * startAccelerateX + lengthY * lengthY;
44
+ for (let i = 0; i < particles.length; i += PARTICLE_BYTE_LENGTH) {
45
+ const { x, y, dx, dy, ax, ay, a } = WsThanosService.getParticleIndicesForBase(i);
46
+ const particleX = particles[x];
47
+ const particleY = particles[y];
48
+ // only update particles that are inside view and visible
49
+ if (particleX > maxWidth ||
50
+ particleX < 0 ||
51
+ particleY > maxHeight ||
52
+ particleY < 0 ||
53
+ particles[a] < MIN_PARTICLE_ALPHA) {
54
+ continue;
55
+ }
56
+ if (!(Math.abs(particles[ax]) > 0 || Math.abs(particles[ay]) > 0)) {
57
+ let pYLength = maxHeight - particleY;
58
+ let pXLength = particleX;
59
+ // we calculate some random looking numbers and functions to have nice looking vaporizing front of particles
60
+ // todo consider to use noise;
61
+ pXLength += Math.tan((pXLength / 20.12) * time + seed) * 0.5;
62
+ pXLength += (particleX % deltaTSec) * 0.5;
63
+ pXLength +=
64
+ Math.sin((pXLength / 30 + 723.394) * time + seed * 12.5) * 11;
65
+ pYLength += Math.tan((pYLength / 0.45) * time + seed * 1.5) * 0.5;
66
+ pYLength +=
67
+ Math.cos((pYLength / 100 + 2323.234) * time + seed * 456.1) * 23;
68
+ const pLength = pXLength * pXLength + pYLength * pYLength;
69
+ if (pLength > accelerateRadiusPow) {
70
+ particles[ax] = Math.random();
71
+ particles[ay] = Math.random() * -1;
72
+ }
73
+ }
74
+ else {
75
+ // use noise to flow along velocity field
76
+ const flowFieldAcc = WsThanosService.getXYFromFlowField(noise, seed, particleX, particleY);
77
+ const accelerationX = flowFieldAcc[0];
78
+ const accelerationY = flowFieldAcc[1];
79
+ particles[ax] += accelerationX;
80
+ particles[ay] += accelerationY;
81
+ }
82
+ // * Math.pow(1 + animationT, 4)
83
+ particles[dx] += particles[ax] * particleAcceleration * deltaTSec;
84
+ particles[dy] += particles[ay] * particleAcceleration * deltaTSec;
85
+ particles[x] += particles[dx] * deltaTSec;
86
+ particles[y] += particles[dy] * deltaTSec;
87
+ // fade particle out ( very late);
88
+ particles[a] *= 1 - Math.pow(animationT, 15); // 255 - Math.sqrt(particles[dx] * particles[dx] + particles[dy] * particles[dy]) / 1.2;
89
+ }
90
+ }
91
+ static drawParticles(drawCtx, particles) {
92
+ const { width, height } = drawCtx.canvas;
93
+ drawCtx.clearRect(0, 0, width, height);
94
+ const image = drawCtx.getImageData(0, 0, width, height);
95
+ const imageData = image.data;
96
+ for (let i = 0; i < particles.length; i += PARTICLE_BYTE_LENGTH) {
97
+ const particleX = particles[i];
98
+ const particleY = particles[i + 1];
99
+ const pI = WsThanosService.getParticleIndicesForBase(i);
100
+ if (particleX > width ||
101
+ particleX < 0 ||
102
+ particleY > height ||
103
+ particleY < 0 ||
104
+ particles[pI.a] < MIN_PARTICLE_ALPHA) {
105
+ continue;
106
+ }
107
+ const { r, g, b, a } = WsThanosService.getColorIndicesForCoord(~~particles[pI.x], ~~particles[pI.y], width);
108
+ imageData[r] = ~~particles[pI.r];
109
+ imageData[g] = ~~particles[pI.g];
110
+ imageData[b] = ~~particles[pI.b];
111
+ imageData[a] = ~~particles[pI.a];
112
+ }
113
+ drawCtx.putImageData(image, 0, 0);
114
+ }
115
+ static prepareCanvasForVaporize(divCanvas, maxParticleCount) {
116
+ const { width, height } = divCanvas;
117
+ // scale result canvas to have more room to draw particles while vaporizing;
118
+ const resultHeight = height * HEIGHT_SCALE;
119
+ const resultWidth = width * WIDTH_SCALE;
120
+ const resultCanvas = document.createElement('canvas');
121
+ resultCanvas.height = resultHeight;
122
+ resultCanvas.width = resultWidth;
123
+ const imageData = divCanvas
124
+ .getContext('2d', { willReadFrequently: true })
125
+ ?.getImageData(0, 0, width, height);
126
+ if (imageData == null) {
127
+ throw new Error('Could not get image data from canvas');
128
+ }
129
+ const particlesData = WsThanosService.createParticlesForImageData(imageData, maxParticleCount, resultHeight);
130
+ return { resultCanvas, particlesData };
131
+ }
132
+ static createParticlesForImageData(imageData, maxParticleCount, resultHeight) {
133
+ const { width, height } = imageData;
134
+ let particleCandidates = 0;
135
+ let particleCount = 0;
136
+ const particleCandiatesList = [];
137
+ for (let y = 0; y < height; y++) {
138
+ for (let x = 0; x < width; x++) {
139
+ const { a } = WsThanosService.getColorIndicesForCoord(x, y, width);
140
+ if (imageData.data[a] >= MIN_PARTICLE_ALPHA) {
141
+ particleCandidates++;
142
+ particleCandiatesList.push({ x, y });
143
+ }
144
+ }
145
+ }
146
+ const maxNumParticles = Math.min(particleCandidates, maxParticleCount);
147
+ const particles = new Float32Array(Float32Array.BYTES_PER_ELEMENT * maxNumParticles * PARTICLE_BYTE_LENGTH);
148
+ let maxParticleX = 0;
149
+ let minParticleY = resultHeight;
150
+ while (particleCount < maxNumParticles) {
151
+ // select random index from candiates
152
+ const index = ~~(Math.random() * particleCandiatesList.length);
153
+ const { x, y } = particleCandiatesList[index];
154
+ // overwrite index with last element to prevent double selection of particles
155
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
156
+ particleCandiatesList[index] = particleCandiatesList.pop();
157
+ maxParticleX = Math.max(maxParticleX, x);
158
+ minParticleY = Math.min(minParticleY, y);
159
+ const { dx, dy, ax, ay, r, g, b, a, ...xy } = WsThanosService.getParticleIndicesForBase(particleCount * PARTICLE_BYTE_LENGTH);
160
+ particles[xy.x] = x;
161
+ particles[xy.y] = y + resultHeight - height;
162
+ particles[dx] = 0;
163
+ particles[dy] = 0;
164
+ particles[ax] = 0;
165
+ particles[ay] = 0;
166
+ const indicesImage = WsThanosService.getColorIndicesForCoord(x, y, width);
167
+ particles[r] = imageData.data[indicesImage.r];
168
+ particles[g] = imageData.data[indicesImage.g];
169
+ particles[b] = imageData.data[indicesImage.b];
170
+ particles[a] = imageData.data[indicesImage.a];
171
+ particleCount++;
172
+ }
173
+ return { particles, maxParticleX, minParticleY };
174
+ }
175
+ static getXYFromFlowField(noise, seed, x, y) {
176
+ const sampleX = noise.scaled3D(x, y, seed + 33.23, FLOW_FIELD_RES);
177
+ const sampleY = noise.scaled3D(x, seed / 13.23, y, FLOW_FIELD_RES) * -1;
178
+ return [sampleX, sampleY];
179
+ }
180
+ /**
181
+ * start the vaporize-effect.
182
+ */
183
+ vaporize(elem) {
184
+ return this.vaporizeIntern(elem);
185
+ }
186
+ vaporizeIntern(elem) {
187
+ elem.style.opacity = elem.style.opacity || '1';
188
+ elem.style.transition = `opacity ${Math.floor(this.thanosOptions.animationLength * 0.8)}ms ease-out`;
189
+ const noise = new SimplexNoise({ frequency: 0.01, min: 0 });
190
+ const seed = new Date().getTime() * Math.random();
191
+ const html2CanvasPromise = html2canvas(elem, {
192
+ backgroundColor: null,
193
+ scale: 1,
194
+ allowTaint: true,
195
+ windowHeight: window.innerHeight,
196
+ windowWidth: window.innerWidth,
197
+ scrollY: -window.scrollY,
198
+ });
199
+ return from(html2CanvasPromise).pipe(map((canvasFromHtmlElem) => {
200
+ const canvasAndParticles = WsThanosService.prepareCanvasForVaporize(canvasFromHtmlElem, this.thanosOptions.maxParticleCount);
201
+ const { resultCanvas } = canvasAndParticles;
202
+ if (elem.parentElement) {
203
+ elem.parentElement.style.position =
204
+ elem.parentElement.style.position || 'relative';
205
+ }
206
+ resultCanvas.style.position = 'absolute';
207
+ resultCanvas.style.left = 0 + 'px';
208
+ resultCanvas.style.top =
209
+ '-' + elem.getBoundingClientRect().height * (HEIGHT_SCALE - 1) + 'px';
210
+ resultCanvas.style.zIndex = '2000';
211
+ resultCanvas.style.pointerEvents = 'none';
212
+ elem.insertAdjacentElement('beforebegin', resultCanvas);
213
+ // this should start the transition above defined
214
+ elem.style.opacity = '0';
215
+ return canvasAndParticles;
216
+ }), switchMap(({ resultCanvas, particlesData }) => {
217
+ let time = 0;
218
+ const { animationLength, maxParticleCount, particleAcceleration } = this.thanosOptions;
219
+ return interval(1000 / 60, animationFrameScheduler).pipe(timeInterval(), tap((deltaT) => (time += deltaT.interval)), map((deltaT) => ({
220
+ deltaTSec: deltaT.interval / 1000,
221
+ animationT: time / animationLength,
222
+ maxWidth: resultCanvas.width,
223
+ maxHeight: resultCanvas.height,
224
+ })), tap((animationState) => {
225
+ WsThanosService.updateParticles({
226
+ particlesData,
227
+ animationState,
228
+ thanosOptions: {
229
+ animationLength,
230
+ maxParticleCount,
231
+ particleAcceleration,
232
+ },
233
+ noise,
234
+ seed,
235
+ });
236
+ const context = resultCanvas.getContext('2d', {
237
+ willReadFrequently: true,
238
+ });
239
+ if (context) {
240
+ WsThanosService.drawParticles(context, particlesData.particles);
241
+ }
242
+ }), takeWhile((animationState) => animationState.animationT <= 1), finalize(() => resultCanvas.remove()));
243
+ }));
244
+ }
245
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: WsThanosService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
246
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: WsThanosService, providedIn: 'root' }); }
247
+ }
248
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: WsThanosService, decorators: [{
249
+ type: Injectable,
250
+ args: [{ providedIn: 'root' }]
251
+ }] });
252
+ //# sourceMappingURL=ws-thanos.service.js.map