destroy-the-text 2.0.1 → 2.0.3
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/dist/AnimationManager.d.ts +19 -0
- package/dist/AnimationManager.d.ts.map +1 -0
- package/dist/AnimationManager.js +46 -0
- package/dist/DestroyTheText.js +1 -1
- package/dist/Letra.d.ts +4 -1
- package/dist/Letra.d.ts.map +1 -1
- package/dist/Letra.js +14 -12
- package/dist/Pixel.d.ts +4 -2
- package/dist/Pixel.d.ts.map +1 -1
- package/dist/Pixel.js +14 -10
- package/dist/Spark.d.ts +4 -2
- package/dist/Spark.d.ts.map +1 -1
- package/dist/Spark.js +12 -8
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface Animatable {
|
|
2
|
+
update(): void;
|
|
3
|
+
isAlive(): boolean;
|
|
4
|
+
}
|
|
5
|
+
declare class AnimationManagerSingleton {
|
|
6
|
+
private static instance;
|
|
7
|
+
private objects;
|
|
8
|
+
private animationId;
|
|
9
|
+
private isRunning;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): AnimationManagerSingleton;
|
|
12
|
+
register(obj: Animatable): void;
|
|
13
|
+
private start;
|
|
14
|
+
private loop;
|
|
15
|
+
getCount(): number;
|
|
16
|
+
}
|
|
17
|
+
export declare const AnimationManager: AnimationManagerSingleton;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=AnimationManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimationManager.d.ts","sourceRoot":"","sources":["../src/AnimationManager.ts"],"names":[],"mappings":"AAGA,UAAU,UAAU;IAClB,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,OAAO,CAAC;CACpB;AAED,cAAM,yBAAyB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA4B;IACnD,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,yBAAyB;IAO/C,QAAQ,CAAC,GAAG,EAAE,UAAU;IAOxB,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,IAAI,CAiBV;IAEF,QAAQ,IAAI,MAAM;CAGnB;AAED,eAAO,MAAM,gBAAgB,2BAA0C,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @ts-ignore - jQuery require
|
|
2
|
+
const $ = require("jquery");
|
|
3
|
+
class AnimationManagerSingleton {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.objects = [];
|
|
6
|
+
this.animationId = null;
|
|
7
|
+
this.isRunning = false;
|
|
8
|
+
this.loop = () => {
|
|
9
|
+
// Remove dead objects
|
|
10
|
+
this.objects = this.objects.filter((obj) => obj.isAlive());
|
|
11
|
+
// Update all objects in one pass
|
|
12
|
+
for (let i = 0; i < this.objects.length; i++) {
|
|
13
|
+
this.objects[i].update();
|
|
14
|
+
}
|
|
15
|
+
// Stop if no more objects
|
|
16
|
+
if (this.objects.length === 0) {
|
|
17
|
+
this.isRunning = false;
|
|
18
|
+
this.animationId = null;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.animationId = requestAnimationFrame(this.loop);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!AnimationManagerSingleton.instance) {
|
|
26
|
+
AnimationManagerSingleton.instance = new AnimationManagerSingleton();
|
|
27
|
+
}
|
|
28
|
+
return AnimationManagerSingleton.instance;
|
|
29
|
+
}
|
|
30
|
+
register(obj) {
|
|
31
|
+
this.objects.push(obj);
|
|
32
|
+
if (!this.isRunning) {
|
|
33
|
+
this.start();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
start() {
|
|
37
|
+
if (this.isRunning)
|
|
38
|
+
return;
|
|
39
|
+
this.isRunning = true;
|
|
40
|
+
this.loop();
|
|
41
|
+
}
|
|
42
|
+
getCount() {
|
|
43
|
+
return this.objects.length;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const AnimationManager = AnimationManagerSingleton.getInstance();
|
package/dist/DestroyTheText.js
CHANGED
|
@@ -21,7 +21,7 @@ export class DestroyTheText {
|
|
|
21
21
|
}
|
|
22
22
|
this.originalTagName = elem.tagName;
|
|
23
23
|
this.originalClass = elem.className;
|
|
24
|
-
this.container = $(document.createElement(
|
|
24
|
+
this.container = $(document.createElement(this.originalTagName.toLowerCase()));
|
|
25
25
|
this.container.attr("id", params.textId);
|
|
26
26
|
this.container.addClass(this.originalClass);
|
|
27
27
|
this.arma = params.arma;
|
package/dist/Letra.d.ts
CHANGED
|
@@ -4,8 +4,11 @@ export declare class Letra {
|
|
|
4
4
|
private container;
|
|
5
5
|
private direction;
|
|
6
6
|
private gravitySpeed;
|
|
7
|
+
private lifespan;
|
|
8
|
+
private startTime;
|
|
7
9
|
constructor(x: number, y: number, container: any);
|
|
8
|
-
|
|
10
|
+
update(): void;
|
|
11
|
+
isAlive(): boolean;
|
|
9
12
|
private getPositiveOrNegative;
|
|
10
13
|
}
|
|
11
14
|
//# sourceMappingURL=Letra.d.ts.map
|
package/dist/Letra.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Letra.d.ts","sourceRoot":"","sources":["../src/Letra.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Letra.d.ts","sourceRoot":"","sources":["../src/Letra.ts"],"names":[],"mappings":"AAKA,qBAAa,KAAK;IACd,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,SAAS,CAAsB;gBAE3B,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG;IAoBhD,MAAM;IAQN,OAAO,IAAI,OAAO;IAIlB,OAAO,CAAC,qBAAqB;CAGhC"}
|
package/dist/Letra.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { AnimationManager } from "./AnimationManager";
|
|
2
|
+
// @ts-ignore - jQuery require
|
|
3
|
+
const $ = require("jquery");
|
|
1
4
|
export class Letra {
|
|
2
5
|
constructor(x, y, container) {
|
|
3
6
|
this.gravitySpeed = 0;
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
this.lifespan = 3000; // 3 seconds
|
|
8
|
+
this.startTime = Date.now();
|
|
6
9
|
this.container = container.clone();
|
|
7
10
|
this.container.removeClass("oculto");
|
|
8
11
|
this.container.addClass("absolute");
|
|
@@ -12,22 +15,21 @@ export class Letra {
|
|
|
12
15
|
this.container.css("font-size", container.parent().css("font-size"));
|
|
13
16
|
this.container.css("font-weight", container.parent().css("font-weight"));
|
|
14
17
|
this.container.css("font-family", container.parent().css("font-family"));
|
|
15
|
-
this.container.css("
|
|
16
|
-
this.container.css("
|
|
18
|
+
this.container.css("transform", `translate(${x}px, ${y}px)`);
|
|
19
|
+
this.container.css("will-change", "transform");
|
|
17
20
|
$("body").append(this.container);
|
|
18
|
-
const interval = setInterval(() => this.gravity(), 10);
|
|
19
|
-
setTimeout(() => {
|
|
20
|
-
clearInterval(interval);
|
|
21
|
-
this.container.remove();
|
|
22
|
-
}, 3000);
|
|
23
21
|
this.direction = { x: this.getPositiveOrNegative() * Math.random(), y: 0 };
|
|
22
|
+
// Register with global animation manager
|
|
23
|
+
AnimationManager.register(this);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
this.container.css("left", this.x + "px");
|
|
27
|
-
this.container.css("top", this.y + "px");
|
|
25
|
+
update() {
|
|
28
26
|
this.gravitySpeed += 0.2;
|
|
29
27
|
this.y += this.gravitySpeed;
|
|
30
28
|
this.x += this.direction.x;
|
|
29
|
+
this.container.css("transform", `translate(${this.x}px, ${this.y}px)`);
|
|
30
|
+
}
|
|
31
|
+
isAlive() {
|
|
32
|
+
return Date.now() - this.startTime < this.lifespan;
|
|
31
33
|
}
|
|
32
34
|
getPositiveOrNegative() {
|
|
33
35
|
return Math.floor(Math.random() * 2) === 0 ? -1 : 1;
|
package/dist/Pixel.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ export declare class Pixel {
|
|
|
4
4
|
private container;
|
|
5
5
|
private direction;
|
|
6
6
|
private gravitySpeed;
|
|
7
|
+
private lifespan;
|
|
8
|
+
private startTime;
|
|
7
9
|
static activePixels: Pixel[];
|
|
8
10
|
static MAX_PIXELS: number;
|
|
9
|
-
private interval;
|
|
10
11
|
constructor(x: number, y: number, color: string);
|
|
11
|
-
|
|
12
|
+
update(): void;
|
|
13
|
+
isAlive(): boolean;
|
|
12
14
|
private getPositiveOrNegative;
|
|
13
15
|
destroy(): void;
|
|
14
16
|
}
|
package/dist/Pixel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pixel.d.ts","sourceRoot":"","sources":["../src/Pixel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Pixel.d.ts","sourceRoot":"","sources":["../src/Pixel.ts"],"names":[],"mappings":"AAKA,qBAAa,KAAK;IACd,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,SAAS,CAAsB;IACvC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,CAAM;IAClC,MAAM,CAAC,UAAU,SAAO;gBAEZ,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAwB/C,MAAM;IAgBN,OAAO,IAAI,OAAO;IAIlB,OAAO,CAAC,qBAAqB;IAItB,OAAO;CAGjB"}
|
package/dist/Pixel.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
+
import { AnimationManager } from "./AnimationManager";
|
|
2
|
+
// @ts-ignore - jQuery require
|
|
3
|
+
const $ = require("jquery");
|
|
1
4
|
export class Pixel {
|
|
2
5
|
constructor(x, y, color) {
|
|
3
6
|
this.gravitySpeed = 0;
|
|
7
|
+
this.lifespan = 3000; // 3 seconds
|
|
8
|
+
this.startTime = Date.now();
|
|
4
9
|
const length = 25;
|
|
5
10
|
this.x = x;
|
|
6
11
|
this.y = y + this.getPositiveOrNegative() * Math.floor(Math.random() * length);
|
|
7
|
-
// @ts-ignore - jQuery require
|
|
8
|
-
const $ = require("jquery");
|
|
9
12
|
this.container = $(document.createElement("div"));
|
|
10
13
|
this.container.addClass("pixel");
|
|
11
14
|
this.container.css("background", color);
|
|
12
|
-
this.container.css("
|
|
13
|
-
this.container.css("
|
|
15
|
+
this.container.css("transform", `translate(${this.x}px, ${this.y}px)`);
|
|
16
|
+
this.container.css("will-change", "transform");
|
|
14
17
|
$("body").append(this.container);
|
|
15
|
-
this.interval = setInterval(() => this.gravity(), 10);
|
|
16
18
|
this.direction = { x: this.getPositiveOrNegative() * Math.random(), y: 0 };
|
|
17
19
|
Pixel.activePixels.push(this);
|
|
18
20
|
if (Pixel.activePixels.length > Pixel.MAX_PIXELS) {
|
|
19
21
|
const oldPixel = Pixel.activePixels.shift();
|
|
20
22
|
oldPixel?.destroy();
|
|
21
23
|
}
|
|
24
|
+
// Register with global animation manager
|
|
25
|
+
AnimationManager.register(this);
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
update() {
|
|
24
28
|
this.gravitySpeed += 0.2;
|
|
25
29
|
this.y += this.gravitySpeed;
|
|
26
30
|
this.x += this.direction.x;
|
|
@@ -29,17 +33,17 @@ export class Pixel {
|
|
|
29
33
|
this.y = window.innerHeight - 10;
|
|
30
34
|
this.gravitySpeed = 0;
|
|
31
35
|
this.direction.x = 0;
|
|
32
|
-
clearInterval(this.interval);
|
|
33
36
|
this.container.css("opacity", "0.8");
|
|
34
37
|
}
|
|
35
|
-
this.container.css("
|
|
36
|
-
|
|
38
|
+
this.container.css("transform", `translate(${this.x}px, ${this.y}px)`);
|
|
39
|
+
}
|
|
40
|
+
isAlive() {
|
|
41
|
+
return Date.now() - this.startTime < this.lifespan;
|
|
37
42
|
}
|
|
38
43
|
getPositiveOrNegative() {
|
|
39
44
|
return Math.floor(Math.random() * 2) === 0 ? -1 : 1;
|
|
40
45
|
}
|
|
41
46
|
destroy() {
|
|
42
|
-
clearInterval(this.interval);
|
|
43
47
|
this.container.remove();
|
|
44
48
|
}
|
|
45
49
|
}
|
package/dist/Spark.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export declare class Spark {
|
|
|
5
5
|
private direction;
|
|
6
6
|
private gravitySpeed;
|
|
7
7
|
static activeSparks: Spark[];
|
|
8
|
-
private
|
|
8
|
+
private lifespan;
|
|
9
|
+
private startTime;
|
|
9
10
|
constructor(x: number, y: number);
|
|
10
|
-
|
|
11
|
+
update(): void;
|
|
12
|
+
isAlive(): boolean;
|
|
11
13
|
destroy(): void;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Spark.d.ts.map
|
package/dist/Spark.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spark.d.ts","sourceRoot":"","sources":["../src/Spark.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Spark.d.ts","sourceRoot":"","sources":["../src/Spark.ts"],"names":[],"mappings":"AAKA,qBAAa,KAAK;IAChB,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,YAAY,CAAa;IACjC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,CAAM;IAClC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAsB;gBAE3B,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAkChC,MAAM;IAQN,OAAO,IAAI,OAAO;IAIX,OAAO;CAOf"}
|
package/dist/Spark.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
import { AnimationManager } from "./AnimationManager";
|
|
1
2
|
// @ts-ignore - jQuery require
|
|
2
3
|
const $ = require("jquery");
|
|
3
4
|
export class Spark {
|
|
4
5
|
constructor(x, y) {
|
|
5
6
|
this.gravitySpeed = 0;
|
|
7
|
+
this.startTime = Date.now();
|
|
6
8
|
this.x = x;
|
|
7
9
|
this.y = y;
|
|
10
|
+
this.lifespan = 200 + Math.random() * 200;
|
|
8
11
|
this.container = $(document.createElement("div"));
|
|
9
12
|
this.container.addClass("pixel");
|
|
10
13
|
const colors = ["#FFD700", "#FFA500", "#FF4500", "#FFFF00"];
|
|
11
14
|
const color = colors[Math.floor(Math.random() * colors.length)];
|
|
12
15
|
this.container.css({
|
|
13
16
|
background: color,
|
|
14
|
-
left: x + "px",
|
|
15
|
-
top: y + "px",
|
|
16
17
|
width: "3px",
|
|
17
18
|
height: "3px",
|
|
18
19
|
boxShadow: `0 0 4px ${color}`,
|
|
19
20
|
zIndex: 100,
|
|
21
|
+
transform: `translate(${x}px, ${y}px)`,
|
|
22
|
+
"will-change": "transform",
|
|
20
23
|
});
|
|
21
24
|
$("body").append(this.container);
|
|
22
|
-
this.interval = setInterval(() => this.gravity(), 10);
|
|
23
25
|
const angle = Math.random() * Math.PI * 2;
|
|
24
26
|
const speed = 2 + Math.random() * 3;
|
|
25
27
|
this.direction = {
|
|
@@ -27,17 +29,19 @@ export class Spark {
|
|
|
27
29
|
y: Math.sin(angle) * speed,
|
|
28
30
|
};
|
|
29
31
|
Spark.activeSparks.push(this);
|
|
30
|
-
|
|
32
|
+
// Register with global animation manager
|
|
33
|
+
AnimationManager.register(this);
|
|
31
34
|
}
|
|
32
|
-
|
|
35
|
+
update() {
|
|
33
36
|
this.gravitySpeed += 0.1;
|
|
34
37
|
this.y += this.gravitySpeed + this.direction.y;
|
|
35
38
|
this.x += this.direction.x;
|
|
36
|
-
this.container.css("
|
|
37
|
-
|
|
39
|
+
this.container.css("transform", `translate(${this.x}px, ${this.y}px)`);
|
|
40
|
+
}
|
|
41
|
+
isAlive() {
|
|
42
|
+
return Date.now() - this.startTime < this.lifespan;
|
|
38
43
|
}
|
|
39
44
|
destroy() {
|
|
40
|
-
clearInterval(this.interval);
|
|
41
45
|
this.container.remove();
|
|
42
46
|
const index = Spark.activeSparks.indexOf(this);
|
|
43
47
|
if (index > -1) {
|