PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.1
Elementor Website Builder – more than just a page builder v4.3.1
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
elementor / assets / js / packages / editor-modal-shell / editor-modal-shell.js

editor-modal-shell.js in Elementor Website Builder – more than just a page builder 4.3.1, at assets/js/packages/editor-modal-shell/editor-modal-shell.js

15,040 lines 566.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(react, _elementor_ui) {
2
3 //#region \0rolldown/runtime.js
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __name = (target, value) => __defProp(target, "name", {
7 value,
8 configurable: true
9 });
10 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11 var __getOwnPropNames = Object.getOwnPropertyNames;
12 var __getProtoOf = Object.getPrototypeOf;
13 var __hasOwnProp = Object.prototype.hasOwnProperty;
14 var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
15 var __exportAll = (all, no_symbols) => {
16 let target = {};
17 for (var name in all) {
18 __defProp(target, name, {
19 get: all[name],
20 enumerable: true
21 });
22 }
23 if (!no_symbols) {
24 __defProp(target, Symbol.toStringTag, { value: "Module" });
25 }
26 return target;
27 };
28 var __copyProps = (to, from, except, desc) => {
29 if (from && typeof from === "object" || typeof from === "function") {
30 for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
31 key = keys[i];
32 if (!__hasOwnProp.call(to, key) && key !== except) {
33 __defProp(to, key, {
34 get: ((k) => from[k]).bind(null, key),
35 enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
36 });
37 }
38 }
39 }
40 return to;
41 };
42 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
43 value: mod,
44 enumerable: true
45 }) : target, mod));
46
47 //#endregion
48 react = __toESM(react);
49
50 //#region packages/packages/libs/editor-modal-shell/src/components/modal-shell.tsx
51 var MODAL_Z_INDEX = 99999;
52 var DEFAULT_WIDTH = 800;
53 var DEFAULT_HEIGHT = 400;
54 var DEFAULT_REVEAL_DURATION_MS = 500;
55 var DEFAULT_REVEAL_DELAY_MS = 0;
56 var ModalShellContext = (0, react.createContext)(null);
57 var useModalShell = () => {
58 const ctx = (0, react.useContext)(ModalShellContext);
59 if (!ctx) throw new Error("useModalShell must be used inside a <ModalShell />");
60 return ctx;
61 };
62 var EXIT_TRANSITION_MS = 225;
63 var prefersReducedMotion = () => typeof window !== "undefined" && Boolean(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches);
64 var ModalShell = ({ children, onClose, revealDuration = DEFAULT_REVEAL_DURATION_MS, revealDelay = DEFAULT_REVEAL_DELAY_MS, container, sx = {}, closeOnEsc = true, closeOnOutsideClick = true, backdrop = true, backdropSx = {}, hideCloseButton = false }) => {
65 const portalTarget = container ?? (typeof document !== "undefined" ? document.body : void 0);
66 const reducedMotion = prefersReducedMotion();
67 const consumerOwnsEnter = revealDuration === 0 || reducedMotion;
68 const [open, setOpen] = (0, react.useState)(true);
69 const startClose = (0, react.useCallback)(() => setOpen(false), []);
70 const contextValue = (0, react.useMemo)(() => ({ close: startClose }), [startClose]);
71 const handleDialogClose = (_event, reason) => {
72 if (reason === "escapeKeyDown" && !closeOnEsc) return;
73 if (reason === "backdropClick" && !closeOnOutsideClick) return;
74 startClose();
75 };
76 const transitionTimeouts = (0, react.useMemo)(() => ({
77 enter: 0,
78 exit: reducedMotion ? 0 : EXIT_TRANSITION_MS
79 }), [reducedMotion]);
80 const animationProps = (0, react.useMemo)(() => consumerOwnsEnter ? {} : {
81 animation: `e-modal-shell-reveal ${revealDuration}ms ease ${revealDelay}ms backwards`,
82 "@keyframes e-modal-shell-reveal": {
83 from: {
84 opacity: 0,
85 transform: "scale(0.95)"
86 },
87 to: {
88 opacity: 1,
89 transform: "scale(1)"
90 }
91 }
92 }, [
93 consumerOwnsEnter,
94 revealDuration,
95 revealDelay
96 ]);
97 return /* @__PURE__ */ react.createElement(_elementor_ui.Dialog, {
98 open,
99 maxWidth: false,
100 onClose: handleDialogClose,
101 container: portalTarget,
102 disableEscapeKeyDown: !closeOnEsc,
103 hideBackdrop: !backdrop,
104 TransitionProps: {
105 onExited: onClose,
106 timeout: transitionTimeouts
107 },
108 slotProps: { backdrop: {
109 transitionDuration: transitionTimeouts,
110 sx: backdropSx
111 } },
112 PaperProps: { sx: {
113 width: DEFAULT_WIDTH,
114 height: DEFAULT_HEIGHT,
115 maxWidth: "100%",
116 overflow: "hidden",
117 ...animationProps,
118 ...sx
119 } },
120 sx: { zIndex: MODAL_Z_INDEX }
121 }, /* @__PURE__ */ react.createElement(ModalShellContext.Provider, { value: contextValue }, /* @__PURE__ */ react.createElement(_elementor_ui.Box, { sx: { display: "contents" } }, children, !hideCloseButton && /* @__PURE__ */ react.createElement(_elementor_ui.CloseButton, {
122 onClick: startClose,
123 sx: {
124 position: "absolute",
125 right: 16,
126 top: 16,
127 zIndex: 3
128 }
129 }))));
130 };
131
132 //#endregion
133 //#region packages/packages/libs/editor-modal-shell/src/components/modal-header.tsx
134 var ModalHeader = ({ title, content }) => {
135 return /* @__PURE__ */ react.createElement(_elementor_ui.Stack, { gap: .75 }, /* @__PURE__ */ react.createElement(_elementor_ui.Typography, {
136 variant: "h4",
137 color: "text.primary"
138 }, title), /* @__PURE__ */ react.createElement(_elementor_ui.Typography, {
139 variant: "subtitle2",
140 color: "text.primary"
141 }, content));
142 };
143
144 //#endregion
145 //#region packages/packages/libs/editor-modal-shell/src/components/modal-footer.tsx
146 var ModalFooter = ({ helpText, link }) => {
147 return /* @__PURE__ */ react.createElement(_elementor_ui.Stack, {
148 direction: "row",
149 alignItems: "center",
150 gap: 1
151 }, /* @__PURE__ */ react.createElement(_elementor_ui.Typography, {
152 variant: "caption",
153 color: "text.tertiary",
154 sx: {
155 fontSize: "11px",
156 lineHeight: "normal"
157 }
158 }, helpText), /* @__PURE__ */ react.createElement(_elementor_ui.Button, {
159 href: link.url,
160 target: "_blank",
161 variant: "text",
162 size: "small",
163 color: "info",
164 sx: { fontSize: "11px" }
165 }, link.text));
166 };
167
168 //#endregion
169 //#region node_modules/lottie-web/build/player/lottie.js
170 var require_lottie = /* @__PURE__ */ __commonJSMin(((exports, module) => {
171 typeof document !== "undefined" && typeof navigator !== "undefined" && (function(global, factory) {
172 typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.lottie = factory());
173 })(exports, (function() {
174 "use strict";
175 var svgNS = "http://www.w3.org/2000/svg";
176 var locationHref = "";
177 var _useWebWorker = false;
178 var initialDefaultFrame = -999999;
179 var setWebWorker = function setWebWorker(flag) {
180 _useWebWorker = !!flag;
181 };
182 var getWebWorker = function getWebWorker() {
183 return _useWebWorker;
184 };
185 var setLocationHref = function setLocationHref(value) {
186 locationHref = value;
187 };
188 var getLocationHref = function getLocationHref() {
189 return locationHref;
190 };
191 function createTag(type) {
192 return document.createElement(type);
193 }
194 function extendPrototype(sources, destination) {
195 var i;
196 var len = sources.length;
197 var sourcePrototype;
198 for (i = 0; i < len; i += 1) {
199 sourcePrototype = sources[i].prototype;
200 for (var attr in sourcePrototype) if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
201 }
202 }
203 function getDescriptor(object, prop) {
204 return Object.getOwnPropertyDescriptor(object, prop);
205 }
206 function createProxyFunction(prototype) {
207 function ProxyFunction() {}
208 ProxyFunction.prototype = prototype;
209 return ProxyFunction;
210 }
211 var audioControllerFactory = function() {
212 function AudioController(audioFactory) {
213 this.audios = [];
214 this.audioFactory = audioFactory;
215 this._volume = 1;
216 this._isMuted = false;
217 }
218 AudioController.prototype = {
219 addAudio: function addAudio(audio) {
220 this.audios.push(audio);
221 },
222 pause: function pause() {
223 var i;
224 var len = this.audios.length;
225 for (i = 0; i < len; i += 1) this.audios[i].pause();
226 },
227 resume: function resume() {
228 var i;
229 var len = this.audios.length;
230 for (i = 0; i < len; i += 1) this.audios[i].resume();
231 },
232 setRate: function setRate(rateValue) {
233 var i;
234 var len = this.audios.length;
235 for (i = 0; i < len; i += 1) this.audios[i].setRate(rateValue);
236 },
237 createAudio: function createAudio(assetPath) {
238 if (this.audioFactory) return this.audioFactory(assetPath);
239 if (window.Howl) return new window.Howl({ src: [assetPath] });
240 return {
241 isPlaying: false,
242 play: function play() {
243 this.isPlaying = true;
244 },
245 seek: function seek() {
246 this.isPlaying = false;
247 },
248 playing: function playing() {},
249 rate: function rate() {},
250 setVolume: function setVolume() {}
251 };
252 },
253 setAudioFactory: function setAudioFactory(audioFactory) {
254 this.audioFactory = audioFactory;
255 },
256 setVolume: function setVolume(value) {
257 this._volume = value;
258 this._updateVolume();
259 },
260 mute: function mute() {
261 this._isMuted = true;
262 this._updateVolume();
263 },
264 unmute: function unmute() {
265 this._isMuted = false;
266 this._updateVolume();
267 },
268 getVolume: function getVolume() {
269 return this._volume;
270 },
271 _updateVolume: function _updateVolume() {
272 var i;
273 var len = this.audios.length;
274 for (i = 0; i < len; i += 1) this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
275 }
276 };
277 return function() {
278 return new AudioController();
279 };
280 }();
281 var createTypedArray = function() {
282 function createRegularArray(type, len) {
283 var i = 0;
284 var arr = [];
285 var value;
286 switch (type) {
287 case "int16":
288 case "uint8c":
289 value = 1;
290 break;
291 default:
292 value = 1.1;
293 break;
294 }
295 for (i = 0; i < len; i += 1) arr.push(value);
296 return arr;
297 }
298 function createTypedArrayFactory(type, len) {
299 if (type === "float32") return new Float32Array(len);
300 if (type === "int16") return new Int16Array(len);
301 if (type === "uint8c") return new Uint8ClampedArray(len);
302 return createRegularArray(type, len);
303 }
304 if (typeof Uint8ClampedArray === "function" && typeof Float32Array === "function") return createTypedArrayFactory;
305 return createRegularArray;
306 }();
307 function createSizedArray(len) {
308 return Array.apply(null, { length: len });
309 }
310 function _typeof$6(o) {
311 "@babel/helpers - typeof";
312 return _typeof$6 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
313 return typeof o;
314 } : function(o) {
315 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
316 }, _typeof$6(o);
317 }
318 var subframeEnabled = true;
319 var expressionsPlugin = null;
320 var expressionsInterfaces = null;
321 var idPrefix$1 = "";
322 var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
323 var _shouldRoundValues = false;
324 var bmPow = Math.pow;
325 var bmSqrt = Math.sqrt;
326 var bmFloor = Math.floor;
327 var bmMax = Math.max;
328 var bmMin = Math.min;
329 var BMMath = {};
330 (function() {
331 var propertyNames = [
332 "abs",
333 "acos",
334 "acosh",
335 "asin",
336 "asinh",
337 "atan",
338 "atanh",
339 "atan2",
340 "ceil",
341 "cbrt",
342 "expm1",
343 "clz32",
344 "cos",
345 "cosh",
346 "exp",
347 "floor",
348 "fround",
349 "hypot",
350 "imul",
351 "log",
352 "log1p",
353 "log2",
354 "log10",
355 "max",
356 "min",
357 "pow",
358 "random",
359 "round",
360 "sign",
361 "sin",
362 "sinh",
363 "sqrt",
364 "tan",
365 "tanh",
366 "trunc",
367 "E",
368 "LN10",
369 "LN2",
370 "LOG10E",
371 "LOG2E",
372 "PI",
373 "SQRT1_2",
374 "SQRT2"
375 ];
376 var i;
377 var len = propertyNames.length;
378 for (i = 0; i < len; i += 1) BMMath[propertyNames[i]] = Math[propertyNames[i]];
379 })();
380 function ProjectInterface$1() {
381 return {};
382 }
383 BMMath.random = Math.random;
384 BMMath.abs = function(val) {
385 if (_typeof$6(val) === "object" && val.length) {
386 var absArr = createSizedArray(val.length);
387 var i;
388 var len = val.length;
389 for (i = 0; i < len; i += 1) absArr[i] = Math.abs(val[i]);
390 return absArr;
391 }
392 return Math.abs(val);
393 };
394 var defaultCurveSegments = 150;
395 var degToRads = Math.PI / 180;
396 var roundCorner = .5519;
397 function roundValues(flag) {
398 _shouldRoundValues = !!flag;
399 }
400 function bmRnd(value) {
401 if (_shouldRoundValues) return Math.round(value);
402 return value;
403 }
404 function styleDiv(element) {
405 element.style.position = "absolute";
406 element.style.top = 0;
407 element.style.left = 0;
408 element.style.display = "block";
409 element.style.transformOrigin = "0 0";
410 element.style.webkitTransformOrigin = "0 0";
411 element.style.backfaceVisibility = "visible";
412 element.style.webkitBackfaceVisibility = "visible";
413 element.style.transformStyle = "preserve-3d";
414 element.style.webkitTransformStyle = "preserve-3d";
415 element.style.mozTransformStyle = "preserve-3d";
416 }
417 function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
418 this.type = type;
419 this.currentTime = currentTime;
420 this.totalTime = totalTime;
421 this.direction = frameMultiplier < 0 ? -1 : 1;
422 }
423 function BMCompleteEvent(type, frameMultiplier) {
424 this.type = type;
425 this.direction = frameMultiplier < 0 ? -1 : 1;
426 }
427 function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
428 this.type = type;
429 this.currentLoop = currentLoop;
430 this.totalLoops = totalLoops;
431 this.direction = frameMultiplier < 0 ? -1 : 1;
432 }
433 function BMSegmentStartEvent(type, firstFrame, totalFrames) {
434 this.type = type;
435 this.firstFrame = firstFrame;
436 this.totalFrames = totalFrames;
437 }
438 function BMDestroyEvent(type, target) {
439 this.type = type;
440 this.target = target;
441 }
442 function BMRenderFrameErrorEvent(nativeError, currentTime) {
443 this.type = "renderFrameError";
444 this.nativeError = nativeError;
445 this.currentTime = currentTime;
446 }
447 function BMConfigErrorEvent(nativeError) {
448 this.type = "configError";
449 this.nativeError = nativeError;
450 }
451 function BMAnimationConfigErrorEvent(type, nativeError) {
452 this.type = type;
453 this.nativeError = nativeError;
454 }
455 var createElementID = function() {
456 var _count = 0;
457 return function createID() {
458 _count += 1;
459 return idPrefix$1 + "__lottie_element_" + _count;
460 };
461 }();
462 function HSVtoRGB(h, s, v) {
463 var r;
464 var g;
465 var b;
466 var i;
467 var f;
468 var p;
469 var q;
470 var t;
471 i = Math.floor(h * 6);
472 f = h * 6 - i;
473 p = v * (1 - s);
474 q = v * (1 - f * s);
475 t = v * (1 - (1 - f) * s);
476 switch (i % 6) {
477 case 0:
478 r = v;
479 g = t;
480 b = p;
481 break;
482 case 1:
483 r = q;
484 g = v;
485 b = p;
486 break;
487 case 2:
488 r = p;
489 g = v;
490 b = t;
491 break;
492 case 3:
493 r = p;
494 g = q;
495 b = v;
496 break;
497 case 4:
498 r = t;
499 g = p;
500 b = v;
501 break;
502 case 5:
503 r = v;
504 g = p;
505 b = q;
506 break;
507 default: break;
508 }
509 return [
510 r,
511 g,
512 b
513 ];
514 }
515 function RGBtoHSV(r, g, b) {
516 var max = Math.max(r, g, b);
517 var min = Math.min(r, g, b);
518 var d = max - min;
519 var h;
520 var s = max === 0 ? 0 : d / max;
521 var v = max / 255;
522 switch (max) {
523 case min:
524 h = 0;
525 break;
526 case r:
527 h = g - b + d * (g < b ? 6 : 0);
528 h /= 6 * d;
529 break;
530 case g:
531 h = b - r + d * 2;
532 h /= 6 * d;
533 break;
534 case b:
535 h = r - g + d * 4;
536 h /= 6 * d;
537 break;
538 default: break;
539 }
540 return [
541 h,
542 s,
543 v
544 ];
545 }
546 function addSaturationToRGB(color, offset) {
547 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
548 hsv[1] += offset;
549 if (hsv[1] > 1) hsv[1] = 1;
550 else if (hsv[1] <= 0) hsv[1] = 0;
551 return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
552 }
553 function addBrightnessToRGB(color, offset) {
554 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
555 hsv[2] += offset;
556 if (hsv[2] > 1) hsv[2] = 1;
557 else if (hsv[2] < 0) hsv[2] = 0;
558 return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
559 }
560 function addHueToRGB(color, offset) {
561 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
562 hsv[0] += offset / 360;
563 if (hsv[0] > 1) hsv[0] -= 1;
564 else if (hsv[0] < 0) hsv[0] += 1;
565 return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
566 }
567 var rgbToHex = function() {
568 var colorMap = [];
569 var i;
570 var hex;
571 for (i = 0; i < 256; i += 1) {
572 hex = i.toString(16);
573 colorMap[i] = hex.length === 1 ? "0" + hex : hex;
574 }
575 return function(r, g, b) {
576 if (r < 0) r = 0;
577 if (g < 0) g = 0;
578 if (b < 0) b = 0;
579 return "#" + colorMap[r] + colorMap[g] + colorMap[b];
580 };
581 }();
582 var setSubframeEnabled = function setSubframeEnabled(flag) {
583 subframeEnabled = !!flag;
584 };
585 var getSubframeEnabled = function getSubframeEnabled() {
586 return subframeEnabled;
587 };
588 var setExpressionsPlugin = function setExpressionsPlugin(value) {
589 expressionsPlugin = value;
590 };
591 var getExpressionsPlugin = function getExpressionsPlugin() {
592 return expressionsPlugin;
593 };
594 var setExpressionInterfaces = function setExpressionInterfaces(value) {
595 expressionsInterfaces = value;
596 };
597 var getExpressionInterfaces = function getExpressionInterfaces() {
598 return expressionsInterfaces;
599 };
600 var setDefaultCurveSegments = function setDefaultCurveSegments(value) {
601 defaultCurveSegments = value;
602 };
603 var getDefaultCurveSegments = function getDefaultCurveSegments() {
604 return defaultCurveSegments;
605 };
606 var setIdPrefix = function setIdPrefix(value) {
607 idPrefix$1 = value;
608 };
609 var getIdPrefix = function getIdPrefix() {
610 return idPrefix$1;
611 };
612 function createNS(type) {
613 return document.createElementNS(svgNS, type);
614 }
615 function _typeof$5(o) {
616 "@babel/helpers - typeof";
617 return _typeof$5 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
618 return typeof o;
619 } : function(o) {
620 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
621 }, _typeof$5(o);
622 }
623 var dataManager = function() {
624 var _counterId = 1;
625 var processes = [];
626 var workerFn;
627 var workerInstance;
628 var workerProxy = {
629 onmessage: function onmessage() {},
630 postMessage: function postMessage(path) {
631 workerFn({ data: path });
632 }
633 };
634 var _workerSelf = { postMessage: function postMessage(data) {
635 workerProxy.onmessage({ data });
636 } };
637 function createWorker(fn) {
638 if (window.Worker && window.Blob && getWebWorker()) {
639 var blob = new Blob(["var _workerSelf = self; self.onmessage = ", fn.toString()], { type: "text/javascript" });
640 var url = URL.createObjectURL(blob);
641 return new Worker(url);
642 }
643 workerFn = fn;
644 return workerProxy;
645 }
646 function setupWorker() {
647 if (!workerInstance) {
648 workerInstance = createWorker(function workerStart(e) {
649 function dataFunctionManager() {
650 function completeLayers(layers, comps) {
651 var layerData;
652 var i;
653 var len = layers.length;
654 var j;
655 var jLen;
656 var k;
657 var kLen;
658 for (i = 0; i < len; i += 1) {
659 layerData = layers[i];
660 if ("ks" in layerData && !layerData.completed) {
661 layerData.completed = true;
662 if (layerData.hasMask) {
663 var maskProps = layerData.masksProperties;
664 jLen = maskProps.length;
665 for (j = 0; j < jLen; j += 1) if (maskProps[j].pt.k.i) convertPathsToAbsoluteValues(maskProps[j].pt.k);
666 else {
667 kLen = maskProps[j].pt.k.length;
668 for (k = 0; k < kLen; k += 1) {
669 if (maskProps[j].pt.k[k].s) convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
670 if (maskProps[j].pt.k[k].e) convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
671 }
672 }
673 }
674 if (layerData.ty === 0) {
675 layerData.layers = findCompLayers(layerData.refId, comps);
676 completeLayers(layerData.layers, comps);
677 } else if (layerData.ty === 4) completeShapes(layerData.shapes);
678 else if (layerData.ty === 5) completeText(layerData);
679 }
680 }
681 }
682 function completeChars(chars, assets) {
683 if (chars) {
684 var i = 0;
685 var len = chars.length;
686 for (i = 0; i < len; i += 1) if (chars[i].t === 1) {
687 chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
688 completeLayers(chars[i].data.layers, assets);
689 }
690 }
691 }
692 function findComp(id, comps) {
693 var i = 0;
694 var len = comps.length;
695 while (i < len) {
696 if (comps[i].id === id) return comps[i];
697 i += 1;
698 }
699 return null;
700 }
701 function findCompLayers(id, comps) {
702 var comp = findComp(id, comps);
703 if (comp) {
704 if (!comp.layers.__used) {
705 comp.layers.__used = true;
706 return comp.layers;
707 }
708 return JSON.parse(JSON.stringify(comp.layers));
709 }
710 return null;
711 }
712 function completeShapes(arr) {
713 var i;
714 var len = arr.length;
715 var j;
716 var jLen;
717 for (i = len - 1; i >= 0; i -= 1) if (arr[i].ty === "sh") if (arr[i].ks.k.i) convertPathsToAbsoluteValues(arr[i].ks.k);
718 else {
719 jLen = arr[i].ks.k.length;
720 for (j = 0; j < jLen; j += 1) {
721 if (arr[i].ks.k[j].s) convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
722 if (arr[i].ks.k[j].e) convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
723 }
724 }
725 else if (arr[i].ty === "gr") completeShapes(arr[i].it);
726 }
727 function convertPathsToAbsoluteValues(path) {
728 var i;
729 var len = path.i.length;
730 for (i = 0; i < len; i += 1) {
731 path.i[i][0] += path.v[i][0];
732 path.i[i][1] += path.v[i][1];
733 path.o[i][0] += path.v[i][0];
734 path.o[i][1] += path.v[i][1];
735 }
736 }
737 function checkVersion(minimum, animVersionString) {
738 var animVersion = animVersionString ? animVersionString.split(".") : [
739 100,
740 100,
741 100
742 ];
743 if (minimum[0] > animVersion[0]) return true;
744 if (animVersion[0] > minimum[0]) return false;
745 if (minimum[1] > animVersion[1]) return true;
746 if (animVersion[1] > minimum[1]) return false;
747 if (minimum[2] > animVersion[2]) return true;
748 if (animVersion[2] > minimum[2]) return false;
749 return null;
750 }
751 var checkText = function() {
752 var minimumVersion = [
753 4,
754 4,
755 14
756 ];
757 function updateTextLayer(textLayer) {
758 var documentData = textLayer.t.d;
759 textLayer.t.d = { k: [{
760 s: documentData,
761 t: 0
762 }] };
763 }
764 function iterateLayers(layers) {
765 var i;
766 var len = layers.length;
767 for (i = 0; i < len; i += 1) if (layers[i].ty === 5) updateTextLayer(layers[i]);
768 }
769 return function(animationData) {
770 if (checkVersion(minimumVersion, animationData.v)) {
771 iterateLayers(animationData.layers);
772 if (animationData.assets) {
773 var i;
774 var len = animationData.assets.length;
775 for (i = 0; i < len; i += 1) if (animationData.assets[i].layers) iterateLayers(animationData.assets[i].layers);
776 }
777 }
778 };
779 }();
780 var checkChars = function() {
781 var minimumVersion = [
782 4,
783 7,
784 99
785 ];
786 return function(animationData) {
787 if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
788 var i;
789 var len = animationData.chars.length;
790 for (i = 0; i < len; i += 1) {
791 var charData = animationData.chars[i];
792 if (charData.data && charData.data.shapes) {
793 completeShapes(charData.data.shapes);
794 charData.data.ip = 0;
795 charData.data.op = 99999;
796 charData.data.st = 0;
797 charData.data.sr = 1;
798 charData.data.ks = {
799 p: {
800 k: [0, 0],
801 a: 0
802 },
803 s: {
804 k: [100, 100],
805 a: 0
806 },
807 a: {
808 k: [0, 0],
809 a: 0
810 },
811 r: {
812 k: 0,
813 a: 0
814 },
815 o: {
816 k: 100,
817 a: 0
818 }
819 };
820 if (!animationData.chars[i].t) {
821 charData.data.shapes.push({ ty: "no" });
822 charData.data.shapes[0].it.push({
823 p: {
824 k: [0, 0],
825 a: 0
826 },
827 s: {
828 k: [100, 100],
829 a: 0
830 },
831 a: {
832 k: [0, 0],
833 a: 0
834 },
835 r: {
836 k: 0,
837 a: 0
838 },
839 o: {
840 k: 100,
841 a: 0
842 },
843 sk: {
844 k: 0,
845 a: 0
846 },
847 sa: {
848 k: 0,
849 a: 0
850 },
851 ty: "tr"
852 });
853 }
854 }
855 }
856 }
857 };
858 }();
859 var checkPathProperties = function() {
860 var minimumVersion = [
861 5,
862 7,
863 15
864 ];
865 function updateTextLayer(textLayer) {
866 var pathData = textLayer.t.p;
867 if (typeof pathData.a === "number") pathData.a = {
868 a: 0,
869 k: pathData.a
870 };
871 if (typeof pathData.p === "number") pathData.p = {
872 a: 0,
873 k: pathData.p
874 };
875 if (typeof pathData.r === "number") pathData.r = {
876 a: 0,
877 k: pathData.r
878 };
879 }
880 function iterateLayers(layers) {
881 var i;
882 var len = layers.length;
883 for (i = 0; i < len; i += 1) if (layers[i].ty === 5) updateTextLayer(layers[i]);
884 }
885 return function(animationData) {
886 if (checkVersion(minimumVersion, animationData.v)) {
887 iterateLayers(animationData.layers);
888 if (animationData.assets) {
889 var i;
890 var len = animationData.assets.length;
891 for (i = 0; i < len; i += 1) if (animationData.assets[i].layers) iterateLayers(animationData.assets[i].layers);
892 }
893 }
894 };
895 }();
896 var checkColors = function() {
897 var minimumVersion = [
898 4,
899 1,
900 9
901 ];
902 function iterateShapes(shapes) {
903 var i;
904 var len = shapes.length;
905 var j;
906 var jLen;
907 for (i = 0; i < len; i += 1) if (shapes[i].ty === "gr") iterateShapes(shapes[i].it);
908 else if (shapes[i].ty === "fl" || shapes[i].ty === "st") if (shapes[i].c.k && shapes[i].c.k[0].i) {
909 jLen = shapes[i].c.k.length;
910 for (j = 0; j < jLen; j += 1) {
911 if (shapes[i].c.k[j].s) {
912 shapes[i].c.k[j].s[0] /= 255;
913 shapes[i].c.k[j].s[1] /= 255;
914 shapes[i].c.k[j].s[2] /= 255;
915 shapes[i].c.k[j].s[3] /= 255;
916 }
917 if (shapes[i].c.k[j].e) {
918 shapes[i].c.k[j].e[0] /= 255;
919 shapes[i].c.k[j].e[1] /= 255;
920 shapes[i].c.k[j].e[2] /= 255;
921 shapes[i].c.k[j].e[3] /= 255;
922 }
923 }
924 } else {
925 shapes[i].c.k[0] /= 255;
926 shapes[i].c.k[1] /= 255;
927 shapes[i].c.k[2] /= 255;
928 shapes[i].c.k[3] /= 255;
929 }
930 }
931 function iterateLayers(layers) {
932 var i;
933 var len = layers.length;
934 for (i = 0; i < len; i += 1) if (layers[i].ty === 4) iterateShapes(layers[i].shapes);
935 }
936 return function(animationData) {
937 if (checkVersion(minimumVersion, animationData.v)) {
938 iterateLayers(animationData.layers);
939 if (animationData.assets) {
940 var i;
941 var len = animationData.assets.length;
942 for (i = 0; i < len; i += 1) if (animationData.assets[i].layers) iterateLayers(animationData.assets[i].layers);
943 }
944 }
945 };
946 }();
947 var checkShapes = function() {
948 var minimumVersion = [
949 4,
950 4,
951 18
952 ];
953 function completeClosingShapes(arr) {
954 var i;
955 var len = arr.length;
956 var j;
957 var jLen;
958 for (i = len - 1; i >= 0; i -= 1) if (arr[i].ty === "sh") if (arr[i].ks.k.i) arr[i].ks.k.c = arr[i].closed;
959 else {
960 jLen = arr[i].ks.k.length;
961 for (j = 0; j < jLen; j += 1) {
962 if (arr[i].ks.k[j].s) arr[i].ks.k[j].s[0].c = arr[i].closed;
963 if (arr[i].ks.k[j].e) arr[i].ks.k[j].e[0].c = arr[i].closed;
964 }
965 }
966 else if (arr[i].ty === "gr") completeClosingShapes(arr[i].it);
967 }
968 function iterateLayers(layers) {
969 var layerData;
970 var i;
971 var len = layers.length;
972 var j;
973 var jLen;
974 var k;
975 var kLen;
976 for (i = 0; i < len; i += 1) {
977 layerData = layers[i];
978 if (layerData.hasMask) {
979 var maskProps = layerData.masksProperties;
980 jLen = maskProps.length;
981 for (j = 0; j < jLen; j += 1) if (maskProps[j].pt.k.i) maskProps[j].pt.k.c = maskProps[j].cl;
982 else {
983 kLen = maskProps[j].pt.k.length;
984 for (k = 0; k < kLen; k += 1) {
985 if (maskProps[j].pt.k[k].s) maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
986 if (maskProps[j].pt.k[k].e) maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
987 }
988 }
989 }
990 if (layerData.ty === 4) completeClosingShapes(layerData.shapes);
991 }
992 }
993 return function(animationData) {
994 if (checkVersion(minimumVersion, animationData.v)) {
995 iterateLayers(animationData.layers);
996 if (animationData.assets) {
997 var i;
998 var len = animationData.assets.length;
999 for (i = 0; i < len; i += 1) if (animationData.assets[i].layers) iterateLayers(animationData.assets[i].layers);
1000 }
1001 }
1002 };
1003 }();
1004 function completeData(animationData) {
1005 if (animationData.__complete) return;
1006 checkColors(animationData);
1007 checkText(animationData);
1008 checkChars(animationData);
1009 checkPathProperties(animationData);
1010 checkShapes(animationData);
1011 completeLayers(animationData.layers, animationData.assets);
1012 completeChars(animationData.chars, animationData.assets);
1013 animationData.__complete = true;
1014 }
1015 function completeText(data) {
1016 if (data.t.a.length === 0 && !("m" in data.t.p)) {}
1017 }
1018 var moduleOb = {};
1019 moduleOb.completeData = completeData;
1020 moduleOb.checkColors = checkColors;
1021 moduleOb.checkChars = checkChars;
1022 moduleOb.checkPathProperties = checkPathProperties;
1023 moduleOb.checkShapes = checkShapes;
1024 moduleOb.completeLayers = completeLayers;
1025 return moduleOb;
1026 }
1027 if (!_workerSelf.dataManager) _workerSelf.dataManager = dataFunctionManager();
1028 if (!_workerSelf.assetLoader) _workerSelf.assetLoader = function() {
1029 function formatResponse(xhr) {
1030 var contentTypeHeader = xhr.getResponseHeader("content-type");
1031 if (contentTypeHeader && xhr.responseType === "json" && contentTypeHeader.indexOf("json") !== -1) return xhr.response;
1032 if (xhr.response && _typeof$5(xhr.response) === "object") return xhr.response;
1033 if (xhr.response && typeof xhr.response === "string") return JSON.parse(xhr.response);
1034 if (xhr.responseText) return JSON.parse(xhr.responseText);
1035 return null;
1036 }
1037 function loadAsset(path, fullPath, callback, errorCallback) {
1038 var response;
1039 var xhr = new XMLHttpRequest();
1040 try {
1041 xhr.responseType = "json";
1042 } catch (err) {}
1043 xhr.onreadystatechange = function() {
1044 if (xhr.readyState === 4) if (xhr.status === 200) {
1045 response = formatResponse(xhr);
1046 callback(response);
1047 } else try {
1048 response = formatResponse(xhr);
1049 callback(response);
1050 } catch (err) {
1051 if (errorCallback) errorCallback(err);
1052 }
1053 };
1054 try {
1055 xhr.open([
1056 "G",
1057 "E",
1058 "T"
1059 ].join(""), path, true);
1060 } catch (error) {
1061 xhr.open([
1062 "G",
1063 "E",
1064 "T"
1065 ].join(""), fullPath + "/" + path, true);
1066 }
1067 xhr.send();
1068 }
1069 return { load: loadAsset };
1070 }();
1071 if (e.data.type === "loadAnimation") _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function(data) {
1072 _workerSelf.dataManager.completeData(data);
1073 _workerSelf.postMessage({
1074 id: e.data.id,
1075 payload: data,
1076 status: "success"
1077 });
1078 }, function() {
1079 _workerSelf.postMessage({
1080 id: e.data.id,
1081 status: "error"
1082 });
1083 });
1084 else if (e.data.type === "complete") {
1085 var animation = e.data.animation;
1086 _workerSelf.dataManager.completeData(animation);
1087 _workerSelf.postMessage({
1088 id: e.data.id,
1089 payload: animation,
1090 status: "success"
1091 });
1092 } else if (e.data.type === "loadData") _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function(data) {
1093 _workerSelf.postMessage({
1094 id: e.data.id,
1095 payload: data,
1096 status: "success"
1097 });
1098 }, function() {
1099 _workerSelf.postMessage({
1100 id: e.data.id,
1101 status: "error"
1102 });
1103 });
1104 });
1105 workerInstance.onmessage = function(event) {
1106 var data = event.data;
1107 var id = data.id;
1108 var process = processes[id];
1109 processes[id] = null;
1110 if (data.status === "success") process.onComplete(data.payload);
1111 else if (process.onError) process.onError();
1112 };
1113 }
1114 }
1115 function createProcess(onComplete, onError) {
1116 _counterId += 1;
1117 var id = "processId_" + _counterId;
1118 processes[id] = {
1119 onComplete,
1120 onError
1121 };
1122 return id;
1123 }
1124 function loadAnimation(path, onComplete, onError) {
1125 setupWorker();
1126 var processId = createProcess(onComplete, onError);
1127 workerInstance.postMessage({
1128 type: "loadAnimation",
1129 path,
1130 fullPath: window.location.origin + window.location.pathname,
1131 id: processId
1132 });
1133 }
1134 function loadData(path, onComplete, onError) {
1135 setupWorker();
1136 var processId = createProcess(onComplete, onError);
1137 workerInstance.postMessage({
1138 type: "loadData",
1139 path,
1140 fullPath: window.location.origin + window.location.pathname,
1141 id: processId
1142 });
1143 }
1144 function completeAnimation(anim, onComplete, onError) {
1145 setupWorker();
1146 var processId = createProcess(onComplete, onError);
1147 workerInstance.postMessage({
1148 type: "complete",
1149 animation: anim,
1150 id: processId
1151 });
1152 }
1153 return {
1154 loadAnimation,
1155 loadData,
1156 completeAnimation
1157 };
1158 }();
1159 var ImagePreloader = function() {
1160 var proxyImage = function() {
1161 var canvas = createTag("canvas");
1162 canvas.width = 1;
1163 canvas.height = 1;
1164 var ctx = canvas.getContext("2d");
1165 ctx.fillStyle = "rgba(0,0,0,0)";
1166 ctx.fillRect(0, 0, 1, 1);
1167 return canvas;
1168 }();
1169 function imageLoaded() {
1170 this.loadedAssets += 1;
1171 if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
1172 if (this.imagesLoadedCb) this.imagesLoadedCb(null);
1173 }
1174 }
1175 function footageLoaded() {
1176 this.loadedFootagesCount += 1;
1177 if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
1178 if (this.imagesLoadedCb) this.imagesLoadedCb(null);
1179 }
1180 }
1181 function getAssetsPath(assetData, assetsPath, originalPath) {
1182 var path = "";
1183 if (assetData.e) path = assetData.p;
1184 else if (assetsPath) {
1185 var imagePath = assetData.p;
1186 if (imagePath.indexOf("images/") !== -1) imagePath = imagePath.split("/")[1];
1187 path = assetsPath + imagePath;
1188 } else {
1189 path = originalPath;
1190 path += assetData.u ? assetData.u : "";
1191 path += assetData.p;
1192 }
1193 return path;
1194 }
1195 function testImageLoaded(img) {
1196 var _count = 0;
1197 var intervalId = setInterval(function() {
1198 if (img.getBBox().width || _count > 500) {
1199 this._imageLoaded();
1200 clearInterval(intervalId);
1201 }
1202 _count += 1;
1203 }.bind(this), 50);
1204 }
1205 function createImageData(assetData) {
1206 var path = getAssetsPath(assetData, this.assetsPath, this.path);
1207 var img = createNS("image");
1208 if (isSafari) this.testImageLoaded(img);
1209 else img.addEventListener("load", this._imageLoaded, false);
1210 img.addEventListener("error", function() {
1211 ob.img = proxyImage;
1212 this._imageLoaded();
1213 }.bind(this), false);
1214 img.setAttributeNS("http://www.w3.org/1999/xlink", "href", path);
1215 if (this._elementHelper.append) this._elementHelper.append(img);
1216 else this._elementHelper.appendChild(img);
1217 var ob = {
1218 img,
1219 assetData
1220 };
1221 return ob;
1222 }
1223 function createImgData(assetData) {
1224 var path = getAssetsPath(assetData, this.assetsPath, this.path);
1225 var img = createTag("img");
1226 img.crossOrigin = "anonymous";
1227 img.addEventListener("load", this._imageLoaded, false);
1228 img.addEventListener("error", function() {
1229 ob.img = proxyImage;
1230 this._imageLoaded();
1231 }.bind(this), false);
1232 img.src = path;
1233 var ob = {
1234 img,
1235 assetData
1236 };
1237 return ob;
1238 }
1239 function createFootageData(data) {
1240 var ob = { assetData: data };
1241 var path = getAssetsPath(data, this.assetsPath, this.path);
1242 dataManager.loadData(path, function(footageData) {
1243 ob.img = footageData;
1244 this._footageLoaded();
1245 }.bind(this), function() {
1246 ob.img = {};
1247 this._footageLoaded();
1248 }.bind(this));
1249 return ob;
1250 }
1251 function loadAssets(assets, cb) {
1252 this.imagesLoadedCb = cb;
1253 var i;
1254 var len = assets.length;
1255 for (i = 0; i < len; i += 1) if (!assets[i].layers) {
1256 if (!assets[i].t || assets[i].t === "seq") {
1257 this.totalImages += 1;
1258 this.images.push(this._createImageData(assets[i]));
1259 } else if (assets[i].t === 3) {
1260 this.totalFootages += 1;
1261 this.images.push(this.createFootageData(assets[i]));
1262 }
1263 }
1264 }
1265 function setPath(path) {
1266 this.path = path || "";
1267 }
1268 function setAssetsPath(path) {
1269 this.assetsPath = path || "";
1270 }
1271 function getAsset(assetData) {
1272 var i = 0;
1273 var len = this.images.length;
1274 while (i < len) {
1275 if (this.images[i].assetData === assetData) return this.images[i].img;
1276 i += 1;
1277 }
1278 return null;
1279 }
1280 function destroy() {
1281 this.imagesLoadedCb = null;
1282 this.images.length = 0;
1283 }
1284 function loadedImages() {
1285 return this.totalImages === this.loadedAssets;
1286 }
1287 function loadedFootages() {
1288 return this.totalFootages === this.loadedFootagesCount;
1289 }
1290 function setCacheType(type, elementHelper) {
1291 if (type === "svg") {
1292 this._elementHelper = elementHelper;
1293 this._createImageData = this.createImageData.bind(this);
1294 } else this._createImageData = this.createImgData.bind(this);
1295 }
1296 function ImagePreloaderFactory() {
1297 this._imageLoaded = imageLoaded.bind(this);
1298 this._footageLoaded = footageLoaded.bind(this);
1299 this.testImageLoaded = testImageLoaded.bind(this);
1300 this.createFootageData = createFootageData.bind(this);
1301 this.assetsPath = "";
1302 this.path = "";
1303 this.totalImages = 0;
1304 this.totalFootages = 0;
1305 this.loadedAssets = 0;
1306 this.loadedFootagesCount = 0;
1307 this.imagesLoadedCb = null;
1308 this.images = [];
1309 }
1310 ImagePreloaderFactory.prototype = {
1311 loadAssets,
1312 setAssetsPath,
1313 setPath,
1314 loadedImages,
1315 loadedFootages,
1316 destroy,
1317 getAsset,
1318 createImgData,
1319 createImageData,
1320 imageLoaded,
1321 footageLoaded,
1322 setCacheType
1323 };
1324 return ImagePreloaderFactory;
1325 }();
1326 function BaseEvent() {}
1327 BaseEvent.prototype = {
1328 triggerEvent: function triggerEvent(eventName, args) {
1329 if (this._cbs[eventName]) {
1330 var callbacks = this._cbs[eventName];
1331 for (var i = 0; i < callbacks.length; i += 1) callbacks[i](args);
1332 }
1333 },
1334 addEventListener: function addEventListener(eventName, callback) {
1335 if (!this._cbs[eventName]) this._cbs[eventName] = [];
1336 this._cbs[eventName].push(callback);
1337 return function() {
1338 this.removeEventListener(eventName, callback);
1339 }.bind(this);
1340 },
1341 removeEventListener: function removeEventListener(eventName, callback) {
1342 if (!callback) this._cbs[eventName] = null;
1343 else if (this._cbs[eventName]) {
1344 var i = 0;
1345 var len = this._cbs[eventName].length;
1346 while (i < len) {
1347 if (this._cbs[eventName][i] === callback) {
1348 this._cbs[eventName].splice(i, 1);
1349 i -= 1;
1350 len -= 1;
1351 }
1352 i += 1;
1353 }
1354 if (!this._cbs[eventName].length) this._cbs[eventName] = null;
1355 }
1356 }
1357 };
1358 var markerParser = function() {
1359 function parsePayloadLines(payload) {
1360 var lines = payload.split("\r\n");
1361 var keys = {};
1362 var line;
1363 var keysCount = 0;
1364 for (var i = 0; i < lines.length; i += 1) {
1365 line = lines[i].split(":");
1366 if (line.length === 2) {
1367 keys[line[0]] = line[1].trim();
1368 keysCount += 1;
1369 }
1370 }
1371 if (keysCount === 0) throw new Error();
1372 return keys;
1373 }
1374 return function(_markers) {
1375 var markers = [];
1376 for (var i = 0; i < _markers.length; i += 1) {
1377 var _marker = _markers[i];
1378 var markerData = {
1379 time: _marker.tm,
1380 duration: _marker.dr
1381 };
1382 try {
1383 markerData.payload = JSON.parse(_markers[i].cm);
1384 } catch (_) {
1385 try {
1386 markerData.payload = parsePayloadLines(_markers[i].cm);
1387 } catch (__) {
1388 markerData.payload = { name: _markers[i].cm };
1389 }
1390 }
1391 markers.push(markerData);
1392 }
1393 return markers;
1394 };
1395 }();
1396 var ProjectInterface = function() {
1397 function registerComposition(comp) {
1398 this.compositions.push(comp);
1399 }
1400 return function() {
1401 function _thisProjectFunction(name) {
1402 var i = 0;
1403 var len = this.compositions.length;
1404 while (i < len) {
1405 if (this.compositions[i].data && this.compositions[i].data.nm === name) {
1406 if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) this.compositions[i].prepareFrame(this.currentFrame);
1407 return this.compositions[i].compInterface;
1408 }
1409 i += 1;
1410 }
1411 return null;
1412 }
1413 _thisProjectFunction.compositions = [];
1414 _thisProjectFunction.currentFrame = 0;
1415 _thisProjectFunction.registerComposition = registerComposition;
1416 return _thisProjectFunction;
1417 };
1418 }();
1419 var renderers = {};
1420 var registerRenderer = function registerRenderer(key, value) {
1421 renderers[key] = value;
1422 };
1423 function getRenderer(key) {
1424 return renderers[key];
1425 }
1426 function getRegisteredRenderer() {
1427 if (renderers.canvas) return "canvas";
1428 for (var key in renderers) if (renderers[key]) return key;
1429 return "";
1430 }
1431 function _typeof$4(o) {
1432 "@babel/helpers - typeof";
1433 return _typeof$4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
1434 return typeof o;
1435 } : function(o) {
1436 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1437 }, _typeof$4(o);
1438 }
1439 var AnimationItem = function AnimationItem() {
1440 this._cbs = [];
1441 this.name = "";
1442 this.path = "";
1443 this.isLoaded = false;
1444 this.currentFrame = 0;
1445 this.currentRawFrame = 0;
1446 this.firstFrame = 0;
1447 this.totalFrames = 0;
1448 this.frameRate = 0;
1449 this.frameMult = 0;
1450 this.playSpeed = 1;
1451 this.playDirection = 1;
1452 this.playCount = 0;
1453 this.animationData = {};
1454 this.assets = [];
1455 this.isPaused = true;
1456 this.autoplay = false;
1457 this.loop = true;
1458 this.renderer = null;
1459 this.animationID = createElementID();
1460 this.assetsPath = "";
1461 this.timeCompleted = 0;
1462 this.segmentPos = 0;
1463 this.isSubframeEnabled = getSubframeEnabled();
1464 this.segments = [];
1465 this._idle = true;
1466 this._completedLoop = false;
1467 this.projectInterface = ProjectInterface();
1468 this.imagePreloader = new ImagePreloader();
1469 this.audioController = audioControllerFactory();
1470 this.markers = [];
1471 this.configAnimation = this.configAnimation.bind(this);
1472 this.onSetupError = this.onSetupError.bind(this);
1473 this.onSegmentComplete = this.onSegmentComplete.bind(this);
1474 this.drawnFrameEvent = new BMEnterFrameEvent("drawnFrame", 0, 0, 0);
1475 this.expressionsPlugin = getExpressionsPlugin();
1476 };
1477 extendPrototype([BaseEvent], AnimationItem);
1478 AnimationItem.prototype.setParams = function(params) {
1479 if (params.wrapper || params.container) this.wrapper = params.wrapper || params.container;
1480 var animType = "svg";
1481 if (params.animType) animType = params.animType;
1482 else if (params.renderer) animType = params.renderer;
1483 var RendererClass = getRenderer(animType);
1484 this.renderer = new RendererClass(this, params.rendererSettings);
1485 this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
1486 this.renderer.setProjectInterface(this.projectInterface);
1487 this.animType = animType;
1488 if (params.loop === "" || params.loop === null || params.loop === void 0 || params.loop === true) this.loop = true;
1489 else if (params.loop === false) this.loop = false;
1490 else this.loop = parseInt(params.loop, 10);
1491 this.autoplay = "autoplay" in params ? params.autoplay : true;
1492 this.name = params.name ? params.name : "";
1493 this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, "autoloadSegments") ? params.autoloadSegments : true;
1494 this.assetsPath = params.assetsPath;
1495 this.initialSegment = params.initialSegment;
1496 if (params.audioFactory) this.audioController.setAudioFactory(params.audioFactory);
1497 if (params.animationData) this.setupAnimation(params.animationData);
1498 else if (params.path) {
1499 if (params.path.lastIndexOf("\\") !== -1) this.path = params.path.substr(0, params.path.lastIndexOf("\\") + 1);
1500 else this.path = params.path.substr(0, params.path.lastIndexOf("/") + 1);
1501 this.fileName = params.path.substr(params.path.lastIndexOf("/") + 1);
1502 this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf(".json"));
1503 dataManager.loadAnimation(params.path, this.configAnimation, this.onSetupError);
1504 }
1505 };
1506 AnimationItem.prototype.onSetupError = function() {
1507 this.trigger("data_failed");
1508 };
1509 AnimationItem.prototype.setupAnimation = function(data) {
1510 dataManager.completeAnimation(data, this.configAnimation);
1511 };
1512 AnimationItem.prototype.setData = function(wrapper, animationData) {
1513 if (animationData) {
1514 if (_typeof$4(animationData) !== "object") animationData = JSON.parse(animationData);
1515 }
1516 var params = {
1517 wrapper,
1518 animationData
1519 };
1520 var wrapperAttributes = wrapper.attributes;
1521 params.path = wrapperAttributes.getNamedItem("data-animation-path") ? wrapperAttributes.getNamedItem("data-animation-path").value : wrapperAttributes.getNamedItem("data-bm-path") ? wrapperAttributes.getNamedItem("data-bm-path").value : wrapperAttributes.getNamedItem("bm-path") ? wrapperAttributes.getNamedItem("bm-path").value : "";
1522 params.animType = wrapperAttributes.getNamedItem("data-anim-type") ? wrapperAttributes.getNamedItem("data-anim-type").value : wrapperAttributes.getNamedItem("data-bm-type") ? wrapperAttributes.getNamedItem("data-bm-type").value : wrapperAttributes.getNamedItem("bm-type") ? wrapperAttributes.getNamedItem("bm-type").value : wrapperAttributes.getNamedItem("data-bm-renderer") ? wrapperAttributes.getNamedItem("data-bm-renderer").value : wrapperAttributes.getNamedItem("bm-renderer") ? wrapperAttributes.getNamedItem("bm-renderer").value : getRegisteredRenderer() || "canvas";
1523 var loop = wrapperAttributes.getNamedItem("data-anim-loop") ? wrapperAttributes.getNamedItem("data-anim-loop").value : wrapperAttributes.getNamedItem("data-bm-loop") ? wrapperAttributes.getNamedItem("data-bm-loop").value : wrapperAttributes.getNamedItem("bm-loop") ? wrapperAttributes.getNamedItem("bm-loop").value : "";
1524 if (loop === "false") params.loop = false;
1525 else if (loop === "true") params.loop = true;
1526 else if (loop !== "") params.loop = parseInt(loop, 10);
1527 params.autoplay = (wrapperAttributes.getNamedItem("data-anim-autoplay") ? wrapperAttributes.getNamedItem("data-anim-autoplay").value : wrapperAttributes.getNamedItem("data-bm-autoplay") ? wrapperAttributes.getNamedItem("data-bm-autoplay").value : wrapperAttributes.getNamedItem("bm-autoplay") ? wrapperAttributes.getNamedItem("bm-autoplay").value : true) !== "false";
1528 params.name = wrapperAttributes.getNamedItem("data-name") ? wrapperAttributes.getNamedItem("data-name").value : wrapperAttributes.getNamedItem("data-bm-name") ? wrapperAttributes.getNamedItem("data-bm-name").value : wrapperAttributes.getNamedItem("bm-name") ? wrapperAttributes.getNamedItem("bm-name").value : "";
1529 if ((wrapperAttributes.getNamedItem("data-anim-prerender") ? wrapperAttributes.getNamedItem("data-anim-prerender").value : wrapperAttributes.getNamedItem("data-bm-prerender") ? wrapperAttributes.getNamedItem("data-bm-prerender").value : wrapperAttributes.getNamedItem("bm-prerender") ? wrapperAttributes.getNamedItem("bm-prerender").value : "") === "false") params.prerender = false;
1530 if (!params.path) this.trigger("destroy");
1531 else this.setParams(params);
1532 };
1533 AnimationItem.prototype.includeLayers = function(data) {
1534 if (data.op > this.animationData.op) {
1535 this.animationData.op = data.op;
1536 this.totalFrames = Math.floor(data.op - this.animationData.ip);
1537 }
1538 var layers = this.animationData.layers;
1539 var i;
1540 var len = layers.length;
1541 var newLayers = data.layers;
1542 var j;
1543 var jLen = newLayers.length;
1544 for (j = 0; j < jLen; j += 1) {
1545 i = 0;
1546 while (i < len) {
1547 if (layers[i].id === newLayers[j].id) {
1548 layers[i] = newLayers[j];
1549 break;
1550 }
1551 i += 1;
1552 }
1553 }
1554 if (data.chars || data.fonts) {
1555 this.renderer.globalData.fontManager.addChars(data.chars);
1556 this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
1557 }
1558 if (data.assets) {
1559 len = data.assets.length;
1560 for (i = 0; i < len; i += 1) this.animationData.assets.push(data.assets[i]);
1561 }
1562 this.animationData.__complete = false;
1563 dataManager.completeAnimation(this.animationData, this.onSegmentComplete);
1564 };
1565 AnimationItem.prototype.onSegmentComplete = function(data) {
1566 this.animationData = data;
1567 var expressionsPlugin = getExpressionsPlugin();
1568 if (expressionsPlugin) expressionsPlugin.initExpressions(this);
1569 this.loadNextSegment();
1570 };
1571 AnimationItem.prototype.loadNextSegment = function() {
1572 var segments = this.animationData.segments;
1573 if (!segments || segments.length === 0 || !this.autoloadSegments) {
1574 this.trigger("data_ready");
1575 this.timeCompleted = this.totalFrames;
1576 return;
1577 }
1578 var segment = segments.shift();
1579 this.timeCompleted = segment.time * this.frameRate;
1580 var segmentPath = this.path + this.fileName + "_" + this.segmentPos + ".json";
1581 this.segmentPos += 1;
1582 dataManager.loadData(segmentPath, this.includeLayers.bind(this), function() {
1583 this.trigger("data_failed");
1584 }.bind(this));
1585 };
1586 AnimationItem.prototype.loadSegments = function() {
1587 if (!this.animationData.segments) this.timeCompleted = this.totalFrames;
1588 this.loadNextSegment();
1589 };
1590 AnimationItem.prototype.imagesLoaded = function() {
1591 this.trigger("loaded_images");
1592 this.checkLoaded();
1593 };
1594 AnimationItem.prototype.preloadImages = function() {
1595 this.imagePreloader.setAssetsPath(this.assetsPath);
1596 this.imagePreloader.setPath(this.path);
1597 this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
1598 };
1599 AnimationItem.prototype.configAnimation = function(animData) {
1600 if (!this.renderer) return;
1601 try {
1602 this.animationData = animData;
1603 if (this.initialSegment) {
1604 this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
1605 this.firstFrame = Math.round(this.initialSegment[0]);
1606 } else {
1607 this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
1608 this.firstFrame = Math.round(this.animationData.ip);
1609 }
1610 this.renderer.configAnimation(animData);
1611 if (!animData.assets) animData.assets = [];
1612 this.assets = this.animationData.assets;
1613 this.frameRate = this.animationData.fr;
1614 this.frameMult = this.animationData.fr / 1e3;
1615 this.renderer.searchExtraCompositions(animData.assets);
1616 this.markers = markerParser(animData.markers || []);
1617 this.trigger("config_ready");
1618 this.preloadImages();
1619 this.loadSegments();
1620 this.updaFrameModifier();
1621 this.waitForFontsLoaded();
1622 if (this.isPaused) this.audioController.pause();
1623 } catch (error) {
1624 this.triggerConfigError(error);
1625 }
1626 };
1627 AnimationItem.prototype.waitForFontsLoaded = function() {
1628 if (!this.renderer) return;
1629 if (this.renderer.globalData.fontManager.isLoaded) this.checkLoaded();
1630 else setTimeout(this.waitForFontsLoaded.bind(this), 20);
1631 };
1632 AnimationItem.prototype.checkLoaded = function() {
1633 if (!this.isLoaded && this.renderer.globalData.fontManager.isLoaded && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== "canvas") && this.imagePreloader.loadedFootages()) {
1634 this.isLoaded = true;
1635 var expressionsPlugin = getExpressionsPlugin();
1636 if (expressionsPlugin) expressionsPlugin.initExpressions(this);
1637 this.renderer.initItems();
1638 setTimeout(function() {
1639 this.trigger("DOMLoaded");
1640 }.bind(this), 0);
1641 this.gotoFrame();
1642 if (this.autoplay) this.play();
1643 }
1644 };
1645 AnimationItem.prototype.resize = function(width, height) {
1646 var _width = typeof width === "number" ? width : void 0;
1647 var _height = typeof height === "number" ? height : void 0;
1648 this.renderer.updateContainerSize(_width, _height);
1649 };
1650 AnimationItem.prototype.setSubframe = function(flag) {
1651 this.isSubframeEnabled = !!flag;
1652 };
1653 AnimationItem.prototype.gotoFrame = function() {
1654 this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame;
1655 if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) this.currentFrame = this.timeCompleted;
1656 this.trigger("enterFrame");
1657 this.renderFrame();
1658 this.trigger("drawnFrame");
1659 };
1660 AnimationItem.prototype.renderFrame = function() {
1661 if (this.isLoaded === false || !this.renderer) return;
1662 try {
1663 if (this.expressionsPlugin) this.expressionsPlugin.resetFrame();
1664 this.renderer.renderFrame(this.currentFrame + this.firstFrame);
1665 } catch (error) {
1666 this.triggerRenderFrameError(error);
1667 }
1668 };
1669 AnimationItem.prototype.play = function(name) {
1670 if (name && this.name !== name) return;
1671 if (this.isPaused === true) {
1672 this.isPaused = false;
1673 this.trigger("_play");
1674 this.audioController.resume();
1675 if (this._idle) {
1676 this._idle = false;
1677 this.trigger("_active");
1678 }
1679 }
1680 };
1681 AnimationItem.prototype.pause = function(name) {
1682 if (name && this.name !== name) return;
1683 if (this.isPaused === false) {
1684 this.isPaused = true;
1685 this.trigger("_pause");
1686 this._idle = true;
1687 this.trigger("_idle");
1688 this.audioController.pause();
1689 }
1690 };
1691 AnimationItem.prototype.togglePause = function(name) {
1692 if (name && this.name !== name) return;
1693 if (this.isPaused === true) this.play();
1694 else this.pause();
1695 };
1696 AnimationItem.prototype.stop = function(name) {
1697 if (name && this.name !== name) return;
1698 this.pause();
1699 this.playCount = 0;
1700 this._completedLoop = false;
1701 this.setCurrentRawFrameValue(0);
1702 };
1703 AnimationItem.prototype.getMarkerData = function(markerName) {
1704 var marker;
1705 for (var i = 0; i < this.markers.length; i += 1) {
1706 marker = this.markers[i];
1707 if (marker.payload && marker.payload.name === markerName) return marker;
1708 }
1709 return null;
1710 };
1711 AnimationItem.prototype.goToAndStop = function(value, isFrame, name) {
1712 if (name && this.name !== name) return;
1713 var numValue = Number(value);
1714 if (isNaN(numValue)) {
1715 var marker = this.getMarkerData(value);
1716 if (marker) this.goToAndStop(marker.time, true);
1717 } else if (isFrame) this.setCurrentRawFrameValue(value);
1718 else this.setCurrentRawFrameValue(value * this.frameModifier);
1719 this.pause();
1720 };
1721 AnimationItem.prototype.goToAndPlay = function(value, isFrame, name) {
1722 if (name && this.name !== name) return;
1723 var numValue = Number(value);
1724 if (isNaN(numValue)) {
1725 var marker = this.getMarkerData(value);
1726 if (marker) if (!marker.duration) this.goToAndStop(marker.time, true);
1727 else this.playSegments([marker.time, marker.time + marker.duration], true);
1728 } else this.goToAndStop(numValue, isFrame, name);
1729 this.play();
1730 };
1731 AnimationItem.prototype.advanceTime = function(value) {
1732 if (this.isPaused === true || this.isLoaded === false) return;
1733 var nextValue = this.currentRawFrame + value * this.frameModifier;
1734 var _isComplete = false;
1735 if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) if (!this.loop || this.playCount === this.loop) {
1736 if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
1737 _isComplete = true;
1738 nextValue = this.totalFrames - 1;
1739 }
1740 } else if (nextValue >= this.totalFrames) {
1741 this.playCount += 1;
1742 if (!this.checkSegments(nextValue % this.totalFrames)) {
1743 this.setCurrentRawFrameValue(nextValue % this.totalFrames);
1744 this._completedLoop = true;
1745 this.trigger("loopComplete");
1746 }
1747 } else this.setCurrentRawFrameValue(nextValue);
1748 else if (nextValue < 0) {
1749 if (!this.checkSegments(nextValue % this.totalFrames)) if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
1750 this.setCurrentRawFrameValue(this.totalFrames + nextValue % this.totalFrames);
1751 if (!this._completedLoop) this._completedLoop = true;
1752 else this.trigger("loopComplete");
1753 } else {
1754 _isComplete = true;
1755 nextValue = 0;
1756 }
1757 } else this.setCurrentRawFrameValue(nextValue);
1758 if (_isComplete) {
1759 this.setCurrentRawFrameValue(nextValue);
1760 this.pause();
1761 this.trigger("complete");
1762 }
1763 };
1764 AnimationItem.prototype.adjustSegment = function(arr, offset) {
1765 this.playCount = 0;
1766 if (arr[1] < arr[0]) {
1767 if (this.frameModifier > 0) if (this.playSpeed < 0) this.setSpeed(-this.playSpeed);
1768 else this.setDirection(-1);
1769 this.totalFrames = arr[0] - arr[1];
1770 this.timeCompleted = this.totalFrames;
1771 this.firstFrame = arr[1];
1772 this.setCurrentRawFrameValue(this.totalFrames - .001 - offset);
1773 } else if (arr[1] > arr[0]) {
1774 if (this.frameModifier < 0) if (this.playSpeed < 0) this.setSpeed(-this.playSpeed);
1775 else this.setDirection(1);
1776 this.totalFrames = arr[1] - arr[0];
1777 this.timeCompleted = this.totalFrames;
1778 this.firstFrame = arr[0];
1779 this.setCurrentRawFrameValue(.001 + offset);
1780 }
1781 this.trigger("segmentStart");
1782 };
1783 AnimationItem.prototype.setSegment = function(init, end) {
1784 var pendingFrame = -1;
1785 if (this.isPaused) {
1786 if (this.currentRawFrame + this.firstFrame < init) pendingFrame = init;
1787 else if (this.currentRawFrame + this.firstFrame > end) pendingFrame = end - init;
1788 }
1789 this.firstFrame = init;
1790 this.totalFrames = end - init;
1791 this.timeCompleted = this.totalFrames;
1792 if (pendingFrame !== -1) this.goToAndStop(pendingFrame, true);
1793 };
1794 AnimationItem.prototype.playSegments = function(arr, forceFlag) {
1795 if (forceFlag) this.segments.length = 0;
1796 if (_typeof$4(arr[0]) === "object") {
1797 var i;
1798 var len = arr.length;
1799 for (i = 0; i < len; i += 1) this.segments.push(arr[i]);
1800 } else this.segments.push(arr);
1801 if (this.segments.length && forceFlag) this.adjustSegment(this.segments.shift(), 0);
1802 if (this.isPaused) this.play();
1803 };
1804 AnimationItem.prototype.resetSegments = function(forceFlag) {
1805 this.segments.length = 0;
1806 this.segments.push([this.animationData.ip, this.animationData.op]);
1807 if (forceFlag) this.checkSegments(0);
1808 };
1809 AnimationItem.prototype.checkSegments = function(offset) {
1810 if (this.segments.length) {
1811 this.adjustSegment(this.segments.shift(), offset);
1812 return true;
1813 }
1814 return false;
1815 };
1816 AnimationItem.prototype.destroy = function(name) {
1817 if (name && this.name !== name || !this.renderer) return;
1818 this.renderer.destroy();
1819 this.imagePreloader.destroy();
1820 this.trigger("destroy");
1821 this._cbs = null;
1822 this.onEnterFrame = null;
1823 this.onLoopComplete = null;
1824 this.onComplete = null;
1825 this.onSegmentStart = null;
1826 this.onDestroy = null;
1827 this.renderer = null;
1828 this.expressionsPlugin = null;
1829 this.imagePreloader = null;
1830 this.projectInterface = null;
1831 };
1832 AnimationItem.prototype.setCurrentRawFrameValue = function(value) {
1833 this.currentRawFrame = value;
1834 this.gotoFrame();
1835 };
1836 AnimationItem.prototype.setSpeed = function(val) {
1837 this.playSpeed = val;
1838 this.updaFrameModifier();
1839 };
1840 AnimationItem.prototype.setDirection = function(val) {
1841 this.playDirection = val < 0 ? -1 : 1;
1842 this.updaFrameModifier();
1843 };
1844 AnimationItem.prototype.setLoop = function(isLooping) {
1845 this.loop = isLooping;
1846 };
1847 AnimationItem.prototype.setVolume = function(val, name) {
1848 if (name && this.name !== name) return;
1849 this.audioController.setVolume(val);
1850 };
1851 AnimationItem.prototype.getVolume = function() {
1852 return this.audioController.getVolume();
1853 };
1854 AnimationItem.prototype.mute = function(name) {
1855 if (name && this.name !== name) return;
1856 this.audioController.mute();
1857 };
1858 AnimationItem.prototype.unmute = function(name) {
1859 if (name && this.name !== name) return;
1860 this.audioController.unmute();
1861 };
1862 AnimationItem.prototype.updaFrameModifier = function() {
1863 this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
1864 this.audioController.setRate(this.playSpeed * this.playDirection);
1865 };
1866 AnimationItem.prototype.getPath = function() {
1867 return this.path;
1868 };
1869 AnimationItem.prototype.getAssetsPath = function(assetData) {
1870 var path = "";
1871 if (assetData.e) path = assetData.p;
1872 else if (this.assetsPath) {
1873 var imagePath = assetData.p;
1874 if (imagePath.indexOf("images/") !== -1) imagePath = imagePath.split("/")[1];
1875 path = this.assetsPath + imagePath;
1876 } else {
1877 path = this.path;
1878 path += assetData.u ? assetData.u : "";
1879 path += assetData.p;
1880 }
1881 return path;
1882 };
1883 AnimationItem.prototype.getAssetData = function(id) {
1884 var i = 0;
1885 var len = this.assets.length;
1886 while (i < len) {
1887 if (id === this.assets[i].id) return this.assets[i];
1888 i += 1;
1889 }
1890 return null;
1891 };
1892 AnimationItem.prototype.hide = function() {
1893 this.renderer.hide();
1894 };
1895 AnimationItem.prototype.show = function() {
1896 this.renderer.show();
1897 };
1898 AnimationItem.prototype.getDuration = function(isFrame) {
1899 return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
1900 };
1901 AnimationItem.prototype.updateDocumentData = function(path, documentData, index) {
1902 try {
1903 this.renderer.getElementByPath(path).updateDocumentData(documentData, index);
1904 } catch (error) {}
1905 };
1906 AnimationItem.prototype.trigger = function(name) {
1907 if (this._cbs && this._cbs[name]) switch (name) {
1908 case "enterFrame":
1909 this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
1910 break;
1911 case "drawnFrame":
1912 this.drawnFrameEvent.currentTime = this.currentFrame;
1913 this.drawnFrameEvent.totalTime = this.totalFrames;
1914 this.drawnFrameEvent.direction = this.frameModifier;
1915 this.triggerEvent(name, this.drawnFrameEvent);
1916 break;
1917 case "loopComplete":
1918 this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
1919 break;
1920 case "complete":
1921 this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
1922 break;
1923 case "segmentStart":
1924 this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
1925 break;
1926 case "destroy":
1927 this.triggerEvent(name, new BMDestroyEvent(name, this));
1928 break;
1929 default: this.triggerEvent(name);
1930 }
1931 if (name === "enterFrame" && this.onEnterFrame) this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
1932 if (name === "loopComplete" && this.onLoopComplete) this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
1933 if (name === "complete" && this.onComplete) this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
1934 if (name === "segmentStart" && this.onSegmentStart) this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
1935 if (name === "destroy" && this.onDestroy) this.onDestroy.call(this, new BMDestroyEvent(name, this));
1936 };
1937 AnimationItem.prototype.triggerRenderFrameError = function(nativeError) {
1938 var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
1939 this.triggerEvent("error", error);
1940 if (this.onError) this.onError.call(this, error);
1941 };
1942 AnimationItem.prototype.triggerConfigError = function(nativeError) {
1943 var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
1944 this.triggerEvent("error", error);
1945 if (this.onError) this.onError.call(this, error);
1946 };
1947 var animationManager = function() {
1948 var moduleOb = {};
1949 var registeredAnimations = [];
1950 var initTime = 0;
1951 var len = 0;
1952 var playingAnimationsNum = 0;
1953 var _stopped = true;
1954 var _isFrozen = false;
1955 function removeElement(ev) {
1956 var i = 0;
1957 var animItem = ev.target;
1958 while (i < len) {
1959 if (registeredAnimations[i].animation === animItem) {
1960 registeredAnimations.splice(i, 1);
1961 i -= 1;
1962 len -= 1;
1963 if (!animItem.isPaused) subtractPlayingCount();
1964 }
1965 i += 1;
1966 }
1967 }
1968 function registerAnimation(element, animationData) {
1969 if (!element) return null;
1970 var i = 0;
1971 while (i < len) {
1972 if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) return registeredAnimations[i].animation;
1973 i += 1;
1974 }
1975 var animItem = new AnimationItem();
1976 setupAnimation(animItem, element);
1977 animItem.setData(element, animationData);
1978 return animItem;
1979 }
1980 function getRegisteredAnimations() {
1981 var i;
1982 var lenAnims = registeredAnimations.length;
1983 var animations = [];
1984 for (i = 0; i < lenAnims; i += 1) animations.push(registeredAnimations[i].animation);
1985 return animations;
1986 }
1987 function addPlayingCount() {
1988 playingAnimationsNum += 1;
1989 activate();
1990 }
1991 function subtractPlayingCount() {
1992 playingAnimationsNum -= 1;
1993 }
1994 function setupAnimation(animItem, element) {
1995 animItem.addEventListener("destroy", removeElement);
1996 animItem.addEventListener("_active", addPlayingCount);
1997 animItem.addEventListener("_idle", subtractPlayingCount);
1998 registeredAnimations.push({
1999 elem: element,
2000 animation: animItem
2001 });
2002 len += 1;
2003 }
2004 function loadAnimation(params) {
2005 var animItem = new AnimationItem();
2006 setupAnimation(animItem, null);
2007 animItem.setParams(params);
2008 return animItem;
2009 }
2010 function setSpeed(val, animation) {
2011 var i;
2012 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.setSpeed(val, animation);
2013 }
2014 function setDirection(val, animation) {
2015 var i;
2016 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.setDirection(val, animation);
2017 }
2018 function play(animation) {
2019 var i;
2020 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.play(animation);
2021 }
2022 function resume(nowTime) {
2023 var elapsedTime = nowTime - initTime;
2024 var i;
2025 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.advanceTime(elapsedTime);
2026 initTime = nowTime;
2027 if (playingAnimationsNum && !_isFrozen) window.requestAnimationFrame(resume);
2028 else _stopped = true;
2029 }
2030 function first(nowTime) {
2031 initTime = nowTime;
2032 window.requestAnimationFrame(resume);
2033 }
2034 function pause(animation) {
2035 var i;
2036 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.pause(animation);
2037 }
2038 function goToAndStop(value, isFrame, animation) {
2039 var i;
2040 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
2041 }
2042 function stop(animation) {
2043 var i;
2044 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.stop(animation);
2045 }
2046 function togglePause(animation) {
2047 var i;
2048 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.togglePause(animation);
2049 }
2050 function destroy(animation) {
2051 var i;
2052 for (i = len - 1; i >= 0; i -= 1) registeredAnimations[i].animation.destroy(animation);
2053 }
2054 function searchAnimations(animationData, standalone, renderer) {
2055 var animElements = [].concat([].slice.call(document.getElementsByClassName("lottie")), [].slice.call(document.getElementsByClassName("bodymovin")));
2056 var i;
2057 var lenAnims = animElements.length;
2058 for (i = 0; i < lenAnims; i += 1) {
2059 if (renderer) animElements[i].setAttribute("data-bm-type", renderer);
2060 registerAnimation(animElements[i], animationData);
2061 }
2062 if (standalone && lenAnims === 0) {
2063 if (!renderer) renderer = "svg";
2064 var body = document.getElementsByTagName("body")[0];
2065 body.innerText = "";
2066 var div = createTag("div");
2067 div.style.width = "100%";
2068 div.style.height = "100%";
2069 div.setAttribute("data-bm-type", renderer);
2070 body.appendChild(div);
2071 registerAnimation(div, animationData);
2072 }
2073 }
2074 function resize() {
2075 var i;
2076 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.resize();
2077 }
2078 function activate() {
2079 if (!_isFrozen && playingAnimationsNum) {
2080 if (_stopped) {
2081 window.requestAnimationFrame(first);
2082 _stopped = false;
2083 }
2084 }
2085 }
2086 function freeze() {
2087 _isFrozen = true;
2088 }
2089 function unfreeze() {
2090 _isFrozen = false;
2091 activate();
2092 }
2093 function setVolume(val, animation) {
2094 var i;
2095 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.setVolume(val, animation);
2096 }
2097 function mute(animation) {
2098 var i;
2099 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.mute(animation);
2100 }
2101 function unmute(animation) {
2102 var i;
2103 for (i = 0; i < len; i += 1) registeredAnimations[i].animation.unmute(animation);
2104 }
2105 moduleOb.registerAnimation = registerAnimation;
2106 moduleOb.loadAnimation = loadAnimation;
2107 moduleOb.setSpeed = setSpeed;
2108 moduleOb.setDirection = setDirection;
2109 moduleOb.play = play;
2110 moduleOb.pause = pause;
2111 moduleOb.stop = stop;
2112 moduleOb.togglePause = togglePause;
2113 moduleOb.searchAnimations = searchAnimations;
2114 moduleOb.resize = resize;
2115 moduleOb.goToAndStop = goToAndStop;
2116 moduleOb.destroy = destroy;
2117 moduleOb.freeze = freeze;
2118 moduleOb.unfreeze = unfreeze;
2119 moduleOb.setVolume = setVolume;
2120 moduleOb.mute = mute;
2121 moduleOb.unmute = unmute;
2122 moduleOb.getRegisteredAnimations = getRegisteredAnimations;
2123 return moduleOb;
2124 }();
2125 var BezierFactory = function() {
2126 /**
2127 * BezierEasing - use bezier curve for transition easing function
2128 * by Gaëtan Renaudeau 2014 - 2015 – MIT License
2129 *
2130 * Credits: is based on Firefox's nsSMILKeySpline.cpp
2131 * Usage:
2132 * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
2133 * spline.get(x) => returns the easing value | x must be in [0, 1] range
2134 *
2135 */
2136 var ob = {};
2137 ob.getBezierEasing = getBezierEasing;
2138 var beziers = {};
2139 function getBezierEasing(a, b, c, d, nm) {
2140 var str = nm || ("bez_" + a + "_" + b + "_" + c + "_" + d).replace(/\./g, "p");
2141 if (beziers[str]) return beziers[str];
2142 var bezEasing = new BezierEasing([
2143 a,
2144 b,
2145 c,
2146 d
2147 ]);
2148 beziers[str] = bezEasing;
2149 return bezEasing;
2150 }
2151 var NEWTON_ITERATIONS = 4;
2152 var NEWTON_MIN_SLOPE = .001;
2153 var SUBDIVISION_PRECISION = 1e-7;
2154 var SUBDIVISION_MAX_ITERATIONS = 10;
2155 var kSplineTableSize = 11;
2156 var kSampleStepSize = 1 / (kSplineTableSize - 1);
2157 var float32ArraySupported = typeof Float32Array === "function";
2158 function A(aA1, aA2) {
2159 return 1 - 3 * aA2 + 3 * aA1;
2160 }
2161 function B(aA1, aA2) {
2162 return 3 * aA2 - 6 * aA1;
2163 }
2164 function C(aA1) {
2165 return 3 * aA1;
2166 }
2167 function calcBezier(aT, aA1, aA2) {
2168 return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
2169 }
2170 function getSlope(aT, aA1, aA2) {
2171 return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
2172 }
2173 function binarySubdivide(aX, aA, aB, mX1, mX2) {
2174 var currentX;
2175 var currentT;
2176 var i = 0;
2177 do {
2178 currentT = aA + (aB - aA) / 2;
2179 currentX = calcBezier(currentT, mX1, mX2) - aX;
2180 if (currentX > 0) aB = currentT;
2181 else aA = currentT;
2182 } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
2183 return currentT;
2184 }
2185 function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
2186 for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
2187 var currentSlope = getSlope(aGuessT, mX1, mX2);
2188 if (currentSlope === 0) return aGuessT;
2189 var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
2190 aGuessT -= currentX / currentSlope;
2191 }
2192 return aGuessT;
2193 }
2194 /**
2195 * points is an array of [ mX1, mY1, mX2, mY2 ]
2196 */
2197 function BezierEasing(points) {
2198 this._p = points;
2199 this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
2200 this._precomputed = false;
2201 this.get = this.get.bind(this);
2202 }
2203 BezierEasing.prototype = {
2204 get: function get(x) {
2205 var mX1 = this._p[0];
2206 var mY1 = this._p[1];
2207 var mX2 = this._p[2];
2208 var mY2 = this._p[3];
2209 if (!this._precomputed) this._precompute();
2210 if (mX1 === mY1 && mX2 === mY2) return x;
2211 if (x === 0) return 0;
2212 if (x === 1) return 1;
2213 return calcBezier(this._getTForX(x), mY1, mY2);
2214 },
2215 _precompute: function _precompute() {
2216 var mX1 = this._p[0];
2217 var mY1 = this._p[1];
2218 var mX2 = this._p[2];
2219 var mY2 = this._p[3];
2220 this._precomputed = true;
2221 if (mX1 !== mY1 || mX2 !== mY2) this._calcSampleValues();
2222 },
2223 _calcSampleValues: function _calcSampleValues() {
2224 var mX1 = this._p[0];
2225 var mX2 = this._p[2];
2226 for (var i = 0; i < kSplineTableSize; ++i) this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
2227 },
2228 /**
2229 * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
2230 */
2231 _getTForX: function _getTForX(aX) {
2232 var mX1 = this._p[0];
2233 var mX2 = this._p[2];
2234 var mSampleValues = this._mSampleValues;
2235 var intervalStart = 0;
2236 var currentSample = 1;
2237 var lastSample = kSplineTableSize - 1;
2238 for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
2239 --currentSample;
2240 var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
2241 var guessForT = intervalStart + dist * kSampleStepSize;
2242 var initialSlope = getSlope(guessForT, mX1, mX2);
2243 if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
2244 if (initialSlope === 0) return guessForT;
2245 return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
2246 }
2247 };
2248 return ob;
2249 }();
2250 var pooling = function() {
2251 function _double(arr) {
2252 return arr.concat(createSizedArray(arr.length));
2253 }
2254 return { "double": _double };
2255 }();
2256 var poolFactory = function() {
2257 return function(initialLength, _create, _release) {
2258 var _length = 0;
2259 var _maxLength = initialLength;
2260 var pool = createSizedArray(_maxLength);
2261 var ob = {
2262 newElement,
2263 release
2264 };
2265 function newElement() {
2266 var element;
2267 if (_length) {
2268 _length -= 1;
2269 element = pool[_length];
2270 } else element = _create();
2271 return element;
2272 }
2273 function release(element) {
2274 if (_length === _maxLength) {
2275 pool = pooling["double"](pool);
2276 _maxLength *= 2;
2277 }
2278 if (_release) _release(element);
2279 pool[_length] = element;
2280 _length += 1;
2281 }
2282 return ob;
2283 };
2284 }();
2285 var bezierLengthPool = function() {
2286 function create() {
2287 return {
2288 addedLength: 0,
2289 percents: createTypedArray("float32", getDefaultCurveSegments()),
2290 lengths: createTypedArray("float32", getDefaultCurveSegments())
2291 };
2292 }
2293 return poolFactory(8, create);
2294 }();
2295 var segmentsLengthPool = function() {
2296 function create() {
2297 return {
2298 lengths: [],
2299 totalLength: 0
2300 };
2301 }
2302 function release(element) {
2303 var i;
2304 var len = element.lengths.length;
2305 for (i = 0; i < len; i += 1) bezierLengthPool.release(element.lengths[i]);
2306 element.lengths.length = 0;
2307 }
2308 return poolFactory(8, create, release);
2309 }();
2310 function bezFunction() {
2311 var math = Math;
2312 function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
2313 var det1 = x1 * y2 + y1 * x3 + x2 * y3 - x3 * y2 - y3 * x1 - x2 * y1;
2314 return det1 > -.001 && det1 < .001;
2315 }
2316 function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
2317 if (z1 === 0 && z2 === 0 && z3 === 0) return pointOnLine2D(x1, y1, x2, y2, x3, y3);
2318 var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
2319 var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
2320 var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
2321 var diffDist;
2322 if (dist1 > dist2) if (dist1 > dist3) diffDist = dist1 - dist2 - dist3;
2323 else diffDist = dist3 - dist2 - dist1;
2324 else if (dist3 > dist2) diffDist = dist3 - dist2 - dist1;
2325 else diffDist = dist2 - dist1 - dist3;
2326 return diffDist > -1e-4 && diffDist < 1e-4;
2327 }
2328 var getBezierLength = function() {
2329 return function(pt1, pt2, pt3, pt4) {
2330 var curveSegments = getDefaultCurveSegments();
2331 var k;
2332 var i;
2333 var len;
2334 var ptCoord;
2335 var perc;
2336 var addedLength = 0;
2337 var ptDistance;
2338 var point = [];
2339 var lastPoint = [];
2340 var lengthData = bezierLengthPool.newElement();
2341 len = pt3.length;
2342 for (k = 0; k < curveSegments; k += 1) {
2343 perc = k / (curveSegments - 1);
2344 ptDistance = 0;
2345 for (i = 0; i < len; i += 1) {
2346 ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * pt3[i] + 3 * (1 - perc) * bmPow(perc, 2) * pt4[i] + bmPow(perc, 3) * pt2[i];
2347 point[i] = ptCoord;
2348 if (lastPoint[i] !== null) ptDistance += bmPow(point[i] - lastPoint[i], 2);
2349 lastPoint[i] = point[i];
2350 }
2351 if (ptDistance) {
2352 ptDistance = bmSqrt(ptDistance);
2353 addedLength += ptDistance;
2354 }
2355 lengthData.percents[k] = perc;
2356 lengthData.lengths[k] = addedLength;
2357 }
2358 lengthData.addedLength = addedLength;
2359 return lengthData;
2360 };
2361 }();
2362 function getSegmentsLength(shapeData) {
2363 var segmentsLength = segmentsLengthPool.newElement();
2364 var closed = shapeData.c;
2365 var pathV = shapeData.v;
2366 var pathO = shapeData.o;
2367 var pathI = shapeData.i;
2368 var i;
2369 var len = shapeData._length;
2370 var lengths = segmentsLength.lengths;
2371 var totalLength = 0;
2372 for (i = 0; i < len - 1; i += 1) {
2373 lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
2374 totalLength += lengths[i].addedLength;
2375 }
2376 if (closed && len) {
2377 lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
2378 totalLength += lengths[i].addedLength;
2379 }
2380 segmentsLength.totalLength = totalLength;
2381 return segmentsLength;
2382 }
2383 function BezierData(length) {
2384 this.segmentLength = 0;
2385 this.points = new Array(length);
2386 }
2387 function PointData(partial, point) {
2388 this.partialLength = partial;
2389 this.point = point;
2390 }
2391 var buildBezierData = function() {
2392 var storedData = {};
2393 return function(pt1, pt2, pt3, pt4) {
2394 var bezierName = (pt1[0] + "_" + pt1[1] + "_" + pt2[0] + "_" + pt2[1] + "_" + pt3[0] + "_" + pt3[1] + "_" + pt4[0] + "_" + pt4[1]).replace(/\./g, "p");
2395 if (!storedData[bezierName]) {
2396 var curveSegments = getDefaultCurveSegments();
2397 var k;
2398 var i;
2399 var len;
2400 var ptCoord;
2401 var perc;
2402 var addedLength = 0;
2403 var ptDistance;
2404 var point;
2405 var lastPoint = null;
2406 if (pt1.length === 2 && (pt1[0] !== pt2[0] || pt1[1] !== pt2[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt1[0] + pt3[0], pt1[1] + pt3[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt2[0] + pt4[0], pt2[1] + pt4[1])) curveSegments = 2;
2407 var bezierData = new BezierData(curveSegments);
2408 len = pt3.length;
2409 for (k = 0; k < curveSegments; k += 1) {
2410 point = createSizedArray(len);
2411 perc = k / (curveSegments - 1);
2412 ptDistance = 0;
2413 for (i = 0; i < len; i += 1) {
2414 ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
2415 point[i] = ptCoord;
2416 if (lastPoint !== null) ptDistance += bmPow(point[i] - lastPoint[i], 2);
2417 }
2418 ptDistance = bmSqrt(ptDistance);
2419 addedLength += ptDistance;
2420 bezierData.points[k] = new PointData(ptDistance, point);
2421 lastPoint = point;
2422 }
2423 bezierData.segmentLength = addedLength;
2424 storedData[bezierName] = bezierData;
2425 }
2426 return storedData[bezierName];
2427 };
2428 }();
2429 function getDistancePerc(perc, bezierData) {
2430 var percents = bezierData.percents;
2431 var lengths = bezierData.lengths;
2432 var len = percents.length;
2433 var initPos = bmFloor((len - 1) * perc);
2434 var lengthPos = perc * bezierData.addedLength;
2435 var lPerc = 0;
2436 if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) return percents[initPos];
2437 var dir = lengths[initPos] > lengthPos ? -1 : 1;
2438 var flag = true;
2439 while (flag) {
2440 if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
2441 lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
2442 flag = false;
2443 } else initPos += dir;
2444 if (initPos < 0 || initPos >= len - 1) {
2445 if (initPos === len - 1) return percents[initPos];
2446 flag = false;
2447 }
2448 }
2449 return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
2450 }
2451 function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
2452 var t1 = getDistancePerc(percent, bezierData);
2453 var u1 = 1 - t1;
2454 return [math.round((u1 * u1 * u1 * pt1[0] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[0] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[0] + t1 * t1 * t1 * pt2[0]) * 1e3) / 1e3, math.round((u1 * u1 * u1 * pt1[1] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[1] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[1] + t1 * t1 * t1 * pt2[1]) * 1e3) / 1e3];
2455 }
2456 var bezierSegmentPoints = createTypedArray("float32", 8);
2457 function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
2458 if (startPerc < 0) startPerc = 0;
2459 else if (startPerc > 1) startPerc = 1;
2460 var t0 = getDistancePerc(startPerc, bezierData);
2461 endPerc = endPerc > 1 ? 1 : endPerc;
2462 var t1 = getDistancePerc(endPerc, bezierData);
2463 var i;
2464 var len = pt1.length;
2465 var u0 = 1 - t0;
2466 var u1 = 1 - t1;
2467 var u0u0u0 = u0 * u0 * u0;
2468 var t0u0u0_3 = t0 * u0 * u0 * 3;
2469 var t0t0u0_3 = t0 * t0 * u0 * 3;
2470 var t0t0t0 = t0 * t0 * t0;
2471 var u0u0u1 = u0 * u0 * u1;
2472 var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1;
2473 var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1;
2474 var t0t0t1 = t0 * t0 * t1;
2475 var u0u1u1 = u0 * u1 * u1;
2476 var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1;
2477 var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1;
2478 var t0t1t1 = t0 * t1 * t1;
2479 var u1u1u1 = u1 * u1 * u1;
2480 var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1;
2481 var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1;
2482 var t1t1t1 = t1 * t1 * t1;
2483 for (i = 0; i < len; i += 1) {
2484 bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1e3) / 1e3;
2485 bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1e3) / 1e3;
2486 bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1e3) / 1e3;
2487 bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1e3) / 1e3;
2488 }
2489 return bezierSegmentPoints;
2490 }
2491 return {
2492 getSegmentsLength,
2493 getNewSegment,
2494 getPointInSegment,
2495 buildBezierData,
2496 pointOnLine2D,
2497 pointOnLine3D
2498 };
2499 }
2500 var bez = bezFunction();
2501 var initFrame = initialDefaultFrame;
2502 var mathAbs = Math.abs;
2503 function interpolateValue(frameNum, caching) {
2504 var offsetTime = this.offsetTime;
2505 var newValue;
2506 if (this.propType === "multidimensional") newValue = createTypedArray("float32", this.pv.length);
2507 var iterationIndex = caching.lastIndex;
2508 var i = iterationIndex;
2509 var len = this.keyframes.length - 1;
2510 var flag = true;
2511 var keyData;
2512 var nextKeyData;
2513 var keyframeMetadata;
2514 while (flag) {
2515 keyData = this.keyframes[i];
2516 nextKeyData = this.keyframes[i + 1];
2517 if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
2518 if (keyData.h) keyData = nextKeyData;
2519 iterationIndex = 0;
2520 break;
2521 }
2522 if (nextKeyData.t - offsetTime > frameNum) {
2523 iterationIndex = i;
2524 break;
2525 }
2526 if (i < len - 1) i += 1;
2527 else {
2528 iterationIndex = 0;
2529 flag = false;
2530 }
2531 }
2532 keyframeMetadata = this.keyframesMetadata[i] || {};
2533 var k;
2534 var kLen;
2535 var perc;
2536 var jLen;
2537 var j;
2538 var fnc;
2539 var nextKeyTime = nextKeyData.t - offsetTime;
2540 var keyTime = keyData.t - offsetTime;
2541 var endValue;
2542 if (keyData.to) {
2543 if (!keyframeMetadata.bezierData) keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
2544 var bezierData = keyframeMetadata.bezierData;
2545 if (frameNum >= nextKeyTime || frameNum < keyTime) {
2546 var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
2547 kLen = bezierData.points[ind].point.length;
2548 for (k = 0; k < kLen; k += 1) newValue[k] = bezierData.points[ind].point[k];
2549 } else {
2550 if (keyframeMetadata.__fnct) fnc = keyframeMetadata.__fnct;
2551 else {
2552 fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
2553 keyframeMetadata.__fnct = fnc;
2554 }
2555 perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
2556 var distanceInLine = bezierData.segmentLength * perc;
2557 var segmentPerc;
2558 var addedLength = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastAddedLength : 0;
2559 j = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastPoint : 0;
2560 flag = true;
2561 jLen = bezierData.points.length;
2562 while (flag) {
2563 addedLength += bezierData.points[j].partialLength;
2564 if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
2565 kLen = bezierData.points[j].point.length;
2566 for (k = 0; k < kLen; k += 1) newValue[k] = bezierData.points[j].point[k];
2567 break;
2568 } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
2569 segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
2570 kLen = bezierData.points[j].point.length;
2571 for (k = 0; k < kLen; k += 1) newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
2572 break;
2573 }
2574 if (j < jLen - 1) j += 1;
2575 else flag = false;
2576 }
2577 caching._lastPoint = j;
2578 caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
2579 caching._lastKeyframeIndex = i;
2580 }
2581 } else {
2582 var outX;
2583 var outY;
2584 var inX;
2585 var inY;
2586 var keyValue;
2587 len = keyData.s.length;
2588 endValue = nextKeyData.s || keyData.e;
2589 if (this.sh && keyData.h !== 1) if (frameNum >= nextKeyTime) {
2590 newValue[0] = endValue[0];
2591 newValue[1] = endValue[1];
2592 newValue[2] = endValue[2];
2593 } else if (frameNum <= keyTime) {
2594 newValue[0] = keyData.s[0];
2595 newValue[1] = keyData.s[1];
2596 newValue[2] = keyData.s[2];
2597 } else {
2598 var quatStart = createQuaternion(keyData.s);
2599 var quatEnd = createQuaternion(endValue);
2600 var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
2601 quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
2602 }
2603 else for (i = 0; i < len; i += 1) {
2604 if (keyData.h !== 1) if (frameNum >= nextKeyTime) perc = 1;
2605 else if (frameNum < keyTime) perc = 0;
2606 else {
2607 if (keyData.o.x.constructor === Array) {
2608 if (!keyframeMetadata.__fnct) keyframeMetadata.__fnct = [];
2609 if (!keyframeMetadata.__fnct[i]) {
2610 outX = keyData.o.x[i] === void 0 ? keyData.o.x[0] : keyData.o.x[i];
2611 outY = keyData.o.y[i] === void 0 ? keyData.o.y[0] : keyData.o.y[i];
2612 inX = keyData.i.x[i] === void 0 ? keyData.i.x[0] : keyData.i.x[i];
2613 inY = keyData.i.y[i] === void 0 ? keyData.i.y[0] : keyData.i.y[i];
2614 fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
2615 keyframeMetadata.__fnct[i] = fnc;
2616 } else fnc = keyframeMetadata.__fnct[i];
2617 } else if (!keyframeMetadata.__fnct) {
2618 outX = keyData.o.x;
2619 outY = keyData.o.y;
2620 inX = keyData.i.x;
2621 inY = keyData.i.y;
2622 fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
2623 keyData.keyframeMetadata = fnc;
2624 } else fnc = keyframeMetadata.__fnct;
2625 perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
2626 }
2627 endValue = nextKeyData.s || keyData.e;
2628 keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
2629 if (this.propType === "multidimensional") newValue[i] = keyValue;
2630 else newValue = keyValue;
2631 }
2632 }
2633 caching.lastIndex = iterationIndex;
2634 return newValue;
2635 }
2636 function slerp(a, b, t) {
2637 var out = [];
2638 var ax = a[0];
2639 var ay = a[1];
2640 var az = a[2];
2641 var aw = a[3];
2642 var bx = b[0];
2643 var by = b[1];
2644 var bz = b[2];
2645 var bw = b[3];
2646 var omega;
2647 var cosom;
2648 var sinom;
2649 var scale0;
2650 var scale1;
2651 cosom = ax * bx + ay * by + az * bz + aw * bw;
2652 if (cosom < 0) {
2653 cosom = -cosom;
2654 bx = -bx;
2655 by = -by;
2656 bz = -bz;
2657 bw = -bw;
2658 }
2659 if (1 - cosom > 1e-6) {
2660 omega = Math.acos(cosom);
2661 sinom = Math.sin(omega);
2662 scale0 = Math.sin((1 - t) * omega) / sinom;
2663 scale1 = Math.sin(t * omega) / sinom;
2664 } else {
2665 scale0 = 1 - t;
2666 scale1 = t;
2667 }
2668 out[0] = scale0 * ax + scale1 * bx;
2669 out[1] = scale0 * ay + scale1 * by;
2670 out[2] = scale0 * az + scale1 * bz;
2671 out[3] = scale0 * aw + scale1 * bw;
2672 return out;
2673 }
2674 function quaternionToEuler(out, quat) {
2675 var qx = quat[0];
2676 var qy = quat[1];
2677 var qz = quat[2];
2678 var qw = quat[3];
2679 var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
2680 var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
2681 var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
2682 out[0] = heading / degToRads;
2683 out[1] = attitude / degToRads;
2684 out[2] = bank / degToRads;
2685 }
2686 function createQuaternion(values) {
2687 var heading = values[0] * degToRads;
2688 var attitude = values[1] * degToRads;
2689 var bank = values[2] * degToRads;
2690 var c1 = Math.cos(heading / 2);
2691 var c2 = Math.cos(attitude / 2);
2692 var c3 = Math.cos(bank / 2);
2693 var s1 = Math.sin(heading / 2);
2694 var s2 = Math.sin(attitude / 2);
2695 var s3 = Math.sin(bank / 2);
2696 var w = c1 * c2 * c3 - s1 * s2 * s3;
2697 return [
2698 s1 * s2 * c3 + c1 * c2 * s3,
2699 s1 * c2 * c3 + c1 * s2 * s3,
2700 c1 * s2 * c3 - s1 * c2 * s3,
2701 w
2702 ];
2703 }
2704 function getValueAtCurrentTime() {
2705 var frameNum = this.comp.renderedFrame - this.offsetTime;
2706 var initTime = this.keyframes[0].t - this.offsetTime;
2707 var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
2708 if (!(frameNum === this._caching.lastFrame || this._caching.lastFrame !== initFrame && (this._caching.lastFrame >= endTime && frameNum >= endTime || this._caching.lastFrame < initTime && frameNum < initTime))) {
2709 if (this._caching.lastFrame >= frameNum) {
2710 this._caching._lastKeyframeIndex = -1;
2711 this._caching.lastIndex = 0;
2712 }
2713 var renderResult = this.interpolateValue(frameNum, this._caching);
2714 this.pv = renderResult;
2715 }
2716 this._caching.lastFrame = frameNum;
2717 return this.pv;
2718 }
2719 function setVValue(val) {
2720 var multipliedValue;
2721 if (this.propType === "unidimensional") {
2722 multipliedValue = val * this.mult;
2723 if (mathAbs(this.v - multipliedValue) > 1e-5) {
2724 this.v = multipliedValue;
2725 this._mdf = true;
2726 }
2727 } else {
2728 var i = 0;
2729 var len = this.v.length;
2730 while (i < len) {
2731 multipliedValue = val[i] * this.mult;
2732 if (mathAbs(this.v[i] - multipliedValue) > 1e-5) {
2733 this.v[i] = multipliedValue;
2734 this._mdf = true;
2735 }
2736 i += 1;
2737 }
2738 }
2739 }
2740 function processEffectsSequence() {
2741 if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) return;
2742 if (this.lock) {
2743 this.setVValue(this.pv);
2744 return;
2745 }
2746 this.lock = true;
2747 this._mdf = this._isFirstFrame;
2748 var i;
2749 var len = this.effectsSequence.length;
2750 var finalValue = this.kf ? this.pv : this.data.k;
2751 for (i = 0; i < len; i += 1) finalValue = this.effectsSequence[i](finalValue);
2752 this.setVValue(finalValue);
2753 this._isFirstFrame = false;
2754 this.lock = false;
2755 this.frameId = this.elem.globalData.frameId;
2756 }
2757 function addEffect(effectFunction) {
2758 this.effectsSequence.push(effectFunction);
2759 this.container.addDynamicProperty(this);
2760 }
2761 function ValueProperty(elem, data, mult, container) {
2762 this.propType = "unidimensional";
2763 this.mult = mult || 1;
2764 this.data = data;
2765 this.v = mult ? data.k * mult : data.k;
2766 this.pv = data.k;
2767 this._mdf = false;
2768 this.elem = elem;
2769 this.container = container;
2770 this.comp = elem.comp;
2771 this.k = false;
2772 this.kf = false;
2773 this.vel = 0;
2774 this.effectsSequence = [];
2775 this._isFirstFrame = true;
2776 this.getValue = processEffectsSequence;
2777 this.setVValue = setVValue;
2778 this.addEffect = addEffect;
2779 }
2780 function MultiDimensionalProperty(elem, data, mult, container) {
2781 this.propType = "multidimensional";
2782 this.mult = mult || 1;
2783 this.data = data;
2784 this._mdf = false;
2785 this.elem = elem;
2786 this.container = container;
2787 this.comp = elem.comp;
2788 this.k = false;
2789 this.kf = false;
2790 this.frameId = -1;
2791 var i;
2792 var len = data.k.length;
2793 this.v = createTypedArray("float32", len);
2794 this.pv = createTypedArray("float32", len);
2795 this.vel = createTypedArray("float32", len);
2796 for (i = 0; i < len; i += 1) {
2797 this.v[i] = data.k[i] * this.mult;
2798 this.pv[i] = data.k[i];
2799 }
2800 this._isFirstFrame = true;
2801 this.effectsSequence = [];
2802 this.getValue = processEffectsSequence;
2803 this.setVValue = setVValue;
2804 this.addEffect = addEffect;
2805 }
2806 function KeyframedValueProperty(elem, data, mult, container) {
2807 this.propType = "unidimensional";
2808 this.keyframes = data.k;
2809 this.keyframesMetadata = [];
2810 this.offsetTime = elem.data.st;
2811 this.frameId = -1;
2812 this._caching = {
2813 lastFrame: initFrame,
2814 lastIndex: 0,
2815 value: 0,
2816 _lastKeyframeIndex: -1
2817 };
2818 this.k = true;
2819 this.kf = true;
2820 this.data = data;
2821 this.mult = mult || 1;
2822 this.elem = elem;
2823 this.container = container;
2824 this.comp = elem.comp;
2825 this.v = initFrame;
2826 this.pv = initFrame;
2827 this._isFirstFrame = true;
2828 this.getValue = processEffectsSequence;
2829 this.setVValue = setVValue;
2830 this.interpolateValue = interpolateValue;
2831 this.effectsSequence = [getValueAtCurrentTime.bind(this)];
2832 this.addEffect = addEffect;
2833 }
2834 function KeyframedMultidimensionalProperty(elem, data, mult, container) {
2835 this.propType = "multidimensional";
2836 var i;
2837 var len = data.k.length;
2838 var s;
2839 var e;
2840 var to;
2841 var ti;
2842 for (i = 0; i < len - 1; i += 1) if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
2843 s = data.k[i].s;
2844 e = data.k[i + 1].s;
2845 to = data.k[i].to;
2846 ti = data.k[i].ti;
2847 if (s.length === 2 && !(s[0] === e[0] && s[1] === e[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], s[0] + to[0], s[1] + to[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], e[0] + ti[0], e[1] + ti[1]) || s.length === 3 && !(s[0] === e[0] && s[1] === e[1] && s[2] === e[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], s[0] + to[0], s[1] + to[1], s[2] + to[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], e[0] + ti[0], e[1] + ti[1], e[2] + ti[2])) {
2848 data.k[i].to = null;
2849 data.k[i].ti = null;
2850 }
2851 if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
2852 if (s.length === 2 || s[2] === e[2] && to[2] === 0 && ti[2] === 0) {
2853 data.k[i].to = null;
2854 data.k[i].ti = null;
2855 }
2856 }
2857 }
2858 this.effectsSequence = [getValueAtCurrentTime.bind(this)];
2859 this.data = data;
2860 this.keyframes = data.k;
2861 this.keyframesMetadata = [];
2862 this.offsetTime = elem.data.st;
2863 this.k = true;
2864 this.kf = true;
2865 this._isFirstFrame = true;
2866 this.mult = mult || 1;
2867 this.elem = elem;
2868 this.container = container;
2869 this.comp = elem.comp;
2870 this.getValue = processEffectsSequence;
2871 this.setVValue = setVValue;
2872 this.interpolateValue = interpolateValue;
2873 this.frameId = -1;
2874 var arrLen = data.k[0].s.length;
2875 this.v = createTypedArray("float32", arrLen);
2876 this.pv = createTypedArray("float32", arrLen);
2877 for (i = 0; i < arrLen; i += 1) {
2878 this.v[i] = initFrame;
2879 this.pv[i] = initFrame;
2880 }
2881 this._caching = {
2882 lastFrame: initFrame,
2883 lastIndex: 0,
2884 value: createTypedArray("float32", arrLen)
2885 };
2886 this.addEffect = addEffect;
2887 }
2888 var PropertyFactory = function() {
2889 function getProp(elem, data, type, mult, container) {
2890 if (data.sid) data = elem.globalData.slotManager.getProp(data);
2891 var p;
2892 if (!data.k.length) p = new ValueProperty(elem, data, mult, container);
2893 else if (typeof data.k[0] === "number") p = new MultiDimensionalProperty(elem, data, mult, container);
2894 else switch (type) {
2895 case 0:
2896 p = new KeyframedValueProperty(elem, data, mult, container);
2897 break;
2898 case 1:
2899 p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
2900 break;
2901 default: break;
2902 }
2903 if (p.effectsSequence.length) container.addDynamicProperty(p);
2904 return p;
2905 }
2906 return { getProp };
2907 }();
2908 function DynamicPropertyContainer() {}
2909 DynamicPropertyContainer.prototype = {
2910 addDynamicProperty: function addDynamicProperty(prop) {
2911 if (this.dynamicProperties.indexOf(prop) === -1) {
2912 this.dynamicProperties.push(prop);
2913 this.container.addDynamicProperty(this);
2914 this._isAnimated = true;
2915 }
2916 },
2917 iterateDynamicProperties: function iterateDynamicProperties() {
2918 this._mdf = false;
2919 var i;
2920 var len = this.dynamicProperties.length;
2921 for (i = 0; i < len; i += 1) {
2922 this.dynamicProperties[i].getValue();
2923 if (this.dynamicProperties[i]._mdf) this._mdf = true;
2924 }
2925 },
2926 initDynamicPropertyContainer: function initDynamicPropertyContainer(container) {
2927 this.container = container;
2928 this.dynamicProperties = [];
2929 this._mdf = false;
2930 this._isAnimated = false;
2931 }
2932 };
2933 var pointPool = function() {
2934 function create() {
2935 return createTypedArray("float32", 2);
2936 }
2937 return poolFactory(8, create);
2938 }();
2939 function ShapePath() {
2940 this.c = false;
2941 this._length = 0;
2942 this._maxLength = 8;
2943 this.v = createSizedArray(this._maxLength);
2944 this.o = createSizedArray(this._maxLength);
2945 this.i = createSizedArray(this._maxLength);
2946 }
2947 ShapePath.prototype.setPathData = function(closed, len) {
2948 this.c = closed;
2949 this.setLength(len);
2950 var i = 0;
2951 while (i < len) {
2952 this.v[i] = pointPool.newElement();
2953 this.o[i] = pointPool.newElement();
2954 this.i[i] = pointPool.newElement();
2955 i += 1;
2956 }
2957 };
2958 ShapePath.prototype.setLength = function(len) {
2959 while (this._maxLength < len) this.doubleArrayLength();
2960 this._length = len;
2961 };
2962 ShapePath.prototype.doubleArrayLength = function() {
2963 this.v = this.v.concat(createSizedArray(this._maxLength));
2964 this.i = this.i.concat(createSizedArray(this._maxLength));
2965 this.o = this.o.concat(createSizedArray(this._maxLength));
2966 this._maxLength *= 2;
2967 };
2968 ShapePath.prototype.setXYAt = function(x, y, type, pos, replace) {
2969 var arr;
2970 this._length = Math.max(this._length, pos + 1);
2971 if (this._length >= this._maxLength) this.doubleArrayLength();
2972 switch (type) {
2973 case "v":
2974 arr = this.v;
2975 break;
2976 case "i":
2977 arr = this.i;
2978 break;
2979 case "o":
2980 arr = this.o;
2981 break;
2982 default:
2983 arr = [];
2984 break;
2985 }
2986 if (!arr[pos] || arr[pos] && !replace) arr[pos] = pointPool.newElement();
2987 arr[pos][0] = x;
2988 arr[pos][1] = y;
2989 };
2990 ShapePath.prototype.setTripleAt = function(vX, vY, oX, oY, iX, iY, pos, replace) {
2991 this.setXYAt(vX, vY, "v", pos, replace);
2992 this.setXYAt(oX, oY, "o", pos, replace);
2993 this.setXYAt(iX, iY, "i", pos, replace);
2994 };
2995 ShapePath.prototype.reverse = function() {
2996 var newPath = new ShapePath();
2997 newPath.setPathData(this.c, this._length);
2998 var vertices = this.v;
2999 var outPoints = this.o;
3000 var inPoints = this.i;
3001 var init = 0;
3002 if (this.c) {
3003 newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
3004 init = 1;
3005 }
3006 var cnt = this._length - 1;
3007 var len = this._length;
3008 var i;
3009 for (i = init; i < len; i += 1) {
3010 newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
3011 cnt -= 1;
3012 }
3013 return newPath;
3014 };
3015 ShapePath.prototype.length = function() {
3016 return this._length;
3017 };
3018 var shapePool = function() {
3019 function create() {
3020 return new ShapePath();
3021 }
3022 function release(shapePath) {
3023 var len = shapePath._length;
3024 var i;
3025 for (i = 0; i < len; i += 1) {
3026 pointPool.release(shapePath.v[i]);
3027 pointPool.release(shapePath.i[i]);
3028 pointPool.release(shapePath.o[i]);
3029 shapePath.v[i] = null;
3030 shapePath.i[i] = null;
3031 shapePath.o[i] = null;
3032 }
3033 shapePath._length = 0;
3034 shapePath.c = false;
3035 }
3036 function clone(shape) {
3037 var cloned = factory.newElement();
3038 var i;
3039 var len = shape._length === void 0 ? shape.v.length : shape._length;
3040 cloned.setLength(len);
3041 cloned.c = shape.c;
3042 for (i = 0; i < len; i += 1) cloned.setTripleAt(shape.v[i][0], shape.v[i][1], shape.o[i][0], shape.o[i][1], shape.i[i][0], shape.i[i][1], i);
3043 return cloned;
3044 }
3045 var factory = poolFactory(4, create, release);
3046 factory.clone = clone;
3047 return factory;
3048 }();
3049 function ShapeCollection() {
3050 this._length = 0;
3051 this._maxLength = 4;
3052 this.shapes = createSizedArray(this._maxLength);
3053 }
3054 ShapeCollection.prototype.addShape = function(shapeData) {
3055 if (this._length === this._maxLength) {
3056 this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
3057 this._maxLength *= 2;
3058 }
3059 this.shapes[this._length] = shapeData;
3060 this._length += 1;
3061 };
3062 ShapeCollection.prototype.releaseShapes = function() {
3063 var i;
3064 for (i = 0; i < this._length; i += 1) shapePool.release(this.shapes[i]);
3065 this._length = 0;
3066 };
3067 var shapeCollectionPool = function() {
3068 var ob = {
3069 newShapeCollection,
3070 release
3071 };
3072 var _length = 0;
3073 var _maxLength = 4;
3074 var pool = createSizedArray(_maxLength);
3075 function newShapeCollection() {
3076 var shapeCollection;
3077 if (_length) {
3078 _length -= 1;
3079 shapeCollection = pool[_length];
3080 } else shapeCollection = new ShapeCollection();
3081 return shapeCollection;
3082 }
3083 function release(shapeCollection) {
3084 var i;
3085 var len = shapeCollection._length;
3086 for (i = 0; i < len; i += 1) shapePool.release(shapeCollection.shapes[i]);
3087 shapeCollection._length = 0;
3088 if (_length === _maxLength) {
3089 pool = pooling["double"](pool);
3090 _maxLength *= 2;
3091 }
3092 pool[_length] = shapeCollection;
3093 _length += 1;
3094 }
3095 return ob;
3096 }();
3097 var ShapePropertyFactory = function() {
3098 var initFrame = -999999;
3099 function interpolateShape(frameNum, previousValue, caching) {
3100 var iterationIndex = caching.lastIndex;
3101 var keyPropS;
3102 var keyPropE;
3103 var isHold;
3104 var j;
3105 var k;
3106 var jLen;
3107 var kLen;
3108 var perc;
3109 var vertexValue;
3110 var kf = this.keyframes;
3111 if (frameNum < kf[0].t - this.offsetTime) {
3112 keyPropS = kf[0].s[0];
3113 isHold = true;
3114 iterationIndex = 0;
3115 } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
3116 keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
3117 isHold = true;
3118 } else {
3119 var i = iterationIndex;
3120 var len = kf.length - 1;
3121 var flag = true;
3122 var keyData;
3123 var nextKeyData;
3124 var keyframeMetadata;
3125 while (flag) {
3126 keyData = kf[i];
3127 nextKeyData = kf[i + 1];
3128 if (nextKeyData.t - this.offsetTime > frameNum) break;
3129 if (i < len - 1) i += 1;
3130 else flag = false;
3131 }
3132 keyframeMetadata = this.keyframesMetadata[i] || {};
3133 isHold = keyData.h === 1;
3134 iterationIndex = i;
3135 if (!isHold) {
3136 if (frameNum >= nextKeyData.t - this.offsetTime) perc = 1;
3137 else if (frameNum < keyData.t - this.offsetTime) perc = 0;
3138 else {
3139 var fnc;
3140 if (keyframeMetadata.__fnct) fnc = keyframeMetadata.__fnct;
3141 else {
3142 fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
3143 keyframeMetadata.__fnct = fnc;
3144 }
3145 perc = fnc((frameNum - (keyData.t - this.offsetTime)) / (nextKeyData.t - this.offsetTime - (keyData.t - this.offsetTime)));
3146 }
3147 keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
3148 }
3149 keyPropS = keyData.s[0];
3150 }
3151 jLen = previousValue._length;
3152 kLen = keyPropS.i[0].length;
3153 caching.lastIndex = iterationIndex;
3154 for (j = 0; j < jLen; j += 1) for (k = 0; k < kLen; k += 1) {
3155 vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
3156 previousValue.i[j][k] = vertexValue;
3157 vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
3158 previousValue.o[j][k] = vertexValue;
3159 vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
3160 previousValue.v[j][k] = vertexValue;
3161 }
3162 }
3163 function interpolateShapeCurrentTime() {
3164 var frameNum = this.comp.renderedFrame - this.offsetTime;
3165 var initTime = this.keyframes[0].t - this.offsetTime;
3166 var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
3167 var lastFrame = this._caching.lastFrame;
3168 if (!(lastFrame !== initFrame && (lastFrame < initTime && frameNum < initTime || lastFrame > endTime && frameNum > endTime))) {
3169 this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
3170 this.interpolateShape(frameNum, this.pv, this._caching);
3171 }
3172 this._caching.lastFrame = frameNum;
3173 return this.pv;
3174 }
3175 function resetShape() {
3176 this.paths = this.localShapeCollection;
3177 }
3178 function shapesEqual(shape1, shape2) {
3179 if (shape1._length !== shape2._length || shape1.c !== shape2.c) return false;
3180 var i;
3181 var len = shape1._length;
3182 for (i = 0; i < len; i += 1) if (shape1.v[i][0] !== shape2.v[i][0] || shape1.v[i][1] !== shape2.v[i][1] || shape1.o[i][0] !== shape2.o[i][0] || shape1.o[i][1] !== shape2.o[i][1] || shape1.i[i][0] !== shape2.i[i][0] || shape1.i[i][1] !== shape2.i[i][1]) return false;
3183 return true;
3184 }
3185 function setVValue(newPath) {
3186 if (!shapesEqual(this.v, newPath)) {
3187 this.v = shapePool.clone(newPath);
3188 this.localShapeCollection.releaseShapes();
3189 this.localShapeCollection.addShape(this.v);
3190 this._mdf = true;
3191 this.paths = this.localShapeCollection;
3192 }
3193 }
3194 function processEffectsSequence() {
3195 if (this.elem.globalData.frameId === this.frameId) return;
3196 if (!this.effectsSequence.length) {
3197 this._mdf = false;
3198 return;
3199 }
3200 if (this.lock) {
3201 this.setVValue(this.pv);
3202 return;
3203 }
3204 this.lock = true;
3205 this._mdf = false;
3206 var finalValue;
3207 if (this.kf) finalValue = this.pv;
3208 else if (this.data.ks) finalValue = this.data.ks.k;
3209 else finalValue = this.data.pt.k;
3210 var i;
3211 var len = this.effectsSequence.length;
3212 for (i = 0; i < len; i += 1) finalValue = this.effectsSequence[i](finalValue);
3213 this.setVValue(finalValue);
3214 this.lock = false;
3215 this.frameId = this.elem.globalData.frameId;
3216 }
3217 function ShapeProperty(elem, data, type) {
3218 this.propType = "shape";
3219 this.comp = elem.comp;
3220 this.container = elem;
3221 this.elem = elem;
3222 this.data = data;
3223 this.k = false;
3224 this.kf = false;
3225 this._mdf = false;
3226 var pathData = type === 3 ? data.pt.k : data.ks.k;
3227 this.v = shapePool.clone(pathData);
3228 this.pv = shapePool.clone(this.v);
3229 this.localShapeCollection = shapeCollectionPool.newShapeCollection();
3230 this.paths = this.localShapeCollection;
3231 this.paths.addShape(this.v);
3232 this.reset = resetShape;
3233 this.effectsSequence = [];
3234 }
3235 function addEffect(effectFunction) {
3236 this.effectsSequence.push(effectFunction);
3237 this.container.addDynamicProperty(this);
3238 }
3239 ShapeProperty.prototype.interpolateShape = interpolateShape;
3240 ShapeProperty.prototype.getValue = processEffectsSequence;
3241 ShapeProperty.prototype.setVValue = setVValue;
3242 ShapeProperty.prototype.addEffect = addEffect;
3243 function KeyframedShapeProperty(elem, data, type) {
3244 this.propType = "shape";
3245 this.comp = elem.comp;
3246 this.elem = elem;
3247 this.container = elem;
3248 this.offsetTime = elem.data.st;
3249 this.keyframes = type === 3 ? data.pt.k : data.ks.k;
3250 this.keyframesMetadata = [];
3251 this.k = true;
3252 this.kf = true;
3253 var len = this.keyframes[0].s[0].i.length;
3254 this.v = shapePool.newElement();
3255 this.v.setPathData(this.keyframes[0].s[0].c, len);
3256 this.pv = shapePool.clone(this.v);
3257 this.localShapeCollection = shapeCollectionPool.newShapeCollection();
3258 this.paths = this.localShapeCollection;
3259 this.paths.addShape(this.v);
3260 this.lastFrame = initFrame;
3261 this.reset = resetShape;
3262 this._caching = {
3263 lastFrame: initFrame,
3264 lastIndex: 0
3265 };
3266 this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
3267 }
3268 KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
3269 KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
3270 KeyframedShapeProperty.prototype.setVValue = setVValue;
3271 KeyframedShapeProperty.prototype.addEffect = addEffect;
3272 var EllShapeProperty = function() {
3273 var cPoint = roundCorner;
3274 function EllShapePropertyFactory(elem, data) {
3275 this.v = shapePool.newElement();
3276 this.v.setPathData(true, 4);
3277 this.localShapeCollection = shapeCollectionPool.newShapeCollection();
3278 this.paths = this.localShapeCollection;
3279 this.localShapeCollection.addShape(this.v);
3280 this.d = data.d;
3281 this.elem = elem;
3282 this.comp = elem.comp;
3283 this.frameId = -1;
3284 this.initDynamicPropertyContainer(elem);
3285 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
3286 this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
3287 if (this.dynamicProperties.length) this.k = true;
3288 else {
3289 this.k = false;
3290 this.convertEllToPath();
3291 }
3292 }
3293 EllShapePropertyFactory.prototype = {
3294 reset: resetShape,
3295 getValue: function getValue() {
3296 if (this.elem.globalData.frameId === this.frameId) return;
3297 this.frameId = this.elem.globalData.frameId;
3298 this.iterateDynamicProperties();
3299 if (this._mdf) this.convertEllToPath();
3300 },
3301 convertEllToPath: function convertEllToPath() {
3302 var p0 = this.p.v[0];
3303 var p1 = this.p.v[1];
3304 var s0 = this.s.v[0] / 2;
3305 var s1 = this.s.v[1] / 2;
3306 var _cw = this.d !== 3;
3307 var _v = this.v;
3308 _v.v[0][0] = p0;
3309 _v.v[0][1] = p1 - s1;
3310 _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
3311 _v.v[1][1] = p1;
3312 _v.v[2][0] = p0;
3313 _v.v[2][1] = p1 + s1;
3314 _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
3315 _v.v[3][1] = p1;
3316 _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
3317 _v.i[0][1] = p1 - s1;
3318 _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
3319 _v.i[1][1] = p1 - s1 * cPoint;
3320 _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
3321 _v.i[2][1] = p1 + s1;
3322 _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
3323 _v.i[3][1] = p1 + s1 * cPoint;
3324 _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
3325 _v.o[0][1] = p1 - s1;
3326 _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
3327 _v.o[1][1] = p1 + s1 * cPoint;
3328 _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
3329 _v.o[2][1] = p1 + s1;
3330 _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
3331 _v.o[3][1] = p1 - s1 * cPoint;
3332 }
3333 };
3334 extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
3335 return EllShapePropertyFactory;
3336 }();
3337 var StarShapeProperty = function() {
3338 function StarShapePropertyFactory(elem, data) {
3339 this.v = shapePool.newElement();
3340 this.v.setPathData(true, 0);
3341 this.elem = elem;
3342 this.comp = elem.comp;
3343 this.data = data;
3344 this.frameId = -1;
3345 this.d = data.d;
3346 this.initDynamicPropertyContainer(elem);
3347 if (data.sy === 1) {
3348 this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
3349 this.is = PropertyFactory.getProp(elem, data.is, 0, .01, this);
3350 this.convertToPath = this.convertStarToPath;
3351 } else this.convertToPath = this.convertPolygonToPath;
3352 this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
3353 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
3354 this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
3355 this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
3356 this.os = PropertyFactory.getProp(elem, data.os, 0, .01, this);
3357 this.localShapeCollection = shapeCollectionPool.newShapeCollection();
3358 this.localShapeCollection.addShape(this.v);
3359 this.paths = this.localShapeCollection;
3360 if (this.dynamicProperties.length) this.k = true;
3361 else {
3362 this.k = false;
3363 this.convertToPath();
3364 }
3365 }
3366 StarShapePropertyFactory.prototype = {
3367 reset: resetShape,
3368 getValue: function getValue() {
3369 if (this.elem.globalData.frameId === this.frameId) return;
3370 this.frameId = this.elem.globalData.frameId;
3371 this.iterateDynamicProperties();
3372 if (this._mdf) this.convertToPath();
3373 },
3374 convertStarToPath: function convertStarToPath() {
3375 var numPts = Math.floor(this.pt.v) * 2;
3376 var angle = Math.PI * 2 / numPts;
3377 var longFlag = true;
3378 var longRad = this.or.v;
3379 var shortRad = this.ir.v;
3380 var longRound = this.os.v;
3381 var shortRound = this.is.v;
3382 var longPerimSegment = 2 * Math.PI * longRad / (numPts * 2);
3383 var shortPerimSegment = 2 * Math.PI * shortRad / (numPts * 2);
3384 var i;
3385 var rad;
3386 var roundness;
3387 var perimSegment;
3388 var currentAng = -Math.PI / 2;
3389 currentAng += this.r.v;
3390 var dir = this.data.d === 3 ? -1 : 1;
3391 this.v._length = 0;
3392 for (i = 0; i < numPts; i += 1) {
3393 rad = longFlag ? longRad : shortRad;
3394 roundness = longFlag ? longRound : shortRound;
3395 perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
3396 var x = rad * Math.cos(currentAng);
3397 var y = rad * Math.sin(currentAng);
3398 var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
3399 var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
3400 x += +this.p.v[0];
3401 y += +this.p.v[1];
3402 this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
3403 longFlag = !longFlag;
3404 currentAng += angle * dir;
3405 }
3406 },
3407 convertPolygonToPath: function convertPolygonToPath() {
3408 var numPts = Math.floor(this.pt.v);
3409 var angle = Math.PI * 2 / numPts;
3410 var rad = this.or.v;
3411 var roundness = this.os.v;
3412 var perimSegment = 2 * Math.PI * rad / (numPts * 4);
3413 var i;
3414 var currentAng = -Math.PI * .5;
3415 var dir = this.data.d === 3 ? -1 : 1;
3416 currentAng += this.r.v;
3417 this.v._length = 0;
3418 for (i = 0; i < numPts; i += 1) {
3419 var x = rad * Math.cos(currentAng);
3420 var y = rad * Math.sin(currentAng);
3421 var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
3422 var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
3423 x += +this.p.v[0];
3424 y += +this.p.v[1];
3425 this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
3426 currentAng += angle * dir;
3427 }
3428 this.paths.length = 0;
3429 this.paths[0] = this.v;
3430 }
3431 };
3432 extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
3433 return StarShapePropertyFactory;
3434 }();
3435 var RectShapeProperty = function() {
3436 function RectShapePropertyFactory(elem, data) {
3437 this.v = shapePool.newElement();
3438 this.v.c = true;
3439 this.localShapeCollection = shapeCollectionPool.newShapeCollection();
3440 this.localShapeCollection.addShape(this.v);
3441 this.paths = this.localShapeCollection;
3442 this.elem = elem;
3443 this.comp = elem.comp;
3444 this.frameId = -1;
3445 this.d = data.d;
3446 this.initDynamicPropertyContainer(elem);
3447 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
3448 this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
3449 this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
3450 if (this.dynamicProperties.length) this.k = true;
3451 else {
3452 this.k = false;
3453 this.convertRectToPath();
3454 }
3455 }
3456 RectShapePropertyFactory.prototype = {
3457 convertRectToPath: function convertRectToPath() {
3458 var p0 = this.p.v[0];
3459 var p1 = this.p.v[1];
3460 var v0 = this.s.v[0] / 2;
3461 var v1 = this.s.v[1] / 2;
3462 var round = bmMin(v0, v1, this.r.v);
3463 var cPoint = round * (1 - roundCorner);
3464 this.v._length = 0;
3465 if (this.d === 2 || this.d === 1) {
3466 this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
3467 this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
3468 if (round !== 0) {
3469 this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
3470 this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
3471 this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
3472 this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
3473 this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
3474 this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
3475 } else {
3476 this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
3477 this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
3478 }
3479 } else {
3480 this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
3481 if (round !== 0) {
3482 this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
3483 this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
3484 this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
3485 this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
3486 this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
3487 this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
3488 this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
3489 } else {
3490 this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
3491 this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
3492 this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
3493 }
3494 }
3495 },
3496 getValue: function getValue() {
3497 if (this.elem.globalData.frameId === this.frameId) return;
3498 this.frameId = this.elem.globalData.frameId;
3499 this.iterateDynamicProperties();
3500 if (this._mdf) this.convertRectToPath();
3501 },
3502 reset: resetShape
3503 };
3504 extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
3505 return RectShapePropertyFactory;
3506 }();
3507 function getShapeProp(elem, data, type) {
3508 var prop;
3509 if (type === 3 || type === 4) if ((type === 3 ? data.pt : data.ks).k.length) prop = new KeyframedShapeProperty(elem, data, type);
3510 else prop = new ShapeProperty(elem, data, type);
3511 else if (type === 5) prop = new RectShapeProperty(elem, data);
3512 else if (type === 6) prop = new EllShapeProperty(elem, data);
3513 else if (type === 7) prop = new StarShapeProperty(elem, data);
3514 if (prop.k) elem.addDynamicProperty(prop);
3515 return prop;
3516 }
3517 function getConstructorFunction() {
3518 return ShapeProperty;
3519 }
3520 function getKeyframedConstructorFunction() {
3521 return KeyframedShapeProperty;
3522 }
3523 var ob = {};
3524 ob.getShapeProp = getShapeProp;
3525 ob.getConstructorFunction = getConstructorFunction;
3526 ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
3527 return ob;
3528 }();
3529 /*!
3530 Transformation Matrix v2.0
3531 (c) Epistemex 2014-2015
3532 www.epistemex.com
3533 By Ken Fyrstenberg
3534 Contributions by leeoniya.
3535 License: MIT, header required.
3536 */
3537 /**
3538 * 2D transformation matrix object initialized with identity matrix.
3539 *
3540 * The matrix can synchronize a canvas context by supplying the context
3541 * as an argument, or later apply current absolute transform to an
3542 * existing context.
3543 *
3544 * All values are handled as floating point values.
3545 *
3546 * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
3547 * @prop {number} a - scale x
3548 * @prop {number} b - shear y
3549 * @prop {number} c - shear x
3550 * @prop {number} d - scale y
3551 * @prop {number} e - translate x
3552 * @prop {number} f - translate y
3553 * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
3554 * @constructor
3555 */
3556 var Matrix = function() {
3557 var _cos = Math.cos;
3558 var _sin = Math.sin;
3559 var _tan = Math.tan;
3560 var _rnd = Math.round;
3561 function reset() {
3562 this.props[0] = 1;
3563 this.props[1] = 0;
3564 this.props[2] = 0;
3565 this.props[3] = 0;
3566 this.props[4] = 0;
3567 this.props[5] = 1;
3568 this.props[6] = 0;
3569 this.props[7] = 0;
3570 this.props[8] = 0;
3571 this.props[9] = 0;
3572 this.props[10] = 1;
3573 this.props[11] = 0;
3574 this.props[12] = 0;
3575 this.props[13] = 0;
3576 this.props[14] = 0;
3577 this.props[15] = 1;
3578 return this;
3579 }
3580 function rotate(angle) {
3581 if (angle === 0) return this;
3582 var mCos = _cos(angle);
3583 var mSin = _sin(angle);
3584 return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
3585 }
3586 function rotateX(angle) {
3587 if (angle === 0) return this;
3588 var mCos = _cos(angle);
3589 var mSin = _sin(angle);
3590 return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
3591 }
3592 function rotateY(angle) {
3593 if (angle === 0) return this;
3594 var mCos = _cos(angle);
3595 var mSin = _sin(angle);
3596 return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
3597 }
3598 function rotateZ(angle) {
3599 if (angle === 0) return this;
3600 var mCos = _cos(angle);
3601 var mSin = _sin(angle);
3602 return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
3603 }
3604 function shear(sx, sy) {
3605 return this._t(1, sy, sx, 1, 0, 0);
3606 }
3607 function skew(ax, ay) {
3608 return this.shear(_tan(ax), _tan(ay));
3609 }
3610 function skewFromAxis(ax, angle) {
3611 var mCos = _cos(angle);
3612 var mSin = _sin(angle);
3613 return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
3614 }
3615 function scale(sx, sy, sz) {
3616 if (!sz && sz !== 0) sz = 1;
3617 if (sx === 1 && sy === 1 && sz === 1) return this;
3618 return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
3619 }
3620 function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
3621 this.props[0] = a;
3622 this.props[1] = b;
3623 this.props[2] = c;
3624 this.props[3] = d;
3625 this.props[4] = e;
3626 this.props[5] = f;
3627 this.props[6] = g;
3628 this.props[7] = h;
3629 this.props[8] = i;
3630 this.props[9] = j;
3631 this.props[10] = k;
3632 this.props[11] = l;
3633 this.props[12] = m;
3634 this.props[13] = n;
3635 this.props[14] = o;
3636 this.props[15] = p;
3637 return this;
3638 }
3639 function translate(tx, ty, tz) {
3640 tz = tz || 0;
3641 if (tx !== 0 || ty !== 0 || tz !== 0) return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
3642 return this;
3643 }
3644 function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
3645 var _p = this.props;
3646 if (a2 === 1 && b2 === 0 && c2 === 0 && d2 === 0 && e2 === 0 && f2 === 1 && g2 === 0 && h2 === 0 && i2 === 0 && j2 === 0 && k2 === 1 && l2 === 0) {
3647 _p[12] = _p[12] * a2 + _p[15] * m2;
3648 _p[13] = _p[13] * f2 + _p[15] * n2;
3649 _p[14] = _p[14] * k2 + _p[15] * o2;
3650 _p[15] *= p2;
3651 this._identityCalculated = false;
3652 return this;
3653 }
3654 var a1 = _p[0];
3655 var b1 = _p[1];
3656 var c1 = _p[2];
3657 var d1 = _p[3];
3658 var e1 = _p[4];
3659 var f1 = _p[5];
3660 var g1 = _p[6];
3661 var h1 = _p[7];
3662 var i1 = _p[8];
3663 var j1 = _p[9];
3664 var k1 = _p[10];
3665 var l1 = _p[11];
3666 var m1 = _p[12];
3667 var n1 = _p[13];
3668 var o1 = _p[14];
3669 var p1 = _p[15];
3670 _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
3671 _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
3672 _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
3673 _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
3674 _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
3675 _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
3676 _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
3677 _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
3678 _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
3679 _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
3680 _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
3681 _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
3682 _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
3683 _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
3684 _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
3685 _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
3686 this._identityCalculated = false;
3687 return this;
3688 }
3689 function multiply(matrix) {
3690 var matrixProps = matrix.props;
3691 return this.transform(matrixProps[0], matrixProps[1], matrixProps[2], matrixProps[3], matrixProps[4], matrixProps[5], matrixProps[6], matrixProps[7], matrixProps[8], matrixProps[9], matrixProps[10], matrixProps[11], matrixProps[12], matrixProps[13], matrixProps[14], matrixProps[15]);
3692 }
3693 function isIdentity() {
3694 if (!this._identityCalculated) {
3695 this._identity = !(this.props[0] !== 1 || this.props[1] !== 0 || this.props[2] !== 0 || this.props[3] !== 0 || this.props[4] !== 0 || this.props[5] !== 1 || this.props[6] !== 0 || this.props[7] !== 0 || this.props[8] !== 0 || this.props[9] !== 0 || this.props[10] !== 1 || this.props[11] !== 0 || this.props[12] !== 0 || this.props[13] !== 0 || this.props[14] !== 0 || this.props[15] !== 1);
3696 this._identityCalculated = true;
3697 }
3698 return this._identity;
3699 }
3700 function equals(matr) {
3701 var i = 0;
3702 while (i < 16) {
3703 if (matr.props[i] !== this.props[i]) return false;
3704 i += 1;
3705 }
3706 return true;
3707 }
3708 function clone(matr) {
3709 var i;
3710 for (i = 0; i < 16; i += 1) matr.props[i] = this.props[i];
3711 return matr;
3712 }
3713 function cloneFromProps(props) {
3714 var i;
3715 for (i = 0; i < 16; i += 1) this.props[i] = props[i];
3716 }
3717 function applyToPoint(x, y, z) {
3718 return {
3719 x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
3720 y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
3721 z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
3722 };
3723 }
3724 function applyToX(x, y, z) {
3725 return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
3726 }
3727 function applyToY(x, y, z) {
3728 return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
3729 }
3730 function applyToZ(x, y, z) {
3731 return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
3732 }
3733 function getInverseMatrix() {
3734 var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
3735 var a = this.props[5] / determinant;
3736 var b = -this.props[1] / determinant;
3737 var c = -this.props[4] / determinant;
3738 var d = this.props[0] / determinant;
3739 var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
3740 var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
3741 var inverseMatrix = new Matrix();
3742 inverseMatrix.props[0] = a;
3743 inverseMatrix.props[1] = b;
3744 inverseMatrix.props[4] = c;
3745 inverseMatrix.props[5] = d;
3746 inverseMatrix.props[12] = e;
3747 inverseMatrix.props[13] = f;
3748 return inverseMatrix;
3749 }
3750 function inversePoint(pt) {
3751 return this.getInverseMatrix().applyToPointArray(pt[0], pt[1], pt[2] || 0);
3752 }
3753 function inversePoints(pts) {
3754 var i;
3755 var len = pts.length;
3756 var retPts = [];
3757 for (i = 0; i < len; i += 1) retPts[i] = inversePoint(pts[i]);
3758 return retPts;
3759 }
3760 function applyToTriplePoints(pt1, pt2, pt3) {
3761 var arr = createTypedArray("float32", 6);
3762 if (this.isIdentity()) {
3763 arr[0] = pt1[0];
3764 arr[1] = pt1[1];
3765 arr[2] = pt2[0];
3766 arr[3] = pt2[1];
3767 arr[4] = pt3[0];
3768 arr[5] = pt3[1];
3769 } else {
3770 var p0 = this.props[0];
3771 var p1 = this.props[1];
3772 var p4 = this.props[4];
3773 var p5 = this.props[5];
3774 var p12 = this.props[12];
3775 var p13 = this.props[13];
3776 arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
3777 arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
3778 arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
3779 arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
3780 arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
3781 arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
3782 }
3783 return arr;
3784 }
3785 function applyToPointArray(x, y, z) {
3786 var arr;
3787 if (this.isIdentity()) arr = [
3788 x,
3789 y,
3790 z
3791 ];
3792 else arr = [
3793 x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
3794 x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
3795 x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
3796 ];
3797 return arr;
3798 }
3799 function applyToPointStringified(x, y) {
3800 if (this.isIdentity()) return x + "," + y;
3801 var _p = this.props;
3802 return Math.round((x * _p[0] + y * _p[4] + _p[12]) * 100) / 100 + "," + Math.round((x * _p[1] + y * _p[5] + _p[13]) * 100) / 100;
3803 }
3804 function toCSS() {
3805 var i = 0;
3806 var props = this.props;
3807 var cssValue = "matrix3d(";
3808 var v = 1e4;
3809 while (i < 16) {
3810 cssValue += _rnd(props[i] * v) / v;
3811 cssValue += i === 15 ? ")" : ",";
3812 i += 1;
3813 }
3814 return cssValue;
3815 }
3816 function roundMatrixProperty(val) {
3817 var v = 1e4;
3818 if (val < 1e-6 && val > 0 || val > -1e-6 && val < 0) return _rnd(val * v) / v;
3819 return val;
3820 }
3821 function to2dCSS() {
3822 var props = this.props;
3823 var _a = roundMatrixProperty(props[0]);
3824 var _b = roundMatrixProperty(props[1]);
3825 var _c = roundMatrixProperty(props[4]);
3826 var _d = roundMatrixProperty(props[5]);
3827 var _e = roundMatrixProperty(props[12]);
3828 var _f = roundMatrixProperty(props[13]);
3829 return "matrix(" + _a + "," + _b + "," + _c + "," + _d + "," + _e + "," + _f + ")";
3830 }
3831 return function() {
3832 this.reset = reset;
3833 this.rotate = rotate;
3834 this.rotateX = rotateX;
3835 this.rotateY = rotateY;
3836 this.rotateZ = rotateZ;
3837 this.skew = skew;
3838 this.skewFromAxis = skewFromAxis;
3839 this.shear = shear;
3840 this.scale = scale;
3841 this.setTransform = setTransform;
3842 this.translate = translate;
3843 this.transform = transform;
3844 this.multiply = multiply;
3845 this.applyToPoint = applyToPoint;
3846 this.applyToX = applyToX;
3847 this.applyToY = applyToY;
3848 this.applyToZ = applyToZ;
3849 this.applyToPointArray = applyToPointArray;
3850 this.applyToTriplePoints = applyToTriplePoints;
3851 this.applyToPointStringified = applyToPointStringified;
3852 this.toCSS = toCSS;
3853 this.to2dCSS = to2dCSS;
3854 this.clone = clone;
3855 this.cloneFromProps = cloneFromProps;
3856 this.equals = equals;
3857 this.inversePoints = inversePoints;
3858 this.inversePoint = inversePoint;
3859 this.getInverseMatrix = getInverseMatrix;
3860 this._t = this.transform;
3861 this.isIdentity = isIdentity;
3862 this._identity = true;
3863 this._identityCalculated = false;
3864 this.props = createTypedArray("float32", 16);
3865 this.reset();
3866 };
3867 }();
3868 function _typeof$3(o) {
3869 "@babel/helpers - typeof";
3870 return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
3871 return typeof o;
3872 } : function(o) {
3873 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
3874 }, _typeof$3(o);
3875 }
3876 var lottie = {};
3877 var standalone = "__[STANDALONE]__";
3878 var animationData = "__[ANIMATIONDATA]__";
3879 var renderer = "";
3880 function setLocation(href) {
3881 setLocationHref(href);
3882 }
3883 function searchAnimations() {
3884 if (standalone === true) animationManager.searchAnimations(animationData, standalone, renderer);
3885 else animationManager.searchAnimations();
3886 }
3887 function setSubframeRendering(flag) {
3888 setSubframeEnabled(flag);
3889 }
3890 function setPrefix(prefix) {
3891 setIdPrefix(prefix);
3892 }
3893 function loadAnimation(params) {
3894 if (standalone === true) params.animationData = JSON.parse(animationData);
3895 return animationManager.loadAnimation(params);
3896 }
3897 function setQuality(value) {
3898 if (typeof value === "string") switch (value) {
3899 case "high":
3900 setDefaultCurveSegments(200);
3901 break;
3902 default:
3903 case "medium":
3904 setDefaultCurveSegments(50);
3905 break;
3906 case "low":
3907 setDefaultCurveSegments(10);
3908 break;
3909 }
3910 else if (!isNaN(value) && value > 1) setDefaultCurveSegments(value);
3911 if (getDefaultCurveSegments() >= 50) roundValues(false);
3912 else roundValues(true);
3913 }
3914 function inBrowser() {
3915 return typeof navigator !== "undefined";
3916 }
3917 function installPlugin(type, plugin) {
3918 if (type === "expressions") setExpressionsPlugin(plugin);
3919 }
3920 function getFactory(name) {
3921 switch (name) {
3922 case "propertyFactory": return PropertyFactory;
3923 case "shapePropertyFactory": return ShapePropertyFactory;
3924 case "matrix": return Matrix;
3925 default: return null;
3926 }
3927 }
3928 lottie.play = animationManager.play;
3929 lottie.pause = animationManager.pause;
3930 lottie.setLocationHref = setLocation;
3931 lottie.togglePause = animationManager.togglePause;
3932 lottie.setSpeed = animationManager.setSpeed;
3933 lottie.setDirection = animationManager.setDirection;
3934 lottie.stop = animationManager.stop;
3935 lottie.searchAnimations = searchAnimations;
3936 lottie.registerAnimation = animationManager.registerAnimation;
3937 lottie.loadAnimation = loadAnimation;
3938 lottie.setSubframeRendering = setSubframeRendering;
3939 lottie.resize = animationManager.resize;
3940 lottie.goToAndStop = animationManager.goToAndStop;
3941 lottie.destroy = animationManager.destroy;
3942 lottie.setQuality = setQuality;
3943 lottie.inBrowser = inBrowser;
3944 lottie.installPlugin = installPlugin;
3945 lottie.freeze = animationManager.freeze;
3946 lottie.unfreeze = animationManager.unfreeze;
3947 lottie.setVolume = animationManager.setVolume;
3948 lottie.mute = animationManager.mute;
3949 lottie.unmute = animationManager.unmute;
3950 lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
3951 lottie.useWebWorker = setWebWorker;
3952 lottie.setIDPrefix = setPrefix;
3953 lottie.__getFactory = getFactory;
3954 lottie.version = "5.13.0";
3955 function checkReady() {
3956 if (document.readyState === "complete") {
3957 clearInterval(readyStateCheckInterval);
3958 searchAnimations();
3959 }
3960 }
3961 function getQueryVariable(variable) {
3962 var vars = queryString.split("&");
3963 for (var i = 0; i < vars.length; i += 1) {
3964 var pair = vars[i].split("=");
3965 if (decodeURIComponent(pair[0]) == variable) return decodeURIComponent(pair[1]);
3966 }
3967 return null;
3968 }
3969 var queryString = "";
3970 if (standalone) {
3971 var scripts = document.getElementsByTagName("script");
3972 var myScript = scripts[scripts.length - 1] || { src: "" };
3973 queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, "") : "";
3974 renderer = getQueryVariable("renderer");
3975 }
3976 var readyStateCheckInterval = setInterval(checkReady, 100);
3977 try {
3978 if (!((typeof exports === "undefined" ? "undefined" : _typeof$3(exports)) === "object" && typeof module !== "undefined") && !(typeof define === "function" && define.amd)) window.bodymovin = lottie;
3979 } catch (err) {}
3980 var ShapeModifiers = function() {
3981 var ob = {};
3982 var modifiers = {};
3983 ob.registerModifier = registerModifier;
3984 ob.getModifier = getModifier;
3985 function registerModifier(nm, factory) {
3986 if (!modifiers[nm]) modifiers[nm] = factory;
3987 }
3988 function getModifier(nm, elem, data) {
3989 return new modifiers[nm](elem, data);
3990 }
3991 return ob;
3992 }();
3993 function ShapeModifier() {}
3994 ShapeModifier.prototype.initModifierProperties = function() {};
3995 ShapeModifier.prototype.addShapeToModifier = function() {};
3996 ShapeModifier.prototype.addShape = function(data) {
3997 if (!this.closed) {
3998 data.sh.container.addDynamicProperty(data.sh);
3999 var shapeData = {
4000 shape: data.sh,
4001 data,
4002 localShapeCollection: shapeCollectionPool.newShapeCollection()
4003 };
4004 this.shapes.push(shapeData);
4005 this.addShapeToModifier(shapeData);
4006 if (this._isAnimated) data.setAsAnimated();
4007 }
4008 };
4009 ShapeModifier.prototype.init = function(elem, data) {
4010 this.shapes = [];
4011 this.elem = elem;
4012 this.initDynamicPropertyContainer(elem);
4013 this.initModifierProperties(elem, data);
4014 this.frameId = initialDefaultFrame;
4015 this.closed = false;
4016 this.k = false;
4017 if (this.dynamicProperties.length) this.k = true;
4018 else this.getValue(true);
4019 };
4020 ShapeModifier.prototype.processKeys = function() {
4021 if (this.elem.globalData.frameId === this.frameId) return;
4022 this.frameId = this.elem.globalData.frameId;
4023 this.iterateDynamicProperties();
4024 };
4025 extendPrototype([DynamicPropertyContainer], ShapeModifier);
4026 function TrimModifier() {}
4027 extendPrototype([ShapeModifier], TrimModifier);
4028 TrimModifier.prototype.initModifierProperties = function(elem, data) {
4029 this.s = PropertyFactory.getProp(elem, data.s, 0, .01, this);
4030 this.e = PropertyFactory.getProp(elem, data.e, 0, .01, this);
4031 this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
4032 this.sValue = 0;
4033 this.eValue = 0;
4034 this.getValue = this.processKeys;
4035 this.m = data.m;
4036 this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
4037 };
4038 TrimModifier.prototype.addShapeToModifier = function(shapeData) {
4039 shapeData.pathsData = [];
4040 };
4041 TrimModifier.prototype.calculateShapeEdges = function(s, e, shapeLength, addedLength, totalModifierLength) {
4042 var segments = [];
4043 if (e <= 1) segments.push({
4044 s,
4045 e
4046 });
4047 else if (s >= 1) segments.push({
4048 s: s - 1,
4049 e: e - 1
4050 });
4051 else {
4052 segments.push({
4053 s,
4054 e: 1
4055 });
4056 segments.push({
4057 s: 0,
4058 e: e - 1
4059 });
4060 }
4061 var shapeSegments = [];
4062 var i;
4063 var len = segments.length;
4064 var segmentOb;
4065 for (i = 0; i < len; i += 1) {
4066 segmentOb = segments[i];
4067 if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
4068 var shapeS;
4069 var shapeE;
4070 if (segmentOb.s * totalModifierLength <= addedLength) shapeS = 0;
4071 else shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
4072 if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) shapeE = 1;
4073 else shapeE = (segmentOb.e * totalModifierLength - addedLength) / shapeLength;
4074 shapeSegments.push([shapeS, shapeE]);
4075 }
4076 }
4077 if (!shapeSegments.length) shapeSegments.push([0, 0]);
4078 return shapeSegments;
4079 };
4080 TrimModifier.prototype.releasePathsData = function(pathsData) {
4081 var i;
4082 var len = pathsData.length;
4083 for (i = 0; i < len; i += 1) segmentsLengthPool.release(pathsData[i]);
4084 pathsData.length = 0;
4085 return pathsData;
4086 };
4087 TrimModifier.prototype.processShapes = function(_isFirstFrame) {
4088 var s;
4089 var e;
4090 if (this._mdf || _isFirstFrame) {
4091 var o = this.o.v % 360 / 360;
4092 if (o < 0) o += 1;
4093 if (this.s.v > 1) s = 1 + o;
4094 else if (this.s.v < 0) s = 0 + o;
4095 else s = this.s.v + o;
4096 if (this.e.v > 1) e = 1 + o;
4097 else if (this.e.v < 0) e = 0 + o;
4098 else e = this.e.v + o;
4099 if (s > e) {
4100 var _s = s;
4101 s = e;
4102 e = _s;
4103 }
4104 s = Math.round(s * 1e4) * 1e-4;
4105 e = Math.round(e * 1e4) * 1e-4;
4106 this.sValue = s;
4107 this.eValue = e;
4108 } else {
4109 s = this.sValue;
4110 e = this.eValue;
4111 }
4112 var shapePaths;
4113 var i;
4114 var len = this.shapes.length;
4115 var j;
4116 var jLen;
4117 var pathsData;
4118 var pathData;
4119 var totalShapeLength;
4120 var totalModifierLength = 0;
4121 if (e === s) for (i = 0; i < len; i += 1) {
4122 this.shapes[i].localShapeCollection.releaseShapes();
4123 this.shapes[i].shape._mdf = true;
4124 this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
4125 if (this._mdf) this.shapes[i].pathsData.length = 0;
4126 }
4127 else if (!(e === 1 && s === 0 || e === 0 && s === 1)) {
4128 var segments = [];
4129 var shapeData;
4130 var localShapeCollection;
4131 for (i = 0; i < len; i += 1) {
4132 shapeData = this.shapes[i];
4133 if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) shapeData.shape.paths = shapeData.localShapeCollection;
4134 else {
4135 shapePaths = shapeData.shape.paths;
4136 jLen = shapePaths._length;
4137 totalShapeLength = 0;
4138 if (!shapeData.shape._mdf && shapeData.pathsData.length) totalShapeLength = shapeData.totalShapeLength;
4139 else {
4140 pathsData = this.releasePathsData(shapeData.pathsData);
4141 for (j = 0; j < jLen; j += 1) {
4142 pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
4143 pathsData.push(pathData);
4144 totalShapeLength += pathData.totalLength;
4145 }
4146 shapeData.totalShapeLength = totalShapeLength;
4147 shapeData.pathsData = pathsData;
4148 }
4149 totalModifierLength += totalShapeLength;
4150 shapeData.shape._mdf = true;
4151 }
4152 }
4153 var shapeS = s;
4154 var shapeE = e;
4155 var addedLength = 0;
4156 var edges;
4157 for (i = len - 1; i >= 0; i -= 1) {
4158 shapeData = this.shapes[i];
4159 if (shapeData.shape._mdf) {
4160 localShapeCollection = shapeData.localShapeCollection;
4161 localShapeCollection.releaseShapes();
4162 if (this.m === 2 && len > 1) {
4163 edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
4164 addedLength += shapeData.totalShapeLength;
4165 } else edges = [[shapeS, shapeE]];
4166 jLen = edges.length;
4167 for (j = 0; j < jLen; j += 1) {
4168 shapeS = edges[j][0];
4169 shapeE = edges[j][1];
4170 segments.length = 0;
4171 if (shapeE <= 1) segments.push({
4172 s: shapeData.totalShapeLength * shapeS,
4173 e: shapeData.totalShapeLength * shapeE
4174 });
4175 else if (shapeS >= 1) segments.push({
4176 s: shapeData.totalShapeLength * (shapeS - 1),
4177 e: shapeData.totalShapeLength * (shapeE - 1)
4178 });
4179 else {
4180 segments.push({
4181 s: shapeData.totalShapeLength * shapeS,
4182 e: shapeData.totalShapeLength
4183 });
4184 segments.push({
4185 s: 0,
4186 e: shapeData.totalShapeLength * (shapeE - 1)
4187 });
4188 }
4189 var newShapesData = this.addShapes(shapeData, segments[0]);
4190 if (segments[0].s !== segments[0].e) {
4191 if (segments.length > 1) if (shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1].c) {
4192 var lastShape = newShapesData.pop();
4193 this.addPaths(newShapesData, localShapeCollection);
4194 newShapesData = this.addShapes(shapeData, segments[1], lastShape);
4195 } else {
4196 this.addPaths(newShapesData, localShapeCollection);
4197 newShapesData = this.addShapes(shapeData, segments[1]);
4198 }
4199 this.addPaths(newShapesData, localShapeCollection);
4200 }
4201 }
4202 shapeData.shape.paths = localShapeCollection;
4203 }
4204 }
4205 } else if (this._mdf) for (i = 0; i < len; i += 1) {
4206 this.shapes[i].pathsData.length = 0;
4207 this.shapes[i].shape._mdf = true;
4208 }
4209 };
4210 TrimModifier.prototype.addPaths = function(newPaths, localShapeCollection) {
4211 var i;
4212 var len = newPaths.length;
4213 for (i = 0; i < len; i += 1) localShapeCollection.addShape(newPaths[i]);
4214 };
4215 TrimModifier.prototype.addSegment = function(pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
4216 shapePath.setXYAt(pt2[0], pt2[1], "o", pos);
4217 shapePath.setXYAt(pt3[0], pt3[1], "i", pos + 1);
4218 if (newShape) shapePath.setXYAt(pt1[0], pt1[1], "v", pos);
4219 shapePath.setXYAt(pt4[0], pt4[1], "v", pos + 1);
4220 };
4221 TrimModifier.prototype.addSegmentFromArray = function(points, shapePath, pos, newShape) {
4222 shapePath.setXYAt(points[1], points[5], "o", pos);
4223 shapePath.setXYAt(points[2], points[6], "i", pos + 1);
4224 if (newShape) shapePath.setXYAt(points[0], points[4], "v", pos);
4225 shapePath.setXYAt(points[3], points[7], "v", pos + 1);
4226 };
4227 TrimModifier.prototype.addShapes = function(shapeData, shapeSegment, shapePath) {
4228 var pathsData = shapeData.pathsData;
4229 var shapePaths = shapeData.shape.paths.shapes;
4230 var i;
4231 var len = shapeData.shape.paths._length;
4232 var j;
4233 var jLen;
4234 var addedLength = 0;
4235 var currentLengthData;
4236 var segmentCount;
4237 var lengths;
4238 var segment;
4239 var shapes = [];
4240 var initPos;
4241 var newShape = true;
4242 if (!shapePath) {
4243 shapePath = shapePool.newElement();
4244 segmentCount = 0;
4245 initPos = 0;
4246 } else {
4247 segmentCount = shapePath._length;
4248 initPos = shapePath._length;
4249 }
4250 shapes.push(shapePath);
4251 for (i = 0; i < len; i += 1) {
4252 lengths = pathsData[i].lengths;
4253 shapePath.c = shapePaths[i].c;
4254 jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
4255 for (j = 1; j < jLen; j += 1) {
4256 currentLengthData = lengths[j - 1];
4257 if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
4258 addedLength += currentLengthData.addedLength;
4259 shapePath.c = false;
4260 } else if (addedLength > shapeSegment.e) {
4261 shapePath.c = false;
4262 break;
4263 } else {
4264 if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
4265 this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
4266 newShape = false;
4267 } else {
4268 segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[j], shapePaths[i].o[j - 1], shapePaths[i].i[j], (shapeSegment.s - addedLength) / currentLengthData.addedLength, (shapeSegment.e - addedLength) / currentLengthData.addedLength, lengths[j - 1]);
4269 this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
4270 newShape = false;
4271 shapePath.c = false;
4272 }
4273 addedLength += currentLengthData.addedLength;
4274 segmentCount += 1;
4275 }
4276 }
4277 if (shapePaths[i].c && lengths.length) {
4278 currentLengthData = lengths[j - 1];
4279 if (addedLength <= shapeSegment.e) {
4280 var segmentLength = lengths[j - 1].addedLength;
4281 if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
4282 this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
4283 newShape = false;
4284 } else {
4285 segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[0], shapePaths[i].o[j - 1], shapePaths[i].i[0], (shapeSegment.s - addedLength) / segmentLength, (shapeSegment.e - addedLength) / segmentLength, lengths[j - 1]);
4286 this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
4287 newShape = false;
4288 shapePath.c = false;
4289 }
4290 } else shapePath.c = false;
4291 addedLength += currentLengthData.addedLength;
4292 segmentCount += 1;
4293 }
4294 if (shapePath._length) {
4295 shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], "i", initPos);
4296 shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], "o", shapePath._length - 1);
4297 }
4298 if (addedLength > shapeSegment.e) break;
4299 if (i < len - 1) {
4300 shapePath = shapePool.newElement();
4301 newShape = true;
4302 shapes.push(shapePath);
4303 segmentCount = 0;
4304 }
4305 }
4306 return shapes;
4307 };
4308 function PuckerAndBloatModifier() {}
4309 extendPrototype([ShapeModifier], PuckerAndBloatModifier);
4310 PuckerAndBloatModifier.prototype.initModifierProperties = function(elem, data) {
4311 this.getValue = this.processKeys;
4312 this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
4313 this._isAnimated = !!this.amount.effectsSequence.length;
4314 };
4315 PuckerAndBloatModifier.prototype.processPath = function(path, amount) {
4316 var percent = amount / 100;
4317 var centerPoint = [0, 0];
4318 var pathLength = path._length;
4319 var i = 0;
4320 for (i = 0; i < pathLength; i += 1) {
4321 centerPoint[0] += path.v[i][0];
4322 centerPoint[1] += path.v[i][1];
4323 }
4324 centerPoint[0] /= pathLength;
4325 centerPoint[1] /= pathLength;
4326 var clonedPath = shapePool.newElement();
4327 clonedPath.c = path.c;
4328 var vX;
4329 var vY;
4330 var oX;
4331 var oY;
4332 var iX;
4333 var iY;
4334 for (i = 0; i < pathLength; i += 1) {
4335 vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
4336 vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
4337 oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
4338 oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
4339 iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
4340 iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
4341 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
4342 }
4343 return clonedPath;
4344 };
4345 PuckerAndBloatModifier.prototype.processShapes = function(_isFirstFrame) {
4346 var shapePaths;
4347 var i;
4348 var len = this.shapes.length;
4349 var j;
4350 var jLen;
4351 var amount = this.amount.v;
4352 if (amount !== 0) {
4353 var shapeData;
4354 var localShapeCollection;
4355 for (i = 0; i < len; i += 1) {
4356 shapeData = this.shapes[i];
4357 localShapeCollection = shapeData.localShapeCollection;
4358 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
4359 localShapeCollection.releaseShapes();
4360 shapeData.shape._mdf = true;
4361 shapePaths = shapeData.shape.paths.shapes;
4362 jLen = shapeData.shape.paths._length;
4363 for (j = 0; j < jLen; j += 1) localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
4364 }
4365 shapeData.shape.paths = shapeData.localShapeCollection;
4366 }
4367 }
4368 if (!this.dynamicProperties.length) this._mdf = false;
4369 };
4370 var TransformPropertyFactory = function() {
4371 var defaultVector = [0, 0];
4372 function applyToMatrix(mat) {
4373 var _mdf = this._mdf;
4374 this.iterateDynamicProperties();
4375 this._mdf = this._mdf || _mdf;
4376 if (this.a) mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
4377 if (this.s) mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
4378 if (this.sk) mat.skewFromAxis(-this.sk.v, this.sa.v);
4379 if (this.r) mat.rotate(-this.r.v);
4380 else mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
4381 if (this.data.p.s) if (this.data.p.z) mat.translate(this.px.v, this.py.v, -this.pz.v);
4382 else mat.translate(this.px.v, this.py.v, 0);
4383 else mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
4384 }
4385 function processKeys(forceRender) {
4386 if (this.elem.globalData.frameId === this.frameId) return;
4387 if (this._isDirty) {
4388 this.precalculateMatrix();
4389 this._isDirty = false;
4390 }
4391 this.iterateDynamicProperties();
4392 if (this._mdf || forceRender) {
4393 var frameRate;
4394 this.v.cloneFromProps(this.pre.props);
4395 if (this.appliedTransformations < 1) this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
4396 if (this.appliedTransformations < 2) this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
4397 if (this.sk && this.appliedTransformations < 3) this.v.skewFromAxis(-this.sk.v, this.sa.v);
4398 if (this.r && this.appliedTransformations < 4) this.v.rotate(-this.r.v);
4399 else if (!this.r && this.appliedTransformations < 4) this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
4400 if (this.autoOriented) {
4401 var v1;
4402 var v2;
4403 frameRate = this.elem.globalData.frameRate;
4404 if (this.p && this.p.keyframes && this.p.getValueAtTime) if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
4405 v1 = this.p.getValueAtTime((this.p.keyframes[0].t + .01) / frameRate, 0);
4406 v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
4407 } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
4408 v1 = this.p.getValueAtTime(this.p.keyframes[this.p.keyframes.length - 1].t / frameRate, 0);
4409 v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - .05) / frameRate, 0);
4410 } else {
4411 v1 = this.p.pv;
4412 v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - .01) / frameRate, this.p.offsetTime);
4413 }
4414 else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
4415 v1 = [];
4416 v2 = [];
4417 var px = this.px;
4418 var py = this.py;
4419 if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
4420 v1[0] = px.getValueAtTime((px.keyframes[0].t + .01) / frameRate, 0);
4421 v1[1] = py.getValueAtTime((py.keyframes[0].t + .01) / frameRate, 0);
4422 v2[0] = px.getValueAtTime(px.keyframes[0].t / frameRate, 0);
4423 v2[1] = py.getValueAtTime(py.keyframes[0].t / frameRate, 0);
4424 } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
4425 v1[0] = px.getValueAtTime(px.keyframes[px.keyframes.length - 1].t / frameRate, 0);
4426 v1[1] = py.getValueAtTime(py.keyframes[py.keyframes.length - 1].t / frameRate, 0);
4427 v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - .01) / frameRate, 0);
4428 v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - .01) / frameRate, 0);
4429 } else {
4430 v1 = [px.pv, py.pv];
4431 v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - .01) / frameRate, px.offsetTime);
4432 v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - .01) / frameRate, py.offsetTime);
4433 }
4434 } else {
4435 v2 = defaultVector;
4436 v1 = v2;
4437 }
4438 this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
4439 }
4440 if (this.data.p && this.data.p.s) if (this.data.p.z) this.v.translate(this.px.v, this.py.v, -this.pz.v);
4441 else this.v.translate(this.px.v, this.py.v, 0);
4442 else this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
4443 }
4444 this.frameId = this.elem.globalData.frameId;
4445 }
4446 function precalculateMatrix() {
4447 this.appliedTransformations = 0;
4448 this.pre.reset();
4449 if (!this.a.effectsSequence.length) {
4450 this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
4451 this.appliedTransformations = 1;
4452 } else return;
4453 if (!this.s.effectsSequence.length) {
4454 this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
4455 this.appliedTransformations = 2;
4456 } else return;
4457 if (this.sk) if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
4458 this.pre.skewFromAxis(-this.sk.v, this.sa.v);
4459 this.appliedTransformations = 3;
4460 } else return;
4461 if (this.r) {
4462 if (!this.r.effectsSequence.length) {
4463 this.pre.rotate(-this.r.v);
4464 this.appliedTransformations = 4;
4465 }
4466 } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
4467 this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
4468 this.appliedTransformations = 4;
4469 }
4470 }
4471 function autoOrient() {}
4472 function addDynamicProperty(prop) {
4473 this._addDynamicProperty(prop);
4474 this.elem.addDynamicProperty(prop);
4475 this._isDirty = true;
4476 }
4477 function TransformProperty(elem, data, container) {
4478 this.elem = elem;
4479 this.frameId = -1;
4480 this.propType = "transform";
4481 this.data = data;
4482 this.v = new Matrix();
4483 this.pre = new Matrix();
4484 this.appliedTransformations = 0;
4485 this.initDynamicPropertyContainer(container || elem);
4486 if (data.p && data.p.s) {
4487 this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
4488 this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
4489 if (data.p.z) this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
4490 } else this.p = PropertyFactory.getProp(elem, data.p || { k: [
4491 0,
4492 0,
4493 0
4494 ] }, 1, 0, this);
4495 if (data.rx) {
4496 this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
4497 this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
4498 this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
4499 if (data.or.k[0].ti) {
4500 var i;
4501 var len = data.or.k.length;
4502 for (i = 0; i < len; i += 1) {
4503 data.or.k[i].to = null;
4504 data.or.k[i].ti = null;
4505 }
4506 }
4507 this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
4508 this.or.sh = true;
4509 } else this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
4510 if (data.sk) {
4511 this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
4512 this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
4513 }
4514 this.a = PropertyFactory.getProp(elem, data.a || { k: [
4515 0,
4516 0,
4517 0
4518 ] }, 1, 0, this);
4519 this.s = PropertyFactory.getProp(elem, data.s || { k: [
4520 100,
4521 100,
4522 100
4523 ] }, 1, .01, this);
4524 if (data.o) this.o = PropertyFactory.getProp(elem, data.o, 0, .01, elem);
4525 else this.o = {
4526 _mdf: false,
4527 v: 1
4528 };
4529 this._isDirty = true;
4530 if (!this.dynamicProperties.length) this.getValue(true);
4531 }
4532 TransformProperty.prototype = {
4533 applyToMatrix,
4534 getValue: processKeys,
4535 precalculateMatrix,
4536 autoOrient
4537 };
4538 extendPrototype([DynamicPropertyContainer], TransformProperty);
4539 TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
4540 TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
4541 function getTransformProperty(elem, data, container) {
4542 return new TransformProperty(elem, data, container);
4543 }
4544 return { getTransformProperty };
4545 }();
4546 function RepeaterModifier() {}
4547 extendPrototype([ShapeModifier], RepeaterModifier);
4548 RepeaterModifier.prototype.initModifierProperties = function(elem, data) {
4549 this.getValue = this.processKeys;
4550 this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
4551 this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
4552 this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
4553 this.so = PropertyFactory.getProp(elem, data.tr.so, 0, .01, this);
4554 this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, .01, this);
4555 this.data = data;
4556 if (!this.dynamicProperties.length) this.getValue(true);
4557 this._isAnimated = !!this.dynamicProperties.length;
4558 this.pMatrix = new Matrix();
4559 this.rMatrix = new Matrix();
4560 this.sMatrix = new Matrix();
4561 this.tMatrix = new Matrix();
4562 this.matrix = new Matrix();
4563 };
4564 RepeaterModifier.prototype.applyTransforms = function(pMatrix, rMatrix, sMatrix, transform, perc, inv) {
4565 var dir = inv ? -1 : 1;
4566 var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
4567 var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
4568 pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
4569 rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
4570 rMatrix.rotate(-transform.r.v * dir * perc);
4571 rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
4572 sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
4573 sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
4574 sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
4575 };
4576 RepeaterModifier.prototype.init = function(elem, arr, pos, elemsData) {
4577 this.elem = elem;
4578 this.arr = arr;
4579 this.pos = pos;
4580 this.elemsData = elemsData;
4581 this._currentCopies = 0;
4582 this._elements = [];
4583 this._groups = [];
4584 this.frameId = -1;
4585 this.initDynamicPropertyContainer(elem);
4586 this.initModifierProperties(elem, arr[pos]);
4587 while (pos > 0) {
4588 pos -= 1;
4589 this._elements.unshift(arr[pos]);
4590 }
4591 if (this.dynamicProperties.length) this.k = true;
4592 else this.getValue(true);
4593 };
4594 RepeaterModifier.prototype.resetElements = function(elements) {
4595 var i;
4596 var len = elements.length;
4597 for (i = 0; i < len; i += 1) {
4598 elements[i]._processed = false;
4599 if (elements[i].ty === "gr") this.resetElements(elements[i].it);
4600 }
4601 };
4602 RepeaterModifier.prototype.cloneElements = function(elements) {
4603 var newElements = JSON.parse(JSON.stringify(elements));
4604 this.resetElements(newElements);
4605 return newElements;
4606 };
4607 RepeaterModifier.prototype.changeGroupRender = function(elements, renderFlag) {
4608 var i;
4609 var len = elements.length;
4610 for (i = 0; i < len; i += 1) {
4611 elements[i]._render = renderFlag;
4612 if (elements[i].ty === "gr") this.changeGroupRender(elements[i].it, renderFlag);
4613 }
4614 };
4615 RepeaterModifier.prototype.processShapes = function(_isFirstFrame) {
4616 var items;
4617 var itemsTransform;
4618 var i;
4619 var dir;
4620 var cont;
4621 var hasReloaded = false;
4622 if (this._mdf || _isFirstFrame) {
4623 var copies = Math.ceil(this.c.v);
4624 if (this._groups.length < copies) {
4625 while (this._groups.length < copies) {
4626 var group = {
4627 it: this.cloneElements(this._elements),
4628 ty: "gr"
4629 };
4630 group.it.push({
4631 a: {
4632 a: 0,
4633 ix: 1,
4634 k: [0, 0]
4635 },
4636 nm: "Transform",
4637 o: {
4638 a: 0,
4639 ix: 7,
4640 k: 100
4641 },
4642 p: {
4643 a: 0,
4644 ix: 2,
4645 k: [0, 0]
4646 },
4647 r: {
4648 a: 1,
4649 ix: 6,
4650 k: [{
4651 s: 0,
4652 e: 0,
4653 t: 0
4654 }, {
4655 s: 0,
4656 e: 0,
4657 t: 1
4658 }]
4659 },
4660 s: {
4661 a: 0,
4662 ix: 3,
4663 k: [100, 100]
4664 },
4665 sa: {
4666 a: 0,
4667 ix: 5,
4668 k: 0
4669 },
4670 sk: {
4671 a: 0,
4672 ix: 4,
4673 k: 0
4674 },
4675 ty: "tr"
4676 });
4677 this.arr.splice(0, 0, group);
4678 this._groups.splice(0, 0, group);
4679 this._currentCopies += 1;
4680 }
4681 this.elem.reloadShapes();
4682 hasReloaded = true;
4683 }
4684 cont = 0;
4685 var renderFlag;
4686 for (i = 0; i <= this._groups.length - 1; i += 1) {
4687 renderFlag = cont < copies;
4688 this._groups[i]._render = renderFlag;
4689 this.changeGroupRender(this._groups[i].it, renderFlag);
4690 if (!renderFlag) {
4691 var elems = this.elemsData[i].it;
4692 var transformData = elems[elems.length - 1];
4693 if (transformData.transform.op.v !== 0) {
4694 transformData.transform.op._mdf = true;
4695 transformData.transform.op.v = 0;
4696 } else transformData.transform.op._mdf = false;
4697 }
4698 cont += 1;
4699 }
4700 this._currentCopies = copies;
4701 var offset = this.o.v;
4702 var offsetModulo = offset % 1;
4703 var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
4704 var pProps = this.pMatrix.props;
4705 var rProps = this.rMatrix.props;
4706 var sProps = this.sMatrix.props;
4707 this.pMatrix.reset();
4708 this.rMatrix.reset();
4709 this.sMatrix.reset();
4710 this.tMatrix.reset();
4711 this.matrix.reset();
4712 var iteration = 0;
4713 if (offset > 0) {
4714 while (iteration < roundOffset) {
4715 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
4716 iteration += 1;
4717 }
4718 if (offsetModulo) {
4719 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
4720 iteration += offsetModulo;
4721 }
4722 } else if (offset < 0) {
4723 while (iteration > roundOffset) {
4724 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
4725 iteration -= 1;
4726 }
4727 if (offsetModulo) {
4728 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
4729 iteration -= offsetModulo;
4730 }
4731 }
4732 i = this.data.m === 1 ? 0 : this._currentCopies - 1;
4733 dir = this.data.m === 1 ? 1 : -1;
4734 cont = this._currentCopies;
4735 var j;
4736 var jLen;
4737 while (cont) {
4738 items = this.elemsData[i].it;
4739 itemsTransform = items[items.length - 1].transform.mProps.v.props;
4740 jLen = itemsTransform.length;
4741 items[items.length - 1].transform.mProps._mdf = true;
4742 items[items.length - 1].transform.op._mdf = true;
4743 items[items.length - 1].transform.op.v = this._currentCopies === 1 ? this.so.v : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
4744 if (iteration !== 0) {
4745 if (i !== 0 && dir === 1 || i !== this._currentCopies - 1 && dir === -1) this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
4746 this.matrix.transform(rProps[0], rProps[1], rProps[2], rProps[3], rProps[4], rProps[5], rProps[6], rProps[7], rProps[8], rProps[9], rProps[10], rProps[11], rProps[12], rProps[13], rProps[14], rProps[15]);
4747 this.matrix.transform(sProps[0], sProps[1], sProps[2], sProps[3], sProps[4], sProps[5], sProps[6], sProps[7], sProps[8], sProps[9], sProps[10], sProps[11], sProps[12], sProps[13], sProps[14], sProps[15]);
4748 this.matrix.transform(pProps[0], pProps[1], pProps[2], pProps[3], pProps[4], pProps[5], pProps[6], pProps[7], pProps[8], pProps[9], pProps[10], pProps[11], pProps[12], pProps[13], pProps[14], pProps[15]);
4749 for (j = 0; j < jLen; j += 1) itemsTransform[j] = this.matrix.props[j];
4750 this.matrix.reset();
4751 } else {
4752 this.matrix.reset();
4753 for (j = 0; j < jLen; j += 1) itemsTransform[j] = this.matrix.props[j];
4754 }
4755 iteration += 1;
4756 cont -= 1;
4757 i += dir;
4758 }
4759 } else {
4760 cont = this._currentCopies;
4761 i = 0;
4762 dir = 1;
4763 while (cont) {
4764 items = this.elemsData[i].it;
4765 itemsTransform = items[items.length - 1].transform.mProps.v.props;
4766 items[items.length - 1].transform.mProps._mdf = false;
4767 items[items.length - 1].transform.op._mdf = false;
4768 cont -= 1;
4769 i += dir;
4770 }
4771 }
4772 return hasReloaded;
4773 };
4774 RepeaterModifier.prototype.addShape = function() {};
4775 function RoundCornersModifier() {}
4776 extendPrototype([ShapeModifier], RoundCornersModifier);
4777 RoundCornersModifier.prototype.initModifierProperties = function(elem, data) {
4778 this.getValue = this.processKeys;
4779 this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
4780 this._isAnimated = !!this.rd.effectsSequence.length;
4781 };
4782 RoundCornersModifier.prototype.processPath = function(path, round) {
4783 var clonedPath = shapePool.newElement();
4784 clonedPath.c = path.c;
4785 var i;
4786 var len = path._length;
4787 var currentV;
4788 var currentI;
4789 var currentO;
4790 var closerV;
4791 var distance;
4792 var newPosPerc;
4793 var index = 0;
4794 var vX;
4795 var vY;
4796 var oX;
4797 var oY;
4798 var iX;
4799 var iY;
4800 for (i = 0; i < len; i += 1) {
4801 currentV = path.v[i];
4802 currentO = path.o[i];
4803 currentI = path.i[i];
4804 if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) if ((i === 0 || i === len - 1) && !path.c) {
4805 clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
4806 index += 1;
4807 } else {
4808 if (i === 0) closerV = path.v[len - 1];
4809 else closerV = path.v[i - 1];
4810 distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
4811 newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
4812 iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
4813 vX = iX;
4814 iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
4815 vY = iY;
4816 oX = vX - (vX - currentV[0]) * roundCorner;
4817 oY = vY - (vY - currentV[1]) * roundCorner;
4818 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
4819 index += 1;
4820 if (i === len - 1) closerV = path.v[0];
4821 else closerV = path.v[i + 1];
4822 distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
4823 newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
4824 oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
4825 vX = oX;
4826 oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
4827 vY = oY;
4828 iX = vX - (vX - currentV[0]) * roundCorner;
4829 iY = vY - (vY - currentV[1]) * roundCorner;
4830 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
4831 index += 1;
4832 }
4833 else {
4834 clonedPath.setTripleAt(path.v[i][0], path.v[i][1], path.o[i][0], path.o[i][1], path.i[i][0], path.i[i][1], index);
4835 index += 1;
4836 }
4837 }
4838 return clonedPath;
4839 };
4840 RoundCornersModifier.prototype.processShapes = function(_isFirstFrame) {
4841 var shapePaths;
4842 var i;
4843 var len = this.shapes.length;
4844 var j;
4845 var jLen;
4846 var rd = this.rd.v;
4847 if (rd !== 0) {
4848 var shapeData;
4849 var localShapeCollection;
4850 for (i = 0; i < len; i += 1) {
4851 shapeData = this.shapes[i];
4852 localShapeCollection = shapeData.localShapeCollection;
4853 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
4854 localShapeCollection.releaseShapes();
4855 shapeData.shape._mdf = true;
4856 shapePaths = shapeData.shape.paths.shapes;
4857 jLen = shapeData.shape.paths._length;
4858 for (j = 0; j < jLen; j += 1) localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
4859 }
4860 shapeData.shape.paths = shapeData.localShapeCollection;
4861 }
4862 }
4863 if (!this.dynamicProperties.length) this._mdf = false;
4864 };
4865 function floatEqual(a, b) {
4866 return Math.abs(a - b) * 1e5 <= Math.min(Math.abs(a), Math.abs(b));
4867 }
4868 function floatZero(f) {
4869 return Math.abs(f) <= 1e-5;
4870 }
4871 function lerp(p0, p1, amount) {
4872 return p0 * (1 - amount) + p1 * amount;
4873 }
4874 function lerpPoint(p0, p1, amount) {
4875 return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
4876 }
4877 function quadRoots(a, b, c) {
4878 if (a === 0) return [];
4879 var s = b * b - 4 * a * c;
4880 if (s < 0) return [];
4881 var singleRoot = -b / (2 * a);
4882 if (s === 0) return [singleRoot];
4883 var delta = Math.sqrt(s) / (2 * a);
4884 return [singleRoot - delta, singleRoot + delta];
4885 }
4886 function polynomialCoefficients(p0, p1, p2, p3) {
4887 return [
4888 -p0 + 3 * p1 - 3 * p2 + p3,
4889 3 * p0 - 6 * p1 + 3 * p2,
4890 -3 * p0 + 3 * p1,
4891 p0
4892 ];
4893 }
4894 function singlePoint(p) {
4895 return new PolynomialBezier(p, p, p, p, false);
4896 }
4897 function PolynomialBezier(p0, p1, p2, p3, linearize) {
4898 if (linearize && pointEqual(p0, p1)) p1 = lerpPoint(p0, p3, 1 / 3);
4899 if (linearize && pointEqual(p2, p3)) p2 = lerpPoint(p0, p3, 2 / 3);
4900 var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
4901 var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
4902 this.a = [coeffx[0], coeffy[0]];
4903 this.b = [coeffx[1], coeffy[1]];
4904 this.c = [coeffx[2], coeffy[2]];
4905 this.d = [coeffx[3], coeffy[3]];
4906 this.points = [
4907 p0,
4908 p1,
4909 p2,
4910 p3
4911 ];
4912 }
4913 PolynomialBezier.prototype.point = function(t) {
4914 return [((this.a[0] * t + this.b[0]) * t + this.c[0]) * t + this.d[0], ((this.a[1] * t + this.b[1]) * t + this.c[1]) * t + this.d[1]];
4915 };
4916 PolynomialBezier.prototype.derivative = function(t) {
4917 return [(3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0], (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1]];
4918 };
4919 PolynomialBezier.prototype.tangentAngle = function(t) {
4920 var p = this.derivative(t);
4921 return Math.atan2(p[1], p[0]);
4922 };
4923 PolynomialBezier.prototype.normalAngle = function(t) {
4924 var p = this.derivative(t);
4925 return Math.atan2(p[0], p[1]);
4926 };
4927 PolynomialBezier.prototype.inflectionPoints = function() {
4928 var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
4929 if (floatZero(denom)) return [];
4930 var tcusp = -.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1]) / denom;
4931 var square = tcusp * tcusp - 1 / 3 * (this.b[1] * this.c[0] - this.b[0] * this.c[1]) / denom;
4932 if (square < 0) return [];
4933 var root = Math.sqrt(square);
4934 if (floatZero(root)) {
4935 if (root > 0 && root < 1) return [tcusp];
4936 return [];
4937 }
4938 return [tcusp - root, tcusp + root].filter(function(r) {
4939 return r > 0 && r < 1;
4940 });
4941 };
4942 PolynomialBezier.prototype.split = function(t) {
4943 if (t <= 0) return [singlePoint(this.points[0]), this];
4944 if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
4945 var p10 = lerpPoint(this.points[0], this.points[1], t);
4946 var p11 = lerpPoint(this.points[1], this.points[2], t);
4947 var p12 = lerpPoint(this.points[2], this.points[3], t);
4948 var p20 = lerpPoint(p10, p11, t);
4949 var p21 = lerpPoint(p11, p12, t);
4950 var p3 = lerpPoint(p20, p21, t);
4951 return [new PolynomialBezier(this.points[0], p10, p20, p3, true), new PolynomialBezier(p3, p21, p12, this.points[3], true)];
4952 };
4953 function extrema(bez, comp) {
4954 var min = bez.points[0][comp];
4955 var max = bez.points[bez.points.length - 1][comp];
4956 if (min > max) {
4957 var e = max;
4958 max = min;
4959 min = e;
4960 }
4961 var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
4962 for (var i = 0; i < f.length; i += 1) if (f[i] > 0 && f[i] < 1) {
4963 var val = bez.point(f[i])[comp];
4964 if (val < min) min = val;
4965 else if (val > max) max = val;
4966 }
4967 return {
4968 min,
4969 max
4970 };
4971 }
4972 PolynomialBezier.prototype.bounds = function() {
4973 return {
4974 x: extrema(this, 0),
4975 y: extrema(this, 1)
4976 };
4977 };
4978 PolynomialBezier.prototype.boundingBox = function() {
4979 var bounds = this.bounds();
4980 return {
4981 left: bounds.x.min,
4982 right: bounds.x.max,
4983 top: bounds.y.min,
4984 bottom: bounds.y.max,
4985 width: bounds.x.max - bounds.x.min,
4986 height: bounds.y.max - bounds.y.min,
4987 cx: (bounds.x.max + bounds.x.min) / 2,
4988 cy: (bounds.y.max + bounds.y.min) / 2
4989 };
4990 };
4991 function intersectData(bez, t1, t2) {
4992 var box = bez.boundingBox();
4993 return {
4994 cx: box.cx,
4995 cy: box.cy,
4996 width: box.width,
4997 height: box.height,
4998 bez,
4999 t: (t1 + t2) / 2,
5000 t1,
5001 t2
5002 };
5003 }
5004 function splitData(data) {
5005 var split = data.bez.split(.5);
5006 return [intersectData(split[0], data.t1, data.t), intersectData(split[1], data.t, data.t2)];
5007 }
5008 function boxIntersect(b1, b2) {
5009 return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
5010 }
5011 function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
5012 if (!boxIntersect(d1, d2)) return;
5013 if (depth >= maxRecursion || d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance) {
5014 intersections.push([d1.t, d2.t]);
5015 return;
5016 }
5017 var d1s = splitData(d1);
5018 var d2s = splitData(d2);
5019 intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
5020 intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
5021 intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
5022 intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
5023 }
5024 PolynomialBezier.prototype.intersections = function(other, tolerance, maxRecursion) {
5025 if (tolerance === void 0) tolerance = 2;
5026 if (maxRecursion === void 0) maxRecursion = 7;
5027 var intersections = [];
5028 intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
5029 return intersections;
5030 };
5031 PolynomialBezier.shapeSegment = function(shapePath, index) {
5032 var nextIndex = (index + 1) % shapePath.length();
5033 return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
5034 };
5035 PolynomialBezier.shapeSegmentInverted = function(shapePath, index) {
5036 var nextIndex = (index + 1) % shapePath.length();
5037 return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
5038 };
5039 function crossProduct(a, b) {
5040 return [
5041 a[1] * b[2] - a[2] * b[1],
5042 a[2] * b[0] - a[0] * b[2],
5043 a[0] * b[1] - a[1] * b[0]
5044 ];
5045 }
5046 function lineIntersection(start1, end1, start2, end2) {
5047 var v1 = [
5048 start1[0],
5049 start1[1],
5050 1
5051 ];
5052 var v2 = [
5053 end1[0],
5054 end1[1],
5055 1
5056 ];
5057 var v3 = [
5058 start2[0],
5059 start2[1],
5060 1
5061 ];
5062 var v4 = [
5063 end2[0],
5064 end2[1],
5065 1
5066 ];
5067 var r = crossProduct(crossProduct(v1, v2), crossProduct(v3, v4));
5068 if (floatZero(r[2])) return null;
5069 return [r[0] / r[2], r[1] / r[2]];
5070 }
5071 function polarOffset(p, angle, length) {
5072 return [p[0] + Math.cos(angle) * length, p[1] - Math.sin(angle) * length];
5073 }
5074 function pointDistance(p1, p2) {
5075 return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
5076 }
5077 function pointEqual(p1, p2) {
5078 return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
5079 }
5080 function ZigZagModifier() {}
5081 extendPrototype([ShapeModifier], ZigZagModifier);
5082 ZigZagModifier.prototype.initModifierProperties = function(elem, data) {
5083 this.getValue = this.processKeys;
5084 this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
5085 this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
5086 this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
5087 this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
5088 };
5089 function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
5090 var angO = angle - Math.PI / 2;
5091 var angI = angle + Math.PI / 2;
5092 var px = point[0] + Math.cos(angle) * direction * amplitude;
5093 var py = point[1] - Math.sin(angle) * direction * amplitude;
5094 outputBezier.setTripleAt(px, py, px + Math.cos(angO) * outAmplitude, py - Math.sin(angO) * outAmplitude, px + Math.cos(angI) * inAmplitude, py - Math.sin(angI) * inAmplitude, outputBezier.length());
5095 }
5096 function getPerpendicularVector(pt1, pt2) {
5097 var vector = [pt2[0] - pt1[0], pt2[1] - pt1[1]];
5098 var rot = -Math.PI * .5;
5099 return [Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1], Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1]];
5100 }
5101 function getProjectingAngle(path, cur) {
5102 var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
5103 var nextIndex = (cur + 1) % path.length();
5104 var prevPoint = path.v[prevIndex];
5105 var nextPoint = path.v[nextIndex];
5106 var pVector = getPerpendicularVector(prevPoint, nextPoint);
5107 return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
5108 }
5109 function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
5110 var angle = getProjectingAngle(path, cur);
5111 var point = path.v[cur % path._length];
5112 var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
5113 var nextPoint = path.v[(cur + 1) % path._length];
5114 var prevDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2)) : 0;
5115 var nextDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2)) : 0;
5116 setPoint(outputBezier, path.v[cur % path._length], angle, direction, amplitude, nextDist / ((frequency + 1) * 2), prevDist / ((frequency + 1) * 2), pointType);
5117 }
5118 function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
5119 for (var i = 0; i < frequency; i += 1) {
5120 var t = (i + 1) / (frequency + 1);
5121 var dist = pointType === 2 ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2)) : 0;
5122 var angle = segment.normalAngle(t);
5123 setPoint(outputBezier, segment.point(t), angle, direction, amplitude, dist / ((frequency + 1) * 2), dist / ((frequency + 1) * 2), pointType);
5124 direction = -direction;
5125 }
5126 return direction;
5127 }
5128 ZigZagModifier.prototype.processPath = function(path, amplitude, frequency, pointType) {
5129 var count = path._length;
5130 var clonedPath = shapePool.newElement();
5131 clonedPath.c = path.c;
5132 if (!path.c) count -= 1;
5133 if (count === 0) return clonedPath;
5134 var direction = -1;
5135 var segment = PolynomialBezier.shapeSegment(path, 0);
5136 zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
5137 for (var i = 0; i < count; i += 1) {
5138 direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
5139 if (i === count - 1 && !path.c) segment = null;
5140 else segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
5141 zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
5142 }
5143 return clonedPath;
5144 };
5145 ZigZagModifier.prototype.processShapes = function(_isFirstFrame) {
5146 var shapePaths;
5147 var i;
5148 var len = this.shapes.length;
5149 var j;
5150 var jLen;
5151 var amplitude = this.amplitude.v;
5152 var frequency = Math.max(0, Math.round(this.frequency.v));
5153 var pointType = this.pointsType.v;
5154 if (amplitude !== 0) {
5155 var shapeData;
5156 var localShapeCollection;
5157 for (i = 0; i < len; i += 1) {
5158 shapeData = this.shapes[i];
5159 localShapeCollection = shapeData.localShapeCollection;
5160 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
5161 localShapeCollection.releaseShapes();
5162 shapeData.shape._mdf = true;
5163 shapePaths = shapeData.shape.paths.shapes;
5164 jLen = shapeData.shape.paths._length;
5165 for (j = 0; j < jLen; j += 1) localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
5166 }
5167 shapeData.shape.paths = shapeData.localShapeCollection;
5168 }
5169 }
5170 if (!this.dynamicProperties.length) this._mdf = false;
5171 };
5172 function linearOffset(p1, p2, amount) {
5173 var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
5174 return [polarOffset(p1, angle, amount), polarOffset(p2, angle, amount)];
5175 }
5176 function offsetSegment(segment, amount) {
5177 var p0;
5178 var p1a;
5179 var p1b;
5180 var p2b;
5181 var p2a;
5182 var p3;
5183 var e = linearOffset(segment.points[0], segment.points[1], amount);
5184 p0 = e[0];
5185 p1a = e[1];
5186 e = linearOffset(segment.points[1], segment.points[2], amount);
5187 p1b = e[0];
5188 p2b = e[1];
5189 e = linearOffset(segment.points[2], segment.points[3], amount);
5190 p2a = e[0];
5191 p3 = e[1];
5192 var p1 = lineIntersection(p0, p1a, p1b, p2b);
5193 if (p1 === null) p1 = p1a;
5194 var p2 = lineIntersection(p2a, p3, p1b, p2b);
5195 if (p2 === null) p2 = p2a;
5196 return new PolynomialBezier(p0, p1, p2, p3);
5197 }
5198 function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
5199 var p0 = seg1.points[3];
5200 var p1 = seg2.points[0];
5201 if (lineJoin === 3) return p0;
5202 if (pointEqual(p0, p1)) return p0;
5203 if (lineJoin === 2) {
5204 var angleOut = -seg1.tangentAngle(1);
5205 var angleIn = -seg2.tangentAngle(0) + Math.PI;
5206 var center = lineIntersection(p0, polarOffset(p0, angleOut + Math.PI / 2, 100), p1, polarOffset(p1, angleOut + Math.PI / 2, 100));
5207 var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
5208 var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
5209 outputBezier.setXYAt(tan[0], tan[1], "o", outputBezier.length() - 1);
5210 tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
5211 outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
5212 return p1;
5213 }
5214 var intersection = lineIntersection(pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2], p0, p1, pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1]);
5215 if (intersection && pointDistance(intersection, p0) < miterLimit) {
5216 outputBezier.setTripleAt(intersection[0], intersection[1], intersection[0], intersection[1], intersection[0], intersection[1], outputBezier.length());
5217 return intersection;
5218 }
5219 return p0;
5220 }
5221 function getIntersection(a, b) {
5222 var intersect = a.intersections(b);
5223 if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
5224 if (intersect.length) return intersect[0];
5225 return null;
5226 }
5227 function pruneSegmentIntersection(a, b) {
5228 var outa = a.slice();
5229 var outb = b.slice();
5230 var intersect = getIntersection(a[a.length - 1], b[0]);
5231 if (intersect) {
5232 outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
5233 outb[0] = b[0].split(intersect[1])[1];
5234 }
5235 if (a.length > 1 && b.length > 1) {
5236 intersect = getIntersection(a[0], b[b.length - 1]);
5237 if (intersect) return [[a[0].split(intersect[0])[0]], [b[b.length - 1].split(intersect[1])[1]]];
5238 }
5239 return [outa, outb];
5240 }
5241 function pruneIntersections(segments) {
5242 var e;
5243 for (var i = 1; i < segments.length; i += 1) {
5244 e = pruneSegmentIntersection(segments[i - 1], segments[i]);
5245 segments[i - 1] = e[0];
5246 segments[i] = e[1];
5247 }
5248 if (segments.length > 1) {
5249 e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
5250 segments[segments.length - 1] = e[0];
5251 segments[0] = e[1];
5252 }
5253 return segments;
5254 }
5255 function offsetSegmentSplit(segment, amount) {
5256 var flex = segment.inflectionPoints();
5257 var left;
5258 var right;
5259 var split;
5260 var mid;
5261 if (flex.length === 0) return [offsetSegment(segment, amount)];
5262 if (flex.length === 1 || floatEqual(flex[1], 1)) {
5263 split = segment.split(flex[0]);
5264 left = split[0];
5265 right = split[1];
5266 return [offsetSegment(left, amount), offsetSegment(right, amount)];
5267 }
5268 split = segment.split(flex[0]);
5269 left = split[0];
5270 var t = (flex[1] - flex[0]) / (1 - flex[0]);
5271 split = split[1].split(t);
5272 mid = split[0];
5273 right = split[1];
5274 return [
5275 offsetSegment(left, amount),
5276 offsetSegment(mid, amount),
5277 offsetSegment(right, amount)
5278 ];
5279 }
5280 function OffsetPathModifier() {}
5281 extendPrototype([ShapeModifier], OffsetPathModifier);
5282 OffsetPathModifier.prototype.initModifierProperties = function(elem, data) {
5283 this.getValue = this.processKeys;
5284 this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
5285 this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
5286 this.lineJoin = data.lj;
5287 this._isAnimated = this.amount.effectsSequence.length !== 0;
5288 };
5289 OffsetPathModifier.prototype.processPath = function(inputBezier, amount, lineJoin, miterLimit) {
5290 var outputBezier = shapePool.newElement();
5291 outputBezier.c = inputBezier.c;
5292 var count = inputBezier.length();
5293 if (!inputBezier.c) count -= 1;
5294 var i;
5295 var j;
5296 var segment;
5297 var multiSegments = [];
5298 for (i = 0; i < count; i += 1) {
5299 segment = PolynomialBezier.shapeSegment(inputBezier, i);
5300 multiSegments.push(offsetSegmentSplit(segment, amount));
5301 }
5302 if (!inputBezier.c) for (i = count - 1; i >= 0; i -= 1) {
5303 segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
5304 multiSegments.push(offsetSegmentSplit(segment, amount));
5305 }
5306 multiSegments = pruneIntersections(multiSegments);
5307 var lastPoint = null;
5308 var lastSeg = null;
5309 for (i = 0; i < multiSegments.length; i += 1) {
5310 var multiSegment = multiSegments[i];
5311 if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
5312 lastSeg = multiSegment[multiSegment.length - 1];
5313 for (j = 0; j < multiSegment.length; j += 1) {
5314 segment = multiSegment[j];
5315 if (lastPoint && pointEqual(segment.points[0], lastPoint)) outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], "o", outputBezier.length() - 1);
5316 else outputBezier.setTripleAt(segment.points[0][0], segment.points[0][1], segment.points[1][0], segment.points[1][1], segment.points[0][0], segment.points[0][1], outputBezier.length());
5317 outputBezier.setTripleAt(segment.points[3][0], segment.points[3][1], segment.points[3][0], segment.points[3][1], segment.points[2][0], segment.points[2][1], outputBezier.length());
5318 lastPoint = segment.points[3];
5319 }
5320 }
5321 if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
5322 return outputBezier;
5323 };
5324 OffsetPathModifier.prototype.processShapes = function(_isFirstFrame) {
5325 var shapePaths;
5326 var i;
5327 var len = this.shapes.length;
5328 var j;
5329 var jLen;
5330 var amount = this.amount.v;
5331 var miterLimit = this.miterLimit.v;
5332 var lineJoin = this.lineJoin;
5333 if (amount !== 0) {
5334 var shapeData;
5335 var localShapeCollection;
5336 for (i = 0; i < len; i += 1) {
5337 shapeData = this.shapes[i];
5338 localShapeCollection = shapeData.localShapeCollection;
5339 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
5340 localShapeCollection.releaseShapes();
5341 shapeData.shape._mdf = true;
5342 shapePaths = shapeData.shape.paths.shapes;
5343 jLen = shapeData.shape.paths._length;
5344 for (j = 0; j < jLen; j += 1) localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
5345 }
5346 shapeData.shape.paths = shapeData.localShapeCollection;
5347 }
5348 }
5349 if (!this.dynamicProperties.length) this._mdf = false;
5350 };
5351 function getFontProperties(fontData) {
5352 var styles = fontData.fStyle ? fontData.fStyle.split(" ") : [];
5353 var fWeight = "normal";
5354 var fStyle = "normal";
5355 var len = styles.length;
5356 var styleName;
5357 for (var i = 0; i < len; i += 1) {
5358 styleName = styles[i].toLowerCase();
5359 switch (styleName) {
5360 case "italic":
5361 fStyle = "italic";
5362 break;
5363 case "bold":
5364 fWeight = "700";
5365 break;
5366 case "black":
5367 fWeight = "900";
5368 break;
5369 case "medium":
5370 fWeight = "500";
5371 break;
5372 case "regular":
5373 case "normal":
5374 fWeight = "400";
5375 break;
5376 case "light":
5377 case "thin":
5378 fWeight = "200";
5379 break;
5380 default: break;
5381 }
5382 }
5383 return {
5384 style: fStyle,
5385 weight: fontData.fWeight || fWeight
5386 };
5387 }
5388 var FontManager = function() {
5389 var maxWaitingTime = 5e3;
5390 var emptyChar = {
5391 w: 0,
5392 size: 0,
5393 shapes: [],
5394 data: { shapes: [] }
5395 };
5396 var combinedCharacters = [];
5397 combinedCharacters = combinedCharacters.concat([
5398 2304,
5399 2305,
5400 2306,
5401 2307,
5402 2362,
5403 2363,
5404 2364,
5405 2364,
5406 2366,
5407 2367,
5408 2368,
5409 2369,
5410 2370,
5411 2371,
5412 2372,
5413 2373,
5414 2374,
5415 2375,
5416 2376,
5417 2377,
5418 2378,
5419 2379,
5420 2380,
5421 2381,
5422 2382,
5423 2383,
5424 2387,
5425 2388,
5426 2389,
5427 2390,
5428 2391,
5429 2402,
5430 2403
5431 ]);
5432 var BLACK_FLAG_CODE_POINT = 127988;
5433 var CANCEL_TAG_CODE_POINT = 917631;
5434 var A_TAG_CODE_POINT = 917601;
5435 var Z_TAG_CODE_POINT = 917626;
5436 var VARIATION_SELECTOR_16_CODE_POINT = 65039;
5437 var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
5438 var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
5439 var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
5440 var surrogateModifiers = [
5441 "d83cdffb",
5442 "d83cdffc",
5443 "d83cdffd",
5444 "d83cdffe",
5445 "d83cdfff"
5446 ];
5447 function trimFontOptions(font) {
5448 var familyArray = font.split(",");
5449 var i;
5450 var len = familyArray.length;
5451 var enabledFamilies = [];
5452 for (i = 0; i < len; i += 1) if (familyArray[i] !== "sans-serif" && familyArray[i] !== "monospace") enabledFamilies.push(familyArray[i]);
5453 return enabledFamilies.join(",");
5454 }
5455 function setUpNode(font, family) {
5456 var parentNode = createTag("span");
5457 parentNode.setAttribute("aria-hidden", true);
5458 parentNode.style.fontFamily = family;
5459 var node = createTag("span");
5460 node.innerText = "giItT1WQy@!-/#";
5461 parentNode.style.position = "absolute";
5462 parentNode.style.left = "-10000px";
5463 parentNode.style.top = "-10000px";
5464 parentNode.style.fontSize = "300px";
5465 parentNode.style.fontVariant = "normal";
5466 parentNode.style.fontStyle = "normal";
5467 parentNode.style.fontWeight = "normal";
5468 parentNode.style.letterSpacing = "0";
5469 parentNode.appendChild(node);
5470 document.body.appendChild(parentNode);
5471 var width = node.offsetWidth;
5472 node.style.fontFamily = trimFontOptions(font) + ", " + family;
5473 return {
5474 node,
5475 w: width,
5476 parent: parentNode
5477 };
5478 }
5479 function checkLoadedFonts() {
5480 var i;
5481 var len = this.fonts.length;
5482 var node;
5483 var w;
5484 var loadedCount = len;
5485 for (i = 0; i < len; i += 1) if (this.fonts[i].loaded) loadedCount -= 1;
5486 else if (this.fonts[i].fOrigin === "n" || this.fonts[i].origin === 0) this.fonts[i].loaded = true;
5487 else {
5488 node = this.fonts[i].monoCase.node;
5489 w = this.fonts[i].monoCase.w;
5490 if (node.offsetWidth !== w) {
5491 loadedCount -= 1;
5492 this.fonts[i].loaded = true;
5493 } else {
5494 node = this.fonts[i].sansCase.node;
5495 w = this.fonts[i].sansCase.w;
5496 if (node.offsetWidth !== w) {
5497 loadedCount -= 1;
5498 this.fonts[i].loaded = true;
5499 }
5500 }
5501 if (this.fonts[i].loaded) {
5502 this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
5503 this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
5504 }
5505 }
5506 if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) setTimeout(this.checkLoadedFontsBinded, 20);
5507 else setTimeout(this.setIsLoadedBinded, 10);
5508 }
5509 function createHelper(fontData, def) {
5510 var engine = document.body && def ? "svg" : "canvas";
5511 var helper;
5512 var fontProps = getFontProperties(fontData);
5513 if (engine === "svg") {
5514 var tHelper = createNS("text");
5515 tHelper.style.fontSize = "100px";
5516 tHelper.setAttribute("font-family", fontData.fFamily);
5517 tHelper.setAttribute("font-style", fontProps.style);
5518 tHelper.setAttribute("font-weight", fontProps.weight);
5519 tHelper.textContent = "1";
5520 if (fontData.fClass) {
5521 tHelper.style.fontFamily = "inherit";
5522 tHelper.setAttribute("class", fontData.fClass);
5523 } else tHelper.style.fontFamily = fontData.fFamily;
5524 def.appendChild(tHelper);
5525 helper = tHelper;
5526 } else {
5527 var tCanvasHelper = new OffscreenCanvas(500, 500).getContext("2d");
5528 tCanvasHelper.font = fontProps.style + " " + fontProps.weight + " 100px " + fontData.fFamily;
5529 helper = tCanvasHelper;
5530 }
5531 function measure(text) {
5532 if (engine === "svg") {
5533 helper.textContent = text;
5534 return helper.getComputedTextLength();
5535 }
5536 return helper.measureText(text).width;
5537 }
5538 return { measureText: measure };
5539 }
5540 function addFonts(fontData, defs) {
5541 if (!fontData) {
5542 this.isLoaded = true;
5543 return;
5544 }
5545 if (this.chars) {
5546 this.isLoaded = true;
5547 this.fonts = fontData.list;
5548 return;
5549 }
5550 if (!document.body) {
5551 this.isLoaded = true;
5552 fontData.list.forEach(function(data) {
5553 data.helper = createHelper(data);
5554 data.cache = {};
5555 });
5556 this.fonts = fontData.list;
5557 return;
5558 }
5559 var fontArr = fontData.list;
5560 var i;
5561 var len = fontArr.length;
5562 var _pendingFonts = len;
5563 for (i = 0; i < len; i += 1) {
5564 var shouldLoadFont = true;
5565 var loadedSelector;
5566 var j;
5567 fontArr[i].loaded = false;
5568 fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, "monospace");
5569 fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, "sans-serif");
5570 if (!fontArr[i].fPath) {
5571 fontArr[i].loaded = true;
5572 _pendingFonts -= 1;
5573 } else if (fontArr[i].fOrigin === "p" || fontArr[i].origin === 3) {
5574 loadedSelector = document.querySelectorAll("style[f-forigin=\"p\"][f-family=\"" + fontArr[i].fFamily + "\"], style[f-origin=\"3\"][f-family=\"" + fontArr[i].fFamily + "\"]");
5575 if (loadedSelector.length > 0) shouldLoadFont = false;
5576 if (shouldLoadFont) {
5577 var s = createTag("style");
5578 s.setAttribute("f-forigin", fontArr[i].fOrigin);
5579 s.setAttribute("f-origin", fontArr[i].origin);
5580 s.setAttribute("f-family", fontArr[i].fFamily);
5581 s.type = "text/css";
5582 s.innerText = "@font-face {font-family: " + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
5583 defs.appendChild(s);
5584 }
5585 } else if (fontArr[i].fOrigin === "g" || fontArr[i].origin === 1) {
5586 loadedSelector = document.querySelectorAll("link[f-forigin=\"g\"], link[f-origin=\"1\"]");
5587 for (j = 0; j < loadedSelector.length; j += 1) if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) shouldLoadFont = false;
5588 if (shouldLoadFont) {
5589 var l = createTag("link");
5590 l.setAttribute("f-forigin", fontArr[i].fOrigin);
5591 l.setAttribute("f-origin", fontArr[i].origin);
5592 l.type = "text/css";
5593 l.rel = "stylesheet";
5594 l.href = fontArr[i].fPath;
5595 document.body.appendChild(l);
5596 }
5597 } else if (fontArr[i].fOrigin === "t" || fontArr[i].origin === 2) {
5598 loadedSelector = document.querySelectorAll("script[f-forigin=\"t\"], script[f-origin=\"2\"]");
5599 for (j = 0; j < loadedSelector.length; j += 1) if (fontArr[i].fPath === loadedSelector[j].src) shouldLoadFont = false;
5600 if (shouldLoadFont) {
5601 var sc = createTag("link");
5602 sc.setAttribute("f-forigin", fontArr[i].fOrigin);
5603 sc.setAttribute("f-origin", fontArr[i].origin);
5604 sc.setAttribute("rel", "stylesheet");
5605 sc.setAttribute("href", fontArr[i].fPath);
5606 defs.appendChild(sc);
5607 }
5608 }
5609 fontArr[i].helper = createHelper(fontArr[i], defs);
5610 fontArr[i].cache = {};
5611 this.fonts.push(fontArr[i]);
5612 }
5613 if (_pendingFonts === 0) this.isLoaded = true;
5614 else setTimeout(this.checkLoadedFonts.bind(this), 100);
5615 }
5616 function addChars(chars) {
5617 if (!chars) return;
5618 if (!this.chars) this.chars = [];
5619 var i;
5620 var len = chars.length;
5621 var j;
5622 var jLen = this.chars.length;
5623 var found;
5624 for (i = 0; i < len; i += 1) {
5625 j = 0;
5626 found = false;
5627 while (j < jLen) {
5628 if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) found = true;
5629 j += 1;
5630 }
5631 if (!found) {
5632 this.chars.push(chars[i]);
5633 jLen += 1;
5634 }
5635 }
5636 }
5637 function getCharData(_char, style, font) {
5638 var i = 0;
5639 var len = this.chars.length;
5640 while (i < len) {
5641 if (this.chars[i].ch === _char && this.chars[i].style === style && this.chars[i].fFamily === font) return this.chars[i];
5642 i += 1;
5643 }
5644 if ((typeof _char === "string" && _char.charCodeAt(0) !== 13 || !_char) && console && console.warn && !this._warned) {
5645 this._warned = true;
5646 console.warn("Missing character from exported characters list: ", _char, style, font);
5647 }
5648 return emptyChar;
5649 }
5650 function measureText(_char2, fontName, size) {
5651 var fontData = this.getFontByName(fontName);
5652 var index = _char2;
5653 if (!fontData.cache[index]) {
5654 var tHelper = fontData.helper;
5655 if (_char2 === " ") {
5656 var doubleSize = tHelper.measureText("|" + _char2 + "|");
5657 var singleSize = tHelper.measureText("||");
5658 fontData.cache[index] = (doubleSize - singleSize) / 100;
5659 } else fontData.cache[index] = tHelper.measureText(_char2) / 100;
5660 }
5661 return fontData.cache[index] * size;
5662 }
5663 function getFontByName(name) {
5664 var i = 0;
5665 var len = this.fonts.length;
5666 while (i < len) {
5667 if (this.fonts[i].fName === name) return this.fonts[i];
5668 i += 1;
5669 }
5670 return this.fonts[0];
5671 }
5672 function getCodePoint(string) {
5673 var codePoint = 0;
5674 var first = string.charCodeAt(0);
5675 if (first >= 55296 && first <= 56319) {
5676 var second = string.charCodeAt(1);
5677 if (second >= 56320 && second <= 57343) codePoint = (first - 55296) * 1024 + second - 56320 + 65536;
5678 }
5679 return codePoint;
5680 }
5681 function isModifier(firstCharCode, secondCharCode) {
5682 var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
5683 return surrogateModifiers.indexOf(sum) !== -1;
5684 }
5685 function isZeroWidthJoiner(charCode) {
5686 return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
5687 }
5688 function isVariationSelector(charCode) {
5689 return charCode === VARIATION_SELECTOR_16_CODE_POINT;
5690 }
5691 function isRegionalCode(string) {
5692 var codePoint = getCodePoint(string);
5693 if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) return true;
5694 return false;
5695 }
5696 function isFlagEmoji(string) {
5697 return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
5698 }
5699 function isCombinedCharacter(_char3) {
5700 return combinedCharacters.indexOf(_char3) !== -1;
5701 }
5702 function isRegionalFlag(text, index) {
5703 var codePoint = getCodePoint(text.substr(index, 2));
5704 if (codePoint !== BLACK_FLAG_CODE_POINT) return false;
5705 var count = 0;
5706 index += 2;
5707 while (count < 5) {
5708 codePoint = getCodePoint(text.substr(index, 2));
5709 if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) return false;
5710 count += 1;
5711 index += 2;
5712 }
5713 return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
5714 }
5715 function setIsLoaded() {
5716 this.isLoaded = true;
5717 }
5718 var Font = function Font() {
5719 this.fonts = [];
5720 this.chars = null;
5721 this.typekitLoaded = 0;
5722 this.isLoaded = false;
5723 this._warned = false;
5724 this.initTime = Date.now();
5725 this.setIsLoadedBinded = this.setIsLoaded.bind(this);
5726 this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
5727 };
5728 Font.isModifier = isModifier;
5729 Font.isZeroWidthJoiner = isZeroWidthJoiner;
5730 Font.isFlagEmoji = isFlagEmoji;
5731 Font.isRegionalCode = isRegionalCode;
5732 Font.isCombinedCharacter = isCombinedCharacter;
5733 Font.isRegionalFlag = isRegionalFlag;
5734 Font.isVariationSelector = isVariationSelector;
5735 Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
5736 Font.prototype = {
5737 addChars,
5738 addFonts,
5739 getCharData,
5740 getFontByName,
5741 measureText,
5742 checkLoadedFonts,
5743 setIsLoaded
5744 };
5745 return Font;
5746 }();
5747 function SlotManager(animationData) {
5748 this.animationData = animationData;
5749 }
5750 SlotManager.prototype.getProp = function(data) {
5751 if (this.animationData.slots && this.animationData.slots[data.sid]) return Object.assign(data, this.animationData.slots[data.sid].p);
5752 return data;
5753 };
5754 function slotFactory(animationData) {
5755 return new SlotManager(animationData);
5756 }
5757 function RenderableElement() {}
5758 RenderableElement.prototype = {
5759 initRenderable: function initRenderable() {
5760 this.isInRange = false;
5761 this.hidden = false;
5762 this.isTransparent = false;
5763 this.renderableComponents = [];
5764 },
5765 addRenderableComponent: function addRenderableComponent(component) {
5766 if (this.renderableComponents.indexOf(component) === -1) this.renderableComponents.push(component);
5767 },
5768 removeRenderableComponent: function removeRenderableComponent(component) {
5769 if (this.renderableComponents.indexOf(component) !== -1) this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
5770 },
5771 prepareRenderableFrame: function prepareRenderableFrame(num) {
5772 this.checkLayerLimits(num);
5773 },
5774 checkTransparency: function checkTransparency() {
5775 if (this.finalTransform.mProp.o.v <= 0) {
5776 if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
5777 this.isTransparent = true;
5778 this.hide();
5779 }
5780 } else if (this.isTransparent) {
5781 this.isTransparent = false;
5782 this.show();
5783 }
5784 },
5785 /**
5786 * @function
5787 * Initializes frame related properties.
5788 *
5789 * @param {number} num
5790 * current frame number in Layer's time
5791 *
5792 */
5793 checkLayerLimits: function checkLayerLimits(num) {
5794 if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
5795 if (this.isInRange !== true) {
5796 this.globalData._mdf = true;
5797 this._mdf = true;
5798 this.isInRange = true;
5799 this.show();
5800 }
5801 } else if (this.isInRange !== false) {
5802 this.globalData._mdf = true;
5803 this.isInRange = false;
5804 this.hide();
5805 }
5806 },
5807 renderRenderable: function renderRenderable() {
5808 var i;
5809 var len = this.renderableComponents.length;
5810 for (i = 0; i < len; i += 1) this.renderableComponents[i].renderFrame(this._isFirstFrame);
5811 },
5812 sourceRectAtTime: function sourceRectAtTime() {
5813 return {
5814 top: 0,
5815 left: 0,
5816 width: 100,
5817 height: 100
5818 };
5819 },
5820 getLayerSize: function getLayerSize() {
5821 if (this.data.ty === 5) return {
5822 w: this.data.textData.width,
5823 h: this.data.textData.height
5824 };
5825 return {
5826 w: this.data.width,
5827 h: this.data.height
5828 };
5829 }
5830 };
5831 var getBlendMode = function() {
5832 var blendModeEnums = {
5833 0: "source-over",
5834 1: "multiply",
5835 2: "screen",
5836 3: "overlay",
5837 4: "darken",
5838 5: "lighten",
5839 6: "color-dodge",
5840 7: "color-burn",
5841 8: "hard-light",
5842 9: "soft-light",
5843 10: "difference",
5844 11: "exclusion",
5845 12: "hue",
5846 13: "saturation",
5847 14: "color",
5848 15: "luminosity"
5849 };
5850 return function(mode) {
5851 return blendModeEnums[mode] || "";
5852 };
5853 }();
5854 function SliderEffect(data, elem, container) {
5855 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
5856 }
5857 function AngleEffect(data, elem, container) {
5858 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
5859 }
5860 function ColorEffect(data, elem, container) {
5861 this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
5862 }
5863 function PointEffect(data, elem, container) {
5864 this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
5865 }
5866 function LayerIndexEffect(data, elem, container) {
5867 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
5868 }
5869 function MaskIndexEffect(data, elem, container) {
5870 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
5871 }
5872 function CheckboxEffect(data, elem, container) {
5873 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
5874 }
5875 function NoValueEffect() {
5876 this.p = {};
5877 }
5878 function EffectsManager(data, element) {
5879 var effects = data.ef || [];
5880 this.effectElements = [];
5881 var i;
5882 var len = effects.length;
5883 var effectItem;
5884 for (i = 0; i < len; i += 1) {
5885 effectItem = new GroupEffect(effects[i], element);
5886 this.effectElements.push(effectItem);
5887 }
5888 }
5889 function GroupEffect(data, element) {
5890 this.init(data, element);
5891 }
5892 extendPrototype([DynamicPropertyContainer], GroupEffect);
5893 GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
5894 GroupEffect.prototype.init = function(data, element) {
5895 this.data = data;
5896 this.effectElements = [];
5897 this.initDynamicPropertyContainer(element);
5898 var i;
5899 var len = this.data.ef.length;
5900 var eff;
5901 var effects = this.data.ef;
5902 for (i = 0; i < len; i += 1) {
5903 eff = null;
5904 switch (effects[i].ty) {
5905 case 0:
5906 eff = new SliderEffect(effects[i], element, this);
5907 break;
5908 case 1:
5909 eff = new AngleEffect(effects[i], element, this);
5910 break;
5911 case 2:
5912 eff = new ColorEffect(effects[i], element, this);
5913 break;
5914 case 3:
5915 eff = new PointEffect(effects[i], element, this);
5916 break;
5917 case 4:
5918 case 7:
5919 eff = new CheckboxEffect(effects[i], element, this);
5920 break;
5921 case 10:
5922 eff = new LayerIndexEffect(effects[i], element, this);
5923 break;
5924 case 11:
5925 eff = new MaskIndexEffect(effects[i], element, this);
5926 break;
5927 case 5:
5928 eff = new EffectsManager(effects[i], element, this);
5929 break;
5930 default:
5931 eff = new NoValueEffect(effects[i], element, this);
5932 break;
5933 }
5934 if (eff) this.effectElements.push(eff);
5935 }
5936 };
5937 function BaseElement() {}
5938 BaseElement.prototype = {
5939 checkMasks: function checkMasks() {
5940 if (!this.data.hasMask) return false;
5941 var i = 0;
5942 var len = this.data.masksProperties.length;
5943 while (i < len) {
5944 if (this.data.masksProperties[i].mode !== "n" && this.data.masksProperties[i].cl !== false) return true;
5945 i += 1;
5946 }
5947 return false;
5948 },
5949 initExpressions: function initExpressions() {
5950 var expressionsInterfaces = getExpressionInterfaces();
5951 if (!expressionsInterfaces) return;
5952 var LayerExpressionInterface = expressionsInterfaces("layer");
5953 var EffectsExpressionInterface = expressionsInterfaces("effects");
5954 var ShapeExpressionInterface = expressionsInterfaces("shape");
5955 var TextExpressionInterface = expressionsInterfaces("text");
5956 var CompExpressionInterface = expressionsInterfaces("comp");
5957 this.layerInterface = LayerExpressionInterface(this);
5958 if (this.data.hasMask && this.maskManager) this.layerInterface.registerMaskInterface(this.maskManager);
5959 var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
5960 this.layerInterface.registerEffectsInterface(effectsInterface);
5961 if (this.data.ty === 0 || this.data.xt) this.compInterface = CompExpressionInterface(this);
5962 else if (this.data.ty === 4) {
5963 this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
5964 this.layerInterface.content = this.layerInterface.shapeInterface;
5965 } else if (this.data.ty === 5) {
5966 this.layerInterface.textInterface = TextExpressionInterface(this);
5967 this.layerInterface.text = this.layerInterface.textInterface;
5968 }
5969 },
5970 setBlendMode: function setBlendMode() {
5971 var blendModeValue = getBlendMode(this.data.bm);
5972 var elem = this.baseElement || this.layerElement;
5973 elem.style["mix-blend-mode"] = blendModeValue;
5974 },
5975 initBaseData: function initBaseData(data, globalData, comp) {
5976 this.globalData = globalData;
5977 this.comp = comp;
5978 this.data = data;
5979 this.layerId = createElementID();
5980 if (!this.data.sr) this.data.sr = 1;
5981 this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
5982 },
5983 getType: function getType() {
5984 return this.type;
5985 },
5986 sourceRectAtTime: function sourceRectAtTime() {}
5987 };
5988 /**
5989 * @file
5990 * Handles element's layer frame update.
5991 * Checks layer in point and out point
5992 *
5993 */
5994 function FrameElement() {}
5995 FrameElement.prototype = {
5996 /**
5997 * @function
5998 * Initializes frame related properties.
5999 *
6000 */
6001 initFrame: function initFrame() {
6002 this._isFirstFrame = false;
6003 this.dynamicProperties = [];
6004 this._mdf = false;
6005 },
6006 /**
6007 * @function
6008 * Calculates all dynamic values
6009 *
6010 * @param {number} num
6011 * current frame number in Layer's time
6012 * @param {boolean} isVisible
6013 * if layers is currently in range
6014 *
6015 */
6016 prepareProperties: function prepareProperties(num, isVisible) {
6017 var i;
6018 var len = this.dynamicProperties.length;
6019 for (i = 0; i < len; i += 1) if (isVisible || this._isParent && this.dynamicProperties[i].propType === "transform") {
6020 this.dynamicProperties[i].getValue();
6021 if (this.dynamicProperties[i]._mdf) {
6022 this.globalData._mdf = true;
6023 this._mdf = true;
6024 }
6025 }
6026 },
6027 addDynamicProperty: function addDynamicProperty(prop) {
6028 if (this.dynamicProperties.indexOf(prop) === -1) this.dynamicProperties.push(prop);
6029 }
6030 };
6031 function FootageElement(data, globalData, comp) {
6032 this.initFrame();
6033 this.initRenderable();
6034 this.assetData = globalData.getAssetData(data.refId);
6035 this.footageData = globalData.imageLoader.getAsset(this.assetData);
6036 this.initBaseData(data, globalData, comp);
6037 }
6038 FootageElement.prototype.prepareFrame = function() {};
6039 extendPrototype([
6040 RenderableElement,
6041 BaseElement,
6042 FrameElement
6043 ], FootageElement);
6044 FootageElement.prototype.getBaseElement = function() {
6045 return null;
6046 };
6047 FootageElement.prototype.renderFrame = function() {};
6048 FootageElement.prototype.destroy = function() {};
6049 FootageElement.prototype.initExpressions = function() {
6050 var expressionsInterfaces = getExpressionInterfaces();
6051 if (!expressionsInterfaces) return;
6052 var FootageInterface = expressionsInterfaces("footage");
6053 this.layerInterface = FootageInterface(this);
6054 };
6055 FootageElement.prototype.getFootageData = function() {
6056 return this.footageData;
6057 };
6058 function AudioElement(data, globalData, comp) {
6059 this.initFrame();
6060 this.initRenderable();
6061 this.assetData = globalData.getAssetData(data.refId);
6062 this.initBaseData(data, globalData, comp);
6063 this._isPlaying = false;
6064 this._canPlay = false;
6065 var assetPath = this.globalData.getAssetsPath(this.assetData);
6066 this.audio = this.globalData.audioController.createAudio(assetPath);
6067 this._currentTime = 0;
6068 this.globalData.audioController.addAudio(this);
6069 this._volumeMultiplier = 1;
6070 this._volume = 1;
6071 this._previousVolume = null;
6072 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
6073 this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, .01, this);
6074 }
6075 AudioElement.prototype.prepareFrame = function(num) {
6076 this.prepareRenderableFrame(num, true);
6077 this.prepareProperties(num, true);
6078 if (!this.tm._placeholder) {
6079 var timeRemapped = this.tm.v;
6080 this._currentTime = timeRemapped;
6081 } else this._currentTime = num / this.data.sr;
6082 this._volume = this.lv.v[0];
6083 var totalVolume = this._volume * this._volumeMultiplier;
6084 if (this._previousVolume !== totalVolume) {
6085 this._previousVolume = totalVolume;
6086 this.audio.volume(totalVolume);
6087 }
6088 };
6089 extendPrototype([
6090 RenderableElement,
6091 BaseElement,
6092 FrameElement
6093 ], AudioElement);
6094 AudioElement.prototype.renderFrame = function() {
6095 if (this.isInRange && this._canPlay) {
6096 if (!this._isPlaying) {
6097 this.audio.play();
6098 this.audio.seek(this._currentTime / this.globalData.frameRate);
6099 this._isPlaying = true;
6100 } else if (!this.audio.playing() || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > .1) this.audio.seek(this._currentTime / this.globalData.frameRate);
6101 }
6102 };
6103 AudioElement.prototype.show = function() {};
6104 AudioElement.prototype.hide = function() {
6105 this.audio.pause();
6106 this._isPlaying = false;
6107 };
6108 AudioElement.prototype.pause = function() {
6109 this.audio.pause();
6110 this._isPlaying = false;
6111 this._canPlay = false;
6112 };
6113 AudioElement.prototype.resume = function() {
6114 this._canPlay = true;
6115 };
6116 AudioElement.prototype.setRate = function(rateValue) {
6117 this.audio.rate(rateValue);
6118 };
6119 AudioElement.prototype.volume = function(volumeValue) {
6120 this._volumeMultiplier = volumeValue;
6121 this._previousVolume = volumeValue * this._volume;
6122 this.audio.volume(this._previousVolume);
6123 };
6124 AudioElement.prototype.getBaseElement = function() {
6125 return null;
6126 };
6127 AudioElement.prototype.destroy = function() {};
6128 AudioElement.prototype.sourceRectAtTime = function() {};
6129 AudioElement.prototype.initExpressions = function() {};
6130 function BaseRenderer() {}
6131 BaseRenderer.prototype.checkLayers = function(num) {
6132 var i;
6133 var len = this.layers.length;
6134 var data;
6135 this.completeLayers = true;
6136 for (i = len - 1; i >= 0; i -= 1) {
6137 if (!this.elements[i]) {
6138 data = this.layers[i];
6139 if (data.ip - data.st <= num - this.layers[i].st && data.op - data.st > num - this.layers[i].st) this.buildItem(i);
6140 }
6141 this.completeLayers = this.elements[i] ? this.completeLayers : false;
6142 }
6143 this.checkPendingElements();
6144 };
6145 BaseRenderer.prototype.createItem = function(layer) {
6146 switch (layer.ty) {
6147 case 2: return this.createImage(layer);
6148 case 0: return this.createComp(layer);
6149 case 1: return this.createSolid(layer);
6150 case 3: return this.createNull(layer);
6151 case 4: return this.createShape(layer);
6152 case 5: return this.createText(layer);
6153 case 6: return this.createAudio(layer);
6154 case 13: return this.createCamera(layer);
6155 case 15: return this.createFootage(layer);
6156 default: return this.createNull(layer);
6157 }
6158 };
6159 BaseRenderer.prototype.createCamera = function() {
6160 throw new Error("You're using a 3d camera. Try the html renderer.");
6161 };
6162 BaseRenderer.prototype.createAudio = function(data) {
6163 return new AudioElement(data, this.globalData, this);
6164 };
6165 BaseRenderer.prototype.createFootage = function(data) {
6166 return new FootageElement(data, this.globalData, this);
6167 };
6168 BaseRenderer.prototype.buildAllItems = function() {
6169 var i;
6170 var len = this.layers.length;
6171 for (i = 0; i < len; i += 1) this.buildItem(i);
6172 this.checkPendingElements();
6173 };
6174 BaseRenderer.prototype.includeLayers = function(newLayers) {
6175 this.completeLayers = false;
6176 var i;
6177 var len = newLayers.length;
6178 var j;
6179 var jLen = this.layers.length;
6180 for (i = 0; i < len; i += 1) {
6181 j = 0;
6182 while (j < jLen) {
6183 if (this.layers[j].id === newLayers[i].id) {
6184 this.layers[j] = newLayers[i];
6185 break;
6186 }
6187 j += 1;
6188 }
6189 }
6190 };
6191 BaseRenderer.prototype.setProjectInterface = function(pInterface) {
6192 this.globalData.projectInterface = pInterface;
6193 };
6194 BaseRenderer.prototype.initItems = function() {
6195 if (!this.globalData.progressiveLoad) this.buildAllItems();
6196 };
6197 BaseRenderer.prototype.buildElementParenting = function(element, parentName, hierarchy) {
6198 var elements = this.elements;
6199 var layers = this.layers;
6200 var i = 0;
6201 var len = layers.length;
6202 while (i < len) {
6203 if (layers[i].ind == parentName) if (!elements[i] || elements[i] === true) {
6204 this.buildItem(i);
6205 this.addPendingElement(element);
6206 } else {
6207 hierarchy.push(elements[i]);
6208 elements[i].setAsParent();
6209 if (layers[i].parent !== void 0) this.buildElementParenting(element, layers[i].parent, hierarchy);
6210 else element.setHierarchy(hierarchy);
6211 }
6212 i += 1;
6213 }
6214 };
6215 BaseRenderer.prototype.addPendingElement = function(element) {
6216 this.pendingElements.push(element);
6217 };
6218 BaseRenderer.prototype.searchExtraCompositions = function(assets) {
6219 var i;
6220 var len = assets.length;
6221 for (i = 0; i < len; i += 1) if (assets[i].xt) {
6222 var comp = this.createComp(assets[i]);
6223 comp.initExpressions();
6224 this.globalData.projectInterface.registerComposition(comp);
6225 }
6226 };
6227 BaseRenderer.prototype.getElementById = function(ind) {
6228 var i;
6229 var len = this.elements.length;
6230 for (i = 0; i < len; i += 1) if (this.elements[i].data.ind === ind) return this.elements[i];
6231 return null;
6232 };
6233 BaseRenderer.prototype.getElementByPath = function(path) {
6234 var pathValue = path.shift();
6235 var element;
6236 if (typeof pathValue === "number") element = this.elements[pathValue];
6237 else {
6238 var i;
6239 var len = this.elements.length;
6240 for (i = 0; i < len; i += 1) if (this.elements[i].data.nm === pathValue) {
6241 element = this.elements[i];
6242 break;
6243 }
6244 }
6245 if (path.length === 0) return element;
6246 return element.getElementByPath(path);
6247 };
6248 BaseRenderer.prototype.setupGlobalData = function(animData, fontsContainer) {
6249 this.globalData.fontManager = new FontManager();
6250 this.globalData.slotManager = slotFactory(animData);
6251 this.globalData.fontManager.addChars(animData.chars);
6252 this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
6253 this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
6254 this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
6255 this.globalData.imageLoader = this.animationItem.imagePreloader;
6256 this.globalData.audioController = this.animationItem.audioController;
6257 this.globalData.frameId = 0;
6258 this.globalData.frameRate = animData.fr;
6259 this.globalData.nm = animData.nm;
6260 this.globalData.compSize = {
6261 w: animData.w,
6262 h: animData.h
6263 };
6264 };
6265 var effectTypes = { TRANSFORM_EFFECT: "transformEFfect" };
6266 function TransformElement() {}
6267 TransformElement.prototype = {
6268 initTransform: function initTransform() {
6269 var mat = new Matrix();
6270 this.finalTransform = {
6271 mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
6272 _matMdf: false,
6273 _localMatMdf: false,
6274 _opMdf: false,
6275 mat,
6276 localMat: mat,
6277 localOpacity: 1
6278 };
6279 if (this.data.ao) this.finalTransform.mProp.autoOriented = true;
6280 if (this.data.ty !== 11) {}
6281 },
6282 renderTransform: function renderTransform() {
6283 this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
6284 this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
6285 if (this.hierarchy) {
6286 var mat;
6287 var finalMat = this.finalTransform.mat;
6288 var i = 0;
6289 var len = this.hierarchy.length;
6290 if (!this.finalTransform._matMdf) while (i < len) {
6291 if (this.hierarchy[i].finalTransform.mProp._mdf) {
6292 this.finalTransform._matMdf = true;
6293 break;
6294 }
6295 i += 1;
6296 }
6297 if (this.finalTransform._matMdf) {
6298 mat = this.finalTransform.mProp.v.props;
6299 finalMat.cloneFromProps(mat);
6300 for (i = 0; i < len; i += 1) finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
6301 }
6302 }
6303 if (!this.localTransforms || this.finalTransform._matMdf) this.finalTransform._localMatMdf = this.finalTransform._matMdf;
6304 if (this.finalTransform._opMdf) this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
6305 },
6306 renderLocalTransform: function renderLocalTransform() {
6307 if (this.localTransforms) {
6308 var i = 0;
6309 var len = this.localTransforms.length;
6310 this.finalTransform._localMatMdf = this.finalTransform._matMdf;
6311 if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) while (i < len) {
6312 if (this.localTransforms[i]._mdf) this.finalTransform._localMatMdf = true;
6313 if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
6314 this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
6315 this.finalTransform._opMdf = true;
6316 }
6317 i += 1;
6318 }
6319 if (this.finalTransform._localMatMdf) {
6320 var localMat = this.finalTransform.localMat;
6321 this.localTransforms[0].matrix.clone(localMat);
6322 for (i = 1; i < len; i += 1) {
6323 var lmat = this.localTransforms[i].matrix;
6324 localMat.multiply(lmat);
6325 }
6326 localMat.multiply(this.finalTransform.mat);
6327 }
6328 if (this.finalTransform._opMdf) {
6329 var localOp = this.finalTransform.localOpacity;
6330 for (i = 0; i < len; i += 1) localOp *= this.localTransforms[i].opacity * .01;
6331 this.finalTransform.localOpacity = localOp;
6332 }
6333 }
6334 },
6335 searchEffectTransforms: function searchEffectTransforms() {
6336 if (this.renderableEffectsManager) {
6337 var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
6338 if (transformEffects.length) {
6339 this.localTransforms = [];
6340 this.finalTransform.localMat = new Matrix();
6341 var i = 0;
6342 var len = transformEffects.length;
6343 for (i = 0; i < len; i += 1) this.localTransforms.push(transformEffects[i]);
6344 }
6345 }
6346 },
6347 globalToLocal: function globalToLocal(pt) {
6348 var transforms = [];
6349 transforms.push(this.finalTransform);
6350 var flag = true;
6351 var comp = this.comp;
6352 while (flag) if (comp.finalTransform) {
6353 if (comp.data.hasMask) transforms.splice(0, 0, comp.finalTransform);
6354 comp = comp.comp;
6355 } else flag = false;
6356 var i;
6357 var len = transforms.length;
6358 var ptNew;
6359 for (i = 0; i < len; i += 1) {
6360 ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
6361 pt = [
6362 pt[0] - ptNew[0],
6363 pt[1] - ptNew[1],
6364 0
6365 ];
6366 }
6367 return pt;
6368 },
6369 mHelper: new Matrix()
6370 };
6371 function MaskElement(data, element, globalData) {
6372 this.data = data;
6373 this.element = element;
6374 this.globalData = globalData;
6375 this.storedData = [];
6376 this.masksProperties = this.data.masksProperties || [];
6377 this.maskElement = null;
6378 var defs = this.globalData.defs;
6379 var i;
6380 var len = this.masksProperties ? this.masksProperties.length : 0;
6381 this.viewData = createSizedArray(len);
6382 this.solidPath = "";
6383 var path;
6384 var properties = this.masksProperties;
6385 var count = 0;
6386 var currentMasks = [];
6387 var j;
6388 var jLen;
6389 var layerId = createElementID();
6390 var rect;
6391 var expansor;
6392 var feMorph;
6393 var x;
6394 var maskType = "clipPath";
6395 var maskRef = "clip-path";
6396 for (i = 0; i < len; i += 1) {
6397 if (properties[i].mode !== "a" && properties[i].mode !== "n" || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
6398 maskType = "mask";
6399 maskRef = "mask";
6400 }
6401 if ((properties[i].mode === "s" || properties[i].mode === "i") && count === 0) {
6402 rect = createNS("rect");
6403 rect.setAttribute("fill", "#ffffff");
6404 rect.setAttribute("width", this.element.comp.data.w || 0);
6405 rect.setAttribute("height", this.element.comp.data.h || 0);
6406 currentMasks.push(rect);
6407 } else rect = null;
6408 path = createNS("path");
6409 if (properties[i].mode === "n") {
6410 this.viewData[i] = {
6411 op: PropertyFactory.getProp(this.element, properties[i].o, 0, .01, this.element),
6412 prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
6413 elem: path,
6414 lastPath: ""
6415 };
6416 defs.appendChild(path);
6417 } else {
6418 count += 1;
6419 path.setAttribute("fill", properties[i].mode === "s" ? "#000000" : "#ffffff");
6420 path.setAttribute("clip-rule", "nonzero");
6421 var filterID;
6422 if (properties[i].x.k !== 0) {
6423 maskType = "mask";
6424 maskRef = "mask";
6425 x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
6426 filterID = createElementID();
6427 expansor = createNS("filter");
6428 expansor.setAttribute("id", filterID);
6429 feMorph = createNS("feMorphology");
6430 feMorph.setAttribute("operator", "erode");
6431 feMorph.setAttribute("in", "SourceGraphic");
6432 feMorph.setAttribute("radius", "0");
6433 expansor.appendChild(feMorph);
6434 defs.appendChild(expansor);
6435 path.setAttribute("stroke", properties[i].mode === "s" ? "#000000" : "#ffffff");
6436 } else {
6437 feMorph = null;
6438 x = null;
6439 }
6440 this.storedData[i] = {
6441 elem: path,
6442 x,
6443 expan: feMorph,
6444 lastPath: "",
6445 lastOperator: "",
6446 filterId: filterID,
6447 lastRadius: 0
6448 };
6449 if (properties[i].mode === "i") {
6450 jLen = currentMasks.length;
6451 var g = createNS("g");
6452 for (j = 0; j < jLen; j += 1) g.appendChild(currentMasks[j]);
6453 var mask = createNS("mask");
6454 mask.setAttribute("mask-type", "alpha");
6455 mask.setAttribute("id", layerId + "_" + count);
6456 mask.appendChild(path);
6457 defs.appendChild(mask);
6458 g.setAttribute("mask", "url(" + getLocationHref() + "#" + layerId + "_" + count + ")");
6459 currentMasks.length = 0;
6460 currentMasks.push(g);
6461 } else currentMasks.push(path);
6462 if (properties[i].inv && !this.solidPath) this.solidPath = this.createLayerSolidPath();
6463 this.viewData[i] = {
6464 elem: path,
6465 lastPath: "",
6466 op: PropertyFactory.getProp(this.element, properties[i].o, 0, .01, this.element),
6467 prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
6468 invRect: rect
6469 };
6470 if (!this.viewData[i].prop.k) this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
6471 }
6472 }
6473 this.maskElement = createNS(maskType);
6474 len = currentMasks.length;
6475 for (i = 0; i < len; i += 1) this.maskElement.appendChild(currentMasks[i]);
6476 if (count > 0) {
6477 this.maskElement.setAttribute("id", layerId);
6478 this.element.maskedElement.setAttribute(maskRef, "url(" + getLocationHref() + "#" + layerId + ")");
6479 defs.appendChild(this.maskElement);
6480 }
6481 if (this.viewData.length) this.element.addRenderableComponent(this);
6482 }
6483 MaskElement.prototype.getMaskProperty = function(pos) {
6484 return this.viewData[pos].prop;
6485 };
6486 MaskElement.prototype.renderFrame = function(isFirstFrame) {
6487 var finalMat = this.element.finalTransform.mat;
6488 var i;
6489 var len = this.masksProperties.length;
6490 for (i = 0; i < len; i += 1) {
6491 if (this.viewData[i].prop._mdf || isFirstFrame) this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
6492 if (this.viewData[i].op._mdf || isFirstFrame) this.viewData[i].elem.setAttribute("fill-opacity", this.viewData[i].op.v);
6493 if (this.masksProperties[i].mode !== "n") {
6494 if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) this.viewData[i].invRect.setAttribute("transform", finalMat.getInverseMatrix().to2dCSS());
6495 if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
6496 var feMorph = this.storedData[i].expan;
6497 if (this.storedData[i].x.v < 0) {
6498 if (this.storedData[i].lastOperator !== "erode") {
6499 this.storedData[i].lastOperator = "erode";
6500 this.storedData[i].elem.setAttribute("filter", "url(" + getLocationHref() + "#" + this.storedData[i].filterId + ")");
6501 }
6502 feMorph.setAttribute("radius", -this.storedData[i].x.v);
6503 } else {
6504 if (this.storedData[i].lastOperator !== "dilate") {
6505 this.storedData[i].lastOperator = "dilate";
6506 this.storedData[i].elem.setAttribute("filter", null);
6507 }
6508 this.storedData[i].elem.setAttribute("stroke-width", this.storedData[i].x.v * 2);
6509 }
6510 }
6511 }
6512 }
6513 };
6514 MaskElement.prototype.getMaskelement = function() {
6515 return this.maskElement;
6516 };
6517 MaskElement.prototype.createLayerSolidPath = function() {
6518 var path = "M0,0 ";
6519 path += " h" + this.globalData.compSize.w;
6520 path += " v" + this.globalData.compSize.h;
6521 path += " h-" + this.globalData.compSize.w;
6522 path += " v-" + this.globalData.compSize.h + " ";
6523 return path;
6524 };
6525 MaskElement.prototype.drawPath = function(pathData, pathNodes, viewData) {
6526 var pathString = " M" + pathNodes.v[0][0] + "," + pathNodes.v[0][1];
6527 var i;
6528 var len = pathNodes._length;
6529 for (i = 1; i < len; i += 1) pathString += " C" + pathNodes.o[i - 1][0] + "," + pathNodes.o[i - 1][1] + " " + pathNodes.i[i][0] + "," + pathNodes.i[i][1] + " " + pathNodes.v[i][0] + "," + pathNodes.v[i][1];
6530 if (pathNodes.c && len > 1) pathString += " C" + pathNodes.o[i - 1][0] + "," + pathNodes.o[i - 1][1] + " " + pathNodes.i[0][0] + "," + pathNodes.i[0][1] + " " + pathNodes.v[0][0] + "," + pathNodes.v[0][1];
6531 if (viewData.lastPath !== pathString) {
6532 var pathShapeValue = "";
6533 if (viewData.elem) {
6534 if (pathNodes.c) pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
6535 viewData.elem.setAttribute("d", pathShapeValue);
6536 }
6537 viewData.lastPath = pathString;
6538 }
6539 };
6540 MaskElement.prototype.destroy = function() {
6541 this.element = null;
6542 this.globalData = null;
6543 this.maskElement = null;
6544 this.data = null;
6545 this.masksProperties = null;
6546 };
6547 var filtersFactory = function() {
6548 var ob = {};
6549 ob.createFilter = createFilter;
6550 ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
6551 function createFilter(filId, skipCoordinates) {
6552 var fil = createNS("filter");
6553 fil.setAttribute("id", filId);
6554 if (skipCoordinates !== true) {
6555 fil.setAttribute("filterUnits", "objectBoundingBox");
6556 fil.setAttribute("x", "0%");
6557 fil.setAttribute("y", "0%");
6558 fil.setAttribute("width", "100%");
6559 fil.setAttribute("height", "100%");
6560 }
6561 return fil;
6562 }
6563 function createAlphaToLuminanceFilter() {
6564 var feColorMatrix = createNS("feColorMatrix");
6565 feColorMatrix.setAttribute("type", "matrix");
6566 feColorMatrix.setAttribute("color-interpolation-filters", "sRGB");
6567 feColorMatrix.setAttribute("values", "0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1");
6568 return feColorMatrix;
6569 }
6570 return ob;
6571 }();
6572 var featureSupport = function() {
6573 var ob = {
6574 maskType: true,
6575 svgLumaHidden: true,
6576 offscreenCanvas: typeof OffscreenCanvas !== "undefined"
6577 };
6578 if (/MSIE 10/i.test(navigator.userAgent) || /MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent) || /Edge\/\d./i.test(navigator.userAgent)) ob.maskType = false;
6579 if (/firefox/i.test(navigator.userAgent)) ob.svgLumaHidden = false;
6580 return ob;
6581 }();
6582 var registeredEffects$1 = {};
6583 var idPrefix = "filter_result_";
6584 function SVGEffects(elem) {
6585 var i;
6586 var source = "SourceGraphic";
6587 var len = elem.data.ef ? elem.data.ef.length : 0;
6588 var filId = createElementID();
6589 var fil = filtersFactory.createFilter(filId, true);
6590 var count = 0;
6591 this.filters = [];
6592 var filterManager;
6593 for (i = 0; i < len; i += 1) {
6594 filterManager = null;
6595 var type = elem.data.ef[i].ty;
6596 if (registeredEffects$1[type]) {
6597 var Effect = registeredEffects$1[type].effect;
6598 filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
6599 source = idPrefix + count;
6600 if (registeredEffects$1[type].countsAsEffect) count += 1;
6601 }
6602 if (filterManager) this.filters.push(filterManager);
6603 }
6604 if (count) {
6605 elem.globalData.defs.appendChild(fil);
6606 elem.layerElement.setAttribute("filter", "url(" + getLocationHref() + "#" + filId + ")");
6607 }
6608 if (this.filters.length) elem.addRenderableComponent(this);
6609 }
6610 SVGEffects.prototype.renderFrame = function(_isFirstFrame) {
6611 var i;
6612 var len = this.filters.length;
6613 for (i = 0; i < len; i += 1) this.filters[i].renderFrame(_isFirstFrame);
6614 };
6615 SVGEffects.prototype.getEffects = function(type) {
6616 var i;
6617 var len = this.filters.length;
6618 var effects = [];
6619 for (i = 0; i < len; i += 1) if (this.filters[i].type === type) effects.push(this.filters[i]);
6620 return effects;
6621 };
6622 function registerEffect$1(id, effect, countsAsEffect) {
6623 registeredEffects$1[id] = {
6624 effect,
6625 countsAsEffect
6626 };
6627 }
6628 function SVGBaseElement() {}
6629 SVGBaseElement.prototype = {
6630 initRendererElement: function initRendererElement() {
6631 this.layerElement = createNS("g");
6632 },
6633 createContainerElements: function createContainerElements() {
6634 this.matteElement = createNS("g");
6635 this.transformedElement = this.layerElement;
6636 this.maskedElement = this.layerElement;
6637 this._sizeChanged = false;
6638 var layerElementParent = null;
6639 if (this.data.td) {
6640 this.matteMasks = {};
6641 var gg = createNS("g");
6642 gg.setAttribute("id", this.layerId);
6643 gg.appendChild(this.layerElement);
6644 layerElementParent = gg;
6645 this.globalData.defs.appendChild(gg);
6646 } else if (this.data.tt) {
6647 this.matteElement.appendChild(this.layerElement);
6648 layerElementParent = this.matteElement;
6649 this.baseElement = this.matteElement;
6650 } else this.baseElement = this.layerElement;
6651 if (this.data.ln) this.layerElement.setAttribute("id", this.data.ln);
6652 if (this.data.cl) this.layerElement.setAttribute("class", this.data.cl);
6653 if (this.data.ty === 0 && !this.data.hd) {
6654 var cp = createNS("clipPath");
6655 var pt = createNS("path");
6656 pt.setAttribute("d", "M0,0 L" + this.data.w + ",0 L" + this.data.w + "," + this.data.h + " L0," + this.data.h + "z");
6657 var clipId = createElementID();
6658 cp.setAttribute("id", clipId);
6659 cp.appendChild(pt);
6660 this.globalData.defs.appendChild(cp);
6661 if (this.checkMasks()) {
6662 var cpGroup = createNS("g");
6663 cpGroup.setAttribute("clip-path", "url(" + getLocationHref() + "#" + clipId + ")");
6664 cpGroup.appendChild(this.layerElement);
6665 this.transformedElement = cpGroup;
6666 if (layerElementParent) layerElementParent.appendChild(this.transformedElement);
6667 else this.baseElement = this.transformedElement;
6668 } else this.layerElement.setAttribute("clip-path", "url(" + getLocationHref() + "#" + clipId + ")");
6669 }
6670 if (this.data.bm !== 0) this.setBlendMode();
6671 },
6672 renderElement: function renderElement() {
6673 if (this.finalTransform._localMatMdf) this.transformedElement.setAttribute("transform", this.finalTransform.localMat.to2dCSS());
6674 if (this.finalTransform._opMdf) this.transformedElement.setAttribute("opacity", this.finalTransform.localOpacity);
6675 },
6676 destroyBaseElement: function destroyBaseElement() {
6677 this.layerElement = null;
6678 this.matteElement = null;
6679 this.maskManager.destroy();
6680 },
6681 getBaseElement: function getBaseElement() {
6682 if (this.data.hd) return null;
6683 return this.baseElement;
6684 },
6685 createRenderableComponents: function createRenderableComponents() {
6686 this.maskManager = new MaskElement(this.data, this, this.globalData);
6687 this.renderableEffectsManager = new SVGEffects(this);
6688 this.searchEffectTransforms();
6689 },
6690 getMatte: function getMatte(matteType) {
6691 if (!this.matteMasks) this.matteMasks = {};
6692 if (!this.matteMasks[matteType]) {
6693 var id = this.layerId + "_" + matteType;
6694 var filId;
6695 var fil;
6696 var useElement;
6697 var gg;
6698 if (matteType === 1 || matteType === 3) {
6699 var masker = createNS("mask");
6700 masker.setAttribute("id", id);
6701 masker.setAttribute("mask-type", matteType === 3 ? "luminance" : "alpha");
6702 useElement = createNS("use");
6703 useElement.setAttributeNS("http://www.w3.org/1999/xlink", "href", "#" + this.layerId);
6704 masker.appendChild(useElement);
6705 this.globalData.defs.appendChild(masker);
6706 if (!featureSupport.maskType && matteType === 1) {
6707 masker.setAttribute("mask-type", "luminance");
6708 filId = createElementID();
6709 fil = filtersFactory.createFilter(filId);
6710 this.globalData.defs.appendChild(fil);
6711 fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
6712 gg = createNS("g");
6713 gg.appendChild(useElement);
6714 masker.appendChild(gg);
6715 gg.setAttribute("filter", "url(" + getLocationHref() + "#" + filId + ")");
6716 }
6717 } else if (matteType === 2) {
6718 var maskGroup = createNS("mask");
6719 maskGroup.setAttribute("id", id);
6720 maskGroup.setAttribute("mask-type", "alpha");
6721 var maskGrouper = createNS("g");
6722 maskGroup.appendChild(maskGrouper);
6723 filId = createElementID();
6724 fil = filtersFactory.createFilter(filId);
6725 var feCTr = createNS("feComponentTransfer");
6726 feCTr.setAttribute("in", "SourceGraphic");
6727 fil.appendChild(feCTr);
6728 var feFunc = createNS("feFuncA");
6729 feFunc.setAttribute("type", "table");
6730 feFunc.setAttribute("tableValues", "1.0 0.0");
6731 feCTr.appendChild(feFunc);
6732 this.globalData.defs.appendChild(fil);
6733 var alphaRect = createNS("rect");
6734 alphaRect.setAttribute("width", this.comp.data.w);
6735 alphaRect.setAttribute("height", this.comp.data.h);
6736 alphaRect.setAttribute("x", "0");
6737 alphaRect.setAttribute("y", "0");
6738 alphaRect.setAttribute("fill", "#ffffff");
6739 alphaRect.setAttribute("opacity", "0");
6740 maskGrouper.setAttribute("filter", "url(" + getLocationHref() + "#" + filId + ")");
6741 maskGrouper.appendChild(alphaRect);
6742 useElement = createNS("use");
6743 useElement.setAttributeNS("http://www.w3.org/1999/xlink", "href", "#" + this.layerId);
6744 maskGrouper.appendChild(useElement);
6745 if (!featureSupport.maskType) {
6746 maskGroup.setAttribute("mask-type", "luminance");
6747 fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
6748 gg = createNS("g");
6749 maskGrouper.appendChild(alphaRect);
6750 gg.appendChild(this.layerElement);
6751 maskGrouper.appendChild(gg);
6752 }
6753 this.globalData.defs.appendChild(maskGroup);
6754 }
6755 this.matteMasks[matteType] = id;
6756 }
6757 return this.matteMasks[matteType];
6758 },
6759 setMatte: function setMatte(id) {
6760 if (!this.matteElement) return;
6761 this.matteElement.setAttribute("mask", "url(" + getLocationHref() + "#" + id + ")");
6762 }
6763 };
6764 /**
6765 * @file
6766 * Handles AE's layer parenting property.
6767 *
6768 */
6769 function HierarchyElement() {}
6770 HierarchyElement.prototype = {
6771 /**
6772 * @function
6773 * Initializes hierarchy properties
6774 *
6775 */
6776 initHierarchy: function initHierarchy() {
6777 this.hierarchy = [];
6778 this._isParent = false;
6779 this.checkParenting();
6780 },
6781 /**
6782 * @function
6783 * Sets layer's hierarchy.
6784 * @param {array} hierarch
6785 * layer's parent list
6786 *
6787 */
6788 setHierarchy: function setHierarchy(hierarchy) {
6789 this.hierarchy = hierarchy;
6790 },
6791 /**
6792 * @function
6793 * Sets layer as parent.
6794 *
6795 */
6796 setAsParent: function setAsParent() {
6797 this._isParent = true;
6798 },
6799 /**
6800 * @function
6801 * Searches layer's parenting chain
6802 *
6803 */
6804 checkParenting: function checkParenting() {
6805 if (this.data.parent !== void 0) this.comp.buildElementParenting(this, this.data.parent, []);
6806 }
6807 };
6808 function RenderableDOMElement() {}
6809 (function() {
6810 extendPrototype([RenderableElement, createProxyFunction({
6811 initElement: function initElement(data, globalData, comp) {
6812 this.initFrame();
6813 this.initBaseData(data, globalData, comp);
6814 this.initTransform(data, globalData, comp);
6815 this.initHierarchy();
6816 this.initRenderable();
6817 this.initRendererElement();
6818 this.createContainerElements();
6819 this.createRenderableComponents();
6820 this.createContent();
6821 this.hide();
6822 },
6823 hide: function hide() {
6824 if (!this.hidden && (!this.isInRange || this.isTransparent)) {
6825 var elem = this.baseElement || this.layerElement;
6826 elem.style.display = "none";
6827 this.hidden = true;
6828 }
6829 },
6830 show: function show() {
6831 if (this.isInRange && !this.isTransparent) {
6832 if (!this.data.hd) {
6833 var elem = this.baseElement || this.layerElement;
6834 elem.style.display = "block";
6835 }
6836 this.hidden = false;
6837 this._isFirstFrame = true;
6838 }
6839 },
6840 renderFrame: function renderFrame() {
6841 if (this.data.hd || this.hidden) return;
6842 this.renderTransform();
6843 this.renderRenderable();
6844 this.renderLocalTransform();
6845 this.renderElement();
6846 this.renderInnerContent();
6847 if (this._isFirstFrame) this._isFirstFrame = false;
6848 },
6849 renderInnerContent: function renderInnerContent() {},
6850 prepareFrame: function prepareFrame(num) {
6851 this._mdf = false;
6852 this.prepareRenderableFrame(num);
6853 this.prepareProperties(num, this.isInRange);
6854 this.checkTransparency();
6855 },
6856 destroy: function destroy() {
6857 this.innerElem = null;
6858 this.destroyBaseElement();
6859 }
6860 })], RenderableDOMElement);
6861 })();
6862 function IImageElement(data, globalData, comp) {
6863 this.assetData = globalData.getAssetData(data.refId);
6864 if (this.assetData && this.assetData.sid) this.assetData = globalData.slotManager.getProp(this.assetData);
6865 this.initElement(data, globalData, comp);
6866 this.sourceRect = {
6867 top: 0,
6868 left: 0,
6869 width: this.assetData.w,
6870 height: this.assetData.h
6871 };
6872 }
6873 extendPrototype([
6874 BaseElement,
6875 TransformElement,
6876 SVGBaseElement,
6877 HierarchyElement,
6878 FrameElement,
6879 RenderableDOMElement
6880 ], IImageElement);
6881 IImageElement.prototype.createContent = function() {
6882 var assetPath = this.globalData.getAssetsPath(this.assetData);
6883 this.innerElem = createNS("image");
6884 this.innerElem.setAttribute("width", this.assetData.w + "px");
6885 this.innerElem.setAttribute("height", this.assetData.h + "px");
6886 this.innerElem.setAttribute("preserveAspectRatio", this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
6887 this.innerElem.setAttributeNS("http://www.w3.org/1999/xlink", "href", assetPath);
6888 this.layerElement.appendChild(this.innerElem);
6889 };
6890 IImageElement.prototype.sourceRectAtTime = function() {
6891 return this.sourceRect;
6892 };
6893 function ProcessedElement(element, position) {
6894 this.elem = element;
6895 this.pos = position;
6896 }
6897 function IShapeElement() {}
6898 IShapeElement.prototype = {
6899 addShapeToModifiers: function addShapeToModifiers(data) {
6900 var i;
6901 var len = this.shapeModifiers.length;
6902 for (i = 0; i < len; i += 1) this.shapeModifiers[i].addShape(data);
6903 },
6904 isShapeInAnimatedModifiers: function isShapeInAnimatedModifiers(data) {
6905 var i = 0;
6906 var len = this.shapeModifiers.length;
6907 while (i < len) if (this.shapeModifiers[i].isAnimatedWithShape(data)) return true;
6908 return false;
6909 },
6910 renderModifiers: function renderModifiers() {
6911 if (!this.shapeModifiers.length) return;
6912 var i;
6913 var len = this.shapes.length;
6914 for (i = 0; i < len; i += 1) this.shapes[i].sh.reset();
6915 len = this.shapeModifiers.length;
6916 var shouldBreakProcess;
6917 for (i = len - 1; i >= 0; i -= 1) {
6918 shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
6919 if (shouldBreakProcess) break;
6920 }
6921 },
6922 searchProcessedElement: function searchProcessedElement(elem) {
6923 var elements = this.processedElements;
6924 var i = 0;
6925 var len = elements.length;
6926 while (i < len) {
6927 if (elements[i].elem === elem) return elements[i].pos;
6928 i += 1;
6929 }
6930 return 0;
6931 },
6932 addProcessedElement: function addProcessedElement(elem, pos) {
6933 var elements = this.processedElements;
6934 var i = elements.length;
6935 while (i) {
6936 i -= 1;
6937 if (elements[i].elem === elem) {
6938 elements[i].pos = pos;
6939 return;
6940 }
6941 }
6942 elements.push(new ProcessedElement(elem, pos));
6943 },
6944 prepareFrame: function prepareFrame(num) {
6945 this.prepareRenderableFrame(num);
6946 this.prepareProperties(num, this.isInRange);
6947 }
6948 };
6949 var lineCapEnum = {
6950 1: "butt",
6951 2: "round",
6952 3: "square"
6953 };
6954 var lineJoinEnum = {
6955 1: "miter",
6956 2: "round",
6957 3: "bevel"
6958 };
6959 function SVGShapeData(transformers, level, shape) {
6960 this.caches = [];
6961 this.styles = [];
6962 this.transformers = transformers;
6963 this.lStr = "";
6964 this.sh = shape;
6965 this.lvl = level;
6966 this._isAnimated = !!shape.k;
6967 var i = 0;
6968 var len = transformers.length;
6969 while (i < len) {
6970 if (transformers[i].mProps.dynamicProperties.length) {
6971 this._isAnimated = true;
6972 break;
6973 }
6974 i += 1;
6975 }
6976 }
6977 SVGShapeData.prototype.setAsAnimated = function() {
6978 this._isAnimated = true;
6979 };
6980 function SVGStyleData(data, level) {
6981 this.data = data;
6982 this.type = data.ty;
6983 this.d = "";
6984 this.lvl = level;
6985 this._mdf = false;
6986 this.closed = data.hd === true;
6987 this.pElem = createNS("path");
6988 this.msElem = null;
6989 }
6990 SVGStyleData.prototype.reset = function() {
6991 this.d = "";
6992 this._mdf = false;
6993 };
6994 function DashProperty(elem, data, renderer, container) {
6995 this.elem = elem;
6996 this.frameId = -1;
6997 this.dataProps = createSizedArray(data.length);
6998 this.renderer = renderer;
6999 this.k = false;
7000 this.dashStr = "";
7001 this.dashArray = createTypedArray("float32", data.length ? data.length - 1 : 0);
7002 this.dashoffset = createTypedArray("float32", 1);
7003 this.initDynamicPropertyContainer(container);
7004 var i;
7005 var len = data.length || 0;
7006 var prop;
7007 for (i = 0; i < len; i += 1) {
7008 prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
7009 this.k = prop.k || this.k;
7010 this.dataProps[i] = {
7011 n: data[i].n,
7012 p: prop
7013 };
7014 }
7015 if (!this.k) this.getValue(true);
7016 this._isAnimated = this.k;
7017 }
7018 DashProperty.prototype.getValue = function(forceRender) {
7019 if (this.elem.globalData.frameId === this.frameId && !forceRender) return;
7020 this.frameId = this.elem.globalData.frameId;
7021 this.iterateDynamicProperties();
7022 this._mdf = this._mdf || forceRender;
7023 if (this._mdf) {
7024 var i = 0;
7025 var len = this.dataProps.length;
7026 if (this.renderer === "svg") this.dashStr = "";
7027 for (i = 0; i < len; i += 1) if (this.dataProps[i].n !== "o") if (this.renderer === "svg") this.dashStr += " " + this.dataProps[i].p.v;
7028 else this.dashArray[i] = this.dataProps[i].p.v;
7029 else this.dashoffset[0] = this.dataProps[i].p.v;
7030 }
7031 };
7032 extendPrototype([DynamicPropertyContainer], DashProperty);
7033 function SVGStrokeStyleData(elem, data, styleOb) {
7034 this.initDynamicPropertyContainer(elem);
7035 this.getValue = this.iterateDynamicProperties;
7036 this.o = PropertyFactory.getProp(elem, data.o, 0, .01, this);
7037 this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
7038 this.d = new DashProperty(elem, data.d || {}, "svg", this);
7039 this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
7040 this.style = styleOb;
7041 this._isAnimated = !!this._isAnimated;
7042 }
7043 extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
7044 function SVGFillStyleData(elem, data, styleOb) {
7045 this.initDynamicPropertyContainer(elem);
7046 this.getValue = this.iterateDynamicProperties;
7047 this.o = PropertyFactory.getProp(elem, data.o, 0, .01, this);
7048 this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
7049 this.style = styleOb;
7050 }
7051 extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
7052 function SVGNoStyleData(elem, data, styleOb) {
7053 this.initDynamicPropertyContainer(elem);
7054 this.getValue = this.iterateDynamicProperties;
7055 this.style = styleOb;
7056 }
7057 extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
7058 function GradientProperty(elem, data, container) {
7059 this.data = data;
7060 this.c = createTypedArray("uint8c", data.p * 4);
7061 var cLength = data.k.k[0].s ? data.k.k[0].s.length - data.p * 4 : data.k.k.length - data.p * 4;
7062 this.o = createTypedArray("float32", cLength);
7063 this._cmdf = false;
7064 this._omdf = false;
7065 this._collapsable = this.checkCollapsable();
7066 this._hasOpacity = cLength;
7067 this.initDynamicPropertyContainer(container);
7068 this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
7069 this.k = this.prop.k;
7070 this.getValue(true);
7071 }
7072 GradientProperty.prototype.comparePoints = function(values, points) {
7073 var i = 0;
7074 var len = this.o.length / 2;
7075 var diff;
7076 while (i < len) {
7077 diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
7078 if (diff > .01) return false;
7079 i += 1;
7080 }
7081 return true;
7082 };
7083 GradientProperty.prototype.checkCollapsable = function() {
7084 if (this.o.length / 2 !== this.c.length / 4) return false;
7085 if (this.data.k.k[0].s) {
7086 var i = 0;
7087 var len = this.data.k.k.length;
7088 while (i < len) {
7089 if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) return false;
7090 i += 1;
7091 }
7092 } else if (!this.comparePoints(this.data.k.k, this.data.p)) return false;
7093 return true;
7094 };
7095 GradientProperty.prototype.getValue = function(forceRender) {
7096 this.prop.getValue();
7097 this._mdf = false;
7098 this._cmdf = false;
7099 this._omdf = false;
7100 if (this.prop._mdf || forceRender) {
7101 var i;
7102 var len = this.data.p * 4;
7103 var mult;
7104 var val;
7105 for (i = 0; i < len; i += 1) {
7106 mult = i % 4 === 0 ? 100 : 255;
7107 val = Math.round(this.prop.v[i] * mult);
7108 if (this.c[i] !== val) {
7109 this.c[i] = val;
7110 this._cmdf = !forceRender;
7111 }
7112 }
7113 if (this.o.length) {
7114 len = this.prop.v.length;
7115 for (i = this.data.p * 4; i < len; i += 1) {
7116 mult = i % 2 === 0 ? 100 : 1;
7117 val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
7118 if (this.o[i - this.data.p * 4] !== val) {
7119 this.o[i - this.data.p * 4] = val;
7120 this._omdf = !forceRender;
7121 }
7122 }
7123 }
7124 this._mdf = !forceRender;
7125 }
7126 };
7127 extendPrototype([DynamicPropertyContainer], GradientProperty);
7128 function SVGGradientFillStyleData(elem, data, styleOb) {
7129 this.initDynamicPropertyContainer(elem);
7130 this.getValue = this.iterateDynamicProperties;
7131 this.initGradientData(elem, data, styleOb);
7132 }
7133 SVGGradientFillStyleData.prototype.initGradientData = function(elem, data, styleOb) {
7134 this.o = PropertyFactory.getProp(elem, data.o, 0, .01, this);
7135 this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
7136 this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
7137 this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, .01, this);
7138 this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
7139 this.g = new GradientProperty(elem, data.g, this);
7140 this.style = styleOb;
7141 this.stops = [];
7142 this.setGradientData(styleOb.pElem, data);
7143 this.setGradientOpacity(data, styleOb);
7144 this._isAnimated = !!this._isAnimated;
7145 };
7146 SVGGradientFillStyleData.prototype.setGradientData = function(pathElement, data) {
7147 var gradientId = createElementID();
7148 var gfill = createNS(data.t === 1 ? "linearGradient" : "radialGradient");
7149 gfill.setAttribute("id", gradientId);
7150 gfill.setAttribute("spreadMethod", "pad");
7151 gfill.setAttribute("gradientUnits", "userSpaceOnUse");
7152 var stops = [];
7153 var stop;
7154 var j;
7155 var jLen = data.g.p * 4;
7156 for (j = 0; j < jLen; j += 4) {
7157 stop = createNS("stop");
7158 gfill.appendChild(stop);
7159 stops.push(stop);
7160 }
7161 pathElement.setAttribute(data.ty === "gf" ? "fill" : "stroke", "url(" + getLocationHref() + "#" + gradientId + ")");
7162 this.gf = gfill;
7163 this.cst = stops;
7164 };
7165 SVGGradientFillStyleData.prototype.setGradientOpacity = function(data, styleOb) {
7166 if (this.g._hasOpacity && !this.g._collapsable) {
7167 var stop;
7168 var j;
7169 var jLen;
7170 var mask = createNS("mask");
7171 var maskElement = createNS("path");
7172 mask.appendChild(maskElement);
7173 var opacityId = createElementID();
7174 var maskId = createElementID();
7175 mask.setAttribute("id", maskId);
7176 var opFill = createNS(data.t === 1 ? "linearGradient" : "radialGradient");
7177 opFill.setAttribute("id", opacityId);
7178 opFill.setAttribute("spreadMethod", "pad");
7179 opFill.setAttribute("gradientUnits", "userSpaceOnUse");
7180 jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
7181 var stops = this.stops;
7182 for (j = data.g.p * 4; j < jLen; j += 2) {
7183 stop = createNS("stop");
7184 stop.setAttribute("stop-color", "rgb(255,255,255)");
7185 opFill.appendChild(stop);
7186 stops.push(stop);
7187 }
7188 maskElement.setAttribute(data.ty === "gf" ? "fill" : "stroke", "url(" + getLocationHref() + "#" + opacityId + ")");
7189 if (data.ty === "gs") {
7190 maskElement.setAttribute("stroke-linecap", lineCapEnum[data.lc || 2]);
7191 maskElement.setAttribute("stroke-linejoin", lineJoinEnum[data.lj || 2]);
7192 if (data.lj === 1) maskElement.setAttribute("stroke-miterlimit", data.ml);
7193 }
7194 this.of = opFill;
7195 this.ms = mask;
7196 this.ost = stops;
7197 this.maskId = maskId;
7198 styleOb.msElem = maskElement;
7199 }
7200 };
7201 extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
7202 function SVGGradientStrokeStyleData(elem, data, styleOb) {
7203 this.initDynamicPropertyContainer(elem);
7204 this.getValue = this.iterateDynamicProperties;
7205 this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
7206 this.d = new DashProperty(elem, data.d || {}, "svg", this);
7207 this.initGradientData(elem, data, styleOb);
7208 this._isAnimated = !!this._isAnimated;
7209 }
7210 extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
7211 function ShapeGroupData() {
7212 this.it = [];
7213 this.prevViewData = [];
7214 this.gr = createNS("g");
7215 }
7216 function SVGTransformData(mProps, op, container) {
7217 this.transform = {
7218 mProps,
7219 op,
7220 container
7221 };
7222 this.elements = [];
7223 this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
7224 }
7225 var buildShapeString = function buildShapeString(pathNodes, length, closed, mat) {
7226 if (length === 0) return "";
7227 var _o = pathNodes.o;
7228 var _i = pathNodes.i;
7229 var _v = pathNodes.v;
7230 var i;
7231 var shapeString = " M" + mat.applyToPointStringified(_v[0][0], _v[0][1]);
7232 for (i = 1; i < length; i += 1) shapeString += " C" + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + " " + mat.applyToPointStringified(_i[i][0], _i[i][1]) + " " + mat.applyToPointStringified(_v[i][0], _v[i][1]);
7233 if (closed && length) {
7234 shapeString += " C" + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + " " + mat.applyToPointStringified(_i[0][0], _i[0][1]) + " " + mat.applyToPointStringified(_v[0][0], _v[0][1]);
7235 shapeString += "z";
7236 }
7237 return shapeString;
7238 };
7239 var SVGElementsRenderer = function() {
7240 var _identityMatrix = new Matrix();
7241 var _matrixHelper = new Matrix();
7242 var ob = { createRenderFunction };
7243 function createRenderFunction(data) {
7244 switch (data.ty) {
7245 case "fl": return renderFill;
7246 case "gf": return renderGradient;
7247 case "gs": return renderGradientStroke;
7248 case "st": return renderStroke;
7249 case "sh":
7250 case "el":
7251 case "rc":
7252 case "sr": return renderPath;
7253 case "tr": return renderContentTransform;
7254 case "no": return renderNoop;
7255 default: return null;
7256 }
7257 }
7258 function renderContentTransform(styleData, itemData, isFirstFrame) {
7259 if (isFirstFrame || itemData.transform.op._mdf) itemData.transform.container.setAttribute("opacity", itemData.transform.op.v);
7260 if (isFirstFrame || itemData.transform.mProps._mdf) itemData.transform.container.setAttribute("transform", itemData.transform.mProps.v.to2dCSS());
7261 }
7262 function renderNoop() {}
7263 function renderPath(styleData, itemData, isFirstFrame) {
7264 var j;
7265 var jLen;
7266 var pathStringTransformed;
7267 var redraw;
7268 var pathNodes;
7269 var l;
7270 var lLen = itemData.styles.length;
7271 var lvl = itemData.lvl;
7272 var paths;
7273 var mat;
7274 var iterations;
7275 var k;
7276 for (l = 0; l < lLen; l += 1) {
7277 redraw = itemData.sh._mdf || isFirstFrame;
7278 if (itemData.styles[l].lvl < lvl) {
7279 mat = _matrixHelper.reset();
7280 iterations = lvl - itemData.styles[l].lvl;
7281 k = itemData.transformers.length - 1;
7282 while (!redraw && iterations > 0) {
7283 redraw = itemData.transformers[k].mProps._mdf || redraw;
7284 iterations -= 1;
7285 k -= 1;
7286 }
7287 if (redraw) {
7288 iterations = lvl - itemData.styles[l].lvl;
7289 k = itemData.transformers.length - 1;
7290 while (iterations > 0) {
7291 mat.multiply(itemData.transformers[k].mProps.v);
7292 iterations -= 1;
7293 k -= 1;
7294 }
7295 }
7296 } else mat = _identityMatrix;
7297 paths = itemData.sh.paths;
7298 jLen = paths._length;
7299 if (redraw) {
7300 pathStringTransformed = "";
7301 for (j = 0; j < jLen; j += 1) {
7302 pathNodes = paths.shapes[j];
7303 if (pathNodes && pathNodes._length) pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
7304 }
7305 itemData.caches[l] = pathStringTransformed;
7306 } else pathStringTransformed = itemData.caches[l];
7307 itemData.styles[l].d += styleData.hd === true ? "" : pathStringTransformed;
7308 itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
7309 }
7310 }
7311 function renderFill(styleData, itemData, isFirstFrame) {
7312 var styleElem = itemData.style;
7313 if (itemData.c._mdf || isFirstFrame) styleElem.pElem.setAttribute("fill", "rgb(" + bmFloor(itemData.c.v[0]) + "," + bmFloor(itemData.c.v[1]) + "," + bmFloor(itemData.c.v[2]) + ")");
7314 if (itemData.o._mdf || isFirstFrame) styleElem.pElem.setAttribute("fill-opacity", itemData.o.v);
7315 }
7316 function renderGradientStroke(styleData, itemData, isFirstFrame) {
7317 renderGradient(styleData, itemData, isFirstFrame);
7318 renderStroke(styleData, itemData, isFirstFrame);
7319 }
7320 function renderGradient(styleData, itemData, isFirstFrame) {
7321 var gfill = itemData.gf;
7322 var hasOpacity = itemData.g._hasOpacity;
7323 var pt1 = itemData.s.v;
7324 var pt2 = itemData.e.v;
7325 if (itemData.o._mdf || isFirstFrame) {
7326 var attr = styleData.ty === "gf" ? "fill-opacity" : "stroke-opacity";
7327 itemData.style.pElem.setAttribute(attr, itemData.o.v);
7328 }
7329 if (itemData.s._mdf || isFirstFrame) {
7330 var attr1 = styleData.t === 1 ? "x1" : "cx";
7331 var attr2 = attr1 === "x1" ? "y1" : "cy";
7332 gfill.setAttribute(attr1, pt1[0]);
7333 gfill.setAttribute(attr2, pt1[1]);
7334 if (hasOpacity && !itemData.g._collapsable) {
7335 itemData.of.setAttribute(attr1, pt1[0]);
7336 itemData.of.setAttribute(attr2, pt1[1]);
7337 }
7338 }
7339 var stops;
7340 var i;
7341 var len;
7342 var stop;
7343 if (itemData.g._cmdf || isFirstFrame) {
7344 stops = itemData.cst;
7345 var cValues = itemData.g.c;
7346 len = stops.length;
7347 for (i = 0; i < len; i += 1) {
7348 stop = stops[i];
7349 stop.setAttribute("offset", cValues[i * 4] + "%");
7350 stop.setAttribute("stop-color", "rgb(" + cValues[i * 4 + 1] + "," + cValues[i * 4 + 2] + "," + cValues[i * 4 + 3] + ")");
7351 }
7352 }
7353 if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
7354 var oValues = itemData.g.o;
7355 if (itemData.g._collapsable) stops = itemData.cst;
7356 else stops = itemData.ost;
7357 len = stops.length;
7358 for (i = 0; i < len; i += 1) {
7359 stop = stops[i];
7360 if (!itemData.g._collapsable) stop.setAttribute("offset", oValues[i * 2] + "%");
7361 stop.setAttribute("stop-opacity", oValues[i * 2 + 1]);
7362 }
7363 }
7364 if (styleData.t === 1) {
7365 if (itemData.e._mdf || isFirstFrame) {
7366 gfill.setAttribute("x2", pt2[0]);
7367 gfill.setAttribute("y2", pt2[1]);
7368 if (hasOpacity && !itemData.g._collapsable) {
7369 itemData.of.setAttribute("x2", pt2[0]);
7370 itemData.of.setAttribute("y2", pt2[1]);
7371 }
7372 }
7373 } else {
7374 var rad;
7375 if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
7376 rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
7377 gfill.setAttribute("r", rad);
7378 if (hasOpacity && !itemData.g._collapsable) itemData.of.setAttribute("r", rad);
7379 }
7380 if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
7381 if (!rad) rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
7382 var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
7383 var percent = itemData.h.v;
7384 if (percent >= 1) percent = .99;
7385 else if (percent <= -1) percent = -.99;
7386 var dist = rad * percent;
7387 var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
7388 var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
7389 gfill.setAttribute("fx", x);
7390 gfill.setAttribute("fy", y);
7391 if (hasOpacity && !itemData.g._collapsable) {
7392 itemData.of.setAttribute("fx", x);
7393 itemData.of.setAttribute("fy", y);
7394 }
7395 }
7396 }
7397 }
7398 function renderStroke(styleData, itemData, isFirstFrame) {
7399 var styleElem = itemData.style;
7400 var d = itemData.d;
7401 if (d && (d._mdf || isFirstFrame) && d.dashStr) {
7402 styleElem.pElem.setAttribute("stroke-dasharray", d.dashStr);
7403 styleElem.pElem.setAttribute("stroke-dashoffset", d.dashoffset[0]);
7404 }
7405 if (itemData.c && (itemData.c._mdf || isFirstFrame)) styleElem.pElem.setAttribute("stroke", "rgb(" + bmFloor(itemData.c.v[0]) + "," + bmFloor(itemData.c.v[1]) + "," + bmFloor(itemData.c.v[2]) + ")");
7406 if (itemData.o._mdf || isFirstFrame) styleElem.pElem.setAttribute("stroke-opacity", itemData.o.v);
7407 if (itemData.w._mdf || isFirstFrame) {
7408 styleElem.pElem.setAttribute("stroke-width", itemData.w.v);
7409 if (styleElem.msElem) styleElem.msElem.setAttribute("stroke-width", itemData.w.v);
7410 }
7411 }
7412 return ob;
7413 }();
7414 function SVGShapeElement(data, globalData, comp) {
7415 this.shapes = [];
7416 this.shapesData = data.shapes;
7417 this.stylesList = [];
7418 this.shapeModifiers = [];
7419 this.itemsData = [];
7420 this.processedElements = [];
7421 this.animatedContents = [];
7422 this.initElement(data, globalData, comp);
7423 this.prevViewData = [];
7424 }
7425 extendPrototype([
7426 BaseElement,
7427 TransformElement,
7428 SVGBaseElement,
7429 IShapeElement,
7430 HierarchyElement,
7431 FrameElement,
7432 RenderableDOMElement
7433 ], SVGShapeElement);
7434 SVGShapeElement.prototype.initSecondaryElement = function() {};
7435 SVGShapeElement.prototype.identityMatrix = new Matrix();
7436 SVGShapeElement.prototype.buildExpressionInterface = function() {};
7437 SVGShapeElement.prototype.createContent = function() {
7438 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
7439 this.filterUniqueShapes();
7440 };
7441 SVGShapeElement.prototype.filterUniqueShapes = function() {
7442 var i;
7443 var len = this.shapes.length;
7444 var shape;
7445 var j;
7446 var jLen = this.stylesList.length;
7447 var style;
7448 var tempShapes = [];
7449 var areAnimated = false;
7450 for (j = 0; j < jLen; j += 1) {
7451 style = this.stylesList[j];
7452 areAnimated = false;
7453 tempShapes.length = 0;
7454 for (i = 0; i < len; i += 1) {
7455 shape = this.shapes[i];
7456 if (shape.styles.indexOf(style) !== -1) {
7457 tempShapes.push(shape);
7458 areAnimated = shape._isAnimated || areAnimated;
7459 }
7460 }
7461 if (tempShapes.length > 1 && areAnimated) this.setShapesAsAnimated(tempShapes);
7462 }
7463 };
7464 SVGShapeElement.prototype.setShapesAsAnimated = function(shapes) {
7465 var i;
7466 var len = shapes.length;
7467 for (i = 0; i < len; i += 1) shapes[i].setAsAnimated();
7468 };
7469 SVGShapeElement.prototype.createStyleElement = function(data, level) {
7470 var elementData;
7471 var styleOb = new SVGStyleData(data, level);
7472 var pathElement = styleOb.pElem;
7473 if (data.ty === "st") elementData = new SVGStrokeStyleData(this, data, styleOb);
7474 else if (data.ty === "fl") elementData = new SVGFillStyleData(this, data, styleOb);
7475 else if (data.ty === "gf" || data.ty === "gs") {
7476 elementData = new (data.ty === "gf" ? SVGGradientFillStyleData : SVGGradientStrokeStyleData)(this, data, styleOb);
7477 this.globalData.defs.appendChild(elementData.gf);
7478 if (elementData.maskId) {
7479 this.globalData.defs.appendChild(elementData.ms);
7480 this.globalData.defs.appendChild(elementData.of);
7481 pathElement.setAttribute("mask", "url(" + getLocationHref() + "#" + elementData.maskId + ")");
7482 }
7483 } else if (data.ty === "no") elementData = new SVGNoStyleData(this, data, styleOb);
7484 if (data.ty === "st" || data.ty === "gs") {
7485 pathElement.setAttribute("stroke-linecap", lineCapEnum[data.lc || 2]);
7486 pathElement.setAttribute("stroke-linejoin", lineJoinEnum[data.lj || 2]);
7487 pathElement.setAttribute("fill-opacity", "0");
7488 if (data.lj === 1) pathElement.setAttribute("stroke-miterlimit", data.ml);
7489 }
7490 if (data.r === 2) pathElement.setAttribute("fill-rule", "evenodd");
7491 if (data.ln) pathElement.setAttribute("id", data.ln);
7492 if (data.cl) pathElement.setAttribute("class", data.cl);
7493 if (data.bm) pathElement.style["mix-blend-mode"] = getBlendMode(data.bm);
7494 this.stylesList.push(styleOb);
7495 this.addToAnimatedContents(data, elementData);
7496 return elementData;
7497 };
7498 SVGShapeElement.prototype.createGroupElement = function(data) {
7499 var elementData = new ShapeGroupData();
7500 if (data.ln) elementData.gr.setAttribute("id", data.ln);
7501 if (data.cl) elementData.gr.setAttribute("class", data.cl);
7502 if (data.bm) elementData.gr.style["mix-blend-mode"] = getBlendMode(data.bm);
7503 return elementData;
7504 };
7505 SVGShapeElement.prototype.createTransformElement = function(data, container) {
7506 var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
7507 var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
7508 this.addToAnimatedContents(data, elementData);
7509 return elementData;
7510 };
7511 SVGShapeElement.prototype.createShapeElement = function(data, ownTransformers, level) {
7512 var ty = 4;
7513 if (data.ty === "rc") ty = 5;
7514 else if (data.ty === "el") ty = 6;
7515 else if (data.ty === "sr") ty = 7;
7516 var elementData = new SVGShapeData(ownTransformers, level, ShapePropertyFactory.getShapeProp(this, data, ty, this));
7517 this.shapes.push(elementData);
7518 this.addShapeToModifiers(elementData);
7519 this.addToAnimatedContents(data, elementData);
7520 return elementData;
7521 };
7522 SVGShapeElement.prototype.addToAnimatedContents = function(data, element) {
7523 var i = 0;
7524 var len = this.animatedContents.length;
7525 while (i < len) {
7526 if (this.animatedContents[i].element === element) return;
7527 i += 1;
7528 }
7529 this.animatedContents.push({
7530 fn: SVGElementsRenderer.createRenderFunction(data),
7531 element,
7532 data
7533 });
7534 };
7535 SVGShapeElement.prototype.setElementStyles = function(elementData) {
7536 var arr = elementData.styles;
7537 var j;
7538 var jLen = this.stylesList.length;
7539 for (j = 0; j < jLen; j += 1) if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) arr.push(this.stylesList[j]);
7540 };
7541 SVGShapeElement.prototype.reloadShapes = function() {
7542 this._isFirstFrame = true;
7543 var i;
7544 var len = this.itemsData.length;
7545 for (i = 0; i < len; i += 1) this.prevViewData[i] = this.itemsData[i];
7546 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
7547 this.filterUniqueShapes();
7548 len = this.dynamicProperties.length;
7549 for (i = 0; i < len; i += 1) this.dynamicProperties[i].getValue();
7550 this.renderModifiers();
7551 };
7552 SVGShapeElement.prototype.searchShapes = function(arr, itemsData, prevViewData, container, level, transformers, render) {
7553 var ownTransformers = [].concat(transformers);
7554 var i;
7555 var len = arr.length - 1;
7556 var j;
7557 var jLen;
7558 var ownStyles = [];
7559 var ownModifiers = [];
7560 var currentTransform;
7561 var modifier;
7562 var processedPos;
7563 for (i = len; i >= 0; i -= 1) {
7564 processedPos = this.searchProcessedElement(arr[i]);
7565 if (!processedPos) arr[i]._render = render;
7566 else itemsData[i] = prevViewData[processedPos - 1];
7567 if (arr[i].ty === "fl" || arr[i].ty === "st" || arr[i].ty === "gf" || arr[i].ty === "gs" || arr[i].ty === "no") {
7568 if (!processedPos) itemsData[i] = this.createStyleElement(arr[i], level);
7569 else itemsData[i].style.closed = arr[i].hd;
7570 if (arr[i]._render) {
7571 if (itemsData[i].style.pElem.parentNode !== container) container.appendChild(itemsData[i].style.pElem);
7572 }
7573 ownStyles.push(itemsData[i].style);
7574 } else if (arr[i].ty === "gr") {
7575 if (!processedPos) itemsData[i] = this.createGroupElement(arr[i]);
7576 else {
7577 jLen = itemsData[i].it.length;
7578 for (j = 0; j < jLen; j += 1) itemsData[i].prevViewData[j] = itemsData[i].it[j];
7579 }
7580 this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
7581 if (arr[i]._render) {
7582 if (itemsData[i].gr.parentNode !== container) container.appendChild(itemsData[i].gr);
7583 }
7584 } else if (arr[i].ty === "tr") {
7585 if (!processedPos) itemsData[i] = this.createTransformElement(arr[i], container);
7586 currentTransform = itemsData[i].transform;
7587 ownTransformers.push(currentTransform);
7588 } else if (arr[i].ty === "sh" || arr[i].ty === "rc" || arr[i].ty === "el" || arr[i].ty === "sr") {
7589 if (!processedPos) itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
7590 this.setElementStyles(itemsData[i]);
7591 } else if (arr[i].ty === "tm" || arr[i].ty === "rd" || arr[i].ty === "ms" || arr[i].ty === "pb" || arr[i].ty === "zz" || arr[i].ty === "op") {
7592 if (!processedPos) {
7593 modifier = ShapeModifiers.getModifier(arr[i].ty);
7594 modifier.init(this, arr[i]);
7595 itemsData[i] = modifier;
7596 this.shapeModifiers.push(modifier);
7597 } else {
7598 modifier = itemsData[i];
7599 modifier.closed = false;
7600 }
7601 ownModifiers.push(modifier);
7602 } else if (arr[i].ty === "rp") {
7603 if (!processedPos) {
7604 modifier = ShapeModifiers.getModifier(arr[i].ty);
7605 itemsData[i] = modifier;
7606 modifier.init(this, arr, i, itemsData);
7607 this.shapeModifiers.push(modifier);
7608 render = false;
7609 } else {
7610 modifier = itemsData[i];
7611 modifier.closed = true;
7612 }
7613 ownModifiers.push(modifier);
7614 }
7615 this.addProcessedElement(arr[i], i + 1);
7616 }
7617 len = ownStyles.length;
7618 for (i = 0; i < len; i += 1) ownStyles[i].closed = true;
7619 len = ownModifiers.length;
7620 for (i = 0; i < len; i += 1) ownModifiers[i].closed = true;
7621 };
7622 SVGShapeElement.prototype.renderInnerContent = function() {
7623 this.renderModifiers();
7624 var i;
7625 var len = this.stylesList.length;
7626 for (i = 0; i < len; i += 1) this.stylesList[i].reset();
7627 this.renderShape();
7628 for (i = 0; i < len; i += 1) if (this.stylesList[i]._mdf || this._isFirstFrame) {
7629 if (this.stylesList[i].msElem) {
7630 this.stylesList[i].msElem.setAttribute("d", this.stylesList[i].d);
7631 this.stylesList[i].d = "M0 0" + this.stylesList[i].d;
7632 }
7633 this.stylesList[i].pElem.setAttribute("d", this.stylesList[i].d || "M0 0");
7634 }
7635 };
7636 SVGShapeElement.prototype.renderShape = function() {
7637 var i;
7638 var len = this.animatedContents.length;
7639 var animatedContent;
7640 for (i = 0; i < len; i += 1) {
7641 animatedContent = this.animatedContents[i];
7642 if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
7643 }
7644 };
7645 SVGShapeElement.prototype.destroy = function() {
7646 this.destroyBaseElement();
7647 this.shapesData = null;
7648 this.itemsData = null;
7649 };
7650 function LetterProps(o, sw, sc, fc, m, p) {
7651 this.o = o;
7652 this.sw = sw;
7653 this.sc = sc;
7654 this.fc = fc;
7655 this.m = m;
7656 this.p = p;
7657 this._mdf = {
7658 o: true,
7659 sw: !!sw,
7660 sc: !!sc,
7661 fc: !!fc,
7662 m: true,
7663 p: true
7664 };
7665 }
7666 LetterProps.prototype.update = function(o, sw, sc, fc, m, p) {
7667 this._mdf.o = false;
7668 this._mdf.sw = false;
7669 this._mdf.sc = false;
7670 this._mdf.fc = false;
7671 this._mdf.m = false;
7672 this._mdf.p = false;
7673 var updated = false;
7674 if (this.o !== o) {
7675 this.o = o;
7676 this._mdf.o = true;
7677 updated = true;
7678 }
7679 if (this.sw !== sw) {
7680 this.sw = sw;
7681 this._mdf.sw = true;
7682 updated = true;
7683 }
7684 if (this.sc !== sc) {
7685 this.sc = sc;
7686 this._mdf.sc = true;
7687 updated = true;
7688 }
7689 if (this.fc !== fc) {
7690 this.fc = fc;
7691 this._mdf.fc = true;
7692 updated = true;
7693 }
7694 if (this.m !== m) {
7695 this.m = m;
7696 this._mdf.m = true;
7697 updated = true;
7698 }
7699 if (p.length && (this.p[0] !== p[0] || this.p[1] !== p[1] || this.p[4] !== p[4] || this.p[5] !== p[5] || this.p[12] !== p[12] || this.p[13] !== p[13])) {
7700 this.p = p;
7701 this._mdf.p = true;
7702 updated = true;
7703 }
7704 return updated;
7705 };
7706 function TextProperty(elem, data) {
7707 this._frameId = initialDefaultFrame;
7708 this.pv = "";
7709 this.v = "";
7710 this.kf = false;
7711 this._isFirstFrame = true;
7712 this._mdf = false;
7713 if (data.d && data.d.sid) data.d = elem.globalData.slotManager.getProp(data.d);
7714 this.data = data;
7715 this.elem = elem;
7716 this.comp = this.elem.comp;
7717 this.keysIndex = 0;
7718 this.canResize = false;
7719 this.minimumFontSize = 1;
7720 this.effectsSequence = [];
7721 this.currentData = {
7722 ascent: 0,
7723 boxWidth: this.defaultBoxWidth,
7724 f: "",
7725 fStyle: "",
7726 fWeight: "",
7727 fc: "",
7728 j: "",
7729 justifyOffset: "",
7730 l: [],
7731 lh: 0,
7732 lineWidths: [],
7733 ls: "",
7734 of: "",
7735 s: "",
7736 sc: "",
7737 sw: 0,
7738 t: 0,
7739 tr: 0,
7740 sz: 0,
7741 ps: null,
7742 fillColorAnim: false,
7743 strokeColorAnim: false,
7744 strokeWidthAnim: false,
7745 yOffset: 0,
7746 finalSize: 0,
7747 finalText: [],
7748 finalLineHeight: 0,
7749 __complete: false
7750 };
7751 this.copyData(this.currentData, this.data.d.k[0].s);
7752 if (!this.searchProperty()) this.completeTextData(this.currentData);
7753 }
7754 TextProperty.prototype.defaultBoxWidth = [0, 0];
7755 TextProperty.prototype.copyData = function(obj, data) {
7756 for (var s in data) if (Object.prototype.hasOwnProperty.call(data, s)) obj[s] = data[s];
7757 return obj;
7758 };
7759 TextProperty.prototype.setCurrentData = function(data) {
7760 if (!data.__complete) this.completeTextData(data);
7761 this.currentData = data;
7762 this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
7763 this._mdf = true;
7764 };
7765 TextProperty.prototype.searchProperty = function() {
7766 return this.searchKeyframes();
7767 };
7768 TextProperty.prototype.searchKeyframes = function() {
7769 this.kf = this.data.d.k.length > 1;
7770 if (this.kf) this.addEffect(this.getKeyframeValue.bind(this));
7771 return this.kf;
7772 };
7773 TextProperty.prototype.addEffect = function(effectFunction) {
7774 this.effectsSequence.push(effectFunction);
7775 this.elem.addDynamicProperty(this);
7776 };
7777 TextProperty.prototype.getValue = function(_finalValue) {
7778 if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) return;
7779 this.currentData.t = this.data.d.k[this.keysIndex].s.t;
7780 var currentValue = this.currentData;
7781 var currentIndex = this.keysIndex;
7782 if (this.lock) {
7783 this.setCurrentData(this.currentData);
7784 return;
7785 }
7786 this.lock = true;
7787 this._mdf = false;
7788 var i;
7789 var len = this.effectsSequence.length;
7790 var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
7791 for (i = 0; i < len; i += 1) if (currentIndex !== this.keysIndex) finalValue = this.effectsSequence[i](finalValue, finalValue.t);
7792 else finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
7793 if (currentValue !== finalValue) this.setCurrentData(finalValue);
7794 this.v = this.currentData;
7795 this.pv = this.v;
7796 this.lock = false;
7797 this.frameId = this.elem.globalData.frameId;
7798 };
7799 TextProperty.prototype.getKeyframeValue = function() {
7800 var textKeys = this.data.d.k;
7801 var frameNum = this.elem.comp.renderedFrame;
7802 var i = 0;
7803 var len = textKeys.length;
7804 while (i <= len - 1) {
7805 if (i === len - 1 || textKeys[i + 1].t > frameNum) break;
7806 i += 1;
7807 }
7808 if (this.keysIndex !== i) this.keysIndex = i;
7809 return this.data.d.k[this.keysIndex].s;
7810 };
7811 TextProperty.prototype.buildFinalText = function(text) {
7812 var charactersArray = [];
7813 var i = 0;
7814 var len = text.length;
7815 var charCode;
7816 var secondCharCode;
7817 var shouldCombine = false;
7818 var shouldCombineNext = false;
7819 var currentChars = "";
7820 while (i < len) {
7821 shouldCombine = shouldCombineNext;
7822 shouldCombineNext = false;
7823 charCode = text.charCodeAt(i);
7824 currentChars = text.charAt(i);
7825 if (FontManager.isCombinedCharacter(charCode)) shouldCombine = true;
7826 else if (charCode >= 55296 && charCode <= 56319) if (FontManager.isRegionalFlag(text, i)) currentChars = text.substr(i, 14);
7827 else {
7828 secondCharCode = text.charCodeAt(i + 1);
7829 if (secondCharCode >= 56320 && secondCharCode <= 57343) if (FontManager.isModifier(charCode, secondCharCode)) {
7830 currentChars = text.substr(i, 2);
7831 shouldCombine = true;
7832 } else if (FontManager.isFlagEmoji(text.substr(i, 4))) currentChars = text.substr(i, 4);
7833 else currentChars = text.substr(i, 2);
7834 }
7835 else if (charCode > 56319) {
7836 secondCharCode = text.charCodeAt(i + 1);
7837 if (FontManager.isVariationSelector(charCode)) shouldCombine = true;
7838 } else if (FontManager.isZeroWidthJoiner(charCode)) {
7839 shouldCombine = true;
7840 shouldCombineNext = true;
7841 }
7842 if (shouldCombine) {
7843 charactersArray[charactersArray.length - 1] += currentChars;
7844 shouldCombine = false;
7845 } else charactersArray.push(currentChars);
7846 i += currentChars.length;
7847 }
7848 return charactersArray;
7849 };
7850 TextProperty.prototype.completeTextData = function(documentData) {
7851 documentData.__complete = true;
7852 var fontManager = this.elem.globalData.fontManager;
7853 var data = this.data;
7854 var letters = [];
7855 var i;
7856 var len;
7857 var newLineFlag;
7858 var index = 0;
7859 var val;
7860 var anchorGrouping = data.m.g;
7861 var currentSize = 0;
7862 var currentPos = 0;
7863 var currentLine = 0;
7864 var lineWidths = [];
7865 var lineWidth = 0;
7866 var maxLineWidth = 0;
7867 var j;
7868 var jLen;
7869 var fontData = fontManager.getFontByName(documentData.f);
7870 var charData;
7871 var cLength = 0;
7872 var fontProps = getFontProperties(fontData);
7873 documentData.fWeight = fontProps.weight;
7874 documentData.fStyle = fontProps.style;
7875 documentData.finalSize = documentData.s;
7876 documentData.finalText = this.buildFinalText(documentData.t);
7877 len = documentData.finalText.length;
7878 documentData.finalLineHeight = documentData.lh;
7879 var trackingOffset = documentData.tr / 1e3 * documentData.finalSize;
7880 var charCode;
7881 if (documentData.sz) {
7882 var flag = true;
7883 var boxWidth = documentData.sz[0];
7884 var boxHeight = documentData.sz[1];
7885 var currentHeight;
7886 var finalText;
7887 while (flag) {
7888 finalText = this.buildFinalText(documentData.t);
7889 currentHeight = 0;
7890 lineWidth = 0;
7891 len = finalText.length;
7892 trackingOffset = documentData.tr / 1e3 * documentData.finalSize;
7893 var lastSpaceIndex = -1;
7894 for (i = 0; i < len; i += 1) {
7895 charCode = finalText[i].charCodeAt(0);
7896 newLineFlag = false;
7897 if (finalText[i] === " ") lastSpaceIndex = i;
7898 else if (charCode === 13 || charCode === 3) {
7899 lineWidth = 0;
7900 newLineFlag = true;
7901 currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
7902 }
7903 if (fontManager.chars) {
7904 charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
7905 cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
7906 } else cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
7907 if (lineWidth + cLength > boxWidth && finalText[i] !== " ") {
7908 if (lastSpaceIndex === -1) len += 1;
7909 else i = lastSpaceIndex;
7910 currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
7911 finalText.splice(i, lastSpaceIndex === i ? 1 : 0, "\r");
7912 lastSpaceIndex = -1;
7913 lineWidth = 0;
7914 } else {
7915 lineWidth += cLength;
7916 lineWidth += trackingOffset;
7917 }
7918 }
7919 currentHeight += fontData.ascent * documentData.finalSize / 100;
7920 if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
7921 documentData.finalSize -= 1;
7922 documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
7923 } else {
7924 documentData.finalText = finalText;
7925 len = documentData.finalText.length;
7926 flag = false;
7927 }
7928 }
7929 }
7930 lineWidth = -trackingOffset;
7931 cLength = 0;
7932 var uncollapsedSpaces = 0;
7933 var currentChar;
7934 for (i = 0; i < len; i += 1) {
7935 newLineFlag = false;
7936 currentChar = documentData.finalText[i];
7937 charCode = currentChar.charCodeAt(0);
7938 if (charCode === 13 || charCode === 3) {
7939 uncollapsedSpaces = 0;
7940 lineWidths.push(lineWidth);
7941 maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
7942 lineWidth = -2 * trackingOffset;
7943 val = "";
7944 newLineFlag = true;
7945 currentLine += 1;
7946 } else val = currentChar;
7947 if (fontManager.chars) {
7948 charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
7949 cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
7950 } else cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
7951 if (currentChar === " ") uncollapsedSpaces += cLength + trackingOffset;
7952 else {
7953 lineWidth += cLength + trackingOffset + uncollapsedSpaces;
7954 uncollapsedSpaces = 0;
7955 }
7956 letters.push({
7957 l: cLength,
7958 an: cLength,
7959 add: currentSize,
7960 n: newLineFlag,
7961 anIndexes: [],
7962 val,
7963 line: currentLine,
7964 animatorJustifyOffset: 0
7965 });
7966 if (anchorGrouping == 2) {
7967 currentSize += cLength;
7968 if (val === "" || val === " " || i === len - 1) {
7969 if (val === "" || val === " ") currentSize -= cLength;
7970 while (currentPos <= i) {
7971 letters[currentPos].an = currentSize;
7972 letters[currentPos].ind = index;
7973 letters[currentPos].extra = cLength;
7974 currentPos += 1;
7975 }
7976 index += 1;
7977 currentSize = 0;
7978 }
7979 } else if (anchorGrouping == 3) {
7980 currentSize += cLength;
7981 if (val === "" || i === len - 1) {
7982 if (val === "") currentSize -= cLength;
7983 while (currentPos <= i) {
7984 letters[currentPos].an = currentSize;
7985 letters[currentPos].ind = index;
7986 letters[currentPos].extra = cLength;
7987 currentPos += 1;
7988 }
7989 currentSize = 0;
7990 index += 1;
7991 }
7992 } else {
7993 letters[index].ind = index;
7994 letters[index].extra = 0;
7995 index += 1;
7996 }
7997 }
7998 documentData.l = letters;
7999 maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
8000 lineWidths.push(lineWidth);
8001 if (documentData.sz) {
8002 documentData.boxWidth = documentData.sz[0];
8003 documentData.justifyOffset = 0;
8004 } else {
8005 documentData.boxWidth = maxLineWidth;
8006 switch (documentData.j) {
8007 case 1:
8008 documentData.justifyOffset = -documentData.boxWidth;
8009 break;
8010 case 2:
8011 documentData.justifyOffset = -documentData.boxWidth / 2;
8012 break;
8013 default: documentData.justifyOffset = 0;
8014 }
8015 }
8016 documentData.lineWidths = lineWidths;
8017 var animators = data.a;
8018 var animatorData;
8019 var letterData;
8020 jLen = animators.length;
8021 var based;
8022 var ind;
8023 var indexes = [];
8024 for (j = 0; j < jLen; j += 1) {
8025 animatorData = animators[j];
8026 if (animatorData.a.sc) documentData.strokeColorAnim = true;
8027 if (animatorData.a.sw) documentData.strokeWidthAnim = true;
8028 if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) documentData.fillColorAnim = true;
8029 ind = 0;
8030 based = animatorData.s.b;
8031 for (i = 0; i < len; i += 1) {
8032 letterData = letters[i];
8033 letterData.anIndexes[j] = ind;
8034 if (based == 1 && letterData.val !== "" || based == 2 && letterData.val !== "" && letterData.val !== " " || based == 3 && (letterData.n || letterData.val == " " || i == len - 1) || based == 4 && (letterData.n || i == len - 1)) {
8035 if (animatorData.s.rn === 1) indexes.push(ind);
8036 ind += 1;
8037 }
8038 }
8039 data.a[j].s.totalChars = ind;
8040 var currentInd = -1;
8041 var newInd;
8042 if (animatorData.s.rn === 1) for (i = 0; i < len; i += 1) {
8043 letterData = letters[i];
8044 if (currentInd != letterData.anIndexes[j]) {
8045 currentInd = letterData.anIndexes[j];
8046 newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
8047 }
8048 letterData.anIndexes[j] = newInd;
8049 }
8050 }
8051 documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
8052 documentData.ls = documentData.ls || 0;
8053 documentData.ascent = fontData.ascent * documentData.finalSize / 100;
8054 };
8055 TextProperty.prototype.updateDocumentData = function(newData, index) {
8056 index = index === void 0 ? this.keysIndex : index;
8057 var dData = this.copyData({}, this.data.d.k[index].s);
8058 dData = this.copyData(dData, newData);
8059 this.data.d.k[index].s = dData;
8060 this.recalculate(index);
8061 this.setCurrentData(dData);
8062 this.elem.addDynamicProperty(this);
8063 };
8064 TextProperty.prototype.recalculate = function(index) {
8065 var dData = this.data.d.k[index].s;
8066 dData.__complete = false;
8067 this.keysIndex = 0;
8068 this._isFirstFrame = true;
8069 this.getValue(dData);
8070 };
8071 TextProperty.prototype.canResizeFont = function(_canResize) {
8072 this.canResize = _canResize;
8073 this.recalculate(this.keysIndex);
8074 this.elem.addDynamicProperty(this);
8075 };
8076 TextProperty.prototype.setMinimumFontSize = function(_fontValue) {
8077 this.minimumFontSize = Math.floor(_fontValue) || 1;
8078 this.recalculate(this.keysIndex);
8079 this.elem.addDynamicProperty(this);
8080 };
8081 var TextSelectorProp = function() {
8082 var max = Math.max;
8083 var min = Math.min;
8084 var floor = Math.floor;
8085 function TextSelectorPropFactory(elem, data) {
8086 this._currentTextLength = -1;
8087 this.k = false;
8088 this.data = data;
8089 this.elem = elem;
8090 this.comp = elem.comp;
8091 this.finalS = 0;
8092 this.finalE = 0;
8093 this.initDynamicPropertyContainer(elem);
8094 this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
8095 if ("e" in data) this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
8096 else this.e = { v: 100 };
8097 this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
8098 this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
8099 this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
8100 this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
8101 this.a = PropertyFactory.getProp(elem, data.a, 0, .01, this);
8102 if (!this.dynamicProperties.length) this.getValue();
8103 }
8104 TextSelectorPropFactory.prototype = {
8105 getMult: function getMult(ind) {
8106 if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) this.getValue();
8107 var x1 = 0;
8108 var y1 = 0;
8109 var x2 = 1;
8110 var y2 = 1;
8111 if (this.ne.v > 0) x1 = this.ne.v / 100;
8112 else y1 = -this.ne.v / 100;
8113 if (this.xe.v > 0) x2 = 1 - this.xe.v / 100;
8114 else y2 = 1 + this.xe.v / 100;
8115 var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
8116 var mult = 0;
8117 var s = this.finalS;
8118 var e = this.finalE;
8119 var type = this.data.sh;
8120 if (type === 2) {
8121 if (e === s) mult = ind >= e ? 1 : 0;
8122 else mult = max(0, min(.5 / (e - s) + (ind - s) / (e - s), 1));
8123 mult = easer(mult);
8124 } else if (type === 3) {
8125 if (e === s) mult = ind >= e ? 0 : 1;
8126 else mult = 1 - max(0, min(.5 / (e - s) + (ind - s) / (e - s), 1));
8127 mult = easer(mult);
8128 } else if (type === 4) {
8129 if (e === s) mult = 0;
8130 else {
8131 mult = max(0, min(.5 / (e - s) + (ind - s) / (e - s), 1));
8132 if (mult < .5) mult *= 2;
8133 else mult = 1 - 2 * (mult - .5);
8134 }
8135 mult = easer(mult);
8136 } else if (type === 5) {
8137 if (e === s) mult = 0;
8138 else {
8139 var tot = e - s;
8140 ind = min(max(0, ind + .5 - s), e - s);
8141 var x = -tot / 2 + ind;
8142 var a = tot / 2;
8143 mult = Math.sqrt(1 - x * x / (a * a));
8144 }
8145 mult = easer(mult);
8146 } else if (type === 6) {
8147 if (e === s) mult = 0;
8148 else {
8149 ind = min(max(0, ind + .5 - s), e - s);
8150 mult = (1 + Math.cos(Math.PI + Math.PI * 2 * ind / (e - s))) / 2;
8151 }
8152 mult = easer(mult);
8153 } else {
8154 if (ind >= floor(s)) if (ind - s < 0) mult = max(0, min(min(e, 1) - (s - ind), 1));
8155 else mult = max(0, min(e - ind, 1));
8156 mult = easer(mult);
8157 }
8158 if (this.sm.v !== 100) {
8159 var smoothness = this.sm.v * .01;
8160 if (smoothness === 0) smoothness = 1e-8;
8161 var threshold = .5 - smoothness * .5;
8162 if (mult < threshold) mult = 0;
8163 else {
8164 mult = (mult - threshold) / smoothness;
8165 if (mult > 1) mult = 1;
8166 }
8167 }
8168 return mult * this.a.v;
8169 },
8170 getValue: function getValue(newCharsFlag) {
8171 this.iterateDynamicProperties();
8172 this._mdf = newCharsFlag || this._mdf;
8173 this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
8174 if (newCharsFlag && this.data.r === 2) this.e.v = this._currentTextLength;
8175 var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
8176 var o = this.o.v / divisor;
8177 var s = this.s.v / divisor + o;
8178 var e = this.e.v / divisor + o;
8179 if (s > e) {
8180 var _s = s;
8181 s = e;
8182 e = _s;
8183 }
8184 this.finalS = s;
8185 this.finalE = e;
8186 }
8187 };
8188 extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
8189 function getTextSelectorProp(elem, data, arr) {
8190 return new TextSelectorPropFactory(elem, data, arr);
8191 }
8192 return { getTextSelectorProp };
8193 }();
8194 function TextAnimatorDataProperty(elem, animatorProps, container) {
8195 var defaultData = { propType: false };
8196 var getProp = PropertyFactory.getProp;
8197 var textAnimatorAnimatables = animatorProps.a;
8198 this.a = {
8199 r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
8200 rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
8201 ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
8202 sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
8203 sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
8204 s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, .01, container) : defaultData,
8205 a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
8206 o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, .01, container) : defaultData,
8207 p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
8208 sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
8209 sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
8210 fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
8211 fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
8212 fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, .01, container) : defaultData,
8213 fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, .01, container) : defaultData,
8214 t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData
8215 };
8216 this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
8217 this.s.t = animatorProps.s.t;
8218 }
8219 function TextAnimatorProperty(textData, renderType, elem) {
8220 this._isFirstFrame = true;
8221 this._hasMaskedPath = false;
8222 this._frameId = -1;
8223 this._textData = textData;
8224 this._renderType = renderType;
8225 this._elem = elem;
8226 this._animatorsData = createSizedArray(this._textData.a.length);
8227 this._pathData = {};
8228 this._moreOptions = { alignment: {} };
8229 this.renderedLetters = [];
8230 this.lettersChangedFlag = false;
8231 this.initDynamicPropertyContainer(elem);
8232 }
8233 TextAnimatorProperty.prototype.searchProperties = function() {
8234 var i;
8235 var len = this._textData.a.length;
8236 var animatorProps;
8237 var getProp = PropertyFactory.getProp;
8238 for (i = 0; i < len; i += 1) {
8239 animatorProps = this._textData.a[i];
8240 this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
8241 }
8242 if (this._textData.p && "m" in this._textData.p) {
8243 this._pathData = {
8244 a: getProp(this._elem, this._textData.p.a, 0, 0, this),
8245 f: getProp(this._elem, this._textData.p.f, 0, 0, this),
8246 l: getProp(this._elem, this._textData.p.l, 0, 0, this),
8247 r: getProp(this._elem, this._textData.p.r, 0, 0, this),
8248 p: getProp(this._elem, this._textData.p.p, 0, 0, this),
8249 m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
8250 };
8251 this._hasMaskedPath = true;
8252 } else this._hasMaskedPath = false;
8253 this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
8254 };
8255 TextAnimatorProperty.prototype.getMeasures = function(documentData, lettersChangedFlag) {
8256 this.lettersChangedFlag = lettersChangedFlag;
8257 if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) return;
8258 this._isFirstFrame = false;
8259 var alignment = this._moreOptions.alignment.v;
8260 var animators = this._animatorsData;
8261 var textData = this._textData;
8262 var matrixHelper = this.mHelper;
8263 var renderType = this._renderType;
8264 var renderedLettersCount = this.renderedLetters.length;
8265 var xPos;
8266 var yPos;
8267 var i;
8268 var len;
8269 var letters = documentData.l;
8270 var pathInfo;
8271 var currentLength;
8272 var currentPoint;
8273 var segmentLength;
8274 var flag;
8275 var pointInd;
8276 var segmentInd;
8277 var prevPoint;
8278 var points;
8279 var segments;
8280 var partialLength;
8281 var totalLength;
8282 var perc;
8283 var tanAngle;
8284 var mask;
8285 if (this._hasMaskedPath) {
8286 mask = this._pathData.m;
8287 if (!this._pathData.n || this._pathData._mdf) {
8288 var paths = mask.v;
8289 if (this._pathData.r.v) paths = paths.reverse();
8290 pathInfo = {
8291 tLength: 0,
8292 segments: []
8293 };
8294 len = paths._length - 1;
8295 var bezierData;
8296 totalLength = 0;
8297 for (i = 0; i < len; i += 1) {
8298 bezierData = bez.buildBezierData(paths.v[i], paths.v[i + 1], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
8299 pathInfo.tLength += bezierData.segmentLength;
8300 pathInfo.segments.push(bezierData);
8301 totalLength += bezierData.segmentLength;
8302 }
8303 i = len;
8304 if (mask.v.c) {
8305 bezierData = bez.buildBezierData(paths.v[i], paths.v[0], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
8306 pathInfo.tLength += bezierData.segmentLength;
8307 pathInfo.segments.push(bezierData);
8308 totalLength += bezierData.segmentLength;
8309 }
8310 this._pathData.pi = pathInfo;
8311 }
8312 pathInfo = this._pathData.pi;
8313 currentLength = this._pathData.f.v;
8314 segmentInd = 0;
8315 pointInd = 1;
8316 segmentLength = 0;
8317 flag = true;
8318 segments = pathInfo.segments;
8319 if (currentLength < 0 && mask.v.c) {
8320 if (pathInfo.tLength < Math.abs(currentLength)) currentLength = -Math.abs(currentLength) % pathInfo.tLength;
8321 segmentInd = segments.length - 1;
8322 points = segments[segmentInd].points;
8323 pointInd = points.length - 1;
8324 while (currentLength < 0) {
8325 currentLength += points[pointInd].partialLength;
8326 pointInd -= 1;
8327 if (pointInd < 0) {
8328 segmentInd -= 1;
8329 points = segments[segmentInd].points;
8330 pointInd = points.length - 1;
8331 }
8332 }
8333 }
8334 points = segments[segmentInd].points;
8335 prevPoint = points[pointInd - 1];
8336 currentPoint = points[pointInd];
8337 partialLength = currentPoint.partialLength;
8338 }
8339 len = letters.length;
8340 xPos = 0;
8341 yPos = 0;
8342 var yOff = documentData.finalSize * 1.2 * .714;
8343 var firstLine = true;
8344 var animatorProps;
8345 var animatorSelector;
8346 var j;
8347 var jLen;
8348 var letterValue;
8349 jLen = animators.length;
8350 var mult;
8351 var ind = -1;
8352 var offf;
8353 var xPathPos;
8354 var yPathPos;
8355 var initPathPos = currentLength;
8356 var initSegmentInd = segmentInd;
8357 var initPointInd = pointInd;
8358 var currentLine = -1;
8359 var elemOpacity;
8360 var sc;
8361 var sw;
8362 var fc;
8363 var k;
8364 var letterSw;
8365 var letterSc;
8366 var letterFc;
8367 var letterM = "";
8368 var letterP = this.defaultPropsArray;
8369 var letterO;
8370 if (documentData.j === 2 || documentData.j === 1) {
8371 var animatorJustifyOffset = 0;
8372 var animatorFirstCharOffset = 0;
8373 var justifyOffsetMult = documentData.j === 2 ? -.5 : -1;
8374 var lastIndex = 0;
8375 var isNewLine = true;
8376 for (i = 0; i < len; i += 1) if (letters[i].n) {
8377 if (animatorJustifyOffset) animatorJustifyOffset += animatorFirstCharOffset;
8378 while (lastIndex < i) {
8379 letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
8380 lastIndex += 1;
8381 }
8382 animatorJustifyOffset = 0;
8383 isNewLine = true;
8384 } else {
8385 for (j = 0; j < jLen; j += 1) {
8386 animatorProps = animators[j].a;
8387 if (animatorProps.t.propType) {
8388 if (isNewLine && documentData.j === 2) animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
8389 animatorSelector = animators[j].s;
8390 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8391 if (mult.length) animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
8392 else animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
8393 }
8394 }
8395 isNewLine = false;
8396 }
8397 if (animatorJustifyOffset) animatorJustifyOffset += animatorFirstCharOffset;
8398 while (lastIndex < i) {
8399 letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
8400 lastIndex += 1;
8401 }
8402 }
8403 for (i = 0; i < len; i += 1) {
8404 matrixHelper.reset();
8405 elemOpacity = 1;
8406 if (letters[i].n) {
8407 xPos = 0;
8408 yPos += documentData.yOffset;
8409 yPos += firstLine ? 1 : 0;
8410 currentLength = initPathPos;
8411 firstLine = false;
8412 if (this._hasMaskedPath) {
8413 segmentInd = initSegmentInd;
8414 pointInd = initPointInd;
8415 points = segments[segmentInd].points;
8416 prevPoint = points[pointInd - 1];
8417 currentPoint = points[pointInd];
8418 partialLength = currentPoint.partialLength;
8419 segmentLength = 0;
8420 }
8421 letterM = "";
8422 letterFc = "";
8423 letterSw = "";
8424 letterO = "";
8425 letterP = this.defaultPropsArray;
8426 } else {
8427 if (this._hasMaskedPath) {
8428 if (currentLine !== letters[i].line) {
8429 switch (documentData.j) {
8430 case 1:
8431 currentLength += totalLength - documentData.lineWidths[letters[i].line];
8432 break;
8433 case 2:
8434 currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
8435 break;
8436 default: break;
8437 }
8438 currentLine = letters[i].line;
8439 }
8440 if (ind !== letters[i].ind) {
8441 if (letters[ind]) currentLength += letters[ind].extra;
8442 currentLength += letters[i].an / 2;
8443 ind = letters[i].ind;
8444 }
8445 currentLength += alignment[0] * letters[i].an * .005;
8446 var animatorOffset = 0;
8447 for (j = 0; j < jLen; j += 1) {
8448 animatorProps = animators[j].a;
8449 if (animatorProps.p.propType) {
8450 animatorSelector = animators[j].s;
8451 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8452 if (mult.length) animatorOffset += animatorProps.p.v[0] * mult[0];
8453 else animatorOffset += animatorProps.p.v[0] * mult;
8454 }
8455 if (animatorProps.a.propType) {
8456 animatorSelector = animators[j].s;
8457 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8458 if (mult.length) animatorOffset += animatorProps.a.v[0] * mult[0];
8459 else animatorOffset += animatorProps.a.v[0] * mult;
8460 }
8461 }
8462 flag = true;
8463 if (this._pathData.a.v) {
8464 currentLength = letters[0].an * .5 + (totalLength - this._pathData.f.v - letters[0].an * .5 - letters[letters.length - 1].an * .5) * ind / (len - 1);
8465 currentLength += this._pathData.f.v;
8466 }
8467 while (flag) if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
8468 perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
8469 xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
8470 yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
8471 matrixHelper.translate(-alignment[0] * letters[i].an * .005, -(alignment[1] * yOff) * .01);
8472 flag = false;
8473 } else if (points) {
8474 segmentLength += currentPoint.partialLength;
8475 pointInd += 1;
8476 if (pointInd >= points.length) {
8477 pointInd = 0;
8478 segmentInd += 1;
8479 if (!segments[segmentInd]) if (mask.v.c) {
8480 pointInd = 0;
8481 segmentInd = 0;
8482 points = segments[segmentInd].points;
8483 } else {
8484 segmentLength -= currentPoint.partialLength;
8485 points = null;
8486 }
8487 else points = segments[segmentInd].points;
8488 }
8489 if (points) {
8490 prevPoint = currentPoint;
8491 currentPoint = points[pointInd];
8492 partialLength = currentPoint.partialLength;
8493 }
8494 }
8495 offf = letters[i].an / 2 - letters[i].add;
8496 matrixHelper.translate(-offf, 0, 0);
8497 } else {
8498 offf = letters[i].an / 2 - letters[i].add;
8499 matrixHelper.translate(-offf, 0, 0);
8500 matrixHelper.translate(-alignment[0] * letters[i].an * .005, -alignment[1] * yOff * .01, 0);
8501 }
8502 for (j = 0; j < jLen; j += 1) {
8503 animatorProps = animators[j].a;
8504 if (animatorProps.t.propType) {
8505 animatorSelector = animators[j].s;
8506 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8507 if (xPos !== 0 || documentData.j !== 0) if (this._hasMaskedPath) if (mult.length) currentLength += animatorProps.t.v * mult[0];
8508 else currentLength += animatorProps.t.v * mult;
8509 else if (mult.length) xPos += animatorProps.t.v * mult[0];
8510 else xPos += animatorProps.t.v * mult;
8511 }
8512 }
8513 if (documentData.strokeWidthAnim) sw = documentData.sw || 0;
8514 if (documentData.strokeColorAnim) if (documentData.sc) sc = [
8515 documentData.sc[0],
8516 documentData.sc[1],
8517 documentData.sc[2]
8518 ];
8519 else sc = [
8520 0,
8521 0,
8522 0
8523 ];
8524 if (documentData.fillColorAnim && documentData.fc) fc = [
8525 documentData.fc[0],
8526 documentData.fc[1],
8527 documentData.fc[2]
8528 ];
8529 for (j = 0; j < jLen; j += 1) {
8530 animatorProps = animators[j].a;
8531 if (animatorProps.a.propType) {
8532 animatorSelector = animators[j].s;
8533 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8534 if (mult.length) matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
8535 else matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
8536 }
8537 }
8538 for (j = 0; j < jLen; j += 1) {
8539 animatorProps = animators[j].a;
8540 if (animatorProps.s.propType) {
8541 animatorSelector = animators[j].s;
8542 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8543 if (mult.length) matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult[0], 1 + (animatorProps.s.v[1] - 1) * mult[1], 1);
8544 else matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult, 1 + (animatorProps.s.v[1] - 1) * mult, 1);
8545 }
8546 }
8547 for (j = 0; j < jLen; j += 1) {
8548 animatorProps = animators[j].a;
8549 animatorSelector = animators[j].s;
8550 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8551 if (animatorProps.sk.propType) if (mult.length) matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
8552 else matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
8553 if (animatorProps.r.propType) if (mult.length) matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
8554 else matrixHelper.rotateZ(-animatorProps.r.v * mult);
8555 if (animatorProps.ry.propType) if (mult.length) matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
8556 else matrixHelper.rotateY(animatorProps.ry.v * mult);
8557 if (animatorProps.rx.propType) if (mult.length) matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
8558 else matrixHelper.rotateX(animatorProps.rx.v * mult);
8559 if (animatorProps.o.propType) if (mult.length) elemOpacity += (animatorProps.o.v * mult[0] - elemOpacity) * mult[0];
8560 else elemOpacity += (animatorProps.o.v * mult - elemOpacity) * mult;
8561 if (documentData.strokeWidthAnim && animatorProps.sw.propType) if (mult.length) sw += animatorProps.sw.v * mult[0];
8562 else sw += animatorProps.sw.v * mult;
8563 if (documentData.strokeColorAnim && animatorProps.sc.propType) for (k = 0; k < 3; k += 1) if (mult.length) sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
8564 else sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
8565 if (documentData.fillColorAnim && documentData.fc) {
8566 if (animatorProps.fc.propType) for (k = 0; k < 3; k += 1) if (mult.length) fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
8567 else fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
8568 if (animatorProps.fh.propType) if (mult.length) fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
8569 else fc = addHueToRGB(fc, animatorProps.fh.v * mult);
8570 if (animatorProps.fs.propType) if (mult.length) fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
8571 else fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
8572 if (animatorProps.fb.propType) if (mult.length) fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
8573 else fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
8574 }
8575 }
8576 for (j = 0; j < jLen; j += 1) {
8577 animatorProps = animators[j].a;
8578 if (animatorProps.p.propType) {
8579 animatorSelector = animators[j].s;
8580 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
8581 if (this._hasMaskedPath) if (mult.length) matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
8582 else matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
8583 else if (mult.length) matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
8584 else matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
8585 }
8586 }
8587 if (documentData.strokeWidthAnim) letterSw = sw < 0 ? 0 : sw;
8588 if (documentData.strokeColorAnim) letterSc = "rgb(" + Math.round(sc[0] * 255) + "," + Math.round(sc[1] * 255) + "," + Math.round(sc[2] * 255) + ")";
8589 if (documentData.fillColorAnim && documentData.fc) letterFc = "rgb(" + Math.round(fc[0] * 255) + "," + Math.round(fc[1] * 255) + "," + Math.round(fc[2] * 255) + ")";
8590 if (this._hasMaskedPath) {
8591 matrixHelper.translate(0, -documentData.ls);
8592 matrixHelper.translate(0, alignment[1] * yOff * .01 + yPos, 0);
8593 if (this._pathData.p.v) {
8594 tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
8595 var rot = Math.atan(tanAngle) * 180 / Math.PI;
8596 if (currentPoint.point[0] < prevPoint.point[0]) rot += 180;
8597 matrixHelper.rotate(-rot * Math.PI / 180);
8598 }
8599 matrixHelper.translate(xPathPos, yPathPos, 0);
8600 currentLength -= alignment[0] * letters[i].an * .005;
8601 if (letters[i + 1] && ind !== letters[i + 1].ind) {
8602 currentLength += letters[i].an / 2;
8603 currentLength += documentData.tr * .001 * documentData.finalSize;
8604 }
8605 } else {
8606 matrixHelper.translate(xPos, yPos, 0);
8607 if (documentData.ps) matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
8608 switch (documentData.j) {
8609 case 1:
8610 matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
8611 break;
8612 case 2:
8613 matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
8614 break;
8615 default: break;
8616 }
8617 matrixHelper.translate(0, -documentData.ls);
8618 matrixHelper.translate(offf, 0, 0);
8619 matrixHelper.translate(alignment[0] * letters[i].an * .005, alignment[1] * yOff * .01, 0);
8620 xPos += letters[i].l + documentData.tr * .001 * documentData.finalSize;
8621 }
8622 if (renderType === "html") letterM = matrixHelper.toCSS();
8623 else if (renderType === "svg") letterM = matrixHelper.to2dCSS();
8624 else letterP = [
8625 matrixHelper.props[0],
8626 matrixHelper.props[1],
8627 matrixHelper.props[2],
8628 matrixHelper.props[3],
8629 matrixHelper.props[4],
8630 matrixHelper.props[5],
8631 matrixHelper.props[6],
8632 matrixHelper.props[7],
8633 matrixHelper.props[8],
8634 matrixHelper.props[9],
8635 matrixHelper.props[10],
8636 matrixHelper.props[11],
8637 matrixHelper.props[12],
8638 matrixHelper.props[13],
8639 matrixHelper.props[14],
8640 matrixHelper.props[15]
8641 ];
8642 letterO = elemOpacity;
8643 }
8644 if (renderedLettersCount <= i) {
8645 letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
8646 this.renderedLetters.push(letterValue);
8647 renderedLettersCount += 1;
8648 this.lettersChangedFlag = true;
8649 } else {
8650 letterValue = this.renderedLetters[i];
8651 this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
8652 }
8653 }
8654 };
8655 TextAnimatorProperty.prototype.getValue = function() {
8656 if (this._elem.globalData.frameId === this._frameId) return;
8657 this._frameId = this._elem.globalData.frameId;
8658 this.iterateDynamicProperties();
8659 };
8660 TextAnimatorProperty.prototype.mHelper = new Matrix();
8661 TextAnimatorProperty.prototype.defaultPropsArray = [];
8662 extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
8663 function ITextElement() {}
8664 ITextElement.prototype.initElement = function(data, globalData, comp) {
8665 this.lettersChangedFlag = true;
8666 this.initFrame();
8667 this.initBaseData(data, globalData, comp);
8668 this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
8669 this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
8670 this.initTransform(data, globalData, comp);
8671 this.initHierarchy();
8672 this.initRenderable();
8673 this.initRendererElement();
8674 this.createContainerElements();
8675 this.createRenderableComponents();
8676 this.createContent();
8677 this.hide();
8678 this.textAnimator.searchProperties(this.dynamicProperties);
8679 };
8680 ITextElement.prototype.prepareFrame = function(num) {
8681 this._mdf = false;
8682 this.prepareRenderableFrame(num);
8683 this.prepareProperties(num, this.isInRange);
8684 };
8685 ITextElement.prototype.createPathShape = function(matrixHelper, shapes) {
8686 var j;
8687 var jLen = shapes.length;
8688 var pathNodes;
8689 var shapeStr = "";
8690 for (j = 0; j < jLen; j += 1) if (shapes[j].ty === "sh") {
8691 pathNodes = shapes[j].ks.k;
8692 shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
8693 }
8694 return shapeStr;
8695 };
8696 ITextElement.prototype.updateDocumentData = function(newData, index) {
8697 this.textProperty.updateDocumentData(newData, index);
8698 };
8699 ITextElement.prototype.canResizeFont = function(_canResize) {
8700 this.textProperty.canResizeFont(_canResize);
8701 };
8702 ITextElement.prototype.setMinimumFontSize = function(_fontSize) {
8703 this.textProperty.setMinimumFontSize(_fontSize);
8704 };
8705 ITextElement.prototype.applyTextPropertiesToMatrix = function(documentData, matrixHelper, lineNumber, xPos, yPos) {
8706 if (documentData.ps) matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
8707 matrixHelper.translate(0, -documentData.ls, 0);
8708 switch (documentData.j) {
8709 case 1:
8710 matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
8711 break;
8712 case 2:
8713 matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
8714 break;
8715 default: break;
8716 }
8717 matrixHelper.translate(xPos, yPos, 0);
8718 };
8719 ITextElement.prototype.buildColor = function(colorData) {
8720 return "rgb(" + Math.round(colorData[0] * 255) + "," + Math.round(colorData[1] * 255) + "," + Math.round(colorData[2] * 255) + ")";
8721 };
8722 ITextElement.prototype.emptyProp = new LetterProps();
8723 ITextElement.prototype.destroy = function() {};
8724 ITextElement.prototype.validateText = function() {
8725 if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
8726 this.buildNewText();
8727 this.textProperty._isFirstFrame = false;
8728 this.textProperty._mdf = false;
8729 }
8730 };
8731 var emptyShapeData = { shapes: [] };
8732 function SVGTextLottieElement(data, globalData, comp) {
8733 this.textSpans = [];
8734 this.renderType = "svg";
8735 this.initElement(data, globalData, comp);
8736 }
8737 extendPrototype([
8738 BaseElement,
8739 TransformElement,
8740 SVGBaseElement,
8741 HierarchyElement,
8742 FrameElement,
8743 RenderableDOMElement,
8744 ITextElement
8745 ], SVGTextLottieElement);
8746 SVGTextLottieElement.prototype.createContent = function() {
8747 if (this.data.singleShape && !this.globalData.fontManager.chars) this.textContainer = createNS("text");
8748 };
8749 SVGTextLottieElement.prototype.buildTextContents = function(textArray) {
8750 var i = 0;
8751 var len = textArray.length;
8752 var textContents = [];
8753 var currentTextContent = "";
8754 while (i < len) {
8755 if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
8756 textContents.push(currentTextContent);
8757 currentTextContent = "";
8758 } else currentTextContent += textArray[i];
8759 i += 1;
8760 }
8761 textContents.push(currentTextContent);
8762 return textContents;
8763 };
8764 SVGTextLottieElement.prototype.buildShapeData = function(data, scale) {
8765 if (data.shapes && data.shapes.length) {
8766 var shape = data.shapes[0];
8767 if (shape.it) {
8768 var shapeItem = shape.it[shape.it.length - 1];
8769 if (shapeItem.s) {
8770 shapeItem.s.k[0] = scale;
8771 shapeItem.s.k[1] = scale;
8772 }
8773 }
8774 }
8775 return data;
8776 };
8777 SVGTextLottieElement.prototype.buildNewText = function() {
8778 this.addDynamicProperty(this);
8779 var i;
8780 var len;
8781 var documentData = this.textProperty.currentData;
8782 this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
8783 if (documentData.fc) this.layerElement.setAttribute("fill", this.buildColor(documentData.fc));
8784 else this.layerElement.setAttribute("fill", "rgba(0,0,0,0)");
8785 if (documentData.sc) {
8786 this.layerElement.setAttribute("stroke", this.buildColor(documentData.sc));
8787 this.layerElement.setAttribute("stroke-width", documentData.sw);
8788 }
8789 this.layerElement.setAttribute("font-size", documentData.finalSize);
8790 var fontData = this.globalData.fontManager.getFontByName(documentData.f);
8791 if (fontData.fClass) this.layerElement.setAttribute("class", fontData.fClass);
8792 else {
8793 this.layerElement.setAttribute("font-family", fontData.fFamily);
8794 var fWeight = documentData.fWeight;
8795 var fStyle = documentData.fStyle;
8796 this.layerElement.setAttribute("font-style", fStyle);
8797 this.layerElement.setAttribute("font-weight", fWeight);
8798 }
8799 this.layerElement.setAttribute("aria-label", documentData.t);
8800 var letters = documentData.l || [];
8801 var usesGlyphs = !!this.globalData.fontManager.chars;
8802 len = letters.length;
8803 var tSpan;
8804 var matrixHelper = this.mHelper;
8805 var shapeStr = "";
8806 var singleShape = this.data.singleShape;
8807 var xPos = 0;
8808 var yPos = 0;
8809 var firstLine = true;
8810 var trackingOffset = documentData.tr * .001 * documentData.finalSize;
8811 if (singleShape && !usesGlyphs && !documentData.sz) {
8812 var tElement = this.textContainer;
8813 var justify = "start";
8814 switch (documentData.j) {
8815 case 1:
8816 justify = "end";
8817 break;
8818 case 2:
8819 justify = "middle";
8820 break;
8821 default:
8822 justify = "start";
8823 break;
8824 }
8825 tElement.setAttribute("text-anchor", justify);
8826 tElement.setAttribute("letter-spacing", trackingOffset);
8827 var textContent = this.buildTextContents(documentData.finalText);
8828 len = textContent.length;
8829 yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
8830 for (i = 0; i < len; i += 1) {
8831 tSpan = this.textSpans[i].span || createNS("tspan");
8832 tSpan.textContent = textContent[i];
8833 tSpan.setAttribute("x", 0);
8834 tSpan.setAttribute("y", yPos);
8835 tSpan.style.display = "inherit";
8836 tElement.appendChild(tSpan);
8837 if (!this.textSpans[i]) this.textSpans[i] = {
8838 span: null,
8839 glyph: null
8840 };
8841 this.textSpans[i].span = tSpan;
8842 yPos += documentData.finalLineHeight;
8843 }
8844 this.layerElement.appendChild(tElement);
8845 } else {
8846 var cachedSpansLength = this.textSpans.length;
8847 var charData;
8848 for (i = 0; i < len; i += 1) {
8849 if (!this.textSpans[i]) this.textSpans[i] = {
8850 span: null,
8851 childSpan: null,
8852 glyph: null
8853 };
8854 if (!usesGlyphs || !singleShape || i === 0) {
8855 tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? "g" : "text");
8856 if (cachedSpansLength <= i) {
8857 tSpan.setAttribute("stroke-linecap", "butt");
8858 tSpan.setAttribute("stroke-linejoin", "round");
8859 tSpan.setAttribute("stroke-miterlimit", "4");
8860 this.textSpans[i].span = tSpan;
8861 if (usesGlyphs) {
8862 var childSpan = createNS("g");
8863 tSpan.appendChild(childSpan);
8864 this.textSpans[i].childSpan = childSpan;
8865 }
8866 this.textSpans[i].span = tSpan;
8867 this.layerElement.appendChild(tSpan);
8868 }
8869 tSpan.style.display = "inherit";
8870 }
8871 matrixHelper.reset();
8872 if (singleShape) {
8873 if (letters[i].n) {
8874 xPos = -trackingOffset;
8875 yPos += documentData.yOffset;
8876 yPos += firstLine ? 1 : 0;
8877 firstLine = false;
8878 }
8879 this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
8880 xPos += letters[i].l || 0;
8881 xPos += trackingOffset;
8882 }
8883 if (usesGlyphs) {
8884 charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
8885 var glyphElement;
8886 if (charData.t === 1) glyphElement = new SVGCompElement(charData.data, this.globalData, this);
8887 else {
8888 var data = emptyShapeData;
8889 if (charData.data && charData.data.shapes) data = this.buildShapeData(charData.data, documentData.finalSize);
8890 glyphElement = new SVGShapeElement(data, this.globalData, this);
8891 }
8892 if (this.textSpans[i].glyph) {
8893 var glyph = this.textSpans[i].glyph;
8894 this.textSpans[i].childSpan.removeChild(glyph.layerElement);
8895 glyph.destroy();
8896 }
8897 this.textSpans[i].glyph = glyphElement;
8898 glyphElement._debug = true;
8899 glyphElement.prepareFrame(0);
8900 glyphElement.renderFrame();
8901 this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
8902 if (charData.t === 1) this.textSpans[i].childSpan.setAttribute("transform", "scale(" + documentData.finalSize / 100 + "," + documentData.finalSize / 100 + ")");
8903 } else {
8904 if (singleShape) tSpan.setAttribute("transform", "translate(" + matrixHelper.props[12] + "," + matrixHelper.props[13] + ")");
8905 tSpan.textContent = letters[i].val;
8906 tSpan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
8907 }
8908 }
8909 if (singleShape && tSpan) tSpan.setAttribute("d", shapeStr);
8910 }
8911 while (i < this.textSpans.length) {
8912 this.textSpans[i].span.style.display = "none";
8913 i += 1;
8914 }
8915 this._sizeChanged = true;
8916 };
8917 SVGTextLottieElement.prototype.sourceRectAtTime = function() {
8918 this.prepareFrame(this.comp.renderedFrame - this.data.st);
8919 this.renderInnerContent();
8920 if (this._sizeChanged) {
8921 this._sizeChanged = false;
8922 var textBox = this.layerElement.getBBox();
8923 this.bbox = {
8924 top: textBox.y,
8925 left: textBox.x,
8926 width: textBox.width,
8927 height: textBox.height
8928 };
8929 }
8930 return this.bbox;
8931 };
8932 SVGTextLottieElement.prototype.getValue = function() {
8933 var i;
8934 var len = this.textSpans.length;
8935 var glyphElement;
8936 this.renderedFrame = this.comp.renderedFrame;
8937 for (i = 0; i < len; i += 1) {
8938 glyphElement = this.textSpans[i].glyph;
8939 if (glyphElement) {
8940 glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
8941 if (glyphElement._mdf) this._mdf = true;
8942 }
8943 }
8944 };
8945 SVGTextLottieElement.prototype.renderInnerContent = function() {
8946 this.validateText();
8947 if (!this.data.singleShape || this._mdf) {
8948 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
8949 if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
8950 this._sizeChanged = true;
8951 var i;
8952 var len;
8953 var renderedLetters = this.textAnimator.renderedLetters;
8954 var letters = this.textProperty.currentData.l;
8955 len = letters.length;
8956 var renderedLetter;
8957 var textSpan;
8958 var glyphElement;
8959 for (i = 0; i < len; i += 1) if (!letters[i].n) {
8960 renderedLetter = renderedLetters[i];
8961 textSpan = this.textSpans[i].span;
8962 glyphElement = this.textSpans[i].glyph;
8963 if (glyphElement) glyphElement.renderFrame();
8964 if (renderedLetter._mdf.m) textSpan.setAttribute("transform", renderedLetter.m);
8965 if (renderedLetter._mdf.o) textSpan.setAttribute("opacity", renderedLetter.o);
8966 if (renderedLetter._mdf.sw) textSpan.setAttribute("stroke-width", renderedLetter.sw);
8967 if (renderedLetter._mdf.sc) textSpan.setAttribute("stroke", renderedLetter.sc);
8968 if (renderedLetter._mdf.fc) textSpan.setAttribute("fill", renderedLetter.fc);
8969 }
8970 }
8971 }
8972 };
8973 function ISolidElement(data, globalData, comp) {
8974 this.initElement(data, globalData, comp);
8975 }
8976 extendPrototype([IImageElement], ISolidElement);
8977 ISolidElement.prototype.createContent = function() {
8978 var rect = createNS("rect");
8979 rect.setAttribute("width", this.data.sw);
8980 rect.setAttribute("height", this.data.sh);
8981 rect.setAttribute("fill", this.data.sc);
8982 this.layerElement.appendChild(rect);
8983 };
8984 function NullElement(data, globalData, comp) {
8985 this.initFrame();
8986 this.initBaseData(data, globalData, comp);
8987 this.initFrame();
8988 this.initTransform(data, globalData, comp);
8989 this.initHierarchy();
8990 }
8991 NullElement.prototype.prepareFrame = function(num) {
8992 this.prepareProperties(num, true);
8993 };
8994 NullElement.prototype.renderFrame = function() {};
8995 NullElement.prototype.getBaseElement = function() {
8996 return null;
8997 };
8998 NullElement.prototype.destroy = function() {};
8999 NullElement.prototype.sourceRectAtTime = function() {};
9000 NullElement.prototype.hide = function() {};
9001 extendPrototype([
9002 BaseElement,
9003 TransformElement,
9004 HierarchyElement,
9005 FrameElement
9006 ], NullElement);
9007 function SVGRendererBase() {}
9008 extendPrototype([BaseRenderer], SVGRendererBase);
9009 SVGRendererBase.prototype.createNull = function(data) {
9010 return new NullElement(data, this.globalData, this);
9011 };
9012 SVGRendererBase.prototype.createShape = function(data) {
9013 return new SVGShapeElement(data, this.globalData, this);
9014 };
9015 SVGRendererBase.prototype.createText = function(data) {
9016 return new SVGTextLottieElement(data, this.globalData, this);
9017 };
9018 SVGRendererBase.prototype.createImage = function(data) {
9019 return new IImageElement(data, this.globalData, this);
9020 };
9021 SVGRendererBase.prototype.createSolid = function(data) {
9022 return new ISolidElement(data, this.globalData, this);
9023 };
9024 SVGRendererBase.prototype.configAnimation = function(animData) {
9025 this.svgElement.setAttribute("xmlns", "http://www.w3.org/2000/svg");
9026 this.svgElement.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
9027 if (this.renderConfig.viewBoxSize) this.svgElement.setAttribute("viewBox", this.renderConfig.viewBoxSize);
9028 else this.svgElement.setAttribute("viewBox", "0 0 " + animData.w + " " + animData.h);
9029 if (!this.renderConfig.viewBoxOnly) {
9030 this.svgElement.setAttribute("width", animData.w);
9031 this.svgElement.setAttribute("height", animData.h);
9032 this.svgElement.style.width = "100%";
9033 this.svgElement.style.height = "100%";
9034 this.svgElement.style.transform = "translate3d(0,0,0)";
9035 this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
9036 }
9037 if (this.renderConfig.width) this.svgElement.setAttribute("width", this.renderConfig.width);
9038 if (this.renderConfig.height) this.svgElement.setAttribute("height", this.renderConfig.height);
9039 if (this.renderConfig.className) this.svgElement.setAttribute("class", this.renderConfig.className);
9040 if (this.renderConfig.id) this.svgElement.setAttribute("id", this.renderConfig.id);
9041 if (this.renderConfig.focusable !== void 0) this.svgElement.setAttribute("focusable", this.renderConfig.focusable);
9042 this.svgElement.setAttribute("preserveAspectRatio", this.renderConfig.preserveAspectRatio);
9043 this.animationItem.wrapper.appendChild(this.svgElement);
9044 var defs = this.globalData.defs;
9045 this.setupGlobalData(animData, defs);
9046 this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
9047 this.data = animData;
9048 var maskElement = createNS("clipPath");
9049 var rect = createNS("rect");
9050 rect.setAttribute("width", animData.w);
9051 rect.setAttribute("height", animData.h);
9052 rect.setAttribute("x", 0);
9053 rect.setAttribute("y", 0);
9054 var maskId = createElementID();
9055 maskElement.setAttribute("id", maskId);
9056 maskElement.appendChild(rect);
9057 this.layerElement.setAttribute("clip-path", "url(" + getLocationHref() + "#" + maskId + ")");
9058 defs.appendChild(maskElement);
9059 this.layers = animData.layers;
9060 this.elements = createSizedArray(animData.layers.length);
9061 };
9062 SVGRendererBase.prototype.destroy = function() {
9063 if (this.animationItem.wrapper) this.animationItem.wrapper.innerText = "";
9064 this.layerElement = null;
9065 this.globalData.defs = null;
9066 var i;
9067 var len = this.layers ? this.layers.length : 0;
9068 for (i = 0; i < len; i += 1) if (this.elements[i] && this.elements[i].destroy) this.elements[i].destroy();
9069 this.elements.length = 0;
9070 this.destroyed = true;
9071 this.animationItem = null;
9072 };
9073 SVGRendererBase.prototype.updateContainerSize = function() {};
9074 SVGRendererBase.prototype.findIndexByInd = function(ind) {
9075 var i = 0;
9076 var len = this.layers.length;
9077 for (i = 0; i < len; i += 1) if (this.layers[i].ind === ind) return i;
9078 return -1;
9079 };
9080 SVGRendererBase.prototype.buildItem = function(pos) {
9081 var elements = this.elements;
9082 if (elements[pos] || this.layers[pos].ty === 99) return;
9083 elements[pos] = true;
9084 var element = this.createItem(this.layers[pos]);
9085 elements[pos] = element;
9086 if (getExpressionsPlugin()) {
9087 if (this.layers[pos].ty === 0) this.globalData.projectInterface.registerComposition(element);
9088 element.initExpressions();
9089 }
9090 this.appendElementInPos(element, pos);
9091 if (this.layers[pos].tt) {
9092 var elementIndex = "tp" in this.layers[pos] ? this.findIndexByInd(this.layers[pos].tp) : pos - 1;
9093 if (elementIndex === -1) return;
9094 if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
9095 this.buildItem(elementIndex);
9096 this.addPendingElement(element);
9097 } else {
9098 var matteMask = elements[elementIndex].getMatte(this.layers[pos].tt);
9099 element.setMatte(matteMask);
9100 }
9101 }
9102 };
9103 SVGRendererBase.prototype.checkPendingElements = function() {
9104 while (this.pendingElements.length) {
9105 var element = this.pendingElements.pop();
9106 element.checkParenting();
9107 if (element.data.tt) {
9108 var i = 0;
9109 var len = this.elements.length;
9110 while (i < len) {
9111 if (this.elements[i] === element) {
9112 var elementIndex = "tp" in element.data ? this.findIndexByInd(element.data.tp) : i - 1;
9113 var matteMask = this.elements[elementIndex].getMatte(this.layers[i].tt);
9114 element.setMatte(matteMask);
9115 break;
9116 }
9117 i += 1;
9118 }
9119 }
9120 }
9121 };
9122 SVGRendererBase.prototype.renderFrame = function(num) {
9123 if (this.renderedFrame === num || this.destroyed) return;
9124 if (num === null) num = this.renderedFrame;
9125 else this.renderedFrame = num;
9126 this.globalData.frameNum = num;
9127 this.globalData.frameId += 1;
9128 this.globalData.projectInterface.currentFrame = num;
9129 this.globalData._mdf = false;
9130 var i;
9131 var len = this.layers.length;
9132 if (!this.completeLayers) this.checkLayers(num);
9133 for (i = len - 1; i >= 0; i -= 1) if (this.completeLayers || this.elements[i]) this.elements[i].prepareFrame(num - this.layers[i].st);
9134 if (this.globalData._mdf) {
9135 for (i = 0; i < len; i += 1) if (this.completeLayers || this.elements[i]) this.elements[i].renderFrame();
9136 }
9137 };
9138 SVGRendererBase.prototype.appendElementInPos = function(element, pos) {
9139 var newElement = element.getBaseElement();
9140 if (!newElement) return;
9141 var i = 0;
9142 var nextElement;
9143 while (i < pos) {
9144 if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) nextElement = this.elements[i].getBaseElement();
9145 i += 1;
9146 }
9147 if (nextElement) this.layerElement.insertBefore(newElement, nextElement);
9148 else this.layerElement.appendChild(newElement);
9149 };
9150 SVGRendererBase.prototype.hide = function() {
9151 this.layerElement.style.display = "none";
9152 };
9153 SVGRendererBase.prototype.show = function() {
9154 this.layerElement.style.display = "block";
9155 };
9156 function ICompElement() {}
9157 extendPrototype([
9158 BaseElement,
9159 TransformElement,
9160 HierarchyElement,
9161 FrameElement,
9162 RenderableDOMElement
9163 ], ICompElement);
9164 ICompElement.prototype.initElement = function(data, globalData, comp) {
9165 this.initFrame();
9166 this.initBaseData(data, globalData, comp);
9167 this.initTransform(data, globalData, comp);
9168 this.initRenderable();
9169 this.initHierarchy();
9170 this.initRendererElement();
9171 this.createContainerElements();
9172 this.createRenderableComponents();
9173 if (this.data.xt || !globalData.progressiveLoad) this.buildAllItems();
9174 this.hide();
9175 };
9176 ICompElement.prototype.prepareFrame = function(num) {
9177 this._mdf = false;
9178 this.prepareRenderableFrame(num);
9179 this.prepareProperties(num, this.isInRange);
9180 if (!this.isInRange && !this.data.xt) return;
9181 if (!this.tm._placeholder) {
9182 var timeRemapped = this.tm.v;
9183 if (timeRemapped === this.data.op) timeRemapped = this.data.op - 1;
9184 this.renderedFrame = timeRemapped;
9185 } else this.renderedFrame = num / this.data.sr;
9186 var i;
9187 var len = this.elements.length;
9188 if (!this.completeLayers) this.checkLayers(this.renderedFrame);
9189 for (i = len - 1; i >= 0; i -= 1) if (this.completeLayers || this.elements[i]) {
9190 this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
9191 if (this.elements[i]._mdf) this._mdf = true;
9192 }
9193 };
9194 ICompElement.prototype.renderInnerContent = function() {
9195 var i;
9196 var len = this.layers.length;
9197 for (i = 0; i < len; i += 1) if (this.completeLayers || this.elements[i]) this.elements[i].renderFrame();
9198 };
9199 ICompElement.prototype.setElements = function(elems) {
9200 this.elements = elems;
9201 };
9202 ICompElement.prototype.getElements = function() {
9203 return this.elements;
9204 };
9205 ICompElement.prototype.destroyElements = function() {
9206 var i;
9207 var len = this.layers.length;
9208 for (i = 0; i < len; i += 1) if (this.elements[i]) this.elements[i].destroy();
9209 };
9210 ICompElement.prototype.destroy = function() {
9211 this.destroyElements();
9212 this.destroyBaseElement();
9213 };
9214 function SVGCompElement(data, globalData, comp) {
9215 this.layers = data.layers;
9216 this.supports3d = true;
9217 this.completeLayers = false;
9218 this.pendingElements = [];
9219 this.elements = this.layers ? createSizedArray(this.layers.length) : [];
9220 this.initElement(data, globalData, comp);
9221 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
9222 }
9223 extendPrototype([
9224 SVGRendererBase,
9225 ICompElement,
9226 SVGBaseElement
9227 ], SVGCompElement);
9228 SVGCompElement.prototype.createComp = function(data) {
9229 return new SVGCompElement(data, this.globalData, this);
9230 };
9231 function SVGRenderer(animationItem, config) {
9232 this.animationItem = animationItem;
9233 this.layers = null;
9234 this.renderedFrame = -1;
9235 this.svgElement = createNS("svg");
9236 var ariaLabel = "";
9237 if (config && config.title) {
9238 var titleElement = createNS("title");
9239 var titleId = createElementID();
9240 titleElement.setAttribute("id", titleId);
9241 titleElement.textContent = config.title;
9242 this.svgElement.appendChild(titleElement);
9243 ariaLabel += titleId;
9244 }
9245 if (config && config.description) {
9246 var descElement = createNS("desc");
9247 var descId = createElementID();
9248 descElement.setAttribute("id", descId);
9249 descElement.textContent = config.description;
9250 this.svgElement.appendChild(descElement);
9251 ariaLabel += " " + descId;
9252 }
9253 if (ariaLabel) this.svgElement.setAttribute("aria-labelledby", ariaLabel);
9254 var defs = createNS("defs");
9255 this.svgElement.appendChild(defs);
9256 var maskElement = createNS("g");
9257 this.svgElement.appendChild(maskElement);
9258 this.layerElement = maskElement;
9259 this.renderConfig = {
9260 preserveAspectRatio: config && config.preserveAspectRatio || "xMidYMid meet",
9261 imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || "xMidYMid slice",
9262 contentVisibility: config && config.contentVisibility || "visible",
9263 progressiveLoad: config && config.progressiveLoad || false,
9264 hideOnTransparent: !(config && config.hideOnTransparent === false),
9265 viewBoxOnly: config && config.viewBoxOnly || false,
9266 viewBoxSize: config && config.viewBoxSize || false,
9267 className: config && config.className || "",
9268 id: config && config.id || "",
9269 focusable: config && config.focusable,
9270 filterSize: {
9271 width: config && config.filterSize && config.filterSize.width || "100%",
9272 height: config && config.filterSize && config.filterSize.height || "100%",
9273 x: config && config.filterSize && config.filterSize.x || "0%",
9274 y: config && config.filterSize && config.filterSize.y || "0%"
9275 },
9276 width: config && config.width,
9277 height: config && config.height,
9278 runExpressions: !config || config.runExpressions === void 0 || config.runExpressions
9279 };
9280 this.globalData = {
9281 _mdf: false,
9282 frameNum: -1,
9283 defs,
9284 renderConfig: this.renderConfig
9285 };
9286 this.elements = [];
9287 this.pendingElements = [];
9288 this.destroyed = false;
9289 this.rendererType = "svg";
9290 }
9291 extendPrototype([SVGRendererBase], SVGRenderer);
9292 SVGRenderer.prototype.createComp = function(data) {
9293 return new SVGCompElement(data, this.globalData, this);
9294 };
9295 function ShapeTransformManager() {
9296 this.sequences = {};
9297 this.sequenceList = [];
9298 this.transform_key_count = 0;
9299 }
9300 ShapeTransformManager.prototype = {
9301 addTransformSequence: function addTransformSequence(transforms) {
9302 var i;
9303 var len = transforms.length;
9304 var key = "_";
9305 for (i = 0; i < len; i += 1) key += transforms[i].transform.key + "_";
9306 var sequence = this.sequences[key];
9307 if (!sequence) {
9308 sequence = {
9309 transforms: [].concat(transforms),
9310 finalTransform: new Matrix(),
9311 _mdf: false
9312 };
9313 this.sequences[key] = sequence;
9314 this.sequenceList.push(sequence);
9315 }
9316 return sequence;
9317 },
9318 processSequence: function processSequence(sequence, isFirstFrame) {
9319 var i = 0;
9320 var len = sequence.transforms.length;
9321 var _mdf = isFirstFrame;
9322 while (i < len && !isFirstFrame) {
9323 if (sequence.transforms[i].transform.mProps._mdf) {
9324 _mdf = true;
9325 break;
9326 }
9327 i += 1;
9328 }
9329 if (_mdf) {
9330 sequence.finalTransform.reset();
9331 for (i = len - 1; i >= 0; i -= 1) sequence.finalTransform.multiply(sequence.transforms[i].transform.mProps.v);
9332 }
9333 sequence._mdf = _mdf;
9334 },
9335 processSequences: function processSequences(isFirstFrame) {
9336 var i;
9337 var len = this.sequenceList.length;
9338 for (i = 0; i < len; i += 1) this.processSequence(this.sequenceList[i], isFirstFrame);
9339 },
9340 getNewKey: function getNewKey() {
9341 this.transform_key_count += 1;
9342 return "_" + this.transform_key_count;
9343 }
9344 };
9345 var lumaLoader = function lumaLoader() {
9346 var id = "__lottie_element_luma_buffer";
9347 var lumaBuffer = null;
9348 var lumaBufferCtx = null;
9349 var svg = null;
9350 function createLumaSvgFilter() {
9351 var _svg = createNS("svg");
9352 var fil = createNS("filter");
9353 var matrix = createNS("feColorMatrix");
9354 fil.setAttribute("id", id);
9355 matrix.setAttribute("type", "matrix");
9356 matrix.setAttribute("color-interpolation-filters", "sRGB");
9357 matrix.setAttribute("values", "0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0");
9358 fil.appendChild(matrix);
9359 _svg.appendChild(fil);
9360 _svg.setAttribute("id", "__lottie_element_luma_buffer_svg");
9361 if (featureSupport.svgLumaHidden) _svg.style.display = "none";
9362 return _svg;
9363 }
9364 function loadLuma() {
9365 if (!lumaBuffer) {
9366 svg = createLumaSvgFilter();
9367 document.body.appendChild(svg);
9368 lumaBuffer = createTag("canvas");
9369 lumaBufferCtx = lumaBuffer.getContext("2d");
9370 lumaBufferCtx.filter = "url(#__lottie_element_luma_buffer)";
9371 lumaBufferCtx.fillStyle = "rgba(0,0,0,0)";
9372 lumaBufferCtx.fillRect(0, 0, 1, 1);
9373 }
9374 }
9375 function getLuma(canvas) {
9376 if (!lumaBuffer) loadLuma();
9377 lumaBuffer.width = canvas.width;
9378 lumaBuffer.height = canvas.height;
9379 lumaBufferCtx.filter = "url(#__lottie_element_luma_buffer)";
9380 return lumaBuffer;
9381 }
9382 return {
9383 load: loadLuma,
9384 get: getLuma
9385 };
9386 };
9387 function createCanvas(width, height) {
9388 if (featureSupport.offscreenCanvas) return new OffscreenCanvas(width, height);
9389 var canvas = createTag("canvas");
9390 canvas.width = width;
9391 canvas.height = height;
9392 return canvas;
9393 }
9394 var assetLoader = function() {
9395 return {
9396 loadLumaCanvas: lumaLoader.load,
9397 getLumaCanvas: lumaLoader.get,
9398 createCanvas
9399 };
9400 }();
9401 var registeredEffects = {};
9402 function CVEffects(elem) {
9403 var i;
9404 var len = elem.data.ef ? elem.data.ef.length : 0;
9405 this.filters = [];
9406 var filterManager;
9407 for (i = 0; i < len; i += 1) {
9408 filterManager = null;
9409 var type = elem.data.ef[i].ty;
9410 if (registeredEffects[type]) {
9411 var Effect = registeredEffects[type].effect;
9412 filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
9413 }
9414 if (filterManager) this.filters.push(filterManager);
9415 }
9416 if (this.filters.length) elem.addRenderableComponent(this);
9417 }
9418 CVEffects.prototype.renderFrame = function(_isFirstFrame) {
9419 var i;
9420 var len = this.filters.length;
9421 for (i = 0; i < len; i += 1) this.filters[i].renderFrame(_isFirstFrame);
9422 };
9423 CVEffects.prototype.getEffects = function(type) {
9424 var i;
9425 var len = this.filters.length;
9426 var effects = [];
9427 for (i = 0; i < len; i += 1) if (this.filters[i].type === type) effects.push(this.filters[i]);
9428 return effects;
9429 };
9430 function registerEffect(id, effect) {
9431 registeredEffects[id] = { effect };
9432 }
9433 function CVMaskElement(data, element) {
9434 this.data = data;
9435 this.element = element;
9436 this.masksProperties = this.data.masksProperties || [];
9437 this.viewData = createSizedArray(this.masksProperties.length);
9438 var i;
9439 var len = this.masksProperties.length;
9440 var hasMasks = false;
9441 for (i = 0; i < len; i += 1) {
9442 if (this.masksProperties[i].mode !== "n") hasMasks = true;
9443 this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3);
9444 }
9445 this.hasMasks = hasMasks;
9446 if (hasMasks) this.element.addRenderableComponent(this);
9447 }
9448 CVMaskElement.prototype.renderFrame = function() {
9449 if (!this.hasMasks) return;
9450 var transform = this.element.finalTransform.mat;
9451 var ctx = this.element.canvasContext;
9452 var i;
9453 var len = this.masksProperties.length;
9454 var pt;
9455 var pts;
9456 var data;
9457 ctx.beginPath();
9458 for (i = 0; i < len; i += 1) if (this.masksProperties[i].mode !== "n") {
9459 if (this.masksProperties[i].inv) {
9460 ctx.moveTo(0, 0);
9461 ctx.lineTo(this.element.globalData.compSize.w, 0);
9462 ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
9463 ctx.lineTo(0, this.element.globalData.compSize.h);
9464 ctx.lineTo(0, 0);
9465 }
9466 data = this.viewData[i].v;
9467 pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0);
9468 ctx.moveTo(pt[0], pt[1]);
9469 var j;
9470 var jLen = data._length;
9471 for (j = 1; j < jLen; j += 1) {
9472 pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
9473 ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
9474 }
9475 pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
9476 ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
9477 }
9478 this.element.globalData.renderer.save(true);
9479 ctx.clip();
9480 };
9481 CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
9482 CVMaskElement.prototype.destroy = function() {
9483 this.element = null;
9484 };
9485 function CVBaseElement() {}
9486 var operationsMap = {
9487 1: "source-in",
9488 2: "source-out",
9489 3: "source-in",
9490 4: "source-out"
9491 };
9492 CVBaseElement.prototype = {
9493 createElements: function createElements() {},
9494 initRendererElement: function initRendererElement() {},
9495 createContainerElements: function createContainerElements() {
9496 if (this.data.tt >= 1) {
9497 this.buffers = [];
9498 var canvasContext = this.globalData.canvasContext;
9499 var bufferCanvas = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
9500 this.buffers.push(bufferCanvas);
9501 var bufferCanvas2 = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
9502 this.buffers.push(bufferCanvas2);
9503 if (this.data.tt >= 3 && !document._isProxy) assetLoader.loadLumaCanvas();
9504 }
9505 this.canvasContext = this.globalData.canvasContext;
9506 this.transformCanvas = this.globalData.transformCanvas;
9507 this.renderableEffectsManager = new CVEffects(this);
9508 this.searchEffectTransforms();
9509 },
9510 createContent: function createContent() {},
9511 setBlendMode: function setBlendMode() {
9512 var globalData = this.globalData;
9513 if (globalData.blendMode !== this.data.bm) {
9514 globalData.blendMode = this.data.bm;
9515 var blendModeValue = getBlendMode(this.data.bm);
9516 globalData.canvasContext.globalCompositeOperation = blendModeValue;
9517 }
9518 },
9519 createRenderableComponents: function createRenderableComponents() {
9520 this.maskManager = new CVMaskElement(this.data, this);
9521 this.transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
9522 },
9523 hideElement: function hideElement() {
9524 if (!this.hidden && (!this.isInRange || this.isTransparent)) this.hidden = true;
9525 },
9526 showElement: function showElement() {
9527 if (this.isInRange && !this.isTransparent) {
9528 this.hidden = false;
9529 this._isFirstFrame = true;
9530 this.maskManager._isFirstFrame = true;
9531 }
9532 },
9533 clearCanvas: function clearCanvas(canvasContext) {
9534 canvasContext.clearRect(this.transformCanvas.tx, this.transformCanvas.ty, this.transformCanvas.w * this.transformCanvas.sx, this.transformCanvas.h * this.transformCanvas.sy);
9535 },
9536 prepareLayer: function prepareLayer() {
9537 if (this.data.tt >= 1) {
9538 var bufferCtx = this.buffers[0].getContext("2d");
9539 this.clearCanvas(bufferCtx);
9540 bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
9541 this.currentTransform = this.canvasContext.getTransform();
9542 this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
9543 this.clearCanvas(this.canvasContext);
9544 this.canvasContext.setTransform(this.currentTransform);
9545 }
9546 },
9547 exitLayer: function exitLayer() {
9548 if (this.data.tt >= 1) {
9549 var buffer = this.buffers[1];
9550 var bufferCtx = buffer.getContext("2d");
9551 this.clearCanvas(bufferCtx);
9552 bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
9553 this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
9554 this.clearCanvas(this.canvasContext);
9555 this.canvasContext.setTransform(this.currentTransform);
9556 this.comp.getElementById("tp" in this.data ? this.data.tp : this.data.ind - 1).renderFrame(true);
9557 this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
9558 if (this.data.tt >= 3 && !document._isProxy) {
9559 var lumaBuffer = assetLoader.getLumaCanvas(this.canvasContext.canvas);
9560 lumaBuffer.getContext("2d").drawImage(this.canvasContext.canvas, 0, 0);
9561 this.clearCanvas(this.canvasContext);
9562 this.canvasContext.drawImage(lumaBuffer, 0, 0);
9563 }
9564 this.canvasContext.globalCompositeOperation = operationsMap[this.data.tt];
9565 this.canvasContext.drawImage(buffer, 0, 0);
9566 this.canvasContext.globalCompositeOperation = "destination-over";
9567 this.canvasContext.drawImage(this.buffers[0], 0, 0);
9568 this.canvasContext.setTransform(this.currentTransform);
9569 this.canvasContext.globalCompositeOperation = "source-over";
9570 }
9571 },
9572 renderFrame: function renderFrame(forceRender) {
9573 if (this.hidden || this.data.hd) return;
9574 if (this.data.td === 1 && !forceRender) return;
9575 this.renderTransform();
9576 this.renderRenderable();
9577 this.renderLocalTransform();
9578 this.setBlendMode();
9579 var forceRealStack = this.data.ty === 0;
9580 this.prepareLayer();
9581 this.globalData.renderer.save(forceRealStack);
9582 this.globalData.renderer.ctxTransform(this.finalTransform.localMat.props);
9583 this.globalData.renderer.ctxOpacity(this.finalTransform.localOpacity);
9584 this.renderInnerContent();
9585 this.globalData.renderer.restore(forceRealStack);
9586 this.exitLayer();
9587 if (this.maskManager.hasMasks) this.globalData.renderer.restore(true);
9588 if (this._isFirstFrame) this._isFirstFrame = false;
9589 },
9590 destroy: function destroy() {
9591 this.canvasContext = null;
9592 this.data = null;
9593 this.globalData = null;
9594 this.maskManager.destroy();
9595 },
9596 mHelper: new Matrix()
9597 };
9598 CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
9599 CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
9600 function CVShapeData(element, data, styles, transformsManager) {
9601 this.styledShapes = [];
9602 this.tr = [
9603 0,
9604 0,
9605 0,
9606 0,
9607 0,
9608 0
9609 ];
9610 var ty = 4;
9611 if (data.ty === "rc") ty = 5;
9612 else if (data.ty === "el") ty = 6;
9613 else if (data.ty === "sr") ty = 7;
9614 this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element);
9615 var i;
9616 var len = styles.length;
9617 var styledShape;
9618 for (i = 0; i < len; i += 1) if (!styles[i].closed) {
9619 styledShape = {
9620 transforms: transformsManager.addTransformSequence(styles[i].transforms),
9621 trNodes: []
9622 };
9623 this.styledShapes.push(styledShape);
9624 styles[i].elements.push(styledShape);
9625 }
9626 }
9627 CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
9628 function CVShapeElement(data, globalData, comp) {
9629 this.shapes = [];
9630 this.shapesData = data.shapes;
9631 this.stylesList = [];
9632 this.itemsData = [];
9633 this.prevViewData = [];
9634 this.shapeModifiers = [];
9635 this.processedElements = [];
9636 this.transformsManager = new ShapeTransformManager();
9637 this.initElement(data, globalData, comp);
9638 }
9639 extendPrototype([
9640 BaseElement,
9641 TransformElement,
9642 CVBaseElement,
9643 IShapeElement,
9644 HierarchyElement,
9645 FrameElement,
9646 RenderableElement
9647 ], CVShapeElement);
9648 CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
9649 CVShapeElement.prototype.transformHelper = {
9650 opacity: 1,
9651 _opMdf: false
9652 };
9653 CVShapeElement.prototype.dashResetter = [];
9654 CVShapeElement.prototype.createContent = function() {
9655 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
9656 };
9657 CVShapeElement.prototype.createStyleElement = function(data, transforms) {
9658 var styleElem = {
9659 data,
9660 type: data.ty,
9661 preTransforms: this.transformsManager.addTransformSequence(transforms),
9662 transforms: [],
9663 elements: [],
9664 closed: data.hd === true
9665 };
9666 var elementData = {};
9667 if (data.ty === "fl" || data.ty === "st") {
9668 elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this);
9669 if (!elementData.c.k) styleElem.co = "rgb(" + bmFloor(elementData.c.v[0]) + "," + bmFloor(elementData.c.v[1]) + "," + bmFloor(elementData.c.v[2]) + ")";
9670 } else if (data.ty === "gf" || data.ty === "gs") {
9671 elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this);
9672 elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this);
9673 elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, .01, this);
9674 elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this);
9675 elementData.g = new GradientProperty(this, data.g, this);
9676 }
9677 elementData.o = PropertyFactory.getProp(this, data.o, 0, .01, this);
9678 if (data.ty === "st" || data.ty === "gs") {
9679 styleElem.lc = lineCapEnum[data.lc || 2];
9680 styleElem.lj = lineJoinEnum[data.lj || 2];
9681 if (data.lj == 1) styleElem.ml = data.ml;
9682 elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this);
9683 if (!elementData.w.k) styleElem.wi = elementData.w.v;
9684 if (data.d) {
9685 elementData.d = new DashProperty(this, data.d, "canvas", this);
9686 if (!elementData.d.k) {
9687 styleElem.da = elementData.d.dashArray;
9688 styleElem["do"] = elementData.d.dashoffset[0];
9689 }
9690 }
9691 } else styleElem.r = data.r === 2 ? "evenodd" : "nonzero";
9692 this.stylesList.push(styleElem);
9693 elementData.style = styleElem;
9694 return elementData;
9695 };
9696 CVShapeElement.prototype.createGroupElement = function() {
9697 return {
9698 it: [],
9699 prevViewData: []
9700 };
9701 };
9702 CVShapeElement.prototype.createTransformElement = function(data) {
9703 return { transform: {
9704 opacity: 1,
9705 _opMdf: false,
9706 key: this.transformsManager.getNewKey(),
9707 op: PropertyFactory.getProp(this, data.o, 0, .01, this),
9708 mProps: TransformPropertyFactory.getTransformProperty(this, data, this)
9709 } };
9710 };
9711 CVShapeElement.prototype.createShapeElement = function(data) {
9712 var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
9713 this.shapes.push(elementData);
9714 this.addShapeToModifiers(elementData);
9715 return elementData;
9716 };
9717 CVShapeElement.prototype.reloadShapes = function() {
9718 this._isFirstFrame = true;
9719 var i;
9720 var len = this.itemsData.length;
9721 for (i = 0; i < len; i += 1) this.prevViewData[i] = this.itemsData[i];
9722 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
9723 len = this.dynamicProperties.length;
9724 for (i = 0; i < len; i += 1) this.dynamicProperties[i].getValue();
9725 this.renderModifiers();
9726 this.transformsManager.processSequences(this._isFirstFrame);
9727 };
9728 CVShapeElement.prototype.addTransformToStyleList = function(transform) {
9729 var i;
9730 var len = this.stylesList.length;
9731 for (i = 0; i < len; i += 1) if (!this.stylesList[i].closed) this.stylesList[i].transforms.push(transform);
9732 };
9733 CVShapeElement.prototype.removeTransformFromStyleList = function() {
9734 var i;
9735 var len = this.stylesList.length;
9736 for (i = 0; i < len; i += 1) if (!this.stylesList[i].closed) this.stylesList[i].transforms.pop();
9737 };
9738 CVShapeElement.prototype.closeStyles = function(styles) {
9739 var i;
9740 var len = styles.length;
9741 for (i = 0; i < len; i += 1) styles[i].closed = true;
9742 };
9743 CVShapeElement.prototype.searchShapes = function(arr, itemsData, prevViewData, shouldRender, transforms) {
9744 var i;
9745 var len = arr.length - 1;
9746 var j;
9747 var jLen;
9748 var ownStyles = [];
9749 var ownModifiers = [];
9750 var processedPos;
9751 var modifier;
9752 var currentTransform;
9753 var ownTransforms = [].concat(transforms);
9754 for (i = len; i >= 0; i -= 1) {
9755 processedPos = this.searchProcessedElement(arr[i]);
9756 if (!processedPos) arr[i]._shouldRender = shouldRender;
9757 else itemsData[i] = prevViewData[processedPos - 1];
9758 if (arr[i].ty === "fl" || arr[i].ty === "st" || arr[i].ty === "gf" || arr[i].ty === "gs") {
9759 if (!processedPos) itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
9760 else itemsData[i].style.closed = false;
9761 ownStyles.push(itemsData[i].style);
9762 } else if (arr[i].ty === "gr") {
9763 if (!processedPos) itemsData[i] = this.createGroupElement(arr[i]);
9764 else {
9765 jLen = itemsData[i].it.length;
9766 for (j = 0; j < jLen; j += 1) itemsData[i].prevViewData[j] = itemsData[i].it[j];
9767 }
9768 this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms);
9769 } else if (arr[i].ty === "tr") {
9770 if (!processedPos) {
9771 currentTransform = this.createTransformElement(arr[i]);
9772 itemsData[i] = currentTransform;
9773 }
9774 ownTransforms.push(itemsData[i]);
9775 this.addTransformToStyleList(itemsData[i]);
9776 } else if (arr[i].ty === "sh" || arr[i].ty === "rc" || arr[i].ty === "el" || arr[i].ty === "sr") {
9777 if (!processedPos) itemsData[i] = this.createShapeElement(arr[i]);
9778 } else if (arr[i].ty === "tm" || arr[i].ty === "rd" || arr[i].ty === "pb" || arr[i].ty === "zz" || arr[i].ty === "op") {
9779 if (!processedPos) {
9780 modifier = ShapeModifiers.getModifier(arr[i].ty);
9781 modifier.init(this, arr[i]);
9782 itemsData[i] = modifier;
9783 this.shapeModifiers.push(modifier);
9784 } else {
9785 modifier = itemsData[i];
9786 modifier.closed = false;
9787 }
9788 ownModifiers.push(modifier);
9789 } else if (arr[i].ty === "rp") {
9790 if (!processedPos) {
9791 modifier = ShapeModifiers.getModifier(arr[i].ty);
9792 itemsData[i] = modifier;
9793 modifier.init(this, arr, i, itemsData);
9794 this.shapeModifiers.push(modifier);
9795 shouldRender = false;
9796 } else {
9797 modifier = itemsData[i];
9798 modifier.closed = true;
9799 }
9800 ownModifiers.push(modifier);
9801 }
9802 this.addProcessedElement(arr[i], i + 1);
9803 }
9804 this.removeTransformFromStyleList();
9805 this.closeStyles(ownStyles);
9806 len = ownModifiers.length;
9807 for (i = 0; i < len; i += 1) ownModifiers[i].closed = true;
9808 };
9809 CVShapeElement.prototype.renderInnerContent = function() {
9810 this.transformHelper.opacity = 1;
9811 this.transformHelper._opMdf = false;
9812 this.renderModifiers();
9813 this.transformsManager.processSequences(this._isFirstFrame);
9814 this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true);
9815 };
9816 CVShapeElement.prototype.renderShapeTransform = function(parentTransform, groupTransform) {
9817 if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
9818 groupTransform.opacity = parentTransform.opacity;
9819 groupTransform.opacity *= groupTransform.op.v;
9820 groupTransform._opMdf = true;
9821 }
9822 };
9823 CVShapeElement.prototype.drawLayer = function() {
9824 var i;
9825 var len = this.stylesList.length;
9826 var j;
9827 var jLen;
9828 var k;
9829 var kLen;
9830 var elems;
9831 var nodes;
9832 var renderer = this.globalData.renderer;
9833 var ctx = this.globalData.canvasContext;
9834 var type;
9835 var currentStyle;
9836 for (i = 0; i < len; i += 1) {
9837 currentStyle = this.stylesList[i];
9838 type = currentStyle.type;
9839 if (!((type === "st" || type === "gs") && currentStyle.wi === 0 || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) {
9840 renderer.save();
9841 elems = currentStyle.elements;
9842 if (type === "st" || type === "gs") {
9843 renderer.ctxStrokeStyle(type === "st" ? currentStyle.co : currentStyle.grd);
9844 renderer.ctxLineWidth(currentStyle.wi);
9845 renderer.ctxLineCap(currentStyle.lc);
9846 renderer.ctxLineJoin(currentStyle.lj);
9847 renderer.ctxMiterLimit(currentStyle.ml || 0);
9848 } else renderer.ctxFillStyle(type === "fl" ? currentStyle.co : currentStyle.grd);
9849 renderer.ctxOpacity(currentStyle.coOp);
9850 if (type !== "st" && type !== "gs") ctx.beginPath();
9851 renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
9852 jLen = elems.length;
9853 for (j = 0; j < jLen; j += 1) {
9854 if (type === "st" || type === "gs") {
9855 ctx.beginPath();
9856 if (currentStyle.da) {
9857 ctx.setLineDash(currentStyle.da);
9858 ctx.lineDashOffset = currentStyle["do"];
9859 }
9860 }
9861 nodes = elems[j].trNodes;
9862 kLen = nodes.length;
9863 for (k = 0; k < kLen; k += 1) if (nodes[k].t === "m") ctx.moveTo(nodes[k].p[0], nodes[k].p[1]);
9864 else if (nodes[k].t === "c") ctx.bezierCurveTo(nodes[k].pts[0], nodes[k].pts[1], nodes[k].pts[2], nodes[k].pts[3], nodes[k].pts[4], nodes[k].pts[5]);
9865 else ctx.closePath();
9866 if (type === "st" || type === "gs") {
9867 renderer.ctxStroke();
9868 if (currentStyle.da) ctx.setLineDash(this.dashResetter);
9869 }
9870 }
9871 if (type !== "st" && type !== "gs") this.globalData.renderer.ctxFill(currentStyle.r);
9872 renderer.restore();
9873 }
9874 }
9875 };
9876 CVShapeElement.prototype.renderShape = function(parentTransform, items, data, isMain) {
9877 var i;
9878 var len = items.length - 1;
9879 var groupTransform = parentTransform;
9880 for (i = len; i >= 0; i -= 1) if (items[i].ty === "tr") {
9881 groupTransform = data[i].transform;
9882 this.renderShapeTransform(parentTransform, groupTransform);
9883 } else if (items[i].ty === "sh" || items[i].ty === "el" || items[i].ty === "rc" || items[i].ty === "sr") this.renderPath(items[i], data[i]);
9884 else if (items[i].ty === "fl") this.renderFill(items[i], data[i], groupTransform);
9885 else if (items[i].ty === "st") this.renderStroke(items[i], data[i], groupTransform);
9886 else if (items[i].ty === "gf" || items[i].ty === "gs") this.renderGradientFill(items[i], data[i], groupTransform);
9887 else if (items[i].ty === "gr") this.renderShape(groupTransform, items[i].it, data[i].it);
9888 else if (items[i].ty === "tm") {}
9889 if (isMain) this.drawLayer();
9890 };
9891 CVShapeElement.prototype.renderStyledShape = function(styledShape, shape) {
9892 if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
9893 var shapeNodes = styledShape.trNodes;
9894 var paths = shape.paths;
9895 var i;
9896 var len;
9897 var j;
9898 var jLen = paths._length;
9899 shapeNodes.length = 0;
9900 var groupTransformMat = styledShape.transforms.finalTransform;
9901 for (j = 0; j < jLen; j += 1) {
9902 var pathNodes = paths.shapes[j];
9903 if (pathNodes && pathNodes.v) {
9904 len = pathNodes._length;
9905 for (i = 1; i < len; i += 1) {
9906 if (i === 1) shapeNodes.push({
9907 t: "m",
9908 p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
9909 });
9910 shapeNodes.push({
9911 t: "c",
9912 pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i])
9913 });
9914 }
9915 if (len === 1) shapeNodes.push({
9916 t: "m",
9917 p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
9918 });
9919 if (pathNodes.c && len) {
9920 shapeNodes.push({
9921 t: "c",
9922 pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0])
9923 });
9924 shapeNodes.push({ t: "z" });
9925 }
9926 }
9927 }
9928 styledShape.trNodes = shapeNodes;
9929 }
9930 };
9931 CVShapeElement.prototype.renderPath = function(pathData, itemData) {
9932 if (pathData.hd !== true && pathData._shouldRender) {
9933 var i;
9934 var len = itemData.styledShapes.length;
9935 for (i = 0; i < len; i += 1) this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
9936 }
9937 };
9938 CVShapeElement.prototype.renderFill = function(styleData, itemData, groupTransform) {
9939 var styleElem = itemData.style;
9940 if (itemData.c._mdf || this._isFirstFrame) styleElem.co = "rgb(" + bmFloor(itemData.c.v[0]) + "," + bmFloor(itemData.c.v[1]) + "," + bmFloor(itemData.c.v[2]) + ")";
9941 if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) styleElem.coOp = itemData.o.v * groupTransform.opacity;
9942 };
9943 CVShapeElement.prototype.renderGradientFill = function(styleData, itemData, groupTransform) {
9944 var styleElem = itemData.style;
9945 var grd;
9946 if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf)) {
9947 var ctx = this.globalData.canvasContext;
9948 var pt1 = itemData.s.v;
9949 var pt2 = itemData.e.v;
9950 if (styleData.t === 1) grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
9951 else {
9952 var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
9953 var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
9954 var percent = itemData.h.v;
9955 if (percent >= 1) percent = .99;
9956 else if (percent <= -1) percent = -.99;
9957 var dist = rad * percent;
9958 var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
9959 var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
9960 grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
9961 }
9962 var i;
9963 var len = styleData.g.p;
9964 var cValues = itemData.g.c;
9965 var opacity = 1;
9966 for (i = 0; i < len; i += 1) {
9967 if (itemData.g._hasOpacity && itemData.g._collapsable) opacity = itemData.g.o[i * 2 + 1];
9968 grd.addColorStop(cValues[i * 4] / 100, "rgba(" + cValues[i * 4 + 1] + "," + cValues[i * 4 + 2] + "," + cValues[i * 4 + 3] + "," + opacity + ")");
9969 }
9970 styleElem.grd = grd;
9971 }
9972 styleElem.coOp = itemData.o.v * groupTransform.opacity;
9973 };
9974 CVShapeElement.prototype.renderStroke = function(styleData, itemData, groupTransform) {
9975 var styleElem = itemData.style;
9976 var d = itemData.d;
9977 if (d && (d._mdf || this._isFirstFrame)) {
9978 styleElem.da = d.dashArray;
9979 styleElem["do"] = d.dashoffset[0];
9980 }
9981 if (itemData.c._mdf || this._isFirstFrame) styleElem.co = "rgb(" + bmFloor(itemData.c.v[0]) + "," + bmFloor(itemData.c.v[1]) + "," + bmFloor(itemData.c.v[2]) + ")";
9982 if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) styleElem.coOp = itemData.o.v * groupTransform.opacity;
9983 if (itemData.w._mdf || this._isFirstFrame) styleElem.wi = itemData.w.v;
9984 };
9985 CVShapeElement.prototype.destroy = function() {
9986 this.shapesData = null;
9987 this.globalData = null;
9988 this.canvasContext = null;
9989 this.stylesList.length = 0;
9990 this.itemsData.length = 0;
9991 };
9992 function CVTextElement(data, globalData, comp) {
9993 this.textSpans = [];
9994 this.yOffset = 0;
9995 this.fillColorAnim = false;
9996 this.strokeColorAnim = false;
9997 this.strokeWidthAnim = false;
9998 this.stroke = false;
9999 this.fill = false;
10000 this.justifyOffset = 0;
10001 this.currentRender = null;
10002 this.renderType = "canvas";
10003 this.values = {
10004 fill: "rgba(0,0,0,0)",
10005 stroke: "rgba(0,0,0,0)",
10006 sWidth: 0,
10007 fValue: ""
10008 };
10009 this.initElement(data, globalData, comp);
10010 }
10011 extendPrototype([
10012 BaseElement,
10013 TransformElement,
10014 CVBaseElement,
10015 HierarchyElement,
10016 FrameElement,
10017 RenderableElement,
10018 ITextElement
10019 ], CVTextElement);
10020 CVTextElement.prototype.tHelper = createTag("canvas").getContext("2d");
10021 CVTextElement.prototype.buildNewText = function() {
10022 var documentData = this.textProperty.currentData;
10023 this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
10024 var hasFill = false;
10025 if (documentData.fc) {
10026 hasFill = true;
10027 this.values.fill = this.buildColor(documentData.fc);
10028 } else this.values.fill = "rgba(0,0,0,0)";
10029 this.fill = hasFill;
10030 var hasStroke = false;
10031 if (documentData.sc) {
10032 hasStroke = true;
10033 this.values.stroke = this.buildColor(documentData.sc);
10034 this.values.sWidth = documentData.sw;
10035 }
10036 var fontData = this.globalData.fontManager.getFontByName(documentData.f);
10037 var i;
10038 var len;
10039 var letters = documentData.l;
10040 var matrixHelper = this.mHelper;
10041 this.stroke = hasStroke;
10042 this.values.fValue = documentData.finalSize + "px " + this.globalData.fontManager.getFontByName(documentData.f).fFamily;
10043 len = documentData.finalText.length;
10044 var charData;
10045 var shapeData;
10046 var k;
10047 var kLen;
10048 var shapes;
10049 var j;
10050 var jLen;
10051 var pathNodes;
10052 var commands;
10053 var pathArr;
10054 var singleShape = this.data.singleShape;
10055 var trackingOffset = documentData.tr * .001 * documentData.finalSize;
10056 var xPos = 0;
10057 var yPos = 0;
10058 var firstLine = true;
10059 var cnt = 0;
10060 for (i = 0; i < len; i += 1) {
10061 charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
10062 shapeData = charData && charData.data || {};
10063 matrixHelper.reset();
10064 if (singleShape && letters[i].n) {
10065 xPos = -trackingOffset;
10066 yPos += documentData.yOffset;
10067 yPos += firstLine ? 1 : 0;
10068 firstLine = false;
10069 }
10070 shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
10071 jLen = shapes.length;
10072 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
10073 if (singleShape) this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
10074 commands = createSizedArray(jLen - 1);
10075 var commandsCounter = 0;
10076 for (j = 0; j < jLen; j += 1) if (shapes[j].ty === "sh") {
10077 kLen = shapes[j].ks.k.i.length;
10078 pathNodes = shapes[j].ks.k;
10079 pathArr = [];
10080 for (k = 1; k < kLen; k += 1) {
10081 if (k === 1) pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
10082 pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToY(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToX(pathNodes.v[k][0], pathNodes.v[k][1], 0), matrixHelper.applyToY(pathNodes.v[k][0], pathNodes.v[k][1], 0));
10083 }
10084 pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToY(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
10085 commands[commandsCounter] = pathArr;
10086 commandsCounter += 1;
10087 }
10088 if (singleShape) {
10089 xPos += letters[i].l;
10090 xPos += trackingOffset;
10091 }
10092 if (this.textSpans[cnt]) this.textSpans[cnt].elem = commands;
10093 else this.textSpans[cnt] = { elem: commands };
10094 cnt += 1;
10095 }
10096 };
10097 CVTextElement.prototype.renderInnerContent = function() {
10098 this.validateText();
10099 var ctx = this.canvasContext;
10100 ctx.font = this.values.fValue;
10101 this.globalData.renderer.ctxLineCap("butt");
10102 this.globalData.renderer.ctxLineJoin("miter");
10103 this.globalData.renderer.ctxMiterLimit(4);
10104 if (!this.data.singleShape) this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
10105 var i;
10106 var len;
10107 var j;
10108 var jLen;
10109 var k;
10110 var kLen;
10111 var renderedLetters = this.textAnimator.renderedLetters;
10112 var letters = this.textProperty.currentData.l;
10113 len = letters.length;
10114 var renderedLetter;
10115 var lastFill = null;
10116 var lastStroke = null;
10117 var lastStrokeW = null;
10118 var commands;
10119 var pathArr;
10120 var renderer = this.globalData.renderer;
10121 for (i = 0; i < len; i += 1) if (!letters[i].n) {
10122 renderedLetter = renderedLetters[i];
10123 if (renderedLetter) {
10124 renderer.save();
10125 renderer.ctxTransform(renderedLetter.p);
10126 renderer.ctxOpacity(renderedLetter.o);
10127 }
10128 if (this.fill) {
10129 if (renderedLetter && renderedLetter.fc) {
10130 if (lastFill !== renderedLetter.fc) {
10131 renderer.ctxFillStyle(renderedLetter.fc);
10132 lastFill = renderedLetter.fc;
10133 }
10134 } else if (lastFill !== this.values.fill) {
10135 lastFill = this.values.fill;
10136 renderer.ctxFillStyle(this.values.fill);
10137 }
10138 commands = this.textSpans[i].elem;
10139 jLen = commands.length;
10140 this.globalData.canvasContext.beginPath();
10141 for (j = 0; j < jLen; j += 1) {
10142 pathArr = commands[j];
10143 kLen = pathArr.length;
10144 this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
10145 for (k = 2; k < kLen; k += 6) this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
10146 }
10147 this.globalData.canvasContext.closePath();
10148 renderer.ctxFill();
10149 }
10150 if (this.stroke) {
10151 if (renderedLetter && renderedLetter.sw) {
10152 if (lastStrokeW !== renderedLetter.sw) {
10153 lastStrokeW = renderedLetter.sw;
10154 renderer.ctxLineWidth(renderedLetter.sw);
10155 }
10156 } else if (lastStrokeW !== this.values.sWidth) {
10157 lastStrokeW = this.values.sWidth;
10158 renderer.ctxLineWidth(this.values.sWidth);
10159 }
10160 if (renderedLetter && renderedLetter.sc) {
10161 if (lastStroke !== renderedLetter.sc) {
10162 lastStroke = renderedLetter.sc;
10163 renderer.ctxStrokeStyle(renderedLetter.sc);
10164 }
10165 } else if (lastStroke !== this.values.stroke) {
10166 lastStroke = this.values.stroke;
10167 renderer.ctxStrokeStyle(this.values.stroke);
10168 }
10169 commands = this.textSpans[i].elem;
10170 jLen = commands.length;
10171 this.globalData.canvasContext.beginPath();
10172 for (j = 0; j < jLen; j += 1) {
10173 pathArr = commands[j];
10174 kLen = pathArr.length;
10175 this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
10176 for (k = 2; k < kLen; k += 6) this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
10177 }
10178 this.globalData.canvasContext.closePath();
10179 renderer.ctxStroke();
10180 }
10181 if (renderedLetter) this.globalData.renderer.restore();
10182 }
10183 };
10184 function CVImageElement(data, globalData, comp) {
10185 this.assetData = globalData.getAssetData(data.refId);
10186 this.img = globalData.imageLoader.getAsset(this.assetData);
10187 this.initElement(data, globalData, comp);
10188 }
10189 extendPrototype([
10190 BaseElement,
10191 TransformElement,
10192 CVBaseElement,
10193 HierarchyElement,
10194 FrameElement,
10195 RenderableElement
10196 ], CVImageElement);
10197 CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
10198 CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
10199 CVImageElement.prototype.createContent = function() {
10200 if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
10201 var canvas = createTag("canvas");
10202 canvas.width = this.assetData.w;
10203 canvas.height = this.assetData.h;
10204 var ctx = canvas.getContext("2d");
10205 var imgW = this.img.width;
10206 var imgH = this.img.height;
10207 var imgRel = imgW / imgH;
10208 var canvasRel = this.assetData.w / this.assetData.h;
10209 var widthCrop;
10210 var heightCrop;
10211 var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
10212 if (imgRel > canvasRel && par === "xMidYMid slice" || imgRel < canvasRel && par !== "xMidYMid slice") {
10213 heightCrop = imgH;
10214 widthCrop = heightCrop * canvasRel;
10215 } else {
10216 widthCrop = imgW;
10217 heightCrop = widthCrop / canvasRel;
10218 }
10219 ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
10220 this.img = canvas;
10221 }
10222 };
10223 CVImageElement.prototype.renderInnerContent = function() {
10224 this.canvasContext.drawImage(this.img, 0, 0);
10225 };
10226 CVImageElement.prototype.destroy = function() {
10227 this.img = null;
10228 };
10229 function CVSolidElement(data, globalData, comp) {
10230 this.initElement(data, globalData, comp);
10231 }
10232 extendPrototype([
10233 BaseElement,
10234 TransformElement,
10235 CVBaseElement,
10236 HierarchyElement,
10237 FrameElement,
10238 RenderableElement
10239 ], CVSolidElement);
10240 CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
10241 CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
10242 CVSolidElement.prototype.renderInnerContent = function() {
10243 this.globalData.renderer.ctxFillStyle(this.data.sc);
10244 this.globalData.renderer.ctxFillRect(0, 0, this.data.sw, this.data.sh);
10245 };
10246 function CanvasRendererBase() {}
10247 extendPrototype([BaseRenderer], CanvasRendererBase);
10248 CanvasRendererBase.prototype.createShape = function(data) {
10249 return new CVShapeElement(data, this.globalData, this);
10250 };
10251 CanvasRendererBase.prototype.createText = function(data) {
10252 return new CVTextElement(data, this.globalData, this);
10253 };
10254 CanvasRendererBase.prototype.createImage = function(data) {
10255 return new CVImageElement(data, this.globalData, this);
10256 };
10257 CanvasRendererBase.prototype.createSolid = function(data) {
10258 return new CVSolidElement(data, this.globalData, this);
10259 };
10260 CanvasRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
10261 CanvasRendererBase.prototype.ctxTransform = function(props) {
10262 if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) return;
10263 this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]);
10264 };
10265 CanvasRendererBase.prototype.ctxOpacity = function(op) {
10266 this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
10267 };
10268 CanvasRendererBase.prototype.ctxFillStyle = function(value) {
10269 this.canvasContext.fillStyle = value;
10270 };
10271 CanvasRendererBase.prototype.ctxStrokeStyle = function(value) {
10272 this.canvasContext.strokeStyle = value;
10273 };
10274 CanvasRendererBase.prototype.ctxLineWidth = function(value) {
10275 this.canvasContext.lineWidth = value;
10276 };
10277 CanvasRendererBase.prototype.ctxLineCap = function(value) {
10278 this.canvasContext.lineCap = value;
10279 };
10280 CanvasRendererBase.prototype.ctxLineJoin = function(value) {
10281 this.canvasContext.lineJoin = value;
10282 };
10283 CanvasRendererBase.prototype.ctxMiterLimit = function(value) {
10284 this.canvasContext.miterLimit = value;
10285 };
10286 CanvasRendererBase.prototype.ctxFill = function(rule) {
10287 this.canvasContext.fill(rule);
10288 };
10289 CanvasRendererBase.prototype.ctxFillRect = function(x, y, w, h) {
10290 this.canvasContext.fillRect(x, y, w, h);
10291 };
10292 CanvasRendererBase.prototype.ctxStroke = function() {
10293 this.canvasContext.stroke();
10294 };
10295 CanvasRendererBase.prototype.reset = function() {
10296 if (!this.renderConfig.clearCanvas) {
10297 this.canvasContext.restore();
10298 return;
10299 }
10300 this.contextData.reset();
10301 };
10302 CanvasRendererBase.prototype.save = function() {
10303 this.canvasContext.save();
10304 };
10305 CanvasRendererBase.prototype.restore = function(actionFlag) {
10306 if (!this.renderConfig.clearCanvas) {
10307 this.canvasContext.restore();
10308 return;
10309 }
10310 if (actionFlag) this.globalData.blendMode = "source-over";
10311 this.contextData.restore(actionFlag);
10312 };
10313 CanvasRendererBase.prototype.configAnimation = function(animData) {
10314 if (this.animationItem.wrapper) {
10315 this.animationItem.container = createTag("canvas");
10316 var containerStyle = this.animationItem.container.style;
10317 containerStyle.width = "100%";
10318 containerStyle.height = "100%";
10319 var origin = "0px 0px 0px";
10320 containerStyle.transformOrigin = origin;
10321 containerStyle.mozTransformOrigin = origin;
10322 containerStyle.webkitTransformOrigin = origin;
10323 containerStyle["-webkit-transform"] = origin;
10324 containerStyle.contentVisibility = this.renderConfig.contentVisibility;
10325 this.animationItem.wrapper.appendChild(this.animationItem.container);
10326 this.canvasContext = this.animationItem.container.getContext("2d");
10327 if (this.renderConfig.className) this.animationItem.container.setAttribute("class", this.renderConfig.className);
10328 if (this.renderConfig.id) this.animationItem.container.setAttribute("id", this.renderConfig.id);
10329 } else this.canvasContext = this.renderConfig.context;
10330 this.contextData.setContext(this.canvasContext);
10331 this.data = animData;
10332 this.layers = animData.layers;
10333 this.transformCanvas = {
10334 w: animData.w,
10335 h: animData.h,
10336 sx: 0,
10337 sy: 0,
10338 tx: 0,
10339 ty: 0
10340 };
10341 this.setupGlobalData(animData, document.body);
10342 this.globalData.canvasContext = this.canvasContext;
10343 this.globalData.renderer = this;
10344 this.globalData.isDashed = false;
10345 this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
10346 this.globalData.transformCanvas = this.transformCanvas;
10347 this.elements = createSizedArray(animData.layers.length);
10348 this.updateContainerSize();
10349 };
10350 CanvasRendererBase.prototype.updateContainerSize = function(width, height) {
10351 this.reset();
10352 var elementWidth;
10353 var elementHeight;
10354 if (width) {
10355 elementWidth = width;
10356 elementHeight = height;
10357 this.canvasContext.canvas.width = elementWidth;
10358 this.canvasContext.canvas.height = elementHeight;
10359 } else {
10360 if (this.animationItem.wrapper && this.animationItem.container) {
10361 elementWidth = this.animationItem.wrapper.offsetWidth;
10362 elementHeight = this.animationItem.wrapper.offsetHeight;
10363 } else {
10364 elementWidth = this.canvasContext.canvas.width;
10365 elementHeight = this.canvasContext.canvas.height;
10366 }
10367 this.canvasContext.canvas.width = elementWidth * this.renderConfig.dpr;
10368 this.canvasContext.canvas.height = elementHeight * this.renderConfig.dpr;
10369 }
10370 var elementRel;
10371 var animationRel;
10372 if (this.renderConfig.preserveAspectRatio.indexOf("meet") !== -1 || this.renderConfig.preserveAspectRatio.indexOf("slice") !== -1) {
10373 var par = this.renderConfig.preserveAspectRatio.split(" ");
10374 var fillType = par[1] || "meet";
10375 var pos = par[0] || "xMidYMid";
10376 var xPos = pos.substr(0, 4);
10377 var yPos = pos.substr(4);
10378 elementRel = elementWidth / elementHeight;
10379 animationRel = this.transformCanvas.w / this.transformCanvas.h;
10380 if (animationRel > elementRel && fillType === "meet" || animationRel < elementRel && fillType === "slice") {
10381 this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
10382 this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
10383 } else {
10384 this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
10385 this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
10386 }
10387 if (xPos === "xMid" && (animationRel < elementRel && fillType === "meet" || animationRel > elementRel && fillType === "slice")) this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2 * this.renderConfig.dpr;
10388 else if (xPos === "xMax" && (animationRel < elementRel && fillType === "meet" || animationRel > elementRel && fillType === "slice")) this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr;
10389 else this.transformCanvas.tx = 0;
10390 if (yPos === "YMid" && (animationRel > elementRel && fillType === "meet" || animationRel < elementRel && fillType === "slice")) this.transformCanvas.ty = (elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2 * this.renderConfig.dpr;
10391 else if (yPos === "YMax" && (animationRel > elementRel && fillType === "meet" || animationRel < elementRel && fillType === "slice")) this.transformCanvas.ty = (elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) * this.renderConfig.dpr;
10392 else this.transformCanvas.ty = 0;
10393 } else if (this.renderConfig.preserveAspectRatio === "none") {
10394 this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
10395 this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
10396 this.transformCanvas.tx = 0;
10397 this.transformCanvas.ty = 0;
10398 } else {
10399 this.transformCanvas.sx = this.renderConfig.dpr;
10400 this.transformCanvas.sy = this.renderConfig.dpr;
10401 this.transformCanvas.tx = 0;
10402 this.transformCanvas.ty = 0;
10403 }
10404 this.transformCanvas.props = [
10405 this.transformCanvas.sx,
10406 0,
10407 0,
10408 0,
10409 0,
10410 this.transformCanvas.sy,
10411 0,
10412 0,
10413 0,
10414 0,
10415 1,
10416 0,
10417 this.transformCanvas.tx,
10418 this.transformCanvas.ty,
10419 0,
10420 1
10421 ];
10422 this.ctxTransform(this.transformCanvas.props);
10423 this.canvasContext.beginPath();
10424 this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
10425 this.canvasContext.closePath();
10426 this.canvasContext.clip();
10427 this.renderFrame(this.renderedFrame, true);
10428 };
10429 CanvasRendererBase.prototype.destroy = function() {
10430 if (this.renderConfig.clearCanvas && this.animationItem.wrapper) this.animationItem.wrapper.innerText = "";
10431 var i;
10432 for (i = (this.layers ? this.layers.length : 0) - 1; i >= 0; i -= 1) if (this.elements[i] && this.elements[i].destroy) this.elements[i].destroy();
10433 this.elements.length = 0;
10434 this.globalData.canvasContext = null;
10435 this.animationItem.container = null;
10436 this.destroyed = true;
10437 };
10438 CanvasRendererBase.prototype.renderFrame = function(num, forceRender) {
10439 if (this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender || this.destroyed || num === -1) return;
10440 this.renderedFrame = num;
10441 this.globalData.frameNum = num - this.animationItem._isFirstFrame;
10442 this.globalData.frameId += 1;
10443 this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
10444 this.globalData.projectInterface.currentFrame = num;
10445 var i;
10446 var len = this.layers.length;
10447 if (!this.completeLayers) this.checkLayers(num);
10448 for (i = len - 1; i >= 0; i -= 1) if (this.completeLayers || this.elements[i]) this.elements[i].prepareFrame(num - this.layers[i].st);
10449 if (this.globalData._mdf) {
10450 if (this.renderConfig.clearCanvas === true) this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
10451 else this.save();
10452 for (i = len - 1; i >= 0; i -= 1) if (this.completeLayers || this.elements[i]) this.elements[i].renderFrame();
10453 if (this.renderConfig.clearCanvas !== true) this.restore();
10454 }
10455 };
10456 CanvasRendererBase.prototype.buildItem = function(pos) {
10457 var elements = this.elements;
10458 if (elements[pos] || this.layers[pos].ty === 99) return;
10459 var element = this.createItem(this.layers[pos], this, this.globalData);
10460 elements[pos] = element;
10461 element.initExpressions();
10462 };
10463 CanvasRendererBase.prototype.checkPendingElements = function() {
10464 while (this.pendingElements.length) this.pendingElements.pop().checkParenting();
10465 };
10466 CanvasRendererBase.prototype.hide = function() {
10467 this.animationItem.container.style.display = "none";
10468 };
10469 CanvasRendererBase.prototype.show = function() {
10470 this.animationItem.container.style.display = "block";
10471 };
10472 function CanvasContext() {
10473 this.opacity = -1;
10474 this.transform = createTypedArray("float32", 16);
10475 this.fillStyle = "";
10476 this.strokeStyle = "";
10477 this.lineWidth = "";
10478 this.lineCap = "";
10479 this.lineJoin = "";
10480 this.miterLimit = "";
10481 this.id = Math.random();
10482 }
10483 function CVContextData() {
10484 this.stack = [];
10485 this.cArrPos = 0;
10486 this.cTr = new Matrix();
10487 var i;
10488 var len = 15;
10489 for (i = 0; i < len; i += 1) {
10490 var canvasContext = new CanvasContext();
10491 this.stack[i] = canvasContext;
10492 }
10493 this._length = len;
10494 this.nativeContext = null;
10495 this.transformMat = new Matrix();
10496 this.currentOpacity = 1;
10497 this.currentFillStyle = "";
10498 this.appliedFillStyle = "";
10499 this.currentStrokeStyle = "";
10500 this.appliedStrokeStyle = "";
10501 this.currentLineWidth = "";
10502 this.appliedLineWidth = "";
10503 this.currentLineCap = "";
10504 this.appliedLineCap = "";
10505 this.currentLineJoin = "";
10506 this.appliedLineJoin = "";
10507 this.appliedMiterLimit = "";
10508 this.currentMiterLimit = "";
10509 }
10510 CVContextData.prototype.duplicate = function() {
10511 var newLength = this._length * 2;
10512 var i = 0;
10513 for (i = this._length; i < newLength; i += 1) this.stack[i] = new CanvasContext();
10514 this._length = newLength;
10515 };
10516 CVContextData.prototype.reset = function() {
10517 this.cArrPos = 0;
10518 this.cTr.reset();
10519 this.stack[this.cArrPos].opacity = 1;
10520 };
10521 CVContextData.prototype.restore = function(forceRestore) {
10522 this.cArrPos -= 1;
10523 var currentContext = this.stack[this.cArrPos];
10524 var transform = currentContext.transform;
10525 var i;
10526 var arr = this.cTr.props;
10527 for (i = 0; i < 16; i += 1) arr[i] = transform[i];
10528 if (forceRestore) {
10529 this.nativeContext.restore();
10530 var prevStack = this.stack[this.cArrPos + 1];
10531 this.appliedFillStyle = prevStack.fillStyle;
10532 this.appliedStrokeStyle = prevStack.strokeStyle;
10533 this.appliedLineWidth = prevStack.lineWidth;
10534 this.appliedLineCap = prevStack.lineCap;
10535 this.appliedLineJoin = prevStack.lineJoin;
10536 this.appliedMiterLimit = prevStack.miterLimit;
10537 }
10538 this.nativeContext.setTransform(transform[0], transform[1], transform[4], transform[5], transform[12], transform[13]);
10539 if (forceRestore || currentContext.opacity !== -1 && this.currentOpacity !== currentContext.opacity) {
10540 this.nativeContext.globalAlpha = currentContext.opacity;
10541 this.currentOpacity = currentContext.opacity;
10542 }
10543 this.currentFillStyle = currentContext.fillStyle;
10544 this.currentStrokeStyle = currentContext.strokeStyle;
10545 this.currentLineWidth = currentContext.lineWidth;
10546 this.currentLineCap = currentContext.lineCap;
10547 this.currentLineJoin = currentContext.lineJoin;
10548 this.currentMiterLimit = currentContext.miterLimit;
10549 };
10550 CVContextData.prototype.save = function(saveOnNativeFlag) {
10551 if (saveOnNativeFlag) this.nativeContext.save();
10552 var props = this.cTr.props;
10553 if (this._length <= this.cArrPos) this.duplicate();
10554 var currentStack = this.stack[this.cArrPos];
10555 var i;
10556 for (i = 0; i < 16; i += 1) currentStack.transform[i] = props[i];
10557 this.cArrPos += 1;
10558 var newStack = this.stack[this.cArrPos];
10559 newStack.opacity = currentStack.opacity;
10560 newStack.fillStyle = currentStack.fillStyle;
10561 newStack.strokeStyle = currentStack.strokeStyle;
10562 newStack.lineWidth = currentStack.lineWidth;
10563 newStack.lineCap = currentStack.lineCap;
10564 newStack.lineJoin = currentStack.lineJoin;
10565 newStack.miterLimit = currentStack.miterLimit;
10566 };
10567 CVContextData.prototype.setOpacity = function(value) {
10568 this.stack[this.cArrPos].opacity = value;
10569 };
10570 CVContextData.prototype.setContext = function(value) {
10571 this.nativeContext = value;
10572 };
10573 CVContextData.prototype.fillStyle = function(value) {
10574 if (this.stack[this.cArrPos].fillStyle !== value) {
10575 this.currentFillStyle = value;
10576 this.stack[this.cArrPos].fillStyle = value;
10577 }
10578 };
10579 CVContextData.prototype.strokeStyle = function(value) {
10580 if (this.stack[this.cArrPos].strokeStyle !== value) {
10581 this.currentStrokeStyle = value;
10582 this.stack[this.cArrPos].strokeStyle = value;
10583 }
10584 };
10585 CVContextData.prototype.lineWidth = function(value) {
10586 if (this.stack[this.cArrPos].lineWidth !== value) {
10587 this.currentLineWidth = value;
10588 this.stack[this.cArrPos].lineWidth = value;
10589 }
10590 };
10591 CVContextData.prototype.lineCap = function(value) {
10592 if (this.stack[this.cArrPos].lineCap !== value) {
10593 this.currentLineCap = value;
10594 this.stack[this.cArrPos].lineCap = value;
10595 }
10596 };
10597 CVContextData.prototype.lineJoin = function(value) {
10598 if (this.stack[this.cArrPos].lineJoin !== value) {
10599 this.currentLineJoin = value;
10600 this.stack[this.cArrPos].lineJoin = value;
10601 }
10602 };
10603 CVContextData.prototype.miterLimit = function(value) {
10604 if (this.stack[this.cArrPos].miterLimit !== value) {
10605 this.currentMiterLimit = value;
10606 this.stack[this.cArrPos].miterLimit = value;
10607 }
10608 };
10609 CVContextData.prototype.transform = function(props) {
10610 this.transformMat.cloneFromProps(props);
10611 var currentTransform = this.cTr;
10612 this.transformMat.multiply(currentTransform);
10613 currentTransform.cloneFromProps(this.transformMat.props);
10614 var trProps = currentTransform.props;
10615 this.nativeContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]);
10616 };
10617 CVContextData.prototype.opacity = function(op) {
10618 var currentOpacity = this.stack[this.cArrPos].opacity;
10619 currentOpacity *= op < 0 ? 0 : op;
10620 if (this.stack[this.cArrPos].opacity !== currentOpacity) {
10621 if (this.currentOpacity !== op) {
10622 this.nativeContext.globalAlpha = op;
10623 this.currentOpacity = op;
10624 }
10625 this.stack[this.cArrPos].opacity = currentOpacity;
10626 }
10627 };
10628 CVContextData.prototype.fill = function(rule) {
10629 if (this.appliedFillStyle !== this.currentFillStyle) {
10630 this.appliedFillStyle = this.currentFillStyle;
10631 this.nativeContext.fillStyle = this.appliedFillStyle;
10632 }
10633 this.nativeContext.fill(rule);
10634 };
10635 CVContextData.prototype.fillRect = function(x, y, w, h) {
10636 if (this.appliedFillStyle !== this.currentFillStyle) {
10637 this.appliedFillStyle = this.currentFillStyle;
10638 this.nativeContext.fillStyle = this.appliedFillStyle;
10639 }
10640 this.nativeContext.fillRect(x, y, w, h);
10641 };
10642 CVContextData.prototype.stroke = function() {
10643 if (this.appliedStrokeStyle !== this.currentStrokeStyle) {
10644 this.appliedStrokeStyle = this.currentStrokeStyle;
10645 this.nativeContext.strokeStyle = this.appliedStrokeStyle;
10646 }
10647 if (this.appliedLineWidth !== this.currentLineWidth) {
10648 this.appliedLineWidth = this.currentLineWidth;
10649 this.nativeContext.lineWidth = this.appliedLineWidth;
10650 }
10651 if (this.appliedLineCap !== this.currentLineCap) {
10652 this.appliedLineCap = this.currentLineCap;
10653 this.nativeContext.lineCap = this.appliedLineCap;
10654 }
10655 if (this.appliedLineJoin !== this.currentLineJoin) {
10656 this.appliedLineJoin = this.currentLineJoin;
10657 this.nativeContext.lineJoin = this.appliedLineJoin;
10658 }
10659 if (this.appliedMiterLimit !== this.currentMiterLimit) {
10660 this.appliedMiterLimit = this.currentMiterLimit;
10661 this.nativeContext.miterLimit = this.appliedMiterLimit;
10662 }
10663 this.nativeContext.stroke();
10664 };
10665 function CVCompElement(data, globalData, comp) {
10666 this.completeLayers = false;
10667 this.layers = data.layers;
10668 this.pendingElements = [];
10669 this.elements = createSizedArray(this.layers.length);
10670 this.initElement(data, globalData, comp);
10671 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
10672 }
10673 extendPrototype([
10674 CanvasRendererBase,
10675 ICompElement,
10676 CVBaseElement
10677 ], CVCompElement);
10678 CVCompElement.prototype.renderInnerContent = function() {
10679 var ctx = this.canvasContext;
10680 ctx.beginPath();
10681 ctx.moveTo(0, 0);
10682 ctx.lineTo(this.data.w, 0);
10683 ctx.lineTo(this.data.w, this.data.h);
10684 ctx.lineTo(0, this.data.h);
10685 ctx.lineTo(0, 0);
10686 ctx.clip();
10687 var i;
10688 for (i = this.layers.length - 1; i >= 0; i -= 1) if (this.completeLayers || this.elements[i]) this.elements[i].renderFrame();
10689 };
10690 CVCompElement.prototype.destroy = function() {
10691 var i;
10692 for (i = this.layers.length - 1; i >= 0; i -= 1) if (this.elements[i]) this.elements[i].destroy();
10693 this.layers = null;
10694 this.elements = null;
10695 };
10696 CVCompElement.prototype.createComp = function(data) {
10697 return new CVCompElement(data, this.globalData, this);
10698 };
10699 function CanvasRenderer(animationItem, config) {
10700 this.animationItem = animationItem;
10701 this.renderConfig = {
10702 clearCanvas: config && config.clearCanvas !== void 0 ? config.clearCanvas : true,
10703 context: config && config.context || null,
10704 progressiveLoad: config && config.progressiveLoad || false,
10705 preserveAspectRatio: config && config.preserveAspectRatio || "xMidYMid meet",
10706 imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || "xMidYMid slice",
10707 contentVisibility: config && config.contentVisibility || "visible",
10708 className: config && config.className || "",
10709 id: config && config.id || "",
10710 runExpressions: !config || config.runExpressions === void 0 || config.runExpressions
10711 };
10712 this.renderConfig.dpr = config && config.dpr || 1;
10713 if (this.animationItem.wrapper) this.renderConfig.dpr = config && config.dpr || window.devicePixelRatio || 1;
10714 this.renderedFrame = -1;
10715 this.globalData = {
10716 frameNum: -1,
10717 _mdf: false,
10718 renderConfig: this.renderConfig,
10719 currentGlobalAlpha: -1
10720 };
10721 this.contextData = new CVContextData();
10722 this.elements = [];
10723 this.pendingElements = [];
10724 this.transformMat = new Matrix();
10725 this.completeLayers = false;
10726 this.rendererType = "canvas";
10727 if (this.renderConfig.clearCanvas) {
10728 this.ctxTransform = this.contextData.transform.bind(this.contextData);
10729 this.ctxOpacity = this.contextData.opacity.bind(this.contextData);
10730 this.ctxFillStyle = this.contextData.fillStyle.bind(this.contextData);
10731 this.ctxStrokeStyle = this.contextData.strokeStyle.bind(this.contextData);
10732 this.ctxLineWidth = this.contextData.lineWidth.bind(this.contextData);
10733 this.ctxLineCap = this.contextData.lineCap.bind(this.contextData);
10734 this.ctxLineJoin = this.contextData.lineJoin.bind(this.contextData);
10735 this.ctxMiterLimit = this.contextData.miterLimit.bind(this.contextData);
10736 this.ctxFill = this.contextData.fill.bind(this.contextData);
10737 this.ctxFillRect = this.contextData.fillRect.bind(this.contextData);
10738 this.ctxStroke = this.contextData.stroke.bind(this.contextData);
10739 this.save = this.contextData.save.bind(this.contextData);
10740 }
10741 }
10742 extendPrototype([CanvasRendererBase], CanvasRenderer);
10743 CanvasRenderer.prototype.createComp = function(data) {
10744 return new CVCompElement(data, this.globalData, this);
10745 };
10746 function HBaseElement() {}
10747 HBaseElement.prototype = {
10748 checkBlendMode: function checkBlendMode() {},
10749 initRendererElement: function initRendererElement() {
10750 this.baseElement = createTag(this.data.tg || "div");
10751 if (this.data.hasMask) {
10752 this.svgElement = createNS("svg");
10753 this.layerElement = createNS("g");
10754 this.maskedElement = this.layerElement;
10755 this.svgElement.appendChild(this.layerElement);
10756 this.baseElement.appendChild(this.svgElement);
10757 } else this.layerElement = this.baseElement;
10758 styleDiv(this.baseElement);
10759 },
10760 createContainerElements: function createContainerElements() {
10761 this.renderableEffectsManager = new CVEffects(this);
10762 this.transformedElement = this.baseElement;
10763 this.maskedElement = this.layerElement;
10764 if (this.data.ln) this.layerElement.setAttribute("id", this.data.ln);
10765 if (this.data.cl) this.layerElement.setAttribute("class", this.data.cl);
10766 if (this.data.bm !== 0) this.setBlendMode();
10767 },
10768 renderElement: function renderElement() {
10769 var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {};
10770 if (this.finalTransform._matMdf) {
10771 var matrixValue = this.finalTransform.mat.toCSS();
10772 transformedElementStyle.transform = matrixValue;
10773 transformedElementStyle.webkitTransform = matrixValue;
10774 }
10775 if (this.finalTransform._opMdf) transformedElementStyle.opacity = this.finalTransform.mProp.o.v;
10776 },
10777 renderFrame: function renderFrame() {
10778 if (this.data.hd || this.hidden) return;
10779 this.renderTransform();
10780 this.renderRenderable();
10781 this.renderElement();
10782 this.renderInnerContent();
10783 if (this._isFirstFrame) this._isFirstFrame = false;
10784 },
10785 destroy: function destroy() {
10786 this.layerElement = null;
10787 this.transformedElement = null;
10788 if (this.matteElement) this.matteElement = null;
10789 if (this.maskManager) {
10790 this.maskManager.destroy();
10791 this.maskManager = null;
10792 }
10793 },
10794 createRenderableComponents: function createRenderableComponents() {
10795 this.maskManager = new MaskElement(this.data, this, this.globalData);
10796 },
10797 addEffects: function addEffects() {},
10798 setMatte: function setMatte() {}
10799 };
10800 HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement;
10801 HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy;
10802 HBaseElement.prototype.buildElementParenting = BaseRenderer.prototype.buildElementParenting;
10803 function HSolidElement(data, globalData, comp) {
10804 this.initElement(data, globalData, comp);
10805 }
10806 extendPrototype([
10807 BaseElement,
10808 TransformElement,
10809 HBaseElement,
10810 HierarchyElement,
10811 FrameElement,
10812 RenderableDOMElement
10813 ], HSolidElement);
10814 HSolidElement.prototype.createContent = function() {
10815 var rect;
10816 if (this.data.hasMask) {
10817 rect = createNS("rect");
10818 rect.setAttribute("width", this.data.sw);
10819 rect.setAttribute("height", this.data.sh);
10820 rect.setAttribute("fill", this.data.sc);
10821 this.svgElement.setAttribute("width", this.data.sw);
10822 this.svgElement.setAttribute("height", this.data.sh);
10823 } else {
10824 rect = createTag("div");
10825 rect.style.width = this.data.sw + "px";
10826 rect.style.height = this.data.sh + "px";
10827 rect.style.backgroundColor = this.data.sc;
10828 }
10829 this.layerElement.appendChild(rect);
10830 };
10831 function HShapeElement(data, globalData, comp) {
10832 this.shapes = [];
10833 this.shapesData = data.shapes;
10834 this.stylesList = [];
10835 this.shapeModifiers = [];
10836 this.itemsData = [];
10837 this.processedElements = [];
10838 this.animatedContents = [];
10839 this.shapesContainer = createNS("g");
10840 this.initElement(data, globalData, comp);
10841 this.prevViewData = [];
10842 this.currentBBox = {
10843 x: 999999,
10844 y: -999999,
10845 h: 0,
10846 w: 0
10847 };
10848 }
10849 extendPrototype([
10850 BaseElement,
10851 TransformElement,
10852 HSolidElement,
10853 SVGShapeElement,
10854 HBaseElement,
10855 HierarchyElement,
10856 FrameElement,
10857 RenderableElement
10858 ], HShapeElement);
10859 HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent;
10860 HShapeElement.prototype.createContent = function() {
10861 var cont;
10862 this.baseElement.style.fontSize = 0;
10863 if (this.data.hasMask) {
10864 this.layerElement.appendChild(this.shapesContainer);
10865 cont = this.svgElement;
10866 } else {
10867 cont = createNS("svg");
10868 var size = this.comp.data ? this.comp.data : this.globalData.compSize;
10869 cont.setAttribute("width", size.w);
10870 cont.setAttribute("height", size.h);
10871 cont.appendChild(this.shapesContainer);
10872 this.layerElement.appendChild(cont);
10873 }
10874 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true);
10875 this.filterUniqueShapes();
10876 this.shapeCont = cont;
10877 };
10878 HShapeElement.prototype.getTransformedPoint = function(transformers, point) {
10879 var i;
10880 var len = transformers.length;
10881 for (i = 0; i < len; i += 1) point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0);
10882 return point;
10883 };
10884 HShapeElement.prototype.calculateShapeBoundingBox = function(item, boundingBox) {
10885 var shape = item.sh.v;
10886 var transformers = item.transformers;
10887 var i;
10888 var len = shape._length;
10889 var vPoint;
10890 var oPoint;
10891 var nextIPoint;
10892 var nextVPoint;
10893 if (len <= 1) return;
10894 for (i = 0; i < len - 1; i += 1) {
10895 vPoint = this.getTransformedPoint(transformers, shape.v[i]);
10896 oPoint = this.getTransformedPoint(transformers, shape.o[i]);
10897 nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]);
10898 nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]);
10899 this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
10900 }
10901 if (shape.c) {
10902 vPoint = this.getTransformedPoint(transformers, shape.v[i]);
10903 oPoint = this.getTransformedPoint(transformers, shape.o[i]);
10904 nextIPoint = this.getTransformedPoint(transformers, shape.i[0]);
10905 nextVPoint = this.getTransformedPoint(transformers, shape.v[0]);
10906 this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
10907 }
10908 };
10909 HShapeElement.prototype.checkBounds = function(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) {
10910 this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint);
10911 var bounds = this.shapeBoundingBox;
10912 boundingBox.x = bmMin(bounds.left, boundingBox.x);
10913 boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax);
10914 boundingBox.y = bmMin(bounds.top, boundingBox.y);
10915 boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax);
10916 };
10917 HShapeElement.prototype.shapeBoundingBox = {
10918 left: 0,
10919 right: 0,
10920 top: 0,
10921 bottom: 0
10922 };
10923 HShapeElement.prototype.tempBoundingBox = {
10924 x: 0,
10925 xMax: 0,
10926 y: 0,
10927 yMax: 0,
10928 width: 0,
10929 height: 0
10930 };
10931 HShapeElement.prototype.getBoundsOfCurve = function(p0, p1, p2, p3) {
10932 var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]];
10933 for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) {
10934 b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
10935 a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
10936 c = 3 * p1[i] - 3 * p0[i];
10937 b |= 0;
10938 a |= 0;
10939 c |= 0;
10940 if (a === 0 && b === 0) {} else if (a === 0) {
10941 t = -c / b;
10942 if (t > 0 && t < 1) bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i));
10943 } else {
10944 b2ac = b * b - 4 * c * a;
10945 if (b2ac >= 0) {
10946 t1 = (-b + bmSqrt(b2ac)) / (2 * a);
10947 if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i));
10948 t2 = (-b - bmSqrt(b2ac)) / (2 * a);
10949 if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i));
10950 }
10951 }
10952 }
10953 this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]);
10954 this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]);
10955 this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]);
10956 this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]);
10957 };
10958 HShapeElement.prototype.calculateF = function(t, p0, p1, p2, p3, i) {
10959 return bmPow(1 - t, 3) * p0[i] + 3 * bmPow(1 - t, 2) * t * p1[i] + 3 * (1 - t) * bmPow(t, 2) * p2[i] + bmPow(t, 3) * p3[i];
10960 };
10961 HShapeElement.prototype.calculateBoundingBox = function(itemsData, boundingBox) {
10962 var i;
10963 var len = itemsData.length;
10964 for (i = 0; i < len; i += 1) if (itemsData[i] && itemsData[i].sh) this.calculateShapeBoundingBox(itemsData[i], boundingBox);
10965 else if (itemsData[i] && itemsData[i].it) this.calculateBoundingBox(itemsData[i].it, boundingBox);
10966 else if (itemsData[i] && itemsData[i].style && itemsData[i].w) this.expandStrokeBoundingBox(itemsData[i].w, boundingBox);
10967 };
10968 HShapeElement.prototype.expandStrokeBoundingBox = function(widthProperty, boundingBox) {
10969 var width = 0;
10970 if (widthProperty.keyframes) {
10971 for (var i = 0; i < widthProperty.keyframes.length; i += 1) {
10972 var kfw = widthProperty.keyframes[i].s;
10973 if (kfw > width) width = kfw;
10974 }
10975 width *= widthProperty.mult;
10976 } else width = widthProperty.v * widthProperty.mult;
10977 boundingBox.x -= width;
10978 boundingBox.xMax += width;
10979 boundingBox.y -= width;
10980 boundingBox.yMax += width;
10981 };
10982 HShapeElement.prototype.currentBoxContains = function(box) {
10983 return this.currentBBox.x <= box.x && this.currentBBox.y <= box.y && this.currentBBox.width + this.currentBBox.x >= box.x + box.width && this.currentBBox.height + this.currentBBox.y >= box.y + box.height;
10984 };
10985 HShapeElement.prototype.renderInnerContent = function() {
10986 this._renderShapeFrame();
10987 if (!this.hidden && (this._isFirstFrame || this._mdf)) {
10988 var tempBoundingBox = this.tempBoundingBox;
10989 var max = 999999;
10990 tempBoundingBox.x = max;
10991 tempBoundingBox.xMax = -max;
10992 tempBoundingBox.y = max;
10993 tempBoundingBox.yMax = -max;
10994 this.calculateBoundingBox(this.itemsData, tempBoundingBox);
10995 tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x;
10996 tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y;
10997 if (this.currentBoxContains(tempBoundingBox)) return;
10998 var changed = false;
10999 if (this.currentBBox.w !== tempBoundingBox.width) {
11000 this.currentBBox.w = tempBoundingBox.width;
11001 this.shapeCont.setAttribute("width", tempBoundingBox.width);
11002 changed = true;
11003 }
11004 if (this.currentBBox.h !== tempBoundingBox.height) {
11005 this.currentBBox.h = tempBoundingBox.height;
11006 this.shapeCont.setAttribute("height", tempBoundingBox.height);
11007 changed = true;
11008 }
11009 if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) {
11010 this.currentBBox.w = tempBoundingBox.width;
11011 this.currentBBox.h = tempBoundingBox.height;
11012 this.currentBBox.x = tempBoundingBox.x;
11013 this.currentBBox.y = tempBoundingBox.y;
11014 this.shapeCont.setAttribute("viewBox", this.currentBBox.x + " " + this.currentBBox.y + " " + this.currentBBox.w + " " + this.currentBBox.h);
11015 var shapeStyle = this.shapeCont.style;
11016 var shapeTransform = "translate(" + this.currentBBox.x + "px," + this.currentBBox.y + "px)";
11017 shapeStyle.transform = shapeTransform;
11018 shapeStyle.webkitTransform = shapeTransform;
11019 }
11020 }
11021 };
11022 function HTextElement(data, globalData, comp) {
11023 this.textSpans = [];
11024 this.textPaths = [];
11025 this.currentBBox = {
11026 x: 999999,
11027 y: -999999,
11028 h: 0,
11029 w: 0
11030 };
11031 this.renderType = "svg";
11032 this.isMasked = false;
11033 this.initElement(data, globalData, comp);
11034 }
11035 extendPrototype([
11036 BaseElement,
11037 TransformElement,
11038 HBaseElement,
11039 HierarchyElement,
11040 FrameElement,
11041 RenderableDOMElement,
11042 ITextElement
11043 ], HTextElement);
11044 HTextElement.prototype.createContent = function() {
11045 this.isMasked = this.checkMasks();
11046 if (this.isMasked) {
11047 this.renderType = "svg";
11048 this.compW = this.comp.data.w;
11049 this.compH = this.comp.data.h;
11050 this.svgElement.setAttribute("width", this.compW);
11051 this.svgElement.setAttribute("height", this.compH);
11052 var g = createNS("g");
11053 this.maskedElement.appendChild(g);
11054 this.innerElem = g;
11055 } else {
11056 this.renderType = "html";
11057 this.innerElem = this.layerElement;
11058 }
11059 this.checkParenting();
11060 };
11061 HTextElement.prototype.buildNewText = function() {
11062 var documentData = this.textProperty.currentData;
11063 this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
11064 var innerElemStyle = this.innerElem.style;
11065 var textColor = documentData.fc ? this.buildColor(documentData.fc) : "rgba(0,0,0,0)";
11066 innerElemStyle.fill = textColor;
11067 innerElemStyle.color = textColor;
11068 if (documentData.sc) {
11069 innerElemStyle.stroke = this.buildColor(documentData.sc);
11070 innerElemStyle.strokeWidth = documentData.sw + "px";
11071 }
11072 var fontData = this.globalData.fontManager.getFontByName(documentData.f);
11073 if (!this.globalData.fontManager.chars) {
11074 innerElemStyle.fontSize = documentData.finalSize + "px";
11075 innerElemStyle.lineHeight = documentData.finalSize + "px";
11076 if (fontData.fClass) this.innerElem.className = fontData.fClass;
11077 else {
11078 innerElemStyle.fontFamily = fontData.fFamily;
11079 var fWeight = documentData.fWeight;
11080 innerElemStyle.fontStyle = documentData.fStyle;
11081 innerElemStyle.fontWeight = fWeight;
11082 }
11083 }
11084 var i;
11085 var len;
11086 var letters = documentData.l;
11087 len = letters.length;
11088 var tSpan;
11089 var tParent;
11090 var tCont;
11091 var matrixHelper = this.mHelper;
11092 var shapes;
11093 var shapeStr = "";
11094 var cnt = 0;
11095 for (i = 0; i < len; i += 1) {
11096 if (this.globalData.fontManager.chars) {
11097 if (!this.textPaths[cnt]) {
11098 tSpan = createNS("path");
11099 tSpan.setAttribute("stroke-linecap", lineCapEnum[1]);
11100 tSpan.setAttribute("stroke-linejoin", lineJoinEnum[2]);
11101 tSpan.setAttribute("stroke-miterlimit", "4");
11102 } else tSpan = this.textPaths[cnt];
11103 if (!this.isMasked) if (this.textSpans[cnt]) {
11104 tParent = this.textSpans[cnt];
11105 tCont = tParent.children[0];
11106 } else {
11107 tParent = createTag("div");
11108 tParent.style.lineHeight = 0;
11109 tCont = createNS("svg");
11110 tCont.appendChild(tSpan);
11111 styleDiv(tParent);
11112 }
11113 } else if (!this.isMasked) if (this.textSpans[cnt]) {
11114 tParent = this.textSpans[cnt];
11115 tSpan = this.textPaths[cnt];
11116 } else {
11117 tParent = createTag("span");
11118 styleDiv(tParent);
11119 tSpan = createTag("span");
11120 styleDiv(tSpan);
11121 tParent.appendChild(tSpan);
11122 }
11123 else tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS("text");
11124 if (this.globalData.fontManager.chars) {
11125 var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
11126 var shapeData;
11127 if (charData) shapeData = charData.data;
11128 else shapeData = null;
11129 matrixHelper.reset();
11130 if (shapeData && shapeData.shapes && shapeData.shapes.length) {
11131 shapes = shapeData.shapes[0].it;
11132 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
11133 shapeStr = this.createPathShape(matrixHelper, shapes);
11134 tSpan.setAttribute("d", shapeStr);
11135 }
11136 if (!this.isMasked) {
11137 this.innerElem.appendChild(tParent);
11138 if (shapeData && shapeData.shapes) {
11139 document.body.appendChild(tCont);
11140 var boundingBox = tCont.getBBox();
11141 tCont.setAttribute("width", boundingBox.width + 2);
11142 tCont.setAttribute("height", boundingBox.height + 2);
11143 tCont.setAttribute("viewBox", boundingBox.x - 1 + " " + (boundingBox.y - 1) + " " + (boundingBox.width + 2) + " " + (boundingBox.height + 2));
11144 var tContStyle = tCont.style;
11145 var tContTranslation = "translate(" + (boundingBox.x - 1) + "px," + (boundingBox.y - 1) + "px)";
11146 tContStyle.transform = tContTranslation;
11147 tContStyle.webkitTransform = tContTranslation;
11148 letters[i].yOffset = boundingBox.y - 1;
11149 } else {
11150 tCont.setAttribute("width", 1);
11151 tCont.setAttribute("height", 1);
11152 }
11153 tParent.appendChild(tCont);
11154 } else this.innerElem.appendChild(tSpan);
11155 } else {
11156 tSpan.textContent = letters[i].val;
11157 tSpan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
11158 if (!this.isMasked) {
11159 this.innerElem.appendChild(tParent);
11160 var tStyle = tSpan.style;
11161 var tSpanTranslation = "translate3d(0," + -documentData.finalSize / 1.2 + "px,0)";
11162 tStyle.transform = tSpanTranslation;
11163 tStyle.webkitTransform = tSpanTranslation;
11164 } else this.innerElem.appendChild(tSpan);
11165 }
11166 if (!this.isMasked) this.textSpans[cnt] = tParent;
11167 else this.textSpans[cnt] = tSpan;
11168 this.textSpans[cnt].style.display = "block";
11169 this.textPaths[cnt] = tSpan;
11170 cnt += 1;
11171 }
11172 while (cnt < this.textSpans.length) {
11173 this.textSpans[cnt].style.display = "none";
11174 cnt += 1;
11175 }
11176 };
11177 HTextElement.prototype.renderInnerContent = function() {
11178 this.validateText();
11179 var svgStyle;
11180 if (this.data.singleShape) {
11181 if (!this._isFirstFrame && !this.lettersChangedFlag) return;
11182 if (this.isMasked && this.finalTransform._matMdf) {
11183 this.svgElement.setAttribute("viewBox", -this.finalTransform.mProp.p.v[0] + " " + -this.finalTransform.mProp.p.v[1] + " " + this.compW + " " + this.compH);
11184 svgStyle = this.svgElement.style;
11185 var translation = "translate(" + -this.finalTransform.mProp.p.v[0] + "px," + -this.finalTransform.mProp.p.v[1] + "px)";
11186 svgStyle.transform = translation;
11187 svgStyle.webkitTransform = translation;
11188 }
11189 }
11190 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
11191 if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) return;
11192 var i;
11193 var len;
11194 var count = 0;
11195 var renderedLetters = this.textAnimator.renderedLetters;
11196 var letters = this.textProperty.currentData.l;
11197 len = letters.length;
11198 var renderedLetter;
11199 var textSpan;
11200 var textPath;
11201 for (i = 0; i < len; i += 1) if (letters[i].n) count += 1;
11202 else {
11203 textSpan = this.textSpans[i];
11204 textPath = this.textPaths[i];
11205 renderedLetter = renderedLetters[count];
11206 count += 1;
11207 if (renderedLetter._mdf.m) if (!this.isMasked) {
11208 textSpan.style.webkitTransform = renderedLetter.m;
11209 textSpan.style.transform = renderedLetter.m;
11210 } else textSpan.setAttribute("transform", renderedLetter.m);
11211 textSpan.style.opacity = renderedLetter.o;
11212 if (renderedLetter.sw && renderedLetter._mdf.sw) textPath.setAttribute("stroke-width", renderedLetter.sw);
11213 if (renderedLetter.sc && renderedLetter._mdf.sc) textPath.setAttribute("stroke", renderedLetter.sc);
11214 if (renderedLetter.fc && renderedLetter._mdf.fc) {
11215 textPath.setAttribute("fill", renderedLetter.fc);
11216 textPath.style.color = renderedLetter.fc;
11217 }
11218 }
11219 if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) {
11220 var boundingBox = this.innerElem.getBBox();
11221 if (this.currentBBox.w !== boundingBox.width) {
11222 this.currentBBox.w = boundingBox.width;
11223 this.svgElement.setAttribute("width", boundingBox.width);
11224 }
11225 if (this.currentBBox.h !== boundingBox.height) {
11226 this.currentBBox.h = boundingBox.height;
11227 this.svgElement.setAttribute("height", boundingBox.height);
11228 }
11229 var margin = 1;
11230 if (this.currentBBox.w !== boundingBox.width + margin * 2 || this.currentBBox.h !== boundingBox.height + margin * 2 || this.currentBBox.x !== boundingBox.x - margin || this.currentBBox.y !== boundingBox.y - margin) {
11231 this.currentBBox.w = boundingBox.width + margin * 2;
11232 this.currentBBox.h = boundingBox.height + margin * 2;
11233 this.currentBBox.x = boundingBox.x - margin;
11234 this.currentBBox.y = boundingBox.y - margin;
11235 this.svgElement.setAttribute("viewBox", this.currentBBox.x + " " + this.currentBBox.y + " " + this.currentBBox.w + " " + this.currentBBox.h);
11236 svgStyle = this.svgElement.style;
11237 var svgTransform = "translate(" + this.currentBBox.x + "px," + this.currentBBox.y + "px)";
11238 svgStyle.transform = svgTransform;
11239 svgStyle.webkitTransform = svgTransform;
11240 }
11241 }
11242 };
11243 function HCameraElement(data, globalData, comp) {
11244 this.initFrame();
11245 this.initBaseData(data, globalData, comp);
11246 this.initHierarchy();
11247 var getProp = PropertyFactory.getProp;
11248 this.pe = getProp(this, data.pe, 0, 0, this);
11249 if (data.ks.p.s) {
11250 this.px = getProp(this, data.ks.p.x, 1, 0, this);
11251 this.py = getProp(this, data.ks.p.y, 1, 0, this);
11252 this.pz = getProp(this, data.ks.p.z, 1, 0, this);
11253 } else this.p = getProp(this, data.ks.p, 1, 0, this);
11254 if (data.ks.a) this.a = getProp(this, data.ks.a, 1, 0, this);
11255 if (data.ks.or.k.length && data.ks.or.k[0].to) {
11256 var i;
11257 var len = data.ks.or.k.length;
11258 for (i = 0; i < len; i += 1) {
11259 data.ks.or.k[i].to = null;
11260 data.ks.or.k[i].ti = null;
11261 }
11262 }
11263 this.or = getProp(this, data.ks.or, 1, degToRads, this);
11264 this.or.sh = true;
11265 this.rx = getProp(this, data.ks.rx, 0, degToRads, this);
11266 this.ry = getProp(this, data.ks.ry, 0, degToRads, this);
11267 this.rz = getProp(this, data.ks.rz, 0, degToRads, this);
11268 this.mat = new Matrix();
11269 this._prevMat = new Matrix();
11270 this._isFirstFrame = true;
11271 this.finalTransform = { mProp: this };
11272 }
11273 extendPrototype([
11274 BaseElement,
11275 FrameElement,
11276 HierarchyElement
11277 ], HCameraElement);
11278 HCameraElement.prototype.setup = function() {
11279 var i;
11280 var len = this.comp.threeDElements.length;
11281 var comp;
11282 var perspectiveStyle;
11283 var containerStyle;
11284 for (i = 0; i < len; i += 1) {
11285 comp = this.comp.threeDElements[i];
11286 if (comp.type === "3d") {
11287 perspectiveStyle = comp.perspectiveElem.style;
11288 containerStyle = comp.container.style;
11289 var perspective = this.pe.v + "px";
11290 var origin = "0px 0px 0px";
11291 var matrix = "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)";
11292 perspectiveStyle.perspective = perspective;
11293 perspectiveStyle.webkitPerspective = perspective;
11294 containerStyle.transformOrigin = origin;
11295 containerStyle.mozTransformOrigin = origin;
11296 containerStyle.webkitTransformOrigin = origin;
11297 perspectiveStyle.transform = matrix;
11298 perspectiveStyle.webkitTransform = matrix;
11299 }
11300 }
11301 };
11302 HCameraElement.prototype.createElements = function() {};
11303 HCameraElement.prototype.hide = function() {};
11304 HCameraElement.prototype.renderFrame = function() {
11305 var _mdf = this._isFirstFrame;
11306 var i;
11307 var len;
11308 if (this.hierarchy) {
11309 len = this.hierarchy.length;
11310 for (i = 0; i < len; i += 1) _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf;
11311 }
11312 if (_mdf || this.pe._mdf || this.p && this.p._mdf || this.px && (this.px._mdf || this.py._mdf || this.pz._mdf) || this.rx._mdf || this.ry._mdf || this.rz._mdf || this.or._mdf || this.a && this.a._mdf) {
11313 this.mat.reset();
11314 if (this.hierarchy) {
11315 len = this.hierarchy.length - 1;
11316 for (i = len; i >= 0; i -= 1) {
11317 var mTransf = this.hierarchy[i].finalTransform.mProp;
11318 this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]);
11319 this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]);
11320 this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v);
11321 this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]);
11322 this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]);
11323 }
11324 }
11325 if (this.p) this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]);
11326 else this.mat.translate(-this.px.v, -this.py.v, this.pz.v);
11327 if (this.a) {
11328 var diffVector;
11329 if (this.p) diffVector = [
11330 this.p.v[0] - this.a.v[0],
11331 this.p.v[1] - this.a.v[1],
11332 this.p.v[2] - this.a.v[2]
11333 ];
11334 else diffVector = [
11335 this.px.v - this.a.v[0],
11336 this.py.v - this.a.v[1],
11337 this.pz.v - this.a.v[2]
11338 ];
11339 var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2));
11340 var lookDir = [
11341 diffVector[0] / mag,
11342 diffVector[1] / mag,
11343 diffVector[2] / mag
11344 ];
11345 var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]);
11346 var mRotationX = Math.atan2(lookDir[1], lookLengthOnXZ);
11347 var mRotationY = Math.atan2(lookDir[0], -lookDir[2]);
11348 this.mat.rotateY(mRotationY).rotateX(-mRotationX);
11349 }
11350 this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v);
11351 this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]);
11352 this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0);
11353 this.mat.translate(0, 0, this.pe.v);
11354 var hasMatrixChanged = !this._prevMat.equals(this.mat);
11355 if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) {
11356 len = this.comp.threeDElements.length;
11357 var comp;
11358 var perspectiveStyle;
11359 var containerStyle;
11360 for (i = 0; i < len; i += 1) {
11361 comp = this.comp.threeDElements[i];
11362 if (comp.type === "3d") {
11363 if (hasMatrixChanged) {
11364 var matValue = this.mat.toCSS();
11365 containerStyle = comp.container.style;
11366 containerStyle.transform = matValue;
11367 containerStyle.webkitTransform = matValue;
11368 }
11369 if (this.pe._mdf) {
11370 perspectiveStyle = comp.perspectiveElem.style;
11371 perspectiveStyle.perspective = this.pe.v + "px";
11372 perspectiveStyle.webkitPerspective = this.pe.v + "px";
11373 }
11374 }
11375 }
11376 this.mat.clone(this._prevMat);
11377 }
11378 }
11379 this._isFirstFrame = false;
11380 };
11381 HCameraElement.prototype.prepareFrame = function(num) {
11382 this.prepareProperties(num, true);
11383 };
11384 HCameraElement.prototype.destroy = function() {};
11385 HCameraElement.prototype.getBaseElement = function() {
11386 return null;
11387 };
11388 function HImageElement(data, globalData, comp) {
11389 this.assetData = globalData.getAssetData(data.refId);
11390 this.initElement(data, globalData, comp);
11391 }
11392 extendPrototype([
11393 BaseElement,
11394 TransformElement,
11395 HBaseElement,
11396 HSolidElement,
11397 HierarchyElement,
11398 FrameElement,
11399 RenderableElement
11400 ], HImageElement);
11401 HImageElement.prototype.createContent = function() {
11402 var assetPath = this.globalData.getAssetsPath(this.assetData);
11403 var img = new Image();
11404 if (this.data.hasMask) {
11405 this.imageElem = createNS("image");
11406 this.imageElem.setAttribute("width", this.assetData.w + "px");
11407 this.imageElem.setAttribute("height", this.assetData.h + "px");
11408 this.imageElem.setAttributeNS("http://www.w3.org/1999/xlink", "href", assetPath);
11409 this.layerElement.appendChild(this.imageElem);
11410 this.baseElement.setAttribute("width", this.assetData.w);
11411 this.baseElement.setAttribute("height", this.assetData.h);
11412 } else this.layerElement.appendChild(img);
11413 img.crossOrigin = "anonymous";
11414 img.src = assetPath;
11415 if (this.data.ln) this.baseElement.setAttribute("id", this.data.ln);
11416 };
11417 function HybridRendererBase(animationItem, config) {
11418 this.animationItem = animationItem;
11419 this.layers = null;
11420 this.renderedFrame = -1;
11421 this.renderConfig = {
11422 className: config && config.className || "",
11423 imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || "xMidYMid slice",
11424 hideOnTransparent: !(config && config.hideOnTransparent === false),
11425 filterSize: {
11426 width: config && config.filterSize && config.filterSize.width || "400%",
11427 height: config && config.filterSize && config.filterSize.height || "400%",
11428 x: config && config.filterSize && config.filterSize.x || "-100%",
11429 y: config && config.filterSize && config.filterSize.y || "-100%"
11430 }
11431 };
11432 this.globalData = {
11433 _mdf: false,
11434 frameNum: -1,
11435 renderConfig: this.renderConfig
11436 };
11437 this.pendingElements = [];
11438 this.elements = [];
11439 this.threeDElements = [];
11440 this.destroyed = false;
11441 this.camera = null;
11442 this.supports3d = true;
11443 this.rendererType = "html";
11444 }
11445 extendPrototype([BaseRenderer], HybridRendererBase);
11446 HybridRendererBase.prototype.buildItem = SVGRenderer.prototype.buildItem;
11447 HybridRendererBase.prototype.checkPendingElements = function() {
11448 while (this.pendingElements.length) this.pendingElements.pop().checkParenting();
11449 };
11450 HybridRendererBase.prototype.appendElementInPos = function(element, pos) {
11451 var newDOMElement = element.getBaseElement();
11452 if (!newDOMElement) return;
11453 var layer = this.layers[pos];
11454 if (!layer.ddd || !this.supports3d) if (this.threeDElements) this.addTo3dContainer(newDOMElement, pos);
11455 else {
11456 var i = 0;
11457 var nextDOMElement;
11458 var nextLayer;
11459 var tmpDOMElement;
11460 while (i < pos) {
11461 if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) {
11462 nextLayer = this.elements[i];
11463 tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement();
11464 nextDOMElement = tmpDOMElement || nextDOMElement;
11465 }
11466 i += 1;
11467 }
11468 if (nextDOMElement) {
11469 if (!layer.ddd || !this.supports3d) this.layerElement.insertBefore(newDOMElement, nextDOMElement);
11470 } else if (!layer.ddd || !this.supports3d) this.layerElement.appendChild(newDOMElement);
11471 }
11472 else this.addTo3dContainer(newDOMElement, pos);
11473 };
11474 HybridRendererBase.prototype.createShape = function(data) {
11475 if (!this.supports3d) return new SVGShapeElement(data, this.globalData, this);
11476 return new HShapeElement(data, this.globalData, this);
11477 };
11478 HybridRendererBase.prototype.createText = function(data) {
11479 if (!this.supports3d) return new SVGTextLottieElement(data, this.globalData, this);
11480 return new HTextElement(data, this.globalData, this);
11481 };
11482 HybridRendererBase.prototype.createCamera = function(data) {
11483 this.camera = new HCameraElement(data, this.globalData, this);
11484 return this.camera;
11485 };
11486 HybridRendererBase.prototype.createImage = function(data) {
11487 if (!this.supports3d) return new IImageElement(data, this.globalData, this);
11488 return new HImageElement(data, this.globalData, this);
11489 };
11490 HybridRendererBase.prototype.createSolid = function(data) {
11491 if (!this.supports3d) return new ISolidElement(data, this.globalData, this);
11492 return new HSolidElement(data, this.globalData, this);
11493 };
11494 HybridRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
11495 HybridRendererBase.prototype.getThreeDContainerByPos = function(pos) {
11496 var i = 0;
11497 var len = this.threeDElements.length;
11498 while (i < len) {
11499 if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) return this.threeDElements[i].perspectiveElem;
11500 i += 1;
11501 }
11502 return null;
11503 };
11504 HybridRendererBase.prototype.createThreeDContainer = function(pos, type) {
11505 var perspectiveElem = createTag("div");
11506 var style;
11507 var containerStyle;
11508 styleDiv(perspectiveElem);
11509 var container = createTag("div");
11510 styleDiv(container);
11511 if (type === "3d") {
11512 style = perspectiveElem.style;
11513 style.width = this.globalData.compSize.w + "px";
11514 style.height = this.globalData.compSize.h + "px";
11515 var center = "50% 50%";
11516 style.webkitTransformOrigin = center;
11517 style.mozTransformOrigin = center;
11518 style.transformOrigin = center;
11519 containerStyle = container.style;
11520 var matrix = "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)";
11521 containerStyle.transform = matrix;
11522 containerStyle.webkitTransform = matrix;
11523 }
11524 perspectiveElem.appendChild(container);
11525 var threeDContainerData = {
11526 container,
11527 perspectiveElem,
11528 startPos: pos,
11529 endPos: pos,
11530 type
11531 };
11532 this.threeDElements.push(threeDContainerData);
11533 return threeDContainerData;
11534 };
11535 HybridRendererBase.prototype.build3dContainers = function() {
11536 var i;
11537 var len = this.layers.length;
11538 var lastThreeDContainerData;
11539 var currentContainer = "";
11540 for (i = 0; i < len; i += 1) if (this.layers[i].ddd && this.layers[i].ty !== 3) {
11541 if (currentContainer !== "3d") {
11542 currentContainer = "3d";
11543 lastThreeDContainerData = this.createThreeDContainer(i, "3d");
11544 }
11545 lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
11546 } else {
11547 if (currentContainer !== "2d") {
11548 currentContainer = "2d";
11549 lastThreeDContainerData = this.createThreeDContainer(i, "2d");
11550 }
11551 lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
11552 }
11553 len = this.threeDElements.length;
11554 for (i = len - 1; i >= 0; i -= 1) this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem);
11555 };
11556 HybridRendererBase.prototype.addTo3dContainer = function(elem, pos) {
11557 var i = 0;
11558 var len = this.threeDElements.length;
11559 while (i < len) {
11560 if (pos <= this.threeDElements[i].endPos) {
11561 var j = this.threeDElements[i].startPos;
11562 var nextElement;
11563 while (j < pos) {
11564 if (this.elements[j] && this.elements[j].getBaseElement) nextElement = this.elements[j].getBaseElement();
11565 j += 1;
11566 }
11567 if (nextElement) this.threeDElements[i].container.insertBefore(elem, nextElement);
11568 else this.threeDElements[i].container.appendChild(elem);
11569 break;
11570 }
11571 i += 1;
11572 }
11573 };
11574 HybridRendererBase.prototype.configAnimation = function(animData) {
11575 var resizerElem = createTag("div");
11576 var wrapper = this.animationItem.wrapper;
11577 var style = resizerElem.style;
11578 style.width = animData.w + "px";
11579 style.height = animData.h + "px";
11580 this.resizerElem = resizerElem;
11581 styleDiv(resizerElem);
11582 style.transformStyle = "flat";
11583 style.mozTransformStyle = "flat";
11584 style.webkitTransformStyle = "flat";
11585 if (this.renderConfig.className) resizerElem.setAttribute("class", this.renderConfig.className);
11586 wrapper.appendChild(resizerElem);
11587 style.overflow = "hidden";
11588 var svg = createNS("svg");
11589 svg.setAttribute("width", "1");
11590 svg.setAttribute("height", "1");
11591 styleDiv(svg);
11592 this.resizerElem.appendChild(svg);
11593 var defs = createNS("defs");
11594 svg.appendChild(defs);
11595 this.data = animData;
11596 this.setupGlobalData(animData, svg);
11597 this.globalData.defs = defs;
11598 this.layers = animData.layers;
11599 this.layerElement = this.resizerElem;
11600 this.build3dContainers();
11601 this.updateContainerSize();
11602 };
11603 HybridRendererBase.prototype.destroy = function() {
11604 if (this.animationItem.wrapper) this.animationItem.wrapper.innerText = "";
11605 this.animationItem.container = null;
11606 this.globalData.defs = null;
11607 var i;
11608 var len = this.layers ? this.layers.length : 0;
11609 for (i = 0; i < len; i += 1) if (this.elements[i] && this.elements[i].destroy) this.elements[i].destroy();
11610 this.elements.length = 0;
11611 this.destroyed = true;
11612 this.animationItem = null;
11613 };
11614 HybridRendererBase.prototype.updateContainerSize = function() {
11615 var elementWidth = this.animationItem.wrapper.offsetWidth;
11616 var elementHeight = this.animationItem.wrapper.offsetHeight;
11617 var elementRel = elementWidth / elementHeight;
11618 var animationRel = this.globalData.compSize.w / this.globalData.compSize.h;
11619 var sx;
11620 var sy;
11621 var tx;
11622 var ty;
11623 if (animationRel > elementRel) {
11624 sx = elementWidth / this.globalData.compSize.w;
11625 sy = elementWidth / this.globalData.compSize.w;
11626 tx = 0;
11627 ty = (elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2;
11628 } else {
11629 sx = elementHeight / this.globalData.compSize.h;
11630 sy = elementHeight / this.globalData.compSize.h;
11631 tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2;
11632 ty = 0;
11633 }
11634 var style = this.resizerElem.style;
11635 style.webkitTransform = "matrix3d(" + sx + ",0,0,0,0," + sy + ",0,0,0,0,1,0," + tx + "," + ty + ",0,1)";
11636 style.transform = style.webkitTransform;
11637 };
11638 HybridRendererBase.prototype.renderFrame = SVGRenderer.prototype.renderFrame;
11639 HybridRendererBase.prototype.hide = function() {
11640 this.resizerElem.style.display = "none";
11641 };
11642 HybridRendererBase.prototype.show = function() {
11643 this.resizerElem.style.display = "block";
11644 };
11645 HybridRendererBase.prototype.initItems = function() {
11646 this.buildAllItems();
11647 if (this.camera) this.camera.setup();
11648 else {
11649 var cWidth = this.globalData.compSize.w;
11650 var cHeight = this.globalData.compSize.h;
11651 var i;
11652 var len = this.threeDElements.length;
11653 for (i = 0; i < len; i += 1) {
11654 var style = this.threeDElements[i].perspectiveElem.style;
11655 style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + "px";
11656 style.perspective = style.webkitPerspective;
11657 }
11658 }
11659 };
11660 HybridRendererBase.prototype.searchExtraCompositions = function(assets) {
11661 var i;
11662 var len = assets.length;
11663 var floatingContainer = createTag("div");
11664 for (i = 0; i < len; i += 1) if (assets[i].xt) {
11665 var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null);
11666 comp.initExpressions();
11667 this.globalData.projectInterface.registerComposition(comp);
11668 }
11669 };
11670 function HCompElement(data, globalData, comp) {
11671 this.layers = data.layers;
11672 this.supports3d = !data.hasMask;
11673 this.completeLayers = false;
11674 this.pendingElements = [];
11675 this.elements = this.layers ? createSizedArray(this.layers.length) : [];
11676 this.initElement(data, globalData, comp);
11677 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
11678 }
11679 extendPrototype([
11680 HybridRendererBase,
11681 ICompElement,
11682 HBaseElement
11683 ], HCompElement);
11684 HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
11685 HCompElement.prototype.createContainerElements = function() {
11686 this._createBaseContainerElements();
11687 if (this.data.hasMask) {
11688 this.svgElement.setAttribute("width", this.data.w);
11689 this.svgElement.setAttribute("height", this.data.h);
11690 this.transformedElement = this.baseElement;
11691 } else this.transformedElement = this.layerElement;
11692 };
11693 HCompElement.prototype.addTo3dContainer = function(elem, pos) {
11694 var j = 0;
11695 var nextElement;
11696 while (j < pos) {
11697 if (this.elements[j] && this.elements[j].getBaseElement) nextElement = this.elements[j].getBaseElement();
11698 j += 1;
11699 }
11700 if (nextElement) this.layerElement.insertBefore(elem, nextElement);
11701 else this.layerElement.appendChild(elem);
11702 };
11703 HCompElement.prototype.createComp = function(data) {
11704 if (!this.supports3d) return new SVGCompElement(data, this.globalData, this);
11705 return new HCompElement(data, this.globalData, this);
11706 };
11707 function HybridRenderer(animationItem, config) {
11708 this.animationItem = animationItem;
11709 this.layers = null;
11710 this.renderedFrame = -1;
11711 this.renderConfig = {
11712 className: config && config.className || "",
11713 imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || "xMidYMid slice",
11714 hideOnTransparent: !(config && config.hideOnTransparent === false),
11715 filterSize: {
11716 width: config && config.filterSize && config.filterSize.width || "400%",
11717 height: config && config.filterSize && config.filterSize.height || "400%",
11718 x: config && config.filterSize && config.filterSize.x || "-100%",
11719 y: config && config.filterSize && config.filterSize.y || "-100%"
11720 },
11721 runExpressions: !config || config.runExpressions === void 0 || config.runExpressions
11722 };
11723 this.globalData = {
11724 _mdf: false,
11725 frameNum: -1,
11726 renderConfig: this.renderConfig
11727 };
11728 this.pendingElements = [];
11729 this.elements = [];
11730 this.threeDElements = [];
11731 this.destroyed = false;
11732 this.camera = null;
11733 this.supports3d = true;
11734 this.rendererType = "html";
11735 }
11736 extendPrototype([HybridRendererBase], HybridRenderer);
11737 HybridRenderer.prototype.createComp = function(data) {
11738 if (!this.supports3d) return new SVGCompElement(data, this.globalData, this);
11739 return new HCompElement(data, this.globalData, this);
11740 };
11741 var CompExpressionInterface = function() {
11742 return function(comp) {
11743 function _thisLayerFunction(name) {
11744 var i = 0;
11745 var len = comp.layers.length;
11746 while (i < len) {
11747 if (comp.layers[i].nm === name || comp.layers[i].ind === name) return comp.elements[i].layerInterface;
11748 i += 1;
11749 }
11750 return null;
11751 }
11752 Object.defineProperty(_thisLayerFunction, "_name", { value: comp.data.nm });
11753 _thisLayerFunction.layer = _thisLayerFunction;
11754 _thisLayerFunction.pixelAspect = 1;
11755 _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
11756 _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
11757 _thisLayerFunction.pixelAspect = 1;
11758 _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
11759 _thisLayerFunction.displayStartTime = 0;
11760 _thisLayerFunction.numLayers = comp.layers.length;
11761 return _thisLayerFunction;
11762 };
11763 }();
11764 function _typeof$2(o) {
11765 "@babel/helpers - typeof";
11766 return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
11767 return typeof o;
11768 } : function(o) {
11769 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
11770 }, _typeof$2(o);
11771 }
11772 function seedRandom(pool, math) {
11773 var global = this;
11774 var width = 256;
11775 var chunks = 6;
11776 var digits = 52;
11777 var rngname = "random";
11778 var startdenom = math.pow(width, chunks);
11779 var significance = math.pow(2, digits);
11780 var overflow = significance * 2;
11781 var mask = width - 1;
11782 var nodecrypto;
11783 function seedrandom(seed, options, callback) {
11784 var key = [];
11785 options = options === true ? { entropy: true } : options || {};
11786 var shortseed = mixkey(flatten(options.entropy ? [seed, tostring(pool)] : seed === null ? autoseed() : seed, 3), key);
11787 var arc4 = new ARC4(key);
11788 var prng = function prng() {
11789 var n = arc4.g(chunks);
11790 var d = startdenom;
11791 var x = 0;
11792 while (n < significance) {
11793 n = (n + x) * width;
11794 d *= width;
11795 x = arc4.g(1);
11796 }
11797 while (n >= overflow) {
11798 n /= 2;
11799 d /= 2;
11800 x >>>= 1;
11801 }
11802 return (n + x) / d;
11803 };
11804 prng.int32 = function() {
11805 return arc4.g(4) | 0;
11806 };
11807 prng.quick = function() {
11808 return arc4.g(4) / 4294967296;
11809 };
11810 prng["double"] = prng;
11811 mixkey(tostring(arc4.S), pool);
11812 return (options.pass || callback || function(prng, seed, is_math_call, state) {
11813 if (state) {
11814 if (state.S) copy(state, arc4);
11815 prng.state = function() {
11816 return copy(arc4, {});
11817 };
11818 }
11819 if (is_math_call) {
11820 math[rngname] = prng;
11821 return seed;
11822 } else return prng;
11823 })(prng, shortseed, "global" in options ? options.global : this == math, options.state);
11824 }
11825 math["seed" + rngname] = seedrandom;
11826 function ARC4(key) {
11827 var t;
11828 var keylen = key.length;
11829 var me = this;
11830 var i = 0;
11831 var j = me.i = me.j = 0;
11832 var s = me.S = [];
11833 if (!keylen) key = [keylen++];
11834 while (i < width) s[i] = i++;
11835 for (i = 0; i < width; i++) {
11836 s[i] = s[j = mask & j + key[i % keylen] + (t = s[i])];
11837 s[j] = t;
11838 }
11839 me.g = function(count) {
11840 var t;
11841 var r = 0;
11842 var i = me.i;
11843 var j = me.j;
11844 var s = me.S;
11845 while (count--) {
11846 t = s[i = mask & i + 1];
11847 r = r * width + s[mask & (s[i] = s[j = mask & j + t]) + (s[j] = t)];
11848 }
11849 me.i = i;
11850 me.j = j;
11851 return r;
11852 };
11853 }
11854 function copy(f, t) {
11855 t.i = f.i;
11856 t.j = f.j;
11857 t.S = f.S.slice();
11858 return t;
11859 }
11860 function flatten(obj, depth) {
11861 var result = [];
11862 var typ = _typeof$2(obj);
11863 var prop;
11864 if (depth && typ == "object") for (prop in obj) try {
11865 result.push(flatten(obj[prop], depth - 1));
11866 } catch (e) {}
11867 return result.length ? result : typ == "string" ? obj : obj + "\0";
11868 }
11869 function mixkey(seed, key) {
11870 var stringseed = seed + "";
11871 var smear;
11872 var j = 0;
11873 while (j < stringseed.length) key[mask & j] = mask & (smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++);
11874 return tostring(key);
11875 }
11876 function autoseed() {
11877 try {
11878 if (nodecrypto) return tostring(nodecrypto.randomBytes(width));
11879 var out = new Uint8Array(width);
11880 (global.crypto || global.msCrypto).getRandomValues(out);
11881 return tostring(out);
11882 } catch (e) {
11883 var browser = global.navigator;
11884 var plugins = browser && browser.plugins;
11885 return [
11886 +/* @__PURE__ */ new Date(),
11887 global,
11888 plugins,
11889 global.screen,
11890 tostring(pool)
11891 ];
11892 }
11893 }
11894 function tostring(a) {
11895 return String.fromCharCode.apply(0, a);
11896 }
11897 mixkey(math.random(), pool);
11898 }
11899 function initialize$2(BMMath) {
11900 seedRandom([], BMMath);
11901 }
11902 var propTypes = { SHAPE: "shape" };
11903 function _typeof$1(o) {
11904 "@babel/helpers - typeof";
11905 return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
11906 return typeof o;
11907 } : function(o) {
11908 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
11909 }, _typeof$1(o);
11910 }
11911 var ExpressionManager = function() {
11912 "use strict";
11913 var ob = {};
11914 var Math = BMMath;
11915 var window = null;
11916 var document = null;
11917 var XMLHttpRequest = null;
11918 var fetch = null;
11919 var frames = null;
11920 var _lottieGlobal = {};
11921 initialize$2(BMMath);
11922 function resetFrame() {
11923 _lottieGlobal = {};
11924 }
11925 function $bm_isInstanceOfArray(arr) {
11926 return arr.constructor === Array || arr.constructor === Float32Array;
11927 }
11928 function isNumerable(tOfV, v) {
11929 return tOfV === "number" || v instanceof Number || tOfV === "boolean" || tOfV === "string";
11930 }
11931 function $bm_neg(a) {
11932 var tOfA = _typeof$1(a);
11933 if (tOfA === "number" || a instanceof Number || tOfA === "boolean") return -a;
11934 if ($bm_isInstanceOfArray(a)) {
11935 var i;
11936 var lenA = a.length;
11937 var retArr = [];
11938 for (i = 0; i < lenA; i += 1) retArr[i] = -a[i];
11939 return retArr;
11940 }
11941 if (a.propType) return a.v;
11942 return -a;
11943 }
11944 var easeInBez = BezierFactory.getBezierEasing(.333, 0, .833, .833, "easeIn").get;
11945 var easeOutBez = BezierFactory.getBezierEasing(.167, .167, .667, 1, "easeOut").get;
11946 var easeInOutBez = BezierFactory.getBezierEasing(.33, 0, .667, 1, "easeInOut").get;
11947 function sum(a, b) {
11948 var tOfA = _typeof$1(a);
11949 var tOfB = _typeof$1(b);
11950 if (isNumerable(tOfA, a) && isNumerable(tOfB, b) || tOfA === "string" || tOfB === "string") return a + b;
11951 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
11952 a = a.slice(0);
11953 a[0] += b;
11954 return a;
11955 }
11956 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
11957 b = b.slice(0);
11958 b[0] = a + b[0];
11959 return b;
11960 }
11961 if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
11962 var i = 0;
11963 var lenA = a.length;
11964 var lenB = b.length;
11965 var retArr = [];
11966 while (i < lenA || i < lenB) {
11967 if ((typeof a[i] === "number" || a[i] instanceof Number) && (typeof b[i] === "number" || b[i] instanceof Number)) retArr[i] = a[i] + b[i];
11968 else retArr[i] = b[i] === void 0 ? a[i] : a[i] || b[i];
11969 i += 1;
11970 }
11971 return retArr;
11972 }
11973 return 0;
11974 }
11975 var add = sum;
11976 function sub(a, b) {
11977 var tOfA = _typeof$1(a);
11978 var tOfB = _typeof$1(b);
11979 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
11980 if (tOfA === "string") a = parseInt(a, 10);
11981 if (tOfB === "string") b = parseInt(b, 10);
11982 return a - b;
11983 }
11984 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
11985 a = a.slice(0);
11986 a[0] -= b;
11987 return a;
11988 }
11989 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
11990 b = b.slice(0);
11991 b[0] = a - b[0];
11992 return b;
11993 }
11994 if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
11995 var i = 0;
11996 var lenA = a.length;
11997 var lenB = b.length;
11998 var retArr = [];
11999 while (i < lenA || i < lenB) {
12000 if ((typeof a[i] === "number" || a[i] instanceof Number) && (typeof b[i] === "number" || b[i] instanceof Number)) retArr[i] = a[i] - b[i];
12001 else retArr[i] = b[i] === void 0 ? a[i] : a[i] || b[i];
12002 i += 1;
12003 }
12004 return retArr;
12005 }
12006 return 0;
12007 }
12008 function mul(a, b) {
12009 var tOfA = _typeof$1(a);
12010 var tOfB = _typeof$1(b);
12011 var arr;
12012 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) return a * b;
12013 var i;
12014 var len;
12015 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
12016 len = a.length;
12017 arr = createTypedArray("float32", len);
12018 for (i = 0; i < len; i += 1) arr[i] = a[i] * b;
12019 return arr;
12020 }
12021 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
12022 len = b.length;
12023 arr = createTypedArray("float32", len);
12024 for (i = 0; i < len; i += 1) arr[i] = a * b[i];
12025 return arr;
12026 }
12027 return 0;
12028 }
12029 function div(a, b) {
12030 var tOfA = _typeof$1(a);
12031 var tOfB = _typeof$1(b);
12032 var arr;
12033 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) return a / b;
12034 var i;
12035 var len;
12036 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
12037 len = a.length;
12038 arr = createTypedArray("float32", len);
12039 for (i = 0; i < len; i += 1) arr[i] = a[i] / b;
12040 return arr;
12041 }
12042 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
12043 len = b.length;
12044 arr = createTypedArray("float32", len);
12045 for (i = 0; i < len; i += 1) arr[i] = a / b[i];
12046 return arr;
12047 }
12048 return 0;
12049 }
12050 function mod(a, b) {
12051 if (typeof a === "string") a = parseInt(a, 10);
12052 if (typeof b === "string") b = parseInt(b, 10);
12053 return a % b;
12054 }
12055 var $bm_sum = sum;
12056 var $bm_sub = sub;
12057 var $bm_mul = mul;
12058 var $bm_div = div;
12059 var $bm_mod = mod;
12060 function clamp(num, min, max) {
12061 if (min > max) {
12062 var mm = max;
12063 max = min;
12064 min = mm;
12065 }
12066 return Math.min(Math.max(num, min), max);
12067 }
12068 function radiansToDegrees(val) {
12069 return val / degToRads;
12070 }
12071 var radians_to_degrees = radiansToDegrees;
12072 function degreesToRadians(val) {
12073 return val * degToRads;
12074 }
12075 var degrees_to_radians = radiansToDegrees;
12076 var helperLengthArray = [
12077 0,
12078 0,
12079 0,
12080 0,
12081 0,
12082 0
12083 ];
12084 function length(arr1, arr2) {
12085 if (typeof arr1 === "number" || arr1 instanceof Number) {
12086 arr2 = arr2 || 0;
12087 return Math.abs(arr1 - arr2);
12088 }
12089 if (!arr2) arr2 = helperLengthArray;
12090 var i;
12091 var len = Math.min(arr1.length, arr2.length);
12092 var addedLength = 0;
12093 for (i = 0; i < len; i += 1) addedLength += Math.pow(arr2[i] - arr1[i], 2);
12094 return Math.sqrt(addedLength);
12095 }
12096 function normalize(vec) {
12097 return div(vec, length(vec));
12098 }
12099 function rgbToHsl(val) {
12100 var r = val[0];
12101 var g = val[1];
12102 var b = val[2];
12103 var max = Math.max(r, g, b);
12104 var min = Math.min(r, g, b);
12105 var h;
12106 var s;
12107 var l = (max + min) / 2;
12108 if (max === min) {
12109 h = 0;
12110 s = 0;
12111 } else {
12112 var d = max - min;
12113 s = l > .5 ? d / (2 - max - min) : d / (max + min);
12114 switch (max) {
12115 case r:
12116 h = (g - b) / d + (g < b ? 6 : 0);
12117 break;
12118 case g:
12119 h = (b - r) / d + 2;
12120 break;
12121 case b:
12122 h = (r - g) / d + 4;
12123 break;
12124 default: break;
12125 }
12126 h /= 6;
12127 }
12128 return [
12129 h,
12130 s,
12131 l,
12132 val[3]
12133 ];
12134 }
12135 function hue2rgb(p, q, t) {
12136 if (t < 0) t += 1;
12137 if (t > 1) t -= 1;
12138 if (t < 1 / 6) return p + (q - p) * 6 * t;
12139 if (t < 1 / 2) return q;
12140 if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
12141 return p;
12142 }
12143 function hslToRgb(val) {
12144 var h = val[0];
12145 var s = val[1];
12146 var l = val[2];
12147 var r;
12148 var g;
12149 var b;
12150 if (s === 0) {
12151 r = l;
12152 b = l;
12153 g = l;
12154 } else {
12155 var q = l < .5 ? l * (1 + s) : l + s - l * s;
12156 var p = 2 * l - q;
12157 r = hue2rgb(p, q, h + 1 / 3);
12158 g = hue2rgb(p, q, h);
12159 b = hue2rgb(p, q, h - 1 / 3);
12160 }
12161 return [
12162 r,
12163 g,
12164 b,
12165 val[3]
12166 ];
12167 }
12168 function linear(t, tMin, tMax, value1, value2) {
12169 if (value1 === void 0 || value2 === void 0) {
12170 value1 = tMin;
12171 value2 = tMax;
12172 tMin = 0;
12173 tMax = 1;
12174 }
12175 if (tMax < tMin) {
12176 var _tMin = tMax;
12177 tMax = tMin;
12178 tMin = _tMin;
12179 }
12180 if (t <= tMin) return value1;
12181 if (t >= tMax) return value2;
12182 var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
12183 if (!value1.length) return value1 + (value2 - value1) * perc;
12184 var i;
12185 var len = value1.length;
12186 var arr = createTypedArray("float32", len);
12187 for (i = 0; i < len; i += 1) arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
12188 return arr;
12189 }
12190 function random(min, max) {
12191 if (max === void 0) if (min === void 0) {
12192 min = 0;
12193 max = 1;
12194 } else {
12195 max = min;
12196 min = void 0;
12197 }
12198 if (max.length) {
12199 var i;
12200 var len = max.length;
12201 if (!min) min = createTypedArray("float32", len);
12202 var arr = createTypedArray("float32", len);
12203 var rnd = BMMath.random();
12204 for (i = 0; i < len; i += 1) arr[i] = min[i] + rnd * (max[i] - min[i]);
12205 return arr;
12206 }
12207 if (min === void 0) min = 0;
12208 var rndm = BMMath.random();
12209 return min + rndm * (max - min);
12210 }
12211 function createPath(points, inTangents, outTangents, closed) {
12212 var i;
12213 var len = points.length;
12214 var path = shapePool.newElement();
12215 path.setPathData(!!closed, len);
12216 var arrPlaceholder = [0, 0];
12217 var inVertexPoint;
12218 var outVertexPoint;
12219 for (i = 0; i < len; i += 1) {
12220 inVertexPoint = inTangents && inTangents[i] ? inTangents[i] : arrPlaceholder;
12221 outVertexPoint = outTangents && outTangents[i] ? outTangents[i] : arrPlaceholder;
12222 path.setTripleAt(points[i][0], points[i][1], outVertexPoint[0] + points[i][0], outVertexPoint[1] + points[i][1], inVertexPoint[0] + points[i][0], inVertexPoint[1] + points[i][1], i, true);
12223 }
12224 return path;
12225 }
12226 function initiateExpression(elem, data, property) {
12227 function noOp(_value) {
12228 return _value;
12229 }
12230 if (!elem.globalData.renderConfig.runExpressions) return noOp;
12231 var val = data.x;
12232 var needsVelocity = /velocity(?![\w\d])/.test(val);
12233 var _needsRandom = val.indexOf("random") !== -1;
12234 var elemType = elem.data.ty;
12235 var transform;
12236 var $bm_transform;
12237 var content;
12238 var effect;
12239 var thisProperty = property;
12240 thisProperty._name = elem.data.nm;
12241 thisProperty.valueAtTime = thisProperty.getValueAtTime;
12242 Object.defineProperty(thisProperty, "value", { get: function get() {
12243 return thisProperty.v;
12244 } });
12245 elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
12246 elem.comp.displayStartTime = 0;
12247 var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
12248 var outPoint = elem.data.op / elem.comp.globalData.frameRate;
12249 var width = elem.data.sw ? elem.data.sw : 0;
12250 var height = elem.data.sh ? elem.data.sh : 0;
12251 var name = elem.data.nm;
12252 var loopIn;
12253 var loop_in;
12254 var loopOut;
12255 var loop_out;
12256 var smooth;
12257 var toWorld;
12258 var fromWorld;
12259 var fromComp;
12260 var toComp;
12261 var fromCompToSurface;
12262 var position;
12263 var rotation;
12264 var anchorPoint;
12265 var scale;
12266 var thisLayer;
12267 var thisComp;
12268 var mask;
12269 var valueAtTime;
12270 var velocityAtTime;
12271 var scoped_bm_rt;
12272 var expression_function = eval("[function _expression_function(){" + val + ";scoped_bm_rt=$bm_rt}]")[0];
12273 var numKeys = property.kf ? data.k.length : 0;
12274 var active = !this.data || this.data.hd !== true;
12275 var wiggle = function wiggle(freq, amp) {
12276 var iWiggle;
12277 var j;
12278 var lenWiggle = this.pv.length ? this.pv.length : 1;
12279 var addedAmps = createTypedArray("float32", lenWiggle);
12280 freq = 5;
12281 var iterations = Math.floor(time * freq);
12282 iWiggle = 0;
12283 j = 0;
12284 while (iWiggle < iterations) {
12285 for (j = 0; j < lenWiggle; j += 1) addedAmps[j] += -amp + amp * 2 * BMMath.random();
12286 iWiggle += 1;
12287 }
12288 var periods = time * freq;
12289 var perc = periods - Math.floor(periods);
12290 var arr = createTypedArray("float32", lenWiggle);
12291 if (lenWiggle > 1) {
12292 for (j = 0; j < lenWiggle; j += 1) arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
12293 return arr;
12294 }
12295 return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
12296 }.bind(this);
12297 if (thisProperty.loopIn) {
12298 loopIn = thisProperty.loopIn.bind(thisProperty);
12299 loop_in = loopIn;
12300 }
12301 if (thisProperty.loopOut) {
12302 loopOut = thisProperty.loopOut.bind(thisProperty);
12303 loop_out = loopOut;
12304 }
12305 if (thisProperty.smooth) smooth = thisProperty.smooth.bind(thisProperty);
12306 function loopInDuration(type, duration) {
12307 return loopIn(type, duration, true);
12308 }
12309 function loopOutDuration(type, duration) {
12310 return loopOut(type, duration, true);
12311 }
12312 if (this.getValueAtTime) valueAtTime = this.getValueAtTime.bind(this);
12313 if (this.getVelocityAtTime) velocityAtTime = this.getVelocityAtTime.bind(this);
12314 var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
12315 function lookAt(elem1, elem2) {
12316 var fVec = [
12317 elem2[0] - elem1[0],
12318 elem2[1] - elem1[1],
12319 elem2[2] - elem1[2]
12320 ];
12321 var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
12322 return [
12323 -Math.atan2(fVec[1], fVec[2]) / degToRads,
12324 pitch,
12325 0
12326 ];
12327 }
12328 function easeOut(t, tMin, tMax, val1, val2) {
12329 return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
12330 }
12331 function easeIn(t, tMin, tMax, val1, val2) {
12332 return applyEase(easeInBez, t, tMin, tMax, val1, val2);
12333 }
12334 function ease(t, tMin, tMax, val1, val2) {
12335 return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
12336 }
12337 function applyEase(fn, t, tMin, tMax, val1, val2) {
12338 if (val1 === void 0) {
12339 val1 = tMin;
12340 val2 = tMax;
12341 } else t = (t - tMin) / (tMax - tMin);
12342 if (t > 1) t = 1;
12343 else if (t < 0) t = 0;
12344 var mult = fn(t);
12345 if ($bm_isInstanceOfArray(val1)) {
12346 var iKey;
12347 var lenKey = val1.length;
12348 var arr = createTypedArray("float32", lenKey);
12349 for (iKey = 0; iKey < lenKey; iKey += 1) arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
12350 return arr;
12351 }
12352 return (val2 - val1) * mult + val1;
12353 }
12354 function nearestKey(time) {
12355 var iKey;
12356 var lenKey = data.k.length;
12357 var index;
12358 var keyTime;
12359 if (!data.k.length || typeof data.k[0] === "number") {
12360 index = 0;
12361 keyTime = 0;
12362 } else {
12363 index = -1;
12364 time *= elem.comp.globalData.frameRate;
12365 if (time < data.k[0].t) {
12366 index = 1;
12367 keyTime = data.k[0].t;
12368 } else {
12369 for (iKey = 0; iKey < lenKey - 1; iKey += 1) if (time === data.k[iKey].t) {
12370 index = iKey + 1;
12371 keyTime = data.k[iKey].t;
12372 break;
12373 } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
12374 if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
12375 index = iKey + 2;
12376 keyTime = data.k[iKey + 1].t;
12377 } else {
12378 index = iKey + 1;
12379 keyTime = data.k[iKey].t;
12380 }
12381 break;
12382 }
12383 if (index === -1) {
12384 index = iKey + 1;
12385 keyTime = data.k[iKey].t;
12386 }
12387 }
12388 }
12389 var obKey = {};
12390 obKey.index = index;
12391 obKey.time = keyTime / elem.comp.globalData.frameRate;
12392 return obKey;
12393 }
12394 function key(ind) {
12395 var obKey;
12396 var iKey;
12397 var lenKey;
12398 if (!data.k.length || typeof data.k[0] === "number") throw new Error("The property has no keyframe at index " + ind);
12399 ind -= 1;
12400 obKey = {
12401 time: data.k[ind].t / elem.comp.globalData.frameRate,
12402 value: []
12403 };
12404 var arr = Object.prototype.hasOwnProperty.call(data.k[ind], "s") ? data.k[ind].s : data.k[ind - 1].e;
12405 lenKey = arr.length;
12406 for (iKey = 0; iKey < lenKey; iKey += 1) {
12407 obKey[iKey] = arr[iKey];
12408 obKey.value[iKey] = arr[iKey];
12409 }
12410 return obKey;
12411 }
12412 function framesToTime(fr, fps) {
12413 if (!fps) fps = elem.comp.globalData.frameRate;
12414 return fr / fps;
12415 }
12416 function timeToFrames(t, fps) {
12417 if (!t && t !== 0) t = time;
12418 if (!fps) fps = elem.comp.globalData.frameRate;
12419 return t * fps;
12420 }
12421 function seedRandom(seed) {
12422 BMMath.seedrandom(randSeed + seed);
12423 }
12424 function sourceRectAtTime() {
12425 return elem.sourceRectAtTime();
12426 }
12427 function substring(init, end) {
12428 if (typeof value === "string") {
12429 if (end === void 0) return value.substring(init);
12430 return value.substring(init, end);
12431 }
12432 return "";
12433 }
12434 function substr(init, end) {
12435 if (typeof value === "string") {
12436 if (end === void 0) return value.substr(init);
12437 return value.substr(init, end);
12438 }
12439 return "";
12440 }
12441 function posterizeTime(framesPerSecond) {
12442 time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
12443 value = valueAtTime(time);
12444 }
12445 var time;
12446 var velocity;
12447 var value;
12448 var text;
12449 var textIndex;
12450 var textTotal;
12451 var selectorValue;
12452 var index = elem.data.ind;
12453 var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
12454 var parent;
12455 var randSeed = Math.floor(Math.random() * 1e6);
12456 var globalData = elem.globalData;
12457 function executeExpression(_value) {
12458 value = _value;
12459 if (this.frameExpressionId === elem.globalData.frameId && this.propType !== "textSelector") return value;
12460 if (this.propType === "textSelector") {
12461 textIndex = this.textIndex;
12462 textTotal = this.textTotal;
12463 selectorValue = this.selectorValue;
12464 }
12465 if (!thisLayer) {
12466 text = elem.layerInterface.text;
12467 thisLayer = elem.layerInterface;
12468 thisComp = elem.comp.compInterface;
12469 toWorld = thisLayer.toWorld.bind(thisLayer);
12470 fromWorld = thisLayer.fromWorld.bind(thisLayer);
12471 fromComp = thisLayer.fromComp.bind(thisLayer);
12472 toComp = thisLayer.toComp.bind(thisLayer);
12473 mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
12474 fromCompToSurface = fromComp;
12475 }
12476 if (!transform) {
12477 transform = elem.layerInterface("ADBE Transform Group");
12478 $bm_transform = transform;
12479 if (transform) anchorPoint = transform.anchorPoint;
12480 }
12481 if (elemType === 4 && !content) content = thisLayer("ADBE Root Vectors Group");
12482 if (!effect) effect = thisLayer(4);
12483 hasParent = !!(elem.hierarchy && elem.hierarchy.length);
12484 if (hasParent && !parent) parent = elem.hierarchy[0].layerInterface;
12485 time = this.comp.renderedFrame / this.comp.globalData.frameRate;
12486 if (_needsRandom) seedRandom(randSeed + time);
12487 if (needsVelocity) velocity = velocityAtTime(time);
12488 expression_function();
12489 this.frameExpressionId = elem.globalData.frameId;
12490 scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE ? scoped_bm_rt.v : scoped_bm_rt;
12491 return scoped_bm_rt;
12492 }
12493 executeExpression.__preventDeadCodeRemoval = [
12494 $bm_transform,
12495 anchorPoint,
12496 time,
12497 velocity,
12498 inPoint,
12499 outPoint,
12500 width,
12501 height,
12502 name,
12503 loop_in,
12504 loop_out,
12505 smooth,
12506 toComp,
12507 fromCompToSurface,
12508 toWorld,
12509 fromWorld,
12510 mask,
12511 position,
12512 rotation,
12513 scale,
12514 thisComp,
12515 numKeys,
12516 active,
12517 wiggle,
12518 loopInDuration,
12519 loopOutDuration,
12520 comp,
12521 lookAt,
12522 easeOut,
12523 easeIn,
12524 ease,
12525 nearestKey,
12526 key,
12527 text,
12528 textIndex,
12529 textTotal,
12530 selectorValue,
12531 framesToTime,
12532 timeToFrames,
12533 sourceRectAtTime,
12534 substring,
12535 substr,
12536 posterizeTime,
12537 index,
12538 globalData
12539 ];
12540 return executeExpression;
12541 }
12542 ob.initiateExpression = initiateExpression;
12543 ob.__preventDeadCodeRemoval = [
12544 window,
12545 document,
12546 XMLHttpRequest,
12547 fetch,
12548 frames,
12549 $bm_neg,
12550 add,
12551 $bm_sum,
12552 $bm_sub,
12553 $bm_mul,
12554 $bm_div,
12555 $bm_mod,
12556 clamp,
12557 radians_to_degrees,
12558 degreesToRadians,
12559 degrees_to_radians,
12560 normalize,
12561 rgbToHsl,
12562 hslToRgb,
12563 linear,
12564 random,
12565 createPath,
12566 _lottieGlobal
12567 ];
12568 ob.resetFrame = resetFrame;
12569 return ob;
12570 }();
12571 var Expressions = function() {
12572 var ob = {};
12573 ob.initExpressions = initExpressions;
12574 ob.resetFrame = ExpressionManager.resetFrame;
12575 function initExpressions(animation) {
12576 var stackCount = 0;
12577 var registers = [];
12578 function pushExpression() {
12579 stackCount += 1;
12580 }
12581 function popExpression() {
12582 stackCount -= 1;
12583 if (stackCount === 0) releaseInstances();
12584 }
12585 function registerExpressionProperty(expression) {
12586 if (registers.indexOf(expression) === -1) registers.push(expression);
12587 }
12588 function releaseInstances() {
12589 var i;
12590 var len = registers.length;
12591 for (i = 0; i < len; i += 1) registers[i].release();
12592 registers.length = 0;
12593 }
12594 animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
12595 animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
12596 animation.renderer.globalData.pushExpression = pushExpression;
12597 animation.renderer.globalData.popExpression = popExpression;
12598 animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
12599 }
12600 return ob;
12601 }();
12602 var MaskManagerInterface = function() {
12603 function MaskInterface(mask, data) {
12604 this._mask = mask;
12605 this._data = data;
12606 }
12607 Object.defineProperty(MaskInterface.prototype, "maskPath", { get: function get() {
12608 if (this._mask.prop.k) this._mask.prop.getValue();
12609 return this._mask.prop;
12610 } });
12611 Object.defineProperty(MaskInterface.prototype, "maskOpacity", { get: function get() {
12612 if (this._mask.op.k) this._mask.op.getValue();
12613 return this._mask.op.v * 100;
12614 } });
12615 return function MaskManager(maskManager) {
12616 var _masksInterfaces = createSizedArray(maskManager.viewData.length);
12617 var i;
12618 var len = maskManager.viewData.length;
12619 for (i = 0; i < len; i += 1) _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
12620 return function maskFunction(name) {
12621 i = 0;
12622 while (i < len) {
12623 if (maskManager.masksProperties[i].nm === name) return _masksInterfaces[i];
12624 i += 1;
12625 }
12626 return null;
12627 };
12628 };
12629 }();
12630 var ExpressionPropertyInterface = function() {
12631 var defaultUnidimensionalValue = {
12632 pv: 0,
12633 v: 0,
12634 mult: 1
12635 };
12636 var defaultMultidimensionalValue = {
12637 pv: [
12638 0,
12639 0,
12640 0
12641 ],
12642 v: [
12643 0,
12644 0,
12645 0
12646 ],
12647 mult: 1
12648 };
12649 function completeProperty(expressionValue, property, type) {
12650 Object.defineProperty(expressionValue, "velocity", { get: function get() {
12651 return property.getVelocityAtTime(property.comp.currentFrame);
12652 } });
12653 expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
12654 expressionValue.key = function(pos) {
12655 if (!expressionValue.numKeys) return 0;
12656 var value = "";
12657 if ("s" in property.keyframes[pos - 1]) value = property.keyframes[pos - 1].s;
12658 else if ("e" in property.keyframes[pos - 2]) value = property.keyframes[pos - 2].e;
12659 else value = property.keyframes[pos - 2].s;
12660 var valueProp = type === "unidimensional" ? new Number(value) : Object.assign({}, value);
12661 valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate;
12662 valueProp.value = type === "unidimensional" ? value[0] : value;
12663 return valueProp;
12664 };
12665 expressionValue.valueAtTime = property.getValueAtTime;
12666 expressionValue.speedAtTime = property.getSpeedAtTime;
12667 expressionValue.velocityAtTime = property.getVelocityAtTime;
12668 expressionValue.propertyGroup = property.propertyGroup;
12669 }
12670 function UnidimensionalPropertyInterface(property) {
12671 if (!property || !("pv" in property)) property = defaultUnidimensionalValue;
12672 var mult = 1 / property.mult;
12673 var val = property.pv * mult;
12674 var expressionValue = new Number(val);
12675 expressionValue.value = val;
12676 completeProperty(expressionValue, property, "unidimensional");
12677 return function() {
12678 if (property.k) property.getValue();
12679 val = property.v * mult;
12680 if (expressionValue.value !== val) {
12681 expressionValue = new Number(val);
12682 expressionValue.value = val;
12683 expressionValue[0] = val;
12684 completeProperty(expressionValue, property, "unidimensional");
12685 }
12686 return expressionValue;
12687 };
12688 }
12689 function MultidimensionalPropertyInterface(property) {
12690 if (!property || !("pv" in property)) property = defaultMultidimensionalValue;
12691 var mult = 1 / property.mult;
12692 var len = property.data && property.data.l || property.pv.length;
12693 var expressionValue = createTypedArray("float32", len);
12694 var arrValue = createTypedArray("float32", len);
12695 expressionValue.value = arrValue;
12696 completeProperty(expressionValue, property, "multidimensional");
12697 return function() {
12698 if (property.k) property.getValue();
12699 for (var i = 0; i < len; i += 1) {
12700 arrValue[i] = property.v[i] * mult;
12701 expressionValue[i] = arrValue[i];
12702 }
12703 return expressionValue;
12704 };
12705 }
12706 function defaultGetter() {
12707 return defaultUnidimensionalValue;
12708 }
12709 return function(property) {
12710 if (!property) return defaultGetter;
12711 if (property.propType === "unidimensional") return UnidimensionalPropertyInterface(property);
12712 return MultidimensionalPropertyInterface(property);
12713 };
12714 }();
12715 var TransformExpressionInterface = function() {
12716 return function(transform) {
12717 function _thisFunction(name) {
12718 switch (name) {
12719 case "scale":
12720 case "Scale":
12721 case "ADBE Scale":
12722 case 6: return _thisFunction.scale;
12723 case "rotation":
12724 case "Rotation":
12725 case "ADBE Rotation":
12726 case "ADBE Rotate Z":
12727 case 10: return _thisFunction.rotation;
12728 case "ADBE Rotate X": return _thisFunction.xRotation;
12729 case "ADBE Rotate Y": return _thisFunction.yRotation;
12730 case "position":
12731 case "Position":
12732 case "ADBE Position":
12733 case 2: return _thisFunction.position;
12734 case "ADBE Position_0": return _thisFunction.xPosition;
12735 case "ADBE Position_1": return _thisFunction.yPosition;
12736 case "ADBE Position_2": return _thisFunction.zPosition;
12737 case "anchorPoint":
12738 case "AnchorPoint":
12739 case "Anchor Point":
12740 case "ADBE AnchorPoint":
12741 case 1: return _thisFunction.anchorPoint;
12742 case "opacity":
12743 case "Opacity":
12744 case 11: return _thisFunction.opacity;
12745 default: return null;
12746 }
12747 }
12748 Object.defineProperty(_thisFunction, "rotation", { get: ExpressionPropertyInterface(transform.r || transform.rz) });
12749 Object.defineProperty(_thisFunction, "zRotation", { get: ExpressionPropertyInterface(transform.rz || transform.r) });
12750 Object.defineProperty(_thisFunction, "xRotation", { get: ExpressionPropertyInterface(transform.rx) });
12751 Object.defineProperty(_thisFunction, "yRotation", { get: ExpressionPropertyInterface(transform.ry) });
12752 Object.defineProperty(_thisFunction, "scale", { get: ExpressionPropertyInterface(transform.s) });
12753 var _px;
12754 var _py;
12755 var _pz;
12756 var _transformFactory;
12757 if (transform.p) _transformFactory = ExpressionPropertyInterface(transform.p);
12758 else {
12759 _px = ExpressionPropertyInterface(transform.px);
12760 _py = ExpressionPropertyInterface(transform.py);
12761 if (transform.pz) _pz = ExpressionPropertyInterface(transform.pz);
12762 }
12763 Object.defineProperty(_thisFunction, "position", { get: function get() {
12764 if (transform.p) return _transformFactory();
12765 return [
12766 _px(),
12767 _py(),
12768 _pz ? _pz() : 0
12769 ];
12770 } });
12771 Object.defineProperty(_thisFunction, "xPosition", { get: ExpressionPropertyInterface(transform.px) });
12772 Object.defineProperty(_thisFunction, "yPosition", { get: ExpressionPropertyInterface(transform.py) });
12773 Object.defineProperty(_thisFunction, "zPosition", { get: ExpressionPropertyInterface(transform.pz) });
12774 Object.defineProperty(_thisFunction, "anchorPoint", { get: ExpressionPropertyInterface(transform.a) });
12775 Object.defineProperty(_thisFunction, "opacity", { get: ExpressionPropertyInterface(transform.o) });
12776 Object.defineProperty(_thisFunction, "skew", { get: ExpressionPropertyInterface(transform.sk) });
12777 Object.defineProperty(_thisFunction, "skewAxis", { get: ExpressionPropertyInterface(transform.sa) });
12778 Object.defineProperty(_thisFunction, "orientation", { get: ExpressionPropertyInterface(transform.or) });
12779 return _thisFunction;
12780 };
12781 }();
12782 var LayerExpressionInterface = function() {
12783 function getMatrix(time) {
12784 var toWorldMat = new Matrix();
12785 if (time !== void 0) this._elem.finalTransform.mProp.getValueAtTime(time).clone(toWorldMat);
12786 else this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
12787 return toWorldMat;
12788 }
12789 function toWorldVec(arr, time) {
12790 var toWorldMat = this.getMatrix(time);
12791 toWorldMat.props[12] = 0;
12792 toWorldMat.props[13] = 0;
12793 toWorldMat.props[14] = 0;
12794 return this.applyPoint(toWorldMat, arr);
12795 }
12796 function toWorld(arr, time) {
12797 var toWorldMat = this.getMatrix(time);
12798 return this.applyPoint(toWorldMat, arr);
12799 }
12800 function fromWorldVec(arr, time) {
12801 var toWorldMat = this.getMatrix(time);
12802 toWorldMat.props[12] = 0;
12803 toWorldMat.props[13] = 0;
12804 toWorldMat.props[14] = 0;
12805 return this.invertPoint(toWorldMat, arr);
12806 }
12807 function fromWorld(arr, time) {
12808 var toWorldMat = this.getMatrix(time);
12809 return this.invertPoint(toWorldMat, arr);
12810 }
12811 function applyPoint(matrix, arr) {
12812 if (this._elem.hierarchy && this._elem.hierarchy.length) {
12813 var i;
12814 var len = this._elem.hierarchy.length;
12815 for (i = 0; i < len; i += 1) this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
12816 }
12817 return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0);
12818 }
12819 function invertPoint(matrix, arr) {
12820 if (this._elem.hierarchy && this._elem.hierarchy.length) {
12821 var i;
12822 var len = this._elem.hierarchy.length;
12823 for (i = 0; i < len; i += 1) this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
12824 }
12825 return matrix.inversePoint(arr);
12826 }
12827 function fromComp(arr) {
12828 var toWorldMat = new Matrix();
12829 toWorldMat.reset();
12830 this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
12831 if (this._elem.hierarchy && this._elem.hierarchy.length) {
12832 var i;
12833 var len = this._elem.hierarchy.length;
12834 for (i = 0; i < len; i += 1) this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
12835 return toWorldMat.inversePoint(arr);
12836 }
12837 return toWorldMat.inversePoint(arr);
12838 }
12839 function sampleImage() {
12840 return [
12841 1,
12842 1,
12843 1,
12844 1
12845 ];
12846 }
12847 return function(elem) {
12848 var transformInterface;
12849 function _registerMaskInterface(maskManager) {
12850 _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
12851 }
12852 function _registerEffectsInterface(effects) {
12853 _thisLayerFunction.effect = effects;
12854 }
12855 function _thisLayerFunction(name) {
12856 switch (name) {
12857 case "ADBE Root Vectors Group":
12858 case "Contents":
12859 case 2: return _thisLayerFunction.shapeInterface;
12860 case 1:
12861 case 6:
12862 case "Transform":
12863 case "transform":
12864 case "ADBE Transform Group": return transformInterface;
12865 case 4:
12866 case "ADBE Effect Parade":
12867 case "effects":
12868 case "Effects": return _thisLayerFunction.effect;
12869 case "ADBE Text Properties": return _thisLayerFunction.textInterface;
12870 default: return null;
12871 }
12872 }
12873 _thisLayerFunction.getMatrix = getMatrix;
12874 _thisLayerFunction.invertPoint = invertPoint;
12875 _thisLayerFunction.applyPoint = applyPoint;
12876 _thisLayerFunction.toWorld = toWorld;
12877 _thisLayerFunction.toWorldVec = toWorldVec;
12878 _thisLayerFunction.fromWorld = fromWorld;
12879 _thisLayerFunction.fromWorldVec = fromWorldVec;
12880 _thisLayerFunction.toComp = toWorld;
12881 _thisLayerFunction.fromComp = fromComp;
12882 _thisLayerFunction.sampleImage = sampleImage;
12883 _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
12884 _thisLayerFunction._elem = elem;
12885 transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
12886 var anchorPointDescriptor = getDescriptor(transformInterface, "anchorPoint");
12887 Object.defineProperties(_thisLayerFunction, {
12888 hasParent: { get: function get() {
12889 return elem.hierarchy.length;
12890 } },
12891 parent: { get: function get() {
12892 return elem.hierarchy[0].layerInterface;
12893 } },
12894 rotation: getDescriptor(transformInterface, "rotation"),
12895 scale: getDescriptor(transformInterface, "scale"),
12896 position: getDescriptor(transformInterface, "position"),
12897 opacity: getDescriptor(transformInterface, "opacity"),
12898 anchorPoint: anchorPointDescriptor,
12899 anchor_point: anchorPointDescriptor,
12900 transform: { get: function get() {
12901 return transformInterface;
12902 } },
12903 active: { get: function get() {
12904 return elem.isInRange;
12905 } }
12906 });
12907 _thisLayerFunction.startTime = elem.data.st;
12908 _thisLayerFunction.index = elem.data.ind;
12909 _thisLayerFunction.source = elem.data.refId;
12910 _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
12911 _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
12912 _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate;
12913 _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate;
12914 _thisLayerFunction._name = elem.data.nm;
12915 _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
12916 _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
12917 return _thisLayerFunction;
12918 };
12919 }();
12920 var propertyGroupFactory = function() {
12921 return function(interfaceFunction, parentPropertyGroup) {
12922 return function(val) {
12923 val = val === void 0 ? 1 : val;
12924 if (val <= 0) return interfaceFunction;
12925 return parentPropertyGroup(val - 1);
12926 };
12927 };
12928 }();
12929 var PropertyInterface = function() {
12930 return function(propertyName, propertyGroup) {
12931 var interfaceFunction = { _name: propertyName };
12932 function _propertyGroup(val) {
12933 val = val === void 0 ? 1 : val;
12934 if (val <= 0) return interfaceFunction;
12935 return propertyGroup(val - 1);
12936 }
12937 return _propertyGroup;
12938 };
12939 }();
12940 var EffectsExpressionInterface = function() {
12941 var ob = { createEffectsInterface };
12942 function createEffectsInterface(elem, propertyGroup) {
12943 if (elem.effectsManager) {
12944 var effectElements = [];
12945 var effectsData = elem.data.ef;
12946 var i;
12947 var len = elem.effectsManager.effectElements.length;
12948 for (i = 0; i < len; i += 1) effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem));
12949 var effects = elem.data.ef || [];
12950 var groupInterface = function groupInterface(name) {
12951 i = 0;
12952 len = effects.length;
12953 while (i < len) {
12954 if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) return effectElements[i];
12955 i += 1;
12956 }
12957 return null;
12958 };
12959 Object.defineProperty(groupInterface, "numProperties", { get: function get() {
12960 return effects.length;
12961 } });
12962 return groupInterface;
12963 }
12964 return null;
12965 }
12966 function createGroupInterface(data, elements, propertyGroup, elem) {
12967 function groupInterface(name) {
12968 var effects = data.ef;
12969 var i = 0;
12970 var len = effects.length;
12971 while (i < len) {
12972 if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
12973 if (effects[i].ty === 5) return effectElements[i];
12974 return effectElements[i]();
12975 }
12976 i += 1;
12977 }
12978 throw new Error();
12979 }
12980 var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
12981 var effectElements = [];
12982 var i;
12983 var len = data.ef.length;
12984 for (i = 0; i < len; i += 1) if (data.ef[i].ty === 5) effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem));
12985 else effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup));
12986 if (data.mn === "ADBE Color Control") Object.defineProperty(groupInterface, "color", { get: function get() {
12987 return effectElements[0]();
12988 } });
12989 Object.defineProperties(groupInterface, {
12990 numProperties: { get: function get() {
12991 return data.np;
12992 } },
12993 _name: { value: data.nm },
12994 propertyGroup: { value: _propertyGroup }
12995 });
12996 groupInterface.enabled = data.en !== 0;
12997 groupInterface.active = groupInterface.enabled;
12998 return groupInterface;
12999 }
13000 function createValueInterface(element, type, elem, propertyGroup) {
13001 var expressionProperty = ExpressionPropertyInterface(element.p);
13002 function interfaceFunction() {
13003 if (type === 10) return elem.comp.compInterface(element.p.v);
13004 return expressionProperty();
13005 }
13006 if (element.p.setGroupProperty) element.p.setGroupProperty(PropertyInterface("", propertyGroup));
13007 return interfaceFunction;
13008 }
13009 return ob;
13010 }();
13011 var ShapePathInterface = function() {
13012 return function pathInterfaceFactory(shape, view, propertyGroup) {
13013 var prop = view.sh;
13014 function interfaceFunction(val) {
13015 if (val === "Shape" || val === "shape" || val === "Path" || val === "path" || val === "ADBE Vector Shape" || val === 2) return interfaceFunction.path;
13016 return null;
13017 }
13018 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13019 prop.setGroupProperty(PropertyInterface("Path", _propertyGroup));
13020 Object.defineProperties(interfaceFunction, {
13021 path: { get: function get() {
13022 if (prop.k) prop.getValue();
13023 return prop;
13024 } },
13025 shape: { get: function get() {
13026 if (prop.k) prop.getValue();
13027 return prop;
13028 } },
13029 _name: { value: shape.nm },
13030 ix: { value: shape.ix },
13031 propertyIndex: { value: shape.ix },
13032 mn: { value: shape.mn },
13033 propertyGroup: { value: propertyGroup }
13034 });
13035 return interfaceFunction;
13036 };
13037 }();
13038 var ShapeExpressionInterface = function() {
13039 function iterateElements(shapes, view, propertyGroup) {
13040 var arr = [];
13041 var i;
13042 var len = shapes ? shapes.length : 0;
13043 for (i = 0; i < len; i += 1) if (shapes[i].ty === "gr") arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup));
13044 else if (shapes[i].ty === "fl") arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup));
13045 else if (shapes[i].ty === "st") arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup));
13046 else if (shapes[i].ty === "tm") arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup));
13047 else if (shapes[i].ty === "tr") {} else if (shapes[i].ty === "el") arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup));
13048 else if (shapes[i].ty === "sr") arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup));
13049 else if (shapes[i].ty === "sh") arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup));
13050 else if (shapes[i].ty === "rc") arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup));
13051 else if (shapes[i].ty === "rd") arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup));
13052 else if (shapes[i].ty === "rp") arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup));
13053 else if (shapes[i].ty === "gf") arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup));
13054 else arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup));
13055 return arr;
13056 }
13057 function contentsInterfaceFactory(shape, view, propertyGroup) {
13058 var interfaces;
13059 var interfaceFunction = function _interfaceFunction(value) {
13060 var i = 0;
13061 var len = interfaces.length;
13062 while (i < len) {
13063 if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) return interfaces[i];
13064 i += 1;
13065 }
13066 if (typeof value === "number") return interfaces[value - 1];
13067 return null;
13068 };
13069 interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13070 interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
13071 interfaceFunction.numProperties = interfaces.length;
13072 interfaceFunction.transform = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
13073 interfaceFunction.propertyIndex = shape.cix;
13074 interfaceFunction._name = shape.nm;
13075 return interfaceFunction;
13076 }
13077 function groupInterfaceFactory(shape, view, propertyGroup) {
13078 var interfaceFunction = function _interfaceFunction(value) {
13079 switch (value) {
13080 case "ADBE Vectors Group":
13081 case "Contents":
13082 case 2: return interfaceFunction.content;
13083 default: return interfaceFunction.transform;
13084 }
13085 };
13086 interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13087 var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup);
13088 var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
13089 interfaceFunction.content = content;
13090 interfaceFunction.transform = transformInterface;
13091 Object.defineProperty(interfaceFunction, "_name", { get: function get() {
13092 return shape.nm;
13093 } });
13094 interfaceFunction.numProperties = shape.np;
13095 interfaceFunction.propertyIndex = shape.ix;
13096 interfaceFunction.nm = shape.nm;
13097 interfaceFunction.mn = shape.mn;
13098 return interfaceFunction;
13099 }
13100 function fillInterfaceFactory(shape, view, propertyGroup) {
13101 function interfaceFunction(val) {
13102 if (val === "Color" || val === "color") return interfaceFunction.color;
13103 if (val === "Opacity" || val === "opacity") return interfaceFunction.opacity;
13104 return null;
13105 }
13106 Object.defineProperties(interfaceFunction, {
13107 color: { get: ExpressionPropertyInterface(view.c) },
13108 opacity: { get: ExpressionPropertyInterface(view.o) },
13109 _name: { value: shape.nm },
13110 mn: { value: shape.mn }
13111 });
13112 view.c.setGroupProperty(PropertyInterface("Color", propertyGroup));
13113 view.o.setGroupProperty(PropertyInterface("Opacity", propertyGroup));
13114 return interfaceFunction;
13115 }
13116 function gradientFillInterfaceFactory(shape, view, propertyGroup) {
13117 function interfaceFunction(val) {
13118 if (val === "Start Point" || val === "start point") return interfaceFunction.startPoint;
13119 if (val === "End Point" || val === "end point") return interfaceFunction.endPoint;
13120 if (val === "Opacity" || val === "opacity") return interfaceFunction.opacity;
13121 return null;
13122 }
13123 Object.defineProperties(interfaceFunction, {
13124 startPoint: { get: ExpressionPropertyInterface(view.s) },
13125 endPoint: { get: ExpressionPropertyInterface(view.e) },
13126 opacity: { get: ExpressionPropertyInterface(view.o) },
13127 type: { get: function get() {
13128 return "a";
13129 } },
13130 _name: { value: shape.nm },
13131 mn: { value: shape.mn }
13132 });
13133 view.s.setGroupProperty(PropertyInterface("Start Point", propertyGroup));
13134 view.e.setGroupProperty(PropertyInterface("End Point", propertyGroup));
13135 view.o.setGroupProperty(PropertyInterface("Opacity", propertyGroup));
13136 return interfaceFunction;
13137 }
13138 function defaultInterfaceFactory() {
13139 function interfaceFunction() {
13140 return null;
13141 }
13142 return interfaceFunction;
13143 }
13144 function strokeInterfaceFactory(shape, view, propertyGroup) {
13145 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13146 var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
13147 function addPropertyToDashOb(i) {
13148 Object.defineProperty(dashOb, shape.d[i].nm, { get: ExpressionPropertyInterface(view.d.dataProps[i].p) });
13149 }
13150 var i;
13151 var len = shape.d ? shape.d.length : 0;
13152 var dashOb = {};
13153 for (i = 0; i < len; i += 1) {
13154 addPropertyToDashOb(i);
13155 view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
13156 }
13157 function interfaceFunction(val) {
13158 if (val === "Color" || val === "color") return interfaceFunction.color;
13159 if (val === "Opacity" || val === "opacity") return interfaceFunction.opacity;
13160 if (val === "Stroke Width" || val === "stroke width") return interfaceFunction.strokeWidth;
13161 return null;
13162 }
13163 Object.defineProperties(interfaceFunction, {
13164 color: { get: ExpressionPropertyInterface(view.c) },
13165 opacity: { get: ExpressionPropertyInterface(view.o) },
13166 strokeWidth: { get: ExpressionPropertyInterface(view.w) },
13167 dash: { get: function get() {
13168 return dashOb;
13169 } },
13170 _name: { value: shape.nm },
13171 mn: { value: shape.mn }
13172 });
13173 view.c.setGroupProperty(PropertyInterface("Color", _propertyGroup));
13174 view.o.setGroupProperty(PropertyInterface("Opacity", _propertyGroup));
13175 view.w.setGroupProperty(PropertyInterface("Stroke Width", _propertyGroup));
13176 return interfaceFunction;
13177 }
13178 function trimInterfaceFactory(shape, view, propertyGroup) {
13179 function interfaceFunction(val) {
13180 if (val === shape.e.ix || val === "End" || val === "end") return interfaceFunction.end;
13181 if (val === shape.s.ix) return interfaceFunction.start;
13182 if (val === shape.o.ix) return interfaceFunction.offset;
13183 return null;
13184 }
13185 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13186 interfaceFunction.propertyIndex = shape.ix;
13187 view.s.setGroupProperty(PropertyInterface("Start", _propertyGroup));
13188 view.e.setGroupProperty(PropertyInterface("End", _propertyGroup));
13189 view.o.setGroupProperty(PropertyInterface("Offset", _propertyGroup));
13190 interfaceFunction.propertyIndex = shape.ix;
13191 interfaceFunction.propertyGroup = propertyGroup;
13192 Object.defineProperties(interfaceFunction, {
13193 start: { get: ExpressionPropertyInterface(view.s) },
13194 end: { get: ExpressionPropertyInterface(view.e) },
13195 offset: { get: ExpressionPropertyInterface(view.o) },
13196 _name: { value: shape.nm }
13197 });
13198 interfaceFunction.mn = shape.mn;
13199 return interfaceFunction;
13200 }
13201 function transformInterfaceFactory(shape, view, propertyGroup) {
13202 function interfaceFunction(value) {
13203 if (shape.a.ix === value || value === "Anchor Point") return interfaceFunction.anchorPoint;
13204 if (shape.o.ix === value || value === "Opacity") return interfaceFunction.opacity;
13205 if (shape.p.ix === value || value === "Position") return interfaceFunction.position;
13206 if (shape.r.ix === value || value === "Rotation" || value === "ADBE Vector Rotation") return interfaceFunction.rotation;
13207 if (shape.s.ix === value || value === "Scale") return interfaceFunction.scale;
13208 if (shape.sk && shape.sk.ix === value || value === "Skew") return interfaceFunction.skew;
13209 if (shape.sa && shape.sa.ix === value || value === "Skew Axis") return interfaceFunction.skewAxis;
13210 return null;
13211 }
13212 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13213 view.transform.mProps.o.setGroupProperty(PropertyInterface("Opacity", _propertyGroup));
13214 view.transform.mProps.p.setGroupProperty(PropertyInterface("Position", _propertyGroup));
13215 view.transform.mProps.a.setGroupProperty(PropertyInterface("Anchor Point", _propertyGroup));
13216 view.transform.mProps.s.setGroupProperty(PropertyInterface("Scale", _propertyGroup));
13217 view.transform.mProps.r.setGroupProperty(PropertyInterface("Rotation", _propertyGroup));
13218 if (view.transform.mProps.sk) {
13219 view.transform.mProps.sk.setGroupProperty(PropertyInterface("Skew", _propertyGroup));
13220 view.transform.mProps.sa.setGroupProperty(PropertyInterface("Skew Angle", _propertyGroup));
13221 }
13222 view.transform.op.setGroupProperty(PropertyInterface("Opacity", _propertyGroup));
13223 Object.defineProperties(interfaceFunction, {
13224 opacity: { get: ExpressionPropertyInterface(view.transform.mProps.o) },
13225 position: { get: ExpressionPropertyInterface(view.transform.mProps.p) },
13226 anchorPoint: { get: ExpressionPropertyInterface(view.transform.mProps.a) },
13227 scale: { get: ExpressionPropertyInterface(view.transform.mProps.s) },
13228 rotation: { get: ExpressionPropertyInterface(view.transform.mProps.r) },
13229 skew: { get: ExpressionPropertyInterface(view.transform.mProps.sk) },
13230 skewAxis: { get: ExpressionPropertyInterface(view.transform.mProps.sa) },
13231 _name: { value: shape.nm }
13232 });
13233 interfaceFunction.ty = "tr";
13234 interfaceFunction.mn = shape.mn;
13235 interfaceFunction.propertyGroup = propertyGroup;
13236 return interfaceFunction;
13237 }
13238 function ellipseInterfaceFactory(shape, view, propertyGroup) {
13239 function interfaceFunction(value) {
13240 if (shape.p.ix === value) return interfaceFunction.position;
13241 if (shape.s.ix === value) return interfaceFunction.size;
13242 return null;
13243 }
13244 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13245 interfaceFunction.propertyIndex = shape.ix;
13246 var prop = view.sh.ty === "tm" ? view.sh.prop : view.sh;
13247 prop.s.setGroupProperty(PropertyInterface("Size", _propertyGroup));
13248 prop.p.setGroupProperty(PropertyInterface("Position", _propertyGroup));
13249 Object.defineProperties(interfaceFunction, {
13250 size: { get: ExpressionPropertyInterface(prop.s) },
13251 position: { get: ExpressionPropertyInterface(prop.p) },
13252 _name: { value: shape.nm }
13253 });
13254 interfaceFunction.mn = shape.mn;
13255 return interfaceFunction;
13256 }
13257 function starInterfaceFactory(shape, view, propertyGroup) {
13258 function interfaceFunction(value) {
13259 if (shape.p.ix === value) return interfaceFunction.position;
13260 if (shape.r.ix === value) return interfaceFunction.rotation;
13261 if (shape.pt.ix === value) return interfaceFunction.points;
13262 if (shape.or.ix === value || value === "ADBE Vector Star Outer Radius") return interfaceFunction.outerRadius;
13263 if (shape.os.ix === value) return interfaceFunction.outerRoundness;
13264 if (shape.ir && (shape.ir.ix === value || value === "ADBE Vector Star Inner Radius")) return interfaceFunction.innerRadius;
13265 if (shape.is && shape.is.ix === value) return interfaceFunction.innerRoundness;
13266 return null;
13267 }
13268 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13269 var prop = view.sh.ty === "tm" ? view.sh.prop : view.sh;
13270 interfaceFunction.propertyIndex = shape.ix;
13271 prop.or.setGroupProperty(PropertyInterface("Outer Radius", _propertyGroup));
13272 prop.os.setGroupProperty(PropertyInterface("Outer Roundness", _propertyGroup));
13273 prop.pt.setGroupProperty(PropertyInterface("Points", _propertyGroup));
13274 prop.p.setGroupProperty(PropertyInterface("Position", _propertyGroup));
13275 prop.r.setGroupProperty(PropertyInterface("Rotation", _propertyGroup));
13276 if (shape.ir) {
13277 prop.ir.setGroupProperty(PropertyInterface("Inner Radius", _propertyGroup));
13278 prop.is.setGroupProperty(PropertyInterface("Inner Roundness", _propertyGroup));
13279 }
13280 Object.defineProperties(interfaceFunction, {
13281 position: { get: ExpressionPropertyInterface(prop.p) },
13282 rotation: { get: ExpressionPropertyInterface(prop.r) },
13283 points: { get: ExpressionPropertyInterface(prop.pt) },
13284 outerRadius: { get: ExpressionPropertyInterface(prop.or) },
13285 outerRoundness: { get: ExpressionPropertyInterface(prop.os) },
13286 innerRadius: { get: ExpressionPropertyInterface(prop.ir) },
13287 innerRoundness: { get: ExpressionPropertyInterface(prop.is) },
13288 _name: { value: shape.nm }
13289 });
13290 interfaceFunction.mn = shape.mn;
13291 return interfaceFunction;
13292 }
13293 function rectInterfaceFactory(shape, view, propertyGroup) {
13294 function interfaceFunction(value) {
13295 if (shape.p.ix === value) return interfaceFunction.position;
13296 if (shape.r.ix === value) return interfaceFunction.roundness;
13297 if (shape.s.ix === value || value === "Size" || value === "ADBE Vector Rect Size") return interfaceFunction.size;
13298 return null;
13299 }
13300 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13301 var prop = view.sh.ty === "tm" ? view.sh.prop : view.sh;
13302 interfaceFunction.propertyIndex = shape.ix;
13303 prop.p.setGroupProperty(PropertyInterface("Position", _propertyGroup));
13304 prop.s.setGroupProperty(PropertyInterface("Size", _propertyGroup));
13305 prop.r.setGroupProperty(PropertyInterface("Rotation", _propertyGroup));
13306 Object.defineProperties(interfaceFunction, {
13307 position: { get: ExpressionPropertyInterface(prop.p) },
13308 roundness: { get: ExpressionPropertyInterface(prop.r) },
13309 size: { get: ExpressionPropertyInterface(prop.s) },
13310 _name: { value: shape.nm }
13311 });
13312 interfaceFunction.mn = shape.mn;
13313 return interfaceFunction;
13314 }
13315 function roundedInterfaceFactory(shape, view, propertyGroup) {
13316 function interfaceFunction(value) {
13317 if (shape.r.ix === value || value === "Round Corners 1") return interfaceFunction.radius;
13318 return null;
13319 }
13320 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13321 var prop = view;
13322 interfaceFunction.propertyIndex = shape.ix;
13323 prop.rd.setGroupProperty(PropertyInterface("Radius", _propertyGroup));
13324 Object.defineProperties(interfaceFunction, {
13325 radius: { get: ExpressionPropertyInterface(prop.rd) },
13326 _name: { value: shape.nm }
13327 });
13328 interfaceFunction.mn = shape.mn;
13329 return interfaceFunction;
13330 }
13331 function repeaterInterfaceFactory(shape, view, propertyGroup) {
13332 function interfaceFunction(value) {
13333 if (shape.c.ix === value || value === "Copies") return interfaceFunction.copies;
13334 if (shape.o.ix === value || value === "Offset") return interfaceFunction.offset;
13335 return null;
13336 }
13337 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
13338 var prop = view;
13339 interfaceFunction.propertyIndex = shape.ix;
13340 prop.c.setGroupProperty(PropertyInterface("Copies", _propertyGroup));
13341 prop.o.setGroupProperty(PropertyInterface("Offset", _propertyGroup));
13342 Object.defineProperties(interfaceFunction, {
13343 copies: { get: ExpressionPropertyInterface(prop.c) },
13344 offset: { get: ExpressionPropertyInterface(prop.o) },
13345 _name: { value: shape.nm }
13346 });
13347 interfaceFunction.mn = shape.mn;
13348 return interfaceFunction;
13349 }
13350 return function(shapes, view, propertyGroup) {
13351 var interfaces;
13352 function _interfaceFunction(value) {
13353 if (typeof value === "number") {
13354 value = value === void 0 ? 1 : value;
13355 if (value === 0) return propertyGroup;
13356 return interfaces[value - 1];
13357 }
13358 var i = 0;
13359 var len = interfaces.length;
13360 while (i < len) {
13361 if (interfaces[i]._name === value) return interfaces[i];
13362 i += 1;
13363 }
13364 return null;
13365 }
13366 function parentGroupWrapper() {
13367 return propertyGroup;
13368 }
13369 _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper);
13370 interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup);
13371 _interfaceFunction.numProperties = interfaces.length;
13372 _interfaceFunction._name = "Contents";
13373 return _interfaceFunction;
13374 };
13375 }();
13376 var TextExpressionInterface = function() {
13377 return function(elem) {
13378 var _sourceText;
13379 function _thisLayerFunction(name) {
13380 switch (name) {
13381 case "ADBE Text Document": return _thisLayerFunction.sourceText;
13382 default: return null;
13383 }
13384 }
13385 Object.defineProperty(_thisLayerFunction, "sourceText", { get: function get() {
13386 elem.textProperty.getValue();
13387 var stringValue = elem.textProperty.currentData.t;
13388 if (!_sourceText || stringValue !== _sourceText.value) {
13389 _sourceText = new String(stringValue);
13390 _sourceText.value = stringValue || new String(stringValue);
13391 Object.defineProperty(_sourceText, "style", { get: function get() {
13392 return { fillColor: elem.textProperty.currentData.fc };
13393 } });
13394 }
13395 return _sourceText;
13396 } });
13397 return _thisLayerFunction;
13398 };
13399 }();
13400 function _typeof(o) {
13401 "@babel/helpers - typeof";
13402 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
13403 return typeof o;
13404 } : function(o) {
13405 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
13406 }, _typeof(o);
13407 }
13408 var FootageInterface = function() {
13409 var outlineInterfaceFactory = function outlineInterfaceFactory(elem) {
13410 var currentPropertyName = "";
13411 var currentProperty = elem.getFootageData();
13412 function init() {
13413 currentPropertyName = "";
13414 currentProperty = elem.getFootageData();
13415 return searchProperty;
13416 }
13417 function searchProperty(value) {
13418 if (currentProperty[value]) {
13419 currentPropertyName = value;
13420 currentProperty = currentProperty[value];
13421 if (_typeof(currentProperty) === "object") return searchProperty;
13422 return currentProperty;
13423 }
13424 var propertyNameIndex = value.indexOf(currentPropertyName);
13425 if (propertyNameIndex !== -1) {
13426 var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10);
13427 currentProperty = currentProperty[index];
13428 if (_typeof(currentProperty) === "object") return searchProperty;
13429 return currentProperty;
13430 }
13431 return "";
13432 }
13433 return init;
13434 };
13435 var dataInterfaceFactory = function dataInterfaceFactory(elem) {
13436 function interfaceFunction(value) {
13437 if (value === "Outline") return interfaceFunction.outlineInterface();
13438 return null;
13439 }
13440 interfaceFunction._name = "Outline";
13441 interfaceFunction.outlineInterface = outlineInterfaceFactory(elem);
13442 return interfaceFunction;
13443 };
13444 return function(elem) {
13445 function _interfaceFunction(value) {
13446 if (value === "Data") return _interfaceFunction.dataInterface;
13447 return null;
13448 }
13449 _interfaceFunction._name = "Data";
13450 _interfaceFunction.dataInterface = dataInterfaceFactory(elem);
13451 return _interfaceFunction;
13452 };
13453 }();
13454 var interfaces = {
13455 layer: LayerExpressionInterface,
13456 effects: EffectsExpressionInterface,
13457 comp: CompExpressionInterface,
13458 shape: ShapeExpressionInterface,
13459 text: TextExpressionInterface,
13460 footage: FootageInterface
13461 };
13462 function getInterface(type) {
13463 return interfaces[type] || null;
13464 }
13465 var expressionHelpers = function() {
13466 function searchExpressions(elem, data, prop) {
13467 if (data.x) {
13468 prop.k = true;
13469 prop.x = true;
13470 prop.initiateExpression = ExpressionManager.initiateExpression;
13471 prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop));
13472 }
13473 }
13474 function getValueAtTime(frameNum) {
13475 frameNum *= this.elem.globalData.frameRate;
13476 frameNum -= this.offsetTime;
13477 if (frameNum !== this._cachingAtTime.lastFrame) {
13478 this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
13479 this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
13480 this._cachingAtTime.lastFrame = frameNum;
13481 }
13482 return this._cachingAtTime.value;
13483 }
13484 function getSpeedAtTime(frameNum) {
13485 var delta = -.01;
13486 var v1 = this.getValueAtTime(frameNum);
13487 var v2 = this.getValueAtTime(frameNum + delta);
13488 var speed = 0;
13489 if (v1.length) {
13490 var i;
13491 for (i = 0; i < v1.length; i += 1) speed += Math.pow(v2[i] - v1[i], 2);
13492 speed = Math.sqrt(speed) * 100;
13493 } else speed = 0;
13494 return speed;
13495 }
13496 function getVelocityAtTime(frameNum) {
13497 if (this.vel !== void 0) return this.vel;
13498 var delta = -.001;
13499 var v1 = this.getValueAtTime(frameNum);
13500 var v2 = this.getValueAtTime(frameNum + delta);
13501 var velocity;
13502 if (v1.length) {
13503 velocity = createTypedArray("float32", v1.length);
13504 var i;
13505 for (i = 0; i < v1.length; i += 1) velocity[i] = (v2[i] - v1[i]) / delta;
13506 } else velocity = (v2 - v1) / delta;
13507 return velocity;
13508 }
13509 function getStaticValueAtTime() {
13510 return this.pv;
13511 }
13512 function setGroupProperty(propertyGroup) {
13513 this.propertyGroup = propertyGroup;
13514 }
13515 return {
13516 searchExpressions,
13517 getSpeedAtTime,
13518 getVelocityAtTime,
13519 getValueAtTime,
13520 getStaticValueAtTime,
13521 setGroupProperty
13522 };
13523 }();
13524 function addPropertyDecorator() {
13525 function loopOut(type, duration, durationFlag) {
13526 if (!this.k || !this.keyframes) return this.pv;
13527 type = type ? type.toLowerCase() : "";
13528 var currentFrame = this.comp.renderedFrame;
13529 var keyframes = this.keyframes;
13530 var lastKeyFrame = keyframes[keyframes.length - 1].t;
13531 if (currentFrame <= lastKeyFrame) return this.pv;
13532 var cycleDuration;
13533 var firstKeyFrame;
13534 if (!durationFlag) {
13535 if (!duration || duration > keyframes.length - 1) duration = keyframes.length - 1;
13536 firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
13537 cycleDuration = lastKeyFrame - firstKeyFrame;
13538 } else {
13539 if (!duration) cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip);
13540 else cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration);
13541 firstKeyFrame = lastKeyFrame - cycleDuration;
13542 }
13543 var i;
13544 var len;
13545 var ret;
13546 if (type === "pingpong") {
13547 if (Math.floor((currentFrame - firstKeyFrame) / cycleDuration) % 2 !== 0) return this.getValueAtTime((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
13548 } else if (type === "offset") {
13549 var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
13550 var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
13551 var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
13552 var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
13553 if (this.pv.length) {
13554 ret = new Array(initV.length);
13555 len = ret.length;
13556 for (i = 0; i < len; i += 1) ret[i] = (endV[i] - initV[i]) * repeats + current[i];
13557 return ret;
13558 }
13559 return (endV - initV) * repeats + current;
13560 } else if (type === "continue") {
13561 var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
13562 var nextLastValue = this.getValueAtTime((lastKeyFrame - .001) / this.comp.globalData.frameRate, 0);
13563 if (this.pv.length) {
13564 ret = new Array(lastValue.length);
13565 len = ret.length;
13566 for (i = 0; i < len; i += 1) ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 5e-4;
13567 return ret;
13568 }
13569 return lastValue + (lastValue - nextLastValue) * ((currentFrame - lastKeyFrame) / .001);
13570 }
13571 return this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
13572 }
13573 function loopIn(type, duration, durationFlag) {
13574 if (!this.k) return this.pv;
13575 type = type ? type.toLowerCase() : "";
13576 var currentFrame = this.comp.renderedFrame;
13577 var keyframes = this.keyframes;
13578 var firstKeyFrame = keyframes[0].t;
13579 if (currentFrame >= firstKeyFrame) return this.pv;
13580 var cycleDuration;
13581 var lastKeyFrame;
13582 if (!durationFlag) {
13583 if (!duration || duration > keyframes.length - 1) duration = keyframes.length - 1;
13584 lastKeyFrame = keyframes[duration].t;
13585 cycleDuration = lastKeyFrame - firstKeyFrame;
13586 } else {
13587 if (!duration) cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame);
13588 else cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration);
13589 lastKeyFrame = firstKeyFrame + cycleDuration;
13590 }
13591 var i;
13592 var len;
13593 var ret;
13594 if (type === "pingpong") {
13595 if (Math.floor((firstKeyFrame - currentFrame) / cycleDuration) % 2 === 0) return this.getValueAtTime(((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
13596 } else if (type === "offset") {
13597 var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
13598 var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
13599 var current = this.getValueAtTime((cycleDuration - (firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
13600 var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1;
13601 if (this.pv.length) {
13602 ret = new Array(initV.length);
13603 len = ret.length;
13604 for (i = 0; i < len; i += 1) ret[i] = current[i] - (endV[i] - initV[i]) * repeats;
13605 return ret;
13606 }
13607 return current - (endV - initV) * repeats;
13608 } else if (type === "continue") {
13609 var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
13610 var nextFirstValue = this.getValueAtTime((firstKeyFrame + .001) / this.comp.globalData.frameRate, 0);
13611 if (this.pv.length) {
13612 ret = new Array(firstValue.length);
13613 len = ret.length;
13614 for (i = 0; i < len; i += 1) ret[i] = firstValue[i] + (firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame) / .001;
13615 return ret;
13616 }
13617 return firstValue + (firstValue - nextFirstValue) * (firstKeyFrame - currentFrame) / .001;
13618 }
13619 return this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
13620 }
13621 function smooth(width, samples) {
13622 if (!this.k) return this.pv;
13623 width = (width || .4) * .5;
13624 samples = Math.floor(samples || 5);
13625 if (samples <= 1) return this.pv;
13626 var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
13627 var initFrame = currentTime - width;
13628 var endFrame = currentTime + width;
13629 var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
13630 var i = 0;
13631 var j = 0;
13632 var value;
13633 if (this.pv.length) value = createTypedArray("float32", this.pv.length);
13634 else value = 0;
13635 var sampleValue;
13636 while (i < samples) {
13637 sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
13638 if (this.pv.length) for (j = 0; j < this.pv.length; j += 1) value[j] += sampleValue[j];
13639 else value += sampleValue;
13640 i += 1;
13641 }
13642 if (this.pv.length) for (j = 0; j < this.pv.length; j += 1) value[j] /= samples;
13643 else value /= samples;
13644 return value;
13645 }
13646 function getTransformValueAtTime(time) {
13647 if (!this._transformCachingAtTime) this._transformCachingAtTime = { v: new Matrix() };
13648 var matrix = this._transformCachingAtTime.v;
13649 matrix.cloneFromProps(this.pre.props);
13650 if (this.appliedTransformations < 1) {
13651 var anchor = this.a.getValueAtTime(time);
13652 matrix.translate(-anchor[0] * this.a.mult, -anchor[1] * this.a.mult, anchor[2] * this.a.mult);
13653 }
13654 if (this.appliedTransformations < 2) {
13655 var scale = this.s.getValueAtTime(time);
13656 matrix.scale(scale[0] * this.s.mult, scale[1] * this.s.mult, scale[2] * this.s.mult);
13657 }
13658 if (this.sk && this.appliedTransformations < 3) {
13659 var skew = this.sk.getValueAtTime(time);
13660 var skewAxis = this.sa.getValueAtTime(time);
13661 matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult);
13662 }
13663 if (this.r && this.appliedTransformations < 4) {
13664 var rotation = this.r.getValueAtTime(time);
13665 matrix.rotate(-rotation * this.r.mult);
13666 } else if (!this.r && this.appliedTransformations < 4) {
13667 var rotationZ = this.rz.getValueAtTime(time);
13668 var rotationY = this.ry.getValueAtTime(time);
13669 var rotationX = this.rx.getValueAtTime(time);
13670 var orientation = this.or.getValueAtTime(time);
13671 matrix.rotateZ(-rotationZ * this.rz.mult).rotateY(rotationY * this.ry.mult).rotateX(rotationX * this.rx.mult).rotateZ(-orientation[2] * this.or.mult).rotateY(orientation[1] * this.or.mult).rotateX(orientation[0] * this.or.mult);
13672 }
13673 if (this.data.p && this.data.p.s) {
13674 var positionX = this.px.getValueAtTime(time);
13675 var positionY = this.py.getValueAtTime(time);
13676 if (this.data.p.z) {
13677 var positionZ = this.pz.getValueAtTime(time);
13678 matrix.translate(positionX * this.px.mult, positionY * this.py.mult, -positionZ * this.pz.mult);
13679 } else matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0);
13680 } else {
13681 var position = this.p.getValueAtTime(time);
13682 matrix.translate(position[0] * this.p.mult, position[1] * this.p.mult, -position[2] * this.p.mult);
13683 }
13684 return matrix;
13685 }
13686 function getTransformStaticValueAtTime() {
13687 return this.v.clone(new Matrix());
13688 }
13689 var getTransformProperty = TransformPropertyFactory.getTransformProperty;
13690 TransformPropertyFactory.getTransformProperty = function(elem, data, container) {
13691 var prop = getTransformProperty(elem, data, container);
13692 if (prop.dynamicProperties.length) prop.getValueAtTime = getTransformValueAtTime.bind(prop);
13693 else prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
13694 prop.setGroupProperty = expressionHelpers.setGroupProperty;
13695 return prop;
13696 };
13697 var propertyGetProp = PropertyFactory.getProp;
13698 PropertyFactory.getProp = function(elem, data, type, mult, container) {
13699 var prop = propertyGetProp(elem, data, type, mult, container);
13700 if (prop.kf) prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
13701 else prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
13702 prop.setGroupProperty = expressionHelpers.setGroupProperty;
13703 prop.loopOut = loopOut;
13704 prop.loopIn = loopIn;
13705 prop.smooth = smooth;
13706 prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
13707 prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
13708 prop.numKeys = data.a === 1 ? data.k.length : 0;
13709 prop.propertyIndex = data.ix;
13710 var value = 0;
13711 if (type !== 0) value = createTypedArray("float32", data.a === 1 ? data.k[0].s.length : data.k.length);
13712 prop._cachingAtTime = {
13713 lastFrame: initialDefaultFrame,
13714 lastIndex: 0,
13715 value
13716 };
13717 expressionHelpers.searchExpressions(elem, data, prop);
13718 if (prop.k) container.addDynamicProperty(prop);
13719 return prop;
13720 };
13721 function getShapeValueAtTime(frameNum) {
13722 if (!this._cachingAtTime) this._cachingAtTime = {
13723 shapeValue: shapePool.clone(this.pv),
13724 lastIndex: 0,
13725 lastTime: initialDefaultFrame
13726 };
13727 frameNum *= this.elem.globalData.frameRate;
13728 frameNum -= this.offsetTime;
13729 if (frameNum !== this._cachingAtTime.lastTime) {
13730 this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
13731 this._cachingAtTime.lastTime = frameNum;
13732 this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
13733 }
13734 return this._cachingAtTime.shapeValue;
13735 }
13736 var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
13737 var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
13738 function ShapeExpressions() {}
13739 ShapeExpressions.prototype = {
13740 vertices: function vertices(prop, time) {
13741 if (this.k) this.getValue();
13742 var shapePath = this.v;
13743 if (time !== void 0) shapePath = this.getValueAtTime(time, 0);
13744 var i;
13745 var len = shapePath._length;
13746 var vertices = shapePath[prop];
13747 var points = shapePath.v;
13748 var arr = createSizedArray(len);
13749 for (i = 0; i < len; i += 1) if (prop === "i" || prop === "o") arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
13750 else arr[i] = [vertices[i][0], vertices[i][1]];
13751 return arr;
13752 },
13753 points: function points(time) {
13754 return this.vertices("v", time);
13755 },
13756 inTangents: function inTangents(time) {
13757 return this.vertices("i", time);
13758 },
13759 outTangents: function outTangents(time) {
13760 return this.vertices("o", time);
13761 },
13762 isClosed: function isClosed() {
13763 return this.v.c;
13764 },
13765 pointOnPath: function pointOnPath(perc, time) {
13766 var shapePath = this.v;
13767 if (time !== void 0) shapePath = this.getValueAtTime(time, 0);
13768 if (!this._segmentsLength) this._segmentsLength = bez.getSegmentsLength(shapePath);
13769 var segmentsLength = this._segmentsLength;
13770 var lengths = segmentsLength.lengths;
13771 var lengthPos = segmentsLength.totalLength * perc;
13772 var i = 0;
13773 var len = lengths.length;
13774 var accumulatedLength = 0;
13775 var pt;
13776 while (i < len) {
13777 if (accumulatedLength + lengths[i].addedLength > lengthPos) {
13778 var initIndex = i;
13779 var endIndex = shapePath.c && i === len - 1 ? 0 : i + 1;
13780 var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength;
13781 pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
13782 break;
13783 } else accumulatedLength += lengths[i].addedLength;
13784 i += 1;
13785 }
13786 if (!pt) pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]];
13787 return pt;
13788 },
13789 vectorOnPath: function vectorOnPath(perc, time, vectorType) {
13790 if (perc == 1) perc = this.v.c;
13791 else if (perc == 0) perc = .999;
13792 var pt1 = this.pointOnPath(perc, time);
13793 var pt2 = this.pointOnPath(perc + .001, time);
13794 var xLength = pt2[0] - pt1[0];
13795 var yLength = pt2[1] - pt1[1];
13796 var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
13797 if (magnitude === 0) return [0, 0];
13798 return vectorType === "tangent" ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude];
13799 },
13800 tangentOnPath: function tangentOnPath(perc, time) {
13801 return this.vectorOnPath(perc, time, "tangent");
13802 },
13803 normalOnPath: function normalOnPath(perc, time) {
13804 return this.vectorOnPath(perc, time, "normal");
13805 },
13806 setGroupProperty: expressionHelpers.setGroupProperty,
13807 getValueAtTime: expressionHelpers.getStaticValueAtTime
13808 };
13809 extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
13810 extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
13811 KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
13812 KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
13813 var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
13814 ShapePropertyFactory.getShapeProp = function(elem, data, type, arr, trims) {
13815 var prop = propertyGetShapeProp(elem, data, type, arr, trims);
13816 prop.propertyIndex = data.ix;
13817 prop.lock = false;
13818 if (type === 3) expressionHelpers.searchExpressions(elem, data.pt, prop);
13819 else if (type === 4) expressionHelpers.searchExpressions(elem, data.ks, prop);
13820 if (prop.k) elem.addDynamicProperty(prop);
13821 return prop;
13822 };
13823 }
13824 function initialize$1() {
13825 addPropertyDecorator();
13826 }
13827 function addDecorator() {
13828 function searchExpressions() {
13829 if (this.data.d.x) {
13830 this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this);
13831 this.addEffect(this.getExpressionValue.bind(this));
13832 return true;
13833 }
13834 return null;
13835 }
13836 TextProperty.prototype.getExpressionValue = function(currentValue, text) {
13837 var newValue = this.calculateExpression(text);
13838 if (currentValue.t !== newValue) {
13839 var newData = {};
13840 this.copyData(newData, currentValue);
13841 newData.t = newValue.toString();
13842 newData.__complete = false;
13843 return newData;
13844 }
13845 return currentValue;
13846 };
13847 TextProperty.prototype.searchProperty = function() {
13848 var isKeyframed = this.searchKeyframes();
13849 var hasExpressions = this.searchExpressions();
13850 this.kf = isKeyframed || hasExpressions;
13851 return this.kf;
13852 };
13853 TextProperty.prototype.searchExpressions = searchExpressions;
13854 }
13855 function initialize() {
13856 addDecorator();
13857 }
13858 function SVGComposableEffect() {}
13859 SVGComposableEffect.prototype = { createMergeNode: function createMergeNode(resultId, ins) {
13860 var feMerge = createNS("feMerge");
13861 feMerge.setAttribute("result", resultId);
13862 var feMergeNode;
13863 var i;
13864 for (i = 0; i < ins.length; i += 1) {
13865 feMergeNode = createNS("feMergeNode");
13866 feMergeNode.setAttribute("in", ins[i]);
13867 feMerge.appendChild(feMergeNode);
13868 feMerge.appendChild(feMergeNode);
13869 }
13870 return feMerge;
13871 } };
13872 var linearFilterValue = "0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0";
13873 function SVGTintFilter(filter, filterManager, elem, id, source) {
13874 this.filterManager = filterManager;
13875 var feColorMatrix = createNS("feColorMatrix");
13876 feColorMatrix.setAttribute("type", "matrix");
13877 feColorMatrix.setAttribute("color-interpolation-filters", "linearRGB");
13878 feColorMatrix.setAttribute("values", linearFilterValue + " 1 0");
13879 this.linearFilter = feColorMatrix;
13880 feColorMatrix.setAttribute("result", id + "_tint_1");
13881 filter.appendChild(feColorMatrix);
13882 feColorMatrix = createNS("feColorMatrix");
13883 feColorMatrix.setAttribute("type", "matrix");
13884 feColorMatrix.setAttribute("color-interpolation-filters", "sRGB");
13885 feColorMatrix.setAttribute("values", "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0");
13886 feColorMatrix.setAttribute("result", id + "_tint_2");
13887 filter.appendChild(feColorMatrix);
13888 this.matrixFilter = feColorMatrix;
13889 var feMerge = this.createMergeNode(id, [
13890 source,
13891 id + "_tint_1",
13892 id + "_tint_2"
13893 ]);
13894 filter.appendChild(feMerge);
13895 }
13896 extendPrototype([SVGComposableEffect], SVGTintFilter);
13897 SVGTintFilter.prototype.renderFrame = function(forceRender) {
13898 if (forceRender || this.filterManager._mdf) {
13899 var colorBlack = this.filterManager.effectElements[0].p.v;
13900 var colorWhite = this.filterManager.effectElements[1].p.v;
13901 var opacity = this.filterManager.effectElements[2].p.v / 100;
13902 this.linearFilter.setAttribute("values", linearFilterValue + " " + opacity + " 0");
13903 this.matrixFilter.setAttribute("values", colorWhite[0] - colorBlack[0] + " 0 0 0 " + colorBlack[0] + " " + (colorWhite[1] - colorBlack[1]) + " 0 0 0 " + colorBlack[1] + " " + (colorWhite[2] - colorBlack[2]) + " 0 0 0 " + colorBlack[2] + " 0 0 0 1 0");
13904 }
13905 };
13906 function SVGFillFilter(filter, filterManager, elem, id) {
13907 this.filterManager = filterManager;
13908 var feColorMatrix = createNS("feColorMatrix");
13909 feColorMatrix.setAttribute("type", "matrix");
13910 feColorMatrix.setAttribute("color-interpolation-filters", "sRGB");
13911 feColorMatrix.setAttribute("values", "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0");
13912 feColorMatrix.setAttribute("result", id);
13913 filter.appendChild(feColorMatrix);
13914 this.matrixFilter = feColorMatrix;
13915 }
13916 SVGFillFilter.prototype.renderFrame = function(forceRender) {
13917 if (forceRender || this.filterManager._mdf) {
13918 var color = this.filterManager.effectElements[2].p.v;
13919 var opacity = this.filterManager.effectElements[6].p.v;
13920 this.matrixFilter.setAttribute("values", "0 0 0 0 " + color[0] + " 0 0 0 0 " + color[1] + " 0 0 0 0 " + color[2] + " 0 0 0 " + opacity + " 0");
13921 }
13922 };
13923 function SVGStrokeEffect(fil, filterManager, elem) {
13924 this.initialized = false;
13925 this.filterManager = filterManager;
13926 this.elem = elem;
13927 this.paths = [];
13928 }
13929 SVGStrokeEffect.prototype.initialize = function() {
13930 var elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
13931 var path;
13932 var groupPath;
13933 var i;
13934 var len;
13935 if (this.filterManager.effectElements[1].p.v === 1) {
13936 len = this.elem.maskManager.masksProperties.length;
13937 i = 0;
13938 } else {
13939 i = this.filterManager.effectElements[0].p.v - 1;
13940 len = i + 1;
13941 }
13942 groupPath = createNS("g");
13943 groupPath.setAttribute("fill", "none");
13944 groupPath.setAttribute("stroke-linecap", "round");
13945 groupPath.setAttribute("stroke-dashoffset", 1);
13946 for (; i < len; i += 1) {
13947 path = createNS("path");
13948 groupPath.appendChild(path);
13949 this.paths.push({
13950 p: path,
13951 m: i
13952 });
13953 }
13954 if (this.filterManager.effectElements[10].p.v === 3) {
13955 var mask = createNS("mask");
13956 var id = createElementID();
13957 mask.setAttribute("id", id);
13958 mask.setAttribute("mask-type", "alpha");
13959 mask.appendChild(groupPath);
13960 this.elem.globalData.defs.appendChild(mask);
13961 var g = createNS("g");
13962 g.setAttribute("mask", "url(" + getLocationHref() + "#" + id + ")");
13963 while (elemChildren[0]) g.appendChild(elemChildren[0]);
13964 this.elem.layerElement.appendChild(g);
13965 this.masker = mask;
13966 groupPath.setAttribute("stroke", "#fff");
13967 } else if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
13968 if (this.filterManager.effectElements[10].p.v === 2) {
13969 elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
13970 while (elemChildren.length) this.elem.layerElement.removeChild(elemChildren[0]);
13971 }
13972 this.elem.layerElement.appendChild(groupPath);
13973 this.elem.layerElement.removeAttribute("mask");
13974 groupPath.setAttribute("stroke", "#fff");
13975 }
13976 this.initialized = true;
13977 this.pathMasker = groupPath;
13978 };
13979 SVGStrokeEffect.prototype.renderFrame = function(forceRender) {
13980 if (!this.initialized) this.initialize();
13981 var i;
13982 var len = this.paths.length;
13983 var mask;
13984 var path;
13985 for (i = 0; i < len; i += 1) if (this.paths[i].m !== -1) {
13986 mask = this.elem.maskManager.viewData[this.paths[i].m];
13987 path = this.paths[i].p;
13988 if (forceRender || this.filterManager._mdf || mask.prop._mdf) path.setAttribute("d", mask.lastPath);
13989 if (forceRender || this.filterManager.effectElements[9].p._mdf || this.filterManager.effectElements[4].p._mdf || this.filterManager.effectElements[7].p._mdf || this.filterManager.effectElements[8].p._mdf || mask.prop._mdf) {
13990 var dasharrayValue;
13991 if (this.filterManager.effectElements[7].p.v !== 0 || this.filterManager.effectElements[8].p.v !== 100) {
13992 var s = Math.min(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * .01;
13993 var e = Math.max(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * .01;
13994 var l = path.getTotalLength();
13995 dasharrayValue = "0 0 0 " + l * s + " ";
13996 var lineLength = l * (e - s);
13997 var segment = 1 + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * .01;
13998 var units = Math.floor(lineLength / segment);
13999 var j;
14000 for (j = 0; j < units; j += 1) dasharrayValue += "1 " + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * .01 + " ";
14001 dasharrayValue += "0 " + l * 10 + " 0 0";
14002 } else dasharrayValue = "1 " + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * .01;
14003 path.setAttribute("stroke-dasharray", dasharrayValue);
14004 }
14005 }
14006 if (forceRender || this.filterManager.effectElements[4].p._mdf) this.pathMasker.setAttribute("stroke-width", this.filterManager.effectElements[4].p.v * 2);
14007 if (forceRender || this.filterManager.effectElements[6].p._mdf) this.pathMasker.setAttribute("opacity", this.filterManager.effectElements[6].p.v);
14008 if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
14009 if (forceRender || this.filterManager.effectElements[3].p._mdf) {
14010 var color = this.filterManager.effectElements[3].p.v;
14011 this.pathMasker.setAttribute("stroke", "rgb(" + bmFloor(color[0] * 255) + "," + bmFloor(color[1] * 255) + "," + bmFloor(color[2] * 255) + ")");
14012 }
14013 }
14014 };
14015 function SVGTritoneFilter(filter, filterManager, elem, id) {
14016 this.filterManager = filterManager;
14017 var feColorMatrix = createNS("feColorMatrix");
14018 feColorMatrix.setAttribute("type", "matrix");
14019 feColorMatrix.setAttribute("color-interpolation-filters", "linearRGB");
14020 feColorMatrix.setAttribute("values", "0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0");
14021 filter.appendChild(feColorMatrix);
14022 var feComponentTransfer = createNS("feComponentTransfer");
14023 feComponentTransfer.setAttribute("color-interpolation-filters", "sRGB");
14024 feComponentTransfer.setAttribute("result", id);
14025 this.matrixFilter = feComponentTransfer;
14026 var feFuncR = createNS("feFuncR");
14027 feFuncR.setAttribute("type", "table");
14028 feComponentTransfer.appendChild(feFuncR);
14029 this.feFuncR = feFuncR;
14030 var feFuncG = createNS("feFuncG");
14031 feFuncG.setAttribute("type", "table");
14032 feComponentTransfer.appendChild(feFuncG);
14033 this.feFuncG = feFuncG;
14034 var feFuncB = createNS("feFuncB");
14035 feFuncB.setAttribute("type", "table");
14036 feComponentTransfer.appendChild(feFuncB);
14037 this.feFuncB = feFuncB;
14038 filter.appendChild(feComponentTransfer);
14039 }
14040 SVGTritoneFilter.prototype.renderFrame = function(forceRender) {
14041 if (forceRender || this.filterManager._mdf) {
14042 var color1 = this.filterManager.effectElements[0].p.v;
14043 var color2 = this.filterManager.effectElements[1].p.v;
14044 var color3 = this.filterManager.effectElements[2].p.v;
14045 var tableR = color3[0] + " " + color2[0] + " " + color1[0];
14046 var tableG = color3[1] + " " + color2[1] + " " + color1[1];
14047 var tableB = color3[2] + " " + color2[2] + " " + color1[2];
14048 this.feFuncR.setAttribute("tableValues", tableR);
14049 this.feFuncG.setAttribute("tableValues", tableG);
14050 this.feFuncB.setAttribute("tableValues", tableB);
14051 }
14052 };
14053 function SVGProLevelsFilter(filter, filterManager, elem, id) {
14054 this.filterManager = filterManager;
14055 var effectElements = this.filterManager.effectElements;
14056 var feComponentTransfer = createNS("feComponentTransfer");
14057 if (effectElements[10].p.k || effectElements[10].p.v !== 0 || effectElements[11].p.k || effectElements[11].p.v !== 1 || effectElements[12].p.k || effectElements[12].p.v !== 1 || effectElements[13].p.k || effectElements[13].p.v !== 0 || effectElements[14].p.k || effectElements[14].p.v !== 1) this.feFuncR = this.createFeFunc("feFuncR", feComponentTransfer);
14058 if (effectElements[17].p.k || effectElements[17].p.v !== 0 || effectElements[18].p.k || effectElements[18].p.v !== 1 || effectElements[19].p.k || effectElements[19].p.v !== 1 || effectElements[20].p.k || effectElements[20].p.v !== 0 || effectElements[21].p.k || effectElements[21].p.v !== 1) this.feFuncG = this.createFeFunc("feFuncG", feComponentTransfer);
14059 if (effectElements[24].p.k || effectElements[24].p.v !== 0 || effectElements[25].p.k || effectElements[25].p.v !== 1 || effectElements[26].p.k || effectElements[26].p.v !== 1 || effectElements[27].p.k || effectElements[27].p.v !== 0 || effectElements[28].p.k || effectElements[28].p.v !== 1) this.feFuncB = this.createFeFunc("feFuncB", feComponentTransfer);
14060 if (effectElements[31].p.k || effectElements[31].p.v !== 0 || effectElements[32].p.k || effectElements[32].p.v !== 1 || effectElements[33].p.k || effectElements[33].p.v !== 1 || effectElements[34].p.k || effectElements[34].p.v !== 0 || effectElements[35].p.k || effectElements[35].p.v !== 1) this.feFuncA = this.createFeFunc("feFuncA", feComponentTransfer);
14061 if (this.feFuncR || this.feFuncG || this.feFuncB || this.feFuncA) {
14062 feComponentTransfer.setAttribute("color-interpolation-filters", "sRGB");
14063 filter.appendChild(feComponentTransfer);
14064 }
14065 if (effectElements[3].p.k || effectElements[3].p.v !== 0 || effectElements[4].p.k || effectElements[4].p.v !== 1 || effectElements[5].p.k || effectElements[5].p.v !== 1 || effectElements[6].p.k || effectElements[6].p.v !== 0 || effectElements[7].p.k || effectElements[7].p.v !== 1) {
14066 feComponentTransfer = createNS("feComponentTransfer");
14067 feComponentTransfer.setAttribute("color-interpolation-filters", "sRGB");
14068 feComponentTransfer.setAttribute("result", id);
14069 filter.appendChild(feComponentTransfer);
14070 this.feFuncRComposed = this.createFeFunc("feFuncR", feComponentTransfer);
14071 this.feFuncGComposed = this.createFeFunc("feFuncG", feComponentTransfer);
14072 this.feFuncBComposed = this.createFeFunc("feFuncB", feComponentTransfer);
14073 }
14074 }
14075 SVGProLevelsFilter.prototype.createFeFunc = function(type, feComponentTransfer) {
14076 var feFunc = createNS(type);
14077 feFunc.setAttribute("type", "table");
14078 feComponentTransfer.appendChild(feFunc);
14079 return feFunc;
14080 };
14081 SVGProLevelsFilter.prototype.getTableValue = function(inputBlack, inputWhite, gamma, outputBlack, outputWhite) {
14082 var cnt = 0;
14083 var segments = 256;
14084 var perc;
14085 var min = Math.min(inputBlack, inputWhite);
14086 var max = Math.max(inputBlack, inputWhite);
14087 var table = Array.call(null, { length: segments });
14088 var colorValue;
14089 var pos = 0;
14090 var outputDelta = outputWhite - outputBlack;
14091 var inputDelta = inputWhite - inputBlack;
14092 while (cnt <= 256) {
14093 perc = cnt / 256;
14094 if (perc <= min) colorValue = inputDelta < 0 ? outputWhite : outputBlack;
14095 else if (perc >= max) colorValue = inputDelta < 0 ? outputBlack : outputWhite;
14096 else colorValue = outputBlack + outputDelta * Math.pow((perc - inputBlack) / inputDelta, 1 / gamma);
14097 table[pos] = colorValue;
14098 pos += 1;
14099 cnt += 256 / (segments - 1);
14100 }
14101 return table.join(" ");
14102 };
14103 SVGProLevelsFilter.prototype.renderFrame = function(forceRender) {
14104 if (forceRender || this.filterManager._mdf) {
14105 var val;
14106 var effectElements = this.filterManager.effectElements;
14107 if (this.feFuncRComposed && (forceRender || effectElements[3].p._mdf || effectElements[4].p._mdf || effectElements[5].p._mdf || effectElements[6].p._mdf || effectElements[7].p._mdf)) {
14108 val = this.getTableValue(effectElements[3].p.v, effectElements[4].p.v, effectElements[5].p.v, effectElements[6].p.v, effectElements[7].p.v);
14109 this.feFuncRComposed.setAttribute("tableValues", val);
14110 this.feFuncGComposed.setAttribute("tableValues", val);
14111 this.feFuncBComposed.setAttribute("tableValues", val);
14112 }
14113 if (this.feFuncR && (forceRender || effectElements[10].p._mdf || effectElements[11].p._mdf || effectElements[12].p._mdf || effectElements[13].p._mdf || effectElements[14].p._mdf)) {
14114 val = this.getTableValue(effectElements[10].p.v, effectElements[11].p.v, effectElements[12].p.v, effectElements[13].p.v, effectElements[14].p.v);
14115 this.feFuncR.setAttribute("tableValues", val);
14116 }
14117 if (this.feFuncG && (forceRender || effectElements[17].p._mdf || effectElements[18].p._mdf || effectElements[19].p._mdf || effectElements[20].p._mdf || effectElements[21].p._mdf)) {
14118 val = this.getTableValue(effectElements[17].p.v, effectElements[18].p.v, effectElements[19].p.v, effectElements[20].p.v, effectElements[21].p.v);
14119 this.feFuncG.setAttribute("tableValues", val);
14120 }
14121 if (this.feFuncB && (forceRender || effectElements[24].p._mdf || effectElements[25].p._mdf || effectElements[26].p._mdf || effectElements[27].p._mdf || effectElements[28].p._mdf)) {
14122 val = this.getTableValue(effectElements[24].p.v, effectElements[25].p.v, effectElements[26].p.v, effectElements[27].p.v, effectElements[28].p.v);
14123 this.feFuncB.setAttribute("tableValues", val);
14124 }
14125 if (this.feFuncA && (forceRender || effectElements[31].p._mdf || effectElements[32].p._mdf || effectElements[33].p._mdf || effectElements[34].p._mdf || effectElements[35].p._mdf)) {
14126 val = this.getTableValue(effectElements[31].p.v, effectElements[32].p.v, effectElements[33].p.v, effectElements[34].p.v, effectElements[35].p.v);
14127 this.feFuncA.setAttribute("tableValues", val);
14128 }
14129 }
14130 };
14131 function SVGDropShadowEffect(filter, filterManager, elem, id, source) {
14132 var globalFilterSize = filterManager.container.globalData.renderConfig.filterSize;
14133 var filterSize = filterManager.data.fs || globalFilterSize;
14134 filter.setAttribute("x", filterSize.x || globalFilterSize.x);
14135 filter.setAttribute("y", filterSize.y || globalFilterSize.y);
14136 filter.setAttribute("width", filterSize.width || globalFilterSize.width);
14137 filter.setAttribute("height", filterSize.height || globalFilterSize.height);
14138 this.filterManager = filterManager;
14139 var feGaussianBlur = createNS("feGaussianBlur");
14140 feGaussianBlur.setAttribute("in", "SourceAlpha");
14141 feGaussianBlur.setAttribute("result", id + "_drop_shadow_1");
14142 feGaussianBlur.setAttribute("stdDeviation", "0");
14143 this.feGaussianBlur = feGaussianBlur;
14144 filter.appendChild(feGaussianBlur);
14145 var feOffset = createNS("feOffset");
14146 feOffset.setAttribute("dx", "25");
14147 feOffset.setAttribute("dy", "0");
14148 feOffset.setAttribute("in", id + "_drop_shadow_1");
14149 feOffset.setAttribute("result", id + "_drop_shadow_2");
14150 this.feOffset = feOffset;
14151 filter.appendChild(feOffset);
14152 var feFlood = createNS("feFlood");
14153 feFlood.setAttribute("flood-color", "#00ff00");
14154 feFlood.setAttribute("flood-opacity", "1");
14155 feFlood.setAttribute("result", id + "_drop_shadow_3");
14156 this.feFlood = feFlood;
14157 filter.appendChild(feFlood);
14158 var feComposite = createNS("feComposite");
14159 feComposite.setAttribute("in", id + "_drop_shadow_3");
14160 feComposite.setAttribute("in2", id + "_drop_shadow_2");
14161 feComposite.setAttribute("operator", "in");
14162 feComposite.setAttribute("result", id + "_drop_shadow_4");
14163 filter.appendChild(feComposite);
14164 var feMerge = this.createMergeNode(id, [id + "_drop_shadow_4", source]);
14165 filter.appendChild(feMerge);
14166 }
14167 extendPrototype([SVGComposableEffect], SVGDropShadowEffect);
14168 SVGDropShadowEffect.prototype.renderFrame = function(forceRender) {
14169 if (forceRender || this.filterManager._mdf) {
14170 if (forceRender || this.filterManager.effectElements[4].p._mdf) this.feGaussianBlur.setAttribute("stdDeviation", this.filterManager.effectElements[4].p.v / 4);
14171 if (forceRender || this.filterManager.effectElements[0].p._mdf) {
14172 var col = this.filterManager.effectElements[0].p.v;
14173 this.feFlood.setAttribute("flood-color", rgbToHex(Math.round(col[0] * 255), Math.round(col[1] * 255), Math.round(col[2] * 255)));
14174 }
14175 if (forceRender || this.filterManager.effectElements[1].p._mdf) this.feFlood.setAttribute("flood-opacity", this.filterManager.effectElements[1].p.v / 255);
14176 if (forceRender || this.filterManager.effectElements[2].p._mdf || this.filterManager.effectElements[3].p._mdf) {
14177 var distance = this.filterManager.effectElements[3].p.v;
14178 var angle = (this.filterManager.effectElements[2].p.v - 90) * degToRads;
14179 var x = distance * Math.cos(angle);
14180 var y = distance * Math.sin(angle);
14181 this.feOffset.setAttribute("dx", x);
14182 this.feOffset.setAttribute("dy", y);
14183 }
14184 }
14185 };
14186 var _svgMatteSymbols = [];
14187 function SVGMatte3Effect(filterElem, filterManager, elem) {
14188 this.initialized = false;
14189 this.filterManager = filterManager;
14190 this.filterElem = filterElem;
14191 this.elem = elem;
14192 elem.matteElement = createNS("g");
14193 elem.matteElement.appendChild(elem.layerElement);
14194 elem.matteElement.appendChild(elem.transformedElement);
14195 elem.baseElement = elem.matteElement;
14196 }
14197 SVGMatte3Effect.prototype.findSymbol = function(mask) {
14198 var i = 0;
14199 var len = _svgMatteSymbols.length;
14200 while (i < len) {
14201 if (_svgMatteSymbols[i] === mask) return _svgMatteSymbols[i];
14202 i += 1;
14203 }
14204 return null;
14205 };
14206 SVGMatte3Effect.prototype.replaceInParent = function(mask, symbolId) {
14207 var parentNode = mask.layerElement.parentNode;
14208 if (!parentNode) return;
14209 var children = parentNode.children;
14210 var i = 0;
14211 var len = children.length;
14212 while (i < len) {
14213 if (children[i] === mask.layerElement) break;
14214 i += 1;
14215 }
14216 var nextChild;
14217 if (i <= len - 2) nextChild = children[i + 1];
14218 var useElem = createNS("use");
14219 useElem.setAttribute("href", "#" + symbolId);
14220 if (nextChild) parentNode.insertBefore(useElem, nextChild);
14221 else parentNode.appendChild(useElem);
14222 };
14223 SVGMatte3Effect.prototype.setElementAsMask = function(elem, mask) {
14224 if (!this.findSymbol(mask)) {
14225 var symbolId = createElementID();
14226 var masker = createNS("mask");
14227 masker.setAttribute("id", mask.layerId);
14228 masker.setAttribute("mask-type", "alpha");
14229 _svgMatteSymbols.push(mask);
14230 var defs = elem.globalData.defs;
14231 defs.appendChild(masker);
14232 var symbol = createNS("symbol");
14233 symbol.setAttribute("id", symbolId);
14234 this.replaceInParent(mask, symbolId);
14235 symbol.appendChild(mask.layerElement);
14236 defs.appendChild(symbol);
14237 var useElem = createNS("use");
14238 useElem.setAttribute("href", "#" + symbolId);
14239 masker.appendChild(useElem);
14240 mask.data.hd = false;
14241 mask.show();
14242 }
14243 elem.setMatte(mask.layerId);
14244 };
14245 SVGMatte3Effect.prototype.initialize = function() {
14246 var ind = this.filterManager.effectElements[0].p.v;
14247 var elements = this.elem.comp.elements;
14248 var i = 0;
14249 var len = elements.length;
14250 while (i < len) {
14251 if (elements[i] && elements[i].data.ind === ind) this.setElementAsMask(this.elem, elements[i]);
14252 i += 1;
14253 }
14254 this.initialized = true;
14255 };
14256 SVGMatte3Effect.prototype.renderFrame = function() {
14257 if (!this.initialized) this.initialize();
14258 };
14259 function SVGGaussianBlurEffect(filter, filterManager, elem, id) {
14260 filter.setAttribute("x", "-100%");
14261 filter.setAttribute("y", "-100%");
14262 filter.setAttribute("width", "300%");
14263 filter.setAttribute("height", "300%");
14264 this.filterManager = filterManager;
14265 var feGaussianBlur = createNS("feGaussianBlur");
14266 feGaussianBlur.setAttribute("result", id);
14267 filter.appendChild(feGaussianBlur);
14268 this.feGaussianBlur = feGaussianBlur;
14269 }
14270 SVGGaussianBlurEffect.prototype.renderFrame = function(forceRender) {
14271 if (forceRender || this.filterManager._mdf) {
14272 var sigma = this.filterManager.effectElements[0].p.v * .3;
14273 var dimensions = this.filterManager.effectElements[1].p.v;
14274 var sigmaX = dimensions == 3 ? 0 : sigma;
14275 var sigmaY = dimensions == 2 ? 0 : sigma;
14276 this.feGaussianBlur.setAttribute("stdDeviation", sigmaX + " " + sigmaY);
14277 var edgeMode = this.filterManager.effectElements[2].p.v == 1 ? "wrap" : "duplicate";
14278 this.feGaussianBlur.setAttribute("edgeMode", edgeMode);
14279 }
14280 };
14281 function TransformEffect() {}
14282 TransformEffect.prototype.init = function(effectsManager) {
14283 this.effectsManager = effectsManager;
14284 this.type = effectTypes.TRANSFORM_EFFECT;
14285 this.matrix = new Matrix();
14286 this.opacity = -1;
14287 this._mdf = false;
14288 this._opMdf = false;
14289 };
14290 TransformEffect.prototype.renderFrame = function(forceFrame) {
14291 this._opMdf = false;
14292 this._mdf = false;
14293 if (forceFrame || this.effectsManager._mdf) {
14294 var effectElements = this.effectsManager.effectElements;
14295 var anchor = effectElements[0].p.v;
14296 var position = effectElements[1].p.v;
14297 var isUniformScale = effectElements[2].p.v === 1;
14298 var scaleHeight = effectElements[3].p.v;
14299 var scaleWidth = isUniformScale ? scaleHeight : effectElements[4].p.v;
14300 var skew = effectElements[5].p.v;
14301 var skewAxis = effectElements[6].p.v;
14302 var rotation = effectElements[7].p.v;
14303 this.matrix.reset();
14304 this.matrix.translate(-anchor[0], -anchor[1], anchor[2]);
14305 this.matrix.scale(scaleWidth * .01, scaleHeight * .01, 1);
14306 this.matrix.rotate(-rotation * degToRads);
14307 this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads);
14308 this.matrix.translate(position[0], position[1], 0);
14309 this._mdf = true;
14310 if (this.opacity !== effectElements[8].p.v) {
14311 this.opacity = effectElements[8].p.v;
14312 this._opMdf = true;
14313 }
14314 }
14315 };
14316 function SVGTransformEffect(_, filterManager) {
14317 this.init(filterManager);
14318 }
14319 extendPrototype([TransformEffect], SVGTransformEffect);
14320 function CVTransformEffect(effectsManager) {
14321 this.init(effectsManager);
14322 }
14323 extendPrototype([TransformEffect], CVTransformEffect);
14324 registerRenderer("canvas", CanvasRenderer);
14325 registerRenderer("html", HybridRenderer);
14326 registerRenderer("svg", SVGRenderer);
14327 ShapeModifiers.registerModifier("tm", TrimModifier);
14328 ShapeModifiers.registerModifier("pb", PuckerAndBloatModifier);
14329 ShapeModifiers.registerModifier("rp", RepeaterModifier);
14330 ShapeModifiers.registerModifier("rd", RoundCornersModifier);
14331 ShapeModifiers.registerModifier("zz", ZigZagModifier);
14332 ShapeModifiers.registerModifier("op", OffsetPathModifier);
14333 setExpressionsPlugin(Expressions);
14334 setExpressionInterfaces(getInterface);
14335 initialize$1();
14336 initialize();
14337 registerEffect$1(20, SVGTintFilter, true);
14338 registerEffect$1(21, SVGFillFilter, true);
14339 registerEffect$1(22, SVGStrokeEffect, false);
14340 registerEffect$1(23, SVGTritoneFilter, true);
14341 registerEffect$1(24, SVGProLevelsFilter, true);
14342 registerEffect$1(25, SVGDropShadowEffect, true);
14343 registerEffect$1(28, SVGMatte3Effect, false);
14344 registerEffect$1(29, SVGGaussianBlurEffect, true);
14345 registerEffect$1(35, SVGTransformEffect, false);
14346 registerEffect(35, CVTransformEffect);
14347 return lottie;
14348 }));
14349 }));
14350
14351 //#endregion
14352 //#region node_modules/lottie-react/build/index.umd.js
14353 var require_index_umd = /* @__PURE__ */ __commonJSMin(((exports, module) => {
14354 (function(global, factory) {
14355 typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require_lottie(), (globalThis.React)) : typeof define === "function" && define.amd ? define([
14356 "exports",
14357 "lottie-web",
14358 "react"
14359 ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["lottie-react"] = {}, global.Lottie, global.React));
14360 })(exports, (function(exports$1, lottie, React) {
14361 "use strict";
14362 function _interopDefaultLegacy(e) {
14363 return e && typeof e === "object" && "default" in e ? e : { "default": e };
14364 }
14365 var lottie__default = /*#__PURE__*/ _interopDefaultLegacy(lottie);
14366 var React__default = /*#__PURE__*/ _interopDefaultLegacy(React);
14367 function _arrayLikeToArray(r, a) {
14368 (null == a || a > r.length) && (a = r.length);
14369 for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
14370 return n;
14371 }
14372 function _arrayWithHoles(r) {
14373 if (Array.isArray(r)) return r;
14374 }
14375 function _defineProperty(e, r, t) {
14376 return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
14377 value: t,
14378 enumerable: !0,
14379 configurable: !0,
14380 writable: !0
14381 }) : e[r] = t, e;
14382 }
14383 function _iterableToArrayLimit(r, l) {
14384 var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
14385 if (null != t) {
14386 var e;
14387 var n;
14388 var i;
14389 var u;
14390 var a = [];
14391 var f = !0;
14392 var o = !1;
14393 try {
14394 if (i = (t = t.call(r)).next, 0 === l) {
14395 if (Object(t) !== t) return;
14396 f = !1;
14397 } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
14398 } catch (r) {
14399 o = !0, n = r;
14400 } finally {
14401 try {
14402 if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
14403 } finally {
14404 if (o) throw n;
14405 }
14406 }
14407 return a;
14408 }
14409 }
14410 function _nonIterableRest() {
14411 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
14412 }
14413 function ownKeys(e, r) {
14414 var t = Object.keys(e);
14415 if (Object.getOwnPropertySymbols) {
14416 var o = Object.getOwnPropertySymbols(e);
14417 r && (o = o.filter(function(r) {
14418 return Object.getOwnPropertyDescriptor(e, r).enumerable;
14419 })), t.push.apply(t, o);
14420 }
14421 return t;
14422 }
14423 function _objectSpread2(e) {
14424 for (var r = 1; r < arguments.length; r++) {
14425 var t = null != arguments[r] ? arguments[r] : {};
14426 r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
14427 _defineProperty(e, r, t[r]);
14428 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
14429 Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
14430 });
14431 }
14432 return e;
14433 }
14434 function _objectWithoutProperties(e, t) {
14435 if (null == e) return {};
14436 var o;
14437 var r;
14438 var i = _objectWithoutPropertiesLoose(e, t);
14439 if (Object.getOwnPropertySymbols) {
14440 var s = Object.getOwnPropertySymbols(e);
14441 for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
14442 }
14443 return i;
14444 }
14445 function _objectWithoutPropertiesLoose(r, e) {
14446 if (null == r) return {};
14447 var t = {};
14448 for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
14449 if (e.includes(n)) continue;
14450 t[n] = r[n];
14451 }
14452 return t;
14453 }
14454 function _slicedToArray(r, e) {
14455 return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
14456 }
14457 function _toPrimitive(t, r) {
14458 if ("object" != typeof t || !t) return t;
14459 var e = t[Symbol.toPrimitive];
14460 if (void 0 !== e) {
14461 var i = e.call(t, r || "default");
14462 if ("object" != typeof i) return i;
14463 throw new TypeError("@@toPrimitive must return a primitive value.");
14464 }
14465 return ("string" === r ? String : Number)(t);
14466 }
14467 function _toPropertyKey(t) {
14468 var i = _toPrimitive(t, "string");
14469 return "symbol" == typeof i ? i : i + "";
14470 }
14471 function _unsupportedIterableToArray(r, a) {
14472 if (r) {
14473 if ("string" == typeof r) return _arrayLikeToArray(r, a);
14474 var t = {}.toString.call(r).slice(8, -1);
14475 return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
14476 }
14477 }
14478 var _excluded$1 = [
14479 "animationData",
14480 "loop",
14481 "autoplay",
14482 "initialSegment",
14483 "onComplete",
14484 "onLoopComplete",
14485 "onEnterFrame",
14486 "onSegmentStart",
14487 "onConfigReady",
14488 "onDataReady",
14489 "onDataFailed",
14490 "onLoadedImages",
14491 "onDOMLoaded",
14492 "onDestroy",
14493 "lottieRef",
14494 "renderer",
14495 "name",
14496 "assetsPath",
14497 "rendererSettings"
14498 ];
14499 var useLottie = function useLottie(props, style) {
14500 var animationData = props.animationData;
14501 var loop = props.loop;
14502 var autoplay = props.autoplay;
14503 var initialSegment = props.initialSegment;
14504 var onComplete = props.onComplete;
14505 var onLoopComplete = props.onLoopComplete;
14506 var onEnterFrame = props.onEnterFrame;
14507 var onSegmentStart = props.onSegmentStart;
14508 var onConfigReady = props.onConfigReady;
14509 var onDataReady = props.onDataReady;
14510 var onDataFailed = props.onDataFailed;
14511 var onLoadedImages = props.onLoadedImages;
14512 var onDOMLoaded = props.onDOMLoaded;
14513 var onDestroy = props.onDestroy;
14514 props.lottieRef;
14515 props.renderer;
14516 props.name;
14517 props.assetsPath;
14518 props.rendererSettings;
14519 var rest = _objectWithoutProperties(props, _excluded$1);
14520 var _useState2 = _slicedToArray(React.useState(false), 2);
14521 var animationLoaded = _useState2[0];
14522 var setAnimationLoaded = _useState2[1];
14523 var animationInstanceRef = React.useRef();
14524 var animationContainer = React.useRef(null);
14525 /**
14526 * Play
14527 */
14528 var play = function play() {
14529 var _a;
14530 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.play();
14531 };
14532 /**
14533 * Stop
14534 */
14535 var stop = function stop() {
14536 var _a;
14537 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.stop();
14538 };
14539 /**
14540 * Pause
14541 */
14542 var pause = function pause() {
14543 var _a;
14544 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.pause();
14545 };
14546 /**
14547 * Set animation speed
14548 * @param speed
14549 */
14550 var setSpeed = function setSpeed(speed) {
14551 var _a;
14552 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.setSpeed(speed);
14553 };
14554 /**
14555 * Got to frame and play
14556 * @param value
14557 * @param isFrame
14558 */
14559 var goToAndPlay = function goToAndPlay(value, isFrame) {
14560 var _a;
14561 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.goToAndPlay(value, isFrame);
14562 };
14563 /**
14564 * Got to frame and stop
14565 * @param value
14566 * @param isFrame
14567 */
14568 var goToAndStop = function goToAndStop(value, isFrame) {
14569 var _a;
14570 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.goToAndStop(value, isFrame);
14571 };
14572 /**
14573 * Set animation direction
14574 * @param direction
14575 */
14576 var setDirection = function setDirection(direction) {
14577 var _a;
14578 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.setDirection(direction);
14579 };
14580 /**
14581 * Play animation segments
14582 * @param segments
14583 * @param forceFlag
14584 */
14585 var playSegments = function playSegments(segments, forceFlag) {
14586 var _a;
14587 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.playSegments(segments, forceFlag);
14588 };
14589 /**
14590 * Set sub frames
14591 * @param useSubFrames
14592 */
14593 var setSubframe = function setSubframe(useSubFrames) {
14594 var _a;
14595 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.setSubframe(useSubFrames);
14596 };
14597 /**
14598 * Get animation duration
14599 * @param inFrames
14600 */
14601 var getDuration = function getDuration(inFrames) {
14602 var _a;
14603 return (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.getDuration(inFrames);
14604 };
14605 /**
14606 * Destroy animation
14607 */
14608 var destroy = function destroy() {
14609 var _a;
14610 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.destroy();
14611 animationInstanceRef.current = void 0;
14612 };
14613 /**
14614 * Load a new animation, and if it's the case, destroy the previous one
14615 * @param {Object} forcedConfigs
14616 */
14617 var loadAnimation = function loadAnimation() {
14618 var forcedConfigs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
14619 var _a;
14620 if (!animationContainer.current) return;
14621 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.destroy();
14622 var config = _objectSpread2(_objectSpread2(_objectSpread2({}, props), forcedConfigs), {}, { container: animationContainer.current });
14623 animationInstanceRef.current = lottie__default["default"].loadAnimation(config);
14624 setAnimationLoaded(!!animationInstanceRef.current);
14625 return function() {
14626 var _a;
14627 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.destroy();
14628 animationInstanceRef.current = void 0;
14629 };
14630 };
14631 /**
14632 * (Re)Initialize when animation data changed
14633 */
14634 React.useEffect(function() {
14635 var onUnmount = loadAnimation();
14636 return function() {
14637 return onUnmount === null || onUnmount === void 0 ? void 0 : onUnmount();
14638 };
14639 }, [animationData, loop]);
14640 React.useEffect(function() {
14641 if (!animationInstanceRef.current) return;
14642 animationInstanceRef.current.autoplay = !!autoplay;
14643 }, [autoplay]);
14644 React.useEffect(function() {
14645 if (!animationInstanceRef.current) return;
14646 if (!initialSegment) {
14647 animationInstanceRef.current.resetSegments(true);
14648 return;
14649 }
14650 if (!Array.isArray(initialSegment) || !initialSegment.length) return;
14651 if (animationInstanceRef.current.currentRawFrame < initialSegment[0] || animationInstanceRef.current.currentRawFrame > initialSegment[1]) animationInstanceRef.current.currentRawFrame = initialSegment[0];
14652 animationInstanceRef.current.setSegment(initialSegment[0], initialSegment[1]);
14653 }, [initialSegment]);
14654 /**
14655 * Reinitialize listener on change
14656 */
14657 React.useEffect(function() {
14658 var listeners = [
14659 {
14660 name: "complete",
14661 handler: onComplete
14662 },
14663 {
14664 name: "loopComplete",
14665 handler: onLoopComplete
14666 },
14667 {
14668 name: "enterFrame",
14669 handler: onEnterFrame
14670 },
14671 {
14672 name: "segmentStart",
14673 handler: onSegmentStart
14674 },
14675 {
14676 name: "config_ready",
14677 handler: onConfigReady
14678 },
14679 {
14680 name: "data_ready",
14681 handler: onDataReady
14682 },
14683 {
14684 name: "data_failed",
14685 handler: onDataFailed
14686 },
14687 {
14688 name: "loaded_images",
14689 handler: onLoadedImages
14690 },
14691 {
14692 name: "DOMLoaded",
14693 handler: onDOMLoaded
14694 },
14695 {
14696 name: "destroy",
14697 handler: onDestroy
14698 }
14699 ].filter(function(listener) {
14700 return listener.handler != null;
14701 });
14702 if (!listeners.length) return;
14703 var deregisterList = listeners.map(
14704 /**
14705 * Handle the process of adding an event listener
14706 * @param {Listener} listener
14707 * @return {Function} Function that deregister the listener
14708 */
14709 function(listener) {
14710 var _a;
14711 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.addEventListener(listener.name, listener.handler);
14712 return function() {
14713 var _a;
14714 (_a = animationInstanceRef.current) === null || _a === void 0 || _a.removeEventListener(listener.name, listener.handler);
14715 };
14716 }
14717 );
14718 return function() {
14719 deregisterList.forEach(function(deregister) {
14720 return deregister();
14721 });
14722 };
14723 }, [
14724 onComplete,
14725 onLoopComplete,
14726 onEnterFrame,
14727 onSegmentStart,
14728 onConfigReady,
14729 onDataReady,
14730 onDataFailed,
14731 onLoadedImages,
14732 onDOMLoaded,
14733 onDestroy
14734 ]);
14735 return {
14736 View: /* @__PURE__ */ React__default["default"].createElement("div", _objectSpread2({
14737 style,
14738 ref: animationContainer
14739 }, rest)),
14740 play,
14741 stop,
14742 pause,
14743 setSpeed,
14744 goToAndStop,
14745 goToAndPlay,
14746 setDirection,
14747 playSegments,
14748 setSubframe,
14749 getDuration,
14750 destroy,
14751 animationContainerRef: animationContainer,
14752 animationLoaded,
14753 animationItem: animationInstanceRef.current
14754 };
14755 };
14756 function getContainerVisibility(container) {
14757 var _container$getBoundin = container.getBoundingClientRect();
14758 var top = _container$getBoundin.top;
14759 var height = _container$getBoundin.height;
14760 return (window.innerHeight - top) / (window.innerHeight + height);
14761 }
14762 function getContainerCursorPosition(container, cursorX, cursorY) {
14763 var _container$getBoundin2 = container.getBoundingClientRect();
14764 var top = _container$getBoundin2.top;
14765 var left = _container$getBoundin2.left;
14766 var width = _container$getBoundin2.width;
14767 var height = _container$getBoundin2.height;
14768 return {
14769 x: (cursorX - left) / width,
14770 y: (cursorY - top) / height
14771 };
14772 }
14773 var useInitInteractivity = function useInitInteractivity(_ref) {
14774 var wrapperRef = _ref.wrapperRef;
14775 var animationItem = _ref.animationItem;
14776 var mode = _ref.mode;
14777 var actions = _ref.actions;
14778 React.useEffect(function() {
14779 var wrapper = wrapperRef.current;
14780 if (!wrapper || !animationItem || !actions.length) return;
14781 animationItem.stop();
14782 var scrollModeHandler = function scrollModeHandler() {
14783 var assignedSegment = null;
14784 var scrollHandler = function scrollHandler() {
14785 var currentPercent = getContainerVisibility(wrapper);
14786 var action = actions.find(function(_ref2) {
14787 var visibility = _ref2.visibility;
14788 return visibility && currentPercent >= visibility[0] && currentPercent <= visibility[1];
14789 });
14790 if (!action) return;
14791 if (action.type === "seek" && action.visibility && action.frames.length === 2) {
14792 var frameToGo = action.frames[0] + Math.ceil((currentPercent - action.visibility[0]) / (action.visibility[1] - action.visibility[0]) * action.frames[1]);
14793 //! goToAndStop must be relative to the start of the current segment
14794 animationItem.goToAndStop(frameToGo - animationItem.firstFrame - 1, true);
14795 }
14796 if (action.type === "loop") {
14797 if (assignedSegment === null) {
14798 animationItem.playSegments(action.frames, true);
14799 assignedSegment = action.frames;
14800 } else if (assignedSegment !== action.frames) {
14801 animationItem.playSegments(action.frames, true);
14802 assignedSegment = action.frames;
14803 } else if (animationItem.isPaused) {
14804 animationItem.playSegments(action.frames, true);
14805 assignedSegment = action.frames;
14806 }
14807 }
14808 if (action.type === "play" && animationItem.isPaused) {
14809 animationItem.resetSegments(true);
14810 animationItem.play();
14811 }
14812 if (action.type === "stop") animationItem.goToAndStop(action.frames[0] - animationItem.firstFrame - 1, true);
14813 };
14814 document.addEventListener("scroll", scrollHandler);
14815 return function() {
14816 document.removeEventListener("scroll", scrollHandler);
14817 };
14818 };
14819 var cursorModeHandler = function cursorModeHandler() {
14820 var handleCursor = function handleCursor(_x, _y) {
14821 var x = _x;
14822 var y = _y;
14823 if (x !== -1 && y !== -1) {
14824 var pos = getContainerCursorPosition(wrapper, x, y);
14825 x = pos.x;
14826 y = pos.y;
14827 }
14828 var action = actions.find(function(_ref3) {
14829 var position = _ref3.position;
14830 if (position && Array.isArray(position.x) && Array.isArray(position.y)) return x >= position.x[0] && x <= position.x[1] && y >= position.y[0] && y <= position.y[1];
14831 if (position && !Number.isNaN(position.x) && !Number.isNaN(position.y)) return x === position.x && y === position.y;
14832 return false;
14833 });
14834 if (!action) return;
14835 if (action.type === "seek" && action.position && Array.isArray(action.position.x) && Array.isArray(action.position.y) && action.frames.length === 2) {
14836 var xPercent = (x - action.position.x[0]) / (action.position.x[1] - action.position.x[0]);
14837 var yPercent = (y - action.position.y[0]) / (action.position.y[1] - action.position.y[0]);
14838 animationItem.playSegments(action.frames, true);
14839 animationItem.goToAndStop(Math.ceil((xPercent + yPercent) / 2 * (action.frames[1] - action.frames[0])), true);
14840 }
14841 if (action.type === "loop") animationItem.playSegments(action.frames, true);
14842 if (action.type === "play") {
14843 if (animationItem.isPaused) animationItem.resetSegments(false);
14844 animationItem.playSegments(action.frames);
14845 }
14846 if (action.type === "stop") animationItem.goToAndStop(action.frames[0], true);
14847 };
14848 var mouseMoveHandler = function mouseMoveHandler(ev) {
14849 handleCursor(ev.clientX, ev.clientY);
14850 };
14851 var mouseOutHandler = function mouseOutHandler() {
14852 handleCursor(-1, -1);
14853 };
14854 wrapper.addEventListener("mousemove", mouseMoveHandler);
14855 wrapper.addEventListener("mouseout", mouseOutHandler);
14856 return function() {
14857 wrapper.removeEventListener("mousemove", mouseMoveHandler);
14858 wrapper.removeEventListener("mouseout", mouseOutHandler);
14859 };
14860 };
14861 switch (mode) {
14862 case "scroll": return scrollModeHandler();
14863 case "cursor": return cursorModeHandler();
14864 }
14865 }, [mode, animationItem]);
14866 };
14867 var useLottieInteractivity = function useLottieInteractivity(_ref4) {
14868 var actions = _ref4.actions;
14869 var mode = _ref4.mode;
14870 var lottieObj = _ref4.lottieObj;
14871 var animationItem = lottieObj.animationItem;
14872 var View = lottieObj.View;
14873 var animationContainerRef = lottieObj.animationContainerRef;
14874 useInitInteractivity({
14875 actions,
14876 animationItem,
14877 mode,
14878 wrapperRef: animationContainerRef
14879 });
14880 return View;
14881 };
14882 var _excluded = ["style", "interactivity"];
14883 var Lottie = function Lottie(props) {
14884 var _a;
14885 var _b;
14886 var _c;
14887 var style = props.style;
14888 var interactivity = props.interactivity;
14889 /**
14890 * Initialize the 'useLottie' hook
14891 */
14892 var _useLottie = useLottie(_objectWithoutProperties(props, _excluded), style);
14893 var View = _useLottie.View;
14894 var play = _useLottie.play;
14895 var stop = _useLottie.stop;
14896 var pause = _useLottie.pause;
14897 var setSpeed = _useLottie.setSpeed;
14898 var goToAndStop = _useLottie.goToAndStop;
14899 var goToAndPlay = _useLottie.goToAndPlay;
14900 var setDirection = _useLottie.setDirection;
14901 var playSegments = _useLottie.playSegments;
14902 var setSubframe = _useLottie.setSubframe;
14903 var getDuration = _useLottie.getDuration;
14904 var destroy = _useLottie.destroy;
14905 var animationContainerRef = _useLottie.animationContainerRef;
14906 var animationLoaded = _useLottie.animationLoaded;
14907 var animationItem = _useLottie.animationItem;
14908 /**
14909 * Make the hook variables/methods available through the provided 'lottieRef'
14910 */
14911 React.useEffect(function() {
14912 if (props.lottieRef) props.lottieRef.current = {
14913 play,
14914 stop,
14915 pause,
14916 setSpeed,
14917 goToAndPlay,
14918 goToAndStop,
14919 setDirection,
14920 playSegments,
14921 setSubframe,
14922 getDuration,
14923 destroy,
14924 animationContainerRef,
14925 animationLoaded,
14926 animationItem
14927 };
14928 }, [(_a = props.lottieRef) === null || _a === void 0 ? void 0 : _a.current]);
14929 return useLottieInteractivity({
14930 lottieObj: {
14931 View,
14932 play,
14933 stop,
14934 pause,
14935 setSpeed,
14936 goToAndStop,
14937 goToAndPlay,
14938 setDirection,
14939 playSegments,
14940 setSubframe,
14941 getDuration,
14942 destroy,
14943 animationContainerRef,
14944 animationLoaded,
14945 animationItem
14946 },
14947 actions: (_b = interactivity === null || interactivity === void 0 ? void 0 : interactivity.actions) !== null && _b !== void 0 ? _b : [],
14948 mode: (_c = interactivity === null || interactivity === void 0 ? void 0 : interactivity.mode) !== null && _c !== void 0 ? _c : "scroll"
14949 });
14950 };
14951 Object.defineProperty(exports$1, "LottiePlayer", {
14952 enumerable: true,
14953 get: function() {
14954 return lottie__default["default"];
14955 }
14956 });
14957 exports$1["default"] = Lottie;
14958 exports$1.useLottie = useLottie;
14959 exports$1.useLottieInteractivity = useLottieInteractivity;
14960 Object.defineProperty(exports$1, "__esModule", { value: true });
14961 }));
14962 }));
14963
14964 //#endregion
14965 //#region packages/packages/libs/editor-modal-shell/src/components/background-lottie.tsx
14966 var import_index_umd = /* @__PURE__ */ __toESM(require_index_umd());
14967 function BackgroundLottie({ animationData, loop = false, autoplay = true, zIndex = MODAL_Z_INDEX - 1, backgroundColor = "transparent", onComplete = () => {} }) {
14968 const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
14969 (0, react.useEffect)(() => {
14970 if (prefersReducedMotion) onComplete?.();
14971 }, [prefersReducedMotion, onComplete]);
14972 if (prefersReducedMotion) return null;
14973 return /* @__PURE__ */ react.createElement(import_index_umd.default, {
14974 animationData,
14975 loop,
14976 autoplay,
14977 onComplete: loop ? void 0 : onComplete,
14978 onDataFailed: onComplete,
14979 rendererSettings: { preserveAspectRatio: "xMidYMid slice" },
14980 style: {
14981 position: "fixed",
14982 inset: 0,
14983 width: "100vw",
14984 height: "100vh",
14985 zIndex,
14986 backgroundColor,
14987 pointerEvents: "none"
14988 }
14989 });
14990 }
14991
14992 //#endregion
14993 //#region packages/packages/libs/editor-modal-shell/src/hooks/use-autoplay-carousel.ts
14994 var DEFAULT_INTERVAL_MS = 4e3;
14995 function useAutoplayCarousel(items, intervalMs = DEFAULT_INTERVAL_MS) {
14996 const [selectedItem, setSelectedItem] = (0, react.useState)(items[0]);
14997 const [isAutoPlaying, setIsAutoPlaying] = (0, react.useState)(true);
14998 const advanceToNextItem = (0, react.useCallback)(() => {
14999 setSelectedItem((current) => {
15000 return items[(items.indexOf(current) + 1) % items.length];
15001 });
15002 }, [items]);
15003 (0, react.useEffect)(() => {
15004 if (!isAutoPlaying) return;
15005 const id = setInterval(advanceToNextItem, intervalMs);
15006 return () => clearInterval(id);
15007 }, [
15008 isAutoPlaying,
15009 advanceToNextItem,
15010 intervalMs
15011 ]);
15012 return {
15013 selectedItem,
15014 selectItem: (0, react.useCallback)((item) => {
15015 setSelectedItem(item);
15016 setIsAutoPlaying(false);
15017 }, [])
15018 };
15019 }
15020
15021 //#endregion
15022 //#region packages/packages/libs/editor-modal-shell/src/index.ts
15023 var src_exports = /* @__PURE__ */ __exportAll({
15024 BackgroundLottie: () => BackgroundLottie,
15025 MODAL_Z_INDEX: () => MODAL_Z_INDEX,
15026 ModalFooter: () => ModalFooter,
15027 ModalHeader: () => ModalHeader,
15028 ModalShell: () => ModalShell,
15029 useAutoplayCarousel: () => useAutoplayCarousel,
15030 useModalShell: () => useModalShell
15031 });
15032
15033 //#endregion
15034 //#region \0elementor-package-library-entry
15035 (window.elementorV2 = window.elementorV2 || {}).editorModalShell = src_exports;
15036
15037 //#endregion
15038 })(React, elementorV2.ui);
15039 window.elementorV2.editorModalShell?.init?.();
15040 //# sourceMappingURL=editor-modal-shell.js.map