vendor: 5,319 bytes, lines 1-186
1(typeof navigator !== "undefined") && (function(root, factory) { 2 if (typeof define === "function" && define.amd) { 3 define(function() { 4 return factory(root); 5 }); 6 } else if (typeof module === "object" && module.exports) { 7 module.exports = factory(root); 8 } else { 9 root.lottie = factory(root); 10 root.bodymovin = root.lottie; 11 } 12}((window || {}), function(window) { 13 /* global locationHref:writable, animationManager, subframeEnabled:writable, defaultCurveSegments:writable, roundValues, 14expressionsPlugin:writable, PropertyFactory, ShapePropertyFactory, Matrix */ 15/* exported locationHref, subframeEnabled, expressionsPlugin */ 16 17'use strict'; 18 19/* exported svgNS, locationHref, initialDefaultFrame */ 20 21var svgNS = 'http://www.w3.org/2000/svg'; 22 23var locationHref = ''; 24 25var initialDefaultFrame = -999999; 26 27/* global createSizedArray */ 28/* exported subframeEnabled, expressionsPlugin, isSafari, cachedColors, bmPow, bmSqrt, bmFloor, bmMax, bmMin, ProjectInterface, 29defaultCurveSegments, degToRads, roundCorner, bmRnd, styleDiv, BMEnterFrameEvent, BMCompleteEvent, BMCompleteLoopEvent, 30BMSegmentStartEvent, BMDestroyEvent, BMRenderFrameErrorEvent, BMConfigErrorEvent, BMAnimationConfigErrorEvent, createElementID, 31addSaturationToRGB, addBrightnessToRGB, addHueToRGB, rgbToHex */ 32 33var subframeEnabled = true; 34var expressionsPlugin; 35var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); 36var cachedColors = {}; 37var bmRnd; 38var bmPow = Math.pow; 39var bmSqrt = Math.sqrt; 40var bmFloor = Math.floor; 41var bmMax = Math.max; 42var bmMin = Math.min; 43 44var BMMath = {}; 45(function () { 46 var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2']; 47 var i; 48 var len = propertyNames.length; 49 for (i = 0; i < len; i += 1) { 50 BMMath[propertyNames[i]] = Math[propertyNames[i]]; 51 } 52}()); 53 54function ProjectInterface() { return {}; } 55 56BMMath.random = Math.random; 57BMMath.abs = function (val) { 58 var tOfVal = typeof val; 59 if (tOfVal === 'object' && val.length) { 60 var absArr = createSizedArray(val.length); 61 var i; 62 var len = val.length; 63 for (i = 0; i < len; i += 1) { 64 absArr[i] = Math.abs(val[i]); 65 } 66 return absArr; 67 } 68 return Math.abs(val); 69}; 70var defaultCurveSegments = 150; 71var degToRads = Math.PI / 180; 72var roundCorner = 0.5519; 73 74function roundValues(flag) { 75 if (flag) { 76 bmRnd = Math.round; 77 } else { 78 bmRnd = function (val) { 79 return val; 80 }; 81 } 82} 83roundValues(false); 84 85function styleDiv(element) { 86 element.style.position = 'absolute'; 87 element.style.top = 0; 88 element.style.left = 0; 89 element.style.display = 'block'; 90 element.style.transformOrigin = '0 0'; 91 element.style.webkitTransformOrigin = '0 0'; 92 element.style.backfaceVisibility = 'visible'; 93 element.style.webkitBackfaceVisibility = 'visible'; 94 element.style.transformStyle = 'preserve-3d'; 95 element.style.webkitTransformStyle = 'preserve-3d'; 96 element.style.mozTransformStyle = 'preserve-3d'; 97} 98 99function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) { 100 this.type = type; 101 this.currentTime = currentTime; 102 this.totalTime = totalTime; 103 this.direction = frameMultiplier < 0 ? -1 : 1; 104} 105 106function BMCompleteEvent(type, frameMultiplier) { 107 this.type = type; 108 this.direction = frameMultiplier < 0 ? -1 : 1; 109} 110 111function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) { 112 this.type = type; 113 this.currentLoop = currentLoop; 114 this.totalLoops = totalLoops; 115 this.direction = frameMultiplier < 0 ? -1 : 1; 116} 117 118function BMSegmentStartEvent(type, firstFrame, totalFrames) { 119 this.type = type; 120 this.firstFrame = firstFrame; 121 this.totalFrames = totalFrames; 122} 123 124function BMDestroyEvent(type, target) { 125 this.type = type; 126 this.target = target; 127} 128 129function BMRenderFrameErrorEvent(nativeError, currentTime) { 130 this.type = 'renderFrameError'; 131 this.nativeError = nativeError; 132 this.currentTime = currentTime; 133} 134 135function BMConfigErrorEvent(nativeError) { 136 this.type = 'configError'; 137 this.nativeError = nativeError; 138} 139 140function BMAnimationConfigErrorEvent(type, nativeError) { 141 this.type = type; 142 this.nativeError = nativeError; 143} 144 145var createElementID = (function () { 146 var _count = 0; 147 return function createID() { 148 _count += 1; 149 return '__lottie_element_' + _count; 150 }; 151}()); 152 153function HSVtoRGB(h, s, v) { 154 var r; 155 var g; 156 var b; 157 var i; 158 var f; 159 var p; 160 var q; 161 var t; 162 i = Math.floor(h * 6); 163 f = h * 6 - i; 164 p = v * (1 - s); 165 q = v * (1 - f * s); 166 t = v * (1 - (1 - f) * s); 167 switch (i % 6) { 168 case 0: r = v; g = t; b = p; break; 169 case 1: r = q; g = v; b = p; break; 170 case 2: r = p; g = v; b = t; break; 171 case 3: r = p; g = q; b = v; break; 172 case 4: r = t; g = p; b = v; break; 173 case 5: r = v; g = p; b = q; break; 174 default: break; 175 } 176 return [r, 177 g, 178 b]; 179} 180 181function RGBtoHSV(r, g, b) { 182 var max = Math.max(r, g, b); 183 var min = Math.min(r, g, b); 184 var d = max - min; 185 var h; 186 var s = (max === 0 ? 0 : d / max);
vendor: 4,232 bytes, lines 187-367
187 var v = max / 255; 188 189 switch (max) { 190 case min: h = 0; break; 191 case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break; 192 case g: h = (b - r) + d * 2; h /= 6 * d; break; 193 case b: h = (r - g) + d * 4; h /= 6 * d; break; 194 default: break; 195 } 196 197 return [ 198 h, 199 s, 200 v, 201 ]; 202} 203 204function addSaturationToRGB(color, offset) { 205 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255); 206 hsv[1] += offset; 207 if (hsv[1] > 1) { 208 hsv[1] = 1; 209 } else if (hsv[1] <= 0) { 210 hsv[1] = 0; 211 } 212 return HSVtoRGB(hsv[0], hsv[1], hsv[2]); 213} 214 215function addBrightnessToRGB(color, offset) { 216 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255); 217 hsv[2] += offset; 218 if (hsv[2] > 1) { 219 hsv[2] = 1; 220 } else if (hsv[2] < 0) { 221 hsv[2] = 0; 222 } 223 return HSVtoRGB(hsv[0], hsv[1], hsv[2]); 224} 225 226function addHueToRGB(color, offset) { 227 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255); 228 hsv[0] += offset / 360; 229 if (hsv[0] > 1) { 230 hsv[0] -= 1; 231 } else if (hsv[0] < 0) { 232 hsv[0] += 1; 233 } 234 return HSVtoRGB(hsv[0], hsv[1], hsv[2]); 235} 236 237var rgbToHex = (function () { 238 var colorMap = []; 239 var i; 240 var hex; 241 for (i = 0; i < 256; i += 1) { 242 hex = i.toString(16); 243 colorMap[i] = hex.length === 1 ? '0' + hex : hex; 244 } 245 246 return function (r, g, b) { 247 if (r < 0) { 248 r = 0; 249 } 250 if (g < 0) { 251 g = 0; 252 } 253 if (b < 0) { 254 b = 0; 255 } 256 return '#' + colorMap[r] + colorMap[g] + colorMap[b]; 257 }; 258}()); 259 260function BaseEvent() {} 261BaseEvent.prototype = { 262 triggerEvent: function (eventName, args) { 263 if (this._cbs[eventName]) { 264 var len = this._cbs[eventName].length; 265 for (var i = 0; i < len; i += 1) { 266 this._cbs[eventName][i](args); 267 } 268 } 269 }, 270 addEventListener: function (eventName, callback) { 271 if (!this._cbs[eventName]) { 272 this._cbs[eventName] = []; 273 } 274 this._cbs[eventName].push(callback); 275 276 return function () { 277 this.removeEventListener(eventName, callback); 278 }.bind(this); 279 }, 280 removeEventListener: function (eventName, callback) { 281 if (!callback) { 282 this._cbs[eventName] = null; 283 } else if (this._cbs[eventName]) { 284 var i = 0; 285 var len = this._cbs[eventName].length; 286 while (i < len) { 287 if (this._cbs[eventName][i] === callback) { 288 this._cbs[eventName].splice(i, 1); 289 i -= 1; 290 len -= 1; 291 } 292 i += 1; 293 } 294 if (!this._cbs[eventName].length) { 295 this._cbs[eventName] = null; 296 } 297 } 298 }, 299}; 300 301/* exported createTypedArray, createSizedArray */ 302 303var createTypedArray = (function () { 304 function createRegularArray(type, len) { 305 var i = 0; 306 var arr = []; 307 var value; 308 switch (type) { 309 case 'int16': 310 case 'uint8c': 311 value = 1; 312 break; 313 default: 314 value = 1.1; 315 break; 316 } 317 for (i = 0; i < len; i += 1) { 318 arr.push(value); 319 } 320 return arr; 321 } 322 function createTypedArrayFactory(type, len) { 323 if (type === 'float32') { 324 return new Float32Array(len); 325 } if (type === 'int16') { 326 return new Int16Array(len); 327 } if (type === 'uint8c') { 328 return new Uint8ClampedArray(len); 329 } 330 return createRegularArray(type, len); 331 } 332 if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') { 333 return createTypedArrayFactory; 334 } 335 return createRegularArray; 336}()); 337 338function createSizedArray(len) { 339 return Array.apply(null, { length: len }); 340} 341 342/* global svgNS */ 343/* exported createNS */ 344 345function createNS(type) { 346 // return {appendChild:function(){},setAttribute:function(){},style:{}} 347 return document.createElementNS(svgNS, type); 348} 349 350/* exported createTag */ 351 352function createTag(type) { 353 // return {appendChild:function(){},setAttribute:function(){},style:{}} 354 return document.createElement(type); 355} 356 357function DynamicPropertyContainer() {} 358DynamicPropertyContainer.prototype = { 359 addDynamicProperty: function (prop) { 360 if (this.dynamicProperties.indexOf(prop) === -1) { 361 this.dynamicProperties.push(prop); 362 this.container.addDynamicProperty(this); 363 this._isAnimated = true; 364 } 365 }, 366 iterateDynamicProperties: function () { 367 this._mdf = false;
vendor: 11,513 bytes, lines 368-776
368 var i; 369 var len = this.dynamicProperties.length; 370 for (i = 0; i < len; i += 1) { 371 this.dynamicProperties[i].getValue(); 372 if (this.dynamicProperties[i]._mdf) { 373 this._mdf = true; 374 } 375 } 376 }, 377 initDynamicPropertyContainer: function (container) { 378 this.container = container; 379 this.dynamicProperties = []; 380 this._mdf = false; 381 this._isAnimated = false; 382 }, 383}; 384 385/* exported getBlendMode */ 386 387var getBlendMode = (function () { 388 var blendModeEnums = { 389 0: 'source-over', 390 1: 'multiply', 391 2: 'screen', 392 3: 'overlay', 393 4: 'darken', 394 5: 'lighten', 395 6: 'color-dodge', 396 7: 'color-burn', 397 8: 'hard-light', 398 9: 'soft-light', 399 10: 'difference', 400 11: 'exclusion', 401 12: 'hue', 402 13: 'saturation', 403 14: 'color', 404 15: 'luminosity', 405 }; 406 407 return function (mode) { 408 return blendModeEnums[mode] || ''; 409 }; 410}()); 411 412/* global createTypedArray */ 413 414/*! 415 Transformation Matrix v2.0 416 (c) Epistemex 2014-2015 417 www.epistemex.com 418 By Ken Fyrstenberg 419 Contributions by leeoniya. 420 License: MIT, header required. 421 */ 422 423/** 424 * 2D transformation matrix object initialized with identity matrix. 425 * 426 * The matrix can synchronize a canvas context by supplying the context 427 * as an argument, or later apply current absolute transform to an 428 * existing context. 429 * 430 * All values are handled as floating point values. 431 * 432 * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix 433 * @prop {number} a - scale x 434 * @prop {number} b - shear y 435 * @prop {number} c - shear x 436 * @prop {number} d - scale y 437 * @prop {number} e - translate x 438 * @prop {number} f - translate y 439 * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context 440 * @constructor 441 */ 442 443var Matrix = (function () { 444 var _cos = Math.cos; 445 var _sin = Math.sin; 446 var _tan = Math.tan; 447 var _rnd = Math.round; 448 449 function reset() { 450 this.props[0] = 1; 451 this.props[1] = 0; 452 this.props[2] = 0; 453 this.props[3] = 0; 454 this.props[4] = 0; 455 this.props[5] = 1; 456 this.props[6] = 0; 457 this.props[7] = 0; 458 this.props[8] = 0; 459 this.props[9] = 0; 460 this.props[10] = 1; 461 this.props[11] = 0; 462 this.props[12] = 0; 463 this.props[13] = 0; 464 this.props[14] = 0; 465 this.props[15] = 1; 466 return this; 467 } 468 469 function rotate(angle) { 470 if (angle === 0) { 471 return this; 472 } 473 var mCos = _cos(angle); 474 var mSin = _sin(angle); 475 return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 476 } 477 478 function rotateX(angle) { 479 if (angle === 0) { 480 return this; 481 } 482 var mCos = _cos(angle); 483 var mSin = _sin(angle); 484 return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1); 485 } 486 487 function rotateY(angle) { 488 if (angle === 0) { 489 return this; 490 } 491 var mCos = _cos(angle); 492 var mSin = _sin(angle); 493 return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1); 494 } 495 496 function rotateZ(angle) { 497 if (angle === 0) { 498 return this; 499 } 500 var mCos = _cos(angle); 501 var mSin = _sin(angle); 502 return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 503 } 504 505 function shear(sx, sy) { 506 return this._t(1, sy, sx, 1, 0, 0); 507 } 508 509 function skew(ax, ay) { 510 return this.shear(_tan(ax), _tan(ay)); 511 } 512 513 function skewFromAxis(ax, angle) { 514 var mCos = _cos(angle); 515 var mSin = _sin(angle); 516 return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) 517 ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) 518 ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 519 // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0); 520 } 521 522 function scale(sx, sy, sz) { 523 if (!sz && sz !== 0) { 524 sz = 1; 525 } 526 if (sx === 1 && sy === 1 && sz === 1) { 527 return this; 528 } 529 return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1); 530 } 531 532 function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) { 533 this.props[0] = a; 534 this.props[1] = b; 535 this.props[2] = c; 536 this.props[3] = d; 537 this.props[4] = e; 538 this.props[5] = f; 539 this.props[6] = g; 540 this.props[7] = h; 541 this.props[8] = i; 542 this.props[9] = j; 543 this.props[10] = k; 544 this.props[11] = l; 545 this.props[12] = m; 546 this.props[13] = n; 547 this.props[14] = o; 548 this.props[15] = p; 549 return this; 550 } 551 552 function translate(tx, ty, tz) { 553 tz = tz || 0; 554 if (tx !== 0 || ty !== 0 || tz !== 0) { 555 return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1); 556 } 557 return this; 558 } 559 560 function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) { 561 var _p = this.props; 562 563 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) { 564 // NOTE: commenting this condition because TurboFan deoptimizes code when present 565 // if(m2 !== 0 || n2 !== 0 || o2 !== 0){ 566 _p[12] = _p[12] * a2 + _p[15] * m2; 567 _p[13] = _p[13] * f2 + _p[15] * n2; 568 _p[14] = _p[14] * k2 + _p[15] * o2; 569 _p[15] *= p2; 570 // } 571 this._identityCalculated = false; 572 return this; 573 } 574 575 var a1 = _p[0]; 576 var b1 = _p[1]; 577 var c1 = _p[2]; 578 var d1 = _p[3]; 579 var e1 = _p[4]; 580 var f1 = _p[5]; 581 var g1 = _p[6]; 582 var h1 = _p[7]; 583 var i1 = _p[8]; 584 var j1 = _p[9]; 585 var k1 = _p[10]; 586 var l1 = _p[11]; 587 var m1 = _p[12]; 588 var n1 = _p[13]; 589 var o1 = _p[14]; 590 var p1 = _p[15]; 591 592 /* matrix order (canvas compatible): 593 * ace 594 * bdf 595 * 001 596 */ 597 _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2; 598 _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2; 599 _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2; 600 _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2; 601 602 _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2; 603 _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2; 604 _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2; 605 _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2; 606 607 _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2; 608 _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2; 609 _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2; 610 _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2; 611 612 _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2; 613 _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2; 614 _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2; 615 _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2; 616 617 this._identityCalculated = false; 618 return this; 619 } 620 621 function isIdentity() { 622 if (!this._identityCalculated) { 623 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); 624 this._identityCalculated = true; 625 } 626 return this._identity; 627 } 628 629 function equals(matr) { 630 var i = 0; 631 while (i < 16) { 632 if (matr.props[i] !== this.props[i]) { 633 return false; 634 } 635 i += 1; 636 } 637 return true; 638 } 639 640 function clone(matr) { 641 var i; 642 for (i = 0; i < 16; i += 1) { 643 matr.props[i] = this.props[i]; 644 } 645 return matr; 646 } 647 648 function cloneFromProps(props) { 649 var i; 650 for (i = 0; i < 16; i += 1) { 651 this.props[i] = props[i]; 652 } 653 } 654 655 function applyToPoint(x, y, z) { 656 return { 657 x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], 658 y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], 659 z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14], 660 }; 661 /* return { 662 x: x * me.a + y * me.c + me.e, 663 y: x * me.b + y * me.d + me.f 664 }; */ 665 } 666 function applyToX(x, y, z) { 667 return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12]; 668 } 669 function applyToY(x, y, z) { 670 return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13]; 671 } 672 function applyToZ(x, y, z) { 673 return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]; 674 } 675 676 function getInverseMatrix() { 677 var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4]; 678 var a = this.props[5] / determinant; 679 var b = -this.props[1] / determinant; 680 var c = -this.props[4] / determinant; 681 var d = this.props[0] / determinant; 682 var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant; 683 var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant; 684 var inverseMatrix = new Matrix(); 685 inverseMatrix.props[0] = a; 686 inverseMatrix.props[1] = b; 687 inverseMatrix.props[4] = c; 688 inverseMatrix.props[5] = d; 689 inverseMatrix.props[12] = e; 690 inverseMatrix.props[13] = f; 691 return inverseMatrix; 692 } 693 694 function inversePoint(pt) { 695 var inverseMatrix = this.getInverseMatrix(); 696 return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0); 697 } 698 699 function inversePoints(pts) { 700 var i; 701 var len = pts.length; 702 var retPts = []; 703 for (i = 0; i < len; i += 1) { 704 retPts[i] = inversePoint(pts[i]); 705 } 706 return retPts; 707 } 708 709 function applyToTriplePoints(pt1, pt2, pt3) { 710 var arr = createTypedArray('float32', 6); 711 if (this.isIdentity()) { 712 arr[0] = pt1[0]; 713 arr[1] = pt1[1]; 714 arr[2] = pt2[0]; 715 arr[3] = pt2[1]; 716 arr[4] = pt3[0]; 717 arr[5] = pt3[1]; 718 } else { 719 var p0 = this.props[0]; 720 var p1 = this.props[1]; 721 var p4 = this.props[4]; 722 var p5 = this.props[5]; 723 var p12 = this.props[12]; 724 var p13 = this.props[13]; 725 arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12; 726 arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13; 727 arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12; 728 arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13; 729 arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12; 730 arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13; 731 } 732 return arr; 733 } 734 735 function applyToPointArray(x, y, z) { 736 var arr; 737 if (this.isIdentity()) { 738 arr = [x, y, z]; 739 } else { 740 arr = [ 741 x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], 742 x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], 743 x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14], 744 ]; 745 } 746 return arr; 747 } 748 749 function applyToPointStringified(x, y) { 750 if (this.isIdentity()) { 751 return x + ',' + y; 752 } 753 var _p = this.props; 754 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; 755 } 756 757 function toCSS() { 758 // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed. 759 /* if(this.isIdentity()) { 760 return ''; 761 } */ 762 var i = 0; 763 var props = this.props; 764 var cssValue = 'matrix3d('; 765 var v = 10000; 766 while (i < 16) { 767 cssValue += _rnd(props[i] * v) / v; 768 cssValue += i === 15 ? ')' : ','; 769 i += 1; 770 } 771 return cssValue; 772 } 773 774 function roundMatrixProperty(val) { 775 var v = 10000; 776 if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
777 return _rnd(val * v) / v; 778 } 779 return val; 780 } 781 782 function to2dCSS() { 783 // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed. 784 /* if(this.isIdentity()) { 785 return ''; 786 } */ 787 var props = this.props; 788 var _a = roundMatrixProperty(props[0]); 789 var _b = roundMatrixProperty(props[1]); 790 var _c = roundMatrixProperty(props[4]); 791 var _d = roundMatrixProperty(props[5]); 792 var _e = roundMatrixProperty(props[12]); 793 var _f = roundMatrixProperty(props[13]); 794 return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')'; 795 } 796 797 return function () { 798 this.reset = reset; 799 this.rotate = rotate; 800 this.rotateX = rotateX; 801 this.rotateY = rotateY; 802 this.rotateZ = rotateZ; 803 this.skew = skew; 804 this.skewFromAxis = skewFromAxis; 805 this.shear = shear; 806 this.scale = scale; 807 this.setTransform = setTransform; 808 this.translate = translate; 809 this.transform = transform; 810 this.applyToPoint = applyToPoint; 811 this.applyToX = applyToX; 812 this.applyToY = applyToY; 813 this.applyToZ = applyToZ; 814 this.applyToPointArray = applyToPointArray; 815 this.applyToTriplePoints = applyToTriplePoints; 816 this.applyToPointStringified = applyToPointStringified; 817 this.toCSS = toCSS; 818 this.to2dCSS = to2dCSS; 819 this.clone = clone; 820 this.cloneFromProps = cloneFromProps; 821 this.equals = equals; 822 this.inversePoints = inversePoints; 823 this.inversePoint = inversePoint; 824 this.getInverseMatrix = getInverseMatrix; 825 this._t = this.transform; 826 this.isIdentity = isIdentity; 827 this._identity = true; 828 this._identityCalculated = false; 829 830 this.props = createTypedArray('float32', 16); 831 this.reset(); 832 }; 833}()); 834 835/* eslint-disable */ 836/* 837 Copyright 2014 David Bau. 838 839 Permission is hereby granted, free of charge, to any person obtaining 840 a copy of this software and associated documentation files (the 841 "Software"), to deal in the Software without restriction, including 842 without limitation the rights to use, copy, modify, merge, publish, 843 distribute, sublicense, and/or sell copies of the Software, and to 844 permit persons to whom the Software is furnished to do so, subject to 845 the following conditions: 846 847 The above copyright notice and this permission notice shall be 848 included in all copies or substantial portions of the Software. 849 850 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 851 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 852 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 853 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 854 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 855 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 856 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 857 858 */ 859 860(function
vendor: 7,580 bytes, lines 860-1065
860(pool, math) { 861// 862// The following constants are related to IEEE 754 limits. 863// 864 var global = this, 865 width = 256, // each RC4 output is 0 <= x < 256 866 chunks = 6, // at least six RC4 outputs for each double 867 digits = 52, // there are 52 significant digits in a double 868 rngname = 'random', // rngname: name for Math.random and Math.seedrandom 869 startdenom = math.pow(width, chunks), 870 significance = math.pow(2, digits), 871 overflow = significance * 2, 872 mask = width - 1, 873 nodecrypto; // node.js crypto module, initialized at the bottom. 874 875// 876// seedrandom() 877// This is the seedrandom function described above. 878// 879 function seedrandom(seed, options, callback) { 880 var key = []; 881 options = (options === true) ? { entropy: true } : (options || {}); 882 883 // Flatten the seed string or build one from local entropy if needed. 884 var shortseed = mixkey(flatten( 885 options.entropy ? [seed, tostring(pool)] : 886 (seed === null) ? autoseed() : seed, 3), key); 887 888 // Use the seed to initialize an ARC4 generator. 889 var arc4 = new ARC4(key); 890 891 // This function returns a random double in [0, 1) that contains 892 // randomness in every bit of the mantissa of the IEEE 754 value. 893 var prng = function() { 894 var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 895 d = startdenom, // and denominator d = 2 ^ 48. 896 x = 0; // and no 'extra last byte'. 897 while (n < significance) { // Fill up all significant digits by 898 n = (n + x) * width; // shifting numerator and 899 d *= width; // denominator and generating a 900 x = arc4.g(1); // new least-significant-byte. 901 } 902 while (n >= overflow) { // To avoid rounding up, before adding 903 n /= 2; // last byte, shift everything 904 d /= 2; // right using integer math until 905 x >>>= 1; // we have exactly the desired bits. 906 } 907 return (n + x) / d; // Form the number within [0, 1). 908 }; 909 910 prng.int32 = function() { return arc4.g(4) | 0; }; 911 prng.quick = function() { return arc4.g(4) / 0x100000000; }; 912 prng.double = prng; 913 914 // Mix the randomness into accumulated entropy. 915 mixkey(tostring(arc4.S), pool); 916 917 // Calling convention: what to return as a function of prng, seed, is_math. 918 return (options.pass || callback || 919 function(prng, seed, is_math_call, state) { 920 if (state) { 921 // Load the arc4 state from the given state if it has an S array. 922 if (state.S) { copy(state, arc4); } 923 // Only provide the .state method if requested via options.state. 924 prng.state = function() { return copy(arc4, {}); }; 925 } 926 927 // If called as a method of Math (Math.seedrandom()), mutate 928 // Math.random because that is how seedrandom.js has worked since v1.0. 929 if (is_math_call) { math[rngname] = prng; return seed; } 930 931 // Otherwise, it is a newer calling convention, so return the 932 // prng directly. 933 else return prng; 934 })( 935 prng, 936 shortseed, 937 'global' in options ? options.global : (this == math), 938 options.state); 939 } 940 math['seed' + rngname] = seedrandom; 941 942// 943// ARC4 944// 945// An ARC4 implementation. The constructor takes a key in the form of 946// an array of at most (width) integers that should be 0 <= x < (width). 947// 948// The g(count) method returns a pseudorandom integer that concatenates 949// the next (count) outputs from ARC4. Its return value is a number x 950// that is in the range 0 <= x < (width ^ count). 951// 952 function ARC4(key) { 953 var t, keylen = key.length, 954 me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; 955 956 // The empty key [] is treated as [0]. 957 if (!keylen) { key = [keylen++]; } 958 959 // Set up S using the standard key scheduling algorithm. 960 while (i < width) { 961 s[i] = i++; 962 } 963 for (i = 0; i < width; i++) { 964 s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; 965 s[j] = t; 966 } 967 968 // The "g" method returns the next (count) outputs as one number. 969 me.g = function(count) { 970 // Using instance members instead of closure state nearly doubles speed. 971 var t, r = 0, 972 i = me.i, j = me.j, s = me.S; 973 while (count--) { 974 t = s[i = mask & (i + 1)]; 975 r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; 976 } 977 me.i = i; me.j = j; 978 return r; 979 // For robust unpredictability, the function call below automatically 980 // discards an initial batch of values. This is called RC4-drop[256]. 981 // See http://google.com/search?q=rsa+fluhrer+response&btnI 982 }; 983 } 984 985// 986// copy() 987// Copies internal state of ARC4 to or from a plain object. 988// 989 function copy(f, t) { 990 t.i = f.i; 991 t.j = f.j; 992 t.S = f.S.slice(); 993 return t; 994 } 995 996// 997// flatten() 998// Converts an object tree to nested arrays of strings. 999// 1000 function flatten(obj, depth) { 1001 var result = [], typ = (typeof obj), prop; 1002 if (depth && typ == 'object') { 1003 for (prop in obj) { 1004 try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} 1005 } 1006 } 1007 return (result.length ? result : typ == 'string' ? obj : obj + '\0'); 1008 } 1009 1010// 1011// mixkey() 1012// Mixes a string seed into a key that is an array of integers, and 1013// returns a shortened string seed that is equivalent to the result key. 1014// 1015 function mixkey(seed, key) { 1016 var stringseed = seed + '', smear, j = 0; 1017 while (j < stringseed.length) { 1018 key[mask & j] = 1019 mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); 1020 } 1021 return tostring(key); 1022 } 1023 1024// 1025// autoseed() 1026// Returns an object for autoseeding, using window.crypto and Node crypto 1027// module if available. 1028// 1029 function autoseed() { 1030 try { 1031 if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); } 1032 var out = new Uint8Array(width); 1033 (global.crypto || global.msCrypto).getRandomValues(out); 1034 return tostring(out); 1035 } catch (e) { 1036 var browser = global.navigator, 1037 plugins = browser && browser.plugins; 1038 return [+new Date(), global, plugins, global.screen, tostring(pool)]; 1039 } 1040 } 1041 1042// 1043// tostring() 1044// Converts an array of charcodes to a string 1045// 1046 function tostring(a) { 1047 return String.fromCharCode.apply(0, a); 1048 } 1049 1050// 1051// When seedrandom.js is loaded, we immediately mix a few bits 1052// from the built-in RNG into the entropy pool. Because we do 1053// not want to interfere with deterministic PRNG state later, 1054// seedrandom will not call math.random on its own again after 1055// initialization. 1056// 1057 mixkey(math.random(), pool); 1058 1059// 1060// Nodejs and AMD support: export the implementation as a module using 1061// either convention. 1062// 1063 1064// End anonymous scope, and pass initial values. 1065}
vendor: 41,121 bytes, lines 1065-2351
1065)( 1066 [], // pool: entropy pool starts empty 1067 BMMath // math: package containing random, pow, and seedrandom 1068); 1069/* eslint-disable */ 1070var BezierFactory = (function () { 1071 /** 1072 * BezierEasing - use bezier curve for transition easing function 1073 * by Gaëtan Renaudeau 2014 - 2015 – MIT License 1074 * 1075 * Credits: is based on Firefox's nsSMILKeySpline.cpp 1076 * Usage: 1077 * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ]) 1078 * spline.get(x) => returns the easing value | x must be in [0, 1] range 1079 * 1080 */ 1081 1082 var ob = {}; 1083 ob.getBezierEasing = getBezierEasing; 1084 var beziers = {}; 1085 1086 function getBezierEasing(a, b, c, d, nm) { 1087 var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p'); 1088 if (beziers[str]) { 1089 return beziers[str]; 1090 } 1091 var bezEasing = new BezierEasing([a, b, c, d]); 1092 beziers[str] = bezEasing; 1093 return bezEasing; 1094 } 1095 1096 // These values are established by empiricism with tests (tradeoff: performance VS precision) 1097 var NEWTON_ITERATIONS = 4; 1098 var NEWTON_MIN_SLOPE = 0.001; 1099 var SUBDIVISION_PRECISION = 0.0000001; 1100 var SUBDIVISION_MAX_ITERATIONS = 10; 1101 1102 var kSplineTableSize = 11; 1103 var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); 1104 1105 var float32ArraySupported = typeof Float32Array === 'function'; 1106 1107 function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } 1108 function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; } 1109 function C(aA1) { return 3.0 * aA1; } 1110 1111 // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. 1112 function calcBezier(aT, aA1, aA2) { 1113 return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; 1114 } 1115 1116 // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. 1117 function getSlope(aT, aA1, aA2) { 1118 return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); 1119 } 1120 1121 function binarySubdivide(aX, aA, aB, mX1, mX2) { 1122 var currentX, 1123 currentT, 1124 i = 0; 1125 do { 1126 currentT = aA + (aB - aA) / 2.0; 1127 currentX = calcBezier(currentT, mX1, mX2) - aX; 1128 if (currentX > 0.0) { 1129 aB = currentT; 1130 } else { 1131 aA = currentT; 1132 } 1133 } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); 1134 return currentT; 1135 } 1136 1137 function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) { 1138 for (var i = 0; i < NEWTON_ITERATIONS; ++i) { 1139 var currentSlope = getSlope(aGuessT, mX1, mX2); 1140 if (currentSlope === 0.0) return aGuessT; 1141 var currentX = calcBezier(aGuessT, mX1, mX2) - aX; 1142 aGuessT -= currentX / currentSlope; 1143 } 1144 return aGuessT; 1145 } 1146 1147 /** 1148 * points is an array of [ mX1, mY1, mX2, mY2 ] 1149 */ 1150 function BezierEasing(points) { 1151 this._p = points; 1152 this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); 1153 this._precomputed = false; 1154 1155 this.get = this.get.bind(this); 1156 } 1157 1158 BezierEasing.prototype = { 1159 1160 get: function (x) { 1161 var mX1 = this._p[0], 1162 mY1 = this._p[1], 1163 mX2 = this._p[2], 1164 mY2 = this._p[3]; 1165 if (!this._precomputed) this._precompute(); 1166 if (mX1 === mY1 && mX2 === mY2) return x; // linear 1167 // Because JavaScript number are imprecise, we should guarantee the extremes are right. 1168 if (x === 0) return 0; 1169 if (x === 1) return 1; 1170 return calcBezier(this._getTForX(x), mY1, mY2); 1171 }, 1172 1173 // Private part 1174 1175 _precompute: function () { 1176 var mX1 = this._p[0], 1177 mY1 = this._p[1], 1178 mX2 = this._p[2], 1179 mY2 = this._p[3]; 1180 this._precomputed = true; 1181 if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); } 1182 }, 1183 1184 _calcSampleValues: function () { 1185 var mX1 = this._p[0], 1186 mX2 = this._p[2]; 1187 for (var i = 0; i < kSplineTableSize; ++i) { 1188 this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); 1189 } 1190 }, 1191 1192 /** 1193 * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection. 1194 */ 1195 _getTForX: function (aX) { 1196 var mX1 = this._p[0], 1197 mX2 = this._p[2], 1198 mSampleValues = this._mSampleValues; 1199 1200 var intervalStart = 0.0; 1201 var currentSample = 1; 1202 var lastSample = kSplineTableSize - 1; 1203 1204 for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) { 1205 intervalStart += kSampleStepSize; 1206 } 1207 --currentSample; 1208 1209 // Interpolate to provide an initial guess for t 1210 var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]); 1211 var guessForT = intervalStart + dist * kSampleStepSize; 1212 1213 var initialSlope = getSlope(guessForT, mX1, mX2); 1214 if (initialSlope >= NEWTON_MIN_SLOPE) { 1215 return newtonRaphsonIterate(aX, guessForT, mX1, mX2); 1216 } if (initialSlope === 0.0) { 1217 return guessForT; 1218 } 1219 return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); 1220 }, 1221 }; 1222 1223 return ob; 1224}()); 1225 1226(function () { 1227 var lastTime = 0; 1228 var vendors = ['ms', 'moz', 'webkit', 'o']; 1229 for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { // eslint-disable-line no-plusplus 1230 window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; 1231 window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; 1232 } 1233 if (!window.requestAnimationFrame) { 1234 window.requestAnimationFrame = function (callback) { 1235 var currTime = new Date().getTime(); 1236 var timeToCall = Math.max(0, 16 - (currTime - lastTime)); 1237 var id = setTimeout(function () { 1238 callback(currTime + timeToCall); 1239 }, 1240 timeToCall); 1241 lastTime = currTime + timeToCall; 1242 return id; 1243 }; 1244 } 1245 if (!window.cancelAnimationFrame) { 1246 window.cancelAnimationFrame = function (id) { 1247 clearTimeout(id); 1248 }; 1249 } 1250}()); 1251 1252/* exported extendPrototype, getDescriptor, createProxyFunction */ 1253 1254function extendPrototype(sources, destination) { 1255 var i; 1256 var len = sources.length; 1257 var sourcePrototype; 1258 for (i = 0; i < len; i += 1) { 1259 sourcePrototype = sources[i].prototype; 1260 for (var attr in sourcePrototype) { 1261 if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr]; 1262 } 1263 } 1264} 1265 1266function getDescriptor(object, prop) { 1267 return Object.getOwnPropertyDescriptor(object, prop); 1268} 1269 1270function createProxyFunction(prototype) { 1271 function ProxyFunction() {} 1272 ProxyFunction.prototype = prototype; 1273 return ProxyFunction; 1274} 1275 1276/* global segmentsLengthPool, defaultCurveSegments, createSizedArray, bmPow, bmSqrt, bmFloor, createTypedArray, bezierLengthPool */ 1277/* exported bez */ 1278 1279function bezFunction() { 1280 var math = Math; 1281 1282 function pointOnLine2D(x1, y1, x2, y2, x3, y3) { 1283 var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1); 1284 return det1 > -0.001 && det1 < 0.001; 1285 } 1286 1287 function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) { 1288 if (z1 === 0 && z2 === 0 && z3 === 0) { 1289 return pointOnLine2D(x1, y1, x2, y2, x3, y3); 1290 } 1291 var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2)); 1292 var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2)); 1293 var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2)); 1294 var diffDist; 1295 if (dist1 > dist2) { 1296 if (dist1 > dist3) { 1297 diffDist = dist1 - dist2 - dist3; 1298 } else { 1299 diffDist = dist3 - dist2 - dist1; 1300 } 1301 } else if (dist3 > dist2) { 1302 diffDist = dist3 - dist2 - dist1; 1303 } else { 1304 diffDist = dist2 - dist1 - dist3; 1305 } 1306 return diffDist > -0.0001 && diffDist < 0.0001; 1307 } 1308 1309 var getBezierLength = (function () { 1310 return function (pt1, pt2, pt3, pt4) { 1311 var curveSegments = defaultCurveSegments; 1312 var k; 1313 var i; 1314 var len; 1315 var ptCoord; 1316 var perc; 1317 var addedLength = 0; 1318 var ptDistance; 1319 var point = []; 1320 var lastPoint = []; 1321 var lengthData = bezierLengthPool.newElement(); 1322 len = pt3.length; 1323 for (k = 0; k < curveSegments; k += 1) { 1324 perc = k / (curveSegments - 1); 1325 ptDistance = 0; 1326 for (i = 0; i < len; i += 1) { 1327 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]; 1328 point[i] = ptCoord; 1329 if (lastPoint[i] !== null) { 1330 ptDistance += bmPow(point[i] - lastPoint[i], 2); 1331 } 1332 lastPoint[i] = point[i]; 1333 } 1334 if (ptDistance) { 1335 ptDistance = bmSqrt(ptDistance); 1336 addedLength += ptDistance; 1337 } 1338 lengthData.percents[k] = perc; 1339 lengthData.lengths[k] = addedLength; 1340 } 1341 lengthData.addedLength = addedLength; 1342 return lengthData; 1343 }; 1344 }()); 1345 1346 function getSegmentsLength(shapeData) { 1347 var segmentsLength = segmentsLengthPool.newElement(); 1348 var closed = shapeData.c; 1349 var pathV = shapeData.v; 1350 var pathO = shapeData.o; 1351 var pathI = shapeData.i; 1352 var i; 1353 var len = shapeData._length; 1354 var lengths = segmentsLength.lengths; 1355 var totalLength = 0; 1356 for (i = 0; i < len - 1; i += 1) { 1357 lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]); 1358 totalLength += lengths[i].addedLength; 1359 } 1360 if (closed && len) { 1361 lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]); 1362 totalLength += lengths[i].addedLength; 1363 } 1364 segmentsLength.totalLength = totalLength; 1365 return segmentsLength; 1366 } 1367 1368 function BezierData(length) { 1369 this.segmentLength = 0; 1370 this.points = new Array(length); 1371 } 1372 1373 function PointData(partial, point) { 1374 this.partialLength = partial; 1375 this.point = point; 1376 } 1377 1378 var buildBezierData = (function () { 1379 var storedData = {}; 1380 1381 return function (pt1, pt2, pt3, pt4) { 1382 var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p'); 1383 if (!storedData[bezierName]) { 1384 var curveSegments = defaultCurveSegments; 1385 var k; 1386 var i; 1387 var len; 1388 var ptCoord; 1389 var perc; 1390 var addedLength = 0; 1391 var ptDistance; 1392 var point; 1393 var lastPoint = null; 1394 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])) { 1395 curveSegments = 2; 1396 } 1397 var bezierData = new BezierData(curveSegments); 1398 len = pt3.length; 1399 for (k = 0; k < curveSegments; k += 1) { 1400 point = createSizedArray(len); 1401 perc = k / (curveSegments - 1); 1402 ptDistance = 0; 1403 for (i = 0; i < len; i += 1) { 1404 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]; 1405 point[i] = ptCoord; 1406 if (lastPoint !== null) { 1407 ptDistance += bmPow(point[i] - lastPoint[i], 2); 1408 } 1409 } 1410 ptDistance = bmSqrt(ptDistance); 1411 addedLength += ptDistance; 1412 bezierData.points[k] = new PointData(ptDistance, point); 1413 lastPoint = point; 1414 } 1415 bezierData.segmentLength = addedLength; 1416 storedData[bezierName] = bezierData; 1417 } 1418 return storedData[bezierName]; 1419 }; 1420 }()); 1421 1422 function getDistancePerc(perc, bezierData) { 1423 var percents = bezierData.percents; 1424 var lengths = bezierData.lengths; 1425 var len = percents.length; 1426 var initPos = bmFloor((len - 1) * perc); 1427 var lengthPos = perc * bezierData.addedLength; 1428 var lPerc = 0; 1429 if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) { 1430 return percents[initPos]; 1431 } 1432 var dir = lengths[initPos] > lengthPos ? -1 : 1; 1433 var flag = true; 1434 while (flag) { 1435 if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) { 1436 lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]); 1437 flag = false; 1438 } else { 1439 initPos += dir; 1440 } 1441 if (initPos < 0 || initPos >= len - 1) { 1442 // FIX for TypedArrays that don't store floating point values with enough accuracy 1443 if (initPos === len - 1) { 1444 return percents[initPos]; 1445 } 1446 flag = false; 1447 } 1448 } 1449 return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc; 1450 } 1451 1452 function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) { 1453 var t1 = getDistancePerc(percent, bezierData); 1454 var u1 = 1 - t1; 1455 var ptX = 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]) * 1000) / 1000; 1456 var ptY = 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]) * 1000) / 1000; 1457 return [ptX, ptY]; 1458 } 1459 1460 var bezierSegmentPoints = createTypedArray('float32', 8); 1461 1462 function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) { 1463 if (startPerc < 0) { 1464 startPerc = 0; 1465 } else if (startPerc > 1) { 1466 startPerc = 1; 1467 } 1468 var t0 = getDistancePerc(startPerc, bezierData); 1469 endPerc = endPerc > 1 ? 1 : endPerc; 1470 var t1 = getDistancePerc(endPerc, bezierData); 1471 var i; 1472 var len = pt1.length; 1473 var u0 = 1 - t0; 1474 var u1 = 1 - t1; 1475 var u0u0u0 = u0 * u0 * u0; 1476 var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase 1477 var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase 1478 var t0t0t0 = t0 * t0 * t0; 1479 // 1480 var u0u0u1 = u0 * u0 * u1; 1481 var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase 1482 var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase 1483 var t0t0t1 = t0 * t0 * t1; 1484 // 1485 var u0u1u1 = u0 * u1 * u1; 1486 var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase 1487 var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase 1488 var t0t1t1 = t0 * t1 * t1; 1489 // 1490 var u1u1u1 = u1 * u1 * u1; 1491 var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase 1492 var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase 1493 var t1t1t1 = t1 * t1 * t1; 1494 for (i = 0; i < len; i += 1) { 1495 bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase 1496 bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase 1497 bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase 1498 bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase 1499 } 1500 1501 return bezierSegmentPoints; 1502 } 1503 1504 return { 1505 getSegmentsLength: getSegmentsLength, 1506 getNewSegment: getNewSegment, 1507 getPointInSegment: getPointInSegment, 1508 buildBezierData: buildBezierData, 1509 pointOnLine2D: pointOnLine2D, 1510 pointOnLine3D: pointOnLine3D, 1511 }; 1512} 1513 1514var bez = bezFunction(); 1515 1516/* exported dataManager */ 1517 1518function dataFunctionManager() { 1519 // var tCanvasHelper = createTag('canvas').getContext('2d'); 1520 1521 function completeLayers(layers, comps, fontManager) { 1522 var layerData; 1523 var i; 1524 var len = layers.length; 1525 var j; 1526 var jLen; 1527 var k; 1528 var kLen; 1529 for (i = 0; i < len; i += 1) { 1530 layerData = layers[i]; 1531 if (('ks' in layerData) && !layerData.completed) { 1532 layerData.completed = true; 1533 if (layerData.tt) { 1534 layers[i - 1].td = layerData.tt; 1535 } 1536 if (layerData.hasMask) { 1537 var maskProps = layerData.masksProperties; 1538 jLen = maskProps.length; 1539 for (j = 0; j < jLen; j += 1) { 1540 if (maskProps[j].pt.k.i) { 1541 convertPathsToAbsoluteValues(maskProps[j].pt.k); 1542 } else { 1543 kLen = maskProps[j].pt.k.length; 1544 for (k = 0; k < kLen; k += 1) { 1545 if (maskProps[j].pt.k[k].s) { 1546 convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]); 1547 } 1548 if (maskProps[j].pt.k[k].e) { 1549 convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]); 1550 } 1551 } 1552 } 1553 } 1554 } 1555 if (layerData.ty === 0) { 1556 layerData.layers = findCompLayers(layerData.refId, comps); 1557 completeLayers(layerData.layers, comps, fontManager); 1558 } else if (layerData.ty === 4) { 1559 completeShapes(layerData.shapes); 1560 } else if (layerData.ty === 5) { 1561 completeText(layerData, fontManager); 1562 } 1563 } 1564 } 1565 } 1566 1567 function findCompLayers(id, comps) { 1568 var i = 0; 1569 var len = comps.length; 1570 while (i < len) { 1571 if (comps[i].id === id) { 1572 if (!comps[i].layers.__used) { 1573 comps[i].layers.__used = true; 1574 return comps[i].layers; 1575 } 1576 return JSON.parse(JSON.stringify(comps[i].layers)); 1577 } 1578 i += 1; 1579 } 1580 return null; 1581 } 1582 1583 function completeShapes(arr) { 1584 var i; 1585 var len = arr.length; 1586 var j; 1587 var jLen; 1588 for (i = len - 1; i >= 0; i -= 1) { 1589 if (arr[i].ty === 'sh') { 1590 if (arr[i].ks.k.i) { 1591 convertPathsToAbsoluteValues(arr[i].ks.k); 1592 } else { 1593 jLen = arr[i].ks.k.length; 1594 for (j = 0; j < jLen; j += 1) { 1595 if (arr[i].ks.k[j].s) { 1596 convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]); 1597 } 1598 if (arr[i].ks.k[j].e) { 1599 convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]); 1600 } 1601 } 1602 } 1603 } else if (arr[i].ty === 'gr') { 1604 completeShapes(arr[i].it); 1605 } 1606 } 1607 } 1608 1609 function convertPathsToAbsoluteValues(path) { 1610 var i; 1611 var len = path.i.length; 1612 for (i = 0; i < len; i += 1) { 1613 path.i[i][0] += path.v[i][0]; 1614 path.i[i][1] += path.v[i][1]; 1615 path.o[i][0] += path.v[i][0]; 1616 path.o[i][1] += path.v[i][1]; 1617 } 1618 } 1619 1620 function checkVersion(minimum, animVersionString) { 1621 var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100]; 1622 if (minimum[0] > animVersion[0]) { 1623 return true; 1624 } if (animVersion[0] > minimum[0]) { 1625 return false; 1626 } 1627 if (minimum[1] > animVersion[1]) { 1628 return true; 1629 } if (animVersion[1] > minimum[1]) { 1630 return false; 1631 } 1632 if (minimum[2] > animVersion[2]) { 1633 return true; 1634 } if (animVersion[2] > minimum[2]) { 1635 return false; 1636 } 1637 return null; 1638 } 1639 1640 var checkText = (function () { 1641 var minimumVersion = [4, 4, 14]; 1642 1643 function updateTextLayer(textLayer) { 1644 var documentData = textLayer.t.d; 1645 textLayer.t.d = { 1646 k: [ 1647 { 1648 s: documentData, 1649 t: 0, 1650 }, 1651 ], 1652 }; 1653 } 1654 1655 function iterateLayers(layers) { 1656 var i; 1657 var len = layers.length; 1658 for (i = 0; i < len; i += 1) { 1659 if (layers[i].ty === 5) { 1660 updateTextLayer(layers[i]); 1661 } 1662 } 1663 } 1664 1665 return function (animationData) { 1666 if (checkVersion(minimumVersion, animationData.v)) { 1667 iterateLayers(animationData.layers); 1668 if (animationData.assets) { 1669 var i; 1670 var len = animationData.assets.length; 1671 for (i = 0; i < len; i += 1) { 1672 if (animationData.assets[i].layers) { 1673 iterateLayers(animationData.assets[i].layers); 1674 } 1675 } 1676 } 1677 } 1678 }; 1679 }()); 1680 1681 var checkChars = (function () { 1682 var minimumVersion = [4, 7, 99]; 1683 return function (animationData) { 1684 if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) { 1685 var i; 1686 var len = animationData.chars.length; 1687 var j; 1688 var jLen; 1689 var pathData; 1690 var paths; 1691 for (i = 0; i < len; i += 1) { 1692 if (animationData.chars[i].data && animationData.chars[i].data.shapes) { 1693 paths = animationData.chars[i].data.shapes[0].it; 1694 jLen = paths.length; 1695 1696 for (j = 0; j < jLen; j += 1) { 1697 pathData = paths[j].ks.k; 1698 if (!pathData.__converted) { 1699 convertPathsToAbsoluteValues(paths[j].ks.k); 1700 pathData.__converted = true; 1701 } 1702 } 1703 } 1704 } 1705 } 1706 }; 1707 }()); 1708 1709 var checkColors = (function () { 1710 var minimumVersion = [4, 1, 9]; 1711 1712 function iterateShapes(shapes) { 1713 var i; 1714 var len = shapes.length; 1715 var j; 1716 var jLen; 1717 for (i = 0; i < len; i += 1) { 1718 if (shapes[i].ty === 'gr') { 1719 iterateShapes(shapes[i].it); 1720 } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') { 1721 if (shapes[i].c.k && shapes[i].c.k[0].i) { 1722 jLen = shapes[i].c.k.length; 1723 for (j = 0; j < jLen; j += 1) { 1724 if (shapes[i].c.k[j].s) { 1725 shapes[i].c.k[j].s[0] /= 255; 1726 shapes[i].c.k[j].s[1] /= 255; 1727 shapes[i].c.k[j].s[2] /= 255; 1728 shapes[i].c.k[j].s[3] /= 255; 1729 } 1730 if (shapes[i].c.k[j].e) { 1731 shapes[i].c.k[j].e[0] /= 255; 1732 shapes[i].c.k[j].e[1] /= 255; 1733 shapes[i].c.k[j].e[2] /= 255; 1734 shapes[i].c.k[j].e[3] /= 255; 1735 } 1736 } 1737 } else { 1738 shapes[i].c.k[0] /= 255; 1739 shapes[i].c.k[1] /= 255; 1740 shapes[i].c.k[2] /= 255; 1741 shapes[i].c.k[3] /= 255; 1742 } 1743 } 1744 } 1745 } 1746 1747 function iterateLayers(layers) { 1748 var i; 1749 var len = layers.length; 1750 for (i = 0; i < len; i += 1) { 1751 if (layers[i].ty === 4) { 1752 iterateShapes(layers[i].shapes); 1753 } 1754 } 1755 } 1756 1757 return function (animationData) { 1758 if (checkVersion(minimumVersion, animationData.v)) { 1759 iterateLayers(animationData.layers); 1760 if (animationData.assets) { 1761 var i; 1762 var len = animationData.assets.length; 1763 for (i = 0; i < len; i += 1) { 1764 if (animationData.assets[i].layers) { 1765 iterateLayers(animationData.assets[i].layers); 1766 } 1767 } 1768 } 1769 } 1770 }; 1771 }()); 1772 1773 var checkShapes = (function () { 1774 var minimumVersion = [4, 4, 18]; 1775 1776 function completeClosingShapes(arr) { 1777 var i; 1778 var len = arr.length; 1779 var j; 1780 var jLen; 1781 for (i = len - 1; i >= 0; i -= 1) { 1782 if (arr[i].ty === 'sh') { 1783 if (arr[i].ks.k.i) { 1784 arr[i].ks.k.c = arr[i].closed; 1785 } else { 1786 jLen = arr[i].ks.k.length; 1787 for (j = 0; j < jLen; j += 1) { 1788 if (arr[i].ks.k[j].s) { 1789 arr[i].ks.k[j].s[0].c = arr[i].closed; 1790 } 1791 if (arr[i].ks.k[j].e) { 1792 arr[i].ks.k[j].e[0].c = arr[i].closed; 1793 } 1794 } 1795 } 1796 } else if (arr[i].ty === 'gr') { 1797 completeClosingShapes(arr[i].it); 1798 } 1799 } 1800 } 1801 1802 function iterateLayers(layers) { 1803 var layerData; 1804 var i; 1805 var len = layers.length; 1806 var j; 1807 var jLen; 1808 var k; 1809 var kLen; 1810 for (i = 0; i < len; i += 1) { 1811 layerData = layers[i]; 1812 if (layerData.hasMask) { 1813 var maskProps = layerData.masksProperties; 1814 jLen = maskProps.length; 1815 for (j = 0; j < jLen; j += 1) { 1816 if (maskProps[j].pt.k.i) { 1817 maskProps[j].pt.k.c = maskProps[j].cl; 1818 } else { 1819 kLen = maskProps[j].pt.k.length; 1820 for (k = 0; k < kLen; k += 1) { 1821 if (maskProps[j].pt.k[k].s) { 1822 maskProps[j].pt.k[k].s[0].c = maskProps[j].cl; 1823 } 1824 if (maskProps[j].pt.k[k].e) { 1825 maskProps[j].pt.k[k].e[0].c = maskProps[j].cl; 1826 } 1827 } 1828 } 1829 } 1830 } 1831 if (layerData.ty === 4) { 1832 completeClosingShapes(layerData.shapes); 1833 } 1834 } 1835 } 1836 1837 return function (animationData) { 1838 if (checkVersion(minimumVersion, animationData.v)) { 1839 iterateLayers(animationData.layers); 1840 if (animationData.assets) { 1841 var i; 1842 var len = animationData.assets.length; 1843 for (i = 0; i < len; i += 1) { 1844 if (animationData.assets[i].layers) { 1845 iterateLayers(animationData.assets[i].layers); 1846 } 1847 } 1848 } 1849 } 1850 }; 1851 }()); 1852 1853 function completeData(animationData, fontManager) { 1854 if (animationData.__complete) { 1855 return; 1856 } 1857 checkColors(animationData); 1858 checkText(animationData); 1859 checkChars(animationData); 1860 checkShapes(animationData); 1861 completeLayers(animationData.layers, animationData.assets, fontManager); 1862 animationData.__complete = true; 1863 } 1864 1865 function completeText(data) { 1866 if (data.t.a.length === 0 && !('m' in data.t.p)) { 1867 data.singleShape = true; 1868 } 1869 } 1870 1871 var moduleOb = {}; 1872 moduleOb.completeData = completeData; 1873 moduleOb.checkColors = checkColors; 1874 moduleOb.checkChars = checkChars; 1875 moduleOb.checkShapes = checkShapes; 1876 moduleOb.completeLayers = completeLayers; 1877 1878 return moduleOb; 1879} 1880 1881var dataManager = dataFunctionManager(); 1882 1883/* exported getFontProperties */ 1884 1885function getFontProperties(fontData) { 1886 var styles = fontData.fStyle ? fontData.fStyle.split(' ') : []; 1887 1888 var fWeight = 'normal'; var 1889 fStyle = 'normal'; 1890 var len = styles.length; 1891 var styleName; 1892 for (var i = 0; i < len; i += 1) { 1893 styleName = styles[i].toLowerCase(); 1894 switch (styleName) { 1895 case 'italic': 1896 fStyle = 'italic'; 1897 break; 1898 case 'bold': 1899 fWeight = '700'; 1900 break; 1901 case 'black': 1902 fWeight = '900'; 1903 break; 1904 case 'medium': 1905 fWeight = '500'; 1906 break; 1907 case 'regular': 1908 case 'normal': 1909 fWeight = '400'; 1910 break; 1911 case 'light': 1912 case 'thin': 1913 fWeight = '200'; 1914 break; 1915 default: 1916 break; 1917 } 1918 } 1919 1920 return { 1921 style: fStyle, 1922 weight: fontData.fWeight || fWeight, 1923 }; 1924} 1925 1926/* global createNS, createTag, getFontProperties */ 1927/* exported FontManager */ 1928 1929var FontManager = (function () { 1930 var maxWaitingTime = 5000; 1931 var emptyChar = { 1932 w: 0, 1933 size: 0, 1934 shapes: [], 1935 }; 1936 var combinedCharacters = []; 1937 // Hindi characters 1938 combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366, 1939 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 1940 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]); 1941 1942 function trimFontOptions(font) { 1943 var familyArray = font.split(','); 1944 var i; 1945 var len = familyArray.length; 1946 var enabledFamilies = []; 1947 for (i = 0; i < len; i += 1) { 1948 if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') { 1949 enabledFamilies.push(familyArray[i]); 1950 } 1951 } 1952 return enabledFamilies.join(','); 1953 } 1954 1955 function setUpNode(font, family) { 1956 var parentNode = createTag('span'); 1957 parentNode.style.fontFamily = family; 1958 var node = createTag('span'); 1959 // Characters that vary significantly among different fonts 1960 node.innerText = 'giItT1WQy@!-/#'; 1961 // Visible - so we can measure it - but not on the screen 1962 parentNode.style.position = 'absolute'; 1963 parentNode.style.left = '-10000px'; 1964 parentNode.style.top = '-10000px'; 1965 // Large font size makes even subtle changes obvious 1966 parentNode.style.fontSize = '300px'; 1967 // Reset any font properties 1968 parentNode.style.fontVariant = 'normal'; 1969 parentNode.style.fontStyle = 'normal'; 1970 parentNode.style.fontWeight = 'normal'; 1971 parentNode.style.letterSpacing = '0'; 1972 parentNode.appendChild(node); 1973 document.body.appendChild(parentNode); 1974 1975 // Remember width with no applied web font 1976 var width = node.offsetWidth; 1977 node.style.fontFamily = trimFontOptions(font) + ', ' + family; 1978 return { node: node, w: width, parent: parentNode }; 1979 } 1980 1981 function checkLoadedFonts() { 1982 var i; 1983 var len = this.fonts.length; 1984 var node; 1985 var w; 1986 var loadedCount = len; 1987 for (i = 0; i < len; i += 1) { 1988 if (this.fonts[i].loaded) { 1989 loadedCount -= 1; 1990 } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) { 1991 this.fonts[i].loaded = true; 1992 } else { 1993 node = this.fonts[i].monoCase.node; 1994 w = this.fonts[i].monoCase.w; 1995 if (node.offsetWidth !== w) { 1996 loadedCount -= 1; 1997 this.fonts[i].loaded = true; 1998 } else { 1999 node = this.fonts[i].sansCase.node; 2000 w = this.fonts[i].sansCase.w; 2001 if (node.offsetWidth !== w) { 2002 loadedCount -= 1; 2003 this.fonts[i].loaded = true; 2004 } 2005 } 2006 if (this.fonts[i].loaded) { 2007 this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent); 2008 this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent); 2009 } 2010 } 2011 } 2012 2013 if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) { 2014 setTimeout(this.checkLoadedFontsBinded, 20); 2015 } else { 2016 setTimeout(this.setIsLoadedBinded, 10); 2017 } 2018 } 2019 2020 function createHelper(def, fontData) { 2021 var tHelper = createNS('text'); 2022 tHelper.style.fontSize = '100px'; 2023 // tHelper.style.fontFamily = fontData.fFamily; 2024 2025 var fontProps = getFontProperties(fontData); 2026 tHelper.setAttribute('font-family', fontData.fFamily); 2027 tHelper.setAttribute('font-style', fontProps.style); 2028 tHelper.setAttribute('font-weight', fontProps.weight); 2029 tHelper.textContent = '1'; 2030 if (fontData.fClass) { 2031 tHelper.style.fontFamily = 'inherit'; 2032 tHelper.setAttribute('class', fontData.fClass); 2033 } else { 2034 tHelper.style.fontFamily = fontData.fFamily; 2035 } 2036 def.appendChild(tHelper); 2037 var tCanvasHelper = createTag('canvas').getContext('2d'); 2038 tCanvasHelper.font = fontData.fWeight + ' ' + fontData.fStyle + ' 100px ' + fontData.fFamily; 2039 // tCanvasHelper.font = ' 100px '+ fontData.fFamily; 2040 return tHelper; 2041 } 2042 2043 function addFonts(fontData, defs) { 2044 if (!fontData) { 2045 this.isLoaded = true; 2046 return; 2047 } 2048 if (this.chars) { 2049 this.isLoaded = true; 2050 this.fonts = fontData.list; 2051 return; 2052 } 2053 2054 var fontArr = fontData.list; 2055 var i; 2056 var len = fontArr.length; 2057 var _pendingFonts = len; 2058 for (i = 0; i < len; i += 1) { 2059 var shouldLoadFont = true; 2060 var loadedSelector; 2061 var j; 2062 fontArr[i].loaded = false; 2063 fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace'); 2064 fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif'); 2065 if (!fontArr[i].fPath) { 2066 fontArr[i].loaded = true; 2067 _pendingFonts -= 1; 2068 } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) { 2069 loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]'); 2070 2071 if (loadedSelector.length > 0) { 2072 shouldLoadFont = false; 2073 } 2074 2075 if (shouldLoadFont) { 2076 var s = createTag('style'); 2077 s.setAttribute('f-forigin', fontArr[i].fOrigin); 2078 s.setAttribute('f-origin', fontArr[i].origin); 2079 s.setAttribute('f-family', fontArr[i].fFamily); 2080 s.type = 'text/css'; 2081 s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}"; 2082 defs.appendChild(s); 2083 } 2084 } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) { 2085 loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]'); 2086 2087 for (j = 0; j < loadedSelector.length; j += 1) { 2088 if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) { 2089 // Font is already loaded 2090 shouldLoadFont = false; 2091 } 2092 } 2093 2094 if (shouldLoadFont) { 2095 var l = createTag('link'); 2096 l.setAttribute('f-forigin', fontArr[i].fOrigin); 2097 l.setAttribute('f-origin', fontArr[i].origin); 2098 l.type = 'text/css'; 2099 l.rel = 'stylesheet'; 2100 l.href = fontArr[i].fPath; 2101 document.body.appendChild(l); 2102 } 2103 } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) { 2104 loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]'); 2105 2106 for (j = 0; j < loadedSelector.length; j += 1) { 2107 if (fontArr[i].fPath === loadedSelector[j].src) { 2108 // Font is already loaded 2109 shouldLoadFont = false; 2110 } 2111 } 2112 2113 if (shouldLoadFont) { 2114 var sc = createTag('link'); 2115 sc.setAttribute('f-forigin', fontArr[i].fOrigin); 2116 sc.setAttribute('f-origin', fontArr[i].origin); 2117 sc.setAttribute('rel', 'stylesheet'); 2118 sc.setAttribute('href', fontArr[i].fPath); 2119 defs.appendChild(sc); 2120 } 2121 } 2122 fontArr[i].helper = createHelper(defs, fontArr[i]); 2123 fontArr[i].cache = {}; 2124 this.fonts.push(fontArr[i]); 2125 } 2126 if (_pendingFonts === 0) { 2127 this.isLoaded = true; 2128 } else { 2129 // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas. 2130 // Adding this timeout seems to fix it 2131 setTimeout(this.checkLoadedFonts.bind(this), 100); 2132 } 2133 } 2134 2135 function addChars(chars) { 2136 if (!chars) { 2137 return; 2138 } 2139 if (!this.chars) { 2140 this.chars = []; 2141 } 2142 var i; 2143 var len = chars.length; 2144 var j; 2145 var jLen = this.chars.length; 2146 var found; 2147 for (i = 0; i < len; i += 1) { 2148 j = 0; 2149 found = false; 2150 while (j < jLen) { 2151 if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) { 2152 found = true; 2153 } 2154 j += 1; 2155 } 2156 if (!found) { 2157 this.chars.push(chars[i]); 2158 jLen += 1; 2159 } 2160 } 2161 } 2162 2163 function getCharData(char, style, font) { 2164 var i = 0; 2165 var len = this.chars.length; 2166 while (i < len) { 2167 if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) { 2168 return this.chars[i]; 2169 } 2170 i += 1; 2171 } 2172 if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char) 2173 && console 2174 && console.warn // eslint-disable-line no-console 2175 && !this._warned 2176 ) { 2177 this._warned = true; 2178 console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console 2179 } 2180 return emptyChar; 2181 } 2182 2183 function measureText(char, fontName, size) { 2184 var fontData = this.getFontByName(fontName); 2185 var index = char.charCodeAt(0); 2186 if (!fontData.cache[index + 1]) { 2187 var tHelper = fontData.helper; 2188 // Canvas version 2189 // fontData.cache[index] = tHelper.measureText(char).width / 100; 2190 // SVG version 2191 // console.log(tHelper.getBBox().width) 2192 if (char === ' ') { 2193 tHelper.textContent = '|' + char + '|'; 2194 var doubleSize = tHelper.getComputedTextLength(); 2195 tHelper.textContent = '||'; 2196 var singleSize = tHelper.getComputedTextLength(); 2197 fontData.cache[index + 1] = (doubleSize - singleSize) / 100; 2198 } else { 2199 tHelper.textContent = char; 2200 fontData.cache[index + 1] = (tHelper.getComputedTextLength()) / 100; 2201 } 2202 } 2203 return fontData.cache[index + 1] * size; 2204 } 2205 2206 function getFontByName(name) { 2207 var i = 0; 2208 var len = this.fonts.length; 2209 while (i < len) { 2210 if (this.fonts[i].fName === name) { 2211 return this.fonts[i]; 2212 } 2213 i += 1; 2214 } 2215 return this.fonts[0]; 2216 } 2217 2218 function getCombinedCharacterCodes() { 2219 return combinedCharacters; 2220 } 2221 2222 function setIsLoaded() { 2223 this.isLoaded = true; 2224 } 2225 2226 var Font = function () { 2227 this.fonts = []; 2228 this.chars = null; 2229 this.typekitLoaded = 0; 2230 this.isLoaded = false; 2231 this._warned = false; 2232 this.initTime = Date.now(); 2233 this.setIsLoadedBinded = this.setIsLoaded.bind(this); 2234 this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this); 2235 }; 2236 // TODO: for now I'm adding these methods to the Class and not the prototype. Think of a better way to implement it. 2237 Font.getCombinedCharacterCodes = getCombinedCharacterCodes; 2238 2239 var fontPrototype = { 2240 addChars: addChars, 2241 addFonts: addFonts, 2242 getCharData: getCharData, 2243 getFontByName: getFontByName, 2244 measureText: measureText, 2245 checkLoadedFonts: checkLoadedFonts, 2246 setIsLoaded: setIsLoaded, 2247 }; 2248 2249 Font.prototype = fontPrototype; 2250 2251 return Font; 2252}()); 2253 2254/* global initialDefaultFrame, BezierFactory, degToRads, bez, createTypedArray */ 2255/* exported PropertyFactory */ 2256 2257var PropertyFactory = (function () { 2258 var initFrame = initialDefaultFrame; 2259 var mathAbs = Math.abs; 2260 2261 function interpolateValue(frameNum, caching) { 2262 var offsetTime = this.offsetTime; 2263 var newValue; 2264 if (this.propType === 'multidimensional') { 2265 newValue = createTypedArray('float32', this.pv.length); 2266 } 2267 var iterationIndex = caching.lastIndex; 2268 var i = iterationIndex; 2269 var len = this.keyframes.length - 1; 2270 var flag = true; 2271 var keyData; 2272 var nextKeyData; 2273 2274 while (flag) { 2275 keyData = this.keyframes[i]; 2276 nextKeyData = this.keyframes[i + 1]; 2277 if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) { 2278 if (keyData.h) { 2279 keyData = nextKeyData; 2280 } 2281 iterationIndex = 0; 2282 break; 2283 } 2284 if ((nextKeyData.t - offsetTime) > frameNum) { 2285 iterationIndex = i; 2286 break; 2287 } 2288 if (i < len - 1) { 2289 i += 1; 2290 } else { 2291 iterationIndex = 0; 2292 flag = false; 2293 } 2294 } 2295 2296 var k; 2297 var kLen; 2298 var perc; 2299 var jLen; 2300 var j; 2301 var fnc; 2302 var nextKeyTime = nextKeyData.t - offsetTime; 2303 var keyTime = keyData.t - offsetTime; 2304 var endValue; 2305 if (keyData.to) { 2306 if (!keyData.bezierData) { 2307 keyData.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti); 2308 } 2309 var bezierData = keyData.bezierData; 2310 if (frameNum >= nextKeyTime || frameNum < keyTime) { 2311 var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0; 2312 kLen = bezierData.points[ind].point.length; 2313 for (k = 0; k < kLen; k += 1) { 2314 newValue[k] = bezierData.points[ind].point[k]; 2315 } 2316 // caching._lastKeyframeIndex = -1; 2317 } else { 2318 if (keyData.__fnct) { 2319 fnc = keyData.__fnct; 2320 } else { 2321 fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get; 2322 keyData.__fnct = fnc; 2323 } 2324 perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime)); 2325 var distanceInLine = bezierData.segmentLength * perc; 2326 2327 var segmentPerc; 2328 var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0; 2329 j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0; 2330 flag = true; 2331 jLen = bezierData.points.length; 2332 while (flag) { 2333 addedLength += bezierData.points[j].partialLength; 2334 if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) { 2335 kLen = bezierData.points[j].point.length; 2336 for (k = 0; k < kLen; k += 1) { 2337 newValue[k] = bezierData.points[j].point[k]; 2338 } 2339 break; 2340 } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) { 2341 segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength; 2342 kLen = bezierData.points[j].point.length; 2343 for (k = 0; k < kLen; k += 1) { 2344 newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc; 2345 } 2346 break; 2347 } 2348 if (j < jLen - 1) { 2349 j += 1; 2350 } else { 2351 flag = false;
vendor: 4,502 bytes, lines 2352-2492
2352 } 2353 } 2354 caching._lastPoint = j; 2355 caching._lastAddedLength = addedLength - bezierData.points[j].partialLength; 2356 caching._lastKeyframeIndex = i; 2357 } 2358 } else { 2359 var outX; 2360 var outY; 2361 var inX; 2362 var inY; 2363 var keyValue; 2364 len = keyData.s.length; 2365 endValue = nextKeyData.s || keyData.e; 2366 if (this.sh && keyData.h !== 1) { 2367 if (frameNum >= nextKeyTime) { 2368 newValue[0] = endValue[0]; 2369 newValue[1] = endValue[1]; 2370 newValue[2] = endValue[2]; 2371 } else if (frameNum <= keyTime) { 2372 newValue[0] = keyData.s[0]; 2373 newValue[1] = keyData.s[1]; 2374 newValue[2] = keyData.s[2]; 2375 } else { 2376 var quatStart = createQuaternion(keyData.s); 2377 var quatEnd = createQuaternion(endValue); 2378 var time = (frameNum - keyTime) / (nextKeyTime - keyTime); 2379 quaternionToEuler(newValue, slerp(quatStart, quatEnd, time)); 2380 } 2381 } else { 2382 for (i = 0; i < len; i += 1) { 2383 if (keyData.h !== 1) { 2384 if (frameNum >= nextKeyTime) { 2385 perc = 1; 2386 } else if (frameNum < keyTime) { 2387 perc = 0; 2388 } else { 2389 if (keyData.o.x.constructor === Array) { 2390 if (!keyData.__fnct) { 2391 keyData.__fnct = []; 2392 } 2393 if (!keyData.__fnct[i]) { 2394 outX = (typeof keyData.o.x[i] === 'undefined') ? keyData.o.x[0] : keyData.o.x[i]; 2395 outY = (typeof keyData.o.y[i] === 'undefined') ? keyData.o.y[0] : keyData.o.y[i]; 2396 inX = (typeof keyData.i.x[i] === 'undefined') ? keyData.i.x[0] : keyData.i.x[i]; 2397 inY = (typeof keyData.i.y[i] === 'undefined') ? keyData.i.y[0] : keyData.i.y[i]; 2398 fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get; 2399 keyData.__fnct[i] = fnc; 2400 } else { 2401 fnc = keyData.__fnct[i]; 2402 } 2403 } else if (!keyData.__fnct) { 2404 outX = keyData.o.x; 2405 outY = keyData.o.y; 2406 inX = keyData.i.x; 2407 inY = keyData.i.y; 2408 fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get; 2409 keyData.__fnct = fnc; 2410 } else { 2411 fnc = keyData.__fnct; 2412 } 2413 perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime)); 2414 } 2415 } 2416 2417 endValue = nextKeyData.s || keyData.e; 2418 keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc; 2419 2420 if (this.propType === 'multidimensional') { 2421 newValue[i] = keyValue; 2422 } else { 2423 newValue = keyValue; 2424 } 2425 } 2426 } 2427 } 2428 caching.lastIndex = iterationIndex; 2429 return newValue; 2430 } 2431 2432 // based on @Toji's https://github.com/toji/gl-matrix/ 2433 function slerp(a, b, t) { 2434 var out = []; 2435 var ax = a[0]; 2436 var ay = a[1]; 2437 var az = a[2]; 2438 var aw = a[3]; 2439 var bx = b[0]; 2440 var by = b[1]; 2441 var bz = b[2]; 2442 var bw = b[3]; 2443 2444 var omega; 2445 var cosom; 2446 var sinom; 2447 var scale0; 2448 var scale1; 2449 2450 cosom = ax * bx + ay * by + az * bz + aw * bw; 2451 if (cosom < 0.0) { 2452 cosom = -cosom; 2453 bx = -bx; 2454 by = -by; 2455 bz = -bz; 2456 bw = -bw; 2457 } 2458 if ((1.0 - cosom) > 0.000001) { 2459 omega = Math.acos(cosom); 2460 sinom = Math.sin(omega); 2461 scale0 = Math.sin((1.0 - t) * omega) / sinom; 2462 scale1 = Math.sin(t * omega) / sinom; 2463 } else { 2464 scale0 = 1.0 - t; 2465 scale1 = t; 2466 } 2467 out[0] = scale0 * ax + scale1 * bx; 2468 out[1] = scale0 * ay + scale1 * by; 2469 out[2] = scale0 * az + scale1 * bz; 2470 out[3] = scale0 * aw + scale1 * bw; 2471 2472 return out; 2473 } 2474 2475 function quaternionToEuler(out, quat) { 2476 var qx = quat[0]; 2477 var qy = quat[1]; 2478 var qz = quat[2]; 2479 var qw = quat[3]; 2480 var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz); 2481 var attitude = Math.asin(2 * qx * qy + 2 * qz * qw); 2482 var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz); 2483 out[0] = heading / degToRads; 2484 out[1] = attitude / degToRads; 2485 out[2] = bank / degToRads; 2486 } 2487 2488 function createQuaternion(values) { 2489 var heading = values[0] * degToRads; 2490 var attitude = values[1] * degToRads; 2491 var bank = values[2] * degToRads; 2492 var c1 = Math.cos(heading / 2);
vendor: 16,687 bytes, lines 2493-2969
2493 var c2 = Math.cos(attitude / 2); 2494 var c3 = Math.cos(bank / 2); 2495 var s1 = Math.sin(heading / 2); 2496 var s2 = Math.sin(attitude / 2); 2497 var s3 = Math.sin(bank / 2); 2498 var w = c1 * c2 * c3 - s1 * s2 * s3; 2499 var x = s1 * s2 * c3 + c1 * c2 * s3; 2500 var y = s1 * c2 * c3 + c1 * s2 * s3; 2501 var z = c1 * s2 * c3 - s1 * c2 * s3; 2502 2503 return [x, y, z, w]; 2504 } 2505 2506 function getValueAtCurrentTime() { 2507 var frameNum = this.comp.renderedFrame - this.offsetTime; 2508 var initTime = this.keyframes[0].t - this.offsetTime; 2509 var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime; 2510 if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) { 2511 if (this._caching.lastFrame >= frameNum) { 2512 this._caching._lastKeyframeIndex = -1; 2513 this._caching.lastIndex = 0; 2514 } 2515 2516 var renderResult = this.interpolateValue(frameNum, this._caching); 2517 this.pv = renderResult; 2518 } 2519 this._caching.lastFrame = frameNum; 2520 return this.pv; 2521 } 2522 2523 function setVValue(val) { 2524 var multipliedValue; 2525 if (this.propType === 'unidimensional') { 2526 multipliedValue = val * this.mult; 2527 if (mathAbs(this.v - multipliedValue) > 0.00001) { 2528 this.v = multipliedValue; 2529 this._mdf = true; 2530 } 2531 } else { 2532 var i = 0; 2533 var len = this.v.length; 2534 while (i < len) { 2535 multipliedValue = val[i] * this.mult; 2536 if (mathAbs(this.v[i] - multipliedValue) > 0.00001) { 2537 this.v[i] = multipliedValue; 2538 this._mdf = true; 2539 } 2540 i += 1; 2541 } 2542 } 2543 } 2544 2545 function processEffectsSequence() { 2546 if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) { 2547 return; 2548 } 2549 if (this.lock) { 2550 this.setVValue(this.pv); 2551 return; 2552 } 2553 this.lock = true; 2554 this._mdf = this._isFirstFrame; 2555 var i; 2556 var len = this.effectsSequence.length; 2557 var finalValue = this.kf ? this.pv : this.data.k; 2558 for (i = 0; i < len; i += 1) { 2559 finalValue = this.effectsSequence[i](finalValue); 2560 } 2561 this.setVValue(finalValue); 2562 this._isFirstFrame = false; 2563 this.lock = false; 2564 this.frameId = this.elem.globalData.frameId; 2565 } 2566 2567 function addEffect(effectFunction) { 2568 this.effectsSequence.push(effectFunction); 2569 this.container.addDynamicProperty(this); 2570 } 2571 2572 function ValueProperty(elem, data, mult, container) { 2573 this.propType = 'unidimensional'; 2574 this.mult = mult || 1; 2575 this.data = data; 2576 this.v = mult ? data.k * mult : data.k; 2577 this.pv = data.k; 2578 this._mdf = false; 2579 this.elem = elem; 2580 this.container = container; 2581 this.comp = elem.comp; 2582 this.k = false; 2583 this.kf = false; 2584 this.vel = 0; 2585 this.effectsSequence = []; 2586 this._isFirstFrame = true; 2587 this.getValue = processEffectsSequence; 2588 this.setVValue = setVValue; 2589 this.addEffect = addEffect; 2590 } 2591 2592 function MultiDimensionalProperty(elem, data, mult, container) { 2593 this.propType = 'multidimensional'; 2594 this.mult = mult || 1; 2595 this.data = data; 2596 this._mdf = false; 2597 this.elem = elem; 2598 this.container = container; 2599 this.comp = elem.comp; 2600 this.k = false; 2601 this.kf = false; 2602 this.frameId = -1; 2603 var i; 2604 var len = data.k.length; 2605 this.v = createTypedArray('float32', len); 2606 this.pv = createTypedArray('float32', len); 2607 this.vel = createTypedArray('float32', len); 2608 for (i = 0; i < len; i += 1) { 2609 this.v[i] = data.k[i] * this.mult; 2610 this.pv[i] = data.k[i]; 2611 } 2612 this._isFirstFrame = true; 2613 this.effectsSequence = []; 2614 this.getValue = processEffectsSequence; 2615 this.setVValue = setVValue; 2616 this.addEffect = addEffect; 2617 } 2618 2619 function KeyframedValueProperty(elem, data, mult, container) { 2620 this.propType = 'unidimensional'; 2621 this.keyframes = data.k; 2622 this.offsetTime = elem.data.st; 2623 this.frameId = -1; 2624 this._caching = { 2625 lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1, 2626 }; 2627 this.k = true; 2628 this.kf = true; 2629 this.data = data; 2630 this.mult = mult || 1; 2631 this.elem = elem; 2632 this.container = container; 2633 this.comp = elem.comp; 2634 this.v = initFrame; 2635 this.pv = initFrame; 2636 this._isFirstFrame = true; 2637 this.getValue = processEffectsSequence; 2638 this.setVValue = setVValue; 2639 this.interpolateValue = interpolateValue; 2640 this.effectsSequence = [getValueAtCurrentTime.bind(this)]; 2641 this.addEffect = addEffect; 2642 } 2643 2644 function KeyframedMultidimensionalProperty(elem, data, mult, container) { 2645 this.propType = 'multidimensional'; 2646 var i; 2647 var len = data.k.length; 2648 var s; 2649 var e; 2650 var to; 2651 var ti; 2652 for (i = 0; i < len - 1; i += 1) { 2653 if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) { 2654 s = data.k[i].s; 2655 e = data.k[i + 1].s; 2656 to = data.k[i].to; 2657 ti = data.k[i].ti; 2658 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]))) { 2659 data.k[i].to = null; 2660 data.k[i].ti = null; 2661 } 2662 if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) { 2663 if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) { 2664 data.k[i].to = null; 2665 data.k[i].ti = null; 2666 } 2667 } 2668 } 2669 } 2670 this.effectsSequence = [getValueAtCurrentTime.bind(this)]; 2671 this.data = data; 2672 this.keyframes = data.k; 2673 this.offsetTime = elem.data.st; 2674 this.k = true; 2675 this.kf = true; 2676 this._isFirstFrame = true; 2677 this.mult = mult || 1; 2678 this.elem = elem; 2679 this.container = container; 2680 this.comp = elem.comp; 2681 this.getValue = processEffectsSequence; 2682 this.setVValue = setVValue; 2683 this.interpolateValue = interpolateValue; 2684 this.frameId = -1; 2685 var arrLen = data.k[0].s.length; 2686 this.v = createTypedArray('float32', arrLen); 2687 this.pv = createTypedArray('float32', arrLen); 2688 for (i = 0; i < arrLen; i += 1) { 2689 this.v[i] = initFrame; 2690 this.pv[i] = initFrame; 2691 } 2692 this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) }; 2693 this.addEffect = addEffect; 2694 } 2695 2696 function getProp(elem, data, type, mult, container) { 2697 var p; 2698 if (!data.k.length) { 2699 p = new ValueProperty(elem, data, mult, container); 2700 } else if (typeof (data.k[0]) === 'number') { 2701 p = new MultiDimensionalProperty(elem, data, mult, container); 2702 } else { 2703 switch (type) { 2704 case 0: 2705 p = new KeyframedValueProperty(elem, data, mult, container); 2706 break; 2707 case 1: 2708 p = new KeyframedMultidimensionalProperty(elem, data, mult, container); 2709 break; 2710 default: 2711 break; 2712 } 2713 } 2714 if (p.effectsSequence.length) { 2715 container.addDynamicProperty(p); 2716 } 2717 return p; 2718 } 2719 2720 var ob = { 2721 getProp: getProp, 2722 }; 2723 return ob; 2724}()); 2725 2726/* global Matrix, degToRads, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 2727/* exported TransformPropertyFactory */ 2728 2729var TransformPropertyFactory = (function () { 2730 var defaultVector = [0, 0]; 2731 2732 function applyToMatrix(mat) { 2733 var _mdf = this._mdf; 2734 this.iterateDynamicProperties(); 2735 this._mdf = this._mdf || _mdf; 2736 if (this.a) { 2737 mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]); 2738 } 2739 if (this.s) { 2740 mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]); 2741 } 2742 if (this.sk) { 2743 mat.skewFromAxis(-this.sk.v, this.sa.v); 2744 } 2745 if (this.r) { 2746 mat.rotate(-this.r.v); 2747 } else { 2748 mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]) 2749 .rotateY(this.or.v[1]) 2750 .rotateX(this.or.v[0]); 2751 } 2752 if (this.data.p.s) { 2753 if (this.data.p.z) { 2754 mat.translate(this.px.v, this.py.v, -this.pz.v); 2755 } else { 2756 mat.translate(this.px.v, this.py.v, 0); 2757 } 2758 } else { 2759 mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]); 2760 } 2761 } 2762 function processKeys(forceRender) { 2763 if (this.elem.globalData.frameId === this.frameId) { 2764 return; 2765 } 2766 if (this._isDirty) { 2767 this.precalculateMatrix(); 2768 this._isDirty = false; 2769 } 2770 2771 this.iterateDynamicProperties(); 2772 2773 if (this._mdf || forceRender) { 2774 var frameRate; 2775 this.v.cloneFromProps(this.pre.props); 2776 if (this.appliedTransformations < 1) { 2777 this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]); 2778 } 2779 if (this.appliedTransformations < 2) { 2780 this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]); 2781 } 2782 if (this.sk && this.appliedTransformations < 3) { 2783 this.v.skewFromAxis(-this.sk.v, this.sa.v); 2784 } 2785 if (this.r && this.appliedTransformations < 4) { 2786 this.v.rotate(-this.r.v); 2787 } else if (!this.r && this.appliedTransformations < 4) { 2788 this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]) 2789 .rotateY(this.or.v[1]) 2790 .rotateX(this.or.v[0]); 2791 } 2792 if (this.autoOriented) { 2793 var v1; 2794 var v2; 2795 frameRate = this.elem.globalData.frameRate; 2796 if (this.p && this.p.keyframes && this.p.getValueAtTime) { 2797 if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) { 2798 v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0); 2799 v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0); 2800 } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) { 2801 v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0); 2802 v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0); 2803 } else { 2804 v1 = this.p.pv; 2805 v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime); 2806 } 2807 } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) { 2808 v1 = []; 2809 v2 = []; 2810 var px = this.px; 2811 var py = this.py; 2812 if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) { 2813 v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0); 2814 v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0); 2815 v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0); 2816 v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0); 2817 } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) { 2818 v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0); 2819 v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0); 2820 v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0); 2821 v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0); 2822 } else { 2823 v1 = [px.pv, py.pv]; 2824 v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime); 2825 v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime); 2826 } 2827 } else { 2828 v2 = defaultVector; 2829 v1 = v2; 2830 } 2831 this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0])); 2832 } 2833 if (this.data.p && this.data.p.s) { 2834 if (this.data.p.z) { 2835 this.v.translate(this.px.v, this.py.v, -this.pz.v); 2836 } else { 2837 this.v.translate(this.px.v, this.py.v, 0); 2838 } 2839 } else { 2840 this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]); 2841 } 2842 } 2843 this.frameId = this.elem.globalData.frameId; 2844 } 2845 2846 function precalculateMatrix() { 2847 if (!this.a.k) { 2848 this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]); 2849 this.appliedTransformations = 1; 2850 } else { 2851 return; 2852 } 2853 if (!this.s.effectsSequence.length) { 2854 this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]); 2855 this.appliedTransformations = 2; 2856 } else { 2857 return; 2858 } 2859 if (this.sk) { 2860 if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) { 2861 this.pre.skewFromAxis(-this.sk.v, this.sa.v); 2862 this.appliedTransformations = 3; 2863 } else { 2864 return; 2865 } 2866 } 2867 if (this.r) { 2868 if (!this.r.effectsSequence.length) { 2869 this.pre.rotate(-this.r.v); 2870 this.appliedTransformations = 4; 2871 } 2872 } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) { 2873 this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]) 2874 .rotateY(this.or.v[1]) 2875 .rotateX(this.or.v[0]); 2876 this.appliedTransformations = 4; 2877 } 2878 } 2879 2880 function autoOrient() { 2881 // 2882 // var prevP = this.getValueAtTime(); 2883 } 2884 2885 function addDynamicProperty(prop) { 2886 this._addDynamicProperty(prop); 2887 this.elem.addDynamicProperty(prop); 2888 this._isDirty = true; 2889 } 2890 2891 function TransformProperty(elem, data, container) { 2892 this.elem = elem; 2893 this.frameId = -1; 2894 this.propType = 'transform'; 2895 this.data = data; 2896 this.v = new Matrix(); 2897 // Precalculated matrix with non animated properties 2898 this.pre = new Matrix(); 2899 this.appliedTransformations = 0; 2900 this.initDynamicPropertyContainer(container || elem); 2901 if (data.p && data.p.s) { 2902 this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this); 2903 this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this); 2904 if (data.p.z) { 2905 this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this); 2906 } 2907 } else { 2908 this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this); 2909 } 2910 if (data.rx) { 2911 this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this); 2912 this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this); 2913 this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this); 2914 if (data.or.k[0].ti) { 2915 var i; 2916 var len = data.or.k.length; 2917 for (i = 0; i < len; i += 1) { 2918 data.or.k[i].to = null; 2919 data.or.k[i].ti = null; 2920 } 2921 } 2922 this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this); 2923 // sh Indicates it needs to be capped between -180 and 180 2924 this.or.sh = true; 2925 } else { 2926 this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this); 2927 } 2928 if (data.sk) { 2929 this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this); 2930 this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this); 2931 } 2932 this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this); 2933 this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this); 2934 // Opacity is not part of the transform properties, that's why it won't use this.dynamicProperties. That way transforms won't get updated if opacity changes. 2935 if (data.o) { 2936 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem); 2937 } else { 2938 this.o = { _mdf: false, v: 1 }; 2939 } 2940 this._isDirty = true; 2941 if (!this.dynamicProperties.length) { 2942 this.getValue(true); 2943 } 2944 } 2945 2946 TransformProperty.prototype = { 2947 applyToMatrix: applyToMatrix, 2948 getValue: processKeys, 2949 precalculateMatrix: precalculateMatrix, 2950 autoOrient: autoOrient, 2951 }; 2952 2953 extendPrototype([DynamicPropertyContainer], TransformProperty); 2954 TransformProperty.prototype.addDynamicProperty = addDynamicProperty; 2955 TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty; 2956 2957 function getTransformProperty(elem, data, container) { 2958 return new TransformProperty(elem, data, container); 2959 } 2960 2961 return { 2962 getTransformProperty: getTransformProperty, 2963 }; 2964}()); 2965 2966/* global createSizedArray, createSizedArray, pointPool */ 2967 2968function ShapePath() { 2969 this.c = false;
vendor: 1,036 bytes, lines 2970-3006
2970 this._length = 0; 2971 this._maxLength = 8; 2972 this.v = createSizedArray(this._maxLength); 2973 this.o = createSizedArray(this._maxLength); 2974 this.i = createSizedArray(this._maxLength); 2975} 2976 2977ShapePath.prototype.setPathData = function (closed, len) { 2978 this.c = closed; 2979 this.setLength(len); 2980 var i = 0; 2981 while (i < len) { 2982 this.v[i] = pointPool.newElement(); 2983 this.o[i] = pointPool.newElement(); 2984 this.i[i] = pointPool.newElement(); 2985 i += 1; 2986 } 2987}; 2988 2989ShapePath.prototype.setLength = function (len) { 2990 while (this._maxLength < len) { 2991 this.doubleArrayLength(); 2992 } 2993 this._length = len; 2994}; 2995 2996ShapePath.prototype.doubleArrayLength = function () { 2997 this.v = this.v.concat(createSizedArray(this._maxLength)); 2998 this.i = this.i.concat(createSizedArray(this._maxLength)); 2999 this.o = this.o.concat(createSizedArray(this._maxLength)); 3000 this._maxLength *= 2; 3001}; 3002 3003ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) { 3004 var arr; 3005 this._length = Math.max(this._length, pos + 1); 3006 if (this._length >= this._maxLength) {
vendor: 4,993 bytes, lines 3007-3165
3007 this.doubleArrayLength(); 3008 } 3009 switch (type) { 3010 case 'v': 3011 arr = this.v; 3012 break; 3013 case 'i': 3014 arr = this.i; 3015 break; 3016 case 'o': 3017 arr = this.o; 3018 break; 3019 default: 3020 arr = []; 3021 break; 3022 } 3023 if (!arr[pos] || (arr[pos] && !replace)) { 3024 arr[pos] = pointPool.newElement(); 3025 } 3026 arr[pos][0] = x; 3027 arr[pos][1] = y; 3028}; 3029 3030ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) { 3031 this.setXYAt(vX, vY, 'v', pos, replace); 3032 this.setXYAt(oX, oY, 'o', pos, replace); 3033 this.setXYAt(iX, iY, 'i', pos, replace); 3034}; 3035 3036ShapePath.prototype.reverse = function () { 3037 var newPath = new ShapePath(); 3038 newPath.setPathData(this.c, this._length); 3039 var vertices = this.v; 3040 var outPoints = this.o; 3041 var inPoints = this.i; 3042 var init = 0; 3043 if (this.c) { 3044 newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false); 3045 init = 1; 3046 } 3047 var cnt = this._length - 1; 3048 var len = this._length; 3049 3050 var i; 3051 for (i = init; i < len; i += 1) { 3052 newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false); 3053 cnt -= 1; 3054 } 3055 return newPath; 3056}; 3057 3058/* global extendPrototype, roundCorner, BezierFactory, shapePool, degToRads, 3059 shapeCollectionPool, PropertyFactory, bmMin, DynamicPropertyContainer */ 3060/* exported ShapePropertyFactory */ 3061 3062var ShapePropertyFactory = (function () { 3063 var initFrame = -999999; 3064 3065 function interpolateShape(frameNum, previousValue, caching) { 3066 var iterationIndex = caching.lastIndex; 3067 var keyPropS; 3068 var keyPropE; 3069 var isHold; 3070 var j; 3071 var k; 3072 var jLen; 3073 var kLen; 3074 var perc; 3075 var vertexValue; 3076 var kf = this.keyframes; 3077 if (frameNum < kf[0].t - this.offsetTime) { 3078 keyPropS = kf[0].s[0]; 3079 isHold = true; 3080 iterationIndex = 0; 3081 } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) { 3082 keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0]; 3083 /* if(kf[kf.length - 1].s){ 3084 keyPropS = kf[kf.length - 1].s[0]; 3085 }else{ 3086 keyPropS = kf[kf.length - 2].e[0]; 3087 } */ 3088 isHold = true; 3089 } else { 3090 var i = iterationIndex; 3091 var len = kf.length - 1; 3092 var flag = true; 3093 var keyData; 3094 var nextKeyData; 3095 while (flag) { 3096 keyData = kf[i]; 3097 nextKeyData = kf[i + 1]; 3098 if ((nextKeyData.t - this.offsetTime) > frameNum) { 3099 break; 3100 } 3101 if (i < len - 1) { 3102 i += 1; 3103 } else { 3104 flag = false; 3105 } 3106 } 3107 isHold = keyData.h === 1; 3108 iterationIndex = i; 3109 if (!isHold) { 3110 if (frameNum >= nextKeyData.t - this.offsetTime) { 3111 perc = 1; 3112 } else if (frameNum < keyData.t - this.offsetTime) { 3113 perc = 0; 3114 } else { 3115 var fnc; 3116 if (keyData.__fnct) { 3117 fnc = keyData.__fnct; 3118 } else { 3119 fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get; 3120 keyData.__fnct = fnc; 3121 } 3122 perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime))); 3123 } 3124 keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0]; 3125 } 3126 keyPropS = keyData.s[0]; 3127 } 3128 jLen = previousValue._length; 3129 kLen = keyPropS.i[0].length; 3130 caching.lastIndex = iterationIndex; 3131 3132 for (j = 0; j < jLen; j += 1) { 3133 for (k = 0; k < kLen; k += 1) { 3134 vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc; 3135 previousValue.i[j][k] = vertexValue; 3136 vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc; 3137 previousValue.o[j][k] = vertexValue; 3138 vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc; 3139 previousValue.v[j][k] = vertexValue; 3140 } 3141 } 3142 } 3143 3144 function interpolateShapeCurrentTime() { 3145 var frameNum = this.comp.renderedFrame - this.offsetTime; 3146 var initTime = this.keyframes[0].t - this.offsetTime; 3147 var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime; 3148 var lastFrame = this._caching.lastFrame; 3149 if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) { 3150 /// / 3151 this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0; 3152 this.interpolateShape(frameNum, this.pv, this._caching); 3153 /// / 3154 } 3155 this._caching.lastFrame = frameNum; 3156 return this.pv; 3157 } 3158 3159 function resetShape() { 3160 this.paths = this.localShapeCollection; 3161 } 3162 3163 function shapesEqual(shape1, shape2) { 3164 if (shape1._length !== shape2._length || shape1.c !== shape2.c) { 3165 return false;
vendor: 15,754 bytes, lines 3166-3574
3166 } 3167 var i; 3168 var len = shape1._length; 3169 for (i = 0; i < len; i += 1) { 3170 if (shape1.v[i][0] !== shape2.v[i][0] 3171 || shape1.v[i][1] !== shape2.v[i][1] 3172 || shape1.o[i][0] !== shape2.o[i][0] 3173 || shape1.o[i][1] !== shape2.o[i][1] 3174 || shape1.i[i][0] !== shape2.i[i][0] 3175 || shape1.i[i][1] !== shape2.i[i][1]) { 3176 return false; 3177 } 3178 } 3179 return true; 3180 } 3181 3182 function setVValue(newPath) { 3183 if (!shapesEqual(this.v, newPath)) { 3184 this.v = shapePool.clone(newPath); 3185 this.localShapeCollection.releaseShapes(); 3186 this.localShapeCollection.addShape(this.v); 3187 this._mdf = true; 3188 this.paths = this.localShapeCollection; 3189 } 3190 } 3191 3192 function processEffectsSequence() { 3193 if (this.elem.globalData.frameId === this.frameId) { 3194 return; 3195 } if (!this.effectsSequence.length) { 3196 this._mdf = false; 3197 return; 3198 } 3199 if (this.lock) { 3200 this.setVValue(this.pv); 3201 return; 3202 } 3203 this.lock = true; 3204 this._mdf = false; 3205 var finalValue; 3206 if (this.kf) { 3207 finalValue = this.pv; 3208 } else if (this.data.ks) { 3209 finalValue = this.data.ks.k; 3210 } else { 3211 finalValue = this.data.pt.k; 3212 } 3213 var i; 3214 var len = this.effectsSequence.length; 3215 for (i = 0; i < len; i += 1) { 3216 finalValue = this.effectsSequence[i](finalValue); 3217 } 3218 this.setVValue(finalValue); 3219 this.lock = false; 3220 this.frameId = this.elem.globalData.frameId; 3221 } 3222 3223 function ShapeProperty(elem, data, type) { 3224 this.propType = 'shape'; 3225 this.comp = elem.comp; 3226 this.container = elem; 3227 this.elem = elem; 3228 this.data = data; 3229 this.k = false; 3230 this.kf = false; 3231 this._mdf = false; 3232 var pathData = type === 3 ? data.pt.k : data.ks.k; 3233 this.v = shapePool.clone(pathData); 3234 this.pv = shapePool.clone(this.v); 3235 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3236 this.paths = this.localShapeCollection; 3237 this.paths.addShape(this.v); 3238 this.reset = resetShape; 3239 this.effectsSequence = []; 3240 } 3241 3242 function addEffect(effectFunction) { 3243 this.effectsSequence.push(effectFunction); 3244 this.container.addDynamicProperty(this); 3245 } 3246 3247 ShapeProperty.prototype.interpolateShape = interpolateShape; 3248 ShapeProperty.prototype.getValue = processEffectsSequence; 3249 ShapeProperty.prototype.setVValue = setVValue; 3250 ShapeProperty.prototype.addEffect = addEffect; 3251 3252 function KeyframedShapeProperty(elem, data, type) { 3253 this.propType = 'shape'; 3254 this.comp = elem.comp; 3255 this.elem = elem; 3256 this.container = elem; 3257 this.offsetTime = elem.data.st; 3258 this.keyframes = type === 3 ? data.pt.k : data.ks.k; 3259 this.k = true; 3260 this.kf = true; 3261 var len = this.keyframes[0].s[0].i.length; 3262 this.v = shapePool.newElement(); 3263 this.v.setPathData(this.keyframes[0].s[0].c, len); 3264 this.pv = shapePool.clone(this.v); 3265 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3266 this.paths = this.localShapeCollection; 3267 this.paths.addShape(this.v); 3268 this.lastFrame = initFrame; 3269 this.reset = resetShape; 3270 this._caching = { lastFrame: initFrame, lastIndex: 0 }; 3271 this.effectsSequence = [interpolateShapeCurrentTime.bind(this)]; 3272 } 3273 KeyframedShapeProperty.prototype.getValue = processEffectsSequence; 3274 KeyframedShapeProperty.prototype.interpolateShape = interpolateShape; 3275 KeyframedShapeProperty.prototype.setVValue = setVValue; 3276 KeyframedShapeProperty.prototype.addEffect = addEffect; 3277 3278 var EllShapeProperty = (function () { 3279 var cPoint = roundCorner; 3280 3281 function EllShapePropertyFactory(elem, data) { 3282 /* this.v = { 3283 v: createSizedArray(4), 3284 i: createSizedArray(4), 3285 o: createSizedArray(4), 3286 c: true 3287 }; */ 3288 this.v = shapePool.newElement(); 3289 this.v.setPathData(true, 4); 3290 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3291 this.paths = this.localShapeCollection; 3292 this.localShapeCollection.addShape(this.v); 3293 this.d = data.d; 3294 this.elem = elem; 3295 this.comp = elem.comp; 3296 this.frameId = -1; 3297 this.initDynamicPropertyContainer(elem); 3298 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this); 3299 this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this); 3300 if (this.dynamicProperties.length) { 3301 this.k = true; 3302 } else { 3303 this.k = false; 3304 this.convertEllToPath(); 3305 } 3306 } 3307 3308 EllShapePropertyFactory.prototype = { 3309 reset: resetShape, 3310 getValue: function () { 3311 if (this.elem.globalData.frameId === this.frameId) { 3312 return; 3313 } 3314 this.frameId = this.elem.globalData.frameId; 3315 this.iterateDynamicProperties(); 3316 3317 if (this._mdf) { 3318 this.convertEllToPath(); 3319 } 3320 }, 3321 convertEllToPath: function () { 3322 var p0 = this.p.v[0]; 3323 var p1 = this.p.v[1]; 3324 var s0 = this.s.v[0] / 2; 3325 var s1 = this.s.v[1] / 2; 3326 var _cw = this.d !== 3; 3327 var _v = this.v; 3328 _v.v[0][0] = p0; 3329 _v.v[0][1] = p1 - s1; 3330 _v.v[1][0] = _cw ? p0 + s0 : p0 - s0; 3331 _v.v[1][1] = p1; 3332 _v.v[2][0] = p0; 3333 _v.v[2][1] = p1 + s1; 3334 _v.v[3][0] = _cw ? p0 - s0 : p0 + s0; 3335 _v.v[3][1] = p1; 3336 _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint; 3337 _v.i[0][1] = p1 - s1; 3338 _v.i[1][0] = _cw ? p0 + s0 : p0 - s0; 3339 _v.i[1][1] = p1 - s1 * cPoint; 3340 _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint; 3341 _v.i[2][1] = p1 + s1; 3342 _v.i[3][0] = _cw ? p0 - s0 : p0 + s0; 3343 _v.i[3][1] = p1 + s1 * cPoint; 3344 _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint; 3345 _v.o[0][1] = p1 - s1; 3346 _v.o[1][0] = _cw ? p0 + s0 : p0 - s0; 3347 _v.o[1][1] = p1 + s1 * cPoint; 3348 _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint; 3349 _v.o[2][1] = p1 + s1; 3350 _v.o[3][0] = _cw ? p0 - s0 : p0 + s0; 3351 _v.o[3][1] = p1 - s1 * cPoint; 3352 }, 3353 }; 3354 3355 extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory); 3356 3357 return EllShapePropertyFactory; 3358 }()); 3359 3360 var StarShapeProperty = (function () { 3361 function StarShapePropertyFactory(elem, data) { 3362 this.v = shapePool.newElement(); 3363 this.v.setPathData(true, 0); 3364 this.elem = elem; 3365 this.comp = elem.comp; 3366 this.data = data; 3367 this.frameId = -1; 3368 this.d = data.d; 3369 this.initDynamicPropertyContainer(elem); 3370 if (data.sy === 1) { 3371 this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this); 3372 this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this); 3373 this.convertToPath = this.convertStarToPath; 3374 } else { 3375 this.convertToPath = this.convertPolygonToPath; 3376 } 3377 this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this); 3378 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this); 3379 this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this); 3380 this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this); 3381 this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this); 3382 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3383 this.localShapeCollection.addShape(this.v); 3384 this.paths = this.localShapeCollection; 3385 if (this.dynamicProperties.length) { 3386 this.k = true; 3387 } else { 3388 this.k = false; 3389 this.convertToPath(); 3390 } 3391 } 3392 3393 StarShapePropertyFactory.prototype = { 3394 reset: resetShape, 3395 getValue: function () { 3396 if (this.elem.globalData.frameId === this.frameId) { 3397 return; 3398 } 3399 this.frameId = this.elem.globalData.frameId; 3400 this.iterateDynamicProperties(); 3401 if (this._mdf) { 3402 this.convertToPath(); 3403 } 3404 }, 3405 convertStarToPath: function () { 3406 var numPts = Math.floor(this.pt.v) * 2; 3407 var angle = (Math.PI * 2) / numPts; 3408 /* this.v.v.length = numPts; 3409 this.v.i.length = numPts; 3410 this.v.o.length = numPts; */ 3411 var longFlag = true; 3412 var longRad = this.or.v; 3413 var shortRad = this.ir.v; 3414 var longRound = this.os.v; 3415 var shortRound = this.is.v; 3416 var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2); 3417 var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2); 3418 var i; 3419 var rad; 3420 var roundness; 3421 var perimSegment; 3422 var currentAng = -Math.PI / 2; 3423 currentAng += this.r.v; 3424 var dir = this.data.d === 3 ? -1 : 1; 3425 this.v._length = 0; 3426 for (i = 0; i < numPts; i += 1) { 3427 rad = longFlag ? longRad : shortRad; 3428 roundness = longFlag ? longRound : shortRound; 3429 perimSegment = longFlag ? longPerimSegment : shortPerimSegment; 3430 var x = rad * Math.cos(currentAng); 3431 var y = rad * Math.sin(currentAng); 3432 var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y); 3433 var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y); 3434 x += +this.p.v[0]; 3435 y += +this.p.v[1]; 3436 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); 3437 3438 /* this.v.v[i] = [x,y]; 3439 this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir]; 3440 this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir]; 3441 this.v._length = numPts; */ 3442 longFlag = !longFlag; 3443 currentAng += angle * dir; 3444 } 3445 }, 3446 convertPolygonToPath: function () { 3447 var numPts = Math.floor(this.pt.v); 3448 var angle = (Math.PI * 2) / numPts; 3449 var rad = this.or.v; 3450 var roundness = this.os.v; 3451 var perimSegment = (2 * Math.PI * rad) / (numPts * 4); 3452 var i; 3453 var currentAng = -Math.PI * 0.5; 3454 var dir = this.data.d === 3 ? -1 : 1; 3455 currentAng += this.r.v; 3456 this.v._length = 0; 3457 for (i = 0; i < numPts; i += 1) { 3458 var x = rad * Math.cos(currentAng); 3459 var y = rad * Math.sin(currentAng); 3460 var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y); 3461 var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y); 3462 x += +this.p.v[0]; 3463 y += +this.p.v[1]; 3464 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); 3465 currentAng += angle * dir; 3466 } 3467 this.paths.length = 0; 3468 this.paths[0] = this.v; 3469 }, 3470 3471 }; 3472 extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory); 3473 3474 return StarShapePropertyFactory; 3475 }()); 3476 3477 var RectShapeProperty = (function () { 3478 function RectShapePropertyFactory(elem, data) { 3479 this.v = shapePool.newElement(); 3480 this.v.c = true; 3481 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3482 this.localShapeCollection.addShape(this.v); 3483 this.paths = this.localShapeCollection; 3484 this.elem = elem; 3485 this.comp = elem.comp; 3486 this.frameId = -1; 3487 this.d = data.d; 3488 this.initDynamicPropertyContainer(elem); 3489 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this); 3490 this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this); 3491 this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this); 3492 if (this.dynamicProperties.length) { 3493 this.k = true; 3494 } else { 3495 this.k = false; 3496 this.convertRectToPath(); 3497 } 3498 } 3499 3500 RectShapePropertyFactory.prototype = { 3501 convertRectToPath: function () { 3502 var p0 = this.p.v[0]; 3503 var p1 = this.p.v[1]; 3504 var v0 = this.s.v[0] / 2; 3505 var v1 = this.s.v[1] / 2; 3506 var round = bmMin(v0, v1, this.r.v); 3507 var cPoint = round * (1 - roundCorner); 3508 this.v._length = 0; 3509 3510 if (this.d === 2 || this.d === 1) { 3511 this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true); 3512 this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true); 3513 if (round !== 0) { 3514 this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true); 3515 this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true); 3516 this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true); 3517 this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true); 3518 this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true); 3519 this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true); 3520 } else { 3521 this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2); 3522 this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3); 3523 } 3524 } else { 3525 this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true); 3526 if (round !== 0) { 3527 this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true); 3528 this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true); 3529 this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true); 3530 this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true); 3531 this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true); 3532 this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true); 3533 this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true); 3534 } else { 3535 this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true); 3536 this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true); 3537 this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true); 3538 } 3539 } 3540 }, 3541 getValue: function () { 3542 if (this.elem.globalData.frameId === this.frameId) { 3543 return; 3544 } 3545 this.frameId = this.elem.globalData.frameId; 3546 this.iterateDynamicProperties(); 3547 if (this._mdf) { 3548 this.convertRectToPath(); 3549 } 3550 }, 3551 reset: resetShape, 3552 }; 3553 extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory); 3554 3555 return RectShapePropertyFactory; 3556 }()); 3557 3558 function getShapeProp(elem, data, type) { 3559 var prop; 3560 if (type === 3 || type === 4) { 3561 var dataProp = type === 3 ? data.pt : data.ks; 3562 var keys = dataProp.k; 3563 if (keys.length) { 3564 prop = new KeyframedShapeProperty(elem, data, type); 3565 } else { 3566 prop = new ShapeProperty(elem, data, type); 3567 } 3568 } else if (type === 5) { 3569 prop = new RectShapeProperty(elem, data); 3570 } else if (type === 6) { 3571 prop = new EllShapeProperty(elem, data); 3572 } else if (type === 7) { 3573 prop = new StarShapeProperty(elem, data); 3574 }
vendor: 2,350 bytes, lines 3575-3657
3575 if (prop.k) { 3576 elem.addDynamicProperty(prop); 3577 } 3578 return prop; 3579 } 3580 3581 function getConstructorFunction() { 3582 return ShapeProperty; 3583 } 3584 3585 function getKeyframedConstructorFunction() { 3586 return KeyframedShapeProperty; 3587 } 3588 3589 var ob = {}; 3590 ob.getShapeProp = getShapeProp; 3591 ob.getConstructorFunction = getConstructorFunction; 3592 ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction; 3593 return ob; 3594}()); 3595 3596/* global shapeCollectionPool, initialDefaultFrame, extendPrototype, DynamicPropertyContainer */ 3597/* exported ShapeModifiers */ 3598 3599var ShapeModifiers = (function () { 3600 var ob = {}; 3601 var modifiers = {}; 3602 ob.registerModifier = registerModifier; 3603 ob.getModifier = getModifier; 3604 3605 function registerModifier(nm, factory) { 3606 if (!modifiers[nm]) { 3607 modifiers[nm] = factory; 3608 } 3609 } 3610 3611 function getModifier(nm, elem, data) { 3612 return new modifiers[nm](elem, data); 3613 } 3614 3615 return ob; 3616}()); 3617 3618function ShapeModifier() {} 3619ShapeModifier.prototype.initModifierProperties = function () {}; 3620ShapeModifier.prototype.addShapeToModifier = function () {}; 3621ShapeModifier.prototype.addShape = function (data) { 3622 if (!this.closed) { 3623 // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick. 3624 data.sh.container.addDynamicProperty(data.sh); 3625 var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() }; 3626 this.shapes.push(shapeData); 3627 this.addShapeToModifier(shapeData); 3628 if (this._isAnimated) { 3629 data.setAsAnimated(); 3630 } 3631 } 3632}; 3633ShapeModifier.prototype.init = function (elem, data) { 3634 this.shapes = []; 3635 this.elem = elem; 3636 this.initDynamicPropertyContainer(elem); 3637 this.initModifierProperties(elem, data); 3638 this.frameId = initialDefaultFrame; 3639 this.closed = false; 3640 this.k = false; 3641 if (this.dynamicProperties.length) { 3642 this.k = true; 3643 } else { 3644 this.getValue(true); 3645 } 3646}; 3647ShapeModifier.prototype.processKeys = function () { 3648 if (this.elem.globalData.frameId === this.frameId) { 3649 return; 3650 } 3651 this.frameId = this.elem.globalData.frameId; 3652 this.iterateDynamicProperties(); 3653}; 3654 3655extendPrototype([DynamicPropertyContainer], ShapeModifier); 3656 3657/* global extendPrototype, ShapeModifier, PropertyFactory, segmentsLengthPool, bez, shapePool, ShapeModifiers */
vendor: 11,784 bytes, lines 3657-4005
3657 3658 3659function TrimModifier() { 3660} 3661extendPrototype([ShapeModifier], TrimModifier); 3662TrimModifier.prototype.initModifierProperties = function (elem, data) { 3663 this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this); 3664 this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this); 3665 this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this); 3666 this.sValue = 0; 3667 this.eValue = 0; 3668 this.getValue = this.processKeys; 3669 this.m = data.m; 3670 this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length; 3671}; 3672 3673TrimModifier.prototype.addShapeToModifier = function (shapeData) { 3674 shapeData.pathsData = []; 3675}; 3676 3677TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) { 3678 var segments = []; 3679 if (e <= 1) { 3680 segments.push({ 3681 s: s, 3682 e: e, 3683 }); 3684 } else if (s >= 1) { 3685 segments.push({ 3686 s: s - 1, 3687 e: e - 1, 3688 }); 3689 } else { 3690 segments.push({ 3691 s: s, 3692 e: 1, 3693 }); 3694 segments.push({ 3695 s: 0, 3696 e: e - 1, 3697 }); 3698 } 3699 var shapeSegments = []; 3700 var i; 3701 var len = segments.length; 3702 var segmentOb; 3703 for (i = 0; i < len; i += 1) { 3704 segmentOb = segments[i]; 3705 if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) { 3706 var shapeS; 3707 var shapeE; 3708 if (segmentOb.s * totalModifierLength <= addedLength) { 3709 shapeS = 0; 3710 } else { 3711 shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength; 3712 } 3713 if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) { 3714 shapeE = 1; 3715 } else { 3716 shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength); 3717 } 3718 shapeSegments.push([shapeS, shapeE]); 3719 } 3720 } 3721 if (!shapeSegments.length) { 3722 shapeSegments.push([0, 0]); 3723 } 3724 return shapeSegments; 3725}; 3726 3727TrimModifier.prototype.releasePathsData = function (pathsData) { 3728 var i; 3729 var len = pathsData.length; 3730 for (i = 0; i < len; i += 1) { 3731 segmentsLengthPool.release(pathsData[i]); 3732 } 3733 pathsData.length = 0; 3734 return pathsData; 3735}; 3736 3737TrimModifier.prototype.processShapes = function (_isFirstFrame) { 3738 var s; 3739 var e; 3740 if (this._mdf || _isFirstFrame) { 3741 var o = (this.o.v % 360) / 360; 3742 if (o < 0) { 3743 o += 1; 3744 } 3745 if (this.s.v > 1) { 3746 s = 1 + o; 3747 } else if (this.s.v < 0) { 3748 s = 0 + o; 3749 } else { 3750 s = this.s.v + o; 3751 } 3752 if (this.e.v > 1) { 3753 e = 1 + o; 3754 } else if (this.e.v < 0) { 3755 e = 0 + o; 3756 } else { 3757 e = this.e.v + o; 3758 } 3759 3760 if (s > e) { 3761 var _s = s; 3762 s = e; 3763 e = _s; 3764 } 3765 s = Math.round(s * 10000) * 0.0001; 3766 e = Math.round(e * 10000) * 0.0001; 3767 this.sValue = s; 3768 this.eValue = e; 3769 } else { 3770 s = this.sValue; 3771 e = this.eValue; 3772 } 3773 var shapePaths; 3774 var i; 3775 var len = this.shapes.length; 3776 var j; 3777 var jLen; 3778 var pathsData; 3779 var pathData; 3780 var totalShapeLength; 3781 var totalModifierLength = 0; 3782 3783 if (e === s) { 3784 for (i = 0; i < len; i += 1) { 3785 this.shapes[i].localShapeCollection.releaseShapes(); 3786 this.shapes[i].shape._mdf = true; 3787 this.shapes[i].shape.paths = this.shapes[i].localShapeCollection; 3788 if (this._mdf) { 3789 this.shapes[i].pathsData.length = 0; 3790 } 3791 } 3792 } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) { 3793 var segments = []; 3794 var shapeData; 3795 var localShapeCollection; 3796 for (i = 0; i < len; i += 1) { 3797 shapeData = this.shapes[i]; 3798 // if shape hasn't changed and trim properties haven't changed, cached previous path can be used 3799 if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) { 3800 shapeData.shape.paths = shapeData.localShapeCollection; 3801 } else { 3802 shapePaths = shapeData.shape.paths; 3803 jLen = shapePaths._length; 3804 totalShapeLength = 0; 3805 if (!shapeData.shape._mdf && shapeData.pathsData.length) { 3806 totalShapeLength = shapeData.totalShapeLength; 3807 } else { 3808 pathsData = this.releasePathsData(shapeData.pathsData); 3809 for (j = 0; j < jLen; j += 1) { 3810 pathData = bez.getSegmentsLength(shapePaths.shapes[j]); 3811 pathsData.push(pathData); 3812 totalShapeLength += pathData.totalLength; 3813 } 3814 shapeData.totalShapeLength = totalShapeLength; 3815 shapeData.pathsData = pathsData; 3816 } 3817 3818 totalModifierLength += totalShapeLength; 3819 shapeData.shape._mdf = true; 3820 } 3821 } 3822 var shapeS = s; 3823 var shapeE = e; 3824 var addedLength = 0; 3825 var edges; 3826 for (i = len - 1; i >= 0; i -= 1) { 3827 shapeData = this.shapes[i]; 3828 if (shapeData.shape._mdf) { 3829 localShapeCollection = shapeData.localShapeCollection; 3830 localShapeCollection.releaseShapes(); 3831 // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group 3832 if (this.m === 2 && len > 1) { 3833 edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength); 3834 addedLength += shapeData.totalShapeLength; 3835 } else { 3836 edges = [[shapeS, shapeE]]; 3837 } 3838 jLen = edges.length; 3839 for (j = 0; j < jLen; j += 1) { 3840 shapeS = edges[j][0]; 3841 shapeE = edges[j][1]; 3842 segments.length = 0; 3843 if (shapeE <= 1) { 3844 segments.push({ 3845 s: shapeData.totalShapeLength * shapeS, 3846 e: shapeData.totalShapeLength * shapeE, 3847 }); 3848 } else if (shapeS >= 1) { 3849 segments.push({ 3850 s: shapeData.totalShapeLength * (shapeS - 1), 3851 e: shapeData.totalShapeLength * (shapeE - 1), 3852 }); 3853 } else { 3854 segments.push({ 3855 s: shapeData.totalShapeLength * shapeS, 3856 e: shapeData.totalShapeLength, 3857 }); 3858 segments.push({ 3859 s: 0, 3860 e: shapeData.totalShapeLength * (shapeE - 1), 3861 }); 3862 } 3863 var newShapesData = this.addShapes(shapeData, segments[0]); 3864 if (segments[0].s !== segments[0].e) { 3865 if (segments.length > 1) { 3866 var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1]; 3867 if (lastShapeInCollection.c) { 3868 var lastShape = newShapesData.pop(); 3869 this.addPaths(newShapesData, localShapeCollection); 3870 newShapesData = this.addShapes(shapeData, segments[1], lastShape); 3871 } else { 3872 this.addPaths(newShapesData, localShapeCollection); 3873 newShapesData = this.addShapes(shapeData, segments[1]); 3874 } 3875 } 3876 this.addPaths(newShapesData, localShapeCollection); 3877 } 3878 } 3879 shapeData.shape.paths = localShapeCollection; 3880 } 3881 } 3882 } else if (this._mdf) { 3883 for (i = 0; i < len; i += 1) { 3884 // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween. 3885 // Don't remove this even if it's losing cached info. 3886 this.shapes[i].pathsData.length = 0; 3887 this.shapes[i].shape._mdf = true; 3888 } 3889 } 3890}; 3891 3892TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) { 3893 var i; 3894 var len = newPaths.length; 3895 for (i = 0; i < len; i += 1) { 3896 localShapeCollection.addShape(newPaths[i]); 3897 } 3898}; 3899 3900TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) { 3901 shapePath.setXYAt(pt2[0], pt2[1], 'o', pos); 3902 shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1); 3903 if (newShape) { 3904 shapePath.setXYAt(pt1[0], pt1[1], 'v', pos); 3905 } 3906 shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1); 3907}; 3908 3909TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) { 3910 shapePath.setXYAt(points[1], points[5], 'o', pos); 3911 shapePath.setXYAt(points[2], points[6], 'i', pos + 1); 3912 if (newShape) { 3913 shapePath.setXYAt(points[0], points[4], 'v', pos); 3914 } 3915 shapePath.setXYAt(points[3], points[7], 'v', pos + 1); 3916}; 3917 3918TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) { 3919 var pathsData = shapeData.pathsData; 3920 var shapePaths = shapeData.shape.paths.shapes; 3921 var i; 3922 var len = shapeData.shape.paths._length; 3923 var j; 3924 var jLen; 3925 var addedLength = 0; 3926 var currentLengthData; 3927 var segmentCount; 3928 var lengths; 3929 var segment; 3930 var shapes = []; 3931 var initPos; 3932 var newShape = true; 3933 if (!shapePath) { 3934 shapePath = shapePool.newElement(); 3935 segmentCount = 0; 3936 initPos = 0; 3937 } else { 3938 segmentCount = shapePath._length; 3939 initPos = shapePath._length; 3940 } 3941 shapes.push(shapePath); 3942 for (i = 0; i < len; i += 1) { 3943 lengths = pathsData[i].lengths; 3944 shapePath.c = shapePaths[i].c; 3945 jLen = shapePaths[i].c ? lengths.length : lengths.length + 1; 3946 for (j = 1; j < jLen; j += 1) { 3947 currentLengthData = lengths[j - 1]; 3948 if (addedLength + currentLengthData.addedLength < shapeSegment.s) { 3949 addedLength += currentLengthData.addedLength; 3950 shapePath.c = false; 3951 } else if (addedLength > shapeSegment.e) { 3952 shapePath.c = false; 3953 break; 3954 } else { 3955 if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) { 3956 this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape); 3957 newShape = false; 3958 } else { 3959 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]); 3960 this.addSegmentFromArray(segment, shapePath, segmentCount, newShape); 3961 // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape); 3962 newShape = false; 3963 shapePath.c = false; 3964 } 3965 addedLength += currentLengthData.addedLength; 3966 segmentCount += 1; 3967 } 3968 } 3969 if (shapePaths[i].c && lengths.length) { 3970 currentLengthData = lengths[j - 1]; 3971 if (addedLength <= shapeSegment.e) { 3972 var segmentLength = lengths[j - 1].addedLength; 3973 if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) { 3974 this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape); 3975 newShape = false; 3976 } else { 3977 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]); 3978 this.addSegmentFromArray(segment, shapePath, segmentCount, newShape); 3979 // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape); 3980 newShape = false; 3981 shapePath.c = false; 3982 } 3983 } else { 3984 shapePath.c = false; 3985 } 3986 addedLength += currentLengthData.addedLength; 3987 segmentCount += 1; 3988 } 3989 if (shapePath._length) { 3990 shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos); 3991 shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1); 3992 } 3993 if (addedLength > shapeSegment.e) { 3994 break; 3995 } 3996 if (i < len - 1) { 3997 shapePath = shapePool.newElement(); 3998 newShape = true; 3999 shapes.push(shapePath); 4000 segmentCount = 0; 4001 } 4002 } 4003 return shapes; 4004}; 4005
vendor: 3,846 bytes, lines 4006-4115
4006ShapeModifiers.registerModifier('tm', TrimModifier); 4007 4008/* global extendPrototype, ShapeModifier, PropertyFactory, shapePool, roundCorner, ShapeModifiers */ 4009 4010function RoundCornersModifier() {} 4011extendPrototype([ShapeModifier], RoundCornersModifier); 4012RoundCornersModifier.prototype.initModifierProperties = function (elem, data) { 4013 this.getValue = this.processKeys; 4014 this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this); 4015 this._isAnimated = !!this.rd.effectsSequence.length; 4016}; 4017 4018RoundCornersModifier.prototype.processPath = function (path, round) { 4019 var clonedPath = shapePool.newElement(); 4020 clonedPath.c = path.c; 4021 var i; 4022 var len = path._length; 4023 var currentV; 4024 var currentI; 4025 var currentO; 4026 var closerV; 4027 var distance; 4028 var newPosPerc; 4029 var index = 0; 4030 var vX; 4031 var vY; 4032 var oX; 4033 var oY; 4034 var iX; 4035 var iY; 4036 for (i = 0; i < len; i += 1) { 4037 currentV = path.v[i]; 4038 currentO = path.o[i]; 4039 currentI = path.i[i]; 4040 if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) { 4041 if ((i === 0 || i === len - 1) && !path.c) { 4042 clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index); 4043 /* clonedPath.v[index] = currentV; 4044 clonedPath.o[index] = currentO; 4045 clonedPath.i[index] = currentI; */ 4046 index += 1; 4047 } else { 4048 if (i === 0) { 4049 closerV = path.v[len - 1]; 4050 } else { 4051 closerV = path.v[i - 1]; 4052 } 4053 distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2)); 4054 newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0; 4055 iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc; 4056 vX = iX; 4057 iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc; 4058 vY = iY; 4059 oX = vX - (vX - currentV[0]) * roundCorner; 4060 oY = vY - (vY - currentV[1]) * roundCorner; 4061 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index); 4062 index += 1; 4063 4064 if (i === len - 1) { 4065 closerV = path.v[0]; 4066 } else { 4067 closerV = path.v[i + 1]; 4068 } 4069 distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2)); 4070 newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0; 4071 oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc; 4072 vX = oX; 4073 oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc; 4074 vY = oY; 4075 iX = vX - (vX - currentV[0]) * roundCorner; 4076 iY = vY - (vY - currentV[1]) * roundCorner; 4077 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index); 4078 index += 1; 4079 } 4080 } else { 4081 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); 4082 index += 1; 4083 } 4084 } 4085 return clonedPath; 4086}; 4087 4088RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) { 4089 var shapePaths; 4090 var i; 4091 var len = this.shapes.length; 4092 var j; 4093 var jLen; 4094 var rd = this.rd.v; 4095 4096 if (rd !== 0) { 4097 var shapeData; 4098 var localShapeCollection; 4099 for (i = 0; i < len; i += 1) { 4100 shapeData = this.shapes[i]; 4101 localShapeCollection = shapeData.localShapeCollection; 4102 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) { 4103 localShapeCollection.releaseShapes(); 4104 shapeData.shape._mdf = true; 4105 shapePaths = shapeData.shape.paths.shapes; 4106 jLen = shapeData.shape.paths._length; 4107 for (j = 0; j < jLen; j += 1) { 4108 localShapeCollection.addShape(this.processPath(shapePaths[j], rd)); 4109 } 4110 } 4111 shapeData.shape.paths = shapeData.localShapeCollection; 4112 } 4113 } 4114 if (!this.dynamicProperties.length) { 4115 this._mdf = false;
vendor: 5,008 bytes, lines 4116-4258
4116 } 4117}; 4118 4119ShapeModifiers.registerModifier('rd', RoundCornersModifier); 4120 4121/* global extendPrototype, ShapeModifier, PropertyFactory, shapePool, ShapeModifiers */ 4122 4123function PuckerAndBloatModifier() {} 4124extendPrototype([ShapeModifier], PuckerAndBloatModifier); 4125PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) { 4126 this.getValue = this.processKeys; 4127 this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this); 4128 this._isAnimated = !!this.amount.effectsSequence.length; 4129}; 4130 4131PuckerAndBloatModifier.prototype.processPath = function (path, amount) { 4132 var percent = amount / 100; 4133 var centerPoint = [0, 0]; 4134 var pathLength = path._length; 4135 var i = 0; 4136 for (i = 0; i < pathLength; i += 1) { 4137 centerPoint[0] += path.v[i][0]; 4138 centerPoint[1] += path.v[i][1]; 4139 } 4140 centerPoint[0] /= pathLength; 4141 centerPoint[1] /= pathLength; 4142 var clonedPath = shapePool.newElement(); 4143 clonedPath.c = path.c; 4144 var vX; 4145 var vY; 4146 var oX; 4147 var oY; 4148 var iX; 4149 var iY; 4150 for (i = 0; i < pathLength; i += 1) { 4151 vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent; 4152 vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent; 4153 oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent; 4154 oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent; 4155 iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent; 4156 iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent; 4157 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i); 4158 } 4159 return clonedPath; 4160}; 4161 4162PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) { 4163 var shapePaths; 4164 var i; 4165 var len = this.shapes.length; 4166 var j; 4167 var jLen; 4168 var amount = this.amount.v; 4169 4170 if (amount !== 0) { 4171 var shapeData; 4172 var localShapeCollection; 4173 for (i = 0; i < len; i += 1) { 4174 shapeData = this.shapes[i]; 4175 localShapeCollection = shapeData.localShapeCollection; 4176 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) { 4177 localShapeCollection.releaseShapes(); 4178 shapeData.shape._mdf = true; 4179 shapePaths = shapeData.shape.paths.shapes; 4180 jLen = shapeData.shape.paths._length; 4181 for (j = 0; j < jLen; j += 1) { 4182 localShapeCollection.addShape(this.processPath(shapePaths[j], amount)); 4183 } 4184 } 4185 shapeData.shape.paths = shapeData.localShapeCollection; 4186 } 4187 } 4188 if (!this.dynamicProperties.length) { 4189 this._mdf = false; 4190 } 4191}; 4192ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier); 4193 4194/* global extendPrototype, ShapeModifier, TransformPropertyFactory, PropertyFactory, Matrix, ShapeModifiers */ 4195 4196function RepeaterModifier() {} 4197extendPrototype([ShapeModifier], RepeaterModifier); 4198 4199RepeaterModifier.prototype.initModifierProperties = function (elem, data) { 4200 this.getValue = this.processKeys; 4201 this.c = PropertyFactory.getProp(elem, data.c, 0, null, this); 4202 this.o = PropertyFactory.getProp(elem, data.o, 0, null, this); 4203 this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this); 4204 this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this); 4205 this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this); 4206 this.data = data; 4207 if (!this.dynamicProperties.length) { 4208 this.getValue(true); 4209 } 4210 this._isAnimated = !!this.dynamicProperties.length; 4211 this.pMatrix = new Matrix(); 4212 this.rMatrix = new Matrix(); 4213 this.sMatrix = new Matrix(); 4214 this.tMatrix = new Matrix(); 4215 this.matrix = new Matrix(); 4216}; 4217 4218RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) { 4219 var dir = inv ? -1 : 1; 4220 var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc); 4221 var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc); 4222 pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]); 4223 rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]); 4224 rMatrix.rotate(-transform.r.v * dir * perc); 4225 rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]); 4226 sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]); 4227 sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY); 4228 sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]); 4229}; 4230 4231RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) { 4232 this.elem = elem; 4233 this.arr = arr; 4234 this.pos = pos; 4235 this.elemsData = elemsData; 4236 this._currentCopies = 0; 4237 this._elements = []; 4238 this._groups = []; 4239 this.frameId = -1; 4240 this.initDynamicPropertyContainer(elem); 4241 this.initModifierProperties(elem, arr[pos]); 4242 while (pos > 0) { 4243 pos -= 1; 4244 // this._elements.unshift(arr.splice(pos,1)[0]); 4245 this._elements.unshift(arr[pos]); 4246 } 4247 if (this.dynamicProperties.length) { 4248 this.k = true; 4249 } else { 4250 this.getValue(true); 4251 } 4252}; 4253 4254RepeaterModifier.prototype.resetElements = function (elements) { 4255 var i; 4256 var len = elements.length; 4257 for (i = 0; i < len; i += 1) { 4258 elements[i]._processed = false;
vendor: 4,888 bytes, lines 4259-4391
4259 if (elements[i].ty === 'gr') { 4260 this.resetElements(elements[i].it); 4261 } 4262 } 4263}; 4264 4265RepeaterModifier.prototype.cloneElements = function (elements) { 4266 var newElements = JSON.parse(JSON.stringify(elements)); 4267 this.resetElements(newElements); 4268 return newElements; 4269}; 4270 4271RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) { 4272 var i; 4273 var len = elements.length; 4274 for (i = 0; i < len; i += 1) { 4275 elements[i]._render = renderFlag; 4276 if (elements[i].ty === 'gr') { 4277 this.changeGroupRender(elements[i].it, renderFlag); 4278 } 4279 } 4280}; 4281 4282RepeaterModifier.prototype.processShapes = function (_isFirstFrame) { 4283 var items; 4284 var itemsTransform; 4285 var i; 4286 var dir; 4287 var cont; 4288 if (this._mdf || _isFirstFrame) { 4289 var copies = Math.ceil(this.c.v); 4290 if (this._groups.length < copies) { 4291 while (this._groups.length < copies) { 4292 var group = { 4293 it: this.cloneElements(this._elements), 4294 ty: 'gr', 4295 }; 4296 group.it.push({ 4297 a: { a: 0, ix: 1, k: [0, 0] }, nm: 'Transform', o: { a: 0, ix: 7, k: 100 }, p: { a: 0, ix: 2, k: [0, 0] }, r: { a: 1, ix: 6, k: [{ s: 0, e: 0, t: 0 }, { s: 0, e: 0, t: 1 }] }, s: { a: 0, ix: 3, k: [100, 100] }, sa: { a: 0, ix: 5, k: 0 }, sk: { a: 0, ix: 4, k: 0 }, ty: 'tr', 4298 }); 4299 4300 this.arr.splice(0, 0, group); 4301 this._groups.splice(0, 0, group); 4302 this._currentCopies += 1; 4303 } 4304 this.elem.reloadShapes(); 4305 } 4306 cont = 0; 4307 var renderFlag; 4308 for (i = 0; i <= this._groups.length - 1; i += 1) { 4309 renderFlag = cont < copies; 4310 this._groups[i]._render = renderFlag; 4311 this.changeGroupRender(this._groups[i].it, renderFlag); 4312 cont += 1; 4313 } 4314 4315 this._currentCopies = copies; 4316 /// / 4317 4318 var offset = this.o.v; 4319 var offsetModulo = offset % 1; 4320 var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset); 4321 var pProps = this.pMatrix.props; 4322 var rProps = this.rMatrix.props; 4323 var sProps = this.sMatrix.props; 4324 this.pMatrix.reset(); 4325 this.rMatrix.reset(); 4326 this.sMatrix.reset(); 4327 this.tMatrix.reset(); 4328 this.matrix.reset(); 4329 var iteration = 0; 4330 4331 if (offset > 0) { 4332 while (iteration < roundOffset) { 4333 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false); 4334 iteration += 1; 4335 } 4336 if (offsetModulo) { 4337 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false); 4338 iteration += offsetModulo; 4339 } 4340 } else if (offset < 0) { 4341 while (iteration > roundOffset) { 4342 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true); 4343 iteration -= 1; 4344 } 4345 if (offsetModulo) { 4346 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true); 4347 iteration -= offsetModulo; 4348 } 4349 } 4350 i = this.data.m === 1 ? 0 : this._currentCopies - 1; 4351 dir = this.data.m === 1 ? 1 : -1; 4352 cont = this._currentCopies; 4353 var j; 4354 var jLen; 4355 while (cont) { 4356 items = this.elemsData[i].it; 4357 itemsTransform = items[items.length - 1].transform.mProps.v.props; 4358 jLen = itemsTransform.length; 4359 items[items.length - 1].transform.mProps._mdf = true; 4360 items[items.length - 1].transform.op._mdf = true; 4361 items[items.length - 1].transform.op.v = this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1)); 4362 if (iteration !== 0) { 4363 if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) { 4364 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false); 4365 } 4366 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]); 4367 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]); 4368 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]); 4369 4370 for (j = 0; j < jLen; j += 1) { 4371 itemsTransform[j] = this.matrix.props[j]; 4372 } 4373 this.matrix.reset(); 4374 } else { 4375 this.matrix.reset(); 4376 for (j = 0; j < jLen; j += 1) { 4377 itemsTransform[j] = this.matrix.props[j]; 4378 } 4379 } 4380 iteration += 1; 4381 cont -= 1; 4382 i += dir; 4383 } 4384 } else { 4385 cont = this._currentCopies; 4386 i = 0; 4387 dir = 1; 4388 while (cont) { 4389 items = this.elemsData[i].it; 4390 itemsTransform = items[items.length - 1].transform.mProps.v.props; 4391 items[items.length - 1].transform.mProps._mdf = false;
vendor: 20,210 bytes, lines 4392-5126
4392 items[items.length - 1].transform.op._mdf = false; 4393 cont -= 1; 4394 i += dir; 4395 } 4396 } 4397}; 4398 4399RepeaterModifier.prototype.addShape = function () {}; 4400 4401ShapeModifiers.registerModifier('rp', RepeaterModifier); 4402 4403/* global createSizedArray, shapePool */ 4404 4405function ShapeCollection() { 4406 this._length = 0; 4407 this._maxLength = 4; 4408 this.shapes = createSizedArray(this._maxLength); 4409} 4410 4411ShapeCollection.prototype.addShape = function (shapeData) { 4412 if (this._length === this._maxLength) { 4413 this.shapes = this.shapes.concat(createSizedArray(this._maxLength)); 4414 this._maxLength *= 2; 4415 } 4416 this.shapes[this._length] = shapeData; 4417 this._length += 1; 4418}; 4419 4420ShapeCollection.prototype.releaseShapes = function () { 4421 var i; 4422 for (i = 0; i < this._length; i += 1) { 4423 shapePool.release(this.shapes[i]); 4424 } 4425 this._length = 0; 4426}; 4427 4428/* global createSizedArray, createTypedArray, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 4429 4430function DashProperty(elem, data, renderer, container) { 4431 this.elem = elem; 4432 this.frameId = -1; 4433 this.dataProps = createSizedArray(data.length); 4434 this.renderer = renderer; 4435 this.k = false; 4436 this.dashStr = ''; 4437 this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0); 4438 this.dashoffset = createTypedArray('float32', 1); 4439 this.initDynamicPropertyContainer(container); 4440 var i; 4441 var len = data.length || 0; 4442 var prop; 4443 for (i = 0; i < len; i += 1) { 4444 prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this); 4445 this.k = prop.k || this.k; 4446 this.dataProps[i] = { n: data[i].n, p: prop }; 4447 } 4448 if (!this.k) { 4449 this.getValue(true); 4450 } 4451 this._isAnimated = this.k; 4452} 4453 4454DashProperty.prototype.getValue = function (forceRender) { 4455 if (this.elem.globalData.frameId === this.frameId && !forceRender) { 4456 return; 4457 } 4458 this.frameId = this.elem.globalData.frameId; 4459 this.iterateDynamicProperties(); 4460 this._mdf = this._mdf || forceRender; 4461 if (this._mdf) { 4462 var i = 0; 4463 var len = this.dataProps.length; 4464 if (this.renderer === 'svg') { 4465 this.dashStr = ''; 4466 } 4467 for (i = 0; i < len; i += 1) { 4468 if (this.dataProps[i].n !== 'o') { 4469 if (this.renderer === 'svg') { 4470 this.dashStr += ' ' + this.dataProps[i].p.v; 4471 } else { 4472 this.dashArray[i] = this.dataProps[i].p.v; 4473 } 4474 } else { 4475 this.dashoffset[0] = this.dataProps[i].p.v; 4476 } 4477 } 4478 } 4479}; 4480extendPrototype([DynamicPropertyContainer], DashProperty); 4481 4482/* global createTypedArray, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 4483function GradientProperty(elem, data, container) { 4484 this.data = data; 4485 this.c = createTypedArray('uint8c', data.p * 4); 4486 var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4; 4487 this.o = createTypedArray('float32', cLength); 4488 this._cmdf = false; 4489 this._omdf = false; 4490 this._collapsable = this.checkCollapsable(); 4491 this._hasOpacity = cLength; 4492 this.initDynamicPropertyContainer(container); 4493 this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this); 4494 this.k = this.prop.k; 4495 this.getValue(true); 4496} 4497 4498GradientProperty.prototype.comparePoints = function (values, points) { 4499 var i = 0; 4500 var len = this.o.length / 2; 4501 var diff; 4502 while (i < len) { 4503 diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]); 4504 if (diff > 0.01) { 4505 return false; 4506 } 4507 i += 1; 4508 } 4509 return true; 4510}; 4511 4512GradientProperty.prototype.checkCollapsable = function () { 4513 if (this.o.length / 2 !== this.c.length / 4) { 4514 return false; 4515 } 4516 if (this.data.k.k[0].s) { 4517 var i = 0; 4518 var len = this.data.k.k.length; 4519 while (i < len) { 4520 if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) { 4521 return false; 4522 } 4523 i += 1; 4524 } 4525 } else if (!this.comparePoints(this.data.k.k, this.data.p)) { 4526 return false; 4527 } 4528 return true; 4529}; 4530 4531GradientProperty.prototype.getValue = function (forceRender) { 4532 this.prop.getValue(); 4533 this._mdf = false; 4534 this._cmdf = false; 4535 this._omdf = false; 4536 if (this.prop._mdf || forceRender) { 4537 var i; 4538 var len = this.data.p * 4; 4539 var mult; 4540 var val; 4541 for (i = 0; i < len; i += 1) { 4542 mult = i % 4 === 0 ? 100 : 255; 4543 val = Math.round(this.prop.v[i] * mult); 4544 if (this.c[i] !== val) { 4545 this.c[i] = val; 4546 this._cmdf = !forceRender; 4547 } 4548 } 4549 if (this.o.length) { 4550 len = this.prop.v.length; 4551 for (i = this.data.p * 4; i < len; i += 1) { 4552 mult = i % 2 === 0 ? 100 : 1; 4553 val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i]; 4554 if (this.o[i - this.data.p * 4] !== val) { 4555 this.o[i - this.data.p * 4] = val; 4556 this._omdf = !forceRender; 4557 } 4558 } 4559 } 4560 this._mdf = !forceRender; 4561 } 4562}; 4563 4564extendPrototype([DynamicPropertyContainer], GradientProperty); 4565 4566/* exported buildShapeString */ 4567 4568var buildShapeString = function (pathNodes, length, closed, mat) { 4569 if (length === 0) { 4570 return ''; 4571 } 4572 var _o = pathNodes.o; 4573 var _i = pathNodes.i; 4574 var _v = pathNodes.v; 4575 var i; 4576 var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]); 4577 for (i = 1; i < length; i += 1) { 4578 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]); 4579 } 4580 if (closed && length) { 4581 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]); 4582 shapeString += 'z'; 4583 } 4584 return shapeString; 4585}; 4586 4587/* global Howl */ 4588/* exported audioControllerFactory */ 4589 4590var audioControllerFactory = (function () { 4591 function AudioController(audioFactory) { 4592 this.audios = []; 4593 this.audioFactory = audioFactory; 4594 this._volume = 1; 4595 this._isMuted = false; 4596 } 4597 4598 AudioController.prototype = { 4599 addAudio: function (audio) { 4600 this.audios.push(audio); 4601 }, 4602 pause: function () { 4603 var i; 4604 var len = this.audios.length; 4605 for (i = 0; i < len; i += 1) { 4606 this.audios[i].pause(); 4607 } 4608 }, 4609 resume: function () { 4610 var i; 4611 var len = this.audios.length; 4612 for (i = 0; i < len; i += 1) { 4613 this.audios[i].resume(); 4614 } 4615 }, 4616 setRate: function (rateValue) { 4617 var i; 4618 var len = this.audios.length; 4619 for (i = 0; i < len; i += 1) { 4620 this.audios[i].setRate(rateValue); 4621 } 4622 }, 4623 createAudio: function (assetPath) { 4624 if (this.audioFactory) { 4625 return this.audioFactory(assetPath); 4626 } if (Howl) { 4627 return new Howl({ 4628 src: [assetPath], 4629 }); 4630 } 4631 return { 4632 isPlaying: false, 4633 play: function () { this.isPlaying = true; }, 4634 seek: function () { this.isPlaying = false; }, 4635 playing: function () {}, 4636 rate: function () {}, 4637 setVolume: function () {}, 4638 }; 4639 }, 4640 setAudioFactory: function (audioFactory) { 4641 this.audioFactory = audioFactory; 4642 }, 4643 setVolume: function (value) { 4644 this._volume = value; 4645 this._updateVolume(); 4646 }, 4647 mute: function () { 4648 this._isMuted = true; 4649 this._updateVolume(); 4650 }, 4651 unmute: function () { 4652 this._isMuted = false; 4653 this._updateVolume(); 4654 }, 4655 getVolume: function () { 4656 return this._volume; 4657 }, 4658 _updateVolume: function () { 4659 var i; 4660 var len = this.audios.length; 4661 for (i = 0; i < len; i += 1) { 4662 this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1)); 4663 } 4664 }, 4665 }; 4666 4667 return function () { 4668 return new AudioController(); 4669 }; 4670}()); 4671 4672/* global createTag, createNS, isSafari */ 4673/* exported ImagePreloader */ 4674 4675var ImagePreloader = (function () { 4676 var proxyImage = (function () { 4677 var canvas = createTag('canvas'); 4678 canvas.width = 1; 4679 canvas.height = 1; 4680 var ctx = canvas.getContext('2d'); 4681 ctx.fillStyle = 'rgba(0,0,0,0)'; 4682 ctx.fillRect(0, 0, 1, 1); 4683 return canvas; 4684 }()); 4685 4686 function imageLoaded() { 4687 this.loadedAssets += 1; 4688 if (this.loadedAssets === this.totalImages) { 4689 if (this.imagesLoadedCb) { 4690 this.imagesLoadedCb(null); 4691 } 4692 } 4693 } 4694 4695 function getAssetsPath(assetData, assetsPath, originalPath) { 4696 var path = ''; 4697 if (assetData.e) { 4698 path = assetData.p; 4699 } else if (assetsPath) { 4700 var imagePath = assetData.p; 4701 if (imagePath.indexOf('images/') !== -1) { 4702 imagePath = imagePath.split('/')[1]; 4703 } 4704 path = assetsPath + imagePath; 4705 } else { 4706 path = originalPath; 4707 path += assetData.u ? assetData.u : ''; 4708 path += assetData.p; 4709 } 4710 return path; 4711 } 4712 4713 function testImageLoaded(img) { 4714 var _count = 0; 4715 var intervalId = setInterval(function () { 4716 var box = img.getBBox(); 4717 if (box.width || _count > 500) { 4718 this._imageLoaded(); 4719 clearInterval(intervalId); 4720 } 4721 _count += 1; 4722 }.bind(this), 50); 4723 } 4724 4725 function createImageData(assetData) { 4726 var path = getAssetsPath(assetData, this.assetsPath, this.path); 4727 var img = createNS('image'); 4728 if (isSafari) { 4729 this.testImageLoaded(img); 4730 } else { 4731 img.addEventListener('load', this._imageLoaded, false); 4732 } 4733 img.addEventListener('error', function () { 4734 ob.img = proxyImage; 4735 this._imageLoaded(); 4736 }.bind(this), false); 4737 img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path); 4738 this._elementHelper.append(img); 4739 var ob = { 4740 img: img, 4741 assetData: assetData, 4742 }; 4743 return ob; 4744 } 4745 4746 function createImgData(assetData) { 4747 var path = getAssetsPath(assetData, this.assetsPath, this.path); 4748 var img = createTag('img'); 4749 img.crossOrigin = 'anonymous'; 4750 img.addEventListener('load', this._imageLoaded, false); 4751 img.addEventListener('error', function () { 4752 ob.img = proxyImage; 4753 this._imageLoaded(); 4754 }.bind(this), false); 4755 img.src = path; 4756 var ob = { 4757 img: img, 4758 assetData: assetData, 4759 }; 4760 return ob; 4761 } 4762 4763 function loadAssets(assets, cb) { 4764 this.imagesLoadedCb = cb; 4765 var i; 4766 var len = assets.length; 4767 for (i = 0; i < len; i += 1) { 4768 if (!assets[i].layers) { 4769 this.totalImages += 1; 4770 this.images.push(this._createImageData(assets[i])); 4771 } 4772 } 4773 } 4774 4775 function setPath(path) { 4776 this.path = path || ''; 4777 } 4778 4779 function setAssetsPath(path) { 4780 this.assetsPath = path || ''; 4781 } 4782 4783 function getImage(assetData) { 4784 var i = 0; 4785 var len = this.images.length; 4786 while (i < len) { 4787 if (this.images[i].assetData === assetData) { 4788 return this.images[i].img; 4789 } 4790 i += 1; 4791 } 4792 return null; 4793 } 4794 4795 function destroy() { 4796 this.imagesLoadedCb = null; 4797 this.images.length = 0; 4798 } 4799 4800 function loaded() { 4801 return this.totalImages === this.loadedAssets; 4802 } 4803 4804 function setCacheType(type, elementHelper) { 4805 if (type === 'svg') { 4806 this._elementHelper = elementHelper; 4807 this._createImageData = this.createImageData.bind(this); 4808 } else { 4809 this._createImageData = this.createImgData.bind(this); 4810 } 4811 } 4812 4813 function ImagePreloaderFactory() { 4814 this._imageLoaded = imageLoaded.bind(this); 4815 this.testImageLoaded = testImageLoaded.bind(this); 4816 this.assetsPath = ''; 4817 this.path = ''; 4818 this.totalImages = 0; 4819 this.loadedAssets = 0; 4820 this.imagesLoadedCb = null; 4821 this.images = []; 4822 } 4823 4824 ImagePreloaderFactory.prototype = { 4825 loadAssets: loadAssets, 4826 setAssetsPath: setAssetsPath, 4827 setPath: setPath, 4828 loaded: loaded, 4829 destroy: destroy, 4830 getImage: getImage, 4831 createImgData: createImgData, 4832 createImageData: createImageData, 4833 imageLoaded: imageLoaded, 4834 setCacheType: setCacheType, 4835 }; 4836 4837 return ImagePreloaderFactory; 4838}()); 4839 4840/* exported featureSupport */ 4841 4842var featureSupport = (function () { 4843 var ob = { 4844 maskType: true, 4845 }; 4846 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)) { 4847 ob.maskType = false; 4848 } 4849 return ob; 4850}()); 4851 4852/* global createNS */ 4853/* exported filtersFactory */ 4854 4855var filtersFactory = (function () { 4856 var ob = {}; 4857 ob.createFilter = createFilter; 4858 ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter; 4859 4860 function createFilter(filId) { 4861 var fil = createNS('filter'); 4862 fil.setAttribute('id', filId); 4863 fil.setAttribute('filterUnits', 'objectBoundingBox'); 4864 fil.setAttribute('x', '0%'); 4865 fil.setAttribute('y', '0%'); 4866 fil.setAttribute('width', '100%'); 4867 fil.setAttribute('height', '100%'); 4868 return fil; 4869 } 4870 4871 function createAlphaToLuminanceFilter() { 4872 var feColorMatrix = createNS('feColorMatrix'); 4873 feColorMatrix.setAttribute('type', 'matrix'); 4874 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 4875 feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1'); 4876 return feColorMatrix; 4877 } 4878 4879 return ob; 4880}()); 4881 4882/* exported assetLoader */ 4883 4884var assetLoader = (function () { 4885 function formatResponse(xhr) { 4886 if (xhr.response && typeof xhr.response === 'object') { 4887 return xhr.response; 4888 } if (xhr.response && typeof xhr.response === 'string') { 4889 return JSON.parse(xhr.response); 4890 } if (xhr.responseText) { 4891 return JSON.parse(xhr.responseText); 4892 } 4893 return null; 4894 } 4895 4896 function loadAsset(path, callback, errorCallback) { 4897 var response; 4898 var xhr = new XMLHttpRequest(); 4899 xhr.open('GET', path, true); 4900 // set responseType after calling open or IE will break. 4901 try { 4902 // This crashes on Android WebView prior to KitKat 4903 xhr.responseType = 'json'; 4904 } catch (err) {} // eslint-disable-line no-empty 4905 xhr.send(); 4906 xhr.onreadystatechange = function () { 4907 if (xhr.readyState === 4) { 4908 if (xhr.status === 200) { 4909 response = formatResponse(xhr); 4910 callback(response); 4911 } else { 4912 try { 4913 response = formatResponse(xhr); 4914 callback(response); 4915 } catch (err) { 4916 if (errorCallback) { 4917 errorCallback(err); 4918 } 4919 } 4920 } 4921 } 4922 }; 4923 } 4924 return { 4925 load: loadAsset, 4926 }; 4927}()); 4928 4929/* global createSizedArray, PropertyFactory, TextAnimatorDataProperty, bez, addHueToRGB, 4930 addSaturationToRGB, addBrightnessToRGB, LetterProps, Matrix, extendPrototype, DynamicPropertyContainer */ 4931 4932function TextAnimatorProperty(textData, renderType, elem) { 4933 this._isFirstFrame = true; 4934 this._hasMaskedPath = false; 4935 this._frameId = -1; 4936 this._textData = textData; 4937 this._renderType = renderType; 4938 this._elem = elem; 4939 this._animatorsData = createSizedArray(this._textData.a.length); 4940 this._pathData = {}; 4941 this._moreOptions = { 4942 alignment: {}, 4943 }; 4944 this.renderedLetters = []; 4945 this.lettersChangedFlag = false; 4946 this.initDynamicPropertyContainer(elem); 4947} 4948 4949TextAnimatorProperty.prototype.searchProperties = function () { 4950 var i; 4951 var len = this._textData.a.length; 4952 var animatorProps; 4953 var getProp = PropertyFactory.getProp; 4954 for (i = 0; i < len; i += 1) { 4955 animatorProps = this._textData.a[i]; 4956 this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this); 4957 } 4958 if (this._textData.p && 'm' in this._textData.p) { 4959 this._pathData = { 4960 f: getProp(this._elem, this._textData.p.f, 0, 0, this), 4961 l: getProp(this._elem, this._textData.p.l, 0, 0, this), 4962 r: this._textData.p.r, 4963 m: this._elem.maskManager.getMaskProperty(this._textData.p.m), 4964 }; 4965 this._hasMaskedPath = true; 4966 } else { 4967 this._hasMaskedPath = false; 4968 } 4969 this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this); 4970}; 4971 4972TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) { 4973 this.lettersChangedFlag = lettersChangedFlag; 4974 if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) { 4975 return; 4976 } 4977 this._isFirstFrame = false; 4978 var alignment = this._moreOptions.alignment.v; 4979 var animators = this._animatorsData; 4980 var textData = this._textData; 4981 var matrixHelper = this.mHelper; 4982 var renderType = this._renderType; 4983 var renderedLettersCount = this.renderedLetters.length; 4984 var xPos; 4985 var yPos; 4986 var i; 4987 var len; 4988 var letters = documentData.l; 4989 var pathInfo; 4990 var currentLength; 4991 var currentPoint; 4992 var segmentLength; 4993 var flag; 4994 var pointInd; 4995 var segmentInd; 4996 var prevPoint; 4997 var points; 4998 var segments; 4999 var partialLength; 5000 var totalLength; 5001 var perc; 5002 var tanAngle; 5003 var mask; 5004 if (this._hasMaskedPath) { 5005 mask = this._pathData.m; 5006 if (!this._pathData.n || this._pathData._mdf) { 5007 var paths = mask.v; 5008 if (this._pathData.r) { 5009 paths = paths.reverse(); 5010 } 5011 // TODO: release bezier data cached from previous pathInfo: this._pathData.pi 5012 pathInfo = { 5013 tLength: 0, 5014 segments: [], 5015 }; 5016 len = paths._length - 1; 5017 var bezierData; 5018 totalLength = 0; 5019 for (i = 0; i < len; i += 1) { 5020 bezierData = bez.buildBezierData(paths.v[i], 5021 paths.v[i + 1], 5022 [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], 5023 [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]); 5024 pathInfo.tLength += bezierData.segmentLength; 5025 pathInfo.segments.push(bezierData); 5026 totalLength += bezierData.segmentLength; 5027 } 5028 i = len; 5029 if (mask.v.c) { 5030 bezierData = bez.buildBezierData(paths.v[i], 5031 paths.v[0], 5032 [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], 5033 [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]); 5034 pathInfo.tLength += bezierData.segmentLength; 5035 pathInfo.segments.push(bezierData); 5036 totalLength += bezierData.segmentLength; 5037 } 5038 this._pathData.pi = pathInfo; 5039 } 5040 pathInfo = this._pathData.pi; 5041 5042 currentLength = this._pathData.f.v; 5043 segmentInd = 0; 5044 pointInd = 1; 5045 segmentLength = 0; 5046 flag = true; 5047 segments = pathInfo.segments; 5048 if (currentLength < 0 && mask.v.c) { 5049 if (pathInfo.tLength < Math.abs(currentLength)) { 5050 currentLength = -Math.abs(currentLength) % pathInfo.tLength; 5051 } 5052 segmentInd = segments.length - 1; 5053 points = segments[segmentInd].points; 5054 pointInd = points.length - 1; 5055 while (currentLength < 0) { 5056 currentLength += points[pointInd].partialLength; 5057 pointInd -= 1; 5058 if (pointInd < 0) { 5059 segmentInd -= 1; 5060 points = segments[segmentInd].points; 5061 pointInd = points.length - 1; 5062 } 5063 } 5064 } 5065 points = segments[segmentInd].points; 5066 prevPoint = points[pointInd - 1]; 5067 currentPoint = points[pointInd]; 5068 partialLength = currentPoint.partialLength; 5069 } 5070 5071 len = letters.length; 5072 xPos = 0; 5073 yPos = 0; 5074 var yOff = documentData.finalSize * 1.2 * 0.714; 5075 var firstLine = true; 5076 var animatorProps; 5077 var animatorSelector; 5078 var j; 5079 var jLen; 5080 var letterValue; 5081 5082 jLen = animators.length; 5083 5084 var mult; 5085 var ind = -1; 5086 var offf; 5087 var xPathPos; 5088 var yPathPos; 5089 var initPathPos = currentLength; 5090 var initSegmentInd = segmentInd; 5091 var initPointInd = pointInd; 5092 var currentLine = -1; 5093 var elemOpacity; 5094 var sc; 5095 var sw; 5096 var fc; 5097 var k; 5098 var letterSw; 5099 var letterSc; 5100 var letterFc; 5101 var letterM = ''; 5102 var letterP = this.defaultPropsArray; 5103 var letterO; 5104 5105 // 5106 if (documentData.j === 2 || documentData.j === 1) { 5107 var animatorJustifyOffset = 0; 5108 var animatorFirstCharOffset = 0; 5109 var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1; 5110 var lastIndex = 0; 5111 var isNewLine = true; 5112 5113 for (i = 0; i < len; i += 1) { 5114 if (letters[i].n) { 5115 if (animatorJustifyOffset) { 5116 animatorJustifyOffset += animatorFirstCharOffset; 5117 } 5118 while (lastIndex < i) { 5119 letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset; 5120 lastIndex += 1; 5121 } 5122 animatorJustifyOffset = 0; 5123 isNewLine = true; 5124 } else { 5125 for (j = 0; j < jLen; j += 1) { 5126 animatorProps = animators[j].a;
vendor: 22,599 bytes, lines 5127-5751
5127 if (animatorProps.t.propType) { 5128 if (isNewLine && documentData.j === 2) { 5129 animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult; 5130 } 5131 animatorSelector = animators[j].s; 5132 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5133 if (mult.length) { 5134 animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult; 5135 } else { 5136 animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult; 5137 } 5138 } 5139 } 5140 isNewLine = false; 5141 } 5142 } 5143 if (animatorJustifyOffset) { 5144 animatorJustifyOffset += animatorFirstCharOffset; 5145 } 5146 while (lastIndex < i) { 5147 letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset; 5148 lastIndex += 1; 5149 } 5150 } 5151 // 5152 5153 for (i = 0; i < len; i += 1) { 5154 matrixHelper.reset(); 5155 elemOpacity = 1; 5156 if (letters[i].n) { 5157 xPos = 0; 5158 yPos += documentData.yOffset; 5159 yPos += firstLine ? 1 : 0; 5160 currentLength = initPathPos; 5161 firstLine = false; 5162 if (this._hasMaskedPath) { 5163 segmentInd = initSegmentInd; 5164 pointInd = initPointInd; 5165 points = segments[segmentInd].points; 5166 prevPoint = points[pointInd - 1]; 5167 currentPoint = points[pointInd]; 5168 partialLength = currentPoint.partialLength; 5169 segmentLength = 0; 5170 } 5171 letterM = ''; 5172 letterFc = ''; 5173 letterSw = ''; 5174 letterO = ''; 5175 letterP = this.defaultPropsArray; 5176 } else { 5177 if (this._hasMaskedPath) { 5178 if (currentLine !== letters[i].line) { 5179 switch (documentData.j) { 5180 case 1: 5181 currentLength += totalLength - documentData.lineWidths[letters[i].line]; 5182 break; 5183 case 2: 5184 currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2; 5185 break; 5186 default: 5187 break; 5188 } 5189 currentLine = letters[i].line; 5190 } 5191 if (ind !== letters[i].ind) { 5192 if (letters[ind]) { 5193 currentLength += letters[ind].extra; 5194 } 5195 currentLength += letters[i].an / 2; 5196 ind = letters[i].ind; 5197 } 5198 currentLength += (alignment[0] * letters[i].an) * 0.005; 5199 var animatorOffset = 0; 5200 for (j = 0; j < jLen; j += 1) { 5201 animatorProps = animators[j].a; 5202 if (animatorProps.p.propType) { 5203 animatorSelector = animators[j].s; 5204 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5205 if (mult.length) { 5206 animatorOffset += animatorProps.p.v[0] * mult[0]; 5207 } else { 5208 animatorOffset += animatorProps.p.v[0] * mult; 5209 } 5210 } 5211 if (animatorProps.a.propType) { 5212 animatorSelector = animators[j].s; 5213 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5214 if (mult.length) { 5215 animatorOffset += animatorProps.a.v[0] * mult[0]; 5216 } else { 5217 animatorOffset += animatorProps.a.v[0] * mult; 5218 } 5219 } 5220 } 5221 flag = true; 5222 while (flag) { 5223 if (segmentLength + partialLength >= currentLength + animatorOffset || !points) { 5224 perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength; 5225 xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc; 5226 yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc; 5227 matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01); 5228 flag = false; 5229 } else if (points) { 5230 segmentLength += currentPoint.partialLength; 5231 pointInd += 1; 5232 if (pointInd >= points.length) { 5233 pointInd = 0; 5234 segmentInd += 1; 5235 if (!segments[segmentInd]) { 5236 if (mask.v.c) { 5237 pointInd = 0; 5238 segmentInd = 0; 5239 points = segments[segmentInd].points; 5240 } else { 5241 segmentLength -= currentPoint.partialLength; 5242 points = null; 5243 } 5244 } else { 5245 points = segments[segmentInd].points; 5246 } 5247 } 5248 if (points) { 5249 prevPoint = currentPoint; 5250 currentPoint = points[pointInd]; 5251 partialLength = currentPoint.partialLength; 5252 } 5253 } 5254 } 5255 offf = letters[i].an / 2 - letters[i].add; 5256 matrixHelper.translate(-offf, 0, 0); 5257 } else { 5258 offf = letters[i].an / 2 - letters[i].add; 5259 matrixHelper.translate(-offf, 0, 0); 5260 5261 // Grouping alignment 5262 matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0); 5263 } 5264 5265 for (j = 0; j < jLen; j += 1) { 5266 animatorProps = animators[j].a; 5267 if (animatorProps.t.propType) { 5268 animatorSelector = animators[j].s; 5269 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5270 // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine" 5271 if (xPos !== 0 || documentData.j !== 0) { 5272 if (this._hasMaskedPath) { 5273 if (mult.length) { 5274 currentLength += animatorProps.t.v * mult[0]; 5275 } else { 5276 currentLength += animatorProps.t.v * mult; 5277 } 5278 } else if (mult.length) { 5279 xPos += animatorProps.t.v * mult[0]; 5280 } else { 5281 xPos += animatorProps.t.v * mult; 5282 } 5283 } 5284 } 5285 } 5286 if (documentData.strokeWidthAnim) { 5287 sw = documentData.sw || 0; 5288 } 5289 if (documentData.strokeColorAnim) { 5290 if (documentData.sc) { 5291 sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]]; 5292 } else { 5293 sc = [0, 0, 0]; 5294 } 5295 } 5296 if (documentData.fillColorAnim && documentData.fc) { 5297 fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]]; 5298 } 5299 for (j = 0; j < jLen; j += 1) { 5300 animatorProps = animators[j].a; 5301 if (animatorProps.a.propType) { 5302 animatorSelector = animators[j].s; 5303 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5304 5305 if (mult.length) { 5306 matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]); 5307 } else { 5308 matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult); 5309 } 5310 } 5311 } 5312 for (j = 0; j < jLen; j += 1) { 5313 animatorProps = animators[j].a; 5314 if (animatorProps.s.propType) { 5315 animatorSelector = animators[j].s; 5316 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5317 if (mult.length) { 5318 matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1); 5319 } else { 5320 matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1); 5321 } 5322 } 5323 } 5324 for (j = 0; j < jLen; j += 1) { 5325 animatorProps = animators[j].a; 5326 animatorSelector = animators[j].s; 5327 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5328 if (animatorProps.sk.propType) { 5329 if (mult.length) { 5330 matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]); 5331 } else { 5332 matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult); 5333 } 5334 } 5335 if (animatorProps.r.propType) { 5336 if (mult.length) { 5337 matrixHelper.rotateZ(-animatorProps.r.v * mult[2]); 5338 } else { 5339 matrixHelper.rotateZ(-animatorProps.r.v * mult); 5340 } 5341 } 5342 if (animatorProps.ry.propType) { 5343 if (mult.length) { 5344 matrixHelper.rotateY(animatorProps.ry.v * mult[1]); 5345 } else { 5346 matrixHelper.rotateY(animatorProps.ry.v * mult); 5347 } 5348 } 5349 if (animatorProps.rx.propType) { 5350 if (mult.length) { 5351 matrixHelper.rotateX(animatorProps.rx.v * mult[0]); 5352 } else { 5353 matrixHelper.rotateX(animatorProps.rx.v * mult); 5354 } 5355 } 5356 if (animatorProps.o.propType) { 5357 if (mult.length) { 5358 elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0]; 5359 } else { 5360 elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult; 5361 } 5362 } 5363 if (documentData.strokeWidthAnim && animatorProps.sw.propType) { 5364 if (mult.length) { 5365 sw += animatorProps.sw.v * mult[0]; 5366 } else { 5367 sw += animatorProps.sw.v * mult; 5368 } 5369 } 5370 if (documentData.strokeColorAnim && animatorProps.sc.propType) { 5371 for (k = 0; k < 3; k += 1) { 5372 if (mult.length) { 5373 sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0]; 5374 } else { 5375 sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult; 5376 } 5377 } 5378 } 5379 if (documentData.fillColorAnim && documentData.fc) { 5380 if (animatorProps.fc.propType) { 5381 for (k = 0; k < 3; k += 1) { 5382 if (mult.length) { 5383 fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0]; 5384 } else { 5385 fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult; 5386 } 5387 } 5388 } 5389 if (animatorProps.fh.propType) { 5390 if (mult.length) { 5391 fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]); 5392 } else { 5393 fc = addHueToRGB(fc, animatorProps.fh.v * mult); 5394 } 5395 } 5396 if (animatorProps.fs.propType) { 5397 if (mult.length) { 5398 fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]); 5399 } else { 5400 fc = addSaturationToRGB(fc, animatorProps.fs.v * mult); 5401 } 5402 } 5403 if (animatorProps.fb.propType) { 5404 if (mult.length) { 5405 fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]); 5406 } else { 5407 fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult); 5408 } 5409 } 5410 } 5411 } 5412 5413 for (j = 0; j < jLen; j += 1) { 5414 animatorProps = animators[j].a; 5415 5416 if (animatorProps.p.propType) { 5417 animatorSelector = animators[j].s; 5418 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5419 if (this._hasMaskedPath) { 5420 if (mult.length) { 5421 matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]); 5422 } else { 5423 matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult); 5424 } 5425 } else if (mult.length) { 5426 matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]); 5427 } else { 5428 matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult); 5429 } 5430 } 5431 } 5432 if (documentData.strokeWidthAnim) { 5433 letterSw = sw < 0 ? 0 : sw; 5434 } 5435 if (documentData.strokeColorAnim) { 5436 letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')'; 5437 } 5438 if (documentData.fillColorAnim && documentData.fc) { 5439 letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')'; 5440 } 5441 5442 if (this._hasMaskedPath) { 5443 matrixHelper.translate(0, -documentData.ls); 5444 5445 matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0); 5446 if (textData.p.p) { 5447 tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]); 5448 var rot = (Math.atan(tanAngle) * 180) / Math.PI; 5449 if (currentPoint.point[0] < prevPoint.point[0]) { 5450 rot += 180; 5451 } 5452 matrixHelper.rotate((-rot * Math.PI) / 180); 5453 } 5454 matrixHelper.translate(xPathPos, yPathPos, 0); 5455 currentLength -= (alignment[0] * letters[i].an) * 0.005; 5456 if (letters[i + 1] && ind !== letters[i + 1].ind) { 5457 currentLength += letters[i].an / 2; 5458 currentLength += (documentData.tr * 0.001) * documentData.finalSize; 5459 } 5460 } else { 5461 matrixHelper.translate(xPos, yPos, 0); 5462 5463 if (documentData.ps) { 5464 // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0); 5465 matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0); 5466 } 5467 switch (documentData.j) { 5468 case 1: 5469 matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0); 5470 break; 5471 case 2: 5472 matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0); 5473 break; 5474 default: 5475 break; 5476 } 5477 matrixHelper.translate(0, -documentData.ls); 5478 matrixHelper.translate(offf, 0, 0); 5479 matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0); 5480 xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize; 5481 } 5482 if (renderType === 'html') { 5483 letterM = matrixHelper.toCSS(); 5484 } else if (renderType === 'svg') { 5485 letterM = matrixHelper.to2dCSS(); 5486 } else { 5487 letterP = [matrixHelper.props[0], matrixHelper.props[1], matrixHelper.props[2], matrixHelper.props[3], matrixHelper.props[4], matrixHelper.props[5], matrixHelper.props[6], matrixHelper.props[7], matrixHelper.props[8], matrixHelper.props[9], matrixHelper.props[10], matrixHelper.props[11], matrixHelper.props[12], matrixHelper.props[13], matrixHelper.props[14], matrixHelper.props[15]]; 5488 } 5489 letterO = elemOpacity; 5490 } 5491 5492 if (renderedLettersCount <= i) { 5493 letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP); 5494 this.renderedLetters.push(letterValue); 5495 renderedLettersCount += 1; 5496 this.lettersChangedFlag = true; 5497 } else { 5498 letterValue = this.renderedLetters[i]; 5499 this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag; 5500 } 5501 } 5502}; 5503 5504TextAnimatorProperty.prototype.getValue = function () { 5505 if (this._elem.globalData.frameId === this._frameId) { 5506 return; 5507 } 5508 this._frameId = this._elem.globalData.frameId; 5509 this.iterateDynamicProperties(); 5510}; 5511 5512TextAnimatorProperty.prototype.mHelper = new Matrix(); 5513TextAnimatorProperty.prototype.defaultPropsArray = []; 5514extendPrototype([DynamicPropertyContainer], TextAnimatorProperty); 5515 5516/* global PropertyFactory, degToRads, TextSelectorProp */ 5517/* exported TextAnimatorDataProperty */ 5518 5519function TextAnimatorDataProperty(elem, animatorProps, container) { 5520 var defaultData = { propType: false }; 5521 var getProp = PropertyFactory.getProp; 5522 var textAnimatorAnimatables = animatorProps.a; 5523 this.a = { 5524 r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData, 5525 rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData, 5526 ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData, 5527 sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData, 5528 sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData, 5529 s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData, 5530 a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData, 5531 o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData, 5532 p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData, 5533 sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData, 5534 sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData, 5535 fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData, 5536 fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData, 5537 fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData, 5538 fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData, 5539 t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData, 5540 }; 5541 5542 this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container); 5543 this.s.t = animatorProps.s.t; 5544} 5545 5546function LetterProps(o, sw, sc, fc, m, p) { 5547 this.o = o; 5548 this.sw = sw; 5549 this.sc = sc; 5550 this.fc = fc; 5551 this.m = m; 5552 this.p = p; 5553 this._mdf = { 5554 o: true, 5555 sw: !!sw, 5556 sc: !!sc, 5557 fc: !!fc, 5558 m: true, 5559 p: true, 5560 }; 5561} 5562 5563LetterProps.prototype.update = function (o, sw, sc, fc, m, p) { 5564 this._mdf.o = false; 5565 this._mdf.sw = false; 5566 this._mdf.sc = false; 5567 this._mdf.fc = false; 5568 this._mdf.m = false; 5569 this._mdf.p = false; 5570 var updated = false; 5571 5572 if (this.o !== o) { 5573 this.o = o; 5574 this._mdf.o = true; 5575 updated = true; 5576 } 5577 if (this.sw !== sw) { 5578 this.sw = sw; 5579 this._mdf.sw = true; 5580 updated = true; 5581 } 5582 if (this.sc !== sc) { 5583 this.sc = sc; 5584 this._mdf.sc = true; 5585 updated = true; 5586 } 5587 if (this.fc !== fc) { 5588 this.fc = fc; 5589 this._mdf.fc = true; 5590 updated = true; 5591 } 5592 if (this.m !== m) { 5593 this.m = m; 5594 this._mdf.m = true; 5595 updated = true; 5596 } 5597 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])) { 5598 this.p = p; 5599 this._mdf.p = true; 5600 updated = true; 5601 } 5602 return updated; 5603}; 5604 5605/* global FontManager, initialDefaultFrame, getFontProperties */ 5606/* exported TextProperty */ 5607 5608function TextProperty(elem, data) { 5609 this._frameId = initialDefaultFrame; 5610 this.pv = ''; 5611 this.v = ''; 5612 this.kf = false; 5613 this._isFirstFrame = true; 5614 this._mdf = false; 5615 this.data = data; 5616 this.elem = elem; 5617 this.comp = this.elem.comp; 5618 this.keysIndex = 0; 5619 this.canResize = false; 5620 this.minimumFontSize = 1; 5621 this.effectsSequence = []; 5622 this.currentData = { 5623 ascent: 0, 5624 boxWidth: this.defaultBoxWidth, 5625 f: '', 5626 fStyle: '', 5627 fWeight: '', 5628 fc: '', 5629 j: '', 5630 justifyOffset: '', 5631 l: [], 5632 lh: 0, 5633 lineWidths: [], 5634 ls: '', 5635 of: '', 5636 s: '', 5637 sc: '', 5638 sw: 0, 5639 t: 0, 5640 tr: 0, 5641 sz: 0, 5642 ps: null, 5643 fillColorAnim: false, 5644 strokeColorAnim: false, 5645 strokeWidthAnim: false, 5646 yOffset: 0, 5647 finalSize: 0, 5648 finalText: [], 5649 finalLineHeight: 0, 5650 __complete: false, 5651 5652 }; 5653 this.copyData(this.currentData, this.data.d.k[0].s); 5654 5655 if (!this.searchProperty()) { 5656 this.completeTextData(this.currentData); 5657 } 5658} 5659 5660TextProperty.prototype.defaultBoxWidth = [0, 0]; 5661 5662TextProperty.prototype.copyData = function (obj, data) { 5663 for (var s in data) { 5664 if (Object.prototype.hasOwnProperty.call(data, s)) { 5665 obj[s] = data[s]; 5666 } 5667 } 5668 return obj; 5669}; 5670 5671TextProperty.prototype.setCurrentData = function (data) { 5672 if (!data.__complete) { 5673 this.completeTextData(data); 5674 } 5675 this.currentData = data; 5676 this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth; 5677 this._mdf = true; 5678}; 5679 5680TextProperty.prototype.searchProperty = function () { 5681 return this.searchKeyframes(); 5682}; 5683 5684TextProperty.prototype.searchKeyframes = function () { 5685 this.kf = this.data.d.k.length > 1; 5686 if (this.kf) { 5687 this.addEffect(this.getKeyframeValue.bind(this)); 5688 } 5689 return this.kf; 5690}; 5691 5692TextProperty.prototype.addEffect = function (effectFunction) { 5693 this.effectsSequence.push(effectFunction); 5694 this.elem.addDynamicProperty(this); 5695}; 5696 5697TextProperty.prototype.getValue = function (_finalValue) { 5698 if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) { 5699 return; 5700 } 5701 this.currentData.t = this.data.d.k[this.keysIndex].s.t; 5702 var currentValue = this.currentData; 5703 var currentIndex = this.keysIndex; 5704 if (this.lock) { 5705 this.setCurrentData(this.currentData); 5706 return; 5707 } 5708 this.lock = true; 5709 this._mdf = false; 5710 var i; var 5711 len = this.effectsSequence.length; 5712 var finalValue = _finalValue || this.data.d.k[this.keysIndex].s; 5713 for (i = 0; i < len; i += 1) { 5714 // Checking if index changed to prevent creating a new object every time the expression updates. 5715 if (currentIndex !== this.keysIndex) { 5716 finalValue = this.effectsSequence[i](finalValue, finalValue.t); 5717 } else { 5718 finalValue = this.effectsSequence[i](this.currentData, finalValue.t); 5719 } 5720 } 5721 if (currentValue !== finalValue) { 5722 this.setCurrentData(finalValue); 5723 } 5724 this.v = this.currentData; 5725 this.pv = this.v; 5726 this.lock = false; 5727 this.frameId = this.elem.globalData.frameId; 5728}; 5729 5730TextProperty.prototype.getKeyframeValue = function () { 5731 var textKeys = this.data.d.k; 5732 var frameNum = this.elem.comp.renderedFrame; 5733 var i = 0; var 5734 len = textKeys.length; 5735 while (i <= len - 1) { 5736 if (i === len - 1 || textKeys[i + 1].t > frameNum) { 5737 break; 5738 } 5739 i += 1; 5740 } 5741 if (this.keysIndex !== i) { 5742 this.keysIndex = i; 5743 } 5744 return this.data.d.k[this.keysIndex].s; 5745}; 5746 5747TextProperty.prototype.buildFinalText = function (text) { 5748 var combinedCharacters = FontManager.getCombinedCharacterCodes(); 5749 var charactersArray = []; 5750 var i = 0; var 5751 len = text.length;
vendor: 4,111 bytes, lines 5752-5866
5752 var charCode; 5753 while (i < len) { 5754 charCode = text.charCodeAt(i); 5755 if (combinedCharacters.indexOf(charCode) !== -1) { 5756 charactersArray[charactersArray.length - 1] += text.charAt(i); 5757 } else if (charCode >= 0xD800 && charCode <= 0xDBFF) { 5758 charCode = text.charCodeAt(i + 1); 5759 if (charCode >= 0xDC00 && charCode <= 0xDFFF) { 5760 charactersArray.push(text.substr(i, 2)); 5761 i += 1; 5762 } else { 5763 charactersArray.push(text.charAt(i)); 5764 } 5765 } else { 5766 charactersArray.push(text.charAt(i)); 5767 } 5768 i += 1; 5769 } 5770 return charactersArray; 5771}; 5772 5773TextProperty.prototype.completeTextData = function (documentData) { 5774 documentData.__complete = true; 5775 var fontManager = this.elem.globalData.fontManager; 5776 var data = this.data; 5777 var letters = []; 5778 var i; var 5779 len; 5780 var newLineFlag; var index = 0; var 5781 val; 5782 var anchorGrouping = data.m.g; 5783 var currentSize = 0; var currentPos = 0; var currentLine = 0; var 5784 lineWidths = []; 5785 var lineWidth = 0; 5786 var maxLineWidth = 0; 5787 var j; var 5788 jLen; 5789 var fontData = fontManager.getFontByName(documentData.f); 5790 var charData; var 5791 cLength = 0; 5792 5793 var fontProps = getFontProperties(fontData); 5794 documentData.fWeight = fontProps.weight; 5795 documentData.fStyle = fontProps.style; 5796 documentData.finalSize = documentData.s; 5797 documentData.finalText = this.buildFinalText(documentData.t); 5798 len = documentData.finalText.length; 5799 documentData.finalLineHeight = documentData.lh; 5800 var trackingOffset = (documentData.tr / 1000) * documentData.finalSize; 5801 var charCode; 5802 if (documentData.sz) { 5803 var flag = true; 5804 var boxWidth = documentData.sz[0]; 5805 var boxHeight = documentData.sz[1]; 5806 var currentHeight; var 5807 finalText; 5808 while (flag) { 5809 finalText = this.buildFinalText(documentData.t); 5810 currentHeight = 0; 5811 lineWidth = 0; 5812 len = finalText.length; 5813 trackingOffset = (documentData.tr / 1000) * documentData.finalSize; 5814 var lastSpaceIndex = -1; 5815 for (i = 0; i < len; i += 1) { 5816 charCode = finalText[i].charCodeAt(0); 5817 newLineFlag = false; 5818 if (finalText[i] === ' ') { 5819 lastSpaceIndex = i; 5820 } else if (charCode === 13 || charCode === 3) { 5821 lineWidth = 0; 5822 newLineFlag = true; 5823 currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2; 5824 } 5825 if (fontManager.chars) { 5826 charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily); 5827 cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100; 5828 } else { 5829 // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily; 5830 cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize); 5831 } 5832 if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') { 5833 if (lastSpaceIndex === -1) { 5834 len += 1; 5835 } else { 5836 i = lastSpaceIndex; 5837 } 5838 currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2; 5839 finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r'); 5840 // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i); 5841 lastSpaceIndex = -1; 5842 lineWidth = 0; 5843 } else { 5844 lineWidth += cLength; 5845 lineWidth += trackingOffset; 5846 } 5847 } 5848 currentHeight += (fontData.ascent * documentData.finalSize) / 100; 5849 if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) { 5850 documentData.finalSize -= 1; 5851 documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s; 5852 } else { 5853 documentData.finalText = finalText; 5854 len = documentData.finalText.length; 5855 flag = false; 5856 } 5857 } 5858 } 5859 lineWidth = -trackingOffset; 5860 cLength = 0; 5861 var uncollapsedSpaces = 0; 5862 var currentChar; 5863 for (i = 0; i < len; i += 1) { 5864 newLineFlag = false; 5865 currentChar = documentData.finalText[i]; 5866 charCode = currentChar.charCodeAt(0);
vendor: 5,076 bytes, lines 5867-6012
5867 if (charCode === 13 || charCode === 3) { 5868 uncollapsedSpaces = 0; 5869 lineWidths.push(lineWidth); 5870 maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth; 5871 lineWidth = -2 * trackingOffset; 5872 val = ''; 5873 newLineFlag = true; 5874 currentLine += 1; 5875 } else { 5876 val = currentChar; 5877 } 5878 if (fontManager.chars) { 5879 charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily); 5880 cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100; 5881 } else { 5882 // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize); 5883 // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily; 5884 cLength = fontManager.measureText(val, documentData.f, documentData.finalSize); 5885 } 5886 5887 // 5888 if (currentChar === ' ') { 5889 uncollapsedSpaces += cLength + trackingOffset; 5890 } else { 5891 lineWidth += cLength + trackingOffset + uncollapsedSpaces; 5892 uncollapsedSpaces = 0; 5893 } 5894 letters.push({ 5895 l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0, 5896 }); 5897 if (anchorGrouping == 2) { // eslint-disable-line eqeqeq 5898 currentSize += cLength; 5899 if (val === '' || val === ' ' || i === len - 1) { 5900 if (val === '' || val === ' ') { 5901 currentSize -= cLength; 5902 } 5903 while (currentPos <= i) { 5904 letters[currentPos].an = currentSize; 5905 letters[currentPos].ind = index; 5906 letters[currentPos].extra = cLength; 5907 currentPos += 1; 5908 } 5909 index += 1; 5910 currentSize = 0; 5911 } 5912 } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq 5913 currentSize += cLength; 5914 if (val === '' || i === len - 1) { 5915 if (val === '') { 5916 currentSize -= cLength; 5917 } 5918 while (currentPos <= i) { 5919 letters[currentPos].an = currentSize; 5920 letters[currentPos].ind = index; 5921 letters[currentPos].extra = cLength; 5922 currentPos += 1; 5923 } 5924 currentSize = 0; 5925 index += 1; 5926 } 5927 } else { 5928 letters[index].ind = index; 5929 letters[index].extra = 0; 5930 index += 1; 5931 } 5932 } 5933 documentData.l = letters; 5934 maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth; 5935 lineWidths.push(lineWidth); 5936 if (documentData.sz) { 5937 documentData.boxWidth = documentData.sz[0]; 5938 documentData.justifyOffset = 0; 5939 } else { 5940 documentData.boxWidth = maxLineWidth; 5941 switch (documentData.j) { 5942 case 1: 5943 documentData.justifyOffset = -documentData.boxWidth; 5944 break; 5945 case 2: 5946 documentData.justifyOffset = -documentData.boxWidth / 2; 5947 break; 5948 default: 5949 documentData.justifyOffset = 0; 5950 } 5951 } 5952 documentData.lineWidths = lineWidths; 5953 5954 var animators = data.a; var animatorData; var 5955 letterData; 5956 jLen = animators.length; 5957 var based; var ind; var 5958 indexes = []; 5959 for (j = 0; j < jLen; j += 1) { 5960 animatorData = animators[j]; 5961 if (animatorData.a.sc) { 5962 documentData.strokeColorAnim = true; 5963 } 5964 if (animatorData.a.sw) { 5965 documentData.strokeWidthAnim = true; 5966 } 5967 if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) { 5968 documentData.fillColorAnim = true; 5969 } 5970 ind = 0; 5971 based = animatorData.s.b; 5972 for (i = 0; i < len; i += 1) { 5973 letterData = letters[i]; 5974 letterData.anIndexes[j] = ind; 5975 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))) { // eslint-disable-line eqeqeq 5976 if (animatorData.s.rn === 1) { 5977 indexes.push(ind); 5978 } 5979 ind += 1; 5980 } 5981 } 5982 data.a[j].s.totalChars = ind; 5983 var currentInd = -1; var 5984 newInd; 5985 if (animatorData.s.rn === 1) { 5986 for (i = 0; i < len; i += 1) { 5987 letterData = letters[i]; 5988 if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq 5989 currentInd = letterData.anIndexes[j]; 5990 newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0]; 5991 } 5992 letterData.anIndexes[j] = newInd; 5993 } 5994 } 5995 } 5996 documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2; 5997 documentData.ls = documentData.ls || 0; 5998 documentData.ascent = (fontData.ascent * documentData.finalSize) / 100; 5999}; 6000 6001TextProperty.prototype.updateDocumentData = function (newData, index) { 6002 index = index === undefined ? this.keysIndex : index; 6003 var dData = this.copyData({}, this.data.d.k[index].s); 6004 dData = this.copyData(dData, newData); 6005 this.data.d.k[index].s = dData; 6006 this.recalculate(index); 6007 this.elem.addDynamicProperty(this); 6008}; 6009 6010TextProperty.prototype.recalculate = function (index) { 6011 var dData = this.data.d.k[index].s; 6012 dData.__complete = false;
vendor: 20,395 bytes, lines 6013-6728
6013 this.keysIndex = 0; 6014 this._isFirstFrame = true; 6015 this.getValue(dData); 6016}; 6017 6018TextProperty.prototype.canResizeFont = function (_canResize) { 6019 this.canResize = _canResize; 6020 this.recalculate(this.keysIndex); 6021 this.elem.addDynamicProperty(this); 6022}; 6023 6024TextProperty.prototype.setMinimumFontSize = function (_fontValue) { 6025 this.minimumFontSize = Math.floor(_fontValue) || 1; 6026 this.recalculate(this.keysIndex); 6027 this.elem.addDynamicProperty(this); 6028}; 6029 6030/* global extendPrototype, BezierFactory, PropertyFactory, DynamicPropertyContainer */ 6031/* exported TextSelectorProp */ 6032 6033var TextSelectorProp = (function () { 6034 var max = Math.max; 6035 var min = Math.min; 6036 var floor = Math.floor; 6037 6038 function TextSelectorPropFactory(elem, data) { 6039 this._currentTextLength = -1; 6040 this.k = false; 6041 this.data = data; 6042 this.elem = elem; 6043 this.comp = elem.comp; 6044 this.finalS = 0; 6045 this.finalE = 0; 6046 this.initDynamicPropertyContainer(elem); 6047 this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this); 6048 if ('e' in data) { 6049 this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this); 6050 } else { 6051 this.e = { v: 100 }; 6052 } 6053 this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this); 6054 this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this); 6055 this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this); 6056 this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this); 6057 if (!this.dynamicProperties.length) { 6058 this.getValue(); 6059 } 6060 } 6061 6062 TextSelectorPropFactory.prototype = { 6063 getMult: function (ind) { 6064 if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) { 6065 this.getValue(); 6066 } 6067 // var easer = bez.getEasingCurve(this.ne.v/100,0,1-this.xe.v/100,1); 6068 var x1 = 0; 6069 var y1 = 0; 6070 var x2 = 1; 6071 var y2 = 1; 6072 if (this.ne.v > 0) { 6073 x1 = this.ne.v / 100.0; 6074 } else { 6075 y1 = -this.ne.v / 100.0; 6076 } 6077 if (this.xe.v > 0) { 6078 x2 = 1.0 - this.xe.v / 100.0; 6079 } else { 6080 y2 = 1.0 + this.xe.v / 100.0; 6081 } 6082 var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get; 6083 6084 var mult = 0; 6085 var s = this.finalS; 6086 var e = this.finalE; 6087 var type = this.data.sh; 6088 if (type === 2) { 6089 if (e === s) { 6090 mult = ind >= e ? 1 : 0; 6091 } else { 6092 mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1)); 6093 } 6094 mult = easer(mult); 6095 } else if (type === 3) { 6096 if (e === s) { 6097 mult = ind >= e ? 0 : 1; 6098 } else { 6099 mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1)); 6100 } 6101 6102 mult = easer(mult); 6103 } else if (type === 4) { 6104 if (e === s) { 6105 mult = 0; 6106 } else { 6107 mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1)); 6108 if (mult < 0.5) { 6109 mult *= 2; 6110 } else { 6111 mult = 1 - 2 * (mult - 0.5); 6112 } 6113 } 6114 mult = easer(mult); 6115 } else if (type === 5) { 6116 if (e === s) { 6117 mult = 0; 6118 } else { 6119 var tot = e - s; 6120 /* ind += 0.5; 6121 mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */ 6122 ind = min(max(0, ind + 0.5 - s), e - s); 6123 var x = -tot / 2 + ind; 6124 var a = tot / 2; 6125 mult = Math.sqrt(1 - (x * x) / (a * a)); 6126 } 6127 mult = easer(mult); 6128 } else if (type === 6) { 6129 if (e === s) { 6130 mult = 0; 6131 } else { 6132 ind = min(max(0, ind + 0.5 - s), e - s); 6133 mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line 6134 } 6135 mult = easer(mult); 6136 } else { 6137 if (ind >= floor(s)) { 6138 if (ind - s < 0) { 6139 mult = max(0, min(min(e, 1) - (s - ind), 1)); 6140 } else { 6141 mult = max(0, min(e - ind, 1)); 6142 } 6143 } 6144 mult = easer(mult); 6145 } 6146 return mult * this.a.v; 6147 }, 6148 getValue: function (newCharsFlag) { 6149 this.iterateDynamicProperties(); 6150 this._mdf = newCharsFlag || this._mdf; 6151 this._currentTextLength = this.elem.textProperty.currentData.l.length || 0; 6152 if (newCharsFlag && this.data.r === 2) { 6153 this.e.v = this._currentTextLength; 6154 } 6155 var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars; 6156 var o = this.o.v / divisor; 6157 var s = this.s.v / divisor + o; 6158 var e = (this.e.v / divisor) + o; 6159 if (s > e) { 6160 var _s = s; 6161 s = e; 6162 e = _s; 6163 } 6164 this.finalS = s; 6165 this.finalE = e; 6166 }, 6167 }; 6168 extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory); 6169 6170 function getTextSelectorProp(elem, data, arr) { 6171 return new TextSelectorPropFactory(elem, data, arr); 6172 } 6173 6174 return { 6175 getTextSelectorProp: getTextSelectorProp, 6176 }; 6177}()); 6178 6179/* global createSizedArray, pooling */ 6180/* exported poolFactory */ 6181 6182var poolFactory = (function () { 6183 return function (initialLength, _create, _release) { 6184 var _length = 0; 6185 var _maxLength = initialLength; 6186 var pool = createSizedArray(_maxLength); 6187 6188 var ob = { 6189 newElement: newElement, 6190 release: release, 6191 }; 6192 6193 function newElement() { 6194 var element; 6195 if (_length) { 6196 _length -= 1; 6197 element = pool[_length]; 6198 } else { 6199 element = _create(); 6200 } 6201 return element; 6202 } 6203 6204 function release(element) { 6205 if (_length === _maxLength) { 6206 pool = pooling.double(pool); 6207 _maxLength *= 2; 6208 } 6209 if (_release) { 6210 _release(element); 6211 } 6212 pool[_length] = element; 6213 _length += 1; 6214 } 6215 6216 return ob; 6217 }; 6218}()); 6219 6220/* global createSizedArray */ 6221/* exported pooling */ 6222 6223var pooling = (function () { 6224 function double(arr) { 6225 return arr.concat(createSizedArray(arr.length)); 6226 } 6227 6228 return { 6229 double: double, 6230 }; 6231}()); 6232 6233/* global createTypedArray, poolFactory */ 6234/* exported pointPool */ 6235 6236var pointPool = (function () { 6237 function create() { 6238 return createTypedArray('float32', 2); 6239 } 6240 return poolFactory(8, create); 6241}()); 6242 6243/* global ShapePath, pointPool, poolFactory */ 6244/* exported shapePool */ 6245 6246var shapePool = (function () { 6247 function create() { 6248 return new ShapePath(); 6249 } 6250 6251 function release(shapePath) { 6252 var len = shapePath._length; 6253 var i; 6254 for (i = 0; i < len; i += 1) { 6255 pointPool.release(shapePath.v[i]); 6256 pointPool.release(shapePath.i[i]); 6257 pointPool.release(shapePath.o[i]); 6258 shapePath.v[i] = null; 6259 shapePath.i[i] = null; 6260 shapePath.o[i] = null; 6261 } 6262 shapePath._length = 0; 6263 shapePath.c = false; 6264 } 6265 6266 function clone(shape) { 6267 var cloned = factory.newElement(); 6268 var i; 6269 var len = shape._length === undefined ? shape.v.length : shape._length; 6270 cloned.setLength(len); 6271 cloned.c = shape.c; 6272 6273 for (i = 0; i < len; i += 1) { 6274 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); 6275 } 6276 return cloned; 6277 } 6278 6279 var factory = poolFactory(4, create, release); 6280 factory.clone = clone; 6281 6282 return factory; 6283}()); 6284 6285/* global createSizedArray, ShapeCollection, shapePool, pooling */ 6286/* exported shapeCollectionPool */ 6287 6288var shapeCollectionPool = (function () { 6289 var ob = { 6290 newShapeCollection: newShapeCollection, 6291 release: release, 6292 }; 6293 6294 var _length = 0; 6295 var _maxLength = 4; 6296 var pool = createSizedArray(_maxLength); 6297 6298 function newShapeCollection() { 6299 var shapeCollection; 6300 if (_length) { 6301 _length -= 1; 6302 shapeCollection = pool[_length]; 6303 } else { 6304 shapeCollection = new ShapeCollection(); 6305 } 6306 return shapeCollection; 6307 } 6308 6309 function release(shapeCollection) { 6310 var i; 6311 var len = shapeCollection._length; 6312 for (i = 0; i < len; i += 1) { 6313 shapePool.release(shapeCollection.shapes[i]); 6314 } 6315 shapeCollection._length = 0; 6316 6317 if (_length === _maxLength) { 6318 pool = pooling.double(pool); 6319 _maxLength *= 2; 6320 } 6321 pool[_length] = shapeCollection; 6322 _length += 1; 6323 } 6324 6325 return ob; 6326}()); 6327 6328/* global poolFactory, bezierLengthPool */ 6329/* exported segmentsLengthPool */ 6330 6331var segmentsLengthPool = (function () { 6332 function create() { 6333 return { 6334 lengths: [], 6335 totalLength: 0, 6336 }; 6337 } 6338 6339 function release(element) { 6340 var i; 6341 var len = element.lengths.length; 6342 for (i = 0; i < len; i += 1) { 6343 bezierLengthPool.release(element.lengths[i]); 6344 } 6345 element.lengths.length = 0; 6346 } 6347 6348 return poolFactory(8, create, release); 6349}()); 6350 6351/* global createTypedArray, defaultCurveSegments, poolFactory */ 6352/* exported bezierLengthPool */ 6353 6354var bezierLengthPool = (function () { 6355 function create() { 6356 return { 6357 addedLength: 0, 6358 percents: createTypedArray('float32', defaultCurveSegments), 6359 lengths: createTypedArray('float32', defaultCurveSegments), 6360 }; 6361 } 6362 return poolFactory(8, create); 6363}()); 6364 6365/* global AudioElement, FontManager */ 6366 6367function BaseRenderer() {} 6368BaseRenderer.prototype.checkLayers = function (num) { 6369 var i; 6370 var len = this.layers.length; 6371 var data; 6372 this.completeLayers = true; 6373 for (i = len - 1; i >= 0; i -= 1) { 6374 if (!this.elements[i]) { 6375 data = this.layers[i]; 6376 if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) { 6377 this.buildItem(i); 6378 } 6379 } 6380 this.completeLayers = this.elements[i] ? this.completeLayers : false; 6381 } 6382 this.checkPendingElements(); 6383}; 6384 6385BaseRenderer.prototype.createItem = function (layer) { 6386 switch (layer.ty) { 6387 case 2: 6388 return this.createImage(layer); 6389 case 0: 6390 return this.createComp(layer); 6391 case 1: 6392 return this.createSolid(layer); 6393 case 3: 6394 return this.createNull(layer); 6395 case 4: 6396 return this.createShape(layer); 6397 case 5: 6398 return this.createText(layer); 6399 case 6: 6400 return this.createAudio(layer); 6401 case 13: 6402 return this.createCamera(layer); 6403 default: 6404 return this.createNull(layer); 6405 } 6406}; 6407 6408BaseRenderer.prototype.createCamera = function () { 6409 throw new Error('You\'re using a 3d camera. Try the html renderer.'); 6410}; 6411 6412BaseRenderer.prototype.createAudio = function (data) { 6413 return new AudioElement(data, this.globalData, this); 6414}; 6415 6416BaseRenderer.prototype.buildAllItems = function () { 6417 var i; 6418 var len = this.layers.length; 6419 for (i = 0; i < len; i += 1) { 6420 this.buildItem(i); 6421 } 6422 this.checkPendingElements(); 6423}; 6424 6425BaseRenderer.prototype.includeLayers = function (newLayers) { 6426 this.completeLayers = false; 6427 var i; 6428 var len = newLayers.length; 6429 var j; 6430 var jLen = this.layers.length; 6431 for (i = 0; i < len; i += 1) { 6432 j = 0; 6433 while (j < jLen) { 6434 if (this.layers[j].id === newLayers[i].id) { 6435 this.layers[j] = newLayers[i]; 6436 break; 6437 } 6438 j += 1; 6439 } 6440 } 6441}; 6442 6443BaseRenderer.prototype.setProjectInterface = function (pInterface) { 6444 this.globalData.projectInterface = pInterface; 6445}; 6446 6447BaseRenderer.prototype.initItems = function () { 6448 if (!this.globalData.progressiveLoad) { 6449 this.buildAllItems(); 6450 } 6451}; 6452BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) { 6453 var elements = this.elements; 6454 var layers = this.layers; 6455 var i = 0; 6456 var len = layers.length; 6457 while (i < len) { 6458 if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq 6459 if (!elements[i] || elements[i] === true) { 6460 this.buildItem(i); 6461 this.addPendingElement(element); 6462 } else { 6463 hierarchy.push(elements[i]); 6464 elements[i].setAsParent(); 6465 if (layers[i].parent !== undefined) { 6466 this.buildElementParenting(element, layers[i].parent, hierarchy); 6467 } else { 6468 element.setHierarchy(hierarchy); 6469 } 6470 } 6471 } 6472 i += 1; 6473 } 6474}; 6475 6476BaseRenderer.prototype.addPendingElement = function (element) { 6477 this.pendingElements.push(element); 6478}; 6479 6480BaseRenderer.prototype.searchExtraCompositions = function (assets) { 6481 var i; 6482 var len = assets.length; 6483 for (i = 0; i < len; i += 1) { 6484 if (assets[i].xt) { 6485 var comp = this.createComp(assets[i]); 6486 comp.initExpressions(); 6487 this.globalData.projectInterface.registerComposition(comp); 6488 } 6489 } 6490}; 6491 6492BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) { 6493 this.globalData.fontManager = new FontManager(); 6494 this.globalData.fontManager.addChars(animData.chars); 6495 this.globalData.fontManager.addFonts(animData.fonts, fontsContainer); 6496 this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem); 6497 this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem); 6498 this.globalData.imageLoader = this.animationItem.imagePreloader; 6499 this.globalData.audioController = this.animationItem.audioController; 6500 this.globalData.frameId = 0; 6501 this.globalData.frameRate = animData.fr; 6502 this.globalData.nm = animData.nm; 6503 this.globalData.compSize = { 6504 w: animData.w, 6505 h: animData.h, 6506 }; 6507}; 6508 6509/* global createElementID, extendPrototype, BaseRenderer, NullElement, SVGShapeElement, SVGTextLottieElement, 6510IImageElement, SVGCompElement, ISolidElement, createNS, locationHref, createSizedArray, expressionsPlugin */ 6511 6512function SVGRenderer(animationItem, config) { 6513 this.animationItem = animationItem; 6514 this.layers = null; 6515 this.renderedFrame = -1; 6516 this.svgElement = createNS('svg'); 6517 var ariaLabel = ''; 6518 if (config && config.title) { 6519 var titleElement = createNS('title'); 6520 var titleId = createElementID(); 6521 titleElement.setAttribute('id', titleId); 6522 titleElement.textContent = config.title; 6523 this.svgElement.appendChild(titleElement); 6524 ariaLabel += titleId; 6525 } 6526 if (config && config.description) { 6527 var descElement = createNS('desc'); 6528 var descId = createElementID(); 6529 descElement.setAttribute('id', descId); 6530 descElement.textContent = config.description; 6531 this.svgElement.appendChild(descElement); 6532 ariaLabel += ' ' + descId; 6533 } 6534 if (ariaLabel) { 6535 this.svgElement.setAttribute('aria-labelledby', ariaLabel); 6536 } 6537 var defs = createNS('defs'); 6538 this.svgElement.appendChild(defs); 6539 var maskElement = createNS('g'); 6540 this.svgElement.appendChild(maskElement); 6541 this.layerElement = maskElement; 6542 this.renderConfig = { 6543 preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet', 6544 imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice', 6545 progressiveLoad: (config && config.progressiveLoad) || false, 6546 hideOnTransparent: !((config && config.hideOnTransparent === false)), 6547 viewBoxOnly: (config && config.viewBoxOnly) || false, 6548 viewBoxSize: (config && config.viewBoxSize) || false, 6549 className: (config && config.className) || '', 6550 id: (config && config.id) || '', 6551 focusable: config && config.focusable, 6552 filterSize: { 6553 width: (config && config.filterSize && config.filterSize.width) || '100%', 6554 height: (config && config.filterSize && config.filterSize.height) || '100%', 6555 x: (config && config.filterSize && config.filterSize.x) || '0%', 6556 y: (config && config.filterSize && config.filterSize.y) || '0%', 6557 }, 6558 }; 6559 6560 this.globalData = { 6561 _mdf: false, 6562 frameNum: -1, 6563 defs: defs, 6564 renderConfig: this.renderConfig, 6565 }; 6566 this.elements = []; 6567 this.pendingElements = []; 6568 this.destroyed = false; 6569 this.rendererType = 'svg'; 6570} 6571 6572extendPrototype([BaseRenderer], SVGRenderer); 6573 6574SVGRenderer.prototype.createNull = function (data) { 6575 return new NullElement(data, this.globalData, this); 6576}; 6577 6578SVGRenderer.prototype.createShape = function (data) { 6579 return new SVGShapeElement(data, this.globalData, this); 6580}; 6581 6582SVGRenderer.prototype.createText = function (data) { 6583 return new SVGTextLottieElement(data, this.globalData, this); 6584}; 6585 6586SVGRenderer.prototype.createImage = function (data) { 6587 return new IImageElement(data, this.globalData, this); 6588}; 6589 6590SVGRenderer.prototype.createComp = function (data) { 6591 return new SVGCompElement(data, this.globalData, this); 6592}; 6593 6594SVGRenderer.prototype.createSolid = function (data) { 6595 return new ISolidElement(data, this.globalData, this); 6596}; 6597 6598SVGRenderer.prototype.configAnimation = function (animData) { 6599 this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); 6600 if (this.renderConfig.viewBoxSize) { 6601 this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize); 6602 } else { 6603 this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h); 6604 } 6605 6606 if (!this.renderConfig.viewBoxOnly) { 6607 this.svgElement.setAttribute('width', animData.w); 6608 this.svgElement.setAttribute('height', animData.h); 6609 this.svgElement.style.width = '100%'; 6610 this.svgElement.style.height = '100%'; 6611 this.svgElement.style.transform = 'translate3d(0,0,0)'; 6612 } 6613 if (this.renderConfig.className) { 6614 this.svgElement.setAttribute('class', this.renderConfig.className); 6615 } 6616 if (this.renderConfig.id) { 6617 this.svgElement.setAttribute('id', this.renderConfig.id); 6618 } 6619 if (this.renderConfig.focusable !== undefined) { 6620 this.svgElement.setAttribute('focusable', this.renderConfig.focusable); 6621 } 6622 this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio); 6623 // this.layerElement.style.transform = 'translate3d(0,0,0)'; 6624 // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px"; 6625 this.animationItem.wrapper.appendChild(this.svgElement); 6626 // Mask animation 6627 var defs = this.globalData.defs; 6628 6629 this.setupGlobalData(animData, defs); 6630 this.globalData.progressiveLoad = this.renderConfig.progressiveLoad; 6631 this.data = animData; 6632 6633 var maskElement = createNS('clipPath'); 6634 var rect = createNS('rect'); 6635 rect.setAttribute('width', animData.w); 6636 rect.setAttribute('height', animData.h); 6637 rect.setAttribute('x', 0); 6638 rect.setAttribute('y', 0); 6639 var maskId = createElementID(); 6640 maskElement.setAttribute('id', maskId); 6641 maskElement.appendChild(rect); 6642 this.layerElement.setAttribute('clip-path', 'url(' + locationHref + '#' + maskId + ')'); 6643 6644 defs.appendChild(maskElement); 6645 this.layers = animData.layers; 6646 this.elements = createSizedArray(animData.layers.length); 6647}; 6648 6649SVGRenderer.prototype.destroy = function () { 6650 if (this.animationItem.wrapper) { 6651 this.animationItem.wrapper.innerText = ''; 6652 } 6653 this.layerElement = null; 6654 this.globalData.defs = null; 6655 var i; 6656 var len = this.layers ? this.layers.length : 0; 6657 for (i = 0; i < len; i += 1) { 6658 if (this.elements[i]) { 6659 this.elements[i].destroy(); 6660 } 6661 } 6662 this.elements.length = 0; 6663 this.destroyed = true; 6664 this.animationItem = null; 6665}; 6666 6667SVGRenderer.prototype.updateContainerSize = function () { 6668}; 6669 6670SVGRenderer.prototype.buildItem = function (pos) { 6671 var elements = this.elements; 6672 if (elements[pos] || this.layers[pos].ty === 99) { 6673 return; 6674 } 6675 elements[pos] = true; 6676 var element = this.createItem(this.layers[pos]); 6677 6678 elements[pos] = element; 6679 if (expressionsPlugin) { 6680 if (this.layers[pos].ty === 0) { 6681 this.globalData.projectInterface.registerComposition(element); 6682 } 6683 element.initExpressions(); 6684 } 6685 this.appendElementInPos(element, pos); 6686 if (this.layers[pos].tt) { 6687 if (!this.elements[pos - 1] || this.elements[pos - 1] === true) { 6688 this.buildItem(pos - 1); 6689 this.addPendingElement(element); 6690 } else { 6691 element.setMatte(elements[pos - 1].layerId); 6692 } 6693 } 6694}; 6695 6696SVGRenderer.prototype.checkPendingElements = function () { 6697 while (this.pendingElements.length) { 6698 var element = this.pendingElements.pop(); 6699 element.checkParenting(); 6700 if (element.data.tt) { 6701 var i = 0; 6702 var len = this.elements.length; 6703 while (i < len) { 6704 if (this.elements[i] === element) { 6705 element.setMatte(this.elements[i - 1].layerId); 6706 break; 6707 } 6708 i += 1; 6709 } 6710 } 6711 } 6712}; 6713 6714SVGRenderer.prototype.renderFrame = function (num) { 6715 if (this.renderedFrame === num || this.destroyed) { 6716 return; 6717 } 6718 if (num === null) { 6719 num = this.renderedFrame; 6720 } else { 6721 this.renderedFrame = num; 6722 } 6723 // console.log('-------'); 6724 // console.log('FRAME ',num); 6725 this.globalData.frameNum = num; 6726 this.globalData.frameId += 1; 6727 this.globalData.projectInterface.currentFrame = num; 6728 this.globalData._mdf = false;
vendor: 4,812 bytes, lines 6729-6866
6729 var i; 6730 var len = this.layers.length; 6731 if (!this.completeLayers) { 6732 this.checkLayers(num); 6733 } 6734 for (i = len - 1; i >= 0; i -= 1) { 6735 if (this.completeLayers || this.elements[i]) { 6736 this.elements[i].prepareFrame(num - this.layers[i].st); 6737 } 6738 } 6739 if (this.globalData._mdf) { 6740 for (i = 0; i < len; i += 1) { 6741 if (this.completeLayers || this.elements[i]) { 6742 this.elements[i].renderFrame(); 6743 } 6744 } 6745 } 6746}; 6747 6748SVGRenderer.prototype.appendElementInPos = function (element, pos) { 6749 var newElement = element.getBaseElement(); 6750 if (!newElement) { 6751 return; 6752 } 6753 var i = 0; 6754 var nextElement; 6755 while (i < pos) { 6756 if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) { 6757 nextElement = this.elements[i].getBaseElement(); 6758 } 6759 i += 1; 6760 } 6761 if (nextElement) { 6762 this.layerElement.insertBefore(newElement, nextElement); 6763 } else { 6764 this.layerElement.appendChild(newElement); 6765 } 6766}; 6767 6768SVGRenderer.prototype.hide = function () { 6769 this.layerElement.style.display = 'none'; 6770}; 6771 6772SVGRenderer.prototype.show = function () { 6773 this.layerElement.style.display = 'block'; 6774}; 6775 6776/* global CVContextData, Matrix, extendPrototype, BaseRenderer, CVShapeElement, CVTextElement, 6777CVImageElement, CVCompElement, CVSolidElement, SVGRenderer, createTag, createSizedArray */ 6778 6779function CanvasRenderer(animationItem, config) { 6780 this.animationItem = animationItem; 6781 this.renderConfig = { 6782 clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true, 6783 context: (config && config.context) || null, 6784 progressiveLoad: (config && config.progressiveLoad) || false, 6785 preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet', 6786 imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice', 6787 className: (config && config.className) || '', 6788 id: (config && config.id) || '', 6789 }; 6790 this.renderConfig.dpr = (config && config.dpr) || 1; 6791 if (this.animationItem.wrapper) { 6792 this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1; 6793 } 6794 this.renderedFrame = -1; 6795 this.globalData = { 6796 frameNum: -1, 6797 _mdf: false, 6798 renderConfig: this.renderConfig, 6799 currentGlobalAlpha: -1, 6800 }; 6801 this.contextData = new CVContextData(); 6802 this.elements = []; 6803 this.pendingElements = []; 6804 this.transformMat = new Matrix(); 6805 this.completeLayers = false; 6806 this.rendererType = 'canvas'; 6807} 6808extendPrototype([BaseRenderer], CanvasRenderer); 6809 6810CanvasRenderer.prototype.createShape = function (data) { 6811 return new CVShapeElement(data, this.globalData, this); 6812}; 6813 6814CanvasRenderer.prototype.createText = function (data) { 6815 return new CVTextElement(data, this.globalData, this); 6816}; 6817 6818CanvasRenderer.prototype.createImage = function (data) { 6819 return new CVImageElement(data, this.globalData, this); 6820}; 6821 6822CanvasRenderer.prototype.createComp = function (data) { 6823 return new CVCompElement(data, this.globalData, this); 6824}; 6825 6826CanvasRenderer.prototype.createSolid = function (data) { 6827 return new CVSolidElement(data, this.globalData, this); 6828}; 6829 6830CanvasRenderer.prototype.createNull = SVGRenderer.prototype.createNull; 6831 6832CanvasRenderer.prototype.ctxTransform = function (props) { 6833 if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) { 6834 return; 6835 } 6836 if (!this.renderConfig.clearCanvas) { 6837 this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]); 6838 return; 6839 } 6840 this.transformMat.cloneFromProps(props); 6841 var cProps = this.contextData.cTr.props; 6842 this.transformMat.transform(cProps[0], cProps[1], cProps[2], cProps[3], cProps[4], cProps[5], cProps[6], cProps[7], cProps[8], cProps[9], cProps[10], cProps[11], cProps[12], cProps[13], cProps[14], cProps[15]); 6843 // this.contextData.cTr.transform(props[0],props[1],props[2],props[3],props[4],props[5],props[6],props[7],props[8],props[9],props[10],props[11],props[12],props[13],props[14],props[15]); 6844 this.contextData.cTr.cloneFromProps(this.transformMat.props); 6845 var trProps = this.contextData.cTr.props; 6846 this.canvasContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]); 6847}; 6848 6849CanvasRenderer.prototype.ctxOpacity = function (op) { 6850 /* if(op === 1){ 6851 return; 6852 } */ 6853 if (!this.renderConfig.clearCanvas) { 6854 this.canvasContext.globalAlpha *= op < 0 ? 0 : op; 6855 this.globalData.currentGlobalAlpha = this.contextData.cO; 6856 return; 6857 } 6858 this.contextData.cO *= op < 0 ? 0 : op; 6859 if (this.globalData.currentGlobalAlpha !== this.contextData.cO) { 6860 this.canvasContext.globalAlpha = this.contextData.cO; 6861 this.globalData.currentGlobalAlpha = this.contextData.cO; 6862 } 6863}; 6864 6865CanvasRenderer.prototype.reset = function () { 6866 if (!this.renderConfig.clearCanvas) {
6867 this.canvasContext.restore(); 6868 return; 6869 } 6870 this.contextData.reset(); 6871}; 6872 6873CanvasRenderer.prototype.save = function (actionFlag) { 6874 if (!this.renderConfig.clearCanvas) { 6875 this.canvasContext.save(); 6876 return; 6877 } 6878 if (actionFlag) { 6879 this.canvasContext.save(); 6880 } 6881 var props = this.contextData.cTr.props; 6882 if (this.contextData._length <= this.contextData.cArrPos) { 6883 this.contextData.duplicate(); 6884 } 6885 var i; 6886 var arr = this.contextData.saved[this.contextData.cArrPos]; 6887 for (i = 0; i < 16; i += 1) { 6888 arr[i] = props[i]; 6889 } 6890 this.contextData.savedOp[this.contextData.cArrPos] = this.contextData.cO; 6891 this.contextData.cArrPos += 1; 6892}; 6893 6894CanvasRenderer.prototype.restore = function (actionFlag) { 6895 if (!this.renderConfig.clearCanvas) { 6896 this.canvasContext.restore(); 6897 return; 6898 } 6899 if (actionFlag) { 6900 this.canvasContext.restore(); 6901 this.globalData.blendMode = 'source-over'; 6902 } 6903 this.contextData.cArrPos -= 1; 6904 var popped = this.contextData.saved[this.contextData.cArrPos]; 6905 var i; 6906 var arr = this.contextData.cTr.props; 6907 for (i = 0; i < 16; i += 1) { 6908 arr[i] = popped[i]; 6909 } 6910 this.canvasContext.setTransform(popped[0], popped[1], popped[4], popped[5], popped[12], popped[13]); 6911 popped = this.contextData.savedOp[this.contextData.cArrPos]; 6912 this.contextData.cO = popped; 6913 if (this.globalData.currentGlobalAlpha !== popped) { 6914 this.canvasContext.globalAlpha = popped; 6915 this.globalData.currentGlobalAlpha = popped; 6916 } 6917}; 6918 6919CanvasRenderer.prototype.configAnimation = function (animData) { 6920 if (this.animationItem.wrapper) { 6921 this.animationItem.container = createTag('canvas'); 6922 var containerStyle = this.animationItem.container.style; 6923 containerStyle.width = '100%'; 6924 containerStyle.height = '100%'; 6925 var origin = '0px 0px 0px'; 6926 containerStyle.transformOrigin = origin; 6927 containerStyle.mozTransformOrigin = origin; 6928 containerStyle.webkitTransformOrigin = origin; 6929 containerStyle['-webkit-transform'] = origin; 6930 this.animationItem.wrapper.appendChild(this.animationItem.container); 6931 this.canvasContext = this.animationItem.container.getContext('2d'); 6932 if (this.renderConfig.className) { 6933 this.animationItem.container.setAttribute('class', this.renderConfig.className); 6934 } 6935 if (this.renderConfig.id) { 6936 this.animationItem.container.setAttribute('id', this.renderConfig.id); 6937 } 6938 } else { 6939 this.canvasContext = this.renderConfig.context; 6940 } 6941 this.data = animData; 6942 this.layers = animData.layers; 6943 this.transformCanvas = { 6944 w: animData.w, 6945 h: animData.h, 6946 sx: 0, 6947 sy: 0, 6948 tx: 0, 6949 ty: 0, 6950 }; 6951 this.setupGlobalData(animData, document.body); 6952 this.globalData.canvasContext = this.canvasContext; 6953 this.globalData.renderer = this; 6954 this.globalData.isDashed = false; 6955 this.globalData.progressiveLoad = this.renderConfig.progressiveLoad; 6956 this.globalData.transformCanvas = this.transformCanvas; 6957 this.elements = createSizedArray(animData.layers.length); 6958 6959 this.updateContainerSize(); 6960}; 6961 6962CanvasRenderer.prototype.updateContainerSize = function () { 6963 this.reset(); 6964 var elementWidth; 6965 var elementHeight; 6966 if (this.animationItem.wrapper && this.animationItem.container) { 6967 elementWidth = this.animationItem.wrapper.offsetWidth; 6968 elementHeight = this.animationItem.wrapper.offsetHeight; 6969 this.animationItem.container.setAttribute('width', elementWidth * this.renderConfig.dpr); 6970 this.animationItem.container.setAttribute('height', elementHeight * this.renderConfig.dpr); 6971 } else { 6972 elementWidth = this.canvasContext.canvas.width * this.renderConfig.dpr; 6973 elementHeight = this.canvasContext.canvas.height * this.renderConfig.dpr; 6974 } 6975 var elementRel; 6976 var animationRel; 6977 if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) { 6978 var par = this.renderConfig.preserveAspectRatio.split(' '); 6979 var fillType = par[1] || 'meet'; 6980 var pos = par[0] || 'xMidYMid'; 6981 var xPos = pos.substr(0, 4); 6982 var yPos = pos.substr(4); 6983 elementRel = elementWidth / elementHeight; 6984 animationRel = this.transformCanvas.w / this.transformCanvas.h; 6985 if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) { 6986 this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr); 6987 this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr); 6988 } else { 6989 this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr); 6990 this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr); 6991 } 6992 6993 if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) { 6994 this.transformCanvas.tx = ((elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2) * this.renderConfig.dpr; 6995 } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) { 6996 this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr; 6997 } else { 6998 this.transformCanvas.tx = 0; 6999 } 7000 if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
vendor: 9,499 bytes, lines 7001-7285
7001 this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2) * this.renderConfig.dpr; 7002 } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) { 7003 this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w))) * this.renderConfig.dpr; 7004 } else { 7005 this.transformCanvas.ty = 0; 7006 } 7007 } else if (this.renderConfig.preserveAspectRatio === 'none') { 7008 this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr); 7009 this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr); 7010 this.transformCanvas.tx = 0; 7011 this.transformCanvas.ty = 0; 7012 } else { 7013 this.transformCanvas.sx = this.renderConfig.dpr; 7014 this.transformCanvas.sy = this.renderConfig.dpr; 7015 this.transformCanvas.tx = 0; 7016 this.transformCanvas.ty = 0; 7017 } 7018 this.transformCanvas.props = [this.transformCanvas.sx, 0, 0, 0, 0, this.transformCanvas.sy, 0, 0, 0, 0, 1, 0, this.transformCanvas.tx, this.transformCanvas.ty, 0, 1]; 7019 /* var i, len = this.elements.length; 7020 for(i=0;i<len;i+=1){ 7021 if(this.elements[i] && this.elements[i].data.ty === 0){ 7022 this.elements[i].resize(this.globalData.transformCanvas); 7023 } 7024 } */ 7025 this.ctxTransform(this.transformCanvas.props); 7026 this.canvasContext.beginPath(); 7027 this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h); 7028 this.canvasContext.closePath(); 7029 this.canvasContext.clip(); 7030 7031 this.renderFrame(this.renderedFrame, true); 7032}; 7033 7034CanvasRenderer.prototype.destroy = function () { 7035 if (this.renderConfig.clearCanvas && this.animationItem.wrapper) { 7036 this.animationItem.wrapper.innerText = ''; 7037 } 7038 var i; 7039 var len = this.layers ? this.layers.length : 0; 7040 for (i = len - 1; i >= 0; i -= 1) { 7041 if (this.elements[i]) { 7042 this.elements[i].destroy(); 7043 } 7044 } 7045 this.elements.length = 0; 7046 this.globalData.canvasContext = null; 7047 this.animationItem.container = null; 7048 this.destroyed = true; 7049}; 7050 7051CanvasRenderer.prototype.renderFrame = function (num, forceRender) { 7052 if ((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1) { 7053 return; 7054 } 7055 this.renderedFrame = num; 7056 this.globalData.frameNum = num - this.animationItem._isFirstFrame; 7057 this.globalData.frameId += 1; 7058 this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender; 7059 this.globalData.projectInterface.currentFrame = num; 7060 7061 // console.log('--------'); 7062 // console.log('NEW: ',num); 7063 var i; 7064 var len = this.layers.length; 7065 if (!this.completeLayers) { 7066 this.checkLayers(num); 7067 } 7068 7069 for (i = 0; i < len; i += 1) { 7070 if (this.completeLayers || this.elements[i]) { 7071 this.elements[i].prepareFrame(num - this.layers[i].st); 7072 } 7073 } 7074 if (this.globalData._mdf) { 7075 if (this.renderConfig.clearCanvas === true) { 7076 this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h); 7077 } else { 7078 this.save(); 7079 } 7080 for (i = len - 1; i >= 0; i -= 1) { 7081 if (this.completeLayers || this.elements[i]) { 7082 this.elements[i].renderFrame(); 7083 } 7084 } 7085 if (this.renderConfig.clearCanvas !== true) { 7086 this.restore(); 7087 } 7088 } 7089}; 7090 7091CanvasRenderer.prototype.buildItem = function (pos) { 7092 var elements = this.elements; 7093 if (elements[pos] || this.layers[pos].ty === 99) { 7094 return; 7095 } 7096 var element = this.createItem(this.layers[pos], this, this.globalData); 7097 elements[pos] = element; 7098 element.initExpressions(); 7099 /* if(this.layers[pos].ty === 0){ 7100 element.resize(this.globalData.transformCanvas); 7101 } */ 7102}; 7103 7104CanvasRenderer.prototype.checkPendingElements = function () { 7105 while (this.pendingElements.length) { 7106 var element = this.pendingElements.pop(); 7107 element.checkParenting(); 7108 } 7109}; 7110 7111CanvasRenderer.prototype.hide = function () { 7112 this.animationItem.container.style.display = 'none'; 7113}; 7114 7115CanvasRenderer.prototype.show = function () { 7116 this.animationItem.container.style.display = 'block'; 7117}; 7118 7119/* global extendPrototype, BaseRenderer, SVGRenderer, SVGShapeElement, HShapeElement, SVGTextLottieElement, 7120HTextElement, HCameraElement, IImageElement, HImageElement, SVGCompElement, HCompElement, ISolidElement, 7121HSolidElement, styleDiv, createTag, createNS */ 7122 7123function HybridRenderer(animationItem, config) { 7124 this.animationItem = animationItem; 7125 this.layers = null; 7126 this.renderedFrame = -1; 7127 this.renderConfig = { 7128 className: (config && config.className) || '', 7129 imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice', 7130 hideOnTransparent: !(config && config.hideOnTransparent === false), 7131 filterSize: { 7132 width: (config && config.filterSize && config.filterSize.width) || '400%', 7133 height: (config && config.filterSize && config.filterSize.height) || '400%', 7134 x: (config && config.filterSize && config.filterSize.x) || '-100%', 7135 y: (config && config.filterSize && config.filterSize.y) || '-100%', 7136 }, 7137 }; 7138 this.globalData = { 7139 _mdf: false, 7140 frameNum: -1, 7141 renderConfig: this.renderConfig, 7142 }; 7143 this.pendingElements = []; 7144 this.elements = []; 7145 this.threeDElements = []; 7146 this.destroyed = false; 7147 this.camera = null; 7148 this.supports3d = true; 7149 this.rendererType = 'html'; 7150} 7151 7152extendPrototype([BaseRenderer], HybridRenderer); 7153 7154HybridRenderer.prototype.buildItem = SVGRenderer.prototype.buildItem; 7155 7156HybridRenderer.prototype.checkPendingElements = function () { 7157 while (this.pendingElements.length) { 7158 var element = this.pendingElements.pop(); 7159 element.checkParenting(); 7160 } 7161}; 7162 7163HybridRenderer.prototype.appendElementInPos = function (element, pos) { 7164 var newDOMElement = element.getBaseElement(); 7165 if (!newDOMElement) { 7166 return; 7167 } 7168 var layer = this.layers[pos]; 7169 if (!layer.ddd || !this.supports3d) { 7170 if (this.threeDElements) { 7171 this.addTo3dContainer(newDOMElement, pos); 7172 } else { 7173 var i = 0; 7174 var nextDOMElement; 7175 var nextLayer; 7176 var tmpDOMElement; 7177 while (i < pos) { 7178 if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) { 7179 nextLayer = this.elements[i]; 7180 tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement(); 7181 nextDOMElement = tmpDOMElement || nextDOMElement; 7182 } 7183 i += 1; 7184 } 7185 if (nextDOMElement) { 7186 if (!layer.ddd || !this.supports3d) { 7187 this.layerElement.insertBefore(newDOMElement, nextDOMElement); 7188 } 7189 } else if (!layer.ddd || !this.supports3d) { 7190 this.layerElement.appendChild(newDOMElement); 7191 } 7192 } 7193 } else { 7194 this.addTo3dContainer(newDOMElement, pos); 7195 } 7196}; 7197 7198HybridRenderer.prototype.createShape = function (data) { 7199 if (!this.supports3d) { 7200 return new SVGShapeElement(data, this.globalData, this); 7201 } 7202 return new HShapeElement(data, this.globalData, this); 7203}; 7204 7205HybridRenderer.prototype.createText = function (data) { 7206 if (!this.supports3d) { 7207 return new SVGTextLottieElement(data, this.globalData, this); 7208 } 7209 return new HTextElement(data, this.globalData, this); 7210}; 7211 7212HybridRenderer.prototype.createCamera = function (data) { 7213 this.camera = new HCameraElement(data, this.globalData, this); 7214 return this.camera; 7215}; 7216 7217HybridRenderer.prototype.createImage = function (data) { 7218 if (!this.supports3d) { 7219 return new IImageElement(data, this.globalData, this); 7220 } 7221 return new HImageElement(data, this.globalData, this); 7222}; 7223 7224HybridRenderer.prototype.createComp = function (data) { 7225 if (!this.supports3d) { 7226 return new SVGCompElement(data, this.globalData, this); 7227 } 7228 return new HCompElement(data, this.globalData, this); 7229}; 7230 7231HybridRenderer.prototype.createSolid = function (data) { 7232 if (!this.supports3d) { 7233 return new ISolidElement(data, this.globalData, this); 7234 } 7235 return new HSolidElement(data, this.globalData, this); 7236}; 7237 7238HybridRenderer.prototype.createNull = SVGRenderer.prototype.createNull; 7239 7240HybridRenderer.prototype.getThreeDContainerByPos = function (pos) { 7241 var i = 0; 7242 var len = this.threeDElements.length; 7243 while (i < len) { 7244 if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) { 7245 return this.threeDElements[i].perspectiveElem; 7246 } 7247 i += 1; 7248 } 7249 return null; 7250}; 7251 7252HybridRenderer.prototype.createThreeDContainer = function (pos, type) { 7253 var perspectiveElem = createTag('div'); 7254 var style; 7255 var containerStyle; 7256 styleDiv(perspectiveElem); 7257 var container = createTag('div'); 7258 styleDiv(container); 7259 if (type === '3d') { 7260 style = perspectiveElem.style; 7261 style.width = this.globalData.compSize.w + 'px'; 7262 style.height = this.globalData.compSize.h + 'px'; 7263 var center = '50% 50%'; 7264 style.webkitTransformOrigin = center; 7265 style.mozTransformOrigin = center; 7266 style.transformOrigin = center; 7267 containerStyle = container.style; 7268 var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)'; 7269 containerStyle.transform = matrix; 7270 containerStyle.webkitTransform = matrix; 7271 } 7272 7273 perspectiveElem.appendChild(container); 7274 // this.resizerElem.appendChild(perspectiveElem); 7275 var threeDContainerData = { 7276 container: container, 7277 perspectiveElem: perspectiveElem, 7278 startPos: pos, 7279 endPos: pos, 7280 type: type, 7281 }; 7282 this.threeDElements.push(threeDContainerData); 7283 return threeDContainerData; 7284}; 7285
vendor: 35,693 bytes, lines 7286-8413
7286HybridRenderer.prototype.build3dContainers = function () { 7287 var i; 7288 var len = this.layers.length; 7289 var lastThreeDContainerData; 7290 var currentContainer = ''; 7291 for (i = 0; i < len; i += 1) { 7292 if (this.layers[i].ddd && this.layers[i].ty !== 3) { 7293 if (currentContainer !== '3d') { 7294 currentContainer = '3d'; 7295 lastThreeDContainerData = this.createThreeDContainer(i, '3d'); 7296 } 7297 lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i); 7298 } else { 7299 if (currentContainer !== '2d') { 7300 currentContainer = '2d'; 7301 lastThreeDContainerData = this.createThreeDContainer(i, '2d'); 7302 } 7303 lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i); 7304 } 7305 } 7306 len = this.threeDElements.length; 7307 for (i = len - 1; i >= 0; i -= 1) { 7308 this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem); 7309 } 7310}; 7311 7312HybridRenderer.prototype.addTo3dContainer = function (elem, pos) { 7313 var i = 0; 7314 var len = this.threeDElements.length; 7315 while (i < len) { 7316 if (pos <= this.threeDElements[i].endPos) { 7317 var j = this.threeDElements[i].startPos; 7318 var nextElement; 7319 while (j < pos) { 7320 if (this.elements[j] && this.elements[j].getBaseElement) { 7321 nextElement = this.elements[j].getBaseElement(); 7322 } 7323 j += 1; 7324 } 7325 if (nextElement) { 7326 this.threeDElements[i].container.insertBefore(elem, nextElement); 7327 } else { 7328 this.threeDElements[i].container.appendChild(elem); 7329 } 7330 break; 7331 } 7332 i += 1; 7333 } 7334}; 7335 7336HybridRenderer.prototype.configAnimation = function (animData) { 7337 var resizerElem = createTag('div'); 7338 var wrapper = this.animationItem.wrapper; 7339 var style = resizerElem.style; 7340 style.width = animData.w + 'px'; 7341 style.height = animData.h + 'px'; 7342 this.resizerElem = resizerElem; 7343 styleDiv(resizerElem); 7344 style.transformStyle = 'flat'; 7345 style.mozTransformStyle = 'flat'; 7346 style.webkitTransformStyle = 'flat'; 7347 if (this.renderConfig.className) { 7348 resizerElem.setAttribute('class', this.renderConfig.className); 7349 } 7350 wrapper.appendChild(resizerElem); 7351 7352 style.overflow = 'hidden'; 7353 var svg = createNS('svg'); 7354 svg.setAttribute('width', '1'); 7355 svg.setAttribute('height', '1'); 7356 styleDiv(svg); 7357 this.resizerElem.appendChild(svg); 7358 var defs = createNS('defs'); 7359 svg.appendChild(defs); 7360 this.data = animData; 7361 // Mask animation 7362 this.setupGlobalData(animData, svg); 7363 this.globalData.defs = defs; 7364 this.layers = animData.layers; 7365 this.layerElement = this.resizerElem; 7366 this.build3dContainers(); 7367 this.updateContainerSize(); 7368}; 7369 7370HybridRenderer.prototype.destroy = function () { 7371 if (this.animationItem.wrapper) { 7372 this.animationItem.wrapper.innerText = ''; 7373 } 7374 this.animationItem.container = null; 7375 this.globalData.defs = null; 7376 var i; 7377 var len = this.layers ? this.layers.length : 0; 7378 for (i = 0; i < len; i += 1) { 7379 this.elements[i].destroy(); 7380 } 7381 this.elements.length = 0; 7382 this.destroyed = true; 7383 this.animationItem = null; 7384}; 7385 7386HybridRenderer.prototype.updateContainerSize = function () { 7387 var elementWidth = this.animationItem.wrapper.offsetWidth; 7388 var elementHeight = this.animationItem.wrapper.offsetHeight; 7389 var elementRel = elementWidth / elementHeight; 7390 var animationRel = this.globalData.compSize.w / this.globalData.compSize.h; 7391 var sx; 7392 var sy; 7393 var tx; 7394 var ty; 7395 if (animationRel > elementRel) { 7396 sx = elementWidth / (this.globalData.compSize.w); 7397 sy = elementWidth / (this.globalData.compSize.w); 7398 tx = 0; 7399 ty = ((elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2); 7400 } else { 7401 sx = elementHeight / (this.globalData.compSize.h); 7402 sy = elementHeight / (this.globalData.compSize.h); 7403 tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2; 7404 ty = 0; 7405 } 7406 var style = this.resizerElem.style; 7407 style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)'; 7408 style.transform = style.webkitTransform; 7409}; 7410 7411HybridRenderer.prototype.renderFrame = SVGRenderer.prototype.renderFrame; 7412 7413HybridRenderer.prototype.hide = function () { 7414 this.resizerElem.style.display = 'none'; 7415}; 7416 7417HybridRenderer.prototype.show = function () { 7418 this.resizerElem.style.display = 'block'; 7419}; 7420 7421HybridRenderer.prototype.initItems = function () { 7422 this.buildAllItems(); 7423 if (this.camera) { 7424 this.camera.setup(); 7425 } else { 7426 var cWidth = this.globalData.compSize.w; 7427 var cHeight = this.globalData.compSize.h; 7428 var i; 7429 var len = this.threeDElements.length; 7430 for (i = 0; i < len; i += 1) { 7431 var style = this.threeDElements[i].perspectiveElem.style; 7432 style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px'; 7433 style.perspective = style.webkitPerspective; 7434 } 7435 } 7436}; 7437 7438HybridRenderer.prototype.searchExtraCompositions = function (assets) { 7439 var i; 7440 var len = assets.length; 7441 var floatingContainer = createTag('div'); 7442 for (i = 0; i < len; i += 1) { 7443 if (assets[i].xt) { 7444 var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null); 7445 comp.initExpressions(); 7446 this.globalData.projectInterface.registerComposition(comp); 7447 } 7448 } 7449}; 7450 7451/* global createSizedArray, createElementID, PropertyFactory, ShapePropertyFactory, createNS, locationHref */ 7452 7453function MaskElement(data, element, globalData) { 7454 this.data = data; 7455 this.element = element; 7456 this.globalData = globalData; 7457 this.storedData = []; 7458 this.masksProperties = this.data.masksProperties || []; 7459 this.maskElement = null; 7460 var defs = this.globalData.defs; 7461 var i; 7462 var len = this.masksProperties ? this.masksProperties.length : 0; 7463 this.viewData = createSizedArray(len); 7464 this.solidPath = ''; 7465 7466 var path; 7467 var properties = this.masksProperties; 7468 var count = 0; 7469 var currentMasks = []; 7470 var j; 7471 var jLen; 7472 var layerId = createElementID(); 7473 var rect; 7474 var expansor; 7475 var feMorph; 7476 var x; 7477 var maskType = 'clipPath'; 7478 var maskRef = 'clip-path'; 7479 for (i = 0; i < len; i += 1) { 7480 if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) { 7481 maskType = 'mask'; 7482 maskRef = 'mask'; 7483 } 7484 7485 if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) { 7486 rect = createNS('rect'); 7487 rect.setAttribute('fill', '#ffffff'); 7488 rect.setAttribute('width', this.element.comp.data.w || 0); 7489 rect.setAttribute('height', this.element.comp.data.h || 0); 7490 currentMasks.push(rect); 7491 } else { 7492 rect = null; 7493 } 7494 7495 path = createNS('path'); 7496 if (properties[i].mode === 'n') { 7497 // TODO move this to a factory or to a constructor 7498 this.viewData[i] = { 7499 op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element), 7500 prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3), 7501 elem: path, 7502 lastPath: '', 7503 }; 7504 defs.appendChild(path); 7505 } else { 7506 count += 1; 7507 7508 path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff'); 7509 path.setAttribute('clip-rule', 'nonzero'); 7510 var filterID; 7511 7512 if (properties[i].x.k !== 0) { 7513 maskType = 'mask'; 7514 maskRef = 'mask'; 7515 x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element); 7516 filterID = createElementID(); 7517 expansor = createNS('filter'); 7518 expansor.setAttribute('id', filterID); 7519 feMorph = createNS('feMorphology'); 7520 feMorph.setAttribute('operator', 'erode'); 7521 feMorph.setAttribute('in', 'SourceGraphic'); 7522 feMorph.setAttribute('radius', '0'); 7523 expansor.appendChild(feMorph); 7524 defs.appendChild(expansor); 7525 path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff'); 7526 } else { 7527 feMorph = null; 7528 x = null; 7529 } 7530 7531 // TODO move this to a factory or to a constructor 7532 this.storedData[i] = { 7533 elem: path, 7534 x: x, 7535 expan: feMorph, 7536 lastPath: '', 7537 lastOperator: '', 7538 filterId: filterID, 7539 lastRadius: 0, 7540 }; 7541 if (properties[i].mode === 'i') { 7542 jLen = currentMasks.length; 7543 var g = createNS('g'); 7544 for (j = 0; j < jLen; j += 1) { 7545 g.appendChild(currentMasks[j]); 7546 } 7547 var mask = createNS('mask'); 7548 mask.setAttribute('mask-type', 'alpha'); 7549 mask.setAttribute('id', layerId + '_' + count); 7550 mask.appendChild(path); 7551 defs.appendChild(mask); 7552 g.setAttribute('mask', 'url(' + locationHref + '#' + layerId + '_' + count + ')'); 7553 7554 currentMasks.length = 0; 7555 currentMasks.push(g); 7556 } else { 7557 currentMasks.push(path); 7558 } 7559 if (properties[i].inv && !this.solidPath) { 7560 this.solidPath = this.createLayerSolidPath(); 7561 } 7562 // TODO move this to a factory or to a constructor 7563 this.viewData[i] = { 7564 elem: path, 7565 lastPath: '', 7566 op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element), 7567 prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3), 7568 invRect: rect, 7569 }; 7570 if (!this.viewData[i].prop.k) { 7571 this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]); 7572 } 7573 } 7574 } 7575 7576 this.maskElement = createNS(maskType); 7577 7578 len = currentMasks.length; 7579 for (i = 0; i < len; i += 1) { 7580 this.maskElement.appendChild(currentMasks[i]); 7581 } 7582 7583 if (count > 0) { 7584 this.maskElement.setAttribute('id', layerId); 7585 this.element.maskedElement.setAttribute(maskRef, 'url(' + locationHref + '#' + layerId + ')'); 7586 defs.appendChild(this.maskElement); 7587 } 7588 if (this.viewData.length) { 7589 this.element.addRenderableComponent(this); 7590 } 7591} 7592 7593MaskElement.prototype.getMaskProperty = function (pos) { 7594 return this.viewData[pos].prop; 7595}; 7596 7597MaskElement.prototype.renderFrame = function (isFirstFrame) { 7598 var finalMat = this.element.finalTransform.mat; 7599 var i; 7600 var len = this.masksProperties.length; 7601 for (i = 0; i < len; i += 1) { 7602 if (this.viewData[i].prop._mdf || isFirstFrame) { 7603 this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]); 7604 } 7605 if (this.viewData[i].op._mdf || isFirstFrame) { 7606 this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v); 7607 } 7608 if (this.masksProperties[i].mode !== 'n') { 7609 if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) { 7610 this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS()); 7611 } 7612 if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) { 7613 var feMorph = this.storedData[i].expan; 7614 if (this.storedData[i].x.v < 0) { 7615 if (this.storedData[i].lastOperator !== 'erode') { 7616 this.storedData[i].lastOperator = 'erode'; 7617 this.storedData[i].elem.setAttribute('filter', 'url(' + locationHref + '#' + this.storedData[i].filterId + ')'); 7618 } 7619 feMorph.setAttribute('radius', -this.storedData[i].x.v); 7620 } else { 7621 if (this.storedData[i].lastOperator !== 'dilate') { 7622 this.storedData[i].lastOperator = 'dilate'; 7623 this.storedData[i].elem.setAttribute('filter', null); 7624 } 7625 this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2); 7626 } 7627 } 7628 } 7629 } 7630}; 7631 7632MaskElement.prototype.getMaskelement = function () { 7633 return this.maskElement; 7634}; 7635 7636MaskElement.prototype.createLayerSolidPath = function () { 7637 var path = 'M0,0 '; 7638 path += ' h' + this.globalData.compSize.w; 7639 path += ' v' + this.globalData.compSize.h; 7640 path += ' h-' + this.globalData.compSize.w; 7641 path += ' v-' + this.globalData.compSize.h + ' '; 7642 return path; 7643}; 7644 7645MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) { 7646 var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1]; 7647 var i; 7648 var len; 7649 len = pathNodes._length; 7650 for (i = 1; i < len; i += 1) { 7651 // 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]; 7652 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]; 7653 } 7654 // 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]; 7655 if (pathNodes.c && len > 1) { 7656 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]; 7657 } 7658 // pathNodes.__renderedString = pathString; 7659 7660 if (viewData.lastPath !== pathString) { 7661 var pathShapeValue = ''; 7662 if (viewData.elem) { 7663 if (pathNodes.c) { 7664 pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString; 7665 } 7666 viewData.elem.setAttribute('d', pathShapeValue); 7667 } 7668 viewData.lastPath = pathString; 7669 } 7670}; 7671 7672MaskElement.prototype.destroy = function () { 7673 this.element = null; 7674 this.globalData = null; 7675 this.maskElement = null; 7676 this.data = null; 7677 this.masksProperties = null; 7678}; 7679 7680/** 7681 * @file 7682 * Handles AE's layer parenting property. 7683 * 7684 */ 7685 7686function HierarchyElement() {} 7687 7688HierarchyElement.prototype = { 7689 /** 7690 * @function 7691 * Initializes hierarchy properties 7692 * 7693 */ 7694 initHierarchy: function () { 7695 // element's parent list 7696 this.hierarchy = []; 7697 // if element is parent of another layer _isParent will be true 7698 this._isParent = false; 7699 this.checkParenting(); 7700 }, 7701 /** 7702 * @function 7703 * Sets layer's hierarchy. 7704 * @param {array} hierarch 7705 * layer's parent list 7706 * 7707 */ 7708 setHierarchy: function (hierarchy) { 7709 this.hierarchy = hierarchy; 7710 }, 7711 /** 7712 * @function 7713 * Sets layer as parent. 7714 * 7715 */ 7716 setAsParent: function () { 7717 this._isParent = true; 7718 }, 7719 /** 7720 * @function 7721 * Searches layer's parenting chain 7722 * 7723 */ 7724 checkParenting: function () { 7725 if (this.data.parent !== undefined) { 7726 this.comp.buildElementParenting(this, this.data.parent, []); 7727 } 7728 }, 7729}; 7730 7731/** 7732 * @file 7733 * Handles element's layer frame update. 7734 * Checks layer in point and out point 7735 * 7736 */ 7737 7738function FrameElement() {} 7739 7740FrameElement.prototype = { 7741 /** 7742 * @function 7743 * Initializes frame related properties. 7744 * 7745 */ 7746 initFrame: function () { 7747 // set to true when inpoint is rendered 7748 this._isFirstFrame = false; 7749 // list of animated properties 7750 this.dynamicProperties = []; 7751 // If layer has been modified in current tick this will be true 7752 this._mdf = false; 7753 }, 7754 /** 7755 * @function 7756 * Calculates all dynamic values 7757 * 7758 * @param {number} num 7759 * current frame number in Layer's time 7760 * @param {boolean} isVisible 7761 * if layers is currently in range 7762 * 7763 */ 7764 prepareProperties: function (num, isVisible) { 7765 var i; 7766 var len = this.dynamicProperties.length; 7767 for (i = 0; i < len; i += 1) { 7768 if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) { 7769 this.dynamicProperties[i].getValue(); 7770 if (this.dynamicProperties[i]._mdf) { 7771 this.globalData._mdf = true; 7772 this._mdf = true; 7773 } 7774 } 7775 } 7776 }, 7777 addDynamicProperty: function (prop) { 7778 if (this.dynamicProperties.indexOf(prop) === -1) { 7779 this.dynamicProperties.push(prop); 7780 } 7781 }, 7782}; 7783 7784/* global TransformPropertyFactory, Matrix */ 7785 7786function TransformElement() {} 7787 7788TransformElement.prototype = { 7789 initTransform: function () { 7790 this.finalTransform = { 7791 mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 }, 7792 _matMdf: false, 7793 _opMdf: false, 7794 mat: new Matrix(), 7795 }; 7796 if (this.data.ao) { 7797 this.finalTransform.mProp.autoOriented = true; 7798 } 7799 7800 // TODO: check TYPE 11: Guided elements 7801 if (this.data.ty !== 11) { 7802 // this.createElements(); 7803 } 7804 }, 7805 renderTransform: function () { 7806 this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame; 7807 this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame; 7808 7809 if (this.hierarchy) { 7810 var mat; 7811 var finalMat = this.finalTransform.mat; 7812 var i = 0; 7813 var len = this.hierarchy.length; 7814 // Checking if any of the transformation matrices in the hierarchy chain has changed. 7815 if (!this.finalTransform._matMdf) { 7816 while (i < len) { 7817 if (this.hierarchy[i].finalTransform.mProp._mdf) { 7818 this.finalTransform._matMdf = true; 7819 break; 7820 } 7821 i += 1; 7822 } 7823 } 7824 7825 if (this.finalTransform._matMdf) { 7826 mat = this.finalTransform.mProp.v.props; 7827 finalMat.cloneFromProps(mat); 7828 for (i = 0; i < len; i += 1) { 7829 mat = this.hierarchy[i].finalTransform.mProp.v.props; 7830 finalMat.transform(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5], mat[6], mat[7], mat[8], mat[9], mat[10], mat[11], mat[12], mat[13], mat[14], mat[15]); 7831 } 7832 } 7833 } 7834 }, 7835 globalToLocal: function (pt) { 7836 var transforms = []; 7837 transforms.push(this.finalTransform); 7838 var flag = true; 7839 var comp = this.comp; 7840 while (flag) { 7841 if (comp.finalTransform) { 7842 if (comp.data.hasMask) { 7843 transforms.splice(0, 0, comp.finalTransform); 7844 } 7845 comp = comp.comp; 7846 } else { 7847 flag = false; 7848 } 7849 } 7850 var i; 7851 var len = transforms.length; 7852 var ptNew; 7853 for (i = 0; i < len; i += 1) { 7854 ptNew = transforms[i].mat.applyToPointArray(0, 0, 0); 7855 // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]); 7856 pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0]; 7857 } 7858 return pt; 7859 }, 7860 mHelper: new Matrix(), 7861}; 7862 7863function RenderableElement() { 7864 7865} 7866 7867RenderableElement.prototype = { 7868 initRenderable: function () { 7869 // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange 7870 this.isInRange = false; 7871 // layer's display state 7872 this.hidden = false; 7873 // If layer's transparency equals 0, it can be hidden 7874 this.isTransparent = false; 7875 // list of animated components 7876 this.renderableComponents = []; 7877 }, 7878 addRenderableComponent: function (component) { 7879 if (this.renderableComponents.indexOf(component) === -1) { 7880 this.renderableComponents.push(component); 7881 } 7882 }, 7883 removeRenderableComponent: function (component) { 7884 if (this.renderableComponents.indexOf(component) !== -1) { 7885 this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1); 7886 } 7887 }, 7888 prepareRenderableFrame: function (num) { 7889 this.checkLayerLimits(num); 7890 }, 7891 checkTransparency: function () { 7892 if (this.finalTransform.mProp.o.v <= 0) { 7893 if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) { 7894 this.isTransparent = true; 7895 this.hide(); 7896 } 7897 } else if (this.isTransparent) { 7898 this.isTransparent = false; 7899 this.show(); 7900 } 7901 }, 7902 /** 7903 * @function 7904 * Initializes frame related properties. 7905 * 7906 * @param {number} num 7907 * current frame number in Layer's time 7908 * 7909 */ 7910 checkLayerLimits: function (num) { 7911 if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) { 7912 if (this.isInRange !== true) { 7913 this.globalData._mdf = true; 7914 this._mdf = true; 7915 this.isInRange = true; 7916 this.show(); 7917 } 7918 } else if (this.isInRange !== false) { 7919 this.globalData._mdf = true; 7920 this.isInRange = false; 7921 this.hide(); 7922 } 7923 }, 7924 renderRenderable: function () { 7925 var i; 7926 var len = this.renderableComponents.length; 7927 for (i = 0; i < len; i += 1) { 7928 this.renderableComponents[i].renderFrame(this._isFirstFrame); 7929 } 7930 /* this.maskManager.renderFrame(this.finalTransform.mat); 7931 this.renderableEffectsManager.renderFrame(this._isFirstFrame); */ 7932 }, 7933 sourceRectAtTime: function () { 7934 return { 7935 top: 0, 7936 left: 0, 7937 width: 100, 7938 height: 100, 7939 }; 7940 }, 7941 getLayerSize: function () { 7942 if (this.data.ty === 5) { 7943 return { w: this.data.textData.width, h: this.data.textData.height }; 7944 } 7945 return { w: this.data.width, h: this.data.height }; 7946 }, 7947}; 7948 7949/* global extendPrototype, RenderableElement, createProxyFunction */ 7950 7951function RenderableDOMElement() {} 7952 7953(function () { 7954 var _prototype = { 7955 initElement: function (data, globalData, comp) { 7956 this.initFrame(); 7957 this.initBaseData(data, globalData, comp); 7958 this.initTransform(data, globalData, comp); 7959 this.initHierarchy(); 7960 this.initRenderable(); 7961 this.initRendererElement(); 7962 this.createContainerElements(); 7963 this.createRenderableComponents(); 7964 this.createContent(); 7965 this.hide(); 7966 }, 7967 hide: function () { 7968 if (!this.hidden && (!this.isInRange || this.isTransparent)) { 7969 var elem = this.baseElement || this.layerElement; 7970 elem.style.display = 'none'; 7971 this.hidden = true; 7972 } 7973 }, 7974 show: function () { 7975 if (this.isInRange && !this.isTransparent) { 7976 if (!this.data.hd) { 7977 var elem = this.baseElement || this.layerElement; 7978 elem.style.display = 'block'; 7979 } 7980 this.hidden = false; 7981 this._isFirstFrame = true; 7982 } 7983 }, 7984 renderFrame: function () { 7985 // If it is exported as hidden (data.hd === true) no need to render 7986 // If it is not visible no need to render 7987 if (this.data.hd || this.hidden) { 7988 return; 7989 } 7990 this.renderTransform(); 7991 this.renderRenderable(); 7992 this.renderElement(); 7993 this.renderInnerContent(); 7994 if (this._isFirstFrame) { 7995 this._isFirstFrame = false; 7996 } 7997 }, 7998 renderInnerContent: function () {}, 7999 prepareFrame: function (num) { 8000 this._mdf = false; 8001 this.prepareRenderableFrame(num); 8002 this.prepareProperties(num, this.isInRange); 8003 this.checkTransparency(); 8004 }, 8005 destroy: function () { 8006 this.innerElem = null; 8007 this.destroyBaseElement(); 8008 }, 8009 }; 8010 extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement); 8011}()); 8012 8013/* exported ProcessedElement */ 8014 8015function ProcessedElement(element, position) { 8016 this.elem = element; 8017 this.pos = position; 8018} 8019 8020/* global createNS */ 8021 8022function SVGStyleData(data, level) { 8023 this.data = data; 8024 this.type = data.ty; 8025 this.d = ''; 8026 this.lvl = level; 8027 this._mdf = false; 8028 this.closed = data.hd === true; 8029 this.pElem = createNS('path'); 8030 this.msElem = null; 8031} 8032 8033SVGStyleData.prototype.reset = function () { 8034 this.d = ''; 8035 this._mdf = false; 8036}; 8037 8038function SVGShapeData(transformers, level, shape) { 8039 this.caches = []; 8040 this.styles = []; 8041 this.transformers = transformers; 8042 this.lStr = ''; 8043 this.sh = shape; 8044 this.lvl = level; 8045 // TODO find if there are some cases where _isAnimated can be false. 8046 // For now, since shapes add up with other shapes. They have to be calculated every time. 8047 // One way of finding out is checking if all styles associated to this shape depend only of this shape 8048 this._isAnimated = !!shape.k; 8049 // TODO: commenting this for now since all shapes are animated 8050 var i = 0; 8051 var len = transformers.length; 8052 while (i < len) { 8053 if (transformers[i].mProps.dynamicProperties.length) { 8054 this._isAnimated = true; 8055 break; 8056 } 8057 i += 1; 8058 } 8059} 8060 8061SVGShapeData.prototype.setAsAnimated = function () { 8062 this._isAnimated = true; 8063}; 8064 8065/* exported SVGTransformData */ 8066 8067function SVGTransformData(mProps, op, container) { 8068 this.transform = { 8069 mProps: mProps, 8070 op: op, 8071 container: container, 8072 }; 8073 this.elements = []; 8074 this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length; 8075} 8076 8077/* global DashProperty, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 8078 8079function SVGStrokeStyleData(elem, data, styleOb) { 8080 this.initDynamicPropertyContainer(elem); 8081 this.getValue = this.iterateDynamicProperties; 8082 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this); 8083 this.w = PropertyFactory.getProp(elem, data.w, 0, null, this); 8084 this.d = new DashProperty(elem, data.d || {}, 'svg', this); 8085 this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this); 8086 this.style = styleOb; 8087 this._isAnimated = !!this._isAnimated; 8088} 8089 8090extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData); 8091 8092/* global PropertyFactory, extendPrototype, DynamicPropertyContainer */ 8093 8094function SVGFillStyleData(elem, data, styleOb) { 8095 this.initDynamicPropertyContainer(elem); 8096 this.getValue = this.iterateDynamicProperties; 8097 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this); 8098 this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this); 8099 this.style = styleOb; 8100} 8101 8102extendPrototype([DynamicPropertyContainer], SVGFillStyleData); 8103 8104/* global PropertyFactory, degToRads, GradientProperty, createElementID, createNS, locationHref, 8105extendPrototype, DynamicPropertyContainer */ 8106 8107function SVGGradientFillStyleData(elem, data, styleOb) { 8108 this.initDynamicPropertyContainer(elem); 8109 this.getValue = this.iterateDynamicProperties; 8110 this.initGradientData(elem, data, styleOb); 8111} 8112 8113SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) { 8114 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this); 8115 this.s = PropertyFactory.getProp(elem, data.s, 1, null, this); 8116 this.e = PropertyFactory.getProp(elem, data.e, 1, null, this); 8117 this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this); 8118 this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this); 8119 this.g = new GradientProperty(elem, data.g, this); 8120 this.style = styleOb; 8121 this.stops = []; 8122 this.setGradientData(styleOb.pElem, data); 8123 this.setGradientOpacity(data, styleOb); 8124 this._isAnimated = !!this._isAnimated; 8125}; 8126 8127SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) { 8128 var gradientId = createElementID(); 8129 var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient'); 8130 gfill.setAttribute('id', gradientId); 8131 gfill.setAttribute('spreadMethod', 'pad'); 8132 gfill.setAttribute('gradientUnits', 'userSpaceOnUse'); 8133 var stops = []; 8134 var stop; 8135 var j; 8136 var jLen; 8137 jLen = data.g.p * 4; 8138 for (j = 0; j < jLen; j += 4) { 8139 stop = createNS('stop'); 8140 gfill.appendChild(stop); 8141 stops.push(stop); 8142 } 8143 pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + locationHref + '#' + gradientId + ')'); 8144 8145 this.gf = gfill; 8146 this.cst = stops; 8147}; 8148 8149SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) { 8150 if (this.g._hasOpacity && !this.g._collapsable) { 8151 var stop; 8152 var j; 8153 var jLen; 8154 var mask = createNS('mask'); 8155 var maskElement = createNS('path'); 8156 mask.appendChild(maskElement); 8157 var opacityId = createElementID(); 8158 var maskId = createElementID(); 8159 mask.setAttribute('id', maskId); 8160 var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient'); 8161 opFill.setAttribute('id', opacityId); 8162 opFill.setAttribute('spreadMethod', 'pad'); 8163 opFill.setAttribute('gradientUnits', 'userSpaceOnUse'); 8164 jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length; 8165 var stops = this.stops; 8166 for (j = data.g.p * 4; j < jLen; j += 2) { 8167 stop = createNS('stop'); 8168 stop.setAttribute('stop-color', 'rgb(255,255,255)'); 8169 opFill.appendChild(stop); 8170 stops.push(stop); 8171 } 8172 maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + locationHref + '#' + opacityId + ')'); 8173 this.of = opFill; 8174 this.ms = mask; 8175 this.ost = stops; 8176 this.maskId = maskId; 8177 styleOb.msElem = maskElement; 8178 } 8179}; 8180 8181extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData); 8182 8183/* global PropertyFactory, DashProperty, extendPrototype, SVGGradientFillStyleData, DynamicPropertyContainer */ 8184 8185function SVGGradientStrokeStyleData(elem, data, styleOb) { 8186 this.initDynamicPropertyContainer(elem); 8187 this.getValue = this.iterateDynamicProperties; 8188 this.w = PropertyFactory.getProp(elem, data.w, 0, null, this); 8189 this.d = new DashProperty(elem, data.d || {}, 'svg', this); 8190 this.initGradientData(elem, data, styleOb); 8191 this._isAnimated = !!this._isAnimated; 8192} 8193 8194extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData); 8195 8196/* global createNS */ 8197/* exported ShapeGroupData */ 8198 8199function ShapeGroupData() { 8200 this.it = []; 8201 this.prevViewData = []; 8202 this.gr = createNS('g'); 8203} 8204 8205/* global Matrix, buildShapeString, bmFloor */ 8206/* exported SVGElementsRenderer */ 8207 8208var SVGElementsRenderer = (function () { 8209 var _identityMatrix = new Matrix(); 8210 var _matrixHelper = new Matrix(); 8211 8212 var ob = { 8213 createRenderFunction: createRenderFunction, 8214 }; 8215 8216 function createRenderFunction(data) { 8217 switch (data.ty) { 8218 case 'fl': 8219 return renderFill; 8220 case 'gf': 8221 return renderGradient; 8222 case 'gs': 8223 return renderGradientStroke; 8224 case 'st': 8225 return renderStroke; 8226 case 'sh': 8227 case 'el': 8228 case 'rc': 8229 case 'sr': 8230 return renderPath; 8231 case 'tr': 8232 return renderContentTransform; 8233 default: 8234 return null; 8235 } 8236 } 8237 8238 function renderContentTransform(styleData, itemData, isFirstFrame) { 8239 if (isFirstFrame || itemData.transform.op._mdf) { 8240 itemData.transform.container.setAttribute('opacity', itemData.transform.op.v); 8241 } 8242 if (isFirstFrame || itemData.transform.mProps._mdf) { 8243 itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS()); 8244 } 8245 } 8246 8247 function renderPath(styleData, itemData, isFirstFrame) { 8248 var j; 8249 var jLen; 8250 var pathStringTransformed; 8251 var redraw; 8252 var pathNodes; 8253 var l; 8254 var lLen = itemData.styles.length; 8255 var lvl = itemData.lvl; 8256 var paths; 8257 var mat; 8258 var props; 8259 var iterations; 8260 var k; 8261 for (l = 0; l < lLen; l += 1) { 8262 redraw = itemData.sh._mdf || isFirstFrame; 8263 if (itemData.styles[l].lvl < lvl) { 8264 mat = _matrixHelper.reset(); 8265 iterations = lvl - itemData.styles[l].lvl; 8266 k = itemData.transformers.length - 1; 8267 while (!redraw && iterations > 0) { 8268 redraw = itemData.transformers[k].mProps._mdf || redraw; 8269 iterations -= 1; 8270 k -= 1; 8271 } 8272 if (redraw) { 8273 iterations = lvl - itemData.styles[l].lvl; 8274 k = itemData.transformers.length - 1; 8275 while (iterations > 0) { 8276 props = itemData.transformers[k].mProps.v.props; 8277 mat.transform(props[0], props[1], props[2], props[3], props[4], props[5], props[6], props[7], props[8], props[9], props[10], props[11], props[12], props[13], props[14], props[15]); 8278 iterations -= 1; 8279 k -= 1; 8280 } 8281 } 8282 } else { 8283 mat = _identityMatrix; 8284 } 8285 paths = itemData.sh.paths; 8286 jLen = paths._length; 8287 if (redraw) { 8288 pathStringTransformed = ''; 8289 for (j = 0; j < jLen; j += 1) { 8290 pathNodes = paths.shapes[j]; 8291 if (pathNodes && pathNodes._length) { 8292 pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat); 8293 } 8294 } 8295 itemData.caches[l] = pathStringTransformed; 8296 } else { 8297 pathStringTransformed = itemData.caches[l]; 8298 } 8299 itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed; 8300 itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf; 8301 } 8302 } 8303 8304 function renderFill(styleData, itemData, isFirstFrame) { 8305 var styleElem = itemData.style; 8306 8307 if (itemData.c._mdf || isFirstFrame) { 8308 styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')'); 8309 } 8310 if (itemData.o._mdf || isFirstFrame) { 8311 styleElem.pElem.setAttribute('fill-opacity', itemData.o.v); 8312 } 8313 } 8314 8315 function renderGradientStroke(styleData, itemData, isFirstFrame) { 8316 renderGradient(styleData, itemData, isFirstFrame); 8317 renderStroke(styleData, itemData, isFirstFrame); 8318 } 8319 8320 function renderGradient(styleData, itemData, isFirstFrame) { 8321 var gfill = itemData.gf; 8322 var hasOpacity = itemData.g._hasOpacity; 8323 var pt1 = itemData.s.v; 8324 var pt2 = itemData.e.v; 8325 8326 if (itemData.o._mdf || isFirstFrame) { 8327 var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity'; 8328 itemData.style.pElem.setAttribute(attr, itemData.o.v); 8329 } 8330 if (itemData.s._mdf || isFirstFrame) { 8331 var attr1 = styleData.t === 1 ? 'x1' : 'cx'; 8332 var attr2 = attr1 === 'x1' ? 'y1' : 'cy'; 8333 gfill.setAttribute(attr1, pt1[0]); 8334 gfill.setAttribute(attr2, pt1[1]); 8335 if (hasOpacity && !itemData.g._collapsable) { 8336 itemData.of.setAttribute(attr1, pt1[0]); 8337 itemData.of.setAttribute(attr2, pt1[1]); 8338 } 8339 } 8340 var stops; 8341 var i; 8342 var len; 8343 var stop; 8344 if (itemData.g._cmdf || isFirstFrame) { 8345 stops = itemData.cst; 8346 var cValues = itemData.g.c; 8347 len = stops.length; 8348 for (i = 0; i < len; i += 1) { 8349 stop = stops[i]; 8350 stop.setAttribute('offset', cValues[i * 4] + '%'); 8351 stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')'); 8352 } 8353 } 8354 if (hasOpacity && (itemData.g._omdf || isFirstFrame)) { 8355 var oValues = itemData.g.o; 8356 if (itemData.g._collapsable) { 8357 stops = itemData.cst; 8358 } else { 8359 stops = itemData.ost; 8360 } 8361 len = stops.length; 8362 for (i = 0; i < len; i += 1) { 8363 stop = stops[i]; 8364 if (!itemData.g._collapsable) { 8365 stop.setAttribute('offset', oValues[i * 2] + '%'); 8366 } 8367 stop.setAttribute('stop-opacity', oValues[i * 2 + 1]); 8368 } 8369 } 8370 if (styleData.t === 1) { 8371 if (itemData.e._mdf || isFirstFrame) { 8372 gfill.setAttribute('x2', pt2[0]); 8373 gfill.setAttribute('y2', pt2[1]); 8374 if (hasOpacity && !itemData.g._collapsable) { 8375 itemData.of.setAttribute('x2', pt2[0]); 8376 itemData.of.setAttribute('y2', pt2[1]); 8377 } 8378 } 8379 } else { 8380 var rad; 8381 if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) { 8382 rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2)); 8383 gfill.setAttribute('r', rad); 8384 if (hasOpacity && !itemData.g._collapsable) { 8385 itemData.of.setAttribute('r', rad); 8386 } 8387 } 8388 if (itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) { 8389 if (!rad) { 8390 rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2)); 8391 } 8392 var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]); 8393 8394 var percent = itemData.h.v; 8395 if (percent >= 1) { 8396 percent = 0.99; 8397 } else if (percent <= -1) { 8398 percent = -0.99; 8399 } 8400 var dist = rad * percent; 8401 var x = Math.cos(ang + itemData.a.v) * dist + pt1[0]; 8402 var y = Math.sin(ang + itemData.a.v) * dist + pt1[1]; 8403 gfill.setAttribute('fx', x); 8404 gfill.setAttribute('fy', y); 8405 if (hasOpacity && !itemData.g._collapsable) { 8406 itemData.of.setAttribute('fx', x); 8407 itemData.of.setAttribute('fy', y); 8408 } 8409 } 8410 // gfill.setAttribute('fy','200'); 8411 } 8412 } 8413
vendor: 4,321 bytes, lines 8414-8557
8414 function renderStroke(styleData, itemData, isFirstFrame) { 8415 var styleElem = itemData.style; 8416 var d = itemData.d; 8417 if (d && (d._mdf || isFirstFrame) && d.dashStr) { 8418 styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr); 8419 styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]); 8420 } 8421 if (itemData.c && (itemData.c._mdf || isFirstFrame)) { 8422 styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')'); 8423 } 8424 if (itemData.o._mdf || isFirstFrame) { 8425 styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v); 8426 } 8427 if (itemData.w._mdf || isFirstFrame) { 8428 styleElem.pElem.setAttribute('stroke-width', itemData.w.v); 8429 if (styleElem.msElem) { 8430 styleElem.msElem.setAttribute('stroke-width', itemData.w.v); 8431 } 8432 } 8433 } 8434 8435 return ob; 8436}()); 8437 8438/* global Matrix */ 8439 8440function ShapeTransformManager() { 8441 this.sequences = {}; 8442 this.sequenceList = []; 8443 this.transform_key_count = 0; 8444} 8445 8446ShapeTransformManager.prototype = { 8447 addTransformSequence: function (transforms) { 8448 var i; 8449 var len = transforms.length; 8450 var key = '_'; 8451 for (i = 0; i < len; i += 1) { 8452 key += transforms[i].transform.key + '_'; 8453 } 8454 var sequence = this.sequences[key]; 8455 if (!sequence) { 8456 sequence = { 8457 transforms: [].concat(transforms), 8458 finalTransform: new Matrix(), 8459 _mdf: false, 8460 }; 8461 this.sequences[key] = sequence; 8462 this.sequenceList.push(sequence); 8463 } 8464 return sequence; 8465 }, 8466 processSequence: function (sequence, isFirstFrame) { 8467 var i = 0; 8468 var len = sequence.transforms.length; 8469 var _mdf = isFirstFrame; 8470 while (i < len && !isFirstFrame) { 8471 if (sequence.transforms[i].transform.mProps._mdf) { 8472 _mdf = true; 8473 break; 8474 } 8475 i += 1; 8476 } 8477 if (_mdf) { 8478 var props; 8479 sequence.finalTransform.reset(); 8480 for (i = len - 1; i >= 0; i -= 1) { 8481 props = sequence.transforms[i].transform.mProps.v.props; 8482 sequence.finalTransform.transform(props[0], props[1], props[2], props[3], props[4], props[5], props[6], props[7], props[8], props[9], props[10], props[11], props[12], props[13], props[14], props[15]); 8483 } 8484 } 8485 sequence._mdf = _mdf; 8486 }, 8487 processSequences: function (isFirstFrame) { 8488 var i; 8489 var len = this.sequenceList.length; 8490 for (i = 0; i < len; i += 1) { 8491 this.processSequence(this.sequenceList[i], isFirstFrame); 8492 } 8493 }, 8494 getNewKey: function () { 8495 this.transform_key_count += 1; 8496 return '_' + this.transform_key_count; 8497 }, 8498}; 8499 8500/* global ShapePropertyFactory, SVGShapeData */ 8501 8502function CVShapeData(element, data, styles, transformsManager) { 8503 this.styledShapes = []; 8504 this.tr = [0, 0, 0, 0, 0, 0]; 8505 var ty = 4; 8506 if (data.ty === 'rc') { 8507 ty = 5; 8508 } else if (data.ty === 'el') { 8509 ty = 6; 8510 } else if (data.ty === 'sr') { 8511 ty = 7; 8512 } 8513 this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element); 8514 var i; 8515 var len = styles.length; 8516 var styledShape; 8517 for (i = 0; i < len; i += 1) { 8518 if (!styles[i].closed) { 8519 styledShape = { 8520 transforms: transformsManager.addTransformSequence(styles[i].transforms), 8521 trNodes: [], 8522 }; 8523 this.styledShapes.push(styledShape); 8524 styles[i].elements.push(styledShape); 8525 } 8526 } 8527} 8528 8529CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated; 8530 8531/* global LayerExpressionInterface, EffectsExpressionInterface, CompExpressionInterface, ShapeExpressionInterface, 8532TextExpressionInterface, getBlendMode,createElementID, EffectsManager */ 8533 8534function BaseElement() { 8535} 8536 8537BaseElement.prototype = { 8538 checkMasks: function () { 8539 if (!this.data.hasMask) { 8540 return false; 8541 } 8542 var i = 0; 8543 var len = this.data.masksProperties.length; 8544 while (i < len) { 8545 if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) { 8546 return true; 8547 } 8548 i += 1; 8549 } 8550 return false; 8551 }, 8552 initExpressions: function () { 8553 this.layerInterface = LayerExpressionInterface(this); 8554 if (this.data.hasMask && this.maskManager) { 8555 this.layerInterface.registerMaskInterface(this.maskManager); 8556 } 8557 var effectsInterface = EffectsExpressionInterface.createEffe
vendor: 11,057 bytes, lines 8557-8888
8557ctsInterface(this, this.layerInterface); 8558 this.layerInterface.registerEffectsInterface(effectsInterface); 8559 8560 if (this.data.ty === 0 || this.data.xt) { 8561 this.compInterface = CompExpressionInterface(this); 8562 } else if (this.data.ty === 4) { 8563 this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface); 8564 this.layerInterface.content = this.layerInterface.shapeInterface; 8565 } else if (this.data.ty === 5) { 8566 this.layerInterface.textInterface = TextExpressionInterface(this); 8567 this.layerInterface.text = this.layerInterface.textInterface; 8568 } 8569 }, 8570 setBlendMode: function () { 8571 var blendModeValue = getBlendMode(this.data.bm); 8572 var elem = this.baseElement || this.layerElement; 8573 8574 elem.style['mix-blend-mode'] = blendModeValue; 8575 }, 8576 initBaseData: function (data, globalData, comp) { 8577 this.globalData = globalData; 8578 this.comp = comp; 8579 this.data = data; 8580 this.layerId = createElementID(); 8581 8582 // Stretch factor for old animations missing this property. 8583 if (!this.data.sr) { 8584 this.data.sr = 1; 8585 } 8586 // effects manager 8587 this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties); 8588 }, 8589 getType: function () { 8590 return this.type; 8591 }, 8592 sourceRectAtTime: function () {}, 8593}; 8594 8595/* global extendPrototype, BaseElement, TransformElement, HierarchyElement, FrameElement */ 8596 8597function NullElement(data, globalData, comp) { 8598 this.initFrame(); 8599 this.initBaseData(data, globalData, comp); 8600 this.initFrame(); 8601 this.initTransform(data, globalData, comp); 8602 this.initHierarchy(); 8603} 8604 8605NullElement.prototype.prepareFrame = function (num) { 8606 this.prepareProperties(num, true); 8607}; 8608 8609NullElement.prototype.renderFrame = function () { 8610}; 8611 8612NullElement.prototype.getBaseElement = function () { 8613 return null; 8614}; 8615 8616NullElement.prototype.destroy = function () { 8617}; 8618 8619NullElement.prototype.sourceRectAtTime = function () { 8620}; 8621 8622NullElement.prototype.hide = function () { 8623}; 8624 8625extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement); 8626 8627/* global filtersFactory, featureSupport, filtersFactory, createElementID, createNS, MaskElement, SVGEffects, locationHref */ 8628 8629function SVGBaseElement() { 8630} 8631 8632SVGBaseElement.prototype = { 8633 initRendererElement: function () { 8634 this.layerElement = createNS('g'); 8635 }, 8636 createContainerElements: function () { 8637 this.matteElement = createNS('g'); 8638 this.transformedElement = this.layerElement; 8639 this.maskedElement = this.layerElement; 8640 this._sizeChanged = false; 8641 var layerElementParent = null; 8642 // If this layer acts as a mask for the following layer 8643 var filId; 8644 var fil; 8645 var gg; 8646 if (this.data.td) { 8647 if (this.data.td == 3 || this.data.td == 1) { // eslint-disable-line eqeqeq 8648 var masker = createNS('mask'); 8649 masker.setAttribute('id', this.layerId); 8650 masker.setAttribute('mask-type', this.data.td == 3 ? 'luminance' : 'alpha'); // eslint-disable-line eqeqeq 8651 masker.appendChild(this.layerElement); 8652 layerElementParent = masker; 8653 this.globalData.defs.appendChild(masker); 8654 // This is only for IE and Edge when mask if of type alpha 8655 if (!featureSupport.maskType && this.data.td == 1) { // eslint-disable-line eqeqeq 8656 masker.setAttribute('mask-type', 'luminance'); 8657 filId = createElementID(); 8658 fil = filtersFactory.createFilter(filId); 8659 this.globalData.defs.appendChild(fil); 8660 fil.appendChild(filtersFactory.createAlphaToLuminanceFilter()); 8661 gg = createNS('g'); 8662 gg.appendChild(this.layerElement); 8663 layerElementParent = gg; 8664 masker.appendChild(gg); 8665 gg.setAttribute('filter', 'url(' + locationHref + '#' + filId + ')'); 8666 } 8667 } else if (this.data.td == 2) { // eslint-disable-line eqeqeq 8668 var maskGroup = createNS('mask'); 8669 maskGroup.setAttribute('id', this.layerId); 8670 maskGroup.setAttribute('mask-type', 'alpha'); 8671 var maskGrouper = createNS('g'); 8672 maskGroup.appendChild(maskGrouper); 8673 filId = createElementID(); 8674 fil = filtersFactory.createFilter(filId); 8675 /// / 8676 8677 // This solution doesn't work on Android when meta tag with viewport attribute is set 8678 /* var feColorMatrix = createNS('feColorMatrix'); 8679 feColorMatrix.setAttribute('type', 'matrix'); 8680 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 8681 feColorMatrix.setAttribute('values','1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 -1 1'); 8682 fil.appendChild(feColorMatrix); */ 8683 /// / 8684 var feCTr = createNS('feComponentTransfer'); 8685 feCTr.setAttribute('in', 'SourceGraphic'); 8686 fil.appendChild(feCTr); 8687 var feFunc = createNS('feFuncA'); 8688 feFunc.setAttribute('type', 'table'); 8689 feFunc.setAttribute('tableValues', '1.0 0.0'); 8690 feCTr.appendChild(feFunc); 8691 /// / 8692 this.globalData.defs.appendChild(fil); 8693 var alphaRect = createNS('rect'); 8694 alphaRect.setAttribute('width', this.comp.data.w); 8695 alphaRect.setAttribute('height', this.comp.data.h); 8696 alphaRect.setAttribute('x', '0'); 8697 alphaRect.setAttribute('y', '0'); 8698 alphaRect.setAttribute('fill', '#ffffff'); 8699 alphaRect.setAttribute('opacity', '0'); 8700 maskGrouper.setAttribute('filter', 'url(' + locationHref + '#' + filId + ')'); 8701 maskGrouper.appendChild(alphaRect); 8702 maskGrouper.appendChild(this.layerElement); 8703 layerElementParent = maskGrouper; 8704 if (!featureSupport.maskType) { 8705 maskGroup.setAttribute('mask-type', 'luminance'); 8706 fil.appendChild(filtersFactory.createAlphaToLuminanceFilter()); 8707 gg = createNS('g'); 8708 maskGrouper.appendChild(alphaRect); 8709 gg.appendChild(this.layerElement); 8710 layerElementParent = gg; 8711 maskGrouper.appendChild(gg); 8712 } 8713 this.globalData.defs.appendChild(maskGroup); 8714 } 8715 } else if (this.data.tt) { 8716 this.matteElement.appendChild(this.layerElement); 8717 layerElementParent = this.matteElement; 8718 this.baseElement = this.matteElement; 8719 } else { 8720 this.baseElement = this.layerElement; 8721 } 8722 if (this.data.ln) { 8723 this.layerElement.setAttribute('id', this.data.ln); 8724 } 8725 if (this.data.cl) { 8726 this.layerElement.setAttribute('class', this.data.cl); 8727 } 8728 // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped 8729 if (this.data.ty === 0 && !this.data.hd) { 8730 var cp = createNS('clipPath'); 8731 var pt = createNS('path'); 8732 pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z'); 8733 var clipId = createElementID(); 8734 cp.setAttribute('id', clipId); 8735 cp.appendChild(pt); 8736 this.globalData.defs.appendChild(cp); 8737 8738 if (this.checkMasks()) { 8739 var cpGroup = createNS('g'); 8740 cpGroup.setAttribute('clip-path', 'url(' + locationHref + '#' + clipId + ')'); 8741 cpGroup.appendChild(this.layerElement); 8742 this.transformedElement = cpGroup; 8743 if (layerElementParent) { 8744 layerElementParent.appendChild(this.transformedElement); 8745 } else { 8746 this.baseElement = this.transformedElement; 8747 } 8748 } else { 8749 this.layerElement.setAttribute('clip-path', 'url(' + locationHref + '#' + clipId + ')'); 8750 } 8751 } 8752 if (this.data.bm !== 0) { 8753 this.setBlendMode(); 8754 } 8755 }, 8756 renderElement: function () { 8757 if (this.finalTransform._matMdf) { 8758 this.transformedElement.setAttribute('transform', this.finalTransform.mat.to2dCSS()); 8759 } 8760 if (this.finalTransform._opMdf) { 8761 this.transformedElement.setAttribute('opacity', this.finalTransform.mProp.o.v); 8762 } 8763 }, 8764 destroyBaseElement: function () { 8765 this.layerElement = null; 8766 this.matteElement = null; 8767 this.maskManager.destroy(); 8768 }, 8769 getBaseElement: function () { 8770 if (this.data.hd) { 8771 return null; 8772 } 8773 return this.baseElement; 8774 }, 8775 createRenderableComponents: function () { 8776 this.maskManager = new MaskElement(this.data, this, this.globalData); 8777 this.renderableEffectsManager = new SVGEffects(this); 8778 }, 8779 setMatte: function (id) { 8780 if (!this.matteElement) { 8781 return; 8782 } 8783 this.matteElement.setAttribute('mask', 'url(' + locationHref + '#' + id + ')'); 8784 }, 8785}; 8786 8787/* global ProcessedElement */ 8788 8789function IShapeElement() { 8790} 8791 8792IShapeElement.prototype = { 8793 addShapeToModifiers: function (data) { 8794 var i; 8795 var len = this.shapeModifiers.length; 8796 for (i = 0; i < len; i += 1) { 8797 this.shapeModifiers[i].addShape(data); 8798 } 8799 }, 8800 isShapeInAnimatedModifiers: function (data) { 8801 var i = 0; 8802 var len = this.shapeModifiers.length; 8803 while (i < len) { 8804 if (this.shapeModifiers[i].isAnimatedWithShape(data)) { 8805 return true; 8806 } 8807 } 8808 return false; 8809 }, 8810 renderModifiers: function () { 8811 if (!this.shapeModifiers.length) { 8812 return; 8813 } 8814 var i; 8815 var len = this.shapes.length; 8816 for (i = 0; i < len; i += 1) { 8817 this.shapes[i].sh.reset(); 8818 } 8819 8820 len = this.shapeModifiers.length; 8821 for (i = len - 1; i >= 0; i -= 1) { 8822 this.shapeModifiers[i].processShapes(this._isFirstFrame); 8823 } 8824 }, 8825 lcEnum: { 8826 1: 'butt', 8827 2: 'round', 8828 3: 'square', 8829 }, 8830 ljEnum: { 8831 1: 'miter', 8832 2: 'round', 8833 3: 'bevel', 8834 }, 8835 searchProcessedElement: function (elem) { 8836 var elements = this.processedElements; 8837 var i = 0; 8838 var len = elements.length; 8839 while (i < len) { 8840 if (elements[i].elem === elem) { 8841 return elements[i].pos; 8842 } 8843 i += 1; 8844 } 8845 return 0; 8846 }, 8847 addProcessedElement: function (elem, pos) { 8848 var elements = this.processedElements; 8849 var i = elements.length; 8850 while (i) { 8851 i -= 1; 8852 if (elements[i].elem === elem) { 8853 elements[i].pos = pos; 8854 return; 8855 } 8856 } 8857 elements.push(new ProcessedElement(elem, pos)); 8858 }, 8859 prepareFrame: function (num) { 8860 this.prepareRenderableFrame(num); 8861 this.prepareProperties(num, this.isInRange); 8862 }, 8863}; 8864 8865/* global TextProperty, TextAnimatorProperty, buildShapeString, LetterProps */ 8866 8867function ITextElement() { 8868} 8869 8870ITextElement.prototype.initElement = function (data, globalData, comp) { 8871 this.lettersChangedFlag = true; 8872 this.initFrame(); 8873 this.initBaseData(data, globalData, comp); 8874 this.textProperty = new TextProperty(this, data.t, this.dynamicProperties); 8875 this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this); 8876 this.initTransform(data, globalData, comp); 8877 this.initHierarchy(); 8878 this.initRenderable(); 8879 this.initRendererElement(); 8880 this.createContainerElements(); 8881 this.createRenderableComponents(); 8882 this.createContent(); 8883 this.hide(); 8884 this.textAnimator.searchProperties(this.dynamicProperties); 8885}; 8886 8887ITextElement.prototype.prepareFrame = function (num) { 8888 this._mdf = false;
vendor: 6,658 bytes, lines 8889-9102
8889 this.prepareRenderableFrame(num); 8890 this.prepareProperties(num, this.isInRange); 8891 if (this.textProperty._mdf || this.textProperty._isFirstFrame) { 8892 this.buildNewText(); 8893 this.textProperty._isFirstFrame = false; 8894 this.textProperty._mdf = false; 8895 } 8896}; 8897 8898ITextElement.prototype.createPathShape = function (matrixHelper, shapes) { 8899 var j; 8900 var jLen = shapes.length; 8901 var pathNodes; 8902 var shapeStr = ''; 8903 for (j = 0; j < jLen; j += 1) { 8904 pathNodes = shapes[j].ks.k; 8905 shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper); 8906 } 8907 return shapeStr; 8908}; 8909 8910ITextElement.prototype.updateDocumentData = function (newData, index) { 8911 this.textProperty.updateDocumentData(newData, index); 8912}; 8913 8914ITextElement.prototype.canResizeFont = function (_canResize) { 8915 this.textProperty.canResizeFont(_canResize); 8916}; 8917 8918ITextElement.prototype.setMinimumFontSize = function (_fontSize) { 8919 this.textProperty.setMinimumFontSize(_fontSize); 8920}; 8921 8922ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) { 8923 if (documentData.ps) { 8924 matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0); 8925 } 8926 matrixHelper.translate(0, -documentData.ls, 0); 8927 switch (documentData.j) { 8928 case 1: 8929 matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0); 8930 break; 8931 case 2: 8932 matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0); 8933 break; 8934 default: 8935 break; 8936 } 8937 matrixHelper.translate(xPos, yPos, 0); 8938}; 8939 8940ITextElement.prototype.buildColor = function (colorData) { 8941 return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')'; 8942}; 8943 8944ITextElement.prototype.emptyProp = new LetterProps(); 8945 8946ITextElement.prototype.destroy = function () { 8947 8948}; 8949 8950/* global extendPrototype, BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement */ 8951 8952function ICompElement() {} 8953 8954extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement); 8955 8956ICompElement.prototype.initElement = function (data, globalData, comp) { 8957 this.initFrame(); 8958 this.initBaseData(data, globalData, comp); 8959 this.initTransform(data, globalData, comp); 8960 this.initRenderable(); 8961 this.initHierarchy(); 8962 this.initRendererElement(); 8963 this.createContainerElements(); 8964 this.createRenderableComponents(); 8965 if (this.data.xt || !globalData.progressiveLoad) { 8966 this.buildAllItems(); 8967 } 8968 this.hide(); 8969}; 8970 8971/* ICompElement.prototype.hide = function(){ 8972 if(!this.hidden){ 8973 this.hideElement(); 8974 var i,len = this.elements.length; 8975 for( i = 0; i < len; i+=1 ){ 8976 if(this.elements[i]){ 8977 this.elements[i].hide(); 8978 } 8979 } 8980 } 8981}; */ 8982 8983ICompElement.prototype.prepareFrame = function (num) { 8984 this._mdf = false; 8985 this.prepareRenderableFrame(num); 8986 this.prepareProperties(num, this.isInRange); 8987 if (!this.isInRange && !this.data.xt) { 8988 return; 8989 } 8990 8991 if (!this.tm._placeholder) { 8992 var timeRemapped = this.tm.v; 8993 if (timeRemapped === this.data.op) { 8994 timeRemapped = this.data.op - 1; 8995 } 8996 this.renderedFrame = timeRemapped; 8997 } else { 8998 this.renderedFrame = num / this.data.sr; 8999 } 9000 var i; 9001 var len = this.elements.length; 9002 if (!this.completeLayers) { 9003 this.checkLayers(this.renderedFrame); 9004 } 9005 // This iteration needs to be backwards because of how expressions connect between each other 9006 for (i = len - 1; i >= 0; i -= 1) { 9007 if (this.completeLayers || this.elements[i]) { 9008 this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st); 9009 if (this.elements[i]._mdf) { 9010 this._mdf = true; 9011 } 9012 } 9013 } 9014}; 9015 9016ICompElement.prototype.renderInnerContent = function () { 9017 var i; 9018 var len = this.layers.length; 9019 for (i = 0; i < len; i += 1) { 9020 if (this.completeLayers || this.elements[i]) { 9021 this.elements[i].renderFrame(); 9022 } 9023 } 9024}; 9025 9026ICompElement.prototype.setElements = function (elems) { 9027 this.elements = elems; 9028}; 9029 9030ICompElement.prototype.getElements = function () { 9031 return this.elements; 9032}; 9033 9034ICompElement.prototype.destroyElements = function () { 9035 var i; 9036 var len = this.layers.length; 9037 for (i = 0; i < len; i += 1) { 9038 if (this.elements[i]) { 9039 this.elements[i].destroy(); 9040 } 9041 } 9042}; 9043 9044ICompElement.prototype.destroy = function () { 9045 this.destroyElements(); 9046 this.destroyBaseElement(); 9047}; 9048 9049/* global extendPrototype, BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, createNS */ 9050 9051function IImageElement(data, globalData, comp) { 9052 this.assetData = globalData.getAssetData(data.refId); 9053 this.initElement(data, globalData, comp); 9054 this.sourceRect = { 9055 top: 0, left: 0, width: this.assetData.w, height: this.assetData.h, 9056 }; 9057} 9058 9059extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement); 9060 9061IImageElement.prototype.createContent = function () { 9062 var assetPath = this.globalData.getAssetsPath(this.assetData); 9063 9064 this.innerElem = createNS('image'); 9065 this.innerElem.setAttribute('width', this.assetData.w + 'px'); 9066 this.innerElem.setAttribute('height', this.assetData.h + 'px'); 9067 this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio); 9068 this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath); 9069 9070 this.layerElement.appendChild(this.innerElem); 9071}; 9072 9073IImageElement.prototype.sourceRectAtTime = function () { 9074 return this.sourceRect; 9075}; 9076 9077/* global extendPrototype, IImageElement, createNS */ 9078 9079function ISolidElement(data, globalData, comp) { 9080 this.initElement(data, globalData, comp); 9081} 9082extendPrototype([IImageElement], ISolidElement); 9083 9084ISolidElement.prototype.createContent = function () { 9085 var rect = createNS('rect'); 9086 /// /rect.style.width = this.data.sw; 9087 /// /rect.style.height = this.data.sh; 9088 /// /rect.style.fill = this.data.sc; 9089 rect.setAttribute('width', this.data.sw); 9090 rect.setAttribute('height', this.data.sh); 9091 rect.setAttribute('fill', this.data.sc); 9092 this.layerElement.appendChild(rect); 9093}; 9094 9095/* global PropertyFactory, extendPrototype, RenderableElement, BaseElement, FrameElement */ 9096 9097function AudioElement(data, globalData, comp) { 9098 this.initFrame(); 9099 this.initRenderable(); 9100 this.assetData = globalData.getAssetData(data.refId); 9101 this.initBaseData(data, globalData, comp); 9102 this._isPlaying = false;
vendor: 19,512 bytes, lines 9103-9683
9103 this._canPlay = false; 9104 var assetPath = this.globalData.getAssetsPath(this.assetData); 9105 this.audio = this.globalData.audioController.createAudio(assetPath); 9106 this._currentTime = 0; 9107 this.globalData.audioController.addAudio(this); 9108 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 9109} 9110 9111AudioElement.prototype.prepareFrame = function (num) { 9112 this.prepareRenderableFrame(num, true); 9113 this.prepareProperties(num, true); 9114 if (!this.tm._placeholder) { 9115 var timeRemapped = this.tm.v; 9116 this._currentTime = timeRemapped; 9117 } else { 9118 this._currentTime = num / this.data.sr; 9119 } 9120}; 9121 9122extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement); 9123 9124AudioElement.prototype.renderFrame = function () { 9125 if (this.isInRange && this._canPlay) { 9126 if (!this._isPlaying) { 9127 this.audio.play(); 9128 this.audio.seek(this._currentTime / this.globalData.frameRate); 9129 this._isPlaying = true; 9130 } else if (!this.audio.playing() 9131 || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1 9132 ) { 9133 this.audio.seek(this._currentTime / this.globalData.frameRate); 9134 } 9135 } 9136}; 9137 9138AudioElement.prototype.show = function () { 9139 // this.audio.play() 9140}; 9141 9142AudioElement.prototype.hide = function () { 9143 this.audio.pause(); 9144 this._isPlaying = false; 9145}; 9146 9147AudioElement.prototype.pause = function () { 9148 this.audio.pause(); 9149 this._isPlaying = false; 9150 this._canPlay = false; 9151}; 9152 9153AudioElement.prototype.resume = function () { 9154 this._canPlay = true; 9155}; 9156 9157AudioElement.prototype.setRate = function (rateValue) { 9158 this.audio.rate(rateValue); 9159}; 9160 9161AudioElement.prototype.volume = function (volumeValue) { 9162 this.audio.volume(volumeValue); 9163}; 9164 9165AudioElement.prototype.getBaseElement = function () { 9166 return null; 9167}; 9168 9169AudioElement.prototype.destroy = function () { 9170}; 9171 9172AudioElement.prototype.sourceRectAtTime = function () { 9173}; 9174 9175AudioElement.prototype.initExpressions = function () { 9176}; 9177 9178/* global createSizedArray, PropertyFactory, extendPrototype, SVGRenderer, ICompElement, SVGBaseElement */ 9179 9180function SVGCompElement(data, globalData, comp) { 9181 this.layers = data.layers; 9182 this.supports3d = true; 9183 this.completeLayers = false; 9184 this.pendingElements = []; 9185 this.elements = this.layers ? createSizedArray(this.layers.length) : []; 9186 // this.layerElement = createNS('g'); 9187 this.initElement(data, globalData, comp); 9188 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 9189} 9190 9191extendPrototype([SVGRenderer, ICompElement, SVGBaseElement], SVGCompElement); 9192 9193/* global extendPrototype, BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, 9194RenderableDOMElement, ITextElement, createSizedArray, createNS */ 9195 9196function SVGTextLottieElement(data, globalData, comp) { 9197 this.textSpans = []; 9198 this.renderType = 'svg'; 9199 this.initElement(data, globalData, comp); 9200} 9201 9202extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement); 9203 9204SVGTextLottieElement.prototype.createContent = function () { 9205 if (this.data.singleShape && !this.globalData.fontManager.chars) { 9206 this.textContainer = createNS('text'); 9207 } 9208}; 9209 9210SVGTextLottieElement.prototype.buildTextContents = function (textArray) { 9211 var i = 0; 9212 var len = textArray.length; 9213 var textContents = []; 9214 var currentTextContent = ''; 9215 while (i < len) { 9216 if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) { 9217 textContents.push(currentTextContent); 9218 currentTextContent = ''; 9219 } else { 9220 currentTextContent += textArray[i]; 9221 } 9222 i += 1; 9223 } 9224 textContents.push(currentTextContent); 9225 return textContents; 9226}; 9227 9228SVGTextLottieElement.prototype.buildNewText = function () { 9229 var i; 9230 var len; 9231 9232 var documentData = this.textProperty.currentData; 9233 this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0); 9234 if (documentData.fc) { 9235 this.layerElement.setAttribute('fill', this.buildColor(documentData.fc)); 9236 } else { 9237 this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)'); 9238 } 9239 if (documentData.sc) { 9240 this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc)); 9241 this.layerElement.setAttribute('stroke-width', documentData.sw); 9242 } 9243 this.layerElement.setAttribute('font-size', documentData.finalSize); 9244 var fontData = this.globalData.fontManager.getFontByName(documentData.f); 9245 if (fontData.fClass) { 9246 this.layerElement.setAttribute('class', fontData.fClass); 9247 } else { 9248 this.layerElement.setAttribute('font-family', fontData.fFamily); 9249 var fWeight = documentData.fWeight; 9250 var fStyle = documentData.fStyle; 9251 this.layerElement.setAttribute('font-style', fStyle); 9252 this.layerElement.setAttribute('font-weight', fWeight); 9253 } 9254 this.layerElement.setAttribute('aria-label', documentData.t); 9255 9256 var letters = documentData.l || []; 9257 var usesGlyphs = !!this.globalData.fontManager.chars; 9258 len = letters.length; 9259 9260 var tSpan; 9261 var matrixHelper = this.mHelper; 9262 var shapes; 9263 var shapeStr = ''; 9264 var singleShape = this.data.singleShape; 9265 var xPos = 0; 9266 var yPos = 0; 9267 var firstLine = true; 9268 var trackingOffset = documentData.tr * 0.001 * documentData.finalSize; 9269 if (singleShape && !usesGlyphs && !documentData.sz) { 9270 var tElement = this.textContainer; 9271 var justify = 'start'; 9272 switch (documentData.j) { 9273 case 1: 9274 justify = 'end'; 9275 break; 9276 case 2: 9277 justify = 'middle'; 9278 break; 9279 default: 9280 justify = 'start'; 9281 break; 9282 } 9283 tElement.setAttribute('text-anchor', justify); 9284 tElement.setAttribute('letter-spacing', trackingOffset); 9285 var textContent = this.buildTextContents(documentData.finalText); 9286 len = textContent.length; 9287 yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0; 9288 for (i = 0; i < len; i += 1) { 9289 tSpan = this.textSpans[i] || createNS('tspan'); 9290 tSpan.textContent = textContent[i]; 9291 tSpan.setAttribute('x', 0); 9292 tSpan.setAttribute('y', yPos); 9293 tSpan.style.display = 'inherit'; 9294 tElement.appendChild(tSpan); 9295 this.textSpans[i] = tSpan; 9296 yPos += documentData.finalLineHeight; 9297 } 9298 9299 this.layerElement.appendChild(tElement); 9300 } else { 9301 var cachedSpansLength = this.textSpans.length; 9302 var shapeData; 9303 var charData; 9304 for (i = 0; i < len; i += 1) { 9305 if (!usesGlyphs || !singleShape || i === 0) { 9306 tSpan = cachedSpansLength > i ? this.textSpans[i] : createNS(usesGlyphs ? 'path' : 'text'); 9307 if (cachedSpansLength <= i) { 9308 tSpan.setAttribute('stroke-linecap', 'butt'); 9309 tSpan.setAttribute('stroke-linejoin', 'round'); 9310 tSpan.setAttribute('stroke-miterlimit', '4'); 9311 this.textSpans[i] = tSpan; 9312 this.layerElement.appendChild(tSpan); 9313 } 9314 tSpan.style.display = 'inherit'; 9315 } 9316 9317 matrixHelper.reset(); 9318 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100); 9319 if (singleShape) { 9320 if (letters[i].n) { 9321 xPos = -trackingOffset; 9322 yPos += documentData.yOffset; 9323 yPos += firstLine ? 1 : 0; 9324 firstLine = false; 9325 } 9326 this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos); 9327 xPos += letters[i].l || 0; 9328 // xPos += letters[i].val === ' ' ? 0 : trackingOffset; 9329 xPos += trackingOffset; 9330 } 9331 if (usesGlyphs) { 9332 charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily); 9333 shapeData = (charData && charData.data) || {}; 9334 shapes = shapeData.shapes ? shapeData.shapes[0].it : []; 9335 if (!singleShape) { 9336 tSpan.setAttribute('d', this.createPathShape(matrixHelper, shapes)); 9337 } else { 9338 shapeStr += this.createPathShape(matrixHelper, shapes); 9339 } 9340 } else { 9341 if (singleShape) { 9342 tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')'); 9343 } 9344 tSpan.textContent = letters[i].val; 9345 tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); 9346 } 9347 // 9348 } 9349 if (singleShape && tSpan) { 9350 tSpan.setAttribute('d', shapeStr); 9351 } 9352 } 9353 while (i < this.textSpans.length) { 9354 this.textSpans[i].style.display = 'none'; 9355 i += 1; 9356 } 9357 9358 this._sizeChanged = true; 9359}; 9360 9361SVGTextLottieElement.prototype.sourceRectAtTime = function () { 9362 this.prepareFrame(this.comp.renderedFrame - this.data.st); 9363 this.renderInnerContent(); 9364 if (this._sizeChanged) { 9365 this._sizeChanged = false; 9366 var textBox = this.layerElement.getBBox(); 9367 this.bbox = { 9368 top: textBox.y, 9369 left: textBox.x, 9370 width: textBox.width, 9371 height: textBox.height, 9372 }; 9373 } 9374 return this.bbox; 9375}; 9376 9377SVGTextLottieElement.prototype.renderInnerContent = function () { 9378 if (!this.data.singleShape) { 9379 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag); 9380 if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) { 9381 this._sizeChanged = true; 9382 var i; 9383 var len; 9384 var renderedLetters = this.textAnimator.renderedLetters; 9385 9386 var letters = this.textProperty.currentData.l; 9387 9388 len = letters.length; 9389 var renderedLetter; 9390 var textSpan; 9391 for (i = 0; i < len; i += 1) { 9392 if (!letters[i].n) { 9393 renderedLetter = renderedLetters[i]; 9394 textSpan = this.textSpans[i]; 9395 if (renderedLetter._mdf.m) { 9396 textSpan.setAttribute('transform', renderedLetter.m); 9397 } 9398 if (renderedLetter._mdf.o) { 9399 textSpan.setAttribute('opacity', renderedLetter.o); 9400 } 9401 if (renderedLetter._mdf.sw) { 9402 textSpan.setAttribute('stroke-width', renderedLetter.sw); 9403 } 9404 if (renderedLetter._mdf.sc) { 9405 textSpan.setAttribute('stroke', renderedLetter.sc); 9406 } 9407 if (renderedLetter._mdf.fc) { 9408 textSpan.setAttribute('fill', renderedLetter.fc); 9409 } 9410 } 9411 } 9412 } 9413 } 9414}; 9415 9416/* global extendPrototype, BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, 9417FrameElement, RenderableDOMElement, Matrix, SVGStyleData, SVGStrokeStyleData, SVGFillStyleData, 9418SVGGradientFillStyleData, SVGGradientStrokeStyleData, locationHref, getBlendMode, ShapeGroupData, 9419TransformPropertyFactory, SVGTransformData, ShapePropertyFactory, SVGShapeData, SVGElementsRenderer, ShapeModifiers */ 9420 9421function SVGShapeElement(data, globalData, comp) { 9422 // List of drawable elements 9423 this.shapes = []; 9424 // Full shape data 9425 this.shapesData = data.shapes; 9426 // List of styles that will be applied to shapes 9427 this.stylesList = []; 9428 // List of modifiers that will be applied to shapes 9429 this.shapeModifiers = []; 9430 // List of items in shape tree 9431 this.itemsData = []; 9432 // List of items in previous shape tree 9433 this.processedElements = []; 9434 // List of animated components 9435 this.animatedContents = []; 9436 this.initElement(data, globalData, comp); 9437 // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties. 9438 // List of elements that have been created 9439 this.prevViewData = []; 9440 // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties. 9441} 9442 9443extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement); 9444 9445SVGShapeElement.prototype.initSecondaryElement = function () { 9446}; 9447 9448SVGShapeElement.prototype.identityMatrix = new Matrix(); 9449 9450SVGShapeElement.prototype.buildExpressionInterface = function () {}; 9451 9452SVGShapeElement.prototype.createContent = function () { 9453 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true); 9454 this.filterUniqueShapes(); 9455}; 9456 9457/* 9458This method searches for multiple shapes that affect a single element and one of them is animated 9459*/ 9460SVGShapeElement.prototype.filterUniqueShapes = function () { 9461 var i; 9462 var len = this.shapes.length; 9463 var shape; 9464 var j; 9465 var jLen = this.stylesList.length; 9466 var style; 9467 var tempShapes = []; 9468 var areAnimated = false; 9469 for (j = 0; j < jLen; j += 1) { 9470 style = this.stylesList[j]; 9471 areAnimated = false; 9472 tempShapes.length = 0; 9473 for (i = 0; i < len; i += 1) { 9474 shape = this.shapes[i]; 9475 if (shape.styles.indexOf(style) !== -1) { 9476 tempShapes.push(shape); 9477 areAnimated = shape._isAnimated || areAnimated; 9478 } 9479 } 9480 if (tempShapes.length > 1 && areAnimated) { 9481 this.setShapesAsAnimated(tempShapes); 9482 } 9483 } 9484}; 9485 9486SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) { 9487 var i; 9488 var len = shapes.length; 9489 for (i = 0; i < len; i += 1) { 9490 shapes[i].setAsAnimated(); 9491 } 9492}; 9493 9494SVGShapeElement.prototype.createStyleElement = function (data, level) { 9495 // TODO: prevent drawing of hidden styles 9496 var elementData; 9497 var styleOb = new SVGStyleData(data, level); 9498 9499 var pathElement = styleOb.pElem; 9500 if (data.ty === 'st') { 9501 elementData = new SVGStrokeStyleData(this, data, styleOb); 9502 } else if (data.ty === 'fl') { 9503 elementData = new SVGFillStyleData(this, data, styleOb); 9504 } else if (data.ty === 'gf' || data.ty === 'gs') { 9505 var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData; 9506 elementData = new GradientConstructor(this, data, styleOb); 9507 this.globalData.defs.appendChild(elementData.gf); 9508 if (elementData.maskId) { 9509 this.globalData.defs.appendChild(elementData.ms); 9510 this.globalData.defs.appendChild(elementData.of); 9511 pathElement.setAttribute('mask', 'url(' + locationHref + '#' + elementData.maskId + ')'); 9512 } 9513 } 9514 9515 if (data.ty === 'st' || data.ty === 'gs') { 9516 pathElement.setAttribute('stroke-linecap', this.lcEnum[data.lc] || 'round'); 9517 pathElement.setAttribute('stroke-linejoin', this.ljEnum[data.lj] || 'round'); 9518 pathElement.setAttribute('fill-opacity', '0'); 9519 if (data.lj === 1) { 9520 pathElement.setAttribute('stroke-miterlimit', data.ml); 9521 } 9522 } 9523 9524 if (data.r === 2) { 9525 pathElement.setAttribute('fill-rule', 'evenodd'); 9526 } 9527 9528 if (data.ln) { 9529 pathElement.setAttribute('id', data.ln); 9530 } 9531 if (data.cl) { 9532 pathElement.setAttribute('class', data.cl); 9533 } 9534 if (data.bm) { 9535 pathElement.style['mix-blend-mode'] = getBlendMode(data.bm); 9536 } 9537 this.stylesList.push(styleOb); 9538 this.addToAnimatedContents(data, elementData); 9539 return elementData; 9540}; 9541 9542SVGShapeElement.prototype.createGroupElement = function (data) { 9543 var elementData = new ShapeGroupData(); 9544 if (data.ln) { 9545 elementData.gr.setAttribute('id', data.ln); 9546 } 9547 if (data.cl) { 9548 elementData.gr.setAttribute('class', data.cl); 9549 } 9550 if (data.bm) { 9551 elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm); 9552 } 9553 return elementData; 9554}; 9555 9556SVGShapeElement.prototype.createTransformElement = function (data, container) { 9557 var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this); 9558 var elementData = new SVGTransformData(transformProperty, transformProperty.o, container); 9559 this.addToAnimatedContents(data, elementData); 9560 return elementData; 9561}; 9562 9563SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) { 9564 var ty = 4; 9565 if (data.ty === 'rc') { 9566 ty = 5; 9567 } else if (data.ty === 'el') { 9568 ty = 6; 9569 } else if (data.ty === 'sr') { 9570 ty = 7; 9571 } 9572 var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this); 9573 var elementData = new SVGShapeData(ownTransformers, level, shapeProperty); 9574 this.shapes.push(elementData); 9575 this.addShapeToModifiers(elementData); 9576 this.addToAnimatedContents(data, elementData); 9577 return elementData; 9578}; 9579 9580SVGShapeElement.prototype.addToAnimatedContents = function (data, element) { 9581 var i = 0; 9582 var len = this.animatedContents.length; 9583 while (i < len) { 9584 if (this.animatedContents[i].element === element) { 9585 return; 9586 } 9587 i += 1; 9588 } 9589 this.animatedContents.push({ 9590 fn: SVGElementsRenderer.createRenderFunction(data), 9591 element: element, 9592 data: data, 9593 }); 9594}; 9595 9596SVGShapeElement.prototype.setElementStyles = function (elementData) { 9597 var arr = elementData.styles; 9598 var j; 9599 var jLen = this.stylesList.length; 9600 for (j = 0; j < jLen; j += 1) { 9601 if (!this.stylesList[j].closed) { 9602 arr.push(this.stylesList[j]); 9603 } 9604 } 9605}; 9606 9607SVGShapeElement.prototype.reloadShapes = function () { 9608 this._isFirstFrame = true; 9609 var i; 9610 var len = this.itemsData.length; 9611 for (i = 0; i < len; i += 1) { 9612 this.prevViewData[i] = this.itemsData[i]; 9613 } 9614 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true); 9615 this.filterUniqueShapes(); 9616 len = this.dynamicProperties.length; 9617 for (i = 0; i < len; i += 1) { 9618 this.dynamicProperties[i].getValue(); 9619 } 9620 this.renderModifiers(); 9621}; 9622 9623SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) { 9624 var ownTransformers = [].concat(transformers); 9625 var i; 9626 var len = arr.length - 1; 9627 var j; 9628 var jLen; 9629 var ownStyles = []; 9630 var ownModifiers = []; 9631 var currentTransform; 9632 var modifier; 9633 var processedPos; 9634 for (i = len; i >= 0; i -= 1) { 9635 processedPos = this.searchProcessedElement(arr[i]); 9636 if (!processedPos) { 9637 arr[i]._render = render; 9638 } else { 9639 itemsData[i] = prevViewData[processedPos - 1]; 9640 } 9641 if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') { 9642 if (!processedPos) { 9643 itemsData[i] = this.createStyleElement(arr[i], level); 9644 } else { 9645 itemsData[i].style.closed = false; 9646 } 9647 if (arr[i]._render) { 9648 container.appendChild(itemsData[i].style.pElem); 9649 } 9650 ownStyles.push(itemsData[i].style); 9651 } else if (arr[i].ty === 'gr') { 9652 if (!processedPos) { 9653 itemsData[i] = this.createGroupElement(arr[i]); 9654 } else { 9655 jLen = itemsData[i].it.length; 9656 for (j = 0; j < jLen; j += 1) { 9657 itemsData[i].prevViewData[j] = itemsData[i].it[j]; 9658 } 9659 } 9660 this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render); 9661 if (arr[i]._render) { 9662 container.appendChild(itemsData[i].gr); 9663 } 9664 } else if (arr[i].ty === 'tr') { 9665 if (!processedPos) { 9666 itemsData[i] = this.createTransformElement(arr[i], container); 9667 } 9668 currentTransform = itemsData[i].transform; 9669 ownTransformers.push(currentTransform); 9670 } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') { 9671 if (!processedPos) { 9672 itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level); 9673 } 9674 this.setElementStyles(itemsData[i]); 9675 } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb') { 9676 if (!processedPos) { 9677 modifier = ShapeModifiers.getModifier(arr[i].ty); 9678 modifier.init(this, arr[i]); 9679 itemsData[i] = modifier; 9680 this.shapeModifiers.push(modifier); 9681 } else { 9682 modifier = itemsData[i]; 9683 modifier.closed = false;
vendor: 24,553 bytes, lines 9684-10263
9684 } 9685 ownModifiers.push(modifier); 9686 } else if (arr[i].ty === 'rp') { 9687 if (!processedPos) { 9688 modifier = ShapeModifiers.getModifier(arr[i].ty); 9689 itemsData[i] = modifier; 9690 modifier.init(this, arr, i, itemsData); 9691 this.shapeModifiers.push(modifier); 9692 render = false; 9693 } else { 9694 modifier = itemsData[i]; 9695 modifier.closed = true; 9696 } 9697 ownModifiers.push(modifier); 9698 } 9699 this.addProcessedElement(arr[i], i + 1); 9700 } 9701 len = ownStyles.length; 9702 for (i = 0; i < len; i += 1) { 9703 ownStyles[i].closed = true; 9704 } 9705 len = ownModifiers.length; 9706 for (i = 0; i < len; i += 1) { 9707 ownModifiers[i].closed = true; 9708 } 9709}; 9710 9711SVGShapeElement.prototype.renderInnerContent = function () { 9712 this.renderModifiers(); 9713 var i; 9714 var len = this.stylesList.length; 9715 for (i = 0; i < len; i += 1) { 9716 this.stylesList[i].reset(); 9717 } 9718 this.renderShape(); 9719 9720 for (i = 0; i < len; i += 1) { 9721 if (this.stylesList[i]._mdf || this._isFirstFrame) { 9722 if (this.stylesList[i].msElem) { 9723 this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d); 9724 // Adding M0 0 fixes same mask bug on all browsers 9725 this.stylesList[i].d = 'M0 0' + this.stylesList[i].d; 9726 } 9727 this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0'); 9728 } 9729 } 9730}; 9731 9732SVGShapeElement.prototype.renderShape = function () { 9733 var i; 9734 var len = this.animatedContents.length; 9735 var animatedContent; 9736 for (i = 0; i < len; i += 1) { 9737 animatedContent = this.animatedContents[i]; 9738 if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) { 9739 animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame); 9740 } 9741 } 9742}; 9743 9744SVGShapeElement.prototype.destroy = function () { 9745 this.destroyBaseElement(); 9746 this.shapesData = null; 9747 this.itemsData = null; 9748}; 9749 9750/* global createNS */ 9751 9752function SVGTintFilter(filter, filterManager) { 9753 this.filterManager = filterManager; 9754 var feColorMatrix = createNS('feColorMatrix'); 9755 feColorMatrix.setAttribute('type', 'matrix'); 9756 feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB'); 9757 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'); 9758 feColorMatrix.setAttribute('result', 'f1'); 9759 filter.appendChild(feColorMatrix); 9760 feColorMatrix = createNS('feColorMatrix'); 9761 feColorMatrix.setAttribute('type', 'matrix'); 9762 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 9763 feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0'); 9764 feColorMatrix.setAttribute('result', 'f2'); 9765 filter.appendChild(feColorMatrix); 9766 this.matrixFilter = feColorMatrix; 9767 if (filterManager.effectElements[2].p.v !== 100 || filterManager.effectElements[2].p.k) { 9768 var feMerge = createNS('feMerge'); 9769 filter.appendChild(feMerge); 9770 var feMergeNode; 9771 feMergeNode = createNS('feMergeNode'); 9772 feMergeNode.setAttribute('in', 'SourceGraphic'); 9773 feMerge.appendChild(feMergeNode); 9774 feMergeNode = createNS('feMergeNode'); 9775 feMergeNode.setAttribute('in', 'f2'); 9776 feMerge.appendChild(feMergeNode); 9777 } 9778} 9779 9780SVGTintFilter.prototype.renderFrame = function (forceRender) { 9781 if (forceRender || this.filterManager._mdf) { 9782 var colorBlack = this.filterManager.effectElements[0].p.v; 9783 var colorWhite = this.filterManager.effectElements[1].p.v; 9784 var opacity = this.filterManager.effectElements[2].p.v / 100; 9785 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 ' + opacity + ' 0'); 9786 } 9787}; 9788 9789/* global createNS */ 9790 9791function SVGFillFilter(filter, filterManager) { 9792 this.filterManager = filterManager; 9793 var feColorMatrix = createNS('feColorMatrix'); 9794 feColorMatrix.setAttribute('type', 'matrix'); 9795 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 9796 feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0'); 9797 filter.appendChild(feColorMatrix); 9798 this.matrixFilter = feColorMatrix; 9799} 9800SVGFillFilter.prototype.renderFrame = function (forceRender) { 9801 if (forceRender || this.filterManager._mdf) { 9802 var color = this.filterManager.effectElements[2].p.v; 9803 var opacity = this.filterManager.effectElements[6].p.v; 9804 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'); 9805 } 9806}; 9807 9808/* global createNS */ 9809 9810function SVGGaussianBlurEffect(filter, filterManager) { 9811 // Outset the filter region by 100% on all sides to accommodate blur expansion. 9812 filter.setAttribute('x', '-100%'); 9813 filter.setAttribute('y', '-100%'); 9814 filter.setAttribute('width', '300%'); 9815 filter.setAttribute('height', '300%'); 9816 9817 this.filterManager = filterManager; 9818 var feGaussianBlur = createNS('feGaussianBlur'); 9819 filter.appendChild(feGaussianBlur); 9820 this.feGaussianBlur = feGaussianBlur; 9821} 9822 9823SVGGaussianBlurEffect.prototype.renderFrame = function (forceRender) { 9824 if (forceRender || this.filterManager._mdf) { 9825 // Empirical value, matching AE's blur appearance. 9826 var kBlurrinessToSigma = 0.3; 9827 var sigma = this.filterManager.effectElements[0].p.v * kBlurrinessToSigma; 9828 9829 // Dimensions mapping: 9830 // 9831 // 1 -> horizontal & vertical 9832 // 2 -> horizontal only 9833 // 3 -> vertical only 9834 // 9835 var dimensions = this.filterManager.effectElements[1].p.v; 9836 var sigmaX = (dimensions == 3) ? 0 : sigma; // eslint-disable-line eqeqeq 9837 var sigmaY = (dimensions == 2) ? 0 : sigma; // eslint-disable-line eqeqeq 9838 9839 this.feGaussianBlur.setAttribute('stdDeviation', sigmaX + ' ' + sigmaY); 9840 9841 // Repeat edges mapping: 9842 // 9843 // 0 -> off -> duplicate 9844 // 1 -> on -> wrap 9845 var edgeMode = (this.filterManager.effectElements[2].p.v == 1) ? 'wrap' : 'duplicate'; // eslint-disable-line eqeqeq 9846 this.feGaussianBlur.setAttribute('edgeMode', edgeMode); 9847 } 9848}; 9849 9850/* global createNS, createElementID, locationHref, bmFloor */ 9851 9852function SVGStrokeEffect(elem, filterManager) { 9853 this.initialized = false; 9854 this.filterManager = filterManager; 9855 this.elem = elem; 9856 this.paths = []; 9857} 9858 9859SVGStrokeEffect.prototype.initialize = function () { 9860 var elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes; 9861 var path; 9862 var groupPath; 9863 var i; 9864 var len; 9865 if (this.filterManager.effectElements[1].p.v === 1) { 9866 len = this.elem.maskManager.masksProperties.length; 9867 i = 0; 9868 } else { 9869 i = this.filterManager.effectElements[0].p.v - 1; 9870 len = i + 1; 9871 } 9872 groupPath = createNS('g'); 9873 groupPath.setAttribute('fill', 'none'); 9874 groupPath.setAttribute('stroke-linecap', 'round'); 9875 groupPath.setAttribute('stroke-dashoffset', 1); 9876 for (i; i < len; i += 1) { 9877 path = createNS('path'); 9878 groupPath.appendChild(path); 9879 this.paths.push({ p: path, m: i }); 9880 } 9881 if (this.filterManager.effectElements[10].p.v === 3) { 9882 var mask = createNS('mask'); 9883 var id = createElementID(); 9884 mask.setAttribute('id', id); 9885 mask.setAttribute('mask-type', 'alpha'); 9886 mask.appendChild(groupPath); 9887 this.elem.globalData.defs.appendChild(mask); 9888 var g = createNS('g'); 9889 g.setAttribute('mask', 'url(' + locationHref + '#' + id + ')'); 9890 while (elemChildren[0]) { 9891 g.appendChild(elemChildren[0]); 9892 } 9893 this.elem.layerElement.appendChild(g); 9894 this.masker = mask; 9895 groupPath.setAttribute('stroke', '#fff'); 9896 } else if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) { 9897 if (this.filterManager.effectElements[10].p.v === 2) { 9898 elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes; 9899 while (elemChildren.length) { 9900 this.elem.layerElement.removeChild(elemChildren[0]); 9901 } 9902 } 9903 this.elem.layerElement.appendChild(groupPath); 9904 this.elem.layerElement.removeAttribute('mask'); 9905 groupPath.setAttribute('stroke', '#fff'); 9906 } 9907 this.initialized = true; 9908 this.pathMasker = groupPath; 9909}; 9910 9911SVGStrokeEffect.prototype.renderFrame = function (forceRender) { 9912 if (!this.initialized) { 9913 this.initialize(); 9914 } 9915 var i; 9916 var len = this.paths.length; 9917 var mask; 9918 var path; 9919 for (i = 0; i < len; i += 1) { 9920 if (this.paths[i].m !== -1) { 9921 mask = this.elem.maskManager.viewData[this.paths[i].m]; 9922 path = this.paths[i].p; 9923 if (forceRender || this.filterManager._mdf || mask.prop._mdf) { 9924 path.setAttribute('d', mask.lastPath); 9925 } 9926 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) { 9927 var dasharrayValue; 9928 if (this.filterManager.effectElements[7].p.v !== 0 || this.filterManager.effectElements[8].p.v !== 100) { 9929 var s = Math.min(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01; 9930 var e = Math.max(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01; 9931 var l = path.getTotalLength(); 9932 dasharrayValue = '0 0 0 ' + l * s + ' '; 9933 var lineLength = l * (e - s); 9934 var segment = 1 + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01; 9935 var units = Math.floor(lineLength / segment); 9936 var j; 9937 for (j = 0; j < units; j += 1) { 9938 dasharrayValue += '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01 + ' '; 9939 } 9940 dasharrayValue += '0 ' + l * 10 + ' 0 0'; 9941 } else { 9942 dasharrayValue = '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01; 9943 } 9944 path.setAttribute('stroke-dasharray', dasharrayValue); 9945 } 9946 } 9947 } 9948 if (forceRender || this.filterManager.effectElements[4].p._mdf) { 9949 this.pathMasker.setAttribute('stroke-width', this.filterManager.effectElements[4].p.v * 2); 9950 } 9951 9952 if (forceRender || this.filterManager.effectElements[6].p._mdf) { 9953 this.pathMasker.setAttribute('opacity', this.filterManager.effectElements[6].p.v); 9954 } 9955 if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) { 9956 if (forceRender || this.filterManager.effectElements[3].p._mdf) { 9957 var color = this.filterManager.effectElements[3].p.v; 9958 this.pathMasker.setAttribute('stroke', 'rgb(' + bmFloor(color[0] * 255) + ',' + bmFloor(color[1] * 255) + ',' + bmFloor(color[2] * 255) + ')'); 9959 } 9960 } 9961}; 9962 9963/* global createNS */ 9964 9965function SVGTritoneFilter(filter, filterManager) { 9966 this.filterManager = filterManager; 9967 var feColorMatrix = createNS('feColorMatrix'); 9968 feColorMatrix.setAttribute('type', 'matrix'); 9969 feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB'); 9970 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'); 9971 feColorMatrix.setAttribute('result', 'f1'); 9972 filter.appendChild(feColorMatrix); 9973 var feComponentTransfer = createNS('feComponentTransfer'); 9974 feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB'); 9975 filter.appendChild(feComponentTransfer); 9976 this.matrixFilter = feComponentTransfer; 9977 var feFuncR = createNS('feFuncR'); 9978 feFuncR.setAttribute('type', 'table'); 9979 feComponentTransfer.appendChild(feFuncR); 9980 this.feFuncR = feFuncR; 9981 var feFuncG = createNS('feFuncG'); 9982 feFuncG.setAttribute('type', 'table'); 9983 feComponentTransfer.appendChild(feFuncG); 9984 this.feFuncG = feFuncG; 9985 var feFuncB = createNS('feFuncB'); 9986 feFuncB.setAttribute('type', 'table'); 9987 feComponentTransfer.appendChild(feFuncB); 9988 this.feFuncB = feFuncB; 9989} 9990 9991SVGTritoneFilter.prototype.renderFrame = function (forceRender) { 9992 if (forceRender || this.filterManager._mdf) { 9993 var color1 = this.filterManager.effectElements[0].p.v; 9994 var color2 = this.filterManager.effectElements[1].p.v; 9995 var color3 = this.filterManager.effectElements[2].p.v; 9996 var tableR = color3[0] + ' ' + color2[0] + ' ' + color1[0]; 9997 var tableG = color3[1] + ' ' + color2[1] + ' ' + color1[1]; 9998 var tableB = color3[2] + ' ' + color2[2] + ' ' + color1[2]; 9999 this.feFuncR.setAttribute('tableValues', tableR); 10000 this.feFuncG.setAttribute('tableValues', tableG); 10001 this.feFuncB.setAttribute('tableValues', tableB); 10002 // var opacity = this.filterManager.effectElements[2].p.v/100; 10003 // 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 ' + opacity + ' 0'); 10004 } 10005}; 10006 10007/* global createNS */ 10008 10009function SVGProLevelsFilter(filter, filterManager) { 10010 this.filterManager = filterManager; 10011 var effectElements = this.filterManager.effectElements; 10012 var feComponentTransfer = createNS('feComponentTransfer'); 10013 10014 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) { 10015 this.feFuncR = this.createFeFunc('feFuncR', feComponentTransfer); 10016 } 10017 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) { 10018 this.feFuncG = this.createFeFunc('feFuncG', feComponentTransfer); 10019 } 10020 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) { 10021 this.feFuncB = this.createFeFunc('feFuncB', feComponentTransfer); 10022 } 10023 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) { 10024 this.feFuncA = this.createFeFunc('feFuncA', feComponentTransfer); 10025 } 10026 10027 if (this.feFuncR || this.feFuncG || this.feFuncB || this.feFuncA) { 10028 feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB'); 10029 filter.appendChild(feComponentTransfer); 10030 feComponentTransfer = createNS('feComponentTransfer'); 10031 } 10032 10033 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) { 10034 feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB'); 10035 filter.appendChild(feComponentTransfer); 10036 this.feFuncRComposed = this.createFeFunc('feFuncR', feComponentTransfer); 10037 this.feFuncGComposed = this.createFeFunc('feFuncG', feComponentTransfer); 10038 this.feFuncBComposed = this.createFeFunc('feFuncB', feComponentTransfer); 10039 } 10040} 10041 10042SVGProLevelsFilter.prototype.createFeFunc = function (type, feComponentTransfer) { 10043 var feFunc = createNS(type); 10044 feFunc.setAttribute('type', 'table'); 10045 feComponentTransfer.appendChild(feFunc); 10046 return feFunc; 10047}; 10048 10049SVGProLevelsFilter.prototype.getTableValue = function (inputBlack, inputWhite, gamma, outputBlack, outputWhite) { 10050 var cnt = 0; 10051 var segments = 256; 10052 var perc; 10053 var min = Math.min(inputBlack, inputWhite); 10054 var max = Math.max(inputBlack, inputWhite); 10055 var table = Array.call(null, { length: segments }); 10056 var colorValue; 10057 var pos = 0; 10058 var outputDelta = outputWhite - outputBlack; 10059 var inputDelta = inputWhite - inputBlack; 10060 while (cnt <= 256) { 10061 perc = cnt / 256; 10062 if (perc <= min) { 10063 colorValue = inputDelta < 0 ? outputWhite : outputBlack; 10064 } else if (perc >= max) { 10065 colorValue = inputDelta < 0 ? outputBlack : outputWhite; 10066 } else { 10067 colorValue = (outputBlack + outputDelta * Math.pow((perc - inputBlack) / inputDelta, 1 / gamma)); 10068 } 10069 table[pos] = colorValue; 10070 pos += 1; 10071 cnt += 256 / (segments - 1); 10072 } 10073 return table.join(' '); 10074}; 10075 10076SVGProLevelsFilter.prototype.renderFrame = function (forceRender) { 10077 if (forceRender || this.filterManager._mdf) { 10078 var val; 10079 var effectElements = this.filterManager.effectElements; 10080 if (this.feFuncRComposed && (forceRender || effectElements[3].p._mdf || effectElements[4].p._mdf || effectElements[5].p._mdf || effectElements[6].p._mdf || effectElements[7].p._mdf)) { 10081 val = this.getTableValue(effectElements[3].p.v, effectElements[4].p.v, effectElements[5].p.v, effectElements[6].p.v, effectElements[7].p.v); 10082 this.feFuncRComposed.setAttribute('tableValues', val); 10083 this.feFuncGComposed.setAttribute('tableValues', val); 10084 this.feFuncBComposed.setAttribute('tableValues', val); 10085 } 10086 10087 if (this.feFuncR && (forceRender || effectElements[10].p._mdf || effectElements[11].p._mdf || effectElements[12].p._mdf || effectElements[13].p._mdf || effectElements[14].p._mdf)) { 10088 val = this.getTableValue(effectElements[10].p.v, effectElements[11].p.v, effectElements[12].p.v, effectElements[13].p.v, effectElements[14].p.v); 10089 this.feFuncR.setAttribute('tableValues', val); 10090 } 10091 10092 if (this.feFuncG && (forceRender || effectElements[17].p._mdf || effectElements[18].p._mdf || effectElements[19].p._mdf || effectElements[20].p._mdf || effectElements[21].p._mdf)) { 10093 val = this.getTableValue(effectElements[17].p.v, effectElements[18].p.v, effectElements[19].p.v, effectElements[20].p.v, effectElements[21].p.v); 10094 this.feFuncG.setAttribute('tableValues', val); 10095 } 10096 10097 if (this.feFuncB && (forceRender || effectElements[24].p._mdf || effectElements[25].p._mdf || effectElements[26].p._mdf || effectElements[27].p._mdf || effectElements[28].p._mdf)) { 10098 val = this.getTableValue(effectElements[24].p.v, effectElements[25].p.v, effectElements[26].p.v, effectElements[27].p.v, effectElements[28].p.v); 10099 this.feFuncB.setAttribute('tableValues', val); 10100 } 10101 10102 if (this.feFuncA && (forceRender || effectElements[31].p._mdf || effectElements[32].p._mdf || effectElements[33].p._mdf || effectElements[34].p._mdf || effectElements[35].p._mdf)) { 10103 val = this.getTableValue(effectElements[31].p.v, effectElements[32].p.v, effectElements[33].p.v, effectElements[34].p.v, effectElements[35].p.v); 10104 this.feFuncA.setAttribute('tableValues', val); 10105 } 10106 } 10107}; 10108 10109/* global createNS, rgbToHex, degToRads */ 10110 10111function SVGDropShadowEffect(filter, filterManager) { 10112 var filterSize = filterManager.container.globalData.renderConfig.filterSize; 10113 filter.setAttribute('x', filterSize.x); 10114 filter.setAttribute('y', filterSize.y); 10115 filter.setAttribute('width', filterSize.width); 10116 filter.setAttribute('height', filterSize.height); 10117 this.filterManager = filterManager; 10118 10119 var feGaussianBlur = createNS('feGaussianBlur'); 10120 feGaussianBlur.setAttribute('in', 'SourceAlpha'); 10121 feGaussianBlur.setAttribute('result', 'drop_shadow_1'); 10122 feGaussianBlur.setAttribute('stdDeviation', '0'); 10123 this.feGaussianBlur = feGaussianBlur; 10124 filter.appendChild(feGaussianBlur); 10125 10126 var feOffset = createNS('feOffset'); 10127 feOffset.setAttribute('dx', '25'); 10128 feOffset.setAttribute('dy', '0'); 10129 feOffset.setAttribute('in', 'drop_shadow_1'); 10130 feOffset.setAttribute('result', 'drop_shadow_2'); 10131 this.feOffset = feOffset; 10132 filter.appendChild(feOffset); 10133 var feFlood = createNS('feFlood'); 10134 feFlood.setAttribute('flood-color', '#00ff00'); 10135 feFlood.setAttribute('flood-opacity', '1'); 10136 feFlood.setAttribute('result', 'drop_shadow_3'); 10137 this.feFlood = feFlood; 10138 filter.appendChild(feFlood); 10139 10140 var feComposite = createNS('feComposite'); 10141 feComposite.setAttribute('in', 'drop_shadow_3'); 10142 feComposite.setAttribute('in2', 'drop_shadow_2'); 10143 feComposite.setAttribute('operator', 'in'); 10144 feComposite.setAttribute('result', 'drop_shadow_4'); 10145 filter.appendChild(feComposite); 10146 10147 var feMerge = createNS('feMerge'); 10148 filter.appendChild(feMerge); 10149 var feMergeNode; 10150 feMergeNode = createNS('feMergeNode'); 10151 feMerge.appendChild(feMergeNode); 10152 feMergeNode = createNS('feMergeNode'); 10153 feMergeNode.setAttribute('in', 'SourceGraphic'); 10154 this.feMergeNode = feMergeNode; 10155 this.feMerge = feMerge; 10156 this.originalNodeAdded = false; 10157 feMerge.appendChild(feMergeNode); 10158} 10159 10160SVGDropShadowEffect.prototype.renderFrame = function (forceRender) { 10161 if (forceRender || this.filterManager._mdf) { 10162 if (forceRender || this.filterManager.effectElements[4].p._mdf) { 10163 this.feGaussianBlur.setAttribute('stdDeviation', this.filterManager.effectElements[4].p.v / 4); 10164 } 10165 if (forceRender || this.filterManager.effectElements[0].p._mdf) { 10166 var col = this.filterManager.effectElements[0].p.v; 10167 this.feFlood.setAttribute('flood-color', rgbToHex(Math.round(col[0] * 255), Math.round(col[1] * 255), Math.round(col[2] * 255))); 10168 } 10169 if (forceRender || this.filterManager.effectElements[1].p._mdf) { 10170 this.feFlood.setAttribute('flood-opacity', this.filterManager.effectElements[1].p.v / 255); 10171 } 10172 if (forceRender || this.filterManager.effectElements[2].p._mdf || this.filterManager.effectElements[3].p._mdf) { 10173 var distance = this.filterManager.effectElements[3].p.v; 10174 var angle = (this.filterManager.effectElements[2].p.v - 90) * degToRads; 10175 var x = distance * Math.cos(angle); 10176 var y = distance * Math.sin(angle); 10177 this.feOffset.setAttribute('dx', x); 10178 this.feOffset.setAttribute('dy', y); 10179 } 10180 /* if(forceRender || this.filterManager.effectElements[5].p._mdf){ 10181 if(this.filterManager.effectElements[5].p.v === 1 && this.originalNodeAdded) { 10182 this.feMerge.removeChild(this.feMergeNode); 10183 this.originalNodeAdded = false; 10184 } else if(this.filterManager.effectElements[5].p.v === 0 && !this.originalNodeAdded) { 10185 this.feMerge.appendChild(this.feMergeNode); 10186 this.originalNodeAdded = true; 10187 } 10188 } */ 10189 } 10190}; 10191 10192/* global createElementID, createNS */ 10193 10194var _svgMatteSymbols = []; 10195 10196function SVGMatte3Effect(filterElem, filterManager, elem) { 10197 this.initialized = false; 10198 this.filterManager = filterManager; 10199 this.filterElem = filterElem; 10200 this.elem = elem; 10201 elem.matteElement = createNS('g'); 10202 elem.matteElement.appendChild(elem.layerElement); 10203 elem.matteElement.appendChild(elem.transformedElement); 10204 elem.baseElement = elem.matteElement; 10205} 10206 10207SVGMatte3Effect.prototype.findSymbol = function (mask) { 10208 var i = 0; 10209 var len = _svgMatteSymbols.length; 10210 while (i < len) { 10211 if (_svgMatteSymbols[i] === mask) { 10212 return _svgMatteSymbols[i]; 10213 } 10214 i += 1; 10215 } 10216 return null; 10217}; 10218 10219SVGMatte3Effect.prototype.replaceInParent = function (mask, symbolId) { 10220 var parentNode = mask.layerElement.parentNode; 10221 if (!parentNode) { 10222 return; 10223 } 10224 var children = parentNode.children; 10225 var i = 0; 10226 var len = children.length; 10227 while (i < len) { 10228 if (children[i] === mask.layerElement) { 10229 break; 10230 } 10231 i += 1; 10232 } 10233 var nextChild; 10234 if (i <= len - 2) { 10235 nextChild = children[i + 1]; 10236 } 10237 var useElem = createNS('use'); 10238 useElem.setAttribute('href', '#' + symbolId); 10239 if (nextChild) { 10240 parentNode.insertBefore(useElem, nextChild); 10241 } else { 10242 parentNode.appendChild(useElem); 10243 } 10244}; 10245 10246SVGMatte3Effect.prototype.setElementAsMask = function (elem, mask) { 10247 if (!this.findSymbol(mask)) { 10248 var symbolId = createElementID(); 10249 var masker = createNS('mask'); 10250 masker.setAttribute('id', mask.layerId); 10251 masker.setAttribute('mask-type', 'alpha'); 10252 _svgMatteSymbols.push(mask); 10253 var defs = elem.globalData.defs; 10254 defs.appendChild(masker); 10255 var symbol = createNS('symbol'); 10256 symbol.setAttribute('id', symbolId); 10257 this.replaceInParent(mask, symbolId); 10258 symbol.appendChild(mask.layerElement); 10259 defs.appendChild(symbol); 10260 var useElem = createNS('use'); 10261 useElem.setAttribute('href', '#' + symbolId); 10262 masker.appendChild(useElem); 10263 mask.data.hd = false;
10264 mask.show(); 10265 } 10266 elem.setMatte(mask.layerId); 10267}; 10268 10269SVGMatte3Effect.prototype.initialize = function () { 10270 var ind = this.filterManager.effectElements[0].p.v; 10271 var elements = this.elem.comp.elements; 10272 var i = 0; 10273 var len = elements.length; 10274 while (i < len) { 10275 if (elements[i] && elements[i].data.ind === ind) { 10276 this.setElementAsMask(this.elem, elements[i]); 10277 } 10278 i += 1; 10279 } 10280 this.initialized = true; 10281}; 10282 10283SVGMatte3Effect.prototype.renderFrame = function () { 10284 if (!this.initialized) { 10285 this.initialize(); 10286 } 10287}; 10288 10289/* global createElementID, filtersFactory, SVGTintFilter, SVGFillFilter, SVGStrokeEffect, SVGTritoneFilter, 10290SVGProLevelsFilter, SVGDropShadowEffect, SVGMatte3Effect, SVGGaussianBlurEffect, locationHref */ 10291 10292function SVGEffects(elem) { 10293 var i; 10294 var len = elem.data.ef ? elem.data.ef.length : 0; 10295 var filId = createElementID(); 10296 var fil = filtersFactory.createFilter(filId); 10297 var count = 0; 10298 this.filters = []; 10299 var filterManager; 10300 for (i = 0; i < len; i += 1) { 10301 filterManager = null; 10302 if (elem.data.ef[i].ty === 20) { 10303 count += 1; 10304 filterManager = new SVGTintFilter(fil, elem.effectsManager.effectElements[i]); 10305 } else if (elem.data.ef[i].ty === 21) { 10306 count += 1; 10307 filterManager = new SVGFillFilter(fil, elem.effectsManager.effectElements[i]); 10308 } else if (elem.data.ef[i].ty === 22) { 10309 filterManager = new SVGStrokeEffect(elem, elem.effectsManager.effectElements[i]); 10310 } else if (elem.data.ef[i].ty === 23) { 10311 count += 1; 10312 filterManager = new SVGTritoneFilter(fil, elem.effectsManager.effectElements[i]); 10313 } else if (elem.data.ef[i].ty === 24) { 10314 count += 1; 10315 filterManager = new SVGProLevelsFilter(fil, elem.effectsManager.effectElements[i]); 10316 } else if (elem.data.ef[i].ty === 25) { 10317 count += 1; 10318 filterManager = new SVGDropShadowEffect(fil, elem.effectsManager.effectElements[i]); 10319 } else if (elem.data.ef[i].ty === 28) { 10320 // count += 1; 10321 filterManager = new SVGMatte3Effect(fil, elem.effectsManager.effectElements[i], elem); 10322 } else if (elem.data.ef[i].ty === 29) { 10323 count += 1; 10324 filterManager = new SVGGaussianBlurEffect(fil, elem.effectsManager.effectElements[i]); 10325 } 10326 if (filterManager) { 10327 this.filters.push(filterManager); 10328 } 10329 } 10330 if (count) { 10331 elem.globalData.defs.appendChild(fil); 10332 elem.layerElement.setAttribute('filter', 'url(' + locationHref + '#' + filId + ')'); 10333 } 10334 if (this.filters.length) { 10335 elem.addRenderableComponent(this); 10336 } 10337} 10338 10339SVGEffects.prototype.renderFrame = function (_isFirstFrame) { 10340 var i; 10341 var len = this.filters.length; 10342 for (i = 0; i < len; i += 1) { 10343 this.filters[i].renderFrame(_isFirstFrame); 10344 } 10345}; 10346 10347/* global Matrix, createTypedArray */ 10348 10349function CVContextData() { 10350 this.saved = []; 10351 this.cArrPos = 0; 10352 this.cTr = new Matrix(); 10353 this.cO = 1; 10354 var i; 10355 var len = 15; 10356 this.savedOp = createTypedArray('float32', len); 10357 for (i = 0; i < len; i += 1) { 10358 this.saved[i] = createTypedArray('float32', 16); 10359 } 10360 this._length = len; 10361} 10362 10363CVContextData.prototype.duplicate = function () { 10364 var newLength = this._length * 2; 10365 var currentSavedOp = this.savedOp; 10366 this.savedOp = createTypedArray('float32', newLength); 10367 this.savedOp.set(currentSavedOp); 10368 var i = 0; 10369 for (i = this._length; i < newLength; i += 1) { 10370 this.saved[i] = createTypedArray('float32', 16); 10371 } 10372 this._length = newLength; 10373}; 10374 10375CVContextData.prototype.reset = function () { 10376 this.cArrPos = 0; 10377 this.cTr.reset(); 10378 this.cO = 1; 10379}; 10380 10381/* global CVEffects, getBlendMode, CVMaskElement, Matrix */ 10382 10383function CVBaseElement() { 10384} 10385 10386CVBaseElement.prototype = { 10387 createElements: function () {}, 10388 initRendererElement: function () {}, 10389 createContainerElements: function () { 10390 this.canvasContext = this.globalData.canvasContext; 10391 this.renderableEffectsManager = new CVEffects(this); 10392 }, 10393 createContent: function () {}, 10394 setBlendMode: function () { 10395 var globalData = this.globalData; 10396 if (globalData.blendMode !== this.data.bm) { 10397 globalData.blendMode = this.data.bm;
vendor: 17,520 bytes, lines 10398-10919
10398 var blendModeValue = getBlendMode(this.data.bm); 10399 globalData.canvasContext.globalCompositeOperation = blendModeValue; 10400 } 10401 }, 10402 createRenderableComponents: function () { 10403 this.maskManager = new CVMaskElement(this.data, this); 10404 }, 10405 hideElement: function () { 10406 if (!this.hidden && (!this.isInRange || this.isTransparent)) { 10407 this.hidden = true; 10408 } 10409 }, 10410 showElement: function () { 10411 if (this.isInRange && !this.isTransparent) { 10412 this.hidden = false; 10413 this._isFirstFrame = true; 10414 this.maskManager._isFirstFrame = true; 10415 } 10416 }, 10417 renderFrame: function () { 10418 if (this.hidden || this.data.hd) { 10419 return; 10420 } 10421 this.renderTransform(); 10422 this.renderRenderable(); 10423 this.setBlendMode(); 10424 var forceRealStack = this.data.ty === 0; 10425 this.globalData.renderer.save(forceRealStack); 10426 this.globalData.renderer.ctxTransform(this.finalTransform.mat.props); 10427 this.globalData.renderer.ctxOpacity(this.finalTransform.mProp.o.v); 10428 this.renderInnerContent(); 10429 this.globalData.renderer.restore(forceRealStack); 10430 if (this.maskManager.hasMasks) { 10431 this.globalData.renderer.restore(true); 10432 } 10433 if (this._isFirstFrame) { 10434 this._isFirstFrame = false; 10435 } 10436 }, 10437 destroy: function () { 10438 this.canvasContext = null; 10439 this.data = null; 10440 this.globalData = null; 10441 this.maskManager.destroy(); 10442 }, 10443 mHelper: new Matrix(), 10444}; 10445CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement; 10446CVBaseElement.prototype.show = CVBaseElement.prototype.showElement; 10447 10448/* global extendPrototype, BaseElement, TransformElement, CVBaseElement,HierarchyElement, FrameElement, 10449RenderableElement, SVGShapeElement, IImageElement, createTag */ 10450 10451function CVImageElement(data, globalData, comp) { 10452 this.assetData = globalData.getAssetData(data.refId); 10453 this.img = globalData.imageLoader.getImage(this.assetData); 10454 this.initElement(data, globalData, comp); 10455} 10456extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement); 10457 10458CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement; 10459CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame; 10460 10461CVImageElement.prototype.createContent = function () { 10462 if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) { 10463 var canvas = createTag('canvas'); 10464 canvas.width = this.assetData.w; 10465 canvas.height = this.assetData.h; 10466 var ctx = canvas.getContext('2d'); 10467 10468 var imgW = this.img.width; 10469 var imgH = this.img.height; 10470 var imgRel = imgW / imgH; 10471 var canvasRel = this.assetData.w / this.assetData.h; 10472 var widthCrop; 10473 var heightCrop; 10474 var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio; 10475 if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) { 10476 heightCrop = imgH; 10477 widthCrop = heightCrop * canvasRel; 10478 } else { 10479 widthCrop = imgW; 10480 heightCrop = widthCrop / canvasRel; 10481 } 10482 ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h); 10483 this.img = canvas; 10484 } 10485}; 10486 10487CVImageElement.prototype.renderInnerContent = function () { 10488 this.canvasContext.drawImage(this.img, 0, 0); 10489}; 10490 10491CVImageElement.prototype.destroy = function () { 10492 this.img = null; 10493}; 10494 10495/* global createSizedArray, PropertyFactory, extendPrototype, CanvasRenderer, ICompElement, CVBaseElement */ 10496 10497function CVCompElement(data, globalData, comp) { 10498 this.completeLayers = false; 10499 this.layers = data.layers; 10500 this.pendingElements = []; 10501 this.elements = createSizedArray(this.layers.length); 10502 this.initElement(data, globalData, comp); 10503 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 10504} 10505 10506extendPrototype([CanvasRenderer, ICompElement, CVBaseElement], CVCompElement); 10507 10508CVCompElement.prototype.renderInnerContent = function () { 10509 var ctx = this.canvasContext; 10510 ctx.beginPath(); 10511 ctx.moveTo(0, 0); 10512 ctx.lineTo(this.data.w, 0); 10513 ctx.lineTo(this.data.w, this.data.h); 10514 ctx.lineTo(0, this.data.h); 10515 ctx.lineTo(0, 0); 10516 ctx.clip(); 10517 var i; 10518 var len = this.layers.length; 10519 for (i = len - 1; i >= 0; i -= 1) { 10520 if (this.completeLayers || this.elements[i]) { 10521 this.elements[i].renderFrame(); 10522 } 10523 } 10524}; 10525 10526CVCompElement.prototype.destroy = function () { 10527 var i; 10528 var len = this.layers.length; 10529 for (i = len - 1; i >= 0; i -= 1) { 10530 if (this.elements[i]) { 10531 this.elements[i].destroy(); 10532 } 10533 } 10534 this.layers = null; 10535 this.elements = null; 10536}; 10537 10538/* global createSizedArray, ShapePropertyFactory, MaskElement */ 10539 10540function CVMaskElement(data, element) { 10541 this.data = data; 10542 this.element = element; 10543 this.masksProperties = this.data.masksProperties || []; 10544 this.viewData = createSizedArray(this.masksProperties.length); 10545 var i; 10546 var len = this.masksProperties.length; 10547 var hasMasks = false; 10548 for (i = 0; i < len; i += 1) { 10549 if (this.masksProperties[i].mode !== 'n') { 10550 hasMasks = true; 10551 } 10552 this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3); 10553 } 10554 this.hasMasks = hasMasks; 10555 if (hasMasks) { 10556 this.element.addRenderableComponent(this); 10557 } 10558} 10559 10560CVMaskElement.prototype.renderFrame = function () { 10561 if (!this.hasMasks) { 10562 return; 10563 } 10564 var transform = this.element.finalTransform.mat; 10565 var ctx = this.element.canvasContext; 10566 var i; 10567 var len = this.masksProperties.length; 10568 var pt; 10569 var pts; 10570 var data; 10571 ctx.beginPath(); 10572 for (i = 0; i < len; i += 1) { 10573 if (this.masksProperties[i].mode !== 'n') { 10574 if (this.masksProperties[i].inv) { 10575 ctx.moveTo(0, 0); 10576 ctx.lineTo(this.element.globalData.compSize.w, 0); 10577 ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h); 10578 ctx.lineTo(0, this.element.globalData.compSize.h); 10579 ctx.lineTo(0, 0); 10580 } 10581 data = this.viewData[i].v; 10582 pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0); 10583 ctx.moveTo(pt[0], pt[1]); 10584 var j; 10585 var jLen = data._length; 10586 for (j = 1; j < jLen; j += 1) { 10587 pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]); 10588 ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]); 10589 } 10590 pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]); 10591 ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]); 10592 } 10593 } 10594 this.element.globalData.renderer.save(true); 10595 ctx.clip(); 10596}; 10597 10598CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty; 10599 10600CVMaskElement.prototype.destroy = function () { 10601 this.element = null; 10602}; 10603 10604/* global ShapeTransformManager, extendPrototype, BaseElement, TransformElement, CVBaseElement, IShapeElement, 10605HierarchyElement, FrameElement, RenderableElement, RenderableDOMElement, PropertyFactory, degToRads, GradientProperty, 10606DashProperty, TransformPropertyFactory, CVShapeData, ShapeModifiers, bmFloor */ 10607 10608function CVShapeElement(data, globalData, comp) { 10609 this.shapes = []; 10610 this.shapesData = data.shapes; 10611 this.stylesList = []; 10612 this.itemsData = []; 10613 this.prevViewData = []; 10614 this.shapeModifiers = []; 10615 this.processedElements = []; 10616 this.transformsManager = new ShapeTransformManager(); 10617 this.initElement(data, globalData, comp); 10618} 10619 10620extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement); 10621 10622CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement; 10623 10624CVShapeElement.prototype.transformHelper = { opacity: 1, _opMdf: false }; 10625 10626CVShapeElement.prototype.dashResetter = []; 10627 10628CVShapeElement.prototype.createContent = function () { 10629 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []); 10630}; 10631 10632CVShapeElement.prototype.createStyleElement = function (data, transforms) { 10633 var styleElem = { 10634 data: data, 10635 type: data.ty, 10636 preTransforms: this.transformsManager.addTransformSequence(transforms), 10637 transforms: [], 10638 elements: [], 10639 closed: data.hd === true, 10640 }; 10641 var elementData = {}; 10642 if (data.ty === 'fl' || data.ty === 'st') { 10643 elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this); 10644 if (!elementData.c.k) { 10645 styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')'; 10646 } 10647 } else if (data.ty === 'gf' || data.ty === 'gs') { 10648 elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this); 10649 elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this); 10650 elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, 0.01, this); 10651 elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this); 10652 elementData.g = new GradientProperty(this, data.g, this); 10653 } 10654 elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this); 10655 if (data.ty === 'st' || data.ty === 'gs') { 10656 styleElem.lc = this.lcEnum[data.lc] || 'round'; 10657 styleElem.lj = this.ljEnum[data.lj] || 'round'; 10658 if (data.lj == 1) { // eslint-disable-line eqeqeq 10659 styleElem.ml = data.ml; 10660 } 10661 elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this); 10662 if (!elementData.w.k) { 10663 styleElem.wi = elementData.w.v; 10664 } 10665 if (data.d) { 10666 var d = new DashProperty(this, data.d, 'canvas', this); 10667 elementData.d = d; 10668 if (!elementData.d.k) { 10669 styleElem.da = elementData.d.dashArray; 10670 styleElem.do = elementData.d.dashoffset[0]; 10671 } 10672 } 10673 } else { 10674 styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero'; 10675 } 10676 this.stylesList.push(styleElem); 10677 elementData.style = styleElem; 10678 return elementData; 10679}; 10680 10681CVShapeElement.prototype.createGroupElement = function () { 10682 var elementData = { 10683 it: [], 10684 prevViewData: [], 10685 }; 10686 return elementData; 10687}; 10688 10689CVShapeElement.prototype.createTransformElement = function (data) { 10690 var elementData = { 10691 transform: { 10692 opacity: 1, 10693 _opMdf: false, 10694 key: this.transformsManager.getNewKey(), 10695 op: PropertyFactory.getProp(this, data.o, 0, 0.01, this), 10696 mProps: TransformPropertyFactory.getTransformProperty(this, data, this), 10697 }, 10698 }; 10699 return elementData; 10700}; 10701 10702CVShapeElement.prototype.createShapeElement = function (data) { 10703 var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager); 10704 10705 this.shapes.push(elementData); 10706 this.addShapeToModifiers(elementData); 10707 return elementData; 10708}; 10709 10710CVShapeElement.prototype.reloadShapes = function () { 10711 this._isFirstFrame = true; 10712 var i; 10713 var len = this.itemsData.length; 10714 for (i = 0; i < len; i += 1) { 10715 this.prevViewData[i] = this.itemsData[i]; 10716 } 10717 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []); 10718 len = this.dynamicProperties.length; 10719 for (i = 0; i < len; i += 1) { 10720 this.dynamicProperties[i].getValue(); 10721 } 10722 this.renderModifiers(); 10723 this.transformsManager.processSequences(this._isFirstFrame); 10724}; 10725 10726CVShapeElement.prototype.addTransformToStyleList = function (transform) { 10727 var i; 10728 var len = this.stylesList.length; 10729 for (i = 0; i < len; i += 1) { 10730 if (!this.stylesList[i].closed) { 10731 this.stylesList[i].transforms.push(transform); 10732 } 10733 } 10734}; 10735 10736CVShapeElement.prototype.removeTransformFromStyleList = function () { 10737 var i; 10738 var len = this.stylesList.length; 10739 for (i = 0; i < len; i += 1) { 10740 if (!this.stylesList[i].closed) { 10741 this.stylesList[i].transforms.pop(); 10742 } 10743 } 10744}; 10745 10746CVShapeElement.prototype.closeStyles = function (styles) { 10747 var i; 10748 var len = styles.length; 10749 for (i = 0; i < len; i += 1) { 10750 styles[i].closed = true; 10751 } 10752}; 10753 10754CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) { 10755 var i; 10756 var len = arr.length - 1; 10757 var j; 10758 var jLen; 10759 var ownStyles = []; 10760 var ownModifiers = []; 10761 var processedPos; 10762 var modifier; 10763 var currentTransform; 10764 var ownTransforms = [].concat(transforms); 10765 for (i = len; i >= 0; i -= 1) { 10766 processedPos = this.searchProcessedElement(arr[i]); 10767 if (!processedPos) { 10768 arr[i]._shouldRender = shouldRender; 10769 } else { 10770 itemsData[i] = prevViewData[processedPos - 1]; 10771 } 10772 if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') { 10773 if (!processedPos) { 10774 itemsData[i] = this.createStyleElement(arr[i], ownTransforms); 10775 } else { 10776 itemsData[i].style.closed = false; 10777 } 10778 10779 ownStyles.push(itemsData[i].style); 10780 } else if (arr[i].ty === 'gr') { 10781 if (!processedPos) { 10782 itemsData[i] = this.createGroupElement(arr[i]); 10783 } else { 10784 jLen = itemsData[i].it.length; 10785 for (j = 0; j < jLen; j += 1) { 10786 itemsData[i].prevViewData[j] = itemsData[i].it[j]; 10787 } 10788 } 10789 this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms); 10790 } else if (arr[i].ty === 'tr') { 10791 if (!processedPos) { 10792 currentTransform = this.createTransformElement(arr[i]); 10793 itemsData[i] = currentTransform; 10794 } 10795 ownTransforms.push(itemsData[i]); 10796 this.addTransformToStyleList(itemsData[i]); 10797 } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') { 10798 if (!processedPos) { 10799 itemsData[i] = this.createShapeElement(arr[i]); 10800 } 10801 } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb') { 10802 if (!processedPos) { 10803 modifier = ShapeModifiers.getModifier(arr[i].ty); 10804 modifier.init(this, arr[i]); 10805 itemsData[i] = modifier; 10806 this.shapeModifiers.push(modifier); 10807 } else { 10808 modifier = itemsData[i]; 10809 modifier.closed = false; 10810 } 10811 ownModifiers.push(modifier); 10812 } else if (arr[i].ty === 'rp') { 10813 if (!processedPos) { 10814 modifier = ShapeModifiers.getModifier(arr[i].ty); 10815 itemsData[i] = modifier; 10816 modifier.init(this, arr, i, itemsData); 10817 this.shapeModifiers.push(modifier); 10818 shouldRender = false; 10819 } else { 10820 modifier = itemsData[i]; 10821 modifier.closed = true; 10822 } 10823 ownModifiers.push(modifier); 10824 } 10825 this.addProcessedElement(arr[i], i + 1); 10826 } 10827 this.removeTransformFromStyleList(); 10828 this.closeStyles(ownStyles); 10829 len = ownModifiers.length; 10830 for (i = 0; i < len; i += 1) { 10831 ownModifiers[i].closed = true; 10832 } 10833}; 10834 10835CVShapeElement.prototype.renderInnerContent = function () { 10836 this.transformHelper.opacity = 1; 10837 this.transformHelper._opMdf = false; 10838 this.renderModifiers(); 10839 this.transformsManager.processSequences(this._isFirstFrame); 10840 this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true); 10841}; 10842 10843CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) { 10844 if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) { 10845 groupTransform.opacity = parentTransform.opacity; 10846 groupTransform.opacity *= groupTransform.op.v; 10847 groupTransform._opMdf = true; 10848 } 10849}; 10850 10851CVShapeElement.prototype.drawLayer = function () { 10852 var i; 10853 var len = this.stylesList.length; 10854 var j; 10855 var jLen; 10856 var k; 10857 var kLen; 10858 var elems; 10859 var nodes; 10860 var renderer = this.globalData.renderer; 10861 var ctx = this.globalData.canvasContext; 10862 var type; 10863 var currentStyle; 10864 for (i = 0; i < len; i += 1) { 10865 currentStyle = this.stylesList[i]; 10866 type = currentStyle.type; 10867 10868 // Skipping style when 10869 // Stroke width equals 0 10870 // style should not be rendered (extra unused repeaters) 10871 // current opacity equals 0 10872 // global opacity equals 0 10873 if (!(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) { 10874 renderer.save(); 10875 elems = currentStyle.elements; 10876 if (type === 'st' || type === 'gs') { 10877 ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd; 10878 ctx.lineWidth = currentStyle.wi; 10879 ctx.lineCap = currentStyle.lc; 10880 ctx.lineJoin = currentStyle.lj; 10881 ctx.miterLimit = currentStyle.ml || 0; 10882 } else { 10883 ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd; 10884 } 10885 renderer.ctxOpacity(currentStyle.coOp); 10886 if (type !== 'st' && type !== 'gs') { 10887 ctx.beginPath(); 10888 } 10889 renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props); 10890 jLen = elems.length; 10891 for (j = 0; j < jLen; j += 1) { 10892 if (type === 'st' || type === 'gs') { 10893 ctx.beginPath(); 10894 if (currentStyle.da) { 10895 ctx.setLineDash(currentStyle.da); 10896 ctx.lineDashOffset = currentStyle.do; 10897 } 10898 } 10899 nodes = elems[j].trNodes; 10900 kLen = nodes.length; 10901 10902 for (k = 0; k < kLen; k += 1) { 10903 if (nodes[k].t === 'm') { 10904 ctx.moveTo(nodes[k].p[0], nodes[k].p[1]); 10905 } else if (nodes[k].t === 'c') { 10906 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]); 10907 } else { 10908 ctx.closePath(); 10909 } 10910 } 10911 if (type === 'st' || type === 'gs') { 10912 ctx.stroke(); 10913 if (currentStyle.da) { 10914 ctx.setLineDash(this.dashResetter); 10915 } 10916 } 10917 } 10918 if (type !== 'st' && type !== 'gs') { 10919 ctx.f
vendor: 5,722 bytes, lines 10919-11091
10919ill(currentStyle.r); 10920 } 10921 renderer.restore(); 10922 } 10923 } 10924}; 10925 10926CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) { 10927 var i; 10928 var len = items.length - 1; 10929 var groupTransform; 10930 groupTransform = parentTransform; 10931 for (i = len; i >= 0; i -= 1) { 10932 if (items[i].ty === 'tr') { 10933 groupTransform = data[i].transform; 10934 this.renderShapeTransform(parentTransform, groupTransform); 10935 } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') { 10936 this.renderPath(items[i], data[i]); 10937 } else if (items[i].ty === 'fl') { 10938 this.renderFill(items[i], data[i], groupTransform); 10939 } else if (items[i].ty === 'st') { 10940 this.renderStroke(items[i], data[i], groupTransform); 10941 } else if (items[i].ty === 'gf' || items[i].ty === 'gs') { 10942 this.renderGradientFill(items[i], data[i], groupTransform); 10943 } else if (items[i].ty === 'gr') { 10944 this.renderShape(groupTransform, items[i].it, data[i].it); 10945 } else if (items[i].ty === 'tm') { 10946 // 10947 } 10948 } 10949 if (isMain) { 10950 this.drawLayer(); 10951 } 10952}; 10953 10954CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) { 10955 if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) { 10956 var shapeNodes = styledShape.trNodes; 10957 var paths = shape.paths; 10958 var i; 10959 var len; 10960 var j; 10961 var jLen = paths._length; 10962 shapeNodes.length = 0; 10963 var groupTransformMat = styledShape.transforms.finalTransform; 10964 for (j = 0; j < jLen; j += 1) { 10965 var pathNodes = paths.shapes[j]; 10966 if (pathNodes && pathNodes.v) { 10967 len = pathNodes._length; 10968 for (i = 1; i < len; i += 1) { 10969 if (i === 1) { 10970 shapeNodes.push({ 10971 t: 'm', 10972 p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0), 10973 }); 10974 } 10975 shapeNodes.push({ 10976 t: 'c', 10977 pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i]), 10978 }); 10979 } 10980 if (len === 1) { 10981 shapeNodes.push({ 10982 t: 'm', 10983 p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0), 10984 }); 10985 } 10986 if (pathNodes.c && len) { 10987 shapeNodes.push({ 10988 t: 'c', 10989 pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0]), 10990 }); 10991 shapeNodes.push({ 10992 t: 'z', 10993 }); 10994 } 10995 } 10996 } 10997 styledShape.trNodes = shapeNodes; 10998 } 10999}; 11000 11001CVShapeElement.prototype.renderPath = function (pathData, itemData) { 11002 if (pathData.hd !== true && pathData._shouldRender) { 11003 var i; 11004 var len = itemData.styledShapes.length; 11005 for (i = 0; i < len; i += 1) { 11006 this.renderStyledShape(itemData.styledShapes[i], itemData.sh); 11007 } 11008 } 11009}; 11010 11011CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) { 11012 var styleElem = itemData.style; 11013 11014 if (itemData.c._mdf || this._isFirstFrame) { 11015 styleElem.co = 'rgb(' 11016 + bmFloor(itemData.c.v[0]) + ',' 11017 + bmFloor(itemData.c.v[1]) + ',' 11018 + bmFloor(itemData.c.v[2]) + ')'; 11019 } 11020 if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) { 11021 styleElem.coOp = itemData.o.v * groupTransform.opacity; 11022 } 11023}; 11024 11025CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) { 11026 var styleElem = itemData.style; 11027 var grd; 11028 if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) { 11029 var ctx = this.globalData.canvasContext; 11030 var pt1 = itemData.s.v; 11031 var pt2 = itemData.e.v; 11032 if (styleData.t === 1) { 11033 grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]); 11034 } else { 11035 var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2)); 11036 var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]); 11037 11038 var percent = itemData.h.v; 11039 if (percent >= 1) { 11040 percent = 0.99; 11041 } else if (percent <= -1) { 11042 percent = -0.99; 11043 } 11044 var dist = rad * percent; 11045 var x = Math.cos(ang + itemData.a.v) * dist + pt1[0]; 11046 var y = Math.sin(ang + itemData.a.v) * dist + pt1[1]; 11047 grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad); 11048 } 11049 11050 var i; 11051 var len = styleData.g.p; 11052 var cValues = itemData.g.c; 11053 var opacity = 1; 11054 11055 for (i = 0; i < len; i += 1) { 11056 if (itemData.g._hasOpacity && itemData.g._collapsable) { 11057 opacity = itemData.g.o[i * 2 + 1]; 11058 } 11059 grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')'); 11060 } 11061 styleElem.grd = grd; 11062 } 11063 styleElem.coOp = itemData.o.v * groupTransform.opacity; 11064}; 11065 11066CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) { 11067 var styleElem = itemData.style; 11068 var d = itemData.d; 11069 if (d && (d._mdf || this._isFirstFrame)) { 11070 styleElem.da = d.dashArray; 11071 styleElem.do = d.dashoffset[0]; 11072 } 11073 if (itemData.c._mdf || this._isFirstFrame) { 11074 styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')'; 11075 } 11076 if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) { 11077 styleElem.coOp = itemData.o.v * groupTransform.opacity; 11078 } 11079 if (itemData.w._mdf || this._isFirstFrame) { 11080 styleElem.wi = itemData.w.v; 11081 } 11082}; 11083 11084CVShapeElement.prototype.destroy = function () { 11085 this.shapesData = null; 11086 this.globalData = null; 11087 this.canvasContext = null; 11088 this.stylesList.length = 0; 11089 this.itemsData.length = 0; 11090}; 11091
vendor: 25,749 bytes, lines 11092-11812
11092/* global extendPrototype, BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, 11093SVGShapeElement, IImageElement */ 11094 11095function CVSolidElement(data, globalData, comp) { 11096 this.initElement(data, globalData, comp); 11097} 11098extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement); 11099 11100CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement; 11101CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame; 11102 11103CVSolidElement.prototype.renderInnerContent = function () { 11104 var ctx = this.canvasContext; 11105 ctx.fillStyle = this.data.sc; 11106 ctx.fillRect(0, 0, this.data.sw, this.data.sh); 11107 // 11108}; 11109 11110/* global extendPrototype, BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, 11111RenderableElement, ITextElement, createTag, createSizedArray */ 11112 11113function CVTextElement(data, globalData, comp) { 11114 this.textSpans = []; 11115 this.yOffset = 0; 11116 this.fillColorAnim = false; 11117 this.strokeColorAnim = false; 11118 this.strokeWidthAnim = false; 11119 this.stroke = false; 11120 this.fill = false; 11121 this.justifyOffset = 0; 11122 this.currentRender = null; 11123 this.renderType = 'canvas'; 11124 this.values = { 11125 fill: 'rgba(0,0,0,0)', 11126 stroke: 'rgba(0,0,0,0)', 11127 sWidth: 0, 11128 fValue: '', 11129 }; 11130 this.initElement(data, globalData, comp); 11131} 11132extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement); 11133 11134CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d'); 11135 11136CVTextElement.prototype.buildNewText = function () { 11137 var documentData = this.textProperty.currentData; 11138 this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0); 11139 11140 var hasFill = false; 11141 if (documentData.fc) { 11142 hasFill = true; 11143 this.values.fill = this.buildColor(documentData.fc); 11144 } else { 11145 this.values.fill = 'rgba(0,0,0,0)'; 11146 } 11147 this.fill = hasFill; 11148 var hasStroke = false; 11149 if (documentData.sc) { 11150 hasStroke = true; 11151 this.values.stroke = this.buildColor(documentData.sc); 11152 this.values.sWidth = documentData.sw; 11153 } 11154 var fontData = this.globalData.fontManager.getFontByName(documentData.f); 11155 var i; 11156 var len; 11157 var letters = documentData.l; 11158 var matrixHelper = this.mHelper; 11159 this.stroke = hasStroke; 11160 this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily; 11161 len = documentData.finalText.length; 11162 // this.tHelper.font = this.values.fValue; 11163 var charData; 11164 var shapeData; 11165 var k; 11166 var kLen; 11167 var shapes; 11168 var j; 11169 var jLen; 11170 var pathNodes; 11171 var commands; 11172 var pathArr; 11173 var singleShape = this.data.singleShape; 11174 var trackingOffset = documentData.tr * 0.001 * documentData.finalSize; 11175 var xPos = 0; 11176 var yPos = 0; 11177 var firstLine = true; 11178 var cnt = 0; 11179 for (i = 0; i < len; i += 1) { 11180 charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily); 11181 shapeData = (charData && charData.data) || {}; 11182 matrixHelper.reset(); 11183 if (singleShape && letters[i].n) { 11184 xPos = -trackingOffset; 11185 yPos += documentData.yOffset; 11186 yPos += firstLine ? 1 : 0; 11187 firstLine = false; 11188 } 11189 11190 shapes = shapeData.shapes ? shapeData.shapes[0].it : []; 11191 jLen = shapes.length; 11192 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100); 11193 if (singleShape) { 11194 this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos); 11195 } 11196 commands = createSizedArray(jLen); 11197 for (j = 0; j < jLen; j += 1) { 11198 kLen = shapes[j].ks.k.i.length; 11199 pathNodes = shapes[j].ks.k; 11200 pathArr = []; 11201 for (k = 1; k < kLen; k += 1) { 11202 if (k === 1) { 11203 pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0)); 11204 } 11205 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)); 11206 } 11207 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)); 11208 commands[j] = pathArr; 11209 } 11210 if (singleShape) { 11211 xPos += letters[i].l; 11212 xPos += trackingOffset; 11213 } 11214 if (this.textSpans[cnt]) { 11215 this.textSpans[cnt].elem = commands; 11216 } else { 11217 this.textSpans[cnt] = { elem: commands }; 11218 } 11219 cnt += 1; 11220 } 11221}; 11222 11223CVTextElement.prototype.renderInnerContent = function () { 11224 var ctx = this.canvasContext; 11225 ctx.font = this.values.fValue; 11226 ctx.lineCap = 'butt'; 11227 ctx.lineJoin = 'miter'; 11228 ctx.miterLimit = 4; 11229 11230 if (!this.data.singleShape) { 11231 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag); 11232 } 11233 11234 var i; 11235 var len; 11236 var j; 11237 var jLen; 11238 var k; 11239 var kLen; 11240 var renderedLetters = this.textAnimator.renderedLetters; 11241 11242 var letters = this.textProperty.currentData.l; 11243 11244 len = letters.length; 11245 var renderedLetter; 11246 var lastFill = null; 11247 var lastStroke = null; 11248 var lastStrokeW = null; 11249 var commands; 11250 var pathArr; 11251 for (i = 0; i < len; i += 1) { 11252 if (!letters[i].n) { 11253 renderedLetter = renderedLetters[i]; 11254 if (renderedLetter) { 11255 this.globalData.renderer.save(); 11256 this.globalData.renderer.ctxTransform(renderedLetter.p); 11257 this.globalData.renderer.ctxOpacity(renderedLetter.o); 11258 } 11259 if (this.fill) { 11260 if (renderedLetter && renderedLetter.fc) { 11261 if (lastFill !== renderedLetter.fc) { 11262 lastFill = renderedLetter.fc; 11263 ctx.fillStyle = renderedLetter.fc; 11264 } 11265 } else if (lastFill !== this.values.fill) { 11266 lastFill = this.values.fill; 11267 ctx.fillStyle = this.values.fill; 11268 } 11269 commands = this.textSpans[i].elem; 11270 jLen = commands.length; 11271 this.globalData.canvasContext.beginPath(); 11272 for (j = 0; j < jLen; j += 1) { 11273 pathArr = commands[j]; 11274 kLen = pathArr.length; 11275 this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]); 11276 for (k = 2; k < kLen; k += 6) { 11277 this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]); 11278 } 11279 } 11280 this.globalData.canvasContext.closePath(); 11281 this.globalData.canvasContext.fill(); 11282 /// ctx.fillText(this.textSpans[i].val,0,0); 11283 } 11284 if (this.stroke) { 11285 if (renderedLetter && renderedLetter.sw) { 11286 if (lastStrokeW !== renderedLetter.sw) { 11287 lastStrokeW = renderedLetter.sw; 11288 ctx.lineWidth = renderedLetter.sw; 11289 } 11290 } else if (lastStrokeW !== this.values.sWidth) { 11291 lastStrokeW = this.values.sWidth; 11292 ctx.lineWidth = this.values.sWidth; 11293 } 11294 if (renderedLetter && renderedLetter.sc) { 11295 if (lastStroke !== renderedLetter.sc) { 11296 lastStroke = renderedLetter.sc; 11297 ctx.strokeStyle = renderedLetter.sc; 11298 } 11299 } else if (lastStroke !== this.values.stroke) { 11300 lastStroke = this.values.stroke; 11301 ctx.strokeStyle = this.values.stroke; 11302 } 11303 commands = this.textSpans[i].elem; 11304 jLen = commands.length; 11305 this.globalData.canvasContext.beginPath(); 11306 for (j = 0; j < jLen; j += 1) { 11307 pathArr = commands[j]; 11308 kLen = pathArr.length; 11309 this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]); 11310 for (k = 2; k < kLen; k += 6) { 11311 this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]); 11312 } 11313 } 11314 this.globalData.canvasContext.closePath(); 11315 this.globalData.canvasContext.stroke(); 11316 /// ctx.strokeText(letters[i].val,0,0); 11317 } 11318 if (renderedLetter) { 11319 this.globalData.renderer.restore(); 11320 } 11321 } 11322 } 11323}; 11324 11325function CVEffects() { 11326 11327} 11328CVEffects.prototype.renderFrame = function () {}; 11329 11330/* global createTag, createNS, styleDiv, CVEffects, MaskElement, SVGBaseElement, HybridRenderer */ 11331 11332function HBaseElement() {} 11333HBaseElement.prototype = { 11334 checkBlendMode: function () {}, 11335 initRendererElement: function () { 11336 this.baseElement = createTag(this.data.tg || 'div'); 11337 if (this.data.hasMask) { 11338 this.svgElement = createNS('svg'); 11339 this.layerElement = createNS('g'); 11340 this.maskedElement = this.layerElement; 11341 this.svgElement.appendChild(this.layerElement); 11342 this.baseElement.appendChild(this.svgElement); 11343 } else { 11344 this.layerElement = this.baseElement; 11345 } 11346 styleDiv(this.baseElement); 11347 }, 11348 createContainerElements: function () { 11349 this.renderableEffectsManager = new CVEffects(this); 11350 this.transformedElement = this.baseElement; 11351 this.maskedElement = this.layerElement; 11352 if (this.data.ln) { 11353 this.layerElement.setAttribute('id', this.data.ln); 11354 } 11355 if (this.data.cl) { 11356 this.layerElement.setAttribute('class', this.data.cl); 11357 } 11358 if (this.data.bm !== 0) { 11359 this.setBlendMode(); 11360 } 11361 }, 11362 renderElement: function () { 11363 var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {}; 11364 if (this.finalTransform._matMdf) { 11365 var matrixValue = this.finalTransform.mat.toCSS(); 11366 transformedElementStyle.transform = matrixValue; 11367 transformedElementStyle.webkitTransform = matrixValue; 11368 } 11369 if (this.finalTransform._opMdf) { 11370 transformedElementStyle.opacity = this.finalTransform.mProp.o.v; 11371 } 11372 }, 11373 renderFrame: function () { 11374 // If it is exported as hidden (data.hd === true) no need to render 11375 // If it is not visible no need to render 11376 if (this.data.hd || this.hidden) { 11377 return; 11378 } 11379 this.renderTransform(); 11380 this.renderRenderable(); 11381 this.renderElement(); 11382 this.renderInnerContent(); 11383 if (this._isFirstFrame) { 11384 this._isFirstFrame = false; 11385 } 11386 }, 11387 destroy: function () { 11388 this.layerElement = null; 11389 this.transformedElement = null; 11390 if (this.matteElement) { 11391 this.matteElement = null; 11392 } 11393 if (this.maskManager) { 11394 this.maskManager.destroy(); 11395 this.maskManager = null; 11396 } 11397 }, 11398 createRenderableComponents: function () { 11399 this.maskManager = new MaskElement(this.data, this, this.globalData); 11400 }, 11401 addEffects: function () { 11402 }, 11403 setMatte: function () {}, 11404}; 11405HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement; 11406HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy; 11407HBaseElement.prototype.buildElementParenting = HybridRenderer.prototype.buildElementParenting; 11408 11409/* global extendPrototype, BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, 11410RenderableDOMElement, createNS, createTag */ 11411 11412function HSolidElement(data, globalData, comp) { 11413 this.initElement(data, globalData, comp); 11414} 11415extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement); 11416 11417HSolidElement.prototype.createContent = function () { 11418 var rect; 11419 if (this.data.hasMask) { 11420 rect = createNS('rect'); 11421 rect.setAttribute('width', this.data.sw); 11422 rect.setAttribute('height', this.data.sh); 11423 rect.setAttribute('fill', this.data.sc); 11424 this.svgElement.setAttribute('width', this.data.sw); 11425 this.svgElement.setAttribute('height', this.data.sh); 11426 } else { 11427 rect = createTag('div'); 11428 rect.style.width = this.data.sw + 'px'; 11429 rect.style.height = this.data.sh + 'px'; 11430 rect.style.backgroundColor = this.data.sc; 11431 } 11432 this.layerElement.appendChild(rect); 11433}; 11434 11435/* global createSizedArray, PropertyFactory, extendPrototype, HybridRenderer, ICompElement, HBaseElement */ 11436 11437function HCompElement(data, globalData, comp) { 11438 this.layers = data.layers; 11439 this.supports3d = !data.hasMask; 11440 this.completeLayers = false; 11441 this.pendingElements = []; 11442 this.elements = this.layers ? createSizedArray(this.layers.length) : []; 11443 this.initElement(data, globalData, comp); 11444 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 11445} 11446 11447extendPrototype([HybridRenderer, ICompElement, HBaseElement], HCompElement); 11448HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements; 11449 11450HCompElement.prototype.createContainerElements = function () { 11451 this._createBaseContainerElements(); 11452 // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)'; 11453 if (this.data.hasMask) { 11454 this.svgElement.setAttribute('width', this.data.w); 11455 this.svgElement.setAttribute('height', this.data.h); 11456 this.transformedElement = this.baseElement; 11457 } else { 11458 this.transformedElement = this.layerElement; 11459 } 11460}; 11461 11462HCompElement.prototype.addTo3dContainer = function (elem, pos) { 11463 var j = 0; 11464 var nextElement; 11465 while (j < pos) { 11466 if (this.elements[j] && this.elements[j].getBaseElement) { 11467 nextElement = this.elements[j].getBaseElement(); 11468 } 11469 j += 1; 11470 } 11471 if (nextElement) { 11472 this.layerElement.insertBefore(elem, nextElement); 11473 } else { 11474 this.layerElement.appendChild(elem); 11475 } 11476}; 11477 11478/* global createNS, extendPrototype, BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, 11479HierarchyElement, FrameElement, RenderableElement, createNS, bmMin, bmSqrt, bmMin, bmMax, bmPow */ 11480 11481function HShapeElement(data, globalData, comp) { 11482 // List of drawable elements 11483 this.shapes = []; 11484 // Full shape data 11485 this.shapesData = data.shapes; 11486 // List of styles that will be applied to shapes 11487 this.stylesList = []; 11488 // List of modifiers that will be applied to shapes 11489 this.shapeModifiers = []; 11490 // List of items in shape tree 11491 this.itemsData = []; 11492 // List of items in previous shape tree 11493 this.processedElements = []; 11494 // List of animated components 11495 this.animatedContents = []; 11496 this.shapesContainer = createNS('g'); 11497 this.initElement(data, globalData, comp); 11498 // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties. 11499 // List of elements that have been created 11500 this.prevViewData = []; 11501 this.currentBBox = { 11502 x: 999999, 11503 y: -999999, 11504 h: 0, 11505 w: 0, 11506 }; 11507} 11508extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement); 11509HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent; 11510 11511HShapeElement.prototype.createContent = function () { 11512 var cont; 11513 this.baseElement.style.fontSize = 0; 11514 if (this.data.hasMask) { 11515 this.layerElement.appendChild(this.shapesContainer); 11516 cont = this.svgElement; 11517 } else { 11518 cont = createNS('svg'); 11519 var size = this.comp.data ? this.comp.data : this.globalData.compSize; 11520 cont.setAttribute('width', size.w); 11521 cont.setAttribute('height', size.h); 11522 cont.appendChild(this.shapesContainer); 11523 this.layerElement.appendChild(cont); 11524 } 11525 11526 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true); 11527 this.filterUniqueShapes(); 11528 this.shapeCont = cont; 11529}; 11530 11531HShapeElement.prototype.getTransformedPoint = function (transformers, point) { 11532 var i; 11533 var len = transformers.length; 11534 for (i = 0; i < len; i += 1) { 11535 point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0); 11536 } 11537 return point; 11538}; 11539 11540HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) { 11541 var shape = item.sh.v; 11542 var transformers = item.transformers; 11543 var i; 11544 var len = shape._length; 11545 var vPoint; 11546 var oPoint; 11547 var nextIPoint; 11548 var nextVPoint; 11549 if (len <= 1) { 11550 return; 11551 } 11552 for (i = 0; i < len - 1; i += 1) { 11553 vPoint = this.getTransformedPoint(transformers, shape.v[i]); 11554 oPoint = this.getTransformedPoint(transformers, shape.o[i]); 11555 nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]); 11556 nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]); 11557 this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox); 11558 } 11559 if (shape.c) { 11560 vPoint = this.getTransformedPoint(transformers, shape.v[i]); 11561 oPoint = this.getTransformedPoint(transformers, shape.o[i]); 11562 nextIPoint = this.getTransformedPoint(transformers, shape.i[0]); 11563 nextVPoint = this.getTransformedPoint(transformers, shape.v[0]); 11564 this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox); 11565 } 11566}; 11567 11568HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) { 11569 this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint); 11570 var bounds = this.shapeBoundingBox; 11571 boundingBox.x = bmMin(bounds.left, boundingBox.x); 11572 boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax); 11573 boundingBox.y = bmMin(bounds.top, boundingBox.y); 11574 boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax); 11575}; 11576 11577HShapeElement.prototype.shapeBoundingBox = { 11578 left: 0, 11579 right: 0, 11580 top: 0, 11581 bottom: 0, 11582}; 11583 11584HShapeElement.prototype.tempBoundingBox = { 11585 x: 0, 11586 xMax: 0, 11587 y: 0, 11588 yMax: 0, 11589 width: 0, 11590 height: 0, 11591}; 11592 11593HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) { 11594 var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]]; 11595 11596 for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) { // eslint-disable-line no-plusplus 11597 b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i]; 11598 a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i]; 11599 c = 3 * p1[i] - 3 * p0[i]; 11600 11601 b |= 0; // eslint-disable-line no-bitwise 11602 a |= 0; // eslint-disable-line no-bitwise 11603 c |= 0; // eslint-disable-line no-bitwise 11604 11605 if (a === 0 && b === 0) { 11606 // 11607 } else if (a === 0) { 11608 t = -c / b; 11609 11610 if (t > 0 && t < 1) { 11611 bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i)); 11612 } 11613 } else { 11614 b2ac = b * b - 4 * c * a; 11615 11616 if (b2ac >= 0) { 11617 t1 = (-b + bmSqrt(b2ac)) / (2 * a); 11618 if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i)); 11619 t2 = (-b - bmSqrt(b2ac)) / (2 * a); 11620 if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i)); 11621 } 11622 } 11623 } 11624 11625 this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]); 11626 this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]); 11627 this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]); 11628 this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]); 11629}; 11630 11631HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) { 11632 return bmPow(1 - t, 3) * p0[i] 11633 + 3 * bmPow(1 - t, 2) * t * p1[i] 11634 + 3 * (1 - t) * bmPow(t, 2) * p2[i] 11635 + bmPow(t, 3) * p3[i]; 11636}; 11637 11638HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) { 11639 var i; 11640 var len = itemsData.length; 11641 for (i = 0; i < len; i += 1) { 11642 if (itemsData[i] && itemsData[i].sh) { 11643 this.calculateShapeBoundingBox(itemsData[i], boundingBox); 11644 } else if (itemsData[i] && itemsData[i].it) { 11645 this.calculateBoundingBox(itemsData[i].it, boundingBox); 11646 } 11647 } 11648}; 11649 11650HShapeElement.prototype.currentBoxContains = function (box) { 11651 return this.currentBBox.x <= box.x 11652 && this.currentBBox.y <= box.y 11653 && this.currentBBox.width + this.currentBBox.x >= box.x + box.width 11654 && this.currentBBox.height + this.currentBBox.y >= box.y + box.height; 11655}; 11656 11657HShapeElement.prototype.renderInnerContent = function () { 11658 this._renderShapeFrame(); 11659 11660 if (!this.hidden && (this._isFirstFrame || this._mdf)) { 11661 var tempBoundingBox = this.tempBoundingBox; 11662 var max = 999999; 11663 tempBoundingBox.x = max; 11664 tempBoundingBox.xMax = -max; 11665 tempBoundingBox.y = max; 11666 tempBoundingBox.yMax = -max; 11667 this.calculateBoundingBox(this.itemsData, tempBoundingBox); 11668 tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x; 11669 tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y; 11670 // var tempBoundingBox = this.shapeCont.getBBox(); 11671 if (this.currentBoxContains(tempBoundingBox)) { 11672 return; 11673 } 11674 var changed = false; 11675 if (this.currentBBox.w !== tempBoundingBox.width) { 11676 this.currentBBox.w = tempBoundingBox.width; 11677 this.shapeCont.setAttribute('width', tempBoundingBox.width); 11678 changed = true; 11679 } 11680 if (this.currentBBox.h !== tempBoundingBox.height) { 11681 this.currentBBox.h = tempBoundingBox.height; 11682 this.shapeCont.setAttribute('height', tempBoundingBox.height); 11683 changed = true; 11684 } 11685 if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) { 11686 this.currentBBox.w = tempBoundingBox.width; 11687 this.currentBBox.h = tempBoundingBox.height; 11688 this.currentBBox.x = tempBoundingBox.x; 11689 this.currentBBox.y = tempBoundingBox.y; 11690 11691 this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h); 11692 var shapeStyle = this.shapeCont.style; 11693 var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)'; 11694 shapeStyle.transform = shapeTransform; 11695 shapeStyle.webkitTransform = shapeTransform; 11696 } 11697 } 11698}; 11699 11700/* global extendPrototype, BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, 11701RenderableDOMElement, ITextElement, createSizedArray, createTag, styleDiv, createNS */ 11702 11703function HTextElement(data, globalData, comp) { 11704 this.textSpans = []; 11705 this.textPaths = []; 11706 this.currentBBox = { 11707 x: 999999, 11708 y: -999999, 11709 h: 0, 11710 w: 0, 11711 }; 11712 this.renderType = 'svg'; 11713 this.isMasked = false; 11714 this.initElement(data, globalData, comp); 11715} 11716extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement); 11717 11718HTextElement.prototype.createContent = function () { 11719 this.isMasked = this.checkMasks(); 11720 if (this.isMasked) { 11721 this.renderType = 'svg'; 11722 this.compW = this.comp.data.w; 11723 this.compH = this.comp.data.h; 11724 this.svgElement.setAttribute('width', this.compW); 11725 this.svgElement.setAttribute('height', this.compH); 11726 var g = createNS('g'); 11727 this.maskedElement.appendChild(g); 11728 this.innerElem = g; 11729 } else { 11730 this.renderType = 'html'; 11731 this.innerElem = this.layerElement; 11732 } 11733 11734 this.checkParenting(); 11735}; 11736 11737HTextElement.prototype.buildNewText = function () { 11738 var documentData = this.textProperty.currentData; 11739 this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0); 11740 var innerElemStyle = this.innerElem.style; 11741 var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)'; 11742 innerElemStyle.fill = textColor; 11743 innerElemStyle.color = textColor; 11744 if (documentData.sc) { 11745 innerElemStyle.stroke = this.buildColor(documentData.sc); 11746 innerElemStyle.strokeWidth = documentData.sw + 'px'; 11747 } 11748 var fontData = this.globalData.fontManager.getFontByName(documentData.f); 11749 if (!this.globalData.fontManager.chars) { 11750 innerElemStyle.fontSize = documentData.finalSize + 'px'; 11751 innerElemStyle.lineHeight = documentData.finalSize + 'px'; 11752 if (fontData.fClass) { 11753 this.innerElem.className = fontData.fClass; 11754 } else { 11755 innerElemStyle.fontFamily = fontData.fFamily; 11756 var fWeight = documentData.fWeight; 11757 var fStyle = documentData.fStyle; 11758 innerElemStyle.fontStyle = fStyle; 11759 innerElemStyle.fontWeight = fWeight; 11760 } 11761 } 11762 var i; 11763 var len; 11764 11765 var letters = documentData.l; 11766 len = letters.length; 11767 var tSpan; 11768 var tParent; 11769 var tCont; 11770 var matrixHelper = this.mHelper; 11771 var shapes; 11772 var shapeStr = ''; 11773 var cnt = 0; 11774 for (i = 0; i < len; i += 1) { 11775 if (this.globalData.fontManager.chars) { 11776 if (!this.textPaths[cnt]) { 11777 tSpan = createNS('path'); 11778 tSpan.setAttribute('stroke-linecap', 'butt'); 11779 tSpan.setAttribute('stroke-linejoin', 'round'); 11780 tSpan.setAttribute('stroke-miterlimit', '4'); 11781 } else { 11782 tSpan = this.textPaths[cnt]; 11783 } 11784 if (!this.isMasked) { 11785 if (this.textSpans[cnt]) { 11786 tParent = this.textSpans[cnt]; 11787 tCont = tParent.children[0]; 11788 } else { 11789 tParent = createTag('div'); 11790 tParent.style.lineHeight = 0; 11791 tCont = createNS('svg'); 11792 tCont.appendChild(tSpan); 11793 styleDiv(tParent); 11794 } 11795 } 11796 } else if (!this.isMasked) { 11797 if (this.textSpans[cnt]) { 11798 tParent = this.textSpans[cnt]; 11799 tSpan = this.textPaths[cnt]; 11800 } else { 11801 tParent = createTag('span'); 11802 styleDiv(tParent); 11803 tSpan = createTag('span'); 11804 styleDiv(tSpan); 11805 tParent.appendChild(tSpan); 11806 } 11807 } else { 11808 tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text'); 11809 } 11810 // tSpan.setAttribute('visibility', 'hidden'); 11811 if (this.globalData.fontManager.chars) { 11812 var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(
vendor: 4,730 bytes, lines 11812-11942
11812documentData.f).fFamily); 11813 var shapeData; 11814 if (charData) { 11815 shapeData = charData.data; 11816 } else { 11817 shapeData = null; 11818 } 11819 matrixHelper.reset(); 11820 if (shapeData && shapeData.shapes) { 11821 shapes = shapeData.shapes[0].it; 11822 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100); 11823 shapeStr = this.createPathShape(matrixHelper, shapes); 11824 tSpan.setAttribute('d', shapeStr); 11825 } 11826 if (!this.isMasked) { 11827 this.innerElem.appendChild(tParent); 11828 if (shapeData && shapeData.shapes) { 11829 // document.body.appendChild is needed to get exact measure of shape 11830 document.body.appendChild(tCont); 11831 var boundingBox = tCont.getBBox(); 11832 tCont.setAttribute('width', boundingBox.width + 2); 11833 tCont.setAttribute('height', boundingBox.height + 2); 11834 tCont.setAttribute('viewBox', (boundingBox.x - 1) + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2)); 11835 var tContStyle = tCont.style; 11836 var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)'; 11837 tContStyle.transform = tContTranslation; 11838 tContStyle.webkitTransform = tContTranslation; 11839 11840 letters[i].yOffset = boundingBox.y - 1; 11841 } else { 11842 tCont.setAttribute('width', 1); 11843 tCont.setAttribute('height', 1); 11844 } 11845 tParent.appendChild(tCont); 11846 } else { 11847 this.innerElem.appendChild(tSpan); 11848 } 11849 } else { 11850 tSpan.textContent = letters[i].val; 11851 tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); 11852 if (!this.isMasked) { 11853 this.innerElem.appendChild(tParent); 11854 // 11855 var tStyle = tSpan.style; 11856 var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)'; 11857 tStyle.transform = tSpanTranslation; 11858 tStyle.webkitTransform = tSpanTranslation; 11859 } else { 11860 this.innerElem.appendChild(tSpan); 11861 } 11862 } 11863 // 11864 if (!this.isMasked) { 11865 this.textSpans[cnt] = tParent; 11866 } else { 11867 this.textSpans[cnt] = tSpan; 11868 } 11869 this.textSpans[cnt].style.display = 'block'; 11870 this.textPaths[cnt] = tSpan; 11871 cnt += 1; 11872 } 11873 while (cnt < this.textSpans.length) { 11874 this.textSpans[cnt].style.display = 'none'; 11875 cnt += 1; 11876 } 11877}; 11878 11879HTextElement.prototype.renderInnerContent = function () { 11880 var svgStyle; 11881 if (this.data.singleShape) { 11882 if (!this._isFirstFrame && !this.lettersChangedFlag) { 11883 return; 11884 } if (this.isMasked && this.finalTransform._matMdf) { 11885 // Todo Benchmark if using this is better than getBBox 11886 this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH); 11887 svgStyle = this.svgElement.style; 11888 var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)'; 11889 svgStyle.transform = translation; 11890 svgStyle.webkitTransform = translation; 11891 } 11892 } 11893 11894 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag); 11895 if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) { 11896 return; 11897 } 11898 var i; 11899 var len; 11900 var count = 0; 11901 var renderedLetters = this.textAnimator.renderedLetters; 11902 11903 var letters = this.textProperty.currentData.l; 11904 11905 len = letters.length; 11906 var renderedLetter; 11907 var textSpan; 11908 var textPath; 11909 for (i = 0; i < len; i += 1) { 11910 if (letters[i].n) { 11911 count += 1; 11912 } else { 11913 textSpan = this.textSpans[i]; 11914 textPath = this.textPaths[i]; 11915 renderedLetter = renderedLetters[count]; 11916 count += 1; 11917 if (renderedLetter._mdf.m) { 11918 if (!this.isMasked) { 11919 textSpan.style.webkitTransform = renderedLetter.m; 11920 textSpan.style.transform = renderedLetter.m; 11921 } else { 11922 textSpan.setAttribute('transform', renderedLetter.m); 11923 } 11924 } 11925 /// /textSpan.setAttribute('opacity',renderedLetter.o); 11926 textSpan.style.opacity = renderedLetter.o; 11927 if (renderedLetter.sw && renderedLetter._mdf.sw) { 11928 textPath.setAttribute('stroke-width', renderedLetter.sw); 11929 } 11930 if (renderedLetter.sc && renderedLetter._mdf.sc) { 11931 textPath.setAttribute('stroke', renderedLetter.sc); 11932 } 11933 if (renderedLetter.fc && renderedLetter._mdf.fc) { 11934 textPath.setAttribute('fill', renderedLetter.fc); 11935 textPath.style.color = renderedLetter.fc; 11936 } 11937 } 11938 } 11939 11940 if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) { 11941 var boundingBox = this.innerElem.getBBox(); 11942
vendor: 13,297 bytes, lines 11943-12349
11943 if (this.currentBBox.w !== boundingBox.width) { 11944 this.currentBBox.w = boundingBox.width; 11945 this.svgElement.setAttribute('width', boundingBox.width); 11946 } 11947 if (this.currentBBox.h !== boundingBox.height) { 11948 this.currentBBox.h = boundingBox.height; 11949 this.svgElement.setAttribute('height', boundingBox.height); 11950 } 11951 11952 var margin = 1; 11953 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)) { 11954 this.currentBBox.w = boundingBox.width + margin * 2; 11955 this.currentBBox.h = boundingBox.height + margin * 2; 11956 this.currentBBox.x = boundingBox.x - margin; 11957 this.currentBBox.y = boundingBox.y - margin; 11958 11959 this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h); 11960 svgStyle = this.svgElement.style; 11961 var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)'; 11962 svgStyle.transform = svgTransform; 11963 svgStyle.webkitTransform = svgTransform; 11964 } 11965 } 11966}; 11967 11968/* global extendPrototype, BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, 11969FrameElement, RenderableElement, createNS */ 11970 11971function HImageElement(data, globalData, comp) { 11972 this.assetData = globalData.getAssetData(data.refId); 11973 this.initElement(data, globalData, comp); 11974} 11975 11976extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement); 11977 11978HImageElement.prototype.createContent = function () { 11979 var assetPath = this.globalData.getAssetsPath(this.assetData); 11980 var img = new Image(); 11981 11982 if (this.data.hasMask) { 11983 this.imageElem = createNS('image'); 11984 this.imageElem.setAttribute('width', this.assetData.w + 'px'); 11985 this.imageElem.setAttribute('height', this.assetData.h + 'px'); 11986 this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath); 11987 this.layerElement.appendChild(this.imageElem); 11988 this.baseElement.setAttribute('width', this.assetData.w); 11989 this.baseElement.setAttribute('height', this.assetData.h); 11990 } else { 11991 this.layerElement.appendChild(img); 11992 } 11993 img.crossOrigin = 'anonymous'; 11994 img.src = assetPath; 11995 if (this.data.ln) { 11996 this.baseElement.setAttribute('id', this.data.ln); 11997 } 11998}; 11999 12000/* global PropertyFactory, degToRads, Matrix, extendPrototype, BaseElement, FrameElement, HierarchyElement */ 12001 12002function HCameraElement(data, globalData, comp) { 12003 this.initFrame(); 12004 this.initBaseData(data, globalData, comp); 12005 this.initHierarchy(); 12006 var getProp = PropertyFactory.getProp; 12007 this.pe = getProp(this, data.pe, 0, 0, this); 12008 if (data.ks.p.s) { 12009 this.px = getProp(this, data.ks.p.x, 1, 0, this); 12010 this.py = getProp(this, data.ks.p.y, 1, 0, this); 12011 this.pz = getProp(this, data.ks.p.z, 1, 0, this); 12012 } else { 12013 this.p = getProp(this, data.ks.p, 1, 0, this); 12014 } 12015 if (data.ks.a) { 12016 this.a = getProp(this, data.ks.a, 1, 0, this); 12017 } 12018 if (data.ks.or.k.length && data.ks.or.k[0].to) { 12019 var i; 12020 var len = data.ks.or.k.length; 12021 for (i = 0; i < len; i += 1) { 12022 data.ks.or.k[i].to = null; 12023 data.ks.or.k[i].ti = null; 12024 } 12025 } 12026 this.or = getProp(this, data.ks.or, 1, degToRads, this); 12027 this.or.sh = true; 12028 this.rx = getProp(this, data.ks.rx, 0, degToRads, this); 12029 this.ry = getProp(this, data.ks.ry, 0, degToRads, this); 12030 this.rz = getProp(this, data.ks.rz, 0, degToRads, this); 12031 this.mat = new Matrix(); 12032 this._prevMat = new Matrix(); 12033 this._isFirstFrame = true; 12034 12035 // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface. 12036 this.finalTransform = { 12037 mProp: this, 12038 }; 12039} 12040extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement); 12041 12042HCameraElement.prototype.setup = function () { 12043 var i; 12044 var len = this.comp.threeDElements.length; 12045 var comp; 12046 var perspectiveStyle; 12047 var containerStyle; 12048 for (i = 0; i < len; i += 1) { 12049 // [perspectiveElem,container] 12050 comp = this.comp.threeDElements[i]; 12051 if (comp.type === '3d') { 12052 perspectiveStyle = comp.perspectiveElem.style; 12053 containerStyle = comp.container.style; 12054 var perspective = this.pe.v + 'px'; 12055 var origin = '0px 0px 0px'; 12056 var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)'; 12057 perspectiveStyle.perspective = perspective; 12058 perspectiveStyle.webkitPerspective = perspective; 12059 containerStyle.transformOrigin = origin; 12060 containerStyle.mozTransformOrigin = origin; 12061 containerStyle.webkitTransformOrigin = origin; 12062 perspectiveStyle.transform = matrix; 12063 perspectiveStyle.webkitTransform = matrix; 12064 } 12065 } 12066}; 12067 12068HCameraElement.prototype.createElements = function () { 12069}; 12070 12071HCameraElement.prototype.hide = function () { 12072}; 12073 12074HCameraElement.prototype.renderFrame = function () { 12075 var _mdf = this._isFirstFrame; 12076 var i; 12077 var len; 12078 if (this.hierarchy) { 12079 len = this.hierarchy.length; 12080 for (i = 0; i < len; i += 1) { 12081 _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf; 12082 } 12083 } 12084 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)) { 12085 this.mat.reset(); 12086 12087 if (this.hierarchy) { 12088 len = this.hierarchy.length - 1; 12089 for (i = len; i >= 0; i -= 1) { 12090 var mTransf = this.hierarchy[i].finalTransform.mProp; 12091 this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]); 12092 this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]); 12093 this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v); 12094 this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]); 12095 this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]); 12096 } 12097 } 12098 if (this.p) { 12099 this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]); 12100 } else { 12101 this.mat.translate(-this.px.v, -this.py.v, this.pz.v); 12102 } 12103 if (this.a) { 12104 var diffVector; 12105 if (this.p) { 12106 diffVector = [this.p.v[0] - this.a.v[0], this.p.v[1] - this.a.v[1], this.p.v[2] - this.a.v[2]]; 12107 } else { 12108 diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]]; 12109 } 12110 var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2)); 12111 // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v)); 12112 var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag]; 12113 var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]); 12114 var mRotationX = (Math.atan2(lookDir[1], lookLengthOnXZ)); 12115 var mRotationY = (Math.atan2(lookDir[0], -lookDir[2])); 12116 this.mat.rotateY(mRotationY).rotateX(-mRotationX); 12117 } 12118 this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v); 12119 this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]); 12120 this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0); 12121 this.mat.translate(0, 0, this.pe.v); 12122 12123 var hasMatrixChanged = !this._prevMat.equals(this.mat); 12124 if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) { 12125 len = this.comp.threeDElements.length; 12126 var comp; 12127 var perspectiveStyle; 12128 var containerStyle; 12129 for (i = 0; i < len; i += 1) { 12130 comp = this.comp.threeDElements[i]; 12131 if (comp.type === '3d') { 12132 if (hasMatrixChanged) { 12133 var matValue = this.mat.toCSS(); 12134 containerStyle = comp.container.style; 12135 containerStyle.transform = matValue; 12136 containerStyle.webkitTransform = matValue; 12137 } 12138 if (this.pe._mdf) { 12139 perspectiveStyle = comp.perspectiveElem.style; 12140 perspectiveStyle.perspective = this.pe.v + 'px'; 12141 perspectiveStyle.webkitPerspective = this.pe.v + 'px'; 12142 } 12143 } 12144 } 12145 this.mat.clone(this._prevMat); 12146 } 12147 } 12148 this._isFirstFrame = false; 12149}; 12150 12151HCameraElement.prototype.prepareFrame = function (num) { 12152 this.prepareProperties(num, true); 12153}; 12154 12155HCameraElement.prototype.destroy = function () { 12156}; 12157HCameraElement.prototype.getBaseElement = function () { return null; }; 12158 12159function HEffects() { 12160} 12161HEffects.prototype.renderFrame = function () {}; 12162 12163/* global createTag, AnimationItem */ 12164/* exported animationManager */ 12165 12166var animationManager = (function () { 12167 var moduleOb = {}; 12168 var registeredAnimations = []; 12169 var initTime = 0; 12170 var len = 0; 12171 var playingAnimationsNum = 0; 12172 var _stopped = true; 12173 var _isFrozen = false; 12174 12175 function removeElement(ev) { 12176 var i = 0; 12177 var animItem = ev.target; 12178 while (i < len) { 12179 if (registeredAnimations[i].animation === animItem) { 12180 registeredAnimations.splice(i, 1); 12181 i -= 1; 12182 len -= 1; 12183 if (!animItem.isPaused) { 12184 subtractPlayingCount(); 12185 } 12186 } 12187 i += 1; 12188 } 12189 } 12190 12191 function registerAnimation(element, animationData) { 12192 if (!element) { 12193 return null; 12194 } 12195 var i = 0; 12196 while (i < len) { 12197 if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) { 12198 return registeredAnimations[i].animation; 12199 } 12200 i += 1; 12201 } 12202 var animItem = new AnimationItem(); 12203 setupAnimation(animItem, element); 12204 animItem.setData(element, animationData); 12205 return animItem; 12206 } 12207 12208 function getRegisteredAnimations() { 12209 var i; 12210 var lenAnims = registeredAnimations.length; 12211 var animations = []; 12212 for (i = 0; i < lenAnims; i += 1) { 12213 animations.push(registeredAnimations[i].animation); 12214 } 12215 return animations; 12216 } 12217 12218 function addPlayingCount() { 12219 playingAnimationsNum += 1; 12220 activate(); 12221 } 12222 12223 function subtractPlayingCount() { 12224 playingAnimationsNum -= 1; 12225 } 12226 12227 function setupAnimation(animItem, element) { 12228 animItem.addEventListener('destroy', removeElement); 12229 animItem.addEventListener('_active', addPlayingCount); 12230 animItem.addEventListener('_idle', subtractPlayingCount); 12231 registeredAnimations.push({ elem: element, animation: animItem }); 12232 len += 1; 12233 } 12234 12235 function loadAnimation(params) { 12236 var animItem = new AnimationItem(); 12237 setupAnimation(animItem, null); 12238 animItem.setParams(params); 12239 return animItem; 12240 } 12241 12242 function setSpeed(val, animation) { 12243 var i; 12244 for (i = 0; i < len; i += 1) { 12245 registeredAnimations[i].animation.setSpeed(val, animation); 12246 } 12247 } 12248 12249 function setDirection(val, animation) { 12250 var i; 12251 for (i = 0; i < len; i += 1) { 12252 registeredAnimations[i].animation.setDirection(val, animation); 12253 } 12254 } 12255 12256 function play(animation) { 12257 var i; 12258 for (i = 0; i < len; i += 1) { 12259 registeredAnimations[i].animation.play(animation); 12260 } 12261 } 12262 function resume(nowTime) { 12263 var elapsedTime = nowTime - initTime; 12264 var i; 12265 for (i = 0; i < len; i += 1) { 12266 registeredAnimations[i].animation.advanceTime(elapsedTime); 12267 } 12268 initTime = nowTime; 12269 if (playingAnimationsNum && !_isFrozen) { 12270 window.requestAnimationFrame(resume); 12271 } else { 12272 _stopped = true; 12273 } 12274 } 12275 12276 function first(nowTime) { 12277 initTime = nowTime; 12278 window.requestAnimationFrame(resume); 12279 } 12280 12281 function pause(animation) { 12282 var i; 12283 for (i = 0; i < len; i += 1) { 12284 registeredAnimations[i].animation.pause(animation); 12285 } 12286 } 12287 12288 function goToAndStop(value, isFrame, animation) { 12289 var i; 12290 for (i = 0; i < len; i += 1) { 12291 registeredAnimations[i].animation.goToAndStop(value, isFrame, animation); 12292 } 12293 } 12294 12295 function stop(animation) { 12296 var i; 12297 for (i = 0; i < len; i += 1) { 12298 registeredAnimations[i].animation.stop(animation); 12299 } 12300 } 12301 12302 function togglePause(animation) { 12303 var i; 12304 for (i = 0; i < len; i += 1) { 12305 registeredAnimations[i].animation.togglePause(animation); 12306 } 12307 } 12308 12309 function destroy(animation) { 12310 var i; 12311 for (i = (len - 1); i >= 0; i -= 1) { 12312 registeredAnimations[i].animation.destroy(animation); 12313 } 12314 } 12315 12316 function searchAnimations(animationData, standalone, renderer) { 12317 var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')), 12318 [].slice.call(document.getElementsByClassName('bodymovin'))); 12319 var i; 12320 var lenAnims = animElements.length; 12321 for (i = 0; i < lenAnims; i += 1) { 12322 if (renderer) { 12323 animElements[i].setAttribute('data-bm-type', renderer); 12324 } 12325 registerAnimation(animElements[i], animationData); 12326 } 12327 if (standalone && lenAnims === 0) { 12328 if (!renderer) { 12329 renderer = 'svg'; 12330 } 12331 var body = document.getElementsByTagName('body')[0]; 12332 body.innerText = ''; 12333 var div = createTag('div'); 12334 div.style.width = '100%'; 12335 div.style.height = '100%'; 12336 div.setAttribute('data-bm-type', renderer); 12337 body.appendChild(div); 12338 registerAnimation(div, animationData); 12339 } 12340 } 12341 12342 function resize() { 12343 var i; 12344 for (i = 0; i < len; i += 1) { 12345 registeredAnimations[i].animation.resize(); 12346 } 12347 } 12348 12349 function activate() {
vendor: 6,430 bytes, lines 12350-12538
12350 if (!_isFrozen && playingAnimationsNum) { 12351 if (_stopped) { 12352 window.requestAnimationFrame(first); 12353 _stopped = false; 12354 } 12355 } 12356 } 12357 12358 function freeze() { 12359 _isFrozen = true; 12360 } 12361 12362 function unfreeze() { 12363 _isFrozen = false; 12364 activate(); 12365 } 12366 12367 function setVolume(val, animation) { 12368 var i; 12369 for (i = 0; i < len; i += 1) { 12370 registeredAnimations[i].animation.setVolume(val, animation); 12371 } 12372 } 12373 12374 function mute(animation) { 12375 var i; 12376 for (i = 0; i < len; i += 1) { 12377 registeredAnimations[i].animation.mute(animation); 12378 } 12379 } 12380 12381 function unmute(animation) { 12382 var i; 12383 for (i = 0; i < len; i += 1) { 12384 registeredAnimations[i].animation.unmute(animation); 12385 } 12386 } 12387 12388 moduleOb.registerAnimation = registerAnimation; 12389 moduleOb.loadAnimation = loadAnimation; 12390 moduleOb.setSpeed = setSpeed; 12391 moduleOb.setDirection = setDirection; 12392 moduleOb.play = play; 12393 moduleOb.pause = pause; 12394 moduleOb.stop = stop; 12395 moduleOb.togglePause = togglePause; 12396 moduleOb.searchAnimations = searchAnimations; 12397 moduleOb.resize = resize; 12398 // moduleOb.start = start; 12399 moduleOb.goToAndStop = goToAndStop; 12400 moduleOb.destroy = destroy; 12401 moduleOb.freeze = freeze; 12402 moduleOb.unfreeze = unfreeze; 12403 moduleOb.setVolume = setVolume; 12404 moduleOb.mute = mute; 12405 moduleOb.unmute = unmute; 12406 moduleOb.getRegisteredAnimations = getRegisteredAnimations; 12407 return moduleOb; 12408}()); 12409 12410/* global createElementID, subframeEnabled, ProjectInterface, ImagePreloader, audioControllerFactory, extendPrototype, BaseEvent, 12411CanvasRenderer, SVGRenderer, HybridRenderer, assetLoader, dataManager, expressionsPlugin, BMEnterFrameEvent, BMCompleteLoopEvent, 12412BMCompleteEvent, BMSegmentStartEvent, BMDestroyEvent, BMEnterFrameEvent, BMCompleteLoopEvent, BMCompleteEvent, BMSegmentStartEvent, 12413BMDestroyEvent, BMRenderFrameErrorEvent, BMConfigErrorEvent */ 12414 12415var AnimationItem = function () { 12416 this._cbs = []; 12417 this.name = ''; 12418 this.path = ''; 12419 this.isLoaded = false; 12420 this.currentFrame = 0; 12421 this.currentRawFrame = 0; 12422 this.firstFrame = 0; 12423 this.totalFrames = 0; 12424 this.frameRate = 0; 12425 this.frameMult = 0; 12426 this.playSpeed = 1; 12427 this.playDirection = 1; 12428 this.playCount = 0; 12429 this.animationData = {}; 12430 this.assets = []; 12431 this.isPaused = true; 12432 this.autoplay = false; 12433 this.loop = true; 12434 this.renderer = null; 12435 this.animationID = createElementID(); 12436 this.assetsPath = ''; 12437 this.timeCompleted = 0; 12438 this.segmentPos = 0; 12439 this.isSubframeEnabled = subframeEnabled; 12440 this.segments = []; 12441 this._idle = true; 12442 this._completedLoop = false; 12443 this.projectInterface = ProjectInterface(); 12444 this.imagePreloader = new ImagePreloader(); 12445 this.audioController = audioControllerFactory(); 12446}; 12447 12448extendPrototype([BaseEvent], AnimationItem); 12449 12450AnimationItem.prototype.setParams = function (params) { 12451 if (params.wrapper || params.container) { 12452 this.wrapper = params.wrapper || params.container; 12453 } 12454 var animType = 'svg'; 12455 if (params.animType) { 12456 animType = params.animType; 12457 } else if (params.renderer) { 12458 animType = params.renderer; 12459 } 12460 switch (animType) { 12461 case 'canvas': 12462 this.renderer = new CanvasRenderer(this, params.rendererSettings); 12463 break; 12464 case 'svg': 12465 this.renderer = new SVGRenderer(this, params.rendererSettings); 12466 break; 12467 default: 12468 this.renderer = new HybridRenderer(this, params.rendererSettings); 12469 break; 12470 } 12471 this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs); 12472 this.renderer.setProjectInterface(this.projectInterface); 12473 this.animType = animType; 12474 if (params.loop === '' 12475 || params.loop === null 12476 || params.loop === undefined 12477 || params.loop === true) { 12478 this.loop = true; 12479 } else if (params.loop === false) { 12480 this.loop = false; 12481 } else { 12482 this.loop = parseInt(params.loop, 10); 12483 } 12484 this.autoplay = 'autoplay' in params ? params.autoplay : true; 12485 this.name = params.name ? params.name : ''; 12486 this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true; 12487 this.assetsPath = params.assetsPath; 12488 this.initialSegment = params.initialSegment; 12489 if (params.audioFactory) { 12490 this.audioController.setAudioFactory(params.audioFactory); 12491 } 12492 if (params.animationData) { 12493 this.configAnimation(params.animationData); 12494 } else if (params.path) { 12495 if (params.path.lastIndexOf('\\') !== -1) { 12496 this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1); 12497 } else { 12498 this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1); 12499 } 12500 this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1); 12501 this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json')); 12502 12503 assetLoader.load(params.path, this.configAnimation.bind(this), function () { 12504 this.trigger('data_failed'); 12505 }.bind(this)); 12506 } 12507}; 12508 12509AnimationItem.prototype.setData = function (wrapper, animationData) { 12510 if (animationData) { 12511 if (typeof animationData !== 'object') { 12512 animationData = JSON.parse(animationData); 12513 } 12514 } 12515 var params = { 12516 wrapper: wrapper, 12517 animationData: animationData, 12518 }; 12519 var wrapperAttributes = wrapper.attributes; 12520 12521 params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary 12522 ? wrapperAttributes.getNamedItem('data-animation-path').value 12523 : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary 12524 ? wrapperAttributes.getNamedItem('data-bm-path').value 12525 : wrapperAttributes.getNamedItem('bm-path') 12526 ? wrapperAttributes.getNamedItem('bm-path').value 12527 : ''; 12528 params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary 12529 ? wrapperAttributes.getNamedItem('data-anim-type').value 12530 : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary 12531 ? wrapperAttributes.getNamedItem('data-bm-type').value 12532 : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary 12533 ? wrapperAttributes.getNamedItem('bm-type').value 12534 : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary 12535 ? wrapperAttributes.getNamedItem('data-bm-renderer').value 12536 : wrapperAttributes.getNamedItem('bm-renderer') 12537 ? wrapperAttributes.getNamedItem('bm-renderer').value 12538 :
vendor: 2,122 bytes, lines 12538-12581
12538 'canvas'; 12539 12540 var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary 12541 ? wrapperAttributes.getNamedItem('data-anim-loop').value 12542 : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary 12543 ? wrapperAttributes.getNamedItem('data-bm-loop').value 12544 : wrapperAttributes.getNamedItem('bm-loop') 12545 ? wrapperAttributes.getNamedItem('bm-loop').value 12546 : ''; 12547 if (loop === 'false') { 12548 params.loop = false; 12549 } else if (loop === 'true') { 12550 params.loop = true; 12551 } else if (loop !== '') { 12552 params.loop = parseInt(loop, 10); 12553 } 12554 var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary 12555 ? wrapperAttributes.getNamedItem('data-anim-autoplay').value 12556 : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary 12557 ? wrapperAttributes.getNamedItem('data-bm-autoplay').value 12558 : wrapperAttributes.getNamedItem('bm-autoplay') 12559 ? wrapperAttributes.getNamedItem('bm-autoplay').value 12560 : true; 12561 params.autoplay = autoplay !== 'false'; 12562 12563 params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary 12564 ? wrapperAttributes.getNamedItem('data-name').value 12565 : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary 12566 ? wrapperAttributes.getNamedItem('data-bm-name').value 12567 : wrapperAttributes.getNamedItem('bm-name') 12568 ? wrapperAttributes.getNamedItem('bm-name').value 12569 : ''; 12570 var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary 12571 ? wrapperAttributes.getNamedItem('data-anim-prerender').value 12572 : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary 12573 ? wrapperAttributes.getNamedItem('data-bm-prerender').value 12574 : wrapperAttributes.getNamedItem('bm-prerender') 12575 ? wrapperAttributes.getNamedItem('bm-prerender').value 12576 : ''; 12577 12578 if (prerender === 'false') { 12579 params.prerender = false; 12580 } 12581
vendor: 9,155 bytes, lines 12581-12897
12581this.setParams(params); 12582}; 12583 12584AnimationItem.prototype.includeLayers = function (data) { 12585 if (data.op > this.animationData.op) { 12586 this.animationData.op = data.op; 12587 this.totalFrames = Math.floor(data.op - this.animationData.ip); 12588 } 12589 var layers = this.animationData.layers; 12590 var i; 12591 var len = layers.length; 12592 var newLayers = data.layers; 12593 var j; 12594 var jLen = newLayers.length; 12595 for (j = 0; j < jLen; j += 1) { 12596 i = 0; 12597 while (i < len) { 12598 if (layers[i].id === newLayers[j].id) { 12599 layers[i] = newLayers[j]; 12600 break; 12601 } 12602 i += 1; 12603 } 12604 } 12605 if (data.chars || data.fonts) { 12606 this.renderer.globalData.fontManager.addChars(data.chars); 12607 this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs); 12608 } 12609 if (data.assets) { 12610 len = data.assets.length; 12611 for (i = 0; i < len; i += 1) { 12612 this.animationData.assets.push(data.assets[i]); 12613 } 12614 } 12615 this.animationData.__complete = false; 12616 dataManager.completeData(this.animationData, this.renderer.globalData.fontManager); 12617 this.renderer.includeLayers(data.layers); 12618 if (expressionsPlugin) { 12619 expressionsPlugin.initExpressions(this); 12620 } 12621 this.loadNextSegment(); 12622}; 12623 12624AnimationItem.prototype.loadNextSegment = function () { 12625 var segments = this.animationData.segments; 12626 if (!segments || segments.length === 0 || !this.autoloadSegments) { 12627 this.trigger('data_ready'); 12628 this.timeCompleted = this.totalFrames; 12629 return; 12630 } 12631 var segment = segments.shift(); 12632 this.timeCompleted = segment.time * this.frameRate; 12633 var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json'; 12634 this.segmentPos += 1; 12635 assetLoader.load(segmentPath, this.includeLayers.bind(this), function () { 12636 this.trigger('data_failed'); 12637 }.bind(this)); 12638}; 12639 12640AnimationItem.prototype.loadSegments = function () { 12641 var segments = this.animationData.segments; 12642 if (!segments) { 12643 this.timeCompleted = this.totalFrames; 12644 } 12645 this.loadNextSegment(); 12646}; 12647 12648AnimationItem.prototype.imagesLoaded = function () { 12649 this.trigger('loaded_images'); 12650 this.checkLoaded(); 12651}; 12652 12653AnimationItem.prototype.preloadImages = function () { 12654 this.imagePreloader.setAssetsPath(this.assetsPath); 12655 this.imagePreloader.setPath(this.path); 12656 this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this)); 12657}; 12658 12659AnimationItem.prototype.configAnimation = function (animData) { 12660 if (!this.renderer) { 12661 return; 12662 } 12663 try { 12664 this.animationData = animData; 12665 12666 if (this.initialSegment) { 12667 this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]); 12668 this.firstFrame = Math.round(this.initialSegment[0]); 12669 } else { 12670 this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip); 12671 this.firstFrame = Math.round(this.animationData.ip); 12672 } 12673 this.renderer.configAnimation(animData); 12674 if (!animData.assets) { 12675 animData.assets = []; 12676 } 12677 12678 this.assets = this.animationData.assets; 12679 this.frameRate = this.animationData.fr; 12680 this.frameMult = this.animationData.fr / 1000; 12681 this.renderer.searchExtraCompositions(animData.assets); 12682 this.trigger('config_ready'); 12683 this.preloadImages(); 12684 this.loadSegments(); 12685 this.updaFrameModifier(); 12686 this.waitForFontsLoaded(); 12687 if (this.isPaused) { 12688 this.audioController.pause(); 12689 } 12690 } catch (error) { 12691 this.triggerConfigError(error); 12692 } 12693}; 12694 12695AnimationItem.prototype.waitForFontsLoaded = function () { 12696 if (!this.renderer) { 12697 return; 12698 } 12699 if (this.renderer.globalData.fontManager.isLoaded) { 12700 this.checkLoaded(); 12701 } else { 12702 setTimeout(this.waitForFontsLoaded.bind(this), 20); 12703 } 12704}; 12705 12706AnimationItem.prototype.checkLoaded = function () { 12707 if (!this.isLoaded 12708 && this.renderer.globalData.fontManager.isLoaded 12709 && (this.imagePreloader.loaded() || this.renderer.rendererType !== 'canvas') 12710 ) { 12711 this.isLoaded = true; 12712 dataManager.completeData(this.animationData, this.renderer.globalData.fontManager); 12713 if (expressionsPlugin) { 12714 expressionsPlugin.initExpressions(this); 12715 } 12716 this.renderer.initItems(); 12717 setTimeout(function () { 12718 this.trigger('DOMLoaded'); 12719 }.bind(this), 0); 12720 this.gotoFrame(); 12721 if (this.autoplay) { 12722 this.play(); 12723 } 12724 } 12725}; 12726 12727AnimationItem.prototype.resize = function () { 12728 this.renderer.updateContainerSize(); 12729}; 12730 12731AnimationItem.prototype.setSubframe = function (flag) { 12732 this.isSubframeEnabled = !!flag; 12733}; 12734 12735AnimationItem.prototype.gotoFrame = function () { 12736 this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise 12737 12738 if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) { 12739 this.currentFrame = this.timeCompleted; 12740 } 12741 this.trigger('enterFrame'); 12742 this.renderFrame(); 12743}; 12744 12745AnimationItem.prototype.renderFrame = function () { 12746 if (this.isLoaded === false) { 12747 return; 12748 } 12749 try { 12750 this.renderer.renderFrame(this.currentFrame + this.firstFrame); 12751 } catch (error) { 12752 this.triggerRenderFrameError(error); 12753 } 12754}; 12755 12756AnimationItem.prototype.play = function (name) { 12757 if (name && this.name !== name) { 12758 return; 12759 } 12760 if (this.isPaused === true) { 12761 this.isPaused = false; 12762 this.audioController.resume(); 12763 if (this._idle) { 12764 this._idle = false; 12765 this.trigger('_active'); 12766 } 12767 } 12768}; 12769 12770AnimationItem.prototype.pause = function (name) { 12771 if (name && this.name !== name) { 12772 return; 12773 } 12774 if (this.isPaused === false) { 12775 this.isPaused = true; 12776 this._idle = true; 12777 this.trigger('_idle'); 12778 this.audioController.pause(); 12779 } 12780}; 12781 12782AnimationItem.prototype.togglePause = function (name) { 12783 if (name && this.name !== name) { 12784 return; 12785 } 12786 if (this.isPaused === true) { 12787 this.play(); 12788 } else { 12789 this.pause(); 12790 } 12791}; 12792 12793AnimationItem.prototype.stop = function (name) { 12794 if (name && this.name !== name) { 12795 return; 12796 } 12797 this.pause(); 12798 this.playCount = 0; 12799 this._completedLoop = false; 12800 this.setCurrentRawFrameValue(0); 12801}; 12802 12803AnimationItem.prototype.goToAndStop = function (value, isFrame, name) { 12804 if (name && this.name !== name) { 12805 return; 12806 } 12807 if (isFrame) { 12808 this.setCurrentRawFrameValue(value); 12809 } else { 12810 this.setCurrentRawFrameValue(value * this.frameModifier); 12811 } 12812 this.pause(); 12813}; 12814 12815AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) { 12816 this.goToAndStop(value, isFrame, name); 12817 this.play(); 12818}; 12819 12820AnimationItem.prototype.advanceTime = function (value) { 12821 if (this.isPaused === true || this.isLoaded === false) { 12822 return; 12823 } 12824 var nextValue = this.currentRawFrame + value * this.frameModifier; 12825 var _isComplete = false; 12826 // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations. 12827 // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop. 12828 if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) { 12829 if (!this.loop || this.playCount === this.loop) { 12830 if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) { 12831 _isComplete = true; 12832 nextValue = this.totalFrames - 1; 12833 } 12834 } else if (nextValue >= this.totalFrames) { 12835 this.playCount += 1; 12836 if (!this.checkSegments(nextValue % this.totalFrames)) { 12837 this.setCurrentRawFrameValue(nextValue % this.totalFrames); 12838 this._completedLoop = true; 12839 this.trigger('loopComplete'); 12840 } 12841 } else { 12842 this.setCurrentRawFrameValue(nextValue); 12843 } 12844 } else if (nextValue < 0) { 12845 if (!this.checkSegments(nextValue % this.totalFrames)) { 12846 if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus 12847 this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames)); 12848 if (!this._completedLoop) { 12849 this._completedLoop = true; 12850 } else { 12851 this.trigger('loopComplete'); 12852 } 12853 } else { 12854 _isComplete = true; 12855 nextValue = 0; 12856 } 12857 } 12858 } else { 12859 this.setCurrentRawFrameValue(nextValue); 12860 } 12861 if (_isComplete) { 12862 this.setCurrentRawFrameValue(nextValue); 12863 this.pause(); 12864 this.trigger('complete'); 12865 } 12866}; 12867 12868AnimationItem.prototype.adjustSegment = function (arr, offset) { 12869 this.playCount = 0; 12870 if (arr[1] < arr[0]) { 12871 if (this.frameModifier > 0) { 12872 if (this.playSpeed < 0) { 12873 this.setSpeed(-this.playSpeed); 12874 } else { 12875 this.setDirection(-1); 12876 } 12877 } 12878 this.totalFrames = arr[0] - arr[1]; 12879 this.timeCompleted = this.totalFrames; 12880 this.firstFrame = arr[1]; 12881 this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset); 12882 } else if (arr[1] > arr[0]) { 12883 if (this.frameModifier < 0) { 12884 if (this.playSpeed < 0) { 12885 this.setSpeed(-this.playSpeed); 12886 } else { 12887 this.setDirection(1); 12888 } 12889 } 12890 this.totalFrames = arr[1] - arr[0]; 12891 this.timeCompleted = this.totalFrames; 12892 this.firstFrame = arr[0]; 12893 this.setCurrentRawFrameValue(0.001 + offset); 12894 } 12895 this.trigger('segmentStart'); 12896}; 12897AnimationItem.prototype.setSegment = function (init, end) {
vendor: 57,785 bytes, lines 12898-14760
12898 var pendingFrame = -1; 12899 if (this.isPaused) { 12900 if (this.currentRawFrame + this.firstFrame < init) { 12901 pendingFrame = init; 12902 } else if (this.currentRawFrame + this.firstFrame > end) { 12903 pendingFrame = end - init; 12904 } 12905 } 12906 12907 this.firstFrame = init; 12908 this.totalFrames = end - init; 12909 this.timeCompleted = this.totalFrames; 12910 if (pendingFrame !== -1) { 12911 this.goToAndStop(pendingFrame, true); 12912 } 12913}; 12914 12915AnimationItem.prototype.playSegments = function (arr, forceFlag) { 12916 if (forceFlag) { 12917 this.segments.length = 0; 12918 } 12919 if (typeof arr[0] === 'object') { 12920 var i; 12921 var len = arr.length; 12922 for (i = 0; i < len; i += 1) { 12923 this.segments.push(arr[i]); 12924 } 12925 } else { 12926 this.segments.push(arr); 12927 } 12928 if (this.segments.length && forceFlag) { 12929 this.adjustSegment(this.segments.shift(), 0); 12930 } 12931 if (this.isPaused) { 12932 this.play(); 12933 } 12934}; 12935 12936AnimationItem.prototype.resetSegments = function (forceFlag) { 12937 this.segments.length = 0; 12938 this.segments.push([this.animationData.ip, this.animationData.op]); 12939 // this.segments.push([this.animationData.ip*this.frameRate,Math.floor(this.animationData.op - this.animationData.ip+this.animationData.ip*this.frameRate)]); 12940 if (forceFlag) { 12941 this.checkSegments(0); 12942 } 12943}; 12944AnimationItem.prototype.checkSegments = function (offset) { 12945 if (this.segments.length) { 12946 this.adjustSegment(this.segments.shift(), offset); 12947 return true; 12948 } 12949 return false; 12950}; 12951 12952AnimationItem.prototype.destroy = function (name) { 12953 if ((name && this.name !== name) || !this.renderer) { 12954 return; 12955 } 12956 this.renderer.destroy(); 12957 this.imagePreloader.destroy(); 12958 this.trigger('destroy'); 12959 this._cbs = null; 12960 this.onEnterFrame = null; 12961 this.onLoopComplete = null; 12962 this.onComplete = null; 12963 this.onSegmentStart = null; 12964 this.onDestroy = null; 12965 this.renderer = null; 12966 this.renderer = null; 12967 this.imagePreloader = null; 12968 this.projectInterface = null; 12969}; 12970 12971AnimationItem.prototype.setCurrentRawFrameValue = function (value) { 12972 this.currentRawFrame = value; 12973 this.gotoFrame(); 12974}; 12975 12976AnimationItem.prototype.setSpeed = function (val) { 12977 this.playSpeed = val; 12978 this.updaFrameModifier(); 12979}; 12980 12981AnimationItem.prototype.setDirection = function (val) { 12982 this.playDirection = val < 0 ? -1 : 1; 12983 this.updaFrameModifier(); 12984}; 12985 12986AnimationItem.prototype.setVolume = function (val, name) { 12987 if (name && this.name !== name) { 12988 return; 12989 } 12990 this.audioController.setVolume(val); 12991}; 12992 12993AnimationItem.prototype.getVolume = function () { 12994 return this.audioController.getVolume(); 12995}; 12996 12997AnimationItem.prototype.mute = function (name) { 12998 if (name && this.name !== name) { 12999 return; 13000 } 13001 this.audioController.mute(); 13002}; 13003 13004AnimationItem.prototype.unmute = function (name) { 13005 if (name && this.name !== name) { 13006 return; 13007 } 13008 this.audioController.unmute(); 13009}; 13010 13011AnimationItem.prototype.updaFrameModifier = function () { 13012 this.frameModifier = this.frameMult * this.playSpeed * this.playDirection; 13013 this.audioController.setRate(this.playSpeed * this.playDirection); 13014}; 13015 13016AnimationItem.prototype.getPath = function () { 13017 return this.path; 13018}; 13019 13020AnimationItem.prototype.getAssetsPath = function (assetData) { 13021 var path = ''; 13022 if (assetData.e) { 13023 path = assetData.p; 13024 } else if (this.assetsPath) { 13025 var imagePath = assetData.p; 13026 if (imagePath.indexOf('images/') !== -1) { 13027 imagePath = imagePath.split('/')[1]; 13028 } 13029 path = this.assetsPath + imagePath; 13030 } else { 13031 path = this.path; 13032 path += assetData.u ? assetData.u : ''; 13033 path += assetData.p; 13034 } 13035 return path; 13036}; 13037 13038AnimationItem.prototype.getAssetData = function (id) { 13039 var i = 0; 13040 var len = this.assets.length; 13041 while (i < len) { 13042 if (id === this.assets[i].id) { 13043 return this.assets[i]; 13044 } 13045 i += 1; 13046 } 13047 return null; 13048}; 13049 13050AnimationItem.prototype.hide = function () { 13051 this.renderer.hide(); 13052}; 13053 13054AnimationItem.prototype.show = function () { 13055 this.renderer.show(); 13056}; 13057 13058AnimationItem.prototype.getDuration = function (isFrame) { 13059 return isFrame ? this.totalFrames : this.totalFrames / this.frameRate; 13060}; 13061 13062AnimationItem.prototype.trigger = function (name) { 13063 if (this._cbs && this._cbs[name]) { 13064 switch (name) { 13065 case 'enterFrame': 13066 this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier)); 13067 break; 13068 case 'loopComplete': 13069 this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult)); 13070 break; 13071 case 'complete': 13072 this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult)); 13073 break; 13074 case 'segmentStart': 13075 this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames)); 13076 break; 13077 case 'destroy': 13078 this.triggerEvent(name, new BMDestroyEvent(name, this)); 13079 break; 13080 default: 13081 this.triggerEvent(name); 13082 } 13083 } 13084 if (name === 'enterFrame' && this.onEnterFrame) { 13085 this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult)); 13086 } 13087 if (name === 'loopComplete' && this.onLoopComplete) { 13088 this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult)); 13089 } 13090 if (name === 'complete' && this.onComplete) { 13091 this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult)); 13092 } 13093 if (name === 'segmentStart' && this.onSegmentStart) { 13094 this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames)); 13095 } 13096 if (name === 'destroy' && this.onDestroy) { 13097 this.onDestroy.call(this, new BMDestroyEvent(name, this)); 13098 } 13099}; 13100 13101AnimationItem.prototype.triggerRenderFrameError = function (nativeError) { 13102 var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame); 13103 this.triggerEvent('error', error); 13104 13105 if (this.onError) { 13106 this.onError.call(this, error); 13107 } 13108}; 13109 13110AnimationItem.prototype.triggerConfigError = function (nativeError) { 13111 var error = new BMConfigErrorEvent(nativeError, this.currentFrame); 13112 this.triggerEvent('error', error); 13113 13114 if (this.onError) { 13115 this.onError.call(this, error); 13116 } 13117}; 13118 13119/* global CompExpressionInterface, expressionsPlugin: writable */ 13120/* exported expressionsPlugin */ 13121 13122var Expressions = (function () { 13123 var ob = {}; 13124 ob.initExpressions = initExpressions; 13125 13126 function initExpressions(animation) { 13127 var stackCount = 0; 13128 var registers = []; 13129 13130 function pushExpression() { 13131 stackCount += 1; 13132 } 13133 13134 function popExpression() { 13135 stackCount -= 1; 13136 if (stackCount === 0) { 13137 releaseInstances(); 13138 } 13139 } 13140 13141 function registerExpressionProperty(expression) { 13142 if (registers.indexOf(expression) === -1) { 13143 registers.push(expression); 13144 } 13145 } 13146 13147 function releaseInstances() { 13148 var i; 13149 var len = registers.length; 13150 for (i = 0; i < len; i += 1) { 13151 registers[i].release(); 13152 } 13153 registers.length = 0; 13154 } 13155 13156 animation.renderer.compInterface = CompExpressionInterface(animation.renderer); 13157 animation.renderer.globalData.projectInterface.registerComposition(animation.renderer); 13158 animation.renderer.globalData.pushExpression = pushExpression; 13159 animation.renderer.globalData.popExpression = popExpression; 13160 animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty; 13161 } 13162 return ob; 13163}()); 13164 13165expressionsPlugin = Expressions; 13166 13167/* eslint-disable camelcase, no-unused-vars */ 13168/* global BMMath, BezierFactory, createTypedArray, degToRads, shapePool */ 13169 13170var ExpressionManager = (function () { 13171 'use strict'; 13172 13173 var ob = {}; 13174 var Math = BMMath; 13175 var window = null; 13176 var document = null; 13177 13178 function $bm_isInstanceOfArray(arr) { 13179 return arr.constructor === Array || arr.constructor === Float32Array; 13180 } 13181 13182 function isNumerable(tOfV, v) { 13183 return tOfV === 'number' || tOfV === 'boolean' || tOfV === 'string' || v instanceof Number; 13184 } 13185 13186 function $bm_neg(a) { 13187 var tOfA = typeof a; 13188 if (tOfA === 'number' || tOfA === 'boolean' || a instanceof Number) { 13189 return -a; 13190 } 13191 if ($bm_isInstanceOfArray(a)) { 13192 var i; 13193 var lenA = a.length; 13194 var retArr = []; 13195 for (i = 0; i < lenA; i += 1) { 13196 retArr[i] = -a[i]; 13197 } 13198 return retArr; 13199 } 13200 if (a.propType) { 13201 return a.v; 13202 } 13203 return -a; 13204 } 13205 13206 var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get; 13207 var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get; 13208 var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get; 13209 13210 function sum(a, b) { 13211 var tOfA = typeof a; 13212 var tOfB = typeof b; 13213 if (tOfA === 'string' || tOfB === 'string') { 13214 return a + b; 13215 } 13216 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13217 return a + b; 13218 } 13219 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13220 a = a.slice(0); 13221 a[0] += b; 13222 return a; 13223 } 13224 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13225 b = b.slice(0); 13226 b[0] = a + b[0]; 13227 return b; 13228 } 13229 if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) { 13230 var i = 0; 13231 var lenA = a.length; 13232 var lenB = b.length; 13233 var retArr = []; 13234 while (i < lenA || i < lenB) { 13235 if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) { 13236 retArr[i] = a[i] + b[i]; 13237 } else { 13238 retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i]; 13239 } 13240 i += 1; 13241 } 13242 return retArr; 13243 } 13244 return 0; 13245 } 13246 var add = sum; 13247 13248 function sub(a, b) { 13249 var tOfA = typeof a; 13250 var tOfB = typeof b; 13251 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13252 if (tOfA === 'string') { 13253 a = parseInt(a, 10); 13254 } 13255 if (tOfB === 'string') { 13256 b = parseInt(b, 10); 13257 } 13258 return a - b; 13259 } 13260 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13261 a = a.slice(0); 13262 a[0] -= b; 13263 return a; 13264 } 13265 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13266 b = b.slice(0); 13267 b[0] = a - b[0]; 13268 return b; 13269 } 13270 if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) { 13271 var i = 0; 13272 var lenA = a.length; 13273 var lenB = b.length; 13274 var retArr = []; 13275 while (i < lenA || i < lenB) { 13276 if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) { 13277 retArr[i] = a[i] - b[i]; 13278 } else { 13279 retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i]; 13280 } 13281 i += 1; 13282 } 13283 return retArr; 13284 } 13285 return 0; 13286 } 13287 13288 function mul(a, b) { 13289 var tOfA = typeof a; 13290 var tOfB = typeof b; 13291 var arr; 13292 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13293 return a * b; 13294 } 13295 13296 var i; 13297 var len; 13298 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13299 len = a.length; 13300 arr = createTypedArray('float32', len); 13301 for (i = 0; i < len; i += 1) { 13302 arr[i] = a[i] * b; 13303 } 13304 return arr; 13305 } 13306 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13307 len = b.length; 13308 arr = createTypedArray('float32', len); 13309 for (i = 0; i < len; i += 1) { 13310 arr[i] = a * b[i]; 13311 } 13312 return arr; 13313 } 13314 return 0; 13315 } 13316 13317 function div(a, b) { 13318 var tOfA = typeof a; 13319 var tOfB = typeof b; 13320 var arr; 13321 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13322 return a / b; 13323 } 13324 var i; 13325 var len; 13326 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13327 len = a.length; 13328 arr = createTypedArray('float32', len); 13329 for (i = 0; i < len; i += 1) { 13330 arr[i] = a[i] / b; 13331 } 13332 return arr; 13333 } 13334 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13335 len = b.length; 13336 arr = createTypedArray('float32', len); 13337 for (i = 0; i < len; i += 1) { 13338 arr[i] = a / b[i]; 13339 } 13340 return arr; 13341 } 13342 return 0; 13343 } 13344 function mod(a, b) { 13345 if (typeof a === 'string') { 13346 a = parseInt(a, 10); 13347 } 13348 if (typeof b === 'string') { 13349 b = parseInt(b, 10); 13350 } 13351 return a % b; 13352 } 13353 var $bm_sum = sum; 13354 var $bm_sub = sub; 13355 var $bm_mul = mul; 13356 var $bm_div = div; 13357 var $bm_mod = mod; 13358 13359 function clamp(num, min, max) { 13360 if (min > max) { 13361 var mm = max; 13362 max = min; 13363 min = mm; 13364 } 13365 return Math.min(Math.max(num, min), max); 13366 } 13367 13368 function radiansToDegrees(val) { 13369 return val / degToRads; 13370 } 13371 var radians_to_degrees = radiansToDegrees; 13372 13373 function degreesToRadians(val) { 13374 return val * degToRads; 13375 } 13376 var degrees_to_radians = radiansToDegrees; 13377 13378 var helperLengthArray = [0, 0, 0, 0, 0, 0]; 13379 13380 function length(arr1, arr2) { 13381 if (typeof arr1 === 'number' || arr1 instanceof Number) { 13382 arr2 = arr2 || 0; 13383 return Math.abs(arr1 - arr2); 13384 } 13385 if (!arr2) { 13386 arr2 = helperLengthArray; 13387 } 13388 var i; 13389 var len = Math.min(arr1.length, arr2.length); 13390 var addedLength = 0; 13391 for (i = 0; i < len; i += 1) { 13392 addedLength += Math.pow(arr2[i] - arr1[i], 2); 13393 } 13394 return Math.sqrt(addedLength); 13395 } 13396 13397 function normalize(vec) { 13398 return div(vec, length(vec)); 13399 } 13400 13401 function rgbToHsl(val) { 13402 var r = val[0]; var g = val[1]; var b = val[2]; 13403 var max = Math.max(r, g, b); 13404 var min = Math.min(r, g, b); 13405 var h; 13406 var s; 13407 var l = (max + min) / 2; 13408 13409 if (max === min) { 13410 h = 0; // achromatic 13411 s = 0; // achromatic 13412 } else { 13413 var d = max - min; 13414 s = l > 0.5 ? d / (2 - max - min) : d / (max + min); 13415 switch (max) { 13416 case r: h = (g - b) / d + (g < b ? 6 : 0); break; 13417 case g: h = (b - r) / d + 2; break; 13418 case b: h = (r - g) / d + 4; break; 13419 default: break; 13420 } 13421 h /= 6; 13422 } 13423 13424 return [h, s, l, val[3]]; 13425 } 13426 13427 function hue2rgb(p, q, t) { 13428 if (t < 0) t += 1; 13429 if (t > 1) t -= 1; 13430 if (t < 1 / 6) return p + (q - p) * 6 * t; 13431 if (t < 1 / 2) return q; 13432 if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; 13433 return p; 13434 } 13435 13436 function hslToRgb(val) { 13437 var h = val[0]; 13438 var s = val[1]; 13439 var l = val[2]; 13440 13441 var r; 13442 var g; 13443 var b; 13444 13445 if (s === 0) { 13446 r = l; // achromatic 13447 b = l; // achromatic 13448 g = l; // achromatic 13449 } else { 13450 var q = l < 0.5 ? l * (1 + s) : l + s - l * s; 13451 var p = 2 * l - q; 13452 r = hue2rgb(p, q, h + 1 / 3); 13453 g = hue2rgb(p, q, h); 13454 b = hue2rgb(p, q, h - 1 / 3); 13455 } 13456 13457 return [r, g, b, val[3]]; 13458 } 13459 13460 function linear(t, tMin, tMax, value1, value2) { 13461 if (value1 === undefined || value2 === undefined) { 13462 value1 = tMin; 13463 value2 = tMax; 13464 tMin = 0; 13465 tMax = 1; 13466 } 13467 if (tMax < tMin) { 13468 var _tMin = tMax; 13469 tMax = tMin; 13470 tMin = _tMin; 13471 } 13472 if (t <= tMin) { 13473 return value1; 13474 } if (t >= tMax) { 13475 return value2; 13476 } 13477 var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin); 13478 if (!value1.length) { 13479 return value1 + (value2 - value1) * perc; 13480 } 13481 var i; 13482 var len = value1.length; 13483 var arr = createTypedArray('float32', len); 13484 for (i = 0; i < len; i += 1) { 13485 arr[i] = value1[i] + (value2[i] - value1[i]) * perc; 13486 } 13487 return arr; 13488 } 13489 function random(min, max) { 13490 if (max === undefined) { 13491 if (min === undefined) { 13492 min = 0; 13493 max = 1; 13494 } else { 13495 max = min; 13496 min = undefined; 13497 } 13498 } 13499 if (max.length) { 13500 var i; 13501 var len = max.length; 13502 if (!min) { 13503 min = createTypedArray('float32', len); 13504 } 13505 var arr = createTypedArray('float32', len); 13506 var rnd = BMMath.random(); 13507 for (i = 0; i < len; i += 1) { 13508 arr[i] = min[i] + rnd * (max[i] - min[i]); 13509 } 13510 return arr; 13511 } 13512 if (min === undefined) { 13513 min = 0; 13514 } 13515 var rndm = BMMath.random(); 13516 return min + rndm * (max - min); 13517 } 13518 13519 function createPath(points, inTangents, outTangents, closed) { 13520 var i; 13521 var len = points.length; 13522 var path = shapePool.newElement(); 13523 path.setPathData(!!closed, len); 13524 var arrPlaceholder = [0, 0]; 13525 var inVertexPoint; 13526 var outVertexPoint; 13527 for (i = 0; i < len; i += 1) { 13528 inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder; 13529 outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder; 13530 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); 13531 } 13532 return path; 13533 } 13534 13535 function initiateExpression(elem, data, property) { 13536 var val = data.x; 13537 var needsVelocity = /velocity(?![\w\d])/.test(val); 13538 var _needsRandom = val.indexOf('random') !== -1; 13539 var elemType = elem.data.ty; 13540 var transform; 13541 var $bm_transform; 13542 var content; 13543 var effect; 13544 var thisProperty = property; 13545 thisProperty.valueAtTime = thisProperty.getValueAtTime; 13546 Object.defineProperty(thisProperty, 'value', { 13547 get: function () { 13548 return thisProperty.v; 13549 }, 13550 }); 13551 elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate; 13552 elem.comp.displayStartTime = 0; 13553 var inPoint = elem.data.ip / elem.comp.globalData.frameRate; 13554 var outPoint = elem.data.op / elem.comp.globalData.frameRate; 13555 var width = elem.data.sw ? elem.data.sw : 0; 13556 var height = elem.data.sh ? elem.data.sh : 0; 13557 var name = elem.data.nm; 13558 var loopIn; 13559 var loop_in; 13560 var loopOut; 13561 var loop_out; 13562 var smooth; 13563 var toWorld; 13564 var fromWorld; 13565 var fromComp; 13566 var toComp; 13567 var fromCompToSurface; 13568 var position; 13569 var rotation; 13570 var anchorPoint; 13571 var scale; 13572 var thisLayer; 13573 var thisComp; 13574 var mask; 13575 var valueAtTime; 13576 var velocityAtTime; 13577 13578 var scoped_bm_rt; 13579 var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval 13580 var numKeys = property.kf ? data.k.length : 0; 13581 13582 var active = !this.data || this.data.hd !== true; 13583 13584 var wiggle = function wiggle(freq, amp) { 13585 var iWiggle; 13586 var j; 13587 var lenWiggle = this.pv.length ? this.pv.length : 1; 13588 var addedAmps = createTypedArray('float32', lenWiggle); 13589 freq = 5; 13590 var iterations = Math.floor(time * freq); 13591 iWiggle = 0; 13592 j = 0; 13593 while (iWiggle < iterations) { 13594 // var rnd = BMMath.random(); 13595 for (j = 0; j < lenWiggle; j += 1) { 13596 addedAmps[j] += -amp + amp * 2 * BMMath.random(); 13597 // addedAmps[j] += -amp + amp*2*rnd; 13598 } 13599 iWiggle += 1; 13600 } 13601 // var rnd2 = BMMath.random(); 13602 var periods = time * freq; 13603 var perc = periods - Math.floor(periods); 13604 var arr = createTypedArray('float32', lenWiggle); 13605 if (lenWiggle > 1) { 13606 for (j = 0; j < lenWiggle; j += 1) { 13607 arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc; 13608 // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc; 13609 // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc); 13610 } 13611 return arr; 13612 } 13613 return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc; 13614 }.bind(this); 13615 13616 if (thisProperty.loopIn) { 13617 loopIn = thisProperty.loopIn.bind(thisProperty); 13618 loop_in = loopIn; 13619 } 13620 13621 if (thisProperty.loopOut) { 13622 loopOut = thisProperty.loopOut.bind(thisProperty); 13623 loop_out = loopOut; 13624 } 13625 13626 if (thisProperty.smooth) { 13627 smooth = thisProperty.smooth.bind(thisProperty); 13628 } 13629 13630 function loopInDuration(type, duration) { 13631 return loopIn(type, duration, true); 13632 } 13633 13634 function loopOutDuration(type, duration) { 13635 return loopOut(type, duration, true); 13636 } 13637 13638 if (this.getValueAtTime) { 13639 valueAtTime = this.getValueAtTime.bind(this); 13640 } 13641 13642 if (this.getVelocityAtTime) { 13643 velocityAtTime = this.getVelocityAtTime.bind(this); 13644 } 13645 13646 var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface); 13647 13648 function lookAt(elem1, elem2) { 13649 var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]]; 13650 var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads; 13651 var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads; 13652 return [yaw, pitch, 0]; 13653 } 13654 13655 function easeOut(t, tMin, tMax, val1, val2) { 13656 return applyEase(easeOutBez, t, tMin, tMax, val1, val2); 13657 } 13658 13659 function easeIn(t, tMin, tMax, val1, val2) { 13660 return applyEase(easeInBez, t, tMin, tMax, val1, val2); 13661 } 13662 13663 function ease(t, tMin, tMax, val1, val2) { 13664 return applyEase(easeInOutBez, t, tMin, tMax, val1, val2); 13665 } 13666 13667 function applyEase(fn, t, tMin, tMax, val1, val2) { 13668 if (val1 === undefined) { 13669 val1 = tMin; 13670 val2 = tMax; 13671 } else { 13672 t = (t - tMin) / (tMax - tMin); 13673 } 13674 if (t > 1) { 13675 t = 1; 13676 } else if (t < 0) { 13677 t = 0; 13678 } 13679 var mult = fn(t); 13680 if ($bm_isInstanceOfArray(val1)) { 13681 var iKey; 13682 var lenKey = val1.length; 13683 var arr = createTypedArray('float32', lenKey); 13684 for (iKey = 0; iKey < lenKey; iKey += 1) { 13685 arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey]; 13686 } 13687 return arr; 13688 } 13689 return (val2 - val1) * mult + val1; 13690 } 13691 13692 function nearestKey(time) { 13693 var iKey; 13694 var lenKey = data.k.length; 13695 var index; 13696 var keyTime; 13697 if (!data.k.length || typeof (data.k[0]) === 'number') { 13698 index = 0; 13699 keyTime = 0; 13700 } else { 13701 index = -1; 13702 time *= elem.comp.globalData.frameRate; 13703 if (time < data.k[0].t) { 13704 index = 1; 13705 keyTime = data.k[0].t; 13706 } else { 13707 for (iKey = 0; iKey < lenKey - 1; iKey += 1) { 13708 if (time === data.k[iKey].t) { 13709 index = iKey + 1; 13710 keyTime = data.k[iKey].t; 13711 break; 13712 } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) { 13713 if (time - data.k[iKey].t > data.k[iKey + 1].t - time) { 13714 index = iKey + 2; 13715 keyTime = data.k[iKey + 1].t; 13716 } else { 13717 index = iKey + 1; 13718 keyTime = data.k[iKey].t; 13719 } 13720 break; 13721 } 13722 } 13723 if (index === -1) { 13724 index = iKey + 1; 13725 keyTime = data.k[iKey].t; 13726 } 13727 } 13728 } 13729 var obKey = {}; 13730 obKey.index = index; 13731 obKey.time = keyTime / elem.comp.globalData.frameRate; 13732 return obKey; 13733 } 13734 13735 function key(ind) { 13736 var obKey; 13737 var iKey; 13738 var lenKey; 13739 if (!data.k.length || typeof (data.k[0]) === 'number') { 13740 throw new Error('The property has no keyframe at index ' + ind); 13741 } 13742 ind -= 1; 13743 obKey = { 13744 time: data.k[ind].t / elem.comp.globalData.frameRate, 13745 value: [], 13746 }; 13747 var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e; 13748 13749 lenKey = arr.length; 13750 for (iKey = 0; iKey < lenKey; iKey += 1) { 13751 obKey[iKey] = arr[iKey]; 13752 obKey.value[iKey] = arr[iKey]; 13753 } 13754 return obKey; 13755 } 13756 13757 function framesToTime(frames, fps) { 13758 if (!fps) { 13759 fps = elem.comp.globalData.frameRate; 13760 } 13761 return frames / fps; 13762 } 13763 13764 function timeToFrames(t, fps) { 13765 if (!t && t !== 0) { 13766 t = time; 13767 } 13768 if (!fps) { 13769 fps = elem.comp.globalData.frameRate; 13770 } 13771 return t * fps; 13772 } 13773 13774 function seedRandom(seed) { 13775 BMMath.seedrandom(randSeed + seed); 13776 } 13777 13778 function sourceRectAtTime() { 13779 return elem.sourceRectAtTime(); 13780 } 13781 13782 function substring(init, end) { 13783 if (typeof value === 'string') { 13784 if (end === undefined) { 13785 return value.substring(init); 13786 } 13787 return value.substring(init, end); 13788 } 13789 return ''; 13790 } 13791 13792 function substr(init, end) { 13793 if (typeof value === 'string') { 13794 if (end === undefined) { 13795 return value.substr(init); 13796 } 13797 return value.substr(init, end); 13798 } 13799 return ''; 13800 } 13801 13802 function posterizeTime(framesPerSecond) { 13803 time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond; 13804 value = valueAtTime(time); 13805 } 13806 13807 var time; 13808 var velocity; 13809 var value; 13810 var text; 13811 var textIndex; 13812 var textTotal; 13813 var selectorValue; 13814 var index = elem.data.ind; 13815 var hasParent = !!(elem.hierarchy && elem.hierarchy.length); 13816 var parent; 13817 var randSeed = Math.floor(Math.random() * 1000000); 13818 var globalData = elem.globalData; 13819 function executeExpression(_value) { 13820 // globalData.pushExpression(); 13821 value = _value; 13822 if (_needsRandom) { 13823 seedRandom(randSeed); 13824 } 13825 if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') { 13826 return value; 13827 } 13828 if (this.propType === 'textSelector') { 13829 textIndex = this.textIndex; 13830 textTotal = this.textTotal; 13831 selectorValue = this.selectorValue; 13832 } 13833 if (!thisLayer) { 13834 text = elem.layerInterface.text; 13835 thisLayer = elem.layerInterface; 13836 thisComp = elem.comp.compInterface; 13837 toWorld = thisLayer.toWorld.bind(thisLayer); 13838 fromWorld = thisLayer.fromWorld.bind(thisLayer); 13839 fromComp = thisLayer.fromComp.bind(thisLayer); 13840 toComp = thisLayer.toComp.bind(thisLayer); 13841 mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null; 13842 fromCompToSurface = fromComp; 13843 } 13844 if (!transform) { 13845 transform = elem.layerInterface('ADBE Transform Group'); 13846 $bm_transform = transform; 13847 if (transform) { 13848 anchorPoint = transform.anchorPoint; 13849 /* position = transform.position; 13850 rotation = transform.rotation; 13851 scale = transform.scale; */ 13852 } 13853 } 13854 13855 if (elemType === 4 && !content) { 13856 content = thisLayer('ADBE Root Vectors Group'); 13857 } 13858 if (!effect) { 13859 effect = thisLayer(4); 13860 } 13861 hasParent = !!(elem.hierarchy && elem.hierarchy.length); 13862 if (hasParent && !parent) { 13863 parent = elem.hierarchy[0].layerInterface; 13864 } 13865 time = this.comp.renderedFrame / this.comp.globalData.frameRate; 13866 if (needsVelocity) { 13867 velocity = velocityAtTime(time); 13868 } 13869 expression_function(); 13870 this.frameExpressionId = elem.globalData.frameId; 13871 13872 // TODO: Check if it's possible to return on ShapeInterface the .v value 13873 if (scoped_bm_rt.propType === 'shape') { 13874 scoped_bm_rt = scoped_bm_rt.v; 13875 } 13876 // globalData.popExpression(); 13877 return scoped_bm_rt; 13878 } 13879 return executeExpression; 13880 } 13881 13882 ob.initiateExpression = initiateExpression; 13883 return ob; 13884}()); 13885 13886/* global ExpressionManager, createTypedArray */ 13887/* exported expressionHelpers */ 13888 13889var expressionHelpers = (function () { 13890 function searchExpressions(elem, data, prop) { 13891 if (data.x) { 13892 prop.k = true; 13893 prop.x = true; 13894 prop.initiateExpression = ExpressionManager.initiateExpression; 13895 prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop)); 13896 } 13897 } 13898 13899 function getValueAtTime(frameNum) { 13900 frameNum *= this.elem.globalData.frameRate; 13901 frameNum -= this.offsetTime; 13902 if (frameNum !== this._cachingAtTime.lastFrame) { 13903 this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0; 13904 this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime); 13905 this._cachingAtTime.lastFrame = frameNum; 13906 } 13907 return this._cachingAtTime.value; 13908 } 13909 13910 function getSpeedAtTime(frameNum) { 13911 var delta = -0.01; 13912 var v1 = this.getValueAtTime(frameNum); 13913 var v2 = this.getValueAtTime(frameNum + delta); 13914 var speed = 0; 13915 if (v1.length) { 13916 var i; 13917 for (i = 0; i < v1.length; i += 1) { 13918 speed += Math.pow(v2[i] - v1[i], 2); 13919 } 13920 speed = Math.sqrt(speed) * 100; 13921 } else { 13922 speed = 0; 13923 } 13924 return speed; 13925 } 13926 13927 function getVelocityAtTime(frameNum) { 13928 if (this.vel !== undefined) { 13929 return this.vel; 13930 } 13931 var delta = -0.001; 13932 // frameNum += this.elem.data.st; 13933 var v1 = this.getValueAtTime(frameNum); 13934 var v2 = this.getValueAtTime(frameNum + delta); 13935 var velocity; 13936 if (v1.length) { 13937 velocity = createTypedArray('float32', v1.length); 13938 var i; 13939 for (i = 0; i < v1.length; i += 1) { 13940 // removing frameRate 13941 // if needed, don't add it here 13942 // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta); 13943 velocity[i] = (v2[i] - v1[i]) / delta; 13944 } 13945 } else { 13946 velocity = (v2 - v1) / delta; 13947 } 13948 return velocity; 13949 } 13950 13951 function getStaticValueAtTime() { 13952 return this.pv; 13953 } 13954 13955 function setGroupProperty(propertyGroup) { 13956 this.propertyGroup = propertyGroup; 13957 } 13958 13959 return { 13960 searchExpressions: searchExpressions, 13961 getSpeedAtTime: getSpeedAtTime, 13962 getVelocityAtTime: getVelocityAtTime, 13963 getValueAtTime: getValueAtTime, 13964 getStaticValueAtTime: getStaticValueAtTime, 13965 setGroupProperty: setGroupProperty, 13966 }; 13967}()); 13968 13969/* global createTypedArray, Matrix, TransformPropertyFactory, expressionHelpers, PropertyFactory, expressionHelpers, 13970initialDefaultFrame, shapePool, ShapePropertyFactory, bez, extendPrototype, ExpressionManager, createSizedArray */ 13971 13972(function addPropertyDecorator() { 13973 function loopOut(type, duration, durationFlag) { 13974 if (!this.k || !this.keyframes) { 13975 return this.pv; 13976 } 13977 type = type ? type.toLowerCase() : ''; 13978 var currentFrame = this.comp.renderedFrame; 13979 var keyframes = this.keyframes; 13980 var lastKeyFrame = keyframes[keyframes.length - 1].t; 13981 if (currentFrame <= lastKeyFrame) { 13982 return this.pv; 13983 } 13984 var cycleDuration; 13985 var firstKeyFrame; 13986 if (!durationFlag) { 13987 if (!duration || duration > keyframes.length - 1) { 13988 duration = keyframes.length - 1; 13989 } 13990 firstKeyFrame = keyframes[keyframes.length - 1 - duration].t; 13991 cycleDuration = lastKeyFrame - firstKeyFrame; 13992 } else { 13993 if (!duration) { 13994 cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip); 13995 } else { 13996 cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration); 13997 } 13998 firstKeyFrame = lastKeyFrame - cycleDuration; 13999 } 14000 var i; 14001 var len; 14002 var ret; 14003 if (type === 'pingpong') { 14004 var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration); 14005 if (iterations % 2 !== 0) { 14006 return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14007 } 14008 } else if (type === 'offset') { 14009 var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0); 14010 var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0); 14011 var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14012 var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration); 14013 if (this.pv.length) { 14014 ret = new Array(initV.length); 14015 len = ret.length; 14016 for (i = 0; i < len; i += 1) { 14017 ret[i] = (endV[i] - initV[i]) * repeats + current[i]; 14018 } 14019 return ret; 14020 } 14021 return (endV - initV) * repeats + current; 14022 } else if (type === 'continue') { 14023 var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0); 14024 var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0); 14025 if (this.pv.length) { 14026 ret = new Array(lastValue.length); 14027 len = ret.length; 14028 for (i = 0; i < len; i += 1) { 14029 ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line 14030 } 14031 return ret; 14032 } 14033 return lastValue + (lastValue - nextLastValue) * (((currentFrame - lastKeyFrame)) / 0.001); 14034 } 14035 return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14036 14037 } 14038 14039 function loopIn(type, duration, durationFlag) { 14040 if (!this.k) { 14041 return this.pv; 14042 } 14043 type = type ? type.toLowerCase() : ''; 14044 var currentFrame = this.comp.renderedFrame; 14045 var keyframes = this.keyframes; 14046 var firstKeyFrame = keyframes[0].t; 14047 if (currentFrame >= firstKeyFrame) { 14048 return this.pv; 14049 } 14050 var cycleDuration; 14051 var lastKeyFrame; 14052 if (!durationFlag) { 14053 if (!duration || duration > keyframes.length - 1) { 14054 duration = keyframes.length - 1; 14055 } 14056 lastKeyFrame = keyframes[duration].t; 14057 cycleDuration = lastKeyFrame - firstKeyFrame; 14058 } else { 14059 if (!duration) { 14060 cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame); 14061 } else { 14062 cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration); 14063 } 14064 lastKeyFrame = firstKeyFrame + cycleDuration; 14065 } 14066 var i; 14067 var len; 14068 var ret; 14069 if (type === 'pingpong') { 14070 var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration); 14071 if (iterations % 2 === 0) { 14072 return this.getValueAtTime((((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14073 } 14074 } else if (type === 'offset') { 14075 var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0); 14076 var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0); 14077 var current = this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration) + firstKeyFrame) / this.comp.globalData.frameRate, 0); 14078 var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1; 14079 if (this.pv.length) { 14080 ret = new Array(initV.length); 14081 len = ret.length; 14082 for (i = 0; i < len; i += 1) { 14083 ret[i] = current[i] - (endV[i] - initV[i]) * repeats; 14084 } 14085 return ret; 14086 } 14087 return current - (endV - initV) * repeats; 14088 } else if (type === 'continue') { 14089 var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0); 14090 var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0); 14091 if (this.pv.length) { 14092 ret = new Array(firstValue.length); 14093 len = ret.length; 14094 for (i = 0; i < len; i += 1) { 14095 ret[i] = firstValue[i] + ((firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame)) / 0.001; 14096 } 14097 return ret; 14098 } 14099 return firstValue + ((firstValue - nextFirstValue) * (firstKeyFrame - currentFrame)) / 0.001; 14100 } 14101 return this.getValueAtTime(((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame))) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14102 14103 } 14104 14105 function smooth(width, samples) { 14106 if (!this.k) { 14107 return this.pv; 14108 } 14109 width = (width || 0.4) * 0.5; 14110 samples = Math.floor(samples || 5); 14111 if (samples <= 1) { 14112 return this.pv; 14113 } 14114 var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate; 14115 var initFrame = currentTime - width; 14116 var endFrame = currentTime + width; 14117 var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1; 14118 var i = 0; 14119 var j = 0; 14120 var value; 14121 if (this.pv.length) { 14122 value = createTypedArray('float32', this.pv.length); 14123 } else { 14124 value = 0; 14125 } 14126 var sampleValue; 14127 while (i < samples) { 14128 sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency); 14129 if (this.pv.length) { 14130 for (j = 0; j < this.pv.length; j += 1) { 14131 value[j] += sampleValue[j]; 14132 } 14133 } else { 14134 value += sampleValue; 14135 } 14136 i += 1; 14137 } 14138 if (this.pv.length) { 14139 for (j = 0; j < this.pv.length; j += 1) { 14140 value[j] /= samples; 14141 } 14142 } else { 14143 value /= samples; 14144 } 14145 return value; 14146 } 14147 14148 function getTransformValueAtTime(time) { 14149 if (!this._transformCachingAtTime) { 14150 this._transformCachingAtTime = { 14151 v: new Matrix(), 14152 }; 14153 } 14154 /// / 14155 var matrix = this._transformCachingAtTime.v; 14156 matrix.cloneFromProps(this.pre.props); 14157 if (this.appliedTransformations < 1) { 14158 var anchor = this.a.getValueAtTime(time); 14159 matrix.translate( 14160 -anchor[0] * this.a.mult, 14161 -anchor[1] * this.a.mult, 14162 anchor[2] * this.a.mult 14163 ); 14164 } 14165 if (this.appliedTransformations < 2) { 14166 var scale = this.s.getValueAtTime(time); 14167 matrix.scale( 14168 scale[0] * this.s.mult, 14169 scale[1] * this.s.mult, 14170 scale[2] * this.s.mult 14171 ); 14172 } 14173 if (this.sk && this.appliedTransformations < 3) { 14174 var skew = this.sk.getValueAtTime(time); 14175 var skewAxis = this.sa.getValueAtTime(time); 14176 matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult); 14177 } 14178 if (this.r && this.appliedTransformations < 4) { 14179 var rotation = this.r.getValueAtTime(time); 14180 matrix.rotate(-rotation * this.r.mult); 14181 } else if (!this.r && this.appliedTransformations < 4) { 14182 var rotationZ = this.rz.getValueAtTime(time); 14183 var rotationY = this.ry.getValueAtTime(time); 14184 var rotationX = this.rx.getValueAtTime(time); 14185 var orientation = this.or.getValueAtTime(time); 14186 matrix.rotateZ(-rotationZ * this.rz.mult) 14187 .rotateY(rotationY * this.ry.mult) 14188 .rotateX(rotationX * this.rx.mult) 14189 .rotateZ(-orientation[2] * this.or.mult) 14190 .rotateY(orientation[1] * this.or.mult) 14191 .rotateX(orientation[0] * this.or.mult); 14192 } 14193 if (this.data.p && this.data.p.s) { 14194 var positionX = this.px.getValueAtTime(time); 14195 var positionY = this.py.getValueAtTime(time); 14196 if (this.data.p.z) { 14197 var positionZ = this.pz.getValueAtTime(time); 14198 matrix.translate( 14199 positionX * this.px.mult, 14200 positionY * this.py.mult, 14201 -positionZ * this.pz.mult 14202 ); 14203 } else { 14204 matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0); 14205 } 14206 } else { 14207 var position = this.p.getValueAtTime(time); 14208 matrix.translate( 14209 position[0] * this.p.mult, 14210 position[1] * this.p.mult, 14211 -position[2] * this.p.mult 14212 ); 14213 } 14214 return matrix; 14215 /// / 14216 } 14217 14218 function getTransformStaticValueAtTime() { 14219 return this.v.clone(new Matrix()); 14220 } 14221 14222 var getTransformProperty = TransformPropertyFactory.getTransformProperty; 14223 TransformPropertyFactory.getTransformProperty = function (elem, data, container) { 14224 var prop = getTransformProperty(elem, data, container); 14225 if (prop.dynamicProperties.length) { 14226 prop.getValueAtTime = getTransformValueAtTime.bind(prop); 14227 } else { 14228 prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop); 14229 } 14230 prop.setGroupProperty = expressionHelpers.setGroupProperty; 14231 return prop; 14232 }; 14233 14234 var propertyGetProp = PropertyFactory.getProp; 14235 PropertyFactory.getProp = function (elem, data, type, mult, container) { 14236 var prop = propertyGetProp(elem, data, type, mult, container); 14237 // prop.getVelocityAtTime = getVelocityAtTime; 14238 // prop.loopOut = loopOut; 14239 // prop.loopIn = loopIn; 14240 if (prop.kf) { 14241 prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop); 14242 } else { 14243 prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop); 14244 } 14245 prop.setGroupProperty = expressionHelpers.setGroupProperty; 14246 prop.loopOut = loopOut; 14247 prop.loopIn = loopIn; 14248 prop.smooth = smooth; 14249 prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop); 14250 prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop); 14251 prop.numKeys = data.a === 1 ? data.k.length : 0; 14252 prop.propertyIndex = data.ix; 14253 var value = 0; 14254 if (type !== 0) { 14255 value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length); 14256 } 14257 prop._cachingAtTime = { 14258 lastFrame: initialDefaultFrame, 14259 lastIndex: 0, 14260 value: value, 14261 }; 14262 expressionHelpers.searchExpressions(elem, data, prop); 14263 if (prop.k) { 14264 container.addDynamicProperty(prop); 14265 } 14266 14267 return prop; 14268 }; 14269 14270 function getShapeValueAtTime(frameNum) { 14271 // For now this caching object is created only when needed instead of creating it when the shape is initialized. 14272 if (!this._cachingAtTime) { 14273 this._cachingAtTime = { 14274 shapeValue: shapePool.clone(this.pv), 14275 lastIndex: 0, 14276 lastTime: initialDefaultFrame, 14277 }; 14278 } 14279 14280 frameNum *= this.elem.globalData.frameRate; 14281 frameNum -= this.offsetTime; 14282 if (frameNum !== this._cachingAtTime.lastTime) { 14283 this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0; 14284 this._cachingAtTime.lastTime = frameNum; 14285 this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime); 14286 } 14287 return this._cachingAtTime.shapeValue; 14288 } 14289 14290 var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction(); 14291 var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction(); 14292 14293 function ShapeExpressions() {} 14294 ShapeExpressions.prototype = { 14295 vertices: function (prop, time) { 14296 if (this.k) { 14297 this.getValue(); 14298 } 14299 var shapePath = this.v; 14300 if (time !== undefined) { 14301 shapePath = this.getValueAtTime(time, 0); 14302 } 14303 var i; 14304 var len = shapePath._length; 14305 var vertices = shapePath[prop]; 14306 var points = shapePath.v; 14307 var arr = createSizedArray(len); 14308 for (i = 0; i < len; i += 1) { 14309 if (prop === 'i' || prop === 'o') { 14310 arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]]; 14311 } else { 14312 arr[i] = [vertices[i][0], vertices[i][1]]; 14313 } 14314 } 14315 return arr; 14316 }, 14317 points: function (time) { 14318 return this.vertices('v', time); 14319 }, 14320 inTangents: function (time) { 14321 return this.vertices('i', time); 14322 }, 14323 outTangents: function (time) { 14324 return this.vertices('o', time); 14325 }, 14326 isClosed: function () { 14327 return this.v.c; 14328 }, 14329 pointOnPath: function (perc, time) { 14330 var shapePath = this.v; 14331 if (time !== undefined) { 14332 shapePath = this.getValueAtTime(time, 0); 14333 } 14334 if (!this._segmentsLength) { 14335 this._segmentsLength = bez.getSegmentsLength(shapePath); 14336 } 14337 14338 var segmentsLength = this._segmentsLength; 14339 var lengths = segmentsLength.lengths; 14340 var lengthPos = segmentsLength.totalLength * perc; 14341 var i = 0; 14342 var len = lengths.length; 14343 var accumulatedLength = 0; 14344 var pt; 14345 while (i < len) { 14346 if (accumulatedLength + lengths[i].addedLength > lengthPos) { 14347 var initIndex = i; 14348 var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1; 14349 var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength; 14350 pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]); 14351 break; 14352 } else { 14353 accumulatedLength += lengths[i].addedLength; 14354 } 14355 i += 1; 14356 } 14357 if (!pt) { 14358 pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]]; 14359 } 14360 return pt; 14361 }, 14362 vectorOnPath: function (perc, time, vectorType) { 14363 // perc doesn't use triple equality because it can be a Number object as well as a primitive. 14364 if (perc == 1) { // eslint-disable-line eqeqeq 14365 perc = this.v.c; 14366 } else if (perc == 0) { // eslint-disable-line eqeqeq 14367 perc = 0.999; 14368 } 14369 var pt1 = this.pointOnPath(perc, time); 14370 var pt2 = this.pointOnPath(perc + 0.001, time); 14371 var xLength = pt2[0] - pt1[0]; 14372 var yLength = pt2[1] - pt1[1]; 14373 var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2)); 14374 if (magnitude === 0) { 14375 return [0, 0]; 14376 } 14377 var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude]; 14378 return unitVector; 14379 }, 14380 tangentOnPath: function (perc, time) { 14381 return this.vectorOnPath(perc, time, 'tangent'); 14382 }, 14383 normalOnPath: function (perc, time) { 14384 return this.vectorOnPath(perc, time, 'normal'); 14385 }, 14386 setGroupProperty: expressionHelpers.setGroupProperty, 14387 getValueAtTime: expressionHelpers.getStaticValueAtTime, 14388 }; 14389 extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction); 14390 extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction); 14391 KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime; 14392 KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression; 14393 14394 var propertyGetShapeProp = ShapePropertyFactory.getShapeProp; 14395 ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) { 14396 var prop = propertyGetShapeProp(elem, data, type, arr, trims); 14397 prop.propertyIndex = data.ix; 14398 prop.lock = false; 14399 if (type === 3) { 14400 expressionHelpers.searchExpressions(elem, data.pt, prop); 14401 } else if (type === 4) { 14402 expressionHelpers.searchExpressions(elem, data.ks, prop); 14403 } 14404 if (prop.k) { 14405 elem.addDynamicProperty(prop); 14406 } 14407 return prop; 14408 }; 14409}()); 14410 14411/* global ExpressionManager, TextProperty */ 14412 14413(function addDecorator() { 14414 function searchExpressions() { 14415 if (this.data.d.x) { 14416 this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this); 14417 this.addEffect(this.getExpressionValue.bind(this)); 14418 return true; 14419 } 14420 return null; 14421 } 14422 14423 TextProperty.prototype.getExpressionValue = function (currentValue, text) { 14424 var newValue = this.calculateExpression(text); 14425 if (currentValue.t !== newValue) { 14426 var newData = {}; 14427 this.copyData(newData, currentValue); 14428 newData.t = newValue.toString(); 14429 newData.__complete = false; 14430 return newData; 14431 } 14432 return currentValue; 14433 }; 14434 14435 TextProperty.prototype.searchProperty = function () { 14436 var isKeyframed = this.searchKeyframes(); 14437 var hasExpressions = this.searchExpressions(); 14438 this.kf = isKeyframed || hasExpressions; 14439 return this.kf; 14440 }; 14441 14442 TextProperty.prototype.searchExpressions = searchExpressions; 14443}()); 14444 14445/* global propertyGroupFactory, PropertyInterface */ 14446/* exported ShapePathInterface */ 14447 14448var ShapePathInterface = ( 14449 14450 function () { 14451 return function pathInterfaceFactory(shape, view, propertyGroup) { 14452 var prop = view.sh; 14453 14454 function interfaceFunction(val) { 14455 if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) { 14456 return interfaceFunction.path; 14457 } 14458 return null; 14459 } 14460 14461 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14462 prop.setGroupProperty(PropertyInterface('Path', _propertyGroup)); 14463 Object.defineProperties(interfaceFunction, { 14464 path: { 14465 get: function () { 14466 if (prop.k) { 14467 prop.getValue(); 14468 } 14469 return prop; 14470 }, 14471 }, 14472 shape: { 14473 get: function () { 14474 if (prop.k) { 14475 prop.getValue(); 14476 } 14477 return prop; 14478 }, 14479 }, 14480 _name: { value: shape.nm }, 14481 ix: { value: shape.ix }, 14482 propertyIndex: { value: shape.ix }, 14483 mn: { value: shape.mn }, 14484 propertyGroup: { value: propertyGroup }, 14485 }); 14486 return interfaceFunction; 14487 }; 14488 }() 14489); 14490 14491/* exported propertyGroupFactory */ 14492 14493var propertyGroupFactory = (function () { 14494 return function (interfaceFunction, parentPropertyGroup) { 14495 return function (val) { 14496 val = val === undefined ? 1 : val; 14497 if (val <= 0) { 14498 return interfaceFunction; 14499 } 14500 return parentPropertyGroup(val - 1); 14501 }; 14502 }; 14503}()); 14504 14505/* exported PropertyInterface */ 14506 14507var PropertyInterface = (function () { 14508 return function (propertyName, propertyGroup) { 14509 var interfaceFunction = { 14510 _name: propertyName, 14511 }; 14512 14513 function _propertyGroup(val) { 14514 val = val === undefined ? 1 : val; 14515 if (val <= 0) { 14516 return interfaceFunction; 14517 } 14518 return propertyGroup(val - 1); 14519 } 14520 14521 return _propertyGroup; 14522 }; 14523}()); 14524 14525/* global ExpressionPropertyInterface, PropertyInterface, propertyGroupFactory, ShapePathInterface */ 14526/* exported ShapeExpressionInterface */ 14527 14528var ShapeExpressionInterface = (function () { 14529 function iterateElements(shapes, view, propertyGroup) { 14530 var arr = []; 14531 var i; 14532 var len = shapes ? shapes.length : 0; 14533 for (i = 0; i < len; i += 1) { 14534 if (shapes[i].ty === 'gr') { 14535 arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup)); 14536 } else if (shapes[i].ty === 'fl') { 14537 arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup)); 14538 } else if (shapes[i].ty === 'st') { 14539 arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup)); 14540 } else if (shapes[i].ty === 'tm') { 14541 arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup)); 14542 } else if (shapes[i].ty === 'tr') { 14543 // arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup)); 14544 } else if (shapes[i].ty === 'el') { 14545 arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup)); 14546 } else if (shapes[i].ty === 'sr') { 14547 arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup)); 14548 } else if (shapes[i].ty === 'sh') { 14549 arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup)); 14550 } else if (shapes[i].ty === 'rc') { 14551 arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup)); 14552 } else if (shapes[i].ty === 'rd') { 14553 arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup)); 14554 } else if (shapes[i].ty === 'rp') { 14555 arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup)); 14556 } 14557 } 14558 return arr; 14559 } 14560 14561 function contentsInterfaceFactory(shape, view, propertyGroup) { 14562 var interfaces; 14563 var interfaceFunction = function _interfaceFunction(value) { 14564 var i = 0; 14565 var len = interfaces.length; 14566 while (i < len) { 14567 if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) { 14568 return interfaces[i]; 14569 } 14570 i += 1; 14571 } 14572 if (typeof value === 'number') { 14573 return interfaces[value - 1]; 14574 } 14575 return null; 14576 }; 14577 14578 interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14579 interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup); 14580 interfaceFunction.numProperties = interfaces.length; 14581 var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup); 14582 interfaceFunction.transform = transformInterface; 14583 interfaceFunction.propertyIndex = shape.cix; 14584 interfaceFunction._name = shape.nm; 14585 14586 return interfaceFunction; 14587 } 14588 14589 function groupInterfaceFactory(shape, view, propertyGroup) { 14590 var interfaceFunction = function _interfaceFunction(value) { 14591 switch (value) { 14592 case 'ADBE Vectors Group': 14593 case 'Contents': 14594 case 2: 14595 return interfaceFunction.content; 14596 // Not necessary for now. Keeping them here in case a new case appears 14597 // case 'ADBE Vector Transform Group': 14598 // case 3: 14599 default: 14600 return interfaceFunction.transform; 14601 } 14602 }; 14603 interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14604 var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup); 14605 var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup); 14606 interfaceFunction.content = content; 14607 interfaceFunction.transform = transformInterface; 14608 Object.defineProperty(interfaceFunction, '_name', { 14609 get: function () { 14610 return shape.nm; 14611 }, 14612 }); 14613 // interfaceFunction.content = interfaceFunction; 14614 interfaceFunction.numProperties = shape.np; 14615 interfaceFunction.propertyIndex = shape.ix; 14616 interfaceFunction.nm = shape.nm; 14617 interfaceFunction.mn = shape.mn; 14618 return interfaceFunction; 14619 } 14620 14621 function fillInterfaceFactory(shape, view, propertyGroup) { 14622 function interfaceFunction(val) { 14623 if (val === 'Color' || val === 'color') { 14624 return interfaceFunction.color; 14625 } if (val === 'Opacity' || val === 'opacity') { 14626 return interfaceFunction.opacity; 14627 } 14628 return null; 14629 } 14630 Object.defineProperties(interfaceFunction, { 14631 color: { 14632 get: ExpressionPropertyInterface(view.c), 14633 }, 14634 opacity: { 14635 get: ExpressionPropertyInterface(view.o), 14636 }, 14637 _name: { value: shape.nm }, 14638 mn: { value: shape.mn }, 14639 }); 14640 14641 view.c.setGroupProperty(PropertyInterface('Color', propertyGroup)); 14642 view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup)); 14643 return interfaceFunction; 14644 } 14645 14646 function strokeInterfaceFactory(shape, view, propertyGroup) { 14647 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14648 var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup); 14649 function addPropertyToDashOb(i) { 14650 Object.defineProperty(dashOb, shape.d[i].nm, { 14651 get: ExpressionPropertyInterface(view.d.dataProps[i].p), 14652 }); 14653 } 14654 var i; 14655 var len = shape.d ? shape.d.length : 0; 14656 var dashOb = {}; 14657 for (i = 0; i < len; i += 1) { 14658 addPropertyToDashOb(i); 14659 view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup); 14660 } 14661 14662 function interfaceFunction(val) { 14663 if (val === 'Color' || val === 'color') { 14664 return interfaceFunction.color; 14665 } if (val === 'Opacity' || val === 'opacity') { 14666 return interfaceFunction.opacity; 14667 } if (val === 'Stroke Width' || val === 'stroke width') { 14668 return interfaceFunction.strokeWidth; 14669 } 14670 return null; 14671 } 14672 Object.defineProperties(interfaceFunction, { 14673 color: { 14674 get: ExpressionPropertyInterface(view.c), 14675 }, 14676 opacity: { 14677 get: ExpressionPropertyInterface(view.o), 14678 }, 14679 strokeWidth: { 14680 get: ExpressionPropertyInterface(view.w), 14681 }, 14682 dash: { 14683 get: function () { 14684 return dashOb; 14685 }, 14686 }, 14687 _name: { value: shape.nm }, 14688 mn: { value: shape.mn }, 14689 }); 14690 14691 view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup)); 14692 view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup)); 14693 view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup)); 14694 return interfaceFunction; 14695 } 14696 14697 function trimInterfaceFactory(shape, view, propertyGroup) { 14698 function interfaceFunction(val) { 14699 if (val === shape.e.ix || val === 'End' || val === 'end') { 14700 return interfaceFunction.end; 14701 } 14702 if (val === shape.s.ix) { 14703 return interfaceFunction.start; 14704 } 14705 if (val === shape.o.ix) { 14706 return interfaceFunction.offset; 14707 } 14708 return null; 14709 } 14710 14711 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14712 interfaceFunction.propertyIndex = shape.ix; 14713 14714 view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup)); 14715 view.e.setGroupProperty(PropertyInterface('End', _propertyGroup)); 14716 view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup)); 14717 interfaceFunction.propertyIndex = shape.ix; 14718 interfaceFunction.propertyGroup = propertyGroup; 14719 14720 Object.defineProperties(interfaceFunction, { 14721 start: { 14722 get: ExpressionPropertyInterface(view.s), 14723 }, 14724 end: { 14725 get: ExpressionPropertyInterface(view.e), 14726 }, 14727 offset: { 14728 get: ExpressionPropertyInterface(view.o), 14729 }, 14730 _name: { value: shape.nm }, 14731 }); 14732 interfaceFunction.mn = shape.mn; 14733 return interfaceFunction; 14734 } 14735 14736 function transformInterfaceFactory(shape, view, propertyGroup) { 14737 function interfaceFunction(value) { 14738 if (shape.a.ix === value || value === 'Anchor Point') { 14739 return interfaceFunction.anchorPoint; 14740 } 14741 if (shape.o.ix === value || value === 'Opacity') { 14742 return interfaceFunction.opacity; 14743 } 14744 if (shape.p.ix === value || value === 'Position') { 14745 return interfaceFunction.position; 14746 } 14747 if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') { 14748 return interfaceFunction.rotation; 14749 } 14750 if (shape.s.ix === value || value === 'Scale') { 14751 return interfaceFunction.scale; 14752 } 14753 if ((shape.sk && shape.sk.ix === value) || value === 'Skew') { 14754 return interfaceFunction.skew; 14755 } 14756 if ((shape.sa && shape.sa.ix === value) || value === 'Skew Axis') { 14757 return interfaceFunction.skewAxis; 14758 } 14759 return null; 14760 }
vendor: 8,901 bytes, lines 14761-15017
14761 14762 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14763 view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup)); 14764 view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 14765 view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup)); 14766 view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup)); 14767 view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup)); 14768 if (view.transform.mProps.sk) { 14769 view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup)); 14770 view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup)); 14771 } 14772 view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup)); 14773 Object.defineProperties(interfaceFunction, { 14774 opacity: { 14775 get: ExpressionPropertyInterface(view.transform.mProps.o), 14776 }, 14777 position: { 14778 get: ExpressionPropertyInterface(view.transform.mProps.p), 14779 }, 14780 anchorPoint: { 14781 get: ExpressionPropertyInterface(view.transform.mProps.a), 14782 }, 14783 scale: { 14784 get: ExpressionPropertyInterface(view.transform.mProps.s), 14785 }, 14786 rotation: { 14787 get: ExpressionPropertyInterface(view.transform.mProps.r), 14788 }, 14789 skew: { 14790 get: ExpressionPropertyInterface(view.transform.mProps.sk), 14791 }, 14792 skewAxis: { 14793 get: ExpressionPropertyInterface(view.transform.mProps.sa), 14794 }, 14795 _name: { value: shape.nm }, 14796 }); 14797 interfaceFunction.ty = 'tr'; 14798 interfaceFunction.mn = shape.mn; 14799 interfaceFunction.propertyGroup = propertyGroup; 14800 return interfaceFunction; 14801 } 14802 14803 function ellipseInterfaceFactory(shape, view, propertyGroup) { 14804 function interfaceFunction(value) { 14805 if (shape.p.ix === value) { 14806 return interfaceFunction.position; 14807 } 14808 if (shape.s.ix === value) { 14809 return interfaceFunction.size; 14810 } 14811 return null; 14812 } 14813 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14814 interfaceFunction.propertyIndex = shape.ix; 14815 var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh; 14816 prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup)); 14817 prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 14818 14819 Object.defineProperties(interfaceFunction, { 14820 size: { 14821 get: ExpressionPropertyInterface(prop.s), 14822 }, 14823 position: { 14824 get: ExpressionPropertyInterface(prop.p), 14825 }, 14826 _name: { value: shape.nm }, 14827 }); 14828 interfaceFunction.mn = shape.mn; 14829 return interfaceFunction; 14830 } 14831 14832 function starInterfaceFactory(shape, view, propertyGroup) { 14833 function interfaceFunction(value) { 14834 if (shape.p.ix === value) { 14835 return interfaceFunction.position; 14836 } 14837 if (shape.r.ix === value) { 14838 return interfaceFunction.rotation; 14839 } 14840 if (shape.pt.ix === value) { 14841 return interfaceFunction.points; 14842 } 14843 if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') { 14844 return interfaceFunction.outerRadius; 14845 } 14846 if (shape.os.ix === value) { 14847 return interfaceFunction.outerRoundness; 14848 } 14849 if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) { 14850 return interfaceFunction.innerRadius; 14851 } 14852 if (shape.is && shape.is.ix === value) { 14853 return interfaceFunction.innerRoundness; 14854 } 14855 return null; 14856 } 14857 14858 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14859 var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh; 14860 interfaceFunction.propertyIndex = shape.ix; 14861 prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup)); 14862 prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup)); 14863 prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup)); 14864 prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 14865 prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup)); 14866 if (shape.ir) { 14867 prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup)); 14868 prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup)); 14869 } 14870 14871 Object.defineProperties(interfaceFunction, { 14872 position: { 14873 get: ExpressionPropertyInterface(prop.p), 14874 }, 14875 rotation: { 14876 get: ExpressionPropertyInterface(prop.r), 14877 }, 14878 points: { 14879 get: ExpressionPropertyInterface(prop.pt), 14880 }, 14881 outerRadius: { 14882 get: ExpressionPropertyInterface(prop.or), 14883 }, 14884 outerRoundness: { 14885 get: ExpressionPropertyInterface(prop.os), 14886 }, 14887 innerRadius: { 14888 get: ExpressionPropertyInterface(prop.ir), 14889 }, 14890 innerRoundness: { 14891 get: ExpressionPropertyInterface(prop.is), 14892 }, 14893 _name: { value: shape.nm }, 14894 }); 14895 interfaceFunction.mn = shape.mn; 14896 return interfaceFunction; 14897 } 14898 14899 function rectInterfaceFactory(shape, view, propertyGroup) { 14900 function interfaceFunction(value) { 14901 if (shape.p.ix === value) { 14902 return interfaceFunction.position; 14903 } 14904 if (shape.r.ix === value) { 14905 return interfaceFunction.roundness; 14906 } 14907 if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') { 14908 return interfaceFunction.size; 14909 } 14910 return null; 14911 } 14912 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14913 14914 var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh; 14915 interfaceFunction.propertyIndex = shape.ix; 14916 prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 14917 prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup)); 14918 prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup)); 14919 14920 Object.defineProperties(interfaceFunction, { 14921 position: { 14922 get: ExpressionPropertyInterface(prop.p), 14923 }, 14924 roundness: { 14925 get: ExpressionPropertyInterface(prop.r), 14926 }, 14927 size: { 14928 get: ExpressionPropertyInterface(prop.s), 14929 }, 14930 _name: { value: shape.nm }, 14931 }); 14932 interfaceFunction.mn = shape.mn; 14933 return interfaceFunction; 14934 } 14935 14936 function roundedInterfaceFactory(shape, view, propertyGroup) { 14937 function interfaceFunction(value) { 14938 if (shape.r.ix === value || value === 'Round Corners 1') { 14939 return interfaceFunction.radius; 14940 } 14941 return null; 14942 } 14943 14944 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14945 var prop = view; 14946 interfaceFunction.propertyIndex = shape.ix; 14947 prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup)); 14948 14949 Object.defineProperties(interfaceFunction, { 14950 radius: { 14951 get: ExpressionPropertyInterface(prop.rd), 14952 }, 14953 _name: { value: shape.nm }, 14954 }); 14955 interfaceFunction.mn = shape.mn; 14956 return interfaceFunction; 14957 } 14958 14959 function repeaterInterfaceFactory(shape, view, propertyGroup) { 14960 function interfaceFunction(value) { 14961 if (shape.c.ix === value || value === 'Copies') { 14962 return interfaceFunction.copies; 14963 } if (shape.o.ix === value || value === 'Offset') { 14964 return interfaceFunction.offset; 14965 } 14966 return null; 14967 } 14968 14969 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14970 var prop = view; 14971 interfaceFunction.propertyIndex = shape.ix; 14972 prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup)); 14973 prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup)); 14974 Object.defineProperties(interfaceFunction, { 14975 copies: { 14976 get: ExpressionPropertyInterface(prop.c), 14977 }, 14978 offset: { 14979 get: ExpressionPropertyInterface(prop.o), 14980 }, 14981 _name: { value: shape.nm }, 14982 }); 14983 interfaceFunction.mn = shape.mn; 14984 return interfaceFunction; 14985 } 14986 14987 return function (shapes, view, propertyGroup) { 14988 var interfaces; 14989 function _interfaceFunction(value) { 14990 if (typeof value === 'number') { 14991 value = value === undefined ? 1 : value; 14992 if (value === 0) { 14993 return propertyGroup; 14994 } 14995 return interfaces[value - 1]; 14996 } 14997 var i = 0; 14998 var len = interfaces.length; 14999 while (i < len) { 15000 if (interfaces[i]._name === value) { 15001 return interfaces[i]; 15002 } 15003 i += 1; 15004 } 15005 return null; 15006 } 15007 function parentGroupWrapper() { 15008 return propertyGroup; 15009 } 15010 _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper); 15011 interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup); 15012 _interfaceFunction.numProperties = interfaces.length; 15013 _interfaceFunction._name = 'Contents'; 15014 return _interfaceFunction; 15015 }; 15016}()); 15017
vendor: 28,011 bytes, lines 15018-15941
15018/* exported TextExpressionInterface */ 15019 15020var TextExpressionInterface = (function () { 15021 return function (elem) { 15022 var _prevValue; 15023 var _sourceText; 15024 function _thisLayerFunction(name) { 15025 switch (name) { 15026 case 'ADBE Text Document': 15027 return _thisLayerFunction.sourceText; 15028 default: 15029 return null; 15030 } 15031 } 15032 Object.defineProperty(_thisLayerFunction, 'sourceText', { 15033 get: function () { 15034 elem.textProperty.getValue(); 15035 var stringValue = elem.textProperty.currentData.t; 15036 if (stringValue !== _prevValue) { 15037 elem.textProperty.currentData.t = _prevValue; 15038 _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers 15039 // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive 15040 _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers 15041 } 15042 return _sourceText; 15043 }, 15044 }); 15045 return _thisLayerFunction; 15046 }; 15047}()); 15048 15049/* global Matrix, MaskManagerInterface, TransformExpressionInterface, getDescriptor */ 15050/* exported LayerExpressionInterface */ 15051 15052var LayerExpressionInterface = (function () { 15053 function getMatrix(time) { 15054 var toWorldMat = new Matrix(); 15055 if (time !== undefined) { 15056 var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time); 15057 propMatrix.clone(toWorldMat); 15058 } else { 15059 var transformMat = this._elem.finalTransform.mProp; 15060 transformMat.applyToMatrix(toWorldMat); 15061 } 15062 return toWorldMat; 15063 } 15064 15065 function toWorldVec(arr, time) { 15066 var toWorldMat = this.getMatrix(time); 15067 toWorldMat.props[12] = 0; 15068 toWorldMat.props[13] = 0; 15069 toWorldMat.props[14] = 0; 15070 return this.applyPoint(toWorldMat, arr); 15071 } 15072 15073 function toWorld(arr, time) { 15074 var toWorldMat = this.getMatrix(time); 15075 return this.applyPoint(toWorldMat, arr); 15076 } 15077 15078 function fromWorldVec(arr, time) { 15079 var toWorldMat = this.getMatrix(time); 15080 toWorldMat.props[12] = 0; 15081 toWorldMat.props[13] = 0; 15082 toWorldMat.props[14] = 0; 15083 return this.invertPoint(toWorldMat, arr); 15084 } 15085 15086 function fromWorld(arr, time) { 15087 var toWorldMat = this.getMatrix(time); 15088 return this.invertPoint(toWorldMat, arr); 15089 } 15090 15091 function applyPoint(matrix, arr) { 15092 if (this._elem.hierarchy && this._elem.hierarchy.length) { 15093 var i; 15094 var len = this._elem.hierarchy.length; 15095 for (i = 0; i < len; i += 1) { 15096 this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix); 15097 } 15098 } 15099 return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0); 15100 } 15101 15102 function invertPoint(matrix, arr) { 15103 if (this._elem.hierarchy && this._elem.hierarchy.length) { 15104 var i; 15105 var len = this._elem.hierarchy.length; 15106 for (i = 0; i < len; i += 1) { 15107 this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix); 15108 } 15109 } 15110 return matrix.inversePoint(arr); 15111 } 15112 15113 function fromComp(arr) { 15114 var toWorldMat = new Matrix(); 15115 toWorldMat.reset(); 15116 this._elem.finalTransform.mProp.applyToMatrix(toWorldMat); 15117 if (this._elem.hierarchy && this._elem.hierarchy.length) { 15118 var i; 15119 var len = this._elem.hierarchy.length; 15120 for (i = 0; i < len; i += 1) { 15121 this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat); 15122 } 15123 return toWorldMat.inversePoint(arr); 15124 } 15125 return toWorldMat.inversePoint(arr); 15126 } 15127 15128 function sampleImage() { 15129 return [1, 1, 1, 1]; 15130 } 15131 15132 return function (elem) { 15133 var transformInterface; 15134 15135 function _registerMaskInterface(maskManager) { 15136 _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem); 15137 } 15138 function _registerEffectsInterface(effects) { 15139 _thisLayerFunction.effect = effects; 15140 } 15141 15142 function _thisLayerFunction(name) { 15143 switch (name) { 15144 case 'ADBE Root Vectors Group': 15145 case 'Contents': 15146 case 2: 15147 return _thisLayerFunction.shapeInterface; 15148 case 1: 15149 case 6: 15150 case 'Transform': 15151 case 'transform': 15152 case 'ADBE Transform Group': 15153 return transformInterface; 15154 case 4: 15155 case 'ADBE Effect Parade': 15156 case 'effects': 15157 case 'Effects': 15158 return _thisLayerFunction.effect; 15159 case 'ADBE Text Properties': 15160 return _thisLayerFunction.textInterface; 15161 default: 15162 return null; 15163 } 15164 } 15165 _thisLayerFunction.getMatrix = getMatrix; 15166 _thisLayerFunction.invertPoint = invertPoint; 15167 _thisLayerFunction.applyPoint = applyPoint; 15168 _thisLayerFunction.toWorld = toWorld; 15169 _thisLayerFunction.toWorldVec = toWorldVec; 15170 _thisLayerFunction.fromWorld = fromWorld; 15171 _thisLayerFunction.fromWorldVec = fromWorldVec; 15172 _thisLayerFunction.toComp = toWorld; 15173 _thisLayerFunction.fromComp = fromComp; 15174 _thisLayerFunction.sampleImage = sampleImage; 15175 _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem); 15176 _thisLayerFunction._elem = elem; 15177 transformInterface = TransformExpressionInterface(elem.finalTransform.mProp); 15178 var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint'); 15179 Object.defineProperties(_thisLayerFunction, { 15180 hasParent: { 15181 get: function () { 15182 return elem.hierarchy.length; 15183 }, 15184 }, 15185 parent: { 15186 get: function () { 15187 return elem.hierarchy[0].layerInterface; 15188 }, 15189 }, 15190 rotation: getDescriptor(transformInterface, 'rotation'), 15191 scale: getDescriptor(transformInterface, 'scale'), 15192 position: getDescriptor(transformInterface, 'position'), 15193 opacity: getDescriptor(transformInterface, 'opacity'), 15194 anchorPoint: anchorPointDescriptor, 15195 anchor_point: anchorPointDescriptor, 15196 transform: { 15197 get: function () { 15198 return transformInterface; 15199 }, 15200 }, 15201 active: { 15202 get: function () { 15203 return elem.isInRange; 15204 }, 15205 }, 15206 }); 15207 15208 _thisLayerFunction.startTime = elem.data.st; 15209 _thisLayerFunction.index = elem.data.ind; 15210 _thisLayerFunction.source = elem.data.refId; 15211 _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100; 15212 _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100; 15213 _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate; 15214 _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate; 15215 _thisLayerFunction._name = elem.data.nm; 15216 15217 _thisLayerFunction.registerMaskInterface = _registerMaskInterface; 15218 _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface; 15219 return _thisLayerFunction; 15220 }; 15221}()); 15222 15223/* exported CompExpressionInterface */ 15224 15225var CompExpressionInterface = (function () { 15226 return function (comp) { 15227 function _thisLayerFunction(name) { 15228 var i = 0; 15229 var len = comp.layers.length; 15230 while (i < len) { 15231 if (comp.layers[i].nm === name || comp.layers[i].ind === name) { 15232 return comp.elements[i].layerInterface; 15233 } 15234 i += 1; 15235 } 15236 return null; 15237 // return {active:false}; 15238 } 15239 Object.defineProperty(_thisLayerFunction, '_name', { value: comp.data.nm }); 15240 _thisLayerFunction.layer = _thisLayerFunction; 15241 _thisLayerFunction.pixelAspect = 1; 15242 _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h; 15243 _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w; 15244 _thisLayerFunction.pixelAspect = 1; 15245 _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate; 15246 _thisLayerFunction.displayStartTime = 0; 15247 _thisLayerFunction.numLayers = comp.layers.length; 15248 return _thisLayerFunction; 15249 }; 15250}()); 15251 15252/* global ExpressionPropertyInterface */ 15253/* exported TransformExpressionInterface */ 15254 15255var TransformExpressionInterface = (function () { 15256 return function (transform) { 15257 function _thisFunction(name) { 15258 switch (name) { 15259 case 'scale': 15260 case 'Scale': 15261 case 'ADBE Scale': 15262 case 6: 15263 return _thisFunction.scale; 15264 case 'rotation': 15265 case 'Rotation': 15266 case 'ADBE Rotation': 15267 case 'ADBE Rotate Z': 15268 case 10: 15269 return _thisFunction.rotation; 15270 case 'ADBE Rotate X': 15271 return _thisFunction.xRotation; 15272 case 'ADBE Rotate Y': 15273 return _thisFunction.yRotation; 15274 case 'position': 15275 case 'Position': 15276 case 'ADBE Position': 15277 case 2: 15278 return _thisFunction.position; 15279 case 'ADBE Position_0': 15280 return _thisFunction.xPosition; 15281 case 'ADBE Position_1': 15282 return _thisFunction.yPosition; 15283 case 'ADBE Position_2': 15284 return _thisFunction.zPosition; 15285 case 'anchorPoint': 15286 case 'AnchorPoint': 15287 case 'Anchor Point': 15288 case 'ADBE AnchorPoint': 15289 case 1: 15290 return _thisFunction.anchorPoint; 15291 case 'opacity': 15292 case 'Opacity': 15293 case 11: 15294 return _thisFunction.opacity; 15295 default: 15296 return null; 15297 } 15298 } 15299 Object.defineProperty(_thisFunction, 'rotation', { 15300 get: ExpressionPropertyInterface(transform.r || transform.rz), 15301 }); 15302 15303 Object.defineProperty(_thisFunction, 'zRotation', { 15304 get: ExpressionPropertyInterface(transform.rz || transform.r), 15305 }); 15306 15307 Object.defineProperty(_thisFunction, 'xRotation', { 15308 get: ExpressionPropertyInterface(transform.rx), 15309 }); 15310 15311 Object.defineProperty(_thisFunction, 'yRotation', { 15312 get: ExpressionPropertyInterface(transform.ry), 15313 }); 15314 Object.defineProperty(_thisFunction, 'scale', { 15315 get: ExpressionPropertyInterface(transform.s), 15316 }); 15317 var _px; 15318 var _py; 15319 var _pz; 15320 var _transformFactory; 15321 if (transform.p) { 15322 _transformFactory = ExpressionPropertyInterface(transform.p); 15323 } else { 15324 _px = ExpressionPropertyInterface(transform.px); 15325 _py = ExpressionPropertyInterface(transform.py); 15326 if (transform.pz) { 15327 _pz = ExpressionPropertyInterface(transform.pz); 15328 } 15329 } 15330 Object.defineProperty(_thisFunction, 'position', { 15331 get: function () { 15332 if (transform.p) { 15333 return _transformFactory(); 15334 } 15335 return [ 15336 _px(), 15337 _py(), 15338 _pz ? _pz() : 0]; 15339 }, 15340 }); 15341 15342 Object.defineProperty(_thisFunction, 'xPosition', { 15343 get: ExpressionPropertyInterface(transform.px), 15344 }); 15345 15346 Object.defineProperty(_thisFunction, 'yPosition', { 15347 get: ExpressionPropertyInterface(transform.py), 15348 }); 15349 15350 Object.defineProperty(_thisFunction, 'zPosition', { 15351 get: ExpressionPropertyInterface(transform.pz), 15352 }); 15353 15354 Object.defineProperty(_thisFunction, 'anchorPoint', { 15355 get: ExpressionPropertyInterface(transform.a), 15356 }); 15357 15358 Object.defineProperty(_thisFunction, 'opacity', { 15359 get: ExpressionPropertyInterface(transform.o), 15360 }); 15361 15362 Object.defineProperty(_thisFunction, 'skew', { 15363 get: ExpressionPropertyInterface(transform.sk), 15364 }); 15365 15366 Object.defineProperty(_thisFunction, 'skewAxis', { 15367 get: ExpressionPropertyInterface(transform.sa), 15368 }); 15369 15370 Object.defineProperty(_thisFunction, 'orientation', { 15371 get: ExpressionPropertyInterface(transform.or), 15372 }); 15373 15374 return _thisFunction; 15375 }; 15376}()); 15377 15378/* exported ProjectInterface */ 15379 15380var ProjectInterface = (function () { 15381 function registerComposition(comp) { 15382 this.compositions.push(comp); 15383 } 15384 15385 return function () { 15386 function _thisProjectFunction(name) { 15387 var i = 0; 15388 var len = this.compositions.length; 15389 while (i < len) { 15390 if (this.compositions[i].data && this.compositions[i].data.nm === name) { 15391 if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) { 15392 this.compositions[i].prepareFrame(this.currentFrame); 15393 } 15394 return this.compositions[i].compInterface; 15395 } 15396 i += 1; 15397 } 15398 return null; 15399 } 15400 15401 _thisProjectFunction.compositions = []; 15402 _thisProjectFunction.currentFrame = 0; 15403 15404 _thisProjectFunction.registerComposition = registerComposition; 15405 15406 return _thisProjectFunction; 15407 }; 15408}()); 15409 15410/* global propertyGroupFactory, ExpressionPropertyInterface, PropertyInterface */ 15411/* exported EffectsExpressionInterface */ 15412 15413var EffectsExpressionInterface = (function () { 15414 var ob = { 15415 createEffectsInterface: createEffectsInterface, 15416 }; 15417 15418 function createEffectsInterface(elem, propertyGroup) { 15419 if (elem.effectsManager) { 15420 var effectElements = []; 15421 var effectsData = elem.data.ef; 15422 var i; 15423 var len = elem.effectsManager.effectElements.length; 15424 for (i = 0; i < len; i += 1) { 15425 effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem)); 15426 } 15427 15428 var effects = elem.data.ef || []; 15429 var groupInterface = function (name) { 15430 i = 0; 15431 len = effects.length; 15432 while (i < len) { 15433 if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) { 15434 return effectElements[i]; 15435 } 15436 i += 1; 15437 } 15438 return null; 15439 }; 15440 Object.defineProperty(groupInterface, 'numProperties', { 15441 get: function () { 15442 return effects.length; 15443 }, 15444 }); 15445 return groupInterface; 15446 } 15447 return null; 15448 } 15449 15450 function createGroupInterface(data, elements, propertyGroup, elem) { 15451 function groupInterface(name) { 15452 var effects = data.ef; 15453 var i = 0; 15454 var len = effects.length; 15455 while (i < len) { 15456 if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) { 15457 if (effects[i].ty === 5) { 15458 return effectElements[i]; 15459 } 15460 return effectElements[i](); 15461 } 15462 i += 1; 15463 } 15464 throw new Error(); 15465 } 15466 var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup); 15467 15468 var effectElements = []; 15469 var i; 15470 var len = data.ef.length; 15471 for (i = 0; i < len; i += 1) { 15472 if (data.ef[i].ty === 5) { 15473 effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem)); 15474 } else { 15475 effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup)); 15476 } 15477 } 15478 15479 if (data.mn === 'ADBE Color Control') { 15480 Object.defineProperty(groupInterface, 'color', { 15481 get: function () { 15482 return effectElements[0](); 15483 }, 15484 }); 15485 } 15486 Object.defineProperties(groupInterface, { 15487 numProperties: { 15488 get: function () { 15489 return data.np; 15490 }, 15491 }, 15492 _name: { value: data.nm }, 15493 propertyGroup: { value: _propertyGroup }, 15494 }); 15495 groupInterface.enabled = data.en !== 0; 15496 groupInterface.active = groupInterface.enabled; 15497 return groupInterface; 15498 } 15499 15500 function createValueInterface(element, type, elem, propertyGroup) { 15501 var expressionProperty = ExpressionPropertyInterface(element.p); 15502 function interfaceFunction() { 15503 if (type === 10) { 15504 return elem.comp.compInterface(element.p.v); 15505 } 15506 return expressionProperty(); 15507 } 15508 15509 if (element.p.setGroupProperty) { 15510 element.p.setGroupProperty(PropertyInterface('', propertyGroup)); 15511 } 15512 15513 return interfaceFunction; 15514 } 15515 15516 return ob; 15517}()); 15518 15519/* global createSizedArray */ 15520/* exported MaskManagerInterface */ 15521 15522var MaskManagerInterface = (function () { 15523 function MaskInterface(mask, data) { 15524 this._mask = mask; 15525 this._data = data; 15526 } 15527 Object.defineProperty(MaskInterface.prototype, 'maskPath', { 15528 get: function () { 15529 if (this._mask.prop.k) { 15530 this._mask.prop.getValue(); 15531 } 15532 return this._mask.prop; 15533 }, 15534 }); 15535 Object.defineProperty(MaskInterface.prototype, 'maskOpacity', { 15536 get: function () { 15537 if (this._mask.op.k) { 15538 this._mask.op.getValue(); 15539 } 15540 return this._mask.op.v * 100; 15541 }, 15542 }); 15543 15544 var MaskManager = function (maskManager) { 15545 var _masksInterfaces = createSizedArray(maskManager.viewData.length); 15546 var i; 15547 var len = maskManager.viewData.length; 15548 for (i = 0; i < len; i += 1) { 15549 _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]); 15550 } 15551 15552 var maskFunction = function (name) { 15553 i = 0; 15554 while (i < len) { 15555 if (maskManager.masksProperties[i].nm === name) { 15556 return _masksInterfaces[i]; 15557 } 15558 i += 1; 15559 } 15560 return null; 15561 }; 15562 return maskFunction; 15563 }; 15564 return MaskManager; 15565}()); 15566 15567/* global createTypedArray */ 15568/* exported ExpressionPropertyInterface */ 15569 15570var ExpressionPropertyInterface = (function () { 15571 var defaultUnidimensionalValue = { pv: 0, v: 0, mult: 1 }; 15572 var defaultMultidimensionalValue = { pv: [0, 0, 0], v: [0, 0, 0], mult: 1 }; 15573 15574 function completeProperty(expressionValue, property, type) { 15575 Object.defineProperty(expressionValue, 'velocity', { 15576 get: function () { 15577 return property.getVelocityAtTime(property.comp.currentFrame); 15578 }, 15579 }); 15580 expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0; 15581 expressionValue.key = function (pos) { 15582 if (!expressionValue.numKeys) { 15583 return 0; 15584 } 15585 var value = ''; 15586 if ('s' in property.keyframes[pos - 1]) { 15587 value = property.keyframes[pos - 1].s; 15588 } else if ('e' in property.keyframes[pos - 2]) { 15589 value = property.keyframes[pos - 2].e; 15590 } else { 15591 value = property.keyframes[pos - 2].s; 15592 } 15593 var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers 15594 valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate; 15595 valueProp.value = type === 'unidimensional' ? value[0] : value; 15596 return valueProp; 15597 }; 15598 expressionValue.valueAtTime = property.getValueAtTime; 15599 expressionValue.speedAtTime = property.getSpeedAtTime; 15600 expressionValue.velocityAtTime = property.getVelocityAtTime; 15601 expressionValue.propertyGroup = property.propertyGroup; 15602 } 15603 15604 function UnidimensionalPropertyInterface(property) { 15605 if (!property || !('pv' in property)) { 15606 property = defaultUnidimensionalValue; 15607 } 15608 var mult = 1 / property.mult; 15609 var val = property.pv * mult; 15610 var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers 15611 expressionValue.value = val; 15612 completeProperty(expressionValue, property, 'unidimensional'); 15613 15614 return function () { 15615 if (property.k) { 15616 property.getValue(); 15617 } 15618 val = property.v * mult; 15619 if (expressionValue.value !== val) { 15620 expressionValue = new Number(val); // eslint-disable-line no-new-wrappers 15621 expressionValue.value = val; 15622 completeProperty(expressionValue, property, 'unidimensional'); 15623 } 15624 return expressionValue; 15625 }; 15626 } 15627 15628 function MultidimensionalPropertyInterface(property) { 15629 if (!property || !('pv' in property)) { 15630 property = defaultMultidimensionalValue; 15631 } 15632 var mult = 1 / property.mult; 15633 var len = (property.data && property.data.l) || property.pv.length; 15634 var expressionValue = createTypedArray('float32', len); 15635 var arrValue = createTypedArray('float32', len); 15636 expressionValue.value = arrValue; 15637 completeProperty(expressionValue, property, 'multidimensional'); 15638 15639 return function () { 15640 if (property.k) { 15641 property.getValue(); 15642 } 15643 for (var i = 0; i < len; i += 1) { 15644 arrValue[i] = property.v[i] * mult; 15645 expressionValue[i] = arrValue[i]; 15646 } 15647 return expressionValue; 15648 }; 15649 } 15650 15651 // TODO: try to avoid using this getter 15652 function defaultGetter() { 15653 return defaultUnidimensionalValue; 15654 } 15655 15656 return function (property) { 15657 if (!property) { 15658 return defaultGetter; 15659 } if (property.propType === 'unidimensional') { 15660 return UnidimensionalPropertyInterface(property); 15661 } 15662 return MultidimensionalPropertyInterface(property); 15663 }; 15664}()); 15665 15666/* global expressionHelpers, TextSelectorProp, ExpressionManager */ 15667/* exported TextExpressionSelectorProp */ 15668 15669(function () { 15670 var TextExpressionSelectorProp = (function () { // eslint-disable-line no-unused-vars 15671 function getValueProxy(index, total) { 15672 this.textIndex = index + 1; 15673 this.textTotal = total; 15674 this.v = this.getValue() * this.mult; 15675 return this.v; 15676 } 15677 15678 return function TextExpressionSelectorPropFactory(elem, data) { 15679 this.pv = 1; 15680 this.comp = elem.comp; 15681 this.elem = elem; 15682 this.mult = 0.01; 15683 this.propType = 'textSelector'; 15684 this.textTotal = data.totalChars; 15685 this.selectorValue = 100; 15686 this.lastValue = [1, 1, 1]; 15687 this.k = true; 15688 this.x = true; 15689 this.getValue = ExpressionManager.initiateExpression.bind(this)(elem, data, this); 15690 this.getMult = getValueProxy; 15691 this.getVelocityAtTime = expressionHelpers.getVelocityAtTime; 15692 if (this.kf) { 15693 this.getValueAtTime = expressionHelpers.getValueAtTime.bind(this); 15694 } else { 15695 this.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(this); 15696 } 15697 this.setGroupProperty = expressionHelpers.setGroupProperty; 15698 }; 15699 }()); 15700 15701 var propertyGetTextProp = TextSelectorProp.getTextSelectorProp; 15702 TextSelectorProp.getTextSelectorProp = function (elem, data, arr) { 15703 if (data.t === 1) { 15704 return new TextExpressionSelectorPropFactory(elem, data, arr); // eslint-disable-line no-undef 15705 } 15706 return propertyGetTextProp(elem, data, arr); 15707 }; 15708}()); 15709 15710/* global PropertyFactory */ 15711/* exported SliderEffect, AngleEffect, ColorEffect, PointEffect, LayerIndexEffect, MaskIndexEffect, CheckboxEffect, NoValueEffect */ 15712 15713function SliderEffect(data, elem, container) { 15714 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 15715} 15716function AngleEffect(data, elem, container) { 15717 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 15718} 15719function ColorEffect(data, elem, container) { 15720 this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container); 15721} 15722function PointEffect(data, elem, container) { 15723 this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container); 15724} 15725function LayerIndexEffect(data, elem, container) { 15726 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 15727} 15728function MaskIndexEffect(data, elem, container) { 15729 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 15730} 15731function CheckboxEffect(data, elem, container) { 15732 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 15733} 15734function NoValueEffect() { 15735 this.p = {}; 15736} 15737 15738/* global extendPrototype, SliderEffect, AngleEffect, ColorEffect, PointEffect, CheckboxEffect, LayerIndexEffect, 15739MaskIndexEffect, NoValueEffect, DynamicPropertyContainer */ 15740 15741function EffectsManager(data, element) { 15742 var effects = data.ef || []; 15743 this.effectElements = []; 15744 var i; 15745 var len = effects.length; 15746 var effectItem; 15747 for (i = 0; i < len; i += 1) { 15748 effectItem = new GroupEffect(effects[i], element); 15749 this.effectElements.push(effectItem); 15750 } 15751} 15752 15753function GroupEffect(data, element) { 15754 this.init(data, element); 15755} 15756 15757extendPrototype([DynamicPropertyContainer], GroupEffect); 15758 15759GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties; 15760 15761GroupEffect.prototype.init = function (data, element) { 15762 this.data = data; 15763 this.effectElements = []; 15764 this.initDynamicPropertyContainer(element); 15765 var i; 15766 var len = this.data.ef.length; 15767 var eff; 15768 var effects = this.data.ef; 15769 for (i = 0; i < len; i += 1) { 15770 eff = null; 15771 switch (effects[i].ty) { 15772 case 0: 15773 eff = new SliderEffect(effects[i], element, this); 15774 break; 15775 case 1: 15776 eff = new AngleEffect(effects[i], element, this); 15777 break; 15778 case 2: 15779 eff = new ColorEffect(effects[i], element, this); 15780 break; 15781 case 3: 15782 eff = new PointEffect(effects[i], element, this); 15783 break; 15784 case 4: 15785 case 7: 15786 eff = new CheckboxEffect(effects[i], element, this); 15787 break; 15788 case 10: 15789 eff = new LayerIndexEffect(effects[i], element, this); 15790 break; 15791 case 11: 15792 eff = new MaskIndexEffect(effects[i], element, this); 15793 break; 15794 case 5: 15795 eff = new EffectsManager(effects[i], element, this); 15796 break; 15797 // case 6: 15798 default: 15799 eff = new NoValueEffect(effects[i], element, this); 15800 break; 15801 } 15802 if (eff) { 15803 this.effectElements.push(eff); 15804 } 15805 } 15806}; 15807 15808 15809var lottie = {}; 15810 15811function setLocationHref(href) { 15812 locationHref = href; 15813} 15814 15815function searchAnimations() { 15816 if (standalone === true) { 15817 animationManager.searchAnimations(animationData, standalone, renderer); 15818 } else { 15819 animationManager.searchAnimations(); 15820 } 15821} 15822 15823function setSubframeRendering(flag) { 15824 subframeEnabled = flag; 15825} 15826 15827function loadAnimation(params) { 15828 if (standalone === true) { 15829 params.animationData = JSON.parse(animationData); 15830 } 15831 return animationManager.loadAnimation(params); 15832} 15833 15834function setQuality(value) { 15835 if (typeof value === 'string') { 15836 switch (value) { 15837 case 'high': 15838 defaultCurveSegments = 200; 15839 break; 15840 default: 15841 case 'medium': 15842 defaultCurveSegments = 50; 15843 break; 15844 case 'low': 15845 defaultCurveSegments = 10; 15846 break; 15847 } 15848 } else if (!isNaN(value) && value > 1) { 15849 defaultCurveSegments = value; 15850 } 15851 if (defaultCurveSegments >= 50) { 15852 roundValues(false); 15853 } else { 15854 roundValues(true); 15855 } 15856} 15857 15858function inBrowser() { 15859 return typeof navigator !== 'undefined'; 15860} 15861 15862function installPlugin(type, plugin) { 15863 if (type === 'expressions') { 15864 expressionsPlugin = plugin; 15865 } 15866} 15867 15868function getFactory(name) { 15869 switch (name) { 15870 case 'propertyFactory': 15871 return PropertyFactory; 15872 case 'shapePropertyFactory': 15873 return ShapePropertyFactory; 15874 case 'matrix': 15875 return Matrix; 15876 default: 15877 return null; 15878 } 15879} 15880 15881lottie.play = animationManager.play; 15882lottie.pause = animationManager.pause; 15883lottie.setLocationHref = setLocationHref; 15884lottie.togglePause = animationManager.togglePause; 15885lottie.setSpeed = animationManager.setSpeed; 15886lottie.setDirection = animationManager.setDirection; 15887lottie.stop = animationManager.stop; 15888lottie.searchAnimations = searchAnimations; 15889lottie.registerAnimation = animationManager.registerAnimation; 15890lottie.loadAnimation = loadAnimation; 15891lottie.setSubframeRendering = setSubframeRendering; 15892lottie.resize = animationManager.resize; 15893// lottie.start = start; 15894lottie.goToAndStop = animationManager.goToAndStop; 15895lottie.destroy = animationManager.destroy; 15896lottie.setQuality = setQuality; 15897lottie.inBrowser = inBrowser; 15898lottie.installPlugin = installPlugin; 15899lottie.freeze = animationManager.freeze; 15900lottie.unfreeze = animationManager.unfreeze; 15901lottie.setVolume = animationManager.setVolume; 15902lottie.mute = animationManager.mute; 15903lottie.unmute = animationManager.unmute; 15904lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations; 15905lottie.__getFactory = getFactory; 15906lottie.version = '5.7.6'; 15907 15908function checkReady() { 15909 if (document.readyState === 'complete') { 15910 clearInterval(readyStateCheckInterval); 15911 searchAnimations(); 15912 } 15913} 15914 15915function getQueryVariable(variable) { 15916 var vars = queryString.split('&'); 15917 for (var i = 0; i < vars.length; i += 1) { 15918 var pair = vars[i].split('='); 15919 if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq 15920 return decodeURIComponent(pair[1]); 15921 } 15922 } 15923 return null; 15924} 15925var standalone = '__[STANDALONE]__'; 15926var animationData = '__[ANIMATIONDATA]__'; 15927var renderer = ''; 15928var queryString; 15929if (standalone) { 15930 var scripts = document.getElementsByTagName('script'); 15931 var index = scripts.length - 1; 15932 var myScript = scripts[index] || { 15933 src: '', 15934 }; 15935 queryString = myScript.src.replace(/^[^\?]+\??/, ''); // eslint-disable-line no-useless-escape 15936 renderer = getQueryVariable('renderer'); 15937} 15938var readyStateCheckInterval = setInterval(checkReady, 100); 15939 15940return lottie; 15941}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.