@lumen5/lottie-web 5.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.json +3 -0
- package/.eslintrc.json +46 -0
- package/.gitattributes +1 -0
- package/.github/FUNDING.yml +1 -0
- package/.github/ISSUE_TEMPLATE.md +22 -0
- package/.github/workflows/publish.yml +26 -0
- package/.github/workflows/testAnimations.yml +29 -0
- package/.github/workflows/updateScreenshots.yml +34 -0
- package/CHANGELOG.md +601 -0
- package/History.md +1230 -0
- package/LICENSE.md +21 -0
- package/README.md +351 -0
- package/bower.json +31 -0
- package/build/old_parser/bodymovin_parser.jsx +3023 -0
- package/build/old_parser/helperProject.aep +0 -0
- package/build/player/cjs/lottie.min.js +18229 -0
- package/build/player/cjs/lottie_canvas.min.js +16465 -0
- package/build/player/cjs/lottie_html.min.js +16312 -0
- package/build/player/cjs/lottie_light.min.js +11584 -0
- package/build/player/cjs/lottie_light_canvas.min.js +13518 -0
- package/build/player/cjs/lottie_light_html.min.js +12843 -0
- package/build/player/cjs/lottie_svg.min.js +15053 -0
- package/build/player/esm/lottie.min.js +18225 -0
- package/build/player/esm/lottie_canvas.min.js +16461 -0
- package/build/player/esm/lottie_html.min.js +16308 -0
- package/build/player/esm/lottie_light.min.js +11580 -0
- package/build/player/esm/lottie_light_canvas.min.js +13514 -0
- package/build/player/esm/lottie_light_html.min.js +12839 -0
- package/build/player/esm/lottie_svg.min.js +15049 -0
- package/build/player/lottie.d.ts +5 -0
- package/build/player/lottie.js +17151 -0
- package/build/player/lottie.min.js +1 -0
- package/build/player/lottie_canvas.js +15506 -0
- package/build/player/lottie_canvas.min.js +1 -0
- package/build/player/lottie_canvas_worker.js +18196 -0
- package/build/player/lottie_canvas_worker.min.js +15 -0
- package/build/player/lottie_html.d.ts +5 -0
- package/build/player/lottie_html.js +15354 -0
- package/build/player/lottie_html.min.js +1 -0
- package/build/player/lottie_light.d.ts +5 -0
- package/build/player/lottie_light.js +10854 -0
- package/build/player/lottie_light.min.js +1 -0
- package/build/player/lottie_light_canvas.d.ts +5 -0
- package/build/player/lottie_light_canvas.js +12666 -0
- package/build/player/lottie_light_canvas.min.js +1 -0
- package/build/player/lottie_light_html.d.ts +5 -0
- package/build/player/lottie_light_html.js +12029 -0
- package/build/player/lottie_light_html.min.js +1 -0
- package/build/player/lottie_svg.d.ts +5 -0
- package/build/player/lottie_svg.js +14179 -0
- package/build/player/lottie_svg.min.js +1 -0
- package/build/player/lottie_worker.js +18196 -0
- package/build/player/lottie_worker.min.js +15 -0
- package/docs/json/animation.json +101 -0
- package/docs/json/effects/angle.json +40 -0
- package/docs/json/effects/checkBox.json +40 -0
- package/docs/json/effects/color.json +40 -0
- package/docs/json/effects/customValue.json +4 -0
- package/docs/json/effects/dropDown.json +40 -0
- package/docs/json/effects/fill.json +55 -0
- package/docs/json/effects/group.json +41 -0
- package/docs/json/effects/index.json +51 -0
- package/docs/json/effects/layer.json +33 -0
- package/docs/json/effects/noValue.json +1 -0
- package/docs/json/effects/point.json +43 -0
- package/docs/json/effects/proLevels.json +130 -0
- package/docs/json/effects/slider.json +40 -0
- package/docs/json/effects/stroke.json +64 -0
- package/docs/json/effects/tint.json +43 -0
- package/docs/json/effects/tritone.json +46 -0
- package/docs/json/helpers/blendMode.json +71 -0
- package/docs/json/helpers/boolean.json +14 -0
- package/docs/json/helpers/composite.json +15 -0
- package/docs/json/helpers/lineCap.json +19 -0
- package/docs/json/helpers/lineJoin.json +19 -0
- package/docs/json/helpers/mask.json +80 -0
- package/docs/json/helpers/textBased.json +23 -0
- package/docs/json/helpers/textGrouping.json +23 -0
- package/docs/json/helpers/textShape.json +31 -0
- package/docs/json/helpers/transform.json +146 -0
- package/docs/json/layers/image.json +113 -0
- package/docs/json/layers/null.json +87 -0
- package/docs/json/layers/preComp.json +118 -0
- package/docs/json/layers/shape.json +157 -0
- package/docs/json/layers/solid.json +120 -0
- package/docs/json/layers/text.json +523 -0
- package/docs/json/properties/doubleKeyframe.json +50 -0
- package/docs/json/properties/multiDimensional.json +21 -0
- package/docs/json/properties/multiDimensionalKeyframed.json +35 -0
- package/docs/json/properties/offsetKeyframe.json +53 -0
- package/docs/json/properties/shape.json +27 -0
- package/docs/json/properties/shapeKeyframed.json +35 -0
- package/docs/json/properties/shapeProp.json +50 -0
- package/docs/json/properties/shapePropKeyframe.json +54 -0
- package/docs/json/properties/value.json +21 -0
- package/docs/json/properties/valueKeyframe.json +33 -0
- package/docs/json/properties/valueKeyframed.json +25 -0
- package/docs/json/shapes/ellipse.json +54 -0
- package/docs/json/shapes/fill.json +48 -0
- package/docs/json/shapes/gFill.json +107 -0
- package/docs/json/shapes/gStroke.json +137 -0
- package/docs/json/shapes/group.json +89 -0
- package/docs/json/shapes/merge.json +27 -0
- package/docs/json/shapes/rect.json +66 -0
- package/docs/json/shapes/repeater.json +63 -0
- package/docs/json/shapes/round.json +35 -0
- package/docs/json/shapes/shape.json +40 -0
- package/docs/json/shapes/star.json +133 -0
- package/docs/json/shapes/stroke.json +78 -0
- package/docs/json/shapes/transform.json +102 -0
- package/docs/json/shapes/trim.json +61 -0
- package/docs/json/sources/chars.json +61 -0
- package/docs/json/sources/image.json +31 -0
- package/docs/json/sources/precomp.json +39 -0
- package/index.d.ts +197 -0
- package/package.json +54 -0
- package/player/index.html +115 -0
- package/player/js/3rd_party/BezierEaser.js +158 -0
- package/player/js/3rd_party/howler.js +5 -0
- package/player/js/3rd_party/seedrandom.js +237 -0
- package/player/js/3rd_party/transformation-matrix.js +449 -0
- package/player/js/EffectsManager.js +83 -0
- package/player/js/animation/AnimationItem.js +809 -0
- package/player/js/animation/AnimationItemWorkerOverride.js +157 -0
- package/player/js/animation/AnimationManager.js +248 -0
- package/player/js/animation/AnimationManagerWorkerOverride.js +201 -0
- package/player/js/effects/EffectsManagerPlaceholder.js +5 -0
- package/player/js/effects/SliderEffect.js +37 -0
- package/player/js/effects/TransformEffect.js +44 -0
- package/player/js/elements/AudioElement.js +102 -0
- package/player/js/elements/BaseElement.js +78 -0
- package/player/js/elements/BaseTextElement.js +4 -0
- package/player/js/elements/CompElement.js +107 -0
- package/player/js/elements/FootageElement.js +47 -0
- package/player/js/elements/ImageElement.js +42 -0
- package/player/js/elements/NullElement.js +39 -0
- package/player/js/elements/ShapeElement.js +76 -0
- package/player/js/elements/SolidElement.js +23 -0
- package/player/js/elements/TextElement.js +94 -0
- package/player/js/elements/canvasElements/CVBaseElement.js +167 -0
- package/player/js/elements/canvasElements/CVCompBaseElement.js +11 -0
- package/player/js/elements/canvasElements/CVCompElement.js +57 -0
- package/player/js/elements/canvasElements/CVContextData.js +239 -0
- package/player/js/elements/canvasElements/CVEffects.js +57 -0
- package/player/js/elements/canvasElements/CVImageElement.js +58 -0
- package/player/js/elements/canvasElements/CVMaskElement.js +72 -0
- package/player/js/elements/canvasElements/CVShapeElement.js +521 -0
- package/player/js/elements/canvasElements/CVSolidElement.js +30 -0
- package/player/js/elements/canvasElements/CVTextElement.js +244 -0
- package/player/js/elements/canvasElements/effects/CVGaussianBlurEffect.js +29 -0
- package/player/js/elements/canvasElements/effects/CVTransformEffect.js +9 -0
- package/player/js/elements/helpers/FrameElement.js +54 -0
- package/player/js/elements/helpers/HierarchyElement.js +52 -0
- package/player/js/elements/helpers/RenderableDOMElement.js +72 -0
- package/player/js/elements/helpers/RenderableElement.js +87 -0
- package/player/js/elements/helpers/TransformElement.js +140 -0
- package/player/js/elements/helpers/shapes/CVShapeData.js +33 -0
- package/player/js/elements/helpers/shapes/ProcessedElement.js +6 -0
- package/player/js/elements/helpers/shapes/SVGElementsRenderer.js +239 -0
- package/player/js/elements/helpers/shapes/SVGFillStyleData.js +18 -0
- package/player/js/elements/helpers/shapes/SVGGradientFillStyleData.js +100 -0
- package/player/js/elements/helpers/shapes/SVGGradientStrokeStyleData.js +20 -0
- package/player/js/elements/helpers/shapes/SVGNoStyleData.js +15 -0
- package/player/js/elements/helpers/shapes/SVGShapeData.js +28 -0
- package/player/js/elements/helpers/shapes/SVGStrokeStyleData.js +21 -0
- package/player/js/elements/helpers/shapes/SVGStyleData.js +19 -0
- package/player/js/elements/helpers/shapes/SVGTransformData.js +11 -0
- package/player/js/elements/helpers/shapes/ShapeElement.js +5 -0
- package/player/js/elements/helpers/shapes/ShapeGroupData.js +9 -0
- package/player/js/elements/helpers/shapes/ShapeTransformManager.js +61 -0
- package/player/js/elements/htmlElements/HBaseElement.js +88 -0
- package/player/js/elements/htmlElements/HCameraElement.js +170 -0
- package/player/js/elements/htmlElements/HCompElement.js +61 -0
- package/player/js/elements/htmlElements/HEffects.js +3 -0
- package/player/js/elements/htmlElements/HImageElement.js +42 -0
- package/player/js/elements/htmlElements/HShapeElement.js +261 -0
- package/player/js/elements/htmlElements/HSolidElement.js +36 -0
- package/player/js/elements/htmlElements/HTextElement.js +290 -0
- package/player/js/elements/svgElements/SVGBaseElement.js +181 -0
- package/player/js/elements/svgElements/SVGCompElement.js +28 -0
- package/player/js/elements/svgElements/SVGEffects.js +70 -0
- package/player/js/elements/svgElements/SVGEffectsPlaceholder.js +3 -0
- package/player/js/elements/svgElements/SVGShapeElement.js +366 -0
- package/player/js/elements/svgElements/SVGTextElement.js +322 -0
- package/player/js/elements/svgElements/effects/SVGComposableEffect.js +22 -0
- package/player/js/elements/svgElements/effects/SVGDropShadowEffect.js +83 -0
- package/player/js/elements/svgElements/effects/SVGFillFilter.js +22 -0
- package/player/js/elements/svgElements/effects/SVGGaussianBlurEffect.js +44 -0
- package/player/js/elements/svgElements/effects/SVGMatte3Effect.js +101 -0
- package/player/js/elements/svgElements/effects/SVGProLevelsFilter.js +108 -0
- package/player/js/elements/svgElements/effects/SVGStrokeEffect.js +119 -0
- package/player/js/elements/svgElements/effects/SVGTintEffect.js +47 -0
- package/player/js/elements/svgElements/effects/SVGTransformEffect.js +10 -0
- package/player/js/elements/svgElements/effects/SVGTritoneFilter.js +43 -0
- package/player/js/main.js +21 -0
- package/player/js/mask.js +239 -0
- package/player/js/module.js +153 -0
- package/player/js/modules/canvas.js +22 -0
- package/player/js/modules/canvas_light.js +25 -0
- package/player/js/modules/full.js +70 -0
- package/player/js/modules/full_worker.js +0 -0
- package/player/js/modules/html.js +37 -0
- package/player/js/modules/html_light.js +25 -0
- package/player/js/modules/main.js +162 -0
- package/player/js/modules/svg.js +37 -0
- package/player/js/modules/svg_light.js +25 -0
- package/player/js/renderers/BaseRenderer.js +187 -0
- package/player/js/renderers/CanvasRenderer.js +67 -0
- package/player/js/renderers/CanvasRendererBase.js +318 -0
- package/player/js/renderers/CanvasRendererWorkerOverride.js +54 -0
- package/player/js/renderers/HybridRenderer.js +47 -0
- package/player/js/renderers/HybridRendererBase.js +344 -0
- package/player/js/renderers/SVGRenderer.js +82 -0
- package/player/js/renderers/SVGRendererBase.js +255 -0
- package/player/js/renderers/renderersManager.js +29 -0
- package/player/js/utils/BaseEvent.js +42 -0
- package/player/js/utils/DataManager.js +676 -0
- package/player/js/utils/DataManagerWorkerOverrides.js +13 -0
- package/player/js/utils/FontManager.js +443 -0
- package/player/js/utils/FontManagerWorkerOverride.js +16 -0
- package/player/js/utils/PolynomialBezier.js +253 -0
- package/player/js/utils/PropertyFactory.js +489 -0
- package/player/js/utils/SlotManager.js +17 -0
- package/player/js/utils/TransformProperty.js +251 -0
- package/player/js/utils/animationFramePolyFill.js +25 -0
- package/player/js/utils/asset_loader.js +53 -0
- package/player/js/utils/asset_loader_worker_override.js +3 -0
- package/player/js/utils/audio/AudioController.js +85 -0
- package/player/js/utils/audio/AudioElement.js +6 -0
- package/player/js/utils/bez.js +251 -0
- package/player/js/utils/common.js +280 -0
- package/player/js/utils/expressions/CompInterface.js +28 -0
- package/player/js/utils/expressions/EffectInterface.js +111 -0
- package/player/js/utils/expressions/ExpressionManager.js +752 -0
- package/player/js/utils/expressions/ExpressionPropertyDecorator.js +463 -0
- package/player/js/utils/expressions/ExpressionTextPropertyDecorator.js +40 -0
- package/player/js/utils/expressions/ExpressionValue.js +61 -0
- package/player/js/utils/expressions/ExpressionValueFactory.js +102 -0
- package/player/js/utils/expressions/Expressions.js +48 -0
- package/player/js/utils/expressions/FootageInterface.js +60 -0
- package/player/js/utils/expressions/InterfacesProvider.js +21 -0
- package/player/js/utils/expressions/LayerInterface.js +179 -0
- package/player/js/utils/expressions/MaskInterface.js +50 -0
- package/player/js/utils/expressions/ProjectInterface.js +31 -0
- package/player/js/utils/expressions/PropertyGroupFactory.js +13 -0
- package/player/js/utils/expressions/PropertyInterface.js +19 -0
- package/player/js/utils/expressions/ShapeInterface.js +543 -0
- package/player/js/utils/expressions/TextInterface.js +35 -0
- package/player/js/utils/expressions/TextSelectorPropertyDecorator.js +44 -0
- package/player/js/utils/expressions/TransformInterface.js +126 -0
- package/player/js/utils/expressions/expressionHelpers.js +86 -0
- package/player/js/utils/expressions/shapes/ShapePathInterface.js +47 -0
- package/player/js/utils/featureSupport.js +16 -0
- package/player/js/utils/filters.js +32 -0
- package/player/js/utils/functionExtensions.js +27 -0
- package/player/js/utils/getFontProperties.js +42 -0
- package/player/js/utils/helpers/arrays.js +43 -0
- package/player/js/utils/helpers/assetManager.js +96 -0
- package/player/js/utils/helpers/blendModes.js +26 -0
- package/player/js/utils/helpers/bufferManager.js +61 -0
- package/player/js/utils/helpers/dynamicProperties.js +29 -0
- package/player/js/utils/helpers/effectTypes.js +3 -0
- package/player/js/utils/helpers/html_elements.js +6 -0
- package/player/js/utils/helpers/propTypes.js +3 -0
- package/player/js/utils/helpers/shapeEnums.js +16 -0
- package/player/js/utils/helpers/svg_elements.js +8 -0
- package/player/js/utils/imagePreloader.js +213 -0
- package/player/js/utils/imagePreloaderWorkerOverride.js +3 -0
- package/player/js/utils/markers/markerParser.js +47 -0
- package/player/js/utils/pooling/bezier_length_pool.js +20 -0
- package/player/js/utils/pooling/point_pool.js +13 -0
- package/player/js/utils/pooling/pool_factory.js +44 -0
- package/player/js/utils/pooling/pooling.js +15 -0
- package/player/js/utils/pooling/segments_length_pool.js +24 -0
- package/player/js/utils/pooling/shapeCollection_pool.js +48 -0
- package/player/js/utils/pooling/shape_pool.js +44 -0
- package/player/js/utils/shapes/DashProperty.js +63 -0
- package/player/js/utils/shapes/GradientProperty.js +93 -0
- package/player/js/utils/shapes/MouseModifier.js +222 -0
- package/player/js/utils/shapes/OffsetPathModifier.js +306 -0
- package/player/js/utils/shapes/PuckerAndBloatModifier.js +80 -0
- package/player/js/utils/shapes/RepeaterModifier.js +232 -0
- package/player/js/utils/shapes/RoundCornersModifier.js +122 -0
- package/player/js/utils/shapes/ShapeCollection.js +29 -0
- package/player/js/utils/shapes/ShapeModifiers.js +71 -0
- package/player/js/utils/shapes/ShapePath.js +100 -0
- package/player/js/utils/shapes/ShapeProperty.js +546 -0
- package/player/js/utils/shapes/TrimModifier.js +359 -0
- package/player/js/utils/shapes/ZigZagModifier.js +174 -0
- package/player/js/utils/shapes/shapePathBuilder.js +20 -0
- package/player/js/utils/text/LetterProps.js +60 -0
- package/player/js/utils/text/TextAnimatorDataProperty.js +34 -0
- package/player/js/utils/text/TextAnimatorProperty.js +610 -0
- package/player/js/utils/text/TextProperty.js +461 -0
- package/player/js/utils/text/TextSelectorProperty.js +179 -0
- package/player/js/worker_wrapper.js +1029 -0
- package/rollup.config.js +215 -0
- package/tasks/build.js +773 -0
- package/tasks/build_worker.js +164 -0
- package/tasks/watch.js +34 -0
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
function workerContent() {
|
|
2
|
+
function extendPrototype(sources, destination) {
|
|
3
|
+
var i;
|
|
4
|
+
var len = sources.length;
|
|
5
|
+
var sourcePrototype;
|
|
6
|
+
for (i = 0; i < len; i += 1) {
|
|
7
|
+
sourcePrototype = sources[i].prototype;
|
|
8
|
+
for (var attr in sourcePrototype) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function ProxyElement(type, namespace) {
|
|
14
|
+
this._state = 'init';
|
|
15
|
+
this._isDirty = false;
|
|
16
|
+
this._isProxy = true;
|
|
17
|
+
this._changedStyles = [];
|
|
18
|
+
this._changedAttributes = [];
|
|
19
|
+
this._changedElements = [];
|
|
20
|
+
this._textContent = null;
|
|
21
|
+
this.type = type;
|
|
22
|
+
this.namespace = namespace;
|
|
23
|
+
this.children = [];
|
|
24
|
+
localIdCounter += 1;
|
|
25
|
+
this.attributes = {
|
|
26
|
+
id: 'l_d_' + localIdCounter,
|
|
27
|
+
};
|
|
28
|
+
this.style = new Style(this);
|
|
29
|
+
}
|
|
30
|
+
ProxyElement.prototype = {
|
|
31
|
+
appendChild: function (_child) {
|
|
32
|
+
_child.parentNode = this;
|
|
33
|
+
this.children.push(_child);
|
|
34
|
+
this._isDirty = true;
|
|
35
|
+
this._changedElements.push([_child, this.attributes.id]);
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
insertBefore: function (_newElement, _nextElement) {
|
|
39
|
+
var children = this.children;
|
|
40
|
+
for (var i = 0; i < children.length; i += 1) {
|
|
41
|
+
if (children[i] === _nextElement) {
|
|
42
|
+
children.splice(i, 0, _newElement);
|
|
43
|
+
this._isDirty = true;
|
|
44
|
+
this._changedElements.push([_newElement, this.attributes.id, _nextElement.attributes.id]);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
children.push(_nextElement);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
setAttribute: function (_attribute, _value) {
|
|
52
|
+
this.attributes[_attribute] = _value;
|
|
53
|
+
if (!this._isDirty) {
|
|
54
|
+
this._isDirty = true;
|
|
55
|
+
}
|
|
56
|
+
this._changedAttributes.push(_attribute);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
serialize: function () {
|
|
60
|
+
return {
|
|
61
|
+
type: this.type,
|
|
62
|
+
namespace: this.namespace,
|
|
63
|
+
style: this.style.serialize(),
|
|
64
|
+
attributes: this.attributes,
|
|
65
|
+
children: this.children.map(function (child) { return child.serialize(); }),
|
|
66
|
+
textContent: this._textContent,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line class-methods-use-this
|
|
71
|
+
addEventListener: function (_, _callback) {
|
|
72
|
+
setTimeout(_callback, 1);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
setAttributeNS: function (_, _attribute, _value) {
|
|
76
|
+
this.attributes[_attribute] = _value;
|
|
77
|
+
if (!this._isDirty) {
|
|
78
|
+
this._isDirty = true;
|
|
79
|
+
}
|
|
80
|
+
this._changedAttributes.push(_attribute);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
Object.defineProperty(ProxyElement.prototype, 'textContent', {
|
|
86
|
+
set: function (_value) {
|
|
87
|
+
this._isDirty = true;
|
|
88
|
+
this._textContent = _value;
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
var localIdCounter = 0;
|
|
93
|
+
var animations = {};
|
|
94
|
+
|
|
95
|
+
var styleProperties = ['width', 'height', 'display', 'transform', 'opacity', 'contentVisibility', 'mix-blend-mode'];
|
|
96
|
+
|
|
97
|
+
function convertArguments(args) {
|
|
98
|
+
var arr = [];
|
|
99
|
+
var i;
|
|
100
|
+
var len = args.length;
|
|
101
|
+
for (i = 0; i < len; i += 1) {
|
|
102
|
+
arr.push(args[i]);
|
|
103
|
+
}
|
|
104
|
+
return arr;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function Style(element) {
|
|
108
|
+
this.element = element;
|
|
109
|
+
}
|
|
110
|
+
Style.prototype = {
|
|
111
|
+
serialize: function () {
|
|
112
|
+
var obj = {};
|
|
113
|
+
for (var i = 0; i < styleProperties.length; i += 1) {
|
|
114
|
+
var propertyKey = styleProperties[i];
|
|
115
|
+
var keyName = '_' + propertyKey;
|
|
116
|
+
if (keyName in this) {
|
|
117
|
+
obj[propertyKey] = this[keyName];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return obj;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
styleProperties.forEach(function (propertyKey) {
|
|
124
|
+
Object.defineProperty(Style.prototype, propertyKey, {
|
|
125
|
+
set: function (value) {
|
|
126
|
+
if (!this.element._isDirty) {
|
|
127
|
+
this.element._isDirty = true;
|
|
128
|
+
}
|
|
129
|
+
this.element._changedStyles.push(propertyKey);
|
|
130
|
+
var keyName = '_' + propertyKey;
|
|
131
|
+
this[keyName] = value;
|
|
132
|
+
},
|
|
133
|
+
get: function () {
|
|
134
|
+
var keyName = '_' + propertyKey;
|
|
135
|
+
return this[keyName];
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
function CanvasContext(element) {
|
|
141
|
+
this.element = element;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
CanvasContext.prototype = {
|
|
145
|
+
createRadialGradient: function () {
|
|
146
|
+
function addColorStop() {
|
|
147
|
+
instruction.stops.push(convertArguments(arguments));
|
|
148
|
+
}
|
|
149
|
+
var instruction = {
|
|
150
|
+
t: 'rGradient',
|
|
151
|
+
a: convertArguments(arguments),
|
|
152
|
+
stops: [],
|
|
153
|
+
};
|
|
154
|
+
this.element.instructions.push(instruction);
|
|
155
|
+
return {
|
|
156
|
+
addColorStop: addColorStop,
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
createLinearGradient: function () {
|
|
161
|
+
function addColorStop() {
|
|
162
|
+
instruction.stops.push(convertArguments(arguments));
|
|
163
|
+
}
|
|
164
|
+
var instruction = {
|
|
165
|
+
t: 'lGradient',
|
|
166
|
+
a: convertArguments(arguments),
|
|
167
|
+
stops: [],
|
|
168
|
+
};
|
|
169
|
+
this.element.instructions.push(instruction);
|
|
170
|
+
return {
|
|
171
|
+
addColorStop: addColorStop,
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
Object.defineProperties(CanvasContext.prototype, {
|
|
178
|
+
canvas: {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function () {
|
|
181
|
+
return this.element;
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
var canvasContextMethods = [
|
|
187
|
+
'fillRect',
|
|
188
|
+
'setTransform',
|
|
189
|
+
'drawImage',
|
|
190
|
+
'beginPath',
|
|
191
|
+
'moveTo',
|
|
192
|
+
'save',
|
|
193
|
+
'restore',
|
|
194
|
+
'fillText',
|
|
195
|
+
'setLineDash',
|
|
196
|
+
'clearRect',
|
|
197
|
+
'clip',
|
|
198
|
+
'rect',
|
|
199
|
+
'stroke',
|
|
200
|
+
'fill',
|
|
201
|
+
'closePath',
|
|
202
|
+
'bezierCurveTo',
|
|
203
|
+
'lineTo',
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
canvasContextMethods.forEach(function (method) {
|
|
207
|
+
CanvasContext.prototype[method] = function () {
|
|
208
|
+
this.element.instructions.push({
|
|
209
|
+
t: method,
|
|
210
|
+
a: convertArguments(arguments),
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
var canvasContextProperties = [
|
|
216
|
+
'globalAlpha',
|
|
217
|
+
'strokeStyle',
|
|
218
|
+
'fillStyle',
|
|
219
|
+
'lineCap',
|
|
220
|
+
'lineJoin',
|
|
221
|
+
'lineWidth',
|
|
222
|
+
'miterLimit',
|
|
223
|
+
'lineDashOffset',
|
|
224
|
+
'globalCompositeOperation',
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
canvasContextProperties.forEach(function (property) {
|
|
228
|
+
Object.defineProperty(CanvasContext.prototype, property,
|
|
229
|
+
{
|
|
230
|
+
set: function (_value) {
|
|
231
|
+
this.element.instructions.push({
|
|
232
|
+
t: property,
|
|
233
|
+
a: _value,
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
function CanvasElement(type, namespace) {
|
|
240
|
+
ProxyElement.call(this, type, namespace);
|
|
241
|
+
this.instructions = [];
|
|
242
|
+
this.width = 0;
|
|
243
|
+
this.height = 0;
|
|
244
|
+
this.context = new CanvasContext(this);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
CanvasElement.prototype = {
|
|
248
|
+
|
|
249
|
+
getContext: function () {
|
|
250
|
+
return this.context;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
resetInstructions: function () {
|
|
254
|
+
this.instructions.length = 0;
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
extendPrototype([ProxyElement], CanvasElement);
|
|
258
|
+
|
|
259
|
+
function createElement(namespace, type) {
|
|
260
|
+
if (type === 'canvas') {
|
|
261
|
+
return new CanvasElement(type, namespace);
|
|
262
|
+
}
|
|
263
|
+
return new ProxyElement(type, namespace);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
var window = self; // eslint-disable-line no-redeclare, no-unused-vars
|
|
267
|
+
|
|
268
|
+
var document = { // eslint-disable-line no-redeclare
|
|
269
|
+
createElementNS: function (namespace, type) {
|
|
270
|
+
return createElement(namespace, type);
|
|
271
|
+
},
|
|
272
|
+
createElement: function (type) {
|
|
273
|
+
return createElement('', type);
|
|
274
|
+
},
|
|
275
|
+
getElementsByTagName: function () {
|
|
276
|
+
return [];
|
|
277
|
+
},
|
|
278
|
+
body: createElement('', 'body'),
|
|
279
|
+
_isProxy: true,
|
|
280
|
+
};
|
|
281
|
+
/* eslint-enable */
|
|
282
|
+
var lottieInternal = (function () {
|
|
283
|
+
'use strict';
|
|
284
|
+
|
|
285
|
+
/* <%= contents %> */
|
|
286
|
+
|
|
287
|
+
function addElementToList(element, list) {
|
|
288
|
+
list.push(element);
|
|
289
|
+
element._isDirty = false;
|
|
290
|
+
element._changedStyles.length = 0;
|
|
291
|
+
element._changedAttributes.length = 0;
|
|
292
|
+
element._changedElements.length = 0;
|
|
293
|
+
element._textContent = null;
|
|
294
|
+
element.children.forEach(function (child) {
|
|
295
|
+
addElementToList(child, list);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function addChangedAttributes(element) {
|
|
300
|
+
var changedAttributes = element._changedAttributes;
|
|
301
|
+
var attributes = [];
|
|
302
|
+
var attribute;
|
|
303
|
+
for (var i = 0; i < changedAttributes.length; i += 1) {
|
|
304
|
+
attribute = changedAttributes[i];
|
|
305
|
+
attributes.push([attribute, element.attributes[attribute]]);
|
|
306
|
+
}
|
|
307
|
+
return attributes;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function addChangedStyles(element) {
|
|
311
|
+
var changedStyles = element._changedStyles;
|
|
312
|
+
var styles = [];
|
|
313
|
+
var style;
|
|
314
|
+
for (var i = 0; i < changedStyles.length; i += 1) {
|
|
315
|
+
style = changedStyles[i];
|
|
316
|
+
styles.push([style, element.style[style]]);
|
|
317
|
+
}
|
|
318
|
+
return styles;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function addChangedElements(element, elements) {
|
|
322
|
+
var changedElements = element._changedElements;
|
|
323
|
+
var elementsList = [];
|
|
324
|
+
var elementData;
|
|
325
|
+
for (var i = 0; i < changedElements.length; i += 1) {
|
|
326
|
+
elementData = changedElements[i];
|
|
327
|
+
elementsList.push([elementData[0].serialize(), elementData[1], elementData[2]]);
|
|
328
|
+
addElementToList(elementData[0], elements);
|
|
329
|
+
}
|
|
330
|
+
return elementsList;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function loadAnimation(payload) {
|
|
334
|
+
var params = payload.params;
|
|
335
|
+
var wrapper;
|
|
336
|
+
var animation;
|
|
337
|
+
var elements = [];
|
|
338
|
+
var canvas;
|
|
339
|
+
if (params.renderer === 'svg') {
|
|
340
|
+
wrapper = document.createElement('div');
|
|
341
|
+
params.container = wrapper;
|
|
342
|
+
} else {
|
|
343
|
+
canvas = params.rendererSettings.canvas;
|
|
344
|
+
if (!canvas) {
|
|
345
|
+
canvas = document.createElement('canvas');
|
|
346
|
+
canvas.width = params.animationData.w;
|
|
347
|
+
canvas.height = params.animationData.h;
|
|
348
|
+
}
|
|
349
|
+
var ctx = canvas.getContext('2d');
|
|
350
|
+
params.rendererSettings.context = ctx;
|
|
351
|
+
}
|
|
352
|
+
animation = lottie.loadAnimation(params);
|
|
353
|
+
animation.addEventListener('error', function (error) {
|
|
354
|
+
console.log(error); // eslint-disable-line
|
|
355
|
+
});
|
|
356
|
+
animation.onError = function (error) {
|
|
357
|
+
console.log('ERRORO', error); // eslint-disable-line
|
|
358
|
+
};
|
|
359
|
+
animation.addEventListener('_play', function () {
|
|
360
|
+
self.postMessage({
|
|
361
|
+
type: 'playing',
|
|
362
|
+
payload: {
|
|
363
|
+
id: payload.id,
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
animation.addEventListener('_pause', function () {
|
|
368
|
+
self.postMessage({
|
|
369
|
+
type: 'paused',
|
|
370
|
+
payload: {
|
|
371
|
+
id: payload.id,
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
if (params.renderer === 'svg') {
|
|
376
|
+
animation.addEventListener('DOMLoaded', function () {
|
|
377
|
+
var serialized = wrapper.serialize();
|
|
378
|
+
addElementToList(wrapper, elements);
|
|
379
|
+
self.postMessage({
|
|
380
|
+
type: 'SVGloaded',
|
|
381
|
+
payload: {
|
|
382
|
+
id: payload.id,
|
|
383
|
+
tree: serialized.children[0],
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
animation.addEventListener('drawnFrame', function (event) {
|
|
388
|
+
var changedElements = [];
|
|
389
|
+
var element;
|
|
390
|
+
for (var i = 0; i < elements.length; i += 1) {
|
|
391
|
+
element = elements[i];
|
|
392
|
+
if (element._isDirty) {
|
|
393
|
+
var changedElement = {
|
|
394
|
+
id: element.attributes.id,
|
|
395
|
+
styles: addChangedStyles(element),
|
|
396
|
+
attributes: addChangedAttributes(element),
|
|
397
|
+
elements: addChangedElements(element, elements),
|
|
398
|
+
textContent: element._textContent || undefined,
|
|
399
|
+
};
|
|
400
|
+
changedElements.push(changedElement);
|
|
401
|
+
element._isDirty = false;
|
|
402
|
+
element._changedAttributes.length = 0;
|
|
403
|
+
element._changedStyles.length = 0;
|
|
404
|
+
element._changedElements.length = 0;
|
|
405
|
+
element._textContent = null;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
self.postMessage({
|
|
409
|
+
type: 'SVGupdated',
|
|
410
|
+
payload: {
|
|
411
|
+
elements: changedElements,
|
|
412
|
+
id: payload.id,
|
|
413
|
+
currentTime: event.currentTime,
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
} else if (canvas._isProxy) {
|
|
418
|
+
animation.addEventListener('drawnFrame', function (event) {
|
|
419
|
+
self.postMessage({
|
|
420
|
+
type: 'CanvasUpdated',
|
|
421
|
+
payload: {
|
|
422
|
+
instructions: canvas.instructions,
|
|
423
|
+
id: payload.id,
|
|
424
|
+
currentTime: event.currentTime,
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
canvas.resetInstructions();
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
animation.addEventListener('DOMLoaded', function () {
|
|
431
|
+
self.postMessage({
|
|
432
|
+
type: 'DOMLoaded',
|
|
433
|
+
payload: {
|
|
434
|
+
id: payload.id,
|
|
435
|
+
totalFrames: animation.totalFrames,
|
|
436
|
+
frameRate: animation.frameRate,
|
|
437
|
+
firstFrame: animation.firstFrame,
|
|
438
|
+
currentFrame: animation.currentFrame,
|
|
439
|
+
playDirection: animation.playDirection,
|
|
440
|
+
isSubframeEnabled: animation.isSubframeEnabled,
|
|
441
|
+
currentRawFrame: animation.currentRawFrame,
|
|
442
|
+
timeCompleted: animation.timeCompleted,
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
animations[payload.id] = {
|
|
447
|
+
animation: animation,
|
|
448
|
+
events: {},
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
loadAnimation: loadAnimation,
|
|
454
|
+
};
|
|
455
|
+
}({}));
|
|
456
|
+
onmessage = function (evt) {
|
|
457
|
+
var data = evt.data;
|
|
458
|
+
var type = data.type;
|
|
459
|
+
var payload = data.payload;
|
|
460
|
+
if (type === 'load') {
|
|
461
|
+
lottieInternal.loadAnimation(payload);
|
|
462
|
+
} else if (type === 'pause') {
|
|
463
|
+
if (animations[payload.id]) {
|
|
464
|
+
animations[payload.id].animation.pause();
|
|
465
|
+
}
|
|
466
|
+
} else if (type === 'play') {
|
|
467
|
+
if (animations[payload.id]) {
|
|
468
|
+
animations[payload.id].animation.play();
|
|
469
|
+
}
|
|
470
|
+
} else if (type === 'stop') {
|
|
471
|
+
if (animations[payload.id]) {
|
|
472
|
+
animations[payload.id].animation.stop();
|
|
473
|
+
}
|
|
474
|
+
} else if (type === 'setSpeed') {
|
|
475
|
+
if (animations[payload.id]) {
|
|
476
|
+
animations[payload.id].animation.setSpeed(payload.value);
|
|
477
|
+
}
|
|
478
|
+
} else if (type === 'setDirection') {
|
|
479
|
+
if (animations[payload.id]) {
|
|
480
|
+
animations[payload.id].animation.setDirection(payload.value);
|
|
481
|
+
}
|
|
482
|
+
} else if (type === 'setLoop') {
|
|
483
|
+
if (animations[payload.id]) {
|
|
484
|
+
animations[payload.id].animation.setLoop(payload.value);
|
|
485
|
+
}
|
|
486
|
+
} else if (type === 'goToAndPlay') {
|
|
487
|
+
if (animations[payload.id]) {
|
|
488
|
+
animations[payload.id].animation.goToAndPlay(payload.value, payload.isFrame);
|
|
489
|
+
}
|
|
490
|
+
} else if (type === 'goToAndStop') {
|
|
491
|
+
if (animations[payload.id]) {
|
|
492
|
+
animations[payload.id].animation.goToAndStop(payload.value, payload.isFrame);
|
|
493
|
+
}
|
|
494
|
+
} else if (type === 'setSubframe') {
|
|
495
|
+
if (animations[payload.id]) {
|
|
496
|
+
animations[payload.id].animation.setSubframe(payload.value);
|
|
497
|
+
}
|
|
498
|
+
} else if (type === 'addEventListener') {
|
|
499
|
+
if (animations[payload.id]) {
|
|
500
|
+
var eventCallback = function () {
|
|
501
|
+
self.postMessage({
|
|
502
|
+
type: 'event',
|
|
503
|
+
payload: {
|
|
504
|
+
id: payload.id,
|
|
505
|
+
callbackId: payload.callbackId,
|
|
506
|
+
argument: arguments[0],
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
animations[payload.id].events[payload.callbackId] = {
|
|
511
|
+
callback: eventCallback,
|
|
512
|
+
};
|
|
513
|
+
animations[payload.id].animation.addEventListener(payload.eventName, eventCallback);
|
|
514
|
+
}
|
|
515
|
+
} else if (type === 'removeEventListener') {
|
|
516
|
+
if (animations[payload.id]) {
|
|
517
|
+
var callback = animations[payload.id].events[payload.callbackId];
|
|
518
|
+
animations[payload.id].animation.removeEventListener(payload.eventName, callback);
|
|
519
|
+
}
|
|
520
|
+
} else if (type === 'destroy') {
|
|
521
|
+
if (animations[payload.id]) {
|
|
522
|
+
animations[payload.id].animation.destroy();
|
|
523
|
+
animations[payload.id] = null;
|
|
524
|
+
}
|
|
525
|
+
} else if (type === 'resize') {
|
|
526
|
+
if (animations[payload.id]) {
|
|
527
|
+
animations[payload.id].animation.resize(payload.width, payload.height);
|
|
528
|
+
}
|
|
529
|
+
} else if (type === 'playSegments') {
|
|
530
|
+
if (animations[payload.id]) {
|
|
531
|
+
animations[payload.id].animation.playSegments(payload.arr, payload.forceFlag);
|
|
532
|
+
}
|
|
533
|
+
} else if (type === 'resetSegments') {
|
|
534
|
+
if (animations[payload.id]) {
|
|
535
|
+
animations[payload.id].animation.resetSegments(payload.forceFlag);
|
|
536
|
+
}
|
|
537
|
+
} else if (type === 'updateDocumentData') {
|
|
538
|
+
animations[payload.id].animation.updateDocumentData(payload.path, payload.documentData, payload.index);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function createWorker(fn) {
|
|
544
|
+
var blob = new Blob(['(' + fn.toString() + '())'], { type: 'text/javascript' });
|
|
545
|
+
var url = URL.createObjectURL(blob);
|
|
546
|
+
return new Worker(url);
|
|
547
|
+
}
|
|
548
|
+
// eslint-disable-next-line no-unused-vars
|
|
549
|
+
var lottie = (function () {
|
|
550
|
+
'use strict';
|
|
551
|
+
|
|
552
|
+
var workerInstance = createWorker(workerContent);
|
|
553
|
+
var animationIdCounter = 0;
|
|
554
|
+
var eventsIdCounter = 0;
|
|
555
|
+
var animations = {};
|
|
556
|
+
var defaultSettings = {
|
|
557
|
+
rendererSettings: {},
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
function createTree(data, container, map, afterElement) {
|
|
561
|
+
var elem;
|
|
562
|
+
if (data.type === 'div') {
|
|
563
|
+
elem = document.createElement('div');
|
|
564
|
+
} else {
|
|
565
|
+
elem = document.createElementNS(data.namespace, data.type);
|
|
566
|
+
}
|
|
567
|
+
if (data.textContent) {
|
|
568
|
+
elem.textContent = data.textContent;
|
|
569
|
+
}
|
|
570
|
+
for (var attr in data.attributes) {
|
|
571
|
+
if (Object.prototype.hasOwnProperty.call(data.attributes, attr)) {
|
|
572
|
+
if (attr === 'href') {
|
|
573
|
+
elem.setAttributeNS('http://www.w3.org/1999/xlink', attr, data.attributes[attr]);
|
|
574
|
+
} else {
|
|
575
|
+
elem.setAttribute(attr, data.attributes[attr]);
|
|
576
|
+
}
|
|
577
|
+
if (attr === 'id') {
|
|
578
|
+
map[data.attributes[attr]] = elem;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
for (var style in data.style) {
|
|
583
|
+
if (Object.prototype.hasOwnProperty.call(data.style, style)) {
|
|
584
|
+
elem.style[style] = data.style[style];
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
data.children.forEach(function (element) {
|
|
588
|
+
createTree(element, elem, map);
|
|
589
|
+
});
|
|
590
|
+
if (!afterElement) {
|
|
591
|
+
container.appendChild(elem);
|
|
592
|
+
} else {
|
|
593
|
+
container.insertBefore(elem, afterElement);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
var handleAnimationLoaded = (function () {
|
|
598
|
+
return function (payload) {
|
|
599
|
+
var animation = animations[payload.id];
|
|
600
|
+
animation._loaded = true;
|
|
601
|
+
// if callbacks have been added before the animation has loaded
|
|
602
|
+
animation.pendingCallbacks.forEach(function (callbackData) {
|
|
603
|
+
animation.animInstance.addEventListener(callbackData.eventName, callbackData.callback);
|
|
604
|
+
if (callbackData.eventName === 'DOMLoaded') {
|
|
605
|
+
callbackData.callback();
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
animation.animInstance.totalFrames = payload.totalFrames;
|
|
609
|
+
animation.animInstance.frameRate = payload.frameRate;
|
|
610
|
+
animation.animInstance.firstFrame = payload.firstFrame;
|
|
611
|
+
animation.animInstance.playDirection = payload.playDirection;
|
|
612
|
+
animation.animInstance.currentFrame = payload.isSubframeEnabled ? payload.currentRawFrame : ~~payload.currentRawFrame; // eslint-disable-line no-bitwise
|
|
613
|
+
|
|
614
|
+
if (payload.timeCompleted !== payload.totalFrames && payload.currentFrame > payload.timeCompleted) {
|
|
615
|
+
animation.animInstance.currentFrame = payload.timeCompleted;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
}());
|
|
619
|
+
|
|
620
|
+
var handleSVGLoaded = (function () {
|
|
621
|
+
return function (payload) {
|
|
622
|
+
var animation = animations[payload.id];
|
|
623
|
+
var container = animation.container;
|
|
624
|
+
var elements = animation.elements;
|
|
625
|
+
createTree(payload.tree, container, elements);
|
|
626
|
+
};
|
|
627
|
+
}());
|
|
628
|
+
|
|
629
|
+
function addNewElements(newElements, elements) {
|
|
630
|
+
var element;
|
|
631
|
+
for (var i = 0; i < newElements.length; i += 1) {
|
|
632
|
+
element = newElements[i];
|
|
633
|
+
var parent = elements[element[1]];
|
|
634
|
+
if (parent) {
|
|
635
|
+
var sibling;
|
|
636
|
+
if (element[2]) {
|
|
637
|
+
sibling = elements[element[2]];
|
|
638
|
+
}
|
|
639
|
+
createTree(element[0], parent, elements, sibling);
|
|
640
|
+
newElements.splice(i, 1);
|
|
641
|
+
i -= 1;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function updateElementStyles(element, styles) {
|
|
647
|
+
var style;
|
|
648
|
+
for (var i = 0; i < styles.length; i += 1) {
|
|
649
|
+
style = styles[i];
|
|
650
|
+
element.style[style[0]] = style[1];
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function updateElementAttributes(element, attributes) {
|
|
655
|
+
var attribute;
|
|
656
|
+
for (var i = 0; i < attributes.length; i += 1) {
|
|
657
|
+
attribute = attributes[i];
|
|
658
|
+
element.setAttribute(attribute[0], attribute[1]);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function updateTextContent(element, text) {
|
|
663
|
+
if (text) {
|
|
664
|
+
element.textContent = text;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function handleAnimationUpdate(payload) {
|
|
669
|
+
var changedElements = payload.elements;
|
|
670
|
+
var animation = animations[payload.id];
|
|
671
|
+
if (animation) {
|
|
672
|
+
var elements = animation.elements;
|
|
673
|
+
var elementData;
|
|
674
|
+
for (var i = 0; i < changedElements.length; i += 1) {
|
|
675
|
+
elementData = changedElements[i];
|
|
676
|
+
var element = elements[elementData.id];
|
|
677
|
+
addNewElements(elementData.elements, elements);
|
|
678
|
+
updateElementStyles(element, elementData.styles);
|
|
679
|
+
updateElementAttributes(element, elementData.attributes);
|
|
680
|
+
updateTextContent(element, elementData.textContent);
|
|
681
|
+
}
|
|
682
|
+
animation.animInstance.currentFrame = payload.currentTime;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function createInstructionsHandler(canvas) {
|
|
687
|
+
var ctx = canvas.getContext('2d');
|
|
688
|
+
var map = {
|
|
689
|
+
beginPath: ctx.beginPath,
|
|
690
|
+
closePath: ctx.closePath,
|
|
691
|
+
rect: ctx.rect,
|
|
692
|
+
clip: ctx.clip,
|
|
693
|
+
clearRect: ctx.clearRect,
|
|
694
|
+
setTransform: ctx.setTransform,
|
|
695
|
+
moveTo: ctx.moveTo,
|
|
696
|
+
bezierCurveTo: ctx.bezierCurveTo,
|
|
697
|
+
lineTo: ctx.lineTo,
|
|
698
|
+
fill: ctx.fill,
|
|
699
|
+
save: ctx.save,
|
|
700
|
+
restore: ctx.restore,
|
|
701
|
+
};
|
|
702
|
+
return function (instructions) {
|
|
703
|
+
for (var i = 0; i < instructions.length; i += 1) {
|
|
704
|
+
var instruction = instructions[i];
|
|
705
|
+
var fn = map[instruction.t];
|
|
706
|
+
if (fn) {
|
|
707
|
+
fn.apply(ctx, instruction.a);
|
|
708
|
+
} else {
|
|
709
|
+
ctx[instruction.t] = instruction.a;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function handleCanvasAnimationUpdate(payload) {
|
|
716
|
+
var animation = animations[payload.id];
|
|
717
|
+
animation.instructionsHandler(payload.instructions);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function handleEvent(payload) {
|
|
721
|
+
var animation = animations[payload.id];
|
|
722
|
+
if (animation) {
|
|
723
|
+
var callbacks = animation.callbacks;
|
|
724
|
+
if (callbacks[payload.callbackId]) {
|
|
725
|
+
callbacks[payload.callbackId].callback(payload.argument);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function handlePlaying(payload) {
|
|
731
|
+
var animation = animations[payload.id];
|
|
732
|
+
if (animation) {
|
|
733
|
+
animation.animInstance.isPaused = false;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function handlePaused(payload) {
|
|
738
|
+
var animation = animations[payload.id];
|
|
739
|
+
if (animation) {
|
|
740
|
+
animation.animInstance.isPaused = true;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
var messageHandlers = {
|
|
745
|
+
DOMLoaded: handleAnimationLoaded,
|
|
746
|
+
SVGloaded: handleSVGLoaded,
|
|
747
|
+
SVGupdated: handleAnimationUpdate,
|
|
748
|
+
CanvasUpdated: handleCanvasAnimationUpdate,
|
|
749
|
+
event: handleEvent,
|
|
750
|
+
playing: handlePlaying,
|
|
751
|
+
paused: handlePaused,
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
workerInstance.onmessage = function (event) {
|
|
755
|
+
if (messageHandlers[event.data.type]) {
|
|
756
|
+
messageHandlers[event.data.type](event.data.payload);
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
function resolveAnimationData(params) {
|
|
761
|
+
return new Promise(function (resolve, reject) {
|
|
762
|
+
var paramsCopy = Object.assign({}, defaultSettings, params);
|
|
763
|
+
if (paramsCopy.animType && !paramsCopy.renderer) {
|
|
764
|
+
paramsCopy.renderer = paramsCopy.animType;
|
|
765
|
+
}
|
|
766
|
+
if (paramsCopy.wrapper) {
|
|
767
|
+
if (!paramsCopy.container) {
|
|
768
|
+
paramsCopy.container = paramsCopy.wrapper;
|
|
769
|
+
}
|
|
770
|
+
delete paramsCopy.wrapper;
|
|
771
|
+
}
|
|
772
|
+
if (paramsCopy.animationData) {
|
|
773
|
+
resolve(paramsCopy);
|
|
774
|
+
} else if (paramsCopy.path) {
|
|
775
|
+
fetch(paramsCopy.path)
|
|
776
|
+
.then(function (response) {
|
|
777
|
+
return response.json();
|
|
778
|
+
})
|
|
779
|
+
.then(function (animationData) {
|
|
780
|
+
paramsCopy.animationData = animationData;
|
|
781
|
+
delete paramsCopy.path;
|
|
782
|
+
resolve(paramsCopy);
|
|
783
|
+
});
|
|
784
|
+
} else {
|
|
785
|
+
reject();
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
function loadAnimation(params) {
|
|
791
|
+
animationIdCounter += 1;
|
|
792
|
+
var animationId = 'lottie_animationId_' + animationIdCounter;
|
|
793
|
+
var animation = {
|
|
794
|
+
elements: {},
|
|
795
|
+
callbacks: {},
|
|
796
|
+
pendingCallbacks: [],
|
|
797
|
+
status: 'init',
|
|
798
|
+
};
|
|
799
|
+
var animInstance = {
|
|
800
|
+
id: animationId,
|
|
801
|
+
isPaused: true,
|
|
802
|
+
pause: function () {
|
|
803
|
+
workerInstance.postMessage({
|
|
804
|
+
type: 'pause',
|
|
805
|
+
payload: {
|
|
806
|
+
id: animationId,
|
|
807
|
+
},
|
|
808
|
+
});
|
|
809
|
+
},
|
|
810
|
+
play: function () {
|
|
811
|
+
workerInstance.postMessage({
|
|
812
|
+
type: 'play',
|
|
813
|
+
payload: {
|
|
814
|
+
id: animationId,
|
|
815
|
+
},
|
|
816
|
+
});
|
|
817
|
+
},
|
|
818
|
+
stop: function () {
|
|
819
|
+
workerInstance.postMessage({
|
|
820
|
+
type: 'stop',
|
|
821
|
+
payload: {
|
|
822
|
+
id: animationId,
|
|
823
|
+
},
|
|
824
|
+
});
|
|
825
|
+
},
|
|
826
|
+
setSpeed: function (value) {
|
|
827
|
+
workerInstance.postMessage({
|
|
828
|
+
type: 'setSpeed',
|
|
829
|
+
payload: {
|
|
830
|
+
id: animationId,
|
|
831
|
+
value: value,
|
|
832
|
+
},
|
|
833
|
+
});
|
|
834
|
+
},
|
|
835
|
+
setDirection: function (value) {
|
|
836
|
+
workerInstance.postMessage({
|
|
837
|
+
type: 'setDirection',
|
|
838
|
+
payload: {
|
|
839
|
+
id: animationId,
|
|
840
|
+
value: value,
|
|
841
|
+
},
|
|
842
|
+
});
|
|
843
|
+
},
|
|
844
|
+
setLoop: function (value) {
|
|
845
|
+
workerInstance.postMessage({
|
|
846
|
+
type: 'setLoop',
|
|
847
|
+
payload: {
|
|
848
|
+
id: animationId,
|
|
849
|
+
value: value,
|
|
850
|
+
},
|
|
851
|
+
});
|
|
852
|
+
},
|
|
853
|
+
goToAndStop: function (value, isFrame) {
|
|
854
|
+
workerInstance.postMessage({
|
|
855
|
+
type: 'goToAndStop',
|
|
856
|
+
payload: {
|
|
857
|
+
id: animationId,
|
|
858
|
+
value: value,
|
|
859
|
+
isFrame: isFrame,
|
|
860
|
+
},
|
|
861
|
+
});
|
|
862
|
+
},
|
|
863
|
+
goToAndPlay: function (value, isFrame) {
|
|
864
|
+
workerInstance.postMessage({
|
|
865
|
+
type: 'goToAndPlay',
|
|
866
|
+
payload: {
|
|
867
|
+
id: animationId,
|
|
868
|
+
value: value,
|
|
869
|
+
isFrame: isFrame,
|
|
870
|
+
},
|
|
871
|
+
});
|
|
872
|
+
},
|
|
873
|
+
playSegments: function (arr, forceFlag) {
|
|
874
|
+
workerInstance.postMessage({
|
|
875
|
+
type: 'playSegments',
|
|
876
|
+
payload: {
|
|
877
|
+
id: animationId,
|
|
878
|
+
arr: arr,
|
|
879
|
+
forceFlag: forceFlag,
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
},
|
|
883
|
+
setSubframe: function (value) {
|
|
884
|
+
workerInstance.postMessage({
|
|
885
|
+
type: 'setSubframe',
|
|
886
|
+
payload: {
|
|
887
|
+
id: animationId,
|
|
888
|
+
value: value,
|
|
889
|
+
},
|
|
890
|
+
});
|
|
891
|
+
},
|
|
892
|
+
addEventListener: function (eventName, callback) {
|
|
893
|
+
if (!animation._loaded) {
|
|
894
|
+
animation.pendingCallbacks.push({
|
|
895
|
+
eventName: eventName,
|
|
896
|
+
callback: callback,
|
|
897
|
+
});
|
|
898
|
+
} else {
|
|
899
|
+
eventsIdCounter += 1;
|
|
900
|
+
var callbackId = 'callback_' + eventsIdCounter;
|
|
901
|
+
animation.callbacks[callbackId] = {
|
|
902
|
+
eventName: eventName,
|
|
903
|
+
callback: callback,
|
|
904
|
+
};
|
|
905
|
+
workerInstance.postMessage({
|
|
906
|
+
type: 'addEventListener',
|
|
907
|
+
payload: {
|
|
908
|
+
id: animationId,
|
|
909
|
+
callbackId: callbackId,
|
|
910
|
+
eventName: eventName,
|
|
911
|
+
},
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
removeEventListener: function (eventName, callback) {
|
|
916
|
+
Object.keys(animation.callbacks)
|
|
917
|
+
.forEach(function (key) {
|
|
918
|
+
if (animation.callbacks[key].eventName === eventName
|
|
919
|
+
&& (animation.callbacks[key].callback === callback || !callback)) {
|
|
920
|
+
delete animation.callbacks[key];
|
|
921
|
+
workerInstance.postMessage({
|
|
922
|
+
type: 'removeEventListener',
|
|
923
|
+
payload: {
|
|
924
|
+
id: animationId,
|
|
925
|
+
callbackId: key,
|
|
926
|
+
eventName: eventName,
|
|
927
|
+
},
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
},
|
|
932
|
+
destroy: function () {
|
|
933
|
+
if (animation.status === 'init') {
|
|
934
|
+
animation.status = 'destroyable';
|
|
935
|
+
} else {
|
|
936
|
+
animation.status = 'destroyed';
|
|
937
|
+
animations[animationId] = null;
|
|
938
|
+
if (animation.container) {
|
|
939
|
+
animation.container.innerHTML = '';
|
|
940
|
+
}
|
|
941
|
+
workerInstance.postMessage({
|
|
942
|
+
type: 'destroy',
|
|
943
|
+
payload: {
|
|
944
|
+
id: animationId,
|
|
945
|
+
},
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
resize: function (width, height) {
|
|
950
|
+
var devicePixelRatio = window.devicePixelRatio || 1;
|
|
951
|
+
workerInstance.postMessage({
|
|
952
|
+
type: 'resize',
|
|
953
|
+
payload: {
|
|
954
|
+
id: animationId,
|
|
955
|
+
// Till Worker thread knows nothing about container, we've to pass it here
|
|
956
|
+
width: width || (animation.container ? animation.container.offsetWidth * devicePixelRatio : 0),
|
|
957
|
+
height: height || (animation.container ? animation.container.offsetHeight * devicePixelRatio : 0),
|
|
958
|
+
},
|
|
959
|
+
});
|
|
960
|
+
},
|
|
961
|
+
updateDocumentData: function (path, documentData, index) {
|
|
962
|
+
workerInstance.postMessage({
|
|
963
|
+
type: 'updateDocumentData',
|
|
964
|
+
payload: {
|
|
965
|
+
id: animationId,
|
|
966
|
+
path: path,
|
|
967
|
+
documentData: documentData,
|
|
968
|
+
index: index,
|
|
969
|
+
},
|
|
970
|
+
});
|
|
971
|
+
},
|
|
972
|
+
};
|
|
973
|
+
animation.animInstance = animInstance;
|
|
974
|
+
resolveAnimationData(params)
|
|
975
|
+
.then(function (animationParams) {
|
|
976
|
+
if (animation.status === 'destroyable') {
|
|
977
|
+
animation.animInstance.destroy();
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
animation.status = 'loaded';
|
|
981
|
+
var transferedObjects = [];
|
|
982
|
+
if (animationParams.container) {
|
|
983
|
+
animation.container = animationParams.container;
|
|
984
|
+
delete animationParams.container;
|
|
985
|
+
}
|
|
986
|
+
if (animationParams.renderer === 'canvas') {
|
|
987
|
+
var canvas = animationParams.rendererSettings.canvas;
|
|
988
|
+
|
|
989
|
+
// If no custom canvas was passed
|
|
990
|
+
if (!canvas) {
|
|
991
|
+
var devicePixelRatio = window.devicePixelRatio || 1;
|
|
992
|
+
canvas = document.createElement('canvas');
|
|
993
|
+
animation.container.appendChild(canvas);
|
|
994
|
+
canvas.width = (animation.container ? animation.container.offsetWidth : animationParams.animationData.w) * devicePixelRatio;
|
|
995
|
+
canvas.height = (animation.container ? animation.container.offsetHeight : animationParams.animationData.h) * devicePixelRatio;
|
|
996
|
+
canvas.style.width = '100%';
|
|
997
|
+
canvas.style.height = '100%';
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// Transfer control to offscreen if it's not already
|
|
1001
|
+
var transferCanvas = canvas;
|
|
1002
|
+
if (typeof OffscreenCanvas === 'undefined') {
|
|
1003
|
+
animation.canvas = canvas;
|
|
1004
|
+
animation.instructionsHandler = createInstructionsHandler(canvas);
|
|
1005
|
+
} else {
|
|
1006
|
+
if (!(canvas instanceof OffscreenCanvas)) {
|
|
1007
|
+
transferCanvas = canvas.transferControlToOffscreen();
|
|
1008
|
+
animationParams.rendererSettings.canvas = transferCanvas;
|
|
1009
|
+
}
|
|
1010
|
+
transferedObjects.push(transferCanvas);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
animations[animationId] = animation;
|
|
1014
|
+
workerInstance.postMessage({
|
|
1015
|
+
type: 'load',
|
|
1016
|
+
payload: {
|
|
1017
|
+
params: animationParams,
|
|
1018
|
+
id: animationId,
|
|
1019
|
+
},
|
|
1020
|
+
}, transferedObjects);
|
|
1021
|
+
});
|
|
1022
|
+
return animInstance;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
var lottiejs = {
|
|
1026
|
+
loadAnimation: loadAnimation,
|
|
1027
|
+
};
|
|
1028
|
+
return lottiejs;
|
|
1029
|
+
}());
|