@tsparticles/engine 4.0.0-beta.1 → 4.0.0-beta.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/browser/Core/Container.js +3 -0
- package/browser/Core/Engine.js +1 -1
- package/browser/Core/Interfaces/IPositionFromSizeParams.js +1 -1
- package/browser/Core/ParticlesManager.js +1 -0
- package/cjs/Core/Container.js +3 -0
- package/cjs/Core/Engine.js +1 -1
- package/cjs/Core/Interfaces/IPositionFromSizeParams.js +1 -1
- package/cjs/Core/ParticlesManager.js +1 -0
- package/dist_browser_Core_Container_js.js +3 -3
- package/esm/Core/Container.js +3 -0
- package/esm/Core/Engine.js +1 -1
- package/esm/Core/Interfaces/IPositionFromSizeParams.js +1 -1
- package/esm/Core/ParticlesManager.js +1 -0
- package/package.json +2 -3
- package/report.html +1 -1
- package/tsparticles.engine.js +2 -2
- package/tsparticles.engine.min.js +1 -1
- package/umd/Core/CanvasManager.js +0 -317
- package/umd/Core/Container.js +0 -383
- package/umd/Core/Engine.js +0 -183
- package/umd/Core/Interfaces/Colors.js +0 -12
- package/umd/Core/Interfaces/IBounds.js +0 -12
- package/umd/Core/Interfaces/IBubbleParticleData.js +0 -12
- package/umd/Core/Interfaces/ICircleBouncer.js +0 -12
- package/umd/Core/Interfaces/IColorManager.js +0 -12
- package/umd/Core/Interfaces/IContainerPlugin.js +0 -12
- package/umd/Core/Interfaces/ICoordinates.js +0 -12
- package/umd/Core/Interfaces/IDelta.js +0 -12
- package/umd/Core/Interfaces/IDimension.js +0 -12
- package/umd/Core/Interfaces/IDistance.js +0 -12
- package/umd/Core/Interfaces/IDrawParticleParams.js +0 -12
- package/umd/Core/Interfaces/IEffectDrawer.js +0 -12
- package/umd/Core/Interfaces/ILoadParams.js +0 -12
- package/umd/Core/Interfaces/IPalette.js +0 -12
- package/umd/Core/Interfaces/IParticleColorStyle.js +0 -12
- package/umd/Core/Interfaces/IParticleHslAnimation.js +0 -12
- package/umd/Core/Interfaces/IParticleLife.js +0 -12
- package/umd/Core/Interfaces/IParticleOpacityData.js +0 -12
- package/umd/Core/Interfaces/IParticleRetinaProps.js +0 -12
- package/umd/Core/Interfaces/IParticleRoll.js +0 -12
- package/umd/Core/Interfaces/IParticleRotateData.js +0 -12
- package/umd/Core/Interfaces/IParticleTransformValues.js +0 -12
- package/umd/Core/Interfaces/IParticleUpdater.js +0 -12
- package/umd/Core/Interfaces/IParticleValueAnimation.js +0 -12
- package/umd/Core/Interfaces/IPlugin.js +0 -12
- package/umd/Core/Interfaces/IPositionFromSizeParams.js +0 -12
- package/umd/Core/Interfaces/IRangeValue.js +0 -12
- package/umd/Core/Interfaces/IShapeDrawData.js +0 -12
- package/umd/Core/Interfaces/IShapeDrawer.js +0 -12
- package/umd/Core/Interfaces/IShapeValues.js +0 -12
- package/umd/Core/Interfaces/ISlowParticleData.js +0 -12
- package/umd/Core/Particle.js +0 -433
- package/umd/Core/ParticlesManager.js +0 -377
- package/umd/Core/RenderManager.js +0 -317
- package/umd/Core/Retina.js +0 -47
- package/umd/Core/Utils/Constants.js +0 -23
- package/umd/Core/Utils/EventListeners.js +0 -102
- package/umd/Core/Utils/PluginManager.js +0 -159
- package/umd/Core/Utils/Ranges.js +0 -91
- package/umd/Core/Utils/SpatialHashGrid.js +0 -116
- package/umd/Core/Utils/Vectors.js +0 -126
- package/umd/Enums/AnimationStatus.js +0 -18
- package/umd/Enums/Directions/MoveDirection.js +0 -27
- package/umd/Enums/Directions/OutModeDirection.js +0 -20
- package/umd/Enums/Directions/RotateDirection.js +0 -19
- package/umd/Enums/Modes/AnimationMode.js +0 -20
- package/umd/Enums/Modes/LimitMode.js +0 -18
- package/umd/Enums/Modes/OutMode.js +0 -21
- package/umd/Enums/Modes/PixelMode.js +0 -18
- package/umd/Enums/RangeType.js +0 -18
- package/umd/Enums/Types/AlterType.js +0 -18
- package/umd/Enums/Types/DestroyType.js +0 -19
- package/umd/Enums/Types/EasingType.js +0 -58
- package/umd/Enums/Types/EventType.js +0 -28
- package/umd/Enums/Types/GradientType.js +0 -19
- package/umd/Enums/Types/ParticleOutType.js +0 -19
- package/umd/Enums/Types/StartValueType.js +0 -19
- package/umd/Options/Classes/AnimatableColor.js +0 -52
- package/umd/Options/Classes/AnimationOptions.js +0 -79
- package/umd/Options/Classes/Background/Background.js +0 -56
- package/umd/Options/Classes/ColorAnimation.js +0 -44
- package/umd/Options/Classes/FullScreen/FullScreen.js +0 -34
- package/umd/Options/Classes/HslAnimation.js +0 -30
- package/umd/Options/Classes/Options.js +0 -171
- package/umd/Options/Classes/OptionsColor.js +0 -42
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +0 -31
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -21
- package/umd/Options/Classes/Particles/Effect/Effect.js +0 -46
- package/umd/Options/Classes/Particles/Fill.js +0 -42
- package/umd/Options/Classes/Particles/Move/Move.js +0 -120
- package/umd/Options/Classes/Particles/Move/MoveAngle.js +0 -35
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +0 -45
- package/umd/Options/Classes/Particles/Move/MoveGravity.js +0 -45
- package/umd/Options/Classes/Particles/Move/OutModes.js +0 -38
- package/umd/Options/Classes/Particles/Move/Path/MovePath.js +0 -46
- package/umd/Options/Classes/Particles/Move/Spin.js +0 -40
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +0 -41
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +0 -37
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +0 -35
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +0 -35
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -34
- package/umd/Options/Classes/Particles/ParticlesOptions.js +0 -116
- package/umd/Options/Classes/Particles/Shape/Shape.js +0 -46
- package/umd/Options/Classes/Particles/Size/Size.js +0 -35
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -34
- package/umd/Options/Classes/Particles/Stroke.js +0 -39
- package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +0 -42
- package/umd/Options/Classes/ResizeEvent.js +0 -34
- package/umd/Options/Classes/ValueWithRandom.js +0 -56
- package/umd/Options/Interfaces/Background/IBackground.js +0 -12
- package/umd/Options/Interfaces/FullScreen/IFullScreen.js +0 -12
- package/umd/Options/Interfaces/IAnimatable.js +0 -12
- package/umd/Options/Interfaces/IAnimatableColor.js +0 -12
- package/umd/Options/Interfaces/IAnimation.js +0 -12
- package/umd/Options/Interfaces/IColorAnimation.js +0 -12
- package/umd/Options/Interfaces/IHslAnimation.js +0 -12
- package/umd/Options/Interfaces/IOptionLoader.js +0 -12
- package/umd/Options/Interfaces/IOptions.js +0 -12
- package/umd/Options/Interfaces/IOptionsColor.js +0 -12
- package/umd/Options/Interfaces/IResizeEvent.js +0 -12
- package/umd/Options/Interfaces/IValueWithRandom.js +0 -12
- package/umd/Options/Interfaces/Particles/Bounce/IParticlesBounce.js +0 -12
- package/umd/Options/Interfaces/Particles/Effect/IEffect.js +0 -12
- package/umd/Options/Interfaces/Particles/IFill.js +0 -12
- package/umd/Options/Interfaces/Particles/IParticlesOptions.js +0 -12
- package/umd/Options/Interfaces/Particles/IStroke.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMove.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMoveAngle.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMoveCenter.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMoveGravity.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IOutModes.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/ISpin.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/Path/IMovePath.js +0 -12
- package/umd/Options/Interfaces/Particles/Number/IParticlesDensity.js +0 -12
- package/umd/Options/Interfaces/Particles/Number/IParticlesNumber.js +0 -12
- package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +0 -12
- package/umd/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -12
- package/umd/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Size/ISize.js +0 -12
- package/umd/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -12
- package/umd/Options/Interfaces/Particles/ZIndex/IZIndex.js +0 -12
- package/umd/Types/CanvasContextType.js +0 -12
- package/umd/Types/CustomEventArgs.js +0 -12
- package/umd/Types/CustomEventListener.js +0 -12
- package/umd/Types/EasingFunction.js +0 -12
- package/umd/Types/EngineInitializers.js +0 -12
- package/umd/Types/ExportResult.js +0 -12
- package/umd/Types/ISourceOptions.js +0 -12
- package/umd/Types/ParticlesGroups.js +0 -12
- package/umd/Types/PathOptions.js +0 -12
- package/umd/Types/RangeValue.js +0 -12
- package/umd/Types/RecursivePartial.js +0 -12
- package/umd/Types/ShapeData.js +0 -12
- package/umd/Types/SingleOrMultiple.js +0 -12
- package/umd/Utils/CanvasUtils.js +0 -145
- package/umd/Utils/ColorUtils.js +0 -395
- package/umd/Utils/EventDispatcher.js +0 -63
- package/umd/Utils/LogUtils.js +0 -37
- package/umd/Utils/MathUtils.js +0 -203
- package/umd/Utils/OptionsUtils.js +0 -25
- package/umd/Utils/TypeUtils.js +0 -40
- package/umd/Utils/Utils.js +0 -484
- package/umd/bundle.js +0 -32
- package/umd/export-types.js +0 -12
- package/umd/exports.js +0 -82
- package/umd/index.js +0 -32
- package/umd/initEngine.js +0 -17
package/umd/Types/RangeValue.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
});
|
package/umd/Types/ShapeData.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
});
|
package/umd/Utils/CanvasUtils.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../Core/Utils/Constants.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.paintBase = paintBase;
|
|
13
|
-
exports.paintImage = paintImage;
|
|
14
|
-
exports.clear = clear;
|
|
15
|
-
exports.drawParticle = drawParticle;
|
|
16
|
-
exports.drawAfterEffect = drawAfterEffect;
|
|
17
|
-
exports.drawBeforeEffect = drawBeforeEffect;
|
|
18
|
-
exports.drawShape = drawShape;
|
|
19
|
-
exports.drawShapeAfterDraw = drawShapeAfterDraw;
|
|
20
|
-
exports.drawShapeBeforeDraw = drawShapeBeforeDraw;
|
|
21
|
-
exports.drawParticlePlugin = drawParticlePlugin;
|
|
22
|
-
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
23
|
-
function paintBase(context, dimension, baseColor) {
|
|
24
|
-
context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
|
|
25
|
-
context.fillRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
|
|
26
|
-
}
|
|
27
|
-
function paintImage(context, dimension, image, opacity) {
|
|
28
|
-
if (!image) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const prevAlpha = context.globalAlpha;
|
|
32
|
-
context.globalAlpha = opacity;
|
|
33
|
-
context.drawImage(image, Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
|
|
34
|
-
context.globalAlpha = prevAlpha;
|
|
35
|
-
}
|
|
36
|
-
function clear(context, dimension) {
|
|
37
|
-
context.clearRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
|
|
38
|
-
}
|
|
39
|
-
function drawParticle(data) {
|
|
40
|
-
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = Constants_js_1.defaultZoom, drawPosition = {
|
|
41
|
-
x: pos.x,
|
|
42
|
-
y: pos.y,
|
|
43
|
-
};
|
|
44
|
-
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
|
45
|
-
if (colorStyles.fill) {
|
|
46
|
-
context.fillStyle = colorStyles.fill;
|
|
47
|
-
}
|
|
48
|
-
const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? Constants_js_1.minStrokeWidth;
|
|
49
|
-
context.lineWidth = strokeWidth;
|
|
50
|
-
if (colorStyles.stroke) {
|
|
51
|
-
context.strokeStyle = colorStyles.stroke;
|
|
52
|
-
}
|
|
53
|
-
const drawData = {
|
|
54
|
-
context,
|
|
55
|
-
particle,
|
|
56
|
-
radius,
|
|
57
|
-
drawRadius: radius * drawScale,
|
|
58
|
-
opacity,
|
|
59
|
-
delta,
|
|
60
|
-
pixelRatio: container.retina.pixelRatio,
|
|
61
|
-
fill: fillEnabled,
|
|
62
|
-
stroke: strokeWidth > Constants_js_1.minStrokeWidth,
|
|
63
|
-
transformData,
|
|
64
|
-
position: { ...pos },
|
|
65
|
-
drawPosition,
|
|
66
|
-
drawScale,
|
|
67
|
-
};
|
|
68
|
-
for (const plugin of container.plugins) {
|
|
69
|
-
plugin.drawParticleTransform?.(drawData);
|
|
70
|
-
}
|
|
71
|
-
const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
|
|
72
|
-
drawBeforeEffect(effect, drawData);
|
|
73
|
-
drawShapeBeforeDraw(shape, drawData);
|
|
74
|
-
drawShape(shape, drawData);
|
|
75
|
-
drawShapeAfterDraw(shape, drawData);
|
|
76
|
-
drawAfterEffect(effect, drawData);
|
|
77
|
-
context.resetTransform();
|
|
78
|
-
}
|
|
79
|
-
function drawAfterEffect(drawer, data) {
|
|
80
|
-
if (!drawer?.drawAfter) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const { particle } = data;
|
|
84
|
-
if (!particle.effect) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
drawer.drawAfter(data);
|
|
88
|
-
}
|
|
89
|
-
function drawBeforeEffect(drawer, data) {
|
|
90
|
-
if (!drawer?.drawBefore) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const { particle } = data;
|
|
94
|
-
if (!particle.effect) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
drawer.drawBefore(data);
|
|
98
|
-
}
|
|
99
|
-
function drawShape(drawer, data) {
|
|
100
|
-
if (!drawer) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const { context, fill, particle, stroke } = data;
|
|
104
|
-
if (!particle.shape) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
context.beginPath();
|
|
108
|
-
drawer.draw(data);
|
|
109
|
-
if (particle.shapeClose) {
|
|
110
|
-
context.closePath();
|
|
111
|
-
}
|
|
112
|
-
if (stroke) {
|
|
113
|
-
context.stroke();
|
|
114
|
-
}
|
|
115
|
-
if (fill) {
|
|
116
|
-
context.fill();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function drawShapeAfterDraw(drawer, data) {
|
|
120
|
-
if (!drawer?.afterDraw) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const { particle } = data;
|
|
124
|
-
if (!particle.shape) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
drawer.afterDraw(data);
|
|
128
|
-
}
|
|
129
|
-
function drawShapeBeforeDraw(drawer, data) {
|
|
130
|
-
if (!drawer?.beforeDraw) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const { particle } = data;
|
|
134
|
-
if (!particle.shape) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
drawer.beforeDraw(data);
|
|
138
|
-
}
|
|
139
|
-
function drawParticlePlugin(context, plugin, particle, delta) {
|
|
140
|
-
if (!plugin.drawParticle) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
plugin.drawParticle(context, particle, delta);
|
|
144
|
-
}
|
|
145
|
-
});
|
package/umd/Utils/ColorUtils.js
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./MathUtils.js", "../Core/Utils/Constants.js", "./TypeUtils.js", "../Enums/Types/AlterType.js", "../Enums/AnimationStatus.js", "./Utils.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.rangeColorToRgb = rangeColorToRgb;
|
|
13
|
-
exports.colorToRgb = colorToRgb;
|
|
14
|
-
exports.colorToHsl = colorToHsl;
|
|
15
|
-
exports.rangeColorToHsl = rangeColorToHsl;
|
|
16
|
-
exports.rgbToHsl = rgbToHsl;
|
|
17
|
-
exports.stringToAlpha = stringToAlpha;
|
|
18
|
-
exports.stringToRgb = stringToRgb;
|
|
19
|
-
exports.hslToRgb = hslToRgb;
|
|
20
|
-
exports.hslaToRgba = hslaToRgba;
|
|
21
|
-
exports.getRandomRgbColor = getRandomRgbColor;
|
|
22
|
-
exports.getStyleFromRgb = getStyleFromRgb;
|
|
23
|
-
exports.getStyleFromHsl = getStyleFromHsl;
|
|
24
|
-
exports.colorMix = colorMix;
|
|
25
|
-
exports.getLinkColor = getLinkColor;
|
|
26
|
-
exports.getLinkRandomColor = getLinkRandomColor;
|
|
27
|
-
exports.getHslFromAnimation = getHslFromAnimation;
|
|
28
|
-
exports.getHslAnimationFromHsl = getHslAnimationFromHsl;
|
|
29
|
-
exports.updateColorValue = updateColorValue;
|
|
30
|
-
exports.updateColor = updateColor;
|
|
31
|
-
exports.alterHsl = alterHsl;
|
|
32
|
-
const MathUtils_js_1 = require("./MathUtils.js");
|
|
33
|
-
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
34
|
-
const TypeUtils_js_1 = require("./TypeUtils.js");
|
|
35
|
-
const AlterType_js_1 = require("../Enums/Types/AlterType.js");
|
|
36
|
-
const AnimationStatus_js_1 = require("../Enums/AnimationStatus.js");
|
|
37
|
-
const Utils_js_1 = require("./Utils.js");
|
|
38
|
-
const styleCache = new Map(), maxCacheSize = 1000, firstIndex = 0, rgbFixedPrecision = 2, hslFixedPrecision = 2;
|
|
39
|
-
function getCachedStyle(key, generator) {
|
|
40
|
-
let cached = styleCache.get(key);
|
|
41
|
-
if (!cached) {
|
|
42
|
-
cached = generator();
|
|
43
|
-
if (styleCache.size >= maxCacheSize) {
|
|
44
|
-
const keysToDelete = [...styleCache.keys()].slice(firstIndex, maxCacheSize * Constants_js_1.half);
|
|
45
|
-
keysToDelete.forEach(k => styleCache.delete(k));
|
|
46
|
-
}
|
|
47
|
-
styleCache.set(key, cached);
|
|
48
|
-
}
|
|
49
|
-
return cached;
|
|
50
|
-
}
|
|
51
|
-
function stringToRgba(pluginManager, input) {
|
|
52
|
-
if (!input) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
for (const manager of pluginManager.colorManagers.values()) {
|
|
56
|
-
if (manager.accepts(input)) {
|
|
57
|
-
return manager.parseString(input);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
function rangeColorToRgb(pluginManager, input, index, useIndex = true) {
|
|
63
|
-
if (!input) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
|
|
67
|
-
if ((0, TypeUtils_js_1.isString)(color.value)) {
|
|
68
|
-
return colorToRgb(pluginManager, color.value, index, useIndex);
|
|
69
|
-
}
|
|
70
|
-
if ((0, TypeUtils_js_1.isArray)(color.value)) {
|
|
71
|
-
const value = (0, Utils_js_1.itemFromArray)(color.value, index, useIndex);
|
|
72
|
-
if (!value) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
return rangeColorToRgb(pluginManager, {
|
|
76
|
-
value,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
for (const manager of pluginManager.colorManagers.values()) {
|
|
80
|
-
const res = manager.handleRangeColor(color);
|
|
81
|
-
if (res) {
|
|
82
|
-
return res;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
function colorToRgb(pluginManager, input, index, useIndex = true) {
|
|
88
|
-
if (!input) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
|
|
92
|
-
if ((0, TypeUtils_js_1.isString)(color.value)) {
|
|
93
|
-
return color.value === Constants_js_1.randomColorValue ? getRandomRgbColor() : stringToRgb(pluginManager, color.value);
|
|
94
|
-
}
|
|
95
|
-
if ((0, TypeUtils_js_1.isArray)(color.value)) {
|
|
96
|
-
const value = (0, Utils_js_1.itemFromArray)(color.value, index, useIndex);
|
|
97
|
-
if (!value) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
return colorToRgb(pluginManager, {
|
|
101
|
-
value,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
for (const manager of pluginManager.colorManagers.values()) {
|
|
105
|
-
const res = manager.handleColor(color);
|
|
106
|
-
if (res) {
|
|
107
|
-
return res;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
function colorToHsl(pluginManager, color, index, useIndex = true) {
|
|
113
|
-
const rgb = colorToRgb(pluginManager, color, index, useIndex);
|
|
114
|
-
return rgb ? rgbToHsl(rgb) : undefined;
|
|
115
|
-
}
|
|
116
|
-
function rangeColorToHsl(pluginManager, color, index, useIndex = true) {
|
|
117
|
-
const rgb = rangeColorToRgb(pluginManager, color, index, useIndex);
|
|
118
|
-
return rgb ? rgbToHsl(rgb) : undefined;
|
|
119
|
-
}
|
|
120
|
-
function rgbToHsl(color) {
|
|
121
|
-
const r1 = color.r / Constants_js_1.rgbMax, g1 = color.g / Constants_js_1.rgbMax, b1 = color.b / Constants_js_1.rgbMax, max = Math.max(r1, g1, b1), min = Math.min(r1, g1, b1), res = {
|
|
122
|
-
h: Constants_js_1.hMin,
|
|
123
|
-
l: (max + min) * Constants_js_1.half,
|
|
124
|
-
s: Constants_js_1.sMin,
|
|
125
|
-
};
|
|
126
|
-
if (max !== min) {
|
|
127
|
-
res.s = res.l < Constants_js_1.half ? (max - min) / (max + min) : (max - min) / (Constants_js_1.double - max - min);
|
|
128
|
-
if (r1 === max) {
|
|
129
|
-
res.h = (g1 - b1) / (max - min);
|
|
130
|
-
}
|
|
131
|
-
else if (g1 === max) {
|
|
132
|
-
res.h = Constants_js_1.double + (b1 - r1) / (max - min);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
res.h = Constants_js_1.double * Constants_js_1.double + (r1 - g1) / (max - min);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
res.l *= Constants_js_1.lMax;
|
|
139
|
-
res.s *= Constants_js_1.sMax;
|
|
140
|
-
res.h *= Constants_js_1.hPhase;
|
|
141
|
-
if (res.h < Constants_js_1.hMin) {
|
|
142
|
-
res.h += Constants_js_1.hMax;
|
|
143
|
-
}
|
|
144
|
-
if (res.h >= Constants_js_1.hMax) {
|
|
145
|
-
res.h -= Constants_js_1.hMax;
|
|
146
|
-
}
|
|
147
|
-
return res;
|
|
148
|
-
}
|
|
149
|
-
function stringToAlpha(pluginManager, input) {
|
|
150
|
-
return stringToRgba(pluginManager, input)?.a;
|
|
151
|
-
}
|
|
152
|
-
function stringToRgb(pluginManager, input) {
|
|
153
|
-
return stringToRgba(pluginManager, input);
|
|
154
|
-
}
|
|
155
|
-
function hslToRgb(hsl) {
|
|
156
|
-
const h = ((hsl.h % Constants_js_1.hMax) + Constants_js_1.hMax) % Constants_js_1.hMax, s = Math.max(Constants_js_1.sMin, Math.min(Constants_js_1.sMax, hsl.s)), l = Math.max(Constants_js_1.lMin, Math.min(Constants_js_1.lMax, hsl.l)), hNormalized = h / Constants_js_1.hMax, sNormalized = s / Constants_js_1.sMax, lNormalized = l / Constants_js_1.lMax;
|
|
157
|
-
if (s === Constants_js_1.sMin) {
|
|
158
|
-
const grayscaleValue = Math.round(lNormalized * Constants_js_1.rgbMax);
|
|
159
|
-
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
|
|
160
|
-
}
|
|
161
|
-
const channel = (temp1, temp2, temp3) => {
|
|
162
|
-
const temp3Min = 0, temp3Max = 1;
|
|
163
|
-
if (temp3 < temp3Min) {
|
|
164
|
-
temp3++;
|
|
165
|
-
}
|
|
166
|
-
if (temp3 > temp3Max) {
|
|
167
|
-
temp3--;
|
|
168
|
-
}
|
|
169
|
-
if (temp3 * Constants_js_1.sextuple < temp3Max) {
|
|
170
|
-
return temp1 + (temp2 - temp1) * Constants_js_1.sextuple * temp3;
|
|
171
|
-
}
|
|
172
|
-
if (temp3 * Constants_js_1.double < temp3Max) {
|
|
173
|
-
return temp2;
|
|
174
|
-
}
|
|
175
|
-
if (temp3 * Constants_js_1.triple < temp3Max * Constants_js_1.double) {
|
|
176
|
-
const temp3Offset = Constants_js_1.double / Constants_js_1.triple;
|
|
177
|
-
return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * Constants_js_1.sextuple;
|
|
178
|
-
}
|
|
179
|
-
return temp1;
|
|
180
|
-
}, temp1 = lNormalized < Constants_js_1.half
|
|
181
|
-
? lNormalized * (Constants_js_1.sNormalizedOffset + sNormalized)
|
|
182
|
-
: lNormalized + sNormalized - lNormalized * sNormalized, temp2 = Constants_js_1.double * lNormalized - temp1, phaseThird = Constants_js_1.phaseNumerator / Constants_js_1.triple, red = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * channel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * channel(temp2, temp1, hNormalized)), blue = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * channel(temp2, temp1, hNormalized - phaseThird));
|
|
183
|
-
return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
|
|
184
|
-
}
|
|
185
|
-
function hslaToRgba(hsla) {
|
|
186
|
-
const rgbResult = hslToRgb(hsla);
|
|
187
|
-
return {
|
|
188
|
-
a: hsla.a,
|
|
189
|
-
b: rgbResult.b,
|
|
190
|
-
g: rgbResult.g,
|
|
191
|
-
r: rgbResult.r,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function getRandomRgbColor(min) {
|
|
195
|
-
const fixedMin = min ?? Constants_js_1.defaultRgbMin, fixedMax = Constants_js_1.rgbMax + Constants_js_1.identity, getRgbInRangeValue = () => Math.floor((0, MathUtils_js_1.getRandomInRange)(fixedMin, fixedMax));
|
|
196
|
-
return {
|
|
197
|
-
b: getRgbInRangeValue(),
|
|
198
|
-
g: getRgbInRangeValue(),
|
|
199
|
-
r: getRgbInRangeValue(),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function getStyleFromRgb(color, hdr, opacity) {
|
|
203
|
-
const op = opacity ?? Constants_js_1.defaultOpacity, key = `rgb-${color.r.toFixed(rgbFixedPrecision)}-${color.g.toFixed(rgbFixedPrecision)}-${color.b.toFixed(rgbFixedPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
|
|
204
|
-
return getCachedStyle(key, () => (hdr ? getHdrStyleFromRgb(color, opacity) : getSdrStyleFromRgb(color, opacity)));
|
|
205
|
-
}
|
|
206
|
-
function getHdrStyleFromRgb(color, opacity) {
|
|
207
|
-
return `color(display-p3 ${(color.r / Constants_js_1.rgbMax).toString()} ${(color.g / Constants_js_1.rgbMax).toString()} ${(color.b / Constants_js_1.rgbMax).toString()} / ${(opacity ?? Constants_js_1.defaultOpacity).toString()})`;
|
|
208
|
-
}
|
|
209
|
-
function getSdrStyleFromRgb(color, opacity) {
|
|
210
|
-
return `rgba(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()}, ${(opacity ?? Constants_js_1.defaultOpacity).toString()})`;
|
|
211
|
-
}
|
|
212
|
-
function getStyleFromHsl(color, hdr, opacity) {
|
|
213
|
-
const op = opacity ?? Constants_js_1.defaultOpacity, key = `hsl-${color.h.toFixed(hslFixedPrecision)}-${color.s.toFixed(hslFixedPrecision)}-${color.l.toFixed(hslFixedPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
|
|
214
|
-
return getCachedStyle(key, () => (hdr ? getHdrStyleFromHsl(color, opacity) : getSdrStyleFromHsl(color, opacity)));
|
|
215
|
-
}
|
|
216
|
-
function getHdrStyleFromHsl(color, opacity) {
|
|
217
|
-
return getHdrStyleFromRgb(hslToRgb(color), opacity);
|
|
218
|
-
}
|
|
219
|
-
function getSdrStyleFromHsl(color, opacity) {
|
|
220
|
-
return `hsla(${color.h.toString()}, ${color.s.toString()}%, ${color.l.toString()}%, ${(opacity ?? Constants_js_1.defaultOpacity).toString()})`;
|
|
221
|
-
}
|
|
222
|
-
function colorMix(color1, color2, size1, size2) {
|
|
223
|
-
let rgb1 = color1, rgb2 = color2;
|
|
224
|
-
if (!("r" in rgb1)) {
|
|
225
|
-
rgb1 = hslToRgb(color1);
|
|
226
|
-
}
|
|
227
|
-
if (!("r" in rgb2)) {
|
|
228
|
-
rgb2 = hslToRgb(color2);
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
b: (0, MathUtils_js_1.mix)(rgb1.b, rgb2.b, size1, size2),
|
|
232
|
-
g: (0, MathUtils_js_1.mix)(rgb1.g, rgb2.g, size1, size2),
|
|
233
|
-
r: (0, MathUtils_js_1.mix)(rgb1.r, rgb2.r, size1, size2),
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
function getLinkColor(p1, p2, linkColor) {
|
|
237
|
-
if (linkColor === Constants_js_1.randomColorValue) {
|
|
238
|
-
return getRandomRgbColor();
|
|
239
|
-
}
|
|
240
|
-
else if (linkColor === Constants_js_1.midColorValue) {
|
|
241
|
-
const sourceColor = p1.getFillColor() ?? p1.getStrokeColor(), destColor = p2?.getFillColor() ?? p2?.getStrokeColor();
|
|
242
|
-
if (sourceColor && destColor && p2) {
|
|
243
|
-
return colorMix(sourceColor, destColor, p1.getRadius(), p2.getRadius());
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
const hslColor = sourceColor ?? destColor;
|
|
247
|
-
if (hslColor) {
|
|
248
|
-
return hslToRgb(hslColor);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
return linkColor;
|
|
254
|
-
}
|
|
255
|
-
return undefined;
|
|
256
|
-
}
|
|
257
|
-
function getLinkRandomColor(pluginManager, optColor, blink, consent) {
|
|
258
|
-
const color = (0, TypeUtils_js_1.isString)(optColor) ? optColor : optColor.value;
|
|
259
|
-
if (color === Constants_js_1.randomColorValue) {
|
|
260
|
-
if (consent) {
|
|
261
|
-
return rangeColorToRgb(pluginManager, {
|
|
262
|
-
value: color,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
if (blink) {
|
|
266
|
-
return Constants_js_1.randomColorValue;
|
|
267
|
-
}
|
|
268
|
-
return Constants_js_1.midColorValue;
|
|
269
|
-
}
|
|
270
|
-
else if (color === Constants_js_1.midColorValue) {
|
|
271
|
-
return Constants_js_1.midColorValue;
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
return rangeColorToRgb(pluginManager, {
|
|
275
|
-
value: color,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
function getHslFromAnimation(animation) {
|
|
280
|
-
return animation === undefined
|
|
281
|
-
? undefined
|
|
282
|
-
: {
|
|
283
|
-
h: animation.h.value,
|
|
284
|
-
s: animation.s.value,
|
|
285
|
-
l: animation.l.value,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
289
|
-
const resColor = {
|
|
290
|
-
h: {
|
|
291
|
-
enable: false,
|
|
292
|
-
value: hsl.h,
|
|
293
|
-
min: Constants_js_1.hMin,
|
|
294
|
-
max: Constants_js_1.hMax,
|
|
295
|
-
},
|
|
296
|
-
s: {
|
|
297
|
-
enable: false,
|
|
298
|
-
value: hsl.s,
|
|
299
|
-
min: Constants_js_1.sMin,
|
|
300
|
-
max: Constants_js_1.sMax,
|
|
301
|
-
},
|
|
302
|
-
l: {
|
|
303
|
-
enable: false,
|
|
304
|
-
value: hsl.l,
|
|
305
|
-
min: Constants_js_1.lMin,
|
|
306
|
-
max: Constants_js_1.lMax,
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
if (animationOptions) {
|
|
310
|
-
setColorAnimation(resColor.h, animationOptions.h, reduceFactor);
|
|
311
|
-
setColorAnimation(resColor.s, animationOptions.s, reduceFactor);
|
|
312
|
-
setColorAnimation(resColor.l, animationOptions.l, reduceFactor);
|
|
313
|
-
}
|
|
314
|
-
return resColor;
|
|
315
|
-
}
|
|
316
|
-
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
317
|
-
colorValue.enable = colorAnimation.enable;
|
|
318
|
-
colorValue.min = colorAnimation.min;
|
|
319
|
-
colorValue.max = colorAnimation.max;
|
|
320
|
-
if (colorValue.enable) {
|
|
321
|
-
colorValue.velocity = ((0, MathUtils_js_1.getRangeValue)(colorAnimation.speed) / Constants_js_1.percentDenominator) * reduceFactor;
|
|
322
|
-
colorValue.decay = Constants_js_1.decayOffset - (0, MathUtils_js_1.getRangeValue)(colorAnimation.decay);
|
|
323
|
-
colorValue.status = AnimationStatus_js_1.AnimationStatus.increasing;
|
|
324
|
-
colorValue.loops = Constants_js_1.defaultLoops;
|
|
325
|
-
colorValue.maxLoops = (0, MathUtils_js_1.getRangeValue)(colorAnimation.count);
|
|
326
|
-
colorValue.time = Constants_js_1.defaultTime;
|
|
327
|
-
colorValue.delayTime = (0, MathUtils_js_1.getRangeValue)(colorAnimation.delay) * Constants_js_1.millisecondsToSeconds;
|
|
328
|
-
if (!colorAnimation.sync) {
|
|
329
|
-
colorValue.velocity *= (0, MathUtils_js_1.getRandom)();
|
|
330
|
-
colorValue.value *= (0, MathUtils_js_1.getRandom)();
|
|
331
|
-
}
|
|
332
|
-
colorValue.initialValue = colorValue.value;
|
|
333
|
-
colorValue.offset = (0, MathUtils_js_1.setRangeValue)(colorAnimation.offset);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
colorValue.velocity = Constants_js_1.defaultVelocity;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function updateColorValue(data, decrease, delta) {
|
|
340
|
-
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
|
|
341
|
-
if (!data.enable ||
|
|
342
|
-
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
data.time ??= 0;
|
|
346
|
-
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
347
|
-
data.time += delta.value;
|
|
348
|
-
}
|
|
349
|
-
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const offset = data.offset ? (0, MathUtils_js_1.randomInRangeValue)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
|
|
353
|
-
if (!decrease || data.status === AnimationStatus_js_1.AnimationStatus.increasing) {
|
|
354
|
-
data.value += velocity;
|
|
355
|
-
if (data.value > max) {
|
|
356
|
-
data.loops ??= 0;
|
|
357
|
-
data.loops++;
|
|
358
|
-
if (decrease) {
|
|
359
|
-
data.status = AnimationStatus_js_1.AnimationStatus.decreasing;
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
data.value -= max;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
data.value -= velocity;
|
|
368
|
-
if (data.value < min) {
|
|
369
|
-
data.loops ??= 0;
|
|
370
|
-
data.loops++;
|
|
371
|
-
data.status = AnimationStatus_js_1.AnimationStatus.increasing;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
if (data.velocity && decay !== identity) {
|
|
375
|
-
data.velocity *= decay;
|
|
376
|
-
}
|
|
377
|
-
data.value = (0, MathUtils_js_1.clamp)(data.value, min, max);
|
|
378
|
-
}
|
|
379
|
-
function updateColor(color, delta) {
|
|
380
|
-
if (!color) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
const { h, s, l } = color;
|
|
384
|
-
updateColorValue(h, false, delta);
|
|
385
|
-
updateColorValue(s, true, delta);
|
|
386
|
-
updateColorValue(l, true, delta);
|
|
387
|
-
}
|
|
388
|
-
function alterHsl(color, type, value) {
|
|
389
|
-
return {
|
|
390
|
-
h: color.h,
|
|
391
|
-
s: color.s,
|
|
392
|
-
l: color.l + (type === AlterType_js_1.AlterType.darken ? -Constants_js_1.lFactor : Constants_js_1.lFactor) * value,
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../Core/Utils/Constants.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EventDispatcher = void 0;
|
|
13
|
-
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
14
|
-
class EventDispatcher {
|
|
15
|
-
_listeners;
|
|
16
|
-
constructor() {
|
|
17
|
-
this._listeners = new Map();
|
|
18
|
-
}
|
|
19
|
-
addEventListener(type, listener) {
|
|
20
|
-
this.removeEventListener(type, listener);
|
|
21
|
-
let arr = this._listeners.get(type);
|
|
22
|
-
if (!arr) {
|
|
23
|
-
arr = [];
|
|
24
|
-
this._listeners.set(type, arr);
|
|
25
|
-
}
|
|
26
|
-
arr.push(listener);
|
|
27
|
-
}
|
|
28
|
-
dispatchEvent(type, args) {
|
|
29
|
-
const listeners = this._listeners.get(type);
|
|
30
|
-
listeners?.forEach(handler => {
|
|
31
|
-
handler(args);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
hasEventListener(type) {
|
|
35
|
-
return !!this._listeners.get(type);
|
|
36
|
-
}
|
|
37
|
-
removeAllEventListeners(type) {
|
|
38
|
-
if (!type) {
|
|
39
|
-
this._listeners = new Map();
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
this._listeners.delete(type);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
removeEventListener(type, listener) {
|
|
46
|
-
const arr = this._listeners.get(type);
|
|
47
|
-
if (!arr) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const length = arr.length, idx = arr.indexOf(listener);
|
|
51
|
-
if (idx < Constants_js_1.minIndex) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (length === Constants_js_1.deleteCount) {
|
|
55
|
-
this._listeners.delete(type);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
arr.splice(idx, Constants_js_1.deleteCount);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.EventDispatcher = EventDispatcher;
|
|
63
|
-
});
|